diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/README.md new file mode 100644 index 000000000000..0daeb387947c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/README.md @@ -0,0 +1,171 @@ + + +# dvander + +> Generate a double-precision floating-point Vandermonde matrix. + +
+ +
+ + + +
+ +## Usage + +```javascript +var dvander = require( '@stdlib/blas/ext/base/ndarray/dvander' ); +``` + +#### dvander( arrays ) + +Generates a double-precision floating-point Vandermonde matrix. + +```javascript +var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); + +var x = new Float64Vector( [ 1.0, 2.0, 3.0 ] ); +var out = zeros( [ 3, 3 ], { + 'dtype': 'float64' +}); + +var mode = scalar2ndarray( 1, { + 'dtype': 'float64' +}); + +var v = dvander( [ 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. + +Let the output ndarray have shape `[M, N]`. 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 + +- Let the output ndarray have shape `[M, N]`. If `M <= 0` or `N <= 0`, the function returns the output ndarray unchanged. + +
+ + + +
+ +## 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 dvander = require( '@stdlib/blas/ext/base/ndarray/dvander' ); + +var M = 3; +var N = 4; + +var opts = { + 'dtype': 'float64' +}; + +var x = discreteUniform( [ M ], 0, 10, opts ); +console.log( ndarray2array( x ) ); + +var out = zeros( [ M, N ], opts ); + +var mode = scalar2ndarray( -1, { + 'dtype': 'float64' +}); + +var v = dvander( [ x, out, mode ] ); +console.log( ndarray2array( v ) ); +``` + +
+ + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/benchmark/benchmark.js new file mode 100644 index 000000000000..4f5e12c5227c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/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 dvander = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// 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': 'float64' + }); + + 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 = dvander( [ 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/dvander/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/docs/repl.txt new file mode 100644 index 000000000000..a78c65f6f86e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/docs/repl.txt @@ -0,0 +1,54 @@ + +{{alias}}( arrays ) + Generates a double-precision floating-point Vandermonde matrix. + + 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) + 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/float64}}( [ 1.0, 2.0, 3.0 ] ); + > var out = {{alias:@stdlib/ndarray/zeros}}( [ 3, 3 ], { 'dtype': 'float64' } ); + > var mode = {{alias:@stdlib/ndarray/from-scalar}}( 1, { 'dtype': 'float64' } ); + > {{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/dvander/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/docs/types/index.d.ts new file mode 100644 index 000000000000..7bbadf1f2eb4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/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 { float64ndarray, typedndarray } from '@stdlib/types/ndarray'; + +/** +* Generates a double-precision floating-point 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 Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var x = new Float64Vector( [ 1.0, 2.0, 3.0 ] ); +* var out = zeros( [ 3, 3 ], { +* 'dtype': 'float64' +* }); +* +* var mode = scalar2ndarray( 1, { +* 'dtype': 'float64' +* }); +* +* var v = dvander( [ 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 dvander( arrays: [ float64ndarray, float64ndarray, typedndarray ] ): float64ndarray; + + +// EXPORTS // + +export = dvander; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/docs/types/test.ts new file mode 100644 index 000000000000..9c02211aa2e1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/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 dvander = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 3 ], { + 'dtype': 'float64' + }); + const out = zeros( [ 3, 3 ], { + 'dtype': 'float64' + }); + const mode = scalar2ndarray( 1, { + 'dtype': 'float64' + }); + + dvander( [ x, out, mode ] ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + dvander( '10' ); // $ExpectError + dvander( 10 ); // $ExpectError + dvander( true ); // $ExpectError + dvander( false ); // $ExpectError + dvander( null ); // $ExpectError + dvander( undefined ); // $ExpectError + dvander( [] ); // $ExpectError + dvander( {} ); // $ExpectError + dvander( ( 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': 'float64' + }); + const out = zeros( [ 3, 3 ], { + 'dtype': 'float64' + }); + const mode = scalar2ndarray( 1, { + 'dtype': 'float64' + }); + + dvander(); // $ExpectError + dvander( [ x, out, mode ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/examples/index.js new file mode 100644 index 000000000000..8ee53e93d121 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/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 dvander = require( './../lib' ); + +var M = 3; +var N = 4; + +var opts = { + 'dtype': 'float64' +}; + +var x = discreteUniform( [ M ], 0, 10, opts ); +console.log( ndarray2array( x ) ); + +var out = zeros( [ M, N ], opts ); + +var mode = scalar2ndarray( -1, { + 'dtype': 'float64' +}); + +var v = dvander( [ x, out, mode ] ); +console.log( ndarray2array( v ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/lib/index.js new file mode 100644 index 000000000000..a689dd814402 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/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 double-precision floating-point Vandermonde matrix. +* +* @module @stdlib/blas/ext/base/ndarray/dvander +* +* @example +* var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var dvander = require( '@stdlib/blas/ext/base/ndarray/dvander' ); +* +* var x = new Float64Vector( [ 1.0, 2.0, 3.0 ] ); +* var out = zeros( [ 3, 3 ], { +* 'dtype': 'float64' +* }); +* +* var mode = scalar2ndarray( 1, { +* 'dtype': 'float64' +* }); +* +* var v = dvander( [ 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/dvander/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/lib/main.js new file mode 100644 index 000000000000..bd83966b2283 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/lib/main.js @@ -0,0 +1,89 @@ +/** +* @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 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' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var strided = require( '@stdlib/blas/ext/base/dvander' ).ndarray; + + +// MAIN // + +/** +* Generates a double-precision floating-point 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 Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var x = new Float64Vector( [ 1.0, 2.0, 3.0 ] ); +* var out = zeros( [ 3, 3 ], { +* 'dtype': 'float64' +* }); +* +* var mode = scalar2ndarray( 1, { +* 'dtype': 'float64' +* }); +* +* var v = dvander( [ 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 dvander( arrays ) { + var mode; + var out; + var sh; + var so; + var x; + + x = arrays[ 0 ]; + out = arrays[ 1 ]; + mode = ndarraylike2scalar( arrays[ 2 ] ); + + sh = getShape( out, false ); + so = getStrides( out, false ); + + 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; +} + + +// EXPORTS // + +module.exports = dvander; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/package.json new file mode 100644 index 000000000000..ed25bb0b374a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/package.json @@ -0,0 +1,72 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/dvander", + "version": "0.0.0", + "description": "Generate a double-precision floating-point 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", + "dvander", + "vandermonde", + "matrix", + "generate", + "ndarray", + "array", + "typed", + "strided", + "float64", + "float", + "double", + "float64array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/test/test.js new file mode 100644 index 000000000000..06add65eeb73 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/test/test.js @@ -0,0 +1,476 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var dvander = 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( 'float64', new Float64Array( 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( 'float64', new Float64Array( 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 dvander, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( dvander.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': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 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': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 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': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 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': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 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': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an empty input ndarray, 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 = new Float64Array( [ 3.0, 4.0, 5.0, 6.0 ] ); + + x = vector( [], 0, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +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; + var x; + var v; + + out = matrix( [ 3.0, 4.0, 5.0, 6.0 ], 2, 0, 0, 1, 0 ); + expected = new Float64Array( [ 3.0, 4.0, 5.0, 6.0 ] ); + + x = vector( [ 1.0, 2.0 ], 2, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'float64' + }); + v = dvander( [ 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': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 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': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 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': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 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': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 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 ndarrays having non-unit strides (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': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array([ + 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 ndarrays having non-unit strides (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': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array([ + 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': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 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': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 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 ndarray (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': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 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': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 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': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 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(); +});