diff --git a/lib/node_modules/@stdlib/ndarray/concat1d/README.md b/lib/node_modules/@stdlib/ndarray/concat1d/README.md new file mode 100644 index 000000000000..c067f8bd81e9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/concat1d/README.md @@ -0,0 +1,232 @@ + + +# concat1d + +> Return a one-dimensional [ndarray][@stdlib/ndarray/ctor] formed by concatenating the provided input arguments. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var concat1d = require( '@stdlib/ndarray/concat1d' ); +``` + +#### concat1d( ...arrays ) + +Returns a one-dimensional [ndarray][@stdlib/ndarray/ctor] formed by concatenating the provided input arguments. + +```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 y = array( [ -5.0, 6.0, -7.0, -8.0, 9.0, -10.0 ] ); + +var out = concat1d( x, y ); +// returns + +var arr = ndarray2array( out ); +// returns [ -1.0, 2.0, 3.0, 4.0, -5.0, 6.0, -7.0, -8.0, 9.0, -10.0 ] +``` + +The function accepts the following arguments: + +- **...arrays**: inputs to concatenate. May be passed as separate arguments or an array of arguments. Where each argument must either be a one-dimensional [ndarray][@stdlib/ndarray/ctor], a zero-dimensional[ndarray][@stdlib/ndarray/ctor] or a scalar value. The data type of the output [ndarray][@stdlib/ndarray/ctor] is determined by applying [type promotion rules][@stdlib/ndarray/promotion-rules]. If provided scalar inputs or [ndarrays][@stdlib/ndarray/ctor] having different [memory layouts][@stdlib/ndarray/orders], the output [ndarray][@stdlib/ndarray/ctor] has the [default order][@stdlib/ndarray/defaults]. + +The following example demonstrates each invocation style returning equivalent results. + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +var x = array( [ -1.0, 2.0 ] ); +var y = scalar2ndarray( -3.0 ); + +// 1. Using separate arguments: +var out = concat1d( x, y, 4.0 ); +// returns + +var arr = ndarray2array( out ); +// returns [ -1.0, 2.0, -3.0, 4.0 ] + +x = array( [ -5.0, 6.0 ] ); +y = scalar2ndarray( -7.0 ); + +// 2. Using an array of arguments: +out = concat1d( [ x, y, 8.0 ] ); +// returns + +arr = ndarray2array( out ); +// returns [ -5.0, 6.0, -7.0, 8.0 ] +``` + +#### concat1d.assign( ...arrays, out ) + +Concatenates provided input arguments 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 = array( [ -5.0, 6.0, -7.0, -8.0 ] ); +var z = zeros( [ 8 ] ); + +var out = concat1d.assign( x, y, z ); +// returns + +var bool = ( out === z ); +// returns true + +var arr = ndarray2array( z ); +// returns [ -1.0, 2.0, 3.0, 4.0, -5.0, 6.0, -7.0, -8.0 ] +``` + +The function accepts the following arguments: + +- **...arrays**: inputs to concatenate. May be passed as separate arguments or an array of arguments. Where each argument must either be a one-dimensional [ndarray][@stdlib/ndarray/ctor], a zero-dimensional[ndarray][@stdlib/ndarray/ctor] or a scalar value. The data type of the output [ndarray][@stdlib/ndarray/ctor] is determined by applying [type promotion rules][@stdlib/ndarray/promotion-rules]. If provided scalar inputs or [ndarrays][@stdlib/ndarray/ctor] having different [memory layouts][@stdlib/ndarray/orders], the output [ndarray][@stdlib/ndarray/ctor] has the [default order][@stdlib/ndarray/defaults]. +- **out**: output [ndarray][@stdlib/ndarray/ctor]. + +The following example demonstrates each invocation style returning equivalent results. + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +var x = array( [ -1.0, 2.0 ] ); +var y = scalar2ndarray( -3.0 ); +var z = zeros( [ 4 ] ); + +// 1. Using separate arguments: +var out = concat1d.assign( x, y, 4.0, z ); +// returns + +var bool = ( out === z ); +// returns true + +var arr = ndarray2array( z ); +// returns [ -1.0, 2.0, -3.0, 4.0 ] + +x = array( [ -5.0, 6.0 ] ); +y = scalar2ndarray( -7.0 ); +z = zeros( [ 4 ] ); + +// 2. Using an array of arguments: +out = concat1d.assign( [ x, y, 8.0 ], z ); +// returns + +bool = ( out === z ); +// returns true + +arr = ndarray2array( out ); +// returns [ -5.0, 6.0, -7.0, 8.0 ] +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var concat1d = require( '@stdlib/ndarray/concat1d' ); + +var xbuf = discreteUniform( 6, 0, 10, { + 'dtype': 'generic' +}); +var x = new ndarray( 'generic', xbuf, [ 6 ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var ybuf = discreteUniform( 8, 0, 10, { + 'dtype': 'generic' +}); +var y = new ndarray( 'generic', ybuf, [ 8 ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( y ) ); + +var out = concat1d( x, y ); +console.log( ndarray2array( out ) ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/concat1d/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/ndarray/concat1d/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..1a70444e1828 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/concat1d/benchmark/benchmark.assign.js @@ -0,0 +1,156 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var concat1d = require( './../lib/assign.js' ); + + +// MAIN // + +bench( pkg+'::ndarrays', function benchmark( b ) { + var values; + var opts; + var out; + var v; + var i; + + opts = { + 'dtype': 'float64' + }; + + values = [ + zeros( [ 32 ], opts ), + zeros( [ 32 ], opts ), + zeros( [ 32 ], opts ), + zeros( [ 32 ], opts ) + ]; + out = zeros( [ 128 ], opts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = concat1d( values, 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( pkg+'::ndarrays,casting', function benchmark( b ) { + var values; + var out; + var v; + var i; + + /* eslint-disable object-curly-newline */ + + values = [ + zeros( [ 32 ], { 'dtype': 'float64' }), + zeros( [ 32 ], { 'dtype': 'float32' }), + zeros( [ 32 ], { 'dtype': 'int32' }), + zeros( [ 32 ], { 'dtype': 'generic' }) + ]; + out = zeros( [ 128 ], { 'dtype': 'generic' }); + + /* eslint-enable object-curly-newline */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = concat1d( values, 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( pkg+'::scalars', function benchmark( b ) { + var values; + var out; + var v; + var i; + + values = [ + 1.0, + 2.0, + 3.0, + 4.0 + ]; + out = zeros( [ 4 ] ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = concat1d( values, 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( pkg+'::ndarrays+scalars', function benchmark( b ) { + var values; + var out; + var v; + var i; + + values = [ + zeros( [ 4 ] ), + 1.0, + 2.0, + zeros( [ 2 ] ), + 4.0 + ]; + out = zeros( [ 9 ] ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = concat1d( values, 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/concat1d/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/concat1d/benchmark/benchmark.js new file mode 100644 index 000000000000..76ca95d2828c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/concat1d/benchmark/benchmark.js @@ -0,0 +1,148 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var concat1d = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::ndarrays', function benchmark( b ) { + var values; + var opts; + var v; + var i; + + opts = { + 'dtype': 'float64' + }; + + values = [ + zeros( [ 32 ], opts ), + zeros( [ 32 ], opts ), + zeros( [ 32 ], opts ), + zeros( [ 32 ], opts ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = concat1d( values ); + 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( pkg+'::ndarrays,casting', function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline */ + + values = [ + zeros( [ 32 ], { 'dtype': 'float64' }), + zeros( [ 32 ], { 'dtype': 'float32' }), + zeros( [ 32 ], { 'dtype': 'int32' }), + zeros( [ 32 ], { 'dtype': 'generic' }) + ]; + + /* eslint-enable object-curly-newline */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = concat1d( values ); + 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( pkg+'::scalars', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + 1.0, + 2.0, + 3.0, + 4.0 + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = concat1d( values ); + 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( pkg+'::ndarrays+scalars', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + zeros( [ 4 ] ), + 1.0, + 2.0, + zeros( [ 2 ] ), + 4.0 + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = concat1d( values ); + 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/concat1d/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/concat1d/docs/repl.txt new file mode 100644 index 000000000000..ae48912e0c6d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/concat1d/docs/repl.txt @@ -0,0 +1,65 @@ + +{{alias}}( ...arrays ) + Returns a one-dimensional ndarray formed by + concatenating the provided inputs. + + Parameters + ---------- + arrays: ...ArrayLike|ndarray|any + Inputs to concatenate. May be passed as separate arguments or an array + of arguments. Where each argument must either be a one-dimensional + ndarray, a zero-dimensional ndarray or a scalar value. The data type of + the output ndarray is determined by applying type promotion rules. If + provided scalar inputs or ndarrays having different memory layouts, the + output ndarray has the default order. + + Returns + ------- + out: ndarray + Output ndarray. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var y = {{alias:@stdlib/ndarray/array}}( [ 5.0, 6.0, 7.0, 8.0 ] ); + > var out = {{alias}}( x, y ) + + > var arr = {{alias:@stdlib/ndarray/to-array}}( out ) + [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] + + +{{alias}}.assign( ...arrays, out ) + Concatenates the provided inputs and assigns results to an output ndarray. + + Parameters + ---------- + arrays: ...ArrayLike|ndarray|any + Inputs to concatenate. May be passed as separate arguments or an array + of arguments. Where each argument must either be a one-dimensional + ndarray, a zero-dimensional ndarray or a scalar value. The data type of + the output ndarray is determined by applying type promotion rules. If + provided scalar inputs or ndarrays having different memory layouts, the + output ndarray has the default order. + + 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}}( [ 3.0, 4.0 ] ); + > var z = {{alias:@stdlib/ndarray/array}}( [ 0.0, 0.0, 0.0, 0.0 ] ); + > var out = {{alias}}.assign( [ x, y ], z ) + + > var bool = ( out === z ) + 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/concat1d/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/concat1d/docs/types/index.d.ts new file mode 100644 index 000000000000..db4bc986218e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/concat1d/docs/types/index.d.ts @@ -0,0 +1,174 @@ +/* +* @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 { ArrayLike } from '@stdlib/types/array'; +import { typedndarray } from '@stdlib/types/ndarray'; + +type Input = typedndarray | number | T; + +/** +* Interface describing `concat1d`. +*/ +interface Concat1d { + /** + * Returns a one-dimensional ndarray formed by concatenating the provided input arguments. + * + * @param arrays - input arguments + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * var ndarray2array = require( '@stdlib/ndarray/to-array' ); + * var ndarray2array = require( '@stdlib/ndarray/to-array' ); + * + * var x = array( [ -1.0, 2.0, 3.0, 4.0 ] ); + * var y = array( [ -5.0, 6.0, -7.0, -8.0, 9.0, -10.0 ] ); + * + * var out = concat1d( [ x, y ] ); + * // returns + * + * var arr = ndarray2array( out ); + * // returns [ -1.0, 2.0, 3.0, 4.0, -5.0, 6.0, -7.0, -8.0, 9.0, -10.0 ] + */ + ( arrays: Array> ): typedndarray; + + /** + * Returns a one-dimensional ndarray formed by concatenating the provided input arguments. + * + * @param arrays - input arguments + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * var ndarray2array = require( '@stdlib/ndarray/to-array' ); + * var ndarray2array = require( '@stdlib/ndarray/to-array' ); + * + * var x = array( [ -1.0, 2.0, 3.0, 4.0 ] ); + * var y = array( [ -5.0, 6.0, -7.0, -8.0, 9.0, -10.0 ] ); + * + * var out = concat1d( x, y ); + * // returns + * + * var arr = ndarray2array( out ); + * // returns [ -1.0, 2.0, 3.0, 4.0, -5.0, 6.0, -7.0, -8.0, 9.0, -10.0 ] + */ + ( ...arrays: Array> ): typedndarray; + + /** + * Concatenates provided input arguments and assigns the result to a provided one-dimensional output ndarray. + * + * @param args - input arguments + * @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 = array( [ -5.0, 6.0, -7.0, -8.0, 9.0, -10.0 ] ); + * var z = empty( [ 10 ] ); + * + * var out = concat1d.assign( [ x, y ], z ); + * // returns + * + * var bool = ( out === z ); + * // returns true + * + * var arr = ndarray2array( z ); + * // returns [ -1.0, 2.0, 3.0, 4.0, -5.0, 6.0, -7.0, -8.0, 9.0, -10.0 ] + */ + assign = typedndarray>( args: ArrayLike>, out: V ): V; + + /** + * Concatenates provided input arguments and assigns the result to a provided one-dimensional output ndarray. + * + * @param args - input arguments + * @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 = array( [ -5.0, 6.0, -7.0, -8.0, 9.0, -10.0 ] ); + * var z = empty( [ 10 ] ); + * + * var out = concat1d.assign( x, y, z ); + * // returns + * + * var bool = ( out === z ); + * // returns true + * + * var arr = ndarray2array( z ); + * // returns [ -1.0, 2.0, 3.0, 4.0, -5.0, 6.0, -7.0, -8.0, 9.0, -10.0 ] + */ + assign = typedndarray>( ...args: Array> ): V; +} + +/** +* Returns a one-dimensional ndarray formed by concatenating the provided input arguments. +* +* @param arrays - input arguments +* @returns output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var x = array( [ -1.0, 2.0, 3.0, 4.0 ] ); +* var y = array( [ -5.0, 6.0, -7.0, -8.0, 9.0, -10.0 ] ); +* +* var out = concat1d( [ x, y ] ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ -1.0, 2.0, 3.0, 4.0, -5.0, 6.0, -7.0, -8.0, 9.0, -10.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 = array( [ -5.0, 6.0, -7.0, -8.0, 9.0, -10.0 ] ); +* var z = empty( [ 10 ] ); +* +* var out = concat1d.assign( [ x, y ], z ); +* // returns +* +* var bool = ( out === z ); +* // returns true +* +* var arr = ndarray2array( z ); +* // returns [ -1.0, 2.0, 3.0, 4.0, -5.0, 6.0, -7.0, -8.0, 9.0, -10.0 ] +*/ +declare var concat1d: Concat1d; + + +// EXPORTS // + +export = concat1d; diff --git a/lib/node_modules/@stdlib/ndarray/concat1d/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/concat1d/docs/types/test.ts new file mode 100644 index 000000000000..067e2af7fd40 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/concat1d/docs/types/test.ts @@ -0,0 +1,54 @@ +/* +* @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 concat1d = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ] ); + const y = zeros( [ 2, 3 ] ); + + concat1d( [ x, y ] ); // $ExpectType typedndarray + concat1d( x, y ); // $ExpectType typedndarray +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + concat1d(); // $ExpectError +} + +// Attached to the function is an `assign` method which returns an ndarray... +{ + const x = zeros( [ 2, 2 ] ); + const y = zeros( [ 2, 3 ] ); + const out = zeros( [ 2, 5 ] ); + + concat1d.assign( [ x, y ], out ); // $ExpectType float64ndarray + concat1d.assign( x, y, out ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + concat1d.assign(); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/concat1d/examples/index.js b/lib/node_modules/@stdlib/ndarray/concat1d/examples/index.js new file mode 100644 index 000000000000..a0e1834cfb5d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/concat1d/examples/index.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'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var concat1d = require( './../lib' ); + +var xbuf = discreteUniform( 6, 0, 10, { + 'dtype': 'generic' +}); +var x = new ndarray( 'generic', xbuf, [ 6 ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var ybuf = discreteUniform( 8, 0, 10, { + 'dtype': 'generic' +}); +var y = new ndarray( 'generic', ybuf, [ 8 ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( y ) ); + +var out = concat1d( x, y ); +console.log( ndarray2array( out ) ); diff --git a/lib/node_modules/@stdlib/ndarray/concat1d/lib/assign.js b/lib/node_modules/@stdlib/ndarray/concat1d/lib/assign.js new file mode 100644 index 000000000000..e413932b0252 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/concat1d/lib/assign.js @@ -0,0 +1,141 @@ +/** +* @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 broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); +var concat = require( '@stdlib/ndarray/concat' ); +var ndims = require( '@stdlib/ndarray/base/ndims' ); +var isArray = require( '@stdlib/assert/is-array' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var broadcastArray = require( '@stdlib/ndarray/broadcast-array' ); +var format = require( '@stdlib/string/format' ); +var defaults = require( '@stdlib/ndarray/defaults' ); +var normalizeArrays = require( './normalize_arrays.js' ); +var resolveDataTypes = require( './resolve_dtypes.js' ); +var resolveOrder = require( './resolve_order.js' ); + + +// VARIABLES // + +var DEFAULT_ORDER = defaults.get( 'order' ); +var DEFAULT_DTYPE = defaults.get( 'dtypes.default' ); + + +// MAIN // + +/** +* Concatenates provided input arguments and assigns the result to a provided one-dimensional output ndarray. +* +* @param {...*} args - input arguments +* @param {ndarray} out - output ndarray +* @throws {Error} function must be provided an array of inputs or more than one separate input arguments and an output ndarray +* @throws {RangeError} function must be provided a one-dimensional ndarray or a zero-dimensional ndarray +* @throws {Error} output argument must be a one-dimensional ndarray-like object +* @returns {ndarray} 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 = array( [ -5.0, 6.0, -7.0, -8.0, 9.0, -10.0 ] ); +* var z = empty( [ 10 ] ); +* +* var out = assign( x, y, z ); +* // returns +* +* var bool = ( out === z ); +* // returns true +* +* var arr = ndarray2array( z ); +* // returns [ -1.0, 2.0, 3.0, 4.0, -5.0, 6.0, -7.0, -8.0, 9.0, -10.0 ] +*/ +function assign() { + var nargs; + var args; + var arrs; + var ord; + var out; + var dt; + var i; + var d; + + nargs = arguments.length; + + // Resolve function arguments... + if ( nargs < 2 ) { + throw new Error( format( 'invalid argument. The function must be provided an array of inputs or more than one separate input arguments and an output ndarray. Value: `%s`.', nargs ) ); + } + if ( nargs > 2 ) { + args = []; + for ( i = 0; i < nargs - 1; i++ ) { + args.push( arguments[ i ] ); + } + } + if ( nargs === 2 ) { + if ( isArray( arguments[ 0 ] ) ) { + args = arguments[ 0 ]; + } else { + args = []; + args.push( arguments[ 0 ] ); + } + } + out = arguments[ nargs - 1 ]; + if ( !isndarrayLike( out ) || ndims( out ) !== 1 ) { + throw new Error( format( 'invalid argument. Output argument must be a one-dimensional ndarray. Value: `%s`.', out ) ); + } + + // Resolve the `dtype` and `order` of input ndarrays... + arrs = []; + for ( i = 0; i < args.length; i++ ) { + if ( isndarrayLike( args[ i ] ) ) { + d = ndims( args[ i ] ); + if ( d > 1 ) { + throw new RangeError( format( 'invalid argument. The function must be provided a one-dimensional ndarray or a zero-dimensional ndarray.. Value: `%s`.', d ) ); + } + arrs.push( args[ i ] ); + } + } + if ( arrs.length >= 1 ) { + dt = resolveDataTypes( arrs ); + ord = resolveOrder( arrs ); + } + + // Broadcast scalar or 0d ndarray inputs... + for ( i = 0; i < args.length; i++ ) { + if ( isndarrayLike( args[ i ] ) ) { + if ( ndims( args[ i ] ) === 0 ) { + args[ i ] = broadcastArray( args[ i ], [ 1 ] ); + } + } else if ( !dt && !ord ) { + args[ i ] = broadcastScalar( args[ i ], DEFAULT_DTYPE, [ 1 ], DEFAULT_ORDER ); // eslint-disable-line max-len + } else { + args[ i ] = broadcastScalar( args[ i ], dt, [ 1 ], ord ); + } + } + return concat.assign( normalizeArrays( args ), out ); +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/ndarray/concat1d/lib/index.js b/lib/node_modules/@stdlib/ndarray/concat1d/lib/index.js new file mode 100644 index 000000000000..cb6f0dbef5c7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/concat1d/lib/index.js @@ -0,0 +1,58 @@ +/** +* @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 concatenating the provided inputs. +* +* @module @stdlib/ndarray/concat1d +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var concat1d = require( '@stdlib/ndarray/concat1d' ); +* +* var x = array( [ -1.0, 2.0, 3.0, 4.0 ] ); +* var y = array( [ -5.0, 6.0, -7.0, -8.0, 9.0, -10.0 ] ); +* +* var out = concat1d( x, y ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ -1.0, 2.0, 3.0, 4.0, -5.0, 6.0, -7.0, -8.0, 9.0, -10.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/concat1d/lib/main.js b/lib/node_modules/@stdlib/ndarray/concat1d/lib/main.js new file mode 100644 index 000000000000..671dba96ec35 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/concat1d/lib/main.js @@ -0,0 +1,130 @@ +/** +* @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 broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); +var concat = require( '@stdlib/ndarray/concat' ); +var ndims = require( '@stdlib/ndarray/base/ndims' ); +var isArray = require( '@stdlib/assert/is-array' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var broadcastArray = require( '@stdlib/ndarray/broadcast-array' ); +var format = require( '@stdlib/string/format' ); +var defaults = require( '@stdlib/ndarray/defaults' ); +var normalizeArrays = require( './normalize_arrays.js' ); +var resolveDataTypes = require( './resolve_dtypes.js' ); +var resolveOrder = require( './resolve_order.js' ); + + +// VARIABLES // + +var DEFAULT_ORDER = defaults.get( 'order' ); +var DEFAULT_DTYPE = defaults.get( 'dtypes.default' ); + + +// MAIN // + +/** +* Returns a one-dimensional ndarray formed by concatenating the provided input arguments. +* +* @param {...*} args - input arguments +* @throws {Error} function must be provided an array of inputs or more than one separate input arguments +* @throws {RangeError} function must be provided a one-dimensional ndarray or a zero-dimensional ndarray +* @returns {ndarray} output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var x = array( [ -1.0, 2.0, 3.0, 4.0 ] ); +* var y = array( [ -5.0, 6.0, -7.0, -8.0, 9.0, -10.0 ] ); +* +* var out = concat1d( x, y ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ -1.0, 2.0, 3.0, 4.0, -5.0, 6.0, -7.0, -8.0, 9.0, -10.0 ] +*/ +function concat1d() { + var nargs; + var args; + var arrs; + var ord; + var dt; + var i; + var d; + + nargs = arguments.length; + + // Resolve function arguments... + if ( nargs < 1 ) { + throw new Error( format( 'invalid argument. The function must be provided an array of inputs or more than one separate input arguments. Value: `%s`.', nargs ) ); + } + if ( nargs > 1 ) { + args = []; + for ( i = 0; i < nargs; i++ ) { + args.push( arguments[ i ] ); + } + } + if ( nargs === 1 ) { + if ( isArray( arguments[ 0 ] ) ) { + args = arguments[ 0 ]; + } else { + args = []; + args.push( arguments[ 0 ] ); + } + } + + // Resolve the `dtype` and `order` of input ndarrays... + arrs = []; + for ( i = 0; i < args.length; i++ ) { + if ( isndarrayLike( args[ i ] ) ) { + d = ndims( args[ i ] ); + if ( d > 1 ) { + throw new RangeError( format( 'invalid argument. The function must be provided a one-dimensional ndarray or a zero-dimensional ndarray.. Value: `%s`.', d ) ); + } + arrs.push( args[ i ] ); + } + } + if ( arrs.length >= 1 ) { + dt = resolveDataTypes( arrs ); + ord = resolveOrder( arrs ); + } + + // Broadcast scalar or 0d ndarray inputs... + for ( i = 0; i < args.length; i++ ) { + if ( isndarrayLike( args[ i ] ) ) { + if ( ndims( args[ i ] ) === 0 ) { + args[ i ] = broadcastArray( args[ i ], [ 1 ] ); + } + } else if ( !dt && !ord ) { + args[ i ] = broadcastScalar( args[ i ], DEFAULT_DTYPE, [ 1 ], DEFAULT_ORDER ); // eslint-disable-line max-len + } else { + args[ i ] = broadcastScalar( args[ i ], dt, [ 1 ], ord ); + } + } + return concat( normalizeArrays( args ) ); +} + + +// EXPORTS // + +module.exports = concat1d; diff --git a/lib/node_modules/@stdlib/ndarray/concat1d/lib/normalize_arrays.js b/lib/node_modules/@stdlib/ndarray/concat1d/lib/normalize_arrays.js new file mode 100644 index 000000000000..766b71c48acd --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/concat1d/lib/normalize_arrays.js @@ -0,0 +1,55 @@ +/** +* @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 ndarraylike2ndarray = require( '@stdlib/ndarray/base/ndarraylike2ndarray' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Normalizes a list of ndarray-like objects. +* +* @private +* @param {Array} arrays - list of input ndarrays +* @throws {TypeError} first argument must be an array of ndarrays +* @returns {Array} list of ndarrays +*/ +function normalize( arrays ) { + var out; + var i; + + out = []; + for ( i = 0; i < arrays.length; i++ ) { + if ( !isndarrayLike( arrays[ i ] ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an array of ndarrays. Value: `%s`.', arrays[ i ] ) ); + } + out.push( ndarraylike2ndarray( arrays[ i ] ) ); + } + return out; +} + + +// EXPORTS // + +module.exports = normalize; diff --git a/lib/node_modules/@stdlib/ndarray/concat1d/lib/resolve_dtypes.js b/lib/node_modules/@stdlib/ndarray/concat1d/lib/resolve_dtypes.js new file mode 100644 index 000000000000..55babc5de084 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/concat1d/lib/resolve_dtypes.js @@ -0,0 +1,61 @@ +/** +* @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 getDType = require( '@stdlib/ndarray/base/dtype' ); +var promoteDataTypes = require( '@stdlib/ndarray/base/promote-dtypes' ); + + +// MAIN // + +/** +* Returns a list of ndarray data types from a list of ndarrays. +* +* @private +* @param {Array} arrays - list of input ndarrays +* @returns {Array} list of data types +*/ +function dataTypes( arrays ) { + var out; + var i; + + out = []; + for ( i = 0; i < arrays.length; i++ ) { + out.push( getDType( arrays[ i ] ) ); + } + return out; +} + +/** +* Returns a list of ndarray data types from a list of ndarrays. +* +* @private +* @param {Array} arrays - list of input ndarrays +* @returns {String} resolved data type +*/ +function resolveDataTypes( arrays ) { + return promoteDataTypes( dataTypes( arrays ) ); +} + + +// EXPORTS // + +module.exports = resolveDataTypes; diff --git a/lib/node_modules/@stdlib/ndarray/concat1d/lib/resolve_order.js b/lib/node_modules/@stdlib/ndarray/concat1d/lib/resolve_order.js new file mode 100644 index 000000000000..84682da2b10a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/concat1d/lib/resolve_order.js @@ -0,0 +1,60 @@ +/** +* @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 getOrder = require( '@stdlib/ndarray/base/order' ); +var defaults = require( '@stdlib/ndarray/defaults' ); + + +// VARIABLES // + +var DEFAULT_ORDER = defaults.get( 'order' ); + + +// MAIN // + +/** +* Resolves the order (i.e. memory layout) of an output ndarray according to a list of input ndarrays. +* +* @private +* @param {Array} arrays - list of inputs ndarrays +* @returns {string} order +*/ +function resolveOrder( arrays ) { + var o; + var i; + + // Resolve the order of the first ndarray: + o = getOrder( arrays[ 0 ] ); + + // If a subsequent input ndarray has a different order, return the default memory layout... + for ( i = 1; i < arrays.length; i++ ) { + if ( getOrder( arrays[ i ] ) !== o ) { + return DEFAULT_ORDER; + } + } + return o; +} + + +// EXPORTS // + +module.exports = resolveOrder; diff --git a/lib/node_modules/@stdlib/ndarray/concat1d/package.json b/lib/node_modules/@stdlib/ndarray/concat1d/package.json new file mode 100644 index 000000000000..9574da015e9e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/concat1d/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/ndarray/concat1d", + "version": "0.0.0", + "description": "Returns a one-dimensional ndarray formed by concatenating the provided input arguments.", + "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", + "push", + "append", + "add", + "concat1d", + "concatenating" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/concat1d/test/test.assign.js b/lib/node_modules/@stdlib/ndarray/concat1d/test/test.assign.js new file mode 100644 index 000000000000..33bb909ff05e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/concat1d/test/test.assign.js @@ -0,0 +1,373 @@ +/** +* @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 scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var assign = require( './../lib/assign.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof assign, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided unsupported number of arguments', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2 ] ); + + values = [ + x, + [], + [ x ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( value ); + }; + } +}); + +tape( 'the function throws an error if provided an output argument with unsupported number of dimensions', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2 ] ); + + values = [ + zeros( [ 2, 2 ] ), + zeros( [ 3, 1, 2 ] ), + zeros( [] ) + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided ndarrays with more than one dimension', function test( t ) { + var values; + var out; + var i; + + out = zeros( [ 10 ] ); + + values = [ + [ zeros( [ 2, 2 ] ), zeros( [ 3, 1, 2 ] ) ], + [ zeros( [ 2, 2, 2 ] ), zeros( [ 4, 1, 1, 1 ] ) ], + [ zeros( [ 2 ] ), zeros( [ 4, 1, 2 ] ) ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( value, out ); + }; + } +}); + +tape( 'the function concatenates provided input arguments and assigns the result to a provided one-dimensional output ndarray(ndarrays)', function test( t ) { + var expected; + var actual; + var xbuf; + var ybuf; + var out; + var x; + var y; + var z; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + + ybuf = new Float64Array( [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + y = new ndarray( 'float64', ybuf, [ 6 ], [ 1 ], 0, 'row-major' ); + + z = zeros( [ 10 ] ); + + out = assign( [ x, y ], z ); + + actual = ndarray2array( z ); + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ]; + + t.strictEqual( resolveStr( getDType( z ) ), 'float64', 'returns expected value' ); + t.strictEqual( getOrder( z ), 'row-major', 'returns expected value' ); + t.deepEqual( getShape( z ), [ 10 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( out, z, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function concatenates provided input arguments and assigns the result to a provided one-dimensional output ndarray(ndarrays, separate arguments)', function test( t ) { + var expected; + var actual; + var xbuf; + var ybuf; + var out; + var x; + var y; + var z; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + + ybuf = new Float64Array( [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + y = new ndarray( 'float64', ybuf, [ 6 ], [ 1 ], 0, 'row-major' ); + + z = zeros( [ 10 ] ); + + out = assign( x, y, z ); + + actual = ndarray2array( z ); + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ]; + + t.strictEqual( resolveStr( getDType( z ) ), 'float64', 'returns expected value' ); + t.strictEqual( getOrder( z ), 'row-major', 'returns expected value' ); + t.deepEqual( getShape( z ), [ 10 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( out, z, 'returns expected value'); + + t.end(); +}); + +tape( 'the function concatenates provided input arguments and assigns the result to a provided one-dimensional output ndarray(0-dimensional ndarrays)', function test( t ) { + var expected; + var actual; + var out; + var x; + var y; + var z; + + x = scalar2ndarray( 1.0 ); + y = scalar2ndarray( 2.0 ); + z = zeros( [ 2 ] ); + + out = assign( [ x, y ], z ); + + actual = ndarray2array( z ); + expected = [ 1.0, 2.0 ]; + + t.strictEqual( resolveStr( getDType( z ) ), 'float64', 'returns expected value' ); + t.strictEqual( getOrder( z ), 'row-major', 'returns expected value' ); + t.deepEqual( getShape( z ), [ 2 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( out, z, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function concatenates provided input arguments and assigns the result to a provided one-dimensional output ndarray(0-dimensional ndarrays, separate arguments)', function test( t ) { + var expected; + var actual; + var out; + var x; + var y; + var z; + + x = scalar2ndarray( 1.0 ); + y = scalar2ndarray( 2.0 ); + z = zeros( [ 2 ] ); + + out = assign( x, y, z ); + + actual = ndarray2array( z ); + expected = [ 1.0, 2.0 ]; + + t.strictEqual( resolveStr( getDType( z ) ), 'float64', 'returns expected value' ); + t.strictEqual( getOrder( z ), 'row-major', 'returns expected value' ); + t.deepEqual( getShape( z ), [ 2 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( out, z, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function concatenates provided input arguments and assigns the result to a provided one-dimensional output ndarray(scalars)', function test( t ) { + var expected; + var actual; + var out; + var z; + + z = zeros( [ 6 ] ); + out = assign( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], z ); + + actual = ndarray2array( z ); + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + + t.strictEqual( resolveStr( getDType( z ) ), 'float64', 'returns expected value' ); + t.strictEqual( getOrder( z ), 'row-major', 'returns expected value' ); + t.deepEqual( getShape( z ), [ 6 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( out, z, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function concatenates provided input arguments and assigns the result to a provided one-dimensional output ndarray(scalars, separate arguments)', function test( t ) { + var expected; + var actual; + var out; + var z; + + z = zeros( [ 6 ] ); + out = assign( 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, z ); + + actual = ndarray2array( z ); + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + + t.strictEqual( resolveStr( getDType( z ) ), 'float64', 'returns expected value' ); + t.strictEqual( getOrder( z ), 'row-major', 'returns expected value' ); + t.deepEqual( getShape( z ), [ 6 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( out, z, 'returns expected value'); + + t.end(); +}); + +tape( 'the function concatenates provided input arguments and assigns the result to a provided one-dimensional output ndarray(ndarrays, scalars)', function test( t ) { + var expected; + var actual; + var xbuf; + var ybuf; + var out; + var x; + var y; + var z; + var o; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + + ybuf = new Float64Array( [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + y = new ndarray( 'float64', ybuf, [ 6 ], [ 1 ], 0, 'row-major' ); + + z = scalar2ndarray( 15.0 ); + o = zeros( [ 14 ] ); + + out = assign( [ x, y, z, 11.0, 12.0, 13.0 ], o ); + + actual = ndarray2array( o ); + expected = [ + 1.0, + 2.0, + 3.0, + 4.0, + 5.0, + 6.0, + 7.0, + 8.0, + 9.0, + 10.0, + 15.0, + 11.0, + 12.0, + 13.0 + ]; + + t.strictEqual( resolveStr( getDType( o ) ), 'float64', 'returns expected value' ); + t.strictEqual( getOrder( o ), 'row-major', 'returns expected value' ); + t.deepEqual( getShape( o ), [ 14 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value'); + + t.end(); +}); + +tape( 'the function concatenates provided input arguments and assigns the result to a provided one-dimensional output ndarray(ndarrays, scalars, separate arguments)', function test( t ) { + var expected; + var actual; + var xbuf; + var ybuf; + var out; + var x; + var y; + var z; + var o; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + + ybuf = new Float64Array( [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + y = new ndarray( 'float64', ybuf, [ 6 ], [ 1 ], 0, 'row-major' ); + + z = scalar2ndarray( 15.0 ); + o = zeros( [ 14 ] ); + + out = assign( x, y, z, 11.0, 12.0, 13.0, o ); + + actual = ndarray2array( o ); + expected = [ + 1.0, + 2.0, + 3.0, + 4.0, + 5.0, + 6.0, + 7.0, + 8.0, + 9.0, + 10.0, + 15.0, + 11.0, + 12.0, + 13.0 + ]; + + t.strictEqual( resolveStr( getDType( o ) ), 'float64', 'returns expected value' ); + t.strictEqual( getOrder( o ), 'row-major', 'returns expected value' ); + t.deepEqual( getShape( o ), [ 14 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/concat1d/test/test.js b/lib/node_modules/@stdlib/ndarray/concat1d/test/test.js new file mode 100644 index 000000000000..e85cd1995432 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/concat1d/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 concat = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof concat, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( concat, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/concat1d/test/test.main.js b/lib/node_modules/@stdlib/ndarray/concat1d/test/test.main.js new file mode 100644 index 000000000000..98bb918d45c3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/concat1d/test/test.main.js @@ -0,0 +1,305 @@ +/** +* @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 scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var concat = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof concat, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided unsupported number of arguments', function test( t ) { + t.throws( badValue(), Error, 'throws an error when provided unsupported number of arguments' ); + t.end(); + + function badValue() { + return function badValue() { + concat(); + }; + } +}); + +tape( 'the function throws an error if provided ndarrays 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( [ 2 ] ), zeros( [ 3, 1, 2 ] ) ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + concat( value ); + }; + } +}); + +tape( 'the function returns a one-dimensional ndarray formed by concatenating the provided input arguments(ndarrays)', function test( t ) { + var expected; + var actual; + var xbuf; + var ybuf; + 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' ); + + ybuf = new Float64Array( [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + y = new ndarray( 'float64', ybuf, [ 6 ], [ 1 ], 0, 'row-major' ); + + out = concat( [ x, y ] ); + + actual = ndarray2array( out ); + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ]; + + t.strictEqual( resolveStr( getDType( out ) ), 'float64', 'returns expected value' ); + t.strictEqual( getOrder( out ), 'row-major', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 10 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a one-dimensional ndarray formed by concatenating the provided input arguments(ndarrays, separate arguments)', function test( t ) { + var expected; + var actual; + var xbuf; + var ybuf; + 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' ); + + ybuf = new Float64Array( [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + y = new ndarray( 'float64', ybuf, [ 6 ], [ 1 ], 0, 'row-major' ); + + out = concat( x, y ); + + actual = ndarray2array( out ); + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ]; + + t.strictEqual( resolveStr( getDType( out ) ), 'float64', 'returns expected value' ); + t.strictEqual( getOrder( out ), 'row-major', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 10 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a one-dimensional ndarray formed by concatenating the provided input arguments(0-dimensional ndarrays)', function test( t ) { + var expected; + var actual; + var out; + var x; + var y; + + x = scalar2ndarray( 1.0 ); + y = scalar2ndarray( 2.0 ); + + out = concat( [ x, y ] ); + + actual = ndarray2array( out ); + expected = [ 1.0, 2.0 ]; + + t.strictEqual( resolveStr( getDType( out ) ), 'float64', 'returns expected value' ); + t.strictEqual( getOrder( out ), 'row-major', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 2 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a one-dimensional ndarray formed by concatenating the provided input arguments(0-dimensional ndarrays, separate arguments)', function test( t ) { + var expected; + var actual; + var out; + var x; + var y; + + x = scalar2ndarray( 1.0 ); + y = scalar2ndarray( 2.0 ); + + out = concat( x, y ); + + actual = ndarray2array( out ); + expected = [ 1.0, 2.0 ]; + + t.strictEqual( resolveStr( getDType( out ) ), 'float64', 'returns expected value' ); + t.strictEqual( getOrder( out ), 'row-major', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 2 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a one-dimensional ndarray formed by concatenating the provided input arguments(scalars)', function test( t ) { + var expected; + var actual; + var out; + + out = concat( [ 1.0, 2.0, 3.0, 4.0, 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 concatenating the provided input arguments(scalars, separate arguments)', function test( t ) { + var expected; + var actual; + var out; + + out = concat( 1.0, 2.0, 3.0, 4.0, 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 concatenating the provided input arguments(ndarrays, scalars)', function test( t ) { + var expected; + var actual; + var xbuf; + var ybuf; + var out; + var x; + var y; + var z; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + + ybuf = new Float64Array( [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + y = new ndarray( 'float64', ybuf, [ 6 ], [ 1 ], 0, 'row-major' ); + + z = scalar2ndarray( 15.0 ); + + out = concat( [ x, y, z, 11.0, 12.0, 13.0 ] ); + + actual = ndarray2array( out ); + expected = [ + 1.0, + 2.0, + 3.0, + 4.0, + 5.0, + 6.0, + 7.0, + 8.0, + 9.0, + 10.0, + 15.0, + 11.0, + 12.0, + 13.0 + ]; + + t.strictEqual( resolveStr( getDType( out ) ), 'float64', 'returns expected value' ); + t.strictEqual( getOrder( out ), 'row-major', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 14 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a one-dimensional ndarray formed by concatenating the provided input arguments(ndarrays, scalars, separate arguments)', function test( t ) { + var expected; + var actual; + var xbuf; + var ybuf; + var out; + var x; + var y; + var z; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + + ybuf = new Float64Array( [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + y = new ndarray( 'float64', ybuf, [ 6 ], [ 1 ], 0, 'row-major' ); + + z = scalar2ndarray( 15.0 ); + + out = concat( x, y, z, 11.0, 12.0, 13.0 ); + + actual = ndarray2array( out ); + expected = [ + 1.0, + 2.0, + 3.0, + 4.0, + 5.0, + 6.0, + 7.0, + 8.0, + 9.0, + 10.0, + 15.0, + 11.0, + 12.0, + 13.0 + ]; + + t.strictEqual( resolveStr( getDType( out ) ), 'float64', 'returns expected value' ); + t.strictEqual( getOrder( out ), 'row-major', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 14 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +});