diff --git a/lib/node_modules/@stdlib/ndarray/push/README.md b/lib/node_modules/@stdlib/ndarray/push/README.md new file mode 100644 index 000000000000..818c6af8d55f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/push/README.md @@ -0,0 +1,155 @@ + + +# push + +> Return a one-dimensional [ndarray][@stdlib/ndarray/ctor] formed by appending the provided scalar values to the input [ndarray][@stdlib/ndarray/ctor]. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var push = require( '@stdlib/ndarray/push' ); +``` + +#### push( x, ...values ) + +Returns a one-dimensional [ndarray][@stdlib/ndarray/ctor] formed by appending the provided scalar values to the 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 = push( x, 5.0, 6.0, 7.0 ); +// returns + +var arr = ndarray2array( out ); +// returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ] +``` + +The function accepts the following arguments: + +- **arr**: input [ndarray][@stdlib/ndarray/ctor]. +- **...values**: scalar values to append. + +#### push.assign( x, ...values, out ) + +Appends 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 = push.assign( x, 5.0, 6.0, 7.0, y ); +// returns + +var bool = ( out === y ); +// returns true + +var arr = ndarray2array( y ); +// returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ] +``` + +The function accepts the following arguments: + +- **arr**: input [ndarray][@stdlib/ndarray/ctor]. +- **out**: output [ndarray][@stdlib/ndarray/ctor]. +- **...values**: scalar values to append. + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var push = require( '@stdlib/ndarray/push' ); + +var opts = { + 'dtype': 'generic' +}; +var x = array( discreteUniform( 6, 0, 10, opts ), opts ); +console.log( ndarray2array( x ) ); + +var out = push( x, 12.0, 14.0 ); +console.log( ndarray2array( out ) ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/push/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/ndarray/push/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..4e9a19ad490e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/push/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 push = 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 = push( 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 = push( 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 = push( 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/push/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/push/benchmark/benchmark.js new file mode 100644 index 000000000000..3d2923206abc --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/push/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 push = 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 = push( 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 = push( 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 = push( 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/push/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/push/docs/repl.txt new file mode 100644 index 000000000000..8272f0576095 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/push/docs/repl.txt @@ -0,0 +1,60 @@ + +{{alias}}( x, ...values ) + Returns a one-dimensional ndarray formed by appending the provided scalar + values to the input ndarray. + + Parameters + ---------- + x: ndarray + Input ndarray. + + values: ...any + Scalar values to append. + + Returns + ------- + out: ndarray + Output ndarray. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var out = {{alias}}( x, 5.0, 6.0 ) + + > var arr = {{alias:@stdlib/ndarray/to-array}}( out ) + [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] + + +{{alias}}.assign( x, ...values, out ) + Appends the provided scalar values to the input ndarray and assigns the + result to a provided one-dimensional output ndarray. + + Parameters + ---------- + x: ndarray + Input ndarray. + + values: ...any + Scalar values to append. + + 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, 3.0, 4.0, y ) + + > var bool = ( out === y ) + true + > var arr = {{alias:@stdlib/ndarray/to-array}}( out ) + [ 1.0, 2.0, 3.0, 4.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/ndarray/push/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/push/docs/types/index.d.ts new file mode 100644 index 000000000000..ca8ca11c5615 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/push/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 `push`. +*/ +interface Push { + /** + * Returns a one-dimensional ndarray formed by appending 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 = push( x, 5.0, 6.0, 7.0 ); + * // returns + * + * var arr = ndarray2array( out ); + * // returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ] + */ + ( x: typedndarray, ...values: Array ): typedndarray; + + /** + * Appends 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 = push.assign( x, 5.0, 6.0, 7.0, y ); + * // returns + * + * var bool = ( out === y ); + * // returns true + * + * var arr = ndarray2array( y ); + * // returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ] + */ + assign = typedndarray>( x: typedndarray, ...values: Array, out: V ): V; +} + +/** +* Returns a one-dimensional ndarray formed by appending 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 = push( x, 5.0, 6.0, 7.0 ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.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 = push.assign( x, 5.0, 6.0, 7.0, y ); +* // returns +* +* var bool = ( out === y ); +* // returns true +* +* var arr = ndarray2array( y ); +* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ] +*/ +declare var push: Push; + + +// EXPORTS // + +export = push; diff --git a/lib/node_modules/@stdlib/ndarray/push/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/push/docs/types/test.ts new file mode 100644 index 000000000000..0f27b7f405c1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/push/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 push = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ] ); + + push( x, 1.0 ); // $ExpectType typedndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + push( '10', 1.0 ); // $ExpectError + push( 10, 1.0 ); // $ExpectError + push( false, 1.0 ); // $ExpectError + push( true, 1.0 ); // $ExpectError + push( null, 1.0 ); // $ExpectError + push( [], 1.0 ); // $ExpectError + push( {}, 1.0 ); // $ExpectError + push( ( x: number ): number => x, 1.0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + push(); // $ExpectError +} + +// Attached to the function is an `assign` method which returns an ndarray... +{ + const x = zeros( [ 2 ] ); + const out = zeros( [ 3 ] ); + + push.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 ] ); + + push.assign( '10', 1.0, out ); // $ExpectError + push.assign( 10, 1.0, out ); // $ExpectError + push.assign( false, 1.0, out ); // $ExpectError + push.assign( true, 1.0, out ); // $ExpectError + push.assign( null, 1.0, out ); // $ExpectError + push.assign( [], 1.0, out ); // $ExpectError + push.assign( {}, 1.0, out ); // $ExpectError + push.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 ] ); + + push.assign( x, 1.0, '10' ); // $ExpectError + push.assign( x, 1.0, 10 ); // $ExpectError + push.assign( x, 1.0, false ); // $ExpectError + push.assign( x, 1.0, true ); // $ExpectError + push.assign( x, 1.0, null ); // $ExpectError + push.assign( x, 1.0, [] ); // $ExpectError + push.assign( x, 1.0, {} ); // $ExpectError + push.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 ] ); + + push.assign(); // $ExpectError + push.assign( x ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/push/examples/index.js b/lib/node_modules/@stdlib/ndarray/push/examples/index.js new file mode 100644 index 000000000000..7673e1ca28ad --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/push/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 push = require( './../lib' ); + +var opts = { + 'dtype': 'generic' +}; +var x = array( discreteUniform( 6, 0, 10, opts ), opts ); +console.log( ndarray2array( x ) ); + +var out = push( x, 12.0, 14.0 ); +console.log( ndarray2array( out ) ); diff --git a/lib/node_modules/@stdlib/ndarray/push/lib/assign.js b/lib/node_modules/@stdlib/ndarray/push/lib/assign.js new file mode 100644 index 000000000000..28d76a8c54da --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/push/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 scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var ndims = require( '@stdlib/ndarray/ndims' ); +var concat1d = require( '@stdlib/ndarray/concat1d' ).assign; +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Appends 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 {Error} must provide at least three arguments +* @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, 5.0, 6.0, 7.0, y ); +* // returns +* +* var bool = ( out === y ); +* // returns true +* +* var arr = ndarray2array( y ); +* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.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 ) ); + } + dtype = getDType( x ); + args = [ x ]; + for ( i = 1; i < nargs - 1; i++ ) { + args.push( scalar2ndarray( arguments[ i ], { + 'dtype': dtype + })); + } + return concat1d( args, out ); +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/ndarray/push/lib/index.js b/lib/node_modules/@stdlib/ndarray/push/lib/index.js new file mode 100644 index 000000000000..cd90839458b4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/push/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 appending the provided scalar values to the input ndarray. +* +* @module @stdlib/ndarray/push +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var push = require( '@stdlib/ndarray/push' ); +* +* var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* +* var out = push( x, 5.0, 6.0, 7.0 ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.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/push/lib/main.js b/lib/node_modules/@stdlib/ndarray/push/lib/main.js new file mode 100644 index 000000000000..6174ef9393e4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/push/lib/main.js @@ -0,0 +1,80 @@ +/** +* @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 scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var ndims = require( '@stdlib/ndarray/ndims' ); +var concat1d = require( '@stdlib/ndarray/concat1d' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns a one-dimensional ndarray formed by appending 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 = push( x, 5.0, 6.0, 7.0 ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ] +*/ +function push( 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( 'invalid operation. Must provide at least two arguments.' ); + } + dtype = getDType( x ); + args = [ x ]; + for ( i = 1; i < nargs; i++ ) { + args.push( scalar2ndarray( arguments[ i ], { + 'dtype': dtype + })); + } + return concat1d( args ); +} + + +// EXPORTS // + +module.exports = push; diff --git a/lib/node_modules/@stdlib/ndarray/push/package.json b/lib/node_modules/@stdlib/ndarray/push/package.json new file mode 100644 index 000000000000..4812e8c0bda3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/push/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/ndarray/push", + "version": "0.0.0", + "description": "Return a one-dimensional ndarray formed by appending 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", + "data", + "structure", + "vector", + "ndarray", + "matrix", + "push", + "append", + "add", + "concat", + "concatenate", + "join", + "merge", + "combine" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/push/test/test.assign.js b/lib/node_modules/@stdlib/ndarray/push/test/test.assign.js new file mode 100644 index 000000000000..e1556bf56cb6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/push/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 push = require( './../lib/assign.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof push, '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() { + push( 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() { + push( 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() { + push( 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() { + push( zeros( [ 2 ] ), 0.0, value ); + }; + } +}); + +tape( 'the function appends 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 = push( x, 5.0, 6.0, y ); + + actual = ndarray2array( y ); + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.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 appends 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 = push( x, 5.0, 6.0, y ); + + actual = ndarray2array( y ); + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.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 appends 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 = push( x, 5.0, 6.0, y ); + + actual = ndarray2array( y ); + expected = [ 1.0, 3.0, 5.0, 7.0, 5.0, 6.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 appends 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 = push( x, 5.0, 6.0, y ); + + actual = ndarray2array( y ); + expected = [ 1.0, 3.0, 5.0, 7.0, 5.0, 6.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/push/test/test.js b/lib/node_modules/@stdlib/ndarray/push/test/test.js new file mode 100644 index 000000000000..704a83f7974e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/push/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 push = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof push, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( push, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/push/test/test.main.js b/lib/node_modules/@stdlib/ndarray/push/test/test.main.js new file mode 100644 index 000000000000..27a023321817 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/push/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 push = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof push, '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() { + push( 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() { + push( value, 0.0 ); + }; + } +}); + +tape( 'the function returns a one-dimensional ndarray formed by appending 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 = push( x, 5.0, 6.0 ); + + actual = ndarray2array( out ); + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.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 appending 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 = push( x, 5.0, 6.0 ); + + actual = ndarray2array( out ); + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.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 appending 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 = push( x, 5.0, 6.0 ); + + actual = ndarray2array( out ); + expected = [ 1.0, 3.0, 5.0, 7.0, 5.0, 6.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 appending 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 = push( x, 5.0, 6.0 ); + + actual = ndarray2array( out ); + expected = [ 1.0, 3.0, 5.0, 7.0, 5.0, 6.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(); +});