diff --git a/lib/node_modules/@stdlib/blas/ext/zero-to/README.md b/lib/node_modules/@stdlib/blas/ext/zero-to/README.md new file mode 100644 index 000000000000..fc3fc7e9e292 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/README.md @@ -0,0 +1,139 @@ + + +# zeroTo + +> Fill an [ndarray][@stdlib/ndarray/ctor] with linearly spaced numeric elements which increment by `1` starting from zero. + +
+ +## Usage + +```javascript +var zeroTo = require( '@stdlib/blas/ext/zero-to' ); +``` + +#### zeroTo( x\[, options] ) + +Fills an [ndarray][@stdlib/ndarray/ctor] with linearly spaced numeric elements which increment by `1` starting from zero. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ 0.0, 0.0, 0.0 ] ); +// returns [ 0.0, 0.0, 0.0 ] + +var y = zeroTo( x ); +// returns [ 0.0, 1.0, 2.0 ] + +var bool = ( x === y ); +// returns true +``` + +The function has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a numeric or "generic" [data type][@stdlib/ndarray/dtypes]. +- **options**: function options (_optional_). + +The function accepts the following options: + +- **dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. + +By default, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. To perform the operation over specific dimensions, provide a `dims` option. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ 0.0, 0.0, 0.0, 0.0 ], { + 'shape': [ 2, 2 ], + 'order': 'row-major' +}); +// returns [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] + +var y = zeroTo( x, { + 'dims': [ 1 ] +}); +// returns [ [ 0.0, 1.0 ], [ 0.0, 1.0 ] ] +``` + +
+ + + +
+ +## Notes + +- The input [ndarray][@stdlib/ndarray/ctor] is filled **in-place** (i.e., the input [ndarray][@stdlib/ndarray/ctor] is **mutated**). +- The function iterates over [ndarray][@stdlib/ndarray/ctor] elements according to the memory layout of the input [ndarray][@stdlib/ndarray/ctor]. Accordingly, performance degradation is possible when operating over multiple dimensions of a large non-contiguous multi-dimensional input [ndarray][@stdlib/ndarray/ctor]. In such scenarios, one may want to copy an input [ndarray][@stdlib/ndarray/ctor] to contiguous memory before performing the operation. + +
+ + + +
+ +## Examples + + + +```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var zeroTo = require( '@stdlib/blas/ext/zero-to' ); + +// Create a zeros-filled ndarray: +var x = zeros( [ 5, 5 ], { + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +// Perform operation: +zeroTo( x, { + 'dims': [ 1 ] +}); + +// Print the results: +console.log( ndarray2array( x ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/zero-to/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/zero-to/benchmark/benchmark.js new file mode 100644 index 000000000000..44081ea85996 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var zeros = require( '@stdlib/array/zeros' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var zeroTo = 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 x = zeros( len, options.dtype ); + x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var o; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = zeroTo( x ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( o.get( 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 = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:dtype=%s,len=%d', pkg, options.dtype, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/zero-to/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/zero-to/docs/repl.txt new file mode 100644 index 000000000000..2ee8e80bf0f7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/docs/repl.txt @@ -0,0 +1,33 @@ + +{{alias}}( x[, options] ) + Fills an ndarray with linearly spaced numeric elements which increment by + 1 starting from zero. + + The function fills an ndarray in-place and thus mutates the input ndarray. + + Parameters + ---------- + x: ndarray + Input array. Must have a numeric or "generic" data type. + + options: Object (optional) + Function options. + + options.dims: Array (optional) + List of dimensions over which to perform operation. If not provided, + the function performs the operation over all elements in a provided + input ndarray. + + Returns + ------- + out: ndarray + Input array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ 0.0, 0.0, 0.0 ] ); + > var y = {{alias}}( x ) + [ 0.0, 1.0, 2.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/zero-to/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/zero-to/docs/types/index.d.ts new file mode 100644 index 000000000000..78e95cfd8694 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/docs/types/index.d.ts @@ -0,0 +1,88 @@ +/* +* @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 { ArrayLike } from '@stdlib/types/array'; +import { typedndarray, genericndarray } from '@stdlib/types/ndarray'; + +/** +* Input array. +*/ +type InputArray = typedndarray | genericndarray; + +/** +* Interface defining options. +*/ +interface Options { + /** + * List of dimensions over which to perform operation. + */ + dims?: ArrayLike; +} + +/** + * Fills an ndarray with linearly spaced numeric elements which increment by 1 starting from zero. + * + * ## Notes + * + * - The input ndarray is filled **in-place** (i.e., the input ndarray is **mutated**). + * + * @param x - input ndarray + * @param options - function options + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ 0.0, 0.0, 0.0 ] ); + * // returns [ 0.0, 0.0, 0.0 ] + * + * var y = zeroTo( x ); + * // returns [ 0.0, 1.0, 2.0 ] + */ +type ZeroTo = ( x: T, options?: Options ) => T; + +/** +* Fills an ndarray with linearly spaced numeric elements which increment by 1 starting from zero. +* +* ## Notes +* +* - The input ndarray is filled **in-place** (i.e., the input ndarray is **mutated**). +* +* @param x - input ndarray +* @param options - function options +* @returns output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ 0.0, 0.0, 0.0 ] ); +* // returns [ 0.0, 0.0, 0.0 ] +* +* var y = zeroTo( x ); +* // returns [ 0.0, 1.0, 2.0 ] +*/ +declare const zeroTo: ZeroTo; + + +// EXPORTS // + +export = zeroTo; diff --git a/lib/node_modules/@stdlib/blas/ext/zero-to/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/zero-to/docs/types/test.ts new file mode 100644 index 000000000000..b080e3311add --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/docs/types/test.ts @@ -0,0 +1,98 @@ +/* +* @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 zeroTo = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + zeroTo( x ); // $ExpectType float64ndarray + zeroTo( x, {} ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + zeroTo( '5' ); // $ExpectError + zeroTo( 5 ); // $ExpectError + zeroTo( true ); // $ExpectError + zeroTo( false ); // $ExpectError + zeroTo( null ); // $ExpectError + zeroTo( void 0 ); // $ExpectError + zeroTo( {} ); // $ExpectError + zeroTo( ( x: number ): number => x ); // $ExpectError + + zeroTo( '5', {} ); // $ExpectError + zeroTo( 5, {} ); // $ExpectError + zeroTo( true, {} ); // $ExpectError + zeroTo( false, {} ); // $ExpectError + zeroTo( null, {} ); // $ExpectError + zeroTo( void 0, {} ); // $ExpectError + zeroTo( {}, {} ); // $ExpectError + zeroTo( ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an options argument which is not an object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + zeroTo( x, '5' ); // $ExpectError + zeroTo( x, 5 ); // $ExpectError + zeroTo( x, true ); // $ExpectError + zeroTo( x, false ); // $ExpectError + zeroTo( x, null ); // $ExpectError + zeroTo( x, [] ); // $ExpectError + zeroTo( x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dims` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + zeroTo( x, { 'dims': '5' } ); // $ExpectError + zeroTo( x, { 'dims': 5 } ); // $ExpectError + zeroTo( x, { 'dims': true } ); // $ExpectError + zeroTo( x, { 'dims': false } ); // $ExpectError + zeroTo( x, { 'dims': null } ); // $ExpectError + zeroTo( x, { 'dims': {} } ); // $ExpectError + zeroTo( x, { 'dims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + zeroTo(); // $ExpectError + zeroTo( x, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/zero-to/examples/index.js b/lib/node_modules/@stdlib/blas/ext/zero-to/examples/index.js new file mode 100644 index 000000000000..8a3986530735 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/examples/index.js @@ -0,0 +1,37 @@ +/** +* @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 ndarray2array = require( '@stdlib/ndarray/to-array' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var zeroTo = require( './../lib' ); + +// Create a zeros-filled ndarray: +var x = zeros( [ 5, 5 ], { + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +// Perform operation: +zeroTo( x, { + 'dims': [ 1 ] +}); + +// Print the results: +console.log( ndarray2array( x ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/zero-to/lib/index.js b/lib/node_modules/@stdlib/blas/ext/zero-to/lib/index.js new file mode 100644 index 000000000000..49059ba2f382 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/lib/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'; + +/** +* Fill an ndarray with linearly spaced numeric elements which increment by 1 starting from zero. +* +* @module @stdlib/blas/ext/zero-to +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var zeroTo = require( '@stdlib/blas/ext/zero-to' ); +* +* var x = array( [ 0.0, 0.0, 0.0 ] ); +* // returns [ 0.0, 0.0, 0.0 ] +* +* var y = zeroTo( x ); +* // returns [ 0.0, 1.0, 2.0 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/zero-to/lib/main.js b/lib/node_modules/@stdlib/blas/ext/zero-to/lib/main.js new file mode 100644 index 000000000000..bc4d6664fe4b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/lib/main.js @@ -0,0 +1,88 @@ +/** +* @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 dtypes = require( '@stdlib/ndarray/dtypes' ); +var gzeroTo = require( '@stdlib/blas/ext/base/ndarray/gzero-to' ); +var dzeroTo = require( '@stdlib/blas/ext/base/ndarray/dzero-to' ); +var szeroTo = require( '@stdlib/blas/ext/base/ndarray/szero-to' ); +var czeroTo = require( '@stdlib/blas/ext/base/ndarray/czero-to' ); +var zzeroTo = require( '@stdlib/blas/ext/base/ndarray/zzero-to' ); +var factory = require( '@stdlib/ndarray/base/nullary-strided1d-dispatch-factory' ); + + +// VARIABLES // + +var odtypes = dtypes( 'numeric_and_generic' ); +var table = { + 'types': [ + 'float64', // output + 'float32', // output + 'complex128', // output + 'complex64' // output + ], + 'fcns': [ + dzeroTo, + szeroTo, + zzeroTo, + czeroTo + ], + 'default': gzeroTo +}; +var options = { + 'strictTraversalOrder': true +}; + + +// MAIN // + +/** +* Fills an ndarray with linearly spaced numeric elements which increment by 1 starting from zero. +* +* @private +* @name zeroTo +* @type {Function} +* @param {ndarray} x - input ndarray +* @param {Options} [options] - function options +* @param {IntegerArray} [options.dims] - list of dimensions over which to perform operation +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} first argument must have a supported data type +* @throws {TypeError} options argument must be an object +* @throws {RangeError} dimension indices must not exceed input ndarray bounds +* @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions +* @throws {Error} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ 0.0, 0.0, 0.0 ] ); +* // returns [ 0.0, 0.0, 0.0 ] +* +* var y = zeroTo( x ); +* // returns [ 0.0, 1.0, 2.0 ] +*/ +var zeroTo = factory( table, [], odtypes, options ); + + +// EXPORTS // + +module.exports = zeroTo; diff --git a/lib/node_modules/@stdlib/blas/ext/zero-to/package.json b/lib/node_modules/@stdlib/blas/ext/zero-to/package.json new file mode 100644 index 000000000000..0f454e75123b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/blas/ext/zero-to", + "version": "0.0.0", + "description": "Fill an ndarray with linearly spaced numeric elements which increment by 1 starting from zero.", + "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", + "zero", + "fill", + "iota", + "sequence", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/zero-to/test/test.js b/lib/node_modules/@stdlib/blas/ext/zero-to/test/test.js new file mode 100644 index 000000000000..2afa37dfe27c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/test/test.js @@ -0,0 +1,509 @@ +/** +* @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 ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var empty = require( '@stdlib/ndarray/empty' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var zeroTo = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof zeroTo, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + 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() { + zeroTo( value ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + 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() { + zeroTo( value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object having a supported data type', function test( t ) { + var values; + var i; + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + 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() { + zeroTo( value ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object having a supported data type (options)', function test( t ) { + var values; + var i; + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + 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() { + zeroTo( value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + 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() { + zeroTo( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which is not an array-like object of integers', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + function noop() {} + ]; + 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() { + zeroTo( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains out-of-bounds indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 5 ], + [ -5 ], + [ 2 ] + ]; + 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() { + zeroTo( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 1, 0 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + zeroTo( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains duplicate indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 0 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + zeroTo( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function fills an ndarray with linearly spaced numeric elements which increment by 1 starting from zero', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); + x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + expected = [ 0.0, 1.0, 2.0 ]; + + actual = zeroTo( x ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 3 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function fills an ndarray with linearly spaced numeric elements which increment by 1 starting from zero (default, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + x = new ndarray( 'float64', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + expected = [ [ 0.0, 1.0 ], [ 2.0, 3.0 ] ]; + + actual = zeroTo( x ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function fills an ndarray with linearly spaced numeric elements which increment by 1 starting from zero (default, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + x = new ndarray( 'float64', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + expected = [ [ 0.0, 2.0 ], [ 1.0, 3.0 ] ]; + + actual = zeroTo( x ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function fills an ndarray with linearly spaced numeric elements which increment by 1 starting from zero (all dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + x = new ndarray( 'float64', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + expected = [ [ 0.0, 1.0 ], [ 2.0, 3.0 ] ]; + + actual = zeroTo( x, { + 'dims': [ 0, 1 ] + }); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function fills an ndarray with linearly spaced numeric elements which increment by 1 starting from zero (all dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + x = new ndarray( 'float64', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + expected = [ [ 0.0, 2.0 ], [ 1.0, 3.0 ] ]; + + actual = zeroTo( x, { + 'dims': [ 0, 1 ] + }); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function fills an ndarray with linearly spaced numeric elements which increment by 1 starting from zero (no dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + x = new ndarray( 'float64', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + expected = [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ]; + + actual = zeroTo( x, { + 'dims': [] + }); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function fills an ndarray with linearly spaced numeric elements which increment by 1 starting from zero (no dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + x = new ndarray( 'float64', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + expected = [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ]; + + actual = zeroTo( x, { + 'dims': [] + }); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying operation dimensions (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + x = new ndarray( 'float64', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + expected = [ [ 0.0, 0.0 ], [ 1.0, 1.0 ] ]; + + actual = zeroTo( x, { + 'dims': [ 0 ] + }); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + x = new ndarray( 'float64', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + expected = [ [ 0.0, 1.0 ], [ 0.0, 1.0 ] ]; + + actual = zeroTo( x, { + 'dims': [ 1 ] + }); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'float64', 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying operation dimensions (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + x = new ndarray( 'float64', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + expected = [ [ 0.0, 0.0 ], [ 1.0, 1.0 ] ]; + + actual = zeroTo( x, { + 'dims': [ 0 ] + }); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + x = new ndarray( 'float64', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + expected = [ [ 0.0, 1.0 ], [ 0.0, 1.0 ] ]; + + actual = zeroTo( x, { + 'dims': [ 1 ] + }); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'float64', 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +});