From 9e9557afee0054d1bfee2883135fc2dc159a6f5c Mon Sep 17 00:00:00 2001 From: headlessNode Date: Mon, 15 Dec 2025 20:08:41 +0500 Subject: [PATCH 01/14] feat: add ndarray/unshift --- 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/ndarray/unshift/README.md | 155 +++++++++++ .../unshift/benchmark/benchmark.assign.js | 115 ++++++++ .../ndarray/unshift/benchmark/benchmark.js | 109 ++++++++ .../@stdlib/ndarray/unshift/docs/repl.txt | 60 ++++ .../ndarray/unshift/docs/types/index.d.ts | 119 ++++++++ .../ndarray/unshift/docs/types/test.ts | 93 +++++++ .../@stdlib/ndarray/unshift/examples/index.js | 33 +++ .../@stdlib/ndarray/unshift/lib/assign.js | 93 +++++++ .../@stdlib/ndarray/unshift/lib/index.js | 56 ++++ .../@stdlib/ndarray/unshift/lib/main.js | 81 ++++++ .../@stdlib/ndarray/unshift/package.json | 66 +++++ .../ndarray/unshift/test/test.assign.js | 263 ++++++++++++++++++ .../@stdlib/ndarray/unshift/test/test.js | 39 +++ .../@stdlib/ndarray/unshift/test/test.main.js | 186 +++++++++++++ 14 files changed, 1468 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/unshift/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/unshift/benchmark/benchmark.assign.js create mode 100644 lib/node_modules/@stdlib/ndarray/unshift/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/unshift/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/unshift/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/unshift/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/unshift/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js create mode 100644 lib/node_modules/@stdlib/ndarray/unshift/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/unshift/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/unshift/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/unshift/test/test.assign.js create mode 100644 lib/node_modules/@stdlib/ndarray/unshift/test/test.js create mode 100644 lib/node_modules/@stdlib/ndarray/unshift/test/test.main.js diff --git a/lib/node_modules/@stdlib/ndarray/unshift/README.md b/lib/node_modules/@stdlib/ndarray/unshift/README.md new file mode 100644 index 000000000000..0e3aaef8ec43 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/unshift/README.md @@ -0,0 +1,155 @@ + + +# unshift + +> Return a one-dimensional [ndarray][@stdlib/ndarray/ctor] formed by prepending the provided scalar values to the input ndarray. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var unshift = require( '@stdlib/ndarray/unshift' ); +``` + +#### unshift( x, ...values ) + +Returns a one-dimensional [ndarray][@stdlib/ndarray/ctor] formed by prepending the provided scalar values to the input ndarray. + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); + +var out = unshift( x, -2.0, -1.0, 0.0 ); +// returns + +var arr = ndarray2array( out ); +// returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] +``` + +The function accepts the following arguments: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. +- **...values**: scalar values to prepend. + +#### unshift.assign( x, ...values, out ) + +Prepends the provided scalar values to the input [ndarray][@stdlib/ndarray/ctor] and assigns the result to a provided one-dimensional output [ndarray][@stdlib/ndarray/ctor]. + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); +var y = zeros( [ 7 ] ); + +var out = unshift.assign( x, -2.0, -1.0, 0.0, y ); +// returns + +var bool = ( out === y ); +// returns true + +var arr = ndarray2array( y ); +// returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] +``` + +The function accepts the following arguments: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. +- **...values**: scalar values to prepend. +- **out**: output [ndarray][@stdlib/ndarray/ctor]. + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var unshift = require( '@stdlib/ndarray/unshift' ); + +var opts = { + 'dtype': 'generic' +}; +var x = array( discreteUniform( 6, 0, 10, opts ), opts ); +console.log( ndarray2array( x ) ); + +var out = unshift( x, -2.0, -1.0, 0.0 ); +console.log( ndarray2array( out ) ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/unshift/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/ndarray/unshift/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..e90d239fd5c7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/unshift/benchmark/benchmark.assign.js @@ -0,0 +1,115 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var unshift = require( './../lib/assign.js' ); + + +// MAIN // + +bench( format( '%s::two scalar values', pkg ), function benchmark( b ) { + var opts; + var out; + var v; + var x; + var i; + + opts = { + 'dtype': 'float64' + }; + x = zeros( [ 3 ], opts ); + out = zeros( [ 5 ], opts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = unshift( x, 1.0, 2.0, out ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::four scalar values', pkg ), function benchmark( b ) { + var opts; + var out; + var v; + var x; + var i; + + opts = { + 'dtype': 'float64' + }; + x = zeros( [ 3 ], opts ); + out = zeros( [ 7 ], opts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = unshift( x, 1.0, 2.0, 3.0, 4.0, out ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::six scalar values', pkg ), function benchmark( b ) { + var opts; + var out; + var v; + var x; + var i; + + opts = { + 'dtype': 'float64' + }; + x = zeros( [ 3 ], opts ); + out = zeros( [ 9 ], opts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = unshift( x, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, out ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/unshift/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/unshift/benchmark/benchmark.js new file mode 100644 index 000000000000..8917e5759ac3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/unshift/benchmark/benchmark.js @@ -0,0 +1,109 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var unshift = require( './../lib' ); + + +// MAIN // + +bench( format( '%s::two scalar values', pkg ), function benchmark( b ) { + var opts; + var v; + var x; + var i; + + opts = { + 'dtype': 'float64' + }; + x = zeros( [ 3 ], opts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = unshift( x, 1.0, 2.0 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::four scalar values', pkg ), function benchmark( b ) { + var opts; + var v; + var x; + var i; + + opts = { + 'dtype': 'float64' + }; + x = zeros( [ 3 ], opts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = unshift( x, 1.0, 2.0, 3.0, 4.0 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::six scalar values', pkg ), function benchmark( b ) { + var opts; + var v; + var x; + var i; + + opts = { + 'dtype': 'float64' + }; + x = zeros( [ 3 ], opts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = unshift( x, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/unshift/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/unshift/docs/repl.txt new file mode 100644 index 000000000000..5a318cc50b69 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/unshift/docs/repl.txt @@ -0,0 +1,60 @@ + +{{alias}}( x, ...values ) + Returns a one-dimensional ndarray formed by prepending the provided scalar + values to the input ndarray. + + Parameters + ---------- + x: ndarray + Input ndarray. + + values: ...any + Scalar values to prepend. + + Returns + ------- + out: ndarray + Output ndarray. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var out = {{alias}}( x, -1.0, 0.0 ) + + > var arr = {{alias:@stdlib/ndarray/to-array}}( out ) + [ -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] + + +{{alias}}.assign( x, ...values, out ) + Prepends the provided scalar values to the input ndarray and assigns results + to an output ndarray. + + Parameters + ---------- + x: ndarray + Input ndarray. + + values: ...any + Scalar values to prepend. + + out: ndarray + Output ndarray. + + Returns + ------- + out: ndarray + Output ndarray. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, 2.0 ] ); + > var y = {{alias:@stdlib/ndarray/array}}( [ 0.0, 0.0, 0.0, 0.0 ] ); + > var out = {{alias}}.assign( x, -1.0, 0.0, y ) + + > var bool = ( out === y ) + true + > var arr = {{alias:@stdlib/ndarray/to-array}}( y ) + [ -1.0, 0.0, 1.0, 2.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/ndarray/unshift/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/unshift/docs/types/index.d.ts new file mode 100644 index 000000000000..043ca97b6036 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/unshift/docs/types/index.d.ts @@ -0,0 +1,119 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { typedndarray } from '@stdlib/types/ndarray'; + +/** +* Interface describing `unshift`. +*/ +interface Unshift { + /** + * Returns a one-dimensional ndarray formed by prepending the provided scalar values to the input ndarray. + * + * @param x - input ndarray + * @param values - scalar values + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * var ndarray2array = require( '@stdlib/ndarray/to-array' ); + * + * var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); + * + * var out = unshift( x, -2.0, -1.0, 0.0 ); + * // returns + * + * var arr = ndarray2array( out ); + * // returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] + */ + ( x: typedndarray, ...values: Array ): typedndarray; + + /** + * Prepends the provided scalar values to the input ndarray and assigns the result to a provided one-dimensional output ndarray. + * + * @param x - input ndarray + * @param values - scalar values + * @param out - output ndarray + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * var empty = require( '@stdlib/ndarray/empty' ); + * var ndarray2array = require( '@stdlib/ndarray/to-array' ); + * + * var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); + * var y = empty( [ 7 ] ); + * + * var out = unshift.assign( x, -2.0, -1.0, 0.0, y ); + * // returns + * + * var bool = ( out === y ); + * // returns true + * + * var arr = ndarray2array( y ); + * // returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] + */ + assign = typedndarray>( x: typedndarray, ...values: Array, out: V ): V; +} + +/** +* Returns a one-dimensional ndarray formed by prepending the provided scalar values to the input ndarray. +* +* @param x - input ndarray +* @param values - scalar values +* @returns output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* +* var out = unshift( x, -2.0, -1.0, 0.0 ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var empty = require( '@stdlib/ndarray/empty' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var y = empty( [ 7 ] ); +* +* var out = unshift.assign( x, -2.0, -1.0, 0.0, y ); +* // returns +* +* var bool = ( out === y ); +* // returns true +* +* var arr = ndarray2array( y ); +* // returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] +*/ +declare var unshift: Unshift; + + +// EXPORTS // + +export = unshift; diff --git a/lib/node_modules/@stdlib/ndarray/unshift/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/unshift/docs/types/test.ts new file mode 100644 index 000000000000..21b00fd54f13 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/unshift/docs/types/test.ts @@ -0,0 +1,93 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/// + +import zeros = require( '@stdlib/ndarray/zeros' ); +import unshift = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ] ); + + unshift( x, 1.0 ); // $ExpectType typedndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + unshift( '10', 1.0 ); // $ExpectError + unshift( 10, 1.0 ); // $ExpectError + unshift( false, 1.0 ); // $ExpectError + unshift( true, 1.0 ); // $ExpectError + unshift( null, 1.0 ); // $ExpectError + unshift( [], 1.0 ); // $ExpectError + unshift( {}, 1.0 ); // $ExpectError + unshift( ( x: number ): number => x, 1.0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + unshift(); // $ExpectError +} + +// Attached to the function is an `assign` method which returns an ndarray... +{ + const x = zeros( [ 2 ] ); + const out = zeros( [ 3 ] ); + + unshift.assign( x, 1.0, out ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the assign method is provided a first argument which is not an ndarray... +{ + const out = zeros( [ 3 ] ); + + unshift.assign( '10', 1.0, out ); // $ExpectError + unshift.assign( 10, 1.0, out ); // $ExpectError + unshift.assign( false, 1.0, out ); // $ExpectError + unshift.assign( true, 1.0, out ); // $ExpectError + unshift.assign( null, 1.0, out ); // $ExpectError + unshift.assign( [], 1.0, out ); // $ExpectError + unshift.assign( {}, 1.0, out ); // $ExpectError + unshift.assign( ( x: number ): number => x, 1.0, out ); // $ExpectError +} + +// The compiler throws an error if the assign method is provided an output argument which is not an ndarray... +{ + const x = zeros( [ 3 ] ); + + unshift.assign( x, 1.0, '10' ); // $ExpectError + unshift.assign( x, 1.0, 10 ); // $ExpectError + unshift.assign( x, 1.0, false ); // $ExpectError + unshift.assign( x, 1.0, true ); // $ExpectError + unshift.assign( x, 1.0, null ); // $ExpectError + unshift.assign( x, 1.0, [] ); // $ExpectError + unshift.assign( x, 1.0, {} ); // $ExpectError + unshift.assign( x, 1.0, ( 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 ] ); + + unshift.assign(); // $ExpectError + unshift.assign( x ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/unshift/examples/index.js b/lib/node_modules/@stdlib/ndarray/unshift/examples/index.js new file mode 100644 index 000000000000..97c9e6eb3f9e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/unshift/examples/index.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var unshift = require( './../lib' ); + +var opts = { + 'dtype': 'generic' +}; +var x = array( discreteUniform( 6, 0, 10, opts ), opts ); +console.log( ndarray2array( x ) ); + +var out = unshift( x, -2.0, -1.0, 0.0 ); +console.log( ndarray2array( out ) ); diff --git a/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js b/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js new file mode 100644 index 000000000000..0c691e89d6d7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js @@ -0,0 +1,93 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var ndims = require( '@stdlib/ndarray/base/ndims' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var concat1d = require( '@stdlib/ndarray/concat1d' ).assign; +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Prepends the provided scalar values to the input ndarray and assigns the result to a provided one-dimensional output ndarray. +* +* @param {ndarray} x - input ndarray +* @param {...*} values - scalar values +* @param {ndarray} out - output ndarray +* @throws {TypeError} first argument must a be one-dimensional ndarray +* @throws {Error} must be provided at least three arguments +* @throws {TypeError} output argument must a be one-dimensional ndarray +* @returns {ndarray} output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var y = zeros( [ 7 ] ); +* +* var out = assign( x, -2.0, -1.0, 0.0, y ); +* // returns +* +* var bool = ( y === out ); +* // returns true +* +* var arr = ndarray2array( out ); +* // throws [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] +*/ +function assign( x ) { + var nargs; + var dtype; + var args; + var out; + var i; + + if ( !isndarrayLike( x ) || ndims( x ) !== 1 ) { + throw new TypeError( format( 'invalid argument. First argument must be a one-dimensional ndarray. Value: `%s`.', x ) ); + } + nargs = arguments.length; + if ( nargs < 3 ) { + throw new Error( format( 'invalid argument. The function must be provided at least three arguments. Value: `%s`.', nargs ) ); + } + out = arguments[ nargs - 1 ]; + if ( !isndarrayLike( out ) || ndims( out ) !== 1 ) { + throw new TypeError( format( 'invalid argument. Output argument must be a one-dimensional ndarray. Value: `%s`.', out ) ); + } + args = []; + dtype = getDType( x ); + for ( i = 1; i < nargs - 1; i++ ) { + args.push( scalar2ndarray( arguments[ i ], { + 'dtype': dtype + })); + } + args.push( x ); + return concat1d( args, out ); +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/ndarray/unshift/lib/index.js b/lib/node_modules/@stdlib/ndarray/unshift/lib/index.js new file mode 100644 index 000000000000..ee2f074e0a23 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/unshift/lib/index.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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'; + +/** +* Return a one-dimensional ndarray formed by prepending the provided scalar values to the input ndarray. +* +* @module @stdlib/ndarray/unshift +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var unshift = require( '@stdlib/ndarray/unshift' ); +* +* var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* +* var out = unshift( x, -2.0, -1.0, 0.0 ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.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/ndarray/unshift/lib/main.js b/lib/node_modules/@stdlib/ndarray/unshift/lib/main.js new file mode 100644 index 000000000000..54a832523622 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/unshift/lib/main.js @@ -0,0 +1,81 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var ndims = require( '@stdlib/ndarray/base/ndims' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var concat1d = require( '@stdlib/ndarray/concat1d' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns a one-dimensional ndarray formed by prepending the provided scalar values to the input ndarray. +* +* @param {ndarray} x - input ndarray +* @param {...*} values - scalar values +* @throws {TypeError} first argument must a be one-dimensional ndarray +* @throws {Error} must be provided at least two arguments +* @returns {ndarray} output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* +* var out = unshift( x, -2.0, -1.0, 0.0 ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] +*/ +function unshift( x ) { + var nargs; + var dtype; + var args; + var i; + + if ( !isndarrayLike( x ) || ndims( x ) !== 1 ) { + throw new TypeError( format( 'invalid argument. First argument must be a one-dimensional ndarray. Value: `%s`.', x ) ); + } + nargs = arguments.length; + if ( nargs < 2 ) { + throw new Error( format( 'invalid argument. The function must be provided at least two arguments. Value: `%s`.', nargs ) ); + } + args = []; + dtype = getDType( x ); + for ( i = 1; i < nargs; i++ ) { + args.push( scalar2ndarray( arguments[ i ], { + 'dtype': dtype + })); + } + args.push( x ); + return concat1d( args ); +} + + +// EXPORTS // + +module.exports = unshift; diff --git a/lib/node_modules/@stdlib/ndarray/unshift/package.json b/lib/node_modules/@stdlib/ndarray/unshift/package.json new file mode 100644 index 000000000000..e7b4cdef1997 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/unshift/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/ndarray/unshift", + "version": "0.0.0", + "description": "Return a one-dimensional ndarray formed by prepending the provided scalar values to the input ndarray.", + "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", + "stdtypes", + "types", + "base", + "data", + "structure", + "vector", + "ndarray", + "matrix", + "add", + "prepend", + "concat", + "join" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/unshift/test/test.assign.js b/lib/node_modules/@stdlib/ndarray/unshift/test/test.assign.js new file mode 100644 index 000000000000..a15ff50cf0ef --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/unshift/test/test.assign.js @@ -0,0 +1,263 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 resolveStr = require( '@stdlib/ndarray/base/dtype-resolve-str' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var unshift = require( './../lib/assign.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof unshift, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { + var values; + var out; + var i; + + out = zeros( [ 4 ] ); + 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() { + unshift( value, 0.0, out ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is an ndarray with more than one dimension', function test( t ) { + var values; + var out; + var i; + + out = zeros( [ 4 ] ); + values = [ + zeros( [ 2, 2 ] ), + zeros( [ 3, 1, 2 ] ), + zeros( [ 2, 2, 2 ] ), + zeros( [ 3, 3, 3, 3 ] ), + zeros( [ 3, 1, 2 ] ) + ]; + + 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() { + unshift( value, 0.0, out ); + }; + } +}); + +tape( 'the function throws an error if provided an output argument which is not an ndarray', 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() { + unshift( zeros( [ 2 ]), 0.0, value ); + }; + } +}); + +tape( 'the function throws an error if provided an output argument which is an ndarray with more than one dimension', function test( t ) { + var values; + var i; + + values = [ + zeros( [ 2, 2 ] ), + zeros( [ 3, 1, 2 ] ), + zeros( [ 2, 2, 2 ] ), + zeros( [ 3, 3, 3, 3 ] ), + zeros( [ 3, 1, 2 ] ) + ]; + + 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() { + unshift( zeros( [ 2 ] ), 0.0, value ); + }; + } +}); + +tape( 'the function prepends the provided provided scalar values to the input ndarray and assigns results to an output ndarray (row-major, contiguous)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + var y; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + y = zeros( [ 6 ], { + 'dtype': 'float64' + }); + + out = unshift( x, 5.0, 6.0, y ); + + actual = ndarray2array( y ); + expected = [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ]; + + t.strictEqual( resolveStr( getDType( y ) ), 'float64', 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + t.deepEqual( getShape( y ), [ 6 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( out, y, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function prepends the provided provided scalar values to the input ndarray and assigns results to an output ndarray (column-major, contiguous)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + var y; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'column-major' ); + y = zeros( [ 6 ], { + 'dtype': 'float64' + }); + + out = unshift( x, 5.0, 6.0, y ); + + actual = ndarray2array( y ); + expected = [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ]; + + t.strictEqual( resolveStr( getDType( y ) ), 'float64', 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + t.deepEqual( getShape( y ), [ 6 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( out, y, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function prepends the provided provided scalar values to the input ndarray and assigns results to an output ndarray (row-major, non-contiguous)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + var y; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( 'float64', xbuf, [ 4 ], [ 2 ], 0, 'row-major' ); + y = zeros( [ 6 ], { + 'dtype': 'float64' + }); + + out = unshift( x, 5.0, 6.0, y ); + + actual = ndarray2array( y ); + expected = [ 5.0, 6.0, 1.0, 3.0, 5.0, 7.0 ]; + + t.strictEqual( resolveStr( getDType( y ) ), 'float64', 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + t.deepEqual( getShape( y ), [ 6 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( out, y, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function prepends the provided provided scalar values to the input ndarray and assigns results to an output ndarray (column-major, non-contiguous)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + var y; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( 'float64', xbuf, [ 4 ], [ 2 ], 0, 'column-major' ); + y = zeros( [ 6 ], { + 'dtype': 'float64' + }); + + out = unshift( x, 5.0, 6.0, y ); + + actual = ndarray2array( y ); + expected = [ 5.0, 6.0, 1.0, 3.0, 5.0, 7.0 ]; + + t.strictEqual( resolveStr( getDType( y ) ), 'float64', 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + t.deepEqual( getShape( y ), [ 6 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( y, out, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/unshift/test/test.js b/lib/node_modules/@stdlib/ndarray/unshift/test/test.js new file mode 100644 index 000000000000..d6ffca59013e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/unshift/test/test.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isMethod = require( '@stdlib/assert/is-method' ); +var unshift = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof unshift, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( unshift, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/unshift/test/test.main.js b/lib/node_modules/@stdlib/ndarray/unshift/test/test.main.js new file mode 100644 index 000000000000..3c4a28e4d6c9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/unshift/test/test.main.js @@ -0,0 +1,186 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 resolveStr = require( '@stdlib/ndarray/base/dtype-resolve-str' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var unshift = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof unshift, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { + unshift( value, 0.0 ); + }; + } +}); + +tape( 'the function throws an error if provided an ndarray with more than one dimension', function test( t ) { + var values; + var i; + + values = [ + zeros( [ 2, 2 ] ), + zeros( [ 3, 1, 2 ] ), + zeros( [ 2, 2, 2 ] ), + zeros( [ 3, 3, 3, 3 ] ), + zeros( [ 3, 1, 2 ] ) + ]; + + 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() { + unshift( value, 0.0 ); + }; + } +}); + +tape( 'the function returns a one-dimensional ndarray formed by prepending provided scalar values (row-major, contiguous)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + + out = unshift( x, 5.0, 6.0 ); + + actual = ndarray2array( out ); + expected = [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ]; + + t.strictEqual( resolveStr( getDType( out ) ), 'float64', 'returns expected value' ); + t.strictEqual( getOrder( out ), 'row-major', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 6 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a one-dimensional ndarray formed by prepending provided scalar values (column-major, contiguous)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'column-major' ); + + out = unshift( x, 5.0, 6.0 ); + + actual = ndarray2array( out ); + expected = [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ]; + + t.strictEqual( resolveStr( getDType( out ) ), 'float64', 'returns expected value' ); + t.strictEqual( getOrder( out ), 'row-major', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 6 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a one-dimensional ndarray formed by prepending provided scalar values (row-major, non-contiguous)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( 'float64', xbuf, [ 4 ], [ 2 ], 0, 'row-major' ); + + out = unshift( x, 5.0, 6.0 ); + + actual = ndarray2array( out ); + expected = [ 5.0, 6.0, 1.0, 3.0, 5.0, 7.0 ]; + + t.strictEqual( resolveStr( getDType( out ) ), 'float64', 'returns expected value' ); + t.strictEqual( getOrder( out ), 'row-major', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 6 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a one-dimensional ndarray formed by prepending provided scalar values (column-major, non-contiguous)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( 'float64', xbuf, [ 4 ], [ 2 ], 0, 'column-major' ); + + out = unshift( x, 5.0, 6.0 ); + + actual = ndarray2array( out ); + expected = [ 5.0, 6.0, 1.0, 3.0, 5.0, 7.0 ]; + + t.strictEqual( resolveStr( getDType( out ) ), 'float64', 'returns expected value' ); + t.strictEqual( getOrder( out ), 'row-major', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 6 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); From d71bc37130c7c608626a97e4557ada45831cd783 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 21 Dec 2025 14:06:38 +0500 Subject: [PATCH 02/14] refactor: 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/ndarray/unshift/README.md | 32 ++-- .../unshift/benchmark/benchmark.assign.js | 6 +- .../ndarray/unshift/benchmark/benchmark.js | 6 +- .../@stdlib/ndarray/unshift/docs/repl.txt | 14 +- .../ndarray/unshift/docs/types/index.d.ts | 162 +++++++++++++++--- .../ndarray/unshift/docs/types/test.ts | 11 +- .../@stdlib/ndarray/unshift/examples/index.js | 2 +- .../@stdlib/ndarray/unshift/lib/assign.js | 10 +- .../@stdlib/ndarray/unshift/lib/index.js | 8 +- .../@stdlib/ndarray/unshift/lib/main.js | 10 +- .../@stdlib/ndarray/unshift/package.json | 2 +- .../ndarray/unshift/test/test.assign.js | 9 + .../@stdlib/ndarray/unshift/test/test.main.js | 9 + 13 files changed, 197 insertions(+), 84 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/unshift/README.md b/lib/node_modules/@stdlib/ndarray/unshift/README.md index 0e3aaef8ec43..8d1f94e38146 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/README.md +++ b/lib/node_modules/@stdlib/ndarray/unshift/README.md @@ -20,7 +20,7 @@ limitations under the License. # unshift -> Return a one-dimensional [ndarray][@stdlib/ndarray/ctor] formed by prepending the provided scalar values to the input ndarray. +> Return a one-dimensional [ndarray][@stdlib/ndarray/ctor] formed by prepending the provided scalar values to a one-dimensional input [ndarray][@stdlib/ndarray/ctor]. @@ -42,53 +42,45 @@ var unshift = require( '@stdlib/ndarray/unshift' ); #### unshift( x, ...values ) -Returns a one-dimensional [ndarray][@stdlib/ndarray/ctor] formed by prepending the provided scalar values to the input ndarray. +Returns a one-dimensional [ndarray][@stdlib/ndarray/ctor] formed by prepending the provided scalar values to a one-dimensional input [ndarray][@stdlib/ndarray/ctor]. ```javascript var array = require( '@stdlib/ndarray/array' ); -var ndarray2array = require( '@stdlib/ndarray/to-array' ); var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); var out = unshift( x, -2.0, -1.0, 0.0 ); -// returns - -var arr = ndarray2array( out ); -// returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] +// returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] ``` The function accepts the following arguments: -- **x**: input [ndarray][@stdlib/ndarray/ctor]. +- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must be one-dimensional. - **...values**: scalar values to prepend. #### unshift.assign( x, ...values, out ) -Prepends the provided scalar values to the input [ndarray][@stdlib/ndarray/ctor] and assigns the result to a provided one-dimensional output [ndarray][@stdlib/ndarray/ctor]. +Prepends the provided scalar values to a one-dimensional input [ndarray][@stdlib/ndarray/ctor] and assigns the result to a provided one-dimensional output [ndarray][@stdlib/ndarray/ctor]. ```javascript var array = require( '@stdlib/ndarray/array' ); var zeros = require( '@stdlib/ndarray/zeros' ); -var ndarray2array = require( '@stdlib/ndarray/to-array' ); var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); var y = zeros( [ 7 ] ); var out = unshift.assign( x, -2.0, -1.0, 0.0, y ); -// returns +// returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] var bool = ( out === y ); // returns true - -var arr = ndarray2array( y ); -// returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] ``` The function accepts the following arguments: -- **x**: input [ndarray][@stdlib/ndarray/ctor]. +- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must be one-dimensional. - **...values**: scalar values to prepend. -- **out**: output [ndarray][@stdlib/ndarray/ctor]. +- **out**: output [ndarray][@stdlib/ndarray/ctor]. Must be one-dimensional. @@ -98,6 +90,10 @@ The function accepts the following arguments:
+## Notes + +- Scalar values are cast to the [data type][@stdlib/ndarray/dtypes] of the input [ndarray][@stdlib/ndarray/ctor]. +
@@ -120,7 +116,7 @@ var opts = { var x = array( discreteUniform( 6, 0, 10, opts ), opts ); console.log( ndarray2array( x ) ); -var out = unshift( x, -2.0, -1.0, 0.0 ); +var out = unshift( x, 12, 14 ); console.log( ndarray2array( out ) ); ``` @@ -150,6 +146,8 @@ console.log( ndarray2array( out ) ); [@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/ctor +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dtypes + diff --git a/lib/node_modules/@stdlib/ndarray/unshift/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/ndarray/unshift/benchmark/benchmark.assign.js index e90d239fd5c7..9d484c11ca47 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/benchmark/benchmark.assign.js +++ b/lib/node_modules/@stdlib/ndarray/unshift/benchmark/benchmark.assign.js @@ -30,7 +30,7 @@ var unshift = require( './../lib/assign.js' ); // MAIN // -bench( format( '%s::two scalar values', pkg ), function benchmark( b ) { +bench( format( '%s:assign:num_scalars=2', pkg ), function benchmark( b ) { var opts; var out; var v; @@ -58,7 +58,7 @@ bench( format( '%s::two scalar values', pkg ), function benchmark( b ) { b.end(); }); -bench( format( '%s::four scalar values', pkg ), function benchmark( b ) { +bench( format( '%s:assign:num_scalars=4', pkg ), function benchmark( b ) { var opts; var out; var v; @@ -86,7 +86,7 @@ bench( format( '%s::four scalar values', pkg ), function benchmark( b ) { b.end(); }); -bench( format( '%s::six scalar values', pkg ), function benchmark( b ) { +bench( format( '%s:assign:num_scalars=6', pkg ), function benchmark( b ) { var opts; var out; var v; diff --git a/lib/node_modules/@stdlib/ndarray/unshift/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/unshift/benchmark/benchmark.js index 8917e5759ac3..936619965b29 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/ndarray/unshift/benchmark/benchmark.js @@ -30,7 +30,7 @@ var unshift = require( './../lib' ); // MAIN // -bench( format( '%s::two scalar values', pkg ), function benchmark( b ) { +bench( format( '%s:num_scalars=2', pkg ), function benchmark( b ) { var opts; var v; var x; @@ -56,7 +56,7 @@ bench( format( '%s::two scalar values', pkg ), function benchmark( b ) { b.end(); }); -bench( format( '%s::four scalar values', pkg ), function benchmark( b ) { +bench( format( '%s:num_scalars=4', pkg ), function benchmark( b ) { var opts; var v; var x; @@ -82,7 +82,7 @@ bench( format( '%s::four scalar values', pkg ), function benchmark( b ) { b.end(); }); -bench( format( '%s::six scalar values', pkg ), function benchmark( b ) { +bench( format( '%s:num_scalars=6', pkg ), function benchmark( b ) { var opts; var v; var x; diff --git a/lib/node_modules/@stdlib/ndarray/unshift/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/unshift/docs/repl.txt index 5a318cc50b69..09ed98fb99f0 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/unshift/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( x, ...values ) Returns a one-dimensional ndarray formed by prepending the provided scalar - values to the input ndarray. + values to a one-dimensional input ndarray. Parameters ---------- @@ -20,14 +20,12 @@ -------- > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, 2.0, 3.0, 4.0 ] ); > var out = {{alias}}( x, -1.0, 0.0 ) - - > var arr = {{alias:@stdlib/ndarray/to-array}}( out ) - [ -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] + [ -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] {{alias}}.assign( x, ...values, out ) - Prepends the provided scalar values to the input ndarray and assigns results - to an output ndarray. + Prepends the provided scalar values to a one-dimensional input ndarray and + assigns results to a provided one-dimensional output ndarray. Parameters ---------- @@ -50,11 +48,9 @@ > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, 2.0 ] ); > var y = {{alias:@stdlib/ndarray/array}}( [ 0.0, 0.0, 0.0, 0.0 ] ); > var out = {{alias}}.assign( x, -1.0, 0.0, y ) - + [ -1.0, 0.0, 1.0, 2.0 ] > var bool = ( out === y ) true - > var arr = {{alias:@stdlib/ndarray/to-array}}( y ) - [ -1.0, 0.0, 1.0, 2.0 ] See Also -------- diff --git a/lib/node_modules/@stdlib/ndarray/unshift/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/unshift/docs/types/index.d.ts index 043ca97b6036..9e4e5716fb89 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/unshift/docs/types/index.d.ts @@ -27,7 +27,7 @@ import { typedndarray } from '@stdlib/types/ndarray'; */ interface Unshift { /** - * Returns a one-dimensional ndarray formed by prepending the provided scalar values to the input ndarray. + * Returns a one-dimensional ndarray formed by prepending the provided scalar values to a one-dimensional input ndarray. * * @param x - input ndarray * @param values - scalar values @@ -35,48 +35,170 @@ interface Unshift { * * @example * var array = require( '@stdlib/ndarray/array' ); - * var ndarray2array = require( '@stdlib/ndarray/to-array' ); * * var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); * * var out = unshift( x, -2.0, -1.0, 0.0 ); - * // returns - * - * var arr = ndarray2array( out ); - * // returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] + * // returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] */ ( x: typedndarray, ...values: Array ): typedndarray; /** - * Prepends the provided scalar values to the input ndarray and assigns the result to a provided one-dimensional output ndarray. + * Prepends the provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. * * @param x - input ndarray - * @param values - scalar values + * @param arg0 - scalar values + * @param out - output ndarray + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * var empty = require( '@stdlib/ndarray/empty' ); + * + * var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); + * var y = empty( [ 5 ] ); + * + * var out = unshift.assign( x, -2.0, y ); + * // returns [ -2.0, 1.0, 2.0, 3.0, 4.0 ] + * + * var bool = ( out === y ); + * // returns true + */ + assign = typedndarray>( x: typedndarray, arg0: T, out: U ): U; + + /** + * Prepends the provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. + * + * @param x - input ndarray + * @param arg0 - scalar values + * @param arg1 - scalar values + * @param out - output ndarray + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * var empty = require( '@stdlib/ndarray/empty' ); + * + * var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); + * var y = empty( [ 6 ] ); + * + * var out = unshift.assign( x, -1.0, 0.0, y ); + * // returns [ -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] + * + * var bool = ( out === y ); + * // returns true + */ + assign = typedndarray>( x: typedndarray, arg0: T, arg1: T, out: U ): U; + + /** + * Prepends the provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. + * + * @param x - input ndarray + * @param arg0 - scalar values + * @param arg1 - scalar values + * @param arg2 - scalar values * @param out - output ndarray * @returns output ndarray * * @example * var array = require( '@stdlib/ndarray/array' ); * var empty = require( '@stdlib/ndarray/empty' ); - * var ndarray2array = require( '@stdlib/ndarray/to-array' ); * * var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); * var y = empty( [ 7 ] ); * * var out = unshift.assign( x, -2.0, -1.0, 0.0, y ); - * // returns + * // returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] + * + * var bool = ( out === y ); + * // returns true + */ + assign = typedndarray>( x: typedndarray, arg0: T, arg1: T, arg2: T, out: U ): U; + + /** + * Prepends the provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. + * + * @param x - input ndarray + * @param arg0 - scalar values + * @param arg1 - scalar values + * @param arg2 - scalar values + * @param arg3 - scalar values + * @param out - output ndarray + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * var empty = require( '@stdlib/ndarray/empty' ); + * + * var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); + * var y = empty( [ 8 ] ); + * + * var out = unshift.assign( x, -3.0, -2.0, -1.0, 0.0, y ); + * // returns [ -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] + * + * var bool = ( out === y ); + * // returns true + */ + assign = typedndarray>( x: typedndarray, arg0: T, arg1: T, arg2: T, arg3: T, out: U ): U; + + /** + * Prepends the provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. + * + * @param x - input ndarray + * @param arg0 - scalar values + * @param arg1 - scalar values + * @param arg2 - scalar values + * @param arg3 - scalar values + * @param arg4 - scalar values + * @param out - output ndarray + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * var empty = require( '@stdlib/ndarray/empty' ); + * + * var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); + * var y = empty( [ 9 ] ); + * + * var out = unshift.assign( x, -4.0, -3.0, -2.0, -1.0, 0.0, y ); + * // returns [ -4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] * * var bool = ( out === y ); * // returns true + */ + assign = typedndarray>( x: typedndarray, arg0: T, arg1: T, arg2: T, arg3: T, arg4: T, out: U ): U; + + /** + * Prepends the provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. + * + * @param x - input ndarray + * @param arg0 - scalar values + * @param arg1 - scalar values + * @param arg2 - scalar values + * @param arg3 - scalar values + * @param arg4 - scalar values + * @param args - additional scalar values and an output ndarray + * @param out - output ndarray + * @returns output ndarray * - * var arr = ndarray2array( y ); - * // returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] + * @example + * var array = require( '@stdlib/ndarray/array' ); + * var empty = require( '@stdlib/ndarray/empty' ); + * + * var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); + * var y = empty( [ 10 ] ); + * + * var out = unshift.assign( x, -5.0, -4.0, -3.0, -2.0, -1.0, 0.0, y ); + * // returns [ -5.0, -4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] + * + * var bool = ( out === y ); + * // returns true */ - assign = typedndarray>( x: typedndarray, ...values: Array, out: V ): V; + assign = typedndarray>( x: typedndarray, arg0: T, arg1: T, arg2: T, arg3: T, arg4: T, ...args: Array ): U; } /** -* Returns a one-dimensional ndarray formed by prepending the provided scalar values to the input ndarray. +* Returns a one-dimensional ndarray formed by prepending the provided scalar values to a one-dimensional input ndarray. * * @param x - input ndarray * @param values - scalar values @@ -84,32 +206,24 @@ interface Unshift { * * @example * var array = require( '@stdlib/ndarray/array' ); -* var ndarray2array = require( '@stdlib/ndarray/to-array' ); * * var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); * * var out = unshift( x, -2.0, -1.0, 0.0 ); -* // returns -* -* var arr = ndarray2array( out ); -* // returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] +* // returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] * * @example * var array = require( '@stdlib/ndarray/array' ); * var empty = require( '@stdlib/ndarray/empty' ); -* var ndarray2array = require( '@stdlib/ndarray/to-array' ); * * var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); * var y = empty( [ 7 ] ); * * var out = unshift.assign( x, -2.0, -1.0, 0.0, y ); -* // returns +* // returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] * * var bool = ( out === y ); * // returns true -* -* var arr = ndarray2array( y ); -* // returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] */ declare var unshift: Unshift; diff --git a/lib/node_modules/@stdlib/ndarray/unshift/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/unshift/docs/types/test.ts index 21b00fd54f13..b0b3c16e0f90 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/unshift/docs/types/test.ts @@ -16,8 +16,6 @@ * limitations under the License. */ -/// - import zeros = require( '@stdlib/ndarray/zeros' ); import unshift = require( './index' ); @@ -56,7 +54,7 @@ import unshift = require( './index' ); unshift.assign( x, 1.0, out ); // $ExpectType float64ndarray } -// The compiler throws an error if the assign method is provided a first argument which is not an ndarray... +// The compiler throws an error if the `assign` method is provided a first argument which is not an ndarray... { const out = zeros( [ 3 ] ); @@ -70,7 +68,7 @@ import unshift = require( './index' ); unshift.assign( ( x: number ): number => x, 1.0, out ); // $ExpectError } -// The compiler throws an error if the assign method is provided an output argument which is not an ndarray... +// The compiler throws an error if the `assign` method is provided an output argument which is not an ndarray... { const x = zeros( [ 3 ] ); @@ -84,10 +82,11 @@ import unshift = require( './index' ); unshift.assign( x, 1.0, ( 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 unsupported number of arguments... { - const x = zeros( [ 2, 2 ] ); + const x = zeros( [ 3 ] ); unshift.assign(); // $ExpectError unshift.assign( x ); // $ExpectError + unshift.assign( x, 1.0 ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/ndarray/unshift/examples/index.js b/lib/node_modules/@stdlib/ndarray/unshift/examples/index.js index 97c9e6eb3f9e..3096085eb9c0 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/unshift/examples/index.js @@ -29,5 +29,5 @@ var opts = { var x = array( discreteUniform( 6, 0, 10, opts ), opts ); console.log( ndarray2array( x ) ); -var out = unshift( x, -2.0, -1.0, 0.0 ); +var out = unshift( x, 12, 14 ); console.log( ndarray2array( out ) ); diff --git a/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js b/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js index 0c691e89d6d7..ff1818309d99 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js +++ b/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js @@ -31,7 +31,7 @@ var format = require( '@stdlib/string/format' ); // MAIN // /** -* Prepends the provided scalar values to the input ndarray and assigns the result to a provided one-dimensional output ndarray. +* Prepends the provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. * * @param {ndarray} x - input ndarray * @param {...*} values - scalar values @@ -44,19 +44,15 @@ var format = require( '@stdlib/string/format' ); * @example * var array = require( '@stdlib/ndarray/array' ); * var zeros = require( '@stdlib/ndarray/zeros' ); -* var ndarray2array = require( '@stdlib/ndarray/to-array' ); * * var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); * var y = zeros( [ 7 ] ); * * var out = assign( x, -2.0, -1.0, 0.0, y ); -* // returns +* // returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] * * var bool = ( y === out ); * // returns true -* -* var arr = ndarray2array( out ); -* // throws [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] */ function assign( x ) { var nargs; @@ -70,7 +66,7 @@ function assign( x ) { } nargs = arguments.length; if ( nargs < 3 ) { - throw new Error( format( 'invalid argument. The function must be provided at least three arguments. Value: `%s`.', nargs ) ); + throw new Error( 'invalid operation. Must provide at least two arguments.' ); } out = arguments[ nargs - 1 ]; if ( !isndarrayLike( out ) || ndims( out ) !== 1 ) { diff --git a/lib/node_modules/@stdlib/ndarray/unshift/lib/index.js b/lib/node_modules/@stdlib/ndarray/unshift/lib/index.js index ee2f074e0a23..1836e01ebaef 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/unshift/lib/index.js @@ -19,22 +19,18 @@ 'use strict'; /** -* Return a one-dimensional ndarray formed by prepending the provided scalar values to the input ndarray. +* Return a one-dimensional ndarray formed by prepending the provided scalar values to a one-dimensional input ndarray. * * @module @stdlib/ndarray/unshift * * @example * var array = require( '@stdlib/ndarray/array' ); -* var ndarray2array = require( '@stdlib/ndarray/to-array' ); * var unshift = require( '@stdlib/ndarray/unshift' ); * * var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); * * var out = unshift( x, -2.0, -1.0, 0.0 ); -* // returns -* -* var arr = ndarray2array( out ); -* // returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] +* // returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] */ // MODULES // diff --git a/lib/node_modules/@stdlib/ndarray/unshift/lib/main.js b/lib/node_modules/@stdlib/ndarray/unshift/lib/main.js index 54a832523622..1635bdb8d600 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/unshift/lib/main.js @@ -31,7 +31,7 @@ var format = require( '@stdlib/string/format' ); // MAIN // /** -* Returns a one-dimensional ndarray formed by prepending the provided scalar values to the input ndarray. +* Returns a one-dimensional ndarray formed by prepending the provided scalar values to a one-dimensional input ndarray. * * @param {ndarray} x - input ndarray * @param {...*} values - scalar values @@ -41,15 +41,11 @@ var format = require( '@stdlib/string/format' ); * * @example * var array = require( '@stdlib/ndarray/array' ); -* var ndarray2array = require( '@stdlib/ndarray/to-array' ); * * var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); * * var out = unshift( x, -2.0, -1.0, 0.0 ); -* // returns -* -* var arr = ndarray2array( out ); -* // returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] +* // returns [ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] */ function unshift( x ) { var nargs; @@ -62,7 +58,7 @@ function unshift( x ) { } nargs = arguments.length; if ( nargs < 2 ) { - throw new Error( format( 'invalid argument. The function must be provided at least two arguments. Value: `%s`.', nargs ) ); + throw new Error( 'invalid operation. Must provide at least two arguments.' ); } args = []; dtype = getDType( x ); diff --git a/lib/node_modules/@stdlib/ndarray/unshift/package.json b/lib/node_modules/@stdlib/ndarray/unshift/package.json index e7b4cdef1997..868536461ae8 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/package.json +++ b/lib/node_modules/@stdlib/ndarray/unshift/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/ndarray/unshift", "version": "0.0.0", - "description": "Return a one-dimensional ndarray formed by prepending the provided scalar values to the input ndarray.", + "description": "Return a one-dimensional ndarray formed by prepending the provided scalar values to a one-dimensional input ndarray.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/ndarray/unshift/test/test.assign.js b/lib/node_modules/@stdlib/ndarray/unshift/test/test.assign.js index a15ff50cf0ef..e29d9aa71043 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/test/test.assign.js +++ b/lib/node_modules/@stdlib/ndarray/unshift/test/test.assign.js @@ -150,6 +150,15 @@ tape( 'the function throws an error if provided an output argument which is an n } }); +tape( 'the function throws an error if provided insufficient arguments', function test( t ) { + t.throws( badValue, TypeError, 'throws an error' ); + t.end(); + + function badValue() { + unshift( zeros( [ 2 ] ), zeros( [ 2 ] ) ); + } +}); + tape( 'the function prepends the provided provided scalar values to the input ndarray and assigns results to an output ndarray (row-major, contiguous)', function test( t ) { var expected; var actual; diff --git a/lib/node_modules/@stdlib/ndarray/unshift/test/test.main.js b/lib/node_modules/@stdlib/ndarray/unshift/test/test.main.js index 3c4a28e4d6c9..b748a8cb3f43 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/test/test.main.js +++ b/lib/node_modules/@stdlib/ndarray/unshift/test/test.main.js @@ -93,6 +93,15 @@ tape( 'the function throws an error if provided an ndarray with more than one di } }); +tape( 'the function throws an error if provided insufficient arguments', function test( t ) { + t.throws( badValue, TypeError, 'throws an error' ); + t.end(); + + function badValue() { + unshift( zeros( [ 2 ] ) ); + } +}); + tape( 'the function returns a one-dimensional ndarray formed by prepending provided scalar values (row-major, contiguous)', function test( t ) { var expected; var actual; From 08c0e16b685642eb22a04a90ccb910f7cd1d7e2d Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 21 Dec 2025 14:13:43 +0500 Subject: [PATCH 03/14] test: fix assertion --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - 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: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js | 2 +- lib/node_modules/@stdlib/ndarray/unshift/test/test.assign.js | 2 +- lib/node_modules/@stdlib/ndarray/unshift/test/test.main.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js b/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js index ff1818309d99..e8eb702e1965 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js +++ b/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js @@ -66,7 +66,7 @@ function assign( x ) { } nargs = arguments.length; if ( nargs < 3 ) { - throw new Error( 'invalid operation. Must provide at least two arguments.' ); + throw new Error( 'invalid operation. Must provide at least three arguments.' ); } out = arguments[ nargs - 1 ]; if ( !isndarrayLike( out ) || ndims( out ) !== 1 ) { diff --git a/lib/node_modules/@stdlib/ndarray/unshift/test/test.assign.js b/lib/node_modules/@stdlib/ndarray/unshift/test/test.assign.js index e29d9aa71043..6ba138ee3694 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/test/test.assign.js +++ b/lib/node_modules/@stdlib/ndarray/unshift/test/test.assign.js @@ -151,7 +151,7 @@ tape( 'the function throws an error if provided an output argument which is an n }); tape( 'the function throws an error if provided insufficient arguments', function test( t ) { - t.throws( badValue, TypeError, 'throws an error' ); + t.throws( badValue, Error, 'throws an error' ); t.end(); function badValue() { diff --git a/lib/node_modules/@stdlib/ndarray/unshift/test/test.main.js b/lib/node_modules/@stdlib/ndarray/unshift/test/test.main.js index b748a8cb3f43..9e462435d282 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/test/test.main.js +++ b/lib/node_modules/@stdlib/ndarray/unshift/test/test.main.js @@ -94,7 +94,7 @@ tape( 'the function throws an error if provided an ndarray with more than one di }); tape( 'the function throws an error if provided insufficient arguments', function test( t ) { - t.throws( badValue, TypeError, 'throws an error' ); + t.throws( badValue, Error, 'throws an error' ); t.end(); function badValue() { From 4dff51e8c26cac7aeeb6658afb350b550f2ce6fb Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 25 Dec 2025 13:26:58 +0500 Subject: [PATCH 04/14] 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: 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/ndarray/unshift/README.md | 10 +++++----- .../@stdlib/ndarray/unshift/docs/repl.txt | 4 ++-- .../ndarray/unshift/docs/types/index.d.ts | 16 ++++++++-------- .../@stdlib/ndarray/unshift/examples/index.js | 4 ++-- .../@stdlib/ndarray/unshift/lib/assign.js | 2 +- .../@stdlib/ndarray/unshift/lib/index.js | 2 +- .../@stdlib/ndarray/unshift/lib/main.js | 2 +- .../@stdlib/ndarray/unshift/package.json | 2 +- .../@stdlib/ndarray/unshift/test/test.assign.js | 10 +++++----- 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/unshift/README.md b/lib/node_modules/@stdlib/ndarray/unshift/README.md index 8d1f94e38146..04879c1904da 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/README.md +++ b/lib/node_modules/@stdlib/ndarray/unshift/README.md @@ -20,7 +20,7 @@ limitations under the License. # unshift -> Return a one-dimensional [ndarray][@stdlib/ndarray/ctor] formed by prepending the provided scalar values to a one-dimensional input [ndarray][@stdlib/ndarray/ctor]. +> Return a one-dimensional [ndarray][@stdlib/ndarray/ctor] formed by prepending provided scalar values to a one-dimensional input [ndarray][@stdlib/ndarray/ctor]. @@ -42,7 +42,7 @@ var unshift = require( '@stdlib/ndarray/unshift' ); #### unshift( x, ...values ) -Returns a one-dimensional [ndarray][@stdlib/ndarray/ctor] formed by prepending the provided scalar values to a one-dimensional input [ndarray][@stdlib/ndarray/ctor]. +Returns a one-dimensional [ndarray][@stdlib/ndarray/ctor] formed by prepending provided scalar values to a one-dimensional input [ndarray][@stdlib/ndarray/ctor]. ```javascript var array = require( '@stdlib/ndarray/array' ); @@ -60,7 +60,7 @@ The function accepts the following arguments: #### unshift.assign( x, ...values, out ) -Prepends the provided scalar values to a one-dimensional input [ndarray][@stdlib/ndarray/ctor] and assigns the result to a provided one-dimensional output [ndarray][@stdlib/ndarray/ctor]. +Prepends provided scalar values to a one-dimensional input [ndarray][@stdlib/ndarray/ctor] and assigns the result to a provided one-dimensional output [ndarray][@stdlib/ndarray/ctor]. ```javascript var array = require( '@stdlib/ndarray/array' ); @@ -105,7 +105,7 @@ The function accepts the following arguments: ## Examples ```javascript -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); var array = require( '@stdlib/ndarray/array' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var unshift = require( '@stdlib/ndarray/unshift' ); @@ -113,7 +113,7 @@ var unshift = require( '@stdlib/ndarray/unshift' ); var opts = { 'dtype': 'generic' }; -var x = array( discreteUniform( 6, 0, 10, opts ), opts ); +var x = array( discreteUniform( [ 6 ], 0, 10, opts ), opts ); console.log( ndarray2array( x ) ); var out = unshift( x, 12, 14 ); diff --git a/lib/node_modules/@stdlib/ndarray/unshift/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/unshift/docs/repl.txt index 09ed98fb99f0..cce43a6e67f2 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/unshift/docs/repl.txt @@ -1,6 +1,6 @@ {{alias}}( x, ...values ) - Returns a one-dimensional ndarray formed by prepending the provided scalar + Returns a one-dimensional ndarray formed by prepending provided scalar values to a one-dimensional input ndarray. Parameters @@ -24,7 +24,7 @@ {{alias}}.assign( x, ...values, out ) - Prepends the provided scalar values to a one-dimensional input ndarray and + Prepends provided scalar values to a one-dimensional input ndarray and assigns results to a provided one-dimensional output ndarray. Parameters diff --git a/lib/node_modules/@stdlib/ndarray/unshift/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/unshift/docs/types/index.d.ts index 9e4e5716fb89..ca5d77581f94 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/unshift/docs/types/index.d.ts @@ -27,7 +27,7 @@ import { typedndarray } from '@stdlib/types/ndarray'; */ interface Unshift { /** - * Returns a one-dimensional ndarray formed by prepending the provided scalar values to a one-dimensional input ndarray. + * Returns a one-dimensional ndarray formed by prepending provided scalar values to a one-dimensional input ndarray. * * @param x - input ndarray * @param values - scalar values @@ -44,7 +44,7 @@ interface Unshift { ( x: typedndarray, ...values: Array ): typedndarray; /** - * Prepends the provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. + * Prepends provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. * * @param x - input ndarray * @param arg0 - scalar values @@ -67,7 +67,7 @@ interface Unshift { assign = typedndarray>( x: typedndarray, arg0: T, out: U ): U; /** - * Prepends the provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. + * Prepends provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. * * @param x - input ndarray * @param arg0 - scalar values @@ -91,7 +91,7 @@ interface Unshift { assign = typedndarray>( x: typedndarray, arg0: T, arg1: T, out: U ): U; /** - * Prepends the provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. + * Prepends provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. * * @param x - input ndarray * @param arg0 - scalar values @@ -116,7 +116,7 @@ interface Unshift { assign = typedndarray>( x: typedndarray, arg0: T, arg1: T, arg2: T, out: U ): U; /** - * Prepends the provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. + * Prepends provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. * * @param x - input ndarray * @param arg0 - scalar values @@ -142,7 +142,7 @@ interface Unshift { assign = typedndarray>( x: typedndarray, arg0: T, arg1: T, arg2: T, arg3: T, out: U ): U; /** - * Prepends the provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. + * Prepends provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. * * @param x - input ndarray * @param arg0 - scalar values @@ -169,7 +169,7 @@ interface Unshift { assign = typedndarray>( x: typedndarray, arg0: T, arg1: T, arg2: T, arg3: T, arg4: T, out: U ): U; /** - * Prepends the provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. + * Prepends provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. * * @param x - input ndarray * @param arg0 - scalar values @@ -198,7 +198,7 @@ interface Unshift { } /** -* Returns a one-dimensional ndarray formed by prepending the provided scalar values to a one-dimensional input ndarray. +* Returns a one-dimensional ndarray formed by prepending provided scalar values to a one-dimensional input ndarray. * * @param x - input ndarray * @param values - scalar values diff --git a/lib/node_modules/@stdlib/ndarray/unshift/examples/index.js b/lib/node_modules/@stdlib/ndarray/unshift/examples/index.js index 3096085eb9c0..6c7abf88fea0 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/unshift/examples/index.js @@ -18,7 +18,7 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); var array = require( '@stdlib/ndarray/array' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var unshift = require( './../lib' ); @@ -26,7 +26,7 @@ var unshift = require( './../lib' ); var opts = { 'dtype': 'generic' }; -var x = array( discreteUniform( 6, 0, 10, opts ), opts ); +var x = array( discreteUniform( [ 6 ], 0, 10, opts ), opts ); console.log( ndarray2array( x ) ); var out = unshift( x, 12, 14 ); diff --git a/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js b/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js index e8eb702e1965..aa62bbaa8243 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js +++ b/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js @@ -31,7 +31,7 @@ var format = require( '@stdlib/string/format' ); // MAIN // /** -* Prepends the provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. +* Prepends provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. * * @param {ndarray} x - input ndarray * @param {...*} values - scalar values diff --git a/lib/node_modules/@stdlib/ndarray/unshift/lib/index.js b/lib/node_modules/@stdlib/ndarray/unshift/lib/index.js index 1836e01ebaef..dda7a9c13df2 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/unshift/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Return a one-dimensional ndarray formed by prepending the provided scalar values to a one-dimensional input ndarray. +* Return a one-dimensional ndarray formed by prepending provided scalar values to a one-dimensional input ndarray. * * @module @stdlib/ndarray/unshift * diff --git a/lib/node_modules/@stdlib/ndarray/unshift/lib/main.js b/lib/node_modules/@stdlib/ndarray/unshift/lib/main.js index 1635bdb8d600..0df0eda13db5 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/unshift/lib/main.js @@ -31,7 +31,7 @@ var format = require( '@stdlib/string/format' ); // MAIN // /** -* Returns a one-dimensional ndarray formed by prepending the provided scalar values to a one-dimensional input ndarray. +* Returns a one-dimensional ndarray formed by prepending provided scalar values to a one-dimensional input ndarray. * * @param {ndarray} x - input ndarray * @param {...*} values - scalar values diff --git a/lib/node_modules/@stdlib/ndarray/unshift/package.json b/lib/node_modules/@stdlib/ndarray/unshift/package.json index 868536461ae8..672da51f0c6c 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/package.json +++ b/lib/node_modules/@stdlib/ndarray/unshift/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/ndarray/unshift", "version": "0.0.0", - "description": "Return a one-dimensional ndarray formed by prepending the provided scalar values to a one-dimensional input ndarray.", + "description": "Return a one-dimensional ndarray formed by prepending provided scalar values to a one-dimensional input ndarray.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/ndarray/unshift/test/test.assign.js b/lib/node_modules/@stdlib/ndarray/unshift/test/test.assign.js index 6ba138ee3694..4dd6ff0959a9 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/test/test.assign.js +++ b/lib/node_modules/@stdlib/ndarray/unshift/test/test.assign.js @@ -121,7 +121,7 @@ tape( 'the function throws an error if provided an output argument which is not function badValue( value ) { return function badValue() { - unshift( zeros( [ 2 ]), 0.0, value ); + unshift( zeros( [ 2 ] ), 0.0, value ); }; } }); @@ -159,7 +159,7 @@ tape( 'the function throws an error if provided insufficient arguments', functio } }); -tape( 'the function prepends the provided provided scalar values to the input ndarray and assigns results to an output ndarray (row-major, contiguous)', function test( t ) { +tape( 'the function prepends provided scalar values to the input ndarray and assigns results to an output ndarray (row-major, contiguous)', function test( t ) { var expected; var actual; var xbuf; @@ -187,7 +187,7 @@ tape( 'the function prepends the provided provided scalar values to the input nd t.end(); }); -tape( 'the function prepends the provided provided scalar values to the input ndarray and assigns results to an output ndarray (column-major, contiguous)', function test( t ) { +tape( 'the function prepends provided scalar values to the input ndarray and assigns results to an output ndarray (column-major, contiguous)', function test( t ) { var expected; var actual; var xbuf; @@ -215,7 +215,7 @@ tape( 'the function prepends the provided provided scalar values to the input nd t.end(); }); -tape( 'the function prepends the provided provided scalar values to the input ndarray and assigns results to an output ndarray (row-major, non-contiguous)', function test( t ) { +tape( 'the function prepends provided scalar values to the input ndarray and assigns results to an output ndarray (row-major, non-contiguous)', function test( t ) { var expected; var actual; var xbuf; @@ -243,7 +243,7 @@ tape( 'the function prepends the provided provided scalar values to the input nd t.end(); }); -tape( 'the function prepends the provided provided scalar values to the input ndarray and assigns results to an output ndarray (column-major, non-contiguous)', function test( t ) { +tape( 'the function prepends provided scalar values to the input ndarray and assigns results to an output ndarray (column-major, non-contiguous)', function test( t ) { var expected; var actual; var xbuf; From afb5afe6446d18fcd2b345fcd5b9cb9f3d254e33 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 25 Dec 2025 01:35:57 -0800 Subject: [PATCH 05/14] docs: fix example Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/unshift/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/unshift/README.md b/lib/node_modules/@stdlib/ndarray/unshift/README.md index 04879c1904da..1aec9750a2cd 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/README.md +++ b/lib/node_modules/@stdlib/ndarray/unshift/README.md @@ -106,14 +106,13 @@ The function accepts the following arguments: ```javascript var discreteUniform = require( '@stdlib/random/discrete-uniform' ); -var array = require( '@stdlib/ndarray/array' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var unshift = require( '@stdlib/ndarray/unshift' ); var opts = { 'dtype': 'generic' }; -var x = array( discreteUniform( [ 6 ], 0, 10, opts ), opts ); +var x = discreteUniform( [ 6 ], 0, 10, opts ); console.log( ndarray2array( x ) ); var out = unshift( x, 12, 14 ); From 055e0e5fd107cd3836d81ef942e80be0ca7c6f11 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 25 Dec 2025 01:38:31 -0800 Subject: [PATCH 06/14] docs: fix descriptions Signed-off-by: Athan --- .../ndarray/unshift/docs/types/index.d.ts | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/unshift/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/unshift/docs/types/index.d.ts index ca5d77581f94..ede9edc88743 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/unshift/docs/types/index.d.ts @@ -47,7 +47,7 @@ interface Unshift { * Prepends provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. * * @param x - input ndarray - * @param arg0 - scalar values + * @param arg0 - first scalar value * @param out - output ndarray * @returns output ndarray * @@ -70,8 +70,8 @@ interface Unshift { * Prepends provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. * * @param x - input ndarray - * @param arg0 - scalar values - * @param arg1 - scalar values + * @param arg0 - first scalar value + * @param arg1 - second scalar value * @param out - output ndarray * @returns output ndarray * @@ -94,9 +94,9 @@ interface Unshift { * Prepends provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. * * @param x - input ndarray - * @param arg0 - scalar values - * @param arg1 - scalar values - * @param arg2 - scalar values + * @param arg0 - first scalar value + * @param arg1 - second scalar value + * @param arg2 - third scalar value * @param out - output ndarray * @returns output ndarray * @@ -119,10 +119,10 @@ interface Unshift { * Prepends provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. * * @param x - input ndarray - * @param arg0 - scalar values - * @param arg1 - scalar values - * @param arg2 - scalar values - * @param arg3 - scalar values + * @param arg0 - first scalar value + * @param arg1 - second scalar value + * @param arg2 - third scalar value + * @param arg3 - fourth scalar value * @param out - output ndarray * @returns output ndarray * @@ -145,11 +145,11 @@ interface Unshift { * Prepends provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. * * @param x - input ndarray - * @param arg0 - scalar values - * @param arg1 - scalar values - * @param arg2 - scalar values - * @param arg3 - scalar values - * @param arg4 - scalar values + * @param arg0 - first scalar value + * @param arg1 - second scalar value + * @param arg2 - third scalar value + * @param arg3 - fourth scalar value + * @param arg4 - fifth scalar value * @param out - output ndarray * @returns output ndarray * @@ -172,11 +172,11 @@ interface Unshift { * Prepends provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray. * * @param x - input ndarray - * @param arg0 - scalar values - * @param arg1 - scalar values - * @param arg2 - scalar values - * @param arg3 - scalar values - * @param arg4 - scalar values + * @param arg0 - first scalar value + * @param arg1 - second scalar value + * @param arg2 - third scalar value + * @param arg3 - fourth scalar value + * @param arg4 - fifth scalar value * @param args - additional scalar values and an output ndarray * @param out - output ndarray * @returns output ndarray From 42ebbc2694d6504ae4b373c6ff539dd1d0ea8ca7 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 25 Dec 2025 01:39:08 -0800 Subject: [PATCH 07/14] docs: update example Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/unshift/examples/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/unshift/examples/index.js b/lib/node_modules/@stdlib/ndarray/unshift/examples/index.js index 6c7abf88fea0..e2918e4c4a11 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/unshift/examples/index.js @@ -19,14 +19,13 @@ 'use strict'; var discreteUniform = require( '@stdlib/random/discrete-uniform' ); -var array = require( '@stdlib/ndarray/array' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var unshift = require( './../lib' ); var opts = { 'dtype': 'generic' }; -var x = array( discreteUniform( [ 6 ], 0, 10, opts ), opts ); +var x = discreteUniform( [ 6 ], 0, 10, opts ); console.log( ndarray2array( x ) ); var out = unshift( x, 12, 14 ); From 8fe8f486db5112fab5388b1479a608114bab70a7 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 25 Dec 2025 01:41:27 -0800 Subject: [PATCH 08/14] docs: fix description Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js b/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js index aa62bbaa8243..31fc3dbf296f 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js +++ b/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js @@ -37,7 +37,7 @@ var format = require( '@stdlib/string/format' ); * @param {...*} values - scalar values * @param {ndarray} out - output ndarray * @throws {TypeError} first argument must a be one-dimensional ndarray -* @throws {Error} must be provided at least three arguments +* @throws {Error} must provide at least three arguments * @throws {TypeError} output argument must a be one-dimensional ndarray * @returns {ndarray} output ndarray * From 6fdc3cd0a390e80f0c19016a18ac7b908b362288 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 25 Dec 2025 01:42:48 -0800 Subject: [PATCH 09/14] docs: fix descriptions Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js b/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js index 31fc3dbf296f..5d36085b76d1 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js +++ b/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js @@ -36,9 +36,9 @@ var format = require( '@stdlib/string/format' ); * @param {ndarray} x - input ndarray * @param {...*} values - scalar values * @param {ndarray} out - output ndarray -* @throws {TypeError} first argument must a be one-dimensional ndarray +* @throws {TypeError} first argument must be a one-dimensional ndarray +* @throws {TypeError} last argument must be a one-dimensional ndarray * @throws {Error} must provide at least three arguments -* @throws {TypeError} output argument must a be one-dimensional ndarray * @returns {ndarray} output ndarray * * @example From 2257cbeaf448a7ed07bf79bc4afebfcaf27f8d98 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 25 Dec 2025 01:43:35 -0800 Subject: [PATCH 10/14] fix: update error message Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js b/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js index 5d36085b76d1..94308d306884 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js +++ b/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js @@ -66,7 +66,7 @@ function assign( x ) { } nargs = arguments.length; if ( nargs < 3 ) { - throw new Error( 'invalid operation. Must provide at least three arguments.' ); + throw new Error( 'invalid invocation. Must provide at least three arguments.' ); } out = arguments[ nargs - 1 ]; if ( !isndarrayLike( out ) || ndims( out ) !== 1 ) { From 33b5073a1ec009d40e4713d8eba65422fde56207 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 25 Dec 2025 01:44:11 -0800 Subject: [PATCH 11/14] fix: update error message Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js b/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js index 94308d306884..1427564144a0 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js +++ b/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js @@ -70,7 +70,7 @@ function assign( x ) { } out = arguments[ nargs - 1 ]; if ( !isndarrayLike( out ) || ndims( out ) !== 1 ) { - throw new TypeError( format( 'invalid argument. Output argument must be a one-dimensional ndarray. Value: `%s`.', out ) ); + throw new TypeError( format( 'invalid argument. Last argument must be a one-dimensional ndarray. Value: `%s`.', out ) ); } args = []; dtype = getDType( x ); From 0dc164fa137ab7d201a894cebc924ce1ca9e98db Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 25 Dec 2025 01:45:07 -0800 Subject: [PATCH 12/14] style: remove spaces Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js b/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js index 1427564144a0..050631acea50 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js +++ b/lib/node_modules/@stdlib/ndarray/unshift/lib/assign.js @@ -68,13 +68,13 @@ function assign( x ) { if ( nargs < 3 ) { throw new Error( 'invalid invocation. Must provide at least three arguments.' ); } - out = arguments[ nargs - 1 ]; + out = arguments[ nargs-1 ]; if ( !isndarrayLike( out ) || ndims( out ) !== 1 ) { throw new TypeError( format( 'invalid argument. Last argument must be a one-dimensional ndarray. Value: `%s`.', out ) ); } - args = []; dtype = getDType( x ); - for ( i = 1; i < nargs - 1; i++ ) { + args = []; + for ( i = 1; i < nargs-1; i++ ) { args.push( scalar2ndarray( arguments[ i ], { 'dtype': dtype })); From 7d0ff00bf6ddc3e9394d4fd8ca24477c6893ea52 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 25 Dec 2025 01:46:47 -0800 Subject: [PATCH 13/14] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/unshift/lib/main.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/unshift/lib/main.js b/lib/node_modules/@stdlib/ndarray/unshift/lib/main.js index 0df0eda13db5..bc037cb9093d 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/unshift/lib/main.js @@ -35,8 +35,8 @@ var format = require( '@stdlib/string/format' ); * * @param {ndarray} x - input ndarray * @param {...*} values - scalar values -* @throws {TypeError} first argument must a be one-dimensional ndarray -* @throws {Error} must be provided at least two arguments +* @throws {TypeError} first argument must be a one-dimensional ndarray +* @throws {Error} must provide at least two arguments * @returns {ndarray} output ndarray * * @example @@ -58,7 +58,7 @@ function unshift( x ) { } nargs = arguments.length; if ( nargs < 2 ) { - throw new Error( 'invalid operation. Must provide at least two arguments.' ); + throw new Error( 'invalid invocation. Must provide at least two arguments.' ); } args = []; dtype = getDType( x ); From db742ac87e4af4df8522f1bdb2c2bf22fa5c048c Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 25 Dec 2025 01:47:41 -0800 Subject: [PATCH 14/14] refactor: swap lines Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/unshift/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/unshift/lib/main.js b/lib/node_modules/@stdlib/ndarray/unshift/lib/main.js index bc037cb9093d..00e4dcb3a164 100644 --- a/lib/node_modules/@stdlib/ndarray/unshift/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/unshift/lib/main.js @@ -60,8 +60,8 @@ function unshift( x ) { if ( nargs < 2 ) { throw new Error( 'invalid invocation. Must provide at least two arguments.' ); } - args = []; dtype = getDType( x ); + args = []; for ( i = 1; i < nargs; i++ ) { args.push( scalar2ndarray( arguments[ i ], { 'dtype': dtype