diff --git a/lib/node_modules/@stdlib/ndarray/concat/README.md b/lib/node_modules/@stdlib/ndarray/concat/README.md index 7d3d00d921a8..6071fec137e9 100644 --- a/lib/node_modules/@stdlib/ndarray/concat/README.md +++ b/lib/node_modules/@stdlib/ndarray/concat/README.md @@ -40,58 +40,62 @@ limitations under the License. var concat = require( '@stdlib/ndarray/concat' ); ``` -#### concat( arrays\[, dim] ) +#### concat( arrays\[, options] ) Concatenates a list of [ndarrays][@stdlib/ndarray/ctor] along a specified [ndarray][@stdlib/ndarray/ctor] dimension. ```javascript var array = require( '@stdlib/ndarray/array' ); -var ndarray2array = require( '@stdlib/ndarray/to-array' ); var x = array( [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ] ); var y = array( [ [ -5.0, 6.0, -7.0 ], [ 8.0, -9.0, 10.0 ] ] ); -var out = concat( [ x, y ], -1 ); -// returns - -var arr = ndarray2array( out ); -// returns [ [ -1.0, 2.0, -5.0, 6.0, -7.0 ], [ -3.0, 4.0, 8.0, -9.0, 10.0 ] ] +var out = concat( [ x, y ], { + 'dim': -1 +}); +// returns [ [ -1.0, 2.0, -5.0, 6.0, -7.0 ], [ -3.0, 4.0, 8.0, -9.0, 10.0 ] ] ``` The function accepts the following arguments: - **arrays**: a list of input [ndarrays][@stdlib/ndarray/ctor]. Must be [broadcast compatible][@stdlib/ndarray/base/broadcast-shapes] except for the dimension along which to concatenate. 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]. -- **dim**: dimension along which to concatenate input [ndarrays][@stdlib/ndarray/ctor] (_optional_). Must be a negative integer. The index of the dimension along which to concatenate is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. Default: `-1`. +- **options**: function options (_optional_). + +The function accepts the following `options`: + +- **dim**: dimension along which to concatenate input [ndarrays][@stdlib/ndarray/ctor]. Must be a negative integer. The index of the dimension along which to concatenate is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. Default: `-1`. -#### concat.assign( arrays, out\[, dim] ) +#### concat.assign( arrays, out\[, options] ) Concatenates a list of ndarrays along a specified ndarray dimension and assigns results to an output ndarray. ```javascript var array = require( '@stdlib/ndarray/array' ); var zeros = require( '@stdlib/ndarray/zeros' ); -var ndarray2array = require( '@stdlib/ndarray/to-array' ); var x = array( [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ] ); var y = array( [ [ -5.0, 6.0, -7.0 ], [ 8.0, -9.0, 10.0 ] ] ); var z = zeros( [ 2, 5 ] ); -var out = concat.assign( [ x, y ], z, -1 ); -// returns +var out = concat.assign( [ x, y ], z, { + 'dim': -1 +}); +// returns [ [ -1.0, 2.0, -5.0, 6.0, -7.0 ], [ -3.0, 4.0, 8.0, -9.0, 10.0 ] ] var bool = ( out === z ); // returns true - -var arr = ndarray2array( z ); -// returns [ [ -1.0, 2.0, -5.0, 6.0, -7.0 ], [ -3.0, 4.0, 8.0, -9.0, 10.0 ] ] ``` The function accepts the following arguments: - **arrays**: a list of input [ndarrays][@stdlib/ndarray/ctor]. Must be [broadcast compatible][@stdlib/ndarray/base/broadcast-shapes] except for the dimension along which to concatenate. 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]. -- **dim**: dimension along which to concatenate input [ndarrays][@stdlib/ndarray/ctor] (_optional_). Must be a negative integer. The index of the dimension along which to concatenate is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. Default: `-1`. +- **options**: function options (_optional_). + +The function accepts the following `options`: + +- **dim**: dimension along which to concatenate input [ndarrays][@stdlib/ndarray/ctor]. Must be a negative integer. The index of the dimension along which to concatenate is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. Default: `-1`. @@ -129,7 +133,7 @@ var ybuf = discreteUniform( 8, 0, 10, { var y = new ndarray( 'generic', ybuf, [ 2, 4 ], [ 4, 1 ], 0, 'row-major' ); console.log( ndarray2array( y ) ); -var out = concat( [ x, y ], -1 ); +var out = concat( [ x, y ] ); console.log( ndarray2array( out ) ); ``` diff --git a/lib/node_modules/@stdlib/ndarray/concat/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/ndarray/concat/benchmark/benchmark.assign.js index eab82229c1cf..b4e75a43cb89 100644 --- a/lib/node_modules/@stdlib/ndarray/concat/benchmark/benchmark.assign.js +++ b/lib/node_modules/@stdlib/ndarray/concat/benchmark/benchmark.assign.js @@ -23,13 +23,14 @@ var bench = require( '@stdlib/bench' ); var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var zeros = require( '@stdlib/ndarray/zeros' ); +var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var concat = require( './../lib/assign.js' ); // MAIN // -bench( pkg+'::1d', function benchmark( b ) { +bench( format( '%s::1d', pkg ), function benchmark( b ) { var values; var opts; var out; @@ -50,7 +51,7 @@ bench( pkg+'::1d', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = concat( values, out, -1 ); + v = concat( values, out ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -63,27 +64,27 @@ bench( pkg+'::1d', function benchmark( b ) { b.end(); }); -bench( pkg+'::1d,casting', function benchmark( b ) { +bench( format( '%s::1d,casting', pkg ), function benchmark( b ) { var values; var out; var v; var i; - /* eslint-disable object-curly-newline */ + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ values = [ - zeros( [ 32 ], { 'dtype': 'float64' }), - zeros( [ 32 ], { 'dtype': 'float32' }), - zeros( [ 32 ], { 'dtype': 'int32' }), - zeros( [ 32 ], { 'dtype': 'generic' }) + zeros( [ 32 ], { 'dtype': 'float64' } ), + zeros( [ 32 ], { 'dtype': 'float32' } ), + zeros( [ 32 ], { 'dtype': 'int32' } ), + zeros( [ 32 ], { 'dtype': 'generic' } ) ]; - out = zeros( [ 128 ], { 'dtype': 'generic' }); + out = zeros( [ 128 ], { 'dtype': 'generic' } ); - /* eslint-enable object-curly-newline */ + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = concat( values, out, -1 ); + v = concat( values, out ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -96,7 +97,7 @@ bench( pkg+'::1d,casting', function benchmark( b ) { b.end(); }); -bench( pkg+'::2d', function benchmark( b ) { +bench( format( '%s::2d', pkg ), function benchmark( b ) { var values; var opts; var out; @@ -117,7 +118,7 @@ bench( pkg+'::2d', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = concat( values, out, -1 ); + v = concat( values, out ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -130,27 +131,27 @@ bench( pkg+'::2d', function benchmark( b ) { b.end(); }); -bench( pkg+'::2d,casting', function benchmark( b ) { +bench( format( '%s::2d,casting', pkg ), function benchmark( b ) { var values; var out; var v; var i; - /* eslint-disable object-curly-newline */ + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ values = [ - zeros( [ 2, 16 ], { 'dtype': 'float64' }), - zeros( [ 2, 16 ], { 'dtype': 'float32' }), - zeros( [ 2, 16 ], { 'dtype': 'int32' }), - zeros( [ 2, 16 ], { 'dtype': 'generic' }) + zeros( [ 2, 16 ], { 'dtype': 'float64' } ), + zeros( [ 2, 16 ], { 'dtype': 'float32' } ), + zeros( [ 2, 16 ], { 'dtype': 'int32' } ), + zeros( [ 2, 16 ], { 'dtype': 'generic' } ) ]; - out = zeros( [ 2, 64 ], { 'dtype': 'generic' }); + out = zeros( [ 2, 64 ], { 'dtype': 'generic' } ); - /* eslint-enable object-curly-newline */ + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = concat( values, out, -1 ); + v = concat( values, out ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -163,7 +164,7 @@ bench( pkg+'::2d,casting', function benchmark( b ) { b.end(); }); -bench( pkg+'::3d', function benchmark( b ) { +bench( format( '%s::3d', pkg ), function benchmark( b ) { var values; var opts; var out; @@ -184,7 +185,7 @@ bench( pkg+'::3d', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = concat( values, out, -1 ); + v = concat( values, out ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -197,27 +198,27 @@ bench( pkg+'::3d', function benchmark( b ) { b.end(); }); -bench( pkg+'::3d,casting', function benchmark( b ) { +bench( format( '%s::3d,casting', pkg ), function benchmark( b ) { var values; var out; var v; var i; - /* eslint-disable object-curly-newline */ + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ values = [ - zeros( [ 2, 2, 8 ], { 'dtype': 'float64' }), - zeros( [ 2, 2, 8 ], { 'dtype': 'float32' }), - zeros( [ 2, 2, 8 ], { 'dtype': 'int32' }), - zeros( [ 2, 2, 8 ], { 'dtype': 'generic' }) + zeros( [ 2, 2, 8 ], { 'dtype': 'float64' } ), + zeros( [ 2, 2, 8 ], { 'dtype': 'float32' } ), + zeros( [ 2, 2, 8 ], { 'dtype': 'int32' } ), + zeros( [ 2, 2, 8 ], { 'dtype': 'generic' } ) ]; - out = zeros( [ 2, 2, 32 ], { 'dtype': 'generic' }); + out = zeros( [ 2, 2, 32 ], { 'dtype': 'generic' } ); - /* eslint-enable object-curly-newline */ + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = concat( values, out, -1 ); + v = concat( values, out ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -230,7 +231,7 @@ bench( pkg+'::3d,casting', function benchmark( b ) { b.end(); }); -bench( pkg+'::4d', function benchmark( b ) { +bench( format( '%s::4d', pkg ), function benchmark( b ) { var values; var opts; var out; @@ -251,7 +252,7 @@ bench( pkg+'::4d', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = concat( values, out, -1 ); + v = concat( values, out ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -264,27 +265,27 @@ bench( pkg+'::4d', function benchmark( b ) { b.end(); }); -bench( pkg+'::4d,casting', function benchmark( b ) { +bench( format( '%s::4d,casting', pkg ), function benchmark( b ) { var values; var out; var v; var i; - /* eslint-disable object-curly-newline */ + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ values = [ - zeros( [ 2, 2, 2, 4 ], { 'dtype': 'float64' }), - zeros( [ 2, 2, 2, 4 ], { 'dtype': 'float32' }), - zeros( [ 2, 2, 2, 4 ], { 'dtype': 'int32' }), - zeros( [ 2, 2, 2, 4 ], { 'dtype': 'generic' }) + zeros( [ 2, 2, 2, 4 ], { 'dtype': 'float64' } ), + zeros( [ 2, 2, 2, 4 ], { 'dtype': 'float32' } ), + zeros( [ 2, 2, 2, 4 ], { 'dtype': 'int32' } ), + zeros( [ 2, 2, 2, 4 ], { 'dtype': 'generic' } ) ]; - out = zeros( [ 2, 2, 2, 16 ], { 'dtype': 'generic' }); + out = zeros( [ 2, 2, 2, 16 ], { 'dtype': 'generic' } ); - /* eslint-enable object-curly-newline */ + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = concat( values, out, -1 ); + v = concat( values, out ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -297,7 +298,7 @@ bench( pkg+'::4d,casting', function benchmark( b ) { b.end(); }); -bench( pkg+'::5d', function benchmark( b ) { +bench( format( '%s::5d', pkg ), function benchmark( b ) { var values; var opts; var out; @@ -318,7 +319,7 @@ bench( pkg+'::5d', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = concat( values, out, -1 ); + v = concat( values, out ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -331,27 +332,27 @@ bench( pkg+'::5d', function benchmark( b ) { b.end(); }); -bench( pkg+'::5d,casting', function benchmark( b ) { +bench( format( '%s::5d,casting', pkg ), function benchmark( b ) { var values; var out; var v; var i; - /* eslint-disable object-curly-newline */ + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ values = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' }), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' }), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' }), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' }) + zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), + zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), + zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), + zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) ]; - out = zeros( [ 2, 2, 2, 2, 8 ], { 'dtype': 'generic' }); + out = zeros( [ 2, 2, 2, 2, 8 ], { 'dtype': 'generic' } ); - /* eslint-enable object-curly-newline */ + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = concat( values, out, -1 ); + v = concat( values, out ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } diff --git a/lib/node_modules/@stdlib/ndarray/concat/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/concat/benchmark/benchmark.js index 513d864440e3..917ae05e460a 100644 --- a/lib/node_modules/@stdlib/ndarray/concat/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/ndarray/concat/benchmark/benchmark.js @@ -23,13 +23,14 @@ var bench = require( '@stdlib/bench' ); var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var zeros = require( '@stdlib/ndarray/zeros' ); +var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var concat = require( './../lib' ); // MAIN // -bench( pkg+'::1d', function benchmark( b ) { +bench( format( '%s::1d', pkg ), function benchmark( b ) { var values; var opts; var v; @@ -48,7 +49,7 @@ bench( pkg+'::1d', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = concat( values, -1 ); + v = concat( values ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -61,25 +62,25 @@ bench( pkg+'::1d', function benchmark( b ) { b.end(); }); -bench( pkg+'::1d,casting', function benchmark( b ) { +bench( format( '%s::1d,casting', pkg ), function benchmark( b ) { var values; var v; var i; - /* eslint-disable object-curly-newline */ + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ values = [ - zeros( [ 32 ], { 'dtype': 'float64' }), - zeros( [ 32 ], { 'dtype': 'float32' }), - zeros( [ 32 ], { 'dtype': 'int32' }), - zeros( [ 32 ], { 'dtype': 'generic' }) + zeros( [ 32 ], { 'dtype': 'float64' } ), + zeros( [ 32 ], { 'dtype': 'float32' } ), + zeros( [ 32 ], { 'dtype': 'int32' } ), + zeros( [ 32 ], { 'dtype': 'generic' } ) ]; - /* eslint-enable object-curly-newline */ + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = concat( values, -1 ); + v = concat( values ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -92,7 +93,7 @@ bench( pkg+'::1d,casting', function benchmark( b ) { b.end(); }); -bench( pkg+'::2d', function benchmark( b ) { +bench( format( '%s::2d', pkg ), function benchmark( b ) { var values; var opts; var v; @@ -111,7 +112,7 @@ bench( pkg+'::2d', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = concat( values, -1 ); + v = concat( values ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -124,25 +125,25 @@ bench( pkg+'::2d', function benchmark( b ) { b.end(); }); -bench( pkg+'::2d,casting', function benchmark( b ) { +bench( format( '%s::2d,casting', pkg ), function benchmark( b ) { var values; var v; var i; - /* eslint-disable object-curly-newline */ + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ values = [ - zeros( [ 2, 16 ], { 'dtype': 'float64' }), - zeros( [ 2, 16 ], { 'dtype': 'float32' }), - zeros( [ 2, 16 ], { 'dtype': 'int32' }), - zeros( [ 2, 16 ], { 'dtype': 'generic' }) + zeros( [ 2, 16 ], { 'dtype': 'float64' } ), + zeros( [ 2, 16 ], { 'dtype': 'float32' } ), + zeros( [ 2, 16 ], { 'dtype': 'int32' } ), + zeros( [ 2, 16 ], { 'dtype': 'generic' } ) ]; - /* eslint-enable object-curly-newline */ + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = concat( values, -1 ); + v = concat( values ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -155,7 +156,7 @@ bench( pkg+'::2d,casting', function benchmark( b ) { b.end(); }); -bench( pkg+'::3d', function benchmark( b ) { +bench( format( '%s::3d', pkg ), function benchmark( b ) { var values; var opts; var v; @@ -174,7 +175,7 @@ bench( pkg+'::3d', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = concat( values, -1 ); + v = concat( values ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -187,25 +188,25 @@ bench( pkg+'::3d', function benchmark( b ) { b.end(); }); -bench( pkg+'::3d,casting', function benchmark( b ) { +bench( format( '%s::3d,casting', pkg ), function benchmark( b ) { var values; var v; var i; - /* eslint-disable object-curly-newline */ + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ values = [ - zeros( [ 2, 2, 8 ], { 'dtype': 'float64' }), - zeros( [ 2, 2, 8 ], { 'dtype': 'float32' }), - zeros( [ 2, 2, 8 ], { 'dtype': 'int32' }), - zeros( [ 2, 2, 8 ], { 'dtype': 'generic' }) + zeros( [ 2, 2, 8 ], { 'dtype': 'float64' } ), + zeros( [ 2, 2, 8 ], { 'dtype': 'float32' } ), + zeros( [ 2, 2, 8 ], { 'dtype': 'int32' } ), + zeros( [ 2, 2, 8 ], { 'dtype': 'generic' } ) ]; - /* eslint-enable object-curly-newline */ + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = concat( values, -1 ); + v = concat( values ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -218,7 +219,7 @@ bench( pkg+'::3d,casting', function benchmark( b ) { b.end(); }); -bench( pkg+'::4d', function benchmark( b ) { +bench( format( '%s::4d', pkg ), function benchmark( b ) { var values; var opts; var v; @@ -237,7 +238,7 @@ bench( pkg+'::4d', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = concat( values, -1 ); + v = concat( values ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -250,25 +251,25 @@ bench( pkg+'::4d', function benchmark( b ) { b.end(); }); -bench( pkg+'::4d,casting', function benchmark( b ) { +bench( format( '%s::4d,casting', pkg ), function benchmark( b ) { var values; var v; var i; - /* eslint-disable object-curly-newline */ + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ values = [ - zeros( [ 2, 2, 2, 4 ], { 'dtype': 'float64' }), - zeros( [ 2, 2, 2, 4 ], { 'dtype': 'float32' }), - zeros( [ 2, 2, 2, 4 ], { 'dtype': 'int32' }), - zeros( [ 2, 2, 2, 4 ], { 'dtype': 'generic' }) + zeros( [ 2, 2, 2, 4 ], { 'dtype': 'float64' } ), + zeros( [ 2, 2, 2, 4 ], { 'dtype': 'float32' } ), + zeros( [ 2, 2, 2, 4 ], { 'dtype': 'int32' } ), + zeros( [ 2, 2, 2, 4 ], { 'dtype': 'generic' } ) ]; - /* eslint-enable object-curly-newline */ + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = concat( values, -1 ); + v = concat( values ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -281,7 +282,7 @@ bench( pkg+'::4d,casting', function benchmark( b ) { b.end(); }); -bench( pkg+'::5d', function benchmark( b ) { +bench( format( '%s::5d', pkg ), function benchmark( b ) { var values; var opts; var v; @@ -300,7 +301,7 @@ bench( pkg+'::5d', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = concat( values, -1 ); + v = concat( values ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -313,25 +314,25 @@ bench( pkg+'::5d', function benchmark( b ) { b.end(); }); -bench( pkg+'::5d,casting', function benchmark( b ) { +bench( format( '%s::5d,casting', pkg ), function benchmark( b ) { var values; var v; var i; - /* eslint-disable object-curly-newline */ + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ values = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' }), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' }), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' }), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' }) + zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), + zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), + zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), + zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) ]; - /* eslint-enable object-curly-newline */ + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = concat( values, -1 ); + v = concat( values ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } diff --git a/lib/node_modules/@stdlib/ndarray/concat/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/concat/docs/repl.txt index da49c69232fd..14a489b04cfa 100644 --- a/lib/node_modules/@stdlib/ndarray/concat/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/concat/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( arrays[, dim] ) +{{alias}}( arrays[, options] ) Concatenates a list of ndarrays along a specified ndarray dimension. Parameters @@ -11,7 +11,10 @@ input ndarrays. If provided ndarrays having different memory layouts, the output ndarray has the default order. - dim: integer (optional) + options: Object (optional) + Function options. + + options.dim: integer (optional) Dimension along which to concatenate input ndarrays. Must be a negative integer. The index of the dimension along which to concatenate is resolved relative to the last dimension, with the last dimension @@ -26,13 +29,11 @@ -------- > 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 ) - - > var arr = {{alias:@stdlib/ndarray/to-array}}( out ) - [ [ 1.0, 2.0, 5.0, 6.0 ], [ 3.0, 4.0, 7.0, 8.0 ] ] + > var out = {{alias}}( [ x, y ], { 'dim': -1 } ) + [ [ 1.0, 2.0, 5.0, 6.0 ], [ 3.0, 4.0, 7.0, 8.0 ] ] -{{alias}}.assign( arrays, out[, dim] ) +{{alias}}.assign( arrays, out[, options] ) Concatenates a list of ndarrays along a specified ndarray dimension and assigns results to a provided output ndarray. @@ -47,7 +48,10 @@ out: ndarray Output ndarray. - dim: integer (optional) + options: Object (optional) + Function options. + + options.dim: integer (optional) Dimension along which to concatenate input ndarrays. Must be a negative integer. The index of the dimension along which to concatenate is resolved relative to the last dimension, with the last dimension @@ -63,12 +67,10 @@ > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0 ], [ 2.0 ] ] ); > var y = {{alias:@stdlib/ndarray/array}}( [ [ 3.0 ], [ 4.0 ] ] ); > var z = {{alias:@stdlib/ndarray/array}}( [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] ); - > var out = {{alias}}.assign( [ x, y ], z, -1 ) - + > var out = {{alias}}.assign( [ x, y ], z, { 'dim': -1 } ) + [ [ 1.0, 3.0 ], [ 2.0, 4.0 ] ] > var bool = ( out === z ) true - > var arr = {{alias:@stdlib/ndarray/to-array}}( out ) - [ [ 1.0, 3.0 ], [ 2.0, 4.0 ] ] See Also -------- diff --git a/lib/node_modules/@stdlib/ndarray/concat/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/concat/docs/types/index.d.ts index c09d62a24133..a2b653b6ee0f 100644 --- a/lib/node_modules/@stdlib/ndarray/concat/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/concat/docs/types/index.d.ts @@ -23,6 +23,16 @@ import { ArrayLike } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; +/** +* Interface describing function options. +*/ +interface Options { + /** + * Dimension along which to concatenate input ndarrays. + */ + dim?: number; +} + /** * Interface describing `concat`. */ @@ -31,11 +41,10 @@ interface Concat { * Concatenates a list of ndarrays along a specified ndarray dimension. * * @param arrays - array-like object containing input ndarrays - * @param dim - dimension along which to concatenate input ndarrays + * @param options - function options * @returns output ndarray * * @example - * var ndarray2array = require( '@stdlib/ndarray/to-array' ); * var Float64Array = require( '@stdlib/array/float64' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); * @@ -45,24 +54,22 @@ interface Concat { * var ybuf = new Float64Array( [ -5.0, 6.0, -7.0, 8.0, -9.0, 10.0 ] ); * var y = new ndarray( 'float64', ybuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); * - * var out = concat( [ x, y ], -1 ); - * // returns - * - * var arr = ndarray2array( out ); - * // returns [ [ -1.0, 2.0, -5.0, 6.0, -7.0 ], [ -3.0, 4.0, 8.0, -9.0, 10.0 ] ] + * var out = concat( [ x, y ], { + * 'dim': -1 + * }); + * // returns [ [ -1.0, 2.0, -5.0, 6.0, -7.0 ], [ -3.0, 4.0, 8.0, -9.0, 10.0 ] ] */ - ( arrays: ArrayLike>, dim?: number ): typedndarray; + ( arrays: ArrayLike>, options?: Options ): typedndarray; /** * Concatenates a list of ndarrays along a specified ndarray dimension and assigns results to a provided output ndarray. * * @param arrays - array-like object containing input ndarrays * @param out - output ndarray - * @param dim - dimension along which to concatenate input ndarrays + * @param options - function options * @returns output ndarray * * @example - * var ndarray2array = require( '@stdlib/ndarray/to-array' ); * var Float64Array = require( '@stdlib/array/float64' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); * @@ -74,26 +81,25 @@ interface Concat { * * var z = new ndarray( 'float64', new Float64Array( 10 ), [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); * - * var out = concat.assign( [ x, y ], z, -1 ); + * var out = concat.assign( [ x, y ], z, { + * 'dim': -1 + * }); + * // returns [ [ -1.0, 2.0, -5.0, 6.0, -7.0 ], [ -3.0, 4.0, 8.0, -9.0, 10.0 ] ] * * var bool = ( out === z ); * // returns true - * - * var arr = ndarray2array( z ); - * // returns [ [ -1.0, 2.0, -5.0, 6.0, -7.0 ], [ -3.0, 4.0, 8.0, -9.0, 10.0 ] ] */ - assign = typedndarray>( arrays: ArrayLike>, out: V, dim?: number ): V; + assign = typedndarray>( arrays: ArrayLike>, out: V, options?: Options ): V; } /** * Concatenates a list of ndarrays along a specified ndarray dimension. * * @param arrays - array-like object containing input ndarrays -* @param dim - dimension along which to concatenate input ndarrays +* @param options - function options * @returns output ndarray * * @example -* var ndarray2array = require( '@stdlib/ndarray/to-array' ); * var Float64Array = require( '@stdlib/array/float64' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); * @@ -103,14 +109,12 @@ interface Concat { * var ybuf = new Float64Array( [ -5.0, 6.0, -7.0, 8.0, -9.0, 10.0 ] ); * var y = new ndarray( 'float64', ybuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); * -* var out = concat( [ x, y ], -1 ); -* // returns -* -* var arr = ndarray2array( out ); -* // returns [ [ -1.0, 2.0, -5.0, 6.0, -7.0 ], [ -3.0, 4.0, 8.0, -9.0, 10.0 ] ] +* var out = concat( [ x, y ], { +* 'dim': -1 +* }); +* // returns [ [ -1.0, 2.0, -5.0, 6.0, -7.0 ], [ -3.0, 4.0, 8.0, -9.0, 10.0 ] ] * * @example -* var ndarray2array = require( '@stdlib/ndarray/to-array' ); * var Float64Array = require( '@stdlib/array/float64' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); * @@ -122,13 +126,13 @@ interface Concat { * * var z = new ndarray( 'float64', new Float64Array( 10 ), [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); * -* var out = concat.assign( [ x, y ], z, -1 ); +* var out = concat.assign( [ x, y ], z, { +* 'dim': -1 +* }); +* // returns [ [ -1.0, 2.0, -5.0, 6.0, -7.0 ], [ -3.0, 4.0, 8.0, -9.0, 10.0 ] ] * * var bool = ( out === z ); * // returns true -* -* var arr = ndarray2array( z ); -* // returns [ [ -1.0, 2.0, -5.0, 6.0, -7.0 ], [ -3.0, 4.0, 8.0, -9.0, 10.0 ] ] */ declare var concat: Concat; diff --git a/lib/node_modules/@stdlib/ndarray/concat/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/concat/docs/types/test.ts index ff76be611a3d..7cc2bd2b83c8 100644 --- a/lib/node_modules/@stdlib/ndarray/concat/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/concat/docs/types/test.ts @@ -30,7 +30,7 @@ import concat = require( './index' ); const y = zeros( [ 2, 3 ] ); concat( [ x, y ] ); // $ExpectType typedndarray - concat( [ x, y ], -1 ); // $ExpectType typedndarray + concat( [ 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... @@ -44,30 +44,43 @@ import concat = require( './index' ); concat( {} ); // $ExpectError concat( ( x: number ): number => x ); // $ExpectError - concat( 5, -1 ); // $ExpectError - concat( true, -1 ); // $ExpectError - concat( false, -1 ); // $ExpectError - concat( null, -1 ); // $ExpectError - concat( undefined, -1 ); // $ExpectError - concat( [ 1 ], -1 ); // $ExpectError - concat( {}, -1 ); // $ExpectError - concat( ( x: number ): number => x, -1 ); // $ExpectError + concat( 5, {} ); // $ExpectError + concat( true, {} ); // $ExpectError + concat( false, {} ); // $ExpectError + concat( null, {} ); // $ExpectError + concat( undefined, {} ); // $ExpectError + concat( [ 1 ], {} ); // $ExpectError + concat( {}, {} ); // $ExpectError + concat( ( x: number ): number => x, {} ); // $ExpectError } -// The compiler throws an error if the function is provided a second argument which is not a number... +// The compiler throws an error if the function is provided an options argument which is not an object... { const x = zeros( [ 2, 2 ] ); const y = zeros( [ 2, 3 ] ); concat( [ x, y ], '5' ); // $ExpectError + concat( [ x, y ], 5 ); // $ExpectError concat( [ x, y ], true ); // $ExpectError concat( [ x, y ], false ); // $ExpectError concat( [ x, y ], null ); // $ExpectError concat( [ x, y ], [ 1 ] ); // $ExpectError - concat( [ x, y ], {} ); // $ExpectError concat( [ x, y ], ( x: number ): number => x ); // $ExpectError } +// The compiler throws an error if the function is provided an invalid `dim` option... +{ + const x = zeros( [ 2, 2 ] ); + const y = zeros( [ 2, 3 ] ); + + concat( [ x, y ], { 'dim': '5'} ); // $ExpectError + concat( [ x, y ], { 'dim': true} ); // $ExpectError + concat( [ x, y ], { 'dim': false } ); // $ExpectError + concat( [ x, y ], { 'dim': null } ); // $ExpectError + concat( [ x, y ], { 'dim': [ 1 ] } ); // $ExpectError + concat( [ x, y ], { 'dim': ( 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 ] ); @@ -75,7 +88,7 @@ import concat = require( './index' ); concat(); // $ExpectError concat( x ); // $ExpectError - concat( [ x, y ], -1, {} ); // $ExpectError + concat( [ x, y ], {}, {} ); // $ExpectError } // Attached to the function is an `assign` method which returns an ndarray... @@ -85,7 +98,7 @@ import concat = require( './index' ); const z = zeros( [ 2, 5 ] ); concat.assign( [ x, y ], z ); // $ExpectType float64ndarray - concat.assign( [ x, y ], z, -1 ); // $ExpectType float64ndarray + concat.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...... @@ -101,14 +114,14 @@ import concat = require( './index' ); concat.assign( {}, z ); // $ExpectError concat.assign( ( x: number ): number => x, z ); // $ExpectError - concat.assign( 5, z, -1 ); // $ExpectError - concat.assign( true, z, -1 ); // $ExpectError - concat.assign( false, z, -1 ); // $ExpectError - concat.assign( null, z, -1 ); // $ExpectError - concat.assign( undefined, z, -1 ); // $ExpectError - concat.assign( [ 1 ], z, -1 ); // $ExpectError - concat.assign( {}, z, -1 ); // $ExpectError - concat.assign( ( x: number ): number => x, z, -1 ); // $ExpectError + concat.assign( 5, z, {} ); // $ExpectError + concat.assign( true, z, {} ); // $ExpectError + concat.assign( false, z, {} ); // $ExpectError + concat.assign( null, z, {} ); // $ExpectError + concat.assign( undefined, z, {} ); // $ExpectError + concat.assign( [ 1 ], z, {} ); // $ExpectError + concat.assign( {}, z, {} ); // $ExpectError + concat.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... @@ -125,31 +138,45 @@ import concat = require( './index' ); concat.assign( [ x, y ], {} ); // $ExpectError concat.assign( [ x, y ], ( x: number ): number => x ); // $ExpectError - concat.assign( [ x, y ], '5', -1 ); // $ExpectError - concat.assign( [ x, y ], 5, -1 ); // $ExpectError - concat.assign( [ x, y ], true, -1 ); // $ExpectError - concat.assign( [ x, y ], false, -1 ); // $ExpectError - concat.assign( [ x, y ], null, -1 ); // $ExpectError - concat.assign( [ x, y ], [ 1 ], -1 ); // $ExpectError - concat.assign( [ x, y ], {}, -1 ); // $ExpectError - concat.assign( [ x, y ], ( x: number ): number => x, -1 ); // $ExpectError + concat.assign( [ x, y ], '5', {} ); // $ExpectError + concat.assign( [ x, y ], 5, {} ); // $ExpectError + concat.assign( [ x, y ], true, {} ); // $ExpectError + concat.assign( [ x, y ], false, {} ); // $ExpectError + concat.assign( [ x, y ], null, {} ); // $ExpectError + concat.assign( [ x, y ], [ 1 ], {} ); // $ExpectError + concat.assign( [ x, y ], {}, {} ); // $ExpectError + concat.assign( [ x, y ], ( x: number ): number => x, {} ); // $ExpectError } -// The compiler throws an error if the `assign` method is provided a third argument which is not a number... +// The compiler throws an error if the `assign` method is provided an options argument which is not an object... { const x = zeros( [ 2, 2 ] ); const y = zeros( [ 2, 3 ] ); const z = zeros( [ 2, 5 ] ); concat.assign( [ x, y ], z, '5' ); // $ExpectError + concat.assign( [ x, y ], z, 5 ); // $ExpectError concat.assign( [ x, y ], z, true ); // $ExpectError concat.assign( [ x, y ], z, false ); // $ExpectError concat.assign( [ x, y ], z, null ); // $ExpectError concat.assign( [ x, y ], z, [ 1 ] ); // $ExpectError - concat.assign( [ x, y ], z, {} ); // $ExpectError concat.assign( [ x, y ], z, ( x: number ): number => x ); // $ExpectError } +// The compiler throws an error if the function is provided an invalid `dim` option... +{ + const x = zeros( [ 2, 2 ] ); + const y = zeros( [ 2, 3 ] ); + const z = zeros( [ 2, 5 ] ); + + concat.assign( [ x, y ], z, { 'dim': '5'} ); // $ExpectError + concat.assign( [ x, y ], z, { 'dim': true} ); // $ExpectError + concat.assign( [ x, y ], z, { 'dim': false } ); // $ExpectError + concat.assign( [ x, y ], z, { 'dim': null } ); // $ExpectError + concat.assign( [ x, y ], z, { 'dim': [ 1 ] } ); // $ExpectError + concat.assign( [ x, y ], z, { 'dim': ( 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 ] ); @@ -158,5 +185,5 @@ import concat = require( './index' ); concat.assign(); // $ExpectError concat.assign( [ x, y ] ); // $ExpectError - concat.assign( [ x, y ], z, -1, {} ); // $ExpectError + concat.assign( [ x, y ], z, {}, {} ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/ndarray/concat/lib/assign.js b/lib/node_modules/@stdlib/ndarray/concat/lib/assign.js index ce6deaab0129..f295f89a9b76 100644 --- a/lib/node_modules/@stdlib/ndarray/concat/lib/assign.js +++ b/lib/node_modules/@stdlib/ndarray/concat/lib/assign.js @@ -22,7 +22,6 @@ var hasEqualValuesIndexed = require( '@stdlib/array/base/assert/has-equal-values-indexed' ); var isMostlySafeCast = require( '@stdlib/ndarray/base/assert/is-mostly-safe-data-type-cast' ); -var isNegativeInteger = require( '@stdlib/assert/is-negative-integer' ).isPrimitive; var isArrayLikeObject = require( '@stdlib/assert/is-array-like-object' ); var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var promoteDataTypes = require( '@stdlib/ndarray/base/promote-dtypes' ); @@ -37,6 +36,7 @@ var normalizeArrays = require( './normalize_arrays.js' ); var broadcastArrays = require( './broadcast_arrays.js' ); var resolveDataTypes = require( './resolve_dtypes.js' ); var resolveShape = require( './resolve_shape.js' ); +var validate = require( './validate.js' ); var base = require( './base.js' ); @@ -47,16 +47,17 @@ var base = require( './base.js' ); * * @param {ArrayLikeObject} arrays - array-like object containing input ndarrays * @param {ndarrayLike} out - output ndarray -* @param {NegativeInteger} [dim] - dimension along which to concatenate input ndarrays +* @param {Options} [options] - function options +* @param {integer} [options.dim=-1] - dimension along which to concatenate the input ndarrays * @throws {TypeError} first argument must be an array of ndarray-like objects * @throws {RangeError} first argument must contain one or more ndarrays * @throws {TypeError} second argument must be an ndarray-like object -* @throws {TypeError} third argument must be a negative integer +* @throws {TypeError} options argument must be an object +* @throws {TypeError} must provide valid options * @throws {Error} must provide ndarrays which can be safely cast to a common data type * @returns {ndarrayLike} output ndarray * * @example -* var ndarray2array = require( '@stdlib/ndarray/to-array' ); * var Float64Array = require( '@stdlib/array/float64' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); * @@ -68,18 +69,17 @@ var base = require( './base.js' ); * * var z = new ndarray( 'float64', new Float64Array( 10 ), [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); * -* var out = assign( [ x, y ], z, -1 ); -* // returns +* var out = assign( [ x, y ], z ); +* // returns [ [ -1.0, 2.0, -5.0, 6.0, -7.0 ], [ -3.0, 4.0, 8.0, -9.0, 10.0 ] ] * * var bool = ( out === z ); * // returns true -* -* var arr = ndarray2array( z ); -* // returns [ [ -1.0, 2.0, -5.0, 6.0, -7.0 ], [ -3.0, 4.0, 8.0, -9.0, 10.0 ] ] */ -function assign( arrays, out, dim ) { +function assign( arrays, out ) { + var opts; var arrs; var view; + var err; var osh; var sh; var dt; @@ -91,12 +91,14 @@ function assign( arrays, out, dim ) { if ( !isndarrayLike( out ) ) { throw new TypeError( format( 'invalid argument. Second argument must be an ndarray. Value: `%s`.', out ) ); } + opts = { + 'dim': -1 + }; if ( arguments.length > 2 ) { - if ( !isNegativeInteger( dim ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a negative integer. Value: `%s`.', dim ) ); + err = validate( opts, arguments[ 2 ] ); + if ( err ) { + throw err; } - } else { - dim = -1; } // Normalize the list of input ndarrays: arrs = normalizeArrays( arrays ); @@ -105,7 +107,7 @@ function assign( arrays, out, dim ) { view = ndarraylike2ndarray( out ); // Broadcast the input ndarrays to a common shape: - arrs = broadcastArrays( arrs, dim ); + arrs = broadcastArrays( arrs, opts.dim ); // Apply type promotion rules to the data types of the input ndarrays: dt = promoteDataTypes( resolveDataTypes( arrs ) ); @@ -117,7 +119,7 @@ function assign( arrays, out, dim ) { throw new Error( format( 'invalid argument. The list of input ndarrays cannot be safely cast to the data of the output ndarray. Input data types: [%s]. Output data type: %s.', join( resolveDataTypes( arrs ), ', ' ), getDType( view ) ) ); } // Normalize the dimension index: - d = normalizeIndex( dim, ndims( arrs[ 0 ] )-1 ); + d = normalizeIndex( opts.dim, ndims( arrs[ 0 ] )-1 ); // Resolve the expected shape of the output ndarray: sh = resolveShape( arrs, d ); diff --git a/lib/node_modules/@stdlib/ndarray/concat/lib/index.js b/lib/node_modules/@stdlib/ndarray/concat/lib/index.js index 46ff181d902c..db36bf920a19 100644 --- a/lib/node_modules/@stdlib/ndarray/concat/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/concat/lib/index.js @@ -25,7 +25,6 @@ * * @example * var Float64Array = require( '@stdlib/array/float64' ); -* var ndarray2array = require( '@stdlib/ndarray/to-array' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); * var concat = require( '@stdlib/ndarray/concat' ); * @@ -35,11 +34,8 @@ * var ybuf = new Float64Array( [ -5.0, 6.0, -7.0, 8.0, -9.0, 10.0 ] ); * var y = new ndarray( 'float64', ybuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); * -* var out = concat( [ x, y ], -1 ); -* // returns -* -* var arr = ndarray2array( out ); -* // returns [ [ -1.0, 2.0, -5.0, 6.0, -7.0 ], [ -3.0, 4.0, 8.0, -9.0, 10.0 ] ] +* var out = concat( [ x, y ] ); +* // returns [ [ -1.0, 2.0, -5.0, 6.0, -7.0 ], [ -3.0, 4.0, 8.0, -9.0, 10.0 ] ] */ // MODULES // diff --git a/lib/node_modules/@stdlib/ndarray/concat/lib/main.js b/lib/node_modules/@stdlib/ndarray/concat/lib/main.js index 57bb17d0c405..2b8284acc7a6 100644 --- a/lib/node_modules/@stdlib/ndarray/concat/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/concat/lib/main.js @@ -20,7 +20,6 @@ // MODULES // -var isNegativeInteger = require( '@stdlib/assert/is-negative-integer' ).isPrimitive; var isArrayLikeObject = require( '@stdlib/assert/is-array-like-object' ); var promoteDataTypes = require( '@stdlib/ndarray/base/promote-dtypes' ); var normalizeIndex = require( '@stdlib/ndarray/base/normalize-index' ); @@ -33,6 +32,7 @@ var broadcastArrays = require( './broadcast_arrays.js' ); var resolveDataTypes = require( './resolve_dtypes.js' ); var resolveShape = require( './resolve_shape.js' ); var resolveOrder = require( './resolve_order.js' ); +var validate = require( './validate.js' ); var base = require( './base.js' ); @@ -42,15 +42,16 @@ var base = require( './base.js' ); * Concatenates a list of ndarrays along a specified ndarray dimension. * * @param {ArrayLikeObject} arrays - array-like object containing input ndarrays -* @param {NegativeInteger} [dim] - dimension along which to concatenate input ndarrays +* @param {Options} [options] - function options +* @param {integer} [options.dim=-1] - dimension along which to concatenate the input ndarrays * @throws {TypeError} first argument must be an array of ndarray-like objects * @throws {RangeError} first argument must contain one or more ndarrays -* @throws {TypeError} second argument must be a negative integer +* @throws {TypeError} options argument must be an object +* @throws {TypeError} must provide valid options * @throws {Error} must provide ndarrays which can be safely cast to a common data type * @returns {ndarray} output ndarray * * @example -* var ndarray2array = require( '@stdlib/ndarray/to-array' ); * var Float64Array = require( '@stdlib/array/float64' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); * @@ -60,14 +61,13 @@ var base = require( './base.js' ); * var ybuf = new Float64Array( [ -5.0, 6.0, -7.0, 8.0, -9.0, 10.0 ] ); * var y = new ndarray( 'float64', ybuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); * -* var out = concat( [ x, y ], -1 ); -* // returns -* -* var arr = ndarray2array( out ); -* // returns [ [ -1.0, 2.0, -5.0, 6.0, -7.0 ], [ -3.0, 4.0, 8.0, -9.0, 10.0 ] ] +* var out = concat( [ x, y ] ); +* // returns [ [ -1.0, 2.0, -5.0, 6.0, -7.0 ], [ -3.0, 4.0, 8.0, -9.0, 10.0 ] ] */ -function concat( arrays, dim ) { +function concat( arrays ) { + var opts; var arrs; + var err; var out; var dt; var d; @@ -75,18 +75,20 @@ function concat( arrays, dim ) { if ( !isArrayLikeObject( arrays ) || arrays.length < 1 ) { throw new TypeError( format( 'invalid argument. First argument must be an array of ndarrays. Value: `%s`.', arrays ) ); } + opts = { + 'dim': -1 + }; if ( arguments.length > 1 ) { - if ( !isNegativeInteger( dim ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a negative integer. Value: `%s`.', dim ) ); + err = validate( opts, arguments[ 1 ] ); + if ( err ) { + throw err; } - } else { - dim = -1; } // Normalize the list of input ndarrays: arrs = normalizeArrays( arrays ); // Broadcast the input ndarrays to a common shape: - arrs = broadcastArrays( arrs, dim ); + arrs = broadcastArrays( arrs, opts.dim ); // Resolve the data type of the output ndarray by applying type promotion rules to the data types of the input ndarrays: dt = promoteDataTypes( resolveDataTypes( arrs ) ); @@ -94,7 +96,7 @@ function concat( arrays, dim ) { throw new Error( format( 'invalid argument. Unable to apply type promotion rules when resolving a data type to which the input ndarrays can be safely cast. Data types: [%s].', join( resolveDataTypes( arrs ), ', ' ) ) ); } // Normalize the dimension index: - d = normalizeIndex( dim, ndims( arrs[ 0 ] )-1 ); + d = normalizeIndex( opts.dim, ndims( arrs[ 0 ] )-1 ); // Create an output ndarray: out = empty( resolveShape( arrs, d ), { diff --git a/lib/node_modules/@stdlib/ndarray/concat/lib/validate.js b/lib/node_modules/@stdlib/ndarray/concat/lib/validate.js new file mode 100644 index 000000000000..924cb3574549 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/concat/lib/validate.js @@ -0,0 +1,66 @@ +/** +* @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 isObject = require( '@stdlib/assert/is-plain-object' ); +var isNegativeInteger = require( '@stdlib/assert/is-negative-integer' ).isPrimitive; +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Validates function options. +* +* @private +* @param {Object} opts - destination object +* @param {Options} options - function options +* @param {integer} [options.dim] - dimension along which to concatenate the input ndarrays +* @returns {(Error|null)} null or an error object +* +* @example +* var opts = {}; +* var options = { +* 'dim': -1 +* }; +* var err = validate( opts, options ); +* if ( err ) { +* throw err; +* } +*/ +function validate( opts, options ) { + if ( !isObject( options ) ) { + return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + if ( hasOwnProp( options, 'dim' ) ) { + opts.dim = options.dim; + if ( !isNegativeInteger( opts.dim ) ) { + return new TypeError( format( 'invalid option. `%s` option must be a negative integer. Option: `%s`.', 'dim', opts.dim ) ); + } + } + return null; +} + + +// EXPORTS // + +module.exports = validate; diff --git a/lib/node_modules/@stdlib/ndarray/concat/test/test.assign.js b/lib/node_modules/@stdlib/ndarray/concat/test/test.assign.js index 823a4e4941b1..dcae9c6410a3 100644 --- a/lib/node_modules/@stdlib/ndarray/concat/test/test.assign.js +++ b/lib/node_modules/@stdlib/ndarray/concat/test/test.assign.js @@ -72,7 +72,7 @@ tape( 'the function throws an error if provided a first argument which is not an } }); -tape( 'the function throws an error if provided a first argument which is not an array of ndarrays (dim)', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not an array of ndarrays (options)', function test( t ) { var values; var out; var i; @@ -102,7 +102,9 @@ tape( 'the function throws an error if provided a first argument which is not an function badValue( value ) { return function badValue() { - assign( value, out, -1 ); + assign( value, out, { + 'dim': -1 + }); }; } }); @@ -138,7 +140,7 @@ tape( 'the function throws an error if provided a first argument containing ndar } }); -tape( 'the function throws an error if provided a first argument containing ndarrays which do not promote to a common data type (dim)', function test( t ) { +tape( 'the function throws an error if provided a first argument containing ndarrays which do not promote to a common data type (options)', function test( t ) { var values; var out; var i; @@ -164,7 +166,9 @@ tape( 'the function throws an error if provided a first argument containing ndar function badValue( value ) { return function badValue() { - assign( value, out, -1 ); + assign( value, out, { + 'dim': -1 + }); }; } }); @@ -200,7 +204,7 @@ tape( 'the function throws an error if provided a first argument containing ndar } }); -tape( 'the function throws an error if provided a first argument containing ndarrays which are not broadcast compatible (dim)', function test( t ) { +tape( 'the function throws an error if provided a first argument containing ndarrays which are not broadcast compatible (options)', function test( t ) { var values; var out; var i; @@ -226,7 +230,9 @@ tape( 'the function throws an error if provided a first argument containing ndar function badValue( value ) { return function badValue() { - assign( value, out, -1 ); + assign( value, out, { + 'dim': -1 + }); }; } }); @@ -265,7 +271,7 @@ tape( 'the function throws an error if provided a second argument which is not a } }); -tape( 'the function throws an error if provided a second argument which is not an ndarray (dim)', function test( t ) { +tape( 'the function throws an error if provided a second argument which is not an ndarray (options)', function test( t ) { var values; var x; var y; @@ -294,7 +300,9 @@ tape( 'the function throws an error if provided a second argument which is not a function badValue( value ) { return function badValue() { - assign( [ x, y ], value, -1 ); + assign( [ x, y ], value, { + 'dim': -1 + }); }; } }); @@ -330,7 +338,7 @@ tape( 'the function throws an error if provided a second argument which has a da } }); -tape( 'the function throws an error if provided a second argument which has a data type to which input ndarrays cannot be safely cast (dim)', function test( t ) { +tape( 'the function throws an error if provided a second argument which has a data type to which input ndarrays cannot be safely cast (options)', function test( t ) { var values; var out; var i; @@ -356,7 +364,9 @@ tape( 'the function throws an error if provided a second argument which has a da function badValue( value ) { return function badValue() { - assign( value, out, -1 ); + assign( value, out, { + 'dim': -1 + }); }; } }); @@ -392,7 +402,7 @@ tape( 'the function throws an error if provided a second argument having an inva } }); -tape( 'the function throws an error if provided a second argument having an invalid shape (dim)', function test( t ) { +tape( 'the function throws an error if provided a second argument having an invalid shape (options)', function test( t ) { var values; var out; var i; @@ -418,12 +428,49 @@ tape( 'the function throws an error if provided a second argument having an inva function badValue( value ) { return function badValue() { - assign( value, out, -1 ); + assign( value, out, { + 'dim': -1 + }); }; } }); -tape( 'the function throws an error if provided a third argument which is not a negative integer', function test( t ) { +tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { + var values; + var x; + var y; + var z; + var i; + + x = zeros( [ 2, 2 ] ); + y = zeros( [ 2, 2 ] ); + z = zeros( [ 2, 4 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( [ x, y ], z, value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument with an invalid `dim` property', function test( t ) { var values; var x; var y; @@ -445,8 +492,8 @@ tape( 'the function throws an error if provided a third argument which is not a false, null, void 0, - [], {}, + [], function noop() {} ]; @@ -457,7 +504,10 @@ tape( 'the function throws an error if provided a third argument which is not a function badValue( value ) { return function badValue() { - assign( [ x, y ], z, value ); + var opts = { + 'dim': value + }; + assign( [ x, y ], z, opts ); }; } }); @@ -503,7 +553,9 @@ tape( 'the function concatenates ndarrays along a specified dimension', function 'dtype': 'float64' }); - out = assign( [ x, y ], z, -1 ); + out = assign( [ x, y ], z, { + 'dim': -1 + }); actual = ndarray2array( z ); expected = [ @@ -524,7 +576,9 @@ tape( 'the function concatenates ndarrays along a specified dimension', function 'dtype': 'float64' }); - out = assign( [ x, y ], z, -2 ); + out = assign( [ x, y ], z, { + 'dim': -2 + }); actual = ndarray2array( z ); expected = [ @@ -544,7 +598,9 @@ tape( 'the function concatenates ndarrays along a specified dimension', function 'dtype': 'float64' }); - out = assign( [ x ], z, -1 ); + out = assign( [ x ], z, { + 'dim': -1 + }); actual = ndarray2array( z ); expected = [ @@ -578,7 +634,9 @@ tape( 'the function concatenates ndarrays along a specified dimension (type prom 'dtype': 'float32' }); - out = assign( [ x, y ], z, -1 ); + out = assign( [ x, y ], z, { + 'dim': -1 + }); actual = ndarray2array( z ); expected = [ @@ -612,7 +670,9 @@ tape( 'the function concatenates ndarray along a specified dimension (broadcasti 'dtype': 'float64' }); - out = assign( [ x, y ], z, -1 ); + out = assign( [ x, y ], z, { + 'dim': -1 + }); actual = ndarray2array( z ); expected = [ [ 1.0, 2.0, 3.0, 4.0 ], @@ -657,7 +717,9 @@ tape( 'the function concatenates ndarrays along a specified dimension (ndims=1)' 'dtype': 'float64' }); - out = assign( [ x, y ], z, -1 ); + out = assign( [ x, y ], z, { + 'dim': -1 + }); actual = ndarray2array( z ); expected = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; diff --git a/lib/node_modules/@stdlib/ndarray/concat/test/test.main.js b/lib/node_modules/@stdlib/ndarray/concat/test/test.main.js index 19da2b8b1196..1434c895f706 100644 --- a/lib/node_modules/@stdlib/ndarray/concat/test/test.main.js +++ b/lib/node_modules/@stdlib/ndarray/concat/test/test.main.js @@ -75,7 +75,7 @@ tape( 'the function throws an error if provided a first argument which is not an } }); -tape( 'the function throws an error if provided a first argument which is not an array of ndarrays (dim)', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not an array of ndarrays (options)', function test( t ) { var values; var i; @@ -102,7 +102,9 @@ tape( 'the function throws an error if provided a first argument which is not an function badValue( value ) { return function badValue() { - concat( value, -1 ); + concat( value, { + 'dim': -1 + }); }; } }); @@ -134,7 +136,7 @@ tape( 'the function throws an error if provided a first argument containing ndar } }); -tape( 'the function throws an error if provided a first argument containing ndarrays which do not promote to a common data type (dim)', function test( t ) { +tape( 'the function throws an error if provided a first argument containing ndarrays which do not promote to a common data type (options)', function test( t ) { var values; var i; @@ -156,7 +158,9 @@ tape( 'the function throws an error if provided a first argument containing ndar function badValue( value ) { return function badValue() { - concat( value, -1 ); + concat( value, { + 'dim': -1 + }); }; } }); @@ -188,7 +192,7 @@ tape( 'the function throws an error if provided a first argument containing ndar } }); -tape( 'the function throws an error if provided a first argument containing ndarrays which are not broadcast compatible (dim)', function test( t ) { +tape( 'the function throws an error if provided a first argument containing ndarrays which are not broadcast compatible (options)', function test( t ) { var values; var i; @@ -210,12 +214,47 @@ tape( 'the function throws an error if provided a first argument containing ndar function badValue( value ) { return function badValue() { - concat( value, -1 ); + concat( value, { + 'dim': -1 + }); }; } }); -tape( 'the function throws an error if provided a second argument which is not a negative integer', function test( t ) { +tape( 'the function throws an error if provided an options argument which is not an object', 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() { + concat( [ x, y ], value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument with an invalid `dim` property', function test( t ) { var values; var x; var y; @@ -235,8 +274,8 @@ tape( 'the function throws an error if provided a second argument which is not a false, null, void 0, - [], {}, + [], function noop() {} ]; @@ -247,7 +286,10 @@ tape( 'the function throws an error if provided a second argument which is not a function badValue( value ) { return function badValue() { - concat( [ x, y ], value ); + var opts = { + 'dim': value + }; + concat( [ x, y ], opts ); }; } }); @@ -285,7 +327,9 @@ tape( 'the function concatenates ndarrays along a specified dimension', function ybuf = new Float64Array( [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ] ); y = new ndarray( 'float64', ybuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); - out = concat( [ x, y ], -1 ); + out = concat( [ x, y ], { + 'dim': -1 + }); actual = ndarray2array( out ); expected = [ @@ -303,7 +347,9 @@ tape( 'the function concatenates ndarrays along a specified dimension', function ybuf = new Float64Array( [ 5.0, 6.0, 7.0, 8.0 ] ); y = new ndarray( 'float64', ybuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - out = concat( [ x, y ], -2 ); + out = concat( [ x, y ], { + 'dim': -2 + }); actual = ndarray2array( out ); expected = [ @@ -320,7 +366,9 @@ tape( 'the function concatenates ndarrays along a specified dimension', function xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); x = new ndarray( 'float64', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - out = concat( [ x ], -1 ); + out = concat( [ x ], { + 'dim': -1 + }); actual = ndarray2array( out ); expected = [ @@ -381,7 +429,9 @@ tape( 'the function concatenates ndarrays along a specified dimension (type prom ybuf = new Int32Array( [ 5, 6, 7, 8 ] ); y = new ndarray( 'int32', ybuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - out = concat( [ x, y ], -1 ); + out = concat( [ x, y ], { + 'dim': -1 + }); actual = ndarray2array( out ); expected = [ @@ -411,7 +461,9 @@ tape( 'the function concatenates ndarray along a specified dimension (broadcasti ybuf = new Float64Array( [ 3.0, 4.0, 5.0, 6.0 ] ); y = new ndarray( 'float64', ybuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - out = concat( [ x, y ], -1 ); + out = concat( [ x, y ], { + 'dim': -1 + }); actual = ndarray2array( out ); expected = [ [ 1.0, 2.0, 3.0, 4.0 ], @@ -445,7 +497,9 @@ tape( 'the function concatenates ndarrays along a specified dimension (ndims=1)' t.deepEqual( getShape( out ), [ 5 ], 'returns expected value' ); t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); - out = concat( [ x, y ], -1 ); + out = concat( [ x, y ], { + 'dim': -1 + }); expected = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; t.strictEqual( resolveStr( getDType( out ) ), 'float64', 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/ndarray/concat/test/test.validate.js b/lib/node_modules/@stdlib/ndarray/concat/test/test.validate.js new file mode 100644 index 000000000000..69e4081aa2c7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/concat/test/test.validate.js @@ -0,0 +1,130 @@ +/** +* @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 validate = require( './../lib/validate.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof validate, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an error if not provided an options object', function test( t ) { + var values; + var err; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + err = validate( {}, values[i] ); + t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); + } + t.end(); +}); + +tape( 'the function returns an error if provided a `dim` option which is not a negative integer', function test( t ) { + var values; + var err; + var i; + + values = [ + '5', + 5, + 3.14, + -3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + err = validate( {}, { + 'dim': values[i] + }); + t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); + } + t.end(); +}); + +tape( 'the function returns `null` if all options are valid', function test( t ) { + var expected; + var options; + var opts; + var err; + + options = { + 'dim': -2 + }; + opts = {}; + + expected = { + 'dim': -2 + }; + + err = validate( opts, options ); + + t.strictEqual( err, null, 'returns expected value' ); + t.deepEqual( opts, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function ignores unrecognized options', function test( t ) { + var options; + var opts; + var err; + + options = { + 'beep': 'boop', + 'foo': 5, + 'bar': {} + }; + + opts = {}; + + err = validate( opts, options ); + + t.strictEqual( err, null, 'returns expected value' ); + t.deepEqual( opts, {}, 'returns expected value' ); + + t.end(); +});