Skip to content

Commit 5f3e534

Browse files
committed
chore: clean-up
--- 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 0166476 commit 5f3e534

File tree

4 files changed

+130
-58
lines changed

4 files changed

+130
-58
lines changed

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

Lines changed: 93 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,41 @@ var daxpy = require( '@stdlib/blas/base/daxpy' ).ndarray;
3030
var dscal = require( '@stdlib/blas/base/dscal' ).ndarray;
3131

3232

33+
// FUNCTIONS //
34+
35+
/**
36+
* Tests whether an operation should be applied to the left side.
37+
*
38+
* @private
39+
* @param {string} side - operation side
40+
* @returns {boolean} boolean indicating if an operation should be applied to the left side
41+
*/
42+
function isLeftSide( side ) {
43+
return side === 'left';
44+
}
45+
46+
3347
// MAIN //
3448

3549
/**
3650
* Applies a real elementary reflector `H = I - tau * v * v^T` to a real M by N matrix `C`.
3751
*
3852
* ## Notes
3953
*
40-
* - `work` should have `N` indexed elements if side = `'left'` and `M` indexed elements if side = `'right'`.
41-
* - `V` should have `1 + (M-1) * abs(strideV)` indexed elements if side = `'left'` and `1 + (N-1) * abs(strideV)` indexed elements if side = `'right'`.
42-
* - `C` is overwritten by `H * C` if side = `'left'` and `C * H` if side = `'right'`.
54+
* - If `side = 'left'`,
55+
*
56+
* - `work` should have `N` indexed elements.
57+
* - `V` should have `1 + (M-1) * abs(strideV)` indexed elements.
58+
* - `C` is overwritten by `H * C`.
59+
*
60+
* - If `side = 'right'`,
61+
*
62+
* - `work` should have `M` indexed elements.
63+
* - `V` should have `1 + (N-1) * abs(strideV)` indexed elements.
64+
* - `C` is overwritten by `C * H`.
4365
*
4466
* @private
45-
* @param {string} side - specifies the side of multiplication with `C`. Use `'left'` to form `H * C` and `'right'` to form `C * H`.
67+
* @param {string} side - specifies the side of multiplication with `C`
4668
* @param {NonNegativeInteger} M - number of rows in `C`
4769
* @param {NonNegativeInteger} N - number of columns in `C`
4870
* @param {Float64Array} V - the vector `v`
@@ -73,51 +95,85 @@ function dlarf1f( side, M, N, V, strideV, offsetV, tau, C, strideC1, strideC2, o
7395
var lastc;
7496
var i;
7597

76-
lastv = 1;
98+
if ( tau === 0.0 ) {
99+
return C;
100+
}
77101
lastc = 0;
78-
if ( tau !== 0.0 ) {
79-
if ( side === 'left' ) {
80-
lastv = M;
81-
} else {
82-
lastv = N;
83-
}
84-
85-
// i points to the last element in V
86-
i = offsetV + ( ( lastv - 1 ) * strideV );
102+
if ( isLeftSide( side ) ) {
103+
lastv = M;
104+
} else {
105+
lastv = N;
106+
}
107+
// Initialize `i` to point to the last element in `V`:
108+
i = offsetV + ( ( lastv-1 ) * strideV );
87109

88-
// Move i to the last non-zero element in V
89-
while ( lastv > 0 && V[ i ] === 0.0 ) {
90-
lastv -= 1;
91-
i -= strideV;
92-
}
93-
if ( side === 'left' ) {
94-
lastc = iladlc( lastv + 1, N, C, strideC1, strideC2, offsetC ) + 1; // to account for the difference between zero-based and one-based indexing
95-
} else {
96-
lastc = iladlr( M, lastv + 1, C, strideC1, strideC2, offsetC ) + 1; // to account for the difference between zero-based and one-based indexing
97-
}
98-
// lastc is zero if a matrix is filled with zeros
110+
// Move `i` to the last non-zero element in `V`, where we assume that V[0] = 1, and it is not stored, so we shouldn't access it...
111+
while ( lastv > 0 && V[ i ] === 0.0 ) {
112+
lastv -= 1;
113+
i -= strideV;
114+
}
115+
if ( isLeftSide( side ) ) {
116+
// Scan for the last non-zero column in `C`:
117+
lastc = iladlc( lastv + 1, N, C, strideC1, strideC2, offsetC ) + 1; // adjust by `+1` to account for the difference between zero-based and one-based indexing
118+
} else {
119+
// Scan for the last non-zero row in `C`:
120+
lastc = iladlr( M, lastv + 1, C, strideC1, strideC2, offsetC ) + 1; // // adjust by `+1` to account for the difference between zero-based and one-based indexing
99121
}
122+
// Return `C` unchanged if all elements in `C` are zero...
100123
if ( lastc === 0 ) {
101-
// Returns C unchanged if tau is zero or all elements in C are zero
102124
return C;
103125
}
104-
if ( side === 'left' ) {
126+
if ( isLeftSide( side ) ) {
127+
// Form: H*C
128+
129+
// If `lastv = 1`, this means `V = 1`, so we just need to compute `C = H*C = (1\tau)*C`...
105130
if ( lastv === 0 ) {
106-
dscal( lastc, 1.0 - tau, C, strideC2, offsetC ); // scale the first row
131+
// C[0,0:lastc] = (1-tau)*C[0,0:lastc]
132+
dscal( lastc, 1.0-tau, C, strideC2, offsetC ); // scale the first row
107133
} else {
108-
dgemv( 'transpose', lastv-1, lastc, 1.0, C, strideC1, strideC2, offsetC + strideC1, V, strideV, offsetV + strideV, 0.0, work, strideWork, offsetWork ); // C( 1, 0 ) is accessed here
134+
// work[0:lastc,0] = C[0:lastv,0:lastc]^T * V[0:lastv,0]
135+
136+
// work[0:lastc,0] = C[1:lastv,0:lastc]^T * V[1:lastv,0]
137+
dgemv( 'transpose', lastv-1, lastc, 1.0, C, strideC1, strideC2, offsetC+strideC1, V, strideV, offsetV+strideV, 0.0, work, strideWork, offsetWork );
138+
139+
// work[0:lastc,0] += C[0,0:lastc]^T * V[0,0] = C[0,0:lastc]^T
109140
daxpy( lastc, 1.0, C, strideC2, offsetC, work, strideWork, offsetWork ); // operates on the first row of C
141+
142+
// C[0:lastv,0:lastc] = C[...] - ( tau * V[0:lastv,0] * work[0:lastc,0]^T)
143+
144+
// C[0,0:lastc] = C[...] - ( tau * V[0,0] * work[0:lastc,0]^^T ) = C[...] - ( tau * work[0:lastc,0]^T )
110145
daxpy( lastc, -tau, work, strideWork, offsetWork, C, strideC2, offsetC ); // operates on the first row of C
111-
dger( lastv-1, lastc, -tau, V, strideV, offsetV + strideV, work, strideWork, offsetWork, C, strideC1, strideC2, offsetC + strideC1 ); // C( 1, 0 ) is accessed here
146+
147+
// C[1:lastv,0:lastc] = C[...] - ( tau * V[1:lastv,0] * work[0:lastc,0]^T )
148+
dger( lastv-1, lastc, -tau, V, strideV, offsetV+strideV, work, strideWork, offsetWork, C, strideC1, strideC2, offsetC+strideC1 );
112149
}
113-
} else if ( lastv === 0 ) {
114-
dscal( lastc, 1.0 - tau, C, strideC1, offsetC ); // scale the first column
115-
} else {
116-
dgemv( 'no-transpose', lastc, lastv-1, 1.0, C, strideC1, strideC2, offsetC + strideC2, V, strideV, offsetV + strideV, 0.0, work, strideWork, offsetWork ); // C( 0, 1 ) is accessed here
117-
daxpy( lastc, 1.0, C, strideC1, offsetC, work, strideWork, offsetWork ); // operates on the first column of C
118-
daxpy( lastc, -tau, work, strideWork, offsetWork, C, strideC1, offsetC ); // operates on the first column of C
119-
dger( lastc, lastv-1, -tau, work, strideWork, offsetWork, V, strideV, offsetV + strideV, C, strideC1, strideC2, offsetC + strideC2 ); // C( 0, 1 ) is accessed here
150+
return C;
151+
}
152+
// side === 'right'
153+
154+
// Form: C*H
155+
156+
// If `N = 1`, then `V = 1`, so we just need to compute `C = CH = C*(1-tau)`...
157+
if ( lastv === 0 ) {
158+
// C[0:lastc,0] = ( 1-tau ) * C[0:lastc,0]
159+
dscal( lastc, 1.0-tau, C, strideC1, offsetC ); // scale the first column
160+
return C;
120161
}
162+
// work[0:lastc,0] = ( 1-tau ) * C[0:lastc,0]
163+
164+
// work[0:lastc,0] = C[0:lastc,1:lastv] * V[1:lastv,0]
165+
dgemv( 'no-transpose', lastc, lastv-1, 1.0, C, strideC1, strideC2, offsetC+strideC2, V, strideV, offsetV+strideV, 0.0, work, strideWork, offsetWork );
166+
167+
// work[0:lastc,0] += C[0:lastc,0] * V[0,0] = C[0:lastc,0]
168+
daxpy( lastc, 1.0, C, strideC1, offsetC, work, strideWork, offsetWork ); // operates on the first column of C
169+
170+
// C[0:lastc,0:lastv] = C[...] - ( tau * work[0:lastc,0] * V[0:lastv,0]^T )
171+
172+
// C[0:lastc,0] = C[...] - ( tau * work[0:lastc,0] * V[0,0]^T ) = C[...] - ( tau * work[0:lastc,0] )
173+
daxpy( lastc, -tau, work, strideWork, offsetWork, C, strideC1, offsetC ); // operates on the first column of C
174+
175+
// C[0:lastc,1:lastv] = C[...] - ( tau * work[0:lastc,0] * V[1:lastv]^T )
176+
dger( lastc, lastv-1, -tau, work, strideWork, offsetWork, V, strideV, offsetV+strideV, C, strideC1, strideC2, offsetC+strideC2 );
121177

122178
return C;
123179
}

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020

2121
// MODULES //
2222

23+
var isOperationSide = require( '@stdlib/blas/base/assert/is-operation-side' );
2324
var isLayout = require( '@stdlib/blas/base/assert/is-layout' );
2425
var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' );
2526
var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' );
27+
var operationSides = require( '@stdlib/blas/base/operation-sides' );
28+
var join = require( '@stdlib/array/base/join' );
2629
var max = require( '@stdlib/math/base/special/max' );
27-
var format = require( '@stdlib/string/format' );
2830
var stride2offset = require( '@stdlib/strided/base/stride2offset' );
31+
var format = require( '@stdlib/string/format' );
2932
var base = require( './base.js' );
3033

3134

@@ -36,12 +39,20 @@ var base = require( './base.js' );
3639
*
3740
* ## Notes
3841
*
39-
* - `work` should have `N` indexed elements if side = `'left'` and `M` indexed elements if side = `'right'`.
40-
* - `V` should have `1 + (M-1) * abs(incv)` indexed elements if side = `'left'` and `1 + (N-1) * abs(incv)` indexed elements if side = `'right'`.
41-
* - `C` is overwritten by `H * C` if side = `'left'` and `C * H` if side = `'right'`.
42+
* - If `side = 'left'`,
43+
*
44+
* - `work` should have `N` indexed elements.
45+
* - `V` should have `1 + (M-1) * abs(strideV)` indexed elements.
46+
* - `C` is overwritten by `H * C`.
47+
*
48+
* - If `side = 'right'`,
49+
*
50+
* - `work` should have `M` indexed elements.
51+
* - `V` should have `1 + (N-1) * abs(strideV)` indexed elements.
52+
* - `C` is overwritten by `C * H`.
4253
*
4354
* @param {string} order - storage layout
44-
* @param {string} side - specifies the side of multiplication with `C`. Use `'left'` to form `H * C` and `'right'` to form `C * H`.
55+
* @param {string} side - specifies the side of multiplication with `C`
4556
* @param {NonNegativeInteger} M - number of rows in `C`
4657
* @param {NonNegativeInteger} N - number of columns in `C`
4758
* @param {Float64Array} V - the vector `v`
@@ -52,7 +63,7 @@ var base = require( './base.js' );
5263
* @param {Float64Array} work - workspace array
5364
* @throws {TypeError} first argument must be a valid order
5465
* @throws {TypeError} second argument must be a valid side
55-
* @throws {RangeError} ninth argument must be greater than or equal to max(1,N)
66+
* @throws {RangeError} fourth argument must be greater than or equal to max(1,N)
5667
* @throws {RangeError} fifth argument must not be zero
5768
* @returns {Float64Array} `C * H` or `H * C`
5869
*
@@ -77,11 +88,11 @@ function dlarf1f( order, side, M, N, V, incv, tau, C, LDC, work ) {
7788
if ( isRowMajor( order ) && LDC < max( 1, N ) ) {
7889
throw new RangeError( format( 'invalid argument. Fourth argument must be greater than or equal to max(1,%d). Value: `%d`.', N, LDC ) );
7990
}
80-
if ( side !== 'left' && side !== 'right' ) { // TODO - refactor this to make use of an array if needed
81-
throw new TypeError( format( 'invalid argument. Second argument must be a valid side (left or right). Value: `%s`.', side ) );
91+
if ( !isOperationSide( side ) ) {
92+
throw new TypeError( format( 'invalid argument. Second argument must be one of the following: "%s". Value: `%s`.', join( operationSides(), '", "' ), side ) );
8293
}
8394
if ( incv === 0 ) {
84-
throw new RangeError( format( 'invalid argument. Fifth argument must not be zero' ) );
95+
throw new RangeError( format( 'invalid argument. Fifth argument must be non-zero. Value: `%s`.', incv ) );
8596
}
8697
if ( isColumnMajor( order ) ) {
8798
sc1 = 1;

lib/node_modules/@stdlib/lapack/base/dlarf1f/lib/index.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@
2121
/**
2222
* LAPACK routine to apply a real elementary reflector `H = I - tau * v * v^T` to a real M by N matrix `C`.
2323
*
24-
* ## Notes
25-
*
26-
* - `work` should have `N` indexed elements if side = `'left'` and `M` indexed elements if side = `'right'`.
27-
* - `V` should have `1 + (M-1) * abs(incv)` indexed elements if side = `'left'` and `1 + (N-1) * abs(incv)` indexed elements if side = `'right'`.
28-
* - `C` is overwritten by `H * C` if side = `'left'` and `C * H` if side = `'right'`.
29-
*
3024
* @module @stdlib/lapack/base/dlarf1f
3125
*
3226
* @example

lib/node_modules/@stdlib/lapack/base/dlarf1f/lib/ndarray.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
// MODULES //
2424

25+
var isOperationSide = require( '@stdlib/blas/base/assert/is-operation-side' );
26+
var operationSides = require( '@stdlib/blas/base/operation-sides' );
27+
var join = require( '@stdlib/array/base/join' );
2528
var format = require( '@stdlib/string/format' );
2629
var base = require( './base.js' );
2730

@@ -33,11 +36,19 @@ var base = require( './base.js' );
3336
*
3437
* ## Notes
3538
*
36-
* - `work` should have `N` indexed elements if side = `'left'` and `M` indexed elements if side = `'right'`.
37-
* - `V` should have `1 + (M-1) * abs(strideV)` indexed elements if side = `'left'` and `1 + (N-1) * abs(strideV)` indexed elements if side = `'right'`.
38-
* - `C` is overwritten by `H * C` if side = `'left'` and `C * H` if side = `'right'`.
39+
* - If `side = 'left'`,
3940
*
40-
* @param {string} side - specifies the side of multiplication with `C`. Use `'left'` to form `H * C` and `'right'` to form `C * H`.
41+
* - `work` should have `N` indexed elements.
42+
* - `V` should have `1 + (M-1) * abs(strideV)` indexed elements.
43+
* - `C` is overwritten by `H * C`.
44+
*
45+
* - If `side = 'right'`,
46+
*
47+
* - `work` should have `M` indexed elements.
48+
* - `V` should have `1 + (N-1) * abs(strideV)` indexed elements.
49+
* - `C` is overwritten by `C * H`.
50+
*
51+
* @param {string} side - specifies the side of multiplication with `C`
4152
* @param {NonNegativeInteger} M - number of rows in `C`
4253
* @param {NonNegativeInteger} N - number of columns in `C`
4354
* @param {Float64Array} V - the vector `v`
@@ -65,8 +76,8 @@ var base = require( './base.js' );
6576
* // returns <Float64Array>[ -4.5, -10.5, -16.5, -0.75, -1.75, -2.75, 0.25, -0.75, -1.75, 1.25, 0.25, -0.75 ]
6677
*/
6778
function dlarf1f( side, M, N, V, strideV, offsetV, tau, C, strideC1, strideC2, offsetC, work, strideWork, offsetWork ) { // eslint-disable-line max-params
68-
if ( side !== 'left' && side !== 'right' ) { // TODO - refactor this to make use of an array if needed
69-
throw new TypeError( format( 'invalid argument. First argument must be a valid side (left or right). Value: `%s`.', side ) );
79+
if ( !isOperationSide( side ) ) {
80+
throw new TypeError( format( 'invalid argument. First argument must be one of the following: "%s". Value: `%s`.', join( operationSides(), '", "' ), side ) );
7081
}
7182
return base( side, M, N, V, strideV, offsetV, tau, C, strideC1, strideC2, offsetC, work, strideWork, offsetWork );
7283
}

0 commit comments

Comments
 (0)