From aca200bad87b83a1aabd09d0e05a62060d96b2b8 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 4 Apr 2026 19:11:15 +0500 Subject: [PATCH 1/3] feat: add blas/ext/zero-to --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/zero-to/README.md | 139 +++++ .../blas/ext/zero-to/benchmark/benchmark.js | 106 ++++ .../@stdlib/blas/ext/zero-to/docs/repl.txt | 33 ++ .../blas/ext/zero-to/docs/types/index.d.ts | 88 +++ .../blas/ext/zero-to/docs/types/test.ts | 98 ++++ .../blas/ext/zero-to/examples/index.js | 37 ++ .../@stdlib/blas/ext/zero-to/lib/index.js | 44 ++ .../@stdlib/blas/ext/zero-to/lib/main.js | 88 +++ .../@stdlib/blas/ext/zero-to/package.json | 65 +++ .../@stdlib/blas/ext/zero-to/test/test.js | 509 ++++++++++++++++++ 10 files changed, 1207 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/zero-to/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/zero-to/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/zero-to/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/zero-to/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/zero-to/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/zero-to/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/zero-to/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/zero-to/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/zero-to/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/zero-to/test/test.js 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(); +}); From 25c52511abf007ab9b85a12d4a805cde53be3a44 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 9 Apr 2026 16:23:17 +0500 Subject: [PATCH 2/3] fix: apply suggestions from code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/zero-to/README.md | 105 +++- .../ext/zero-to/benchmark/benchmark.assign.js | 103 ++++ .../blas/ext/zero-to/benchmark/benchmark.js | 7 +- .../@stdlib/blas/ext/zero-to/docs/repl.txt | 76 ++- .../blas/ext/zero-to/docs/types/index.d.ts | 113 +++- .../blas/ext/zero-to/docs/types/test.ts | 122 ++++- .../blas/ext/zero-to/examples/index.js | 19 +- .../@stdlib/blas/ext/zero-to/lib/assign.js | 109 ++++ .../@stdlib/blas/ext/zero-to/lib/base.js | 87 +++ .../@stdlib/blas/ext/zero-to/lib/defaults.js | 38 ++ .../@stdlib/blas/ext/zero-to/lib/dtypes.js | 36 ++ .../@stdlib/blas/ext/zero-to/lib/index.js | 38 +- .../@stdlib/blas/ext/zero-to/lib/main.js | 142 +++-- .../@stdlib/blas/ext/zero-to/package.json | 2 +- .../blas/ext/zero-to/test/test.assign.js | 509 ++++++++++++++++++ .../@stdlib/blas/ext/zero-to/test/test.js | 476 +--------------- .../blas/ext/zero-to/test/test.main.js | 421 +++++++++++++++ 17 files changed, 1779 insertions(+), 624 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/ext/zero-to/benchmark/benchmark.assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/zero-to/lib/assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/zero-to/lib/base.js create mode 100644 lib/node_modules/@stdlib/blas/ext/zero-to/lib/defaults.js create mode 100644 lib/node_modules/@stdlib/blas/ext/zero-to/lib/dtypes.js create mode 100644 lib/node_modules/@stdlib/blas/ext/zero-to/test/test.assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/zero-to/test/test.main.js diff --git a/lib/node_modules/@stdlib/blas/ext/zero-to/README.md b/lib/node_modules/@stdlib/blas/ext/zero-to/README.md index fc3fc7e9e292..84d3d880eaa7 100644 --- a/lib/node_modules/@stdlib/blas/ext/zero-to/README.md +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/README.md @@ -20,7 +20,7 @@ limitations under the License. # zeroTo -> Fill an [ndarray][@stdlib/ndarray/ctor] with linearly spaced numeric elements which increment by `1` starting from zero. +> Return a new [ndarray][@stdlib/ndarray/ctor] filled with linearly spaced numeric elements which increment by `1` starting from zero along one or more [ndarray][@stdlib/ndarray/ctor] dimensions.
@@ -30,49 +30,91 @@ limitations under the License. var zeroTo = require( '@stdlib/blas/ext/zero-to' ); ``` -#### zeroTo( x\[, options] ) +#### zeroTo( shape\[, options] ) -Fills an [ndarray][@stdlib/ndarray/ctor] with linearly spaced numeric elements which increment by `1` starting from zero. +Returns a new [ndarray][@stdlib/ndarray/ctor] filled with linearly spaced numeric elements which increment by `1` starting from zero along one or more [ndarray][@stdlib/ndarray/ctor] dimensions. ```javascript -var array = require( '@stdlib/ndarray/array' ); - -var x = array( [ 0.0, 0.0, 0.0 ] ); -// returns [ 0.0, 0.0, 0.0 ] +var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var y = zeroTo( x ); -// returns [ 0.0, 1.0, 2.0 ] +var x = zeroTo( [ 3 ] ); +// returns -var bool = ( x === y ); -// returns true +var arr = ndarray2array( x ); +// returns [ 0.0, 1.0, 2.0 ] ``` The function has the following parameters: -- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a numeric or "generic" [data type][@stdlib/ndarray/dtypes]. +- **shape**: array shape. - **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]. +- **dims**: list of dimensions over which to perform operation. If not provided, the function generates values along the last dimension. Default: `[-1]`. +- **dtype**: output [ndarray][@stdlib/ndarray/ctor] [data type][@stdlib/ndarray/dtypes]. Must be a numeric or "generic" [data type][@stdlib/ndarray/dtypes]. Default: `'float64'`. +- **order**: specifies whether an [ndarray][@stdlib/ndarray/ctor] is `'row-major'` (C-style) or `'column-major'` (Fortran-style). +- **mode**: specifies how to handle indices which exceed array dimensions (see [`ndarray`][@stdlib/ndarray/ctor]). Default: `'throw'`. +- **submode**: a mode array which specifies for each dimension how to handle subscripts which exceed array dimensions (see [`ndarray`][@stdlib/ndarray/ctor]). If provided fewer modes than dimensions, the constructor recycles modes using modulo arithmetic. Default: `[ options.mode ]`. -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. +By default, the function generates values along the last dimension of an output [ndarray][@stdlib/ndarray/ctor]. To perform the operation over specific dimensions, provide a `dims` option. ```javascript -var array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var x = array( [ 0.0, 0.0, 0.0, 0.0 ], { - 'shape': [ 2, 2 ], - 'order': 'row-major' +var x = zeroTo( [ 2, 2 ], { + 'dims': [ 0, 1 ] }); -// returns [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] +// returns + +var arr = ndarray2array( x ); +// returns [ [ 0.0, 1.0 ], [ 2.0, 3.0 ] ] +``` + +To specify the output [ndarray][@stdlib/ndarray/ctor] [data type][@stdlib/ndarray/dtypes], provide a `dtype` option. + +```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var y = zeroTo( x, { - 'dims': [ 1 ] +var x = zeroTo( [ 3 ], { + 'dtype': 'float32' }); -// returns [ [ 0.0, 1.0 ], [ 0.0, 1.0 ] ] +// returns + +var arr = ndarray2array( x ); +// returns [ 0.0, 1.0, 2.0 ] ``` +#### zeroTo.assign( x\[, options] ) + +Fills an [ndarray][@stdlib/ndarray/ctor] with linearly spaced numeric elements which increment by `1` starting from zero along one or more [ndarray][@stdlib/ndarray/ctor] dimensions. + +```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var zeros = require( '@stdlib/ndarray/zeros' ); + +var x = zeros( [ 3 ] ); +// returns + +var out = zeroTo.assign( x ); +// returns + +var bool = ( x === out ); +// returns true + +var arr = ndarray2array( out ); +// returns [ 0.0, 1.0, 2.0 ] +``` + +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 generates values along the last dimension. Default: `[-1]`. +
@@ -96,21 +138,26 @@ var y = zeroTo( x, { ```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 ], { +// Create a new ndarray: +var x = zeroTo( [ 5, 5 ], { 'dtype': 'generic' }); console.log( ndarray2array( x ) ); -// Perform operation: -zeroTo( x, { - 'dims': [ 1 ] +// Generate values over a specific dimension: +x = zeroTo( [ 5, 5 ], { + 'dtype': 'generic', + 'dims': [ 0 ] }); +console.log( ndarray2array( x ) ); -// Print the results: +// Generate values over all dimensions: +x = zeroTo( [ 5, 5 ], { + 'dtype': 'generic', + 'dims': [ 0, 1 ] +}); console.log( ndarray2array( x ) ); ``` diff --git a/lib/node_modules/@stdlib/blas/ext/zero-to/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/blas/ext/zero-to/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..0087b9a7c7da --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/benchmark/benchmark.assign.js @@ -0,0 +1,103 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var 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/ndarray/zeros' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assign = require( './../lib/assign.js' ); + + +// 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 ); + 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 = assign( x ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( x.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:assign:dtype=%s,len=%d', pkg, options.dtype, len ), f ); + } +} + +main(); 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 index 44081ea85996..dfdc4bb36380 100644 --- a/lib/node_modules/@stdlib/blas/ext/zero-to/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/benchmark/benchmark.js @@ -23,8 +23,6 @@ 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' ); @@ -47,9 +45,6 @@ var options = { * @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; /** @@ -64,7 +59,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - o = zeroTo( x ); + o = zeroTo( [ len ], options ); if ( typeof o !== 'object' ) { b.fail( 'should return an ndarray' ); } 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 index 2ee8e80bf0f7..31a86d3aa453 100644 --- a/lib/node_modules/@stdlib/blas/ext/zero-to/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/docs/repl.txt @@ -1,7 +1,66 @@ -{{alias}}( x[, options] ) +{{alias}}( shape[, options] ) + Returns a new ndarray filled with linearly spaced numeric elements which + increment by 1 starting from zero along one or more ndarray dimensions. + + Parameters + ---------- + shape: Array|integer + Array shape. + + options: Object (optional) + Function options. + + options.dims: Array (optional) + List of dimensions over which to perform operation. If not provided, + the function generates values along the last dimension. Default: [-1]. + + options.dtype: string (optional) + Output ndarray data type. Must be a numeric or "generic" data type. + Default: 'float64'. + + options.order: string (optional) + Specifies whether an array is row-major (C-style) or column-major + (Fortran-style). + + options.mode: string (optional) + Specifies how to handle indices which exceed array dimensions. If equal + to 'throw', an ndarray instance throws an error when an index exceeds + array dimensions. If equal to 'normalize', an ndarray instance + normalizes negative indices and throws an error when an index exceeds + array dimensions. If equal to 'wrap', an ndarray instance wraps around + indices exceeding array dimensions using modulo arithmetic. If equal to + 'clamp', an ndarray instance sets an index exceeding array dimensions + to either `0` (minimum index) or the maximum index. Default: 'throw'. + + options.submode: Array (optional) + Specifies how to handle subscripts which exceed array dimensions. If a + mode for a corresponding dimension is equal to 'throw', an ndarray + instance throws an error when a subscript exceeds array dimensions. If + equal to 'normalize', an ndarray instance normalizes negative + subscripts and throws an error when a subscript exceeds array + dimensions. If equal to 'wrap', an ndarray instance wraps around + subscripts exceeding array dimensions using modulo arithmetic. If equal + to 'clamp', an ndarray instance sets a subscript exceeding array + dimensions to either `0` (minimum index) or the maximum index. If the + number of modes is fewer than the number of dimensions, the function + recycles modes using modulo arithmetic. Default: [ options.mode ]. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var out = {{alias}}( [ 3 ] ); + > {{alias:@stdlib/ndarray/to-array}}( out ) + [ 0.0, 1.0, 2.0 ] + + +{{alias}}.assign( x[, options] ) Fills an ndarray with linearly spaced numeric elements which increment by - 1 starting from zero. + 1 starting from zero along one or more ndarray dimensions. The function fills an ndarray in-place and thus mutates the input ndarray. @@ -15,8 +74,8 @@ 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. + the function generates values along the last dimension. + Default: [-1]. Returns ------- @@ -25,9 +84,12 @@ Examples -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ 0.0, 0.0, 0.0 ] ); - > var y = {{alias}}( x ) - [ 0.0, 1.0, 2.0 ] + > var x = {{alias:@stdlib/ndarray/zeros}}( [ 3 ] ); + > var out = {{alias}}.assign( x ); + > {{alias:@stdlib/ndarray/to-array}}( out ) + [ 0.0, 1.0, 2.0 ] + > var bool = ( out === x ) + true 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 index 78e95cfd8694..2d5c963e8e8e 100644 --- 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 @@ -21,17 +21,17 @@ /// import { ArrayLike } from '@stdlib/types/array'; -import { typedndarray, genericndarray } from '@stdlib/types/ndarray'; +import { NumericAndGenericDataType as DataType, typedndarray, genericndarray, Mode, Order } from '@stdlib/types/ndarray'; /** -* Input array. +* Output array. */ -type InputArray = typedndarray | genericndarray; +type OutputArray = typedndarray | genericndarray; /** -* Interface defining options. +* Interface defining "base" options. */ -interface Options { +interface BaseOptions { /** * List of dimensions over which to perform operation. */ @@ -39,7 +39,54 @@ interface Options { } /** - * Fills an ndarray with linearly spaced numeric elements which increment by 1 starting from zero. +* Interface defining options. +*/ +interface Options extends BaseOptions { + /** + * Output ndarray data type. + */ + dtype?: DataType; + + /** + * Array order (either 'row-major' (C-style) or 'column-major' (Fortran-style)). + */ + order?: Order; + + /** + * Specifies how to handle a linear index which exceeds array dimensions (default: 'throw'). + */ + mode?: Mode; + + /** + * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). + */ + submode?: Array; +} + +/** +* Interface for performing an operation on an ndarray. +*/ +interface ZeroTo { + /** + * Returns a new ndarray filled with linearly spaced numeric elements which increment by 1 starting from zero along one or more ndarray dimensions. + * + * @param shape - array shape + * @param options - function options + * @returns output ndarray + * + * @example + * var ndarray2array = require( '@stdlib/ndarray/to-array' ); + * + * var out = zeroTo( [ 3 ] ); + * // returns + * + * var arr = ndarray2array( out ); + * // returns [ 0.0, 1.0, 2.0 ] + */ + ( shape: number | ArrayLike, options?: Options ): OutputArray; + + /** + * Fills an ndarray with linearly spaced numeric elements which increment by 1 starting from zero along one or more ndarray dimensions. * * ## Notes * @@ -50,35 +97,55 @@ interface Options { * @returns output ndarray * * @example - * var array = require( '@stdlib/ndarray/array' ); + * var zeros = require( '@stdlib/ndarray/zeros' ); + * var ndarray2array = require( '@stdlib/ndarray/to-array' ); + * + * var x = zeros( [ 3 ] ); + * // returns * - * var x = array( [ 0.0, 0.0, 0.0 ] ); - * // returns [ 0.0, 0.0, 0.0 ] + * var out = zeroTo.assign( x ); + * // returns * - * var y = zeroTo( x ); - * // returns [ 0.0, 1.0, 2.0 ] + * var bool = ( out === x ); + * // returns true + * + * var arr = ndarray2array( out ); + * // returns [ 0.0, 1.0, 2.0 ] */ -type ZeroTo = ( x: T, options?: Options ) => T; + assign( x: T, options?: BaseOptions ): T; +} /** -* Fills an ndarray with linearly spaced numeric elements which increment by 1 starting from zero. -* -* ## Notes +* Returns a new ndarray filled with linearly spaced numeric elements which increment by 1 starting from zero along one or more ndarray dimensions. * -* - The input ndarray is filled **in-place** (i.e., the input ndarray is **mutated**). -* -* @param x - input ndarray +* @param shape - array shape * @param options - function options * @returns output ndarray * * @example -* var array = require( '@stdlib/ndarray/array' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var out = zeroTo( [ 3 ] ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ 0.0, 1.0, 2.0 ] +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var x = zeros( [ 3 ] ); +* // returns +* +* var out = zeroTo.assign( x ); +* // returns * -* var x = array( [ 0.0, 0.0, 0.0 ] ); -* // returns [ 0.0, 0.0, 0.0 ] +* var bool = ( out === x ); +* // returns true * -* var y = zeroTo( x ); -* // returns [ 0.0, 1.0, 2.0 ] +* var arr = ndarray2array( out ); +* // returns [ 0.0, 1.0, 2.0 ] */ declare const zeroTo: 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 index b080e3311add..35bf4e48930f 100644 --- 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 @@ -28,18 +28,16 @@ import zeroTo = require( './index' ); // The function returns an ndarray... { - const x = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - - zeroTo( x ); // $ExpectType float64ndarray - zeroTo( x, {} ); // $ExpectType float64ndarray + zeroTo( [ 3 ] ); // $ExpectType OutputArray + zeroTo( [ 2, 2 ] ); // $ExpectType OutputArray + zeroTo( 3 ); // $ExpectType OutputArray + zeroTo( [ 3 ], {} ); // $ExpectType OutputArray + zeroTo( [ 3 ], { 'dtype': 'float32' } ); // $ExpectType OutputArray } -// The compiler throws an error if the function is provided a first argument which is not an ndarray... +// The compiler throws an error if the function is provided a first argument which is not a number or an array of numbers... { zeroTo( '5' ); // $ExpectError - zeroTo( 5 ); // $ExpectError zeroTo( true ); // $ExpectError zeroTo( false ); // $ExpectError zeroTo( null ); // $ExpectError @@ -48,7 +46,6 @@ import zeroTo = require( './index' ); zeroTo( ( x: number ): number => x ); // $ExpectError zeroTo( '5', {} ); // $ExpectError - zeroTo( 5, {} ); // $ExpectError zeroTo( true, {} ); // $ExpectError zeroTo( false, {} ); // $ExpectError zeroTo( null, {} ); // $ExpectError @@ -58,41 +55,112 @@ import zeroTo = require( './index' ); } // The compiler throws an error if the function is provided an options argument which is not an object... +{ + zeroTo( [ 3 ], '5' ); // $ExpectError + zeroTo( [ 3 ], 5 ); // $ExpectError + zeroTo( [ 3 ], true ); // $ExpectError + zeroTo( [ 3 ], false ); // $ExpectError + zeroTo( [ 3 ], null ); // $ExpectError + zeroTo( [ 3 ], [] ); // $ExpectError + zeroTo( [ 3 ], ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dtype` option... +{ + zeroTo( [ 3 ], { 'dtype': '5' } ); // $ExpectError + zeroTo( [ 3 ], { 'dtype': 5 } ); // $ExpectError + zeroTo( [ 3 ], { 'dtype': true } ); // $ExpectError + zeroTo( [ 3 ], { 'dtype': false } ); // $ExpectError + zeroTo( [ 3 ], { 'dtype': null } ); // $ExpectError + zeroTo( [ 3 ], { 'dtype': [] } ); // $ExpectError + zeroTo( [ 3 ], { 'dtype': {} } ); // $ExpectError + zeroTo( [ 3 ], { 'dtype': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dims` option... +{ + zeroTo( [ 3 ], { 'dims': '5' } ); // $ExpectError + zeroTo( [ 3 ], { 'dims': 5 } ); // $ExpectError + zeroTo( [ 3 ], { 'dims': true } ); // $ExpectError + zeroTo( [ 3 ], { 'dims': false } ); // $ExpectError + zeroTo( [ 3 ], { 'dims': null } ); // $ExpectError + zeroTo( [ 3 ], { 'dims': {} } ); // $ExpectError + zeroTo( [ 3 ], { 'dims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + zeroTo(); // $ExpectError + zeroTo( [ 3 ], {}, {} ); // $ExpectError +} + +// Attached to the function is an `assign` method which returns an ndarray... { 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 + zeroTo.assign( x ); // $ExpectType float64ndarray + zeroTo.assign( x, {} ); // $ExpectType float64ndarray } -// The compiler throws an error if the function is provided an invalid `dims` option... +// The compiler throws an error if the `assign` method is provided a first argument which is not an ndarray... +{ + zeroTo.assign( '5' ); // $ExpectError + zeroTo.assign( 5 ); // $ExpectError + zeroTo.assign( true ); // $ExpectError + zeroTo.assign( false ); // $ExpectError + zeroTo.assign( null ); // $ExpectError + zeroTo.assign( void 0 ); // $ExpectError + zeroTo.assign( {} ); // $ExpectError + zeroTo.assign( ( x: number ): number => x ); // $ExpectError + + zeroTo.assign( '5', {} ); // $ExpectError + zeroTo.assign( 5, {} ); // $ExpectError + zeroTo.assign( true, {} ); // $ExpectError + zeroTo.assign( false, {} ); // $ExpectError + zeroTo.assign( null, {} ); // $ExpectError + zeroTo.assign( void 0, {} ); // $ExpectError + zeroTo.assign( {}, {} ); // $ExpectError + zeroTo.assign( ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an options argument which is not an object... { 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 + zeroTo.assign( x, '5' ); // $ExpectError + zeroTo.assign( x, 5 ); // $ExpectError + zeroTo.assign( x, true ); // $ExpectError + zeroTo.assign( x, false ); // $ExpectError + zeroTo.assign( x, null ); // $ExpectError + zeroTo.assign( x, [] ); // $ExpectError + zeroTo.assign( x, ( x: number ): number => x ); // $ExpectError } -// The compiler throws an error if the function is provided an unsupported number of arguments... +// The compiler throws an error if the `assign` method is provided an invalid `dims` option... { const x = zeros( [ 2, 2 ], { 'dtype': 'float64' }); - zeroTo(); // $ExpectError - zeroTo( x, {}, {} ); // $ExpectError + zeroTo.assign( x, { 'dims': '5' } ); // $ExpectError + zeroTo.assign( x, { 'dims': 5 } ); // $ExpectError + zeroTo.assign( x, { 'dims': true } ); // $ExpectError + zeroTo.assign( x, { 'dims': false } ); // $ExpectError + zeroTo.assign( x, { 'dims': null } ); // $ExpectError + zeroTo.assign( x, { 'dims': {} } ); // $ExpectError + zeroTo.assign( x, { 'dims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + zeroTo.assign(); // $ExpectError + zeroTo.assign( 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 index 8a3986530735..a2f04c93ede8 100644 --- a/lib/node_modules/@stdlib/blas/ext/zero-to/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/examples/index.js @@ -19,19 +19,24 @@ '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 ], { +// Create a new ndarray: +var x = zeroTo( [ 5, 5 ], { 'dtype': 'generic' }); console.log( ndarray2array( x ) ); -// Perform operation: -zeroTo( x, { - 'dims': [ 1 ] +// Generate values over a specific dimension: +x = zeroTo( [ 5, 5 ], { + 'dtype': 'generic', + 'dims': [ 0 ] }); +console.log( ndarray2array( x ) ); -// Print the results: +// Generate values over all dimensions: +x = zeroTo( [ 5, 5 ], { + 'dtype': 'generic', + 'dims': [ 0, 1 ] +}); console.log( ndarray2array( x ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/zero-to/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/zero-to/lib/assign.js new file mode 100644 index 000000000000..72e30ba72a75 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/lib/assign.js @@ -0,0 +1,109 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isEmptyCollection = require( '@stdlib/assert/is-empty-collection' ); +var isIntegerArray = require( '@stdlib/assert/is-integer-array' ).primitives; +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var resolveStr = require( '@stdlib/ndarray/base/dtype-resolve-str' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var contains = require( '@stdlib/array/base/assert/contains' ); +var join = require( '@stdlib/array/base/join' ); +var format = require( '@stdlib/string/format' ); +var DTYPES = require( './dtypes.js' ); +var defaults = require( './defaults.js' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Fills an ndarray with linearly spaced numeric elements which increment by 1 starting from zero along one or more ndarray dimensions. +* +* @param {ndarrayLike} x - input ndarray +* @param {Options} [options] - function options +* @param {IntegerArray} [options.dims=[-1]] - list of dimensions over which to perform operation +* @throws {TypeError} first argument must be an ndarray-like object having at least one dimension +* @throws {TypeError} first argument must have a supported data type +* @throws {TypeError} options argument must be an object +* @throws {TypeError} must provide valid options +* @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 +* @returns {ndarray} output ndarray +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var x = zeros( [ 3 ] ); +* // returns +* +* var out = assign( x ); +* // returns +* +* var bool = ( out === x ); +* // returns true +* +* var arr = ndarray2array( out ); +* // returns [ 0.0, 1.0, 2.0 ] +*/ +function assign( x ) { + var options; + var opts; + var sh; + var dt; + + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + } + sh = getShape( x ); + if ( sh.length < 1 ) { + throw new TypeError( 'invalid argument. First argument must be an ndarray having at least one dimension.' ); + } + dt = resolveStr( getDType( x ) ); + if ( !contains( DTYPES.odtypes, dt ) ) { + throw new TypeError( format( 'invalid argument. First argument must have one of the following data types: "%s". Data type: `%s`.', join( DTYPES.odtypes, '", "' ), dt ) ); + } + options = defaults(); + + if ( arguments.length > 1 ) { + opts = arguments[ 1 ]; + if ( !isPlainObject( opts ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + } + if ( hasOwnProp( opts, 'dims' ) ) { + if ( !isIntegerArray( opts.dims ) && !isEmptyCollection( opts.dims ) ) { // eslint-disable-line max-len + throw new TypeError( format( 'invalid option. `%s` option must be an array of integers. Option: `%s`.', 'dims', opts.dims ) ); + } + options.dims = opts.dims; + } + } + // Perform operation: + return base( x, options ); +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/blas/ext/zero-to/lib/base.js b/lib/node_modules/@stdlib/blas/ext/zero-to/lib/base.js new file mode 100644 index 000000000000..48c93e9db42c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/lib/base.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 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' ); +var DTYPES = require( './dtypes.js' ); + + +// VARIABLES // + +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, [], DTYPES.odtypes, options ); + + +// EXPORTS // + +module.exports = zeroTo; diff --git a/lib/node_modules/@stdlib/blas/ext/zero-to/lib/defaults.js b/lib/node_modules/@stdlib/blas/ext/zero-to/lib/defaults.js new file mode 100644 index 000000000000..a8ac5148b369 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/lib/defaults.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MAIN // + +/** +* Returns default options. +* +* @private +* @returns {Object} default options +*/ +function defaults() { + return { + 'dims': [ -1 ] // by default, generate values along the last dimension + }; +} + + +// EXPORTS // + +module.exports = defaults; diff --git a/lib/node_modules/@stdlib/blas/ext/zero-to/lib/dtypes.js b/lib/node_modules/@stdlib/blas/ext/zero-to/lib/dtypes.js new file mode 100644 index 000000000000..1b5a26cdd918 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/lib/dtypes.js @@ -0,0 +1,36 @@ +/** +* @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 dtypes2strings = require( '@stdlib/ndarray/base/dtypes2strings' ); +var dtypes = require( '@stdlib/ndarray/dtypes' ); + + +// MAIN // + +var dt = { + 'odtypes': dtypes2strings( dtypes( 'numeric_and_generic' ) ) +}; + + +// EXPORTS // + +module.exports = dt; 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 index 49059ba2f382..8483cbd0b634 100644 --- a/lib/node_modules/@stdlib/blas/ext/zero-to/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/lib/index.js @@ -19,26 +19,52 @@ 'use strict'; /** -* Fill an ndarray with linearly spaced numeric elements which increment by 1 starting from zero. +* Return a new ndarray filled with linearly spaced numeric elements which increment by 1 starting from zero along one or more ndarray dimensions. * * @module @stdlib/blas/ext/zero-to * * @example -* var array = require( '@stdlib/ndarray/array' ); +* var ndarray2array = require( '@stdlib/ndarray/to-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 out = zeroTo( [ 2, 3 ] ); +* // returns * -* var y = zeroTo( x ); -* // returns [ 0.0, 1.0, 2.0 ] +* var arr = ndarray2array( out ); +* // returns [ [ 0.0, 1.0, 2.0 ], [ 0.0, 1.0, 2.0 ] ] +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var zeroTo = require( '@stdlib/blas/ext/zero-to' ); +* +* var x = zeros( [ 2, 3 ] ); +* // returns +* +* var out = zeroTo.assign( x ); +* // returns +* +* var bool = ( out === x ); +* // returns true +* +* var arr = ndarray2array( out ); +* // returns [ [ 0.0, 1.0, 2.0 ], [ 0.0, 1.0, 2.0 ] ] */ // MODULES // +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); var main = require( './main.js' ); +var assign = require( './assign.js' ); + + +// MAIN // + +setReadOnly( main, 'assign', assign ); // EXPORTS // module.exports = main; + +// exports: { "assign": "main.assign" } 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 index bc4d6664fe4b..4cd400b139d0 100644 --- a/lib/node_modules/@stdlib/blas/ext/zero-to/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/lib/main.js @@ -20,67 +20,119 @@ // 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 -}; +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isNonNegativeIntegerArray = require( '@stdlib/assert/is-nonnegative-integer-array' ).primitives; +var isEmptyCollection = require( '@stdlib/assert/is-empty-collection' ); +var isIntegerArray = require( '@stdlib/assert/is-integer-array' ).primitives; +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var isOrder = require( '@stdlib/ndarray/base/assert/is-order' ); +var isDataType = require( '@stdlib/ndarray/base/assert/is-data-type' ); +var resolveStr = require( '@stdlib/ndarray/base/dtype-resolve-str' ); +var contains = require( '@stdlib/array/base/assert/contains' ); +var empty = require( '@stdlib/ndarray/empty' ); +var join = require( '@stdlib/array/base/join' ); +var format = require( '@stdlib/string/format' ); +var DTYPES = require( './dtypes.js' ); +var defaults = require( './defaults.js' ); +var base = require( './base.js' ); // MAIN // /** -* Fills an ndarray with linearly spaced numeric elements which increment by 1 starting from zero. +* Returns a new ndarray filled with linearly spaced numeric elements which increment by 1 starting from zero along one or more ndarray dimensions. * -* @private -* @name zeroTo -* @type {Function} -* @param {ndarray} x - input ndarray +* @param {(NonNegativeInteger|NonNegativeIntegerArray)} shape - array shape * @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 +* @param {IntegerArray} [options.dims=[-1]] - list of dimensions over which to perform operation +* @param {*} [options.dtype] - output ndarray data type +* @param {string} [options.order] - ndarray order +* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed ndarray dimensions +* @param {ArrayLikeObject} [options.submode=["throw"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis +* @throws {TypeError} first argument must be either a nonnegative integer or an array of nonnegative integers * @throws {TypeError} options argument must be an object +* @throws {TypeError} must provide valid options * @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 ndarray2array = require( '@stdlib/ndarray/to-array' ); * -* var x = array( [ 0.0, 0.0, 0.0 ] ); -* // returns [ 0.0, 0.0, 0.0 ] +* var out = zeroTo( [ 3 ] ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ 0.0, 1.0, 2.0 ] +* +* @example +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); * -* var y = zeroTo( x ); -* // returns [ 0.0, 1.0, 2.0 ] +* var out = zeroTo( [ 2, 3 ] ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ [ 0.0, 1.0, 2.0 ], [ 0.0, 1.0, 2.0 ] ] */ -var zeroTo = factory( table, [], odtypes, options ); +function zeroTo( shape ) { + var options; + var opts; + var out; + var sh; + var dt; + + if ( isNonNegativeInteger( shape ) ) { + sh = [ shape ]; + } else if ( isNonNegativeIntegerArray( shape ) ) { + sh = shape; // Note: empty shape (i.e., a shape for a zero-dimensional ndarray) is not allowed + } else { + throw new TypeError( format( 'invalid argument. First argument must be a nonnegative integer or an array of nonnegative integers. Value: `%s`.', shape ) ); + } + options = defaults(); + + if ( arguments.length > 1 ) { + opts = arguments[ 1 ]; + if ( !isPlainObject( opts ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + } + if ( hasOwnProp( opts, 'dtype' ) ) { + dt = resolveStr( opts.dtype ); + if ( !isDataType( opts.dtype ) || !contains( DTYPES.odtypes, dt ) ) { // eslint-disable-line max-len + throw new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'dtype', join( DTYPES.odtypes, '", "' ), opts.dtype ) ); + } + options.dtype = dt; + } + if ( hasOwnProp( opts, 'order' ) ) { + if ( !isOrder( opts.order ) ) { + throw new TypeError( format( 'invalid option. `%s` option must be a supported order. Option: `%s`.', 'order', opts.order ) ); + } + options.order = opts.order; + } + if ( hasOwnProp( opts, 'mode' ) ) { + // Defer to `empty` to validate below... + options.mode = opts.mode; + } + if ( hasOwnProp( opts, 'submode' ) ) { + // Defer to `empty` to validate below... + options.submode = opts.submode; + } + if ( hasOwnProp( opts, 'dims' ) ) { + if ( !isIntegerArray( opts.dims ) && !isEmptyCollection( opts.dims ) ) { // eslint-disable-line max-len + throw new TypeError( format( 'invalid option. `%s` option must be an array of integers. Option: `%s`.', 'dims', opts.dims ) ); + } + options.dims = opts.dims; + } + } + // Set the default data type if not provided: + options.dtype = options.dtype || 'float64'; + + // Create an output ndarray: + out = empty( sh, options ); + + // Perform operation: + return base( out, options ); +} // EXPORTS // diff --git a/lib/node_modules/@stdlib/blas/ext/zero-to/package.json b/lib/node_modules/@stdlib/blas/ext/zero-to/package.json index 0f454e75123b..290fd10db05f 100644 --- a/lib/node_modules/@stdlib/blas/ext/zero-to/package.json +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/package.json @@ -1,7 +1,7 @@ { "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.", + "description": "Return a new ndarray filled with linearly spaced numeric elements which increment by 1 starting from zero along one or more ndarray dimensions.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/blas/ext/zero-to/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/zero-to/test/test.assign.js new file mode 100644 index 000000000000..0c9f5af95a5d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/test/test.assign.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 assign = require( './../lib/assign.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof assign, '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() { + assign( 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() { + assign( 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() { + assign( 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() { + assign( 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() { + assign( 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() { + assign( 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() { + assign( 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() { + assign( 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() { + assign( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function fills an ndarray with linearly spaced values incrementing by 1 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 = assign( 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 values incrementing by 1 from zero (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 ], [ 0.0, 1.0 ] ]; + + actual = assign( 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 values incrementing by 1 from zero (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, 1.0 ], [ 0.0, 1.0 ] ]; + + actual = assign( 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 values incrementing by 1 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 = assign( 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 values incrementing by 1 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 = assign( 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 values incrementing by 1 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 = assign( 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 values incrementing by 1 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 = assign( 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 = assign( 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 = assign( 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 = assign( 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 = assign( 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(); +}); 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 index 2afa37dfe27c..f01239ae22f6 100644 --- a/lib/node_modules/@stdlib/blas/ext/zero-to/test/test.js +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/test/test.js @@ -21,14 +21,7 @@ // 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 isMethod = require( '@stdlib/assert/is-method' ); var zeroTo = require( './../lib' ); @@ -40,470 +33,7 @@ tape( 'main export is a function', function test( t ) { 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' ); - +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( zeroTo, 'assign' ), true, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/zero-to/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/zero-to/test/test.main.js new file mode 100644 index 000000000000..bb8fcadca5d5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/test/test.main.js @@ -0,0 +1,421 @@ +/** +* @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 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 a nonnegative integer or an array of nonnegative integers', function test( t ) { + var values; + var i; + + values = [ + '5', + -1, + 3.14, + 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 a nonnegative integer or an array of nonnegative integers (options)', function test( t ) { + var values; + var i; + + values = [ + '5', + -1, + 3.14, + 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 second argument which is not an 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( [ 2, 2 ], value ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid `dtype` option', function test( t ) { + var values; + var i; + + values = [ + 'foo', + 'bool', + 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( [ 2, 2 ], { + 'dtype': value + }); + }; + } +}); + +tape( 'the function throws an error if provided an invalid `order` option', function test( t ) { + var values; + var i; + + values = [ + 'foo', + 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( [ 2, 2 ], { + 'order': 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 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( [ 2, 2 ], { + '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 i; + + 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( [ 2, 2 ], { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices', function test( t ) { + var values; + var i; + + 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( [ 2, 2 ], { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains duplicate indices', function test( t ) { + var values; + var i; + + 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( [ 2, 2 ], { + 'dims': value + }); + }; + } +}); + +tape( 'the function returns an ndarray containing linearly spaced values incrementing by 1 from zero', function test( t ) { + var expected; + var actual; + + expected = [ 0.0, 1.0, 2.0 ]; + + actual = zeroTo( [ 3 ] ); + + 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 returns an ndarray containing linearly spaced values incrementing by 1 from zero (nonnegative integer shape)', function test( t ) { + var expected; + var actual; + + expected = [ 0.0, 1.0, 2.0 ]; + + actual = zeroTo( 3 ); + + 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 returns an ndarray containing linearly spaced values incrementing by 1 from zero (row-major)', function test( t ) { + var expected; + var actual; + + expected = [ [ 0.0, 1.0 ], [ 0.0, 1.0 ] ]; + + actual = zeroTo( [ 2, 2 ] ); + + t.strictEqual( getDType( actual ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an output data type', function test( t ) { + var expected; + var actual; + + expected = [ 0.0, 1.0, 2.0 ]; + + actual = zeroTo( [ 3 ], { + 'dtype': 'float32' + }); + + t.strictEqual( getDType( actual ), 'float32', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 3 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an output array order', function test( t ) { + var expected; + var actual; + + expected = [ [ 0.0, 1.0 ], [ 0.0, 1.0 ] ]; + + actual = zeroTo( [ 2, 2 ], { + 'order': 'column-major' + }); + + 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 supports specifying operation dimensions', function test( t ) { + var expected; + var actual; + + expected = [ [ 0.0, 1.0 ], [ 0.0, 1.0 ] ]; + + actual = zeroTo( [ 2, 2 ], { + 'dims': [ -1 ] + }); + + t.strictEqual( getDType( actual ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying operation dimensions (dim 0)', function test( t ) { + var expected; + var actual; + + expected = [ [ 0.0, 0.0 ], [ 1.0, 1.0 ] ]; + + actual = zeroTo( [ 2, 2 ], { + 'dims': [ 0 ] + }); + + t.strictEqual( getDType( actual ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an ndarray containing linearly spaced values incrementing by 1 from zero (all dimensions)', function test( t ) { + var expected; + var actual; + + expected = [ [ 0.0, 1.0 ], [ 2.0, 3.0 ] ]; + + actual = zeroTo( [ 2, 2 ], { + 'dims': [ 0, 1 ] + }); + + t.strictEqual( getDType( actual ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an ndarray containing linearly spaced values incrementing by 1 from zero (no dimensions)', function test( t ) { + var expected; + var actual; + + expected = [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ]; + + actual = zeroTo( [ 2, 2 ], { + 'dims': [] + }); + + t.strictEqual( getDType( actual ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); From 120775250129c8b4e619d62fc9d3f4012da5681e Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 9 Apr 2026 16:50:31 +0500 Subject: [PATCH 3/3] docs: apply suggestions from code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/zero-to/README.md | 33 ++++------------ .../@stdlib/blas/ext/zero-to/docs/repl.txt | 12 +++--- .../blas/ext/zero-to/docs/types/index.d.ts | 38 +++++-------------- .../@stdlib/blas/ext/zero-to/lib/assign.js | 10 ++--- .../@stdlib/blas/ext/zero-to/lib/base.js | 8 ++-- .../@stdlib/blas/ext/zero-to/lib/index.js | 14 ++----- .../@stdlib/blas/ext/zero-to/lib/main.js | 16 +------- 7 files changed, 33 insertions(+), 98 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/zero-to/README.md b/lib/node_modules/@stdlib/blas/ext/zero-to/README.md index 84d3d880eaa7..494e01b4da87 100644 --- a/lib/node_modules/@stdlib/blas/ext/zero-to/README.md +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/README.md @@ -35,13 +35,8 @@ var zeroTo = require( '@stdlib/blas/ext/zero-to' ); Returns a new [ndarray][@stdlib/ndarray/ctor] filled with linearly spaced numeric elements which increment by `1` starting from zero along one or more [ndarray][@stdlib/ndarray/ctor] dimensions. ```javascript -var ndarray2array = require( '@stdlib/ndarray/to-array' ); - -var x = zeroTo( [ 3 ] ); -// returns - -var arr = ndarray2array( x ); -// returns [ 0.0, 1.0, 2.0 ] +var x = zeroTo( [ 2, 3 ] ); +// returns [ [ 0.0, 1.0, 2.0 ], [ 0.0, 1.0, 2.0 ] ] ``` The function has the following parameters: @@ -60,29 +55,19 @@ The function accepts the following options: By default, the function generates values along the last dimension of an output [ndarray][@stdlib/ndarray/ctor]. To perform the operation over specific dimensions, provide a `dims` option. ```javascript -var ndarray2array = require( '@stdlib/ndarray/to-array' ); - var x = zeroTo( [ 2, 2 ], { 'dims': [ 0, 1 ] }); -// returns - -var arr = ndarray2array( x ); -// returns [ [ 0.0, 1.0 ], [ 2.0, 3.0 ] ] +// returns [ [ 0.0, 1.0 ], [ 2.0, 3.0 ] ] ``` To specify the output [ndarray][@stdlib/ndarray/ctor] [data type][@stdlib/ndarray/dtypes], provide a `dtype` option. ```javascript -var ndarray2array = require( '@stdlib/ndarray/to-array' ); - var x = zeroTo( [ 3 ], { 'dtype': 'float32' }); -// returns - -var arr = ndarray2array( x ); -// returns [ 0.0, 1.0, 2.0 ] +// returns [ 0.0, 1.0, 2.0 ] ``` #### zeroTo.assign( x\[, options] ) @@ -90,20 +75,16 @@ var arr = ndarray2array( x ); Fills an [ndarray][@stdlib/ndarray/ctor] with linearly spaced numeric elements which increment by `1` starting from zero along one or more [ndarray][@stdlib/ndarray/ctor] dimensions. ```javascript -var ndarray2array = require( '@stdlib/ndarray/to-array' ); var zeros = require( '@stdlib/ndarray/zeros' ); -var x = zeros( [ 3 ] ); -// returns +var x = zeros( [ 2, 3 ] ); +// returns [ [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ] ] var out = zeroTo.assign( x ); -// returns +// returns [ [ 0.0, 1.0, 2.0 ], [ 0.0, 1.0, 2.0 ] ] var bool = ( x === out ); // returns true - -var arr = ndarray2array( out ); -// returns [ 0.0, 1.0, 2.0 ] ``` The function has the following parameters: 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 index 31a86d3aa453..96e2aaa78b27 100644 --- a/lib/node_modules/@stdlib/blas/ext/zero-to/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/docs/repl.txt @@ -53,9 +53,8 @@ Examples -------- - > var out = {{alias}}( [ 3 ] ); - > {{alias:@stdlib/ndarray/to-array}}( out ) - [ 0.0, 1.0, 2.0 ] + > var out = {{alias}}( [ 2, 3 ] ) + [ [ 0.0, 1.0, 2.0 ], [ 0.0, 1.0, 2.0 ] ] {{alias}}.assign( x[, options] ) @@ -84,10 +83,9 @@ Examples -------- - > var x = {{alias:@stdlib/ndarray/zeros}}( [ 3 ] ); - > var out = {{alias}}.assign( x ); - > {{alias:@stdlib/ndarray/to-array}}( out ) - [ 0.0, 1.0, 2.0 ] + > var x = {{alias:@stdlib/ndarray/zeros}}( [ 2, 3 ] ); + > var out = {{alias}}.assign( x ) + [ [ 0.0, 1.0, 2.0 ], [ 0.0, 1.0, 2.0 ] ] > var bool = ( out === x ) true 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 index 2d5c963e8e8e..1f28a866994c 100644 --- 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 @@ -75,13 +75,8 @@ interface ZeroTo { * @returns output ndarray * * @example - * var ndarray2array = require( '@stdlib/ndarray/to-array' ); - * - * var out = zeroTo( [ 3 ] ); - * // returns - * - * var arr = ndarray2array( out ); - * // returns [ 0.0, 1.0, 2.0 ] + * var out = zeroTo( [ 2, 3 ] ); + * // returns [ [ 0.0, 1.0, 2.0 ], [ 0.0, 1.0, 2.0 ] ] */ ( shape: number | ArrayLike, options?: Options ): OutputArray; @@ -98,19 +93,15 @@ interface ZeroTo { * * @example * var zeros = require( '@stdlib/ndarray/zeros' ); - * var ndarray2array = require( '@stdlib/ndarray/to-array' ); * - * var x = zeros( [ 3 ] ); - * // returns + * var x = zeros( [ 2, 3 ] ); + * // returns [ [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ] ] * * var out = zeroTo.assign( x ); - * // returns + * // returns [ [ 0.0, 1.0, 2.0 ], [ 0.0, 1.0, 2.0 ] ] * * var bool = ( out === x ); * // returns true - * - * var arr = ndarray2array( out ); - * // returns [ 0.0, 1.0, 2.0 ] */ assign( x: T, options?: BaseOptions ): T; } @@ -123,29 +114,20 @@ interface ZeroTo { * @returns output ndarray * * @example -* var ndarray2array = require( '@stdlib/ndarray/to-array' ); -* -* var out = zeroTo( [ 3 ] ); -* // returns -* -* var arr = ndarray2array( out ); -* // returns [ 0.0, 1.0, 2.0 ] +* var out = zeroTo( [ 2, 3 ] ); +* // returns [ [ 0.0, 1.0, 2.0 ], [ 0.0, 1.0, 2.0 ] ] * * @example * var zeros = require( '@stdlib/ndarray/zeros' ); -* var ndarray2array = require( '@stdlib/ndarray/to-array' ); * -* var x = zeros( [ 3 ] ); -* // returns +* var x = zeros( [ 2, 3 ] ); +* // returns [ [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ] ] * * var out = zeroTo.assign( x ); -* // returns +* // returns [ [ 0.0, 1.0, 2.0 ], [ 0.0, 1.0, 2.0 ] ] * * var bool = ( out === x ); * // returns true -* -* var arr = ndarray2array( out ); -* // returns [ 0.0, 1.0, 2.0 ] */ declare const zeroTo: ZeroTo; diff --git a/lib/node_modules/@stdlib/blas/ext/zero-to/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/zero-to/lib/assign.js index 72e30ba72a75..973aaa82ee69 100644 --- a/lib/node_modules/@stdlib/blas/ext/zero-to/lib/assign.js +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/lib/assign.js @@ -54,19 +54,15 @@ var base = require( './base.js' ); * * @example * var zeros = require( '@stdlib/ndarray/zeros' ); -* var ndarray2array = require( '@stdlib/ndarray/to-array' ); * -* var x = zeros( [ 3 ] ); -* // returns +* var x = zeros( [ 2, 3 ] ); +* // returns [ [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ] ] * * var out = assign( x ); -* // returns +* // returns [ [ 0.0, 1.0, 2.0 ], [ 0.0, 1.0, 2.0 ] ] * * var bool = ( out === x ); * // returns true -* -* var arr = ndarray2array( out ); -* // returns [ 0.0, 1.0, 2.0 ] */ function assign( x ) { var options; diff --git a/lib/node_modules/@stdlib/blas/ext/zero-to/lib/base.js b/lib/node_modules/@stdlib/blas/ext/zero-to/lib/base.js index 48c93e9db42c..400015083c5e 100644 --- a/lib/node_modules/@stdlib/blas/ext/zero-to/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/lib/base.js @@ -71,13 +71,13 @@ var options = { * @returns {ndarray} output ndarray * * @example -* var array = require( '@stdlib/ndarray/array' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); * -* var x = array( [ 0.0, 0.0, 0.0 ] ); -* // returns [ 0.0, 0.0, 0.0 ] +* var x = zeros( [ 2, 3 ] ); +* // returns [ [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ] ] * * var y = zeroTo( x ); -* // returns [ 0.0, 1.0, 2.0 ] +* // returns [ [ 0.0, 1.0, 2.0 ], [ 3.0, 4.0, 5.0 ] ] */ var zeroTo = factory( table, [], DTYPES.odtypes, options ); 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 index 8483cbd0b634..efcfccacb5f5 100644 --- a/lib/node_modules/@stdlib/blas/ext/zero-to/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/lib/index.js @@ -24,31 +24,23 @@ * @module @stdlib/blas/ext/zero-to * * @example -* var ndarray2array = require( '@stdlib/ndarray/to-array' ); * var zeroTo = require( '@stdlib/blas/ext/zero-to' ); * * var out = zeroTo( [ 2, 3 ] ); -* // returns -* -* var arr = ndarray2array( out ); -* // returns [ [ 0.0, 1.0, 2.0 ], [ 0.0, 1.0, 2.0 ] ] +* // returns [ [ 0.0, 1.0, 2.0 ], [ 0.0, 1.0, 2.0 ] ] * * @example * var zeros = require( '@stdlib/ndarray/zeros' ); -* var ndarray2array = require( '@stdlib/ndarray/to-array' ); * var zeroTo = require( '@stdlib/blas/ext/zero-to' ); * * var x = zeros( [ 2, 3 ] ); -* // returns +* // returns [ [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ] ] * * var out = zeroTo.assign( x ); -* // returns +* // returns [ [ 0.0, 1.0, 2.0 ], [ 0.0, 1.0, 2.0 ] ] * * var bool = ( out === x ); * // returns true -* -* var arr = ndarray2array( out ); -* // returns [ [ 0.0, 1.0, 2.0 ], [ 0.0, 1.0, 2.0 ] ] */ // MODULES // 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 index 4cd400b139d0..9f30dfb834c0 100644 --- a/lib/node_modules/@stdlib/blas/ext/zero-to/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/zero-to/lib/main.js @@ -58,22 +58,8 @@ var base = require( './base.js' ); * @returns {ndarray} output ndarray * * @example -* var ndarray2array = require( '@stdlib/ndarray/to-array' ); -* -* var out = zeroTo( [ 3 ] ); -* // returns -* -* var arr = ndarray2array( out ); -* // returns [ 0.0, 1.0, 2.0 ] -* -* @example -* var ndarray2array = require( '@stdlib/ndarray/to-array' ); -* * var out = zeroTo( [ 2, 3 ] ); -* // returns -* -* var arr = ndarray2array( out ); -* // returns [ [ 0.0, 1.0, 2.0 ], [ 0.0, 1.0, 2.0 ] ] +* // returns [ [ 0.0, 1.0, 2.0 ], [ 0.0, 1.0, 2.0 ] ] */ function zeroTo( shape ) { var options;