From 1d02fbfe42223b720698cbecd4431d36642ab0a4 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Wed, 3 Dec 2025 17:52:37 +0500 Subject: [PATCH 01/10] feat: add blas/ext/base/gjoin --- .../@stdlib/blas/ext/base/gjoin/README.md | 178 ++++++++++++++++++ .../ext/base/gjoin/benchmark/benchmark.js | 96 ++++++++++ .../base/gjoin/benchmark/benchmark.ndarray.js | 96 ++++++++++ .../@stdlib/blas/ext/base/gjoin/docs/repl.txt | 77 ++++++++ .../blas/ext/base/gjoin/docs/types/index.d.ts | 96 ++++++++++ .../blas/ext/base/gjoin/docs/types/test.ts | 147 +++++++++++++++ .../blas/ext/base/gjoin/examples/index.js | 30 +++ .../blas/ext/base/gjoin/lib/accessors.js | 77 ++++++++ .../@stdlib/blas/ext/base/gjoin/lib/index.js | 57 ++++++ .../@stdlib/blas/ext/base/gjoin/lib/main.js | 51 +++++ .../blas/ext/base/gjoin/lib/ndarray.js | 74 ++++++++ .../@stdlib/blas/ext/base/gjoin/package.json | 65 +++++++ .../@stdlib/blas/ext/base/gjoin/test/test.js | 38 ++++ .../blas/ext/base/gjoin/test/test.main.js | 145 ++++++++++++++ .../blas/ext/base/gjoin/test/test.ndarray.js | 157 +++++++++++++++ 15 files changed, 1384 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gjoin/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gjoin/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gjoin/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gjoin/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gjoin/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/README.md b/lib/node_modules/@stdlib/blas/ext/base/gjoin/README.md new file mode 100644 index 000000000000..65f39b55a304 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/README.md @@ -0,0 +1,178 @@ + + +# gjoin + +> Return a string created by joining strided array elements using a specified separator. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var gjoin = require( '@stdlib/blas/ext/base/gjoin' ); +``` + +#### gjoin( N, separator, x, strideX ) + +Returns a string created by joining strided array elements using a specified separator. + +```javascript +var x = [ 1.0, 2.0, 3.0, 4.0 ]; + +var str = gjoin( x.length, ',', x, 1 ); +// returns '1,2,3,4' +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **separator**: separator. +- **x**: input array. +- **strideX**: stride length. + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to join every other element: + +```javascript +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + +var str = gjoin( 3, '-', x, 2 ); +// returns '1-3-5' +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial array... +var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + +// Create an offset view... +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +// Join elements... +var str = gjoin( 3, '|', x1, 2 ); +// returns '2|4|6' +``` + +#### gjoin.ndarray( N, separator, x, strideX, offsetX ) + +Returns a string created by joining strided array elements using a specified separator and alternative indexing semantics. + +```javascript +var x = [ 1.0, 2.0, 3.0, 4.0 ]; + +var str = gjoin.ndarray( x.length, ',', x, 1, 0 ); +// returns '1,2,3,4' +``` + +The function has the following additional parameters: + +- **offsetX**: starting index. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of the strided array: + +```javascript +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + +var str = gjoin.ndarray( 3, '|', x, 1, x.length-3 ); +// returns '4|5|6' +``` + +
+ + + + + +
+ +## Notes + +- If `N <= 0`, the function returns an empty string. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). + +
+ + + + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gjoin = require( '@stdlib/blas/ext/base/gjoin' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +console.log( x ); + +var out = gjoin( x.length, ' | ', x, 1 ); +console.log( out ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gjoin/benchmark/benchmark.js new file mode 100644 index 000000000000..d55a91d819ae --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/benchmark/benchmark.js @@ -0,0 +1,96 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var oneTo = require( '@stdlib/array/one-to' ); +var pkg = require( './../package.json' ).name; +var gjoin = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = oneTo( len, 'float64' ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = gjoin( x.length, ',', x, 1 ); + if ( out !== out ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( out ) ) { + b.fail( 'should return a string' ); + } + 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+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gjoin/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..3f5d62ea1b1b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/benchmark/benchmark.ndarray.js @@ -0,0 +1,96 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var oneTo = require( '@stdlib/array/one-to' ); +var pkg = require( './../package.json' ).name; +var gjoin = require( './../lib/ndarray.js' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = oneTo( len, 'float64' ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = gjoin( x.length, ',', x, 1, 0 ); + if ( out !== out ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( out ) ) { + b.fail( 'should return a string' ); + } + 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+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/repl.txt new file mode 100644 index 000000000000..46470f9c8354 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/repl.txt @@ -0,0 +1,77 @@ + +{{alias}}( N, separator, x, strideX ) + Returns a string created by joining strided array elements using a specified + separator. + + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use a typed + array view. + + If `N <= 0`, the function returns an empty string. + + Parameters + ---------- + N: integer + Number of indexed elements. + + separator: any + Separator. + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length. + + Returns + ------- + str: string + Joined string. + + Examples + -------- + > var x = [ 1.0, 2.0, 3.0, 4.0 ]; + > var str = {{alias}}( x.length, ',', x, 1 ) + '1,2,3,4' + + +{{alias}}.ndarray( N, separator, x, strideX, offsetX ) + Returns a string created by joining strided array elements using a specified + separator and alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameter supports indexing semantics based on a starting + index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + separator: any + Separator. + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length. + + offsetX: integer + Starting index. + + Returns + ------- + str: string + Joined string. + + Examples + -------- + > var x = [ 1.0, 2.0, 3.0, 4.0 ]; + > var str = {{alias}}.ndarray( x.length, ',', x, 1, 0 ) + '1,2,3,4' + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/types/index.d.ts new file mode 100644 index 000000000000..375a67c84cc4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/types/index.d.ts @@ -0,0 +1,96 @@ +/* +* @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 { Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = Collection | AccessorArrayLike; + +/** +* Interface describing `gjoin`. +*/ +interface Routine { + /** + * Returns a string created by joining strided array elements using a specified separator. + * + * @param N - number of indexed elements + * @param separator - separator + * @param x - input array + * @param strideX - stride length + * @returns joined string + * + * @example + * var x = [ 1.0, 2.0, 3.0, 4.0 ]; + * + * var str = gjoin( x.length, ',', x, 1 ); + * // returns '1,2,3,4' + */ + ( N: number, separator: unknown, x: InputArray, strideX: number ): string; + + /** + * Returns a string created by joining strided array elements using a specified separator and alternative indexing semantics. + * + * @param N - number of indexed elements + * @param separator - separator + * @param x - input array + * @param strideX - stride length + * @param offsetX - starting index + * @returns joined string + * + * @example + * var x = [ 1.0, 2.0, 3.0, 4.0 ]; + * + * var str = gjoin.ndarray( x.length, ',', x, 1, 0 ); + * // returns '1,2,3,4' + */ + ndarray( N: number, separator: unknown, x: InputArray, strideX: number, offsetX: number ): string; +} + +/** +* Returns a string created by joining strided array elements using a specified separator. +* +* @param N - number of indexed elements +* @param sep - separator +* @param x - input array +* @param strideX - stride length +* @returns joined string +* +* @example +* var x = [ 1.0, 2.0, 3.0, 4.0 ]; +* +* var str = gjoin( x.length, ',', x, 1 ); +* // returns '1,2,3,4' +* +* @example +* var x = [ 1.0, 2.0, 3.0, 4.0 ]; +* +* var str = gjoin.ndarray( x.length, ',', x, 1, 0 ); +* // returns '1,2,3,4' +*/ +declare var gjoin: Routine; + + +// EXPORTS // + +export = gjoin; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/types/test.ts new file mode 100644 index 000000000000..192d6b0b260c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/types/test.ts @@ -0,0 +1,147 @@ +/* +* @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. +*/ + +import gjoin = require( './index' ); + + +// TESTS // + +// The function returns a string... +{ + const x = [ 1, 2, 3, 4 ]; + + gjoin( x.length, ',', x, 1 ); // $ExpectType string +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = [ 1, 2, 3, 4 ]; + + gjoin( '5', ',', x, 1 ); // $ExpectError + gjoin( true, ',', x, 1 ); // $ExpectError + gjoin( false, ',', x, 1 ); // $ExpectError + gjoin( null, ',', x, 1 ); // $ExpectError + gjoin( undefined, ',', x, 1 ); // $ExpectError + gjoin( [], ',', x, 1 ); // $ExpectError + gjoin( {}, ',', x, 1 ); // $ExpectError + gjoin( ( x: number ): number => x, ',', x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not an array-like object... +{ + gjoin( 4, ',', 5, 1 ); // $ExpectError + gjoin( 4, ',', true, 1 ); // $ExpectError + gjoin( 4, ',', false, 1 ); // $ExpectError + gjoin( 4, ',', null, 1 ); // $ExpectError + gjoin( 4, ',', undefined, 1 ); // $ExpectError + gjoin( 4, ',', {}, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = [ 1, 2, 3, 4 ]; + + gjoin( x.length, ',', x, '5' ); // $ExpectError + gjoin( x.length, ',', x, true ); // $ExpectError + gjoin( x.length, ',', x, false ); // $ExpectError + gjoin( x.length, ',', x, null ); // $ExpectError + gjoin( x.length, ',', x, undefined ); // $ExpectError + gjoin( x.length, ',', x, [] ); // $ExpectError + gjoin( x.length, ',', x, {} ); // $ExpectError + gjoin( x.length, ',', x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + const x = [ 1, 2, 3, 4 ]; + + gjoin(); // $ExpectError + gjoin( x.length ); // $ExpectError + gjoin( x.length, ',' ); // $ExpectError + gjoin( x.length, ',', x ); // $ExpectError +} + +// Attached to the main export is an `ndarray` method which returns a string... +{ + const x = [ 1, 2, 3, 4 ]; + + gjoin.ndarray( x.length, ',', x, 1, 0 ); // $ExpectType string +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = [ 1, 2, 3, 4 ]; + + gjoin.ndarray( '5', ',', x, 1, 0 ); // $ExpectError + gjoin.ndarray( true, ',', x, 1, 0 ); // $ExpectError + gjoin.ndarray( false, ',', x, 1, 0 ); // $ExpectError + gjoin.ndarray( null, ',', x, 1, 0 ); // $ExpectError + gjoin.ndarray( undefined, ',', x, 1, 0 ); // $ExpectError + gjoin.ndarray( [], ',', x, 1, 0 ); // $ExpectError + gjoin.ndarray( {}, ',', x, 1, 0 ); // $ExpectError + gjoin.ndarray( ( x: number ): number => x, ',', x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not an array-like object... +{ + gjoin.ndarray( 4, ',', 5, 1, 0 ); // $ExpectError + gjoin.ndarray( 4, ',', true, 1, 0 ); // $ExpectError + gjoin.ndarray( 4, ',', false, 1, 0 ); // $ExpectError + gjoin.ndarray( 4, ',', null, 1, 0 ); // $ExpectError + gjoin.ndarray( 4, ',', undefined, 1, 0 ); // $ExpectError + gjoin.ndarray( 4, ',', {}, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = [ 1, 2, 3, 4 ]; + + gjoin.ndarray( x.length, ',', x, '5', 0 ); // $ExpectError + gjoin.ndarray( x.length, ',', x, true, 0 ); // $ExpectError + gjoin.ndarray( x.length, ',', x, false, 0 ); // $ExpectError + gjoin.ndarray( x.length, ',', x, null, 0 ); // $ExpectError + gjoin.ndarray( x.length, ',', x, undefined, 0 ); // $ExpectError + gjoin.ndarray( x.length, ',', x, [], 0 ); // $ExpectError + gjoin.ndarray( x.length, ',', x, {}, 0 ); // $ExpectError + gjoin.ndarray( x.length, ',', x, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = [ 1, 2, 3, 4 ]; + + gjoin.ndarray( x.length, ',', x, 1, '5' ); // $ExpectError + gjoin.ndarray( x.length, ',', x, 1, true ); // $ExpectError + gjoin.ndarray( x.length, ',', x, 1, false ); // $ExpectError + gjoin.ndarray( x.length, ',', x, 1, null ); // $ExpectError + gjoin.ndarray( x.length, ',', x, 1, undefined ); // $ExpectError + gjoin.ndarray( x.length, ',', x, 1, [] ); // $ExpectError + gjoin.ndarray( x.length, ',', x, 1, {} ); // $ExpectError + gjoin.ndarray( x.length, ',', x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided insufficient arguments... +{ + const x = [ 1, 2, 3, 4 ]; + + gjoin.ndarray(); // $ExpectError + gjoin.ndarray( x.length ); // $ExpectError + gjoin.ndarray( x.length, ',' ); // $ExpectError + gjoin.ndarray( x.length, ',', x ); // $ExpectError + gjoin.ndarray( x.length, ',', x, 1 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gjoin/examples/index.js new file mode 100644 index 000000000000..e91bd7c389b7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/examples/index.js @@ -0,0 +1,30 @@ +/** +* @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 gjoin = require( './../lib' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +console.log( x ); + +var out = gjoin( x.length, ' | ', x, 1 ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/accessors.js new file mode 100644 index 000000000000..37487a9fd91b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/accessors.js @@ -0,0 +1,77 @@ +/** +* @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 join = require( '@stdlib/array/base/join' ); + + +// MAIN // + +/** +* Returns a string created by joining strided array elements using a specified separator. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {*} separator - separator +* @param {Object} x - input array object +* @param {Collection} x.data - input array data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {string} joined string +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = [ 1, 2, 3, 4 ]; +* +* var str = gjoin( x.length, ',', arraylike2object( toAccessorArray( x ) ), 1, 0 ); +* // returns '1,2,3,4' +*/ +function gjoin( N, separator, x, strideX, offsetX ) { + var xbuf; + var view; + var get; + var ix; + var i; + + // Cache reference to array data: + xbuf = x.data; + + // Cache a reference to the element accessor: + get = x.accessors[ 0 ]; + + // Create a view of the strided elements + view = []; + ix = offsetX; + for ( i = 0; i < N; i++ ) { + view.push( get( xbuf, ix ) ); + ix += strideX; + } + + return join( view, separator ); +} + + +// EXPORTS // + +module.exports = gjoin; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/index.js new file mode 100644 index 000000000000..9b2fbafe28da --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/index.js @@ -0,0 +1,57 @@ +/** +* @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 a string created by joining strided array elements using a specified separator. +* +* @module @stdlib/blas/ext/base/gjoin +* +* @example +* var gjoin = require( '@stdlib/blas/ext/base/gjoin' ); +* +* var x = [ 1, 2, 3, 4 ]; +* +* var str = gjoin( x.length, ',', x, 1 ); +* // returns '1,2,3,4' +* +* @example +* var gjoin = require( '@stdlib/blas/ext/base/gjoin' ); +* +* var x = [ 1, 2, 3, 4 ]; +* +* var str = gjoin.ndarray( x.length, ',', x, 1, 0 ); +* // returns '1,2,3,4' +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/main.js new file mode 100644 index 000000000000..9ba21f239316 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/main.js @@ -0,0 +1,51 @@ +/** +* @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 stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Returns a string created by joining strided array elements using a specified separator. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {*} separator - separator +* @param {Collection} x - input array +* @param {integer} strideX - stride length +* @returns {string} joined string +* +* @example +* var x = [ 1, 2, 3, 4 ]; +* +* var str = gjoin( x.length, ',', x, 1 ); +* // returns '1,2,3,4' +*/ +function gjoin( N, separator, x, strideX ) { + return ndarray( N, separator, x, strideX, stride2offset( N, strideX ) ); +} + + +// EXPORTS // + +module.exports = gjoin; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/ndarray.js new file mode 100644 index 000000000000..6260bf5c6bd7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/ndarray.js @@ -0,0 +1,74 @@ +/** +* @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 arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var join = require( '@stdlib/array/base/join' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Returns a string created by joining strided array elements using a specified separator and alternative indexing semantics. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {*} separator - separator +* @param {Collection} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {string} joined string +* +* @example +* var x = [ 1, 2, 3, 4 ]; +* +* var str = gjoin( x.length, ',', x, 1, 0 ); +* // returns '1,2,3,4' +*/ +function gjoin( N, separator, x, strideX, offsetX ) { + var view; + var ix; + var o; + var i; + + if ( N <= 0 ) { + return ''; + } + o = arraylike2object( x ); + if ( o.accessorProtocol ) { + return accessors( N, separator, o, strideX, offsetX ); + } + + // Create a view of the strided elements + view = []; + ix = offsetX; + for ( i = 0; i < N; i++ ) { + view.push( x[ ix ] ); + ix += strideX; + } + + return join( view, separator ); +} + + +// EXPORTS // + +module.exports = gjoin; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/package.json b/lib/node_modules/@stdlib/blas/ext/base/gjoin/package.json new file mode 100644 index 000000000000..9e5a2ba8cca4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/blas/ext/base/gjoin", + "version": "0.0.0", + "description": "Return a string created by joining strided array elements using a specified separator.", + "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/base/gjoin/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.js new file mode 100644 index 000000000000..f135965eedaf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.js @@ -0,0 +1,38 @@ +/** +* @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 gjoin = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gjoin, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof gjoin.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.main.js new file mode 100644 index 000000000000..559071ffcca6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.main.js @@ -0,0 +1,145 @@ +/** +* @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var gjoin = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gjoin, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( gjoin.length, 4, 'has expected arity' ); + t.end(); +}); + +tape( 'the function returns a string created by joining strided array elements', function test( t ) { + var actual; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + + // Nonnegative stride... + actual = gjoin( x.length, ',', x, 1 ); + t.strictEqual( actual, '1,2,3,4,5,6', 'returns expected value' ); + + actual = gjoin( 3, '-', x, 2 ); + t.strictEqual( actual, '1-3-5', 'returns expected value' ); + + actual = gjoin( 1, '|', x, 1 ); + t.strictEqual( actual, '1', 'returns expected value' ); + + // Negative stride... + actual = gjoin( x.length, ',', x, -1 ); + t.strictEqual( actual, '6,5,4,3,2,1', 'returns expected value' ); + + actual = gjoin( 3, '-', x, -2 ); + t.strictEqual( actual, '5-3-1', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a string created by joining strided array elements (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + + // Nonnegative stride... + actual = gjoin( x.length, ',', x, 1 ); + t.strictEqual( actual, '1,2,3,4,5,6', 'returns expected value' ); + + actual = gjoin( 3, '-', x, 2 ); + t.strictEqual( actual, '1-3-5', 'returns expected value' ); + + actual = gjoin( 1, '|', x, 1 ); + t.strictEqual( actual, '1', 'returns expected value' ); + + // Negative stride... + actual = gjoin( x.length, ',', x, -1 ); + t.strictEqual( actual, '6,5,4,3,2,1', 'returns expected value' ); + + actual = gjoin( 3, '-', x, -2 ); + t.strictEqual( actual, '5-3-1', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty string if provided `N` parameter is less than or equal to zero', function test( t ) { + var actual; + + actual = gjoin( 0, ',', [ 1.0, 2.0, 3.0 ], 1 ); + t.strictEqual( actual, '', 'returns expected value' ); + + actual = gjoin( -1, ',', [ 1.0, 2.0, 3.0 ], 1 ); + t.strictEqual( actual, '', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty string if provided `N` parameter is less than or equal to zero (accessors)', function test( t ) { + var actual; + + actual = gjoin( 0, ',', toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1 ); + t.strictEqual( actual, '', 'returns expected value' ); + + actual = gjoin( -1, ',', toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1 ); + t.strictEqual( actual, '', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function handles null and undefined values', function test( t ) { + var actual; + var x; + + x = [ 1, null, 3, undefined, 5 ]; + + actual = gjoin( x.length, ',', x, 1 ); + t.strictEqual( actual, '1,,3,,5', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function handles different separator types', function test( t ) { + var actual; + var x; + + x = [ 1, 2, 3 ]; + + actual = gjoin( x.length, '', x, 1 ); + t.strictEqual( actual, '123', 'returns expected value' ); + + actual = gjoin( x.length, ' - ', x, 1 ); + t.strictEqual( actual, '1 - 2 - 3', 'returns expected value' ); + + actual = gjoin( x.length, 0, x, 1 ); + t.strictEqual( actual, '10203', 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.ndarray.js new file mode 100644 index 000000000000..bc9609fb9f01 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.ndarray.js @@ -0,0 +1,157 @@ +/** +* @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var gjoin = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gjoin, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( gjoin.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function returns a string created by joining strided array elements', function test( t ) { + var actual; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + + // Nonnegative stride... + actual = gjoin( x.length, ',', x, 1, 0 ); + t.strictEqual( actual, '1,2,3,4,5,6', 'returns expected value' ); + + actual = gjoin( x.length-1, '-', x, 1, 1 ); + t.strictEqual( actual, '2-3-4-5-6', 'returns expected value' ); + + actual = gjoin( x.length-2, '|', x, 1, 2 ); + t.strictEqual( actual, '3|4|5|6', 'returns expected value' ); + + actual = gjoin( 3, '-', x, 2, 0 ); + t.strictEqual( actual, '1-3-5', 'returns expected value' ); + + // Negative stride... + actual = gjoin( x.length, ',', x, -1, x.length-1 ); + t.strictEqual( actual, '6,5,4,3,2,1', 'returns expected value' ); + + actual = gjoin( 3, '-', x, -2, x.length-1 ); + t.strictEqual( actual, '6-4-2', 'returns expected value' ); + + actual = gjoin( 3, '|', x, -2, x.length-2 ); + t.strictEqual( actual, '5|3|1', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a string created by joining strided array elements (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + + // Nonnegative stride... + actual = gjoin( x.length, ',', x, 1, 0 ); + t.strictEqual( actual, '1,2,3,4,5,6', 'returns expected value' ); + + actual = gjoin( x.length-1, ',', x, 1, 1 ); + t.strictEqual( actual, '2,3,4,5,6', 'returns expected value' ); + + actual = gjoin( x.length-2, ',', x, 1, 2 ); + t.strictEqual( actual, '3,4,5,6', 'returns expected value' ); + + actual = gjoin( 3, '-', x, 2, 0 ); + t.strictEqual( actual, '1-3-5', 'returns expected value' ); + + // Negative stride... + actual = gjoin( x.length, ',', x, -1, x.length-1 ); + t.strictEqual( actual, '6,5,4,3,2,1', 'returns expected value' ); + + actual = gjoin( 3, '-', x, -2, x.length-1 ); + t.strictEqual( actual, '6-4-2', 'returns expected value' ); + + actual = gjoin( 3, '|', x, -2, x.length-2 ); + t.strictEqual( actual, '5|3|1', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty string if provided an `N` parameter is less than or equal to zero', function test( t ) { + var actual; + + actual = gjoin( 0, ',', [ 1.0, 2.0, 3.0 ], 1, 0 ); + t.strictEqual( actual, '', 'returns expected value' ); + + actual = gjoin( -1, ',', [ 1.0, 2.0, 3.0 ], 1, 0 ); + t.strictEqual( actual, '', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty string if provided an `N` parameter is less than or equal to zero (accessors)', function test( t ) { + var actual; + + actual = gjoin( 0, ',', toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1, 0 ); + t.strictEqual( actual, '', 'returns expected value' ); + + actual = gjoin( -1, ',', toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1, 0 ); + t.strictEqual( actual, '', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function handles null and undefined values', function test( t ) { + var actual; + var x; + + x = [ 1, null, 3, undefined, 5 ]; + + actual = gjoin( x.length, ',', x, 1, 0 ); + t.strictEqual( actual, '1,,3,,5', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function handles different separator types', function test( t ) { + var actual; + var x; + + x = [ 1, 2, 3 ]; + + actual = gjoin( x.length, '', x, 1, 0 ); + t.strictEqual( actual, '123', 'returns expected value' ); + + actual = gjoin( x.length, ' - ', x, 1, 0 ); + t.strictEqual( actual, '1 - 2 - 3', 'returns expected value' ); + + actual = gjoin( x.length, 0, x, 1, 0 ); + t.strictEqual( actual, '10203', 'returns expected value' ); + + t.end(); +}); From ac035c4c03a846488114fd220e785a037ca62406 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 4 Dec 2025 00:24:54 -0800 Subject: [PATCH 02/10] docs: update punctuation Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gjoin/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/README.md b/lib/node_modules/@stdlib/blas/ext/base/gjoin/README.md index 65f39b55a304..92e8c4ac9cb9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gjoin/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/README.md @@ -72,13 +72,13 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float64Array = require( '@stdlib/array/float64' ); -// Initial array... +// Initial array: var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); -// Create an offset view... +// Create an offset view: var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -// Join elements... +// Join elements: var str = gjoin( 3, '|', x1, 2 ); // returns '2|4|6' ``` From b64c79a6507b48c4e7098abbdb42b178c8cbde87 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 4 Dec 2025 00:26:26 -0800 Subject: [PATCH 03/10] docs: add note Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gjoin/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/README.md b/lib/node_modules/@stdlib/blas/ext/base/gjoin/README.md index 92e8c4ac9cb9..1b9ec62d047b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gjoin/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/README.md @@ -117,7 +117,8 @@ var str = gjoin.ndarray( 3, '|', x, 1, x.length-3 ); ## Notes -- If `N <= 0`, the function returns an empty string. +- If `N <= 0`, both functions return an empty string. +- If an array element is either `null` or `undefined`, both functions will serialize the element as an empty string. - Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). From bc5889b32b77bb8f77254d3053f8085ec4bdd674 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 4 Dec 2025 00:28:40 -0800 Subject: [PATCH 04/10] docs: fix type Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/repl.txt index 46470f9c8354..4d073f16df3d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/repl.txt @@ -16,7 +16,7 @@ N: integer Number of indexed elements. - separator: any + separator: string Separator. x: Array|TypedArray From 211d572d6732d01a40b1a97050b511d346457876 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 4 Dec 2025 00:29:52 -0800 Subject: [PATCH 05/10] docs: fix type Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/repl.txt index 4d073f16df3d..4293e86b8fcb 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/repl.txt @@ -50,7 +50,7 @@ N: integer Number of indexed elements. - separator: any + separator: string Separator. x: Array|TypedArray From 02aa25bef0d2e69623b71d36b9dd4a246fb3e322 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Fri, 5 Dec 2025 00:54:25 +0500 Subject: [PATCH 06/10] refactor: 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: na - 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: passed - task: lint_license_headers status: passed --- --- .../blas/ext/base/gjoin/docs/types/index.d.ts | 4 +- .../blas/ext/base/gjoin/docs/types/test.ts | 28 ++++++++++++ .../blas/ext/base/gjoin/lib/accessors.js | 38 +++++++++++----- .../@stdlib/blas/ext/base/gjoin/lib/main.js | 6 +-- .../blas/ext/base/gjoin/lib/ndarray.js | 31 +++++++++---- .../blas/ext/base/gjoin/test/test.main.js | 44 +++++-------------- .../blas/ext/base/gjoin/test/test.ndarray.js | 40 +++++------------ 7 files changed, 104 insertions(+), 87 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/types/index.d.ts index 375a67c84cc4..4bdb5ab6d374 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/types/index.d.ts @@ -46,7 +46,7 @@ interface Routine { * var str = gjoin( x.length, ',', x, 1 ); * // returns '1,2,3,4' */ - ( N: number, separator: unknown, x: InputArray, strideX: number ): string; + ( N: number, separator: string, x: InputArray, strideX: number ): string; /** * Returns a string created by joining strided array elements using a specified separator and alternative indexing semantics. @@ -64,7 +64,7 @@ interface Routine { * var str = gjoin.ndarray( x.length, ',', x, 1, 0 ); * // returns '1,2,3,4' */ - ndarray( N: number, separator: unknown, x: InputArray, strideX: number, offsetX: number ): string; + ndarray( N: number, separator: string, x: InputArray, strideX: number, offsetX: number ): string; } /** diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/types/test.ts index 192d6b0b260c..e79296bb0696 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/types/test.ts @@ -42,6 +42,20 @@ import gjoin = require( './index' ); gjoin( ( x: number ): number => x, ',', x, 1 ); // $ExpectError } +// The compiler throws an error if the function is provided a second argument which is not a string... +{ + const x = [ 1, 2, 3, 4 ]; + + gjoin( x.length, 5, x, 1 ); // $ExpectError + gjoin( x.length, true, x, 1 ); // $ExpectError + gjoin( x.length, false, x, 1 ); // $ExpectError + gjoin( x.length, null, x, 1 ); // $ExpectError + gjoin( x.length, undefined, x, 1 ); // $ExpectError + gjoin( x.length, [], x, 1 ); // $ExpectError + gjoin( x.length, {}, x, 1 ); // $ExpectError + gjoin( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError +} + // The compiler throws an error if the function is provided a third argument which is not an array-like object... { gjoin( 4, ',', 5, 1 ); // $ExpectError @@ -97,6 +111,20 @@ import gjoin = require( './index' ); gjoin.ndarray( ( x: number ): number => x, ',', x, 1, 0 ); // $ExpectError } +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a string... +{ + const x = [ 1, 2, 3, 4 ]; + + gjoin.ndarray( x.length, 5, x, 1, 0 ); // $ExpectError + gjoin.ndarray( x.length, true, x, 1, 0 ); // $ExpectError + gjoin.ndarray( x.length, false, x, 1, 0 ); // $ExpectError + gjoin.ndarray( x.length, null, x, 1, 0 ); // $ExpectError + gjoin.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError + gjoin.ndarray( x.length, [], x, 1, 0 ); // $ExpectError + gjoin.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError + gjoin.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + // The compiler throws an error if the `ndarray` method is provided a third argument which is not an array-like object... { gjoin.ndarray( 4, ',', 5, 1, 0 ); // $ExpectError diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/accessors.js index 37487a9fd91b..eca2883e8c11 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/accessors.js @@ -18,11 +18,6 @@ 'use strict'; -// MODULES // - -var join = require( '@stdlib/array/base/join' ); - - // MAIN // /** @@ -30,7 +25,7 @@ var join = require( '@stdlib/array/base/join' ); * * @private * @param {PositiveInteger} N - number of indexed elements -* @param {*} separator - separator +* @param {string} separator - separator * @param {Object} x - input array object * @param {Collection} x.data - input array data * @param {Array} x.accessors - array element accessors @@ -44,31 +39,50 @@ var join = require( '@stdlib/array/base/join' ); * * var x = [ 1, 2, 3, 4 ]; * -* var str = gjoin( x.length, ',', arraylike2object( toAccessorArray( x ) ), 1, 0 ); +* var out = gjoin( x.length, ',', arraylike2object( toAccessorArray( x ) ), 1, 0 ); * // returns '1,2,3,4' */ function gjoin( N, separator, x, strideX, offsetX ) { var xbuf; - var view; var get; + var out; var ix; + var v; var i; + if ( N <= 0 ) { + return ''; + } + // Cache reference to array data: xbuf = x.data; // Cache a reference to the element accessor: get = x.accessors[ 0 ]; - // Create a view of the strided elements - view = []; + if ( N === 1 ) { + // Get the single element: + v = get( xbuf, offsetX ); + if ( v === null || v === void 0 ) { + return ''; + } + return String( v ); + } + + out = ''; ix = offsetX; for ( i = 0; i < N; i++ ) { - view.push( get( xbuf, ix ) ); + if ( i > 0 ) { + out += separator; + } + v = get( xbuf, ix ); + if ( v !== null && v !== void 0 ) { + out += String( v ); + } ix += strideX; } - return join( view, separator ); + return out; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/main.js index 9ba21f239316..6b23aede4e15 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/main.js @@ -30,7 +30,7 @@ var ndarray = require( './ndarray.js' ); * Returns a string created by joining strided array elements using a specified separator. * * @param {PositiveInteger} N - number of indexed elements -* @param {*} separator - separator +* @param {string} separator - separator * @param {Collection} x - input array * @param {integer} strideX - stride length * @returns {string} joined string @@ -38,8 +38,8 @@ var ndarray = require( './ndarray.js' ); * @example * var x = [ 1, 2, 3, 4 ]; * -* var str = gjoin( x.length, ',', x, 1 ); -* // returns '1,2,3,4' +* var out = gjoin( x.length, ',', x, 1 ); +* // return '1,2,3,4' */ function gjoin( N, separator, x, strideX ) { return ndarray( N, separator, x, strideX, stride2offset( N, strideX ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/ndarray.js index 6260bf5c6bd7..1f43050d2e66 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/ndarray.js @@ -21,7 +21,6 @@ // MODULES // var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); -var join = require( '@stdlib/array/base/join' ); var accessors = require( './accessors.js' ); @@ -31,7 +30,7 @@ var accessors = require( './accessors.js' ); * Returns a string created by joining strided array elements using a specified separator and alternative indexing semantics. * * @param {PositiveInteger} N - number of indexed elements -* @param {*} separator - separator +* @param {string} separator - separator * @param {Collection} x - input array * @param {integer} strideX - stride length * @param {NonNegativeInteger} offsetX - starting index @@ -40,13 +39,14 @@ var accessors = require( './accessors.js' ); * @example * var x = [ 1, 2, 3, 4 ]; * -* var str = gjoin( x.length, ',', x, 1, 0 ); +* var out = gjoin( x.length, ',', x, 1, 0 ); * // returns '1,2,3,4' */ function gjoin( N, separator, x, strideX, offsetX ) { - var view; + var out; var ix; var o; + var v; var i; if ( N <= 0 ) { @@ -57,15 +57,30 @@ function gjoin( N, separator, x, strideX, offsetX ) { return accessors( N, separator, o, strideX, offsetX ); } - // Create a view of the strided elements - view = []; + if ( N === 1 ) { + // Get the single element: + v = x[ offsetX ]; + if ( v === null || v === void 0 ) { + return ''; + } + return String( v ); + } + + // Build the string directly without creating intermediate array: + out = ''; ix = offsetX; for ( i = 0; i < N; i++ ) { - view.push( x[ ix ] ); + if ( i > 0 ) { + out += separator; + } + v = x[ ix ]; + if ( v !== null && v !== void 0 ) { + out += String( v ); + } ix += strideX; } - return join( view, separator ); + return out; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.main.js index 559071ffcca6..6815fdc14db6 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.main.js @@ -61,6 +61,11 @@ tape( 'the function returns a string created by joining strided array elements', actual = gjoin( 3, '-', x, -2 ); t.strictEqual( actual, '5-3-1', 'returns expected value' ); + // Null and undefined values... + x = [ 1, null, 3, undefined, 5 ]; + actual = gjoin( x.length, ',', x, 1 ); + t.strictEqual( actual, '1,,3,,5', 'returns expected value' ); + t.end(); }); @@ -87,10 +92,15 @@ tape( 'the function returns a string created by joining strided array elements ( actual = gjoin( 3, '-', x, -2 ); t.strictEqual( actual, '5-3-1', 'returns expected value' ); + // Null and undefined values... + x = toAccessorArray( [ 1, null, 3, undefined, 5 ] ); + actual = gjoin( x.length, ',', x, 1 ); + t.strictEqual( actual, '1,,3,,5', 'returns expected value' ); + t.end(); }); -tape( 'the function returns an empty string if provided `N` parameter is less than or equal to zero', function test( t ) { +tape( 'the function returns an empty string if provided an `N` parameter is less than or equal to zero', function test( t ) { var actual; actual = gjoin( 0, ',', [ 1.0, 2.0, 3.0 ], 1 ); @@ -102,7 +112,7 @@ tape( 'the function returns an empty string if provided `N` parameter is less th t.end(); }); -tape( 'the function returns an empty string if provided `N` parameter is less than or equal to zero (accessors)', function test( t ) { +tape( 'the function returns an empty string if provided an `N` parameter is less than or equal to zero (accessors)', function test( t ) { var actual; actual = gjoin( 0, ',', toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1 ); @@ -113,33 +123,3 @@ tape( 'the function returns an empty string if provided `N` parameter is less th t.end(); }); - -tape( 'the function handles null and undefined values', function test( t ) { - var actual; - var x; - - x = [ 1, null, 3, undefined, 5 ]; - - actual = gjoin( x.length, ',', x, 1 ); - t.strictEqual( actual, '1,,3,,5', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function handles different separator types', function test( t ) { - var actual; - var x; - - x = [ 1, 2, 3 ]; - - actual = gjoin( x.length, '', x, 1 ); - t.strictEqual( actual, '123', 'returns expected value' ); - - actual = gjoin( x.length, ' - ', x, 1 ); - t.strictEqual( actual, '1 - 2 - 3', 'returns expected value' ); - - actual = gjoin( x.length, 0, x, 1 ); - t.strictEqual( actual, '10203', 'returns expected value' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.ndarray.js index bc9609fb9f01..bd2ec4fe46f4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.ndarray.js @@ -67,6 +67,11 @@ tape( 'the function returns a string created by joining strided array elements', actual = gjoin( 3, '|', x, -2, x.length-2 ); t.strictEqual( actual, '5|3|1', 'returns expected value' ); + // Null and undefined values... + x = [ 1, null, 3, undefined, 5 ]; + actual = gjoin( x.length, ',', x, 1, 0 ); + t.strictEqual( actual, '1,,3,,5', 'returns expected value' ); + t.end(); }); @@ -99,6 +104,11 @@ tape( 'the function returns a string created by joining strided array elements ( actual = gjoin( 3, '|', x, -2, x.length-2 ); t.strictEqual( actual, '5|3|1', 'returns expected value' ); + // Null and undefined values... + x = toAccessorArray( [ 1, null, 3, undefined, 5 ] ); + actual = gjoin( x.length, ',', x, 1, 0 ); + t.strictEqual( actual, '1,,3,,5', 'returns expected value' ); + t.end(); }); @@ -125,33 +135,3 @@ tape( 'the function returns an empty string if provided an `N` parameter is less t.end(); }); - -tape( 'the function handles null and undefined values', function test( t ) { - var actual; - var x; - - x = [ 1, null, 3, undefined, 5 ]; - - actual = gjoin( x.length, ',', x, 1, 0 ); - t.strictEqual( actual, '1,,3,,5', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function handles different separator types', function test( t ) { - var actual; - var x; - - x = [ 1, 2, 3 ]; - - actual = gjoin( x.length, '', x, 1, 0 ); - t.strictEqual( actual, '123', 'returns expected value' ); - - actual = gjoin( x.length, ' - ', x, 1, 0 ); - t.strictEqual( actual, '1 - 2 - 3', 'returns expected value' ); - - actual = gjoin( x.length, 0, x, 1, 0 ); - t.strictEqual( actual, '10203', 'returns expected value' ); - - t.end(); -}); From 168e7ed6e66140f20c03841b4f16c97442756083 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 5 Dec 2025 02:32:03 -0800 Subject: [PATCH 07/10] test: update desc Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.main.js index 6815fdc14db6..14f1fad78c39 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.main.js @@ -100,7 +100,7 @@ tape( 'the function returns a string created by joining strided array elements ( t.end(); }); -tape( 'the function returns an empty string if provided an `N` parameter is less than or equal to zero', function test( t ) { +tape( 'the function returns an empty string if provided an `N` parameter less than or equal to zero', function test( t ) { var actual; actual = gjoin( 0, ',', [ 1.0, 2.0, 3.0 ], 1 ); From 5f8eae8c7dfed2e51fcc236b47ef558b4994227b Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 5 Dec 2025 02:32:34 -0800 Subject: [PATCH 08/10] test: update desc Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.main.js index 14f1fad78c39..b8c23cefc333 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.main.js @@ -112,7 +112,7 @@ tape( 'the function returns an empty string if provided an `N` parameter less th t.end(); }); -tape( 'the function returns an empty string if provided an `N` parameter is less than or equal to zero (accessors)', function test( t ) { +tape( 'the function returns an empty string if provided an `N` parameter less than or equal to zero (accessors)', function test( t ) { var actual; actual = gjoin( 0, ',', toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1 ); From 70ef5689363c7a5738efb5be7ca5bcaa22ab731c Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 5 Dec 2025 02:34:02 -0800 Subject: [PATCH 09/10] test: update desc Signed-off-by: Athan --- .../@stdlib/blas/ext/base/gjoin/test/test.ndarray.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.ndarray.js index bd2ec4fe46f4..76a01f83b758 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.ndarray.js @@ -112,7 +112,7 @@ tape( 'the function returns a string created by joining strided array elements ( t.end(); }); -tape( 'the function returns an empty string if provided an `N` parameter is less than or equal to zero', function test( t ) { +tape( 'the function returns an empty string if provided an `N` parameter less than or equal to zero', function test( t ) { var actual; actual = gjoin( 0, ',', [ 1.0, 2.0, 3.0 ], 1, 0 ); @@ -124,7 +124,7 @@ tape( 'the function returns an empty string if provided an `N` parameter is less t.end(); }); -tape( 'the function returns an empty string if provided an `N` parameter is less than or equal to zero (accessors)', function test( t ) { +tape( 'the function returns an empty string if provided an `N` parameter less than or equal to zero (accessors)', function test( t ) { var actual; actual = gjoin( 0, ',', toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1, 0 ); From 25a04815191d58ff40820bd2cdd5960242db1aa2 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 5 Dec 2025 02:45:00 -0800 Subject: [PATCH 10/10] refactor: simplify implementation and add optimized path --- 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: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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/base/gjoin/lib/accessors.js | 23 +++------- .../blas/ext/base/gjoin/lib/ndarray.js | 44 +++++++++++++------ 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/accessors.js index eca2883e8c11..baf661c999d4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/accessors.js @@ -18,6 +18,11 @@ 'use strict'; +// MODULES // + +var isUndefinedOrNull = require( '@stdlib/assert/is-undefined-or-null' ); + + // MAIN // /** @@ -50,38 +55,24 @@ function gjoin( N, separator, x, strideX, offsetX ) { var v; var i; - if ( N <= 0 ) { - return ''; - } - // Cache reference to array data: xbuf = x.data; // Cache a reference to the element accessor: get = x.accessors[ 0 ]; - if ( N === 1 ) { - // Get the single element: - v = get( xbuf, offsetX ); - if ( v === null || v === void 0 ) { - return ''; - } - return String( v ); - } - - out = ''; ix = offsetX; + out = ''; for ( i = 0; i < N; i++ ) { if ( i > 0 ) { out += separator; } v = get( xbuf, ix ); - if ( v !== null && v !== void 0 ) { + if ( !isUndefinedOrNull( v ) ) { out += String( v ); } ix += strideX; } - return out; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/ndarray.js index 1f43050d2e66..b977f5b5c46e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/ndarray.js @@ -20,10 +20,34 @@ // MODULES // +var isUndefinedOrNull = require( '@stdlib/assert/is-undefined-or-null' ); var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); var accessors = require( './accessors.js' ); +// FUNCTIONS // + +/** +* Tests whether an object has a specified method. +* +* @private +* @param {Object} obj - input object +* @param {string} method - method name +* @returns {boolean} boolean indicating whether an object has a specified method +* +* @example +* var bool = hasMethod( [], 'join' ); +* // returns true +* +* @example +* var bool = hasMethod( [], 'beep' ); +* // returns false +*/ +function hasMethod( obj, method ) { + return ( typeof obj[ method ] === 'function' ); +} + + // MAIN // /** @@ -52,34 +76,26 @@ function gjoin( N, separator, x, strideX, offsetX ) { if ( N <= 0 ) { return ''; } + // Check for a contiguous strided array with left-to-right iteration... + if ( strideX === 1 && offsetX === 0 && N === x.length && hasMethod( x, 'join' ) ) { + return x.join( separator ); + } o = arraylike2object( x ); if ( o.accessorProtocol ) { return accessors( N, separator, o, strideX, offsetX ); } - - if ( N === 1 ) { - // Get the single element: - v = x[ offsetX ]; - if ( v === null || v === void 0 ) { - return ''; - } - return String( v ); - } - - // Build the string directly without creating intermediate array: - out = ''; ix = offsetX; + out = ''; for ( i = 0; i < N; i++ ) { if ( i > 0 ) { out += separator; } v = x[ ix ]; - if ( v !== null && v !== void 0 ) { + if ( !isUndefinedOrNull( v ) ) { out += String( v ); } ix += strideX; } - return out; }