diff --git a/lib/node_modules/@stdlib/ndarray/vconcat/README.md b/lib/node_modules/@stdlib/ndarray/vconcat/README.md new file mode 100644 index 000000000000..4c59685a5afa --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/vconcat/README.md @@ -0,0 +1,172 @@ + + +# vconcat + +> Concatenate a list of [ndarrays][@stdlib/ndarray/ctor] along the second-to-last dimension. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var vconcat = require( '@stdlib/ndarray/vconcat' ); +``` + +#### vconcat( arrays ) + +Concatenates a list of [ndarrays][@stdlib/ndarray/ctor] along the second-to-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 = vconcat( [ x, y ] ); +// 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**: 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]. + +#### vconcat.assign( arrays, out ) + +Concatenates a list of [ndarrays][@stdlib/ndarray/ctor] along the second-to-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( [ 5, 2 ] ); +// returns [ [ 0.0, 0.0 ], [ 0.0, 0.0 ], [ 0.0, 0.0 ], [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] + +var out = vconcat.assign( [ x, y ], z ); +// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ], [ 7.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]. + +
+ + + + + +
+ +- Input [ndarrays][@stdlib/ndarray/ctor] must have more than one dimension. + +
+ + + + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var vconcat = require( '@stdlib/ndarray/vconcat' ); + +var x = discreteUniform( [ 2, 3 ], 0, 10, { + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +var y = discreteUniform( [ 3, 3 ], 0, 10, { + 'dtype': 'generic' +}); +console.log( ndarray2array( y ) ); + +var out = vconcat( [ x, y ] ); +console.log( ndarray2array( out ) ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/vconcat/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/ndarray/vconcat/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..fb3a1e7df93b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/vconcat/benchmark/benchmark.assign.js @@ -0,0 +1,133 @@ +/** +* @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 vconcat = require( './../lib/assign.js' ); + + +// MAIN // + +bench( format( '%s::2d', pkg ), function benchmark( b ) { + var values; + var opts; + var out; + var v; + var i; + + opts = { + 'dtype': 'float64' + }; + + values = [ + discreteUniform( [ 16, 32 ], -100, 100, opts ), + discreteUniform( [ 16, 32 ], -100, 100, opts ), + discreteUniform( [ 16, 32 ], -100, 100, opts ), + discreteUniform( [ 16, 32 ], -100, 100, opts ) + ]; + out = zeros( [ 64, 32 ], opts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = vconcat( 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( [ 16, 32 ], -100, 100, { 'dtype': 'float64' } ), + discreteUniform( [ 16, 32 ], -100, 100, { 'dtype': 'float32' } ), + discreteUniform( [ 16, 32 ], -100, 100, { 'dtype': 'int32' } ), + discreteUniform( [ 16, 32 ], -100, 100, { 'dtype': 'generic' } ) + ]; + out = zeros( [ 64, 32 ], { 'dtype': 'generic' } ); + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = vconcat( 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, 64, 16 ], opts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = vconcat( 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/vconcat/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/vconcat/benchmark/benchmark.js new file mode 100644 index 000000000000..fdb3fa3967e3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/vconcat/benchmark/benchmark.js @@ -0,0 +1,126 @@ +/** +* @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 vconcat = require( './../lib' ); + + +// MAIN // + +bench( format( '%s::2d', pkg ), function benchmark( b ) { + var values; + var opts; + var v; + var i; + + opts = { + 'dtype': 'float64' + }; + + values = [ + discreteUniform( [ 16, 32 ], -100, 100, opts ), + discreteUniform( [ 16, 32 ], -100, 100, opts ), + discreteUniform( [ 16, 32 ], -100, 100, opts ), + discreteUniform( [ 16, 32 ], -100, 100, opts ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = vconcat( 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( [ 16, 32 ], -100, 100, { 'dtype': 'float64' } ), + discreteUniform( [ 16, 32 ], -100, 100, { 'dtype': 'float32' } ), + discreteUniform( [ 16, 32 ], -100, 100, { 'dtype': 'int32' } ), + discreteUniform( [ 16, 32 ], -100, 100, { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = vconcat( 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 = vconcat( 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/vconcat/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/vconcat/docs/repl.txt new file mode 100644 index 000000000000..b23d9006cec7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/vconcat/docs/repl.txt @@ -0,0 +1,72 @@ + +{{alias}}( arrays ) + Concatenates a list of ndarrays along the second-to-last dimension. + + Input ndarrays must have more than one 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 at least two + dimensions, and each input ndarray must have a shape which is + broadcast-compatible with the other input ndarrays along all dimensions + other than the second-to-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 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ], [ 7.0, 8.0 ] ] + + +{{alias}}.assign( arrays, out ) + Concatenates a list of ndarrays along the second-to-last dimension and + assigns results to a provided output ndarray. + + Input ndarrays must have more than one dimension. + + 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 at least two + dimensions, and each input ndarray must have a shape which is + broadcast-compatible with the other input ndarrays along all dimensions + other than the second-to-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}}( [ 4, 2 ] ); + > var out = {{alias}}.assign( [ x, y ], z ) + [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ], [ 7.0, 8.0 ] ] + > var bool = ( out === z ) + true + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/vconcat/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/vconcat/docs/types/index.d.ts new file mode 100644 index 000000000000..816961cf04d3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/vconcat/docs/types/index.d.ts @@ -0,0 +1,133 @@ +/* +* @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 `vconcat`. +*/ +interface Vconcat { + /** + * Concatenates a list of ndarrays along the second-to-last dimension. + * + * ## Notes + * + * - Input ndarrays must have more than one 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 = vconcat( [ x, y ] ); + * // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ], [ 7.0, 8.0 ], [ 9.0, 10.0 ] ] + */ + ( arrays: ArrayLike> ): typedndarray; + + /** + * Concatenates a list of ndarrays along the second-to-last dimension and assigns results to a provided output ndarray. + * + * ## Notes + * + * - Input ndarrays must have more than one dimension. + * + * @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( [ 5, 2 ] ); + * // returns [ [ 0.0, 0.0 ], [ 0.0, 0.0 ], [ 0.0, 0.0 ], [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] + * + * var out = vconcat.assign( [ x, y ], z ); + * // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ], [ 7.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 second-to-last dimension. +* +* ## Notes +* +* - Input ndarrays must have more than one 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 = vconcat( [ x, y ] ); +* // 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 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( [ 5, 2 ] ); +* // returns [ [ 0.0, 0.0 ], [ 0.0, 0.0 ], [ 0.0, 0.0 ], [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] +* +* var out = vconcat.assign( [ x, y ], z ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ], [ 7.0, 8.0 ], [ 9.0, 10.0 ] ] +* +* var bool = ( out === z ); +* // returns true +*/ +declare var vconcat: Vconcat; + + +// EXPORTS // + +export = vconcat; diff --git a/lib/node_modules/@stdlib/ndarray/vconcat/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/vconcat/docs/types/test.ts new file mode 100644 index 000000000000..bcd87021e577 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/vconcat/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 vconcat = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ] ); + const y = zeros( [ 3, 2 ] ); + + vconcat( [ 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... +{ + vconcat( '5' ); // $ExpectError + vconcat( 5 ); // $ExpectError + vconcat( true ); // $ExpectError + vconcat( false ); // $ExpectError + vconcat( null ); // $ExpectError + vconcat( undefined ); // $ExpectError + vconcat( [ 1 ] ); // $ExpectError + vconcat( {} ); // $ExpectError + vconcat( ( 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( [ 3, 2 ] ); + + vconcat(); // $ExpectError + vconcat( x ); // $ExpectError + vconcat( [ x, y ], {} ); // $ExpectError +} + +// Attached to the function is an `assign` method which returns an ndarray... +{ + const x = zeros( [ 2, 2 ] ); + const y = zeros( [ 3, 2 ] ); + const z = zeros( [ 5, 2 ] ); + + vconcat.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( [ 5, 2 ] ); + + vconcat.assign( '5', z ); // $ExpectError + vconcat.assign( 5, z ); // $ExpectError + vconcat.assign( true, z ); // $ExpectError + vconcat.assign( false, z ); // $ExpectError + vconcat.assign( null, z ); // $ExpectError + vconcat.assign( undefined, z ); // $ExpectError + vconcat.assign( [ 1 ], z ); // $ExpectError + vconcat.assign( {}, z ); // $ExpectError + vconcat.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( [ 3, 2 ] ); + + vconcat.assign( [ x, y ], '5' ); // $ExpectError + vconcat.assign( [ x, y ], 5 ); // $ExpectError + vconcat.assign( [ x, y ], true ); // $ExpectError + vconcat.assign( [ x, y ], false ); // $ExpectError + vconcat.assign( [ x, y ], null ); // $ExpectError + vconcat.assign( [ x, y ], [ 1 ] ); // $ExpectError + vconcat.assign( [ x, y ], {} ); // $ExpectError + vconcat.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( [ 3, 2 ] ); + const z = zeros( [ 5, 2 ] ); + + vconcat.assign(); // $ExpectError + vconcat.assign( [ x, y ] ); // $ExpectError + vconcat.assign( [ x, y ], z, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/vconcat/examples/index.js b/lib/node_modules/@stdlib/ndarray/vconcat/examples/index.js new file mode 100644 index 000000000000..449ea010eb6a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/vconcat/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 vconcat = require( './../lib' ); + +var x = discreteUniform( [ 2, 3 ], 0, 10, { + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +var y = discreteUniform( [ 3, 3 ], 0, 10, { + 'dtype': 'generic' +}); +console.log( ndarray2array( y ) ); + +var out = vconcat( [ x, y ] ); +console.log( ndarray2array( out ) ); diff --git a/lib/node_modules/@stdlib/ndarray/vconcat/lib/assign.js b/lib/node_modules/@stdlib/ndarray/vconcat/lib/assign.js new file mode 100644 index 000000000000..a78e98365924 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/vconcat/lib/assign.js @@ -0,0 +1,75 @@ +/** +* @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 second-to-last dimension and assigns results to a provided output ndarray. +* +* ## Notes +* +* - Input ndarrays must have more than one dimension. +* +* @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 {RangeError} must provide ndarrays having two or more dimensions +* @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( [ 5, 2 ] ); +* // 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 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ], [ 7.0, 8.0 ], [ 9.0, 10.0 ] ] +* +* var bool = ( out === z ); +* // returns true +*/ +function assign( arrays, out ) { + concat( arrays, out, { + 'dim': -2 + }); + return out; +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/ndarray/vconcat/lib/index.js b/lib/node_modules/@stdlib/ndarray/vconcat/lib/index.js new file mode 100644 index 000000000000..3e2fc5f2874d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/vconcat/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 second-to-last dimension. +* +* @module @stdlib/ndarray/vconcat +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var vconcat = require( '@stdlib/ndarray/vconcat' ); +* +* 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 = vconcat( [ x, y ] ); +* // 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/vconcat/lib/main.js b/lib/node_modules/@stdlib/ndarray/vconcat/lib/main.js new file mode 100644 index 000000000000..18d976aa9588 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/vconcat/lib/main.js @@ -0,0 +1,63 @@ +/** +* @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 second-to-last dimension. +* +* ## Notes +* +* - Input ndarrays must have more than one 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 {RangeError} must provide ndarrays having two or more dimensions +* @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 = vconcat( [ x, y ] ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ], [ 7.0, 8.0 ], [ 9.0, 10.0 ] ] +*/ +function vconcat( arrays ) { + return concat( arrays, { + 'dim': -2 + }); +} + + +// EXPORTS // + +module.exports = vconcat; diff --git a/lib/node_modules/@stdlib/ndarray/vconcat/package.json b/lib/node_modules/@stdlib/ndarray/vconcat/package.json new file mode 100644 index 000000000000..18c396565b7c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/vconcat/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/ndarray/vconcat", + "version": "0.0.0", + "description": "Concatenate a list of ndarrays along the second-to-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", + "row", + "rows", + "join", + "concat", + "vconcat", + "vcat", + "row_stack", + "vstack", + "stack" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/vconcat/test/test.assign.js b/lib/node_modules/@stdlib/ndarray/vconcat/test/test.assign.js new file mode 100644 index 000000000000..25b57adf4387 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/vconcat/test/test.assign.js @@ -0,0 +1,447 @@ +/** +* @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( [ 4, 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( 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( [ 4, 2 ] ); + 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( [ 4, 2 ] ); + + 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 having fewer than two dimensions', function test( t ) { + var values; + var out; + var i; + + out = zeros( [ 6 ] ); + + values = [ + [ + empty( [ 3 ], { + 'dtype': 'float64' + }), + empty( [ 3 ], { + 'dtype': 'float64' + }) + ], + [ + empty( [ 2, 2 ], { + 'dtype': 'float64' + }), + empty( [ 2 ], { + 'dtype': 'float64' + }) + ] + ]; + + 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 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( [ 4, 3 ] ); + + values = [ + [ + empty( [ 2, 2 ], { + 'dtype': 'float64' + }), + empty( [ 2, 3 ], { + '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( [ 4, 2 ], { + '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( [ 4, 2 ], { + '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 two-dimensional ndarrays along the second-to-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, [ 3, 2 ], [ 2, 1 ], 0, 'row-major' ); + + z = zeros( [ 5, 2 ], { + 'dtype': 'float64' + }); + + 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( out, z, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function concatenates ndarrays along the second-to-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( [ 4, 2 ], { + 'dtype': 'float64' + }); + + 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 ] + ]; + + 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 second-to-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 second-to-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, 1, 2 ], [ 2, 2, 1 ], 0, 'row-major' ); + + z = zeros( [ 2, 3, 2 ], { + 'dtype': 'float64' + }); + + out = assign( [ x, y ], z ); + + actual = ndarray2array( z ); + expected = [ + [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 9.0, 10.0 ] + ], + [ + [ 5.0, 6.0 ], + [ 7.0, 8.0 ], + [ 11.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/vconcat/test/test.js b/lib/node_modules/@stdlib/ndarray/vconcat/test/test.js new file mode 100644 index 000000000000..995b26845cca --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/vconcat/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 vconcat = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof vconcat, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( vconcat, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/vconcat/test/test.main.js b/lib/node_modules/@stdlib/ndarray/vconcat/test/test.main.js new file mode 100644 index 000000000000..c48d1ec594f8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/vconcat/test/test.main.js @@ -0,0 +1,316 @@ +/** +* @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 vconcat = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof vconcat, '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() { + vconcat( 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() { + vconcat( [] ); + } +}); + +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() { + vconcat( value ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument containing ndarrays having fewer than two dimensions', function test( t ) { + var values; + var i; + + values = [ + [ + empty( [ 3 ], { + 'dtype': 'float64' + }), + empty( [ 3 ], { + 'dtype': 'float64' + }) + ], + [ + empty( [ 2, 2 ], { + 'dtype': 'float64' + }), + empty( [ 2 ], { + 'dtype': 'float64' + }) + ] + ]; + + 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() { + vconcat( 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( [ 2, 3 ], { + '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() { + vconcat( 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() { + vconcat( value ); + }; + } +}); + +tape( 'the function concatenates two-dimensional ndarrays along the second-to-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, [ 3, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = vconcat( [ 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( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 5, 2 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function concatenates a single ndarray along the second-to-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 = vconcat( [ 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 second-to-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 = vconcat( [ x, y ] ); + + actual = ndarray2array( out ); + expected = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 5.0, 6.0 ], + [ 7.0, 8.0 ] + ]; + + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 4, 2 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function concatenates three-dimensional ndarrays along the second-to-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, 1, 2 ], [ 2, 2, 1 ], 0, 'row-major' ); + + out = vconcat( [ x, y ] ); + + actual = ndarray2array( out ); + expected = [ + [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 9.0, 10.0 ] + ], + [ + [ 5.0, 6.0 ], + [ 7.0, 8.0 ], + [ 11.0, 12.0 ] + ] + ]; + + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 2, 3, 2 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +});