From d58b43574fbb39026b14cfb3db20b6bb60d80df0 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Mon, 21 Sep 2026 22:20:52 +0500 Subject: [PATCH 1/3] feat: add blas/ext/base/ndarray/gvander --- .../blas/ext/base/ndarray/gvander/README.md | 175 +++++++ .../ndarray/gvander/benchmark/benchmark.js | 115 +++++ .../ext/base/ndarray/gvander/docs/repl.txt | 53 ++ .../ndarray/gvander/docs/types/index.d.ts | 64 +++ .../base/ndarray/gvander/docs/types/test.ts | 70 +++ .../base/ndarray/gvander/examples/index.js | 44 ++ .../ext/base/ndarray/gvander/lib/index.js | 55 ++ .../blas/ext/base/ndarray/gvander/lib/main.js | 87 ++++ .../ext/base/ndarray/gvander/package.json | 67 +++ .../ext/base/ndarray/gvander/test/test.js | 475 ++++++++++++++++++ 10 files changed, 1205 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/test/test.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/README.md new file mode 100644 index 000000000000..2ba54e6d0467 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/README.md @@ -0,0 +1,175 @@ + + +# gvander + +> Generate a Vandermonde matrix. + +
+ +
+ + + +
+ +## Usage + +```javascript +var gvander = require( '@stdlib/blas/ext/base/ndarray/gvander' ); +``` + +#### gvander( arrays ) + +Generates a Vandermonde matrix. + +```javascript +var Vector = require( '@stdlib/ndarray/vector' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +var x = new Vector( 'generic', [ 1.0, 2.0, 3.0 ] ); +var out = zeros( [ 3, 3 ], { + 'dtype': 'generic' +}); + +var mode = scalar2ndarray( 1, { + 'dtype': 'generic' +}); + +var v = gvander( [ x, out, mode ] ); +// returns [ [ 1.0, 1.0, 1.0 ], [ 1.0, 2.0, 4.0 ], [ 1.0, 3.0, 9.0 ] ] + +var bool = ( v === out ); +// returns true +``` + +The function has the following parameters: + +- **arrays**: array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a two-dimensional output ndarray. + - a zero-dimensional ndarray specifying the mode. + +When the mode is positive, the matrix is generated such that + +```text +[ + 1 x_0^1 x_0^2 ... x_0^(N-1) + 1 x_1^1 x_1^2 ... x_1^(N-1) + ... +] +``` + +with increasing powers along the rows. + +When the mode is negative, the matrix is generated such that + +```text +[ + x_0^(N-1) ... x_0^2 x_0^1 1 + x_1^(N-1) ... x_1^2 x_1^1 1 + ... +] +``` + +with decreasing powers along the rows. + +
+ + + +
+ +## Notes + +- If `M <= 0` or `N <= 0`, the function returns the output ndarray unchanged. +- The function supports array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var gvander = require( '@stdlib/blas/ext/base/ndarray/gvander' ); + +var M = 3; +var N = 4; + +var opts = { + 'dtype': 'generic' +}; + +var x = discreteUniform( [ M ], 0, 10, opts ); +console.log( ndarray2array( x ) ); + +var out = zeros( [ M, N ], opts ); + +var mode = scalar2ndarray( -1, { + 'dtype': 'generic' +}); + +var v = gvander( [ x, out, mode ] ); +console.log( ndarray2array( v ) ); +``` + +
+ + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/benchmark/benchmark.js new file mode 100644 index 000000000000..d6f86d79c619 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/benchmark/benchmark.js @@ -0,0 +1,115 @@ +/** +* @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/uniform' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var pkg = require( './../package.json' ).name; +var gvander = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var mode; + var out; + var x; + + x = uniform( [ len ], -10.0, 10.0, options ); + out = zeros( [ len, len ], options ); + + mode = scalar2ndarray( 1, { + 'dtype': 'generic' + }); + + 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++ ) { + v = gvander( [ x, out, mode ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( v.get( i%len, i%len ) ) ) { + 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/ndarray/gvander/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/repl.txt new file mode 100644 index 000000000000..d75dc5b00044 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/repl.txt @@ -0,0 +1,53 @@ + +{{alias}}( arrays ) + 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) + 1 x_1^1 x_1^2 ... x_1^(N-1) + ... + ] + + with increasing powers along the rows. + + When the mode is negative, the matrix is generated such that + + [ + x_0^(N-1) ... x_0^2 x_0^1 1 + x_1^(N-1) ... x_1^2 x_1^1 1 + ... + ] + + with decreasing powers along the rows. + + If `M <= 0` or `N <= 0`, the function returns the output ndarray + unchanged. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a two-dimensional output ndarray. + - a zero-dimensional ndarray specifying the mode. + + Returns + ------- + out: ndarray + Output ndarray. + + Examples + -------- + > var x = new {{alias:@stdlib/ndarray/vector}}( 'generic', [ 1.0, 2.0, 3.0 ] ); + > var out = {{alias:@stdlib/ndarray/zeros}}( [ 3, 3 ], { 'dtype': 'generic' } ); + > var mode = {{alias:@stdlib/ndarray/from-scalar}}( 1, { 'dtype': 'generic' } ); + > {{alias}}( [ x, out, mode ] ); + > out + [ [ 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/ndarray/gvander/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/types/index.d.ts new file mode 100644 index 000000000000..73b79cdede00 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/types/index.d.ts @@ -0,0 +1,64 @@ +/* +* @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 { typedndarray } from '@stdlib/types/ndarray'; + +/** +* Generates a Vandermonde matrix. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a two-dimensional output ndarray. +* - a zero-dimensional ndarray specifying the mode. +* +* @param arrays - array-like object containing ndarrays +* @returns output ndarray +* +* @example +* var Vector = require( '@stdlib/ndarray/vector' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var x = new Vector( 'generic', [ 1.0, 2.0, 3.0 ] ); +* var out = zeros( [ 3, 3 ], { +* 'dtype': 'generic' +* }); +* +* var mode = scalar2ndarray( 1, { +* 'dtype': 'generic' +* }); +* +* var v = gvander( [ x, out, mode ] ); +* // returns [ [ 1.0, 1.0, 1.0 ], [ 1.0, 2.0, 4.0 ], [ 1.0, 3.0, 9.0 ] ] +* +* var bool = ( v === out ); +* // returns true +*/ +declare function gvander = typedndarray>( arrays: [ typedndarray, T, typedndarray ] ): T; + + +// EXPORTS // + +export = gvander; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/types/test.ts new file mode 100644 index 000000000000..58cc2b30a896 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/types/test.ts @@ -0,0 +1,70 @@ +/* +* @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 space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +import gvander = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 3 ], { + 'dtype': 'generic' + }); + const out = zeros( [ 3, 3 ], { + 'dtype': 'generic' + }); + const mode = scalar2ndarray( 1, { + 'dtype': 'generic' + }); + + gvander( [ x, out, mode ] ); // $ExpectType genericndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + gvander( '10' ); // $ExpectError + gvander( 10 ); // $ExpectError + gvander( true ); // $ExpectError + gvander( false ); // $ExpectError + gvander( null ); // $ExpectError + gvander( undefined ); // $ExpectError + gvander( [] ); // $ExpectError + gvander( {} ); // $ExpectError + gvander( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 3 ], { + 'dtype': 'generic' + }); + const out = zeros( [ 3, 3 ], { + 'dtype': 'generic' + }); + const mode = scalar2ndarray( 1, { + 'dtype': 'generic' + }); + + gvander(); // $ExpectError + gvander( [ x, out, mode ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/examples/index.js new file mode 100644 index 000000000000..7d6ed5d6db31 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/examples/index.js @@ -0,0 +1,44 @@ +/** +* @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/discrete-uniform' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var gvander = require( './../lib' ); + +var M = 3; +var N = 4; + +var opts = { + 'dtype': 'generic' +}; + +var x = discreteUniform( [ M ], 0, 10, opts ); +console.log( ndarray2array( x ) ); + +var out = zeros( [ M, N ], opts ); + +var mode = scalar2ndarray( -1, { + 'dtype': 'generic' +}); + +var v = gvander( [ x, out, mode ] ); +console.log( ndarray2array( v ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/lib/index.js new file mode 100644 index 000000000000..0f5766088d5c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/lib/index.js @@ -0,0 +1,55 @@ +/** +* @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/ndarray/gvander +* +* @example +* var Vector = require( '@stdlib/ndarray/vector' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var gvander = require( '@stdlib/blas/ext/base/ndarray/gvander' ); +* +* var x = new Vector( 'generic', [ 1.0, 2.0, 3.0 ] ); +* var out = zeros( [ 3, 3 ], { +* 'dtype': 'generic' +* }); +* +* var mode = scalar2ndarray( 1, { +* 'dtype': 'generic' +* }); +* +* var v = gvander( [ x, out, mode ] ); +* // returns [ [ 1.0, 1.0, 1.0 ], [ 1.0, 2.0, 4.0 ], [ 1.0, 3.0, 9.0 ] ] +* +* var bool = ( v === out ); +* // returns true +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/lib/main.js new file mode 100644 index 000000000000..8f3e46def731 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/lib/main.js @@ -0,0 +1,87 @@ +/** +* @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 ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +var numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getStrides = require( '@stdlib/ndarray/base/strides' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var strided = require( '@stdlib/blas/ext/base/gvander' ).ndarray; + + +// MAIN // + +/** +* Generates a Vandermonde matrix. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a two-dimensional output ndarray. +* - a zero-dimensional ndarray specifying the mode. +* +* @param {ArrayLikeObject} arrays - array-like object containing ndarrays +* @returns {Object} output ndarray +* +* @example +* var Vector = require( '@stdlib/ndarray/vector' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var x = new Vector( 'generic', [ 1.0, 2.0, 3.0 ] ); +* var out = zeros( [ 3, 3 ], { +* 'dtype': 'generic' +* }); +* +* var mode = scalar2ndarray( 1, { +* 'dtype': 'generic' +* }); +* +* var v = gvander( [ x, out, mode ] ); +* // returns [ [ 1.0, 1.0, 1.0 ], [ 1.0, 2.0, 4.0 ], [ 1.0, 3.0, 9.0 ] ] +* +* var bool = ( v === out ); +* // returns true +*/ +function gvander( arrays ) { + var mode; + var out; + var so; + var x; + + x = arrays[ 0 ]; + out = arrays[ 1 ]; + mode = ndarraylike2scalar( arrays[ 2 ] ); + + so = getStrides( out, false ); + + strided( mode, numelDimension( out, 0 ), numelDimension( out, 1 ), getData( x ), getStride( x, 0 ), getOffset( x ), getData( out ), so[ 0 ], so[ 1 ], getOffset( out ) ); // eslint-disable-line max-len + return out; +} + + +// EXPORTS // + +module.exports = gvander; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/package.json new file mode 100644 index 000000000000..d3701e35b556 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/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", + "ndarray", + "array", + "typed", + "strided" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/test/test.js new file mode 100644 index 000000000000..f2b6630f8a37 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/test/test.js @@ -0,0 +1,475 @@ +/** +* @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 scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var gvander = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} N - number of elements +* @param {integer} stride - stride +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, N, stride, offset ) { + return new ndarray( 'generic', buffer, [ N ], [ stride ], offset, 'row-major' ); +} + +/** +* Returns a two-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @param {integer} stride0 - stride of the first dimension +* @param {integer} stride1 - stride of the second dimension +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} two-dimensional ndarray +*/ +function matrix( buffer, M, N, stride0, stride1, offset ) { + return new ndarray( 'generic', buffer, [ M, N ], [ stride0, stride1 ], offset, 'row-major' ); +} + + +// 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 1', function test( t ) { + t.strictEqual( gvander.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (row-major, increasing)', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0, 3.0 ], 3, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 3, 3, 1, 0 ); + + mode = scalar2ndarray( 1, { + 'dtype': 'generic' + }); + v = gvander( [ x, out, mode ] ); + + expected = [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ]; + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (row-major, decreasing)', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0, 3.0 ], 3, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 3, 3, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'generic' + }); + v = gvander( [ x, out, mode ] ); + + expected = [ 1.0, 1.0, 1.0, 4.0, 2.0, 1.0, 9.0, 3.0, 1.0 ]; + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (column-major, increasing)', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0, 3.0 ], 3, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 3, 1, 3, 0 ); + + mode = scalar2ndarray( 1, { + 'dtype': 'generic' + }); + v = gvander( [ x, out, mode ] ); + + expected = [ 1.0, 1.0, 1.0, 1.0, 2.0, 3.0, 1.0, 4.0, 9.0 ]; + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (column-major, decreasing)', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0, 3.0 ], 3, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 3, 1, 3, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'generic' + }); + v = gvander( [ x, out, mode ] ); + + expected = [ 1.0, 4.0, 9.0, 1.0, 2.0, 3.0, 1.0, 1.0, 1.0 ]; + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a reference to the output ndarray', function test( t ) { + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0 ], 2, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0 ], 2, 2, 2, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'generic' + }); + v = gvander( [ x, out, mode ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `M` equal to `0`, the function returns the output ndarray unchanged', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + out = matrix( [ 3.0, 4.0, 5.0, 6.0 ], 0, 3, 3, 1, 0 ); + expected = [ 3.0, 4.0, 5.0, 6.0 ]; + + x = vector( [], 0, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'generic' + }); + v = gvander( [ x, out, mode ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `N` equal to `0`, the function returns the output ndarray unchanged', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + out = matrix( [ 3.0, 4.0, 5.0, 6.0 ], 2, 0, 0, 1, 0 ); + expected = [ 3.0, 4.0, 5.0, 6.0 ]; + + x = vector( [ 1.0, 2.0 ], 2, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'generic' + }); + v = gvander( [ x, out, mode ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports input ndarrays with strides', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 0.0, 3.0, 0.0 ], 2, 2, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 2, 3, 3, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'generic' + }); + v = gvander( [ x, out, mode ] ); + + expected = [ 1.0, 1.0, 1.0, 9.0, 3.0, 1.0 ]; + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports input ndarrays with negative strides', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 3.0, 0.0, 1.0 ], 2, -2, 2 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 2, 3, 3, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'generic' + }); + v = gvander( [ x, out, mode ] ); + + expected = [ 1.0, 1.0, 1.0, 9.0, 3.0, 1.0 ]; + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays having non-zero offsets', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 0.0, 1.0, 2.0, 3.0 ], 3, 1, 1 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 3, 3, 1, 2 ); + + mode = scalar2ndarray( 1, { + 'dtype': 'generic' + }); + v = gvander( [ x, out, mode ] ); + + expected = [ 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ]; + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports output ndarrays with negative strides', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0, 3.0 ], 3, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 3, -3, 1, 6 ); + + mode = scalar2ndarray( 1, { + 'dtype': 'generic' + }); + v = gvander( [ x, out, mode ] ); + + expected = [ 1.0, 3.0, 9.0, 1.0, 2.0, 4.0, 1.0, 1.0, 1.0 ]; + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports output stride with padding (row-major)', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0 ], 2, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 2, 3, 5, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'generic' + }); + v = gvander( [ x, out, mode ] ); + + expected = [ + 1.0, + 1.0, + 1.0, + 0.0, + 0.0, + 4.0, + 2.0, + 1.0, + 0.0, + 0.0 + ]; + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports output stride with padding (column-major)', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0 ], 2, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 2, 3, 1, 4, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'generic' + }); + v = gvander( [ x, out, mode ] ); + + 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.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports non-square matrices (M > N, row-major, decreasing)', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0, 3.0 ], 3, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 2, 2, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'generic' + }); + v = gvander( [ x, out, mode ] ); + + expected = [ 1.0, 1.0, 2.0, 1.0, 3.0, 1.0 ]; + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports non-square matrices (M < N, row-major, increasing)', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 2.0, 3.0 ], 2, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 2, 4, 4, 1, 0 ); + + mode = scalar2ndarray( 1, { + 'dtype': 'generic' + }); + v = gvander( [ x, out, mode ] ); + + expected = [ 1.0, 2.0, 4.0, 8.0, 1.0, 3.0, 9.0, 27.0 ]; + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), 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 mode; + var out; + var x; + var v; + + x = vector( [ 0.0, 2.0 ], 2, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 2, 3, 3, 1, 0 ); + + mode = scalar2ndarray( 1, { + 'dtype': 'generic' + }); + v = gvander( [ x, out, mode ] ); + + expected = [ 1.0, 0.0, 0.0, 1.0, 2.0, 4.0 ]; + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles a single column (N=1)', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 5.0, 10.0, 15.0 ], 3, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0 ], 3, 1, 1, 1, 0 ); + + mode = scalar2ndarray( 1, { + 'dtype': 'generic' + }); + v = gvander( [ x, out, mode ] ); + + expected = [ 1.0, 1.0, 1.0 ]; + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles a single row (M=1)', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 3.0 ], 1, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0 ], 1, 4, 4, 1, 0 ); + + mode = scalar2ndarray( 1, { + 'dtype': 'generic' + }); + v = gvander( [ x, out, mode ] ); + + expected = [ 1.0, 3.0, 9.0, 27.0 ]; + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); From bc8dcd00899f6bcb077760ff34e389e79e906d81 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Mon, 21 Sep 2026 22:28:26 +0500 Subject: [PATCH 2/3] fix: lint err --- .../@stdlib/blas/ext/base/ndarray/gvander/README.md | 5 ++--- .../@stdlib/blas/ext/base/ndarray/gvander/docs/repl.txt | 2 +- .../blas/ext/base/ndarray/gvander/docs/types/index.d.ts | 4 ++-- .../@stdlib/blas/ext/base/ndarray/gvander/lib/index.js | 4 ++-- .../@stdlib/blas/ext/base/ndarray/gvander/lib/main.js | 4 ++-- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/README.md index 2ba54e6d0467..93da93963eeb 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/README.md @@ -41,12 +41,11 @@ var gvander = require( '@stdlib/blas/ext/base/ndarray/gvander' ); Generates a Vandermonde matrix. ```javascript -var Vector = require( '@stdlib/ndarray/vector' ); +var vector = require( '@stdlib/ndarray/vector/ctor' ); var zeros = require( '@stdlib/ndarray/zeros' ); var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var x = new Vector( 'generic', [ 1.0, 2.0, 3.0 ] ); +var x = vector( [ 1.0, 2.0, 3.0 ], 'generic' ); var out = zeros( [ 3, 3 ], { 'dtype': 'generic' }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/repl.txt index d75dc5b00044..14ca8dcd64d4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/repl.txt @@ -41,7 +41,7 @@ Examples -------- - > var x = new {{alias:@stdlib/ndarray/vector}}( 'generic', [ 1.0, 2.0, 3.0 ] ); + > var x = {{alias:@stdlib/ndarray/vector/ctor}}( [ 1.0, 2.0, 3.0 ], 'generic' ); > var out = {{alias:@stdlib/ndarray/zeros}}( [ 3, 3 ], { 'dtype': 'generic' } ); > var mode = {{alias:@stdlib/ndarray/from-scalar}}( 1, { 'dtype': 'generic' } ); > {{alias}}( [ x, out, mode ] ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/types/index.d.ts index 73b79cdede00..373aac56b60a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/types/index.d.ts @@ -37,11 +37,11 @@ import { typedndarray } from '@stdlib/types/ndarray'; * @returns output ndarray * * @example -* var Vector = require( '@stdlib/ndarray/vector' ); +* var vector = require( '@stdlib/ndarray/vector/ctor' ); * var zeros = require( '@stdlib/ndarray/zeros' ); * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * -* var x = new Vector( 'generic', [ 1.0, 2.0, 3.0 ] ); +* var x = vector( [ 1.0, 2.0, 3.0 ], 'generic' ); * var out = zeros( [ 3, 3 ], { * 'dtype': 'generic' * }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/lib/index.js index 0f5766088d5c..c230d9b278a0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/lib/index.js @@ -24,12 +24,12 @@ * @module @stdlib/blas/ext/base/ndarray/gvander * * @example -* var Vector = require( '@stdlib/ndarray/vector' ); +* var vector = require( '@stdlib/ndarray/vector/ctor' ); * var zeros = require( '@stdlib/ndarray/zeros' ); * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * var gvander = require( '@stdlib/blas/ext/base/ndarray/gvander' ); * -* var x = new Vector( 'generic', [ 1.0, 2.0, 3.0 ] ); +* var x = vector( [ 1.0, 2.0, 3.0 ], 'generic' ); * var out = zeros( [ 3, 3 ], { * 'dtype': 'generic' * }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/lib/main.js index 8f3e46def731..37a558dbc9a7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/lib/main.js @@ -46,11 +46,11 @@ var strided = require( '@stdlib/blas/ext/base/gvander' ).ndarray; * @returns {Object} output ndarray * * @example -* var Vector = require( '@stdlib/ndarray/vector' ); +* var vector = require( '@stdlib/ndarray/vector/ctor' ); * var zeros = require( '@stdlib/ndarray/zeros' ); * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * -* var x = new Vector( 'generic', [ 1.0, 2.0, 3.0 ] ); +* var x = vector( [ 1.0, 2.0, 3.0 ], 'generic' ); * var out = zeros( [ 3, 3 ], { * 'dtype': 'generic' * }); From 8a4b738db194bd9cde89fa41c108f8a495b6207f Mon Sep 17 00:00:00 2001 From: headlessNode Date: Tue, 22 Sep 2026 19:13:37 +0500 Subject: [PATCH 3/3] fix: apply suggestions from code review --- .../@stdlib/blas/ext/base/ndarray/gvander/README.md | 4 ++-- .../blas/ext/base/ndarray/gvander/docs/repl.txt | 6 +++--- .../ext/base/ndarray/gvander/docs/types/index.d.ts | 2 +- .../@stdlib/blas/ext/base/ndarray/gvander/lib/main.js | 6 ++++-- .../@stdlib/blas/ext/base/ndarray/gvander/test/test.js | 10 +++++----- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/README.md index 93da93963eeb..2db633f1c2da 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/README.md @@ -69,7 +69,7 @@ The function has the following parameters: - a two-dimensional output ndarray. - a zero-dimensional ndarray specifying the mode. -When the mode is positive, the matrix is generated such that +Let the output ndarray have shape `[M, N]`. When the mode is positive, the matrix is generated such that ```text [ @@ -101,7 +101,7 @@ with decreasing powers along the rows. ## Notes -- If `M <= 0` or `N <= 0`, the function returns the output ndarray unchanged. +- Let the output ndarray have shape `[M, N]`. If `M <= 0` or `N <= 0`, the function returns the output ndarray unchanged. - The function supports array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/repl.txt index 14ca8dcd64d4..cf9186ffa611 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/repl.txt @@ -2,7 +2,8 @@ {{alias}}( arrays ) Generates a Vandermonde matrix. - When the mode is positive, the matrix is generated such that + Let the output ndarray have shape `[M, N]`. When the mode is positive, + the matrix is generated such that [ 1 x_0^1 x_0^2 ... x_0^(N-1) @@ -22,8 +23,7 @@ with decreasing powers along the rows. - If `M <= 0` or `N <= 0`, the function returns the output ndarray - unchanged. + If `M <= 0` or `N <= 0`, the function returns the output ndarray unchanged. Parameters ---------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/types/index.d.ts index 373aac56b60a..20e4854b712e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/docs/types/index.d.ts @@ -56,7 +56,7 @@ import { typedndarray } from '@stdlib/types/ndarray'; * var bool = ( v === out ); * // returns true */ -declare function gvander = typedndarray>( arrays: [ typedndarray, T, typedndarray ] ): T; +declare function gvander = typedndarray>( arrays: [ typedndarray, U, typedndarray ] ): U; // EXPORTS // diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/lib/main.js index 37a558dbc9a7..68704e4ed808 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); -var numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getShape = require( '@stdlib/ndarray/base/shape' ); var getStrides = require( '@stdlib/ndarray/base/strides' ); var getStride = require( '@stdlib/ndarray/base/stride' ); var getOffset = require( '@stdlib/ndarray/base/offset' ); @@ -68,6 +68,7 @@ var strided = require( '@stdlib/blas/ext/base/gvander' ).ndarray; function gvander( arrays ) { var mode; var out; + var sh; var so; var x; @@ -75,9 +76,10 @@ function gvander( arrays ) { out = arrays[ 1 ]; mode = ndarraylike2scalar( arrays[ 2 ] ); + sh = getShape( out, false ); so = getStrides( out, false ); - strided( mode, numelDimension( out, 0 ), numelDimension( out, 1 ), getData( x ), getStride( x, 0 ), getOffset( x ), getData( out ), so[ 0 ], so[ 1 ], getOffset( out ) ); // eslint-disable-line max-len + strided( mode, sh[ 0 ], sh[ 1 ], getData( x ), getStride( x, 0 ), getOffset( x ), getData( out ), so[ 0 ], so[ 1 ], getOffset( out ) ); // eslint-disable-line max-len return out; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/test/test.js index f2b6630f8a37..909db00dee56 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/test/test.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gvander/test/test.js @@ -175,7 +175,7 @@ tape( 'the function returns a reference to the output ndarray', function test( t t.end(); }); -tape( 'if provided `M` equal to `0`, the function returns the output ndarray unchanged', function test( t ) { +tape( 'if provided an empty input ndarray, the function returns the output ndarray unchanged', function test( t ) { var expected; var mode; var out; @@ -197,7 +197,7 @@ tape( 'if provided `M` equal to `0`, the function returns the output ndarray unc t.end(); }); -tape( 'if provided `N` equal to `0`, the function returns the output ndarray unchanged', function test( t ) { +tape( 'if not provided an output ndarray with at least one column, the function returns the output ndarray unchanged', function test( t ) { var expected; var mode; var out; @@ -303,7 +303,7 @@ tape( 'the function supports output ndarrays with negative strides', function te t.end(); }); -tape( 'the function supports output stride with padding (row-major)', function test( t ) { +tape( 'the function supports output ndarrays having non-unit strides (row-major)', function test( t ) { var expected; var mode; var out; @@ -335,7 +335,7 @@ tape( 'the function supports output stride with padding (row-major)', function t t.end(); }); -tape( 'the function supports output stride with padding (column-major)', function test( t ) { +tape( 'the function supports output ndarrays having non-unit strides (column-major)', function test( t ) { var expected; var mode; var out; @@ -411,7 +411,7 @@ tape( 'the function supports non-square matrices (M < N, row-major, increasing)' t.end(); }); -tape( 'the function handles zero values in the input array (row-major, increasing)', function test( t ) { +tape( 'the function handles zero values in the input ndarray (row-major, increasing)', function test( t ) { var expected; var mode; var out;