From 199641d0b99ae9c85569156f85a220483b18707d Mon Sep 17 00:00:00 2001 From: Varad Gupta Date: Thu, 22 Feb 2024 01:11:19 +0530 Subject: [PATCH 01/22] Added new example for namespace packages --- README.md | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 52c4319e7f48..ae64de5c8962 100644 --- a/README.md +++ b/README.md @@ -291,35 +291,53 @@ var arr = ndarray( [ [ 1, 2 ], [ 3, 4 ] ] ); ### Namespaces -stdlib is comprised of various top-level namespaces (i.e., collections of related functionality united by common themes). For example, to install all math functionality found in the top-level `math` namespace, +stdlib is comprised of various top-level namespaces (i.e., collections of related functionality united by common themes). For example, to install all time functionality found in the top-level `time` namespace, ```bash -$ npm install @stdlib/math +$ npm install @stdlib/time ``` Once installed, packages within a top-level namespace can be individually required/imported to minimize load times and decrease bundle sizes. For example, to use `require` ```javascript -var sin = require( '@stdlib/math/base/special/sin' ); +var daysInMonth = require( '@stdlib/time/days-in-month' ); -var v = sin( 3.14 ); +var num = daysInMonth(); // returns ``` +To determine the number of days for a particular month and year, provide month and year arguments. + +```javascript +var num = daysInMonth( 2 ); +// returns + +num = daysInMonth( 2, 2016 ); +// returns 29 + +num = daysInMonth( 2, 2017 ); +// returns 28 +``` + and to use `import` ```javascript -import sin from '@stdlib/math/base/special/sin'; +import daysInMonth from '@stdlib/time/days-in-month'; -var v = sin( 3.14 ); -// returns +var v; +var i; + +for ( i = 0; i < 2021; i++ ) { + v = daysInMonth( 'feb', i ); + console.log( 'In the year %d, February has %d days.', i, v ); +} ``` -**Note**: installing nested namespaces found within top-level namespaces (e.g., `math/base`) is **not** supported. Consider installing individual packages or the relevant top-level namespace. +**Note**: installing nested namespaces found within top-level namespaces is **not** supported. Consider installing individual packages or the relevant top-level namespace. From dd5797f698729d1ad482264b47e49a7ce740f19e Mon Sep 17 00:00:00 2001 From: Varad Gupta Date: Thu, 22 Feb 2024 18:56:09 +0530 Subject: [PATCH 02/22] Added take-map and added namespace new examples --- README.md | 51 +- .../@stdlib/array/base/take-map/README.md | 124 ++++ .../benchmark/benchmark.assign.length.js | 106 +++ .../base/take-map/benchmark/benchmark.js | 52 ++ .../take-map/benchmark/benchmark.length.js | 98 +++ .../@stdlib/array/base/take-map/docs/repl.txt | 94 +++ .../array/base/take-map/docs/types/index.d.ts | 217 +++++++ .../array/base/take-map/docs/types/test.ts | 80 +++ .../array/base/take-map/examples/index.js | 42 ++ .../@stdlib/array/base/take-map/lib/assign.js | 201 ++++++ .../@stdlib/array/base/take-map/lib/index.js | 64 ++ .../@stdlib/array/base/take-map/lib/main.js | 77 +++ .../@stdlib/array/base/take-map/package.json | 62 ++ .../array/base/take-map/test/test.assign.js | 607 ++++++++++++++++++ .../@stdlib/array/base/take-map/test/test.js | 46 ++ .../array/base/take-map/test/test.main.js | 181 ++++++ 16 files changed, 2081 insertions(+), 21 deletions(-) create mode 100644 lib/node_modules/@stdlib/array/base/take-map/README.md create mode 100644 lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.assign.length.js create mode 100644 lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.length.js create mode 100644 lib/node_modules/@stdlib/array/base/take-map/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/array/base/take-map/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/array/base/take-map/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/array/base/take-map/examples/index.js create mode 100644 lib/node_modules/@stdlib/array/base/take-map/lib/assign.js create mode 100644 lib/node_modules/@stdlib/array/base/take-map/lib/index.js create mode 100644 lib/node_modules/@stdlib/array/base/take-map/lib/main.js create mode 100644 lib/node_modules/@stdlib/array/base/take-map/package.json create mode 100644 lib/node_modules/@stdlib/array/base/take-map/test/test.assign.js create mode 100644 lib/node_modules/@stdlib/array/base/take-map/test/test.js create mode 100644 lib/node_modules/@stdlib/array/base/take-map/test/test.main.js diff --git a/README.md b/README.md index ae64de5c8962..daf9e3031052 100644 --- a/README.md +++ b/README.md @@ -296,29 +296,34 @@ stdlib is comprised of various top-level namespaces (i.e., collections of relate ```bash -$ npm install @stdlib/time +$ npm install @stdlib/string ``` -Once installed, packages within a top-level namespace can be individually required/imported to minimize load times and decrease bundle sizes. For example, to use `require` +Once installed, packages within a top-level namespace can be individually required/imported to minimize load times and decrease bundle sizes. ```javascript -var daysInMonth = require( '@stdlib/time/days-in-month' ); +var uppercase = require( '@stdlib/string/uppercase' ); -var num = daysInMonth(); -// returns +var str = uppercase( 'bEEp' ); +// returns 'BEEP' ``` +```javascript +var startsWith = require( '@stdlib/string/starts-with' ); -To determine the number of days for a particular month and year, provide month and year arguments. +var str = 'To be, or not to be, that is the question.'; -```javascript -var num = daysInMonth( 2 ); -// returns +var bool = startsWith( str, 'To be' ); +// returns true -num = daysInMonth( 2, 2016 ); -// returns 29 +bool = startsWith( str, 'to be' ); +// returns false +``` +```javascript +var removeWords = require( '@stdlib/string/remove-words' ); -num = daysInMonth( 2, 2017 ); -// returns 28 +var str = 'beep boop Foo bar'; +var out = removeWords( str, [ 'boop', 'foo' ] ); +// returns 'beep Foo bar' ``` and to use `import` @@ -326,18 +331,22 @@ and to use `import` ```javascript -import daysInMonth from '@stdlib/time/days-in-month'; +import pascalcase from '@stdlib/string/pascalcase'; -var v; -var i; +var out = pascalcase( 'foo bar' ); +// returns 'FooBar' -for ( i = 0; i < 2021; i++ ) { - v = daysInMonth( 'feb', i ); - console.log( 'In the year %d, February has %d days.', i, v ); -} +out = pascalcase( 'IS_MOBILE' ); +// returns 'IsMobile' + +out = pascalcase( 'Hello World!' ); +// returns 'HelloWorld' + +out = pascalcase( '--foo-bar--' ); +// returns 'FooBar' ``` -**Note**: installing nested namespaces found within top-level namespaces is **not** supported. Consider installing individual packages or the relevant top-level namespace. +**Note**: installing nested namespaces found within top-level namespaces (..string/lowercase) is **not** supported. Consider installing individual packages or the relevant top-level namespace. 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 000000000000..ee93ba0ddfb9 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/README.md @@ -0,0 +1,124 @@ + + +# take + +> Combine the functionality of take and map into a single API call. + +
+ +## Usage + +```javascript +var take = require( '@stdlib/array/base/take-map' ); +``` + +#### take( x, indices, mode, clbk[, thisArg]) + +Combines the take and map operations into a single API call. + +```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**: The input array from which elements will be selected based on the provided indices. +- **indices**: An array of indices indicating the positions of elements to be selected from the input array. +- **mode**: index [mode][@stdlib/ndarray/base/ind]. +- **clbk**: A callback function that maps each selected value specified by indices to the corresponding output value. +- **thisArg**: An optional parameter that can be used to set the this value within the 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 take = require('@stdlib/array/base/take'); +var takeMap = require('@stdlib/array/base/take-map'); + +// Generate a linearly spaced array: +var x = linspace(0, 100, 11); +console.log('Original Array:', x); + +// Generate an array of random indices: +var N = discreteUniform(5, 15); +var indices = filledBy(N, discreteUniform.factory(0, x.length - 1)); +console.log('Generated Indices:', indices); + +// Take a random sample of elements from `x` using `take`: +var yTake = take(x, indices, 'throw'); +console.log('Taken Elements using take:', yTake); + +// Define a custom mapping function: +function customMapping(value) { + return value * 2; +} + +// Take a random sample of elements from `x` and apply custom mapping using `takeMap`: +var yTakeMap = takeMap(x, indices, 'throw', customMapping); +console.log('Taken and Mapped Elements using takeMap:', yTakeMap); + +``` + +
+ + + + + + + + + + + + + + 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 000000000000..95ea8a0e9af8 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.assign.length.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 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 take = 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 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = take.assign( x, idx, 'throw', out, 1, 0 ); + 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 000000000000..a3413b3e0c43 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 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 take = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::copy:len=100', function benchmark( b ) { + var x; + var i; + var v; + + x = zeroTo( 100 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = take( x, x, 'throw' ); + 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 000000000000..1ac63bf0f443 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.length.js @@ -0,0 +1,98 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 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 take = 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 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = take( x, idx, 'throw' ); + 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 000000000000..00b670361f2b --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/docs/repl.txt @@ -0,0 +1,94 @@ + +{{alias}}( x, indices, mode, callback ) + Takes elements with given indices from x and pass the values from tha call back 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 + The map function to apply on selected elements of x. + + Returns + ------- + out: Array + Output array. + + Examples + -------- + function square(x){ + return x * x; + } + > var x = [ 1, 2, 3, 4 ]; + > var y = {{alias}}( x, [ 1, 3 ], 'throw',square ) + [ 4, 16] + + +{{alias}}.assign( x, indices, mode, callback, out, stride, offset ) + Takes elements from an array, passes via callback 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. + + callback : function + The map function to apply on selected elements of x. + + out: ArrayLikeObject + Output array. + + stride: integer + Output array stride. + + offset: integer + Output array offset. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + > function square(x){ + return x * x; + } + > var x = [ 1, 2, 3, 4 ]; + > var out = [ 0, 0, 0, 0 ]; + > var arr = {{alias}}.assign( x, [ 1, 3 ], 'throw', square, out, 2, 0 ) + [ 4, 0, 16, 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 000000000000..983cb70fd6f5 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/docs/types/index.d.ts @@ -0,0 +1,217 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 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 { 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 { + // Implementation... + return {} as 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 { + return {} as Collection; +}; + +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 000000000000..2d3f60f513d7 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/docs/types/test.ts @@ -0,0 +1,80 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2022 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... +{ + 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... +{ + 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... +{ + 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... +{ + 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... +{ + 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 000000000000..818e0f310dba --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/examples/index.js @@ -0,0 +1,42 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 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/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/lib/assign.js b/lib/node_modules/@stdlib/array/base/take-map/lib/assign.js new file mode 100644 index 000000000000..d96197555bc5 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/lib/assign.js @@ -0,0 +1,201 @@ +/** +* @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 ]; + * + * var arr = takeMapIndexed( x, indices, 'throw', out, 1, 0, function(val) { + * return val; + * }); + * // arr is [ 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 ] = clbk( x[ j ] ); + io += stride; + } + return out; +} + +/** + * Takes elements from an accessor array and assigns the values to elements in an accessor output array. + * + * @private + * @param {Object} x - Input array object. + * @param {Object} indices - Index array object. + * @param {string} mode - Index mode. + * @param {Object} out - Output array object. + * @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); + * var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); + * + * var x = toAccessorArray( [ 1, 2, 3, 4 ] ); + * var indices = toAccessorArray( [ 3, 1, 2, 0 ] ); + * + * var out = toAccessorArray( [ 0, 0, 0, 0 ] ); + * var arr = accessorsMap( arraylike2object( x ), arraylike2object( indices ), 'throw', arraylike2object( out ), 1, 0, function(val) { + * return val; + * }); + * + * var v = arr.get( 0 ); + * // v is 4 + */ +function accessorsMap( x, indices, mode, out, stride, offset, clbk ) { + var getIndex; + var xdata; + var idata; + var odata; + var xget; + var iget; + var oset; + var max; + var io; + var i; + var j; + + xdata = x.data; + idata = indices.data; + odata = out.data; + + xget = x.accessors[ 0 ]; + iget = indices.accessors[ 0 ]; + oset = out.accessors[ 1 ]; + + // Resolve a function for returning an index according to the specified index mode: + getIndex = ind( mode ); + + // Resolve the maximum index: + max = xdata.length - 1; + + // Extract each desired element from the provided array... + io = offset; + for (i = 0; i < idata.length; i++) { + j = getIndex(iget(idata, i), max); + oset(odata, io, clbk(xget(xdata, j))); + io += stride; + } + return odata; +} + + + +// 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 ]; +* var arr = assignMap( x, indices, 'throw', out, 1, 0, function(val) { +* return val; +* }); +* // 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 000000000000..04c370ee3815 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/lib/index.js @@ -0,0 +1,64 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 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 ]; +* +* 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 ]; +* +* 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 000000000000..ca169f776ecc --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/lib/main.js @@ -0,0 +1,77 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 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. +* +* @param {Collection} x - input array +* @param {IntegerArray} indices - list of indices +* @param {string} mode - index mode +* @returns {Array} output array +* +* @example +* var x = [ 1, 2, 3, 4 ]; +* var indices = [ 3, 1, 2, 0 ]; +* +* var y = take( x, indices, 'throw' ); +* // returns [ 4, 2, 3, 1 ] +*/ +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 ); + out.push( clbk(xget( x, 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 000000000000..1b49afa2dbda --- /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": "Combine the functionality of take and map into a single API call.", + "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 000000000000..a394c9a724e2 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/test/test.assign.js @@ -0,0 +1,607 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 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 take = require( './../lib/assign.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof take, '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; + + x = [ 1, 2, 3, 4 ]; + + indices = [ 1, 3 ]; + out = zeros( indices.length, 'generic' ); + actual = take( x, indices, 'throw', out, 1, 0 ); + expected = [ 2, 4 ]; + + 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 = take( x, indices, 'throw', out, 2, 0 ); + expected = [ 2, 0, 2, 0, 4, 0, 4, 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 = take( x, indices, 'throw', out, -1, out.length-1 ); + expected = [ 1, 2, 3, 4 ]; + + 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 = take( x, indices, 'throw', out, 1, 1 ); + expected = [ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function takes elements from an array (real typed array)', function test( t ) { + var expected; + var indices; + var actual; + var out; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + indices = [ 1, 3 ]; + out = zeros( indices.length, 'float64' ); + actual = take( x, indices, 'throw', out, 1, 0 ); + expected = new Float64Array( [ 2.0, 4.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 = take( x, indices, 'throw', out, 2, 0 ); + expected = new Float64Array( [ 2.0, 0.0, 2.0, 0.0, 4.0, 0.0, 4.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 = take( x, indices, 'throw', out, -1, out.length-1 ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.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 = take( x, indices, 'throw', out, 1, 1 ); + expected = new Float64Array( [ 0.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.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 elements from an array (complex typed array)', function test( t ) { + var expected; + var indices; + var actual; + var out; + var x; + + 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 = take( x, indices, 'throw', out, 1, 0 ); + 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 = take( x, indices, 'throw', out, 2, 0 ); + 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 = take( x, indices, 'throw', out, -1, out.length-1 ); + 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 = take( x, indices, 'throw', out, 1, 1 ); + 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 elements from an array (accessors)', function test( t ) { + var expected; + var indices; + var actual; + var out; + var x; + + x = toAccessorArray( [ 1, 2, 3, 4 ] ); + + indices = toAccessorArray( [ 1, 3 ] ); + out = toAccessorArray( zeros( indices.length, 'generic' ) ); + actual = take( x, indices, 'throw', out, 1, 0 ); + expected = [ 2, 4 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + isEqual( actual, expected ); + + indices = toAccessorArray( [ 1, 1, 3, 3 ] ); + out = toAccessorArray( zeros( indices.length*2, 'generic' ) ); + actual = take( x, indices, 'throw', out, 2, 0 ); + expected = [ 2, 0, 2, 0, 4, 0, 4, 0 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + isEqual( actual, expected ); + + indices = toAccessorArray( [ 3, 2, 1, 0 ] ); + out = toAccessorArray( zeros( indices.length, 'generic' ) ); + actual = take( x, indices, 'throw', out, -1, out.length-1 ); + expected = [ 1, 2, 3, 4 ]; + + 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 = take( x, indices, 'throw', out, 1, 1 ); + expected = [ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; + + 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 leaves an output array unchanged if provided a second argument which is empty', function test( t ) { + var expected; + var actual; + var out; + var x; + + x = [ 1, 2, 3, 4 ]; + out = [ 0, 0, 0, 0 ]; + expected = [ 0, 0, 0, 0 ]; + actual = take( x, [], 'throw', out, 1, 0 ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ 1, 2, 3, 4 ] ); + out = [ 0, 0, 0, 0 ]; + expected = [ 0, 0, 0, 0 ]; + actual = take( x, [], 'throw', out, 1, 0 ); + 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 = take( x, [], 'throw', out, 1, 0 ); + 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 = take( x, [], 'throw', out, 1, 0 ); + 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; + + 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() { + take( x, indices, 'throw', out, 1, 0 ); + } +}); + +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; + + 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() { + take( x, indices, 'throw', out, 1, 0 ); + } +}); + +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; + + 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() { + take( x, indices, 'throw', out, 1, 0 ); + } +}); + +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; + + 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() { + take( x, indices, 'throw', out, 1, 0 ); + } +}); + +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; + + x = [ 1, 2, 3, 4 ]; + indices = [ -1, -2, -3, -4 ]; + out = zeros( x.length, 'generic' ); + + actual = take( x, indices, 'normalize', out, 1, 0 ); + expected = [ 4, 3, 2, 1 ]; + 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; + + x = toAccessorArray( [ 1, 2, 3, 4 ] ); + indices = toAccessorArray( [ -1, -2, -3, -4 ] ); + out = zeros( x.length, 'generic' ); + + take( x, indices, 'normalize', toAccessorArray( out ), 1, 0 ); + 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; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + indices = [ -1, -2, -3, -4 ]; + out = zeros( x.length, 'float64' ); + + actual = take( x, indices, 'normalize', out, 1, 0 ); + 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; + + x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + indices = [ -1, -2 ]; + out = zeros( x.length, 'complex128' ); + + actual = take( x, indices, 'normalize', out, 1, 0 ); + 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; + + 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() { + take( x, indices, 'normalize', out, 1, 0 ); + } +}); + +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; + + 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() { + take( x, indices, 'normalize', out, 1, 0 ); + } +}); + +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; + + 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() { + take( x, indices, 'normalize', out, 1, 0 ); + } +}); + +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; + + 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() { + take( x, indices, 'normalize', out, 1, 0 ); + } +}); + +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; + + x = [ 1, 2, 3, 4 ]; + indices = [ -10, 10, -5, 5 ]; + out = zeros( x.length, 'generic' ); + + actual = take( x, indices, 'clamp', out, 1, 0 ); + 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; + + x = toAccessorArray( [ 1, 2, 3, 4 ] ); + indices = toAccessorArray( [ -10, 10, -5, 5 ] ); + out = zeros( x.length, 'generic' ); + + take( x, indices, 'clamp', toAccessorArray( out ), 1, 0 ); + 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; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + indices = [ -10, 10, -5, 5 ]; + out = zeros( x.length, 'float64' ); + + actual = take( x, indices, 'clamp', out, 1, 0 ); + 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; + + 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 = take( x, indices, 'clamp', out, 1, 0 ); + 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; + + x = [ 1, 2, 3, 4 ]; + indices = [ -10, 10, -5, 5 ]; + out = zeros( x.length, 'generic' ); + + actual = take( x, indices, 'wrap', out, 1, 0 ); + 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; + + x = toAccessorArray( [ 1, 2, 3, 4 ] ); + indices = toAccessorArray( [ -10, 10, -5, 5 ] ); + out = zeros( x.length, 'generic' ); + + take( x, indices, 'wrap', toAccessorArray( out ), 1, 0 ); + 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; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + indices = [ -10, 10, -5, 5 ]; + out = zeros( x.length, 'float64' ); + + actual = take( x, indices, 'wrap', out, 1, 0 ); + 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; + + 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 = take( x, indices, 'wrap', out, 1, 0 ); + 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 000000000000..f251ec21b3ec --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/test/test.js @@ -0,0 +1,46 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 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(); +}); + +tape( '...', function test( t ) { + // Add your test cases for the `take-map` module here + 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 000000000000..66c26e2ff4f8 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/test/test.main.js @@ -0,0 +1,181 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 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; + + x = [ 1, 2, 3, 4 ]; + + indices = [ 1, 3 ]; + actual = takeMap( x, indices, 'throw' ); + expected = [ 2, 4 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + indices = [ 1, 1, 3, 3 ]; + actual = takeMap( x, indices, 'throw' ); + expected = [ 2, 2, 4, 4 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + indices = [ 3, 2, 1, 0 ]; + actual = takeMap( x, indices, 'throw' ); + expected = [ 4, 3, 2, 1 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; + actual = takeMap( x, indices, 'throw' ); + expected = [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; + 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; + + 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' ); + + 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 ]; + t.deepEqual( takeMap( x, [], 'throw' ), [], 'returns expected value' ); + 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; + + 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' ); + } +}); + +tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { + var expected; + var indices; + var actual; + var x; + + x = [ 1, 2, 3, 4 ]; + + indices = [ -1, -2, -3, -4 ]; + actual = takeMap( x, indices, 'normalize' ); + expected = [ 4, 3, 2, 1 ]; + 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; + + 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' ); + } +}); + +tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { + var expected; + var indices; + var actual; + var x; + + x = [ 1, 2, 3, 4 ]; + + indices = [ -10, 10, -5, 5 ]; + actual = takeMap( x, indices, 'clamp' ); + 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; + + x = [ 1, 2, 3, 4 ]; + + indices = [ -10, 10, -5, 5 ]; + actual = takeMap( x, indices, 'wrap' ); + expected = [ 3, 3, 4, 2 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); From 2190f7f24480d72bc59fa1f92fb43c2103d038e7 Mon Sep 17 00:00:00 2001 From: Varad Gupta Date: Thu, 22 Feb 2024 18:58:34 +0530 Subject: [PATCH 03/22] Added take-map and added namespace new examples --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index daf9e3031052..2c7e5b45569e 100644 --- a/README.md +++ b/README.md @@ -291,7 +291,7 @@ var arr = ndarray( [ [ 1, 2 ], [ 3, 4 ] ] ); ### Namespaces -stdlib is comprised of various top-level namespaces (i.e., collections of related functionality united by common themes). For example, to install all time functionality found in the top-level `time` namespace, +stdlib is comprised of various top-level namespaces (i.e., collections of related functionality united by common themes). For example, to install all time functionality found in the top-level `string` namespace, From 51ab57e553b8b67288171a686460e7efebdc2182 Mon Sep 17 00:00:00 2001 From: Varad Gupta Date: Thu, 22 Feb 2024 19:01:58 +0530 Subject: [PATCH 04/22] Added take-map and added namespace new examples --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2c7e5b45569e..9c6c0deee2ba 100644 --- a/README.md +++ b/README.md @@ -291,7 +291,7 @@ var arr = ndarray( [ [ 1, 2 ], [ 3, 4 ] ] ); ### Namespaces -stdlib is comprised of various top-level namespaces (i.e., collections of related functionality united by common themes). For example, to install all time functionality found in the top-level `string` namespace, +stdlib is comprised of various top-level namespaces (i.e., collections of related functionality united by common themes). For example, to install all string functionality found in the top-level `string` namespace, From 7a45086641ab94fcc4a99d64b34cd8eec98850e0 Mon Sep 17 00:00:00 2001 From: Varad Gupta Date: Fri, 23 Feb 2024 09:23:11 +0530 Subject: [PATCH 05/22] Added new newspace examples --- .../@stdlib/array/base/take-map/README.md | 124 ---- .../benchmark/benchmark.assign.length.js | 106 --- .../base/take-map/benchmark/benchmark.js | 52 -- .../take-map/benchmark/benchmark.length.js | 98 --- .../@stdlib/array/base/take-map/docs/repl.txt | 94 --- .../array/base/take-map/docs/types/index.d.ts | 217 ------- .../array/base/take-map/docs/types/test.ts | 80 --- .../array/base/take-map/examples/index.js | 42 -- .../@stdlib/array/base/take-map/lib/assign.js | 201 ------ .../@stdlib/array/base/take-map/lib/index.js | 64 -- .../@stdlib/array/base/take-map/lib/main.js | 77 --- .../@stdlib/array/base/take-map/package.json | 62 -- .../array/base/take-map/test/test.assign.js | 607 ------------------ .../@stdlib/array/base/take-map/test/test.js | 46 -- .../array/base/take-map/test/test.main.js | 181 ------ 15 files changed, 2051 deletions(-) delete mode 100644 lib/node_modules/@stdlib/array/base/take-map/README.md delete mode 100644 lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.assign.length.js delete mode 100644 lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.js delete mode 100644 lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.length.js delete mode 100644 lib/node_modules/@stdlib/array/base/take-map/docs/repl.txt delete mode 100644 lib/node_modules/@stdlib/array/base/take-map/docs/types/index.d.ts delete mode 100644 lib/node_modules/@stdlib/array/base/take-map/docs/types/test.ts delete mode 100644 lib/node_modules/@stdlib/array/base/take-map/examples/index.js delete mode 100644 lib/node_modules/@stdlib/array/base/take-map/lib/assign.js delete mode 100644 lib/node_modules/@stdlib/array/base/take-map/lib/index.js delete mode 100644 lib/node_modules/@stdlib/array/base/take-map/lib/main.js delete mode 100644 lib/node_modules/@stdlib/array/base/take-map/package.json delete mode 100644 lib/node_modules/@stdlib/array/base/take-map/test/test.assign.js delete mode 100644 lib/node_modules/@stdlib/array/base/take-map/test/test.js delete mode 100644 lib/node_modules/@stdlib/array/base/take-map/test/test.main.js diff --git a/lib/node_modules/@stdlib/array/base/take-map/README.md b/lib/node_modules/@stdlib/array/base/take-map/README.md deleted file mode 100644 index ee93ba0ddfb9..000000000000 --- a/lib/node_modules/@stdlib/array/base/take-map/README.md +++ /dev/null @@ -1,124 +0,0 @@ - - -# take - -> Combine the functionality of take and map into a single API call. - -
- -## Usage - -```javascript -var take = require( '@stdlib/array/base/take-map' ); -``` - -#### take( x, indices, mode, clbk[, thisArg]) - -Combines the take and map operations into a single API call. - -```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**: The input array from which elements will be selected based on the provided indices. -- **indices**: An array of indices indicating the positions of elements to be selected from the input array. -- **mode**: index [mode][@stdlib/ndarray/base/ind]. -- **clbk**: A callback function that maps each selected value specified by indices to the corresponding output value. -- **thisArg**: An optional parameter that can be used to set the this value within the 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 take = require('@stdlib/array/base/take'); -var takeMap = require('@stdlib/array/base/take-map'); - -// Generate a linearly spaced array: -var x = linspace(0, 100, 11); -console.log('Original Array:', x); - -// Generate an array of random indices: -var N = discreteUniform(5, 15); -var indices = filledBy(N, discreteUniform.factory(0, x.length - 1)); -console.log('Generated Indices:', indices); - -// Take a random sample of elements from `x` using `take`: -var yTake = take(x, indices, 'throw'); -console.log('Taken Elements using take:', yTake); - -// Define a custom mapping function: -function customMapping(value) { - return value * 2; -} - -// Take a random sample of elements from `x` and apply custom mapping using `takeMap`: -var yTakeMap = takeMap(x, indices, 'throw', customMapping); -console.log('Taken and Mapped Elements using takeMap:', yTakeMap); - -``` - -
- - - - - - - - - - - - - - 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 deleted file mode 100644 index 95ea8a0e9af8..000000000000 --- a/lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.assign.length.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 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 take = 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 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = take.assign( x, idx, 'throw', out, 1, 0 ); - 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 deleted file mode 100644 index a3413b3e0c43..000000000000 --- a/lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.js +++ /dev/null @@ -1,52 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 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 take = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::copy:len=100', function benchmark( b ) { - var x; - var i; - var v; - - x = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = take( x, x, 'throw' ); - 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 deleted file mode 100644 index 1ac63bf0f443..000000000000 --- a/lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.length.js +++ /dev/null @@ -1,98 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 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 take = 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 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = take( x, idx, 'throw' ); - 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 deleted file mode 100644 index 00b670361f2b..000000000000 --- a/lib/node_modules/@stdlib/array/base/take-map/docs/repl.txt +++ /dev/null @@ -1,94 +0,0 @@ - -{{alias}}( x, indices, mode, callback ) - Takes elements with given indices from x and pass the values from tha call back 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 - The map function to apply on selected elements of x. - - Returns - ------- - out: Array - Output array. - - Examples - -------- - function square(x){ - return x * x; - } - > var x = [ 1, 2, 3, 4 ]; - > var y = {{alias}}( x, [ 1, 3 ], 'throw',square ) - [ 4, 16] - - -{{alias}}.assign( x, indices, mode, callback, out, stride, offset ) - Takes elements from an array, passes via callback 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. - - callback : function - The map function to apply on selected elements of x. - - out: ArrayLikeObject - Output array. - - stride: integer - Output array stride. - - offset: integer - Output array offset. - - Returns - ------- - out: ArrayLikeObject - Output array. - - Examples - -------- - > function square(x){ - return x * x; - } - > var x = [ 1, 2, 3, 4 ]; - > var out = [ 0, 0, 0, 0 ]; - > var arr = {{alias}}.assign( x, [ 1, 3 ], 'throw', square, out, 2, 0 ) - [ 4, 0, 16, 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 deleted file mode 100644 index 983cb70fd6f5..000000000000 --- a/lib/node_modules/@stdlib/array/base/take-map/docs/types/index.d.ts +++ /dev/null @@ -1,217 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 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 { 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 { - // Implementation... - return {} as 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 { - return {} as Collection; -}; - -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 deleted file mode 100644 index 2d3f60f513d7..000000000000 --- a/lib/node_modules/@stdlib/array/base/take-map/docs/types/test.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 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... -{ - 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... -{ - 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... -{ - 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... -{ - 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... -{ - 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 deleted file mode 100644 index 818e0f310dba..000000000000 --- a/lib/node_modules/@stdlib/array/base/take-map/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 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/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/lib/assign.js b/lib/node_modules/@stdlib/array/base/take-map/lib/assign.js deleted file mode 100644 index d96197555bc5..000000000000 --- a/lib/node_modules/@stdlib/array/base/take-map/lib/assign.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @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 ]; - * - * var arr = takeMapIndexed( x, indices, 'throw', out, 1, 0, function(val) { - * return val; - * }); - * // arr is [ 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 ] = clbk( x[ j ] ); - io += stride; - } - return out; -} - -/** - * Takes elements from an accessor array and assigns the values to elements in an accessor output array. - * - * @private - * @param {Object} x - Input array object. - * @param {Object} indices - Index array object. - * @param {string} mode - Index mode. - * @param {Object} out - Output array object. - * @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); - * var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); - * - * var x = toAccessorArray( [ 1, 2, 3, 4 ] ); - * var indices = toAccessorArray( [ 3, 1, 2, 0 ] ); - * - * var out = toAccessorArray( [ 0, 0, 0, 0 ] ); - * var arr = accessorsMap( arraylike2object( x ), arraylike2object( indices ), 'throw', arraylike2object( out ), 1, 0, function(val) { - * return val; - * }); - * - * var v = arr.get( 0 ); - * // v is 4 - */ -function accessorsMap( x, indices, mode, out, stride, offset, clbk ) { - var getIndex; - var xdata; - var idata; - var odata; - var xget; - var iget; - var oset; - var max; - var io; - var i; - var j; - - xdata = x.data; - idata = indices.data; - odata = out.data; - - xget = x.accessors[ 0 ]; - iget = indices.accessors[ 0 ]; - oset = out.accessors[ 1 ]; - - // Resolve a function for returning an index according to the specified index mode: - getIndex = ind( mode ); - - // Resolve the maximum index: - max = xdata.length - 1; - - // Extract each desired element from the provided array... - io = offset; - for (i = 0; i < idata.length; i++) { - j = getIndex(iget(idata, i), max); - oset(odata, io, clbk(xget(xdata, j))); - io += stride; - } - return odata; -} - - - -// 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 ]; -* var arr = assignMap( x, indices, 'throw', out, 1, 0, function(val) { -* return val; -* }); -* // 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 deleted file mode 100644 index 04c370ee3815..000000000000 --- a/lib/node_modules/@stdlib/array/base/take-map/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 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 ]; -* -* 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 ]; -* -* 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 deleted file mode 100644 index ca169f776ecc..000000000000 --- a/lib/node_modules/@stdlib/array/base/take-map/lib/main.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 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. -* -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {string} mode - index mode -* @returns {Array} output array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* var indices = [ 3, 1, 2, 0 ]; -* -* var y = take( x, indices, 'throw' ); -* // returns [ 4, 2, 3, 1 ] -*/ -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 ); - out.push( clbk(xget( x, 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 deleted file mode 100644 index 1b49afa2dbda..000000000000 --- a/lib/node_modules/@stdlib/array/base/take-map/package.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "name": "@stdlib/array/base/take-map", - "version": "0.0.0", - "description": "Combine the functionality of take and map into a single API call.", - "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 deleted file mode 100644 index a394c9a724e2..000000000000 --- a/lib/node_modules/@stdlib/array/base/take-map/test/test.assign.js +++ /dev/null @@ -1,607 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 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 take = require( './../lib/assign.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof take, '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; - - x = [ 1, 2, 3, 4 ]; - - indices = [ 1, 3 ]; - out = zeros( indices.length, 'generic' ); - actual = take( x, indices, 'throw', out, 1, 0 ); - expected = [ 2, 4 ]; - - 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 = take( x, indices, 'throw', out, 2, 0 ); - expected = [ 2, 0, 2, 0, 4, 0, 4, 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 = take( x, indices, 'throw', out, -1, out.length-1 ); - expected = [ 1, 2, 3, 4 ]; - - 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 = take( x, indices, 'throw', out, 1, 1 ); - expected = [ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; - - t.strictEqual( actual, out, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function takes elements from an array (real typed array)', function test( t ) { - var expected; - var indices; - var actual; - var out; - var x; - - x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - indices = [ 1, 3 ]; - out = zeros( indices.length, 'float64' ); - actual = take( x, indices, 'throw', out, 1, 0 ); - expected = new Float64Array( [ 2.0, 4.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 = take( x, indices, 'throw', out, 2, 0 ); - expected = new Float64Array( [ 2.0, 0.0, 2.0, 0.0, 4.0, 0.0, 4.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 = take( x, indices, 'throw', out, -1, out.length-1 ); - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.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 = take( x, indices, 'throw', out, 1, 1 ); - expected = new Float64Array( [ 0.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.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 elements from an array (complex typed array)', function test( t ) { - var expected; - var indices; - var actual; - var out; - var x; - - 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 = take( x, indices, 'throw', out, 1, 0 ); - 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 = take( x, indices, 'throw', out, 2, 0 ); - 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 = take( x, indices, 'throw', out, -1, out.length-1 ); - 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 = take( x, indices, 'throw', out, 1, 1 ); - 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 elements from an array (accessors)', function test( t ) { - var expected; - var indices; - var actual; - var out; - var x; - - x = toAccessorArray( [ 1, 2, 3, 4 ] ); - - indices = toAccessorArray( [ 1, 3 ] ); - out = toAccessorArray( zeros( indices.length, 'generic' ) ); - actual = take( x, indices, 'throw', out, 1, 0 ); - expected = [ 2, 4 ]; - - t.strictEqual( actual, out, 'returns expected value' ); - isEqual( actual, expected ); - - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - out = toAccessorArray( zeros( indices.length*2, 'generic' ) ); - actual = take( x, indices, 'throw', out, 2, 0 ); - expected = [ 2, 0, 2, 0, 4, 0, 4, 0 ]; - - t.strictEqual( actual, out, 'returns expected value' ); - isEqual( actual, expected ); - - indices = toAccessorArray( [ 3, 2, 1, 0 ] ); - out = toAccessorArray( zeros( indices.length, 'generic' ) ); - actual = take( x, indices, 'throw', out, -1, out.length-1 ); - expected = [ 1, 2, 3, 4 ]; - - 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 = take( x, indices, 'throw', out, 1, 1 ); - expected = [ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; - - 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 leaves an output array unchanged if provided a second argument which is empty', function test( t ) { - var expected; - var actual; - var out; - var x; - - x = [ 1, 2, 3, 4 ]; - out = [ 0, 0, 0, 0 ]; - expected = [ 0, 0, 0, 0 ]; - actual = take( x, [], 'throw', out, 1, 0 ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = toAccessorArray( [ 1, 2, 3, 4 ] ); - out = [ 0, 0, 0, 0 ]; - expected = [ 0, 0, 0, 0 ]; - actual = take( x, [], 'throw', out, 1, 0 ); - 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 = take( x, [], 'throw', out, 1, 0 ); - 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 = take( x, [], 'throw', out, 1, 0 ); - 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; - - 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() { - take( x, indices, 'throw', out, 1, 0 ); - } -}); - -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; - - 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() { - take( x, indices, 'throw', out, 1, 0 ); - } -}); - -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; - - 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() { - take( x, indices, 'throw', out, 1, 0 ); - } -}); - -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; - - 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() { - take( x, indices, 'throw', out, 1, 0 ); - } -}); - -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; - - x = [ 1, 2, 3, 4 ]; - indices = [ -1, -2, -3, -4 ]; - out = zeros( x.length, 'generic' ); - - actual = take( x, indices, 'normalize', out, 1, 0 ); - expected = [ 4, 3, 2, 1 ]; - 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; - - x = toAccessorArray( [ 1, 2, 3, 4 ] ); - indices = toAccessorArray( [ -1, -2, -3, -4 ] ); - out = zeros( x.length, 'generic' ); - - take( x, indices, 'normalize', toAccessorArray( out ), 1, 0 ); - 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; - - x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - indices = [ -1, -2, -3, -4 ]; - out = zeros( x.length, 'float64' ); - - actual = take( x, indices, 'normalize', out, 1, 0 ); - 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; - - x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - indices = [ -1, -2 ]; - out = zeros( x.length, 'complex128' ); - - actual = take( x, indices, 'normalize', out, 1, 0 ); - 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; - - 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() { - take( x, indices, 'normalize', out, 1, 0 ); - } -}); - -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; - - 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() { - take( x, indices, 'normalize', out, 1, 0 ); - } -}); - -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; - - 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() { - take( x, indices, 'normalize', out, 1, 0 ); - } -}); - -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; - - 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() { - take( x, indices, 'normalize', out, 1, 0 ); - } -}); - -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; - - x = [ 1, 2, 3, 4 ]; - indices = [ -10, 10, -5, 5 ]; - out = zeros( x.length, 'generic' ); - - actual = take( x, indices, 'clamp', out, 1, 0 ); - 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; - - x = toAccessorArray( [ 1, 2, 3, 4 ] ); - indices = toAccessorArray( [ -10, 10, -5, 5 ] ); - out = zeros( x.length, 'generic' ); - - take( x, indices, 'clamp', toAccessorArray( out ), 1, 0 ); - 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; - - x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - indices = [ -10, 10, -5, 5 ]; - out = zeros( x.length, 'float64' ); - - actual = take( x, indices, 'clamp', out, 1, 0 ); - 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; - - 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 = take( x, indices, 'clamp', out, 1, 0 ); - 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; - - x = [ 1, 2, 3, 4 ]; - indices = [ -10, 10, -5, 5 ]; - out = zeros( x.length, 'generic' ); - - actual = take( x, indices, 'wrap', out, 1, 0 ); - 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; - - x = toAccessorArray( [ 1, 2, 3, 4 ] ); - indices = toAccessorArray( [ -10, 10, -5, 5 ] ); - out = zeros( x.length, 'generic' ); - - take( x, indices, 'wrap', toAccessorArray( out ), 1, 0 ); - 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; - - x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - indices = [ -10, 10, -5, 5 ]; - out = zeros( x.length, 'float64' ); - - actual = take( x, indices, 'wrap', out, 1, 0 ); - 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; - - 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 = take( x, indices, 'wrap', out, 1, 0 ); - 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 deleted file mode 100644 index f251ec21b3ec..000000000000 --- a/lib/node_modules/@stdlib/array/base/take-map/test/test.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 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(); -}); - -tape( '...', function test( t ) { - // Add your test cases for the `take-map` module here - 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 deleted file mode 100644 index 66c26e2ff4f8..000000000000 --- a/lib/node_modules/@stdlib/array/base/take-map/test/test.main.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 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; - - x = [ 1, 2, 3, 4 ]; - - indices = [ 1, 3 ]; - actual = takeMap( x, indices, 'throw' ); - expected = [ 2, 4 ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - indices = [ 1, 1, 3, 3 ]; - actual = takeMap( x, indices, 'throw' ); - expected = [ 2, 2, 4, 4 ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - indices = [ 3, 2, 1, 0 ]; - actual = takeMap( x, indices, 'throw' ); - expected = [ 4, 3, 2, 1 ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = takeMap( x, indices, 'throw' ); - expected = [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; - 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; - - 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' ); - - 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 ]; - t.deepEqual( takeMap( x, [], 'throw' ), [], 'returns expected value' ); - 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; - - 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' ); - } -}); - -tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -1, -2, -3, -4 ]; - actual = takeMap( x, indices, 'normalize' ); - expected = [ 4, 3, 2, 1 ]; - 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; - - 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' ); - } -}); - -tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = takeMap( x, indices, 'clamp' ); - 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; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = takeMap( x, indices, 'wrap' ); - expected = [ 3, 3, 4, 2 ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); From 72143048d0eed323578823882586556ccc38de91 Mon Sep 17 00:00:00 2001 From: Varad Gupta Date: Fri, 23 Feb 2024 09:50:33 +0530 Subject: [PATCH 06/22] added new feature@stdlib/array/base/take-map --- README.md | 47 +- .../@stdlib/array/base/take-map/README.md | 124 ++++ .../benchmark/benchmark.assign.length.js | 106 +++ .../base/take-map/benchmark/benchmark.js | 52 ++ .../take-map/benchmark/benchmark.length.js | 98 +++ .../@stdlib/array/base/take-map/docs/repl.txt | 94 +++ .../array/base/take-map/docs/types/index.d.ts | 217 +++++++ .../array/base/take-map/docs/types/test.ts | 80 +++ .../array/base/take-map/examples/index.js | 42 ++ .../@stdlib/array/base/take-map/lib/assign.js | 201 ++++++ .../@stdlib/array/base/take-map/lib/index.js | 64 ++ .../@stdlib/array/base/take-map/lib/main.js | 77 +++ .../@stdlib/array/base/take-map/package.json | 62 ++ .../array/base/take-map/test/test.assign.js | 607 ++++++++++++++++++ .../@stdlib/array/base/take-map/test/test.js | 46 ++ .../array/base/take-map/test/test.main.js | 181 ++++++ 16 files changed, 2061 insertions(+), 37 deletions(-) create mode 100644 lib/node_modules/@stdlib/array/base/take-map/README.md create mode 100644 lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.assign.length.js create mode 100644 lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.length.js create mode 100644 lib/node_modules/@stdlib/array/base/take-map/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/array/base/take-map/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/array/base/take-map/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/array/base/take-map/examples/index.js create mode 100644 lib/node_modules/@stdlib/array/base/take-map/lib/assign.js create mode 100644 lib/node_modules/@stdlib/array/base/take-map/lib/index.js create mode 100644 lib/node_modules/@stdlib/array/base/take-map/lib/main.js create mode 100644 lib/node_modules/@stdlib/array/base/take-map/package.json create mode 100644 lib/node_modules/@stdlib/array/base/take-map/test/test.assign.js create mode 100644 lib/node_modules/@stdlib/array/base/take-map/test/test.js create mode 100644 lib/node_modules/@stdlib/array/base/take-map/test/test.main.js diff --git a/README.md b/README.md index 9c6c0deee2ba..52c4319e7f48 100644 --- a/README.md +++ b/README.md @@ -291,39 +291,21 @@ var arr = ndarray( [ [ 1, 2 ], [ 3, 4 ] ] ); ### Namespaces -stdlib is comprised of various top-level namespaces (i.e., collections of related functionality united by common themes). For example, to install all string functionality found in the top-level `string` namespace, +stdlib is comprised of various top-level namespaces (i.e., collections of related functionality united by common themes). For example, to install all math functionality found in the top-level `math` namespace, ```bash -$ npm install @stdlib/string +$ npm install @stdlib/math ``` -Once installed, packages within a top-level namespace can be individually required/imported to minimize load times and decrease bundle sizes. +Once installed, packages within a top-level namespace can be individually required/imported to minimize load times and decrease bundle sizes. For example, to use `require` ```javascript -var uppercase = require( '@stdlib/string/uppercase' ); +var sin = require( '@stdlib/math/base/special/sin' ); -var str = uppercase( 'bEEp' ); -// returns 'BEEP' -``` -```javascript -var startsWith = require( '@stdlib/string/starts-with' ); - -var str = 'To be, or not to be, that is the question.'; - -var bool = startsWith( str, 'To be' ); -// returns true - -bool = startsWith( str, 'to be' ); -// returns false -``` -```javascript -var removeWords = require( '@stdlib/string/remove-words' ); - -var str = 'beep boop Foo bar'; -var out = removeWords( str, [ 'boop', 'foo' ] ); -// returns 'beep Foo bar' +var v = sin( 3.14 ); +// returns ``` and to use `import` @@ -331,22 +313,13 @@ and to use `import` ```javascript -import pascalcase from '@stdlib/string/pascalcase'; - -var out = pascalcase( 'foo bar' ); -// returns 'FooBar' - -out = pascalcase( 'IS_MOBILE' ); -// returns 'IsMobile' - -out = pascalcase( 'Hello World!' ); -// returns 'HelloWorld' +import sin from '@stdlib/math/base/special/sin'; -out = pascalcase( '--foo-bar--' ); -// returns 'FooBar' +var v = sin( 3.14 ); +// returns ``` -**Note**: installing nested namespaces found within top-level namespaces (..string/lowercase) is **not** supported. Consider installing individual packages or the relevant top-level namespace. +**Note**: installing nested namespaces found within top-level namespaces (e.g., `math/base`) is **not** supported. Consider installing individual packages or the relevant top-level namespace. 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 000000000000..ee93ba0ddfb9 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/README.md @@ -0,0 +1,124 @@ + + +# take + +> Combine the functionality of take and map into a single API call. + +
+ +## Usage + +```javascript +var take = require( '@stdlib/array/base/take-map' ); +``` + +#### take( x, indices, mode, clbk[, thisArg]) + +Combines the take and map operations into a single API call. + +```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**: The input array from which elements will be selected based on the provided indices. +- **indices**: An array of indices indicating the positions of elements to be selected from the input array. +- **mode**: index [mode][@stdlib/ndarray/base/ind]. +- **clbk**: A callback function that maps each selected value specified by indices to the corresponding output value. +- **thisArg**: An optional parameter that can be used to set the this value within the 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 take = require('@stdlib/array/base/take'); +var takeMap = require('@stdlib/array/base/take-map'); + +// Generate a linearly spaced array: +var x = linspace(0, 100, 11); +console.log('Original Array:', x); + +// Generate an array of random indices: +var N = discreteUniform(5, 15); +var indices = filledBy(N, discreteUniform.factory(0, x.length - 1)); +console.log('Generated Indices:', indices); + +// Take a random sample of elements from `x` using `take`: +var yTake = take(x, indices, 'throw'); +console.log('Taken Elements using take:', yTake); + +// Define a custom mapping function: +function customMapping(value) { + return value * 2; +} + +// Take a random sample of elements from `x` and apply custom mapping using `takeMap`: +var yTakeMap = takeMap(x, indices, 'throw', customMapping); +console.log('Taken and Mapped Elements using takeMap:', yTakeMap); + +``` + +
+ + + + + + + + + + + + + + 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 000000000000..95ea8a0e9af8 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.assign.length.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 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 take = 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 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = take.assign( x, idx, 'throw', out, 1, 0 ); + 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 000000000000..a3413b3e0c43 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 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 take = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::copy:len=100', function benchmark( b ) { + var x; + var i; + var v; + + x = zeroTo( 100 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = take( x, x, 'throw' ); + 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 000000000000..1ac63bf0f443 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.length.js @@ -0,0 +1,98 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 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 take = 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 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = take( x, idx, 'throw' ); + 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 000000000000..00b670361f2b --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/docs/repl.txt @@ -0,0 +1,94 @@ + +{{alias}}( x, indices, mode, callback ) + Takes elements with given indices from x and pass the values from tha call back 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 + The map function to apply on selected elements of x. + + Returns + ------- + out: Array + Output array. + + Examples + -------- + function square(x){ + return x * x; + } + > var x = [ 1, 2, 3, 4 ]; + > var y = {{alias}}( x, [ 1, 3 ], 'throw',square ) + [ 4, 16] + + +{{alias}}.assign( x, indices, mode, callback, out, stride, offset ) + Takes elements from an array, passes via callback 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. + + callback : function + The map function to apply on selected elements of x. + + out: ArrayLikeObject + Output array. + + stride: integer + Output array stride. + + offset: integer + Output array offset. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + > function square(x){ + return x * x; + } + > var x = [ 1, 2, 3, 4 ]; + > var out = [ 0, 0, 0, 0 ]; + > var arr = {{alias}}.assign( x, [ 1, 3 ], 'throw', square, out, 2, 0 ) + [ 4, 0, 16, 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 000000000000..983cb70fd6f5 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/docs/types/index.d.ts @@ -0,0 +1,217 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 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 { 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 { + // Implementation... + return {} as 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 { + return {} as Collection; +}; + +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 000000000000..2d3f60f513d7 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/docs/types/test.ts @@ -0,0 +1,80 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2022 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... +{ + 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... +{ + 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... +{ + 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... +{ + 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... +{ + 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 000000000000..818e0f310dba --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/examples/index.js @@ -0,0 +1,42 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 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/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/lib/assign.js b/lib/node_modules/@stdlib/array/base/take-map/lib/assign.js new file mode 100644 index 000000000000..d96197555bc5 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/lib/assign.js @@ -0,0 +1,201 @@ +/** +* @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 ]; + * + * var arr = takeMapIndexed( x, indices, 'throw', out, 1, 0, function(val) { + * return val; + * }); + * // arr is [ 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 ] = clbk( x[ j ] ); + io += stride; + } + return out; +} + +/** + * Takes elements from an accessor array and assigns the values to elements in an accessor output array. + * + * @private + * @param {Object} x - Input array object. + * @param {Object} indices - Index array object. + * @param {string} mode - Index mode. + * @param {Object} out - Output array object. + * @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); + * var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); + * + * var x = toAccessorArray( [ 1, 2, 3, 4 ] ); + * var indices = toAccessorArray( [ 3, 1, 2, 0 ] ); + * + * var out = toAccessorArray( [ 0, 0, 0, 0 ] ); + * var arr = accessorsMap( arraylike2object( x ), arraylike2object( indices ), 'throw', arraylike2object( out ), 1, 0, function(val) { + * return val; + * }); + * + * var v = arr.get( 0 ); + * // v is 4 + */ +function accessorsMap( x, indices, mode, out, stride, offset, clbk ) { + var getIndex; + var xdata; + var idata; + var odata; + var xget; + var iget; + var oset; + var max; + var io; + var i; + var j; + + xdata = x.data; + idata = indices.data; + odata = out.data; + + xget = x.accessors[ 0 ]; + iget = indices.accessors[ 0 ]; + oset = out.accessors[ 1 ]; + + // Resolve a function for returning an index according to the specified index mode: + getIndex = ind( mode ); + + // Resolve the maximum index: + max = xdata.length - 1; + + // Extract each desired element from the provided array... + io = offset; + for (i = 0; i < idata.length; i++) { + j = getIndex(iget(idata, i), max); + oset(odata, io, clbk(xget(xdata, j))); + io += stride; + } + return odata; +} + + + +// 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 ]; +* var arr = assignMap( x, indices, 'throw', out, 1, 0, function(val) { +* return val; +* }); +* // 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 000000000000..04c370ee3815 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/lib/index.js @@ -0,0 +1,64 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 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 ]; +* +* 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 ]; +* +* 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 000000000000..ca169f776ecc --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/lib/main.js @@ -0,0 +1,77 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 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. +* +* @param {Collection} x - input array +* @param {IntegerArray} indices - list of indices +* @param {string} mode - index mode +* @returns {Array} output array +* +* @example +* var x = [ 1, 2, 3, 4 ]; +* var indices = [ 3, 1, 2, 0 ]; +* +* var y = take( x, indices, 'throw' ); +* // returns [ 4, 2, 3, 1 ] +*/ +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 ); + out.push( clbk(xget( x, 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 000000000000..1b49afa2dbda --- /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": "Combine the functionality of take and map into a single API call.", + "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 000000000000..a394c9a724e2 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/test/test.assign.js @@ -0,0 +1,607 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 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 take = require( './../lib/assign.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof take, '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; + + x = [ 1, 2, 3, 4 ]; + + indices = [ 1, 3 ]; + out = zeros( indices.length, 'generic' ); + actual = take( x, indices, 'throw', out, 1, 0 ); + expected = [ 2, 4 ]; + + 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 = take( x, indices, 'throw', out, 2, 0 ); + expected = [ 2, 0, 2, 0, 4, 0, 4, 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 = take( x, indices, 'throw', out, -1, out.length-1 ); + expected = [ 1, 2, 3, 4 ]; + + 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 = take( x, indices, 'throw', out, 1, 1 ); + expected = [ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function takes elements from an array (real typed array)', function test( t ) { + var expected; + var indices; + var actual; + var out; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + indices = [ 1, 3 ]; + out = zeros( indices.length, 'float64' ); + actual = take( x, indices, 'throw', out, 1, 0 ); + expected = new Float64Array( [ 2.0, 4.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 = take( x, indices, 'throw', out, 2, 0 ); + expected = new Float64Array( [ 2.0, 0.0, 2.0, 0.0, 4.0, 0.0, 4.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 = take( x, indices, 'throw', out, -1, out.length-1 ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.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 = take( x, indices, 'throw', out, 1, 1 ); + expected = new Float64Array( [ 0.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.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 elements from an array (complex typed array)', function test( t ) { + var expected; + var indices; + var actual; + var out; + var x; + + 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 = take( x, indices, 'throw', out, 1, 0 ); + 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 = take( x, indices, 'throw', out, 2, 0 ); + 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 = take( x, indices, 'throw', out, -1, out.length-1 ); + 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 = take( x, indices, 'throw', out, 1, 1 ); + 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 elements from an array (accessors)', function test( t ) { + var expected; + var indices; + var actual; + var out; + var x; + + x = toAccessorArray( [ 1, 2, 3, 4 ] ); + + indices = toAccessorArray( [ 1, 3 ] ); + out = toAccessorArray( zeros( indices.length, 'generic' ) ); + actual = take( x, indices, 'throw', out, 1, 0 ); + expected = [ 2, 4 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + isEqual( actual, expected ); + + indices = toAccessorArray( [ 1, 1, 3, 3 ] ); + out = toAccessorArray( zeros( indices.length*2, 'generic' ) ); + actual = take( x, indices, 'throw', out, 2, 0 ); + expected = [ 2, 0, 2, 0, 4, 0, 4, 0 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + isEqual( actual, expected ); + + indices = toAccessorArray( [ 3, 2, 1, 0 ] ); + out = toAccessorArray( zeros( indices.length, 'generic' ) ); + actual = take( x, indices, 'throw', out, -1, out.length-1 ); + expected = [ 1, 2, 3, 4 ]; + + 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 = take( x, indices, 'throw', out, 1, 1 ); + expected = [ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; + + 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 leaves an output array unchanged if provided a second argument which is empty', function test( t ) { + var expected; + var actual; + var out; + var x; + + x = [ 1, 2, 3, 4 ]; + out = [ 0, 0, 0, 0 ]; + expected = [ 0, 0, 0, 0 ]; + actual = take( x, [], 'throw', out, 1, 0 ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ 1, 2, 3, 4 ] ); + out = [ 0, 0, 0, 0 ]; + expected = [ 0, 0, 0, 0 ]; + actual = take( x, [], 'throw', out, 1, 0 ); + 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 = take( x, [], 'throw', out, 1, 0 ); + 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 = take( x, [], 'throw', out, 1, 0 ); + 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; + + 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() { + take( x, indices, 'throw', out, 1, 0 ); + } +}); + +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; + + 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() { + take( x, indices, 'throw', out, 1, 0 ); + } +}); + +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; + + 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() { + take( x, indices, 'throw', out, 1, 0 ); + } +}); + +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; + + 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() { + take( x, indices, 'throw', out, 1, 0 ); + } +}); + +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; + + x = [ 1, 2, 3, 4 ]; + indices = [ -1, -2, -3, -4 ]; + out = zeros( x.length, 'generic' ); + + actual = take( x, indices, 'normalize', out, 1, 0 ); + expected = [ 4, 3, 2, 1 ]; + 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; + + x = toAccessorArray( [ 1, 2, 3, 4 ] ); + indices = toAccessorArray( [ -1, -2, -3, -4 ] ); + out = zeros( x.length, 'generic' ); + + take( x, indices, 'normalize', toAccessorArray( out ), 1, 0 ); + 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; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + indices = [ -1, -2, -3, -4 ]; + out = zeros( x.length, 'float64' ); + + actual = take( x, indices, 'normalize', out, 1, 0 ); + 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; + + x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + indices = [ -1, -2 ]; + out = zeros( x.length, 'complex128' ); + + actual = take( x, indices, 'normalize', out, 1, 0 ); + 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; + + 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() { + take( x, indices, 'normalize', out, 1, 0 ); + } +}); + +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; + + 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() { + take( x, indices, 'normalize', out, 1, 0 ); + } +}); + +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; + + 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() { + take( x, indices, 'normalize', out, 1, 0 ); + } +}); + +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; + + 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() { + take( x, indices, 'normalize', out, 1, 0 ); + } +}); + +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; + + x = [ 1, 2, 3, 4 ]; + indices = [ -10, 10, -5, 5 ]; + out = zeros( x.length, 'generic' ); + + actual = take( x, indices, 'clamp', out, 1, 0 ); + 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; + + x = toAccessorArray( [ 1, 2, 3, 4 ] ); + indices = toAccessorArray( [ -10, 10, -5, 5 ] ); + out = zeros( x.length, 'generic' ); + + take( x, indices, 'clamp', toAccessorArray( out ), 1, 0 ); + 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; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + indices = [ -10, 10, -5, 5 ]; + out = zeros( x.length, 'float64' ); + + actual = take( x, indices, 'clamp', out, 1, 0 ); + 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; + + 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 = take( x, indices, 'clamp', out, 1, 0 ); + 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; + + x = [ 1, 2, 3, 4 ]; + indices = [ -10, 10, -5, 5 ]; + out = zeros( x.length, 'generic' ); + + actual = take( x, indices, 'wrap', out, 1, 0 ); + 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; + + x = toAccessorArray( [ 1, 2, 3, 4 ] ); + indices = toAccessorArray( [ -10, 10, -5, 5 ] ); + out = zeros( x.length, 'generic' ); + + take( x, indices, 'wrap', toAccessorArray( out ), 1, 0 ); + 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; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + indices = [ -10, 10, -5, 5 ]; + out = zeros( x.length, 'float64' ); + + actual = take( x, indices, 'wrap', out, 1, 0 ); + 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; + + 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 = take( x, indices, 'wrap', out, 1, 0 ); + 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 000000000000..f251ec21b3ec --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/test/test.js @@ -0,0 +1,46 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 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(); +}); + +tape( '...', function test( t ) { + // Add your test cases for the `take-map` module here + 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 000000000000..66c26e2ff4f8 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/take-map/test/test.main.js @@ -0,0 +1,181 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 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; + + x = [ 1, 2, 3, 4 ]; + + indices = [ 1, 3 ]; + actual = takeMap( x, indices, 'throw' ); + expected = [ 2, 4 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + indices = [ 1, 1, 3, 3 ]; + actual = takeMap( x, indices, 'throw' ); + expected = [ 2, 2, 4, 4 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + indices = [ 3, 2, 1, 0 ]; + actual = takeMap( x, indices, 'throw' ); + expected = [ 4, 3, 2, 1 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; + actual = takeMap( x, indices, 'throw' ); + expected = [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; + 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; + + 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' ); + + 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 ]; + t.deepEqual( takeMap( x, [], 'throw' ), [], 'returns expected value' ); + 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; + + 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' ); + } +}); + +tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { + var expected; + var indices; + var actual; + var x; + + x = [ 1, 2, 3, 4 ]; + + indices = [ -1, -2, -3, -4 ]; + actual = takeMap( x, indices, 'normalize' ); + expected = [ 4, 3, 2, 1 ]; + 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; + + 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' ); + } +}); + +tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { + var expected; + var indices; + var actual; + var x; + + x = [ 1, 2, 3, 4 ]; + + indices = [ -10, 10, -5, 5 ]; + actual = takeMap( x, indices, 'clamp' ); + 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; + + x = [ 1, 2, 3, 4 ]; + + indices = [ -10, 10, -5, 5 ]; + actual = takeMap( x, indices, 'wrap' ); + expected = [ 3, 3, 4, 2 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); From 7e69c54d462fe65c0feca13b3864d1d83d2ee98b Mon Sep 17 00:00:00 2001 From: Varad Gupta Date: Fri, 23 Feb 2024 21:19:52 +0530 Subject: [PATCH 07/22] All test ok --- .../@stdlib/array/base/map2d/package.json | 5 +- .../@stdlib/array/base/take-map/lib/assign.js | 65 ++++++++++++- .../@stdlib/array/base/take-map/lib/main.js | 3 +- .../@stdlib/array/base/take-map/package.json | 4 +- .../array/base/take-map/test/test.assign.js | 95 ++++++++++--------- .../array/base/take-map/test/test.main.js | 26 ++--- .../@stdlib/array/base/take/lib/main.js | 11 ++- .../@stdlib/array/base/take/package.json | 4 +- 8 files changed, 147 insertions(+), 66 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/map2d/package.json b/lib/node_modules/@stdlib/array/base/map2d/package.json index 7c2bb1df730c..5aeba1a11544 100644 --- a/lib/node_modules/@stdlib/array/base/map2d/package.json +++ b/lib/node_modules/@stdlib/array/base/map2d/package.json @@ -31,8 +31,9 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": {}, - "devDependencies": {}, + "dependencies": { + "make": "^0.8.1" + }, "engines": { "node": ">=0.10.0", "npm": ">2.7.0" 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 index d96197555bc5..2fa844508bcc 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/lib/assign.js +++ b/lib/node_modules/@stdlib/array/base/take-map/lib/assign.js @@ -63,14 +63,16 @@ function takeMapIndexed( x, indices, mode, out, stride, offset, clbk ) { // 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 ] = clbk( x[ j ] ); + if(j != undefined) 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; + out[ io ] = clbk.call(null,x[ k ],k); + out[ io+1 ] = clbk.call(null, x[ k+1 ],k+1); + io += so; + } + return out; +} // 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 index ca169f776ecc..96934284af53 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/take-map/lib/main.js @@ -32,6 +32,7 @@ var ind = require( '@stdlib/ndarray/base/ind' ).factory; * @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 @@ -66,7 +67,7 @@ function takeMap( x, indices, mode, clbk ) { out = []; for ( i = 0; i < indices.length; i++ ) { j = getIndex( iget( indices, i ), max ); - out.push( clbk(xget( x, j )) ); // use `Array#push` to ensure "fast" elements + out.push( clbk.call(null,(xget( x, j )),j) ); // use `Array#push` to ensure "fast" elements } return out; } diff --git a/lib/node_modules/@stdlib/array/base/take-map/package.json b/lib/node_modules/@stdlib/array/base/take-map/package.json index 1b49afa2dbda..f5310c8cc897 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/package.json +++ b/lib/node_modules/@stdlib/array/base/take-map/package.json @@ -22,7 +22,9 @@ "test": "./test" }, "types": "./docs/types", - "scripts": {}, + "scripts": { + "test": "tape test/*.js" + }, "homepage": "https://github.com/stdlib-js/stdlib", "repository": { "type": "git", 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 index a394c9a724e2..3679471feadf 100644 --- 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 @@ -28,14 +28,19 @@ 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 take = require( './../lib/assign.js' ); +var takeMap = require( './../lib/assign.js' ); // TESTS // +//callback function +function clbk( val ) { + return val; +} + tape( 'main export is a function', function test( t ) { t.ok( true, __filename ); - t.strictEqual( typeof take, 'function', 'main export is a function' ); + t.strictEqual( typeof takeMap, 'function', 'main export is a function' ); t.end(); }); @@ -50,7 +55,7 @@ tape( 'the function takes elements from an array (generic)', function test( t ) indices = [ 1, 3 ]; out = zeros( indices.length, 'generic' ); - actual = take( x, indices, 'throw', out, 1, 0 ); + actual = takeMap( x, indices, 'throw', out, 1, 0 , clbk); expected = [ 2, 4 ]; t.strictEqual( actual, out, 'returns expected value' ); @@ -58,7 +63,7 @@ tape( 'the function takes elements from an array (generic)', function test( t ) indices = [ 1, 1, 3, 3 ]; out = zeros( indices.length*2, 'generic' ); - actual = take( x, indices, 'throw', out, 2, 0 ); + actual = takeMap( x, indices, 'throw', out, 2, 0, clbk ); expected = [ 2, 0, 2, 0, 4, 0, 4, 0 ]; t.strictEqual( actual, out, 'returns expected value' ); @@ -66,7 +71,7 @@ tape( 'the function takes elements from an array (generic)', function test( t ) indices = [ 3, 2, 1, 0 ]; out = zeros( indices.length, 'generic' ); - actual = take( x, indices, 'throw', out, -1, out.length-1 ); + actual = takeMap( x, indices, 'throw', out, -1, out.length-1,clbk ); expected = [ 1, 2, 3, 4 ]; t.strictEqual( actual, out, 'returns expected value' ); @@ -74,7 +79,7 @@ tape( 'the function takes elements from an array (generic)', function test( t ) indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; out = zeros( indices.length+1, 'generic' ); - actual = take( x, indices, 'throw', out, 1, 1 ); + actual = takeMap( x, indices, 'throw', out, 1, 1,clbk ); expected = [ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; t.strictEqual( actual, out, 'returns expected value' ); @@ -83,7 +88,7 @@ tape( 'the function takes elements from an array (generic)', function test( t ) t.end(); }); -tape( 'the function takes elements from an array (real typed array)', function test( t ) { +tape( 'the function takeMaps elements from an array (real typed array)', function test( t ) { var expected; var indices; var actual; @@ -94,7 +99,7 @@ tape( 'the function takes elements from an array (real typed array)', function t indices = [ 1, 3 ]; out = zeros( indices.length, 'float64' ); - actual = take( x, indices, 'throw', out, 1, 0 ); + actual = takeMap( x, indices, 'throw', out, 1, 0,clbk ); expected = new Float64Array( [ 2.0, 4.0 ] ); t.strictEqual( actual, out, 'returns expected value' ); @@ -102,7 +107,7 @@ tape( 'the function takes elements from an array (real typed array)', function t indices = [ 1, 1, 3, 3 ]; out = zeros( indices.length*2, 'float64' ); - actual = take( x, indices, 'throw', out, 2, 0 ); + actual = takeMap( x, indices, 'throw', out, 2, 0, clbk ); expected = new Float64Array( [ 2.0, 0.0, 2.0, 0.0, 4.0, 0.0, 4.0, 0.0 ] ); t.strictEqual( actual, out, 'returns expected value' ); @@ -110,7 +115,7 @@ tape( 'the function takes elements from an array (real typed array)', function t indices = [ 3, 2, 1, 0 ]; out = zeros( indices.length, 'float64' ); - actual = take( x, indices, 'throw', out, -1, out.length-1 ); + actual = takeMap( x, indices, 'throw', out, -1, out.length-1,clbk ); expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); t.strictEqual( actual, out, 'returns expected value' ); @@ -118,7 +123,7 @@ tape( 'the function takes elements from an array (real typed array)', function t indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; out = zeros( indices.length+1, 'float64' ); - actual = take( x, indices, 'throw', out, 1, 1 ); + actual = takeMap( x, indices, 'throw', out, 1, 1,clbk ); expected = new Float64Array( [ 0.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); // eslint-disable-line max-len t.strictEqual( actual, out, 'returns expected value' ); @@ -127,7 +132,7 @@ tape( 'the function takes elements from an array (real typed array)', function t t.end(); }); -tape( 'the function takes elements from an array (complex typed array)', function test( t ) { +tape( 'the function takeMaps elements from an array (complex typed array)', function test( t ) { var expected; var indices; var actual; @@ -138,7 +143,7 @@ tape( 'the function takes elements from an array (complex typed array)', functio indices = [ 1, 3 ]; out = zeros( indices.length, 'complex128' ); - actual = take( x, indices, 'throw', out, 1, 0 ); + 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' ); @@ -146,7 +151,7 @@ tape( 'the function takes elements from an array (complex typed array)', functio indices = [ 1, 1, 3, 3 ]; out = zeros( indices.length*2, 'complex64' ); - actual = take( x, indices, 'throw', out, 2, 0 ); + 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' ); @@ -156,7 +161,7 @@ tape( 'the function takes elements from an array (complex typed array)', functio indices = [ 3, 2, 1, 0 ]; out = zeros( indices.length, 'complex128' ); - actual = take( x, indices, 'throw', out, -1, out.length-1 ); + 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' ); @@ -164,7 +169,7 @@ tape( 'the function takes elements from an array (complex typed array)', functio indices = [ 1, 1, 1, 1 ]; out = zeros( indices.length+1, 'complex64' ); - actual = take( x, indices, 'throw', out, 1, 1 ); + 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' ); @@ -173,7 +178,7 @@ tape( 'the function takes elements from an array (complex typed array)', functio t.end(); }); -tape( 'the function takes elements from an array (accessors)', function test( t ) { +tape( 'the function takeMaps elements from an array (accessors)', function test( t ) { var expected; var indices; var actual; @@ -184,7 +189,7 @@ tape( 'the function takes elements from an array (accessors)', function test( t indices = toAccessorArray( [ 1, 3 ] ); out = toAccessorArray( zeros( indices.length, 'generic' ) ); - actual = take( x, indices, 'throw', out, 1, 0 ); + actual = takeMap( x, indices, 'throw', out, 1, 0, clbk ); expected = [ 2, 4 ]; t.strictEqual( actual, out, 'returns expected value' ); @@ -192,7 +197,7 @@ tape( 'the function takes elements from an array (accessors)', function test( t indices = toAccessorArray( [ 1, 1, 3, 3 ] ); out = toAccessorArray( zeros( indices.length*2, 'generic' ) ); - actual = take( x, indices, 'throw', out, 2, 0 ); + actual = takeMap( x, indices, 'throw', out, 2, 0, clbk ); expected = [ 2, 0, 2, 0, 4, 0, 4, 0 ]; t.strictEqual( actual, out, 'returns expected value' ); @@ -200,7 +205,7 @@ tape( 'the function takes elements from an array (accessors)', function test( t indices = toAccessorArray( [ 3, 2, 1, 0 ] ); out = toAccessorArray( zeros( indices.length, 'generic' ) ); - actual = take( x, indices, 'throw', out, -1, out.length-1 ); + actual = takeMap( x, indices, 'throw', out, -1, out.length-1,clbk ); expected = [ 1, 2, 3, 4 ]; t.strictEqual( actual, out, 'returns expected value' ); @@ -208,7 +213,7 @@ tape( 'the function takes elements from an array (accessors)', function test( t indices = toAccessorArray( [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ] ); out = toAccessorArray( zeros( indices.length+1, 'generic' ) ); - actual = take( x, indices, 'throw', out, 1, 1 ); + actual = takeMap( x, indices, 'throw', out, 1, 1,clbk ); expected = [ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; t.strictEqual( actual, out, 'returns expected value' ); @@ -233,25 +238,25 @@ tape( 'the function returns leaves an output array unchanged if provided a secon x = [ 1, 2, 3, 4 ]; out = [ 0, 0, 0, 0 ]; expected = [ 0, 0, 0, 0 ]; - actual = take( x, [], 'throw', out, 1, 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 = take( x, [], 'throw', out, 1, 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 = take( x, [], 'throw', out, 1, 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 = take( x, [], 'throw', out, 1, 0 ); + actual = takeMap( x, [], 'throw', out, 1, 0,clbk ); t.strictEqual( isSameComplex128Array( actual, expected ), true, 'returns expected value' ); t.end(); @@ -270,7 +275,7 @@ tape( 'when the "mode" is "throw", the function throws an error if provided an o t.end(); function badValue() { - take( x, indices, 'throw', out, 1, 0 ); + takeMap( x, indices, 'throw', out, 1, 0 ,clbk); } }); @@ -287,7 +292,7 @@ tape( 'when the "mode" is "throw", the function throws an error if provided an o t.end(); function badValue() { - take( x, indices, 'throw', out, 1, 0 ); + takeMap( x, indices, 'throw', out, 1, 0,clbk ); } }); @@ -304,7 +309,7 @@ tape( 'when the "mode" is "throw", the function throws an error if provided an o t.end(); function badValue() { - take( x, indices, 'throw', out, 1, 0 ); + takeMap( x, indices, 'throw', out, 1, 0, clbk ); } }); @@ -321,7 +326,7 @@ tape( 'when the "mode" is "throw", the function throws an error if provided an o t.end(); function badValue() { - take( x, indices, 'throw', out, 1, 0 ); + takeMap( x, indices, 'throw', out, 1, 0,clbk ); } }); @@ -336,7 +341,7 @@ tape( 'when the "mode" is "normalize", the function normalizes negative indices indices = [ -1, -2, -3, -4 ]; out = zeros( x.length, 'generic' ); - actual = take( x, indices, 'normalize', out, 1, 0 ); + actual = takeMap( x, indices, 'normalize', out, 1, 0,clbk ); expected = [ 4, 3, 2, 1 ]; t.deepEqual( actual, expected, 'returns expected value' ); @@ -353,7 +358,7 @@ tape( 'when the "mode" is "normalize", the function normalizes negative indices indices = toAccessorArray( [ -1, -2, -3, -4 ] ); out = zeros( x.length, 'generic' ); - take( x, indices, 'normalize', toAccessorArray( out ), 1, 0 ); + takeMap( x, indices, 'normalize', toAccessorArray( out ), 1, 0 ,clbk); expected = [ 4, 3, 2, 1 ]; t.deepEqual( out, expected, 'returns expected value' ); @@ -371,7 +376,7 @@ tape( 'when the "mode" is "normalize", the function normalizes negative indices indices = [ -1, -2, -3, -4 ]; out = zeros( x.length, 'float64' ); - actual = take( x, indices, 'normalize', out, 1, 0 ); + 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' ); @@ -389,7 +394,7 @@ tape( 'when the "mode" is "normalize", the function normalizes negative indices indices = [ -1, -2 ]; out = zeros( x.length, 'complex128' ); - actual = take( x, indices, 'normalize', out, 1, 0 ); + 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' ); @@ -409,7 +414,7 @@ tape( 'when the "mode" is "normalize", the function throws an error if provided t.end(); function badValue() { - take( x, indices, 'normalize', out, 1, 0 ); + takeMap( x, indices, 'normalize', out, 1, 0,clbk ); } }); @@ -426,7 +431,7 @@ tape( 'when the "mode" is "normalize", the function throws an error if provided t.end(); function badValue() { - take( x, indices, 'normalize', out, 1, 0 ); + takeMap( x, indices, 'normalize', out, 1, 0 ,clbk); } }); @@ -443,7 +448,7 @@ tape( 'when the "mode" is "normalize", the function throws an error if provided t.end(); function badValue() { - take( x, indices, 'normalize', out, 1, 0 ); + takeMap( x, indices, 'normalize', out, 1, 0,clbk ); } }); @@ -460,7 +465,7 @@ tape( 'when the "mode" is "normalize", the function throws an error if provided t.end(); function badValue() { - take( x, indices, 'normalize', out, 1, 0 ); + takeMap( x, indices, 'normalize', out, 1, 0,clbk ); } }); @@ -475,7 +480,7 @@ tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices (ge indices = [ -10, 10, -5, 5 ]; out = zeros( x.length, 'generic' ); - actual = take( x, indices, 'clamp', out, 1, 0 ); + actual = takeMap( x, indices, 'clamp', out, 1, 0 ,clbk); expected = [ 1, 4, 1, 4 ]; t.deepEqual( actual, expected, 'returns expected value' ); @@ -492,7 +497,7 @@ tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices (ac indices = toAccessorArray( [ -10, 10, -5, 5 ] ); out = zeros( x.length, 'generic' ); - take( x, indices, 'clamp', toAccessorArray( out ), 1, 0 ); + takeMap( x, indices, 'clamp', toAccessorArray( out ), 1, 0,clbk ); expected = [ 1, 4, 1, 4 ]; t.deepEqual( out, expected, 'returns expected value' ); @@ -510,7 +515,7 @@ tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices (re indices = [ -10, 10, -5, 5 ]; out = zeros( x.length, 'float64' ); - actual = take( x, indices, 'clamp', out, 1, 0 ); + 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' ); @@ -528,7 +533,7 @@ tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices (co indices = [ -10, 10, -5, 5 ]; out = zeros( x.length, 'complex128' ); - actual = take( x, indices, 'clamp', out, 1, 0 ); + 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' ); @@ -546,7 +551,7 @@ tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices (gene indices = [ -10, 10, -5, 5 ]; out = zeros( x.length, 'generic' ); - actual = take( x, indices, 'wrap', out, 1, 0 ); + actual = takeMap( x, indices, 'wrap', out, 1, 0,clbk ); expected = [ 3, 3, 4, 2 ]; t.deepEqual( actual, expected, 'returns expected value' ); @@ -563,7 +568,7 @@ tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices (acce indices = toAccessorArray( [ -10, 10, -5, 5 ] ); out = zeros( x.length, 'generic' ); - take( x, indices, 'wrap', toAccessorArray( out ), 1, 0 ); + takeMap( x, indices, 'wrap', toAccessorArray( out ), 1, 0,clbk ); expected = [ 3, 3, 4, 2 ]; t.deepEqual( out, expected, 'returns expected value' ); @@ -581,7 +586,7 @@ tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices (real indices = [ -10, 10, -5, 5 ]; out = zeros( x.length, 'float64' ); - actual = take( x, indices, 'wrap', out, 1, 0 ); + 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' ); @@ -599,7 +604,7 @@ tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices (comp indices = [ -10, 10, -5, 5 ]; out = zeros( x.length, 'complex128' ); - actual = take( x, indices, 'wrap', out, 1, 0 ); + 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' ); 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 index 66c26e2ff4f8..67480da34183 100644 --- 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 @@ -28,6 +28,10 @@ var imagf = require( '@stdlib/complex/imagf' ); var isComplex64 = require( '@stdlib/assert/is-complex64' ); var takeMap = require( './../lib' ); +// CALLBACK +function clbk( v ) { + return v; +} // TESTS // @@ -51,22 +55,22 @@ tape( 'the function takes elements from an array', function test( t ) { x = [ 1, 2, 3, 4 ]; indices = [ 1, 3 ]; - actual = takeMap( x, indices, 'throw' ); + actual = takeMap( x, indices, 'throw',clbk ); expected = [ 2, 4 ]; t.deepEqual( actual, expected, 'returns expected value' ); indices = [ 1, 1, 3, 3 ]; - actual = takeMap( x, indices, 'throw' ); + actual = takeMap( x, indices, 'throw',clbk ); expected = [ 2, 2, 4, 4 ]; t.deepEqual( actual, expected, 'returns expected value' ); indices = [ 3, 2, 1, 0 ]; - actual = takeMap( x, indices, 'throw' ); + actual = takeMap( x, indices, 'throw',clbk ); expected = [ 4, 3, 2, 1 ]; t.deepEqual( actual, expected, 'returns expected value' ); indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = takeMap( x, indices, 'throw' ); + actual = takeMap( x, indices, 'throw',clbk ); expected = [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; t.deepEqual( actual, expected, 'returns expected value' ); @@ -83,7 +87,7 @@ tape( 'the function takes elements from an array (accessors)', function test( t 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' ); + actual = takeMap( x, indices, 'throw', clbk ); t.notEqual( actual, x, 'returns different reference' ); for ( i = 0; i < indices.length; i++ ) { @@ -98,7 +102,7 @@ tape( 'the function takes elements from an array (accessors)', function test( t tape( 'the function returns an empty array if provided a second argument which is empty', function test( t ) { var x = [ 1, 2, 3, 4 ]; - t.deepEqual( takeMap( x, [], 'throw' ), [], 'returns expected value' ); + t.deepEqual( takeMap( x, [], 'throw' ), [], 'returns expected value',clbk ); t.end(); }); @@ -113,7 +117,7 @@ tape( 'when the "mode" is "throw", the function throws an error if provided an o t.end(); function badValue() { - takeMap( x, indices, 'throw' ); + takeMap( x, indices, 'throw',clbk ); } }); @@ -126,7 +130,7 @@ tape( 'when the "mode" is "normalize", the function normalizes negative indices' x = [ 1, 2, 3, 4 ]; indices = [ -1, -2, -3, -4 ]; - actual = takeMap( x, indices, 'normalize' ); + actual = takeMap( x, indices, 'normalize',clbk ); expected = [ 4, 3, 2, 1 ]; t.deepEqual( actual, expected, 'returns expected value' ); @@ -144,7 +148,7 @@ tape( 'when the "mode" is "normalize", the function throws an error if provided t.end(); function badValue() { - takeMap( x, indices, 'normalize' ); + takeMap( x, indices, 'normalize',clbk ); } }); @@ -157,7 +161,7 @@ tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', f x = [ 1, 2, 3, 4 ]; indices = [ -10, 10, -5, 5 ]; - actual = takeMap( x, indices, 'clamp' ); + actual = takeMap( x, indices, 'clamp',clbk ); expected = [ 1, 4, 1, 4 ]; t.deepEqual( actual, expected, 'returns expected value' ); @@ -173,7 +177,7 @@ tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices', fun x = [ 1, 2, 3, 4 ]; indices = [ -10, 10, -5, 5 ]; - actual = takeMap( x, indices, 'wrap' ); + actual = takeMap( x, indices, 'wrap',clbk); expected = [ 3, 3, 4, 2 ]; t.deepEqual( actual, expected, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/array/base/take/lib/main.js b/lib/node_modules/@stdlib/array/base/take/lib/main.js index e32e11d44b69..b2291e2d772d 100644 --- a/lib/node_modules/@stdlib/array/base/take/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/take/lib/main.js @@ -32,6 +32,7 @@ var ind = require( '@stdlib/ndarray/base/ind' ).factory; * @param {Collection} x - input array * @param {IntegerArray} indices - list of indices * @param {string} mode - index mode +* @param {Function} [clbk] - callback to invoke for each element * @returns {Array} output array * * @example @@ -41,7 +42,7 @@ var ind = require( '@stdlib/ndarray/base/ind' ).factory; * var y = take( x, indices, 'throw' ); * // returns [ 4, 2, 3, 1 ] */ -function take( x, indices, mode ) { +function take( x, indices, mode, clbk ) { var getIndex; var xget; var iget; @@ -64,7 +65,13 @@ function take( x, indices, mode ) { out = []; for ( i = 0; i < indices.length; i++ ) { j = getIndex( iget( indices, i ), max ); - out.push( xget( x, j ) ); // use `Array#push` to ensure "fast" elements + if(j!==undefined) { + if ( clbk ) { + out.push( clbk( xget( x, j ) ) ); + } else { + out.push( xget( x, j ) ); // use `Array#push` to ensure "fast" elements + } + } } return out; } diff --git a/lib/node_modules/@stdlib/array/base/take/package.json b/lib/node_modules/@stdlib/array/base/take/package.json index 49cfa7981ef2..af751f83e2f2 100644 --- a/lib/node_modules/@stdlib/array/base/take/package.json +++ b/lib/node_modules/@stdlib/array/base/take/package.json @@ -22,7 +22,9 @@ "test": "./test" }, "types": "./docs/types", - "scripts": {}, + "scripts": { + "test": "tape test/*.js" + }, "homepage": "https://github.com/stdlib-js/stdlib", "repository": { "type": "git", From 862542aba20530138a1acce8f7f2de141c4ce149 Mon Sep 17 00:00:00 2001 From: Varad Gupta Date: Sat, 24 Feb 2024 08:51:11 +0530 Subject: [PATCH 08/22] made changes --- lib/node_modules/@stdlib/array/base/map2d/package.json | 5 ++--- lib/node_modules/@stdlib/array/base/take-map/README.md | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/map2d/package.json b/lib/node_modules/@stdlib/array/base/map2d/package.json index 5aeba1a11544..7c2bb1df730c 100644 --- a/lib/node_modules/@stdlib/array/base/map2d/package.json +++ b/lib/node_modules/@stdlib/array/base/map2d/package.json @@ -31,9 +31,8 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "make": "^0.8.1" - }, + "dependencies": {}, + "devDependencies": {}, "engines": { "node": ">=0.10.0", "npm": ">2.7.0" diff --git a/lib/node_modules/@stdlib/array/base/take-map/README.md b/lib/node_modules/@stdlib/array/base/take-map/README.md index ee93ba0ddfb9..ba70425685e9 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/README.md +++ b/lib/node_modules/@stdlib/array/base/take-map/README.md @@ -18,7 +18,7 @@ limitations under the License. --> -# take +# take-map > Combine the functionality of take and map into a single API call. @@ -27,7 +27,7 @@ limitations under the License. ## Usage ```javascript -var take = require( '@stdlib/array/base/take-map' ); +var takeMap = require( '@stdlib/array/base/take-map' ); ``` #### take( x, indices, mode, clbk[, thisArg]) From b912605544ca3eeecd3ac7b841aa39cca2936c0f Mon Sep 17 00:00:00 2001 From: Varad Gupta Date: Sat, 24 Feb 2024 11:51:22 +0530 Subject: [PATCH 09/22] Refined and checked --- .../@stdlib/array/base/take-map/README.md | 59 ++++++++++--------- .../benchmark/benchmark.assign.length.js | 6 +- .../base/take-map/benchmark/benchmark.js | 6 +- .../take-map/benchmark/benchmark.length.js | 6 +- .../array/base/take-map/docs/types/index.d.ts | 11 +--- .../array/base/take-map/docs/types/test.ts | 2 +- .../array/base/take-map/examples/index.js | 4 +- .../@stdlib/array/base/take-map/lib/index.js | 2 +- .../@stdlib/array/base/take-map/lib/main.js | 2 +- .../@stdlib/array/base/take-map/package.json | 6 +- .../array/base/take-map/test/test.assign.js | 2 +- .../@stdlib/array/base/take-map/test/test.js | 2 +- .../array/base/take-map/test/test.main.js | 2 +- 13 files changed, 54 insertions(+), 56 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/take-map/README.md b/lib/node_modules/@stdlib/array/base/take-map/README.md index ba70425685e9..ba2b6a81037a 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/README.md +++ b/lib/node_modules/@stdlib/array/base/take-map/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2022 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. @@ -20,7 +20,7 @@ limitations under the License. # take-map -> Combine the functionality of take and map into a single API call. +> Takes elements from an array, applies a mapping function using a callback, and returns a new array.
@@ -30,7 +30,7 @@ limitations under the License. var takeMap = require( '@stdlib/array/base/take-map' ); ``` -#### take( x, indices, mode, clbk[, thisArg]) +#### takeMap( x, indices, mode, clbk[, thisArg]) Combines the take and map operations into a single API call. @@ -47,11 +47,11 @@ var y = takeMap(x, [1, 3], 'throw', customMapping); The function supports the following parameters: -- **x**: The input array from which elements will be selected based on the provided indices. -- **indices**: An array of indices indicating the positions of elements to be selected from the input array. +- **x**: input array. +- **indices**: list of indices. - **mode**: index [mode][@stdlib/ndarray/base/ind]. -- **clbk**: A callback function that maps each selected value specified by indices to the corresponding output value. -- **thisArg**: An optional parameter that can be used to set the this value within the callback function. +- **clbk**: function to apply. +- **thisArg**: applied function execution context (optional).
@@ -71,33 +71,36 @@ The function supports the following parameters: ```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 take = require('@stdlib/array/base/take'); var takeMap = require('@stdlib/array/base/take-map'); -// Generate a linearly spaced array: -var x = linspace(0, 100, 11); -console.log('Original Array:', x); +// Sample data +var sourceArray = [10, 20, 30, 40, 50]; +var indices = [2, 0, 3, 1]; // Indices to be taken +var mode = 'wrap'; // Index mode: 'wrap' to wrap around when exceeding array length -// Generate an array of random indices: -var N = discreteUniform(5, 15); -var indices = filledBy(N, discreteUniform.factory(0, x.length - 1)); -console.log('Generated Indices:', indices); - -// Take a random sample of elements from `x` using `take`: -var yTake = take(x, indices, 'throw'); -console.log('Taken Elements using take:', yTake); +// Use Case 1: Multiply each value by its index +function multiplyByIndex(value, index) { + return value * index; +} -// Define a custom mapping function: -function customMapping(value) { - return value * 2; +// Use Case 2: Add 100 to each value +function addTo100(value) { + return value + 100; } -// Take a random sample of elements from `x` and apply custom mapping using `takeMap`: -var yTakeMap = takeMap(x, indices, 'throw', customMapping); -console.log('Taken and Mapped Elements using takeMap:', yTakeMap); +// Applying Use Case 1: Multiply each value by its index +var multipliedResult = takeMap(sourceArray, indices, mode, multiplyByIndex); +// returns + +// Applying Use Case 2: Add 100 to each value +var addedResult = takeMap(sourceArray, indices, mode, addTo100); +// returns + +// Additional Feature: Specify an output array +var outputArray = new Array(indices.length).fill(0); +takeMap.assign(sourceArray, indices, mode, multiplyByIndex, outputArray); +// returns + ``` 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 index 95ea8a0e9af8..924c98eb4c88 100644 --- 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 @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2022 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. @@ -26,7 +26,7 @@ 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 take = require( './../lib' ); +var takeMap = require( './../lib' ); // FUNCTIONS // @@ -64,7 +64,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = take.assign( x, idx, 'throw', out, 1, 0 ); + v = takeMap.assign( x, idx, 'throw', out, 1, 0 ); if ( typeof v !== 'object' ) { b.fail( 'should return an array' ); } 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 index a3413b3e0c43..1ed17f5431a3 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2022 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. @@ -24,7 +24,7 @@ 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 take = require( './../lib' ); +var takeMap = require( './../lib' ); // MAIN // @@ -38,7 +38,7 @@ bench( pkg+'::copy:len=100', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = take( x, x, 'throw' ); + v = takeMap( x, x, 'throw' ); if ( typeof v !== 'object' ) { b.fail( 'should return an array' ); } 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 index 1ac63bf0f443..8d9ce9707cfb 100644 --- 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 @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2022 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. @@ -25,7 +25,7 @@ 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 take = require( './../lib' ); +var takeMap = require( './../lib' ); // FUNCTIONS // @@ -56,7 +56,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = take( x, idx, 'throw' ); + v = takeMap( x, idx, 'throw' ); if ( typeof v !== 'object' ) { b.fail( 'should return an array' ); } 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 index 983cb70fd6f5..f9589e9643bd 100644 --- 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 @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2022 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. @@ -169,10 +169,7 @@ interface TakeMap { * var y = takeMap( x, [ 1, 3 ], 'throw', transform ); * // returns [ 4, 8 ] */ -declare function takeMap( x: Collection | AccessorArrayLike, indices: IndexArray, mode: Mode, clbk: Callback ): Collection { - // Implementation... - return {} as Collection; -} +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. @@ -210,8 +207,6 @@ declare function takeMapAssign( out: Collection, stride: number, offset: number -): Collection { - return {} as Collection; -}; +): Collection 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 index 2d3f60f513d7..fa80a182d8e6 100644 --- 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 @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2022 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. 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 index 818e0f310dba..e0b96064b498 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/examples/index.js +++ b/lib/node_modules/@stdlib/array/base/take-map/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2022 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. @@ -31,6 +31,7 @@ console.log( x ); var N = discreteUniform( 5, 15 ); var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) ); console.log( indices ); +// returns // Define a mapping function (e.g., square the value): function square( val ) { @@ -40,3 +41,4 @@ function square( val ) { // Take a random sample of elements from `x` and apply the mapping function: var y = takeMap( x, indices, 'throw', square ); console.log( y ); +// returns 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 index 04c370ee3815..fe5d7f306ad0 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/lib/index.js +++ b/lib/node_modules/@stdlib/array/base/take-map/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2022 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. 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 index 96934284af53..1cbe69e03157 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/take-map/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2022 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. diff --git a/lib/node_modules/@stdlib/array/base/take-map/package.json b/lib/node_modules/@stdlib/array/base/take-map/package.json index f5310c8cc897..77a0190b7f33 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/package.json +++ b/lib/node_modules/@stdlib/array/base/take-map/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/array/base/take-map", "version": "0.0.0", - "description": "Combine the functionality of take and map into a single API call.", + "description": "Takes elements from an array, applies a mapping function using a callback, and returns a new array.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -22,9 +22,7 @@ "test": "./test" }, "types": "./docs/types", - "scripts": { - "test": "tape test/*.js" - }, + "scripts": {}, "homepage": "https://github.com/stdlib-js/stdlib", "repository": { "type": "git", 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 index 3679471feadf..d347c7d4e21d 100644 --- 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 @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2022 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. 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 index f251ec21b3ec..af29acc51124 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/test/test.js +++ b/lib/node_modules/@stdlib/array/base/take-map/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2022 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. 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 index 67480da34183..5389066fe05e 100644 --- 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 @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2022 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. From 8de51edca57a018f668dbe5d1a27b0fffc8d4b76 Mon Sep 17 00:00:00 2001 From: Varad Gupta Date: Sat, 24 Feb 2024 13:50:14 +0530 Subject: [PATCH 10/22] fixed error in js examples --- lib/node_modules/@stdlib/array/base/take-map/examples/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index e0b96064b498..587f01ee87b1 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/examples/index.js +++ b/lib/node_modules/@stdlib/array/base/take-map/examples/index.js @@ -21,7 +21,7 @@ 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/take-map' ); +var takeMap = require( './../lib' ); // Generate a linearly spaced array: var x = linspace( 0, 100, 11 ); From 98105eab51a48e07674a0410efbadd33dd52dd65 Mon Sep 17 00:00:00 2001 From: Varad Gupta Date: Sat, 24 Feb 2024 14:49:37 +0530 Subject: [PATCH 11/22] fixed error in readme and benchmarks --- lib/node_modules/@stdlib/array/base/take-map/README.md | 5 ----- .../base/take-map/benchmark/benchmark.assign.length.js | 5 ++++- .../@stdlib/array/base/take-map/benchmark/benchmark.js | 6 +++++- .../array/base/take-map/benchmark/benchmark.length.js | 6 +++++- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/take-map/README.md b/lib/node_modules/@stdlib/array/base/take-map/README.md index ba2b6a81037a..53623fe8aaca 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/README.md +++ b/lib/node_modules/@stdlib/array/base/take-map/README.md @@ -96,11 +96,6 @@ var multipliedResult = takeMap(sourceArray, indices, mode, multiplyByIndex); var addedResult = takeMap(sourceArray, indices, mode, addTo100); // returns -// Additional Feature: Specify an output array -var outputArray = new Array(indices.length).fill(0); -takeMap.assign(sourceArray, indices, mode, multiplyByIndex, outputArray); -// returns - ``` 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 index 924c98eb4c88..4f54fa27f537 100644 --- 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 @@ -61,10 +61,13 @@ function createBenchmark( len ) { 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 ); + v = takeMap.assign( x, idx, 'throw', out, 1, 0, clbk ); if ( typeof v !== 'object' ) { b.fail( 'should return an array' ); } 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 index 1ed17f5431a3..cd487babdb4a 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.js @@ -36,9 +36,13 @@ bench( pkg+'::copy:len=100', function benchmark( b ) { x = zeroTo( 100 ); + function clbk( val ) { + return val ; + } + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = takeMap( x, x, 'throw' ); + v = takeMap( x, x, 'throw',clbk ); if ( typeof v !== 'object' ) { b.fail( 'should return an array' ); } 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 index 8d9ce9707cfb..58930c11dc02 100644 --- 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 @@ -54,9 +54,13 @@ function createBenchmark( len ) { x = [ 1, 2, 3, 4 ]; + function clbk(val){ + return val; + } + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = takeMap( x, idx, 'throw' ); + v = takeMap( x, idx, 'throw',clbk ); if ( typeof v !== 'object' ) { b.fail( 'should return an array' ); } From 8356c2f70bdec9bad9e2418e7c96a4eee428202e Mon Sep 17 00:00:00 2001 From: Varad Gupta Date: Sat, 24 Feb 2024 15:08:05 +0530 Subject: [PATCH 12/22] resolved readme reference problem --- lib/node_modules/@stdlib/array/base/take-map/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/base/take-map/README.md b/lib/node_modules/@stdlib/array/base/take-map/README.md index 53623fe8aaca..7d059e2315fd 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/README.md +++ b/lib/node_modules/@stdlib/array/base/take-map/README.md @@ -115,7 +115,7 @@ var addedResult = takeMap(sourceArray, indices, mode, addTo100); From e958cade33c9025f9ffaf350002d4316d58e564b Mon Sep 17 00:00:00 2001 From: Varad Gupta Date: Sat, 24 Feb 2024 15:43:34 +0530 Subject: [PATCH 13/22] changed according to the lint --- lib/node_modules/@stdlib/array/base/take-map/README.md | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/take-map/README.md b/lib/node_modules/@stdlib/array/base/take-map/README.md index 7d059e2315fd..a4e13baa46cf 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/README.md +++ b/lib/node_modules/@stdlib/array/base/take-map/README.md @@ -27,10 +27,10 @@ limitations under the License. ## Usage ```javascript -var takeMap = require( '@stdlib/array/base/take-map' ); +var takeMap = require('@stdlib/array/base/take-map'); ``` -#### takeMap( x, indices, mode, clbk[, thisArg]) +#### takeMap( x, indices, mode, clbk) Combines the take and map operations into a single API call. @@ -71,9 +71,6 @@ The function supports the following parameters: ```javascript -var takeMap = require('@stdlib/array/base/take-map'); - -// Sample data var sourceArray = [10, 20, 30, 40, 50]; var indices = [2, 0, 3, 1]; // Indices to be taken var mode = 'wrap'; // Index mode: 'wrap' to wrap around when exceeding array length @@ -95,8 +92,6 @@ var multipliedResult = takeMap(sourceArray, indices, mode, multiplyByIndex); // Applying Use Case 2: Add 100 to each value var addedResult = takeMap(sourceArray, indices, mode, addTo100); // returns - - ``` From 02c660c1ad471dfcd5c0bf2bbeb2799687a2d6d7 Mon Sep 17 00:00:00 2001 From: Varad Gupta Date: Sat, 24 Feb 2024 16:00:18 +0530 Subject: [PATCH 14/22] changed according to the lint --- .../@stdlib/array/base/take-map/README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/take-map/README.md b/lib/node_modules/@stdlib/array/base/take-map/README.md index a4e13baa46cf..b9ba9205e13c 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/README.md +++ b/lib/node_modules/@stdlib/array/base/take-map/README.md @@ -30,7 +30,7 @@ limitations under the License. var takeMap = require('@stdlib/array/base/take-map'); ``` -#### takeMap( x, indices, mode, clbk) +### takeMap( x, indices, mode, clbk) Combines the take and map operations into a single API call. @@ -42,17 +42,17 @@ function customMapping(value) { } var y = takeMap(x, [1, 3], 'throw', customMapping); +var y = takeMap.apply( null, ['throw', customMapping].concat(x, [1, 3]) ); // 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. -- **thisArg**: applied function execution context (optional). - +- **x**: input array. +- **indices**: list of indices. +- **mode**: index [mode][@stdlib/ndarray/base/ind]. +- **clbk**: function to apply. +- **thisArg**: applied function execution context (optional). From 88427f680b0349a1ad6343f3a24d74b7eb1ae480 Mon Sep 17 00:00:00 2001 From: Varad Gupta Date: Sat, 24 Feb 2024 16:53:23 +0530 Subject: [PATCH 15/22] made some linting changes --- .../@stdlib/array/base/take-map/README.md | 11 ++--- .../array/base/take-map/docs/types/index.d.ts | 14 +----- .../@stdlib/array/base/take-map/lib/assign.js | 49 ++++++++++--------- 3 files changed, 31 insertions(+), 43 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/take-map/README.md b/lib/node_modules/@stdlib/array/base/take-map/README.md index b9ba9205e13c..fd1128c8fa95 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/README.md +++ b/lib/node_modules/@stdlib/array/base/take-map/README.md @@ -42,17 +42,16 @@ function customMapping(value) { } var y = takeMap(x, [1, 3], 'throw', customMapping); -var y = takeMap.apply( null, ['throw', customMapping].concat(x, [1, 3]) ); // 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. -- **thisArg**: applied function execution context (optional). +- **x**: input array. +- **indices**: list of indices. +- **mode**: index [mode][@stdlib/ndarray/base/ind]. +- **clbk**: function to apply. +- **thisArg**: applied function execution context (optional). 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 index f9589e9643bd..56b8a9650799 100644 --- 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 @@ -21,9 +21,6 @@ import { Collection, AccessorArrayLike } from '@stdlib/types/array'; import { Mode } from '@stdlib/types/ndarray'; - - - /** * Index array. */ @@ -199,14 +196,5 @@ declare function takeMap( x: Collection | AccessorArrayLike, indices * 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 - +declare function takeMapAssign( x: Collection | AccessorArrayLike, indices: IndexArray, mode: Mode, clbk: Callback, out: Collection, stride: number, offset: number ): Collection export = takeMap; 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 index 2fa844508bcc..e469b5ddbc66 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/lib/assign.js +++ b/lib/node_modules/@stdlib/array/base/take-map/lib/assign.js @@ -29,28 +29,28 @@ 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 ]; - * - * var arr = takeMapIndexed( x, indices, 'throw', out, 1, 0, function(val) { - * return val; - * }); - * // arr is [ 4, 2, 3, 1 ] - */ +* 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 ]; +* +* var arr = takeMapIndexed( x, indices, 'throw', out, 1, 0, function(val) { +* return val; +* }); +* // arr is [ 4, 2, 3, 1 ] +*/ function takeMapIndexed( x, indices, mode, out, stride, offset, clbk ) { var getIndex; var max; @@ -63,14 +63,15 @@ function takeMapIndexed( x, indices, mode, out, stride, offset, clbk ) { // 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 ); - if(j != undefined) out[ io ] = x[ j ] ; + out[ io ] = x[ j ]; io += stride; } - for(i = 0;i Date: Sun, 25 Feb 2024 04:33:24 +0530 Subject: [PATCH 16/22] fix: resolved linting errors --- .../base/take-map/benchmark/benchmark.js | 4 +- .../take-map/benchmark/benchmark.length.js | 4 +- .../array/base/take-map/examples/index.js | 4 +- .../@stdlib/array/base/take-map/lib/assign.js | 76 ++++--- .../@stdlib/array/base/take-map/lib/main.js | 16 +- .../array/base/take-map/test/test.assign.js | 71 +++--- .../@stdlib/array/base/take-map/test/test.js | 16 +- .../array/base/take-map/test/test.main.js | 212 +++++++++--------- 8 files changed, 207 insertions(+), 196 deletions(-) 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 index cd487babdb4a..e1fef30bd2e1 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/array/base/take-map/benchmark/benchmark.js @@ -37,12 +37,12 @@ bench( pkg+'::copy:len=100', function benchmark( b ) { x = zeroTo( 100 ); function clbk( val ) { - return val ; + return val; } b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = takeMap( x, x, 'throw',clbk ); + v = takeMap( x, x, 'throw', clbk ); if ( typeof v !== 'object' ) { b.fail( 'should return an array' ); } 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 index 58930c11dc02..9a88e12ee270 100644 --- 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 @@ -54,13 +54,13 @@ function createBenchmark( len ) { x = [ 1, 2, 3, 4 ]; - function clbk(val){ + function clbk(val) { return val; } b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = takeMap( x, idx, 'throw',clbk ); + v = takeMap( x, idx, 'throw', clbk ); if ( typeof v !== 'object' ) { b.fail( 'should return an array' ); } 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 index 587f01ee87b1..0b513736c544 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/examples/index.js +++ b/lib/node_modules/@stdlib/array/base/take-map/examples/index.js @@ -31,14 +31,12 @@ console.log( x ); var N = discreteUniform( 5, 15 ); var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) ); console.log( indices ); -// returns // Define a mapping function (e.g., square the value): function square( val ) { - return val * 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 ); -// returns 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 index e469b5ddbc66..7008789a4798 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/lib/assign.js +++ b/lib/node_modules/@stdlib/array/base/take-map/lib/assign.js @@ -72,39 +72,40 @@ function takeMapIndexed( x, indices, mode, out, stride, offset, clbk ) { 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 ) { +function complexMap( x, indices, mode, out, stride, offset, clbk ) { var getIndex; var idata; var iget; @@ -193,8 +200,12 @@ function complexMap( x, indices, mode, out, stride, offset,clbk ) { for ( i = 0; i < idata.length; i++ ) { j = getIndex( iget( idata, i ), max ); k = j * 2; - out[ io ] = clbk.call(null,x[ k ],k); - out[ io+1 ] = clbk.call(null, x[ k+1 ],k+1); + + // 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; @@ -256,6 +267,7 @@ function assignMap(x, indices, mode, out, stride, offset, clbk) { return out; } +// eslint-disable-next-line stdlib/section-header-empty-lines // EXPORTS // module.exports = assignMap; 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 index 1cbe69e03157..a80b682e343f 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/take-map/lib/main.js @@ -27,7 +27,7 @@ var ind = require( '@stdlib/ndarray/base/ind' ).factory; // MAIN // /** -* Takes elements from an array. +* 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 @@ -38,9 +38,11 @@ var ind = require( '@stdlib/ndarray/base/ind' ).factory; * @example * var x = [ 1, 2, 3, 4 ]; * var indices = [ 3, 1, 2, 0 ]; -* -* var y = take( x, indices, 'throw' ); -* // returns [ 4, 2, 3, 1 ] +* 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; @@ -55,8 +57,6 @@ function takeMap( x, indices, mode, clbk ) { xget = resolveGetter( x ); iget = resolveGetter( indices ); - - // Resolve a function for returning an index according to the specified index mode: getIndex = ind( mode ); @@ -67,7 +67,9 @@ function takeMap( x, indices, mode, clbk ) { out = []; for ( i = 0; i < indices.length; i++ ) { j = getIndex( iget( indices, i ), max ); - out.push( clbk.call(null,(xget( x, j )),j) ); // use `Array#push` to ensure "fast" elements + + // 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; } 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 index d347c7d4e21d..efea82cea5a8 100644 --- 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 @@ -33,7 +33,6 @@ var takeMap = require( './../lib/assign.js' ); // TESTS // -//callback function function clbk( val ) { return val; } @@ -55,7 +54,7 @@ tape( 'the function takes elements from an array (generic)', function test( t ) indices = [ 1, 3 ]; out = zeros( indices.length, 'generic' ); - actual = takeMap( x, indices, 'throw', out, 1, 0 , clbk); + actual = takeMap( x, indices, 'throw', out, 1, 0, clbk); expected = [ 2, 4 ]; t.strictEqual( actual, out, 'returns expected value' ); @@ -71,7 +70,7 @@ tape( 'the function takes elements from an array (generic)', function test( t ) indices = [ 3, 2, 1, 0 ]; out = zeros( indices.length, 'generic' ); - actual = takeMap( x, indices, 'throw', out, -1, out.length-1,clbk ); + actual = takeMap( x, indices, 'throw', out, -1, out.length-1, clbk ); expected = [ 1, 2, 3, 4 ]; t.strictEqual( actual, out, 'returns expected value' ); @@ -79,7 +78,7 @@ tape( 'the function takes elements from an array (generic)', function test( t ) 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 ); + actual = takeMap( x, indices, 'throw', out, 1, 1, clbk ); expected = [ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; t.strictEqual( actual, out, 'returns expected value' ); @@ -99,7 +98,7 @@ tape( 'the function takeMaps elements from an array (real typed array)', functio indices = [ 1, 3 ]; out = zeros( indices.length, 'float64' ); - actual = takeMap( x, indices, 'throw', out, 1, 0,clbk ); + actual = takeMap( x, indices, 'throw', out, 1, 0, clbk ); expected = new Float64Array( [ 2.0, 4.0 ] ); t.strictEqual( actual, out, 'returns expected value' ); @@ -115,7 +114,7 @@ tape( 'the function takeMaps elements from an array (real typed array)', functio indices = [ 3, 2, 1, 0 ]; out = zeros( indices.length, 'float64' ); - actual = takeMap( x, indices, 'throw', out, -1, out.length-1,clbk ); + actual = takeMap( x, indices, 'throw', out, -1, out.length-1, clbk ); expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); t.strictEqual( actual, out, 'returns expected value' ); @@ -123,7 +122,7 @@ tape( 'the function takeMaps elements from an array (real typed array)', functio 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 ); + actual = takeMap( x, indices, 'throw', out, 1, 1, clbk ); expected = new Float64Array( [ 0.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); // eslint-disable-line max-len t.strictEqual( actual, out, 'returns expected value' ); @@ -143,7 +142,7 @@ tape( 'the function takeMaps elements from an array (complex typed array)', func indices = [ 1, 3 ]; out = zeros( indices.length, 'complex128' ); - actual = takeMap( x, indices, 'throw', out, 1, 0,clbk ); + 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' ); @@ -151,7 +150,7 @@ tape( 'the function takeMaps elements from an array (complex typed array)', func indices = [ 1, 1, 3, 3 ]; out = zeros( indices.length*2, 'complex64' ); - actual = takeMap( x, indices, 'throw', out, 2, 0,clbk ); + 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' ); @@ -161,7 +160,7 @@ tape( 'the function takeMaps elements from an array (complex typed array)', func indices = [ 3, 2, 1, 0 ]; out = zeros( indices.length, 'complex128' ); - actual = takeMap( x, indices, 'throw', out, -1, out.length-1,clbk ); + 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' ); @@ -169,7 +168,7 @@ tape( 'the function takeMaps elements from an array (complex typed array)', func indices = [ 1, 1, 1, 1 ]; out = zeros( indices.length+1, 'complex64' ); - actual = takeMap( x, indices, 'throw', out, 1, 1,clbk ); + 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' ); @@ -205,7 +204,7 @@ tape( 'the function takeMaps elements from an array (accessors)', function test( indices = toAccessorArray( [ 3, 2, 1, 0 ] ); out = toAccessorArray( zeros( indices.length, 'generic' ) ); - actual = takeMap( x, indices, 'throw', out, -1, out.length-1,clbk ); + actual = takeMap( x, indices, 'throw', out, -1, out.length-1, clbk ); expected = [ 1, 2, 3, 4 ]; t.strictEqual( actual, out, 'returns expected value' ); @@ -213,7 +212,7 @@ tape( 'the function takeMaps elements from an array (accessors)', function test( 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 ); + actual = takeMap( x, indices, 'throw', out, 1, 1, clbk ); expected = [ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; t.strictEqual( actual, out, 'returns expected value' ); @@ -238,25 +237,25 @@ tape( 'the function returns leaves an output array unchanged if provided a secon x = [ 1, 2, 3, 4 ]; out = [ 0, 0, 0, 0 ]; expected = [ 0, 0, 0, 0 ]; - actual = takeMap( x, [], 'throw', out, 1, 0,clbk ); + 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 ); + 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 ); + 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 ); + actual = takeMap( x, [], 'throw', out, 1, 0, clbk ); t.strictEqual( isSameComplex128Array( actual, expected ), true, 'returns expected value' ); t.end(); @@ -275,7 +274,7 @@ tape( 'when the "mode" is "throw", the function throws an error if provided an o t.end(); function badValue() { - takeMap( x, indices, 'throw', out, 1, 0 ,clbk); + takeMap( x, indices, 'throw', out, 1, 0, clbk); } }); @@ -292,7 +291,7 @@ tape( 'when the "mode" is "throw", the function throws an error if provided an o t.end(); function badValue() { - takeMap( x, indices, 'throw', out, 1, 0,clbk ); + takeMap( x, indices, 'throw', out, 1, 0, clbk ); } }); @@ -326,7 +325,7 @@ tape( 'when the "mode" is "throw", the function throws an error if provided an o t.end(); function badValue() { - takeMap( x, indices, 'throw', out, 1, 0,clbk ); + takeMap( x, indices, 'throw', out, 1, 0, clbk ); } }); @@ -341,7 +340,7 @@ tape( 'when the "mode" is "normalize", the function normalizes negative indices indices = [ -1, -2, -3, -4 ]; out = zeros( x.length, 'generic' ); - actual = takeMap( x, indices, 'normalize', out, 1, 0,clbk ); + actual = takeMap( x, indices, 'normalize', out, 1, 0, clbk ); expected = [ 4, 3, 2, 1 ]; t.deepEqual( actual, expected, 'returns expected value' ); @@ -358,7 +357,7 @@ tape( 'when the "mode" is "normalize", the function normalizes negative indices indices = toAccessorArray( [ -1, -2, -3, -4 ] ); out = zeros( x.length, 'generic' ); - takeMap( x, indices, 'normalize', toAccessorArray( out ), 1, 0 ,clbk); + takeMap( x, indices, 'normalize', toAccessorArray( out ), 1, 0, clbk); expected = [ 4, 3, 2, 1 ]; t.deepEqual( out, expected, 'returns expected value' ); @@ -376,7 +375,7 @@ tape( 'when the "mode" is "normalize", the function normalizes negative indices indices = [ -1, -2, -3, -4 ]; out = zeros( x.length, 'float64' ); - actual = takeMap( x, indices, 'normalize', out, 1, 0,clbk ); + 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' ); @@ -394,7 +393,7 @@ tape( 'when the "mode" is "normalize", the function normalizes negative indices indices = [ -1, -2 ]; out = zeros( x.length, 'complex128' ); - actual = takeMap( x, indices, 'normalize', out, 1, 0 ,clbk); + 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' ); @@ -414,7 +413,7 @@ tape( 'when the "mode" is "normalize", the function throws an error if provided t.end(); function badValue() { - takeMap( x, indices, 'normalize', out, 1, 0,clbk ); + takeMap( x, indices, 'normalize', out, 1, 0, clbk ); } }); @@ -431,7 +430,7 @@ tape( 'when the "mode" is "normalize", the function throws an error if provided t.end(); function badValue() { - takeMap( x, indices, 'normalize', out, 1, 0 ,clbk); + takeMap( x, indices, 'normalize', out, 1, 0, clbk); } }); @@ -448,7 +447,7 @@ tape( 'when the "mode" is "normalize", the function throws an error if provided t.end(); function badValue() { - takeMap( x, indices, 'normalize', out, 1, 0,clbk ); + takeMap( x, indices, 'normalize', out, 1, 0, clbk ); } }); @@ -465,7 +464,7 @@ tape( 'when the "mode" is "normalize", the function throws an error if provided t.end(); function badValue() { - takeMap( x, indices, 'normalize', out, 1, 0,clbk ); + takeMap( x, indices, 'normalize', out, 1, 0, clbk ); } }); @@ -480,7 +479,7 @@ tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices (ge indices = [ -10, 10, -5, 5 ]; out = zeros( x.length, 'generic' ); - actual = takeMap( x, indices, 'clamp', out, 1, 0 ,clbk); + actual = takeMap( x, indices, 'clamp', out, 1, 0, clbk); expected = [ 1, 4, 1, 4 ]; t.deepEqual( actual, expected, 'returns expected value' ); @@ -497,7 +496,7 @@ tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices (ac indices = toAccessorArray( [ -10, 10, -5, 5 ] ); out = zeros( x.length, 'generic' ); - takeMap( x, indices, 'clamp', toAccessorArray( out ), 1, 0,clbk ); + takeMap( x, indices, 'clamp', toAccessorArray( out ), 1, 0, clbk ); expected = [ 1, 4, 1, 4 ]; t.deepEqual( out, expected, 'returns expected value' ); @@ -515,7 +514,7 @@ tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices (re indices = [ -10, 10, -5, 5 ]; out = zeros( x.length, 'float64' ); - actual = takeMap( x, indices, 'clamp', out, 1, 0,clbk ); + 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' ); @@ -533,7 +532,7 @@ tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices (co indices = [ -10, 10, -5, 5 ]; out = zeros( x.length, 'complex128' ); - actual = takeMap( x, indices, 'clamp', out, 1, 0,clbk ); + 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' ); @@ -551,7 +550,7 @@ tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices (gene indices = [ -10, 10, -5, 5 ]; out = zeros( x.length, 'generic' ); - actual = takeMap( x, indices, 'wrap', out, 1, 0,clbk ); + actual = takeMap( x, indices, 'wrap', out, 1, 0, clbk ); expected = [ 3, 3, 4, 2 ]; t.deepEqual( actual, expected, 'returns expected value' ); @@ -568,7 +567,7 @@ tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices (acce indices = toAccessorArray( [ -10, 10, -5, 5 ] ); out = zeros( x.length, 'generic' ); - takeMap( x, indices, 'wrap', toAccessorArray( out ), 1, 0,clbk ); + takeMap( x, indices, 'wrap', toAccessorArray( out ), 1, 0, clbk ); expected = [ 3, 3, 4, 2 ]; t.deepEqual( out, expected, 'returns expected value' ); @@ -586,7 +585,7 @@ tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices (real indices = [ -10, 10, -5, 5 ]; out = zeros( x.length, 'float64' ); - actual = takeMap( x, indices, 'wrap', out, 1, 0,clbk ); + 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' ); @@ -604,7 +603,7 @@ tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices (comp indices = [ -10, 10, -5, 5 ]; out = zeros( x.length, 'complex128' ); - actual = takeMap( x, indices, 'wrap', out, 1, 0,clbk ); + 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' ); 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 index af29acc51124..31b781fec12b 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/test/test.js +++ b/lib/node_modules/@stdlib/array/base/take-map/test/test.js @@ -29,18 +29,18 @@ 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(); + 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(); + t.strictEqual( hasOwnProp( takeMap, 'assign' ), true, 'returns expected value' ); + t.strictEqual( hasMethod( takeMap, 'assign' ), true, 'returns expected value' ); + t.end(); }); tape( '...', function test( t ) { - // Add your test cases for the `take-map` module here - t.end(); + // Add your test cases for the `take-map` module here + 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 index 5389066fe05e..d7bb12eb9038 100644 --- 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 @@ -28,158 +28,158 @@ var imagf = require( '@stdlib/complex/imagf' ); var isComplex64 = require( '@stdlib/assert/is-complex64' ); var takeMap = require( './../lib' ); -// CALLBACK function clbk( v ) { - return v; + return v; } +// eslint-disable-next-line stdlib/section-header-empty-lines // 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(); + 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(); + 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; - - x = [ 1, 2, 3, 4 ]; - - indices = [ 1, 3 ]; - actual = takeMap( x, indices, 'throw',clbk ); - expected = [ 2, 4 ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - indices = [ 1, 1, 3, 3 ]; - actual = takeMap( x, indices, 'throw',clbk ); - expected = [ 2, 2, 4, 4 ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - indices = [ 3, 2, 1, 0 ]; - actual = takeMap( x, indices, 'throw',clbk ); - expected = [ 4, 3, 2, 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 = [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); + var expected; + var indices; + var actual; + var x; + + x = [ 1, 2, 3, 4 ]; + + indices = [ 1, 3 ]; + actual = takeMap( x, indices, 'throw', clbk ); + expected = [ 2, 4 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + indices = [ 1, 1, 3, 3 ]; + actual = takeMap( x, indices, 'throw', clbk ); + expected = [ 2, 2, 4, 4 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + indices = [ 3, 2, 1, 0 ]; + actual = takeMap( x, indices, 'throw', clbk ); + expected = [ 4, 3, 2, 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 = [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; + 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; - - 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(); + var expected; + var indices; + var actual; + var x; + var v; + var i; + + 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 ]; - t.deepEqual( takeMap( x, [], 'throw' ), [], 'returns expected value',clbk ); - t.end(); + var x = [ 1, 2, 3, 4 ]; + 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; + var indices; + var x; - x = [ 1, 2, 3, 4 ]; - indices = [ 4, 5, 1, 2 ]; + x = [ 1, 2, 3, 4 ]; + indices = [ 4, 5, 1, 2 ]; - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); - function badValue() { - takeMap( x, indices, 'throw',clbk ); - } + 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; + var expected; + var indices; + var actual; + var x; - x = [ 1, 2, 3, 4 ]; + x = [ 1, 2, 3, 4 ]; - indices = [ -1, -2, -3, -4 ]; - actual = takeMap( x, indices, 'normalize',clbk ); - expected = [ 4, 3, 2, 1 ]; - t.deepEqual( actual, expected, 'returns expected value' ); + indices = [ -1, -2, -3, -4 ]; + actual = takeMap( x, indices, 'normalize', clbk ); + expected = [ 4, 3, 2, 1 ]; + t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); + 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; + var indices; + var x; - x = [ 1, 2, 3, 4 ]; - indices = [ 2, 50, 1, 2 ]; + x = [ 1, 2, 3, 4 ]; + indices = [ 2, 50, 1, 2 ]; - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); - function badValue() { - takeMap( x, indices, 'normalize',clbk ); - } + 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; + var expected; + var indices; + var actual; + var x; - x = [ 1, 2, 3, 4 ]; + 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' ); + 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(); + 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; + var expected; + var indices; + var actual; + var x; - x = [ 1, 2, 3, 4 ]; + 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' ); + 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(); + t.end(); }); From da8703eda70a3aa401ec8032f7cf754935690e10 Mon Sep 17 00:00:00 2001 From: vr-varad Date: Sun, 25 Feb 2024 12:22:31 +0530 Subject: [PATCH 17/22] fix: errors in ts and js files --- .../@stdlib/array/base/take-map/README.md | 1 - .../@stdlib/array/base/take-map/docs/repl.txt | 35 ++++---- .../array/base/take-map/docs/types/index.d.ts | 4 +- .../array/base/take-map/docs/types/test.ts | 83 +++++++++++-------- .../@stdlib/array/base/take/lib/main.js | 7 +- 5 files changed, 72 insertions(+), 58 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/take-map/README.md b/lib/node_modules/@stdlib/array/base/take-map/README.md index fd1128c8fa95..c98c8f0941fd 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/README.md +++ b/lib/node_modules/@stdlib/array/base/take-map/README.md @@ -51,7 +51,6 @@ The function supports the following parameters: - **indices**: list of indices. - **mode**: index [mode][@stdlib/ndarray/base/ind]. - **clbk**: function to apply. -- **thisArg**: applied function execution context (optional). 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 index 00b670361f2b..2bb1ff0690a5 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/take-map/docs/repl.txt @@ -1,8 +1,10 @@ {{alias}}( x, indices, mode, callback ) - Takes elements with given indices from x and pass the values from tha call back function. + Takes elements with given indices from x and + pass the values from tha call back function. - If `indices` is an empty array, the function returns an empty array. + If `indices` is an empty array, the function + returns an empty array. Parameters ---------- @@ -31,16 +33,14 @@ Examples -------- - function square(x){ - return x * x; - } - > var x = [ 1, 2, 3, 4 ]; - > var y = {{alias}}( x, [ 1, 3 ], 'throw',square ) - [ 4, 16] + > 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, callback, out, stride, offset ) - Takes elements from an array, passes via callback function and assigns the values to elements in a +{{alias}}.assign( x, indices, mode, out, stride, offset, callback ) + Takes elements from an array, passes via + callback function and assigns the values to elements in a provided output array. Parameters @@ -60,9 +60,6 @@ equal to 'clamp', the function sets an index to either 0 (minimum index) or the maximum index. - callback : function - The map function to apply on selected elements of x. - out: ArrayLikeObject Output array. @@ -72,6 +69,9 @@ offset: integer Output array offset. + callback : function + The map function to apply on selected elements of x. + Returns ------- out: ArrayLikeObject @@ -79,13 +79,10 @@ Examples -------- - > function square(x){ - return x * x; - } - > var x = [ 1, 2, 3, 4 ]; + > var x = [ -1, -2, -3, -4 ]; > var out = [ 0, 0, 0, 0 ]; - > var arr = {{alias}}.assign( x, [ 1, 3 ], 'throw', square, out, 2, 0 ) - [ 4, 0, 16, 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 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 index 56b8a9650799..4156a12549db 100644 --- 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 @@ -166,7 +166,7 @@ interface TakeMap { * var y = takeMap( x, [ 1, 3 ], 'throw', transform ); * // returns [ 4, 8 ] */ -declare function takeMap( x: Collection | AccessorArrayLike, indices: IndexArray, mode: Mode, clbk: Callback ): Collection +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. @@ -196,5 +196,5 @@ declare function takeMap( x: Collection | AccessorArrayLike, indices * 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 +declare function takeMapAssign( x: Collection | AccessorArrayLike, indices: IndexArray, mode: Mode, clbk: Callback, out: Collection, stride: number, offset: number ): Collection; 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 index fa80a182d8e6..688a5edb2329 100644 --- 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 @@ -22,59 +22,74 @@ import takeMap = require( './index' ); // The function returns an array... { - const transform = (v: number) => v * 2; + // 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[] + // eslint-disable-next-line expect-type/expect + takeMap( [ 1, 2, 3, 4 ], [ 1, 3 ], 'throw', transform ); // $ExpectType number[] + // eslint-disable-next-line expect-type/expect + takeMap( [ 1, 2, 3, 4 ], [ 1, 3 ], 'normalize', transform ); // $ExpectType any[] + // eslint-disable-next-line expect-type/expect + takeMap( [ 1, 2, 3, 4 ], [ 1, 3 ], 'clamp', transform ); // $ExpectType number[] + // eslint-disable-next-line expect-type/expect + 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... { - const transform = (v: number) => v * 2; + // 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 + // eslint-disable-next-line + takeMap( 1, [ 1, 3 ], 'throw', transform ); // $ExpectError + // eslint-disable-next-line + takeMap( true, [ 1, 3 ], 'throw', transform ); // $ExpectError + // eslint-disable-next-line + takeMap( false, [ 1, 3 ], 'throw', transform ); // $ExpectError + // eslint-disable-next-line + takeMap( null, [ 1, 3 ], 'throw', transform ); // $ExpectError + // eslint-disable-next-line + takeMap( void 0, [ 1, 3 ], 'throw', transform ); // $ExpectError + // eslint-disable-next-line + 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... { - const transform = (v: number) => v * 2; + // 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 + 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... { - const transform = (v: number) => v * 2; + // 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 + 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... { - const transform = (v: number) => v * 2; + // 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 + takeMap(); // $ExpectError + takeMap( [], [] ); // $ExpectError + takeMap( [], [], 'throw' ); // $ExpectError + takeMap( [], [], 'throw', transform, {} ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/array/base/take/lib/main.js b/lib/node_modules/@stdlib/array/base/take/lib/main.js index b2291e2d772d..046d125288ba 100644 --- a/lib/node_modules/@stdlib/array/base/take/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/take/lib/main.js @@ -65,13 +65,16 @@ function take( x, indices, mode, clbk ) { out = []; for ( i = 0; i < indices.length; i++ ) { j = getIndex( iget( indices, i ), max ); - if(j!==undefined) { + + // eslint-disable-next-line no-undefined + if (j!==undefined) { if ( clbk ) { + // eslint-disable-next-line node/callback-return out.push( clbk( xget( x, j ) ) ); } else { out.push( xget( x, j ) ); // use `Array#push` to ensure "fast" elements } - } + } } return out; } From db18da9d739263422376c167babb9505dc7b9e0b Mon Sep 17 00:00:00 2001 From: vr-varad Date: Sun, 25 Feb 2024 16:16:19 +0530 Subject: [PATCH 18/22] fix: errors in ts and js files --- lib/node_modules/@stdlib/array/base/take-map/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/node_modules/@stdlib/array/base/take-map/README.md b/lib/node_modules/@stdlib/array/base/take-map/README.md index c98c8f0941fd..f35d619c7995 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/README.md +++ b/lib/node_modules/@stdlib/array/base/take-map/README.md @@ -35,6 +35,7 @@ var takeMap = require('@stdlib/array/base/take-map'); Combines the take and map operations into a single API call. ```javascript +var takeMap = require('@stdlib/array/base/take-map'); var x = [ 1, 2, 3, 4 ]; function customMapping(value) { @@ -69,6 +70,7 @@ The function supports the following parameters: ```javascript +var takeMap = require('@stdlib/array/base/take-map'); var sourceArray = [10, 20, 30, 40, 50]; var indices = [2, 0, 3, 1]; // Indices to be taken var mode = 'wrap'; // Index mode: 'wrap' to wrap around when exceeding array length From 2a0c8d9f2f814e577cbf18545b250ab0cf2a29ae Mon Sep 17 00:00:00 2001 From: vr-varad Date: Mon, 26 Feb 2024 16:07:36 +0530 Subject: [PATCH 19/22] fix: added new clbks --- .../@stdlib/array/base/take-map/README.md | 8 +- .../@stdlib/array/base/take-map/docs/repl.txt | 4 +- .../@stdlib/array/base/take-map/package.json | 4 +- .../array/base/take-map/test/test.assign.js | 130 +++++++++++++++--- .../@stdlib/array/base/take-map/test/test.js | 5 - .../array/base/take-map/test/test.main.js | 45 ++++-- .../@stdlib/array/base/take/lib/main.js | 14 +- 7 files changed, 160 insertions(+), 50 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/take-map/README.md b/lib/node_modules/@stdlib/array/base/take-map/README.md index f35d619c7995..59518cc043f2 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/README.md +++ b/lib/node_modules/@stdlib/array/base/take-map/README.md @@ -71,8 +71,8 @@ The function supports the following parameters: ```javascript var takeMap = require('@stdlib/array/base/take-map'); -var sourceArray = [10, 20, 30, 40, 50]; -var indices = [2, 0, 3, 1]; // Indices to be taken +var sourceArray = [ 10, 20, 30, 40, 50 ]; +var indices = [ 2, 0, 3, 1 ]; // Indices to be taken var mode = 'wrap'; // Index mode: 'wrap' to wrap around when exceeding array length // Use Case 1: Multiply each value by its index @@ -86,11 +86,11 @@ function addTo100(value) { } // Applying Use Case 1: Multiply each value by its index -var multipliedResult = takeMap(sourceArray, indices, mode, multiplyByIndex); +var multipliedResult = takeMap( sourceArray, indices, mode, multiplyByIndex ); // returns // Applying Use Case 2: Add 100 to each value -var addedResult = takeMap(sourceArray, indices, mode, addTo100); +var addedResult = takeMap( sourceArray, indices, mode, addTo100 ); // returns ``` 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 index 2bb1ff0690a5..c5b73ccba759 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/take-map/docs/repl.txt @@ -35,7 +35,7 @@ -------- > var x = [ -1, -2, -3, -4 ]; > var y = {{alias}}( x, [ 1, 3 ], 'throw', {{alias:@stdlib/math/base/special/abs}} ) - [ 2, 4] + [ 2, 4 ] {{alias}}.assign( x, indices, mode, out, stride, offset, callback ) @@ -81,7 +81,7 @@ -------- > 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}}) + > 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 diff --git a/lib/node_modules/@stdlib/array/base/take-map/package.json b/lib/node_modules/@stdlib/array/base/take-map/package.json index 77a0190b7f33..2f8b9c063ce4 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/package.json +++ b/lib/node_modules/@stdlib/array/base/take-map/package.json @@ -22,7 +22,9 @@ "test": "./test" }, "types": "./docs/types", - "scripts": {}, + "scripts": { + "test": "tape test/*.js" + }, "homepage": "https://github.com/stdlib-js/stdlib", "repository": { "type": "git", 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 index efea82cea5a8..73dc269484d6 100644 --- 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 @@ -33,10 +33,6 @@ var takeMap = require( './../lib/assign.js' ); // TESTS // -function clbk( val ) { - return val; -} - tape( 'main export is a function', function test( t ) { t.ok( true, __filename ); t.strictEqual( typeof takeMap, 'function', 'main export is a function' ); @@ -50,12 +46,16 @@ tape( 'the function takes elements from an array (generic)', function test( t ) 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 = [ 2, 4 ]; + expected = [ 4, 16 ]; t.strictEqual( actual, out, 'returns expected value' ); t.deepEqual( actual, expected, 'returns expected value' ); @@ -63,7 +63,7 @@ tape( 'the function takes elements from an array (generic)', function test( t ) indices = [ 1, 1, 3, 3 ]; out = zeros( indices.length*2, 'generic' ); actual = takeMap( x, indices, 'throw', out, 2, 0, clbk ); - expected = [ 2, 0, 2, 0, 4, 0, 4, 0 ]; + expected = [ 4, 0, 4, 0, 16, 0, 16, 0 ]; t.strictEqual( actual, out, 'returns expected value' ); t.deepEqual( actual, expected, 'returns expected value' ); @@ -71,7 +71,7 @@ tape( 'the function takes elements from an array (generic)', function test( t ) indices = [ 3, 2, 1, 0 ]; out = zeros( indices.length, 'generic' ); actual = takeMap( x, indices, 'throw', out, -1, out.length-1, clbk ); - expected = [ 1, 2, 3, 4 ]; + expected = [ 1, 4, 9, 16 ]; t.strictEqual( actual, out, 'returns expected value' ); t.deepEqual( actual, expected, 'returns expected value' ); @@ -79,7 +79,7 @@ tape( 'the function takes elements from an array (generic)', function test( t ) 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; + 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' ); @@ -94,12 +94,16 @@ tape( 'the function takeMaps elements from an array (real typed array)', functio 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( [ 2.0, 4.0 ] ); + expected = new Float64Array( [ 4.0, 8.0 ] ); t.strictEqual( actual, out, 'returns expected value' ); t.deepEqual( actual, expected, 'returns expected value' ); @@ -107,7 +111,7 @@ tape( 'the function takeMaps elements from an array (real typed array)', functio indices = [ 1, 1, 3, 3 ]; out = zeros( indices.length*2, 'float64' ); actual = takeMap( x, indices, 'throw', out, 2, 0, clbk ); - expected = new Float64Array( [ 2.0, 0.0, 2.0, 0.0, 4.0, 0.0, 4.0, 0.0 ] ); + 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' ); @@ -115,7 +119,7 @@ tape( 'the function takeMaps elements from an array (real typed array)', functio indices = [ 3, 2, 1, 0 ]; out = zeros( indices.length, 'float64' ); actual = takeMap( x, indices, 'throw', out, -1, out.length-1, clbk ); - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + 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' ); @@ -123,7 +127,7 @@ tape( 'the function takeMaps elements from an array (real typed array)', functio 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, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); // eslint-disable-line max-len + 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' ); @@ -138,6 +142,10 @@ tape( 'the function takeMaps elements from an array (complex typed array)', func 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 ]; @@ -184,12 +192,16 @@ tape( 'the function takeMaps elements from an array (accessors)', function test( 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 = [ 2, 4 ]; + expected = [ 3, 5 ]; t.strictEqual( actual, out, 'returns expected value' ); isEqual( actual, expected ); @@ -197,7 +209,7 @@ tape( 'the function takeMaps elements from an array (accessors)', function test( indices = toAccessorArray( [ 1, 1, 3, 3 ] ); out = toAccessorArray( zeros( indices.length*2, 'generic' ) ); actual = takeMap( x, indices, 'throw', out, 2, 0, clbk ); - expected = [ 2, 0, 2, 0, 4, 0, 4, 0 ]; + expected = [ 3, 0, 3, 0, 5, 0, 5, 0 ]; t.strictEqual( actual, out, 'returns expected value' ); isEqual( actual, expected ); @@ -205,7 +217,7 @@ tape( 'the function takeMaps elements from an array (accessors)', function test( indices = toAccessorArray( [ 3, 2, 1, 0 ] ); out = toAccessorArray( zeros( indices.length, 'generic' ) ); actual = takeMap( x, indices, 'throw', out, -1, out.length-1, clbk ); - expected = [ 1, 2, 3, 4 ]; + expected = [ 2, 3, 4, 5 ]; t.strictEqual( actual, out, 'returns expected value' ); isEqual( actual, expected ); @@ -213,7 +225,7 @@ tape( 'the function takeMaps elements from an array (accessors)', function test( 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; + expected = [ 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 ]; t.strictEqual( actual, out, 'returns expected value' ); isEqual( actual, expected ); @@ -234,6 +246,10 @@ tape( 'the function returns leaves an output array unchanged if provided a secon var out; var x; + function clbk( val ) { + return val; + } + x = [ 1, 2, 3, 4 ]; out = [ 0, 0, 0, 0 ]; expected = [ 0, 0, 0, 0 ]; @@ -266,6 +282,10 @@ tape( 'when the "mode" is "throw", the function throws an error if provided an o var out; var x; + function clbk( val ) { + return val; + } + x = [ 1, 2, 3, 4 ]; indices = [ 4, 5, 1, 2 ]; out = zeros( x.length, 'generic' ); @@ -283,6 +303,10 @@ tape( 'when the "mode" is "throw", the function throws an error if provided an o 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' ) ); @@ -300,6 +324,10 @@ tape( 'when the "mode" is "throw", the function throws an error if provided an o 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' ); @@ -317,6 +345,10 @@ tape( 'when the "mode" is "throw", the function throws an error if provided an o 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' ); @@ -336,12 +368,16 @@ tape( 'when the "mode" is "normalize", the function normalizes negative indices 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 = [ 4, 3, 2, 1 ]; + expected = [ 8, 6, 4, 2 ]; t.deepEqual( actual, expected, 'returns expected value' ); t.end(); @@ -353,6 +389,10 @@ tape( 'when the "mode" is "normalize", the function normalizes negative 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' ); @@ -371,6 +411,10 @@ tape( 'when the "mode" is "normalize", the function normalizes negative indices 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' ); @@ -389,6 +433,10 @@ tape( 'when the "mode" is "normalize", the function normalizes negative indices 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' ); @@ -405,6 +453,10 @@ tape( 'when the "mode" is "normalize", the function throws an error if provided var out; var x; + function clbk( val ) { + return val; + } + x = [ 1, 2, 3, 4 ]; indices = [ 4, 5, 1, 2 ]; out = zeros( x.length, 'generic' ); @@ -422,6 +474,10 @@ tape( 'when the "mode" is "normalize", the function throws an error if provided 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' ) ); @@ -439,6 +495,10 @@ tape( 'when the "mode" is "normalize", the function throws an error if provided 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' ); @@ -456,6 +516,10 @@ tape( 'when the "mode" is "normalize", the function throws an error if provided 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' ); @@ -475,6 +539,10 @@ tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices (ge var out; var x; + function clbk( val ) { + return val; + } + x = [ 1, 2, 3, 4 ]; indices = [ -10, 10, -5, 5 ]; out = zeros( x.length, 'generic' ); @@ -492,6 +560,10 @@ tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices (ac 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' ); @@ -510,6 +582,10 @@ tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices (re 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' ); @@ -528,6 +604,10 @@ tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices (co 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' ); @@ -546,6 +626,10 @@ tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices (gene var out; var x; + function clbk( val ) { + return val; + } + x = [ 1, 2, 3, 4 ]; indices = [ -10, 10, -5, 5 ]; out = zeros( x.length, 'generic' ); @@ -563,6 +647,10 @@ tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices (acce 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' ); @@ -581,6 +669,10 @@ tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices (real 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' ); @@ -599,6 +691,10 @@ tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices (comp 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' ); 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 index 31b781fec12b..a03afc0f668d 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/test/test.js +++ b/lib/node_modules/@stdlib/array/base/take-map/test/test.js @@ -39,8 +39,3 @@ tape( 'attached to the main export is an `assign` method', function test( t ) { t.strictEqual( hasMethod( takeMap, 'assign' ), true, 'returns expected value' ); t.end(); }); - -tape( '...', function test( t ) { - // Add your test cases for the `take-map` module here - 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 index d7bb12eb9038..fbadbecc65f4 100644 --- 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 @@ -28,11 +28,7 @@ var imagf = require( '@stdlib/complex/imagf' ); var isComplex64 = require( '@stdlib/assert/is-complex64' ); var takeMap = require( './../lib' ); -function clbk( v ) { - return v; -} -// eslint-disable-next-line stdlib/section-header-empty-lines // TESTS // tape( 'main export is a function', function test( t ) { @@ -52,26 +48,30 @@ tape( 'the function takes elements from an array', function test( t ) { 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 = [ 2, 4 ]; + expected = [ 4, 16 ]; t.deepEqual( actual, expected, 'returns expected value' ); indices = [ 1, 1, 3, 3 ]; actual = takeMap( x, indices, 'throw', clbk ); - expected = [ 2, 2, 4, 4 ]; + expected = [ 4, 4, 16, 16 ]; t.deepEqual( actual, expected, 'returns expected value' ); indices = [ 3, 2, 1, 0 ]; actual = takeMap( x, indices, 'throw', clbk ); - expected = [ 4, 3, 2, 1 ]; + 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 = [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; + expected = [ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 ]; t.deepEqual( actual, expected, 'returns expected value' ); t.end(); @@ -85,6 +85,10 @@ tape( 'the function takes elements from an array (accessors)', function test( t 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 ); @@ -102,6 +106,9 @@ tape( 'the function takes elements from an array (accessors)', function test( t 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(); }); @@ -110,6 +117,10 @@ tape( 'when the "mode" is "throw", the function throws an error if provided an o var indices; var x; + function clbk( v ) { + return v; + } + x = [ 1, 2, 3, 4 ]; indices = [ 4, 5, 1, 2 ]; @@ -127,11 +138,15 @@ tape( 'when the "mode" is "normalize", the function normalizes negative 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 = [ 4, 3, 2, 1 ]; + expected = [ 8, 6, 4, 2 ]; t.deepEqual( actual, expected, 'returns expected value' ); t.end(); @@ -141,6 +156,10 @@ tape( 'when the "mode" is "normalize", the function throws an error if provided var indices; var x; + function clbk( v ) { + return v; + } + x = [ 1, 2, 3, 4 ]; indices = [ 2, 50, 1, 2 ]; @@ -158,6 +177,10 @@ tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', f var actual; var x; + function clbk( v ) { + return v; + } + x = [ 1, 2, 3, 4 ]; indices = [ -10, 10, -5, 5 ]; @@ -174,6 +197,10 @@ tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices', fun var actual; var x; + function clbk( v ) { + return v; + } + x = [ 1, 2, 3, 4 ]; indices = [ -10, 10, -5, 5 ]; diff --git a/lib/node_modules/@stdlib/array/base/take/lib/main.js b/lib/node_modules/@stdlib/array/base/take/lib/main.js index 046d125288ba..e32e11d44b69 100644 --- a/lib/node_modules/@stdlib/array/base/take/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/take/lib/main.js @@ -32,7 +32,6 @@ var ind = require( '@stdlib/ndarray/base/ind' ).factory; * @param {Collection} x - input array * @param {IntegerArray} indices - list of indices * @param {string} mode - index mode -* @param {Function} [clbk] - callback to invoke for each element * @returns {Array} output array * * @example @@ -42,7 +41,7 @@ var ind = require( '@stdlib/ndarray/base/ind' ).factory; * var y = take( x, indices, 'throw' ); * // returns [ 4, 2, 3, 1 ] */ -function take( x, indices, mode, clbk ) { +function take( x, indices, mode ) { var getIndex; var xget; var iget; @@ -65,16 +64,7 @@ function take( x, indices, mode, clbk ) { out = []; for ( i = 0; i < indices.length; i++ ) { j = getIndex( iget( indices, i ), max ); - - // eslint-disable-next-line no-undefined - if (j!==undefined) { - if ( clbk ) { - // eslint-disable-next-line node/callback-return - out.push( clbk( xget( x, j ) ) ); - } else { - out.push( xget( x, j ) ); // use `Array#push` to ensure "fast" elements - } - } + out.push( xget( x, j ) ); // use `Array#push` to ensure "fast" elements } return out; } From ef66eabf4e0cf12021feae53045aca35d45a2031 Mon Sep 17 00:00:00 2001 From: vr-varad Date: Tue, 27 Feb 2024 23:49:45 +0530 Subject: [PATCH 20/22] fix: resolved changes --- .../@stdlib/array/base/take-map/README.md | 12 +- .../benchmark/benchmark.assign.length.js | 2 +- .../take-map/benchmark/benchmark.length.js | 2 +- .../array/base/take-map/docs/types/index.d.ts | 2 + .../@stdlib/array/base/take-map/lib/assign.js | 106 +++++++++--------- .../@stdlib/array/base/take-map/lib/index.js | 8 ++ .../@stdlib/array/base/take-map/lib/main.js | 8 +- .../@stdlib/array/base/take-map/package.json | 2 +- .../array/base/take-map/test/test.assign.js | 20 ++-- .../array/base/take-map/test/test.main.js | 2 +- 10 files changed, 90 insertions(+), 74 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/take-map/README.md b/lib/node_modules/@stdlib/array/base/take-map/README.md index 59518cc043f2..85fa46eef1c8 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/README.md +++ b/lib/node_modules/@stdlib/array/base/take-map/README.md @@ -20,7 +20,7 @@ limitations under the License. # take-map -> Takes elements from an array, applies a mapping function using a callback, and returns a new array. +> Take elements from an array, applies a mapping function using a callback, and returns a new array.
@@ -42,7 +42,7 @@ function customMapping(value) { return value * 2; } -var y = takeMap(x, [1, 3], 'throw', customMapping); +var y = takeMap( x, [ 1, 3 ], 'throw', customMapping ); // returns [ 4, 8 ] ``` @@ -76,22 +76,22 @@ var indices = [ 2, 0, 3, 1 ]; // Indices to be taken var mode = 'wrap'; // Index mode: 'wrap' to wrap around when exceeding array length // Use Case 1: Multiply each value by its index -function multiplyByIndex(value, index) { +function multiplyByIndex( value, index ) { return value * index; } // Use Case 2: Add 100 to each value -function addTo100(value) { +function addTo100( value ) { return value + 100; } // Applying Use Case 1: Multiply each value by its index var multipliedResult = takeMap( sourceArray, indices, mode, multiplyByIndex ); -// returns +// returns [ 60, 0, 120, 20 ] // Applying Use Case 2: Add 100 to each value var addedResult = takeMap( sourceArray, indices, mode, addTo100 ); -// returns +// returns [ 130, 110, 140, 120 ] ```
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 index 4f54fa27f537..5f150f679fd5 100644 --- 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 @@ -61,7 +61,7 @@ function createBenchmark( len ) { var i; x = [ 1, 2, 3, 4 ]; - function clbk(val) { + function clbk( val ) { return val; } 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 index 9a88e12ee270..df46e8bd47f5 100644 --- 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 @@ -54,7 +54,7 @@ function createBenchmark( len ) { x = [ 1, 2, 3, 4 ]; - function clbk(val) { + function clbk( val ) { return val; } 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 index 4156a12549db..d719261df8a9 100644 --- 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 @@ -16,6 +16,8 @@ * limitations under the License. */ +// TypeScript Version: 4.1 + /// import { Collection, AccessorArrayLike } from '@stdlib/types/array'; 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 index 7008789a4798..5c868c946569 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/lib/assign.js +++ b/lib/node_modules/@stdlib/array/base/take-map/lib/assign.js @@ -32,24 +32,26 @@ var ind = require( '@stdlib/ndarray/base/ind' ).factory; * 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. +* @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 ]; * -* var arr = takeMapIndexed( x, indices, 'throw', out, 1, 0, function(val) { -* return val; -* }); -* // arr is [ 4, 2, 3, 1 ] +* 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; @@ -73,7 +75,7 @@ function takeMapIndexed( x, indices, mode, out, stride, offset, clbk ) { } for (i = 0; i Date: Sun, 3 Mar 2024 03:05:12 +0530 Subject: [PATCH 21/22] fix: made some changes --- .../@stdlib/array/base/take-map/README.md | 81 +++++++++++++------ .../@stdlib/array/base/take-map/docs/repl.txt | 12 ++- .../array/base/take-map/docs/types/index.d.ts | 4 + .../array/base/take-map/docs/types/test.ts | 6 -- .../@stdlib/array/base/take-map/lib/index.js | 4 +- .../@stdlib/array/base/take-map/package.json | 6 +- .../array/base/take-map/test/test.assign.js | 8 +- 7 files changed, 73 insertions(+), 48 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/take-map/README.md b/lib/node_modules/@stdlib/array/base/take-map/README.md index 85fa46eef1c8..1fbb962f2456 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/README.md +++ b/lib/node_modules/@stdlib/array/base/take-map/README.md @@ -20,22 +20,21 @@ limitations under the License. # take-map -> Take elements from an array, applies a mapping function using a callback, and returns a new array. +> 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'); +var takeMap = require( '@stdlib/array/base/take-map' ); ``` -### takeMap( x, indices, mode, clbk) +### takeMap( x, indices, mode, clbk ) -Combines the take and map operations into a single API call. +Takes elements from an array and returns a new array after applying a mapping function. ```javascript -var takeMap = require('@stdlib/array/base/take-map'); var x = [ 1, 2, 3, 4 ]; function customMapping(value) { @@ -53,6 +52,38 @@ The function supports the following parameters: - **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. + +
@@ -70,28 +101,28 @@ The function supports the following parameters: ```javascript -var takeMap = require('@stdlib/array/base/take-map'); -var sourceArray = [ 10, 20, 30, 40, 50 ]; -var indices = [ 2, 0, 3, 1 ]; // Indices to be taken -var mode = 'wrap'; // Index mode: 'wrap' to wrap around when exceeding array length - -// Use Case 1: Multiply each value by its index -function multiplyByIndex( value, index ) { - return value * index; +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; } -// Use Case 2: Add 100 to each value -function addTo100( value ) { - return value + 100; -} - -// Applying Use Case 1: Multiply each value by its index -var multipliedResult = takeMap( sourceArray, indices, mode, multiplyByIndex ); -// returns [ 60, 0, 120, 20 ] - -// Applying Use Case 2: Add 100 to each value -var addedResult = takeMap( sourceArray, indices, mode, addTo100 ); -// returns [ 130, 110, 140, 120 ] +// 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/docs/repl.txt b/lib/node_modules/@stdlib/array/base/take-map/docs/repl.txt index c5b73ccba759..8be243708488 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/take-map/docs/repl.txt @@ -1,10 +1,9 @@ {{alias}}( x, indices, mode, callback ) - Takes elements with given indices from x and - pass the values from tha call back function. + 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. + If `indices` is an empty array, the function returns an empty array. Parameters ---------- @@ -39,9 +38,8 @@ {{alias}}.assign( x, indices, mode, out, stride, offset, callback ) - Takes elements from an array, passes via - callback function and assigns the values to elements in a - provided output array. + Takes elements from an array, applies a mapping function, and assigns the + values to elements in a provided output array. Parameters ---------- 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 index d719261df8a9..cbb0a7ec7cb3 100644 --- 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 @@ -199,4 +199,8 @@ declare function takeMap( x: Collection | AccessorArrayLike, indices * // 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 index 688a5edb2329..e20da669abf6 100644 --- 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 @@ -40,17 +40,11 @@ import takeMap = require( './index' ); // eslint-disable-next-line @typescript-eslint/explicit-function-return-type const transform = ( v: number ) => v * 2; - // eslint-disable-next-line takeMap( 1, [ 1, 3 ], 'throw', transform ); // $ExpectError - // eslint-disable-next-line takeMap( true, [ 1, 3 ], 'throw', transform ); // $ExpectError - // eslint-disable-next-line takeMap( false, [ 1, 3 ], 'throw', transform ); // $ExpectError - // eslint-disable-next-line takeMap( null, [ 1, 3 ], 'throw', transform ); // $ExpectError - // eslint-disable-next-line takeMap( void 0, [ 1, 3 ], 'throw', transform ); // $ExpectError - // eslint-disable-next-line takeMap( {}, [ 1, 3 ], 'throw', transform ); // $ExpectError } 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 index c12e70443d59..b3918c07e909 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/lib/index.js +++ b/lib/node_modules/@stdlib/array/base/take-map/lib/index.js @@ -28,7 +28,7 @@ * * var x = [ 1, 2, 3, 4 ]; * -* function mapFunction( val ){ +* function mapFunction( val ) { return val; } * @@ -44,7 +44,7 @@ * var out = [ 0, 0, 0, 0, 0, 0 ]; * var indices = [ 0, 0, 1, 1, 3, 3 ]; * -* function clbk( val ){ +* function clbk( val ) { return val; } * diff --git a/lib/node_modules/@stdlib/array/base/take-map/package.json b/lib/node_modules/@stdlib/array/base/take-map/package.json index 14ca8f8c0ed3..b64bac7386f7 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/package.json +++ b/lib/node_modules/@stdlib/array/base/take-map/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/array/base/take-map", "version": "0.0.0", - "description": "Take elements from an array, applies a mapping function using a callback, and returns a new array.", + "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", @@ -22,9 +22,7 @@ "test": "./test" }, "types": "./docs/types", - "scripts": { - "test": "tape test/*.js" - }, + "scripts": {}, "homepage": "https://github.com/stdlib-js/stdlib", "repository": { "type": "git", 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 index f07e1e42389e..7e8156daef4d 100644 --- 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 @@ -87,7 +87,7 @@ tape( 'the function takes elements from an array (generic)', function test( t ) t.end(); }); -tape( 'the function takeMaps elements from an array (real typed array)', function test( t ) { +tape( 'the function takes and maps elements from an array (real typed array)', function test( t ) { var expected; var indices; var actual; @@ -135,7 +135,7 @@ tape( 'the function takeMaps elements from an array (real typed array)', functio t.end(); }); -tape( 'the function takeMaps elements from an array (complex typed array)', function test( t ) { +tape( 'the function takes and maps elements from an array (complex typed array)', function test( t ) { var expected; var indices; var actual; @@ -185,7 +185,7 @@ tape( 'the function takeMaps elements from an array (complex typed array)', func t.end(); }); -tape( 'the function takeMaps elements from an array (accessors)', function test( t ) { +tape( 'the function takes and maps elements from an array (accessors)', function test( t ) { var expected; var indices; var actual; @@ -240,7 +240,7 @@ tape( 'the function takeMaps elements from an array (accessors)', function test( } }); -tape( 'the function returns leaves an output array unchanged if provided a second argument which is empty', function test( t ) { +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; From e2aeb122440f9b54844beb9ebc71572b262263b8 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Wed, 6 Mar 2024 10:19:29 -0500 Subject: [PATCH 22/22] Apply suggestions from code review Signed-off-by: Philipp Burckhardt --- lib/node_modules/@stdlib/array/base/take-map/README.md | 5 ++--- lib/node_modules/@stdlib/array/base/take-map/docs/repl.txt | 4 ++-- .../@stdlib/array/base/take-map/docs/types/test.ts | 4 ---- lib/node_modules/@stdlib/array/base/take/package.json | 4 +--- 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/take-map/README.md b/lib/node_modules/@stdlib/array/base/take-map/README.md index 1fbb962f2456..5d426e425772 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/README.md +++ b/lib/node_modules/@stdlib/array/base/take-map/README.md @@ -18,7 +18,7 @@ limitations under the License. --> -# take-map +# takeMap > Take elements from an array and return a new array after applying a mapping function. @@ -37,7 +37,7 @@ Takes elements from an array and returns a new array after applying a mapping fu ```javascript var x = [ 1, 2, 3, 4 ]; -function customMapping(value) { +function customMapping( value ) { return value * 2; } @@ -83,7 +83,6 @@ The function supports the following parameters: - **offset**: output array offset. - **clbk**: callback function. - 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 index 8be243708488..50ca76703374 100644 --- a/lib/node_modules/@stdlib/array/base/take-map/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/take-map/docs/repl.txt @@ -23,7 +23,7 @@ or the maximum index. callback : function - The map function to apply on selected elements of x. + Map function to apply to selected elements of `x`. Returns ------- @@ -68,7 +68,7 @@ Output array offset. callback : function - The map function to apply on selected elements of x. + Map function to apply to selected elements of `x`. Returns ------- 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 index e20da669abf6..2eaef25ff043 100644 --- 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 @@ -25,13 +25,9 @@ import takeMap = require( './index' ); // eslint-disable-next-line @typescript-eslint/explicit-function-return-type const transform = ( v: number ) => v * 2; - // eslint-disable-next-line expect-type/expect takeMap( [ 1, 2, 3, 4 ], [ 1, 3 ], 'throw', transform ); // $ExpectType number[] - // eslint-disable-next-line expect-type/expect takeMap( [ 1, 2, 3, 4 ], [ 1, 3 ], 'normalize', transform ); // $ExpectType any[] - // eslint-disable-next-line expect-type/expect takeMap( [ 1, 2, 3, 4 ], [ 1, 3 ], 'clamp', transform ); // $ExpectType number[] - // eslint-disable-next-line expect-type/expect takeMap( [ '1', '2', '3', '4' ], [ 1, 3 ], 'wrap', transform ); // $ExpectType string[] } diff --git a/lib/node_modules/@stdlib/array/base/take/package.json b/lib/node_modules/@stdlib/array/base/take/package.json index af751f83e2f2..49cfa7981ef2 100644 --- a/lib/node_modules/@stdlib/array/base/take/package.json +++ b/lib/node_modules/@stdlib/array/base/take/package.json @@ -22,9 +22,7 @@ "test": "./test" }, "types": "./docs/types", - "scripts": { - "test": "tape test/*.js" - }, + "scripts": {}, "homepage": "https://github.com/stdlib-js/stdlib", "repository": { "type": "git",