Skip to content

Commit efad4c2

Browse files
committed
refactor: apply suggestions from code review
--- 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: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent a07fb24 commit efad4c2

11 files changed

Lines changed: 663 additions & 86 deletions

File tree

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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+
/* eslint-disable max-len */
20+
21+
'use strict';
22+
23+
// MODULES //
24+
25+
var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' );
26+
var dfill = require( '@stdlib/blas/ext/base/dfill' ).ndarray;
27+
28+
29+
// MAIN //
30+
31+
/**
32+
* Generates a double-precision floating-point Vandermonde matrix.
33+
*
34+
* @private
35+
* @param {integer} mode - specifies whether columns should contain powers that are increasing or decreasing
36+
* @param {NonNegativeInteger} M - number of rows in `out`
37+
* @param {NonNegativeInteger} N - number of columns in `out`
38+
* @param {Float64Array} x - input array
39+
* @param {integer} strideX - stride length for `x`
40+
* @param {NonNegativeInteger} offsetX - starting index for `x`
41+
* @param {Float64Array} out - output array
42+
* @param {integer} strideOut1 - stride length for the first dimension of `Out`
43+
* @param {integer} strideOut2 - stride length for the second dimension of `Out`
44+
* @param {NonNegativeInteger} offsetOut - starting index for `Out`
45+
* @returns {Float64Array} output array
46+
*
47+
* @example
48+
* var Float64Array = require( '@stdlib/array/float64' );
49+
*
50+
* var x = new Float64Array( [ 1.0, 2.0, 3.0 ] );
51+
* var out = new Float64Array( 9 );
52+
*
53+
* dvander( -1, 3, 3, x, 1, 0, out, 3, 1, 0 );
54+
* // out => <Float64Array>[ 1.0, 1.0, 1.0, 4.0, 2.0, 1.0, 9.0, 3.0, 1.0 ]
55+
*/
56+
function dvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) {
57+
var do0;
58+
var do1;
59+
var rm;
60+
var S0;
61+
var S1;
62+
var sx;
63+
var io;
64+
var ix;
65+
var i0;
66+
var i1;
67+
68+
// Note on variable naming convention: S#, do#, io, i# where # corresponds to the loop number, with `0` being the innermost loop...
69+
rm = isRowMajor( [ strideOut1, strideOut2 ] );
70+
71+
// Extract loop variables for loop interchange...
72+
if ( rm ) {
73+
S0 = N;
74+
S1 = M;
75+
do0 = strideOut2; // offset increment for innermost loop
76+
do1 = strideOut1 - ( S0*strideOut2 ); // offset increment for outermost loop
77+
} else { // order === 'column-major'
78+
S0 = M;
79+
S1 = N;
80+
do0 = strideOut1; // offset increment for innermost loop
81+
do1 = strideOut2 - ( S0*strideOut1 ); // offset increment for outermost loop
82+
}
83+
sx = strideX;
84+
io = offsetOut;
85+
86+
// For a Vandermonde matrix, each row `i` contains powers of `x[i]`:
87+
if ( rm ) {
88+
ix = offsetX;
89+
for ( i1 = 0; i1 < S1; i1++ ) {
90+
if ( mode > 0 ) {
91+
// Increasing: x^0, x^1, ..., x^(N-1)
92+
out[ io ] = 1.0;
93+
io += do0;
94+
for ( i0 = 1; i0 < S0; i0++ ) {
95+
out[ io ] = out[ io - do0 ] * x[ ix ];
96+
io += do0;
97+
}
98+
} else {
99+
// Decreasing: x^(N-1), x^(N-2), ..., x^0
100+
out[ io + ( ( S0-1 ) * do0 ) ] = 1.0;
101+
for ( i0 = S0 - 2; i0 >= 0; i0-- ) {
102+
out[ io + ( i0*do0 ) ] = out[ io + ( (i0+1)*do0 ) ] * x[ ix ];
103+
}
104+
io += S0 * do0;
105+
}
106+
ix += sx;
107+
io += do1;
108+
}
109+
} else if ( mode > 0 ) {
110+
// Increasing: column j contains x^j
111+
dfill( S0, 1.0, out, do0, io );
112+
io += ( S0 * do0 ) + do1;
113+
for ( i1 = 1; i1 < S1; i1++ ) {
114+
ix = offsetX;
115+
for ( i0 = 0; i0 < S0; i0++ ) {
116+
out[ io ] = out[ io - strideOut2 ] * x[ ix ];
117+
ix += sx;
118+
io += do0;
119+
}
120+
io += do1;
121+
}
122+
} else {
123+
// Decreasing: column 0 contains x^(N-1), last column all ones
124+
dfill( S0, 1.0, out, do0, offsetOut + ( ( S1-1 ) * strideOut2 ) );
125+
for ( i1 = S1 - 2; i1 >= 0; i1-- ) {
126+
io = offsetOut + ( i1 * strideOut2 );
127+
ix = offsetX;
128+
for ( i0 = 0; i0 < S0; i0++ ) {
129+
out[ io ] = out[ io + strideOut2 ] * x[ ix ];
130+
ix += sx;
131+
io += do0;
132+
}
133+
}
134+
}
135+
return out;
136+
}
137+
138+
139+
// EXPORTS //
140+
141+
module.exports = dvander;

lib/node_modules/@stdlib/blas/ext/base/dvander/lib/dvander.js

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
// MODULES //
2222

