diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/README.md new file mode 100644 index 000000000000..ddfd8ac65469 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/README.md @@ -0,0 +1,122 @@ + + +# gjoin + +> Return a string created by joining one-dimensional ndarray elements using a specified separator. + +
+ +
+ + + +
+ +## Usage + +```javascript +var gjoin = require( '@stdlib/blas/ext/base/ndarray/gjoin' ); +``` + +#### gjoin( arrays ) + +Returns a string created by joining one-dimensional ndarray elements using a specified separator. + +```javascript +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +var xbuf = [ 1.0, 3.0, 4.0, 2.0 ]; +var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + +var separator = scalar2ndarray( ',', { + 'dtype': 'generic' +}); + +var out = gjoin( [ x, separator ] ); +// returns '1,3,4,2' +``` + +The function has the following parameters: + +- **arrays**: array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a zero-dimensional ndarray containing the separator. + +
+ + + +
+ +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +var gjoin = require( '@stdlib/blas/ext/base/ndarray/gjoin' ); + +var xbuf = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var separator = scalar2ndarray( ',', { + 'dtype': 'generic' +}); +console.log( 'Separator:', ndarraylike2scalar( separator ) ); + +var out = gjoin( [ x, separator ] ); +console.log( out ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/benchmark/benchmark.js new file mode 100644 index 000000000000..9a27c7b0fec2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/benchmark/benchmark.js @@ -0,0 +1,108 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var pow = require( '@stdlib/math/base/special/pow' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var pkg = require( './../package.json' ).name; +var gjoin = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var separator; + var xbuf; + var x; + + xbuf = uniform( len, 0.0, 100.0, options ); + x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); + + separator = scalar2ndarray( ',', { + 'dtype': 'generic' + }); + + return benchmark; + + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = gjoin( [ x, separator ] ); + 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/ndarray/gjoin/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/docs/repl.txt new file mode 100644 index 000000000000..84bca0676e04 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/docs/repl.txt @@ -0,0 +1,33 @@ + +{{alias}}( arrays ) + Returns a string created by joining one-dimensional ndarray elements using a + specified separator. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a zero-dimensional ndarray containing the separator. + + Returns + ------- + out: string + Joined string. + + Examples + -------- + > var xbuf = [ 1.0, 2.0, 3.0 ]; + > var dt = 'generic'; + > var sh = [ xbuf.length ]; + > var sx = [ 1 ]; + > var ox = 0; + > var ord = 'row-major'; + > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); + > var v = {{alias:@stdlib/ndarray/from-scalar}}( ',', { 'dtype': dt } ); + > {{alias}}( [ x, v ] ) + '1,2,3' + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/docs/types/index.d.ts new file mode 100644 index 000000000000..60ef701ecef9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/docs/types/index.d.ts @@ -0,0 +1,50 @@ +/* +* @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 { typedndarray } from '@stdlib/types/ndarray'; + +/** +* Returns a string created by joining one-dimensional ndarray elements using a specified separator. +* +* @param arrays - array-like object containing a one-dimensional input ndarray and a zero-dimensional ndarray containing a separator +* @returns joined string +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var xbuf = [ 1.0, 3.0, 4.0, 2.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var separator = scalar2ndarray( ',', { +* 'dtype': 'generic' +* }); +* +* var v = gjoin( [ x, separator ] ); +* // returns '1,3,4,2' +*/ +declare function gjoin( arrays: [ typedndarray, typedndarray ] ): string; + + +// EXPORTS // + +export = gjoin; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/docs/types/test.ts new file mode 100644 index 000000000000..3020843a6a21 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/docs/types/test.ts @@ -0,0 +1,64 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +import gjoin = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = zeros( [ 10 ], { + 'dtype': 'generic' + }); + const separator = scalar2ndarray( ',', { + 'dtype': 'generic' + }); + + gjoin( [ x, separator ] ); // $ExpectType string +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + gjoin( '10' ); // $ExpectError + gjoin( 10 ); // $ExpectError + gjoin( true ); // $ExpectError + gjoin( false ); // $ExpectError + gjoin( null ); // $ExpectError + gjoin( undefined ); // $ExpectError + gjoin( [] ); // $ExpectError + gjoin( {} ); // $ExpectError + gjoin( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 10 ], { + 'dtype': 'generic' + }); + const separator = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + + gjoin(); // $ExpectError + gjoin( [ x, separator ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/examples/index.js new file mode 100644 index 000000000000..eb7f035fa292 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/examples/index.js @@ -0,0 +1,40 @@ +/** +* @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 ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +var gjoin = require( './../lib' ); + +var xbuf = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var separator = scalar2ndarray( ',', { + 'dtype': 'generic' +}); +console.log( 'Separator: ', ndarraylike2scalar( separator ) ); + +var out = gjoin( [ x, separator ] ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/lib/index.js new file mode 100644 index 000000000000..25b5a84622d0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/lib/index.js @@ -0,0 +1,49 @@ +/** +* @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 one-dimensional ndarray elements using a specified separator. +* +* @module @stdlib/blas/ext/base/ndarray/gjoin +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var gjoin = require( '@stdlib/blas/ext/base/ndarray/gjoin' ); +* +* var xbuf = [ 1.0, 3.0, 4.0, 2.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var separator = scalar2ndarray( ',', { +* 'dtype': 'generic' +* }); +* +* var v = gjoin( [ x, separator ] ); +* // returns '1,3,4,2' +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/lib/main.js new file mode 100644 index 000000000000..af26cc78a4e3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/lib/main.js @@ -0,0 +1,62 @@ +/** +* @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 numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var strided = require( '@stdlib/blas/ext/base/gjoin' ).ndarray; +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); + + +// MAIN // + +/** +* Returns a string created by joining one-dimensional ndarray elements using a specified separator. +* +* @param {ArrayLikeObject} arrays - array-like object containing a one-dimensional input ndarray and a zero-dimensional ndarray containing a separator +* @returns {string} joined string +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var xbuf = [ 1.0, 3.0, 4.0, 2.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var separator = scalar2ndarray( ',', { +* 'dtype': 'generic' +* }); +* +* var v = gjoin( [ x, separator ] ); +* // returns '1,3,4,2' +*/ +function gjoin( arrays ) { + var x = arrays[ 0 ]; + var s = ndarraylike2scalar( arrays[ 1 ] ); + return strided( numelDimension( x, 0 ), s, getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = gjoin; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/package.json new file mode 100644 index 000000000000..dac9901376f1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/package.json @@ -0,0 +1,63 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/gjoin", + "version": "0.0.0", + "description": "Return a string created by joining one-dimensional ndarray 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", + "array", + "join", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/test/test.js new file mode 100644 index 000000000000..93f0b148caa0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin/test/test.js @@ -0,0 +1,80 @@ +/** +* @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 scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var gjoin = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, length, stride, offset ) { + return new ndarray( 'generic', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// 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 returns a string created by joining one-dimensional ndarray elements using a specified separator', function test( t ) { + var separator; + var actual; + var x; + + x = vector( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ], 6, 1, 0 ); + + separator = scalar2ndarray( ',', { + 'dtype': 'generic' + }); + actual = gjoin( [ x, separator ] ); + t.strictEqual( actual, '1,1,2,2,3,3', 'returns expected value' ); + + separator = scalar2ndarray( '|', { + 'dtype': 'generic' + }); + actual = gjoin( [ x, separator ] ); + t.strictEqual( actual, '1|1|2|2|3|3', 'returns expected value' ); + + separator = scalar2ndarray( '>', { + 'dtype': 'generic' + }); + actual = gjoin( [ x, separator ] ); + t.strictEqual( actual, '1>1>2>2>3>3', 'returns expected value' ); + + t.end(); +});