From cb2fccf455cff54a00f19f6da85c5e8709a02711 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 14 Mar 2026 18:01:09 +0500 Subject: [PATCH 01/32] feat: add blas/ext/base/gvander --- .../@stdlib/blas/ext/base/gvander/README.md | 211 ++++++ .../ext/base/gvander/benchmark/benchmark.js | 106 +++ .../gvander/benchmark/benchmark.ndarray.js | 106 +++ .../blas/ext/base/gvander/docs/repl.txt | 121 ++++ .../ext/base/gvander/docs/types/index.d.ts | 119 ++++ .../blas/ext/base/gvander/docs/types/test.ts | 341 ++++++++++ .../blas/ext/base/gvander/examples/index.js | 35 + .../blas/ext/base/gvander/lib/accessors.js | 135 ++++ .../blas/ext/base/gvander/lib/index.js | 59 ++ .../@stdlib/blas/ext/base/gvander/lib/main.js | 69 ++ .../blas/ext/base/gvander/lib/ndarray.js | 151 +++++ .../blas/ext/base/gvander/package.json | 67 ++ .../blas/ext/base/gvander/test/test.js | 38 ++ .../blas/ext/base/gvander/test/test.main.js | 528 +++++++++++++++ .../ext/base/gvander/test/test.ndarray.js | 633 ++++++++++++++++++ 15 files changed, 2719 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gvander/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gvander/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gvander/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gvander/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gvander/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gvander/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gvander/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gvander/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gvander/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gvander/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gvander/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md b/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md new file mode 100644 index 000000000000..358432fe3022 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md @@ -0,0 +1,211 @@ + + +# gvander + +> Generate a Vandermonde matrix. + +
+ +
+ + + +
+ +## Usage + +```javascript +var gvander = require( '@stdlib/blas/ext/base/gvander' ); +``` + +#### gvander( order, mode, M, N, x, strideX, out, LDO ) + +Generates a Vandermonde matrix. + +```javascript +var x = [ 1.0, 2.0, 3.0 ]; +var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +gvander( 'row-major', 1, 3, 3, x, 1, out, 3 ); +// out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] +``` + +The function has the following parameters: + +- **order**: storage layout. +- **mode**: mode indicating whether to generate increasing (`1`) or decreasing (`-1`) powers. +- **M**: number of rows. +- **N**: number of columns. +- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideX**: stride length for `x`. +- **out**: output [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **LDO**: stride length for leading dimension of `out`. + + +```javascript +var x = [ 1.0, 2.0, 3.0 ]; +var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +gvander( 'row-major', -1, 3, 3, x, 1, out, 3 ); +// out => [ 1.0, 1.0, 1.0, 4.0, 2.0, 1.0, 9.0, 3.0, 1.0 ] +``` + +The `M` and `strideX` parameters determine which elements in the input array are accessed at runtime. For example, to use every other element from the input array: + +```javascript +var x = [ 1.0, 0.0, 2.0, 0.0, 3.0 ]; +var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +gvander( 'row-major', 1, 3, 3, x, 2, out, 3 ); +// out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial array: +var x0 = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] ); + +// Create an offset view: +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var out = new Float64Array( 9 ); + +gvander( 'row-major', 1, 3, 3, x1, 1, out, 3 ); +// out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] +``` + + + +#### gvander.ndarray( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) + + + +Generates a Vandermonde matrix using alternative indexing semantics. + +```javascript +var x = [ 1.0, 2.0, 3.0 ]; +var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +gvander.ndarray( 1, 3, 3, x, 1, 0, out, 3, 1, 0 ); +// out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. +- **strideOut1**: stride length for the first dimension of `out`. +- **strideOut2**: stride length for the second dimension of `out`. +- **offsetOut**: starting index for `out`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on starting indices. For example, to use every other element from the input array starting from the second element: + +```javascript +var x = [ 0.0, 1.0, 0.0, 2.0, 0.0, 3.0 ]; +var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +gvander.ndarray( 1, 3, 3, x, 2, 1, out, 3, 1, 0 ); +// out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] +``` + +
+ + + +
+ +## Notes + +- If `M <= 0` or `N <= 0`, both functions return `out` unchanged. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). +- Depending on the environment, the typed versions ([`dvander`][@stdlib/blas/ext/base/dvander], [`svander`][@stdlib/blas/ext/base/svander], etc.) are likely to be significantly more performant. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var zeros = require( '@stdlib/array/zeros' ); +var gvander = require( '@stdlib/blas/ext/base/gvander' ); + +var M = 3; +var N = 4; + +var x = discreteUniform( M, 0, 10, { + 'dtype': 'generic' +}); +var out = zeros( M*N, 'generic' ); +console.log( x ); + +gvander( 'row-major', -1, M, N, x, 1, out, N ); +console.log( out ); +``` + +
+ + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/benchmark/benchmark.js new file mode 100644 index 000000000000..8d9965229356 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/benchmark/benchmark.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var zeros = require( '@stdlib/array/zeros' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gvander = require( './../lib/main.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var out = zeros( len * len, options.dtype ); + var x = uniform( len, -10, 10, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x[ 0 ] += 0.1; + v = gvander( 'row-major', 1, len, len, x, 1, out, len ); + if ( isnan( v[ i%v.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v[ i%v.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..0f83aae16e71 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/benchmark/benchmark.ndarray.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var zeros = require( '@stdlib/array/zeros' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gvander = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var out = zeros( len * len, options.dtype ); + var x = uniform( len, -10, 10, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x[ 0 ] += 0.1; + v = gvander( 1, len, len, x, 1, 0, out, len, 1, 0 ); + if ( isnan( v[ i%v.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v[ i%v.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:ndarray:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/repl.txt new file mode 100644 index 000000000000..cd3882d08765 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/repl.txt @@ -0,0 +1,121 @@ + +{{alias}}( order, mode, M, N, x, strideX, out, LDO ) + Generates a Vandermonde matrix. + + The `M` and stride parameters determine which elements in the strided + arrays are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use a + typed array view. + + If `M <= 0` or `N <= 0`, the function returns the output array unchanged. + + Parameters + ---------- + order: string + Row-major or column-major storage layout. + + mode: integer + Mode indicating whether to generate increasing (`1`) or decreasing + (`-1`) powers. + + M: integer + Number of rows. + + N: integer + Number of columns. + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length for `x`. + + out: Array|TypedArray + Output array. + + LDO: integer + Stride length for the leading dimension of `out`. + + Returns + ------- + out: Array|TypedArray + Output array. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, 2.0, 3.0 ]; + > var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}( 'row-major', 1, 3, 3, x, 1, out, 3 ) + [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] + + // Decreasing mode: + > x = [ 1.0, 2.0, 3.0 ]; + > out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}( 'row-major', -1, 3, 3, x, 1, out, 3 ) + [ 1.0, 1.0, 1.0, 4.0, 2.0, 1.0, 9.0, 3.0, 1.0 ] + + +{{alias}}.ndarray( mode, M, N, x, strideX, offsetX, out, so1, so2, oo ) + Generates a Vandermonde matrix using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on + starting indices. + + Parameters + ---------- + mode: integer + Mode indicating whether to generate increasing (`1`) or decreasing + (`-1`) powers. + + M: integer + Number of rows. + + N: integer + Number of columns. + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length for `x`. + + offsetX: integer + Starting index for `x`. + + out: Array|TypedArray + Output array. + + so1: integer + Stride length for the first dimension of `out`. + + so2: integer + Stride length for the second dimension of `out`. + + oo: integer + Starting index for `out`. + + Returns + ------- + out: Array|TypedArray + Output array. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, 2.0, 3.0 ]; + > var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( 1, 3, 3, x, 1, 0, out, 3, 1, 0 ) + [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] + + // Advanced indexing: + > x = [ 0.0, 1.0, 0.0, 2.0, 0.0, 3.0 ]; + > out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( 1, 3, 3, x, 2, 1, out, 3, 1, 0 ) + [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/types/index.d.ts new file mode 100644 index 000000000000..c3cefd919469 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/types/index.d.ts @@ -0,0 +1,119 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Layout } from '@stdlib/types/blas'; +import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Output array. +*/ +type OutputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Interface describing `gvander`. +*/ +interface Routine { + /** + * Generates a Vandermonde matrix. + * + * @param order - storage layout + * @param mode - mode indicating whether to generate increasing or decreasing powers + * @param M - number of rows + * @param N - number of columns + * @param x - input array + * @param strideX - stride length for `x` + * @param out - output array + * @param LDO - stride length for the leading dimension of `out` + * @returns output array + * + * @example + * var x = [ 1.0, 2.0, 3.0 ]; + * var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + * + * gvander( 'row-major', 1, 3, 3, x, 1, out, 3 ); + * // out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] + */ + ( order: Layout, mode: number, M: number, N: number, x: InputArray, strideX: number, out: T, LDO: number ): T; + + /** + * Generates a Vandermonde matrix using alternative indexing semantics. + * + * @param mode - mode indicating whether to generate increasing or decreasing powers + * @param M - number of rows + * @param N - number of columns + * @param x - input array + * @param strideX - stride length for `x` + * @param offsetX - starting index for `x` + * @param out - output array + * @param strideOut1 - stride length for the first dimension of `out` + * @param strideOut2 - stride length for the second dimension of `out` + * @param offsetOut - starting index for `out` + * @returns output array + * + * @example + * var x = [ 1.0, 2.0, 3.0 ]; + * var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + * + * gvander.ndarray( 1, 3, 3, x, 1, 0, out, 3, 1, 0 ); + * // out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] + */ + ndarray( mode: number, M: number, N: number, x: InputArray, strideX: number, offsetX: number, out: T, strideOut1: number, strideOut2: number, offsetOut: number ): T; +} + +/** +* Generates a Vandermonde matrix. +* +* @param order - storage layout +* @param mode - mode indicating whether to generate increasing or decreasing powers +* @param M - number of rows +* @param N - number of columns +* @param x - input array +* @param strideX - stride length for `x` +* @param out - output array +* @param LDO - stride length for the leading dimension of `out` +* @returns output array +* +* @example +* var x = [ 1.0, 2.0, 3.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gvander( 'row-major', 1, 3, 3, x, 1, out, 3 ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] +* +* @example +* var x = [ 1.0, 2.0, 3.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gvander.ndarray( 1, 3, 3, x, 1, 0, out, 3, 1, 0 ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] +*/ +declare var gvander: Routine; + + +// EXPORTS // + +export = gvander; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/types/test.ts new file mode 100644 index 000000000000..70e940864733 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/types/test.ts @@ -0,0 +1,341 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import AccessorArray = require( '@stdlib/array/base/accessor' ); +import gvander = require( './index' ); + + +// TESTS // + +// The function returns a numeric array... +{ + const x = new Float64Array( 10 ); + const out = new Float64Array( 30 ); + + gvander( 'row-major', 1, 10, 3, x, 1, out, 3 ); // $ExpectType Float64Array + gvander( 'row-major', 1, 10, 3, new AccessorArray( x ), 1, new AccessorArray( out ), 3 ); // $ExpectType AccessorArray +} + +// The compiler throws an error if the function is provided a first argument which is not a valid order... +{ + const x = new Float64Array( 10 ); + const out = new Float64Array( 30 ); + + gvander( '10', 1, 10, 3, x, 1, out, 3 ); // $ExpectError + gvander( true, 1, 10, 3, x, 1, out, 3 ); // $ExpectError + gvander( false, 1, 10, 3, x, 1, out, 3 ); // $ExpectError + gvander( null, 1, 10, 3, x, 1, out, 3 ); // $ExpectError + gvander( undefined, 1, 10, 3, x, 1, out, 3 ); // $ExpectError + gvander( [], 1, 10, 3, x, 1, out, 3 ); // $ExpectError + gvander( {}, 1, 10, 3, x, 1, out, 3 ); // $ExpectError + gvander( ( x: number ): number => x, 1, 10, 3, x, 1, out, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + const out = new Float64Array( 30 ); + + gvander( 'row-major', '10', 10, 3, x, 1, out, 3 ); // $ExpectError + gvander( 'row-major', true, 10, 3, x, 1, out, 3 ); // $ExpectError + gvander( 'row-major', false, 10, 3, x, 1, out, 3 ); // $ExpectError + gvander( 'row-major', null, 10, 3, x, 1, out, 3 ); // $ExpectError + gvander( 'row-major', undefined, 10, 3, x, 1, out, 3 ); // $ExpectError + gvander( 'row-major', [], 10, 3, x, 1, out, 3 ); // $ExpectError + gvander( 'row-major', {}, 10, 3, x, 1, out, 3 ); // $ExpectError + gvander( 'row-major', ( x: number ): number => x, 10, 3, x, 1, out, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + const out = new Float64Array( 30 ); + + gvander( 'row-major', 1, '10', 3, x, 1, out, 3 ); // $ExpectError + gvander( 'row-major', 1, true, 3, x, 1, out, 3 ); // $ExpectError + gvander( 'row-major', 1, false, 3, x, 1, out, 3 ); // $ExpectError + gvander( 'row-major', 1, null, 3, x, 1, out, 3 ); // $ExpectError + gvander( 'row-major', 1, undefined, 3, x, 1, out, 3 ); // $ExpectError + gvander( 'row-major', 1, [], 3, x, 1, out, 3 ); // $ExpectError + gvander( 'row-major', 1, {}, 3, x, 1, out, 3 ); // $ExpectError + gvander( 'row-major', 1, ( x: number ): number => x, 3, x, 1, out, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const out = new Float64Array( 30 ); + + gvander( 'row-major', 1, 10, '10', x, 1, out, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, true, x, 1, out, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, false, x, 1, out, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, null, x, 1, out, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, undefined, x, 1, out, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, [], x, 1, out, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, {}, x, 1, out, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, ( x: number ): number => x, x, 1, out, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a numeric array... +{ + const out = new Float64Array( 30 ); + + gvander( 'row-major', 1, 10, 3, '10', 1, out, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, 3, true, 1, out, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, 3, false, 1, out, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, 3, null, 1, out, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, 3, undefined, 1, out, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, 3, [ '1' ], 1, out, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, 3, {}, 1, out, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, 3, ( x: number ): number => x, 1, out, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const out = new Float64Array( 30 ); + + gvander( 'row-major', 1, 10, 3, x, '10', out, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x, true, out, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x, false, out, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x, null, out, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x, undefined, out, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x, [], out, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x, {}, out, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x, ( x: number ): number => x, out, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + gvander( 'row-major', 1, 10, 3, x, 1, '10', 3 ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x, 1, true, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x, 1, false, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x, 1, null, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x, 1, undefined, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x, 1, [ '1' ], 3 ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x, 1, {}, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x, 1, ( x: number ): number => x, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eighth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const out = new Float64Array( 30 ); + + gvander( 'row-major', 1, 10, 3, x, 1, out, '10' ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x, 1, out, true ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x, 1, out, false ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x, 1, out, null ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x, 1, out, undefined ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x, 1, out, [] ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x, 1, out, {} ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x, 1, out, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + const out = new Float64Array( 30 ); + + gvander(); // $ExpectError + gvander( 'row-major' ); // $ExpectError + gvander( 'row-major', 1 ); // $ExpectError + gvander( 'row-major', 1, 10 ); // $ExpectError + gvander( 'row-major', 1, 10, 3 ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x, 1 ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x, 1, out ); // $ExpectError + gvander( 'row-major', 1, 10, 3, x, 1, out, 3, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a numeric array... +{ + const x = new Float64Array( 10 ); + const out = new Float64Array( 30 ); + + gvander.ndarray( 1, 10, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectType Float64Array + gvander.ndarray( 1, 10, 3, new AccessorArray( x ), 1, 0, new AccessorArray( out ), 3, 1, 0 ); // $ExpectType AccessorArray +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + const out = new Float64Array( 30 ); + + gvander.ndarray( '10', 10, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( true, 10, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( false, 10, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( null, 10, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( undefined, 10, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( [], 10, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( {}, 10, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( ( x: number ): number => x, 10, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + const out = new Float64Array( 30 ); + + gvander.ndarray( 1, '10', 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, true, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, false, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, null, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, undefined, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, [], 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, {}, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, ( x: number ): number => x, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + const out = new Float64Array( 30 ); + + gvander.ndarray( 1, 10, '10', x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, true, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, false, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, null, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, undefined, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, [], x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, {}, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, ( x: number ): number => x, x, 1, 0, out, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a numeric array... +{ + const out = new Float64Array( 30 ); + + gvander.ndarray( 1, 10, 3, '10', 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, true, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, false, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, null, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, undefined, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, [ '1' ], 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, {}, 1, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, ( x: number ): number => x, 1, 0, out, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const out = new Float64Array( 30 ); + + gvander.ndarray( 1, 10, 3, x, '10', 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, true, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, false, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, null, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, undefined, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, [], 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, {}, 0, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, ( x: number ): number => x, 0, out, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const out = new Float64Array( 30 ); + + gvander.ndarray( 1, 10, 3, x, 1, '10', out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, true, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, false, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, null, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, undefined, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, [], out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, {}, out, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, ( x: number ): number => x, out, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + gvander.ndarray( 1, 10, 3, x, 1, 0, '10', 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, true, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, false, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, null, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, undefined, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, [ '1' ], 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, {}, 3, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, ( x: number ): number => x, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const out = new Float64Array( 30 ); + + gvander.ndarray( 1, 10, 3, x, 1, 0, out, '10', 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out, true, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out, false, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out, null, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out, undefined, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out, [], 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out, {}, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a ninth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const out = new Float64Array( 30 ); + + gvander.ndarray( 1, 10, 3, x, 1, 0, out, 3, '10', 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out, 3, true, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out, 3, false, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out, 3, null, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out, 3, undefined, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out, 3, [], 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out, 3, {}, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out, 3, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a tenth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const out = new Float64Array( 30 ); + + gvander.ndarray( 1, 10, 3, x, 1, 0, out, 3, 1, '10' ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out, 3, 1, true ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out, 3, 1, false ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out, 3, 1, null ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out, 3, 1, undefined ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out, 3, 1, [] ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out, 3, 1, {} ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out, 3, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + const out = new Float64Array( 30 ); + + gvander.ndarray(); // $ExpectError + gvander.ndarray( 1 ); // $ExpectError + gvander.ndarray( 1, 10 ); // $ExpectError + gvander.ndarray( 1, 10, 3 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out, 3 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out, 3, 1 ); // $ExpectError + gvander.ndarray( 1, 10, 3, x, 1, 0, out, 3, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/examples/index.js new file mode 100644 index 000000000000..e7115e5918d3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/examples/index.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var zeros = require( '@stdlib/array/zeros' ); +var gvander = require( './../lib' ); + +var M = 3; +var N = 4; + +var x = discreteUniform( M, 0, 10, { + 'dtype': 'generic' +}); +var out = zeros( M*N, 'generic' ); +console.log( x ); + +gvander( 'row-major', -1, M, N, x, 1, out, N ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js new file mode 100644 index 000000000000..3098272a24df --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js @@ -0,0 +1,135 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); + + +// MAIN // + +/** +* Generates a Vandermonde matrix using accessor arrays. +* +* @private +* @param {integer} mode - mode indicating whether to generate increasing or decreasing powers +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @param {Object} x - input array object +* @param {integer} sx - stride length for `x` +* @param {NonNegativeInteger} ox - starting index for `x` +* @param {Object} out - output array object +* @param {integer} so1 - stride length for the first dimension of `out` +* @param {integer} so2 - stride length for the second dimension of `out` +* @param {NonNegativeInteger} oo - starting index for `out` +* @returns {Collection} output array +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = [ 1.0, 2.0, 3.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gvander( 1, 3, 3, arraylike2object( toAccessorArray( x ) ), 1, 0, arraylike2object( toAccessorArray( out ) ), 3, 1, 0 ); +* +* console.log( out ); +* // => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] +*/ +function gvander( mode, M, N, x, sx, ox, out, so1, so2, oo ) { + var xget; + var oget; + var oset; + var ix; + var io; + var v; + var i; + var j; + + xget = x.accessors[ 0 ]; + oget = out.accessors[ 0 ]; + oset = out.accessors[ 1 ]; + + if ( isRowMajor( [ so1, so2 ] ) ) { + ix = ox; + io = oo; + if ( mode > 0 ) { + for ( i = 0; i < M; i++ ) { + v = xget( x.data, ix ); + oset( out.data, io, 1.0 ); + for ( j = 1; j < N; j++ ) { + oset( out.data, io + (j*so2), oget( out.data, io + ((j-1)*so2) ) * v ); + } + ix += sx; + io += so1; + } + } else { + for ( i = 0; i < M; i++ ) { + v = xget( x.data, ix ); + oset( out.data, io + ((N-1)*so2), 1.0 ); + for ( j = N - 2; j >= 0; j-- ) { + oset( out.data, io + (j*so2), oget( out.data, io + ((j+1)*so2) ) * v ); + } + ix += sx; + io += so1; + } + } + } else if ( mode > 0 ) { + // Column-major, increasing: fill column 0 with 1s... + io = oo; + for ( i = 0; i < M; i++ ) { + oset( out.data, io, 1.0 ); + io += so1; + } + // Fill remaining columns by multiplying previous column by x... + for ( j = 1; j < N; j++ ) { + ix = ox; + io = oo + ( j * so2 ); + for ( i = 0; i < M; i++ ) { + oset( out.data, io, oget( out.data, io - so2 ) * xget( x.data, ix ) ); + ix += sx; + io += so1; + } + } + } else { + // Column-major, decreasing: fill column N-1 with 1s... + io = oo + ( (N-1) * so2 ); + for ( i = 0; i < M; i++ ) { + oset( out.data, io, 1.0 ); + io += so1; + } + // Fill remaining columns by multiplying next column by x... + for ( j = N - 2; j >= 0; j-- ) { + ix = ox; + io = oo + ( j * so2 ); + for ( i = 0; i < M; i++ ) { + oset( out.data, io, oget( out.data, io + so2 ) * xget( x.data, ix ) ); + ix += sx; + io += so1; + } + } + } + return out.data; +} + + +// EXPORTS // + +module.exports = gvander; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/index.js new file mode 100644 index 000000000000..d1690184dc46 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/index.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Generate a Vandermonde matrix. +* +* @module @stdlib/blas/ext/base/gvander +* +* @example +* var gvander = require( '@stdlib/blas/ext/base/gvander' ); +* +* var x = [ 1.0, 2.0, 3.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gvander( 'row-major', 1, 3, 3, x, 1, out, 3 ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] +* +* @example +* var gvander = require( '@stdlib/blas/ext/base/gvander' ); +* +* var x = [ 1.0, 2.0, 3.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gvander.ndarray( 1, 3, 3, x, 1, 0, out, 3, 1, 0 ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/main.js new file mode 100644 index 000000000000..a57086dc64d2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/main.js @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Generates a Vandermonde matrix. +* +* @param {string} order - storage layout +* @param {integer} mode - mode indicating whether to generate increasing or decreasing powers +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @param {Collection} x - input array +* @param {integer} strideX - stride length for `x` +* @param {Collection} out - output array +* @param {PositiveInteger} LDO - stride length for leading dimension of `out` +* @returns {Collection} output array +* +* @example +* var x = [ 1.0, 2.0, 3.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gvander( 'row-major', 1, 3, 3, x, 1, out, 3 ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] +*/ +function gvander( order, mode, M, N, x, strideX, out, LDO ) { + var sa1; + var sa2; + var ox; + + ox = stride2offset( M, strideX ); + if ( isColumnMajor( order ) ) { + sa1 = 1; + sa2 = LDO; + } else { // order === 'row-major' + sa1 = LDO; + sa2 = 1; + } + return ndarray( mode, M, N, x, strideX, ox, out, sa1, sa2, 0 ); +} + + +// EXPORTS // + +module.exports = gvander; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/ndarray.js new file mode 100644 index 000000000000..e7d0034137c2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/ndarray.js @@ -0,0 +1,151 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len */ + +'use strict'; + +// MODULES // + +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); +var gfill = require( '@stdlib/blas/ext/base/gfill' ).ndarray; +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Generates a Vandermonde matrix using alternative indexing semantics. +* +* @param {integer} mode - mode indicating whether to generate increasing or decreasing powers +* @param {NonNegativeInteger} M - number of rows in the matrix `Out` +* @param {NonNegativeInteger} N - number of columns in the matrix `Out` +* @param {Collection} x - input vector +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Collection} out - output matrix +* @param {integer} strideOut1 - stride length for the first dimension of `out` +* @param {integer} strideOut2 - stride length for the second dimension of `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @returns {Collection} output matrix +* +* @example +* var x = [ 1.0, 2.0, 3.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gvander( 1, 3, 3, x, 1, 0, out, 3, 1, 0 ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] +*/ +function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) { + var xobj; + var oobj; + var do0; + var do1; + var rm; + var S0; + var S1; + var sx; + var io; + var ix; + var i0; + var i1; + + if ( M <= 0 || N <= 0 ) { + return out; + } + xobj = arraylike2object( x ); + oobj = arraylike2object( out ); + if ( xobj.accessorProtocol || oobj.accessorProtocol ) { + return accessors( mode, M, N, xobj, strideX, offsetX, oobj, strideOut1, strideOut2, offsetOut ); + } + + // Note on variable naming convention: S#, do#, io, i# where # corresponds to the loop number, with `0` being the innermost loop... + rm = isRowMajor( [ strideOut1, strideOut2 ] ); + + // Extract loop variables for loop interchange... + if ( rm ) { + S0 = N; + S1 = M; + do0 = strideOut2; // offset increment for innermost loop + do1 = strideOut1 - ( S0*strideOut2 ); // offset increment for outermost loop + } else { // order === 'column-major' + S0 = M; + S1 = N; + do0 = strideOut1; // offset increment for innermost loop + do1 = strideOut2 - ( S0*strideOut1 ); // offset increment for outermost loop + } + sx = strideX; + io = offsetOut; + + // For a Vandermonde matrix, each row `i` contains powers of `x[i]`: + if ( rm ) { + ix = offsetX; + for ( i1 = 0; i1 < S1; i1++ ) { + if ( mode > 0 ) { + // Increasing: x^0, x^1, ..., x^(N-1) + out[ io ] = 1.0; + io += do0; + for ( i0 = 1; i0 < S0; i0++ ) { + out[ io ] = out[ io - do0 ] * x[ ix ]; + io += do0; + } + } else { + // Decreasing: x^(N-1), x^(N-2), ..., x^0 + out[ io + ( ( S0-1 ) * do0 ) ] = 1.0; + for ( i0 = S0 - 2; i0 >= 0; i0-- ) { + out[ io + ( i0*do0 ) ] = out[ io + ( (i0+1)*do0 ) ] * x[ ix ]; + } + io += S0 * do0; + } + ix += sx; + io += do1; + } + } else if ( mode > 0 ) { + // Increasing: column j contains x^j + gfill( S0, 1.0, out, do0, io ); + io += ( S0 * do0 ) + do1; + for ( i1 = 1; i1 < S1; i1++ ) { + ix = offsetX; + for ( i0 = 0; i0 < S0; i0++ ) { + out[ io ] = out[ io - strideOut2 ] * x[ ix ]; + ix += sx; + io += do0; + } + io += do1; + } + } else { + // Decreasing: column 0 contains x^(N-1), last column all ones + gfill( S0, 1.0, out, do0, offsetOut + ( ( S1-1 ) * strideOut2 ) ); + for ( i1 = S1 - 2; i1 >= 0; i1-- ) { + io = offsetOut + ( i1 * strideOut2 ); + ix = offsetX; + for ( i0 = 0; i0 < S0; i0++ ) { + out[ io ] = out[ io + strideOut2 ] * x[ ix ]; + ix += sx; + io += do0; + } + } + } + return out; +} + + +// EXPORTS // + +module.exports = gvander; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/package.json b/lib/node_modules/@stdlib/blas/ext/base/gvander/package.json new file mode 100644 index 000000000000..3ce0d0088cad --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/blas/ext/base/gvander", + "version": "0.0.0", + "description": "Generate a Vandermonde matrix.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "extended", + "vandermonde", + "matrix", + "generate", + "strided", + "strided array", + "typed", + "array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.js new file mode 100644 index 000000000000..e601d310a933 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var gvander = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gvander, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof gvander.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.main.js new file mode 100644 index 000000000000..03e22fcc3834 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.main.js @@ -0,0 +1,528 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var gvander = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gvander, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 8', function test( t ) { + t.strictEqual( gvander.length, 8, 'has expected arity' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (row-major, decreasing)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 'row-major', -1, 3, 3, x, 1, out, 3 ); + + expected = [ 1.0, 1.0, 1.0, 4.0, 2.0, 1.0, 9.0, 3.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (row-major, decreasing, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 'row-major', -1, 3, 3, toAccessorArray( x ), 1, toAccessorArray( out ), 3 ); + + expected = [ 1.0, 1.0, 1.0, 4.0, 2.0, 1.0, 9.0, 3.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (row-major, increasing)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 'row-major', 1, 3, 3, x, 1, out, 3 ); + + expected = [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (row-major, increasing, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 'row-major', 1, 3, 3, toAccessorArray( x ), 1, toAccessorArray( out ), 3 ); + + expected = [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (column-major, decreasing)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 'column-major', -1, 3, 3, x, 1, out, 3 ); + + expected = [ 1.0, 4.0, 9.0, 1.0, 2.0, 3.0, 1.0, 1.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (column-major, decreasing, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 'column-major', -1, 3, 3, toAccessorArray( x ), 1, toAccessorArray( out ), 3 ); + + expected = [ 1.0, 4.0, 9.0, 1.0, 2.0, 3.0, 1.0, 1.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (column-major, increasing)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 'column-major', 1, 3, 3, x, 1, out, 3 ); + + expected = [ 1.0, 1.0, 1.0, 1.0, 2.0, 3.0, 1.0, 4.0, 9.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (column-major, increasing, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 'column-major', 1, 3, 3, toAccessorArray( x ), 1, toAccessorArray( out ), 3 ); + + expected = [ 1.0, 1.0, 1.0, 1.0, 2.0, 3.0, 1.0, 4.0, 9.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the output array', function test( t ) { + var out; + var x; + var v; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + + v = gvander( 'row-major', -1, 2, 2, x, 1, out, 2 ); + + t.strictEqual( v, out, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the output array (accessors)', function test( t ) { + var out; + var x; + var v; + + x = toAccessorArray( [ 1.0, 2.0 ] ); + out = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0 ] ); + + v = gvander( 'row-major', -1, 2, 2, x, 1, out, 2 ); + + t.strictEqual( v, out, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a stride (row-major)', function test( t ) { + var expected; + var out; + var x; + + // Pick every other element: x[0]=1.0, x[2]=3.0 + x = [ 1.0, 0.0, 3.0, 0.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 'row-major', -1, 2, 3, x, 2, out, 3 ); + + expected = [ 1.0, 1.0, 1.0, 9.0, 3.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a stride (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 0.0, 3.0, 0.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 'row-major', -1, 2, 3, toAccessorArray( x ), 2, toAccessorArray( out ), 3 ); + + expected = [ 1.0, 1.0, 1.0, 9.0, 3.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride (row-major)', function test( t ) { + var expected; + var out; + var x; + + // Negative stride: starts from last and goes backward + x = [ 3.0, 0.0, 1.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 'row-major', -1, 2, 3, x, -2, out, 3 ); + + // x[2]=1.0 (first), x[0]=3.0 (second) + expected = [ 1.0, 1.0, 1.0, 9.0, 3.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a stride (column-major)', function test( t ) { + var expected; + var out; + var x; + + // Pick every other element: x[0]=1.0, x[2]=3.0 + x = [ 1.0, 0.0, 3.0, 0.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 'column-major', -1, 2, 3, x, 2, out, 2 ); + + expected = [ 1.0, 9.0, 1.0, 3.0, 1.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a stride (column-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 0.0, 3.0, 0.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 'column-major', -1, 2, 3, toAccessorArray( x ), 2, toAccessorArray( out ), 2 ); + + expected = [ 1.0, 9.0, 1.0, 3.0, 1.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride (column-major)', function test( t ) { + var expected; + var out; + var x; + + // Negative stride: starts from last and goes backward + x = [ 3.0, 0.0, 1.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 'column-major', -1, 2, 3, x, -2, out, 2 ); + + // x[2]=1.0 (first), x[0]=3.0 (second) + expected = [ 1.0, 9.0, 1.0, 3.0, 1.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `LDO` larger than the matrix dimension (row-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + // 2x3 row-major with LDO=5 (padding of 2 per row) + gvander( 'row-major', -1, 2, 3, x, 1, out, 5 ); + + expected = [ + 1.0, + 1.0, + 1.0, + 0.0, + 0.0, + 4.0, + 2.0, + 1.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `LDO` larger than the matrix dimension (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 'row-major', -1, 2, 3, toAccessorArray( x ), 1, toAccessorArray( out ), 5 ); + + expected = [ + 1.0, + 1.0, + 1.0, + 0.0, + 0.0, + 4.0, + 2.0, + 1.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `LDO` larger than the matrix dimension (column-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + // 2x3 column-major with LDO=4 (padding of 2 per column) + gvander( 'column-major', -1, 2, 3, x, 1, out, 4 ); + + expected = [ + 1.0, + 4.0, + 0.0, + 0.0, + 1.0, + 2.0, + 0.0, + 0.0, + 1.0, + 1.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `LDO` larger than the matrix dimension (column-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 'column-major', -1, 2, 3, toAccessorArray( x ), 1, toAccessorArray( out ), 4 ); + + expected = [ + 1.0, + 4.0, + 0.0, + 0.0, + 1.0, + 2.0, + 0.0, + 0.0, + 1.0, + 1.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports non-square matrices (M > N, row-major, decreasing)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 'row-major', -1, 3, 2, x, 1, out, 2 ); + + // 3x2 matrix, decreasing: + expected = [ 1.0, 1.0, 2.0, 1.0, 3.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports non-square matrices (M < N, row-major, increasing)', function test( t ) { + var expected; + var out; + var x; + + x = [ 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 'row-major', 1, 2, 4, x, 1, out, 4 ); + + // 2x4 matrix, increasing: + expected = [ 1.0, 2.0, 4.0, 8.0, 1.0, 3.0, 9.0, 27.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var expected; + var out; + var x0; + var x1; + + // Initial array: + x0 = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] ); + + // Create an offset view: + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + + out = new Float64Array( 9 ); + + gvander( 'row-major', 1, 3, 3, x1, 1, out, 3 ); + + expected = new Float64Array([ + 1.0, + 1.0, + 1.0, + 1.0, + 2.0, + 4.0, + 1.0, + 3.0, + 9.0 + ]); + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles zero values in the input array (row-major, increasing)', function test( t ) { + var expected; + var out; + var x; + + x = [ 0.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 'row-major', 1, 2, 3, x, 1, out, 3 ); + + expected = [ 1.0, 0.0, 0.0, 1.0, 2.0, 4.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles single column (N=1)', function test( t ) { + var expected; + var out; + var x; + + x = [ 5.0, 10.0, 15.0 ]; + out = [ 0.0, 0.0, 0.0 ]; + + gvander( 'row-major', 1, 3, 1, x, 1, out, 1 ); + + // Single column: all x^0 = 1 + expected = [ 1.0, 1.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles single row (M=1)', function test( t ) { + var expected; + var out; + var x; + + x = [ 3.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 'row-major', 1, 1, 4, x, 1, out, 4 ); + + // Single row: [ 3^0, 3^1, 3^2, 3^3 ] = [ 1, 3, 9, 27 ] + expected = [ 1.0, 3.0, 9.0, 27.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.ndarray.js new file mode 100644 index 000000000000..7cc7f5d5d541 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.ndarray.js @@ -0,0 +1,633 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var gvander = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gvander, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 10', function test( t ) { + t.strictEqual( gvander.length, 10, 'has expected arity' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (row-major, decreasing)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( -1, 3, 3, x, 1, 0, out, 3, 1, 0 ); + + expected = [ 1.0, 1.0, 1.0, 4.0, 2.0, 1.0, 9.0, 3.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (row-major, decreasing, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( -1, 3, 3, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 3, 1, 0 ); // eslint-disable-line max-len + + expected = [ 1.0, 1.0, 1.0, 4.0, 2.0, 1.0, 9.0, 3.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (row-major, increasing)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 1, 3, 3, x, 1, 0, out, 3, 1, 0 ); + + expected = [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (row-major, increasing, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 1, 3, 3, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 3, 1, 0 ); // eslint-disable-line max-len + + expected = [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (column-major, decreasing)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( -1, 3, 3, x, 1, 0, out, 1, 3, 0 ); + + expected = [ 1.0, 4.0, 9.0, 1.0, 2.0, 3.0, 1.0, 1.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (column-major, decreasing, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( -1, 3, 3, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 1, 3, 0 ); // eslint-disable-line max-len + + expected = [ 1.0, 4.0, 9.0, 1.0, 2.0, 3.0, 1.0, 1.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (column-major, increasing)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 1, 3, 3, x, 1, 0, out, 1, 3, 0 ); + + expected = [ 1.0, 1.0, 1.0, 1.0, 2.0, 3.0, 1.0, 4.0, 9.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (column-major, increasing, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 1, 3, 3, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 1, 3, 0 ); // eslint-disable-line max-len + + expected = [ 1.0, 1.0, 1.0, 1.0, 2.0, 3.0, 1.0, 4.0, 9.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the output array', function test( t ) { + var out; + var x; + var v; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + + v = gvander( -1, 2, 2, x, 1, 0, out, 2, 1, 0 ); + + t.strictEqual( v, out, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the output array (accessors)', function test( t ) { + var out; + var x; + var v; + + x = toAccessorArray( [ 1.0, 2.0 ] ); + out = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0 ] ); + + v = gvander( -1, 2, 2, x, 1, 0, out, 2, 1, 0 ); + + t.strictEqual( v, out, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `M` equal to `0`, the function early returns', function test( t ) { + var out; + var x; + + x = []; + out = []; + + gvander( -1, 0, 3, x, 1, 0, out, 3, 1, 0 ); + + t.deepEqual( out, [], 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` equal to `0`, the function early returns', function test( t ) { + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = []; + + gvander( -1, 2, 0, x, 1, 0, out, 0, 1, 0 ); + + t.deepEqual( out, [], 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a stride (row-major)', function test( t ) { + var expected; + var out; + var x; + + // Pick every other element: x[0]=1.0, x[2]=3.0 + x = [ 1.0, 0.0, 3.0, 0.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( -1, 2, 3, x, 2, 0, out, 3, 1, 0 ); + + expected = [ 1.0, 1.0, 1.0, 9.0, 3.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a stride (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 0.0, 3.0, 0.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( -1, 2, 3, toAccessorArray( x ), 2, 0, toAccessorArray( out ), 3, 1, 0 ); // eslint-disable-line max-len + + expected = [ 1.0, 1.0, 1.0, 9.0, 3.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride (row-major)', function test( t ) { + var expected; + var out; + var x; + + // Negative stride: starts from last and goes backward + x = [ 3.0, 0.0, 1.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( -1, 2, 3, x, -2, 2, out, 3, 1, 0 ); + + // x[2]=1.0 (first), x[0]=3.0 (second) + expected = [ 1.0, 1.0, 1.0, 9.0, 3.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a stride (column-major)', function test( t ) { + var expected; + var out; + var x; + + // Pick every other element: x[0]=1.0, x[2]=3.0 + x = [ 1.0, 0.0, 3.0, 0.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( -1, 2, 3, x, 2, 0, out, 1, 2, 0 ); + + expected = [ 1.0, 9.0, 1.0, 3.0, 1.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a stride (column-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 0.0, 3.0, 0.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( -1, 2, 3, toAccessorArray( x ), 2, 0, toAccessorArray( out ), 1, 2, 0 ); // eslint-disable-line max-len + + expected = [ 1.0, 9.0, 1.0, 3.0, 1.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride (column-major)', function test( t ) { + var expected; + var out; + var x; + + // Negative stride: starts from last and goes backward + x = [ 3.0, 0.0, 1.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( -1, 2, 3, x, -2, 2, out, 1, 2, 0 ); + + // x[2]=1.0 (first), x[0]=3.0 (second) + expected = [ 1.0, 9.0, 1.0, 3.0, 1.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` offset', function test( t ) { + var expected; + var out; + var x; + + x = [ + 0.0, + 1.0, // 0 + 2.0, // 1 + 3.0 // 2 + ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 1, 3, 3, x, 1, 1, out, 3, 1, 0 ); + + expected = [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` offset (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ + 0.0, + 1.0, // 0 + 2.0, // 1 + 3.0 // 2 + ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 1, 3, 3, toAccessorArray( x ), 1, 1, toAccessorArray( out ), 3, 1, 0 ); // eslint-disable-line max-len + + expected = [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an output offset', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 1, 2, 2, x, 1, 0, out, 2, 1, 2 ); + + expected = [ 0.0, 0.0, 1.0, 1.0, 1.0, 2.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an output offset (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 1, 2, 2, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 2, 1, 2 ); // eslint-disable-line max-len + + expected = [ 0.0, 0.0, 1.0, 1.0, 1.0, 2.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports output stride with padding (row-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + // 2x3 row-major with strideOut1=5 (padding of 2 per row) + gvander( -1, 2, 3, x, 1, 0, out, 5, 1, 0 ); + + expected = [ + 1.0, + 1.0, + 1.0, + 0.0, + 0.0, + 4.0, + 2.0, + 1.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports output stride with padding (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( -1, 2, 3, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 5, 1, 0 ); // eslint-disable-line max-len + + expected = [ + 1.0, + 1.0, + 1.0, + 0.0, + 0.0, + 4.0, + 2.0, + 1.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports output stride with padding (column-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + // 2x3 column-major with strideOut2=4 (padding of 2 per column) + gvander( -1, 2, 3, x, 1, 0, out, 1, 4, 0 ); + + expected = [ + 1.0, + 4.0, + 0.0, + 0.0, + 1.0, + 2.0, + 0.0, + 0.0, + 1.0, + 1.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports output stride with padding (column-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( -1, 2, 3, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 1, 4, 0 ); // eslint-disable-line max-len + + expected = [ + 1.0, + 4.0, + 0.0, + 0.0, + 1.0, + 2.0, + 0.0, + 0.0, + 1.0, + 1.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports non-square matrices (M > N, row-major, decreasing)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( -1, 3, 2, x, 1, 0, out, 2, 1, 0 ); + + // 3x2 matrix, decreasing: + expected = [ 1.0, 1.0, 2.0, 1.0, 3.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports non-square matrices (M < N, row-major, increasing)', function test( t ) { + var expected; + var out; + var x; + + x = [ 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 1, 2, 4, x, 1, 0, out, 4, 1, 0 ); + + // 2x4 matrix, increasing: + expected = [ 1.0, 2.0, 4.0, 8.0, 1.0, 3.0, 9.0, 27.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var expected; + var out; + var x; + + x = [ + 0.0, + 2.0, // 0 + 0.0, + 3.0 // 1 + ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 1, 2, 3, x, 2, 1, out, 3, 1, 0 ); + + expected = [ 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles zero values in the input array (row-major, increasing)', function test( t ) { + var expected; + var out; + var x; + + x = [ 0.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 1, 2, 3, x, 1, 0, out, 3, 1, 0 ); + + expected = [ 1.0, 0.0, 0.0, 1.0, 2.0, 4.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles single column (N=1)', function test( t ) { + var expected; + var out; + var x; + + x = [ 5.0, 10.0, 15.0 ]; + out = [ 0.0, 0.0, 0.0 ]; + + gvander( 1, 3, 1, x, 1, 0, out, 1, 1, 0 ); + + // Single column: all x^0 = 1 + expected = [ 1.0, 1.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles single row (M=1)', function test( t ) { + var expected; + var out; + var x; + + x = [ 3.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + + gvander( 1, 1, 4, x, 1, 0, out, 4, 1, 0 ); + + // Single row: [ 3^0, 3^1, 3^2, 3^3 ] = [ 1, 3, 9, 27 ] + expected = [ 1.0, 3.0, 9.0, 27.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports column-major with output offset and stride', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + // Column-major 2x2 starting at offset 2, with strideOut2=3 (padding of 1) + gvander( 1, 2, 2, x, 1, 0, out, 1, 3, 2 ); + + expected = [ 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 2.0, 0.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); From a86243753bde069d021d5b84b43ab57d3dae065c Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 15 Mar 2026 00:21:18 +0500 Subject: [PATCH 02/32] docs: apply suggestions from code review --- .../@stdlib/blas/ext/base/gvander/README.md | 6 +++--- .../@stdlib/blas/ext/base/gvander/docs/repl.txt | 8 ++++---- .../blas/ext/base/gvander/docs/types/index.d.ts | 12 ++++++------ .../@stdlib/blas/ext/base/gvander/lib/accessors.js | 4 ++-- .../@stdlib/blas/ext/base/gvander/lib/main.js | 6 +++--- .../@stdlib/blas/ext/base/gvander/lib/ndarray.js | 10 +++++----- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md b/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md index 358432fe3022..7475c62e5e63 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md @@ -52,12 +52,12 @@ The function has the following parameters: - **order**: storage layout. - **mode**: mode indicating whether to generate increasing (`1`) or decreasing (`-1`) powers. -- **M**: number of rows. -- **N**: number of columns. +- **M**: number of rows in `out`. +- **N**: number of columns in `out`. - **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. - **strideX**: stride length for `x`. - **out**: output [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. -- **LDO**: stride length for leading dimension of `out`. +- **LDO**: stride length for the leading dimension of `out`. ```javascript diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/repl.txt index cd3882d08765..abf01f95c9c6 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/repl.txt @@ -20,10 +20,10 @@ (`-1`) powers. M: integer - Number of rows. + Number of rows in `out`. N: integer - Number of columns. + Number of columns in `out`. x: Array|TypedArray Input array. @@ -71,10 +71,10 @@ (`-1`) powers. M: integer - Number of rows. + Number of rows in `out`. N: integer - Number of columns. + Number of columns in `out`. x: Array|TypedArray Input array. diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/types/index.d.ts index c3cefd919469..9a18e9aad7d4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/types/index.d.ts @@ -42,8 +42,8 @@ interface Routine { * * @param order - storage layout * @param mode - mode indicating whether to generate increasing or decreasing powers - * @param M - number of rows - * @param N - number of columns + * @param M - number of rows in `out` + * @param N - number of columns in `out` * @param x - input array * @param strideX - stride length for `x` * @param out - output array @@ -63,8 +63,8 @@ interface Routine { * Generates a Vandermonde matrix using alternative indexing semantics. * * @param mode - mode indicating whether to generate increasing or decreasing powers - * @param M - number of rows - * @param N - number of columns + * @param M - number of rows in `out` + * @param N - number of columns in `out` * @param x - input array * @param strideX - stride length for `x` * @param offsetX - starting index for `x` @@ -89,8 +89,8 @@ interface Routine { * * @param order - storage layout * @param mode - mode indicating whether to generate increasing or decreasing powers -* @param M - number of rows -* @param N - number of columns +* @param M - number of rows in `out` +* @param N - number of columns in `out` * @param x - input array * @param strideX - stride length for `x` * @param out - output array diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js index 3098272a24df..d7950c2e45b4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js @@ -30,8 +30,8 @@ var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); * * @private * @param {integer} mode - mode indicating whether to generate increasing or decreasing powers -* @param {NonNegativeInteger} M - number of rows -* @param {NonNegativeInteger} N - number of columns +* @param {NonNegativeInteger} M - number of rows in `out` +* @param {NonNegativeInteger} N - number of columns in `out` * @param {Object} x - input array object * @param {integer} sx - stride length for `x` * @param {NonNegativeInteger} ox - starting index for `x` diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/main.js index a57086dc64d2..40c05bcccbfc 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/main.js @@ -32,12 +32,12 @@ var ndarray = require( './ndarray.js' ); * * @param {string} order - storage layout * @param {integer} mode - mode indicating whether to generate increasing or decreasing powers -* @param {NonNegativeInteger} M - number of rows -* @param {NonNegativeInteger} N - number of columns +* @param {NonNegativeInteger} M - number of rows in `out` +* @param {NonNegativeInteger} N - number of columns in `out` * @param {Collection} x - input array * @param {integer} strideX - stride length for `x` * @param {Collection} out - output array -* @param {PositiveInteger} LDO - stride length for leading dimension of `out` +* @param {PositiveInteger} LDO - stride length for the leading dimension of `out` * @returns {Collection} output array * * @example diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/ndarray.js index e7d0034137c2..5eeea4bb1ee5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/ndarray.js @@ -34,16 +34,16 @@ var accessors = require( './accessors.js' ); * Generates a Vandermonde matrix using alternative indexing semantics. * * @param {integer} mode - mode indicating whether to generate increasing or decreasing powers -* @param {NonNegativeInteger} M - number of rows in the matrix `Out` -* @param {NonNegativeInteger} N - number of columns in the matrix `Out` -* @param {Collection} x - input vector +* @param {NonNegativeInteger} M - number of rows in `out` +* @param {NonNegativeInteger} N - number of columns in `out` +* @param {Collection} x - input array * @param {integer} strideX - stride length for `x` * @param {NonNegativeInteger} offsetX - starting index for `x` -* @param {Collection} out - output matrix +* @param {Collection} out - output array * @param {integer} strideOut1 - stride length for the first dimension of `out` * @param {integer} strideOut2 - stride length for the second dimension of `out` * @param {NonNegativeInteger} offsetOut - starting index for `out` -* @returns {Collection} output matrix +* @returns {Collection} output array * * @example * var x = [ 1.0, 2.0, 3.0 ]; From 69c1162ff77c688ed3abd9844ea22db60d88a4c9 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 15 Mar 2026 21:58:34 +0500 Subject: [PATCH 03/32] 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: 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../blas/ext/base/gvander/lib/accessors.js | 2 + .../@stdlib/blas/ext/base/gvander/lib/base.js | 149 ++++++++++++ .../@stdlib/blas/ext/base/gvander/lib/main.js | 44 +++- .../blas/ext/base/gvander/lib/ndarray.js | 103 ++------ .../blas/ext/base/gvander/test/test.main.js | 222 ++++++++++++++++++ .../ext/base/gvander/test/test.ndarray.js | 128 ++++++++++ 6 files changed, 556 insertions(+), 92 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js index d7950c2e45b4..05b80f2606f4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js @@ -16,6 +16,8 @@ * limitations under the License. */ +/* eslint-disable max-len */ + 'use strict'; // MODULES // diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js new file mode 100644 index 000000000000..a77a502a2ab1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js @@ -0,0 +1,149 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len */ + +'use strict'; + +// MODULES // + +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); +var gfill = require( '@stdlib/blas/ext/base/gfill' ).ndarray; +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Generates a Vandermonde matrix using alternative indexing semantics. +* +* @private +* @param {integer} mode - mode indicating whether to generate increasing or decreasing powers +* @param {NonNegativeInteger} M - number of rows in `out` +* @param {NonNegativeInteger} N - number of columns in `out` +* @param {Collection} x - input array +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Collection} out - output array +* @param {integer} strideOut1 - stride length for the first dimension of `out` +* @param {integer} strideOut2 - stride length for the second dimension of `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @returns {Collection} output array +* +* @example +* var x = [ 1.0, 2.0, 3.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gvander( 1, 3, 3, x, 1, 0, out, 3, 1, 0 ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] +*/ +function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) { + var xobj; + var oobj; + var do0; + var do1; + var rm; + var S0; + var S1; + var sx; + var io; + var ix; + var i0; + var i1; + + xobj = arraylike2object( x ); + oobj = arraylike2object( out ); + if ( xobj.accessorProtocol || oobj.accessorProtocol ) { + return accessors( mode, M, N, xobj, strideX, offsetX, oobj, strideOut1, strideOut2, offsetOut ); + } + + // Note on variable naming convention: S#, do#, io, i# where # corresponds to the loop number, with `0` being the innermost loop... + rm = isRowMajor( [ strideOut1, strideOut2 ] ); + + // Extract loop variables for loop interchange... + if ( rm ) { + S0 = N; + S1 = M; + do0 = strideOut2; // offset increment for innermost loop + do1 = strideOut1 - ( S0*strideOut2 ); // offset increment for outermost loop + } else { // order === 'column-major' + S0 = M; + S1 = N; + do0 = strideOut1; // offset increment for innermost loop + do1 = strideOut2 - ( S0*strideOut1 ); // offset increment for outermost loop + } + sx = strideX; + io = offsetOut; + + // For a Vandermonde matrix, each row `i` contains powers of `x[i]`: + if ( rm ) { + ix = offsetX; + for ( i1 = 0; i1 < S1; i1++ ) { + if ( mode > 0 ) { + // Increasing: x^0, x^1, ..., x^(N-1) + out[ io ] = 1.0; + io += do0; + for ( i0 = 1; i0 < S0; i0++ ) { + out[ io ] = out[ io - do0 ] * x[ ix ]; + io += do0; + } + } else { + // Decreasing: x^(N-1), x^(N-2), ..., x^0 + out[ io + ( ( S0-1 ) * do0 ) ] = 1.0; + for ( i0 = S0 - 2; i0 >= 0; i0-- ) { + out[ io + ( i0*do0 ) ] = out[ io + ( (i0+1)*do0 ) ] * x[ ix ]; + } + io += S0 * do0; + } + ix += sx; + io += do1; + } + } else if ( mode > 0 ) { + // Increasing: column j contains x^j + gfill( S0, 1.0, out, do0, io ); + io += ( S0 * do0 ) + do1; + for ( i1 = 1; i1 < S1; i1++ ) { + ix = offsetX; + for ( i0 = 0; i0 < S0; i0++ ) { + out[ io ] = out[ io - strideOut2 ] * x[ ix ]; + ix += sx; + io += do0; + } + io += do1; + } + } else { + // Decreasing: column 0 contains x^(N-1), last column all ones + gfill( S0, 1.0, out, do0, offsetOut + ( ( S1-1 ) * strideOut2 ) ); + for ( i1 = S1 - 2; i1 >= 0; i1-- ) { + io = offsetOut + ( i1 * strideOut2 ); + ix = offsetX; + for ( i0 = 0; i0 < S0; i0++ ) { + out[ io ] = out[ io + strideOut2 ] * x[ ix ]; + ix += sx; + io += do0; + } + } + } + return out; +} + + +// EXPORTS // + +module.exports = gvander; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/main.js index 40c05bcccbfc..0f2f2fdab3d3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/main.js @@ -21,8 +21,11 @@ // MODULES // var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); +var isLayout = require( '@stdlib/blas/base/assert/is-layout' ); var stride2offset = require( '@stdlib/strided/base/stride2offset' ); -var ndarray = require( './ndarray.js' ); +var max = require( '@stdlib/math/base/special/fast/max' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); // MAIN // @@ -38,6 +41,11 @@ var ndarray = require( './ndarray.js' ); * @param {integer} strideX - stride length for `x` * @param {Collection} out - output array * @param {PositiveInteger} LDO - stride length for the leading dimension of `out` +* @throws {TypeError} first argument must be a valid order +* @throws {RangeError} third argument must be a nonnegative integer +* @throws {RangeError} fourth argument must be a nonnegative integer +* @throws {RangeError} sixth argument must be non-zero +* @throws {RangeError} eighth argument must be a valid stride * @returns {Collection} output array * * @example @@ -48,19 +56,49 @@ var ndarray = require( './ndarray.js' ); * // out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] */ function gvander( order, mode, M, N, x, strideX, out, LDO ) { + var iscm; var sa1; var sa2; var ox; + var k; + + if ( !isLayout( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + if ( M < 0 ) { + throw new RangeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', M ) ); + } + if ( N < 0 ) { + throw new RangeError( format( 'invalid argument. Fourth argument must be a nonnegative integer. Value: `%d`.', N ) ); + } + if ( strideX === 0 ) { + throw new RangeError( format( 'invalid argument. Sixth argument must be non-zero. Value: `%d`.', strideX ) ); + } + + iscm = isColumnMajor( order ); + if ( iscm ) { + k = M; + } else { + k = N; + } + + if ( LDO < max( 1, k ) ) { + throw new RangeError( format( 'invalid argument. Eighth argument must be greater than or equal to max(1,%d). Value: `%d`.', k, LDO ) ); + } + + if ( M === 0 || N === 0 ) { + return out; + } ox = stride2offset( M, strideX ); - if ( isColumnMajor( order ) ) { + if ( iscm ) { sa1 = 1; sa2 = LDO; } else { // order === 'row-major' sa1 = LDO; sa2 = 1; } - return ndarray( mode, M, N, x, strideX, ox, out, sa1, sa2, 0 ); + return base( mode, M, N, x, strideX, ox, out, sa1, sa2, 0 ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/ndarray.js index 5eeea4bb1ee5..fa30eacf1767 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/ndarray.js @@ -22,10 +22,8 @@ // MODULES // -var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); -var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); -var gfill = require( '@stdlib/blas/ext/base/gfill' ).ndarray; -var accessors = require( './accessors.js' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); // MAIN // @@ -43,6 +41,9 @@ var accessors = require( './accessors.js' ); * @param {integer} strideOut1 - stride length for the first dimension of `out` * @param {integer} strideOut2 - stride length for the second dimension of `out` * @param {NonNegativeInteger} offsetOut - starting index for `out` +* @throws {RangeError} second argument must be a nonnegative integer +* @throws {RangeError} third argument must be a nonnegative integer +* @throws {RangeError} fifth argument must be non-zero * @returns {Collection} output array * * @example @@ -53,96 +54,20 @@ var accessors = require( './accessors.js' ); * // out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] */ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) { - var xobj; - var oobj; - var do0; - var do1; - var rm; - var S0; - var S1; - var sx; - var io; - var ix; - var i0; - var i1; - - if ( M <= 0 || N <= 0 ) { - return out; + if ( M < 0 ) { + throw new RangeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%d`.', M ) ); } - xobj = arraylike2object( x ); - oobj = arraylike2object( out ); - if ( xobj.accessorProtocol || oobj.accessorProtocol ) { - return accessors( mode, M, N, xobj, strideX, offsetX, oobj, strideOut1, strideOut2, offsetOut ); + if ( N < 0 ) { + throw new RangeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', N ) ); } - - // Note on variable naming convention: S#, do#, io, i# where # corresponds to the loop number, with `0` being the innermost loop... - rm = isRowMajor( [ strideOut1, strideOut2 ] ); - - // Extract loop variables for loop interchange... - if ( rm ) { - S0 = N; - S1 = M; - do0 = strideOut2; // offset increment for innermost loop - do1 = strideOut1 - ( S0*strideOut2 ); // offset increment for outermost loop - } else { // order === 'column-major' - S0 = M; - S1 = N; - do0 = strideOut1; // offset increment for innermost loop - do1 = strideOut2 - ( S0*strideOut1 ); // offset increment for outermost loop + if ( strideX === 0 ) { + throw new RangeError( format( 'invalid argument. Fifth argument must be non-zero. Value: `%d`.', strideX ) ); } - sx = strideX; - io = offsetOut; - // For a Vandermonde matrix, each row `i` contains powers of `x[i]`: - if ( rm ) { - ix = offsetX; - for ( i1 = 0; i1 < S1; i1++ ) { - if ( mode > 0 ) { - // Increasing: x^0, x^1, ..., x^(N-1) - out[ io ] = 1.0; - io += do0; - for ( i0 = 1; i0 < S0; i0++ ) { - out[ io ] = out[ io - do0 ] * x[ ix ]; - io += do0; - } - } else { - // Decreasing: x^(N-1), x^(N-2), ..., x^0 - out[ io + ( ( S0-1 ) * do0 ) ] = 1.0; - for ( i0 = S0 - 2; i0 >= 0; i0-- ) { - out[ io + ( i0*do0 ) ] = out[ io + ( (i0+1)*do0 ) ] * x[ ix ]; - } - io += S0 * do0; - } - ix += sx; - io += do1; - } - } else if ( mode > 0 ) { - // Increasing: column j contains x^j - gfill( S0, 1.0, out, do0, io ); - io += ( S0 * do0 ) + do1; - for ( i1 = 1; i1 < S1; i1++ ) { - ix = offsetX; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = out[ io - strideOut2 ] * x[ ix ]; - ix += sx; - io += do0; - } - io += do1; - } - } else { - // Decreasing: column 0 contains x^(N-1), last column all ones - gfill( S0, 1.0, out, do0, offsetOut + ( ( S1-1 ) * strideOut2 ) ); - for ( i1 = S1 - 2; i1 >= 0; i1-- ) { - io = offsetOut + ( i1 * strideOut2 ); - ix = offsetX; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = out[ io + strideOut2 ] * x[ ix ]; - ix += sx; - io += do0; - } - } + if ( M === 0 || N === 0 ) { + return out; } - return out; + return base( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.main.js index 03e22fcc3834..e4956f81537b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.main.js @@ -39,6 +39,228 @@ tape( 'the function has an arity of 8', function test( t ) { t.end(); }); +tape( 'the function throws an error if provided an invalid first argument', function test( t ) { + var values; + var i; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gvander( value, -1, 3, 3, [ 1.0, 2.0, 3.0 ], 1, [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3 ); // eslint-disable-line max-len + }; + } +}); + +tape( 'the function throws an error if provided an invalid first argument (accessors)', function test( t ) { + var values; + var i; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gvander( value, -1, 3, 3, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1, toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ), 3 ); // eslint-disable-line max-len + }; + } +}); + +tape( 'the function throws an error if provided an invalid third argument', function test( t ) { + var values; + var i; + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gvander( 'row-major', -1, value, 3, [ 1.0, 2.0, 3.0 ], 1, [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3 ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid third argument (accessors)', function test( t ) { + var values; + var i; + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gvander( 'row-major', -1, value, 3, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1, toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ), 3 ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid fourth argument', function test( t ) { + var values; + var i; + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gvander( 'row-major', -1, 3, value, [ 1.0, 2.0, 3.0 ], 1, [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3 ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid fourth argument (accessors)', function test( t ) { + var values; + var i; + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gvander( 'row-major', -1, 3, value, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1, toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ), 3 ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid sixth argument', function test( t ) { + var values; + var i; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gvander( 'row-major', -1, 3, 3, [ 1.0, 2.0, 3.0 ], value, [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3 ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid sixth argument (accessors)', function test( t ) { + var values; + var i; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gvander( 'row-major', -1, 3, 3, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), value, toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ), 3 ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid eighth argument', function test( t ) { + var values; + var i; + + values = [ + -3, + -2, + -1, + 0, + 1 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gvander( 'row-major', -1, 3, 3, [ 1.0, 2.0, 3.0 ], 1, [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], value ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid eighth argument (accessors)', function test( t ) { + var values; + var i; + + values = [ + -3, + -2, + -1, + 0, + 1 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gvander( 'row-major', -1, 3, 3, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1, toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ), value ); + }; + } +}); + tape( 'the function generates a Vandermonde matrix (row-major, decreasing)', function test( t ) { var expected; var out; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.ndarray.js index 7cc7f5d5d541..c690c13679dd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.ndarray.js @@ -38,6 +38,134 @@ tape( 'the function has an arity of 10', function test( t ) { t.end(); }); +tape( 'the function throws an error if provided an invalid second argument', function test( t ) { + var values; + var i; + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gvander( -1, value, 3, [ 1.0, 2.0, 3.0 ], 1, 0, [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 1, 0 ); // eslint-disable-line max-len + }; + } +}); + +tape( 'the function throws an error if provided an invalid second argument (accessors)', function test( t ) { + var values; + var i; + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gvander( -1, value, 3, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1, 0, toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ), 3, 1, 0 ); // eslint-disable-line max-len + }; + } +}); + +tape( 'the function throws an error if provided an invalid third argument', function test( t ) { + var values; + var i; + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gvander( -1, 3, value, [ 1.0, 2.0, 3.0 ], 1, 0, [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 1, 0 ); // eslint-disable-line max-len + }; + } +}); + +tape( 'the function throws an error if provided an invalid third argument (accessors)', function test( t ) { + var values; + var i; + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gvander( -1, 3, value, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1, 0, toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ), 3, 1, 0 ); // eslint-disable-line max-len + }; + } +}); + +tape( 'the function throws an error if provided an invalid fifth argument', function test( t ) { + var values; + var i; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gvander( -1, 3, 3, [ 1.0, 2.0, 3.0 ], value, 0, [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 1, 0 ); // eslint-disable-line max-len + }; + } +}); + +tape( 'the function throws an error if provided an invalid fifth argument (accessors)', function test( t ) { + var values; + var i; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gvander( -1, 3, 3, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), value, 0, toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ), 3, 1, 0 ); // eslint-disable-line max-len + }; + } +}); + tape( 'the function generates a Vandermonde matrix (row-major, decreasing)', function test( t ) { var expected; var out; From 21d9643b424e2414b8d4799cb3a14ca2a6be7411 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Fri, 20 Mar 2026 17:11:45 +0500 Subject: [PATCH 04/32] refactor: apply suggestions from code review --- .../@stdlib/blas/ext/base/gvander/README.md | 50 ++---------- .../blas/ext/base/gvander/docs/repl.txt | 53 +++++++----- .../ext/base/gvander/docs/types/index.d.ts | 20 ++--- .../blas/ext/base/gvander/lib/accessors.js | 81 +++++++++++-------- .../@stdlib/blas/ext/base/gvander/lib/base.js | 75 +++++++++-------- .../@stdlib/blas/ext/base/gvander/lib/main.js | 22 +++-- .../blas/ext/base/gvander/lib/ndarray.js | 7 +- .../blas/ext/base/gvander/test/test.main.js | 16 ++-- .../ext/base/gvander/test/test.ndarray.js | 4 +- 9 files changed, 160 insertions(+), 168 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md b/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md index 7475c62e5e63..44ed3a496844 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md @@ -36,7 +36,7 @@ limitations under the License. var gvander = require( '@stdlib/blas/ext/base/gvander' ); ``` -#### gvander( order, mode, M, N, x, strideX, out, LDO ) +#### gvander( order, mode, M, N, x, strideX, out, ldo ) Generates a Vandermonde matrix. @@ -50,52 +50,14 @@ gvander( 'row-major', 1, 3, 3, x, 1, out, 3 ); The function has the following parameters: -- **order**: storage layout. -- **mode**: mode indicating whether to generate increasing (`1`) or decreasing (`-1`) powers. -- **M**: number of rows in `out`. +- **order**: row-major (C-style) or column-major (Fortran-style) order. +- **mode**: mode. If `mode < 0`, the function generates decreasing powers. If `mode > 0`, the function generates increasing powers. +- **M**: number of rows in `out` and number of indexed elements in `x`. - **N**: number of columns in `out`. - **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. - **strideX**: stride length for `x`. -- **out**: output [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. -- **LDO**: stride length for the leading dimension of `out`. - - -```javascript -var x = [ 1.0, 2.0, 3.0 ]; -var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - -gvander( 'row-major', -1, 3, 3, x, 1, out, 3 ); -// out => [ 1.0, 1.0, 1.0, 4.0, 2.0, 1.0, 9.0, 3.0, 1.0 ] -``` - -The `M` and `strideX` parameters determine which elements in the input array are accessed at runtime. For example, to use every other element from the input array: - -```javascript -var x = [ 1.0, 0.0, 2.0, 0.0, 3.0 ]; -var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - -gvander( 'row-major', 1, 3, 3, x, 2, out, 3 ); -// out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] -``` - -Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. - - - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); - -// Initial array: -var x0 = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] ); - -// Create an offset view: -var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - -var out = new Float64Array( 9 ); - -gvander( 'row-major', 1, 3, 3, x1, 1, out, 3 ); -// out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] -``` +- **out**: output matrix. +- **ldo**: stride of the first dimension of `out` (a.k.a., leading dimension of the matrix `out`). diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/repl.txt index abf01f95c9c6..1581d81664d9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/repl.txt @@ -1,26 +1,40 @@ -{{alias}}( order, mode, M, N, x, strideX, out, LDO ) +{{alias}}( order, mode, M, N, x, strideX, out, ldo ) Generates a Vandermonde matrix. - The `M` and stride parameters determine which elements in the strided - arrays are accessed at runtime. + When the mode is positive, the matrix is generated such that - Indexing is relative to the first index. To introduce an offset, use a - typed array view. + [ + 1 x_0^1 x_0^2 ... x_0^N + 1 x_1^1 x_1^2 ... x_1^N + ... + ] - If `M <= 0` or `N <= 0`, the function returns the output array unchanged. + with increasing powers along the rows. + + When the mode is negative, the matrix is generated such that + + [ + x_0^N ... x_0^2 x_0^1 1 + x_1^N ... x_1^2 x_1^1 1 + ... + ] + + with decreasing powers along the rows. + + If `M <= 0` or `N <= 0`, the function returns the output matrix unchanged. Parameters ---------- order: string - Row-major or column-major storage layout. + Row-major (C-style) or column-major (Fortran-style) order. mode: integer - Mode indicating whether to generate increasing (`1`) or decreasing - (`-1`) powers. + Mode. If `mode < 0`, the function generates decreasing powers. If + `mode > 0`, the function generates increasing powers. M: integer - Number of rows in `out`. + Number of rows in `out` and number of indexed elements in `x`. N: integer Number of columns in `out`. @@ -32,15 +46,16 @@ Stride length for `x`. out: Array|TypedArray - Output array. + Output matrix. - LDO: integer - Stride length for the leading dimension of `out`. + ldo: integer + Stride of the first dimension of `out` (a.k.a., leading dimension of + the matrix `out`). Returns ------- out: Array|TypedArray - Output array. + Output matrix. Examples -------- @@ -67,11 +82,11 @@ Parameters ---------- mode: integer - Mode indicating whether to generate increasing (`1`) or decreasing - (`-1`) powers. + Mode. If `mode < 0`, the function generates decreasing powers. If + `mode > 0`, the function generates increasing powers. M: integer - Number of rows in `out`. + Number of rows in `out` and number of indexed elements in `x`. N: integer Number of columns in `out`. @@ -86,7 +101,7 @@ Starting index for `x`. out: Array|TypedArray - Output array. + Output matrix. so1: integer Stride length for the first dimension of `out`. @@ -100,7 +115,7 @@ Returns ------- out: Array|TypedArray - Output array. + Output matrix. Examples -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/types/index.d.ts index 9a18e9aad7d4..4e5c3fde6b43 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/types/index.d.ts @@ -29,7 +29,7 @@ import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array type InputArray = NumericArray | Collection | AccessorArrayLike; /** -* Output array. +* Output matrix. */ type OutputArray = NumericArray | Collection | AccessorArrayLike; @@ -46,9 +46,9 @@ interface Routine { * @param N - number of columns in `out` * @param x - input array * @param strideX - stride length for `x` - * @param out - output array - * @param LDO - stride length for the leading dimension of `out` - * @returns output array + * @param out - output matrix + * @param ldo - stride of the first dimension of `out` (a.k.a., leading dimension of the matrix `out`) + * @returns output matrix * * @example * var x = [ 1.0, 2.0, 3.0 ]; @@ -57,7 +57,7 @@ interface Routine { * gvander( 'row-major', 1, 3, 3, x, 1, out, 3 ); * // out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] */ - ( order: Layout, mode: number, M: number, N: number, x: InputArray, strideX: number, out: T, LDO: number ): T; + ( order: Layout, mode: number, M: number, N: number, x: InputArray, strideX: number, out: T, ldo: number ): T; /** * Generates a Vandermonde matrix using alternative indexing semantics. @@ -68,11 +68,11 @@ interface Routine { * @param x - input array * @param strideX - stride length for `x` * @param offsetX - starting index for `x` - * @param out - output array + * @param out - output matrix * @param strideOut1 - stride length for the first dimension of `out` * @param strideOut2 - stride length for the second dimension of `out` * @param offsetOut - starting index for `out` - * @returns output array + * @returns output matrix * * @example * var x = [ 1.0, 2.0, 3.0 ]; @@ -93,9 +93,9 @@ interface Routine { * @param N - number of columns in `out` * @param x - input array * @param strideX - stride length for `x` -* @param out - output array -* @param LDO - stride length for the leading dimension of `out` -* @returns output array +* @param out - output matrix +* @param ldo - stride of the first dimension of `out` (a.k.a., leading dimension of the matrix `out`) +* @returns output matrix * * @example * var x = [ 1.0, 2.0, 3.0 ]; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js index 05b80f2606f4..6d82dcd24896 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js @@ -23,6 +23,7 @@ // MODULES // var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); +var gfill = require( '@stdlib/blas/ext/base/gfill' ).ndarray; // MAIN // @@ -37,11 +38,11 @@ var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); * @param {Object} x - input array object * @param {integer} sx - stride length for `x` * @param {NonNegativeInteger} ox - starting index for `x` -* @param {Object} out - output array object +* @param {Object} out - output matrix object * @param {integer} so1 - stride length for the first dimension of `out` * @param {integer} so2 - stride length for the second dimension of `out` * @param {NonNegativeInteger} oo - starting index for `out` -* @returns {Collection} output array +* @returns {Collection} output matrix * * @example * var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); @@ -56,79 +57,91 @@ var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); * // => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] */ function gvander( mode, M, N, x, sx, ox, out, so1, so2, oo ) { + var xbuf; + var obuf; var xget; var oget; var oset; + var isrm; + var tmp; var ix; var io; var v; var i; var j; + xbuf = x.data; + obuf = out.data; xget = x.accessors[ 0 ]; oget = out.accessors[ 0 ]; oset = out.accessors[ 1 ]; - if ( isRowMajor( [ so1, so2 ] ) ) { + isrm = isRowMajor( [ so1, so2 ] ); + + if ( isrm && mode > 0 ) { + // Row-major, increasing: x^0, x^1, ..., x^(N-1) ix = ox; io = oo; - if ( mode > 0 ) { - for ( i = 0; i < M; i++ ) { - v = xget( x.data, ix ); - oset( out.data, io, 1.0 ); - for ( j = 1; j < N; j++ ) { - oset( out.data, io + (j*so2), oget( out.data, io + ((j-1)*so2) ) * v ); - } - ix += sx; - io += so1; + for ( i = 0; i < M; i++ ) { + v = xget( xbuf, ix ); + oset( obuf, io, 1.0 ); + tmp = 1.0; + io += so2; + for ( j = 1; j < N; j++ ) { + tmp *= v; + oset( obuf, io, tmp ); + io += so2; } - } else { - for ( i = 0; i < M; i++ ) { - v = xget( x.data, ix ); - oset( out.data, io + ((N-1)*so2), 1.0 ); - for ( j = N - 2; j >= 0; j-- ) { - oset( out.data, io + (j*so2), oget( out.data, io + ((j+1)*so2) ) * v ); - } - ix += sx; - io += so1; + ix += sx; + io += so1 - ( N*so2 ); + } + } else if ( isrm ) { + // Row-major, decreasing: x^(N-1), x^(N-2), ..., x^0 + ix = ox; + io = oo + ( (N-1)*so2 ); + for ( i = 0; i < M; i++ ) { + v = xget( xbuf, ix ); + oset( obuf, io, 1.0 ); + tmp = 1.0; + io -= so2; + for ( j = 1; j < N; j++ ) { + tmp *= v; + oset( obuf, io, tmp ); + io -= so2; } + ix += sx; + io += so1 + ( N*so2 ); } } else if ( mode > 0 ) { // Column-major, increasing: fill column 0 with 1s... - io = oo; - for ( i = 0; i < M; i++ ) { - oset( out.data, io, 1.0 ); - io += so1; - } + gfill( M, 1.0, obuf, so1, oo ); + // Fill remaining columns by multiplying previous column by x... for ( j = 1; j < N; j++ ) { ix = ox; io = oo + ( j * so2 ); for ( i = 0; i < M; i++ ) { - oset( out.data, io, oget( out.data, io - so2 ) * xget( x.data, ix ) ); + oset( obuf, io, oget( obuf, io - so2 ) * xget( xbuf, ix ) ); ix += sx; io += so1; } } } else { // Column-major, decreasing: fill column N-1 with 1s... - io = oo + ( (N-1) * so2 ); - for ( i = 0; i < M; i++ ) { - oset( out.data, io, 1.0 ); - io += so1; - } + gfill( M, 1.0, obuf, so1, oo + ( (N-1) * so2 ) ); + // Fill remaining columns by multiplying next column by x... for ( j = N - 2; j >= 0; j-- ) { ix = ox; io = oo + ( j * so2 ); for ( i = 0; i < M; i++ ) { - oset( out.data, io, oget( out.data, io + so2 ) * xget( x.data, ix ) ); + oset( obuf, io, oget( obuf, io + so2 ) * xget( xbuf, ix ) ); ix += sx; io += so1; } } } - return out.data; + return obuf; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js index a77a502a2ab1..3e16c7997b19 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js @@ -37,14 +37,14 @@ var accessors = require( './accessors.js' ); * @param {integer} mode - mode indicating whether to generate increasing or decreasing powers * @param {NonNegativeInteger} M - number of rows in `out` * @param {NonNegativeInteger} N - number of columns in `out` -* @param {Collection} x - input array +* @param {NumericArray} x - input array * @param {integer} strideX - stride length for `x` * @param {NonNegativeInteger} offsetX - starting index for `x` -* @param {Collection} out - output array +* @param {NumericArray} out - output matrix * @param {integer} strideOut1 - stride length for the first dimension of `out` * @param {integer} strideOut2 - stride length for the second dimension of `out` * @param {NonNegativeInteger} offsetOut - starting index for `out` -* @returns {Collection} output array +* @returns {NumericArray} output matrix * * @example * var x = [ 1.0, 2.0, 3.0 ]; @@ -75,47 +75,51 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, // Note on variable naming convention: S#, do#, io, i# where # corresponds to the loop number, with `0` being the innermost loop... rm = isRowMajor( [ strideOut1, strideOut2 ] ); + sx = strideX; - // Extract loop variables for loop interchange... - if ( rm ) { + if ( rm && mode > 0 ) { + // Row-major, increasing: x^0, x^1, ..., x^(N-1) S0 = N; S1 = M; - do0 = strideOut2; // offset increment for innermost loop - do1 = strideOut1 - ( S0*strideOut2 ); // offset increment for outermost loop - } else { // order === 'column-major' - S0 = M; - S1 = N; - do0 = strideOut1; // offset increment for innermost loop - do1 = strideOut2 - ( S0*strideOut1 ); // offset increment for outermost loop - } - sx = strideX; - io = offsetOut; - - // For a Vandermonde matrix, each row `i` contains powers of `x[i]`: - if ( rm ) { + do0 = strideOut2; + do1 = strideOut1 - ( S0*strideOut2 ); + io = offsetOut; ix = offsetX; for ( i1 = 0; i1 < S1; i1++ ) { - if ( mode > 0 ) { - // Increasing: x^0, x^1, ..., x^(N-1) - out[ io ] = 1.0; + out[ io ] = 1.0; + io += do0; + for ( i0 = 1; i0 < S0; i0++ ) { + out[ io ] = out[ io - do0 ] * x[ ix ]; io += do0; - for ( i0 = 1; i0 < S0; i0++ ) { - out[ io ] = out[ io - do0 ] * x[ ix ]; - io += do0; - } - } else { - // Decreasing: x^(N-1), x^(N-2), ..., x^0 - out[ io + ( ( S0-1 ) * do0 ) ] = 1.0; - for ( i0 = S0 - 2; i0 >= 0; i0-- ) { - out[ io + ( i0*do0 ) ] = out[ io + ( (i0+1)*do0 ) ] * x[ ix ]; - } - io += S0 * do0; + } + ix += sx; + io += do1; + } + } else if ( rm ) { + // Row-major, decreasing: x^(N-1), x^(N-2), ..., x^0 + S0 = N; + S1 = M; + do0 = strideOut2; + do1 = strideOut1 + ( S0*strideOut2 ); + io = offsetOut + ( ( S0-1 ) * do0 ); + ix = offsetX; + for ( i1 = 0; i1 < S1; i1++ ) { + out[ io ] = 1.0; + io -= do0; + for ( i0 = 1; i0 < S0; i0++ ) { + out[ io ] = out[ io + do0 ] * x[ ix ]; + io -= do0; } ix += sx; io += do1; } } else if ( mode > 0 ) { - // Increasing: column j contains x^j + // Column-major, increasing: column j contains x^j + S0 = M; + S1 = N; + do0 = strideOut1; + do1 = strideOut2 - ( S0*strideOut1 ); + io = offsetOut; gfill( S0, 1.0, out, do0, io ); io += ( S0 * do0 ) + do1; for ( i1 = 1; i1 < S1; i1++ ) { @@ -128,7 +132,10 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, io += do1; } } else { - // Decreasing: column 0 contains x^(N-1), last column all ones + // Column-major, decreasing: column 0 contains x^(N-1), last column all ones + S0 = M; + S1 = N; + do0 = strideOut1; gfill( S0, 1.0, out, do0, offsetOut + ( ( S1-1 ) * strideOut2 ) ); for ( i1 = S1 - 2; i1 >= 0; i1-- ) { io = offsetOut + ( i1 * strideOut2 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/main.js index 0f2f2fdab3d3..6baba9553924 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/main.js @@ -37,16 +37,16 @@ var base = require( './base.js' ); * @param {integer} mode - mode indicating whether to generate increasing or decreasing powers * @param {NonNegativeInteger} M - number of rows in `out` * @param {NonNegativeInteger} N - number of columns in `out` -* @param {Collection} x - input array +* @param {NumericArray} x - input array * @param {integer} strideX - stride length for `x` -* @param {Collection} out - output array -* @param {PositiveInteger} LDO - stride length for the leading dimension of `out` +* @param {NumericArray} out - output matrix +* @param {PositiveInteger} ldo - stride of the first dimension of `out` (a.k.a., leading dimension of the matrix `out`) * @throws {TypeError} first argument must be a valid order * @throws {RangeError} third argument must be a nonnegative integer * @throws {RangeError} fourth argument must be a nonnegative integer * @throws {RangeError} sixth argument must be non-zero * @throws {RangeError} eighth argument must be a valid stride -* @returns {Collection} output array +* @returns {NumericArray} output matrix * * @example * var x = [ 1.0, 2.0, 3.0 ]; @@ -55,7 +55,7 @@ var base = require( './base.js' ); * gvander( 'row-major', 1, 3, 3, x, 1, out, 3 ); * // out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] */ -function gvander( order, mode, M, N, x, strideX, out, LDO ) { +function gvander( order, mode, M, N, x, strideX, out, ldo ) { var iscm; var sa1; var sa2; @@ -74,28 +74,24 @@ function gvander( order, mode, M, N, x, strideX, out, LDO ) { if ( strideX === 0 ) { throw new RangeError( format( 'invalid argument. Sixth argument must be non-zero. Value: `%d`.', strideX ) ); } - iscm = isColumnMajor( order ); if ( iscm ) { k = M; } else { k = N; } - - if ( LDO < max( 1, k ) ) { - throw new RangeError( format( 'invalid argument. Eighth argument must be greater than or equal to max(1,%d). Value: `%d`.', k, LDO ) ); + if ( ldo < max( 1, k ) ) { + throw new RangeError( format( 'invalid argument. Eighth argument must be greater than or equal to max(1,%d). Value: `%d`.', k, ldo ) ); } - if ( M === 0 || N === 0 ) { return out; } - ox = stride2offset( M, strideX ); if ( iscm ) { sa1 = 1; - sa2 = LDO; + sa2 = ldo; } else { // order === 'row-major' - sa1 = LDO; + sa1 = ldo; sa2 = 1; } return base( mode, M, N, x, strideX, ox, out, sa1, sa2, 0 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/ndarray.js index fa30eacf1767..8094c2be3eb6 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/ndarray.js @@ -34,17 +34,17 @@ var base = require( './base.js' ); * @param {integer} mode - mode indicating whether to generate increasing or decreasing powers * @param {NonNegativeInteger} M - number of rows in `out` * @param {NonNegativeInteger} N - number of columns in `out` -* @param {Collection} x - input array +* @param {NumericArray} x - input array * @param {integer} strideX - stride length for `x` * @param {NonNegativeInteger} offsetX - starting index for `x` -* @param {Collection} out - output array +* @param {NumericArray} out - output matrix * @param {integer} strideOut1 - stride length for the first dimension of `out` * @param {integer} strideOut2 - stride length for the second dimension of `out` * @param {NonNegativeInteger} offsetOut - starting index for `out` * @throws {RangeError} second argument must be a nonnegative integer * @throws {RangeError} third argument must be a nonnegative integer * @throws {RangeError} fifth argument must be non-zero -* @returns {Collection} output array +* @returns {NumericArray} output matrix * * @example * var x = [ 1.0, 2.0, 3.0 ]; @@ -63,7 +63,6 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, if ( strideX === 0 ) { throw new RangeError( format( 'invalid argument. Fifth argument must be non-zero. Value: `%d`.', strideX ) ); } - if ( M === 0 || N === 0 ) { return out; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.main.js index e4956f81537b..4ff62f363e6f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.main.js @@ -389,7 +389,7 @@ tape( 'the function generates a Vandermonde matrix (column-major, increasing, ac t.end(); }); -tape( 'the function returns the output array', function test( t ) { +tape( 'the function returns the output matrix', function test( t ) { var out; var x; var v; @@ -403,7 +403,7 @@ tape( 'the function returns the output array', function test( t ) { t.end(); }); -tape( 'the function returns the output array (accessors)', function test( t ) { +tape( 'the function returns the output matrix (accessors)', function test( t ) { var out; var x; var v; @@ -519,7 +519,7 @@ tape( 'the function supports specifying a negative stride (column-major)', funct t.end(); }); -tape( 'the function supports an `LDO` larger than the matrix dimension (row-major)', function test( t ) { +tape( 'the function supports an `ldo` larger than the matrix dimension (row-major)', function test( t ) { var expected; var out; var x; @@ -527,7 +527,7 @@ tape( 'the function supports an `LDO` larger than the matrix dimension (row-majo x = [ 1.0, 2.0 ]; out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - // 2x3 row-major with LDO=5 (padding of 2 per row) + // 2x3 row-major with ldo=5 (padding of 2 per row) gvander( 'row-major', -1, 2, 3, x, 1, out, 5 ); expected = [ @@ -547,7 +547,7 @@ tape( 'the function supports an `LDO` larger than the matrix dimension (row-majo t.end(); }); -tape( 'the function supports an `LDO` larger than the matrix dimension (row-major, accessors)', function test( t ) { +tape( 'the function supports an `ldo` larger than the matrix dimension (row-major, accessors)', function test( t ) { var expected; var out; var x; @@ -574,7 +574,7 @@ tape( 'the function supports an `LDO` larger than the matrix dimension (row-majo t.end(); }); -tape( 'the function supports an `LDO` larger than the matrix dimension (column-major)', function test( t ) { +tape( 'the function supports an `ldo` larger than the matrix dimension (column-major)', function test( t ) { var expected; var out; var x; @@ -582,7 +582,7 @@ tape( 'the function supports an `LDO` larger than the matrix dimension (column-m x = [ 1.0, 2.0 ]; out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - // 2x3 column-major with LDO=4 (padding of 2 per column) + // 2x3 column-major with ldo=4 (padding of 2 per column) gvander( 'column-major', -1, 2, 3, x, 1, out, 4 ); expected = [ @@ -604,7 +604,7 @@ tape( 'the function supports an `LDO` larger than the matrix dimension (column-m t.end(); }); -tape( 'the function supports an `LDO` larger than the matrix dimension (column-major, accessors)', function test( t ) { +tape( 'the function supports an `ldo` larger than the matrix dimension (column-major, accessors)', function test( t ) { var expected; var out; var x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.ndarray.js index c690c13679dd..74a17fa4faa1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.ndarray.js @@ -294,7 +294,7 @@ tape( 'the function generates a Vandermonde matrix (column-major, increasing, ac t.end(); }); -tape( 'the function returns the output array', function test( t ) { +tape( 'the function returns the output matrix', function test( t ) { var out; var x; var v; @@ -308,7 +308,7 @@ tape( 'the function returns the output array', function test( t ) { t.end(); }); -tape( 'the function returns the output array (accessors)', function test( t ) { +tape( 'the function returns the output matrix (accessors)', function test( t ) { var out; var x; var v; From 305052caf813604939b1fe8049b58ad333bbb354 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Fri, 20 Mar 2026 17:38:51 +0500 Subject: [PATCH 05/32] fix: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../@stdlib/blas/ext/base/gvander/lib/accessors.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js index 6d82dcd24896..459e42016f28 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js @@ -16,9 +16,6 @@ * limitations under the License. */ -/* eslint-disable max-len */ - -'use strict'; // MODULES // From 1ecf9e02996638343200b67fca3e0c5c022ecdce Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Fri, 20 Mar 2026 17:42:40 +0500 Subject: [PATCH 06/32] fix: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../@stdlib/blas/ext/base/gvander/lib/accessors.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js index 459e42016f28..2dc176dbae5c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js @@ -17,6 +17,10 @@ */ +*/ + +'use strict'; + // MODULES // var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); From 7780772a82dc168307d90ce98cc0829be7b1d856 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Fri, 20 Mar 2026 17:49:54 +0500 Subject: [PATCH 07/32] fix: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../@stdlib/blas/ext/base/gvander/lib/accessors.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js index 2dc176dbae5c..695db1bd3cad 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js @@ -16,9 +16,6 @@ * limitations under the License. */ - -*/ - 'use strict'; // MODULES // From 4ff7d5673f449dec385e402686e1edcac3c66aa2 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 22 Mar 2026 21:10:46 +0500 Subject: [PATCH 08/32] 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: 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../blas/ext/base/gvander/lib/accessors.js | 77 +++++++++++-------- .../@stdlib/blas/ext/base/gvander/lib/base.js | 15 ++-- 2 files changed, 54 insertions(+), 38 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js index 695db1bd3cad..bc5a6dfe30b8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js @@ -62,11 +62,15 @@ function gvander( mode, M, N, x, sx, ox, out, so1, so2, oo ) { var oset; var isrm; var tmp; - var ix; + var do0; + var do1; + var S0; + var S1; var io; + var ix; + var i0; + var i1; var v; - var i; - var j; xbuf = x.data; obuf = out.data; @@ -74,65 +78,78 @@ function gvander( mode, M, N, x, sx, ox, out, so1, so2, oo ) { oget = out.accessors[ 0 ]; oset = out.accessors[ 1 ]; + // Note on variable naming convention: S#, do#, io, i# where # corresponds to the loop number, with `0` being the innermost loop... isrm = isRowMajor( [ so1, so2 ] ); if ( isrm && mode > 0 ) { // Row-major, increasing: x^0, x^1, ..., x^(N-1) - ix = ox; + S0 = N; + S1 = M; + do0 = so2; + do1 = so1 - ( S0*so2 ); io = oo; - for ( i = 0; i < M; i++ ) { + ix = ox; + for ( i1 = 0; i1 < S1; i1++ ) { v = xget( xbuf, ix ); oset( obuf, io, 1.0 ); tmp = 1.0; - io += so2; - for ( j = 1; j < N; j++ ) { + io += do0; + for ( i0 = 1; i0 < S0; i0++ ) { tmp *= v; oset( obuf, io, tmp ); - io += so2; + io += do0; } ix += sx; - io += so1 - ( N*so2 ); + io += do1; } } else if ( isrm ) { // Row-major, decreasing: x^(N-1), x^(N-2), ..., x^0 + S0 = N; + S1 = M; + do0 = so2; + do1 = so1 + ( S0*so2 ); + io = oo + ( ( S0-1 ) * do0 ); ix = ox; - io = oo + ( (N-1)*so2 ); - for ( i = 0; i < M; i++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { v = xget( xbuf, ix ); oset( obuf, io, 1.0 ); tmp = 1.0; - io -= so2; - for ( j = 1; j < N; j++ ) { + io -= do0; + for ( i0 = 1; i0 < S0; i0++ ) { tmp *= v; oset( obuf, io, tmp ); - io -= so2; + io -= do0; } ix += sx; - io += so1 + ( N*so2 ); + io += do1; } } else if ( mode > 0 ) { - // Column-major, increasing: fill column 0 with 1s... - gfill( M, 1.0, obuf, so1, oo ); - - // Fill remaining columns by multiplying previous column by x... - for ( j = 1; j < N; j++ ) { + // Column-major, increasing: column j contains x^j + S0 = M; + S1 = N; + do0 = so1; + do1 = so2 - ( S0*so1 ); + io = oo; + gfill( S0, 1.0, obuf, do0, io ); + io += so2; + for ( i1 = 1; i1 < S1; i1++ ) { ix = ox; - io = oo + ( j * so2 ); - for ( i = 0; i < M; i++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { oset( obuf, io, oget( obuf, io - so2 ) * xget( xbuf, ix ) ); ix += sx; - io += so1; + io += do0; } + io += do1; } } else { - // Column-major, decreasing: fill column N-1 with 1s... - gfill( M, 1.0, obuf, so1, oo + ( (N-1) * so2 ) ); - - // Fill remaining columns by multiplying next column by x... - for ( j = N - 2; j >= 0; j-- ) { + // Column-major, decreasing: column 0 contains x^(N-1), last column all ones + S0 = M; + S1 = N; + gfill( S0, 1.0, obuf, so1, oo + ( ( S1-1 ) * so2 ) ); + for ( i1 = S1 - 2; i1 >= 0; i1-- ) { + io = oo + ( i1 * so2 ); ix = ox; - io = oo + ( j * so2 ); - for ( i = 0; i < M; i++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { oset( obuf, io, oget( obuf, io + so2 ) * xget( xbuf, ix ) ); ix += sx; io += so1; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js index 3e16c7997b19..455ef45e6b97 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js @@ -54,11 +54,11 @@ var accessors = require( './accessors.js' ); * // out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] */ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) { + var isrm; var xobj; var oobj; var do0; var do1; - var rm; var S0; var S1; var sx; @@ -74,10 +74,10 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, } // Note on variable naming convention: S#, do#, io, i# where # corresponds to the loop number, with `0` being the innermost loop... - rm = isRowMajor( [ strideOut1, strideOut2 ] ); + isrm = isRowMajor( [ strideOut1, strideOut2 ] ); sx = strideX; - if ( rm && mode > 0 ) { + if ( isrm && mode > 0 ) { // Row-major, increasing: x^0, x^1, ..., x^(N-1) S0 = N; S1 = M; @@ -95,7 +95,7 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, ix += sx; io += do1; } - } else if ( rm ) { + } else if ( isrm ) { // Row-major, decreasing: x^(N-1), x^(N-2), ..., x^0 S0 = N; S1 = M; @@ -121,7 +121,7 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, do1 = strideOut2 - ( S0*strideOut1 ); io = offsetOut; gfill( S0, 1.0, out, do0, io ); - io += ( S0 * do0 ) + do1; + io += strideOut2; for ( i1 = 1; i1 < S1; i1++ ) { ix = offsetX; for ( i0 = 0; i0 < S0; i0++ ) { @@ -135,15 +135,14 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, // Column-major, decreasing: column 0 contains x^(N-1), last column all ones S0 = M; S1 = N; - do0 = strideOut1; - gfill( S0, 1.0, out, do0, offsetOut + ( ( S1-1 ) * strideOut2 ) ); + gfill( S0, 1.0, out, strideOut1, offsetOut + ( ( S1-1 ) * strideOut2 ) ); for ( i1 = S1 - 2; i1 >= 0; i1-- ) { io = offsetOut + ( i1 * strideOut2 ); ix = offsetX; for ( i0 = 0; i0 < S0; i0++ ) { out[ io ] = out[ io + strideOut2 ] * x[ ix ]; ix += sx; - io += do0; + io += strideOut1; } } } From 416bb2da28091590404a98534e2ccbae82078cfc Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 6 Apr 2026 19:00:51 -0700 Subject: [PATCH 09/32] refactor: reduce assignment duplication Signed-off-by: Athan --- .../@stdlib/blas/ext/base/gvander/lib/base.js | 73 ++++++++++--------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js index 455ef45e6b97..9102abcf1002 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js @@ -77,46 +77,49 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, isrm = isRowMajor( [ strideOut1, strideOut2 ] ); sx = strideX; - if ( isrm && mode > 0 ) { - // Row-major, increasing: x^0, x^1, ..., x^(N-1) + if ( isrm ) { S0 = N; S1 = M; do0 = strideOut2; - do1 = strideOut1 - ( S0*strideOut2 ); - io = offsetOut; ix = offsetX; - for ( i1 = 0; i1 < S1; i1++ ) { - out[ io ] = 1.0; - io += do0; - for ( i0 = 1; i0 < S0; i0++ ) { - out[ io ] = out[ io - do0 ] * x[ ix ]; + + // Increasing: x^0, x^1, ..., x^(N-1) + if ( mode > 0 ) { + do1 = strideOut1 - ( S0*strideOut2 ); + io = offsetOut; + for ( i1 = 0; i1 < S1; i1++ ) { + out[ io ] = 1.0; io += do0; + for ( i0 = 1; i0 < S0; i0++ ) { + out[ io ] = out[ io-do0 ] * x[ ix ]; + io += do0; + } + ix += sx; + io += do1; } - ix += sx; - io += do1; + return out; } - } else if ( isrm ) { - // Row-major, decreasing: x^(N-1), x^(N-2), ..., x^0 - S0 = N; - S1 = M; - do0 = strideOut2; + // Decreasing: x^(N-1), x^(N-2), ..., x^0 do1 = strideOut1 + ( S0*strideOut2 ); io = offsetOut + ( ( S0-1 ) * do0 ); - ix = offsetX; for ( i1 = 0; i1 < S1; i1++ ) { out[ io ] = 1.0; io -= do0; for ( i0 = 1; i0 < S0; i0++ ) { - out[ io ] = out[ io + do0 ] * x[ ix ]; + out[ io ] = out[ io+do0 ] * x[ ix ]; io -= do0; } ix += sx; io += do1; } - } else if ( mode > 0 ) { - // Column-major, increasing: column j contains x^j - S0 = M; - S1 = N; + return out; + } + // Column-major... + S0 = M; + S1 = N; + + // Increasing: column j contains x^j + if ( mode > 0 ) { do0 = strideOut1; do1 = strideOut2 - ( S0*strideOut1 ); io = offsetOut; @@ -125,25 +128,23 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, for ( i1 = 1; i1 < S1; i1++ ) { ix = offsetX; for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = out[ io - strideOut2 ] * x[ ix ]; + out[ io ] = out[ io-strideOut2 ] * x[ ix ]; ix += sx; io += do0; } io += do1; } - } else { - // Column-major, decreasing: column 0 contains x^(N-1), last column all ones - S0 = M; - S1 = N; - gfill( S0, 1.0, out, strideOut1, offsetOut + ( ( S1-1 ) * strideOut2 ) ); - for ( i1 = S1 - 2; i1 >= 0; i1-- ) { - io = offsetOut + ( i1 * strideOut2 ); - ix = offsetX; - for ( i0 = 0; i0 < S0; i0++ ) { - out[ io ] = out[ io + strideOut2 ] * x[ ix ]; - ix += sx; - io += strideOut1; - } + return out; + } + // Decreasing: column 0 contains x^(N-1), last column all ones + gfill( S0, 1.0, out, strideOut1, offsetOut + ( ( S1-1 ) * strideOut2 ) ); + for ( i1 = S1 - 2; i1 >= 0; i1-- ) { + io = offsetOut + ( i1*strideOut2 ); + ix = offsetX; + for ( i0 = 0; i0 < S0; i0++ ) { + out[ io ] = out[ io+strideOut2 ] * x[ ix ]; + ix += sx; + io += strideOut1; } } return out; From 28c22a2381edadab90f4f9c49aeb65105da93423 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 6 Apr 2026 19:03:44 -0700 Subject: [PATCH 10/32] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js index 9102abcf1002..f80dfe322381 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js @@ -138,7 +138,7 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, } // Decreasing: column 0 contains x^(N-1), last column all ones gfill( S0, 1.0, out, strideOut1, offsetOut + ( ( S1-1 ) * strideOut2 ) ); - for ( i1 = S1 - 2; i1 >= 0; i1-- ) { + for ( i1 = S1-2; i1 >= 0; i1-- ) { io = offsetOut + ( i1*strideOut2 ); ix = offsetX; for ( i0 = 0; i0 < S0; i0++ ) { From d7ad94ad41fedf160afcbfcc3f987685d78b8853 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 6 Apr 2026 19:13:57 -0700 Subject: [PATCH 11/32] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js index f80dfe322381..5807e8e23b16 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js @@ -101,7 +101,7 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, } // Decreasing: x^(N-1), x^(N-2), ..., x^0 do1 = strideOut1 + ( S0*strideOut2 ); - io = offsetOut + ( ( S0-1 ) * do0 ); + io = offsetOut + ( ( S0-1 ) * strideOut2 ); for ( i1 = 0; i1 < S1; i1++ ) { out[ io ] = 1.0; io -= do0; From 229126b34596648529acc53921bd78da181b0605 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 6 Apr 2026 19:18:25 -0700 Subject: [PATCH 12/32] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js index 5807e8e23b16..67978df90042 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js @@ -123,7 +123,7 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, do0 = strideOut1; do1 = strideOut2 - ( S0*strideOut1 ); io = offsetOut; - gfill( S0, 1.0, out, do0, io ); + gfill( S0, 1.0, out, strideOut1, offsetOut ); io += strideOut2; for ( i1 = 1; i1 < S1; i1++ ) { ix = offsetX; From 3341c3b8fe3146e853db2e1ef1e06260b094d894 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 6 Apr 2026 19:19:31 -0700 Subject: [PATCH 13/32] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js index 67978df90042..4e819f429b8d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js @@ -120,11 +120,10 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, // Increasing: column j contains x^j if ( mode > 0 ) { + gfill( S0, 1.0, out, strideOut1, offsetOut ); do0 = strideOut1; do1 = strideOut2 - ( S0*strideOut1 ); - io = offsetOut; - gfill( S0, 1.0, out, strideOut1, offsetOut ); - io += strideOut2; + io = offsetOut + strideOut2; for ( i1 = 1; i1 < S1; i1++ ) { ix = offsetX; for ( i0 = 0; i0 < S0; i0++ ) { From 1cf43b0877508e35b2ce87766042919ea7262c72 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Wed, 8 Apr 2026 03:11:16 +0500 Subject: [PATCH 14/32] fix: 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: passed - 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../blas/ext/base/gvander/docs/repl.txt | 8 +++--- .../blas/ext/base/gvander/lib/accessors.js | 27 ++++++++++-------- .../@stdlib/blas/ext/base/gvander/lib/base.js | 28 +++++++++++-------- 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/repl.txt index 1581d81664d9..e0a82e4a3ea9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/repl.txt @@ -5,8 +5,8 @@ When the mode is positive, the matrix is generated such that [ - 1 x_0^1 x_0^2 ... x_0^N - 1 x_1^1 x_1^2 ... x_1^N + 1 x_0^1 x_0^2 ... x_0^(N-1) + 1 x_1^1 x_1^2 ... x_1^(N-1) ... ] @@ -15,8 +15,8 @@ When the mode is negative, the matrix is generated such that [ - x_0^N ... x_0^2 x_0^1 1 - x_1^N ... x_1^2 x_1^1 1 + x_0^(N-1) ... x_0^2 x_0^1 1 + x_1^(N-1) ... x_1^2 x_1^1 1 ... ] diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js index bc5a6dfe30b8..c823f14e4c0a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js @@ -107,10 +107,10 @@ function gvander( mode, M, N, x, sx, ox, out, so1, so2, oo ) { S0 = N; S1 = M; do0 = so2; - do1 = so1 + ( S0*so2 ); - io = oo + ( ( S0-1 ) * do0 ); - ix = ox; - for ( i1 = 0; i1 < S1; i1++ ) { + do1 = so1 - ( S0*so2 ); + io = oo + ( ( S1-1 ) * so1 ) + ( ( S0-1 ) * so2 ); + ix = ox + ( ( S1-1 ) * sx ); + for ( i1 = S1-1; i1 >= 0; i1-- ) { v = xget( xbuf, ix ); oset( obuf, io, 1.0 ); tmp = 1.0; @@ -120,8 +120,8 @@ function gvander( mode, M, N, x, sx, ox, out, so1, so2, oo ) { oset( obuf, io, tmp ); io -= do0; } - ix += sx; - io += do1; + ix -= sx; + io -= do1; } } else if ( mode > 0 ) { // Column-major, increasing: column j contains x^j @@ -145,15 +145,18 @@ function gvander( mode, M, N, x, sx, ox, out, so1, so2, oo ) { // Column-major, decreasing: column 0 contains x^(N-1), last column all ones S0 = M; S1 = N; + do0 = so1; + do1 = so2 - ( S0*so1 ); gfill( S0, 1.0, obuf, so1, oo + ( ( S1-1 ) * so2 ) ); - for ( i1 = S1 - 2; i1 >= 0; i1-- ) { - io = oo + ( i1 * so2 ); - ix = ox; - for ( i0 = 0; i0 < S0; i0++ ) { + io = oo + ( ( S1-2 ) * so2 ) + ( ( S0-1 ) * so1 ); + for ( i1 = S1-2; i1 >= 0; i1-- ) { + ix = ox + ( ( S0-1 ) * sx ); + for ( i0 = S0-1; i0 >= 0; i0-- ) { oset( obuf, io, oget( obuf, io + so2 ) * xget( xbuf, ix ) ); - ix += sx; - io += so1; + ix -= sx; + io -= do0; } + io -= do1; } } return obuf; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js index 4e819f429b8d..24be50686ba2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js @@ -81,12 +81,12 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, S0 = N; S1 = M; do0 = strideOut2; - ix = offsetX; // Increasing: x^0, x^1, ..., x^(N-1) if ( mode > 0 ) { do1 = strideOut1 - ( S0*strideOut2 ); io = offsetOut; + ix = offsetX; for ( i1 = 0; i1 < S1; i1++ ) { out[ io ] = 1.0; io += do0; @@ -100,24 +100,25 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, return out; } // Decreasing: x^(N-1), x^(N-2), ..., x^0 - do1 = strideOut1 + ( S0*strideOut2 ); - io = offsetOut + ( ( S0-1 ) * strideOut2 ); - for ( i1 = 0; i1 < S1; i1++ ) { + do1 = strideOut1 - ( S0*strideOut2 ); + io = offsetOut + ( ( S1-1 ) * strideOut1 ) + ( ( S0-1 ) * strideOut2 ); + ix = offsetX + ( ( S1-1 ) * sx ); + for ( i1 = S1-1; i1 >= 0; i1-- ) { out[ io ] = 1.0; io -= do0; for ( i0 = 1; i0 < S0; i0++ ) { out[ io ] = out[ io+do0 ] * x[ ix ]; io -= do0; } - ix += sx; - io += do1; + ix -= sx; + io -= do1; } return out; } // Column-major... S0 = M; S1 = N; - + // Increasing: column j contains x^j if ( mode > 0 ) { gfill( S0, 1.0, out, strideOut1, offsetOut ); @@ -137,14 +138,17 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, } // Decreasing: column 0 contains x^(N-1), last column all ones gfill( S0, 1.0, out, strideOut1, offsetOut + ( ( S1-1 ) * strideOut2 ) ); + do0 = strideOut1; + do1 = strideOut2 - ( S0*strideOut1 ); + io = offsetOut + ( ( S1-2 ) * strideOut2 ) + ( ( S0-1 ) * strideOut1 ); for ( i1 = S1-2; i1 >= 0; i1-- ) { - io = offsetOut + ( i1*strideOut2 ); - ix = offsetX; - for ( i0 = 0; i0 < S0; i0++ ) { + ix = offsetX + ( ( S0-1 ) * sx ); + for ( i0 = S0-1; i0 >= 0; i0-- ) { out[ io ] = out[ io+strideOut2 ] * x[ ix ]; - ix += sx; - io += strideOut1; + ix -= sx; + io -= do0; } + io -= do1; } return out; } From d107953a58aa70c068063d1e4694591d26ee6cec Mon Sep 17 00:00:00 2001 From: headlessNode Date: Wed, 8 Apr 2026 03:17:57 +0500 Subject: [PATCH 15/32] fix: apply suggestion 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: 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/base/gvander/lib/accessors.js | 4 ++++ lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js index c823f14e4c0a..c4765805afe3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js @@ -29,6 +29,10 @@ var gfill = require( '@stdlib/blas/ext/base/gfill' ).ndarray; /** * Generates a Vandermonde matrix using accessor arrays. * +* ## Notes +* +* - The implementation uses recursive multiplication to generate successive powers, which carries risk of additional accumulated floating-point error; however, for most use cases, such additional error should be negligible and not problematic. +* * @private * @param {integer} mode - mode indicating whether to generate increasing or decreasing powers * @param {NonNegativeInteger} M - number of rows in `out` diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js index 24be50686ba2..1bab0d3b12ff 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js @@ -33,6 +33,10 @@ var accessors = require( './accessors.js' ); /** * Generates a Vandermonde matrix using alternative indexing semantics. * +* ## Notes +* +* - The implementation uses recursive multiplication to generate successive powers, which carries risk of additional accumulated floating-point error; however, for most use cases, such additional error should be negligible and not problematic. +* * @private * @param {integer} mode - mode indicating whether to generate increasing or decreasing powers * @param {NonNegativeInteger} M - number of rows in `out` From 7be82979c7a7d39461fa02cb38d38778ed03baf6 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 9 Apr 2026 19:45:20 -0700 Subject: [PATCH 16/32] style: remove assignment duplication Signed-off-by: Athan --- .../blas/ext/base/gvander/lib/accessors.js | 81 +++++++++---------- 1 file changed, 39 insertions(+), 42 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js index c4765805afe3..874ec56fab21 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js @@ -85,33 +85,31 @@ function gvander( mode, M, N, x, sx, ox, out, so1, so2, oo ) { // Note on variable naming convention: S#, do#, io, i# where # corresponds to the loop number, with `0` being the innermost loop... isrm = isRowMajor( [ so1, so2 ] ); - if ( isrm && mode > 0 ) { - // Row-major, increasing: x^0, x^1, ..., x^(N-1) + if ( isrm ) { S0 = N; S1 = M; do0 = so2; do1 = so1 - ( S0*so2 ); - io = oo; - ix = ox; - for ( i1 = 0; i1 < S1; i1++ ) { - v = xget( xbuf, ix ); - oset( obuf, io, 1.0 ); - tmp = 1.0; - io += do0; - for ( i0 = 1; i0 < S0; i0++ ) { - tmp *= v; - oset( obuf, io, tmp ); + if ( mode > 0 ) { + // Increasing: x^0, x^1, ..., x^(N-1) + io = oo; + ix = ox; + for ( i1 = 0; i1 < S1; i1++ ) { + v = xget( xbuf, ix ); + oset( obuf, io, 1.0 ); + tmp = 1.0; io += do0; + for ( i0 = 1; i0 < S0; i0++ ) { + tmp *= v; + oset( obuf, io, tmp ); + io += do0; + } + ix += sx; + io += do1; } - ix += sx; - io += do1; + return obuf; } - } else if ( isrm ) { - // Row-major, decreasing: x^(N-1), x^(N-2), ..., x^0 - S0 = N; - S1 = M; - do0 = so2; - do1 = so1 - ( S0*so2 ); + // Decreasing: x^(N-1), x^(N-2), ..., x^0 io = oo + ( ( S1-1 ) * so1 ) + ( ( S0-1 ) * so2 ); ix = ox + ( ( S1-1 ) * sx ); for ( i1 = S1-1; i1 >= 0; i1-- ) { @@ -127,12 +125,15 @@ function gvander( mode, M, N, x, sx, ox, out, so1, so2, oo ) { ix -= sx; io -= do1; } - } else if ( mode > 0 ) { - // Column-major, increasing: column j contains x^j - S0 = M; - S1 = N; - do0 = so1; - do1 = so2 - ( S0*so1 ); + return obuf; + } + // Column-major... + S0 = M; + S1 = N; + do0 = so1; + do1 = so2 - ( S0*so1 ); + if ( mode > 0 ) { + // Increasing: column j contains x^j io = oo; gfill( S0, 1.0, obuf, do0, io ); io += so2; @@ -145,23 +146,19 @@ function gvander( mode, M, N, x, sx, ox, out, so1, so2, oo ) { } io += do1; } - } else { - // Column-major, decreasing: column 0 contains x^(N-1), last column all ones - S0 = M; - S1 = N; - do0 = so1; - do1 = so2 - ( S0*so1 ); - gfill( S0, 1.0, obuf, so1, oo + ( ( S1-1 ) * so2 ) ); - io = oo + ( ( S1-2 ) * so2 ) + ( ( S0-1 ) * so1 ); - for ( i1 = S1-2; i1 >= 0; i1-- ) { - ix = ox + ( ( S0-1 ) * sx ); - for ( i0 = S0-1; i0 >= 0; i0-- ) { - oset( obuf, io, oget( obuf, io + so2 ) * xget( xbuf, ix ) ); - ix -= sx; - io -= do0; - } - io -= do1; + return obuf; + } + // Decreasing: column 0 contains x^(N-1), last column all ones + gfill( S0, 1.0, obuf, so1, oo + ( ( S1-1 ) * so2 ) ); + io = oo + ( ( S1-2 ) * so2 ) + ( ( S0-1 ) * so1 ); + for ( i1 = S1-2; i1 >= 0; i1-- ) { + ix = ox + ( ( S0-1 ) * sx ); + for ( i0 = S0-1; i0 >= 0; i0-- ) { + oset( obuf, io, oget( obuf, io + so2 ) * xget( xbuf, ix ) ); + ix -= sx; + io -= do0; } + io -= do1; } return obuf; } From 47a6d6f453e6fdd2efb087744b17835753b0b672 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 9 Apr 2026 19:47:10 -0700 Subject: [PATCH 17/32] style: move comments Signed-off-by: Athan --- .../@stdlib/blas/ext/base/gvander/lib/accessors.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js index 874ec56fab21..e2e959917fe4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js @@ -90,8 +90,9 @@ function gvander( mode, M, N, x, sx, ox, out, so1, so2, oo ) { S1 = M; do0 = so2; do1 = so1 - ( S0*so2 ); + + // Increasing: x^0, x^1, ..., x^(N-1) if ( mode > 0 ) { - // Increasing: x^0, x^1, ..., x^(N-1) io = oo; ix = ox; for ( i1 = 0; i1 < S1; i1++ ) { @@ -132,8 +133,9 @@ function gvander( mode, M, N, x, sx, ox, out, so1, so2, oo ) { S1 = N; do0 = so1; do1 = so2 - ( S0*so1 ); + + // Increasing: column j contains x^j if ( mode > 0 ) { - // Increasing: column j contains x^j io = oo; gfill( S0, 1.0, obuf, do0, io ); io += so2; From 17a131018e60f4e4ccd506d39bb58f68578586b6 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 9 Apr 2026 19:48:16 -0700 Subject: [PATCH 18/32] refactor: reduce assignment duplication Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js index 1bab0d3b12ff..0ced74916404 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js @@ -122,12 +122,12 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, // Column-major... S0 = M; S1 = N; + do0 = strideOut1; + do1 = strideOut2 - ( S0*strideOut1 ); // Increasing: column j contains x^j if ( mode > 0 ) { gfill( S0, 1.0, out, strideOut1, offsetOut ); - do0 = strideOut1; - do1 = strideOut2 - ( S0*strideOut1 ); io = offsetOut + strideOut2; for ( i1 = 1; i1 < S1; i1++ ) { ix = offsetX; @@ -142,8 +142,6 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, } // Decreasing: column 0 contains x^(N-1), last column all ones gfill( S0, 1.0, out, strideOut1, offsetOut + ( ( S1-1 ) * strideOut2 ) ); - do0 = strideOut1; - do1 = strideOut2 - ( S0*strideOut1 ); io = offsetOut + ( ( S1-2 ) * strideOut2 ) + ( ( S0-1 ) * strideOut1 ); for ( i1 = S1-2; i1 >= 0; i1-- ) { ix = offsetX + ( ( S0-1 ) * sx ); From 1e64d34b91455117e130c0cc2c64dea7c0f8f4fa Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 9 Apr 2026 19:50:10 -0700 Subject: [PATCH 19/32] refactor: remove unnecessary variable Signed-off-by: Athan --- .../@stdlib/blas/ext/base/gvander/lib/base.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js index 0ced74916404..b3b917bfb55a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js @@ -65,7 +65,6 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, var do1; var S0; var S1; - var sx; var io; var ix; var i0; @@ -79,7 +78,6 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, // Note on variable naming convention: S#, do#, io, i# where # corresponds to the loop number, with `0` being the innermost loop... isrm = isRowMajor( [ strideOut1, strideOut2 ] ); - sx = strideX; if ( isrm ) { S0 = N; @@ -98,7 +96,7 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, out[ io ] = out[ io-do0 ] * x[ ix ]; io += do0; } - ix += sx; + ix += strideX; io += do1; } return out; @@ -106,7 +104,7 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, // Decreasing: x^(N-1), x^(N-2), ..., x^0 do1 = strideOut1 - ( S0*strideOut2 ); io = offsetOut + ( ( S1-1 ) * strideOut1 ) + ( ( S0-1 ) * strideOut2 ); - ix = offsetX + ( ( S1-1 ) * sx ); + ix = offsetX + ( ( S1-1 ) * strideX ); for ( i1 = S1-1; i1 >= 0; i1-- ) { out[ io ] = 1.0; io -= do0; @@ -114,7 +112,7 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, out[ io ] = out[ io+do0 ] * x[ ix ]; io -= do0; } - ix -= sx; + ix -= strideX; io -= do1; } return out; @@ -133,7 +131,7 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, ix = offsetX; for ( i0 = 0; i0 < S0; i0++ ) { out[ io ] = out[ io-strideOut2 ] * x[ ix ]; - ix += sx; + ix += strideX; io += do0; } io += do1; @@ -144,10 +142,10 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, gfill( S0, 1.0, out, strideOut1, offsetOut + ( ( S1-1 ) * strideOut2 ) ); io = offsetOut + ( ( S1-2 ) * strideOut2 ) + ( ( S0-1 ) * strideOut1 ); for ( i1 = S1-2; i1 >= 0; i1-- ) { - ix = offsetX + ( ( S0-1 ) * sx ); + ix = offsetX + ( ( S0-1 ) * strideX ); for ( i0 = S0-1; i0 >= 0; i0-- ) { out[ io ] = out[ io+strideOut2 ] * x[ ix ]; - ix -= sx; + ix -= strideX; io -= do0; } io -= do1; From 9526ff2924d1052621656e57b7ba7edce0113c95 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 9 Apr 2026 19:51:26 -0700 Subject: [PATCH 20/32] refactor: reduce assignment duplication Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js index b3b917bfb55a..89cf283e6dad 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js @@ -83,10 +83,10 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, S0 = N; S1 = M; do0 = strideOut2; + do1 = strideOut1 - ( S0*strideOut2 ); // Increasing: x^0, x^1, ..., x^(N-1) if ( mode > 0 ) { - do1 = strideOut1 - ( S0*strideOut2 ); io = offsetOut; ix = offsetX; for ( i1 = 0; i1 < S1; i1++ ) { @@ -102,7 +102,6 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, return out; } // Decreasing: x^(N-1), x^(N-2), ..., x^0 - do1 = strideOut1 - ( S0*strideOut2 ); io = offsetOut + ( ( S1-1 ) * strideOut1 ) + ( ( S0-1 ) * strideOut2 ); ix = offsetX + ( ( S1-1 ) * strideX ); for ( i1 = S1-1; i1 >= 0; i1-- ) { From 1738a4467d58548a8895ec87c8281ce87dfa9d77 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 9 Apr 2026 19:53:00 -0700 Subject: [PATCH 21/32] refactor: remove useless variable Signed-off-by: Athan --- .../@stdlib/blas/ext/base/gvander/lib/accessors.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js index e2e959917fe4..de7edfa4dc22 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js @@ -64,7 +64,6 @@ function gvander( mode, M, N, x, sx, ox, out, so1, so2, oo ) { var xget; var oget; var oset; - var isrm; var tmp; var do0; var do1; @@ -83,9 +82,7 @@ function gvander( mode, M, N, x, sx, ox, out, so1, so2, oo ) { oset = out.accessors[ 1 ]; // Note on variable naming convention: S#, do#, io, i# where # corresponds to the loop number, with `0` being the innermost loop... - isrm = isRowMajor( [ so1, so2 ] ); - - if ( isrm ) { + if ( isRowMajor( [ so1, so2 ] ) ) { S0 = N; S1 = M; do0 = so2; From 31b862df983b12e549903dcf0ca5fac5ca95d844 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 9 Apr 2026 19:53:37 -0700 Subject: [PATCH 22/32] refactor: remove useless variable Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js index 89cf283e6dad..69503c01175a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js @@ -58,7 +58,6 @@ var accessors = require( './accessors.js' ); * // out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] */ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) { - var isrm; var xobj; var oobj; var do0; @@ -77,9 +76,7 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, } // Note on variable naming convention: S#, do#, io, i# where # corresponds to the loop number, with `0` being the innermost loop... - isrm = isRowMajor( [ strideOut1, strideOut2 ] ); - - if ( isrm ) { + if ( isRowMajor( [ strideOut1, strideOut2 ] ) ) { S0 = N; S1 = M; do0 = strideOut2; From e52e17105b2314002107e86709dd4269b40ab75c Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 9 Apr 2026 20:04:13 -0700 Subject: [PATCH 23/32] fix: remove assertion Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gvander/lib/main.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/main.js index 6baba9553924..6aa049085504 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/main.js @@ -44,7 +44,6 @@ var base = require( './base.js' ); * @throws {TypeError} first argument must be a valid order * @throws {RangeError} third argument must be a nonnegative integer * @throws {RangeError} fourth argument must be a nonnegative integer -* @throws {RangeError} sixth argument must be non-zero * @throws {RangeError} eighth argument must be a valid stride * @returns {NumericArray} output matrix * @@ -71,9 +70,6 @@ function gvander( order, mode, M, N, x, strideX, out, ldo ) { if ( N < 0 ) { throw new RangeError( format( 'invalid argument. Fourth argument must be a nonnegative integer. Value: `%d`.', N ) ); } - if ( strideX === 0 ) { - throw new RangeError( format( 'invalid argument. Sixth argument must be non-zero. Value: `%d`.', strideX ) ); - } iscm = isColumnMajor( order ); if ( iscm ) { k = M; From 90d98ba6f0586bf7cd82ade4cd4f8feb97333948 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 9 Apr 2026 20:05:24 -0700 Subject: [PATCH 24/32] fix: remove assertion Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gvander/lib/ndarray.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/ndarray.js index 8094c2be3eb6..6d6f42be8196 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/ndarray.js @@ -43,7 +43,6 @@ var base = require( './base.js' ); * @param {NonNegativeInteger} offsetOut - starting index for `out` * @throws {RangeError} second argument must be a nonnegative integer * @throws {RangeError} third argument must be a nonnegative integer -* @throws {RangeError} fifth argument must be non-zero * @returns {NumericArray} output matrix * * @example @@ -60,9 +59,6 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, if ( N < 0 ) { throw new RangeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', N ) ); } - if ( strideX === 0 ) { - throw new RangeError( format( 'invalid argument. Fifth argument must be non-zero. Value: `%d`.', strideX ) ); - } if ( M === 0 || N === 0 ) { return out; } From 4bd7c0e98792e7736fa4648309687a167ef58082 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 9 Apr 2026 20:13:02 -0700 Subject: [PATCH 25/32] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../blas/ext/base/gvander/test/test.main.js | 40 ------------------- .../ext/base/gvander/test/test.ndarray.js | 40 ------------------- 2 files changed, 80 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.main.js index 4ff62f363e6f..a1d7f03dc7bc 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.main.js @@ -173,46 +173,6 @@ tape( 'the function throws an error if provided an invalid fourth argument (acce } }); -tape( 'the function throws an error if provided an invalid sixth argument', function test( t ) { - var values; - var i; - - values = [ - 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - gvander( 'row-major', -1, 3, 3, [ 1.0, 2.0, 3.0 ], value, [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3 ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid sixth argument (accessors)', function test( t ) { - var values; - var i; - - values = [ - 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - gvander( 'row-major', -1, 3, 3, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), value, toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ), 3 ); - }; - } -}); - tape( 'the function throws an error if provided an invalid eighth argument', function test( t ) { var values; var i; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.ndarray.js index 74a17fa4faa1..0214c8c716c5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.ndarray.js @@ -126,46 +126,6 @@ tape( 'the function throws an error if provided an invalid third argument (acces } }); -tape( 'the function throws an error if provided an invalid fifth argument', function test( t ) { - var values; - var i; - - values = [ - 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - gvander( -1, 3, 3, [ 1.0, 2.0, 3.0 ], value, 0, [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 1, 0 ); // eslint-disable-line max-len - }; - } -}); - -tape( 'the function throws an error if provided an invalid fifth argument (accessors)', function test( t ) { - var values; - var i; - - values = [ - 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - gvander( -1, 3, 3, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), value, 0, toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ), 3, 1, 0 ); // eslint-disable-line max-len - }; - } -}); - tape( 'the function generates a Vandermonde matrix (row-major, decreasing)', function test( t ) { var expected; var out; From 179225144daff04ddc5e5d32d0ad6ea1e0316c98 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 9 Apr 2026 20:22:08 -0700 Subject: [PATCH 26/32] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/blas/ext/base/gvander/test/test.ndarray.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.ndarray.js index 0214c8c716c5..fcd974e945c4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.ndarray.js @@ -282,7 +282,7 @@ tape( 'the function returns the output matrix (accessors)', function test( t ) { t.end(); }); -tape( 'if provided an `M` equal to `0`, the function early returns', function test( t ) { +tape( 'if provided an `M` equal to `0`, the function returns the output matrix unchanged', function test( t ) { var out; var x; @@ -295,7 +295,7 @@ tape( 'if provided an `M` equal to `0`, the function early returns', function te t.end(); }); -tape( 'if provided an `N` equal to `0`, the function early returns', function test( t ) { +tape( 'if provided an `N` equal to `0`, the function returns the output matrix unchanged', function test( t ) { var out; var x; @@ -645,9 +645,9 @@ tape( 'the function supports complex access patterns', function test( t ) { ]; out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - gvander( 1, 2, 3, x, 2, 1, out, 3, 1, 0 ); + gvander( 1, 2, 3, x, 2, 1, out, 3, -1, 2 ); - expected = [ 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ]; + expected = [ 4.0, 2.0, 1.0, 9.0, 3.0, 1.0 ]; t.deepEqual( out, expected, 'returns expected value' ); t.end(); From 6ebd5ab6bc890cf6267929190bf6ed27a96e2b9e Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 9 Apr 2026 20:29:10 -0700 Subject: [PATCH 27/32] docs: add explainer and add example Signed-off-by: Athan --- .../@stdlib/blas/ext/base/gvander/README.md | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md b/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md index 44ed3a496844..a1cdffd37cbd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md @@ -59,6 +59,49 @@ The function has the following parameters: - **out**: output matrix. - **ldo**: stride of the first dimension of `out` (a.k.a., leading dimension of the matrix `out`). +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial arrays: +var x0 = new Float64Array( [ 999.0, 1.0, 2.0, 3.0 ] ); +var out0 = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +// Create offset views: +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var out1 = new Float64Array( out0.buffer, out0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +gvander( 'row-major', 1, 3, 3, x, 1, out, 3 ); +// out0 => [ 0.0, 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] +``` + +When the mode is positive, the matrix is generated such that + +```text +[ + 1 x_0^1 x_0^2 ... x_0^(N-1) + 1 x_1^1 x_1^2 ... x_1^(N-1) + ... +] +``` + +with increasing powers along the rows. + +When the mode is negative, the matrix is generated such that + +```text +[ + x_0^(N-1) ... x_0^2 x_0^1 1 + x_1^(N-1) ... x_1^2 x_1^1 1 + ... +] +``` + +with decreasing powers along the rows. + #### gvander.ndarray( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) From 83b4aef18e65c153ca4421064b6371c91eba0cd1 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 9 Apr 2026 20:29:54 -0700 Subject: [PATCH 28/32] docs: fix example Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gvander/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md b/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md index a1cdffd37cbd..0432f1dbb234 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md @@ -74,7 +74,7 @@ var out0 = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element var out1 = new Float64Array( out0.buffer, out0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -gvander( 'row-major', 1, 3, 3, x, 1, out, 3 ); +gvander( 'row-major', 1, 3, 3, x1, 1, out1, 3 ); // out0 => [ 0.0, 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] ``` From e8c67dba14f2bd0f737e4e8ba6592d7eb8e28220 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 9 Apr 2026 20:31:25 -0700 Subject: [PATCH 29/32] style: remove whitespace Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js index de7edfa4dc22..43ba30176fa7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js @@ -130,7 +130,6 @@ function gvander( mode, M, N, x, sx, ox, out, so1, so2, oo ) { S1 = N; do0 = so1; do1 = so2 - ( S0*so1 ); - // Increasing: column j contains x^j if ( mode > 0 ) { io = oo; From ddd838c50fe277f739427914cc4dadc5066cfbea Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 9 Apr 2026 20:31:55 -0700 Subject: [PATCH 30/32] style: add empty line Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js index 43ba30176fa7..9fe455991033 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js @@ -130,6 +130,7 @@ function gvander( mode, M, N, x, sx, ox, out, so1, so2, oo ) { S1 = N; do0 = so1; do1 = so2 - ( S0*so1 ); + // Increasing: column j contains x^j if ( mode > 0 ) { io = oo; From f048d6019f361241469fd2261e1d15c6e9fe18c4 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 9 Apr 2026 20:52:41 -0700 Subject: [PATCH 31/32] docs: fix example Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gvander/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md b/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md index 0432f1dbb234..8ee02ab8b81b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md @@ -68,7 +68,7 @@ var Float64Array = require( '@stdlib/array/float64' ); // Initial arrays: var x0 = new Float64Array( [ 999.0, 1.0, 2.0, 3.0 ] ); -var out0 = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +var out0 = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); // Create offset views: var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element From a2c557a1818b52173e60e8972f8b934d1290eedf Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 9 Apr 2026 21:08:59 -0700 Subject: [PATCH 32/32] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gvander/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md b/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md index 8ee02ab8b81b..9d62c15f2c79 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md @@ -61,7 +61,7 @@ The function has the following parameters: Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. - + ```javascript var Float64Array = require( '@stdlib/array/float64' );