diff --git a/lib/node_modules/@stdlib/blas/ext/join/README.md b/lib/node_modules/@stdlib/blas/ext/join/README.md new file mode 100644 index 000000000000..d9320fcfec7f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/README.md @@ -0,0 +1,211 @@ + + +# join + +> Return an [ndarray][@stdlib/ndarray/ctor] created by joining elements using a separator along one or more [ndarray][@stdlib/ndarray/ctor] dimensions. + +
+ +## Usage + +```javascript +var join = require( '@stdlib/blas/ext/join' ); +``` + +#### join( x\[, options] ) + +Returns an [ndarray][@stdlib/ndarray/ctor] created by joining elements using a separator along one or more [ndarray][@stdlib/ndarray/ctor] dimensions. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +// Create an input ndarray: +var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +// returns + +// Perform operation: +var out = join( x ); +// returns [ '1,2,3,4,5,6' ] +``` + +The function has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. +- **options**: function options (_optional_). + +The function accepts the following options: + +- **sep**: separator. May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having a "generic" [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor] separator value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] separator value must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. Default: `,`. +- **dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. +- **keepdims**: boolean indicating whether the reduced dimensions should be included in the returned [ndarray][@stdlib/ndarray/ctor] as singleton dimensions. Default: `false`. + +By default, the function joins [ndarray][@stdlib/ndarray/ctor] elements by using `,` as a separator. To perform the operation with a different separator, provide a `sep` option. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + +var out = join( x, { + 'sep': '|' +}); +// returns [ '1|2|3|4|5|6' ] +``` + +By default, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. To perform the operation over specific dimensions, provide a `dims` option. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); + +var out = join( x, { + 'dims': [ 0 ] +}); +// returns [ '1,3', '2,4' ] + +out = join( x, { + 'dims': [ 1 ] +}); +// returns [ '1,2', '3,4' ] + +out = join( x, { + 'dims': [ 0, 1 ] +}); +// returns [ '1,2,3,4' ] +``` + +By default, the function excludes reduced dimensions from the output [ndarray][@stdlib/ndarray/ctor]. To include the reduced dimensions as singleton dimensions, set the `keepdims` option to `true`. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); + +var opts = { + 'dims': [ 0 ], + 'keepdims': true +}; + +var out = join( x, opts ); +// returns [ [ '1,3', '2,4' ] ] +``` + +#### join.assign( x, out\[, options] ) + +Joins elements of an input [ndarray][@stdlib/ndarray/ctor] using a separator along one or more [ndarray][@stdlib/ndarray/ctor] dimensions and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor]. + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-ndarray' ); + +var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); +var y = scalar2ndarray( '', { + 'dtype': 'generic' +}); + +var out = join.assign( x, y ); +// returns [ '1,2,3,4' ] + +var bool = ( out === y ); +// returns true +``` + +The method has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. +- **out**: output [ndarray][@stdlib/ndarray/ctor]. +- **options**: function options (_optional_). + +The method accepts the following options: + +- **sep**: separator. May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having a "generic" [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor] separator value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] separator value must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. Default: `,`. +- **dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. + +
+ + + +
+ +## Notes + +- Setting the `keepdims` option to `true` can be useful when wanting to ensure that the output [ndarray][@stdlib/ndarray/ctor] is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with ndarrays having the same shape as the input [ndarray][@stdlib/ndarray/ctor]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var join = require( '@stdlib/blas/ext/join' ); + +// Generate an array of random numbers: +var xbuf = discreteUniform( 10, 0, 20, { + 'dtype': 'float64' +}); + +// Wrap in an ndarray: +var x = new ndarray( 'float64', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +// Perform operation: +var out = join( x, { + 'dims': [ -1 ] +}); + +// Print the results: +console.log( ndarray2array( out ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/join/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/blas/ext/join/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..d1e2db378dbd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/benchmark/benchmark.assign.js @@ -0,0 +1,114 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var empty = require( '@stdlib/ndarray/empty' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var join = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var out; + var x; + + x = uniform( len, -50.0, 50.0, options ); + x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' ); + + out = empty( [], { + 'dtype': 'generic' + }); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var o; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = join.assign( x, out ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( o.get() ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:assign:dtype=%s,len=%d', pkg, options.dtype, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/join/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/join/benchmark/benchmark.js new file mode 100644 index 000000000000..11dacf36bbb2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/benchmark/benchmark.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var join = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -50.0, 50.0, options ); + x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var o; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = join( x ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( o.get() ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:dtype=%s,len=%d', pkg, options.dtype, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/join/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/join/docs/repl.txt new file mode 100644 index 000000000000..214f3ac9e379 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/docs/repl.txt @@ -0,0 +1,90 @@ + +{{alias}}( x[, options] ) + Returns an ndarray created by joining elements using a separator along one + or more ndarray dimensions. + + Parameters + ---------- + x: ndarray + Input array. + + options: Object (optional) + Function options. + + options.sep: ndarray|any + Separator. May be either a scalar value or an ndarray. If provided an + ndarray, the value must have a shape which is broadcast compatible with + the complement of the shape defined by `options.dims`. For example, + given the input shape [2, 3, 4] and `options.dims=[0]`, an ndarray + separator value must have a shape which is broadcast compatible with the + shape [3, 4]. Similarly, when performing the operation over all elements + in a provided input ndarray, an ndarray separator value must be a zero- + dimensional ndarray. Default: ','. + + options.dims: Array (optional) + List of dimensions over which to perform operation. If not provided, the + function performs the operation over all elements in a provided input + ndarray. + + options.keepdims: boolean (optional) + Boolean indicating whether the reduced dimensions should be included in + the returned ndarray as singleton dimensions. Default: false. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var y = {{alias}}( x ) + [ '1,2,3,4' ] + + +{{alias}}.assign( x, out[, options] ) + Joins elements of an input ndarray using a separator along one or more + ndarray dimensions and assigns results to a provided output ndarray. + + Parameters + ---------- + x: ndarray + Input array. + + out: ndarray + Output array. + + options: Object (optional) + Function options. + + options.sep: ndarray|any + Separator. May be either a scalar value or an ndarray. If provided an + ndarray, the value must have a shape which is broadcast compatible with + the complement of the shape defined by `options.dims`. For example, + given the input shape [2, 3, 4] and `options.dims=[0]`, an ndarray + separator value must have a shape which is broadcast compatible with the + shape [3, 4]. Similarly, when performing the operation over all elements + in a provided input ndarray, an ndarray separator value must be a zero- + dimensional ndarray. Default: ','. + + options.dims: Array (optional) + List of dimensions over which to perform operation. If not provided, the + function performs the operation over all elements in a provided input + ndarray. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var out = {{alias:@stdlib/ndarray/from-scalar}}( '' ); + > var y = {{alias}}.assign( x, out ) + [ '1,2,3,4' ] + > var bool = ( out === y ) + true + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/join/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/join/docs/types/index.d.ts new file mode 100644 index 000000000000..13f0e87a7309 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/docs/types/index.d.ts @@ -0,0 +1,153 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { genericndarray, typedndarray } from '@stdlib/types/ndarray'; + +/** +* Input array. +*/ +type InputArray = typedndarray; + +/** +* Output array. +*/ +type OutputArray = genericndarray; + +/** +* Interface defining "base" options. +*/ +interface BaseOptions { + /** + * List of dimensions over which to perform operation. + */ + dims?: ArrayLike; +} + +/** +* Interface defining options. +*/ +interface Options extends BaseOptions { + /** + * Separator. Default: `,`. + */ + sep?: T | genericndarray; + + /** + * Boolean indicating whether the reduced dimensions should be included in the returned array as singleton dimensions. Default: `false`. + */ + keepdims?: boolean; +} + + +/** +* Interface describing `join`. +*/ +interface Join { + /** + * Returns an ndarray created by joining elements using a separator along one or more ndarray dimensions. + * + * @param x - input ndarray + * @param options - function options + * @param options.sep - separator + * @param options.dims - list of dimensions over which to perform operation + * @param options.keepdims - boolean indicating whether the reduced dimensions should be included in the returned ndarray as singleton dimensions + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ 1.0, 2.0, 3.0 ] ); + * + * var y = join( x ); + * // returns [ '1,2,3' ] + */ + ( x: InputArray, options?: Options ): OutputArray; + + /** + * Joins elements of an input ndarray using a separator along one or more ndarray dimensions and assigns results to a provided output ndarray. + * + * @param x - input ndarray + * @param separator - separator + * @param out - output ndarray + * @param options - function options + * @param options.sep - separator + * @param options.dims - list of dimensions over which to perform operation + * @returns output ndarray + * + * @example + * var empty = require( '@stdlib/ndarray/empty' ); + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ 1.0, 2.0, 3.0 ], { + * 'dtype': 'generic' + * }); + * var y = empty( [], { + * 'dtype': 'generic' + * }); + * + * var out = join.assign( x, y ); + * // returns [ '1,2,3' ] + * + * var bool = ( out === y ); + * // returns true + */ + assign = typedndarray>( x: InputArray, out: V, options?: Options ): V; +} + +/** +* Returns an ndarray created by joining elements using a separator along one or more ndarray dimensions. +* +* @param x - input ndarray +* @param options - function options +* @returns output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ 1.0, 2.0, 3.0 ] ); +* +* var y = join( x ); +* // returns [ '1,2,3' ] +* +* @example +* var empty = require( '@stdlib/ndarray/empty' ); +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ 1.0, 2.0, 3.0 ], { +* 'dtype': 'generic' +* }); +* var y = empty( [], { +* 'dtype': 'generic' +* }); +* +* var out = join.assign( x, y ); +* // returns [ '1,2,3' ] +* +* var bool = ( out === y ); +* // returns true +*/ +declare const join: Join; + + +// EXPORTS // + +export = join; diff --git a/lib/node_modules/@stdlib/blas/ext/join/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/join/docs/types/test.ts new file mode 100644 index 000000000000..c032e30879e2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/docs/types/test.ts @@ -0,0 +1,210 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +import join = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + join( x ); // $ExpectType OutputArray + join( x, {} ); // $ExpectType OutputArray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + join( '5' ); // $ExpectError + join( 5 ); // $ExpectError + join( true ); // $ExpectError + join( false ); // $ExpectError + join( null ); // $ExpectError + join( void 0 ); // $ExpectError + join( {} ); // $ExpectError + join( ( x: number ): number => x ); // $ExpectError + + join( '5', {} ); // $ExpectError + join( 5, {} ); // $ExpectError + join( true, {} ); // $ExpectError + join( false, {} ); // $ExpectError + join( null, {} ); // $ExpectError + join( void 0, {} ); // $ExpectError + join( {}, {} ); // $ExpectError + join( ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an options argument which is not an object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + join( x, '5' ); // $ExpectError + join( x, true ); // $ExpectError + join( x, false ); // $ExpectError + join( x, [] ); // $ExpectError + join( x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dims` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + join( x, { 'dims': '5' } ); // $ExpectError + join( x, { 'dims': 5 } ); // $ExpectError + join( x, { 'dims': true } ); // $ExpectError + join( x, { 'dims': false } ); // $ExpectError + join( x, { 'dims': null } ); // $ExpectError + join( x, { 'dims': {} } ); // $ExpectError + join( x, { 'dims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `keepdims` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + join( x, { 'keepdims': '5' } ); // $ExpectError + join( x, { 'keepdims': 5 } ); // $ExpectError + join( x, { 'keepdims': null } ); // $ExpectError + join( x, { 'keepdims': {} } ); // $ExpectError + join( x, { 'keepdims': ( 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 ], { + 'dtype': 'float64' + }); + + join(); // $ExpectError + join( x, {}, {} ); // $ExpectError +} + +// Attached to the function is an `assign` method which returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = scalar2ndarray( '', { + 'dtype': 'generic' + }); + + join.assign( x, y ); // $ExpectType genericndarray + join.assign( x, y, {} ); // $ExpectType genericndarray +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not an ndarray... +{ + const y = scalar2ndarray( '' ); + + join.assign( '5', y ); // $ExpectError + join.assign( 5, y ); // $ExpectError + join.assign( true, y ); // $ExpectError + join.assign( false, y ); // $ExpectError + join.assign( null, y ); // $ExpectError + join.assign( void 0, y ); // $ExpectError + join.assign( {}, y ); // $ExpectError + join.assign( ( x: number ): number => x, y ); // $ExpectError + + join.assign( '5', y, {} ); // $ExpectError + join.assign( 5, y, {} ); // $ExpectError + join.assign( true, y, {} ); // $ExpectError + join.assign( false, y, {} ); // $ExpectError + join.assign( null, y, {} ); // $ExpectError + join.assign( void 0, y, {} ); // $ExpectError + join.assign( {}, y, {} ); // $ExpectError + join.assign( ( x: number ): number => x, y, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a output argument which is not an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + join.assign( x, '5' ); // $ExpectError + join.assign( x, 5 ); // $ExpectError + join.assign( x, true ); // $ExpectError + join.assign( x, false ); // $ExpectError + join.assign( x, null ); // $ExpectError + join.assign( x, void 0 ); // $ExpectError + join.assign( x, ( x: number ): number => x ); // $ExpectError + + join.assign( x, '5', {} ); // $ExpectError + join.assign( x, 5, {} ); // $ExpectError + join.assign( x, true, {} ); // $ExpectError + join.assign( x, false, {} ); // $ExpectError + join.assign( x, null, {} ); // $ExpectError + join.assign( x, void 0, {} ); // $ExpectError + join.assign( x, ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an options argument which is not an object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = scalar2ndarray( '' ); + + join.assign( x, y, '5' ); // $ExpectError + join.assign( x, y, true ); // $ExpectError + join.assign( x, y, false ); // $ExpectError + join.assign( x, y, null ); // $ExpectError + join.assign( x, y, [] ); // $ExpectError + join.assign( x, y, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an invalid `dims` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = scalar2ndarray( '' ); + + join.assign( x, y, { 'dims': '5' } ); // $ExpectError + join.assign( x, y, { 'dims': 5 } ); // $ExpectError + join.assign( x, y, { 'dims': true } ); // $ExpectError + join.assign( x, y, { 'dims': false } ); // $ExpectError + join.assign( x, y, { 'dims': null } ); // $ExpectError + join.assign( x, y, { 'dims': {} } ); // $ExpectError + join.assign( x, y, { 'dims': ( 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 ], { + 'dtype': 'float64' + }); + const y = scalar2ndarray( '' ); + + join.assign(); // $ExpectError + join.assign( x ); // $ExpectError + join.assign( x, y, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/join/examples/index.js b/lib/node_modules/@stdlib/blas/ext/join/examples/index.js new file mode 100644 index 000000000000..6c69582b04a3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/examples/index.js @@ -0,0 +1,41 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var join = require( './../lib' ); + +// Generate an array of random numbers: +var xbuf = discreteUniform( 10, 0, 20, { + 'dtype': 'float64' +}); + +// Wrap in an ndarray: +var x = new ndarray( 'float64', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +// Perform operation: +var out = join( x, { + 'dims': [ -1 ] +}); + +// Print the results: +console.log( ndarray2array( out ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/join/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/join/lib/assign.js new file mode 100644 index 000000000000..29feee4e31e7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/lib/assign.js @@ -0,0 +1,136 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); +var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' ); +var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ).assign; + + +// MAIN // + +/** +* Joins elements of an input ndarray using a separator along one or more ndarray dimensions and assigns the results to a provided output ndarray. +* +* @param {ndarrayLike} x - input ndarray +* @param {ndarrayLike} out - output ndarray +* @param {Options} [options] - function options +* @param {(ndarrayLike|*)} [options.sep=','] - separator +* @param {integer} [options.dims] - list of dimensions over which to perform operation +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} second argument must be an ndarray-like object +* @throws {TypeError} options argument must be an object +* @throws {RangeError} dimension indices must not exceed input ndarray bounds +* @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions +* @throws {Error} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 2, 3 ]; +* +* // Define the array strides: +* var strides = [ 3, 1 ]; +* +* // Define the index offset: +* var offset = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, shape, strides, offset, 'row-major' ); +* +* // Create an output ndarray: +* var y = scalar2ndarray( '', { +* 'dtype': 'generic' +* }); +* +* // Perform operation: +* var out = assign( x, y ); +* // returns [ '1,2,3,4,5,6' ] +* +* var bool = ( out === y ); +* // returns true +*/ +function assign( x, out, options ) { + var nargs; + var opts; + var sh; + var s; + + nargs = arguments.length; + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + } + if ( !isndarrayLike( out ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an ndarray-like object. Value: `%s`.', out ) ); + } + // Initialize the separator: + s = ','; + + // Initialize an options object: + opts = {}; + + if ( nargs > 2 ) { + if ( !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + // Resolve provided options... + if ( hasOwnProp( options, 'sep' ) ) { + s = options.sep; + } + if ( hasOwnProp( options, 'dims' ) ) { + opts.dims = options.dims; + } + } + // Broadcast the separator to match the shape of the non-reduced dimensions... + if ( isndarrayLike( s ) ) { + // When not provided `dims`, the operation is performed across all dimensions and `s` is assumed to be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `s` to match the shape of the non-core dimensions... + if ( hasOwnProp( opts, 'dims' ) ) { + s = maybeBroadcastArray( s, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len + } + } else { + if ( hasOwnProp( opts, 'dims' ) ) { + sh = nonCoreShape( getShape( x ), opts.dims ); + } else { + sh = []; + } + s = broadcastScalar( s, 'generic', sh, getOrder( x ) ); + } + return base( x, s, out, opts ); +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/blas/ext/join/lib/base.js b/lib/node_modules/@stdlib/blas/ext/join/lib/base.js new file mode 100644 index 000000000000..a8707e442fe9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/lib/base.js @@ -0,0 +1,100 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var dtypes = require( '@stdlib/ndarray/dtypes' ); +var gjoin = require( '@stdlib/blas/ext/base/ndarray/gjoin' ); +var factory = require( '@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-factory' ); + + +// VARIABLES // + +var idtypes0 = dtypes( 'all' ); // input ndarray +var idtypes1 = [ 'generic' ]; // separator ndarray +var odtypes = [ 'generic' ]; +var policies = { + 'output': 'same', // note: because we always return a "generic" ndarray, this policy is effectively ignored + 'casting': 'none' +}; +var table = { + 'default': gjoin +}; + + +// MAIN // + +/** +* Returns an ndarray created by joining elements using a separator along one or more ndarray dimensions. +* +* @private +* @name join +* @type {Function} +* @param {ndarrayLike} x - input ndarray +* @param {ndarrayLike} separator - separator +* @param {Options} [options] - function options +* @param {IntegerArray} [options.dims] - list of dimensions over which to perform operation +* @param {boolean} [options.keepdims=false] - boolean indicating whether the reduced dimensions should be included in the returned ndarray as singleton dimensions +* @param {*} [options.dtype] - output ndarray data type +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} second argument must be an ndarray-like object +* @throws {TypeError} options argument must be an object +* @throws {RangeError} dimension indices must not exceed input ndarray bounds +* @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions +* @throws {Error} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Create a separator ndarray: +* var separator = scalar2ndarray( ',', { +* 'dtype': 'generic' +* }); +* +* // Perform operation: +* var out = join( x, separator, { +* 'dtype': 'generic' +* }); +* // returns [ '1,2,3,4,5,6' ] +*/ +var join = factory( table, [ idtypes0, idtypes1 ], odtypes, policies ); + + +// EXPORTS // + +module.exports = join; diff --git a/lib/node_modules/@stdlib/blas/ext/join/lib/index.js b/lib/node_modules/@stdlib/blas/ext/join/lib/index.js new file mode 100644 index 000000000000..9befa4193b98 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/lib/index.js @@ -0,0 +1,67 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Return an ndarray created by joining elements using a separator along an ndarray dimension. +* +* @module @stdlib/blas/ext/join +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var join = require( '@stdlib/blas/ext/join' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 2, 3 ]; +* +* // Define the array strides: +* var sx = [ 3, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Perform operation: +* var out = join( x ); +* // returns [ '1,2,3,4,5,6' ] +*/ + +// 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/blas/ext/join/lib/main.js b/lib/node_modules/@stdlib/blas/ext/join/lib/main.js new file mode 100644 index 000000000000..421bdb3b57d7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/lib/main.js @@ -0,0 +1,129 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); +var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' ); +var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Returns an ndarray created by joining elements using a separator along an ndarray dimension. +* +* @param {ndarrayLike} x - input ndarray +* @param {Options} [options] - function options +* @param {(ndarrayLike|*)} [options.sep=','] - separator +* @param {integer} [options.dims] - list of dimensions over which to perform operation +* @param {boolean} [options.keepdims=false] - boolean indicating whether the reduced dimensions should be included in the returned ndarray as singleton dimensions +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} options argument must be an object +* @throws {RangeError} dimension indices must not exceed input ndarray bounds +* @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions +* @throws {Error} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 2, 3 ]; +* +* // Define the array strides: +* var sx = [ 3, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Perform operation: +* var out = join( x ); +* // returns [ '1,2,3,4,5,6' ] +*/ +function join( x, options ) { + var nargs; + var opts; + var sh; + var s; + + nargs = arguments.length; + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + } + // Initialize the separator: + s = ','; + + // Initialize an options object: + opts = { + 'dtype': 'generic', // default behavior is to always return a generic ndarray + 'keepdims': false + }; + + if ( nargs > 1 ) { + if ( !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + // Resolve provided options... + if ( hasOwnProp( options, 'sep' ) ) { + s = options.sep; + } + if ( hasOwnProp( options, 'dims' ) ) { + opts.dims = options.dims; + } + if ( hasOwnProp( options, 'keepdims' ) ) { + opts.keepdims = options.keepdims; + } + } + // Broadcast the separator to match the shape of the non-reduced dimensions... + if ( isndarrayLike( s ) ) { + // When not provided `dims`, the operation is performed across all dimensions and `s` is assumed to be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `s` to match the shape of the non-core dimensions... + if ( hasOwnProp( opts, 'dims' ) ) { + s = maybeBroadcastArray( s, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len + } + } else { + if ( hasOwnProp( opts, 'dims' ) ) { + sh = nonCoreShape( getShape( x ), opts.dims ); + } else { + sh = []; + } + s = broadcastScalar( s, 'generic', sh, getOrder( x ) ); + } + return base( x, s, opts ); +} + + +// EXPORTS // + +module.exports = join; diff --git a/lib/node_modules/@stdlib/blas/ext/join/package.json b/lib/node_modules/@stdlib/blas/ext/join/package.json new file mode 100644 index 000000000000..6aa24ac98368 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/blas/ext/join", + "version": "0.0.0", + "description": "Return an ndarray created by joining elements using a separator along one or more ndarray dimensions.", + "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", + "stdmath", + "mathematics", + "math", + "blas", + "extended", + "join", + "string", + "strided", + "array", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/join/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/join/test/test.assign.js new file mode 100644 index 000000000000..6dce0fe05e0e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/test/test.assign.js @@ -0,0 +1,564 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var empty = require( '@stdlib/ndarray/empty' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var join = require( './../lib' ).assign; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof join, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object', function test( t ) { + var values; + var i; + var y; + + y = empty( [], { + 'dtype': 'generic' + }); + + 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() { + join( value, y ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var opts; + var i; + var y; + + opts = { + 'dtype': 'generic' + }; + + y = empty( [], opts ); + + 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() { + join( value, y, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is a zero-dimensional ndarray', function test( t ) { + var values; + var opts; + var i; + var y; + + opts = { + 'dtype': 'generic' + }; + + y = empty( [], opts ); + + values = [ + scalar2ndarray( 10.0 ), + scalar2ndarray( -3.0 ), + scalar2ndarray( 0.0 ) + ]; + 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() { + join( value, y, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an output argument which is not an ndarray-like object', function test( t ) { + var values; + var opts; + var i; + var x; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + + 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() { + join( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided an output argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var opts; + var i; + var x; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + + 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() { + join( x, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a separator which is not broadcast-compatible with the first argument', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + y = empty( [], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + 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() { + join( x, y, { + 'separator': value + }); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + y = empty( [], opts ); + + values = [ + '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() { + join( x, y, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `dim` option which is not an integer', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + y = empty( [], opts ); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + 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() { + join( x, y, { + 'dim': value + }); + }; + } +}); + +tape( 'the function joins elements of an input ndarray using a separator along an ndarray dimensions and assigns results to an output ndarray (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + out = empty( [ 2 ], { + 'dtype': 'generic' + }); + + actual = join( x, out ); + expected = [ '1,2', '3,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function joins elements of an input ndarray using a separator along an ndarray dimensions and assigns results to an output ndarray (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + out = empty( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = join( x, out ); + expected = [ '1,3', '2,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the operation dimension (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + out = empty( [ 2 ], { + 'dtype': 'generic' + }); + + actual = join( x, out, { + 'dim': 0 + }); + expected = [ '1,3', '2,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + out = empty( [ 2 ], { + 'dtype': 'generic' + }); + + actual = join( x, out, { + 'dim': 1 + }); + expected = [ '1,2', '3,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the operation dimension (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + out = empty( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = join( x, out, { + 'dim': 0 + }); + expected = [ '1,3', '2,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + out = empty( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = join( x, out, { + 'dim': 1 + }); + expected = [ '1,2', '3,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a custom separator (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + out = empty( [ 2 ], { + 'dtype': 'generic' + }); + + actual = join( x, out, { + 'dim': 0, + 'separator': '|' + }); + expected = [ '1|3', '2|4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + out = empty( [ 2 ], { + 'dtype': 'generic' + }); + + actual = join( x, out, { + 'dim': 1, + 'separator': '|' + }); + expected = [ '1|2', '3|4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a custom separator (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + out = empty( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = join( x, out, { + 'dim': 0, + 'separator': '|' + }); + expected = [ '1|3', '2|4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + out = empty( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = join( x, out, { + 'dim': 1, + 'separator': '|' + }); + expected = [ '1|2', '3|4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/join/test/test.js b/lib/node_modules/@stdlib/blas/ext/join/test/test.js new file mode 100644 index 000000000000..8970ba39e74a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/test/test.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isMethod = require( '@stdlib/assert/is-method' ); +var join = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof join, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( join, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/join/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/join/test/test.main.js new file mode 100644 index 000000000000..4606fae9ae06 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/test/test.main.js @@ -0,0 +1,457 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var join = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof join, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-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() { + join( value ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options)', 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() { + join( value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is a zero-dimensional ndarray', function test( t ) { + var values; + var i; + + values = [ + scalar2ndarray( 10.0 ), + scalar2ndarray( -3.0 ), + scalar2ndarray( 0.0 ) + ]; + 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() { + join( value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a separator which is not broadcast-compatible with the first argument', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + { + 'separator': zeros( [ 4 ], opts ) + }, + { + 'separator': zeros( [ 2, 2, 2 ], opts ) + }, + { + 'separator': zeros( [ 0 ], opts ) + } + ]; + 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() { + join( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '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() { + join( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `dim` option which is not an integer', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + 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() { + join( x, { + 'dim': value + }); + }; + } +}); + +tape( 'the function returns an ndarray created by joining elements of an input ndarray (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = join( x ); + expected = [ '1,2', '3,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an ndarray created by joining elements of an input ndarray (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = join( x ); + expected = [ '1,3', '2,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the operation dimension (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = join( x, { + 'dim': 0 + }); + expected = [ '1,3', '2,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = join( x, { + 'dim': 1 + }); + expected = [ '1,2', '3,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the operation dimension (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + + actual = join( x, { + 'dim': 0 + }); + expected = [ '1,3', '2,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + + actual = join( x, { + 'dim': 1 + }); + expected = [ '1,2', '3,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the `keepdims` option (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = join( x, { + 'keepdims': true + }); + expected = [ [ '1,2' ], [ '3,2' ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 1 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the `keepdims` option (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = join( x, { + 'keepdims': true + }); + expected = [ [ '1,3' ], [ '2,2' ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 1 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a custom separator (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = join( x, { + 'dim': 0, + 'separator': '|' + }); + expected = [ '1|3', '2|4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = join( x, { + 'dim': 1, + 'separator': '|' + }); + expected = [ '1|2', '3|4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a custom separator (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + + actual = join( x, { + 'dim': 0, + 'separator': '|' + }); + expected = [ '1|3', '2|4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + + actual = join( x, { + 'dim': 1, + 'separator': '|' + }); + expected = [ '1|2', '3|4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +});