diff --git a/lib/node_modules/@stdlib/ndarray/hconcat/README.md b/lib/node_modules/@stdlib/ndarray/hconcat/README.md new file mode 100644 index 000000000000..ab9029e9d641 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/hconcat/README.md @@ -0,0 +1,162 @@ + + +# hconcat + +> Concatenate a list of [ndarrays][@stdlib/ndarray/ctor] along the last dimension. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var hconcat = require( '@stdlib/ndarray/hconcat' ); +``` + +#### hconcat( arrays ) + +Concatenates a list of [ndarrays][@stdlib/ndarray/ctor] along the last dimension. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); +// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] + +var y = array( [ [ 5.0, 6.0, 7.0 ], [ 8.0, 9.0, 10.0 ] ] ); +// returns [ [ 5.0, 6.0, 7.0 ], [ 8.0, 9.0, 10.0 ] ] + +var out = hconcat( [ x, y ] ); +// returns [ [ 1.0, 2.0, 5.0, 6.0, 7.0 ], [ 3.0, 4.0, 8.0, 9.0, 10.0 ] ] +``` + +The function accepts the following arguments: + +- **arrays**: a list of input [ndarrays][@stdlib/ndarray/ctor]. The data type of the output [ndarray][@stdlib/ndarray/ctor] is determined by applying [type promotion rules][@stdlib/ndarray/promotion-rules] to the list of input [ndarrays][@stdlib/ndarray/ctor]. If provided [ndarrays][@stdlib/ndarray/ctor] having different [memory layouts][@stdlib/ndarray/orders], the output [ndarray][@stdlib/ndarray/ctor] has the [default order][@stdlib/ndarray/defaults]. + +#### hconcat.assign( arrays, out ) + +Concatenates a list of [ndarrays][@stdlib/ndarray/ctor] along the last dimension and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor]. + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var zeros = require( '@stdlib/ndarray/zeros' ); + +var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); +// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] + +var y = array( [ [ 5.0, 6.0, 7.0 ], [ 8.0, 9.0, 10.0 ] ] ); +// returns [ [ 5.0, 6.0, 7.0 ], [ 8.0, 9.0, 10.0 ] ] + +var z = zeros( [ 2, 5 ] ); +// returns [ [ 0.0, 0.0, 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ] + +var out = hconcat.assign( [ x, y ], z ); +// returns [ [ 1.0, 2.0, 5.0, 6.0, 7.0 ], [ 3.0, 4.0, 8.0, 9.0, 10.0 ] ] + +var bool = ( out === z ); +// returns true +``` + +The function accepts the following arguments: + +- **arrays**: a list of input [ndarrays][@stdlib/ndarray/ctor]. Must [promote][@stdlib/ndarray/promotion-rules] to a [data type][@stdlib/ndarray/dtypes] which can be (mostly) [safely cast][@stdlib/ndarray/mostly-safe-casts] to the [data type][@stdlib/ndarray/dtypes] of the output [ndarray][@stdlib/ndarray/ctor]. +- **out**: output [ndarray][@stdlib/ndarray/ctor]. + +
+ + + + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var hconcat = require( '@stdlib/ndarray/hconcat' ); + +var x = discreteUniform( [ 2, 2 ], 0, 10, { + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +var y = discreteUniform( [ 2, 3 ], 0, 10, { + 'dtype': 'generic' +}); +console.log( ndarray2array( y ) ); + +var out = hconcat( [ x, y ] ); +console.log( ndarray2array( out ) ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/hconcat/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/ndarray/hconcat/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..ecf926e6118e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/hconcat/benchmark/benchmark.assign.js @@ -0,0 +1,167 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var hconcat = require( './../lib/assign.js' ); + + +// MAIN // + +bench( format( '%s::1d', pkg ), function benchmark( b ) { + var values; + var opts; + var out; + var v; + var i; + + opts = { + 'dtype': 'float64' + }; + + values = [ + discreteUniform( [ 32 ], -100, 100, opts ), + discreteUniform( [ 32 ], -100, 100, opts ), + discreteUniform( [ 32 ], -100, 100, opts ), + discreteUniform( [ 32 ], -100, 100, opts ) + ]; + out = zeros( [ 128 ], opts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = hconcat( 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( format( '%s::2d', pkg ), function benchmark( b ) { + var values; + var opts; + var out; + var v; + var i; + + opts = { + 'dtype': 'float64' + }; + + values = [ + discreteUniform( [ 32, 16 ], -100, 100, opts ), + discreteUniform( [ 32, 16 ], -100, 100, opts ), + discreteUniform( [ 32, 16 ], -100, 100, opts ), + discreteUniform( [ 32, 16 ], -100, 100, opts ) + ]; + out = zeros( [ 32, 64 ], opts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = hconcat( 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( format( '%s::2d,casting', pkg ), function benchmark( b ) { + var values; + var out; + var v; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + discreteUniform( [ 32, 16 ], -100, 100, { 'dtype': 'float64' } ), + discreteUniform( [ 32, 16 ], -100, 100, { 'dtype': 'float32' } ), + discreteUniform( [ 32, 16 ], -100, 100, { 'dtype': 'int32' } ), + discreteUniform( [ 32, 16 ], -100, 100, { 'dtype': 'generic' } ) + ]; + out = zeros( [ 32, 64 ], { 'dtype': 'generic' } ); + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = hconcat( 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( format( '%s::3d', pkg ), function benchmark( b ) { + var values; + var opts; + var out; + var v; + var i; + + opts = { + 'dtype': 'float64' + }; + + values = [ + discreteUniform( [ 4, 16, 16 ], -100, 100, opts ), + discreteUniform( [ 4, 16, 16 ], -100, 100, opts ), + discreteUniform( [ 4, 16, 16 ], -100, 100, opts ), + discreteUniform( [ 4, 16, 16 ], -100, 100, opts ) + ]; + out = zeros( [ 4, 16, 64 ], opts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = hconcat( 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/hconcat/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/hconcat/benchmark/benchmark.js new file mode 100644 index 000000000000..0b33d79ddebb --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/hconcat/benchmark/benchmark.js @@ -0,0 +1,158 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var hconcat = require( './../lib' ); + + +// MAIN // + +bench( format( '%s::1d', pkg ), function benchmark( b ) { + var values; + var opts; + var v; + var i; + + opts = { + 'dtype': 'float64' + }; + + values = [ + discreteUniform( [ 32 ], -100, 100, opts ), + discreteUniform( [ 32 ], -100, 100, opts ), + discreteUniform( [ 32 ], -100, 100, opts ), + discreteUniform( [ 32 ], -100, 100, opts ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = hconcat( 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( format( '%s::2d', pkg ), function benchmark( b ) { + var values; + var opts; + var v; + var i; + + opts = { + 'dtype': 'float64' + }; + + values = [ + discreteUniform( [ 32, 16 ], -100, 100, opts ), + discreteUniform( [ 32, 16 ], -100, 100, opts ), + discreteUniform( [ 32, 16 ], -100, 100, opts ), + discreteUniform( [ 32, 16 ], -100, 100, opts ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = hconcat( 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( format( '%s::2d,casting', pkg ), function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + discreteUniform( [ 32, 16 ], -100, 100, { 'dtype': 'float64' } ), + discreteUniform( [ 32, 16 ], -100, 100, { 'dtype': 'float32' } ), + discreteUniform( [ 32, 16 ], -100, 100, { 'dtype': 'int32' } ), + discreteUniform( [ 32, 16 ], -100, 100, { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = hconcat( 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( format( '%s::3d', pkg ), function benchmark( b ) { + var values; + var opts; + var v; + var i; + + opts = { + 'dtype': 'float64' + }; + + values = [ + discreteUniform( [ 4, 16, 16 ], -100, 100, opts ), + discreteUniform( [ 4, 16, 16 ], -100, 100, opts ), + discreteUniform( [ 4, 16, 16 ], -100, 100, opts ), + discreteUniform( [ 4, 16, 16 ], -100, 100, opts ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = hconcat( 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/hconcat/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/hconcat/docs/repl.txt new file mode 100644 index 000000000000..1a4ac3d51329 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/hconcat/docs/repl.txt @@ -0,0 +1,66 @@ + +{{alias}}( arrays ) + Concatenates a list of ndarrays along the last dimension. + + The data type of the output ndarray is determined by applying type + promotion rules to the list of input ndarrays. + + If provided ndarrays having different memory layouts, the output ndarray + has the default order. + + Parameters + ---------- + arrays: ArrayLikeObject + List of input ndarrays. Each input ndarray must have a shape which is + broadcast-compatible with the other input ndarrays along all dimensions + other than the last dimension. + + 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 ] ) + [ [ 1.0, 2.0, 5.0, 6.0 ], [ 3.0, 4.0, 7.0, 8.0 ] ] + + +{{alias}}.assign( arrays, out ) + Concatenates a list of ndarrays along the last dimension and assigns + results to a provided output ndarray. + + Input ndarrays must promote to a data type which can be (mostly) safely + cast to the data type of the output ndarray. + + Parameters + ---------- + arrays: ArrayLikeObject + List of input ndarrays. Each input ndarray must have a shape which is + broadcast-compatible with the other input ndarrays along all dimensions + other than the last dimension. + + out: ndarray + Output ndarray. Must have a data type to which the input ndarrays can + be (mostly) safely cast. + + 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 z = {{alias:@stdlib/ndarray/zeros}}( [ 2, 4 ] ); + > var out = {{alias}}.assign( [ x, y ], z ) + [ [ 1.0, 2.0, 5.0, 6.0 ], [ 3.0, 4.0, 7.0, 8.0 ] ] + > var bool = ( out === z ) + true + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/hconcat/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/hconcat/docs/types/index.d.ts new file mode 100644 index 000000000000..cf6cb46d948d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/hconcat/docs/types/index.d.ts @@ -0,0 +1,121 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { ArrayLike } from '@stdlib/types/array'; +import { typedndarray } from '@stdlib/types/ndarray'; + +/** +* Interface describing `hconcat`. +*/ +interface Hconcat { + /** + * Concatenates a list of ndarrays along the last dimension. + * + * @param arrays - array-like object containing input ndarrays + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); + * // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] + * + * var y = array( [ [ 5.0, 6.0, 7.0 ], [ 8.0, 9.0, 10.0 ] ] ); + * // returns [ [ 5.0, 6.0, 7.0 ], [ 8.0, 9.0, 10.0 ] ] + * + * var out = hconcat( [ x, y ] ); + * // returns [ [ 1.0, 2.0, 5.0, 6.0, 7.0 ], [ 3.0, 4.0, 8.0, 9.0, 10.0 ] ] + */ + ( arrays: ArrayLike> ): typedndarray; + + /** + * Concatenates a list of ndarrays along the last dimension and assigns results to a provided output ndarray. + * + * @param arrays - array-like object containing input ndarrays + * @param out - output ndarray + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * var zeros = require( '@stdlib/ndarray/zeros' ); + * + * var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); + * // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] + * + * var y = array( [ [ 5.0, 6.0, 7.0 ], [ 8.0, 9.0, 10.0 ] ] ); + * // returns [ [ 5.0, 6.0, 7.0 ], [ 8.0, 9.0, 10.0 ] ] + * + * var z = zeros( [ 2, 5 ] ); + * // returns [ [ 0.0, 0.0, 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ] + * + * var out = hconcat.assign( [ x, y ], z ); + * // returns [ [ 1.0, 2.0, 5.0, 6.0, 7.0 ], [ 3.0, 4.0, 8.0, 9.0, 10.0 ] ] + * + * var bool = ( out === z ); + * // returns true + */ + assign = typedndarray>( arrays: ArrayLike>, out: V ): V; +} + +/** +* Concatenates a list of ndarrays along the last dimension. +* +* @param arrays - array-like object containing input ndarrays +* @returns output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] +* +* var y = array( [ [ 5.0, 6.0, 7.0 ], [ 8.0, 9.0, 10.0 ] ] ); +* // returns [ [ 5.0, 6.0, 7.0 ], [ 8.0, 9.0, 10.0 ] ] +* +* var out = hconcat( [ x, y ] ); +* // returns [ [ 1.0, 2.0, 5.0, 6.0, 7.0 ], [ 3.0, 4.0, 8.0, 9.0, 10.0 ] ] +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* +* var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] +* +* var y = array( [ [ 5.0, 6.0, 7.0 ], [ 8.0, 9.0, 10.0 ] ] ); +* // returns [ [ 5.0, 6.0, 7.0 ], [ 8.0, 9.0, 10.0 ] ] +* +* var z = zeros( [ 2, 5 ] ); +* // returns [ [ 0.0, 0.0, 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ] +* +* var out = hconcat.assign( [ x, y ], z ); +* // returns [ [ 1.0, 2.0, 5.0, 6.0, 7.0 ], [ 3.0, 4.0, 8.0, 9.0, 10.0 ] ] +* +* var bool = ( out === z ); +* // returns true +*/ +declare var hconcat: Hconcat; + + +// EXPORTS // + +export = hconcat; diff --git a/lib/node_modules/@stdlib/ndarray/hconcat/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/hconcat/docs/types/test.ts new file mode 100644 index 000000000000..6d0a0c65689e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/hconcat/docs/types/test.ts @@ -0,0 +1,106 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/// + +import zeros = require( '@stdlib/ndarray/zeros' ); +import hconcat = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ] ); + const y = zeros( [ 2, 3 ] ); + + hconcat( [ x, y ] ); // $ExpectType typedndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array-like object containing ndarrays... +{ + hconcat( '5' ); // $ExpectError + hconcat( 5 ); // $ExpectError + hconcat( true ); // $ExpectError + hconcat( false ); // $ExpectError + hconcat( null ); // $ExpectError + hconcat( undefined ); // $ExpectError + hconcat( [ 1 ] ); // $ExpectError + hconcat( {} ); // $ExpectError + hconcat( ( 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 ] ); + const y = zeros( [ 2, 3 ] ); + + hconcat(); // $ExpectError + hconcat( x ); // $ExpectError + hconcat( [ x, y ], {} ); // $ExpectError +} + +// Attached to the function is an `assign` method which returns an ndarray... +{ + const x = zeros( [ 2, 2 ] ); + const y = zeros( [ 2, 3 ] ); + const z = zeros( [ 2, 5 ] ); + + hconcat.assign( [ x, y ], z ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object containing ndarrays... +{ + const z = zeros( [ 2, 5 ] ); + + hconcat.assign( '5', z ); // $ExpectError + hconcat.assign( 5, z ); // $ExpectError + hconcat.assign( true, z ); // $ExpectError + hconcat.assign( false, z ); // $ExpectError + hconcat.assign( null, z ); // $ExpectError + hconcat.assign( undefined, z ); // $ExpectError + hconcat.assign( [ 1 ], z ); // $ExpectError + hconcat.assign( {}, z ); // $ExpectError + hconcat.assign( ( x: number ): number => x, z ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not an ndarray... +{ + const x = zeros( [ 2, 2 ] ); + const y = zeros( [ 2, 3 ] ); + + hconcat.assign( [ x, y ], '5' ); // $ExpectError + hconcat.assign( [ x, y ], 5 ); // $ExpectError + hconcat.assign( [ x, y ], true ); // $ExpectError + hconcat.assign( [ x, y ], false ); // $ExpectError + hconcat.assign( [ x, y ], null ); // $ExpectError + hconcat.assign( [ x, y ], [ 1 ] ); // $ExpectError + hconcat.assign( [ x, y ], {} ); // $ExpectError + hconcat.assign( [ x, y ], ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ] ); + const y = zeros( [ 2, 3 ] ); + const z = zeros( [ 2, 5 ] ); + + hconcat.assign(); // $ExpectError + hconcat.assign( [ x, y ] ); // $ExpectError + hconcat.assign( [ x, y ], z, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/hconcat/examples/index.js b/lib/node_modules/@stdlib/ndarray/hconcat/examples/index.js new file mode 100644 index 000000000000..565f762ac8a5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/hconcat/examples/index.js @@ -0,0 +1,36 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var hconcat = require( './../lib' ); + +var x = discreteUniform( [ 2, 2 ], 0, 10, { + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +var y = discreteUniform( [ 2, 3 ], 0, 10, { + 'dtype': 'generic' +}); +console.log( ndarray2array( y ) ); + +var out = hconcat( [ x, y ] ); +console.log( ndarray2array( out ) ); diff --git a/lib/node_modules/@stdlib/ndarray/hconcat/lib/assign.js b/lib/node_modules/@stdlib/ndarray/hconcat/lib/assign.js new file mode 100644 index 000000000000..5416744c4900 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/hconcat/lib/assign.js @@ -0,0 +1,70 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var concat = require( '@stdlib/ndarray/concat' ).assign; + + +// MAIN // + +/** +* Concatenates a list of ndarrays along the last dimension and assigns results to a provided output ndarray. +* +* @param {ArrayLikeObject} arrays - array-like object containing input ndarrays +* @param {ndarrayLike} out - output ndarray +* @throws {TypeError} first argument must be an array-like object containing one or more ndarrays +* @throws {TypeError} second argument must be an ndarray-like object +* @throws {TypeError} second argument must have a valid shape +* @throws {Error} must provide ndarrays which are broadcast-compatible with one another +* @throws {Error} must provide ndarrays which can be safely cast to a common data type +* @throws {Error} input ndarrays must be safely castable to the output ndarray data type +* @returns {ndarrayLike} output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* +* var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] +* +* var y = array( [ [ 5.0, 6.0, 7.0 ], [ 8.0, 9.0, 10.0 ] ] ); +* // returns [ [ 5.0, 6.0, 7.0 ], [ 8.0, 9.0, 10.0 ] ] +* +* var z = zeros( [ 2, 5 ] ); +* // returns [ [ 0.0, 0.0, 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ] +* +* var out = assign( [ x, y ], z ); +* // returns [ [ 1.0, 2.0, 5.0, 6.0, 7.0 ], [ 3.0, 4.0, 8.0, 9.0, 10.0 ] ] +* +* var bool = ( out === z ); +* // returns true +*/ +function assign( arrays, out ) { + concat( arrays, out, { + 'dim': -1 + }); + return out; +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/ndarray/hconcat/lib/index.js b/lib/node_modules/@stdlib/ndarray/hconcat/lib/index.js new file mode 100644 index 000000000000..2064d9578c8d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/hconcat/lib/index.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Concatenate a list of ndarrays along the last dimension. +* +* @module @stdlib/ndarray/hconcat +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var hconcat = require( '@stdlib/ndarray/hconcat' ); +* +* var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] +* +* var y = array( [ [ 5.0, 6.0, 7.0 ], [ 8.0, 9.0, 10.0 ] ] ); +* // returns [ [ 5.0, 6.0, 7.0 ], [ 8.0, 9.0, 10.0 ] ] +* +* var out = hconcat( [ x, y ] ); +* // returns [ [ 1.0, 2.0, 5.0, 6.0, 7.0 ], [ 3.0, 4.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/hconcat/lib/main.js b/lib/node_modules/@stdlib/ndarray/hconcat/lib/main.js new file mode 100644 index 000000000000..678c94a50f77 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/hconcat/lib/main.js @@ -0,0 +1,58 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var concat = require( '@stdlib/ndarray/concat' ); + + +// MAIN // + +/** +* Concatenates a list of ndarrays along the last dimension. +* +* @param {ArrayLikeObject} arrays - array-like object containing input ndarrays +* @throws {TypeError} first argument must be an array-like object containing one or more ndarrays +* @throws {Error} must provide ndarrays which are broadcast-compatible with one another +* @throws {Error} must provide ndarrays which can be safely cast to a common data type +* @returns {ndarray} output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] +* +* var y = array( [ [ 5.0, 6.0, 7.0 ], [ 8.0, 9.0, 10.0 ] ] ); +* // returns [ [ 5.0, 6.0, 7.0 ], [ 8.0, 9.0, 10.0 ] ] +* +* var out = hconcat( [ x, y ] ); +* // returns [ [ 1.0, 2.0, 5.0, 6.0, 7.0 ], [ 3.0, 4.0, 8.0, 9.0, 10.0 ] ] +*/ +function hconcat( arrays ) { + return concat( arrays, { + 'dim': -1 + }); +} + + +// EXPORTS // + +module.exports = hconcat; diff --git a/lib/node_modules/@stdlib/ndarray/hconcat/package.json b/lib/node_modules/@stdlib/ndarray/hconcat/package.json new file mode 100644 index 000000000000..7d1cf18a9c0b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/hconcat/package.json @@ -0,0 +1,74 @@ +{ + "name": "@stdlib/ndarray/hconcat", + "version": "0.0.0", + "description": "Concatenate a list of ndarrays along the last dimension.", + "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", + "matrix", + "vector", + "ndarray", + "multidimensional", + "array", + "concatenate", + "column", + "col", + "columns", + "join", + "concat", + "hconcat", + "hcat", + "column_stack", + "hstack", + "stack" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/hconcat/test/test.assign.js b/lib/node_modules/@stdlib/ndarray/hconcat/test/test.assign.js new file mode 100644 index 000000000000..56f6c03f4af1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/hconcat/test/test.assign.js @@ -0,0 +1,433 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Int32Array = require( '@stdlib/array/int32' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var empty = require( '@stdlib/ndarray/empty' ); +var assign = require( './../lib/assign.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof assign, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { + var values; + var out; + var i; + + out = zeros( [ 2, 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() { + assign( value, out ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is an empty array-like object', function test( t ) { + var out = zeros( [ 2, 4 ] ); + t.throws( bad, TypeError, 'throws an error' ); + t.end(); + + function bad() { + assign( [], out ); + } +}); + +tape( 'the function throws an error if provided a first argument containing values which are not ndarrays', function test( t ) { + var values; + var out; + var i; + + out = zeros( [ 2, 4 ] ); + + values = [ + [ 'beep', 'boop' ], + [ 1, 2, 3 ], + [ null ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( value, out ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ] ); + y = zeros( [ 2, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( [ x, y ], value ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument containing ndarrays which are not broadcast-compatible', function test( t ) { + var values; + var out; + var i; + + out = zeros( [ 3, 4 ] ); + + values = [ + [ + empty( [ 2, 2 ], { + 'dtype': 'float64' + }), + empty( [ 3, 2 ], { + 'dtype': 'float64' + }) + ] + ]; + + 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, out ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument containing ndarrays which do not promote to a common data type', function test( t ) { + var values; + var out; + var i; + + out = zeros( [ 2, 4 ], { + 'dtype': 'float64' + }); + + values = [ + [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }), + empty( [ 2, 2 ], { + 'dtype': 'float64' + }) + ] + ]; + + 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, out ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument having a data type to which input ndarrays cannot be safely cast', function test( t ) { + var values; + var out; + var i; + + out = empty( [ 2, 4 ], { + 'dtype': 'bool' + }); + + values = [ + [ + empty( [ 2, 2 ], { + 'dtype': 'float32' + }), + empty( [ 2, 2 ], { + 'dtype': 'float64' + }) + ] + ]; + + 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, out ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument having an invalid shape', function test( t ) { + var values; + var out; + var i; + + out = zeros( [ 5, 5 ], { + 'dtype': 'float64' + }); + + values = [ + [ + empty( [ 2, 2 ], { + 'dtype': 'float64' + }), + empty( [ 2, 2 ], { + 'dtype': 'float64' + }) + ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( value, out ); + }; + } +}); + +tape( 'the function concatenates one-dimensional ndarrays along the last dimension', 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 ] ); + x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + + ybuf = new Float64Array( [ 4.0, 5.0 ] ); + y = new ndarray( 'float64', ybuf, [ 2 ], [ 1 ], 0, 'row-major' ); + + z = zeros( [ 5 ], { + 'dtype': 'float64' + }); + + out = assign( [ x, y ], z ); + + actual = ndarray2array( z ); + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + + t.strictEqual( out, z, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function concatenates two-dimensional ndarrays along the last dimension', 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, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + ybuf = new Float64Array( [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + y = new ndarray( 'float64', ybuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + z = zeros( [ 2, 5 ], { + 'dtype': 'float64' + }); + + out = assign( [ x, y ], z ); + + actual = ndarray2array( z ); + expected = [ + [ 1.0, 2.0, 5.0, 6.0, 7.0 ], + [ 3.0, 4.0, 8.0, 9.0, 10.0 ] + ]; + + t.strictEqual( out, z, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function concatenates ndarrays along the last dimension (type promotion)', 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, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + ybuf = new Int32Array( [ 5, 6, 7, 8 ] ); + y = new ndarray( 'int32', ybuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + z = zeros( [ 2, 4 ], { + 'dtype': 'float64' + }); + + out = assign( [ x, y ], z ); + + actual = ndarray2array( z ); + expected = [ + [ 1.0, 2.0, 5.0, 6.0 ], + [ 3.0, 4.0, 7.0, 8.0 ] + ]; + + t.strictEqual( out, z, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function concatenates a single ndarray along the last dimension', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + var z; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float64', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + z = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + out = assign( [ x ], z ); + + actual = ndarray2array( z ); + expected = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ] + ]; + + t.strictEqual( out, z, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function concatenates three-dimensional ndarrays along the last dimension', 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, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( 'float64', xbuf, [ 2, 2, 2 ], [ 4, 2, 1 ], 0, 'row-major' ); + + ybuf = new Float64Array( [ 9.0, 10.0, 11.0, 12.0 ] ); + y = new ndarray( 'float64', ybuf, [ 2, 2, 1 ], [ 2, 1, 1 ], 0, 'row-major' ); + + z = zeros( [ 2, 2, 3 ], { + 'dtype': 'float64' + }); + + out = assign( [ x, y ], z ); + + actual = ndarray2array( z ); + expected = [ + [ + [ 1.0, 2.0, 9.0 ], + [ 3.0, 4.0, 10.0 ] + ], + [ + [ 5.0, 6.0, 11.0 ], + [ 7.0, 8.0, 12.0 ] + ] + ]; + + t.strictEqual( out, z, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/hconcat/test/test.js b/lib/node_modules/@stdlib/ndarray/hconcat/test/test.js new file mode 100644 index 000000000000..f54eeff98db5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/hconcat/test/test.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isMethod = require( '@stdlib/assert/is-method' ); +var hconcat = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof hconcat, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( hconcat, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/hconcat/test/test.main.js b/lib/node_modules/@stdlib/ndarray/hconcat/test/test.main.js new file mode 100644 index 000000000000..06f982fa079b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/hconcat/test/test.main.js @@ -0,0 +1,301 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Int32Array = require( '@stdlib/array/int32' ); +var empty = require( '@stdlib/ndarray/empty' ); +var hconcat = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof hconcat, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + hconcat( value ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is an empty array-like object', function test( t ) { + t.throws( bad, TypeError, 'throws an error' ); + t.end(); + + function bad() { + hconcat( [] ); + } +}); + +tape( 'the function throws an error if provided a first argument which is not an array-like object containing ndarrays', function test( t ) { + var values; + var i; + + values = [ + [ 'beep', 'boop' ], + [ 1, 2, 3 ], + [ null ] + ]; + + 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() { + hconcat( value ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument containing ndarrays which are not broadcast-compatible', function test( t ) { + var values; + var i; + + values = [ + [ + empty( [ 2, 2 ], { + 'dtype': 'float64' + }), + empty( [ 3, 2 ], { + 'dtype': 'float64' + }) + ] + ]; + + 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() { + hconcat( value ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument containing ndarrays which do not promote to a common data type', function test( t ) { + var values; + var i; + + values = [ + [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }), + empty( [ 2, 2 ], { + 'dtype': 'float64' + }) + ] + ]; + + 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() { + hconcat( value ); + }; + } +}); + +tape( 'the function concatenates one-dimensional ndarrays along the last dimension', 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 ] ); + x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + + ybuf = new Float64Array( [ 4.0, 5.0 ] ); + y = new ndarray( 'float64', ybuf, [ 2 ], [ 1 ], 0, 'row-major' ); + + out = hconcat( [ x, y ] ); + + actual = ndarray2array( out ); + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 5 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function concatenates two-dimensional ndarrays along the last dimension', 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, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + ybuf = new Float64Array( [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + y = new ndarray( 'float64', ybuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + out = hconcat( [ x, y ] ); + + actual = ndarray2array( out ); + expected = [ + [ 1.0, 2.0, 5.0, 6.0, 7.0 ], + [ 3.0, 4.0, 8.0, 9.0, 10.0 ] + ]; + + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 2, 5 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function concatenates a single ndarray along the last dimension', 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, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = hconcat( [ x ] ); + + actual = ndarray2array( out ); + expected = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ] + ]; + + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 2, 2 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function concatenates ndarrays along the last dimension (type promotion)', 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, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + ybuf = new Int32Array( [ 5, 6, 7, 8 ] ); + y = new ndarray( 'int32', ybuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = hconcat( [ x, y ] ); + + actual = ndarray2array( out ); + expected = [ + [ 1.0, 2.0, 5.0, 6.0 ], + [ 3.0, 4.0, 7.0, 8.0 ] + ]; + + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 2, 4 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function concatenates three-dimensional ndarrays along the last dimension', 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, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( 'float64', xbuf, [ 2, 2, 2 ], [ 4, 2, 1 ], 0, 'row-major' ); + + ybuf = new Float64Array( [ 9.0, 10.0, 11.0, 12.0 ] ); + y = new ndarray( 'float64', ybuf, [ 2, 2, 1 ], [ 2, 1, 1 ], 0, 'row-major' ); + + out = hconcat( [ x, y ] ); + + actual = ndarray2array( out ); + expected = [ + [ + [ 1.0, 2.0, 9.0 ], + [ 3.0, 4.0, 10.0 ] + ], + [ + [ 5.0, 6.0, 11.0 ], + [ 7.0, 8.0, 12.0 ] + ] + ]; + + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 2, 2, 3 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +});