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..1b9ec62d047b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/README.md @@ -0,0 +1,179 @@ + + +# 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`, 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]). + +
+ + + + + +
+ +## 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..4293e86b8fcb --- /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: string + 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: string + 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..4bdb5ab6d374 --- /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: string, 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: string, 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..e79296bb0696 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/types/test.ts @@ -0,0 +1,175 @@ +/* +* @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 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 + 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 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 + 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..baf661c999d4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/accessors.js @@ -0,0 +1,82 @@ +/** +* @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 isUndefinedOrNull = require( '@stdlib/assert/is-undefined-or-null' ); + + +// MAIN // + +/** +* Returns a string created by joining strided array elements using a specified separator. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {string} 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 out = gjoin( x.length, ',', arraylike2object( toAccessorArray( x ) ), 1, 0 ); +* // returns '1,2,3,4' +*/ +function gjoin( N, separator, x, strideX, offsetX ) { + var xbuf; + var get; + var out; + var ix; + var v; + var i; + + // Cache reference to array data: + xbuf = x.data; + + // Cache a reference to the element accessor: + get = x.accessors[ 0 ]; + + ix = offsetX; + out = ''; + for ( i = 0; i < N; i++ ) { + if ( i > 0 ) { + out += separator; + } + v = get( xbuf, ix ); + if ( !isUndefinedOrNull( v ) ) { + out += String( v ); + } + ix += strideX; + } + return out; +} + + +// 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..6b23aede4e15 --- /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 {string} separator - separator +* @param {Collection} x - input array +* @param {integer} strideX - stride length +* @returns {string} joined string +* +* @example +* var x = [ 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 ) ); +} + + +// 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..b977f5b5c46e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/ndarray.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 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 // + +/** +* 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 {string} 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 out = gjoin( x.length, ',', x, 1, 0 ); +* // returns '1,2,3,4' +*/ +function gjoin( N, separator, x, strideX, offsetX ) { + var out; + var ix; + var o; + var v; + var i; + + 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 ); + } + ix = offsetX; + out = ''; + for ( i = 0; i < N; i++ ) { + if ( i > 0 ) { + out += separator; + } + v = x[ ix ]; + if ( !isUndefinedOrNull( v ) ) { + out += String( v ); + } + ix += strideX; + } + return out; +} + + +// 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..b8c23cefc333 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.main.js @@ -0,0 +1,125 @@ +/** +* @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' ); + + // 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(); +}); + +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' ); + + // 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 an `N` parameter 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 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 ); + 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(); +}); 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..76a01f83b758 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.ndarray.js @@ -0,0 +1,137 @@ +/** +* @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' ); + + // 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(); +}); + +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' ); + + // 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(); +}); + +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 ); + 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 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(); +});