2323
var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' );
24+
var isLayout = require( '@stdlib/blas/base/assert/is-layout' );
2425
var stride2offset = require( '@stdlib/strided/base/stride2offset' );
25-
var ndarray = require( './ndarray.js' );
26+
var max = require( '@stdlib/math/base/special/fast/max' );
27+
var format = require( '@stdlib/string/format' );
28+
var base = require( './base.js' );
2629

2730

2831
// MAIN //
@@ -38,6 +41,11 @@ var ndarray = require( './ndarray.js' );
3841
* @param {integer} strideX - stride length for `x`
3942
* @param {Float64Array} out - output array
4043
* @param {PositiveInteger} LDO - stride length for the leading dimension of `Out`
44+
* @throws {TypeError} first argument must be a valid order
45+
* @throws {RangeError} third argument must be a nonnegative integer
46+
* @throws {RangeError} fourth argument must be a nonnegative integer
47+
* @throws {RangeError} sixth argument must be non-zero
48+
* @throws {RangeError} eighth argument must be a valid stride
4149
* @returns {Float64Array} output array
4250
*
4351
* @example
@@ -50,19 +58,49 @@ var ndarray = require( './ndarray.js' );
5058
* // out => <Float64Array>[ 1.0, 1.0, 1.0, 4.0, 2.0, 1.0, 9.0, 3.0, 1.0 ]
5159
*/
5260
function dvander( order, mode, M, N, x, strideX, out, LDO ) {
61+
var iscm;
5362
var sa1;
5463
var sa2;
5564
var ox;
65+
var k;
66+
67+
if ( !isLayout( order ) ) {
68+
throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) );
69+
}
70+
if ( M < 0 ) {
71+
throw new RangeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', M ) );
72+
}
73+
if ( N < 0 ) {
74+
throw new RangeError( format( 'invalid argument. Fourth argument must be a nonnegative integer. Value: `%d`.', N ) );
75+
}
76+
if ( strideX === 0 ) {
77+
throw new RangeError( format( 'invalid argument. Sixth argument must be non-zero. Value: `%d`.', strideX ) );
78+
}
79+
80+
iscm = isColumnMajor( order );
81+
if ( iscm ) {
82+
k = M;
83+
} else {
84+
k = N;
85+
}
86+
87+
if ( LDO < max( 1, k ) ) {
88+
throw new RangeError( format( 'invalid argument. Eighth argument must be greater than or equal to max(1,%d). Value: `%d`.', k, LDO ) );
89+
}
90+
91+
if ( M === 0 || N === 0 ) {
92+
return out;
93+
}
5694

5795
ox = stride2offset( M, strideX );
58-
if ( isColumnMajor( order ) ) {
96+
if ( iscm ) {
5997
sa1 = 1;
6098
sa2 = LDO;
6199
} else { // order === 'row-major'
62100
sa1 = LDO;
63101
sa2 = 1;
64102
}
65-
return ndarray( mode, M, N, x, strideX, ox, out, sa1, sa2, 0 );
103+
return base( mode, M, N, x, strideX, ox, out, sa1, sa2, 0 );
66104
}
67105

68106

lib/node_modules/@stdlib/blas/ext/base/dvander/lib/dvander.native.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020

2121
// MODULES //
2222

23+
var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' );
24+
var isLayout = require( '@stdlib/blas/base/assert/is-layout' );
2325
var resolve = require( '@stdlib/blas/base/layout-resolve-enum' );
26+
var max = require( '@stdlib/math/base/special/fast/max' );
27+
var format = require( '@stdlib/string/format' );
2428
var addon = require( './../src/addon.node' );
2529

2630

@@ -37,6 +41,11 @@ var addon = require( './../src/addon.node' );
3741
* @param {integer} strideX - stride length for `x`
3842
* @param {Float64Array} out - output array
3943
* @param {PositiveInteger} LDO - stride length for the leading dimension of `Out`
44+
* @throws {TypeError} first argument must be a valid order
45+
* @throws {RangeError} third argument must be a nonnegative integer
46+
* @throws {RangeError} fourth argument must be a nonnegative integer
47+
* @throws {RangeError} sixth argument must be non-zero
48+
* @throws {RangeError} eighth argument must be a valid stride
4049
* @returns {Float64Array} output array
4150
*
4251
* @example
@@ -49,6 +58,35 @@ var addon = require( './../src/addon.node' );
4958
* // out => <Float64Array>[ 1.0, 1.0, 1.0, 4.0, 2.0, 1.0, 9.0, 3.0, 1.0 ]
5059
*/
5160
function dvander( order, mode, M, N, x, strideX, out, LDO ) {
61+
var k;
62+
63+
if ( !isLayout( order ) ) {
64+
throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) );
65+
}
66+
if ( M < 0 ) {
67+
throw new RangeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', M ) );
68+
}
69+
if ( N < 0 ) {
70+
throw new RangeError( format( 'invalid argument. Fourth argument must be a nonnegative integer. Value: `%d`.', N ) );
71+
}
72+
if ( strideX === 0 ) {
73+
throw new RangeError( format( 'invalid argument. Sixth argument must be non-zero. Value: `%d`.', strideX ) );
74+
}
75+
76+
if ( isColumnMajor( order ) ) {
77+
k = M;
78+
} else {
79+
k = N;
80+
}
81+
82+
if ( LDO < max( 1, k ) ) {
83+
throw new RangeError( format( 'invalid argument. Eighth argument must be greater than or equal to max(1,%d). Value: `%d`.', k, LDO ) );
84+
}
85+
86+
if ( M === 0 || N === 0 ) {
87+
return out;
88+
}
89+
5290
addon( resolve( order ), mode, M, N, x, strideX, out, LDO );
5391
return out;
5492
}

0 commit comments

Comments
 (0)