From 25f3c66d2bb084ec864a58e6a5824fd079d27922 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Fri, 12 Dec 2025 22:00:27 +0500 Subject: [PATCH 1/4] feat: add blas/ext/join --- 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/README.md | 204 ++++++ .../ext/join/benchmark/benchmark.assign.js | 113 ++++ .../blas/ext/join/benchmark/benchmark.js | 105 +++ .../@stdlib/blas/ext/join/docs/repl.txt | 93 +++ .../blas/ext/join/docs/types/index.d.ts | 166 +++++ .../@stdlib/blas/ext/join/docs/types/test.ts | 220 ++++++ .../@stdlib/blas/ext/join/examples/index.js | 41 ++ .../@stdlib/blas/ext/join/lib/assign.js | 152 +++++ .../@stdlib/blas/ext/join/lib/base.js | 99 +++ .../@stdlib/blas/ext/join/lib/index.js | 71 ++ .../@stdlib/blas/ext/join/lib/main.js | 139 ++++ .../@stdlib/blas/ext/join/package.json | 65 ++ .../@stdlib/blas/ext/join/test/test.assign.js | 632 ++++++++++++++++++ .../@stdlib/blas/ext/join/test/test.js | 39 ++ .../@stdlib/blas/ext/join/test/test.main.js | 520 ++++++++++++++ 15 files changed, 2659 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/join/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/join/benchmark/benchmark.assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/join/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/join/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/join/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/join/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/join/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/join/lib/assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/join/lib/base.js create mode 100644 lib/node_modules/@stdlib/blas/ext/join/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/join/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/join/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/join/test/test.assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/join/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/join/test/test.main.js diff --git a/lib/node_modules/@stdlib/blas/ext/join/README.md b/lib/node_modules/@stdlib/blas/ext/join/README.md new file mode 100644 index 000000000000..bda60ce9b5a0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/README.md @@ -0,0 +1,204 @@ + + +# join + +> Return an [ndarray][@stdlib/ndarray/ctor] created by joining elements using a specified separator along an [ndarray][@stdlib/ndarray/ctor] dimension. + +
+ +## Usage + +```javascript +var join = require( '@stdlib/blas/ext/join' ); +``` + +#### join( x, separator\[, options] ) + +Returns an [ndarray][@stdlib/ndarray/ctor] created by joining elements using a specified separator along an [ndarray][@stdlib/ndarray/ctor] dimension. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +// Create an input ndarray: +var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +// returns + +// Perform operation: +var out = join( x, ',' ); +// returns + +var v = out.get(); +// returns '1,2,3,4,5,6' +``` + +The function has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have at least one dimension. +- **separator**: separator. May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] with generic [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the non-reduced dimensions of the input [ndarray][@stdlib/ndarray/ctor]. For example, given the input shape `[2, 3, 4]` and `options.dim=0`, the separator [ndarray][@stdlib/ndarray/ctor] must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. +- **options**: function options (_optional_). + +The function accepts the following options: + +- **dim**: dimension over which to perform operation. If provided a negative integer, the dimension along which to perform the operation is determined by counting backward from the last dimension (where `-1` refers to the last dimension). Default: `-1`. +- **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 performs the operation over elements in the last dimension. To perform the operation over a different dimension, provide a `dim` option. + +```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); + +var out = join( x, ',', { + 'dim': 0 +}); +// returns + +var v = ndarray2array( out ); +// 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 ndarray2array = require( '@stdlib/ndarray/to-array' ); + +var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); + +var opts = { + 'dim': 0, + 'keepdims': true +}; + +var out = join( x, ',', opts ); +// returns + +var v = ndarray2array( out ); +// returns [ [ '1,3', '2,4' ] ] +``` + +#### join.assign( x, separator, out\[, options] ) + +Joins elements of an input [ndarray][@stdlib/ndarray/ctor] using a specified separator along an [ndarray][@stdlib/ndarray/ctor] dimension and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor]. + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var empty = require( '@stdlib/ndarray/empty' ); + +var x = array( [ 1.0, 2.0, 3.0, 4.0 ], { + 'dtype': 'generic' +}); +var y = empty( [], { + 'dtype': 'generic' +}); + +var out = join.assign( x, ',', y ); +// returns + +var v = out.get(); +// returns '1,2,3,4' + +var bool = ( out === y ); +// returns true +``` + +The method has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have at least one dimension. +- **separator**: separator. May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] with generic [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the non-reduced dimensions of the input [ndarray][@stdlib/ndarray/ctor]. For example, given the input shape `[2, 3, 4]` and `options.dim=0`, the separator [ndarray][@stdlib/ndarray/ctor] must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. +- **out**: output [ndarray][@stdlib/ndarray/ctor]. +- **options**: function options (_optional_). + +The method accepts the following options: + +- **dim**: dimension over which to perform operation. If provided a negative integer, the dimension along which to perform the operation is determined by counting backward from the last dimension (where `-1` refers to the last dimension). Default: `-1`. + +
+ + + +
+ +## Notes + +- Setting the `keepdims` option to `true` can be useful when wanting to ensure that the output [ndarray][@stdlib/ndarray/ctor] is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with ndarrays having the same shape as the input [ndarray][@stdlib/ndarray/ctor]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var join = require( '@stdlib/blas/ext/join' ); + +// Generate an array of random numbers: +var xbuf = discreteUniform( 10, 0, 20, { + 'dtype': 'float64' +}); + +// Wrap in an ndarray: +var x = new ndarray( 'float64', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +// Perform operation: +var out = join( x, ',', { + 'dim': 0 +}); + +// Print the results: +console.log( ndarray2array( out ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/join/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/blas/ext/join/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..444a1ed78e87 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/benchmark/benchmark.assign.js @@ -0,0 +1,113 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var empty = require( '@stdlib/ndarray/empty' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var join = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var out; + var x; + + x = uniform( len, -50.0, 50.0, options ); + x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' ); + + out = empty( [], { + 'dtype': 'generic' + }); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var o; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = join.assign( x, ',', out ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( o.get() ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':assign:dtype='+options.dtype+',len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/join/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/join/benchmark/benchmark.js new file mode 100644 index 000000000000..453d2f9ec09e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/benchmark/benchmark.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var join = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -50.0, 50.0, options ); + x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var o; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = join( x, ',' ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( o.get() ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':dtype='+options.dtype+',len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/join/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/join/docs/repl.txt new file mode 100644 index 000000000000..571cd179ac9c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/docs/repl.txt @@ -0,0 +1,93 @@ + +{{alias}}( x, separator[, options] ) + Returns an ndarray created by joining elements using a specified separator + along an ndarray dimension. + + Parameters + ---------- + x: ndarray + Input array. Must have at least one dimension. + + separator: ndarray|any + Separator. May be either a scalar value or an ndarray. If provided + a scalar value, the value is cast to the generic data type. If provided + an ndarray, the value must have a shape which is broadcast compatible + with the non-reduced dimensions of the input ndarray. For example, given + the input shape `[2, 3, 4]` and `options.dim=0`, the separator + ndarray must have a shape which is broadcast-compatible with the shape + `[3, 4]`. + + options: Object (optional) + Function options. + + options.dim: integer (optional) + Dimension over which to perform a reduction. If provided a negative + integer, the dimension along which to perform the operation is + determined by counting backward from the last dimension (where -1 refers + to the last dimension). Default: -1. + + options.keepdims: boolean (optional) + Boolean indicating whether the reduced dimensions should be included in + the returned ndarray as singleton dimensions. Default: false. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var y = {{alias}}( x, ',' ); + > var v = y.get() + '1,2,3,4' + + +{{alias}}.assign( x, separator, out[, options] ) + Joins elements of an input ndarray using a specified separator along an + ndarray dimension and assigns results to a provided output ndarray. + + Parameters + ---------- + x: ndarray + Input array. Must have at least one dimension. + + separator: ndarray|any + Separator. May be either a scalar value or an ndarray. If provided + a scalar value, the value is cast to the generic data type. If provided + an ndarray, the value must have a shape which is broadcast compatible + with the non-reduced dimensions of the input ndarray. For example, given + the input shape `[2, 3, 4]` and `options.dim=0`, the separator + ndarray must have a shape which is broadcast-compatible with the shape + `[3, 4]`. + + out: ndarray + Output array. + + options: Object (optional) + Function options. + + options.dim: integer (optional) + Dimension over which to perform a reduction. If provided a negative + integer, the dimension along which to perform the operation is + determined by counting backward from the last dimension (where -1 refers + to the last dimension). Default: -1. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, 2.0, 3.0, 4.0 ], { 'dtype': 'generic' } ); + > var out = {{alias:@stdlib/ndarray/zeros}}( [], { 'dtype': 'generic' } ); + > var y = {{alias}}.assign( x, ',', out ) + + > var bool = ( out === y ) + true + > var v = out.get() + '1,2,3,4' + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/join/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/join/docs/types/index.d.ts new file mode 100644 index 000000000000..8c1a2b38ae57 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/docs/types/index.d.ts @@ -0,0 +1,166 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { genericndarray, typedndarray } from '@stdlib/types/ndarray'; + +/** +* Input array. +*/ +type InputArray = typedndarray; + +/** +* Separator. +*/ +type Separator = genericndarray | U; + +/** +* Output array. +*/ +type OutputArray = genericndarray; + +/** +* Interface defining "base" options. +*/ +interface BaseOptions { + /** + * Dimension over which to perform operation. Default: `-1`. + * + * ## Notes + * + * - If provided a negative integer, the dimension along which to perform the operation is determined by counting backward from the last dimension (where `-1` refers to the last dimension). + */ + dim?: number; +} + +/** +* Interface defining options. +*/ +interface Options extends BaseOptions { + /** + * Boolean indicating whether the reduced dimensions should be included in the returned array as singleton dimensions. Default: `false`. + */ + keepdims?: boolean; +} + + +/** +* Interface describing `join`. +*/ +interface Join { + /** + * Returns an ndarray created by joining elements using a specified separator along an ndarray dimension. + * + * @param x - input ndarray + * @param separator - separator + * @param options - function options + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ 1.0, 2.0, 3.0 ] ); + * + * var y = join( x, ',' ); + * // returns + * + * var idx = y.get(); + * // returns '1,2,3' + */ + ( x: InputArray, separator: Separator, options?: Options ): OutputArray; + + /** + * Joins elements of an input ndarray using a specified separator along an ndarray dimension and assigns results to a provided output ndarray. + * + * @param x - input ndarray + * @param separator - separator + * @param out - output ndarray + * @param options - function options + * @returns output ndarray + * + * @example + * var empty = require( '@stdlib/ndarray/empty' ); + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ 1.0, 2.0, 3.0 ], { + * 'dtype': 'generic' + * }); + * var y = empty( [], { + * 'dtype': 'generic' + * }); + * + * var out = join.assign( x, ',', y ); + * // returns + * + * var bool = ( out === y ); + * // returns true + * + * var idx = out.get(); + * // returns '1,2,3' + */ + assign( x: InputArray, Separator: Separator, out: V, options?: BaseOptions ): V; +} + +/** +* Returns an ndarray created by joining elements using a specified separator along an ndarray dimension. +* +* @param x - input ndarray +* @param separator - separator +* @param options - function options +* @returns output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ 1.0, 2.0, 3.0 ] ); +* +* var y = join( x, ',' ); +* // returns +* +* var idx = y.get(); +* // returns '1,2,3' +* +* @example +* var empty = require( '@stdlib/ndarray/empty' ); +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ 1.0, 2.0, 3.0 ], { +* 'dtype': 'generic' +* }); +* var y = empty( [], { +* 'dtype': 'generic' +* }); +* +* var out = join.assign( x, ',', y ); +* // returns +* +* var bool = ( out === y ); +* // returns true +* +* var idx = out.get(); +* // returns '1,2,3' +*/ +declare const join: Join; + + +// EXPORTS // + +export = join; diff --git a/lib/node_modules/@stdlib/blas/ext/join/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/join/docs/types/test.ts new file mode 100644 index 000000000000..21b88311714b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/docs/types/test.ts @@ -0,0 +1,220 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable @typescript-eslint/no-unused-expressions, space-in-parens */ + +/// + +import zeros = require( '@stdlib/ndarray/zeros' ); +import empty = require( '@stdlib/ndarray/empty' ); +import join = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + join( x, ',' ); // $ExpectType OutputArray + join( x, ',', {} ); // $ExpectType OutputArray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + join( '5', ',' ); // $ExpectError + join( 5, ',' ); // $ExpectError + join( true, ',' ); // $ExpectError + join( false, ',' ); // $ExpectError + join( null, ',' ); // $ExpectError + join( void 0, ',' ); // $ExpectError + join( {}, ',' ); // $ExpectError + join( ( x: number ): number => x, ',' ); // $ExpectError + + join( '5', ',', {} ); // $ExpectError + join( 5, ',', {} ); // $ExpectError + join( true, ',', {} ); // $ExpectError + join( false, ',', {} ); // $ExpectError + join( null, ',', {} ); // $ExpectError + join( void 0, ',', {} ); // $ExpectError + join( {}, ',', {} ); // $ExpectError + join( ( x: number ): number => x, ',', {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an options argument which is not an object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + join( x, ',', '5' ); // $ExpectError + join( x, ',', true ); // $ExpectError + join( x, ',', false ); // $ExpectError + join( x, ',', [] ); // $ExpectError + join( x, ',', ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dim` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + join( x, ',', { 'dim': '5' } ); // $ExpectError + join( x, ',', { 'dim': true } ); // $ExpectError + join( x, ',', { 'dim': false } ); // $ExpectError + join( x, ',', { 'dim': null } ); // $ExpectError + join( x, ',', { 'dim': [] } ); // $ExpectError + join( x, ',', { 'dim': {} } ); // $ExpectError + join( x, ',', { 'dim': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `keepdims` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + join( x, ',', { 'keepdims': '5' } ); // $ExpectError + join( x, ',', { 'keepdims': 5 } ); // $ExpectError + join( x, ',', { 'keepdims': null } ); // $ExpectError + join( x, ',', { 'keepdims': {} } ); // $ExpectError + join( x, ',', { 'keepdims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + join(); // $ExpectError + join( x, ',', {}, {} ); // $ExpectError +} + +// Attached to the function is an `assign` method which returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = empty( [], { + 'dtype': 'generic' + }); + + join.assign( x, ',', y ); // $ExpectType genericndarray + join.assign( x, ',', y, {} ); // $ExpectType genericndarray +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not an ndarray... +{ + const y = zeros( [], { + 'dtype': 'generic' + }); + + join.assign( '5', ',', y ); // $ExpectError + join.assign( 5, ',', y ); // $ExpectError + join.assign( true, ',', y ); // $ExpectError + join.assign( false, ',', y ); // $ExpectError + join.assign( null, ',', y ); // $ExpectError + join.assign( void 0, ',', y ); // $ExpectError + join.assign( {}, ',', y ); // $ExpectError + join.assign( ( x: number ): number => x, ',', y ); // $ExpectError + + join.assign( '5', ',', y, {} ); // $ExpectError + join.assign( 5, ',', y, {} ); // $ExpectError + join.assign( true, ',', y, {} ); // $ExpectError + join.assign( false, ',', y, {} ); // $ExpectError + join.assign( null, ',', y, {} ); // $ExpectError + join.assign( void 0, ',', y, {} ); // $ExpectError + join.assign( {}, ',', y, {} ); // $ExpectError + join.assign( ( x: number ): number => x, ',', y, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a output argument which is not an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + join.assign( x, ',', '5' ); // $ExpectError + join.assign( x, ',', 5 ); // $ExpectError + join.assign( x, ',', true ); // $ExpectError + join.assign( x, ',', false ); // $ExpectError + join.assign( x, ',', null ); // $ExpectError + join.assign( x, ',', void 0 ); // $ExpectError + join.assign( x, ',', ( x: number ): number => x ); // $ExpectError + + join.assign( x, ',', '5', {} ); // $ExpectError + join.assign( x, ',', 5, {} ); // $ExpectError + join.assign( x, ',', true, {} ); // $ExpectError + join.assign( x, ',', false, {} ); // $ExpectError + join.assign( x, ',', null, {} ); // $ExpectError + join.assign( x, ',', void 0, {} ); // $ExpectError + join.assign( x, ',', ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an options argument which is not an object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [], { + 'dtype': 'generic' + }); + + join.assign( x, ',', y, '5' ); // $ExpectError + join.assign( x, ',', y, true ); // $ExpectError + join.assign( x, ',', y, false ); // $ExpectError + join.assign( x, ',', y, null ); // $ExpectError + join.assign( x, ',', y, [] ); // $ExpectError + join.assign( x, ',', y, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an invalid `dim` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [], { + 'dtype': 'generic' + }); + + join.assign( x, ',', y, { 'dim': '5' } ); // $ExpectError + join.assign( x, ',', y, { 'dim': true } ); // $ExpectError + join.assign( x, ',', y, { 'dim': false } ); // $ExpectError + join.assign( x, ',', y, { 'dim': null } ); // $ExpectError + join.assign( x, ',', y, { 'dim': [] } ); // $ExpectError + join.assign( x, ',', y, { 'dim': {} } ); // $ExpectError + join.assign( x, ',', y, { 'dim': ( 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 = zeros( [], { + 'dtype': 'generic' + }); + + join.assign(); // $ExpectError + join.assign( x ); // $ExpectError + join.assign( x, ',', y, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/join/examples/index.js b/lib/node_modules/@stdlib/blas/ext/join/examples/index.js new file mode 100644 index 000000000000..ce07350bb05c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/examples/index.js @@ -0,0 +1,41 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var join = require( './../lib' ); + +// Generate an array of random numbers: +var xbuf = discreteUniform( 10, 0, 20, { + 'dtype': 'float64' +}); + +// Wrap in an ndarray: +var x = new ndarray( 'float64', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +// Perform operation: +var out = join( x, ',', { + 'dim': 0 +}); + +// Print the results: +console.log( ndarray2array( out ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/join/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/join/lib/assign.js new file mode 100644 index 000000000000..33a6abbc2747 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/lib/assign.js @@ -0,0 +1,152 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable stdlib/jsdoc-doctest */ + +'use strict'; + +// MODULES // + +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); +var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' ); +var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ).assign; + + +// MAIN // + +/** +* Joins elements of an input ndarray using a specified separator along an ndarray dimension and assigns the results to a provided output ndarray. +* +* @param {ndarrayLike} x - input ndarray +* @param {(ndarrayLike|*)} separator - separator +* @param {ndarrayLike} out - output ndarray +* @param {Options} [options] - function options +* @param {integer} [options.dim=-1] - dimension over which to perform operation +* @throws {TypeError} function must be provided at least three arguments +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} second argument must be either an ndarray-like object or a scalar value +* @throws {TypeError} third argument must be an ndarray-like object +* @throws {TypeError} third argument must be an ndarray-like object having the generic data type +* @throws {TypeError} options argument must be an object +* @throws {RangeError} dimension index must not exceed input ndarray bounds +* @throws {RangeError} first argument must have at least one dimension +* @throws {Error} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var empty = require( '@stdlib/ndarray/empty' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 2, 3 ]; +* +* // Define the array strides: +* var strides = [ 3, 1 ]; +* +* // Define the index offset: +* var offset = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, shape, strides, offset, 'row-major' ); +* +* // Create an output ndarray: +* var y = empty( [ 2 ], { +* 'dtype': 'generic' +* }); +* +* // Perform operation: +* var out = assign( x, ',', y ); +* // returns +* +* var bool = ( out === y ); +* // returns true +* +* var arr = ndarray2array( out ); +* // returns [ '1,2,3', '4,5,6' ] +*/ +function assign( x, separator, out, options ) { + var nargs; + var opts; + var ord; + var sh; + var s; + + nargs = arguments.length; + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + } + if ( nargs < 3 ) { + throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); + } + // Resolve input ndarray meta data: + ord = getOrder( x ); + + if ( getDType( out ) !== 'generic' ) { + throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object having the generic data type. Value: `%s`.', out ) ); + } + + // Initialize an options object: + opts = { + 'dims': [ -1 ] // default behavior is to perform a reduction over the last dimension + }; + + if ( nargs > 3 ) { + if ( !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + // Resolve provided options... + if ( hasOwnProp( options, 'dim' ) ) { + opts.dims[ 0 ] = options.dim; + } + } + // Resolve the list of non-reduced dimensions: + sh = getShape( x ); + if ( sh.length < 1 ) { + throw new RangeError( 'invalid argument. First argument must have at least one dimension.' ); + } + sh = nonCoreShape( sh, opts.dims ); + + // Broadcast the separator to match the shape of the non-reduced dimensions... + if ( isndarrayLike( separator ) ) { + if ( getDType( separator ) !== 'generic' ) { + throw new TypeError( format( 'invalid argument. Second argument must have a generic data type. Value: `%s`.', separator ) ); + } + s = maybeBroadcastArray( separator, sh ); + } else { + s = broadcastScalar( separator, 'generic', sh, ord ); + } + return base( x, s, out, opts ); +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/blas/ext/join/lib/base.js b/lib/node_modules/@stdlib/blas/ext/join/lib/base.js new file mode 100644 index 000000000000..2b78af3f4d3d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/lib/base.js @@ -0,0 +1,99 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var dtypes = require( '@stdlib/ndarray/dtypes' ); +var gjoin = require( '@stdlib/blas/ext/base/ndarray/gjoin' ); +var factory = require( '@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-factory' ); + + +// VARIABLES // + +var idtypes0 = dtypes( 'all' ); // input ndarray +var idtypes1 = dtypes( 'all' ); // separator ndarray +var odtypes = dtypes( 'all' ); +var policies = { + 'output': 'same', + 'casting': 'promoted' +}; +var table = { + 'default': gjoin +}; + + +// MAIN // + +/** +* Returns an ndarray created by joining elements using a specified separator along an ndarray dimension. +* +* @private +* @name join +* @type {Function} +* @param {ndarrayLike} x - input ndarray +* @param {ndarrayLike} separator - separator +* @param {Options} [options] - function options +* @param {IntegerArray} [options.dims] - list of dimensions over which to perform operation +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} second argument must be either an ndarray-like object +* @throws {TypeError} options argument must be an object +* @throws {RangeError} dimension indices must not exceed input ndarray bounds +* @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions +* @throws {Error} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 6 ]; +* +* // Define the array strides: +* var sx = [ 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'generic', xbuf, sh, sx, ox, 'row-major' ); +* +* // Create a separator ndarray: +* var separator = scalar2ndarray( ',', { +* 'dtype': 'generic' +* }) +* +* // Perform operation: +* var out = join( x, separator ); +* // returns +* +* var v = out.get(); +* // returns '1,2,3,4,5,6' +*/ +var join = factory( table, [ idtypes0, idtypes1 ], odtypes, policies ); + + +// EXPORTS // + +module.exports = join; diff --git a/lib/node_modules/@stdlib/blas/ext/join/lib/index.js b/lib/node_modules/@stdlib/blas/ext/join/lib/index.js new file mode 100644 index 000000000000..69e2162520a7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/lib/index.js @@ -0,0 +1,71 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Return an ndarray created by joining elements using a specified separator along an ndarray dimension. +* +* @module @stdlib/blas/ext/join +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var join = require( '@stdlib/blas/ext/join' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 2, 3 ]; +* +* // Define the array strides: +* var sx = [ 3, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Perform operation: +* var out = join( x, ',' ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ '1,2,3', '4,5,6' ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var assign = require( './assign.js' ); + + +// MAIN // + +setReadOnly( main, 'assign', assign ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "assign": "main.assign" } diff --git a/lib/node_modules/@stdlib/blas/ext/join/lib/main.js b/lib/node_modules/@stdlib/blas/ext/join/lib/main.js new file mode 100644 index 000000000000..65b48e6fd281 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/lib/main.js @@ -0,0 +1,139 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); +var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' ); +var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Returns an ndarray created by joining elements using a specified separator along an ndarray dimension. +* +* @param {ndarrayLike} x - input ndarray +* @param {(ndarrayLike|*)} separator - separator +* @param {Options} [options] - function options +* @param {integer} [options.dim=-1] - dimension 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 either an ndarray-like object or a scalar value +* @throws {TypeError} options argument must be an object +* @throws {RangeError} dimension index must not exceed input ndarray bounds +* @throws {RangeError} first argument must have at least one dimension +* @throws {Error} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 2, 3 ]; +* +* // Define the array strides: +* var sx = [ 3, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Perform operation: +* var out = join( x, ',' ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ '1,2,3', '4,5,6' ] +*/ +function join( x, separator, options ) { + var nargs; + var opts; + var ord; + var sh; + var s; + + nargs = arguments.length; + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + } + if ( nargs < 2 ) { + throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray-like object or a scalar value. Value: `%s`.', separator ) ); + } + // Resolve input ndarray meta data: + ord = getOrder( x ); + + // Initialize an options object: + opts = { + 'dims': [ -1 ], // default behavior is to perform a reduction over the last dimension + 'dtype': 'generic', // default behavior is to always return a generic ndarray + 'keepdims': false + }; + + if ( nargs > 2 ) { + if ( !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + // Resolve provided options... + if ( hasOwnProp( options, 'dim' ) ) { + opts.dims[ 0 ] = options.dim; + } + if ( hasOwnProp( options, 'keepdims' ) ) { + opts.keepdims = options.keepdims; + } + } + // Resolve the list of non-reduced dimensions: + sh = getShape( x ); + if ( sh.length < 1 ) { + throw new RangeError( 'invalid argument. First argument must have at least one dimension.' ); + } + sh = nonCoreShape( sh, opts.dims ); + + // Broadcast the separator to match the shape of the non-reduced dimensions... + if ( isndarrayLike( separator ) ) { + if ( getDType( separator ) !== 'generic' ) { + throw new TypeError( format( 'invalid argument. Second argument must have a generic data type. Value: `%s`.', separator ) ); + } + s = maybeBroadcastArray( separator, sh ); + } else { + s = broadcastScalar( separator, 'generic', sh, ord ); + } + return base( x, s, opts ); +} + + +// EXPORTS // + +module.exports = join; diff --git a/lib/node_modules/@stdlib/blas/ext/join/package.json b/lib/node_modules/@stdlib/blas/ext/join/package.json new file mode 100644 index 000000000000..b1ca3ab9d61e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/blas/ext/join", + "version": "0.0.0", + "description": "Return an ndarray created by joining elements using a specified separator along an ndarray dimension.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "extended", + "join", + "string", + "strided", + "array", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/join/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/join/test/test.assign.js new file mode 100644 index 000000000000..0248c2901d0f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/test/test.assign.js @@ -0,0 +1,632 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var empty = require( '@stdlib/ndarray/empty' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var join = require( './../lib' ).assign; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof join, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (separator=scalar)', function test( t ) { + var values; + var i; + var y; + + y = empty( [], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + join( value, ',', y ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (separator=ndarray)', function test( t ) { + var values; + var opts; + var i; + var y; + var s; + + opts = { + 'dtype': 'generic' + }; + y = empty( [], opts ); + s = scalar2ndarray( ',', opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + join( value, s, y ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (separator=scalar, options)', function test( t ) { + var values; + var opts; + var i; + var y; + + opts = { + 'dtype': 'generic' + }; + + y = empty( [], opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + join( value, ',', y, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (separator=ndarray, options)', function test( t ) { + var values; + var opts; + var i; + var y; + var s; + + opts = { + 'dtype': 'generic' + }; + + y = empty( [], opts ); + s = scalar2ndarray( ',', opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + join( value, s, y, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is a zero-dimensional ndarray', function test( t ) { + var values; + var opts; + var i; + var y; + + opts = { + 'dtype': 'generic' + }; + + y = empty( [], opts ); + + values = [ + scalar2ndarray( 10.0 ), + scalar2ndarray( -3.0 ), + scalar2ndarray( 0.0 ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + join( value, ',', y, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an output argument which is not an ndarray-like object', function test( t ) { + var values; + var opts; + var i; + var x; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + join( x, ',', value ); + }; + } +}); + +tape( 'the function throws an error if provided an output argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var opts; + var i; + var x; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + join( x, ',', value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided insufficient number of arguments', function test( t ) { + var x; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + t.throws( badValue1, TypeError, 'throws an error when provided insufficient arguments' ); + t.throws( badValue2, TypeError, 'throws an error when provided insufficient arguments' ); + t.throws( badValue3, TypeError, 'throws an error when provided insufficient arguments' ); + t.end(); + + function badValue1() { + join( x ); + } + + function badValue2() { + join( x, ',' ); + } + + function badValue3() { + join(); + } +}); + +tape( 'the function throws an error if provided a separator which is not broadcast-compatible with the first argument', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + y = empty( [], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + join( x, value, y ); + }; + } +}); + +tape( 'the function throws an error if provided an separator which is not broadcast-compatible with the first argument (options)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + y = empty( [], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + join( x, value, y, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (separator=scalar)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + y = empty( [], opts ); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + join( x, ',', y, value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (separator=ndarray)', function test( t ) { + var values; + var opts; + var x; + var y; + var s; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + y = empty( [], opts ); + s = scalar2ndarray( ',', opts ); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + join( x, s, y, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `dim` option which is not an integer', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + y = empty( [], opts ); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + join( x, ',', y, { + 'dim': value + }); + }; + } +}); + +tape( 'the function joins elements of an input ndarray using a specified separator along an ndarray dimensions and assigns results to an output ndarray (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + out = empty( [ 2 ], { + 'dtype': 'generic' + }); + + actual = join( x, ',', out ); + expected = [ '1,2', '3,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function joins elements of an input ndarray using a specified separator along an ndarray dimensions and assigns results to an output ndarray (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + out = empty( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = join( x, ',', out ); + expected = [ '1,3', '2,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the operation dimension (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + out = empty( [ 2 ], { + 'dtype': 'generic' + }); + + actual = join( x, ',', out, { + 'dim': 0 + }); + expected = [ '1,3', '2,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + out = empty( [ 2 ], { + 'dtype': 'generic' + }); + + actual = join( x, ',', out, { + 'dim': 1 + }); + expected = [ '1,2', '3,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the operation dimension (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + out = empty( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = join( x, ',', out, { + 'dim': 0 + }); + expected = [ '1,3', '2,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + out = empty( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = join( x, ',', out, { + 'dim': 1 + }); + expected = [ '1,2', '3,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/join/test/test.js b/lib/node_modules/@stdlib/blas/ext/join/test/test.js new file mode 100644 index 000000000000..8970ba39e74a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/test/test.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isMethod = require( '@stdlib/assert/is-method' ); +var join = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof join, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( join, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/join/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/join/test/test.main.js new file mode 100644 index 000000000000..7073d9b19cb0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/join/test/test.main.js @@ -0,0 +1,520 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var join = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof join, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (separator=scalar)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + join( value, ',' ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (separator=ndarray)', function test( t ) { + var values; + var s; + var i; + + s = scalar2ndarray( ',', { + 'dtype': 'generic' + }); + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + join( value, s ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (separator=scalar, options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + join( value, ',', {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (separator=ndarray, options)', function test( t ) { + var values; + var i; + var s; + + s = scalar2ndarray( ',', { + 'dtype': 'generic' + }); + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + join( value, s, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is a zero-dimensional ndarray', function test( t ) { + var values; + var i; + + values = [ + scalar2ndarray( 10.0 ), + scalar2ndarray( -3.0 ), + scalar2ndarray( 0.0 ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + join( value, ',', {} ); + }; + } +}); + +tape( 'the function throws an error if provided insufficient number of arguments', function test( t ) { + var x; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + t.throws( badValue1, TypeError, 'throws an error when provided insufficient arguments' ); + t.throws( badValue2, TypeError, 'throws an error when provided insufficient arguments' ); + t.end(); + + function badValue1() { + join( x ); + } + + function badValue2() { + join(); + } +}); + +tape( 'the function throws an error if provided a separator which is not broadcast-compatible with the first argument', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + join( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided an search element which is not broadcast-compatible with the first argument (options)', 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 ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + join( x, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (separator=scalar)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + join( x, ',', value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (separator=ndarray)', function test( t ) { + var values; + var opts; + var x; + var s; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + s = scalar2ndarray( ',', opts ); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + join( x, s, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `dim` option which is not an integer', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + join( x, ',', { + 'dim': value + }); + }; + } +}); + +tape( 'the function returns an ndarray created by joining elements of an input ndarray (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = join( x, ',' ); + expected = [ '1,2', '3,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an ndarray created by joining elements of an input ndarray (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = join( x, ',' ); + expected = [ '1,3', '2,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the operation dimension (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = join( x, ',', { + 'dim': 0 + }); + expected = [ '1,3', '2,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = join( x, ',', { + 'dim': 1 + }); + expected = [ '1,2', '3,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the operation dimension (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + + actual = join( x, ',', { + 'dim': 0 + }); + expected = [ '1,3', '2,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + + actual = join( x, ',', { + 'dim': 1 + }); + expected = [ '1,2', '3,4' ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the `keepdims` option (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = join( x, ',', { + 'keepdims': true + }); + expected = [ [ '1,2' ], [ '3,2' ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 1 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the `keepdims` option (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = join( x, ',', { + 'keepdims': true + }); + expected = [ [ '1,3' ], [ '2,2' ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 1 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); From f24e12541fd496159f9f6cb389a4bd4986447f5b Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Fri, 12 Dec 2025 22:15:42 +0500 Subject: [PATCH 2/4] refactor: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../@stdlib/blas/ext/join/benchmark/benchmark.assign.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/join/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/blas/ext/join/benchmark/benchmark.assign.js index 444a1ed78e87..146e0594105c 100644 --- a/lib/node_modules/@stdlib/blas/ext/join/benchmark/benchmark.assign.js +++ b/lib/node_modules/@stdlib/blas/ext/join/benchmark/benchmark.assign.js @@ -33,7 +33,7 @@ var join = require( './../lib' ); // VARIABLES // var options = { - 'dtype': 'float64' + 'dtype': 'generic' }; From a25a3a4105f1e6f322fab1e7f43f6abd96bb9426 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sat, 13 Dec 2025 09:10:19 +0500 Subject: [PATCH 3/4] chore: apply suggestion from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/blas/ext/join/lib/assign.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/join/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/join/lib/assign.js index 33a6abbc2747..af019c92817c 100644 --- a/lib/node_modules/@stdlib/blas/ext/join/lib/assign.js +++ b/lib/node_modules/@stdlib/blas/ext/join/lib/assign.js @@ -16,7 +16,6 @@ * limitations under the License. */ -/* eslint-disable stdlib/jsdoc-doctest */ 'use strict'; From a945261118dccb6b60b669f47f8946e4aecbc875 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sun, 14 Dec 2025 10:02:00 +0500 Subject: [PATCH 4/4] fix: lint error Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/blas/ext/join/lib/assign.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/join/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/join/lib/assign.js index af019c92817c..dac6646659e0 100644 --- a/lib/node_modules/@stdlib/blas/ext/join/lib/assign.js +++ b/lib/node_modules/@stdlib/blas/ext/join/lib/assign.js @@ -16,7 +16,6 @@ * limitations under the License. */ - 'use strict'; // MODULES //