diff --git a/lib/node_modules/@stdlib/ndarray/rowcat/README.md b/lib/node_modules/@stdlib/ndarray/rowcat/README.md new file mode 100644 index 000000000000..95a3d8e61552 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rowcat/README.md @@ -0,0 +1,171 @@ + + +# rowcat + +> Concatenate a list of one-dimensional or two-dimensional [ndarrays][@stdlib/ndarray/ctor] as rows. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var rowcat = require( '@stdlib/ndarray/rowcat' ); +``` + +#### rowcat( arrays ) + +Concatenates a list of one-dimensional or two-dimensional [ndarrays][@stdlib/ndarray/ctor] as rows. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ 1.0, 2.0, 3.0 ] ); +// returns [ 1.0, 2.0, 3.0 ] + +var y = array( [ [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); +// returns [ [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] + +var out = rowcat( [ x, y ] ); +// returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.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]. + +#### rowcat.assign( arrays, out ) + +Concatenates a list of one-dimensional or two-dimensional [ndarrays][@stdlib/ndarray/ctor] as rows 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 ] ); +// returns [ 1.0, 2.0, 3.0 ] + +var y = array( [ [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); +// returns [ [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] + +var z = zeros( [ 3, 3 ] ); +// returns [ [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ] ] + +var out = rowcat.assign( [ x, y ], z ); +// returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.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]. Must be a two-dimensional [ndarray][@stdlib/ndarray/ctor]. + +
+ + + + + +
+ +- One-dimensional input [ndarrays][@stdlib/ndarray/ctor] having length `N` are promoted to two-dimensional [ndarrays][@stdlib/ndarray/ctor] having shape `[1, N]`. +- Input [ndarrays][@stdlib/ndarray/ctor] must have the same number of columns. + +
+ + + + + +
+ +## Examples + +```javascript +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var rowcat = require( '@stdlib/ndarray/rowcat' ); + +var x = discreteUniform( [ 3 ], 0, 10, { + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +var y = discreteUniform( [ 2, 3 ], 0, 10, { + 'dtype': 'generic' +}); +console.log( ndarray2array( y ) ); + +var out = rowcat( [ x, y ] ); +console.log( ndarray2array( out ) ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/rowcat/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/ndarray/rowcat/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..ca2ebe168324 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rowcat/benchmark/benchmark.assign.js @@ -0,0 +1,200 @@ +/** +* @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 rowcat = 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( [ 4, 32 ], opts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = rowcat( 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::1d,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 ], -100, 100, { 'dtype': 'float64' } ), + discreteUniform( [ 32 ], -100, 100, { 'dtype': 'float32' } ), + discreteUniform( [ 32 ], -100, 100, { 'dtype': 'int32' } ), + discreteUniform( [ 32 ], -100, 100, { 'dtype': 'generic' } ) + ]; + out = zeros( [ 4, 32 ], { 'dtype': 'generic' } ); + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = rowcat( 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( [ 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 = rowcat( 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 = rowcat( 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::mixed_1d_2d', pkg ), function benchmark( b ) { + var values; + var opts; + var out; + var v; + var i; + + opts = { + 'dtype': 'float64' + }; + + values = [ + discreteUniform( [ 32 ], -100, 100, opts ), + discreteUniform( [ 16, 32 ], -100, 100, opts ), + discreteUniform( [ 32 ], -100, 100, opts ), + discreteUniform( [ 16, 32 ], -100, 100, opts ) + ]; + out = zeros( [ 34, 32 ], opts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = rowcat( 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/rowcat/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/rowcat/benchmark/benchmark.js new file mode 100644 index 000000000000..63aeb1ac4a8d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rowcat/benchmark/benchmark.js @@ -0,0 +1,189 @@ +/** +* @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 rowcat = 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 = rowcat( 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::1d,casting', pkg ), function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + discreteUniform( [ 32 ], -100, 100, { 'dtype': 'float64' } ), + discreteUniform( [ 32 ], -100, 100, { 'dtype': 'float32' } ), + discreteUniform( [ 32 ], -100, 100, { 'dtype': 'int32' } ), + discreteUniform( [ 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 = rowcat( 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( [ 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 = rowcat( 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 = rowcat( 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::mixed_1d_2d', pkg ), function benchmark( b ) { + var values; + var opts; + var v; + var i; + + opts = { + 'dtype': 'float64' + }; + + values = [ + discreteUniform( [ 32 ], -100, 100, opts ), + discreteUniform( [ 16, 32 ], -100, 100, opts ), + discreteUniform( [ 32 ], -100, 100, opts ), + discreteUniform( [ 16, 32 ], -100, 100, opts ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = rowcat( 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/rowcat/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/rowcat/docs/repl.txt new file mode 100644 index 000000000000..e8f1f85d3a7f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rowcat/docs/repl.txt @@ -0,0 +1,76 @@ + +{{alias}}( arrays ) + Concatenates a list of one-dimensional or two-dimensional ndarrays as rows. + + One-dimensional input ndarrays having length `N` are promoted to two- + dimensional ndarrays having shape `[1, N]`. + + Each input ndarray must have the same number of columns. + + 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 be either one- + dimensional or two-dimensional and must have the same number of + columns. + + Returns + ------- + out: ndarray + Output ndarray. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, 2.0, 3.0 ] ); + > var y = {{alias:@stdlib/ndarray/array}}( [ [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); + > var out = {{alias}}( [ x, y ] ) + [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] + + +{{alias}}.assign( arrays, out ) + Concatenates a list of one-dimensional or two-dimensional ndarrays as rows + and assigns results to a provided output ndarray. + + One-dimensional input ndarrays having length `N` are promoted to two- + dimensional ndarrays having shape `[1, N]`. + + Each input ndarray must have the same number of columns. + + 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 be either one- + dimensional or two-dimensional and must have the same number of + columns. + + out: ndarray + Output ndarray. Must be a two-dimensional ndarray and 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 ] ); + > var y = {{alias:@stdlib/ndarray/array}}( [ [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); + > var z = {{alias:@stdlib/ndarray/zeros}}( [ 3, 3 ] ); + > var out = {{alias}}.assign( [ x, y ], z ) + [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] + > var bool = ( out === z ) + true + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/rowcat/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/rowcat/docs/types/index.d.ts new file mode 100644 index 000000000000..aaeb4f93d0ea --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rowcat/docs/types/index.d.ts @@ -0,0 +1,136 @@ +/* +* @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 `rowcat`. +*/ +interface Rowcat { + /** + * Concatenates a list of one-dimensional or two-dimensional ndarrays as rows. + * + * ## Notes + * + * - One-dimensional input ndarrays having length `N` are promoted to two-dimensional ndarrays having shape `[1, N]`. + * - Input ndarrays must have the same number of columns. + * + * @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 ] ); + * // returns [ 1.0, 2.0, 3.0 ] + * + * var y = array( [ [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); + * // returns [ [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] + * + * var out = rowcat( [ x, y ] ); + * // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] + */ + ( arrays: ArrayLike> ): typedndarray; + + /** + * Concatenates a list of one-dimensional or two-dimensional ndarrays as rows and assigns results to a provided output ndarray. + * + * ## Notes + * + * - One-dimensional input ndarrays having length `N` are promoted to two-dimensional ndarrays having shape `[1, N]`. + * - Input ndarrays must have the same number of columns. + * + * @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 ] ); + * // returns [ 1.0, 2.0, 3.0 ] + * + * var y = array( [ [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); + * // returns [ [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] + * + * var z = zeros( [ 3, 3 ] ); + * // returns [ [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ] ] + * + * var out = rowcat.assign( [ x, y ], z ); + * // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] + * + * var bool = ( out === z ); + * // returns true + */ + assign = typedndarray>( arrays: ArrayLike>, out: V ): V; +} + +/** +* Concatenates a list of one-dimensional or two-dimensional ndarrays as rows. +* +* ## Notes +* +* - One-dimensional input ndarrays having length `N` are promoted to two-dimensional ndarrays having shape `[1, N]`. +* - Input ndarrays must have the same number of columns. +* +* @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 ] ); +* // returns [ 1.0, 2.0, 3.0 ] +* +* var y = array( [ [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); +* // returns [ [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] +* +* var out = rowcat( [ x, y ] ); +* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* +* var x = array( [ 1.0, 2.0, 3.0 ] ); +* // returns [ 1.0, 2.0, 3.0 ] +* +* var y = array( [ [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); +* // returns [ [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] +* +* var z = zeros( [ 3, 3 ] ); +* // returns [ [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ] ] +* +* var out = rowcat.assign( [ x, y ], z ); +* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] +* +* var bool = ( out === z ); +* // returns true +*/ +declare var rowcat: Rowcat; + + +// EXPORTS // + +export = rowcat; diff --git a/lib/node_modules/@stdlib/ndarray/rowcat/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/rowcat/docs/types/test.ts new file mode 100644 index 000000000000..dfec5f421cd5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rowcat/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 rowcat = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ] ); + const y = zeros( [ 3, 2 ] ); + + rowcat( [ 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... +{ + rowcat( '5' ); // $ExpectError + rowcat( 5 ); // $ExpectError + rowcat( true ); // $ExpectError + rowcat( false ); // $ExpectError + rowcat( null ); // $ExpectError + rowcat( undefined ); // $ExpectError + rowcat( [ 1 ] ); // $ExpectError + rowcat( {} ); // $ExpectError + rowcat( ( 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 ] ); + + rowcat(); // $ExpectError + rowcat( x ); // $ExpectError + rowcat( [ 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 ] ); + + rowcat.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 ] ); + + rowcat.assign( '5', z ); // $ExpectError + rowcat.assign( 5, z ); // $ExpectError + rowcat.assign( true, z ); // $ExpectError + rowcat.assign( false, z ); // $ExpectError + rowcat.assign( null, z ); // $ExpectError + rowcat.assign( undefined, z ); // $ExpectError + rowcat.assign( [ 1 ], z ); // $ExpectError + rowcat.assign( {}, z ); // $ExpectError + rowcat.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 ] ); + + rowcat.assign( [ x, y ], '5' ); // $ExpectError + rowcat.assign( [ x, y ], 5 ); // $ExpectError + rowcat.assign( [ x, y ], true ); // $ExpectError + rowcat.assign( [ x, y ], false ); // $ExpectError + rowcat.assign( [ x, y ], null ); // $ExpectError + rowcat.assign( [ x, y ], [ 1 ] ); // $ExpectError + rowcat.assign( [ x, y ], {} ); // $ExpectError + rowcat.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 ] ); + + rowcat.assign(); // $ExpectError + rowcat.assign( [ x, y ] ); // $ExpectError + rowcat.assign( [ x, y ], z, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/rowcat/examples/index.js b/lib/node_modules/@stdlib/ndarray/rowcat/examples/index.js new file mode 100644 index 000000000000..d2826800defa --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rowcat/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 rowcat = require( './../lib' ); + +var x = discreteUniform( [ 3 ], 0, 10, { + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +var y = discreteUniform( [ 2, 3 ], 0, 10, { + 'dtype': 'generic' +}); +console.log( ndarray2array( y ) ); + +var out = rowcat( [ x, y ] ); +console.log( ndarray2array( out ) ); diff --git a/lib/node_modules/@stdlib/ndarray/rowcat/lib/assign.js b/lib/node_modules/@stdlib/ndarray/rowcat/lib/assign.js new file mode 100644 index 000000000000..c85ab98715ba --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rowcat/lib/assign.js @@ -0,0 +1,124 @@ +/** +* @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 isArrayLikeObject = require( '@stdlib/assert/is-array-like-object' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var ndarraylike2ndarray = require( '@stdlib/ndarray/base/ndarraylike2ndarray' ); +var prependSingletonDimensions = require( '@stdlib/ndarray/base/prepend-singleton-dimensions' ); +var ndims = require( '@stdlib/ndarray/base/ndims' ); +var getShape = require( '@stdlib/ndarray/base/shape' ); +var concat = require( '@stdlib/ndarray/concat' ).assign; +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Concatenates a list of one-dimensional or two-dimensional ndarrays as rows and assigns results to a provided output ndarray. +* +* ## Notes +* +* - One-dimensional input ndarrays having length `N` are promoted to two-dimensional ndarrays having shape `[1, N]`. +* - Input ndarrays must have the same number of columns. +* +* @param {ArrayLikeObject} arrays - array-like object containing input ndarrays +* @param {ndarrayLike} out - output ndarray +* @throws {TypeError} first argument must be an array-like object +* @throws {RangeError} first argument must contain one or more ndarrays +* @throws {TypeError} first argument must contain ndarray-like objects +* @throws {TypeError} second argument must be an ndarray-like object +* @throws {RangeError} second argument must be a two-dimensional ndarray +* @throws {RangeError} must provide one- or two-dimensional ndarrays +* @throws {Error} must provide ndarrays having the same number of columns +* @throws {Error} must provide ndarrays which can be safely cast to a common 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 ] ); +* // returns [ 1.0, 2.0, 3.0 ] +* +* var y = array( [ [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); +* // returns [ [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] +* +* var z = zeros( [ 3, 3 ] ); +* // returns [ [ 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 ] ] +* +* var bool = ( out === z ); +* // returns true +*/ +function assign( arrays, out ) { + var ncols; + var arrs; + var arr; + var sh; + var n; + var i; + + if ( !isArrayLikeObject( arrays ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', arrays ) ); + } + if ( arrays.length < 1 ) { + throw new RangeError( format( 'invalid argument. First argument must contain one or more ndarrays. Value: `%s`.', arrays ) ); + } + if ( !isndarrayLike( out ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an ndarray. Value: `%s`.', out ) ); + } + if ( ndims( out ) !== 2 ) { + throw new RangeError( format( 'invalid argument. Second argument must be a two-dimensional ndarray. Number of dimensions: `%u`.', ndims( out ) ) ); + } + arrs = []; + for ( i = 0; i < arrays.length; i++ ) { + arr = arrays[ i ]; + if ( !isndarrayLike( arr ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing one or more ndarrays. Value: `%s`.', arr ) ); + } + n = ndims( arr ); + if ( n !== 1 && n !== 2 ) { + throw new RangeError( format( 'invalid argument. Must provide one- or two-dimensional ndarrays. Number of dimensions: `%u`.', n ) ); + } + if ( n === 1 ) { + arr = prependSingletonDimensions( ndarraylike2ndarray( arr ), 1, false ); + } + sh = getShape( arr, false ); + if ( i === 0 ) { + ncols = sh[ 1 ]; + } else if ( sh[ 1 ] !== ncols ) { + throw new Error( format( 'invalid argument. All ndarrays must have the same number of columns. Expected number of columns: `%u`. Actual number of columns: `%u`.', ncols, sh[ 1 ] ) ); + } + arrs.push( arr ); + } + concat( arrs, out, { + 'dim': -2 + }); + return out; +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/ndarray/rowcat/lib/index.js b/lib/node_modules/@stdlib/ndarray/rowcat/lib/index.js new file mode 100644 index 000000000000..42f50865c7e6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rowcat/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 one-dimensional or two-dimensional ndarrays as rows. +* +* @module @stdlib/ndarray/rowcat +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var rowcat = require( '@stdlib/ndarray/rowcat' ); +* +* var x = array( [ 1.0, 2.0, 3.0 ] ); +* // returns [ 1.0, 2.0, 3.0 ] +* +* var y = array( [ [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); +* // returns [ [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] +* +* var out = rowcat( [ x, y ] ); +* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.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/rowcat/lib/main.js b/lib/node_modules/@stdlib/ndarray/rowcat/lib/main.js new file mode 100644 index 000000000000..857e51549cfc --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rowcat/lib/main.js @@ -0,0 +1,107 @@ +/** +* @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 isArrayLikeObject = require( '@stdlib/assert/is-array-like-object' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var ndarraylike2ndarray = require( '@stdlib/ndarray/base/ndarraylike2ndarray' ); +var prependSingletonDimensions = require( '@stdlib/ndarray/base/prepend-singleton-dimensions' ); +var ndims = require( '@stdlib/ndarray/base/ndims' ); +var getShape = require( '@stdlib/ndarray/base/shape' ); +var concat = require( '@stdlib/ndarray/concat' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Concatenates a list of one-dimensional or two-dimensional ndarrays as rows. +* +* ## Notes +* +* - One-dimensional input ndarrays having length `N` are promoted to two-dimensional ndarrays having shape `[1, N]`. +* - Input ndarrays must have the same number of columns. +* +* @param {ArrayLikeObject} arrays - array-like object containing input ndarrays +* @throws {TypeError} first argument must be an array-like object +* @throws {RangeError} first argument must contain one or more ndarrays +* @throws {TypeError} first argument must contain ndarray-like objects +* @throws {RangeError} must provide one- or two-dimensional ndarrays +* @throws {Error} must provide ndarrays having the same number of columns +* @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 ] ); +* // returns [ 1.0, 2.0, 3.0 ] +* +* var y = array( [ [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); +* // returns [ [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] +* +* var out = rowcat( [ x, y ] ); +* // returns [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] +*/ +function rowcat( arrays ) { + var ncols; + var arrs; + var arr; + var sh; + var n; + var i; + + if ( !isArrayLikeObject( arrays ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', arrays ) ); + } + if ( arrays.length < 1 ) { + throw new RangeError( format( 'invalid argument. First argument must contain one or more ndarrays. Value: `%s`.', arrays ) ); + } + arrs = []; + for ( i = 0; i < arrays.length; i++ ) { + arr = arrays[ i ]; + if ( !isndarrayLike( arr ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing one or more ndarrays. Value: `%s`.', arr ) ); + } + n = ndims( arr ); + if ( n !== 1 && n !== 2 ) { + throw new RangeError( format( 'invalid argument. Must provide one- or two-dimensional ndarrays. Number of dimensions: `%u`.', n ) ); + } + if ( n === 1 ) { + arr = prependSingletonDimensions( ndarraylike2ndarray( arr ), 1, false ); + } + sh = getShape( arr, false ); + if ( i === 0 ) { + ncols = sh[ 1 ]; + } else if ( sh[ 1 ] !== ncols ) { + throw new Error( format( 'invalid argument. All ndarrays must have the same number of columns. Expected number of columns: `%u`. Actual number of columns: `%u`.', ncols, sh[ 1 ] ) ); + } + arrs.push( arr ); + } + return concat( arrs, { + 'dim': -2 + }); +} + + +// EXPORTS // + +module.exports = rowcat; diff --git a/lib/node_modules/@stdlib/ndarray/rowcat/package.json b/lib/node_modules/@stdlib/ndarray/rowcat/package.json new file mode 100644 index 000000000000..489b6d192b49 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rowcat/package.json @@ -0,0 +1,72 @@ +{ + "name": "@stdlib/ndarray/rowcat", + "version": "0.0.0", + "description": "Concatenate a list of one-dimensional or two-dimensional ndarrays as rows.", + "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", + "rowcat", + "row_stack", + "vstack", + "stack" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/rowcat/test/test.assign.js b/lib/node_modules/@stdlib/ndarray/rowcat/test/test.assign.js new file mode 100644 index 000000000000..5c6a9ca09539 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rowcat/test/test.assign.js @@ -0,0 +1,558 @@ +/** +* @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 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, RangeError, '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 second argument which is not a two-dimensional ndarray', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ] ); + y = zeros( [ 2, 2 ] ); + + values = [ + zeros( [], { + 'dtype': 'float64' + }), + zeros( [ 4 ], { + 'dtype': 'float64' + }), + zeros( [ 2, 2, 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( [ x, y ], value ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument containing an ndarray which is neither one-dimensional nor two-dimensional', function test( t ) { + var values; + var out; + var i; + + out = zeros( [ 4, 2 ] ); + + values = [ + [ + empty( [], { + 'dtype': 'float64' + }) + ], + [ + empty( [ 2, 2, 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 do not have the same number of columns', function test( t ) { + var values; + var out; + var i; + + out = zeros( [ 4, 2 ] ); + + 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( [ 1, 4 ], { + 'dtype': 'float64' + }); + + values = [ + [ + empty( [ 2 ], { + 'dtype': 'bool' + }), + empty( [ 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 which has a data type to which input ndarrays cannot be safely cast', function test( t ) { + var values; + var out; + var i; + + out = empty( [ 2, 2 ], { + 'dtype': 'bool' + }); + + values = [ + [ + empty( [ 2 ], { + 'dtype': 'float32' + }), + empty( [ 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 ], { + 'dtype': 'float64' + }), + empty( [ 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 as rows', 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 one-dimensional ndarrays as rows', 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, 6.0 ] ); + y = new ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); + + z = zeros( [ 2, 3 ], { + 'dtype': 'float64' + }); + + out = assign( [ x, y ], z ); + + actual = ndarray2array( z ); + expected = [ + [ 1.0, 2.0, 3.0 ], + [ 4.0, 5.0, 6.0 ] + ]; + + t.strictEqual( out, z, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function concatenates a mix of one-dimensional and two-dimensional ndarrays as rows', function test( t ) { + var expected; + var actual; + var xbuf; + var ybuf; + var zbuf; + var out; + var x; + var y; + var z; + var w; + + 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, 6.0, 7.0, 8.0, 9.0 ] ); + y = new ndarray( 'float64', ybuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + zbuf = new Float64Array( [ 10.0, 11.0, 12.0 ] ); + z = new ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + + w = zeros( [ 4, 3 ], { + 'dtype': 'float64' + }); + + out = assign( [ x, y, z ], w ); + + actual = ndarray2array( w ); + expected = [ + [ 1.0, 2.0, 3.0 ], + [ 4.0, 5.0, 6.0 ], + [ 7.0, 8.0, 9.0 ], + [ 10.0, 11.0, 12.0 ] + ]; + + t.strictEqual( out, w, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function concatenates ndarrays as rows (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 Float64Array( [ 5.0, 6.0, 7.0, 8.0 ] ); + y = new ndarray( 'float64', ybuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + z = zeros( [ 4, 2 ], { + 'dtype': 'float32' + }); + + 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 mix of one-dimensional and two-dimensional ndarrays as rows (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 ] ); + x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + + ybuf = new Float64Array( [ 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + y = new ndarray( 'float64', ybuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + z = zeros( [ 3, 3 ], { + 'dtype': 'float32' + }); + + 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 ] + ]; + + t.strictEqual( out, z, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function concatenates a single ndarray as rows', 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' ); + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + + z = zeros( [ 1, 3 ], { + 'dtype': 'float64' + }); + + out = assign( [ x ], z ); + + actual = ndarray2array( z ); + expected = [ + [ 1.0, 2.0, 3.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/rowcat/test/test.js b/lib/node_modules/@stdlib/ndarray/rowcat/test/test.js new file mode 100644 index 000000000000..162b30e27fb4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rowcat/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 rowcat = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof rowcat, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( rowcat, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/rowcat/test/test.main.js b/lib/node_modules/@stdlib/ndarray/rowcat/test/test.main.js new file mode 100644 index 000000000000..abec66d09b68 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rowcat/test/test.main.js @@ -0,0 +1,400 @@ +/** +* @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 rowcat = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof rowcat, '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() { + rowcat( 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, RangeError, 'throws an error' ); + t.end(); + + function bad() { + rowcat( [] ); + } +}); + +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() { + rowcat( value ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument containing an ndarray which is neither one-dimensional nor two-dimensional', function test( t ) { + var values; + var i; + + values = [ + [ + empty( [], { + 'dtype': 'float64' + }) + ], + [ + empty( [ 2, 2, 2 ], { + 'dtype': 'float64' + }) + ], + [ + empty( [ 2 ], { + 'dtype': 'float64' + }), + empty( [ 2, 2, 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() { + rowcat( value ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument containing ndarrays which do not have the same number of columns', function test( t ) { + var values; + var i; + + values = [ + [ + empty( [ 2, 2 ], { + 'dtype': 'float64' + }), + empty( [ 2, 3 ], { + 'dtype': 'float64' + }) + ], + [ + empty( [ 3 ], { + 'dtype': 'float64' + }), + 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() { + rowcat( 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 ], { + 'dtype': 'bool' + }), + empty( [ 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() { + rowcat( value ); + }; + } +}); + +tape( 'the function concatenates two-dimensional ndarrays as rows', 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 = rowcat( [ 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 one-dimensional ndarrays as rows', 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, 6.0 ] ); + y = new ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); + + out = rowcat( [ x, y ] ); + + actual = ndarray2array( out ); + expected = [ + [ 1.0, 2.0, 3.0 ], + [ 4.0, 5.0, 6.0 ] + ]; + + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 2, 3 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function concatenates a mix of one-dimensional and two-dimensional ndarrays as rows', function test( t ) { + var expected; + var actual; + var xbuf; + var ybuf; + var zbuf; + 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, 6.0, 7.0, 8.0, 9.0 ] ); + y = new ndarray( 'float64', ybuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + zbuf = new Float64Array( [ 10.0, 11.0, 12.0 ] ); + z = new ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + + out = rowcat( [ x, y, z ] ); + + actual = ndarray2array( out ); + expected = [ + [ 1.0, 2.0, 3.0 ], + [ 4.0, 5.0, 6.0 ], + [ 7.0, 8.0, 9.0 ], + [ 10.0, 11.0, 12.0 ] + ]; + + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 4, 3 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function concatenates a single ndarray as rows', 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 = rowcat( [ 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' ); + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + + out = rowcat( [ x ] ); + + actual = ndarray2array( out ); + expected = [ + [ 1.0, 2.0, 3.0 ] + ]; + + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 1, 3 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function concatenates ndarrays as rows (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 = rowcat( [ 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 a mix of one-dimensional and two-dimensional ndarrays as rows (type promotion)', function test( t ) { + var expected; + var actual; + var xbuf; + var ybuf; + var out; + var x; + var y; + + xbuf = new Int32Array( [ 1, 2, 3 ] ); + x = new ndarray( 'int32', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + + ybuf = new Float64Array( [ 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + y = new ndarray( 'float64', ybuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + out = rowcat( [ x, y ] ); + + actual = ndarray2array( out ); + expected = [ + [ 1.0, 2.0, 3.0 ], + [ 4.0, 5.0, 6.0 ], + [ 7.0, 8.0, 9.0 ] + ]; + + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 3, 3 ], 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +});