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..44ed3a496844 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/README.md @@ -0,0 +1,173 @@ + + +# 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**: 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 matrix. +- **ldo**: stride of the first dimension of `out` (a.k.a., leading dimension of the matrix `out`). + + + +#### 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..1581d81664d9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/docs/repl.txt @@ -0,0 +1,136 @@ + +{{alias}}( order, mode, M, N, x, strideX, out, ldo ) + Generates a Vandermonde matrix. + + 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 + ... + ] + + 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 (C-style) or column-major (Fortran-style) order. + + mode: integer + Mode. If `mode < 0`, the function generates decreasing powers. If + `mode > 0`, the function generates increasing powers. + + M: integer + Number of rows in `out` and number of indexed elements in `x`. + + N: integer + Number of columns in `out`. + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length for `x`. + + out: Array|TypedArray + Output matrix. + + ldo: integer + Stride of the first dimension of `out` (a.k.a., leading dimension of + the matrix `out`). + + Returns + ------- + out: Array|TypedArray + Output matrix. + + 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. If `mode < 0`, the function generates decreasing powers. If + `mode > 0`, the function generates increasing powers. + + M: integer + Number of rows in `out` and number of indexed elements in `x`. + + N: integer + Number of columns in `out`. + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length for `x`. + + offsetX: integer + Starting index for `x`. + + out: Array|TypedArray + Output matrix. + + 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 matrix. + + 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..4e5c3fde6b43 --- /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 matrix. +*/ +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 in `out` + * @param N - number of columns in `out` + * @param x - input array + * @param strideX - stride length for `x` + * @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 ]; + * 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 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` + * @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 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.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 in `out` +* @param N - number of columns in `out` +* @param x - input array +* @param strideX - stride length for `x` +* @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 ]; +* 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..bc5a6dfe30b8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/accessors.js @@ -0,0 +1,165 @@ +/** +* @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' ); +var gfill = require( '@stdlib/blas/ext/base/gfill' ).ndarray; + + +// 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 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` +* @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 matrix +* +* @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 xbuf; + var obuf; + var xget; + var oget; + var oset; + var isrm; + var tmp; + var do0; + var do1; + var S0; + var S1; + var io; + var ix; + var i0; + var i1; + var v; + + xbuf = x.data; + obuf = out.data; + xget = x.accessors[ 0 ]; + 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) + 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 ); + io += do0; + } + ix += sx; + 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; + 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; + } + } else if ( mode > 0 ) { + // 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; + for ( i0 = 0; i0 < S0; i0++ ) { + oset( obuf, io, oget( obuf, io - so2 ) * xget( xbuf, 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, 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++ ) { + oset( obuf, io, oget( obuf, io + so2 ) * xget( xbuf, ix ) ); + ix += sx; + io += so1; + } + } + } + return obuf; +} + + +// EXPORTS // + +module.exports = gvander; 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..455ef45e6b97 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js @@ -0,0 +1,155 @@ +/** +* @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 {NumericArray} x - input array +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @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 {NumericArray} 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 isrm; + var xobj; + var oobj; + var do0; + var do1; + 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... + isrm = isRowMajor( [ strideOut1, strideOut2 ] ); + sx = strideX; + + if ( isrm && mode > 0 ) { + // Row-major, increasing: x^0, x^1, ..., x^(N-1) + 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 ]; + io += do0; + } + ix += sx; + io += do1; + } + } else if ( isrm ) { + // 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 ) { + // 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 += strideOut2; + 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 { + // 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; +} + + +// 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..6baba9553924 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/main.js @@ -0,0 +1,103 @@ +/** +* @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 isLayout = require( '@stdlib/blas/base/assert/is-layout' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var max = require( '@stdlib/math/base/special/fast/max' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.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 in `out` +* @param {NonNegativeInteger} N - number of columns in `out` +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length for `x` +* @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 {NumericArray} 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( '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 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 ( iscm ) { + sa1 = 1; + sa2 = ldo; + } else { // order === 'row-major' + sa1 = ldo; + sa2 = 1; + } + return base( 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..8094c2be3eb6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/lib/ndarray.js @@ -0,0 +1,75 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var base = require( './base.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 `out` +* @param {NonNegativeInteger} N - number of columns in `out` +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @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 {NumericArray} 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 ) { + if ( M < 0 ) { + throw new RangeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%d`.', M ) ); + } + 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; + } + return base( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ); +} + + +// 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..4ff62f363e6f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.main.js @@ -0,0 +1,750 @@ +/** +* @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 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; + 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 matrix', 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 matrix (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..74a17fa4faa1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gvander/test/test.ndarray.js @@ -0,0 +1,761 @@ +/** +* @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 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; + 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 matrix', 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 matrix (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(); +});