diff --git a/lib/node_modules/@stdlib/blas/ext/join-between/README.md b/lib/node_modules/@stdlib/blas/ext/join-between/README.md new file mode 100644 index 000000000000..e04ba389fed5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join-between/README.md @@ -0,0 +1,213 @@ + + +# joinBetween + +> Return an [ndarray][@stdlib/ndarray/ctor] created by joining elements using specified separators for each pair of consecutive elements along one or more [ndarray][@stdlib/ndarray/ctor] dimensions. + +
+ +## Usage + +```javascript +var joinBetween = require( '@stdlib/blas/ext/join-between' ); +``` + +#### joinBetween( x\[, options] ) + +Returns an [ndarray][@stdlib/ndarray/ctor] created by joining elements using specified separators for each pair of consecutive elements 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 [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] + +// Perform operation: +var out = joinBetween( 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: + +- **prefix**: prefix to prepend to each joined string. Default: `''`. +- **suffix**: suffix to append to each joined string. Default: `''`. +- **separators**: separators. Must be an array-like object. When provided an array containing a single element, the same separator is used between all consecutive pairs of elements. When containing multiple elements, each element specifies the separator to use between consecutive pairs, and the number of elements must equal one less than the number of elements along the reduced dimensions. 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 between all consecutive pairs of elements. To perform the operation with a different separator, provide a `separators` 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 = joinBetween( x, { + 'separators': [ '|' ] +}); +// returns [ '1|2|3|4|5|6' ] +``` + +To specify a prefix and suffix to prepend and append to each joined string, provide `prefix` and `suffix` options. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +// returns [ 1, 2, 3, 4, 5, 6 ] + +var out = joinBetween( x, { + 'prefix': '[ ', + 'suffix': ' ]', + 'separators': [ ', ' ] +}); +// 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 ] ] ); +// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] + +var out = joinBetween( x, { + 'dims': [ 0 ] +}); +// returns [ '1,3', '2,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 ] ] ); +// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] + +var out = joinBetween( x, { + 'dims': [ 0 ], + 'keepdims': true +}); +// returns [ [ '1,3', '2,4' ] ] +``` + +#### joinBetween.assign( x, out\[, options] ) + +Joins elements of an input [ndarray][@stdlib/ndarray/ctor] using specified separators for each pair of consecutive elements 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-scalar' ); + +var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); +var y = scalar2ndarray( '', { + 'dtype': 'generic' +}); + +var out = joinBetween.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: + +- **prefix**: prefix to prepend to each joined string. Default: `''`. +- **suffix**: suffix to append to each joined string. Default: `''`. +- **separators**: separators. Must be an array-like object. When provided an array containing a single element, the same separator is used between all consecutive pairs of elements. When containing multiple elements, each element specifies the separator to use between consecutive pairs, and the number of elements must equal one less than the number of elements along the reduced dimensions. 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]. +- When providing an array containing multiple separators, each element specifies the separator to use between consecutive pairs. The same separators are used for every complement position when reducing specific dimensions. + +
+ + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var joinBetween = require( '@stdlib/blas/ext/join-between' ); + +var x = uniform( [ 5, 2 ], 0.0, 20.0 ); +console.log( ndarray2array( x ) ); + +var out = joinBetween( x, { + 'dims': [ -1 ], + 'prefix': '[ ', + 'suffix': ' ]', + 'separators': [ ', ' ] +}); +console.log( ndarray2array( out ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/join-between/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/blas/ext/join-between/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..1d39fa94bbba --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join-between/benchmark/benchmark.assign.js @@ -0,0 +1,114 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var 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 joinBetween = 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 = joinBetween.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-between/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/join-between/benchmark/benchmark.js new file mode 100644 index 000000000000..1a52b2ec8464 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join-between/benchmark/benchmark.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'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 joinBetween = 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 = joinBetween( 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-between/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/join-between/docs/repl.txt new file mode 100644 index 000000000000..5c0b9856fe50 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join-between/docs/repl.txt @@ -0,0 +1,99 @@ + +{{alias}}( x[, options] ) + Returns an ndarray created by joining elements using specified separators + for each pair of consecutive elements along one or more ndarray dimensions. + + Parameters + ---------- + x: ndarray + Input array. + + options: Object (optional) + Function options. + + options.prefix: string (optional) + Prefix to prepend to each joined string. Default: ''. + + options.suffix: string (optional) + Suffix to append to each joined string. Default: ''. + + options.separators: ArrayLikeObject (optional) + Separators. When provided an array containing a single element, the + same separator is used between all consecutive pairs of elements. When + containing multiple elements, each element specifies the separator to + use between consecutive pairs, and the number of elements must equal + one less than the number of elements along the reduced dimensions. + 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, 5.0, 6.0 ] ); + > var y = {{alias}}( x ) + [ '1,2,3,4,5,6' ] + + +{{alias}}.assign( x, out[, options] ) + Joins elements of an input ndarray using specified separators for each pair + of consecutive elements 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.prefix: string (optional) + Prefix to prepend to each joined string. Default: ''. + + options.suffix: string (optional) + Suffix to append to each joined string. Default: ''. + + options.separators: ArrayLikeObject (optional) + Separators. When provided an array containing a single element, the + same separator is used between all consecutive pairs of elements. When + containing multiple elements, each element specifies the separator to + use between consecutive pairs, and the number of elements must equal + one less than the number of elements along the reduced dimensions. + 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, 5.0, 6.0 ] ); + > var out = {{alias:@stdlib/ndarray/from-scalar}}( '' ); + > var y = {{alias}}.assign( x, out ) + [ '1,2,3,4,5,6' ] + > var bool = ( out === y ) + true + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/join-between/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/join-between/docs/types/index.d.ts new file mode 100644 index 000000000000..d21152bd0e07 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join-between/docs/types/index.d.ts @@ -0,0 +1,168 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { 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 { + /** + * Prefix to prepend to each joined string. Default: `''`. + */ + prefix?: string; + + /** + * Suffix to append to each joined string. Default: `''`. + */ + suffix?: string; + + /** + * Separators. Default: `[ ',' ]`. + */ + separators?: ArrayLike; + + /** + * Boolean indicating whether the reduced dimensions should be included in the returned array as singleton dimensions. Default: `false`. + */ + keepdims?: boolean; +} + + +/** +* Interface describing `joinBetween`. +*/ +interface JoinBetween { + /** + * Returns an ndarray created by joining elements using specified separators for each pair of consecutive elements along one or more ndarray dimensions. + * + * @param x - input ndarray + * @param options - function options + * @param options.prefix - prefix to prepend to each joined string + * @param options.suffix - suffix to append to each joined string + * @param options.separators - separators + * @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, 4.0, 5.0, 6.0 ] ); + * // returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] + * + * var y = joinBetween( x ); + * // returns [ '1,2,3,4,5,6' ] + */ + ( x: InputArray, options?: Options ): OutputArray; + + /** + * Joins elements of an input ndarray using specified separators for each pair of consecutive elements along one or more ndarray dimensions and assigns results to a provided output ndarray. + * + * @param x - input ndarray + * @param out - output ndarray + * @param options - function options + * @param options.prefix - prefix to prepend to each joined string + * @param options.suffix - suffix to append to each joined string + * @param options.separators - separators + * @param options.dims - list of dimensions over which to perform operation + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); + * + * var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + * // returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] + * + * var y = scalar2ndarray( '', { + * 'dtype': 'generic' + * }); + * + * var out = joinBetween.assign( x, y ); + * // returns [ '1,2,3,4,5,6' ] + * + * var bool = ( out === y ); + * // returns true + */ + assign = typedndarray>( x: InputArray, out: V, options?: Options ): V; +} + +/** +* Returns an ndarray created by joining elements using specified separators for each pair of consecutive elements 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, 4.0, 5.0, 6.0 ] ); +* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] +* +* var y = joinBetween( x ); +* // returns [ '1,2,3,4,5,6' ] +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] +* +* var y = scalar2ndarray( '', { +* 'dtype': 'generic' +* }); +* +* var out = joinBetween.assign( x, y ); +* // returns [ '1,2,3,4,5,6' ] +* +* var bool = ( out === y ); +* // returns true +*/ +declare const joinBetween: JoinBetween; + + +// EXPORTS // + +export = joinBetween; diff --git a/lib/node_modules/@stdlib/blas/ext/join-between/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/join-between/docs/types/test.ts new file mode 100644 index 000000000000..7765515cf942 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join-between/docs/types/test.ts @@ -0,0 +1,297 @@ +/* +* @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. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +import joinBetween = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + joinBetween( x ); // $ExpectType OutputArray + joinBetween( x, {} ); // $ExpectType OutputArray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + joinBetween( '5' ); // $ExpectError + joinBetween( 5 ); // $ExpectError + joinBetween( true ); // $ExpectError + joinBetween( false ); // $ExpectError + joinBetween( null ); // $ExpectError + joinBetween( void 0 ); // $ExpectError + joinBetween( {} ); // $ExpectError + joinBetween( ( x: number ): number => x ); // $ExpectError + + joinBetween( '5', {} ); // $ExpectError + joinBetween( 5, {} ); // $ExpectError + joinBetween( true, {} ); // $ExpectError + joinBetween( false, {} ); // $ExpectError + joinBetween( null, {} ); // $ExpectError + joinBetween( void 0, {} ); // $ExpectError + joinBetween( {}, {} ); // $ExpectError + joinBetween( ( 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' + }); + + joinBetween( x, '5' ); // $ExpectError + joinBetween( x, true ); // $ExpectError + joinBetween( x, false ); // $ExpectError + joinBetween( x, [] ); // $ExpectError + joinBetween( 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' + }); + + joinBetween( x, { 'dims': '5' } ); // $ExpectError + joinBetween( x, { 'dims': 5 } ); // $ExpectError + joinBetween( x, { 'dims': true } ); // $ExpectError + joinBetween( x, { 'dims': false } ); // $ExpectError + joinBetween( x, { 'dims': null } ); // $ExpectError + joinBetween( x, { 'dims': {} } ); // $ExpectError + joinBetween( 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' + }); + + joinBetween( x, { 'keepdims': '5' } ); // $ExpectError + joinBetween( x, { 'keepdims': 5 } ); // $ExpectError + joinBetween( x, { 'keepdims': null } ); // $ExpectError + joinBetween( x, { 'keepdims': {} } ); // $ExpectError + joinBetween( x, { 'keepdims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `prefix` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + joinBetween( x, { 'prefix': 5 } ); // $ExpectError + joinBetween( x, { 'prefix': true } ); // $ExpectError + joinBetween( x, { 'prefix': false } ); // $ExpectError + joinBetween( x, { 'prefix': null } ); // $ExpectError + joinBetween( x, { 'prefix': {} } ); // $ExpectError + joinBetween( x, { 'prefix': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `suffix` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + joinBetween( x, { 'suffix': 5 } ); // $ExpectError + joinBetween( x, { 'suffix': true } ); // $ExpectError + joinBetween( x, { 'suffix': false } ); // $ExpectError + joinBetween( x, { 'suffix': null } ); // $ExpectError + joinBetween( x, { 'suffix': {} } ); // $ExpectError + joinBetween( x, { 'suffix': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `separators` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + joinBetween( x, { 'separators': 5 } ); // $ExpectError + joinBetween( x, { 'separators': true } ); // $ExpectError + joinBetween( x, { 'separators': false } ); // $ExpectError + joinBetween( x, { 'separators': null } ); // $ExpectError + joinBetween( x, { 'separators': {} } ); // $ExpectError + joinBetween( x, { 'separators': ( 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' + }); + + joinBetween(); // $ExpectError + joinBetween( 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' + }); + + joinBetween.assign( x, y ); // $ExpectType genericndarray + joinBetween.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( '' ); + + joinBetween.assign( '5', y ); // $ExpectError + joinBetween.assign( 5, y ); // $ExpectError + joinBetween.assign( true, y ); // $ExpectError + joinBetween.assign( false, y ); // $ExpectError + joinBetween.assign( null, y ); // $ExpectError + joinBetween.assign( void 0, y ); // $ExpectError + joinBetween.assign( {}, y ); // $ExpectError + joinBetween.assign( ( x: number ): number => x, y ); // $ExpectError + + joinBetween.assign( '5', y, {} ); // $ExpectError + joinBetween.assign( 5, y, {} ); // $ExpectError + joinBetween.assign( true, y, {} ); // $ExpectError + joinBetween.assign( false, y, {} ); // $ExpectError + joinBetween.assign( null, y, {} ); // $ExpectError + joinBetween.assign( void 0, y, {} ); // $ExpectError + joinBetween.assign( {}, y, {} ); // $ExpectError + joinBetween.assign( ( x: number ): number => x, y, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an output argument which is not an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + joinBetween.assign( x, '5' ); // $ExpectError + joinBetween.assign( x, 5 ); // $ExpectError + joinBetween.assign( x, true ); // $ExpectError + joinBetween.assign( x, false ); // $ExpectError + joinBetween.assign( x, null ); // $ExpectError + joinBetween.assign( x, void 0 ); // $ExpectError + joinBetween.assign( x, ( x: number ): number => x ); // $ExpectError + + joinBetween.assign( x, '5', {} ); // $ExpectError + joinBetween.assign( x, 5, {} ); // $ExpectError + joinBetween.assign( x, true, {} ); // $ExpectError + joinBetween.assign( x, false, {} ); // $ExpectError + joinBetween.assign( x, null, {} ); // $ExpectError + joinBetween.assign( x, void 0, {} ); // $ExpectError + joinBetween.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( '' ); + + joinBetween.assign( x, y, '5' ); // $ExpectError + joinBetween.assign( x, y, true ); // $ExpectError + joinBetween.assign( x, y, false ); // $ExpectError + joinBetween.assign( x, y, null ); // $ExpectError + joinBetween.assign( x, y, [] ); // $ExpectError + joinBetween.assign( x, y, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an invalid `prefix` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = scalar2ndarray( '' ); + + joinBetween.assign( x, y, { 'prefix': 5 } ); // $ExpectError + joinBetween.assign( x, y, { 'prefix': true } ); // $ExpectError + joinBetween.assign( x, y, { 'prefix': false } ); // $ExpectError + joinBetween.assign( x, y, { 'prefix': null } ); // $ExpectError + joinBetween.assign( x, y, { 'prefix': {} } ); // $ExpectError + joinBetween.assign( x, y, { 'prefix': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an invalid `suffix` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = scalar2ndarray( '' ); + + joinBetween.assign( x, y, { 'suffix': 5 } ); // $ExpectError + joinBetween.assign( x, y, { 'suffix': true } ); // $ExpectError + joinBetween.assign( x, y, { 'suffix': false } ); // $ExpectError + joinBetween.assign( x, y, { 'suffix': null } ); // $ExpectError + joinBetween.assign( x, y, { 'suffix': {} } ); // $ExpectError + joinBetween.assign( x, y, { 'suffix': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an invalid `separators` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = scalar2ndarray( '' ); + + joinBetween.assign( x, y, { 'separators': 5 } ); // $ExpectError + joinBetween.assign( x, y, { 'separators': true } ); // $ExpectError + joinBetween.assign( x, y, { 'separators': false } ); // $ExpectError + joinBetween.assign( x, y, { 'separators': null } ); // $ExpectError + joinBetween.assign( x, y, { 'separators': {} } ); // $ExpectError + joinBetween.assign( x, y, { 'separators': ( 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( '' ); + + joinBetween.assign( x, y, { 'dims': '5' } ); // $ExpectError + joinBetween.assign( x, y, { 'dims': 5 } ); // $ExpectError + joinBetween.assign( x, y, { 'dims': true } ); // $ExpectError + joinBetween.assign( x, y, { 'dims': false } ); // $ExpectError + joinBetween.assign( x, y, { 'dims': null } ); // $ExpectError + joinBetween.assign( x, y, { 'dims': {} } ); // $ExpectError + joinBetween.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( '' ); + + joinBetween.assign(); // $ExpectError + joinBetween.assign( x ); // $ExpectError + joinBetween.assign( x, y, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/join-between/examples/index.js b/lib/node_modules/@stdlib/blas/ext/join-between/examples/index.js new file mode 100644 index 000000000000..1024dbe61609 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join-between/examples/index.js @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var uniform = require( '@stdlib/random/uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var joinBetween = require( './../lib' ); + +var x = uniform( [ 5, 2 ], 0.0, 20.0 ); +console.log( ndarray2array( x ) ); + +var out = joinBetween( x, { + 'dims': [ -1 ], + 'prefix': '[ ', + 'suffix': ' ]', + 'separators': [ ', ' ] +}); +console.log( ndarray2array( out ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/join-between/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/join-between/lib/assign.js new file mode 100644 index 000000000000..a5bbfacb07ac --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join-between/lib/assign.js @@ -0,0 +1,145 @@ +/** +* @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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var unaryReduceStrided1d = require( '@stdlib/ndarray/base/unary-reduce-strided1d' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var gjoinBetween = require( '@stdlib/blas/ext/base/ndarray/gjoin-between' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var format = require( '@stdlib/string/format' ); +var validate = require( './validate.js' ); + + +// MAIN // + +/** +* Joins elements of an input ndarray using specified separators for each pair of consecutive elements 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 {string} [options.prefix=''] - prefix to prepend to each joined string +* @param {string} [options.suffix=''] - suffix to append to each joined string +* @param {ArrayLikeObject} [options.separators=[',']] - separators +* @param {IntegerArray} [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 array = require( '@stdlib/ndarray/array' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* // Create an input ndarray: +* var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] +* +* // 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 separators; + var prefix; + var suffix; + var order; + var opts; + var err; + var shx; + var N; + + 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 ) ); + } + shx = getShape( x ); + order = getOrder( x ); + N = shx.length; + + // Resolve options: + opts = { + 'prefix': '', + 'suffix': '', + 'separators': [ ',' ], + 'dims': zeroTo( N ) + }; + if ( arguments.length > 2 ) { + err = validate( opts, N, options ); + if ( err ) { + throw err; + } + } + // Resolve prefix and suffix: + prefix = scalar2ndarray( opts.prefix, { + 'dtype': 'generic', + 'order': order + }); + suffix = scalar2ndarray( opts.suffix, { + 'dtype': 'generic', + 'order': order + }); + + // Resolve separators as a one-dimensional ndarray. When the separators array has a single element, the same separator is used for all consecutive pairs regardless of core size: + if ( opts.separators.length === 1 ) { + separators = broadcastScalar( opts.separators[ 0 ], 'generic', [ 1 ], order ); + } else { + separators = new ndarray( 'generic', opts.separators, [ opts.separators.length ], [ 1 ], 0, order ); + } + // Perform the reduction: + unaryReduceStrided1d( dispatch, [ x, out ], opts.dims ); + + return out; + + /** + * Dispatch function which joins elements of a one-dimensional ndarray slice. + * + * @private + * @param {Array} arrays - ndarrays + * @returns {string} joined string + */ + function dispatch( arrays ) { + return gjoinBetween( [ arrays[ 0 ], prefix, suffix, separators ] ); + } +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/blas/ext/join-between/lib/index.js b/lib/node_modules/@stdlib/blas/ext/join-between/lib/index.js new file mode 100644 index 000000000000..ea36e56d02c9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join-between/lib/index.js @@ -0,0 +1,55 @@ +/** +* @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'; + +/** +* Return an ndarray created by joining elements using specified separators for each pair of consecutive elements along one or more ndarray dimensions. +* +* @module @stdlib/blas/ext/join-between +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var joinBetween = require( '@stdlib/blas/ext/join-between' ); +* +* // Create an input ndarray: +* var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] +* +* // Perform operation: +* var out = joinBetween( 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-between/lib/main.js b/lib/node_modules/@stdlib/blas/ext/join-between/lib/main.js new file mode 100644 index 000000000000..a9492bf5063b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join-between/lib/main.js @@ -0,0 +1,154 @@ +/** +* @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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var unaryReduceStrided1d = require( '@stdlib/ndarray/base/unary-reduce-strided1d' ); +var spreadDimensions = require( '@stdlib/ndarray/base/spread-dimensions' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var indicesComplement = require( '@stdlib/array/base/indices-complement' ); +var takeIndexed = require( '@stdlib/array/base/take-indexed' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var gjoinBetween = require( '@stdlib/blas/ext/base/ndarray/gjoin-between' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var empty = require( '@stdlib/ndarray/empty' ); +var format = require( '@stdlib/string/format' ); +var validate = require( './validate.js' ); + + +// MAIN // + +/** +* Returns an ndarray created by joining elements using specified separators for each pair of consecutive elements along one or more ndarray dimensions. +* +* @param {ndarrayLike} x - input ndarray +* @param {Options} [options] - function options +* @param {string} [options.prefix=''] - prefix to prepend to each joined string +* @param {string} [options.suffix=''] - suffix to append to each joined string +* @param {ArrayLikeObject} [options.separators=[',']] - separators +* @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 +* @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 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 [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] +* +* // Perform operation: +* var out = joinBetween( x ); +* // returns [ '1,2,3,4,5,6' ] +*/ +function joinBetween( x, options ) { + var separators; + var prefix; + var suffix; + var order; + var opts; + var err; + var idx; + var shy; + var shx; + var N; + var y; + + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + } + shx = getShape( x ); + order = getOrder( x ); + N = shx.length; + + // Resolve options: + opts = { + 'prefix': '', + 'suffix': '', + 'separators': [ ',' ], + 'dims': zeroTo( N ), + 'keepdims': false + }; + if ( arguments.length > 1 ) { + err = validate( opts, N, options ); + if ( err ) { + throw err; + } + } + // Resolve the list of non-reduced dimensions and the output shape: + idx = indicesComplement( N, opts.dims ); + shy = takeIndexed( shx, idx ); + + // Create the output ndarray: + y = empty( shy, { + 'dtype': 'generic', + 'order': order + }); + + // Resolve prefix and suffix: + prefix = scalar2ndarray( opts.prefix, { + 'dtype': 'generic', + 'order': order + }); + suffix = scalar2ndarray( opts.suffix, { + 'dtype': 'generic', + 'order': order + }); + + // Resolve separators as a one-dimensional ndarray. When the separators array has a single element, the same separator is used for all consecutive pairs regardless of core size: + if ( opts.separators.length === 1 ) { + separators = broadcastScalar( opts.separators[ 0 ], 'generic', [ 1 ], order ); + } else { + separators = new ndarray( 'generic', opts.separators, [ opts.separators.length ], [ 1 ], 0, order ); + } + // Perform the reduction: + unaryReduceStrided1d( dispatch, [ x, y ], opts.dims ); + + // Check whether we need to reinsert singleton dimensions... + if ( opts.keepdims ) { + y = spreadDimensions( N, y, idx, true ); + } + return y; + + /** + * Dispatch function which joins elements of a one-dimensional ndarray slice. + * + * @private + * @param {Array} arrays - ndarrays + * @returns {string} joined string + */ + function dispatch( arrays ) { + return gjoinBetween( [ arrays[ 0 ], prefix, suffix, separators ] ); + } +} + + +// EXPORTS // + +module.exports = joinBetween; diff --git a/lib/node_modules/@stdlib/blas/ext/join-between/lib/validate.js b/lib/node_modules/@stdlib/blas/ext/join-between/lib/validate.js new file mode 100644 index 000000000000..1e6bb7e0d292 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join-between/lib/validate.js @@ -0,0 +1,105 @@ +/** +* @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 isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isCollection = require( '@stdlib/assert/is-collection' ); +var isIntegerArray = require( '@stdlib/assert/is-integer-array' ).primitives; +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var normalizeIndices = require( '@stdlib/ndarray/base/to-unique-normalized-indices' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Validates function options. +* +* @private +* @param {Object} opts - destination object +* @param {NonNegativeInteger} ndims - number of input ndarray dimensions +* @param {Options} options - function options +* @param {string} [options.prefix] - prefix to prepend to each joined string +* @param {string} [options.suffix] - suffix to append to each joined string +* @param {ArrayLikeObject} [options.separators] - separators +* @param {IntegerArray} [options.dims] - list of dimensions over which to perform operation +* @param {boolean} [options.keepdims] - boolean indicating whether the reduced dimensions should be included in the returned ndarray as singleton dimensions +* @returns {(Error|null)} null or an error object +* +* @example +* var opts = { +* 'prefix': '', +* 'suffix': '', +* 'separators': [ ',' ], +* 'dims': [ 0, 1 ], +* 'keepdims': false +* }; +* var options = { +* 'separators': [ ' + ', ' = ' ], +* 'dims': [ -1 ] +* }; +* var err = validate( opts, 2, options ); +* if ( err ) { +* throw err; +* } +*/ +function validate( opts, ndims, options ) { + if ( !isPlainObject( options ) ) { + return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + if ( hasOwnProp( options, 'prefix' ) ) { + opts.prefix = options.prefix; + } + if ( hasOwnProp( options, 'suffix' ) ) { + opts.suffix = options.suffix; + } + if ( hasOwnProp( options, 'separators' ) ) { + opts.separators = options.separators; + if ( !isCollection( opts.separators ) ) { + return new TypeError( format( 'invalid option. `%s` option must be an array-like object. Option: `%s`.', 'separators', opts.separators ) ); + } + } + if ( hasOwnProp( options, 'dims' ) ) { + if ( !isIntegerArray( options.dims ) ) { + return new TypeError( format( 'invalid option. `%s` option must be an array of integers. Option: `%s`.', 'dims', options.dims ) ); + } + opts.dims = normalizeIndices( options.dims, ndims-1 ); + if ( opts.dims === null ) { + return new RangeError( format( 'invalid option. `%s` option contains an out-of-bounds dimension index.', 'dims' ) ); + } + if ( opts.dims.length !== options.dims.length ) { + return new Error( format( 'invalid option. `%s` option contains duplicate indices.', 'dims' ) ); + } + } + if ( hasOwnProp( options, 'keepdims' ) ) { + opts.keepdims = options.keepdims; + if ( !isBoolean( opts.keepdims ) ) { + return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'keepdims', opts.keepdims ) ); + } + } + return null; +} + + +// EXPORTS // + +module.exports = validate; diff --git a/lib/node_modules/@stdlib/blas/ext/join-between/package.json b/lib/node_modules/@stdlib/blas/ext/join-between/package.json new file mode 100644 index 000000000000..cff714a53274 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join-between/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/blas/ext/join-between", + "version": "0.0.0", + "description": "Return an ndarray created by joining elements using specified separators for each pair of consecutive elements 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", + "join-between", + "string", + "strided", + "array", + "ndarray", + "separator", + "prefix", + "suffix" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/join-between/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/join-between/test/test.assign.js new file mode 100644 index 000000000000..5723e7c3333e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join-between/test/test.assign.js @@ -0,0 +1,265 @@ +/** +* @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 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 empty = require( '@stdlib/ndarray/empty' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var joinBetween = require( './../lib' ).assign; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof joinBetween, '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() { + joinBetween( 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 x; + var i; + + x = zeros( [ 2, 2 ], { + '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() { + joinBetween( 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 y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + y = empty( [], { + '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() { + joinBetween( x, y, value ); + }; + } +}); + +tape( 'the function joins elements and assigns results to an output ndarray (default, 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( [], { + 'dtype': 'generic' + }); + + actual = joinBetween( 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 ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( actual.get(), expected, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying reduction dimensions (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 = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + actual = joinBetween( x, out, { + 'dims': [ 0 ] + }); + expected = [ '1,3', '2,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], '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, 'row-major' ); + out = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + actual = joinBetween( x, out, { + 'dims': [ 1 ] + }); + expected = [ '1,2', '3,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], '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 prefix and suffix', 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 = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + actual = joinBetween( x, out, { + 'dims': [ 1 ], + 'prefix': '[ ', + 'suffix': ' ]', + 'separators': [ ', ' ] + }); + expected = [ '[ 1, 2 ]', '[ 3, 4 ]' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports per-pair separators via an array', 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, [ 4 ], [ 1 ], 0, 'row-major' ); + out = empty( [], { + 'dtype': 'generic' + }); + + actual = joinBetween( x, out, { + 'separators': [ ' + ', ' - ', ' != ' ], + 'prefix': 'op: ', + 'suffix': '' + }); + expected = 'op: 1 + 2 - 3 != 4'; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( actual.get(), expected, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/join-between/test/test.js b/lib/node_modules/@stdlib/blas/ext/join-between/test/test.js new file mode 100644 index 000000000000..1564eee01108 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join-between/test/test.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isMethod = require( '@stdlib/assert/is-method' ); +var joinBetween = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof joinBetween, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( joinBetween, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/join-between/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/join-between/test/test.main.js new file mode 100644 index 000000000000..ca3901817b7d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join-between/test/test.main.js @@ -0,0 +1,401 @@ +/** +* @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 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 getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var joinBetween = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof joinBetween, '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() { + joinBetween( 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() { + joinBetween( 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() { + joinBetween( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains out-of-bounds indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ -10 ], + [ 0, 20 ], + [ 20 ] + ]; + 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() { + joinBetween( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains duplicate indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 0 ], + [ 1, 1 ], + [ 0, 1, 0 ], + [ 1, 0, 1 ] + ]; + 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() { + joinBetween( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function returns an ndarray created by joining elements of an input ndarray (default, 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 = joinBetween( 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 ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an ndarray created by joining elements of an input ndarray (default, 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 = joinBetween( 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 ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a reduction on an ndarray (all dimensions, 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 = joinBetween( x, { + 'dims': [ 0, 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 ), [], 'returns expected value' ); + t.deepEqual( actual.get(), expected, 'returns expected value' ); + + actual = joinBetween( x, { + 'dims': [ 0, 1 ], + 'keepdims': true + }); + expected = [ [ '1,2,3,4' ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 1, 1 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying reduction dimensions (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 = joinBetween( x, { + 'dims': [ 0 ] + }); + expected = [ '1,3', '2,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = joinBetween( x, { + 'dims': [ 1 ] + }); + expected = [ '1,2', '3,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = joinBetween( x, { + 'dims': [ 0 ], + 'keepdims': true + }); + expected = [ [ '1,3', '2,4' ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 1, 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a custom scalar 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 = joinBetween( x, { + 'dims': [ 1 ], + 'separators': [ '|' ] + }); + expected = [ '1|2', '3|4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a prefix and suffix (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 = joinBetween( x, { + 'dims': [ 1 ], + 'prefix': '[ ', + 'suffix': ' ]', + 'separators': [ ', ' ] + }); + expected = [ '[ 1, 2 ]', '[ 3, 4 ]' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = joinBetween( x, { + 'dims': [ 0 ], + 'prefix': '(', + 'suffix': ')', + 'separators': [ '|' ] + }); + expected = [ '(1|3)', '(2|4)' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports per-pair separators via an array', 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, [ 4 ], [ 1 ], 0, 'row-major' ); + + actual = joinBetween( x, { + 'separators': [ ' + ', ' - ', ' != ' ], + 'prefix': 'op: ', + 'suffix': '' + }); + expected = 'op: 1 + 2 - 3 != 4'; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.deepEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports per-pair separators via an array with dims', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + actual = joinBetween( x, { + 'dims': [ 1 ], + 'separators': [ ' + ', ' = ' ] + }); + expected = [ '1 + 2 = 3', '4 + 5 = 6' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +});