diff --git a/.github/workflows/update_package_meta_data.yml b/.github/workflows/update_package_meta_data.yml index 3fe94c736a9..319f75e9809 100644 --- a/.github/workflows/update_package_meta_data.yml +++ b/.github/workflows/update_package_meta_data.yml @@ -83,6 +83,11 @@ jobs: run: | node lib/node_modules/@stdlib/_tools/package-json/scripts/update_directories lib/node_modules/@stdlib + # Update gypfile field: + - name: 'Update gypfile field' + run: | + node lib/node_modules/@stdlib/_tools/package-json/scripts/update_gypfile lib/node_modules/@stdlib + # Import GPG key to sign commits: - name: 'Import GPG key to sign commits' # Pin action to full length commit SHA diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 40e76b8eabc..d7b90d54164 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -8,6 +8,7 @@ AgPriyanshu18 <113460573+AgPriyanshu18@users.noreply.github.com> Ali Salesi Aman Bhansali <92033532+aman-095@users.noreply.github.com> Amit Jimiwal +Anudeep Sanapala <71971574+anudeeps0306@users.noreply.github.com> Athan Reines Brendan Graetz Bruno Fenzl @@ -30,6 +31,7 @@ Joris Labie Justin Dennison Karthik Prakash <116057817+skoriop@users.noreply.github.com> Khaldon +Lovelin <100030865+lovelindhoni@users.noreply.github.com> Marcus Fantham Matt Cochrane Mihir Pandit <129577900+MSP20086@users.noreply.github.com> @@ -38,11 +40,13 @@ Momtchil Momtchev Naresh Jagadeesan Nithin Katta <88046362+nithinkatta@users.noreply.github.com> Ognjen Jevremović +Oneday12323 <107678750+Oneday12323@users.noreply.github.com> Philipp Burckhardt Prajwal Kulkarni Pranav Goswami Praneki <97080887+PraneGIT@users.noreply.github.com> Pratik <97464067+Pratik772846@users.noreply.github.com> +Priyansh <88396544+itsspriyansh@users.noreply.github.com> Rejoan Sardar <119718513+Rejoan-Sardar@users.noreply.github.com> Ricky Reusser Robert Gislason @@ -51,6 +55,7 @@ Rutam <138517416+performant23@users.noreply.github.com> Ryan Seal Sai Srikar Dumpeti <80447788+the-r3aper7@users.noreply.github.com> Seyyed Parsa Neshaei +Shashank Shekhar Singh <123410790+Shashankss1205@users.noreply.github.com> Shraddheya Shendre Shubham Snehil Shah <130062020+Snehil-Shah@users.noreply.github.com> diff --git a/lib/node_modules/@stdlib/_tools/package-json/scripts/update_directories b/lib/node_modules/@stdlib/_tools/package-json/scripts/update_directories index 634a2b5df19..66afd72dc24 100755 --- a/lib/node_modules/@stdlib/_tools/package-json/scripts/update_directories +++ b/lib/node_modules/@stdlib/_tools/package-json/scripts/update_directories @@ -39,9 +39,9 @@ // MODULES // var proc = require( 'process' ); -var debug = require( 'debug' )( 'update-package-directories' ); var join = require( 'path' ).join; var resolve = require( 'path' ).resolve; +var logger = require( 'debug' ); var parseArgs = require( 'minimist' ); var isObject = require( '@stdlib/assert/is-plain-object' ); var cwd = require( '@stdlib/process/cwd' ); @@ -53,6 +53,7 @@ var standardize = require( '@stdlib/_tools/package-json/standardize' ); // VARIABLES // +var debug = logger( 'update-package-directories' ); var DIR_KEYS = [ 'benchmark', @@ -98,7 +99,6 @@ function main( dir ) { var fpath; var opts; var pkgs; - var dir; var pkg; var i; var j; diff --git a/lib/node_modules/@stdlib/_tools/package-json/scripts/update_gypfile b/lib/node_modules/@stdlib/_tools/package-json/scripts/update_gypfile new file mode 100755 index 00000000000..4cc89104e73 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/package-json/scripts/update_gypfile @@ -0,0 +1,140 @@ +#!/usr/bin/env node + +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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'; + +/* +* Update package `package.json` files by setting the `gyppfile` field to `true` for packages which contain a `binding.gyp` and/or `include.gypi` file. +* +* * *$1*: root search directory +* +* If not provided a root search directory, the root search directory is the current working directory. +* +* To enable verbose logging, set the `DEBUG` environment variable. +* +* ``` bash +* $ DEBUG=* update_gypfile . +* ``` +*/ + +// MODULES // + +var join = require( 'path' ).join; +var resolve = require( 'path' ).resolve; +var proc = require( 'process' ); +var logger = require( 'debug' ); +var parseArgs = require( 'minimist' ); +var isObject = require( '@stdlib/assert/is-plain-object' ); +var cwd = require( '@stdlib/process/cwd' ); +var exists = require( '@stdlib/fs/exists' ).sync; +var findPkgs = require( '@stdlib/_tools/pkgs/find' ).sync; +var writeFile = require( '@stdlib/fs/write-file' ).sync; +var standardize = require( '@stdlib/_tools/package-json/standardize' ); + + +// VARIABLES // + +var GYPFILES = [ + 'binding.gyp', + 'include.gypi' +]; +var debug = logger( 'update-gypfile' ); +var opts; +var args; +var dir; + + +// FUNCTIONS // + +/** +* Updates package `package.json` files by setting the `gypfile` field if a package contains a `binding.gyp` and/or `include.gypi` file. +* +* @private +* @param {string} dir - root search directory +*/ +function main( dir ) { + var fpath; + var opts; + var pkgs; + var pkg; + var i; + var j; + + debug( 'Searching for packages in %s.', dir ); + opts = { + 'dir': dir, + 'pattern': '**/package.json' + }; + pkgs = findPkgs( opts ); + debug( 'Found %d packages.', pkgs.length ); + + for ( i = 0; i < pkgs.length; i++ ) { + fpath = join( pkgs[ i ], 'package.json' ); + debug( 'Loading package file: %s (%d of %d).', fpath, i+1, pkgs.length ); + + try { + pkg = require( fpath ); // eslint-disable-line stdlib/no-dynamic-require + } catch ( err ) { + debug( 'Encountered an error when loading package file: %s (%d of %d). Error: %s', fpath, i+1, pkgs.length, err.message ); + continue; + } + if ( !isObject( pkg ) ) { + debug( 'Unable to load package.json file: %s (%d of %d).', fpath, i+1, pkgs.length ); + continue; + } + + if ( pkg.gypfile ) { + debug( 'Current gypfile value: %s.', pkg.gypfile ); + } + debug( 'Updating gypfile.' ); + for ( j = 0; j < GYPFILES.length; j++ ) { + if ( exists( join( pkgs[ i ], GYPFILES[ j ] ) ) ) { + pkg.gypfile = true; + break; + } + } + + debug( 'Standardizing package data.' ); + pkg = standardize( pkg ); + + debug( 'Serializing package data.' ); + pkg = JSON.stringify( pkg, null, 2 ); // 2-space indentation + + debug( 'Writing package data to file.' ); + writeFile( fpath, pkg+'\n', { + 'encoding': 'utf8' + }); + } + debug( 'Finished updating all packages.' ); +} + + +// MAIN // + +// Parse command-line arguments: +opts = {}; +args = parseArgs( proc.argv.slice( 2 ), opts ); + +if ( args._[ 0 ] ) { + dir = resolve( cwd(), args._[ 0 ] ); +} else { + dir = cwd(); +} +main( dir ); diff --git a/lib/node_modules/@stdlib/array/base/join/README.md b/lib/node_modules/@stdlib/array/base/join/README.md new file mode 100644 index 00000000000..fa364e59994 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/join/README.md @@ -0,0 +1,141 @@ + + +# join + +> Return a string created by joining array elements using a specified separator. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var join = require( '@stdlib/array/base/join' ); +``` + +#### join( x, separator ) + +Returns a string created by joining array elements using a specified separator. + +```javascript +var x = [ 1, 2, 3, 4, 5, 6 ]; + +var out = join( x, ',' ); +// returns '1,2,3,4,5,6' +``` + +
+ + + + + +
+ +## Notes + +- If provided an array-like object having a `join` method, the function defers execution to that method and assumes that the method API has the following signature: + + ```text + x.join( separator ) + ``` + +- If an array element is either `null` or `undefined`, the function will serialize the element as an empty string. + +
+ + + + + +
+ +## Examples + + + +```javascript +var Complex128Array = require( '@stdlib/array/complex128' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var AccessorArray = require( '@stdlib/array/base/accessor' ); +var Float64Array = require( '@stdlib/array/float64' ); +var join = require( '@stdlib/array/base/join' ); + +var x = [ 0, 1, 2, 3, 4, 5 ]; +var s = join( x, ',' ); +// returns '0,1,2,3,4,5' + +x = new Float64Array( [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +s = join( x, ',' ); +// returns '0,1,2,3,4,5' + +s = join( x, '-' ); +// returns '0-1-2-3-4-5' + +s = new AccessorArray( [ 1, 2, 3, 4 ] ); +s = join( s, ',' ); +// returns '1,2,3,4' + +x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +s = join( x, ',' ); +// returns '1 + 2i,3 + 4i,5 + 6i' + +x = new Complex64Array( [ 1.0, -1.0, 2.0, -2.0 ] ); +s = join( x, ',' ); +// returns '1 - 1i,2 - 2i' +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/base/join/benchmark/benchmark.length.js b/lib/node_modules/@stdlib/array/base/join/benchmark/benchmark.length.js new file mode 100644 index 00000000000..60ed2fc96ac --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/join/benchmark/benchmark.length.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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' ); +var ones = require( '@stdlib/array/base/ones' ); +var pkg = require( './../package.json' ).name; +var join = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = ones( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var s; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + s = join( x, ',' ); + if ( !isString( s ) ) { + b.fail( 'should return a string' ); + } + } + if ( !isString( s ) ) { + b.fail( 'should return a string' ); + } + b.toc(); + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + f = createBenchmark( len ); + bench( pkg+':dtype=generic,len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/base/join/docs/repl.txt b/lib/node_modules/@stdlib/array/base/join/docs/repl.txt new file mode 100644 index 00000000000..431b9dd83c2 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/join/docs/repl.txt @@ -0,0 +1,35 @@ + +{{alias}}( x, separator ) + Return a string created by joining array elements using a + specified separator. + + If provided an array-like object having a `join` method, the function + defers execution to that method and assumes that the method has the + following signature: + + x.join( separator ) + + If provided an array-like object without a `join` method, the function + manually constructs the output string. + + Parameters + ---------- + x: ArrayLikeObject + Input array. + + separator: string + Separator to be used. + + Returns + ------- + out: string + Joined string. + + Examples + -------- + > var out = {{alias}}( [ 1, 2, 3, 4 ], ',' ) + '1,2,3,4' + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/array/base/join/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/join/docs/types/index.d.ts new file mode 100644 index 00000000000..5f2d0537218 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/join/docs/types/index.d.ts @@ -0,0 +1,74 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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, TypedArray, ComplexTypedArray } from '@stdlib/types/array'; + +/** +* Returns a string created by joining array elements using a specified separator. +* +* @param x - input array +* @param separator - separator element +* @returns string +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); +* +* var out = join( x, ',' ); +* // returns '1,2,3' +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* +* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* var out = join( x, ',' ); +* // returns '1 + 2i,3 + 4i,5 + 6i' +*/ +declare function join( x: T, separator: string ): string; + +/** +* Returns a string created by joining array elements using a specified separator. +* +* @param x - input array +* @param separator - separator element +* @returns string +* +* @example +* var x = [ 1, 2, 3 ]; +* +* var out = join( x, ',' ); +* // returns '1,2,3' +* +* @example +* var x = [ 1, 2, 3, 4, 5, 6 ]; +* +* var out = join( x, '-' ); +* // returns '1-2-3-4-5-6' +*/ +declare function join( x: Collection, separator: string ): string; + + +// EXPORTS // + +export = join; diff --git a/lib/node_modules/@stdlib/array/base/join/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/join/docs/types/test.ts new file mode 100644 index 00000000000..7ff06fc321f --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/join/docs/types/test.ts @@ -0,0 +1,68 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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 Complex128Array = require( '@stdlib/array/complex128' ); +import Complex64Array = require( '@stdlib/array/complex64' ); +import join = require( './index' ); + + +// TESTS // + +// The function returns a string... +{ + join( [ 1, 2, 3 ], ',' ); // $ExpectType string + join( new Float64Array( [ 1, 2, 3 ] ), ',' ); // $ExpectType string + join( new Float32Array( [ 1, 2, 3 ] ), ',' ); // $ExpectType string + join( new Int32Array( [ 1, 2, 3 ] ), ',' ); // $ExpectType string + join( new Int16Array( [ 1, 2, 3 ] ), ',' ); // $ExpectType string + join( new Int8Array( [ 1, 2, 3 ] ), ',' ); // $ExpectType string + join( new Uint32Array( [ 1, 2, 3 ] ), ',' ); // $ExpectType string + join( new Uint16Array( [ 1, 2, 3 ] ), ',' ); // $ExpectType string + join( new Uint8Array( [ 1, 2, 3 ] ), ',' ); // $ExpectType string + join( new Uint8ClampedArray( [ 1, 2, 3 ] ), ',' ); // $ExpectType string + join( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), ',' ); // $ExpectType string + join( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), ',' ); // $ExpectType string +} + +// The compiler throws an error if the function is provided a first argument which is not a collection... +{ + join( 5, ',' ); // $ExpectError + join( true, ',' ); // $ExpectError + join( false, ',' ); // $ExpectError + join( null, ',' ); // $ExpectError + join( void 0, ',' ); // $ExpectError + join( {}, ',' ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a string... +{ + const x = [ 1, 2, 3 ]; + + join( x, true ); // $ExpectError + join( x, false ); // $ExpectError + join( x, null ); // $ExpectError + join( x, {} ); // $ExpectError + join( x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + join(); // $ExpectError + join( [ 1, 2, 3 ] ); // $ExpectError + join( [ 1, 2, 3 ], ',', {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/array/base/join/examples/index.js b/lib/node_modules/@stdlib/array/base/join/examples/index.js new file mode 100644 index 00000000000..3588b02cf3f --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/join/examples/index.js @@ -0,0 +1,60 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 Complex128Array = require( '@stdlib/array/complex128' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Float64Array = require( '@stdlib/array/float64' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var AccessorArray = require( '@stdlib/array/base/accessor' ); +var join = require( './../lib' ); + +var x = [ 0, 1, 2, 3, 4, 5 ]; + +var s = join( x, ',' ); +console.log( s ); +// => '0,1,2,3,4,5' + +x = new Float64Array( zeroTo( 6 ) ); + +s = join( x, ',' ); +console.log( s ); +// => '0,1,2,3,4,5' + +s = join( x, '-' ); +console.log( s ); +// => '0-1-2-3-4-5' + +s = new AccessorArray( [ 1, 2, 3, 4 ] ); + +s = join( s, ',' ); +console.log( s ); +// => '1,2,3,4' + +x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + +s = join( x, ',' ); +console.log( s ); +// => '1 + 2i,3 + 4i,5 + 6i' + +x = new Complex64Array( [ 1.0, -1.0, 2.0, -2.0 ] ); + +s = join( x, ',' ); +console.log( s ); +// => '1 - 1i,2 - 2i' diff --git a/lib/node_modules/@stdlib/array/base/join/lib/index.js b/lib/node_modules/@stdlib/array/base/join/lib/index.js new file mode 100644 index 00000000000..7480632b571 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/join/lib/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 array elements using a specified separator. +* +* @module @stdlib/array/base/join +* +* @example +* var join = require( '@stdlib/array/base/join' ); +* +* var x = [ 1, 2, 3, 4 ]; +* +* var out = join( x, ',' ); +* // returns '1,2,3,4' +*/ + + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/array/base/join/lib/main.js b/lib/node_modules/@stdlib/array/base/join/lib/main.js new file mode 100644 index 00000000000..d4b9f6594d1 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/join/lib/main.js @@ -0,0 +1,158 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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' ); + + +// 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' ); +} + +/** +* Returns a string created by joining array elements using a specified separator when input is an accessor array. +* +* @private +* @param {Object} x - input array object +* @param {integer} separator - separator +* @returns {string} joined string +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) ); +* +* var out = accessors( x, ',' ); +* // returns '1,2,3,4' +*/ +function accessors( x, separator ) { + var output; + var data; + var get; + var i; + var v; + data = x.data; + get = x.accessors[ 0 ]; + output = ''; + for ( i = 0; i < data.length; i++ ) { + v = get( data, i ); + if ( typeof v === 'undefined' || v === null ) { + v = ''; + } + output += v; + if ( i < data.length - 1 ) { + output += separator; + } + } + return output; +} + +/** +* Returns a string created by manually joining array elements using a specified separator. +* +* @private +* @param {Object} x - input array object +* @param {integer} separator - separator +* @returns {string} joined string +* +* @example +* var x = [ 1, 2, 3, 4 ]; +* var out = constructString( x, ',' ); +* // returns '1,2,3,4' +*/ +function constructString( x, separator ) { + var i; + var s; + var v; + s = ''; + for ( i = 0; i < x.length; i++ ) { + v = x[ i ]; + if ( typeof v === 'undefined' || v === null ) { + v = ''; + } + s += v; + if ( i < x.length - 1 ) { + s += separator; + } + } + return s; +} + + +// MAIN // + +/** +* Returns a string created by joining array elements using a specified separator. +* +* @param {Collection} x - input array +* @param {integer} separator - separator to be used in string +* @returns {string} joined string +* +* @example +* var x = [ 1, 2, 3, 4 ]; +* +* var out = join( x, ',' ); +* // returns '1,2,3,4' +* +* @example +* var x = [ 1, 2, 3, null, undefined, 4 ]; +* +* var out = join( x, '-' ); +* // returns '1-2-3---4' +*/ +function join( x, separator ) { + var obj; + if ( hasMethod( x, 'join' ) ) { + return x.join( separator ); + } + obj = arraylike2object( x ); + if ( obj.accessorProtocol ) { + return accessors( obj, separator ); + } + if ( obj.dtype === 'generic' || obj.dtype === null ) { + return constructString( x, separator ); + } + return x.join( separator ); +} + + +// EXPORTS // + +module.exports = join; diff --git a/lib/node_modules/@stdlib/array/base/join/package.json b/lib/node_modules/@stdlib/array/base/join/package.json new file mode 100644 index 00000000000..829703a669a --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/join/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/array/base/join", + "version": "0.0.0", + "description": "Return a string created by joining 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", + "stdtypes", + "types", + "data", + "structure", + "array", + "generic", + "join", + "concat", + "concatenate", + "serialize", + "tostring" + ] +} diff --git a/lib/node_modules/@stdlib/array/base/join/test/test.js b/lib/node_modules/@stdlib/array/base/join/test/test.js new file mode 100644 index 00000000000..5849b500283 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/join/test/test.js @@ -0,0 +1,222 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 AccessorArray = require( '@stdlib/array/base/accessor' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Int32Array = require( '@stdlib/array/int32' ); +var join = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof join, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function joins an array-like object (generic)', function test( t ) { + var expected; + var actual; + var x; + + x = [ 1, 2, 3, null ]; + + expected = '1,2,3,'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + expected = '1-2-3-'; + actual = join( x, '-' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = []; + + expected = ''; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = [ 'hello', '', undefined, null, NaN, undefined ]; + + expected = 'hello,,,,NaN,'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = [ null, undefined, null, undefined ]; + + expected = ',,,'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = [ null, 1, 2, 'testString', undefined ]; + + expected = ',1,2,testString,'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = [ null, 1, 2, NaN, undefined ]; + + expected = ',1,2,NaN,'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = [ 1 ]; + + expected = '1'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function joins an array-like object (float64)', function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + + expected = '1,2,3'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0 ] ); + + expected = '1'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [] ); + + expected = ''; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function joins an array-like object (int32)', function test( t ) { + var expected; + var actual; + var x; + + x = new Int32Array( [ 1, 2, 3 ] ); + + expected = '1,2,3'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = new Int32Array( [] ); + + expected = ''; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = new Int32Array( [ 1 ] ); + + expected = '1'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function joins an array-like object (complex128)', function test( t ) { + var expected; + var actual; + var x; + + x = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0 ] ); + + expected = '1 - 1i,2 - 2i'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = new Complex128Array( [] ); + + expected = ''; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function joins an array-like object (accessors)', function test( t ) { + var expected; + var actual; + var x; + + x = new AccessorArray( [ 1, 2, 3, 4 ] ); + + expected = '1,2,3,4'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = new AccessorArray( [ 1, 2, 3, null, undefined, 4 ] ); + + expected = '1,2,3,,,4'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = new AccessorArray( [ 1 ] ); + + expected = '1'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = new AccessorArray( [ null, undefined, NaN ] ); + + expected = ',,NaN'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = new AccessorArray( [] ); + + expected = ''; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/take-map/README.md b/lib/node_modules/@stdlib/array/base/take-map/README.md new file mode 100644 index 00000000000..5d426e42577 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/README.md @@ -0,0 +1,147 @@ + + +# takeMap + +> Take elements from an array and return a new array after applying a mapping function. + +
+ +## Usage + +```javascript +var takeMap = require( '@stdlib/array/base/take-map' ); +``` + +### takeMap( x, indices, mode, clbk ) + +Takes elements from an array and returns a new array after applying a mapping function. + +```javascript +var x = [ 1, 2, 3, 4 ]; + +function customMapping( value ) { + return value * 2; +} + +var y = takeMap( x, [ 1, 3 ], 'throw', customMapping ); +// returns [ 4, 8 ] +``` + +The function supports the following parameters: + +- **x**: input array. +- **indices**: list of indices. +- **mode**: index [mode][@stdlib/ndarray/base/ind]. +- **clbk**: function to apply. + +### takeMap.assign( x, indices, mode, out, stride, offset, clbk ) + +> Takes elements from an array and assigns the values to elements in a provided output array. + +```javascript +var x = [ 1, 2, 3, 4 ]; + +var out = [ 0, 0, 0, 0, 0, 0 ]; +var indices = [ 0, 0, 1, 1, 3, 3 ]; + +function clbk( val ) { + return val * 2; +} + +var arr = takeMap.assign( x, indices, 'throw', out, -1, out.length-1, clbk ); +// returns [ 8, 8, 4, 4, 2, 2 ] + +var bool = ( arr === out ); +// returns true +``` + +The function supports the following parameters: + +- **x**: input array. +- **indices**: list of indices. +- **mode**: index [mode][@stdlib/ndarray/base/ind]. +- **out**: output array. +- **stride**: output array stride. +- **offset**: output array offset. +- **clbk**: callback function. + +
+ + + +
+ +
+ + + +
+ +## Examples + + + +```javascript +var filledBy = require( '@stdlib/array/base/filled-by' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var linspace = require( '@stdlib/array/base/linspace' ); +var takeMap = require( '@stdlib/array/base/take-map' ); + +// Generate a linearly spaced array: +var x = linspace( 0, 100, 11 ); +console.log( x ); + +// Generate an array of random indices: +var N = discreteUniform( 5, 15 ); +var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) ); +console.log( indices ); + +// Define a mapping function (e.g., square the value): +function square( val ) { + return val * val; +} + +// Take a random sample of elements from `x` and apply the mapping function: +var y = takeMap( x, indices, 'throw', square ); +console.log( y ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.assign.length.js b/lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.assign.length.js new file mode 100644 index 00000000000..5f150f679fd --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.assign.length.js @@ -0,0 +1,109 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var zeros = require( '@stdlib/array/zeros' ); +var isArray = require( '@stdlib/assert/is-array' ); +var pkg = require( './../package.json' ).name; +var takeMap = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var out; + var idx; + + idx = discreteUniform( len, 0, 3, { + 'dtype': 'generic' + }); + out = zeros( len, 'generic' ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var x; + var v; + var i; + + x = [ 1, 2, 3, 4 ]; + function clbk( val ) { + return val; + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = takeMap.assign( x, idx, 'throw', out, 1, 0, clbk ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':assign:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.js new file mode 100644 index 00000000000..e1fef30bd2e --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isArray = require( '@stdlib/assert/is-array' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var pkg = require( './../package.json' ).name; +var takeMap = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::copy:len=100', function benchmark( b ) { + var x; + var i; + var v; + + x = zeroTo( 100 ); + + function clbk( val ) { + return val; + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = takeMap( x, x, 'throw', clbk ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.length.js b/lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.length.js new file mode 100644 index 00000000000..df46e8bd47f --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.length.js @@ -0,0 +1,102 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var isArray = require( '@stdlib/assert/is-array' ); +var pkg = require( './../package.json' ).name; +var takeMap = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var idx = discreteUniform( len, 0, 3 ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var x; + var v; + var i; + + x = [ 1, 2, 3, 4 ]; + + function clbk( val ) { + return val; + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = takeMap( x, idx, 'throw', clbk ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + 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/array/base/take-map/docs/repl.txt b/lib/node_modules/@stdlib/array/base/take-map/docs/repl.txt new file mode 100644 index 00000000000..50ca7670337 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/docs/repl.txt @@ -0,0 +1,89 @@ + +{{alias}}( x, indices, mode, callback ) + Takes elements from an array and returns a new array after applying a + mapping function. + + If `indices` is an empty array, the function returns an empty array. + + Parameters + ---------- + x: ArrayLikeObject + Input array. + + indices: ArrayLikeObject + List of element indices. + + mode: string + Specifies how to handle an index outside the interval [0, max], where + `max` is the maximum possible array index. If equal to 'throw', the + function throws an error. If equal to 'normalize', the function throws + an error if provided an out-of-bounds normalized index. If equal to + 'wrap', the function wraps around an index using modulo arithmetic. If + equal to 'clamp', the function sets an index to either 0 (minimum index) + or the maximum index. + + callback : function + Map function to apply to selected elements of `x`. + + Returns + ------- + out: Array + Output array. + + Examples + -------- + > var x = [ -1, -2, -3, -4 ]; + > var y = {{alias}}( x, [ 1, 3 ], 'throw', {{alias:@stdlib/math/base/special/abs}} ) + [ 2, 4 ] + + +{{alias}}.assign( x, indices, mode, out, stride, offset, callback ) + Takes elements from an array, applies a mapping function, and assigns the + values to elements in a provided output array. + + Parameters + ---------- + x: ArrayLikeObject + Input array. + + indices: ArrayLikeObject + List of element indices. + + mode: string + Specifies how to handle an index outside the interval [0, max], where + `max` is the maximum possible array index. If equal to 'throw', the + function throws an error. If equal to 'normalize', the function throws + an error if provided an out-of-bounds normalized index. If equal to + 'wrap', the function wraps around an index using modulo arithmetic. If + equal to 'clamp', the function sets an index to either 0 (minimum index) + or the maximum index. + + out: ArrayLikeObject + Output array. + + stride: integer + Output array stride. + + offset: integer + Output array offset. + + callback : function + Map function to apply to selected elements of `x`. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + > var x = [ -1, -2, -3, -4 ]; + > var out = [ 0, 0, 0, 0 ]; + > var arr = {{alias}}.assign( x, [ 1, 3 ], 'throw', out, 2, 0 ,{{alias:@stdlib/math/base/special/abs}} ) + [ 2, 0, 4, 0 ] + > var bool = ( arr === out ) + true + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/array/base/take-map/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/take-map/docs/types/index.d.ts new file mode 100644 index 00000000000..cbb0a7ec7cb --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/docs/types/index.d.ts @@ -0,0 +1,206 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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'; +import { Mode } from '@stdlib/types/ndarray'; + +/** +* Index array. +*/ +type IndexArray = Collection | AccessorArrayLike; + +/** +* Callback function invoked for each indexed element. +*/ +type Callback = ( value: T, index: number ) => U; + +/** +* Interface describing `takeMap`. +*/ +interface TakeMap { + /** + * Takes elements from an array based on an index array and applies a callback function to each element. + * + * @param x - input array + * @param indices - list of element indices + * @param mode - index mode + * @param clbk - callback function + * @returns output array + * + * @example + * var x = [ 1, 2, 3, 4 ]; + * + * function transform( v ) { + * return v * 2; + * } + * + * var y = takeMap( x, [ 1, 3 ], 'throw', transform ); + * // returns [ 4, 8 ] + */ + ( x: Collection, indices: IndexArray, mode: Mode, clbk: Callback ): Array; + + /** + * Takes elements from an array based on an index array and applies a callback function to each element. The function assigns the transformed values to elements in a provided output array. + * + * @param x - input array + * @param indices - list of element indices + * @param mode - index mode + * @param clbk - callback function + * @param out - output array + * @param stride - output array stride + * @param offset - output array offset + * @returns output array + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + * var out = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + * + * function transform( v ) { + * return v * 2; + * } + * + * var arr = takeMap.assign( x, [ 1, 3 ], 'throw', transform, out, 2, 0 ); + * // returns [ 4.0, 0.0, 8.0, 0.0 ] + * + * var bool = ( arr === out ); + * // returns true + */ + assign( x: Collection | AccessorArrayLike, indices: IndexArray, mode: Mode, clbk: Callback, out: Collection, stride: number, offset: number ): Collection; + + /** + * Takes elements from an array based on an index array and applies a callback function to each element. The function assigns the transformed values to elements in a provided output array. + * + * @param x - input array + * @param indices - list of element indices + * @param mode - index mode + * @param clbk - callback function + * @param out - output array + * @param stride - output array stride + * @param offset - output array offset + * @returns output array + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * + * var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + * var out = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + * + * function transform( v ) { + * return v * 2; + * } + * + * var arr = takeMap.assign( x, [ 1, 3 ], 'throw', transform, out, 2, 0 ); + * // returns [ 4.0, 0.0, 8.0, 0.0 ] + * + * var bool = ( arr === out ); + * // returns true + */ + assign( x: Collection | AccessorArrayLike, indices: IndexArray, mode: Mode, clbk: Callback, out: AccessorArrayLike, stride: number, offset: number ): AccessorArrayLike; + + /** + * Takes elements from an array based on an index array and applies a callback function to each element. The function assigns the transformed values to elements in a provided output array. + * + * @param x - input array + * @param indices - list of element indices + * @param mode - index mode + * @param clbk - callback function + * @param out - output array + * @param stride - output array stride + * @param offset - output array offset + * @returns output array + * + * @example + * var Complex128Array = require( '@stdlib/array/float64' ); + * + * var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + * var out = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + * + * function transform( v ) { + * return v * 2; + * } + * + * var arr = takeMap.assign( x, [ 1, 3 ], 'throw', transform, out, 2, 0 ); + * // returns [ 4.0, 0.0, 8.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] + * + * var bool = ( arr === out ); + * // returns true + */ + assign( x: Collection | AccessorArrayLike, indices: IndexArray, mode: Mode, clbk: Callback, out: Collection, stride: number, offset: number ): Collection; +} + +/** +* Takes elements from an array based on an index array and applies a callback function to each element. +* +* @param x - input array +* @param indices - list of element indices +* @param mode - index mode +* @param clbk - callback function +* @returns output array +* +* @example +* var x = [ 1, 2, 3, 4 ]; +* +* function transform( v ) { +* return v * 2; +* } +* +* var y = takeMap( x, [ 1, 3 ], 'throw', transform ); +* // returns [ 4, 8 ] +*/ +declare function takeMap( x: Collection | AccessorArrayLike, indices: IndexArray, mode: Mode, clbk: Callback ): Collection; + +/** +* Takes elements from an array based on an index array and applies a callback function to each element. The function assigns the transformed values to elements in a provided output array. +* +* @param x - input array +* @param indices - list of element indices +* @param mode - index mode +* @param clbk - callback function +* @param out - output array +* @param stride - output array stride +* @param offset - output array offset +* @returns output array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var out = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); +* +* function transform( v ) { +* return v * 2; +* } +* +* var arr = takeMap.assign( x, [ 1, 3 ], 'throw', transform, out, 2, 0 ); +* // returns [ 4.0, 0.0, 8.0, 0.0 ] +* +* var bool = ( arr === out ); +* // returns true +*/ +declare function takeMapAssign( x: Collection | AccessorArrayLike, indices: IndexArray, mode: Mode, clbk: Callback, out: Collection, stride: number, offset: number ): Collection; + + +// EXPORTS // + +export = takeMap; diff --git a/lib/node_modules/@stdlib/array/base/take-map/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/take-map/docs/types/test.ts new file mode 100644 index 00000000000..2eaef25ff04 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/docs/types/test.ts @@ -0,0 +1,85 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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 takeMap = require( './index' ); + +// TESTS // + +// The function returns an array... +{ + // eslint-disable-next-line @typescript-eslint/explicit-function-return-type + const transform = ( v: number ) => v * 2; + + takeMap( [ 1, 2, 3, 4 ], [ 1, 3 ], 'throw', transform ); // $ExpectType number[] + takeMap( [ 1, 2, 3, 4 ], [ 1, 3 ], 'normalize', transform ); // $ExpectType any[] + takeMap( [ 1, 2, 3, 4 ], [ 1, 3 ], 'clamp', transform ); // $ExpectType number[] + takeMap( [ '1', '2', '3', '4' ], [ 1, 3 ], 'wrap', transform ); // $ExpectType string[] +} + +// The compiler throws an error if the function is provided a first argument which is not an array-like object... +{ + // eslint-disable-next-line @typescript-eslint/explicit-function-return-type + const transform = ( v: number ) => v * 2; + + takeMap( 1, [ 1, 3 ], 'throw', transform ); // $ExpectError + takeMap( true, [ 1, 3 ], 'throw', transform ); // $ExpectError + takeMap( false, [ 1, 3 ], 'throw', transform ); // $ExpectError + takeMap( null, [ 1, 3 ], 'throw', transform ); // $ExpectError + takeMap( void 0, [ 1, 3 ], 'throw', transform ); // $ExpectError + takeMap( {}, [ 1, 3 ], 'throw', transform ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... +{ + // eslint-disable-next-line @typescript-eslint/explicit-function-return-type + const transform = ( v: number ) => v * 2; + + takeMap( [], 1, 'throw', transform ); // $ExpectError + takeMap( [], true, 'throw', transform ); // $ExpectError + takeMap( [], false, 'throw', transform ); // $ExpectError + takeMap( [], null, 'throw', transform ); // $ExpectError + takeMap( [], void 0, 'throw', transform ); // $ExpectError + takeMap( [], {}, 'throw', transform ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a valid index mode... +{ + // eslint-disable-next-line @typescript-eslint/explicit-function-return-type + const transform = ( v: number ) => v * 2; + + takeMap( [], [ 1, 3 ], '1', transform ); // $ExpectError + takeMap( [], [ 1, 3 ], 1, transform ); // $ExpectError + takeMap( [], [ 1, 3 ], true, transform ); // $ExpectError + takeMap( [], [ 1, 3 ], false, transform ); // $ExpectError + takeMap( [], [ 1, 3 ], null, transform ); // $ExpectError + takeMap( [], [ 1, 3 ], void 0, transform ); // $ExpectError + takeMap( [], [ 1, 3 ], {}, transform ); // $ExpectError + takeMap( [], [ 1, 3 ], [], transform ); // $ExpectError + takeMap( [], [ 1, 3 ], ( x: number ): number => x, transform ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + // eslint-disable-next-line @typescript-eslint/explicit-function-return-type + const transform = ( v: number ) => v * 2; + + takeMap(); // $ExpectError + takeMap( [], [] ); // $ExpectError + takeMap( [], [], 'throw' ); // $ExpectError + takeMap( [], [], 'throw', transform, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/array/base/take-map/examples/index.js b/lib/node_modules/@stdlib/array/base/take-map/examples/index.js new file mode 100644 index 00000000000..0b513736c54 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/examples/index.js @@ -0,0 +1,42 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 filledBy = require( '@stdlib/array/base/filled-by' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var linspace = require( '@stdlib/array/base/linspace' ); +var takeMap = require( './../lib' ); + +// Generate a linearly spaced array: +var x = linspace( 0, 100, 11 ); +console.log( x ); + +// Generate an array of random indices: +var N = discreteUniform( 5, 15 ); +var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) ); +console.log( indices ); + +// Define a mapping function (e.g., square the value): +function square( val ) { + return val * val; +} + +// Take a random sample of elements from `x` and apply the mapping function: +var y = takeMap( x, indices, 'throw', square ); +console.log( y ); diff --git a/lib/node_modules/@stdlib/array/base/take-map/lib/assign.js b/lib/node_modules/@stdlib/array/base/take-map/lib/assign.js new file mode 100644 index 00000000000..5c868c94656 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/lib/assign.js @@ -0,0 +1,277 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isComplexDataType = require( '@stdlib/array/base/assert/is-complex-floating-point-data-type' ); +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex' ); +var ind = require( '@stdlib/ndarray/base/ind' ).factory; + + +// FUNCTIONS // + +/** +* Takes elements from an indexed array and assigns the values to elements in an indexed output array. +* +* @private +* @param {Collection} x - input array. +* @param {IntegerArray} indices - list of indices. +* @param {string} mode - index mode. +* @param {Collection} out - output array. +* @param {integer} stride - output array stride. +* @param {NonNegativeInteger} offset - output array offset. +* @param {Function} clbk - callback function applied to each selected element. +* @returns {Collection} output array. +* +* @example +* var x = [ 1, 2, 3, 4 ]; +* var indices = [ 3, 1, 2, 0 ]; +* var out = [ 0, 0, 0, 0 ]; +* +* function clbk( val ){ + return val; +} +* +* var arr = takeMapIndexed( x, indices, 'throw', out, 1, 0, clbk ); +* // returns [ 4, 2, 3, 1 ] +*/ +function takeMapIndexed( x, indices, mode, out, stride, offset, clbk ) { + var getIndex; + var max; + var io; + var i; + var j; + + // Resolve a function for returning an index according to the specified index mode: + getIndex = ind( mode ); + + // Resolve the maximum index: + max = x.length - 1; + + // Extract each desired element from the provided array... + io = offset; + for ( i = 0; i < indices.length; i++ ) { + j = getIndex( indices[ i ], max ); + out[ io ] = x[ j ]; + io += stride; + } + for (i = 0; i[ 1.0, 2.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ] +*/ +function complexMap( x, indices, mode, out, stride, offset, clbk ) { + var getIndex; + var idata; + var iget; + var max; + var io; + var so; + var i; + var j; + var k; + + idata = indices.data; + iget = indices.accessors[ 0 ]; + + // Resolve a function for returning an index according to the specified index mode: + getIndex = ind( mode ); + + // Resolve the maximum index: + max = ( x.length/2 ) - 1; // resolve the length of the original complex array + + // Extract each desired element from the provided array... + so = stride * 2; // note: multiply by 2, as real-valued array consists of interleaved real and imaginary components + io = offset * 2; + for ( i = 0; i < idata.length; i++ ) { + j = getIndex( iget( idata, i ), max ); + k = j * 2; + + // eslint-disable-next-line no-useless-call + out[ io ] = clbk.call( null, x[ k ], k ); + + // eslint-disable-next-line no-useless-call + out[ io+1 ] = clbk.call( null, x[ k+1 ], k+1 ); + io += so; + } + return out; +} + + +// MAIN // + +/** +* Takes elements from an array and assigns the values to elements in a provided output array. +* +* @param {Collection} x - input array. +* @param {IntegerArray} indices - list of indices. +* @param {string} mode - index mode. +* @param {Collection} out - output array. +* @param {integer} stride - output array stride. +* @param {NonNegativeInteger} offset - output array offset. +* @param {Function} clbk - callback function applied to each selected element. +* @returns {Collection} output array. +* +* @example +* var x = [ 1, 2, 3, 4 ]; +* var indices = [ 3, 1, 2, 0 ]; +* +* var out = [ 0, 0, 0, 0 ]; +* +* function clbk( val ){ + return val; +} +* var arr = assignMap( x, indices, 'throw', out, 1, 0, clbk); +* // arr is [ 4, 2, 3, 1 ] +* +* var bool = ( arr === out ); +* // bool is true +*/ +function assignMap( x, indices, mode, out, stride, offset, clbk ) { + var xo; + var io; + var oo; + + xo = arraylike2object( x ); + io = arraylike2object( indices ); + oo = arraylike2object( out ); + if ( + xo.accessorProtocol || + io.accessorProtocol || + oo.accessorProtocol + ) { + // Note: we only explicitly support complex-to-complex, as this function should not be concerned with casting rules, etc. That is left to userland... + if ( + isComplexDataType( xo.dtype ) && + isComplexDataType( oo.dtype ) + ) { + complexMap( reinterpret( x, 0 ), io, mode, reinterpret( out, 0 ), stride, offset, clbk ); // eslint-disable-line max-len + return out; + } + accessorsMap( xo, io, mode, oo, stride, offset, clbk ); + return out; + } + takeMapIndexed( x, indices, mode, out, stride, offset, clbk ); + return out; +} + + +// EXPORTS // + +module.exports = assignMap; diff --git a/lib/node_modules/@stdlib/array/base/take-map/lib/index.js b/lib/node_modules/@stdlib/array/base/take-map/lib/index.js new file mode 100644 index 00000000000..b3918c07e90 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/lib/index.js @@ -0,0 +1,72 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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'; + +/** +* Take elements from an array and apply a provided function to map values. +* +* @module @stdlib/array/base/take-map +* +* @example +* var takeMap = require( '@stdlib/array/base/take-map' ); +* +* var x = [ 1, 2, 3, 4 ]; +* +* function mapFunction( val ) { + return val; +} +* +* var indices = [ 0, 0, 1, 1, 3, 3 ]; +* var y = takeMap( x, indices, 'throw', mapFunction ); +* // returns [ 1, 1, 2, 2, 4, 4 ] +* +* @example +* var takeMap = require( '@stdlib/array/base/take-map' ); +* +* var x = [ 1, 2, 3, 4 ]; +* +* var out = [ 0, 0, 0, 0, 0, 0 ]; +* var indices = [ 0, 0, 1, 1, 3, 3 ]; +* +* function clbk( val ) { + return val; +} +* +* var arr = takeMap.assign( x, indices, 'throw', out, 1, 0, mapFunction ); +* // returns [ 1, 1, 2, 2, 4, 4 ] +* +* var bool = ( arr === out ); +* // returns true +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var assign = require( './assign.js' ); + + +// MAIN // + +setReadOnly( main, 'assign', assign ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/array/base/take-map/lib/main.js b/lib/node_modules/@stdlib/array/base/take-map/lib/main.js new file mode 100644 index 00000000000..7e9d637e075 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/lib/main.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 resolveGetter = require( '@stdlib/array/base/resolve-getter' ); +var ind = require( '@stdlib/ndarray/base/ind' ).factory; + + +// MAIN // + +/** +* Takes elements from an array, applies a mapping function using a callback, and returns a new array. +* +* @param {Collection} x - input array +* @param {IntegerArray} indices - list of indices +* @param {string} mode - index mode +* @param {Function} clbk - callback to invoke +* @returns {Array} output array +* +* @example +* var x = [ 1, 2, 3, 4 ]; +* var indices = [ 3, 1, 2, 0 ]; +* +* function clbk(val){ + return 2 * val; +} +* +* var y = takeMap( x, indices, 'throw' ,clbk ); +* // returns [ 8, 4, 6, 2 ] +*/ +function takeMap( x, indices, mode, clbk ) { + var getIndex; + var xget; + var iget; + var out; + var max; + var i; + var j; + + // Resolve an accessor for retrieving array elements: + xget = resolveGetter( x ); + iget = resolveGetter( indices ); + + // Resolve a function for returning an index according to the specified index mode: + getIndex = ind( mode ); + + // Resolve the maximum index: + max = x.length - 1; + + // Extract each desired element from the provided array... + out = []; + for ( i = 0; i < indices.length; i++ ) { + j = getIndex( iget( indices, i ), max ); + + // eslint-disable-next-line no-useless-call + out.push( clbk.call( null, xget( x, j ), j ) ); // use `Array#push` to ensure "fast" elements + } + return out; +} + + +// EXPORTS // + +module.exports = takeMap; diff --git a/lib/node_modules/@stdlib/array/base/take-map/package.json b/lib/node_modules/@stdlib/array/base/take-map/package.json new file mode 100644 index 00000000000..b64bac7386f --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/package.json @@ -0,0 +1,62 @@ +{ + "name": "@stdlib/array/base/take-map", + "version": "0.0.0", + "description": "Take elements from an array and return a new array after applying a mapping function.", + "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", + "utilities", + "utils", + "generic", + "array", + "take", + "extract", + "copy", + "index" + ] +} diff --git a/lib/node_modules/@stdlib/array/base/take-map/test/test.assign.js b/lib/node_modules/@stdlib/array/base/take-map/test/test.assign.js new file mode 100644 index 00000000000..7e8156daef4 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/test/test.assign.js @@ -0,0 +1,707 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 Complex128Array = require( '@stdlib/array/complex128' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Float64Array = require( '@stdlib/array/float64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameComplex64Array = require( '@stdlib/assert/is-same-complex64array' ); +var zeros = require( '@stdlib/array/zeros' ); +var takeMap = require( './../lib/assign.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof takeMap, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function takes elements from an array (generic)', function test( t ) { + var expected; + var indices; + var actual; + var out; + var x; + + function clbk( val ) { + return val * val; + } + + x = [ 1, 2, 3, 4 ]; + + indices = [ 1, 3 ]; + out = zeros( indices.length, 'generic' ); + actual = takeMap( x, indices, 'throw', out, 1, 0, clbk ); + expected = [ 4, 16 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + indices = [ 1, 1, 3, 3 ]; + out = zeros( indices.length*2, 'generic' ); + actual = takeMap( x, indices, 'throw', out, 2, 0, clbk ); + expected = [ 4, 0, 4, 0, 16, 0, 16, 0 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + indices = [ 3, 2, 1, 0 ]; + out = zeros( indices.length, 'generic' ); + actual = takeMap( x, indices, 'throw', out, -1, out.length-1, clbk ); + expected = [ 1, 4, 9, 16 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; + out = zeros( indices.length+1, 'generic' ); + actual = takeMap( x, indices, 'throw', out, 1, 1, clbk ); + expected = [ 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function takes and maps elements from an array (real typed array)', function test( t ) { + var expected; + var indices; + var actual; + var out; + var x; + + function clbk( val ) { + return val * 2; + } + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + indices = [ 1, 3 ]; + out = zeros( indices.length, 'float64' ); + actual = takeMap( x, indices, 'throw', out, 1, 0, clbk ); + expected = new Float64Array( [ 4.0, 8.0 ] ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + indices = [ 1, 1, 3, 3 ]; + out = zeros( indices.length*2, 'float64' ); + actual = takeMap( x, indices, 'throw', out, 2, 0, clbk ); + expected = new Float64Array( [ 4.0, 0.0, 4.0, 0.0, 8.0, 0.0, 8.0, 0.0 ] ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + indices = [ 3, 2, 1, 0 ]; + out = zeros( indices.length, 'float64' ); + actual = takeMap( x, indices, 'throw', out, -1, out.length-1, clbk ); + expected = new Float64Array( [ 2.0, 4.0, 6.0, 8.0 ] ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; + out = zeros( indices.length+1, 'float64' ); + actual = takeMap( x, indices, 'throw', out, 1, 1, clbk ); + expected = new Float64Array( [ 0.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0 ] ); // eslint-disable-line max-len + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function takes and maps elements from an array (complex typed array)', function test( t ) { + var expected; + var indices; + var actual; + var out; + var x; + + function clbk( val ) { + return val; + } + + x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + indices = [ 1, 3 ]; + out = zeros( indices.length, 'complex128' ); + actual = takeMap( x, indices, 'throw', out, 1, 0, clbk ); + expected = new Complex128Array( [ 3.0, 4.0, 7.0, 8.0 ] ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameComplex128Array( actual, expected ), true, 'returns expected value' ); + + indices = [ 1, 1, 3, 3 ]; + out = zeros( indices.length*2, 'complex64' ); + actual = takeMap( x, indices, 'throw', out, 2, 0, clbk ); + expected = new Complex64Array( [ 3.0, 4.0, 0.0, 0.0, 3.0, 4.0, 0.0, 0.0, 7.0, 8.0, 0.0, 0.0, 7.0, 8.0, 0.0, 0.0 ] ); // eslint-disable-line max-len + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameComplex64Array( actual, expected ), true, 'returns expected value' ); + + x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + indices = [ 3, 2, 1, 0 ]; + out = zeros( indices.length, 'complex128' ); + actual = takeMap( x, indices, 'throw', out, -1, out.length-1, clbk ); + expected = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); // eslint-disable-line max-len + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameComplex128Array( actual, expected ), true, 'returns expected value' ); + + indices = [ 1, 1, 1, 1 ]; + out = zeros( indices.length+1, 'complex64' ); + actual = takeMap( x, indices, 'throw', out, 1, 1, clbk ); + expected = new Complex64Array( [ 0.0, 0.0, 3.0, 4.0, 3.0, 4.0, 3.0, 4.0, 3.0, 4.0 ] ); // eslint-disable-line max-len + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameComplex64Array( actual, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function takes and maps elements from an array (accessors)', function test( t ) { + var expected; + var indices; + var actual; + var out; + var x; + + function clbk( val ) { + return val + 1; + } + + x = toAccessorArray( [ 1, 2, 3, 4 ] ); + + indices = toAccessorArray( [ 1, 3 ] ); + out = toAccessorArray( zeros( indices.length, 'generic' ) ); + actual = takeMap( x, indices, 'throw', out, 1, 0, clbk ); + expected = [ 3, 5 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + isEqual( actual, expected ); + + indices = toAccessorArray( [ 1, 1, 3, 3 ] ); + out = toAccessorArray( zeros( indices.length*2, 'generic' ) ); + actual = takeMap( x, indices, 'throw', out, 2, 0, clbk ); + expected = [ 3, 0, 3, 0, 5, 0, 5, 0 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + isEqual( actual, expected ); + + indices = toAccessorArray( [ 3, 2, 1, 0 ] ); + out = toAccessorArray( zeros( indices.length, 'generic' ) ); + actual = takeMap( x, indices, 'throw', out, -1, out.length-1, clbk ); + expected = [ 2, 3, 4, 5 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + isEqual( actual, expected ); + + indices = toAccessorArray( [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ] ); + out = toAccessorArray( zeros( indices.length+1, 'generic' ) ); + actual = takeMap( x, indices, 'throw', out, 1, 1, clbk ); + expected = [ 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + isEqual( actual, expected ); + + t.end(); + + function isEqual( actual, expected ) { + var i; + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( actual.get( i ), expected[ i ], 'returns expected value' ); + } + } +}); + +tape( 'the function returns an output array unchanged if provided a second argument which is empty', function test( t ) { + var expected; + var actual; + var out; + var x; + + function clbk( val ) { + return val; + } + + x = [ 1, 2, 3, 4 ]; + out = [ 0, 0, 0, 0 ]; + expected = [ 0, 0, 0, 0 ]; + actual = takeMap( x, [], 'throw', out, 1, 0, clbk ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ 1, 2, 3, 4 ] ); + out = [ 0, 0, 0, 0 ]; + expected = [ 0, 0, 0, 0 ]; + actual = takeMap( x, [], 'throw', out, 1, 0, clbk ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + out = [ 0, 0, 0, 0 ]; + expected = [ 0, 0, 0, 0 ]; + actual = takeMap( x, [], 'throw', out, 1, 0, clbk ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + out = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + expected = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + actual = takeMap( x, [], 'throw', out, 1, 0, clbk ); + t.strictEqual( isSameComplex128Array( actual, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index (generic)', function test( t ) { + var indices; + var out; + var x; + + function clbk( val ) { + return val; + } + + x = [ 1, 2, 3, 4 ]; + indices = [ 4, 5, 1, 2 ]; + out = zeros( x.length, 'generic' ); + + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + takeMap( x, indices, 'throw', out, 1, 0, clbk ); + } +}); + +tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index (accessors)', function test( t ) { + var indices; + var out; + var x; + + function clbk( val ) { + return val; + } + + x = toAccessorArray( [ 1, 2, 3, 4 ] ); + indices = toAccessorArray( [ 4, 5, 1, 2 ] ); + out = toAccessorArray( zeros( x.length, 'generic' ) ); + + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + takeMap( x, indices, 'throw', out, 1, 0, clbk ); + } +}); + +tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index (real typed)', function test( t ) { + var indices; + var out; + var x; + + function clbk( val ) { + return val; + } + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + indices = [ 4, 5, 1, 2 ]; + out = zeros( x.length, 'float64' ); + + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + takeMap( x, indices, 'throw', out, 1, 0, clbk ); + } +}); + +tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index (complex typed)', function test( t ) { + var indices; + var out; + var x; + + function clbk( val ) { + return val; + } + + x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + indices = [ 4, 5, 1, 2 ]; + out = zeros( x.length, 'complex128' ); + + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + takeMap( x, indices, 'throw', out, 1, 0, clbk ); + } +}); + +tape( 'when the "mode" is "normalize", the function normalizes negative indices (generic)', function test( t ) { + var expected; + var indices; + var actual; + var out; + var x; + + function clbk( val ) { + return val * 2; + } + + x = [ 1, 2, 3, 4 ]; + indices = [ -1, -2, -3, -4 ]; + out = zeros( x.length, 'generic' ); + + actual = takeMap( x, indices, 'normalize', out, 1, 0, clbk ); + expected = [ 8, 6, 4, 2 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when the "mode" is "normalize", the function normalizes negative indices (accessors)', function test( t ) { + var expected; + var indices; + var out; + var x; + + function clbk( val ) { + return val; + } + + x = toAccessorArray( [ 1, 2, 3, 4 ] ); + indices = toAccessorArray( [ -1, -2, -3, -4 ] ); + out = zeros( x.length, 'generic' ); + + takeMap( x, indices, 'normalize', toAccessorArray( out ), 1, 0, clbk ); + expected = [ 4, 3, 2, 1 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when the "mode" is "normalize", the function normalizes negative indices (real typed)', function test( t ) { + var expected; + var indices; + var actual; + var out; + var x; + + function clbk( val ) { + return val; + } + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + indices = [ -1, -2, -3, -4 ]; + out = zeros( x.length, 'float64' ); + + actual = takeMap( x, indices, 'normalize', out, 1, 0, clbk ); + expected = new Float64Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when the "mode" is "normalize", the function normalizes negative indices (complex typed)', function test( t ) { + var expected; + var indices; + var actual; + var out; + var x; + + function clbk( val ) { + return val; + } + + x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + indices = [ -1, -2 ]; + out = zeros( x.length, 'complex128' ); + + actual = takeMap( x, indices, 'normalize', out, 1, 0, clbk ); + expected = new Complex128Array( [ 3.0, 4.0, 1.0, 2.0 ] ); + t.strictEqual( isSameComplex128Array( actual, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index (generic)', function test( t ) { + var indices; + var out; + var x; + + function clbk( val ) { + return val; + } + + x = [ 1, 2, 3, 4 ]; + indices = [ 4, 5, 1, 2 ]; + out = zeros( x.length, 'generic' ); + + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + takeMap( x, indices, 'normalize', out, 1, 0, clbk ); + } +}); + +tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index (accessors)', function test( t ) { + var indices; + var out; + var x; + + function clbk( val ) { + return val; + } + + x = toAccessorArray( [ 1, 2, 3, 4 ] ); + indices = toAccessorArray( [ 4, 5, 1, 2 ] ); + out = toAccessorArray( zeros( x.length, 'generic' ) ); + + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + takeMap( x, indices, 'normalize', out, 1, 0, clbk ); + } +}); + +tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index (real typed)', function test( t ) { + var indices; + var out; + var x; + + function clbk( val ) { + return val; + } + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + indices = [ 4, 5, 1, 2 ]; + out = zeros( x.length, 'float64' ); + + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + takeMap( x, indices, 'normalize', out, 1, 0, clbk ); + } +}); + +tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index (complex typed)', function test( t ) { + var indices; + var out; + var x; + + function clbk( val ) { + return val; + } + + x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + indices = [ 4, 5, 1, 2 ]; + out = zeros( x.length, 'complex128' ); + + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + takeMap( x, indices, 'normalize', out, 1, 0, clbk ); + } +}); + +tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices (generic)', function test( t ) { + var expected; + var indices; + var actual; + var out; + var x; + + function clbk( val ) { + return val; + } + + x = [ 1, 2, 3, 4 ]; + indices = [ -10, 10, -5, 5 ]; + out = zeros( x.length, 'generic' ); + + actual = takeMap( x, indices, 'clamp', out, 1, 0, clbk ); + expected = [ 1, 4, 1, 4 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices (accessors)', function test( t ) { + var expected; + var indices; + var out; + var x; + + function clbk( val ) { + return val; + } + + x = toAccessorArray( [ 1, 2, 3, 4 ] ); + indices = toAccessorArray( [ -10, 10, -5, 5 ] ); + out = zeros( x.length, 'generic' ); + + takeMap( x, indices, 'clamp', toAccessorArray( out ), 1, 0, clbk ); + expected = [ 1, 4, 1, 4 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices (real typed)', function test( t ) { + var expected; + var indices; + var actual; + var out; + var x; + + function clbk( val ) { + return val; + } + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + indices = [ -10, 10, -5, 5 ]; + out = zeros( x.length, 'float64' ); + + actual = takeMap( x, indices, 'clamp', out, 1, 0, clbk ); + expected = new Float64Array( [ 1.0, 4.0, 1.0, 4.0 ] ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices (complex typed)', function test( t ) { + var expected; + var indices; + var actual; + var out; + var x; + + function clbk( val ) { + return val; + } + + x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + indices = [ -10, 10, -5, 5 ]; + out = zeros( x.length, 'complex128' ); + + actual = takeMap( x, indices, 'clamp', out, 1, 0, clbk ); + expected = new Complex128Array( [ 1.0, 2.0, 7.0, 8.0, 1.0, 2.0, 7.0, 8.0 ] ); // eslint-disable-line max-len + t.strictEqual( isSameComplex128Array( actual, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices (generic)', function test( t ) { + var expected; + var indices; + var actual; + var out; + var x; + + function clbk( val ) { + return val; + } + + x = [ 1, 2, 3, 4 ]; + indices = [ -10, 10, -5, 5 ]; + out = zeros( x.length, 'generic' ); + + actual = takeMap( x, indices, 'wrap', out, 1, 0, clbk ); + expected = [ 3, 3, 4, 2 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices (accessors)', function test( t ) { + var expected; + var indices; + var out; + var x; + + function clbk( val ) { + return val; + } + + x = toAccessorArray( [ 1, 2, 3, 4 ] ); + indices = toAccessorArray( [ -10, 10, -5, 5 ] ); + out = zeros( x.length, 'generic' ); + + takeMap( x, indices, 'wrap', toAccessorArray( out ), 1, 0, clbk ); + expected = [ 3, 3, 4, 2 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices (real typed)', function test( t ) { + var expected; + var indices; + var actual; + var out; + var x; + + function clbk( val ) { + return val; + } + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + indices = [ -10, 10, -5, 5 ]; + out = zeros( x.length, 'float64' ); + + actual = takeMap( x, indices, 'wrap', out, 1, 0, clbk ); + expected = new Float64Array( [ 3.0, 3.0, 4.0, 2.0 ] ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices (complex typed)', function test( t ) { + var expected; + var indices; + var actual; + var out; + var x; + + function clbk( val ) { + return val; + } + + x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + indices = [ -10, 10, -5, 5 ]; + out = zeros( x.length, 'complex128' ); + + actual = takeMap( x, indices, 'wrap', out, 1, 0, clbk ); + expected = new Complex128Array( [ 5.0, 6.0, 5.0, 6.0, 7.0, 8.0, 3.0, 4.0 ] ); // eslint-disable-line max-len + t.strictEqual( isSameComplex128Array( actual, expected ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/take-map/test/test.js b/lib/node_modules/@stdlib/array/base/take-map/test/test.js new file mode 100644 index 00000000000..a03afc0f668 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/test/test.js @@ -0,0 +1,41 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var hasMethod = require( '@stdlib/assert/is-method' ); +var takeMap = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof takeMap, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( hasOwnProp( takeMap, 'assign' ), true, 'returns expected value' ); + t.strictEqual( hasMethod( takeMap, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/take-map/test/test.main.js b/lib/node_modules/@stdlib/array/base/take-map/test/test.main.js new file mode 100644 index 00000000000..e783cef7146 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/test/test.main.js @@ -0,0 +1,212 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 Complex64Array = require( '@stdlib/array/complex64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var realf = require( '@stdlib/complex/realf' ); +var imagf = require( '@stdlib/complex/imagf' ); +var isComplex64 = require( '@stdlib/assert/is-complex64' ); +var takeMap = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof takeMap, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( typeof takeMap.assign, 'function', 'assign method is a function' ); + t.end(); +}); + +tape( 'the function takes elements from an array', function test( t ) { + var expected; + var indices; + var actual; + var x; + + function clbk( v ) { + return v*v; + } + + x = [ 1, 2, 3, 4 ]; + + indices = [ 1, 3 ]; + actual = takeMap( x, indices, 'throw', clbk ); + expected = [ 4, 16 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + indices = [ 1, 1, 3, 3 ]; + actual = takeMap( x, indices, 'throw', clbk ); + expected = [ 4, 4, 16, 16 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + indices = [ 3, 2, 1, 0 ]; + actual = takeMap( x, indices, 'throw', clbk ); + expected = [ 16, 9, 4, 1 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; + actual = takeMap( x, indices, 'throw', clbk ); + expected = [ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function takes elements from an array (accessors)', function test( t ) { + var expected; + var indices; + var actual; + var x; + var v; + var i; + + function clbk( v ) { + return v; + } + + x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + indices = toAccessorArray( [ 1, 1, 3, 3 ] ); + actual = takeMap( x, indices, 'throw', clbk ); + + t.notEqual( actual, x, 'returns different reference' ); + for ( i = 0; i < indices.length; i++ ) { + v = actual[ i ]; + expected = x.get( indices.get( i ) ); + t.strictEqual( isComplex64( v ), true, 'returns expected value' ); + t.strictEqual( realf( v ), realf( expected ), 'returns expected value' ); + t.strictEqual( imagf( v ), imagf( expected ), 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function returns an empty array if provided a second argument which is empty', function test( t ) { + var x = [ 1, 2, 3, 4 ]; + function clbk( v ) { + return v; + } + t.deepEqual( takeMap( x, [], 'throw' ), [], 'returns expected value', clbk ); + t.end(); +}); + +tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index', function test( t ) { + var indices; + var x; + + function clbk( v ) { + return v; + } + + x = [ 1, 2, 3, 4 ]; + indices = [ 4, 5, 1, 2 ]; + + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + takeMap( x, indices, 'throw', clbk ); + } +}); + +tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { + var expected; + var indices; + var actual; + var x; + + function clbk( v ) { + return v*2; + } + + x = [ 1, 2, 3, 4 ]; + + indices = [ -1, -2, -3, -4 ]; + actual = takeMap( x, indices, 'normalize', clbk ); + expected = [ 8, 6, 4, 2 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index', function test( t ) { + var indices; + var x; + + function clbk( v ) { + return v; + } + + x = [ 1, 2, 3, 4 ]; + indices = [ 2, 50, 1, 2 ]; + + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + takeMap( x, indices, 'normalize', clbk ); + } +}); + +tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { + var expected; + var indices; + var actual; + var x; + + function clbk( v ) { + return v; + } + + x = [ 1, 2, 3, 4 ]; + + indices = [ -10, 10, -5, 5 ]; + actual = takeMap( x, indices, 'clamp', clbk ); + expected = [ 1, 4, 1, 4 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices', function test( t ) { + var expected; + var indices; + var actual; + var x; + + function clbk( v ) { + return v; + } + + x = [ 1, 2, 3, 4 ]; + + indices = [ -10, 10, -5, 5 ]; + actual = takeMap( x, indices, 'wrap', clbk ); + expected = [ 3, 3, 4, 2 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/assert/is-boolean/benchmark/benchmark.js b/lib/node_modules/@stdlib/assert/is-boolean/benchmark/benchmark.js index 3ae451e9ea0..c79db99ffbd 100644 --- a/lib/node_modules/@stdlib/assert/is-boolean/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/assert/is-boolean/benchmark/benchmark.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable no-new-wrappers, no-empty-function */ +/* eslint-disable no-empty-function */ 'use strict'; @@ -30,7 +30,32 @@ var isBoolean = require( './../lib' ); // MAIN // -bench( pkg+'::primitives', function benchmark( b ) { +bench( pkg+'::primitives,true', function benchmark( b ) { + var values; + var bool; + var i; + + values = [ + true, + false + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isBoolean( values[ i % values.length ] ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean.isPrimitive( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::primitives,false', function benchmark( b ) { var values; var bool; var i; @@ -39,8 +64,6 @@ bench( pkg+'::primitives', function benchmark( b ) { '5', 5, NaN, - true, - false, null, void 0 ]; @@ -60,7 +83,32 @@ bench( pkg+'::primitives', function benchmark( b ) { b.end(); }); -bench( pkg+'::objects', function benchmark( b ) { +bench( pkg+'::objects,true', function benchmark( b ) { + var values; + var bool; + var i; + + values = [ + new Boolean( true ), + new Boolean( false ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isBoolean( values[ i % values.length ] ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean.isPrimitive( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::objects,false', function benchmark( b ) { var values; var bool; var i; @@ -68,8 +116,7 @@ bench( pkg+'::objects', function benchmark( b ) { values = [ [], {}, - function noop() {}, - new Boolean( true ) + function noop() {} ]; b.tic(); @@ -87,7 +134,32 @@ bench( pkg+'::objects', function benchmark( b ) { b.end(); }); -bench( pkg+'::primitives:isPrimitive', function benchmark( b ) { +bench( pkg+'::primitives:isPrimitive,true', function benchmark( b ) { + var values; + var bool; + var i; + + values = [ + true, + false + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isBoolean.isPrimitive( values[ i % values.length ] ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean.isPrimitive( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::primitives:isPrimitive,false', function benchmark( b ) { var values; var bool; var i; @@ -96,8 +168,6 @@ bench( pkg+'::primitives:isPrimitive', function benchmark( b ) { '5', 5, NaN, - true, - false, null, void 0 ]; @@ -117,7 +187,7 @@ bench( pkg+'::primitives:isPrimitive', function benchmark( b ) { b.end(); }); -bench( pkg+'::objects:isPrimitive', function benchmark( b ) { +bench( pkg+'::objects:isPrimitive,false', function benchmark( b ) { var values; var bool; var i; @@ -144,7 +214,7 @@ bench( pkg+'::objects:isPrimitive', function benchmark( b ) { b.end(); }); -bench( pkg+'::primitives:isObject', function benchmark( b ) { +bench( pkg+'::primitives:isObject,false', function benchmark( b ) { var values; var bool; var i; @@ -174,7 +244,32 @@ bench( pkg+'::primitives:isObject', function benchmark( b ) { b.end(); }); -bench( pkg+'::objects:isObject', function benchmark( b ) { +bench( pkg+'::objects:isObject,true', function benchmark( b ) { + var values; + var bool; + var i; + + values = [ + new Boolean( true ), + new Boolean( false ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isBoolean.isObject( values[ i % values.length ] ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean.isPrimitive( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::objects:isObject,false', function benchmark( b ) { var values; var bool; var i; @@ -182,8 +277,7 @@ bench( pkg+'::objects:isObject', function benchmark( b ) { values = [ [], {}, - function noop() {}, - new Boolean( true ) + function noop() {} ]; b.tic(); diff --git a/lib/node_modules/@stdlib/assert/is-same-date-object/README.md b/lib/node_modules/@stdlib/assert/is-same-date-object/README.md new file mode 100644 index 00000000000..ca7a7af7a88 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-same-date-object/README.md @@ -0,0 +1,90 @@ + + +# isSameDateObject + +> Test if two values are [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) objects corresponding to the same date and time. + +
+ +## Usage + +```javascript +var isSameDateObject = require( '@stdlib/assert/is-same-date-object' ); +``` + +#### isSameDateObject( d1, d2 ) + +Tests if two values are both Date objects corresponding to the same date and time. + +```javascript +var d1 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); +var d2 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); +var bool = isSameDateObject( d1, d2 ); +// returns true + +bool = isSameDateObject( d1, new Date( 2023, 11, 31, 23, 59, 59, 78 ) ); +// returns false +``` + +
+ + + +
+ +## Examples + + + +```javascript +var isSameDateObject = require( '@stdlib/assert/is-same-date-object' ); + +var d1 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); +var d2 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); + +var bool = isSameDateObject( d1, d2 ); +// returns true + +d1 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); +d2 = new Date( 2024, 11, 31, 23, 59, 59, 78 ); + +bool = isSameDateObject( d1, d2 ); +// returns false + +d1 = new Date(); +d2 = new Date( '2024-12-31T23:59:59.999' ); + +bool = isSameDateObject( d1, d2 ); +// returns false + +var d3 = new Date( 2024, 11, 31 ); +var d4 = new Date( 'December 31, 2024 23:59:59:999' ); + +bool = isSameDateObject( d1, d3 ); +// returns false + +bool = isSameDateObject( d2, d4 ); +// returns true +``` + +
+ + diff --git a/lib/node_modules/@stdlib/assert/is-same-date-object/benchmark/benchmark.js b/lib/node_modules/@stdlib/assert/is-same-date-object/benchmark/benchmark.js new file mode 100644 index 00000000000..3c000a5afc7 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-same-date-object/benchmark/benchmark.js @@ -0,0 +1,62 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var isSameDateObject = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var date1; + var date2; + var bool; + var i; + values = [ + '5', + 'Date', + new Date( 'December 31, 2024 23:59:59:999' ), + new Date( '2024-12-31T23:59:59.999' ), + NaN, + true, + false, + null + ]; + date1 = new Date(); + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + date2 = values[ i%values.length ]; + bool = isSameDateObject( date1, date2 ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/assert/is-same-date-object/docs/repl.txt b/lib/node_modules/@stdlib/assert/is-same-date-object/docs/repl.txt new file mode 100644 index 00000000000..e5078d77477 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-same-date-object/docs/repl.txt @@ -0,0 +1,32 @@ + +{{alias}}( d1, d2 ) + Tests if two values are both Date objects corresponding + to the same date and time. + + Parameters + ---------- + d1: any + First input value. + d2: any + Second input value. + + Returns + ------- + bool: boolean + Boolean indicating whether both values are Date objects + corresponding to the same date and time. + + Examples + -------- + > var d1 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); + > var d2 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); + > var bool = {{alias}}( d1, d2 ) + true + > var d1 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); + > var d2 = new Date( 2024, 11, 31, 23, 59, 59, 78 ); + > var bool = {{alias}}( d1, d2 ) + false + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/assert/is-same-date-object/docs/types/index.d.ts b/lib/node_modules/@stdlib/assert/is-same-date-object/docs/types/index.d.ts new file mode 100644 index 00000000000..557a16d2e67 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-same-date-object/docs/types/index.d.ts @@ -0,0 +1,47 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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 + +/** +* Tests if two values are both Date objects corresponding to the same date and time. +* +* @param d1 - first input value +* @param d2 - second input value +* @returns boolean indicating whether both are Date objects corresponding to the same date and time. +* +* @example +* var d1 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); +* var d2 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); +* +* var bool = isSameDateObject( d1, d2 ); +* // returns true +* +* @example +* var d1 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); +* var d2 = new Date( 2024, 11, 31, 23, 59, 59, 78 ); +* +* var bool = isSameDateObject( d1, d2 ); +* // returns false +*/ +declare function isSameDateObject( d1: any, d2: any ): boolean; + + +// EXPORTS // + +export = isSameDateObject; diff --git a/lib/node_modules/@stdlib/assert/is-same-date-object/docs/types/test.ts b/lib/node_modules/@stdlib/assert/is-same-date-object/docs/types/test.ts new file mode 100644 index 00000000000..0bc2ed487ab --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-same-date-object/docs/types/test.ts @@ -0,0 +1,36 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isSameDateObject = require( './index' ); + + +// TESTS // + +// The function returns a boolean... +{ + isSameDateObject( new Date(), new Date() ); // $ExpectType boolean + isSameDateObject( null, null ); // $ExpectType boolean + isSameDateObject( 'beep', 'boop' ); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + isSameDateObject(); // $ExpectError + isSameDateObject( new Date() ); // $ExpectError + isSameDateObject( 'beep', 'beep', new Date() ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/assert/is-same-date-object/examples/index.js b/lib/node_modules/@stdlib/assert/is-same-date-object/examples/index.js new file mode 100644 index 00000000000..000083c8070 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-same-date-object/examples/index.js @@ -0,0 +1,51 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isSameDateObject = require( './../lib' ); + +var d1 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); +var d2 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); + +var bool = isSameDateObject( d1, d2 ); +console.log( bool ); +// => true + +d1 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); +d2 = new Date( 2024, 11, 31, 23, 59, 59, 78 ); + +bool = isSameDateObject( d1, d2 ); +console.log( bool ); +// => false + +d1 = new Date(); +d2 = new Date( '2024-12-31T23:59:59.999' ); +bool = isSameDateObject( d1, d2 ); +// returns false + +var d3 = new Date( 2024, 11, 31 ); +var d4 = new Date( 'December 31, 2024 23:59:59:999' ); + +bool = isSameDateObject( d1, d3 ); +console.log( bool ); +// => false + +bool = isSameDateObject( d2, d4 ); +console.log( bool ); +// => true diff --git a/lib/node_modules/@stdlib/assert/is-same-date-object/lib/index.js b/lib/node_modules/@stdlib/assert/is-same-date-object/lib/index.js new file mode 100644 index 00000000000..8344411ffca --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-same-date-object/lib/index.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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'; + +/** +* Test if two arguments are both Date objects corresponding to the same date and time. +* +* @module @stdlib/assert/is-same-date-object +* +* @example +* var isSameDateObject = require( '@stdlib/assert/is-same-date-object' ); +* +* var d1 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); +* var d2 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); +* +* var bool = isSameDateObject( d1, d2 ); +* // returns true +* +* @example +* var isSameDateObject = require( '@stdlib/assert/is-same-date-object' ); +* +* var d1 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); +* var d2 = new Date( 2024, 11, 31, 23, 59, 59, 78 ); +* +* var bool = isSameDateObject( d1, d2 ); +* // returns false +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/assert/is-same-date-object/lib/main.js b/lib/node_modules/@stdlib/assert/is-same-date-object/lib/main.js new file mode 100644 index 00000000000..d804d00bcd4 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-same-date-object/lib/main.js @@ -0,0 +1,57 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isDateObject = require( '@stdlib/assert/is-date-object' ); + + +// MAIN // + +/** +* Tests if two arguments are both Date objects corresponding to the same date and time. +* +* @param {*} d1 - first value +* @param {*} d2 - second value +* @returns {boolean} boolean result +* +* @example +* var d1 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); +* var d2 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); +* var bool = isSameDateObject( d1, d2 ); +* // returns true +* +* @example +* var d1 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); +* var d2 = new Date( 2024, 11, 31, 23, 59, 59, 78 ); +* var bool = isSameDateObject( d1, d2 ); +* // returns false +*/ +function isSameDateObject( d1, d2 ) { + if ( isDateObject( d1 ) && isDateObject( d2 ) ) { + return d1.getTime() === d2.getTime(); + } + return false; +} + + +// EXPORTS // + +module.exports = isSameDateObject; diff --git a/lib/node_modules/@stdlib/assert/is-same-date-object/package.json b/lib/node_modules/@stdlib/assert/is-same-date-object/package.json new file mode 100644 index 00000000000..185de950003 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-same-date-object/package.json @@ -0,0 +1,77 @@ +{ + "name": "@stdlib/assert/is-same-date-object", + "version": "0.0.0", + "description": "Test if two values are both Date objects corresponding to the same date and time.", + "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", + "stdassert", + "assertion", + "assert", + "utilities", + "utility", + "utils", + "util", + "equal", + "same", + "strict", + "is", + "issame", + "issamevalue", + "isequal", + "isstrictequal", + "type", + "check", + "valid", + "validate", + "test", + "date", + "time", + "generic" + ] +} diff --git a/lib/node_modules/@stdlib/assert/is-same-date-object/test/test.js b/lib/node_modules/@stdlib/assert/is-same-date-object/test/test.js new file mode 100644 index 00000000000..1f85c75dca8 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-same-date-object/test/test.js @@ -0,0 +1,90 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isSameDateObject = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isSameDateObject, 'function', 'main export is a function' ); + t.end(); +} ); + +tape( 'the function returns `true` if provided two Date objects corresponding to the same date and time', function test( t ) { + var d1; + var d2; + + d1 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); + t.strictEqual( isSameDateObject( d1, d1 ), true, 'returns expected value' ); + + d1 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); + d2 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); + t.strictEqual( isSameDateObject( d1, d2 ), true, 'returns expected value' ); + + d1 = new Date( 'December 31, 2024 23:59:59:999' ); + d2 = new Date( '2024-12-31T23:59:59.999' ); + t.strictEqual( isSameDateObject( d1, d2 ), true, 'returns expected value' ); + + t.end(); +} ); + +tape( 'the function returns `false` if not provided two Date objects corresponding to the same date and time', function test( t ) { + var d1; + var d2; + + d1 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); + d2 = new Date( 2024, 11, 31, 23, 59, 59, 78 ); + t.strictEqual( isSameDateObject( d1, d2 ), false, 'returns expected value' ); + + d1 = new Date(); + d2 = new Date( 2024, 11, 31, 23, 59, 59, 999 ); + t.strictEqual( isSameDateObject( d1, d2 ), false, 'returns expected value' ); + + d1 = new Date( 2024, 11, 31 ); + d2 = new Date( 2024, 11, 30 ); + t.strictEqual( isSameDateObject( d1, d2 ), false, 'returns expected value' ); + + d1 = new Date( 2024, 11, 31 ); + d2 = 'string'; + t.strictEqual( isSameDateObject( d1, d2 ), false, 'returns expected value' ); + + d1 = new Date( 2024, 11, 31 ); + d2 = 1; + t.strictEqual( isSameDateObject( d1, d2 ), false, 'returns expected value' ); + + d1 = new Date( 2024, 11, 31 ); + d2 = undefined; + t.strictEqual( isSameDateObject( d1, d2 ), false, 'returns expected value' ); + + d1 = new Date( 2024, 11, 31 ); + d2 = {}; + t.strictEqual( isSameDateObject( d1, d2 ), false, 'returns expected value' ); + + d1 = new Date( 2024, 11, 31 ); + d2 = []; + t.strictEqual( isSameDateObject( d1, d2 ), false, 'returns expected value' ); + + t.end(); +} ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/docs/types/index.d.ts index 17432901c94..e47c736c52e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/docs/types/index.d.ts @@ -2916,7 +2916,7 @@ interface Namespace { * @param N - number of indexed elements * @param x - input array * @param stride - stride length - * @returns `x` + * @returns input array * * @example * var Float32Array = require( '@stdlib/array/float32' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/srev/README.md b/lib/node_modules/@stdlib/blas/ext/base/srev/README.md index 059eee9a1a3..d9b2cbd85f1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/srev/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/srev/README.md @@ -49,16 +49,14 @@ The function has the following parameters: - **x**: input [`Float32Array`][@stdlib/array/float32]. - **stride**: index increment. -The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to reverse every other element +The `N` and `stride` parameters determine which elements in the strided array are accessed at runtime. For example, to reverse every other element ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); -var N = floor( x.length / 2 ); -srev( N, x, 2 ); +srev( 4, x, 2 ); // x => [ -1.0, 1.0, 4.0, -5.0, 3.0, 0.0, -2.0, -3.0 ] ``` @@ -66,17 +64,15 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); // Initial array... var x0 = new Float32Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); // Create an offset view... var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length/2 ); // Reverse every other element... -srev( N, x1, 2 ); +srev( 3, x1, 2 ); // x0 => [ 1.0, -6.0, 3.0, -4.0, 5.0, -2.0 ] ``` @@ -97,7 +93,7 @@ The function has the following additional parameters: - **offset**: 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 `x` +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 Float32Array = require( '@stdlib/array/float32' ); @@ -116,7 +112,7 @@ srev.ndarray( 3, x, 1, x.length-3 ); ## Notes -- If `N <= 0`, both functions return `x` unchanged. +- If `N <= 0`, both functions return the strided array unchanged. - Where possible, one should "reverse" a strided array by negating its stride, which is an `O(1)` operation, in contrast to performing an in-place reversal, which is `O(N)`. However, in certain circumstances, this is not tenable, particularly when interfacing with libraries which assume and/or expect a specific memory layout (e.g., strided array elements arranged in memory in ascending order). In general, when working with strided arrays, only perform an in-place reversal when strictly necessary. @@ -130,27 +126,13 @@ srev.ndarray( 3, x, 1, x.length-3 ); ```javascript -var round = require( '@stdlib/math/base/special/round' ); -var randu = require( '@stdlib/random/base/randu' ); -var Float32Array = require( '@stdlib/array/float32' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var srev = require( '@stdlib/blas/ext/base/srev' ); -var rand; -var sign; -var x; -var i; - -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - rand = round( randu()*100.0 ); - sign = randu(); - if ( sign < 0.5 ) { - sign = -1.0; - } else { - sign = 1.0; - } - x[ i ] = sign * rand; -} +var rand = discreteUniform( -100, 100 ); + +var x = filledarrayBy( 10, 'float32', rand ); console.log( x ); srev( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/srev/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/srev/benchmark/benchmark.js index ddf0b510174..5fb56f6b5ca 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/srev/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/srev/benchmark/benchmark.js @@ -21,14 +21,19 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var srev = require( './../lib/srev.js' ); +// VARIABLES // + +var rand = uniform( -10.0, 10.0 ); + + // FUNCTIONS // /** @@ -39,13 +44,7 @@ var srev = require( './../lib/srev.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < len; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/srev/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/srev/benchmark/benchmark.native.js index d1be25ce39a..02f9829c194 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/srev/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/srev/benchmark/benchmark.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,6 +36,7 @@ var srev = tryRequire( resolve( __dirname, './../lib/srev.native.js' ) ); var opts = { 'skip': ( srev instanceof Error ) }; +var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -48,13 +49,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < len; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/srev/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/srev/benchmark/benchmark.ndarray.js index 86ceebe03a4..623d7ad8650 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/srev/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/srev/benchmark/benchmark.ndarray.js @@ -21,14 +21,19 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var srev = require( './../lib/ndarray.js' ); +// VARIABLES // + +var rand = uniform( -10.0, 10.0 ); + + // FUNCTIONS // /** @@ -39,13 +44,7 @@ var srev = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < len; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/srev/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/srev/benchmark/benchmark.ndarray.native.js index 103928d0ae9..755e42bf0e1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/srev/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/srev/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,6 +36,7 @@ var srev = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( srev instanceof Error ) }; +var rand = uniform( -10.0, 10.0 ); // FUNCTIONS // @@ -48,13 +49,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < len; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/srev/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/srev/docs/repl.txt index b1aa34c06d2..e826a2ec66f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/srev/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/srev/docs/repl.txt @@ -2,8 +2,8 @@ {{alias}}( N, x, stride ) Reverses a single-precision floating-point strided array in-place. - The `N` and `stride` parameters determine which elements in `x` are accessed - at runtime. + 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 typed array views. @@ -24,7 +24,7 @@ Returns ------- x: Float32Array - Input array `x`. + Input array. Examples -------- @@ -35,19 +35,18 @@ // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}( N, x, 2 ) + > {{alias}}( 3, x, 2 ) [ 4.0, 1.0, 3.0, -5.0, -2.0, -1.0, -3.0 ] // Using view offsets: > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > {{alias}}( N, x1, 2 ) + > {{alias}}( 3, x1, 2 ) [ -6.0, 3.0, -4.0, 5.0, -2.0 ] > x0 [ 1.0, -6.0, 3.0, -4.0, 5.0, -2.0 ] + {{alias}}.ndarray( N, x, stride, offset ) Reverses a single-precision floating-point strided array in-place using alternative indexing semantics. @@ -73,7 +72,7 @@ Returns ------- x: Float32Array - Input array `x`. + Input array. Examples -------- @@ -84,8 +83,7 @@ // Using an index offset: > x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, x, 2, 1 ) + > {{alias}}.ndarray( 3, x, 2, 1 ) [ 1.0, -6.0, 3.0, -4.0, 5.0, -2.0 ] See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/srev/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/srev/docs/types/index.d.ts index dca4d827962..658e02347a1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/srev/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/srev/docs/types/index.d.ts @@ -28,7 +28,7 @@ interface Routine { * @param N - number of indexed elements * @param x - input array * @param stride - stride length - * @returns `x` + * @returns input array * * @example * var Float32Array = require( '@stdlib/array/float32' ); @@ -47,7 +47,7 @@ interface Routine { * @param x - input array * @param stride - stride length * @param offset - starting index - * @returns `x` + * @returns input array * * @example * var Float32Array = require( '@stdlib/array/float32' ); @@ -66,7 +66,7 @@ interface Routine { * @param N - number of indexed elements * @param x - input array * @param stride - stride length -* @returns `x` +* @returns input array * * @example * var Float32Array = require( '@stdlib/array/float32' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/srev/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/srev/examples/index.js index d59641e3185..2e809742345 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/srev/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/srev/examples/index.js @@ -18,27 +18,13 @@ 'use strict'; -var round = require( '@stdlib/math/base/special/round' ); -var randu = require( '@stdlib/random/base/randu' ); -var Float32Array = require( '@stdlib/array/float32' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var srev = require( './../lib' ); -var rand; -var sign; -var x; -var i; +var rand = discreteUniform( -100, 100 ); -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - rand = round( randu()*100.0 ); - sign = randu(); - if ( sign < 0.5 ) { - sign = -1.0; - } else { - sign = 1.0; - } - x[ i ] = sign * rand; -} +var x = filledarrayBy( 10, 'float32', rand ); console.log( x ); srev( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/srev/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/srev/include.gypi index 868c5c12e85..26476a8c265 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/srev/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/srev/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.cpp', + '<(src_dir)/addon.c', ' + +/** +* Receives JavaScript callback invocation data. +* +* @private +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 3 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, stride, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 1 ); + c_srev( N, X, stride ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/srev/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/srev/src/addon.cpp deleted file mode 100644 index 8a4d952d74d..00000000000 --- a/lib/node_modules/@stdlib/blas/ext/base/srev/src/addon.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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. -*/ - -#include "stdlib/blas/ext/base/srev.h" -#include -#include -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_blas_ext_base_srev { - - /** - * Reverses a single-precision floating-point strided array in-place. - * - * ## Notes - * - * - When called from JavaScript, the function expects three arguments: - * - * - `N`: number of indexed elements - * - `X`: input array - * - `strideX`: `X` stride length - */ - napi_value node_srev( napi_env env, napi_callback_info info ) { - napi_status status; - - size_t argc = 3; - napi_value argv[ 3 ]; - status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); - assert( status == napi_ok ); - - if ( argc < 3 ) { - napi_throw_error( env, nullptr, "invalid invocation. Must provide 3 arguments." ); - return nullptr; - } - - napi_valuetype vtype0; - status = napi_typeof( env, argv[ 0 ], &vtype0 ); - assert( status == napi_ok ); - if ( vtype0 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); - return nullptr; - } - - bool res1; - status = napi_is_typedarray( env, argv[ 1 ], &res1 ); - assert( status == napi_ok ); - if ( res1 == false ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float32Array." ); - return nullptr; - } - - napi_valuetype vtype2; - status = napi_typeof( env, argv[ 2 ], &vtype2 ); - assert( status == napi_ok ); - if ( vtype2 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a number." ); - return nullptr; - } - - int64_t N; - status = napi_get_value_int64( env, argv[ 0 ], &N ); - assert( status == napi_ok ); - - int64_t strideX; - status = napi_get_value_int64( env, argv[ 2 ], &strideX ); - assert( status == napi_ok ); - - napi_typedarray_type vtype1; - size_t xlen; - void *X; - status = napi_get_typedarray_info( env, argv[ 1 ], &vtype1, &xlen, &X, nullptr, nullptr ); - assert( status == napi_ok ); - if ( vtype1 != napi_float32_array ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float32Array." ); - return nullptr; - } - if ( (N-1)*llabs(strideX) >= (int64_t)xlen ) { - napi_throw_range_error( env, nullptr, "invalid argument. Second argument has insufficient elements based on the associated stride and the number of indexed elements." ); - return nullptr; - } - - c_srev( N, (float *)X, strideX ); - - return nullptr; - } - - napi_value Init( napi_env env, napi_value exports ) { - napi_status status; - napi_value fcn; - status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_srev, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_blas_ext_base_srev diff --git a/lib/node_modules/@stdlib/blas/ext/base/srev/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/srev/test/test.ndarray.js index 4b4cae7eeec..dc6f7f49a7f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/srev/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/srev/test/test.ndarray.js @@ -92,7 +92,7 @@ tape( 'the function returns a reference to the input array', function test( t ) t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', function test( t ) { var expected; var x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/srev/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/srev/test/test.ndarray.native.js index 796802255b5..76a0816a0a6 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/srev/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/srev/test/test.ndarray.native.js @@ -101,7 +101,7 @@ tape( 'the function returns a reference to the input array', opts, function test t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', opts, function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', opts, function test( t ) { var expected; var x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/srev/test/test.srev.js b/lib/node_modules/@stdlib/blas/ext/base/srev/test/test.srev.js index 45b95d71f45..5f593186bbc 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/srev/test/test.srev.js +++ b/lib/node_modules/@stdlib/blas/ext/base/srev/test/test.srev.js @@ -92,7 +92,7 @@ tape( 'the function returns a reference to the input array', function test( t ) t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', function test( t ) { var expected; var x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/srev/test/test.srev.native.js b/lib/node_modules/@stdlib/blas/ext/base/srev/test/test.srev.native.js index 0a67705562b..695ef7609ba 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/srev/test/test.srev.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/srev/test/test.srev.native.js @@ -101,7 +101,7 @@ tape( 'the function returns a reference to the input array', opts, function test t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', opts, function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', opts, function test( t ) { var expected; var x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumors/README.md b/lib/node_modules/@stdlib/blas/ext/base/ssumors/README.md index 27f3e43d255..1bb2708c2ad 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumors/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumors/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2020 The Stdlib Authors. +Copyright (c) 2024 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. @@ -56,16 +56,14 @@ The function has the following parameters: - **x**: input [`Float32Array`][@stdlib/array/float32]. - **stride**: index increment for `x`. -The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the sum of every other element in `x`, +The `N` and `stride` parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of every other element in `x`, ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); -var N = floor( x.length / 2 ); -var v = ssumors( N, x, 2 ); +var v = ssumors( 4, x, 2 ); // returns 5.0 ``` @@ -75,14 +73,11 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length / 2 ); - -var v = ssumors( N, x1, 2 ); +var v = ssumors( 4, x1, 2 ); // returns 5.0 ``` @@ -108,12 +103,10 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -var N = floor( x.length / 2 ); -var v = ssumors.ndarray( N, x, 2, 1 ); +var v = ssumors.ndarray( 4, x, 2, 1 ); // returns 5.0 ``` @@ -139,18 +132,11 @@ var v = ssumors.ndarray( N, x, 2, 1 ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float32Array = require( '@stdlib/array/float32' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var ssumors = require( '@stdlib/blas/ext/base/ssumors' ); -var x; -var i; - -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*100.0 ); -} +var x = filledarrayBy( 10, 'float32', discreteUniform( -100.0, 100.0 ) ); console.log( x ); var v = ssumors( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumors/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ssumors/benchmark/benchmark.js index 14202a4ae21..e2ced82c9d3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumors/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumors/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -21,14 +21,19 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var ssumors = require( './../lib/ssumors.js' ); +// VARIABLES // + +var rand = uniform( -100.0, 100.0 ); + + // FUNCTIONS // /** @@ -39,13 +44,7 @@ var ssumors = require( './../lib/ssumors.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*10.0 ) - 20.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumors/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/ssumors/benchmark/benchmark.native.js index 182af8a0d18..4704db358d0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumors/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumors/benchmark/benchmark.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,6 +36,7 @@ var ssumors = tryRequire( resolve( __dirname, './../lib/ssumors.native.js' ) ); var opts = { 'skip': ( ssumors instanceof Error ) }; +var rand = uniform( -100.0, 100.0 ); // FUNCTIONS // @@ -48,13 +49,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*10.0 ) - 20.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumors/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/ssumors/benchmark/benchmark.ndarray.js index d1e87438aa6..1914b4ca36b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumors/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumors/benchmark/benchmark.ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -21,14 +21,19 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var ssumors = require( './../lib/ndarray.js' ); +// VARIABLES // + +var rand = uniform( -100.0, 100.0 ); + + // FUNCTIONS // /** @@ -39,13 +44,7 @@ var ssumors = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*10.0 ) - 20.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumors/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/ssumors/benchmark/benchmark.ndarray.native.js index 00e628e2e82..8ecc9047e1e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumors/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumors/benchmark/benchmark.ndarray.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,6 +36,7 @@ var ssumors = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( ssumors instanceof Error ) }; +var rand = uniform( -100.0, 100.0 ); // FUNCTIONS // @@ -48,13 +49,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*10.0 ) - 20.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumors/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ssumors/docs/repl.txt index 679ad382d36..1446e4e653f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumors/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumors/docs/repl.txt @@ -3,8 +3,8 @@ Computes the sum of single-precision floating-point strided array elements using ordinary recursive summation. - The `N` and `stride` parameters determine which elements in `x` are accessed - at runtime. + 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. @@ -36,19 +36,16 @@ // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > var stride = 2; - > {{alias}}( N, x, stride ) + > {{alias}}( 3, x, 2 ) 1.0 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > stride = 2; - > {{alias}}( N, x1, stride ) + > {{alias}}( 3, x1, 2 ) -1.0 + {{alias}}.ndarray( N, x, stride, offset ) Computes the sum of single-precision floating-point strided array elements using ordinary recursive summation and alternative indexing semantics. @@ -84,9 +81,8 @@ 1.0 // Using offset parameter: - > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, x, 2, 1 ) + > x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > {{alias}}.ndarray( 3, x, 2, 1 ) -1.0 See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumors/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ssumors/examples/index.js index abce62d2367..b558dc6ed42 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumors/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumors/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -18,18 +18,11 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float32Array = require( '@stdlib/array/float32' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var ssumors = require( './../lib' ); -var x; -var i; - -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*100.0 ); -} +var x = filledarrayBy( 10, 'float32', discreteUniform( -100.0, 100.0 ) ); console.log( x ); var v = ssumors( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumors/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/ssumors/include.gypi index 868c5c12e85..26476a8c265 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumors/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumors/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.cpp', + '<(src_dir)/addon.c', ' +#include + +/** +* Receives JavaScript callback invocation data. +* +* @private +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 3 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, stride, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 1 ); + + napi_value v; + napi_status status = napi_create_double( env, (double)stdlib_strided_ssumors( N, (float *)X, stride ), &v ); + assert( status == napi_ok ); + + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumors/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/ssumors/src/addon.cpp deleted file mode 100644 index 59e7b26886d..00000000000 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumors/src/addon.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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. -*/ - -#include "stdlib/blas/ext/base/ssumors.h" -#include -#include -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_blas_ext_base_ssumors { - - /** - * Computes the sum of single-precision floating-point strided array elements using ordinary recursive summation. - * - * ## Notes - * - * - When called from JavaScript, the function expects three arguments: - * - * - `N`: number of indexed elements - * - `X`: input array - * - `stride`: stride length - */ - napi_value node_ssumors( napi_env env, napi_callback_info info ) { - napi_status status; - - size_t argc = 3; - napi_value argv[ 3 ]; - status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); - assert( status == napi_ok ); - - if ( argc < 3 ) { - napi_throw_error( env, nullptr, "invalid invocation. Must provide 3 arguments." ); - return nullptr; - } - - napi_valuetype vtype0; - status = napi_typeof( env, argv[ 0 ], &vtype0 ); - assert( status == napi_ok ); - if ( vtype0 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); - return nullptr; - } - - bool res; - status = napi_is_typedarray( env, argv[ 1 ], &res ); - assert( status == napi_ok ); - if ( res == false ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float32Array." ); - return nullptr; - } - - napi_valuetype vtype2; - status = napi_typeof( env, argv[ 2 ], &vtype2 ); - assert( status == napi_ok ); - if ( vtype2 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a number." ); - return nullptr; - } - - int64_t N; - status = napi_get_value_int64( env, argv[ 0 ], &N ); - assert( status == napi_ok ); - - int64_t stride; - status = napi_get_value_int64( env, argv[ 2 ], &stride ); - assert( status == napi_ok ); - - napi_typedarray_type vtype1; - size_t xlen; - void *X; - status = napi_get_typedarray_info( env, argv[ 1 ], &vtype1, &xlen, &X, nullptr, nullptr ); - assert( status == napi_ok ); - if ( vtype1 != napi_float32_array ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float32Array." ); - return nullptr; - } - if ( (N-1)*llabs(stride) >= (int64_t)xlen ) { - napi_throw_range_error( env, nullptr, "invalid argument. Second argument has insufficient elements based on the associated stride and the number of indexed elements." ); - return nullptr; - } - - napi_value v; - status = napi_create_double( env, (double)stdlib_strided_ssumors( N, (float *)X, stride ), &v ); - assert( status == napi_ok ); - - return v; - } - - napi_value Init( napi_env env, napi_value exports ) { - napi_status status; - napi_value fcn; - status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_ssumors, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_blas_ext_base_ssumors diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumors/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/ssumors/test/test.ndarray.js index 98f1e751fa5..6c36f24a018 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumors/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumors/test/test.ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var ssumors = require( './../lib/ndarray.js' ); @@ -36,7 +35,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 4', function test( t ) { - t.strictEqual( ssumors.length, 4, 'has expected arity' ); + t.strictEqual( ssumors.length, 4, 'returns expected value' ); t.end(); }); @@ -110,7 +109,7 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); + N = 4; v = ssumors( N, x, 2, 0 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -133,7 +132,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); + N = 4; v = ssumors( N, x, -2, 6 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -167,7 +166,7 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]); - N = floor( x.length / 2 ); + N = 4; v = ssumors( N, x, 2, 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumors/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/ssumors/test/test.ndarray.native.js index d296d7925a4..17708b47b5d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumors/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumors/test/test.ndarray.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -45,7 +44,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 4', opts, function test( t ) { - t.strictEqual( ssumors.length, 4, 'has expected arity' ); + t.strictEqual( ssumors.length, 4, 'returns expected value' ); t.end(); }); @@ -119,7 +118,7 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); + N = 4; v = ssumors( N, x, 2, 0 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -142,7 +141,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); + N = 4; v = ssumors( N, x, -2, 6 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -176,7 +175,7 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { 3.0, 4.0 // 3 ]); - N = floor( x.length / 2 ); + N = 4; v = ssumors( N, x, 2, 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumors/test/test.ssumors.js b/lib/node_modules/@stdlib/blas/ext/base/ssumors/test/test.ssumors.js index f2c2bf43b42..275aa3635b1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumors/test/test.ssumors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumors/test/test.ssumors.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var ssumors = require( './../lib/ssumors.js' ); @@ -36,7 +35,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 3', function test( t ) { - t.strictEqual( ssumors.length, 3, 'has expected arity' ); + t.strictEqual( ssumors.length, 3, 'returns expected value' ); t.end(); }); @@ -110,7 +109,7 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); + N = 4; v = ssumors( N, x, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -133,7 +132,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); + N = 4; v = ssumors( N, x, -2 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -171,7 +170,7 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); + N = 4; v = ssumors( N, x1, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumors/test/test.ssumors.native.js b/lib/node_modules/@stdlib/blas/ext/base/ssumors/test/test.ssumors.native.js index 862d2dc95fb..26570499999 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumors/test/test.ssumors.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumors/test/test.ssumors.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -45,7 +44,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 3', opts, function test( t ) { - t.strictEqual( ssumors.length, 3, 'has expected arity' ); + t.strictEqual( ssumors.length, 3, 'returns expected value' ); t.end(); }); @@ -201,7 +200,7 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); + N = 4; v = ssumors( N, x, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -224,7 +223,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); + N = 4; v = ssumors( N, x, -2 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -262,7 +261,7 @@ tape( 'the function supports view offsets', opts, function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); + N = 4; v = ssumors( N, x1, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/README.md b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/README.md index cd38c2d01ea..89ac46033fd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2020 The Stdlib Authors. +Copyright (c) 2024 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. @@ -56,16 +56,14 @@ The function has the following parameters: - **x**: input [`Float32Array`][@stdlib/array/float32]. - **stride**: index increment for `x`. -The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the sum of every other element in `x`, +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of every other element in `x`, ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); -var N = floor( x.length / 2 ); -var v = ssumpw( N, x, 2 ); +var v = ssumpw( 4, x, 2 ); // returns 5.0 ``` @@ -75,14 +73,11 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length / 2 ); - -var v = ssumpw( N, x1, 2 ); +var v = ssumpw( 4, x1, 2 ); // returns 5.0 ``` @@ -108,12 +103,10 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -var N = floor( x.length / 2 ); -var v = ssumpw.ndarray( N, x, 2, 1 ); +var v = ssumpw.ndarray( 4, x, 2, 1 ); // returns 5.0 ``` @@ -139,18 +132,11 @@ var v = ssumpw.ndarray( N, x, 2, 1 ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float32Array = require( '@stdlib/array/float32' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var ssumpw = require( '@stdlib/blas/ext/base/ssumpw' ); -var x; -var i; - -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*100.0 ); -} +var x = filledarrayBy(10, 'float32', discreteUniform(0, 100)); console.log( x ); var v = ssumpw( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/benchmark/benchmark.js index 5560d04682a..3d80ee7c0e6 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -21,14 +21,19 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var ssumpw = require( './../lib/ssumpw.js' ); +// VARIABLES // + +var rand = uniform( -100.0, 100.0 ); + + // FUNCTIONS // /** @@ -39,13 +44,7 @@ var ssumpw = require( './../lib/ssumpw.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*10.0 ) - 20.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/benchmark/benchmark.native.js index 63976466780..75eba90307e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/benchmark/benchmark.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,6 +36,7 @@ var ssumpw = tryRequire( resolve( __dirname, './../lib/ssumpw.native.js' ) ); var opts = { 'skip': ( ssumpw instanceof Error ) }; +var rand = uniform( -100.0, 100.0 ); // FUNCTIONS // @@ -48,13 +49,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*10.0 ) - 20.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/benchmark/benchmark.ndarray.js index 03ac333f321..2d9da5ceedc 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/benchmark/benchmark.ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -21,14 +21,19 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var ssumpw = require( './../lib/ndarray.js' ); +// VARIABLES // + +var rand = uniform( -100.0, 100.0 ); + + // FUNCTIONS // /** @@ -39,13 +44,7 @@ var ssumpw = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*10.0 ) - 20.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/benchmark/benchmark.ndarray.native.js index 7cc835edcdb..5d45da4c73c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/benchmark/benchmark.ndarray.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,6 +36,7 @@ var ssumpw = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( ssumpw instanceof Error ) }; +var rand = uniform( -100.0, 100.0 ); // FUNCTIONS // @@ -48,13 +49,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*10.0 ) - 20.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/docs/repl.txt index 1c5f2cf4027..124979eb58c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/docs/repl.txt @@ -3,8 +3,8 @@ Computes the sum of single-precision floating-point strided array elements using pairwise summation. - The `N` and `stride` parameters determine which elements in `x` are accessed - at runtime. + 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. @@ -36,19 +36,16 @@ // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > var stride = 2; - > {{alias}}( N, x, stride ) + > {{alias}}( 3, x, 2 ) 1.0 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > stride = 2; - > {{alias}}( N, x1, stride ) + > {{alias}}( 3, x1, 2 ) -1.0 + {{alias}}.ndarray( N, x, stride, offset ) Computes the sum of single-precision floating-point strided array elements using pairwise summation and alternative indexing semantics. @@ -84,9 +81,8 @@ 1.0 // Using offset parameter: - > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, x, 2, 1 ) + > x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > {{alias}}.ndarray( 3, x, 2, 1 ) -1.0 See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/examples/index.js index bfbc22ac7d7..c8c4a83414d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -18,18 +18,11 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float32Array = require( '@stdlib/array/float32' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var ssumpw = require( './../lib' ); -var x; -var i; - -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*100.0 ); -} +var x = filledarrayBy( 10, 'float32', discreteUniform( -100.0, 100.0 ) ); console.log( x ); var v = ssumpw( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/include.gypi index 868c5c12e85..26476a8c265 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.cpp', + '<(src_dir)/addon.c', ' +#include + +/** +* Receives JavaScript callback invocation data. +* +* @private +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 3 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, stride, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 1 ); + + napi_value v; + napi_status status = napi_create_double( env, (double)stdlib_strided_ssumpw( N, (float *)X, stride ), &v ); + assert( status == napi_ok ); + + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/src/addon.cpp deleted file mode 100644 index 88de5819375..00000000000 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/src/addon.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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. -*/ - -#include "stdlib/blas/ext/base/ssumpw.h" -#include -#include -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_blas_ext_base_ssumpw { - - /** - * Computes the sum of single-precision floating-point strided array elements using pairwise summation. - * - * ## Notes - * - * - When called from JavaScript, the function expects three arguments: - * - * - `N`: number of indexed elements - * - `X`: input array - * - `stride`: stride length - */ - napi_value node_ssumpw( napi_env env, napi_callback_info info ) { - napi_status status; - - size_t argc = 3; - napi_value argv[ 3 ]; - status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); - assert( status == napi_ok ); - - if ( argc < 3 ) { - napi_throw_error( env, nullptr, "invalid invocation. Must provide 3 arguments." ); - return nullptr; - } - - napi_valuetype vtype0; - status = napi_typeof( env, argv[ 0 ], &vtype0 ); - assert( status == napi_ok ); - if ( vtype0 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); - return nullptr; - } - - bool res; - status = napi_is_typedarray( env, argv[ 1 ], &res ); - assert( status == napi_ok ); - if ( res == false ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float32Array." ); - return nullptr; - } - - napi_valuetype vtype2; - status = napi_typeof( env, argv[ 2 ], &vtype2 ); - assert( status == napi_ok ); - if ( vtype2 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a number." ); - return nullptr; - } - - int64_t N; - status = napi_get_value_int64( env, argv[ 0 ], &N ); - assert( status == napi_ok ); - - int64_t stride; - status = napi_get_value_int64( env, argv[ 2 ], &stride ); - assert( status == napi_ok ); - - napi_typedarray_type vtype1; - size_t xlen; - void *X; - status = napi_get_typedarray_info( env, argv[ 1 ], &vtype1, &xlen, &X, nullptr, nullptr ); - assert( status == napi_ok ); - if ( vtype1 != napi_float32_array ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float32Array." ); - return nullptr; - } - if ( (N-1)*llabs(stride) >= (int64_t)xlen ) { - napi_throw_range_error( env, nullptr, "invalid argument. Second argument has insufficient elements based on the associated stride and the number of indexed elements." ); - return nullptr; - } - - napi_value v; - status = napi_create_double( env, (double)stdlib_strided_ssumpw( N, (float *)X, stride ), &v ); - assert( status == napi_ok ); - - return v; - } - - napi_value Init( napi_env env, napi_value exports ) { - napi_status status; - napi_value fcn; - status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_ssumpw, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_blas_ext_base_ssumpw diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/test/test.ndarray.js index fe76d087c67..e9c183089d5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/test/test.ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var ssumpw = require( './../lib/ndarray.js' ); @@ -36,7 +35,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 4', function test( t ) { - t.strictEqual( ssumpw.length, 4, 'has expected arity' ); + t.strictEqual( ssumpw.length, 4, 'returns expected value' ); t.end(); }); @@ -118,7 +117,7 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); + N = 4; v = ssumpw( N, x, 2, 0 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -142,7 +141,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); + N = 4; v = ssumpw( N, x, -2, 6 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -184,7 +183,7 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]); - N = floor( x.length / 2 ); + N = 4; v = ssumpw( N, x, 2, 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/test/test.ndarray.native.js index 4c34bbc7f16..99493e472db 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/test/test.ndarray.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -45,7 +44,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 4', opts, function test( t ) { - t.strictEqual( ssumpw.length, 4, 'has expected arity' ); + t.strictEqual( ssumpw.length, 4, 'returns expected value' ); t.end(); }); @@ -127,7 +126,7 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); + N = 4; v = ssumpw( N, x, 2, 0 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -151,7 +150,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); + N = 4; v = ssumpw( N, x, -2, 6 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -193,7 +192,7 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { 3.0, 4.0 // 3 ]); - N = floor( x.length / 2 ); + N = 4; v = ssumpw( N, x, 2, 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/test/test.ssumpw.js b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/test/test.ssumpw.js index 9107ad8d25d..ea6438f6a75 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/test/test.ssumpw.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/test/test.ssumpw.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var ssumpw = require( './../lib/ssumpw.js' ); @@ -36,7 +35,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 3', function test( t ) { - t.strictEqual( ssumpw.length, 3, 'has expected arity' ); + t.strictEqual( ssumpw.length, 3, 'returns expected value' ); t.end(); }); @@ -103,9 +102,9 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; + var N; x = new Float32Array([ 1.0, // 0 @@ -118,7 +117,7 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); + N = 4; v = ssumpw( N, x, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -126,10 +125,10 @@ tape( 'the function supports a `stride` parameter', function test( t ) { }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; var i; + var N; x = new Float32Array([ 1.0, // 3 @@ -142,7 +141,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); + N = 4; v = ssumpw( N, x, -2 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -172,8 +171,8 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', function test( t ) { var x0; var x1; - var N; var v; + var N; x0 = new Float32Array([ 2.0, @@ -187,9 +186,8 @@ tape( 'the function supports view offsets', function test( t ) { 6.0 ]); + N = 4; x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = ssumpw( N, x1, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/test/test.ssumpw.native.js b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/test/test.ssumpw.native.js index c83329086b5..f8c3bac2d29 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssumpw/test/test.ssumpw.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssumpw/test/test.ssumpw.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -45,7 +44,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 3', opts, function test( t ) { - t.strictEqual( ssumpw.length, 3, 'has expected arity' ); + t.strictEqual( ssumpw.length, 3, 'returns expected value' ); t.end(); }); @@ -209,7 +208,7 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); + N = 4; v = ssumpw( N, x, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -233,7 +232,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); + N = 4; v = ssumpw( N, x, -2 ); t.strictEqual( v, 5.0, 'returns expected value' ); @@ -279,7 +278,7 @@ tape( 'the function supports view offsets', opts, function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); + N = 4; v = ssumpw( N, x1, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/constants/int32/max/README.md b/lib/node_modules/@stdlib/constants/int32/max/README.md index 3ed9c8db901..a2a96d70871 100644 --- a/lib/node_modules/@stdlib/constants/int32/max/README.md +++ b/lib/node_modules/@stdlib/constants/int32/max/README.md @@ -62,6 +62,60 @@ console.log( INT32_MAX ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/constants/int32/max.h" +``` + +#### STDLIB_CONSTANT_INT32_MAX + +Macro for the maximum [signed 32-bit integer][max-int32]. + +
+ + + + + +
+ +
+ + + + + +
+ +
+ + + +
+ + +