Skip to content

Commit aed3649

Browse files
committed
refactor: remove the swaps to a different function
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 7392aa6 commit aed3649

File tree

2 files changed

+82
-34
lines changed

2 files changed

+82
-34
lines changed

lib/node_modules/@stdlib/lapack/base/dgebak/lib/base.js

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@
2020

2121
// MODULES //
2222

23-
var dswap = require( '@stdlib/blas/base/dswap' ).ndarray;
2423
var dscal = require( '@stdlib/blas/base/dscal' ).ndarray;
25-
var trunc = require( '@stdlib/math/base/special/trunc' );
24+
var swaps = require( './swaps.js' );
2625

2726

2827
// MAIN //
@@ -65,9 +64,7 @@ var trunc = require( '@stdlib/math/base/special/trunc' );
6564
* // returns <Float64Array>[ 0.5, 2, 4, 10, 3, 6 ]
6665
*/
6766
function dgebak( job, side, N, M, ilo, ihi, scale, strideScale, offsetScale, V, strideV1, strideV2, offsetV ) { // eslint-disable-line max-len, max-params
68-
var ii;
6967
var i;
70-
var k;
7168
var s;
7269

7370
if ( N === 0 || M === 0 || job === 'none' ) {
@@ -76,22 +73,8 @@ function dgebak( job, side, N, M, ilo, ihi, scale, strideScale, offsetScale, V,
7673

7774
if ( ilo === ihi ) {
7875
if ( job === 'permute' || job === 'both' ) {
79-
for ( ii = 0; ii < N; ii++ ) {
80-
i = ii;
81-
if ( i >= ilo && i <= ihi ) {
82-
continue;
83-
}
84-
if ( i < ilo ) {
85-
i = ilo - ( ii + 1 ); // Use ii + 1 here to match fortran's 1 based implementation
86-
}
87-
k = trunc( scale[ offsetScale + (i * strideScale) ] ); // K = int ( scale[ i ] )
88-
if ( k === i ) {
89-
continue;
90-
}
91-
dswap( M, V, strideV2, offsetV + (i * strideV1), V, strideV2, offsetV + (k * strideV1) ); // eslint-disable-line max-len
92-
}
76+
swaps( N, M, ilo, ihi, scale, strideScale, offsetScale, V, strideV1, strideV2, offsetV ); // eslint-disable-line max-len
9377
}
94-
9578
return V;
9679
}
9780

@@ -110,22 +93,8 @@ function dgebak( job, side, N, M, ilo, ihi, scale, strideScale, offsetScale, V,
11093
}
11194

11295
if ( job === 'permute' || job === 'both' ) {
113-
for ( ii = 0; ii < N; ii++ ) {
114-
i = ii;
115-
if ( i >= ilo && i <= ihi ) {
116-
continue;
117-
}
118-
if ( i < ilo ) {
119-
i = ilo - ( ii + 1 ); // Use ii + 1 here to match fortran's 1 based implementation
120-
}
121-
k = trunc( scale[ offsetScale + (i * strideScale) ] ); // K = int ( scale[ i ] )
122-
if ( k === i ) {
123-
continue;
124-
}
125-
dswap( M, V, strideV2, offsetV + ( i * strideV1 ), V, strideV2, offsetV + ( k * strideV1 ) ); // eslint-disable-line max-len
126-
}
96+
swaps( N, M, ilo, ihi, scale, strideScale, offsetScale, V, strideV1, strideV2, offsetV ); // eslint-disable-line max-len
12797
}
128-
12998
return V;
13099
}
131100

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var dswap = require( '@stdlib/blas/base/dswap' ).ndarray;
24+
var trunc = require( '@stdlib/math/base/special/trunc' );
25+
26+
27+
// MAIN //
28+
29+
/**
30+
* Swaps the rows of a matrix `V` according to the permutation specified by the `scale` array.
31+
*
32+
* @private
33+
* @param {NonNegativeInteger} N - number of rows in matrix `V`
34+
* @param {NonNegativeInteger} M - number of columns in matrix `V`
35+
* @param {NonNegativeInteger} ilo - index of leftmost column of the submatrix computed by `dgebal` (zero-based)
36+
* @param {NonNegativeInteger} ihi - index of rightmost column of the submatrix computed by `dgebal` (zero-based)
37+
* @param {Float64Array} scale - contains the details of the permutations and scaling factors applied when balancing `V`, computed by `dgebal`
38+
* @param {integer} strideScale - stride of `scale`
39+
* @param {NonNegativeInteger} offsetScale - starting index for `scale`
40+
* @param {Float64Array} V - input matrix
41+
* @param {integer} strideV1 - stride of the first dimension of `V`
42+
* @param {integer} strideV2 - stride of the second dimension of `V`
43+
* @param {NonNegativeInteger} offsetV - starting index for `V`
44+
* @returns {void} manipulates `V` in place
45+
*
46+
* @example
47+
* var Float64Array = require( '@stdlib/array/float64' );
48+
*
49+
* var scale = new Float64Array( [ 2.0, 1.0, 0.0 ] );
50+
* var V = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
51+
*
52+
* swaps( 3, 2, 0, 1, scale, 1, 0, V, 2, 1, 0 );
53+
* // V => <Float64Array>[ 5, 6, 3, 4, 1, 2 ]
54+
*/
55+
function swaps( N, M, ilo, ihi, scale, strideScale, offsetScale, V, strideV1, strideV2, offsetV ) { // eslint-disable-line max-len, max-params
56+
var ii;
57+
var k;
58+
var i;
59+
60+
for ( ii = 0; ii < N; ii++ ) {
61+
i = ii;
62+
if ( i >= ilo && i <= ihi ) {
63+
continue;
64+
}
65+
if ( i < ilo ) {
66+
i = ilo - ( ii + 1 ); // Use ii + 1 here to match fortran's 1 based implementation
67+
}
68+
k = trunc( scale[ offsetScale + (i * strideScale) ] ); // K = int ( scale[ i ] )
69+
if ( k === i ) {
70+
continue;
71+
}
72+
dswap( M, V, strideV2, offsetV + (i * strideV1), V, strideV2, offsetV + (k * strideV1) ); // eslint-disable-line max-len
73+
}
74+
}
75+
76+
77+
// EXPORTS //
78+
79+
module.exports = swaps;

0 commit comments

Comments
 (0)