16
16
* limitations under the License.
17
17
*/
18
18
19
- /* eslint-disable max-len, max-params, max-statements, max-lines-per-function */
19
+ /* eslint-disable max-len, max-params, max-statements */
20
20
21
21
'use strict' ;
22
22
@@ -28,6 +28,7 @@ var dnrm2 = require( '@stdlib/blas/base/dnrm2' ).ndarray;
28
28
var idamax = require ( '@stdlib/blas/base/idamax' ) . ndarray ;
29
29
var abs = require ( '@stdlib/math/base/special/abs' ) ;
30
30
var isnan = require ( '@stdlib/assert/is-nan' ) ;
31
+ var dfill = require ( '@stdlib/blas/ext/base/dfill' ) . ndarray ;
31
32
var max = require ( '@stdlib/math/base/special/maxn' ) ;
32
33
var min = require ( '@stdlib/math/base/special/minn' ) ;
33
34
var dscal = require ( '@stdlib/blas/base/dscal' ) . ndarray ;
@@ -37,6 +38,10 @@ var dscal = require( '@stdlib/blas/base/dscal' ).ndarray;
37
38
38
39
var sclfac = 2.0 ;
39
40
var factor = 0.95 ;
41
+ var sfmin1 = dlamch ( 'S' ) / dlamch ( 'P' ) ;
42
+ var sfmax1 = 1.0 / sfmin1 ;
43
+ var sfmin2 = sfmin1 * sclfac ;
44
+ var sfmax2 = 1.0 / sfmin2 ;
40
45
41
46
42
47
// MAIN //
@@ -74,7 +79,7 @@ var factor = 0.95;
74
79
* @param {Float64Array } scale - array containing permutation and scaling information
75
80
* @param {integer } strideScale - stride of `scale`
76
81
* @param {NonNegativeInteger } offsetScale - starting index for `scale`
77
- * @throws {RangeError } should not return NaN
82
+ * @throws {RangeError } the input matrix cannot be balanced. Encountered a NaN during computation.
78
83
* @returns {integer } status code
79
84
*
80
85
* @example
@@ -93,10 +98,6 @@ var factor = 0.95;
93
98
function dgebal ( job , N , A , strideA1 , strideA2 , offsetA , out , strideOut , offsetOut , scale , strideScale , offsetScale ) {
94
99
var canSwap ;
95
100
var noconv ;
96
- var sfmin1 ;
97
- var sfmin2 ;
98
- var sfmax1 ;
99
- var sfmax2 ;
100
101
var ica ;
101
102
var ira ;
102
103
var ia1 ;
@@ -124,11 +125,7 @@ function dgebal( job, N, A, strideA1, strideA2, offsetA, out, strideOut, offsetO
124
125
}
125
126
126
127
if ( job === 'none' ) {
127
- is = offsetScale ;
128
- for ( i = 0 ; i < N ; i ++ ) {
129
- scale [ is ] = 1.0 ;
130
- is += strideScale ;
131
- }
128
+ dfill ( N , 1.0 , scale , strideScale , offsetScale ) ;
132
129
133
130
out [ offsetOut ] = 0.0 ; // ilo
134
131
out [ offsetOut + strideOut ] = N - 1 ; // ihi
@@ -227,11 +224,7 @@ function dgebal( job, N, A, strideA1, strideA2, offsetA, out, strideOut, offsetO
227
224
}
228
225
229
226
// Initialize scale for non-permuted submatrix
230
- is = offsetScale + ( k * strideScale ) ;
231
- for ( i = k ; i <= l ; i ++ ) {
232
- scale [ is ] = 1.0 ;
233
- is += strideScale ;
234
- }
227
+ dfill ( N - k , 1.0 , scale , strideScale , offsetScale + ( k * strideScale ) ) ;
235
228
236
229
if ( job === 'permute' ) {
237
230
out [ offsetOut ] = k ; // ilo
@@ -240,11 +233,6 @@ function dgebal( job, N, A, strideA1, strideA2, offsetA, out, strideOut, offsetO
240
233
}
241
234
242
235
// Balance the submatrix in rows K to L, iterative loop for norm reduction (job = 'B')
243
- sfmin1 = dlamch ( 'S' ) / dlamch ( 'P' ) ;
244
- sfmax1 = 1.0 / sfmin1 ;
245
- sfmin2 = sfmin1 * sclfac ;
246
- sfmax2 = 1.0 / sfmin2 ;
247
-
248
236
noconv = true ;
249
237
while ( noconv ) {
250
238
is = offsetScale + ( k * strideScale ) ; // Follows scale
@@ -270,7 +258,7 @@ function dgebal( job, N, A, strideA1, strideA2, offsetA, out, strideOut, offsetO
270
258
}
271
259
272
260
if ( isnan ( c ) || isnan ( r ) || isnan ( ca ) || isnan ( ra ) ) {
273
- throw new RangeError ( 'should not return NaN' ) ;
261
+ throw new RangeError ( 'invalid argument. The input matrix cannot be balanced. Encountered a NaN during computation. ' ) ;
274
262
}
275
263
276
264
g = r / sclfac ;
@@ -306,24 +294,20 @@ function dgebal( job, N, A, strideA1, strideA2, offsetA, out, strideOut, offsetO
306
294
continue ;
307
295
}
308
296
309
- if ( f < 1.0 && scale [ is ] < 1.0 ) {
310
- if ( f * scale [ is ] <= sfmin1 ) {
311
- ia1 += strideA2 ;
312
- ia2 += strideA1 ;
313
- is += strideScale ;
314
- ia3 += strideA2 ;
315
- continue ;
316
- }
297
+ if ( f < 1.0 && scale [ is ] < 1.0 && f * scale [ is ] <= sfmin1 ) {
298
+ ia1 += strideA2 ;
299
+ ia2 += strideA1 ;
300
+ is += strideScale ;
301
+ ia3 += strideA2 ;
302
+ continue ;
317
303
}
318
304
319
- if ( f > 1.0 && scale [ is ] > 1.0 ) {
320
- if ( scale [ is ] >= sfmax1 / f ) {
321
- ia1 += strideA2 ;
322
- ia2 += strideA1 ;
323
- is += strideScale ;
324
- ia3 += strideA2 ;
325
- continue ;
326
- }
305
+ if ( f > 1.0 && scale [ is ] > 1.0 && scale [ is ] >= sfmax1 / f ) {
306
+ ia1 += strideA2 ;
307
+ ia2 += strideA1 ;
308
+ is += strideScale ;
309
+ ia3 += strideA2 ;
310
+ continue ;
327
311
}
328
312
329
313
g = 1.0 / f ;
0 commit comments