From 96d593cbb87502b76d4c662329435a66b025a51a Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 4 Apr 2026 01:20:48 +0500 Subject: [PATCH 1/3] feat: add blas/ext/join-between --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/join-between/README.md | 213 ++++++++++ .../benchmark/benchmark.assign.js | 114 +++++ .../ext/join-between/benchmark/benchmark.js | 106 +++++ .../blas/ext/join-between/docs/repl.txt | 99 +++++ .../ext/join-between/docs/types/index.d.ts | 168 ++++++++ .../blas/ext/join-between/docs/types/test.ts | 297 +++++++++++++ .../blas/ext/join-between/examples/index.js | 34 ++ .../blas/ext/join-between/lib/assign.js | 145 +++++++ .../blas/ext/join-between/lib/index.js | 55 +++ .../@stdlib/blas/ext/join-between/lib/main.js | 154 +++++++ .../blas/ext/join-between/lib/validate.js | 105 +++++ .../blas/ext/join-between/package.json | 69 +++ .../blas/ext/join-between/test/test.assign.js | 265 ++++++++++++ .../blas/ext/join-between/test/test.js | 39 ++ .../blas/ext/join-between/test/test.main.js | 401 ++++++++++++++++++ 15 files changed, 2264 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/join-between/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/join-between/benchmark/benchmark.assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/join-between/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/join-between/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/join-between/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/join-between/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/join-between/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/join-between/lib/assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/join-between/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/join-between/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/join-between/lib/validate.js create mode 100644 lib/node_modules/@stdlib/blas/ext/join-between/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/join-between/test/test.assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/join-between/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/join-between/test/test.main.js 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(); +}); From d5280f3481b3ffc05d473216f960c7595d26e71a Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 9 Apr 2026 18:59:52 +0500 Subject: [PATCH 2/3] fix: apply suggestions from code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/join-between/README.md | 83 ++- .../benchmark/benchmark.assign.js | 20 +- .../ext/join-between/benchmark/benchmark.js | 22 +- .../blas/ext/join-between/docs/repl.txt | 72 ++- .../ext/join-between/docs/types/index.d.ts | 46 +- .../blas/ext/join-between/docs/types/test.ts | 269 ++++---- .../blas/ext/join-between/examples/index.js | 10 +- .../blas/ext/join-between/lib/assign.js | 144 +++-- .../@stdlib/blas/ext/join-between/lib/base.js | 103 +++ .../blas/ext/join-between/lib/index.js | 8 +- .../@stdlib/blas/ext/join-between/lib/main.js | 165 ++--- .../blas/ext/join-between/lib/validate.js | 105 ---- .../blas/ext/join-between/test/test.assign.js | 590 +++++++++++++++++- .../blas/ext/join-between/test/test.main.js | 421 +++++++++++-- 14 files changed, 1504 insertions(+), 554 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/ext/join-between/lib/base.js delete mode 100644 lib/node_modules/@stdlib/blas/ext/join-between/lib/validate.js diff --git a/lib/node_modules/@stdlib/blas/ext/join-between/README.md b/lib/node_modules/@stdlib/blas/ext/join-between/README.md index e04ba389fed5..df51557084a8 100644 --- a/lib/node_modules/@stdlib/blas/ext/join-between/README.md +++ b/lib/node_modules/@stdlib/blas/ext/join-between/README.md @@ -30,60 +30,56 @@ limitations under the License. var joinBetween = require( '@stdlib/blas/ext/join-between' ); ``` -#### joinBetween( x\[, options] ) +#### joinBetween( x, separators\[, 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' ); +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 a separators ndarray: +var sep = scalar2ndarray( ',', { + 'dtype': 'generic' +}); + // Perform operation: -var out = joinBetween( x ); +var out = joinBetween( x, sep ); // returns [ '1,2,3,4,5,6' ] ``` The function has the following parameters: - **x**: input [ndarray][@stdlib/ndarray/ctor]. +- **separators**: separators [ndarray][@stdlib/ndarray/ctor]. Must be [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape consisting of the complement of the shape defined by `options.dims` followed by `N-1` where `N` is the number of elements along the reduced dimensions. - **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: `[ ',' ]`. +- **prefix**: prefix to prepend to each joined string. May be a scalar value or an [ndarray][@stdlib/ndarray/ctor] which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. Default: `''`. +- **suffix**: suffix to append to each joined string. May be a scalar value or an [ndarray][@stdlib/ndarray/ctor] which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. 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. +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 scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); -var out = joinBetween( x, { - 'separators': [ '|' ] +var sep = scalar2ndarray( ', ', { + 'dtype': 'generic' }); -// 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, { +var out = joinBetween( x, sep, { 'prefix': '[ ', - 'suffix': ' ]', - 'separators': [ ', ' ] + 'suffix': ' ]' }); // returns [ '[ 1, 2, 3, 4, 5, 6 ]' ] ``` @@ -92,32 +88,45 @@ By default, the function performs the operation over all elements in a provided ```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 ] ] ); -// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] -var out = joinBetween( x, { +var sep = scalar2ndarray( ',', { + 'dtype': 'generic' +}); + +var out = joinBetween( x, sep, { 'dims': [ 0 ] }); // returns [ '1,3', '2,4' ] + +out = joinBetween( x, sep, { + 'dims': [ 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 scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); -// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] -var out = joinBetween( x, { +var sep = scalar2ndarray( ',', { + 'dtype': 'generic' +}); + +var out = joinBetween( x, sep, { 'dims': [ 0 ], 'keepdims': true }); // returns [ [ '1,3', '2,4' ] ] ``` -#### joinBetween.assign( x, out\[, options] ) +#### joinBetween.assign( x, separators, 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]. @@ -126,11 +135,14 @@ 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 sep = scalar2ndarray( ',', { + 'dtype': 'generic' +}); var y = scalar2ndarray( '', { 'dtype': 'generic' }); -var out = joinBetween.assign( x, y ); +var out = joinBetween.assign( x, sep, y ); // returns [ '1,2,3,4' ] var bool = ( out === y ); @@ -140,14 +152,14 @@ var bool = ( out === y ); The method has the following parameters: - **x**: input [ndarray][@stdlib/ndarray/ctor]. +- **separators**: separators [ndarray][@stdlib/ndarray/ctor]. Must be [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape consisting of the complement of the shape defined by `options.dims` followed by `N-1` where `N` is the number of elements along the reduced dimensions. - **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: `[ ',' ]`. +- **prefix**: prefix to prepend to each joined string. May be a scalar value or an [ndarray][@stdlib/ndarray/ctor] which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. Default: `''`. +- **suffix**: suffix to append to each joined string. May be a scalar value or an [ndarray][@stdlib/ndarray/ctor] which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. 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]. @@ -159,7 +171,6 @@ The method accepts the following options: ## 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. @@ -172,6 +183,7 @@ The method accepts the following options: ```javascript +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var uniform = require( '@stdlib/random/uniform' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var joinBetween = require( '@stdlib/blas/ext/join-between' ); @@ -179,11 +191,14 @@ 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, { +var sep = scalar2ndarray( ', ', { + 'dtype': 'generic' +}); + +var out = joinBetween( x, sep, { 'dims': [ -1 ], 'prefix': '[ ', - 'suffix': ' ]', - 'separators': [ ', ' ] + 'suffix': ' ]' }); 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 index 1d39fa94bbba..eab2a5d24c10 100644 --- 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 @@ -21,11 +21,11 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; var pow = require( '@stdlib/math/base/special/pow' ); -var uniform = require( '@stdlib/random/array/uniform' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var uniform = require( '@stdlib/random/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' ); @@ -48,11 +48,15 @@ var options = { * @returns {Function} benchmark function */ function createBenchmark( len ) { + var sep; var out; var x; - x = uniform( len, -50.0, 50.0, options ); - x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' ); + x = uniform( [ len ], -50.0, 50.0, options ); + + sep = scalar2ndarray( ',', { + 'dtype': 'generic' + }); out = empty( [], { 'dtype': 'generic' @@ -72,14 +76,14 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - o = joinBetween.assign( x, out ); + o = joinBetween.assign( x, sep, out ); if ( typeof o !== 'object' ) { b.fail( 'should return an ndarray' ); } } b.toc(); - if ( isnan( o.get() ) ) { - b.fail( 'should not return NaN' ); + if ( !isString( o.get() ) ) { + b.fail( 'should return a string' ); } b.pass( 'benchmark finished' ); b.end(); 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 index 1a52b2ec8464..e140456523fa 100644 --- a/lib/node_modules/@stdlib/blas/ext/join-between/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/join-between/benchmark/benchmark.js @@ -21,10 +21,10 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; var pow = require( '@stdlib/math/base/special/pow' ); -var uniform = require( '@stdlib/random/array/uniform' ); -var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var uniform = require( '@stdlib/random/uniform' ); var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var joinBetween = require( './../lib' ); @@ -47,8 +47,14 @@ var options = { * @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' ); + var sep; + var x; + + x = uniform( [ len ], -50.0, 50.0, options ); + + sep = scalar2ndarray( ',', { + 'dtype': 'generic' + }); return benchmark; @@ -64,14 +70,14 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - o = joinBetween( x ); + o = joinBetween( x, sep ); if ( typeof o !== 'object' ) { b.fail( 'should return an ndarray' ); } } b.toc(); - if ( isnan( o.get() ) ) { - b.fail( 'should not return NaN' ); + if ( !isString( o.get() ) ) { + b.fail( 'should return a string' ); } b.pass( 'benchmark finished' ); b.end(); 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 index 5c0b9856fe50..303b4fc5dfcd 100644 --- a/lib/node_modules/@stdlib/blas/ext/join-between/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/join-between/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( x[, options] ) +{{alias}}( x, separators[, options] ) Returns an ndarray created by joining elements using specified separators for each pair of consecutive elements along one or more ndarray dimensions. @@ -8,22 +8,23 @@ x: ndarray Input array. + separators: ndarray + Separators. Must be broadcast compatible with the shape consisting of + the complement of the shape defined by `options.dims` followed by one + less than the number of elements along the reduced dimensions. + 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.prefix: ndarray|string (optional) + Prefix to prepend to each joined string. May be a scalar value or an + ndarray which is broadcast compatible with the complement of the shape + defined by `options.dims`. 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.suffix: ndarray|string (optional) + Suffix to append to each joined string. May be a scalar value or an + ndarray which is broadcast compatible with the complement of the shape + defined by `options.dims`. Default: ''. options.dims: Array (optional) List of dimensions over which to perform operation. If not provided, the @@ -41,12 +42,14 @@ 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' ] + > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var opts = { 'dtype': 'generic' }; + > var sep = {{alias:@stdlib/ndarray/from-scalar}}( ',', opts ); + > var y = {{alias}}( x, sep ) + [ '1,2,3,4' ] -{{alias}}.assign( x, out[, options] ) +{{alias}}.assign( x, separators, 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. @@ -56,25 +59,26 @@ x: ndarray Input array. + separators: ndarray + Separators. Must be broadcast compatible with the shape consisting of + the complement of the shape defined by `options.dims` followed by one + less than the number of elements along the reduced dimensions. + 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.prefix: ndarray|string (optional) + Prefix to prepend to each joined string. May be a scalar value or an + ndarray which is broadcast compatible with the complement of the shape + defined by `options.dims`. 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.suffix: ndarray|string (optional) + Suffix to append to each joined string. May be a scalar value or an + ndarray which is broadcast compatible with the complement of the shape + defined by `options.dims`. Default: ''. options.dims: Array (optional) List of dimensions over which to perform operation. If not provided, the @@ -88,10 +92,12 @@ 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 x = {{alias:@stdlib/ndarray/array}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var opts = { 'dtype': 'generic' }; + > var sep = {{alias:@stdlib/ndarray/from-scalar}}( ',', opts ); + > var out = {{alias:@stdlib/ndarray/from-scalar}}( '', opts ); + > var y = {{alias}}.assign( x, sep, out ) + [ '1,2,3,4' ] > var bool = ( out === y ) true 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 index d21152bd0e07..c9fb8471c0a1 100644 --- 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 @@ -45,21 +45,16 @@ interface BaseOptions { /** * Interface defining options. */ -interface Options extends BaseOptions { +interface Options extends BaseOptions { /** * Prefix to prepend to each joined string. Default: `''`. */ - prefix?: string; + prefix?: string | typedndarray; /** * Suffix to append to each joined string. Default: `''`. */ - suffix?: string; - - /** - * Separators. Default: `[ ',' ]`. - */ - separators?: ArrayLike; + suffix?: string | typedndarray; /** * Boolean indicating whether the reduced dimensions should be included in the returned array as singleton dimensions. Default: `false`. @@ -76,34 +71,39 @@ 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 separators - separators 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 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 = joinBetween( x ); + * var sep = scalar2ndarray( ',', { + * 'dtype': 'generic' + * }); + * + * var y = joinBetween( x, sep ); * // returns [ '1,2,3,4,5,6' ] */ - ( x: InputArray, options?: Options ): OutputArray; + ( x: InputArray, separators: typedndarray, 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 separators - separators 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 * @@ -114,33 +114,43 @@ interface JoinBetween { * 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 sep = scalar2ndarray( ',', { + * 'dtype': 'generic' + * }); + * * var y = scalar2ndarray( '', { * 'dtype': 'generic' * }); * - * var out = joinBetween.assign( x, y ); + * var out = joinBetween.assign( x, sep, y ); * // returns [ '1,2,3,4,5,6' ] * * var bool = ( out === y ); * // returns true */ - assign = typedndarray>( x: InputArray, out: V, options?: Options ): V; + assign = typedndarray>( x: InputArray, separators: typedndarray, 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 separators - separators ndarray * @param options - function options * @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 = joinBetween( x ); +* var sep = scalar2ndarray( ',', { +* 'dtype': 'generic' +* }); +* +* var y = joinBetween( x, sep ); * // returns [ '1,2,3,4,5,6' ] * * @example @@ -150,11 +160,15 @@ interface JoinBetween { * 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 sep = scalar2ndarray( ',', { +* 'dtype': 'generic' +* }); +* * var y = scalar2ndarray( '', { * 'dtype': 'generic' * }); * -* var out = joinBetween.assign( x, y ); +* var out = joinBetween.assign( x, sep, y ); * // returns [ '1,2,3,4,5,6' ] * * var bool = ( out === y ); 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 index 7765515cf942..61cbb1e009fd 100644 --- 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 @@ -30,113 +30,94 @@ import joinBetween = require( './index' ); const x = zeros( [ 2, 2 ], { 'dtype': 'float64' }); + const sep = scalar2ndarray( ',', { + 'dtype': 'generic' + }); - joinBetween( x ); // $ExpectType OutputArray - joinBetween( x, {} ); // $ExpectType OutputArray + joinBetween( x, sep ); // $ExpectType OutputArray + joinBetween( x, sep, {} ); // $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 + const sep = scalar2ndarray( ',', { + 'dtype': 'generic' + }); + + joinBetween( '5', sep ); // $ExpectError + joinBetween( 5, sep ); // $ExpectError + joinBetween( true, sep ); // $ExpectError + joinBetween( false, sep ); // $ExpectError + joinBetween( null, sep ); // $ExpectError + joinBetween( void 0, sep ); // $ExpectError + joinBetween( {}, sep ); // $ExpectError + joinBetween( ( x: number ): number => x, sep ); // $ExpectError } -// The compiler throws an error if the function is provided an options argument which is not an object... +// The compiler throws an error if the function is provided a second argument which is not an ndarray... { const x = zeros( [ 2, 2 ], { 'dtype': 'float64' }); joinBetween( x, '5' ); // $ExpectError + joinBetween( x, 5 ); // $ExpectError joinBetween( x, true ); // $ExpectError joinBetween( x, false ); // $ExpectError - joinBetween( x, [] ); // $ExpectError + joinBetween( x, null ); // $ExpectError + joinBetween( x, void 0 ); // $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... +// 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, { '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' + const sep = scalar2ndarray( ',', { + 'dtype': 'generic' }); - 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 + joinBetween( x, sep, '5' ); // $ExpectError + joinBetween( x, sep, true ); // $ExpectError + joinBetween( x, sep, false ); // $ExpectError + joinBetween( x, sep, [] ); // $ExpectError + joinBetween( x, sep, ( x: number ): number => x ); // $ExpectError } -// The compiler throws an error if the function is provided an invalid `prefix` option... +// The compiler throws an error if the function is provided an invalid `dims` 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' + const sep = scalar2ndarray( ',', { + 'dtype': 'generic' }); - 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 + joinBetween( x, sep, { 'dims': '5' } ); // $ExpectError + joinBetween( x, sep, { 'dims': 5 } ); // $ExpectError + joinBetween( x, sep, { 'dims': true } ); // $ExpectError + joinBetween( x, sep, { 'dims': false } ); // $ExpectError + joinBetween( x, sep, { 'dims': null } ); // $ExpectError + joinBetween( x, sep, { 'dims': {} } ); // $ExpectError + joinBetween( x, sep, { 'dims': ( x: number ): number => x } ); // $ExpectError } -// The compiler throws an error if the function is provided an invalid `separators` option... +// The compiler throws an error if the function is provided an invalid `keepdims` option... { const x = zeros( [ 2, 2 ], { 'dtype': 'float64' }); + const sep = scalar2ndarray( ',', { + 'dtype': 'generic' + }); - 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 + joinBetween( x, sep, { 'keepdims': '5' } ); // $ExpectError + joinBetween( x, sep, { 'keepdims': 5 } ); // $ExpectError + joinBetween( x, sep, { 'keepdims': null } ); // $ExpectError + joinBetween( x, sep, { 'keepdims': {} } ); // $ExpectError + joinBetween( x, sep, { 'keepdims': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the function is provided an unsupported number of arguments... @@ -144,9 +125,13 @@ import joinBetween = require( './index' ); const x = zeros( [ 2, 2 ], { 'dtype': 'float64' }); + const sep = scalar2ndarray( ',', { + 'dtype': 'generic' + }); joinBetween(); // $ExpectError - joinBetween( x, {}, {} ); // $ExpectError + joinBetween( x ); // $ExpectError + joinBetween( x, sep, {}, {} ); // $ExpectError } // Attached to the function is an `assign` method which returns an ndarray... @@ -154,118 +139,85 @@ import joinBetween = require( './index' ); const x = zeros( [ 2, 2 ], { 'dtype': 'float64' }); + const sep = scalar2ndarray( ',', { + 'dtype': 'generic' + }); const y = scalar2ndarray( '', { 'dtype': 'generic' }); - joinBetween.assign( x, y ); // $ExpectType genericndarray - joinBetween.assign( x, y, {} ); // $ExpectType genericndarray + joinBetween.assign( x, sep, y ); // $ExpectType genericndarray + joinBetween.assign( x, sep, 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 sep = scalar2ndarray( ',', { + 'dtype': 'generic' }); 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 + joinBetween.assign( '5', sep, y ); // $ExpectError + joinBetween.assign( 5, sep, y ); // $ExpectError + joinBetween.assign( true, sep, y ); // $ExpectError + joinBetween.assign( false, sep, y ); // $ExpectError + joinBetween.assign( null, sep, y ); // $ExpectError + joinBetween.assign( void 0, sep, y ); // $ExpectError + joinBetween.assign( {}, sep, y ); // $ExpectError + joinBetween.assign( ( x: number ): number => x, sep, y ); // $ExpectError } -// The compiler throws an error if the `assign` method is provided an invalid `prefix` option... +// The compiler throws an error if the `assign` method is provided a second argument which is not an ndarray... { 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 + joinBetween.assign( x, '5', y ); // $ExpectError + joinBetween.assign( x, 5, y ); // $ExpectError + joinBetween.assign( x, true, y ); // $ExpectError + joinBetween.assign( x, false, y ); // $ExpectError + joinBetween.assign( x, null, y ); // $ExpectError + joinBetween.assign( x, void 0, y ); // $ExpectError + joinBetween.assign( x, {}, y ); // $ExpectError + joinBetween.assign( x, ( x: number ): number => x, y ); // $ExpectError } -// The compiler throws an error if the `assign` method is provided an invalid `suffix` option... +// The compiler throws an error if the `assign` method is provided a third argument which is not an ndarray... { const x = zeros( [ 2, 2 ], { 'dtype': 'float64' }); - const y = scalar2ndarray( '' ); + const sep = scalar2ndarray( ',', { + 'dtype': 'generic' + }); - 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 + joinBetween.assign( x, sep, '5' ); // $ExpectError + joinBetween.assign( x, sep, 5 ); // $ExpectError + joinBetween.assign( x, sep, true ); // $ExpectError + joinBetween.assign( x, sep, false ); // $ExpectError + joinBetween.assign( x, sep, null ); // $ExpectError + joinBetween.assign( x, sep, void 0 ); // $ExpectError + joinBetween.assign( x, sep, ( x: number ): number => x ); // $ExpectError } -// The compiler throws an error if the `assign` method is provided an invalid `separators` option... +// 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 sep = scalar2ndarray( ',', { + 'dtype': 'generic' + }); 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 + joinBetween.assign( x, sep, y, '5' ); // $ExpectError + joinBetween.assign( x, sep, y, true ); // $ExpectError + joinBetween.assign( x, sep, y, false ); // $ExpectError + joinBetween.assign( x, sep, y, null ); // $ExpectError + joinBetween.assign( x, sep, y, [] ); // $ExpectError + joinBetween.assign( x, sep, y, ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the `assign` method is provided an invalid `dims` option... @@ -273,15 +225,18 @@ import joinBetween = require( './index' ); const x = zeros( [ 2, 2 ], { 'dtype': 'float64' }); + const sep = scalar2ndarray( ',', { + 'dtype': 'generic' + }); 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 + joinBetween.assign( x, sep, y, { 'dims': '5' } ); // $ExpectError + joinBetween.assign( x, sep, y, { 'dims': 5 } ); // $ExpectError + joinBetween.assign( x, sep, y, { 'dims': true } ); // $ExpectError + joinBetween.assign( x, sep, y, { 'dims': false } ); // $ExpectError + joinBetween.assign( x, sep, y, { 'dims': null } ); // $ExpectError + joinBetween.assign( x, sep, y, { 'dims': {} } ); // $ExpectError + joinBetween.assign( x, sep, y, { 'dims': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the `assign` method is provided an unsupported number of arguments... @@ -289,9 +244,13 @@ import joinBetween = require( './index' ); const x = zeros( [ 2, 2 ], { 'dtype': 'float64' }); + const sep = scalar2ndarray( ',', { + 'dtype': 'generic' + }); const y = scalar2ndarray( '' ); joinBetween.assign(); // $ExpectError joinBetween.assign( x ); // $ExpectError - joinBetween.assign( x, y, {}, {} ); // $ExpectError + joinBetween.assign( x, sep ); // $ExpectError + joinBetween.assign( x, sep, 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 index 1024dbe61609..ae69b1a2db86 100644 --- a/lib/node_modules/@stdlib/blas/ext/join-between/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/join-between/examples/index.js @@ -18,6 +18,7 @@ 'use strict'; +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var uniform = require( '@stdlib/random/uniform' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var joinBetween = require( './../lib' ); @@ -25,10 +26,13 @@ var joinBetween = require( './../lib' ); var x = uniform( [ 5, 2 ], 0.0, 20.0 ); console.log( ndarray2array( x ) ); -var out = joinBetween( x, { +var sep = scalar2ndarray( ', ', { + 'dtype': 'generic' +}); + +var out = joinBetween( x, sep, { 'dims': [ -1 ], 'prefix': '[ ', - 'suffix': ' ]', - 'separators': [ ', ' ] + 'suffix': ' ]' }); 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 index a5bbfacb07ac..4a47f9b38105 100644 --- a/lib/node_modules/@stdlib/blas/ext/join-between/lib/assign.js +++ b/lib/node_modules/@stdlib/blas/ext/join-between/lib/assign.js @@ -20,17 +20,18 @@ // 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 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 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 ndims = require( '@stdlib/ndarray/base/ndims' ); +var numel = require( '@stdlib/ndarray/base/numel' ); var format = require( '@stdlib/string/format' ); -var validate = require( './validate.js' ); +var base = require( './base.js' ).assign; // MAIN // @@ -39,14 +40,15 @@ var validate = require( './validate.js' ); * 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} separators - separators * @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 {(ndarrayLike|string)} [options.prefix=''] - prefix to prepend to each joined string +* @param {(ndarrayLike|string)} [options.suffix=''] - suffix to append to each joined string * @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} third 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 @@ -61,82 +63,110 @@ var validate = require( './validate.js' ); * 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 a separators ndarray: +* var sep = scalar2ndarray( ',', { +* 'dtype': 'generic' +* }); +* * // Create an output ndarray: * var y = scalar2ndarray( '', { * 'dtype': 'generic' * }); * * // Perform operation: -* var out = assign( x, y ); +* var out = assign( x, sep, y ); * // returns [ '1,2,3,4,5,6' ] * * var bool = ( out === y ); * // returns true */ -function assign( x, out, options ) { - var separators; +function assign( x, separators, out, options ) { var prefix; var suffix; - var order; var opts; - var err; + var sep; var shx; - var N; + var sh; + var M; + var p; + var s; if ( !isndarrayLike( x ) ) { throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); } + if ( !isndarrayLike( separators ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an ndarray-like object. Value: `%s`.', separators ) ); + } if ( !isndarrayLike( out ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an ndarray-like object. Value: `%s`.', out ) ); + throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); } - shx = getShape( x ); - order = getOrder( x ); - N = shx.length; + // Initialize prefix, suffix, and options: + p = ''; + s = ''; + opts = {}; - // Resolve options: - opts = { - 'prefix': '', - 'suffix': '', - 'separators': [ ',' ], - 'dims': zeroTo( N ) - }; - if ( arguments.length > 2 ) { - err = validate( opts, N, options ); - if ( err ) { - throw err; + if ( arguments.length > 3 ) { + if ( !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + if ( hasOwnProp( options, 'prefix' ) ) { + p = options.prefix; + } + if ( hasOwnProp( options, 'suffix' ) ) { + s = options.suffix; + } + if ( hasOwnProp( options, 'dims' ) ) { + opts.dims = options.dims; } } - // Resolve prefix and suffix: - prefix = scalar2ndarray( opts.prefix, { - 'dtype': 'generic', - 'order': order - }); - suffix = scalar2ndarray( opts.suffix, { - 'dtype': 'generic', - 'order': order - }); + shx = getShape( x ); - // 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 ); + // Broadcast prefix to the complement shape... + if ( isndarrayLike( p ) ) { + if ( hasOwnProp( opts, 'dims' ) ) { + prefix = maybeBroadcastArray( p, nonCoreShape( shx, opts.dims ) ); + } else if ( ndims( p ) === 0 ) { + prefix = p; + } else { + throw new TypeError( format( 'invalid option. `%s` option must be a zero-dimensional ndarray when not specifying dimensions. Value: `%s`.', 'prefix', p ) ); + } } else { - separators = new ndarray( 'generic', opts.separators, [ opts.separators.length ], [ 1 ], 0, order ); + if ( hasOwnProp( opts, 'dims' ) ) { + sh = nonCoreShape( shx, opts.dims ); + } else { + sh = []; + } + prefix = broadcastScalar( p, 'generic', sh, getOrder( x ) ); } - // 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 ] ); + // Broadcast suffix to the complement shape... + if ( isndarrayLike( s ) ) { + if ( hasOwnProp( opts, 'dims' ) ) { + suffix = maybeBroadcastArray( s, nonCoreShape( shx, opts.dims ) ); + } else if ( ndims( s ) === 0 ) { + suffix = s; + } else { + throw new TypeError( format( 'invalid option. `%s` option must be a zero-dimensional ndarray when not specifying dimensions. Value: `%s`.', 'suffix', s ) ); + } + } else { + if ( hasOwnProp( opts, 'dims' ) ) { + sh = nonCoreShape( shx, opts.dims ); + } else { + sh = []; + } + suffix = broadcastScalar( s, 'generic', sh, getOrder( x ) ); + } + // Broadcast separators to [ ...complementShape, M-1 ] where M is the number of elements along the reduced dimensions... + if ( hasOwnProp( opts, 'dims' ) ) { + sh = nonCoreShape( shx, opts.dims ); + M = numel( shx ) / numel( sh ); + } else { + sh = []; + M = numel( shx ); } + sh.push( M - 1 ); + sep = maybeBroadcastArray( separators, sh ); + + return base( x, prefix, suffix, sep, out, opts ); } diff --git a/lib/node_modules/@stdlib/blas/ext/join-between/lib/base.js b/lib/node_modules/@stdlib/blas/ext/join-between/lib/base.js new file mode 100644 index 000000000000..049661e69582 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join-between/lib/base.js @@ -0,0 +1,103 @@ +/** +* @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 dtypes = require( '@stdlib/ndarray/dtypes' ); +var gjoinBetween = require( '@stdlib/blas/ext/base/ndarray/gjoin-between' ); +var factory = require( '@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-factory' ); + + +// VARIABLES // + +var idtypes0 = dtypes( 'all' ); // input ndarray +var idtypes1 = [ 'generic' ]; // prefix ndarray +var idtypes2 = [ 'generic' ]; // suffix ndarray +var idtypes3 = [ 'generic' ]; // separators 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': gjoinBetween +}; + + +// MAIN // + +/** +* Returns an ndarray created by joining elements using specified separators for each pair of consecutive elements along one or more ndarray dimensions. +* +* @private +* @name joinBetween +* @type {Function} +* @param {ndarrayLike} x - input ndarray +* @param {ndarrayLike} prefix - prefix +* @param {ndarrayLike} suffix - suffix +* @param {ndarrayLike} separators - separators +* @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} third argument must be an ndarray-like object +* @throws {TypeError} fourth 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' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // 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 prefix and suffix ndarrays: +* var prefix = scalar2ndarray( '', { +* 'dtype': 'generic' +* }); +* var suffix = scalar2ndarray( '', { +* 'dtype': 'generic' +* }); +* +* // Create a separators ndarray: +* var separators = new ndarray( 'generic', [ ',' ], [ 1 ], [ 0 ], 0, 'row-major' ); +* +* // Perform operation: +* var out = joinBetween( x, prefix, suffix, separators, { +* 'dtype': 'generic' +* }); +* // returns [ '1,2,3,4,5,6' ] +*/ +var joinBetween = factory( table, [ idtypes0, idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len + + +// EXPORTS // + +module.exports = joinBetween; + +// exports: { "assign": "joinBetween.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 index ea36e56d02c9..35c9e708486e 100644 --- a/lib/node_modules/@stdlib/blas/ext/join-between/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/join-between/lib/index.js @@ -25,14 +25,20 @@ * * @example * var array = require( '@stdlib/ndarray/array' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * 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 ] * +* // Create a separators ndarray: +* var sep = scalar2ndarray( ',', { +* 'dtype': 'generic' +* }); +* * // Perform operation: -* var out = joinBetween( x ); +* var out = joinBetween( x, sep ); * // returns [ '1,2,3,4,5,6' ] */ 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 index a9492bf5063b..9a22c6efab34 100644 --- a/lib/node_modules/@stdlib/blas/ext/join-between/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/join-between/lib/main.js @@ -20,21 +20,18 @@ // 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 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 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 empty = require( '@stdlib/ndarray/empty' ); +var ndims = require( '@stdlib/ndarray/base/ndims' ); +var numel = require( '@stdlib/ndarray/base/numel' ); var format = require( '@stdlib/string/format' ); -var validate = require( './validate.js' ); +var base = require( './base.js' ); // MAIN // @@ -43,13 +40,14 @@ var validate = require( './validate.js' ); * 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 {ndarrayLike} separators - separators * @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 {(ndarrayLike|string)} [options.prefix=''] - prefix to prepend to each joined string +* @param {(ndarrayLike|string)} [options.suffix=''] - suffix to append to each joined string * @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} 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 @@ -58,94 +56,111 @@ var validate = require( './validate.js' ); * * @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 a separators ndarray: +* var sep = scalar2ndarray( ',', { +* 'dtype': 'generic' +* }); +* * // Perform operation: -* var out = joinBetween( x ); +* var out = joinBetween( x, sep ); * // returns [ '1,2,3,4,5,6' ] */ -function joinBetween( x, options ) { - var separators; +function joinBetween( x, separators, options ) { var prefix; var suffix; - var order; var opts; - var err; - var idx; - var shy; + var sep; var shx; - var N; - var y; + var sh; + var M; + var p; + var s; 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: + if ( !isndarrayLike( separators ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an ndarray-like object. Value: `%s`.', separators ) ); + } + // Initialize prefix, suffix, and options: + p = ''; + s = ''; opts = { - 'prefix': '', - 'suffix': '', - 'separators': [ ',' ], - 'dims': zeroTo( N ), + 'dtype': 'generic', 'keepdims': false }; - if ( arguments.length > 1 ) { - err = validate( opts, N, options ); - if ( err ) { - throw err; + + if ( arguments.length > 2 ) { + if ( !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + if ( hasOwnProp( options, 'prefix' ) ) { + p = options.prefix; + } + if ( hasOwnProp( options, 'suffix' ) ) { + s = options.suffix; + } + if ( hasOwnProp( options, 'dims' ) ) { + opts.dims = options.dims; + } + if ( hasOwnProp( options, 'keepdims' ) ) { + opts.keepdims = options.keepdims; } } - // 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 - }); + shx = getShape( x ); - // 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 ); + // Broadcast prefix to the complement shape... + if ( isndarrayLike( p ) ) { + if ( hasOwnProp( opts, 'dims' ) ) { + prefix = maybeBroadcastArray( p, nonCoreShape( shx, opts.dims ) ); + } else if ( ndims( p ) === 0 ) { + prefix = p; + } else { + throw new TypeError( format( 'invalid option. `%s` option must be a zero-dimensional ndarray when not specifying dimensions. Value: `%s`.', 'prefix', p ) ); + } } else { - separators = new ndarray( 'generic', opts.separators, [ opts.separators.length ], [ 1 ], 0, order ); + if ( hasOwnProp( opts, 'dims' ) ) { + sh = nonCoreShape( shx, opts.dims ); + } else { + sh = []; + } + prefix = broadcastScalar( p, 'generic', sh, getOrder( x ) ); } - // 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 ); + // Broadcast suffix to the complement shape... + if ( isndarrayLike( s ) ) { + if ( hasOwnProp( opts, 'dims' ) ) { + suffix = maybeBroadcastArray( s, nonCoreShape( shx, opts.dims ) ); + } else if ( ndims( s ) === 0 ) { + suffix = s; + } else { + throw new TypeError( format( 'invalid option. `%s` option must be a zero-dimensional ndarray when not specifying dimensions. Value: `%s`.', 'suffix', s ) ); + } + } else { + if ( hasOwnProp( opts, 'dims' ) ) { + sh = nonCoreShape( shx, opts.dims ); + } else { + sh = []; + } + suffix = broadcastScalar( s, 'generic', sh, getOrder( x ) ); } - 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 ] ); + // Broadcast separators to [ ...complementShape, M-1 ] where M is the number of elements along the reduced dimensions... + if ( hasOwnProp( opts, 'dims' ) ) { + sh = nonCoreShape( shx, opts.dims ); + M = numel( shx ) / numel( sh ); + } else { + sh = []; + M = numel( shx ); } + sh.push( M - 1 ); + sep = maybeBroadcastArray( separators, sh ); + + return base( x, prefix, suffix, sep, opts ); } 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 deleted file mode 100644 index 1e6bb7e0d292..000000000000 --- a/lib/node_modules/@stdlib/blas/ext/join-between/lib/validate.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @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/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/join-between/test/test.assign.js index 5723e7c3333e..9d6f49ee876d 100644 --- 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 @@ -22,6 +22,7 @@ var tape = require( 'tape' ); var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var zeros = require( '@stdlib/ndarray/zeros' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); @@ -32,6 +33,13 @@ var getOrder = require( '@stdlib/ndarray/order' ); var joinBetween = require( './../lib' ).assign; +// VARIABLES // + +var sep = scalar2ndarray( ',', { + 'dtype': 'generic' +}); + + // TESTS // tape( 'main export is a function', function test( t ) { @@ -68,12 +76,82 @@ tape( 'the function throws an error if provided a first argument which is not an function badValue( value ) { return function badValue() { - joinBetween( value, y ); + joinBetween( value, sep, 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 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, sep, y, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + 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( x, value, y ); }; } }); -tape( 'the function throws an error if provided an output argument which is not an ndarray-like object', function test( t ) { +tape( 'the function throws an error if provided a third argument which is not an ndarray-like object', function test( t ) { var values; var x; var i; @@ -101,7 +179,70 @@ tape( 'the function throws an error if provided an output argument which is not function badValue( value ) { return function badValue() { - joinBetween( x, value ); + joinBetween( x, sep, value ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is not an ndarray-like object (options)', 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, sep, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a separators ndarray which is not broadcast-compatible', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + y = empty( [ 2 ], 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 incompatible separators' ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + joinBetween( x, value, y ); }; } }); @@ -136,7 +277,141 @@ tape( 'the function throws an error if provided an options argument which is not function badValue( value ) { return function badValue() { - joinBetween( x, y, value ); + joinBetween( x, sep, y, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which is not an array-like object of integers', 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, + [ '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() { + joinBetween( x, sep, y, { + 'dims': 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 y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + y = empty( [], { + '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, sep, y, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + y = empty( [], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 1, 2 ], + [ 0, 1, 2, 3 ] + ]; + 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, sep, y, { + '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 y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + y = empty( [], { + '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, sep, y, { + 'dims': value + }); }; } }); @@ -154,7 +429,34 @@ tape( 'the function joins elements and assigns results to an output ndarray (def 'dtype': 'generic' }); - actual = joinBetween( x, out ); + actual = joinBetween( x, sep, 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 joins elements and assigns results to an output ndarray (default, 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( [], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = joinBetween( x, sep, out ); expected = '1,2,3,4'; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); @@ -167,6 +469,104 @@ tape( 'the function joins elements and assigns results to an output ndarray (def 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 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( [], { + 'dtype': 'generic' + }); + + actual = joinBetween( x, sep, out, { + 'dims': [ 0, 1 ] + }); + expected = '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(); +}); + +tape( 'the function performs a reduction on an ndarray (all dimensions, 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 = zeros( [], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = joinBetween( x, sep, out, { + 'dims': [ 0, 1 ] + }); + expected = '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(); +}); + +tape( 'the function performs a reduction on an ndarray (no 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, 2 ], { + 'dtype': 'generic' + }); + + actual = joinBetween( x, sep, out, { + 'dims': [] + }); + 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 performs a reduction on an ndarray (no dimensions, 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 = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = joinBetween( x, sep, out, { + 'dims': [] + }); + 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 specifying reduction dimensions (row-major)', function test( t ) { var expected; var actual; @@ -180,29 +580,65 @@ tape( 'the function supports specifying reduction dimensions (row-major)', funct 'dtype': 'generic' }); - actual = joinBetween( x, out, { + actual = joinBetween( x, sep, 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, { + actual = joinBetween( x, sep, out, { + 'dims': [ 1 ] + }); + 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 specifying reduction dimensions (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 = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = joinBetween( x, sep, out, { + 'dims': [ 0 ] + }); + expected = [ '1,3', '2,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); + + out = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = joinBetween( x, sep, 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' ); @@ -222,13 +658,12 @@ tape( 'the function supports specifying a prefix and suffix', function test( t ) 'dtype': 'generic' }); - actual = joinBetween( x, out, { + actual = joinBetween( x, sep, out, { 'dims': [ 1 ], 'prefix': '[ ', - 'suffix': ' ]', - 'separators': [ ', ' ] + 'suffix': ' ]' }); - expected = [ '[ 1, 2 ]', '[ 3, 4 ]' ]; + expected = [ '[ 1,2 ]', '[ 3,4 ]' ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -237,11 +672,13 @@ tape( 'the function supports specifying a prefix and suffix', function test( t ) t.end(); }); -tape( 'the function supports per-pair separators via an array', function test( t ) { +tape( 'the function supports ndarray prefix and suffix (all dimensions)', function test( t ) { var expected; var actual; var xbuf; var out; + var p; + var s; var x; xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; @@ -250,8 +687,125 @@ tape( 'the function supports per-pair separators via an array', function test( t 'dtype': 'generic' }); - actual = joinBetween( x, out, { - 'separators': [ ' + ', ' - ', ' != ' ], + p = scalar2ndarray( '[ ', { + 'dtype': 'generic' + }); + s = scalar2ndarray( ' ]', { + 'dtype': 'generic' + }); + + actual = joinBetween( x, sep, out, { + 'prefix': p, + 'suffix': s + }); + expected = '[ 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(); +}); + +tape( 'the function supports ndarray prefix and suffix (specific dimensions)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var p; + var s; + 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' + }); + + p = scalar2ndarray( '( ', { + 'dtype': 'generic' + }); + s = scalar2ndarray( ' )', { + 'dtype': 'generic' + }); + + actual = joinBetween( x, sep, out, { + 'dims': [ 1 ], + 'prefix': p, + 'suffix': s + }); + 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 throws an error if provided an ndarray prefix which is not zero-dimensional when not specifying dimensions', function test( t ) { + var out; + var x; + var p; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + out = empty( [], { + 'dtype': 'generic' + }); + p = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + t.throws( function badValue() { + joinBetween( x, sep, out, { + 'prefix': p + }); + }, TypeError, 'throws an error' ); + t.end(); +}); + +tape( 'the function throws an error if provided an ndarray suffix which is not zero-dimensional when not specifying dimensions', function test( t ) { + var out; + var x; + var s; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + out = empty( [], { + 'dtype': 'generic' + }); + s = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + t.throws( function badValue() { + joinBetween( x, sep, out, { + 'suffix': s + }); + }, TypeError, 'throws an error' ); + t.end(); +}); + +tape( 'the function supports per-pair separators', function test( t ) { + var expected; + var actual; + var seps; + 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' + }); + + seps = new ndarray( 'generic', [ ' + ', ' - ', ' != ' ], [ 3 ], [ 1 ], 0, 'row-major' ); + + actual = joinBetween( x, seps, out, { 'prefix': 'op: ', 'suffix': '' }); 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 index ca3901817b7d..01209a1a1137 100644 --- 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 @@ -22,6 +22,7 @@ var tape = require( 'tape' ); var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var zeros = require( '@stdlib/ndarray/zeros' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); @@ -31,6 +32,13 @@ var getOrder = require( '@stdlib/ndarray/order' ); var joinBetween = require( './../lib' ); +// VARIABLES // + +var sep = scalar2ndarray( ',', { + 'dtype': 'generic' +}); + + // TESTS // tape( 'main export is a function', function test( t ) { @@ -62,7 +70,7 @@ tape( 'the function throws an error if provided a first argument which is not an function badValue( value ) { return function badValue() { - joinBetween( value ); + joinBetween( value, sep ); }; } }); @@ -90,12 +98,12 @@ tape( 'the function throws an error if provided a first argument which is not an function badValue( value ) { return function badValue() { - joinBetween( value, {} ); + joinBetween( value, sep, {} ); }; } }); -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object', function test( t ) { var values; var x; var i; @@ -106,12 +114,14 @@ tape( 'the function throws an error if provided an options argument which is not values = [ '5', + 5, NaN, true, false, null, void 0, [], + {}, function noop() {} ]; for ( i = 0; i < values.length; i++ ) { @@ -126,6 +136,99 @@ tape( 'the function throws an error if provided an options argument which is not } }); +tape( 'the function throws an error if provided a separators ndarray which is not broadcast-compatible', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], 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 incompatible separators' ); + } + 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 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, sep, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which is not an array-like object of integers', 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() { + joinBetween( x, sep, { + 'dims': 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; @@ -147,7 +250,34 @@ tape( 'the function throws an error if provided a `dims` option which contains o function badValue( value ) { return function badValue() { - joinBetween( x, { + joinBetween( x, sep, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 1, 2 ], + [ 0, 1, 2, 3 ] + ]; + 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, sep, { 'dims': value }); }; @@ -176,7 +306,7 @@ tape( 'the function throws an error if provided a `dims` option which contains d function badValue( value ) { return function badValue() { - joinBetween( x, { + joinBetween( x, sep, { 'dims': value }); }; @@ -192,7 +322,7 @@ tape( 'the function returns an ndarray created by joining elements of an input n xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - actual = joinBetween( x ); + actual = joinBetween( x, sep ); expected = '1,2,3,4'; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); @@ -213,7 +343,7 @@ tape( 'the function returns an ndarray created by joining elements of an input n xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); - actual = joinBetween( x ); + actual = joinBetween( x, sep ); expected = '1,2,3,4'; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); @@ -234,7 +364,7 @@ tape( 'the function performs a reduction on an ndarray (all dimensions, row-majo xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - actual = joinBetween( x, { + actual = joinBetween( x, sep, { 'dims': [ 0, 1 ] }); expected = '1,2,3,4'; @@ -244,7 +374,7 @@ tape( 'the function performs a reduction on an ndarray (all dimensions, row-majo t.deepEqual( getShape( actual ), [], 'returns expected value' ); t.deepEqual( actual.get(), expected, 'returns expected value' ); - actual = joinBetween( x, { + actual = joinBetween( x, sep, { 'dims': [ 0, 1 ], 'keepdims': true }); @@ -257,6 +387,84 @@ tape( 'the function performs a reduction on an ndarray (all dimensions, row-majo t.end(); }); +tape( 'the function performs a reduction on an ndarray (all dimensions, 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 = joinBetween( x, sep, { + '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, sep, { + '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 performs a reduction on an ndarray (no 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, sep, { + 'dims': [], + 'keepdims': false + }); + 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, 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a reduction on an ndarray (no dimensions, 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 = joinBetween( x, sep, { + 'dims': [], + 'keepdims': false + }); + 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, 2 ], '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; @@ -266,7 +474,7 @@ tape( 'the function supports specifying reduction dimensions (row-major)', funct xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - actual = joinBetween( x, { + actual = joinBetween( x, sep, { 'dims': [ 0 ] }); expected = [ '1,3', '2,4' ]; @@ -275,7 +483,7 @@ tape( 'the function supports specifying reduction dimensions (row-major)', funct t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - actual = joinBetween( x, { + actual = joinBetween( x, sep, { 'dims': [ 1 ] }); expected = [ '1,2', '3,4' ]; @@ -284,7 +492,7 @@ tape( 'the function supports specifying reduction dimensions (row-major)', funct t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - actual = joinBetween( x, { + actual = joinBetween( x, sep, { 'dims': [ 0 ], 'keepdims': true }); @@ -294,23 +502,41 @@ tape( 'the function supports specifying reduction dimensions (row-major)', funct t.deepEqual( getShape( actual ), [ 1, 2 ], 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + actual = joinBetween( x, sep, { + 'dims': [ 1 ], + 'keepdims': true + }); + expected = [ [ '1,2' ], [ '3,4' ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 1 ], '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 ) { +tape( 'the function supports specifying reduction dimensions (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, 'row-major' ); + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); - actual = joinBetween( x, { - 'dims': [ 1 ], - 'separators': [ '|' ] + actual = joinBetween( x, sep, { + '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, sep, { + 'dims': [ 1 ] }); - expected = [ '1|2', '3|4' ]; + expected = [ '1,2', '3,4' ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); @@ -319,7 +545,7 @@ tape( 'the function supports specifying a custom scalar separator (row-major)', t.end(); }); -tape( 'the function supports specifying a prefix and suffix (row-major)', function test( t ) { +tape( 'the function supports specifying a prefix and suffix', function test( t ) { var expected; var actual; var xbuf; @@ -328,25 +554,61 @@ tape( 'the function supports specifying a prefix and suffix (row-major)', functi xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - actual = joinBetween( x, { + actual = joinBetween( x, sep, { 'dims': [ 1 ], 'prefix': '[ ', - 'suffix': ' ]', - 'separators': [ ', ' ] + 'suffix': ' ]' }); - expected = [ '[ 1, 2 ]', '[ 3, 4 ]' ]; + 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': [ '|' ] + t.end(); +}); + +tape( 'the function supports per-pair separators', function test( t ) { + var expected; + var actual; + var seps; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + + seps = new ndarray( 'generic', [ ' + ', ' - ', ' != ' ], [ 3 ], [ 1 ], 0, 'row-major' ); + + actual = joinBetween( x, seps, { + '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 with dims', function test( t ) { + var expected; + var actual; + var seps; + 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' ); + + seps = new ndarray( 'generic', [ ' + ', ' = ' ], [ 2 ], [ 1 ], 0, 'row-major' ); + + actual = joinBetween( x, seps, { + 'dims': [ 1 ] }); - expected = [ '(1|3)', '(2|4)' ]; + expected = [ '1 + 2 = 3', '4 + 5 = 6' ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); @@ -355,21 +617,29 @@ tape( 'the function supports specifying a prefix and suffix (row-major)', functi t.end(); }); -tape( 'the function supports per-pair separators via an array', function test( t ) { +tape( 'the function supports ndarray prefix and suffix (all dimensions)', function test( t ) { var expected; var actual; var xbuf; + var p; + var s; 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': '' + p = scalar2ndarray( '[ ', { + 'dtype': 'generic' }); - expected = 'op: 1 + 2 - 3 != 4'; + s = scalar2ndarray( ' ]', { + 'dtype': 'generic' + }); + + actual = joinBetween( x, sep, { + 'prefix': p, + 'suffix': s + }); + expected = '[ 1,2,3,4 ]'; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), [], 'returns expected value' ); @@ -378,20 +648,89 @@ tape( 'the function supports per-pair separators via an array', function test( t t.end(); }); -tape( 'the function supports per-pair separators via an array with dims', function test( t ) { +tape( 'the function supports ndarray prefix and suffix (specific dimensions)', function test( t ) { var expected; var actual; var xbuf; + var p; + var s; 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' ); + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + p = scalar2ndarray( '( ', { + 'dtype': 'generic' + }); + s = scalar2ndarray( ' )', { + 'dtype': 'generic' + }); - actual = joinBetween( x, { + actual = joinBetween( x, sep, { 'dims': [ 1 ], - 'separators': [ ' + ', ' = ' ] + 'prefix': p, + 'suffix': s }); - expected = [ '1 + 2 = 3', '4 + 5 = 6' ]; + 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 throws an error if provided an ndarray prefix which is not zero-dimensional when not specifying dimensions', function test( t ) { + var x; + var p; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + p = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + t.throws( function badValue() { + joinBetween( x, sep, { + 'prefix': p + }); + }, TypeError, 'throws an error' ); + t.end(); +}); + +tape( 'the function throws an error if provided an ndarray suffix which is not zero-dimensional when not specifying dimensions', function test( t ) { + var x; + var s; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + s = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + t.throws( function badValue() { + joinBetween( x, sep, { + 'suffix': s + }); + }, TypeError, 'throws an error' ); + t.end(); +}); + +tape( 'the function supports negative dimension indices', 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, sep, { + 'dims': [ -1 ] + }); + expected = [ '1,2', '3,4' ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); From 017c8c33f37f9612090a5f784635e72c6ae183b9 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Wed, 15 Apr 2026 10:25:09 +0500 Subject: [PATCH 3/3] fix: apply suggestions from code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../blas/ext/join-between/docs/repl.txt | 14 +++-- .../blas/ext/join-between/lib/assign.js | 3 + .../@stdlib/blas/ext/join-between/lib/main.js | 3 + .../blas/ext/join-between/test/test.assign.js | 62 ++++++++++++++++--- .../blas/ext/join-between/test/test.main.js | 7 --- 5 files changed, 67 insertions(+), 22 deletions(-) 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 index 303b4fc5dfcd..4c8ab5133704 100644 --- a/lib/node_modules/@stdlib/blas/ext/join-between/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/join-between/docs/repl.txt @@ -9,9 +9,10 @@ Input array. separators: ndarray - Separators. Must be broadcast compatible with the shape consisting of - the complement of the shape defined by `options.dims` followed by one - less than the number of elements along the reduced dimensions. + Separators. Must be broadcast compatible with the shape consisting + of the complement of the shape defined by `options.dims` followed + by `N-1` where `N` is the number of elements along the reduced + dimensions. options: Object (optional) Function options. @@ -60,9 +61,10 @@ Input array. separators: ndarray - Separators. Must be broadcast compatible with the shape consisting of - the complement of the shape defined by `options.dims` followed by one - less than the number of elements along the reduced dimensions. + Separators. Must be broadcast compatible with the shape consisting + of the complement of the shape defined by `options.dims` followed + by `N-1` where `N` is the number of elements along the reduced + dimensions. out: ndarray Output array. 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 index 4a47f9b38105..9ef6fbccd5fb 100644 --- a/lib/node_modules/@stdlib/blas/ext/join-between/lib/assign.js +++ b/lib/node_modules/@stdlib/blas/ext/join-between/lib/assign.js @@ -50,8 +50,11 @@ var base = require( './base.js' ).assign; * @throws {TypeError} second argument must be an ndarray-like object * @throws {TypeError} third argument must be an ndarray-like object * @throws {TypeError} options argument must be an object +* @throws {TypeError} a provided `prefix` or `suffix` ndarray must be zero-dimensional when not specifying reduction dimensions * @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} a provided `prefix` or `suffix` ndarray must be broadcast compatible with the complement of the shape defined by `options.dims` +* @throws {Error} a provided `separators` ndarray must be broadcast compatible with the shape consisting of the complement of the shape defined by `options.dims` followed by `N-1` where `N` is the number of elements along the reduced dimensions * @throws {Error} must provide valid options * @returns {ndarray} output ndarray * 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 index 9a22c6efab34..1a9ea8e57997 100644 --- a/lib/node_modules/@stdlib/blas/ext/join-between/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/join-between/lib/main.js @@ -49,8 +49,11 @@ var base = require( './base.js' ); * @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 {TypeError} a provided `prefix` or `suffix` ndarray must be zero-dimensional when not specifying reduction dimensions * @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} a provided `prefix` or `suffix` ndarray must be broadcast compatible with the complement of the shape defined by `options.dims` +* @throws {Error} a provided `separators` ndarray must be broadcast compatible with the shape consisting of the complement of the shape defined by `options.dims` followed by `N-1` where `N` is the number of elements along the reduced dimensions * @throws {Error} must provide valid options * @returns {ndarray} output ndarray * 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 index 9d6f49ee876d..9fee191b0410 100644 --- 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 @@ -27,9 +27,6 @@ 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; @@ -433,9 +430,6 @@ tape( 'the function joins elements and assigns results to an output ndarray (def 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' ); @@ -460,9 +454,6 @@ tape( 'the function joins elements and assigns results to an output ndarray (def 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' ); @@ -817,3 +808,56 @@ tape( 'the function supports per-pair separators', function test( t ) { t.end(); }); + +tape( 'the function supports per-pair separators with dims', function test( t ) { + var expected; + var actual; + var seps; + var xbuf; + var out; + 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' ); + out = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + seps = new ndarray( 'generic', [ ' + ', ' = ' ], [ 2 ], [ 1 ], 0, 'row-major' ); + + actual = joinBetween( x, seps, out, { + 'dims': [ 1 ] + }); + expected = [ '1 + 2 = 3', '4 + 5 = 6' ]; + + 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 negative dimension indices', 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, sep, out, { + 'dims': [ -1 ] + }); + 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(); +}); 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 index 01209a1a1137..66dc126803d4 100644 --- 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 @@ -26,7 +26,6 @@ var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); 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' ); @@ -326,7 +325,6 @@ tape( 'the function returns an ndarray created by joining elements of an input n 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' ); @@ -347,7 +345,6 @@ tape( 'the function returns an ndarray created by joining elements of an input n 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' ); @@ -370,7 +367,6 @@ tape( 'the function performs a reduction on an ndarray (all dimensions, row-majo 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' ); @@ -402,7 +398,6 @@ tape( 'the function performs a reduction on an ndarray (all dimensions, column-m 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' ); @@ -435,7 +430,6 @@ tape( 'the function performs a reduction on an ndarray (no dimensions, row-major 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, 2 ], 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -458,7 +452,6 @@ tape( 'the function performs a reduction on an ndarray (no dimensions, column-ma 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, 2 ], 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' );