From ac148b384cdfd062528c69f125553b322bbec107 Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Sat, 2 Mar 2024 20:12:40 +0530 Subject: [PATCH 01/14] added mskreject-map --- .../array/base/mskreject-map/README.md | 174 ++++++++++ .../benchmark/benchmark.assign.length.js | 106 ++++++ .../base/mskreject-map/benchmark/benchmark.js | 57 ++++ .../benchmark/benchmark.length.js | 99 ++++++ .../array/base/mskreject-map/docs/repl.txt | 91 +++++ .../base/mskreject-map/docs/types/index.d.ts | 57 ++++ .../base/mskreject-map/docs/types/test.ts | 56 ++++ .../base/mskreject-map/examples/index.js | 42 +++ .../array/base/mskreject-map/lib/assign.js | 237 +++++++++++++ .../array/base/mskreject-map/lib/index.js | 67 ++++ .../array/base/mskreject-map/lib/main.js | 69 ++++ .../array/base/mskreject-map/package.json | 65 ++++ .../base/mskreject-map/test/test.assign.js | 311 ++++++++++++++++++ .../array/base/mskreject-map/test/test.js | 41 +++ .../base/mskreject-map/test/test.main.js | 109 ++++++ 15 files changed, 1581 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/base/mskreject-map/README.md create mode 100644 lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.assign.length.js create mode 100644 lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.length.js create mode 100644 lib/node_modules/@stdlib/array/base/mskreject-map/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/array/base/mskreject-map/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/array/base/mskreject-map/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/array/base/mskreject-map/examples/index.js create mode 100644 lib/node_modules/@stdlib/array/base/mskreject-map/lib/assign.js create mode 100644 lib/node_modules/@stdlib/array/base/mskreject-map/lib/index.js create mode 100644 lib/node_modules/@stdlib/array/base/mskreject-map/lib/main.js create mode 100644 lib/node_modules/@stdlib/array/base/mskreject-map/package.json create mode 100644 lib/node_modules/@stdlib/array/base/mskreject-map/test/test.assign.js create mode 100644 lib/node_modules/@stdlib/array/base/mskreject-map/test/test.js create mode 100644 lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/README.md b/lib/node_modules/@stdlib/array/base/mskreject-map/README.md new file mode 100644 index 000000000000..f0be87dbda19 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/README.md @@ -0,0 +1,174 @@ + + +# mskreject-map + +> Apply a mask to a provided input array and map the unmasked values according to the clbk function provided. + +
+ +## Usage + +```javascript +var mskrejectMap = require( '@stdlib/array/base/mskreject-map' ); +``` + +#### mskrejectMap( x, mask, clbk\[, thisArg ] ) + +Returns a new array by applying a mask and mapping the unmasked values according to the clbk function to the provided input array. + +```javascript +var x = [ 1, 2, 3, 4 ]; + +function clbk( val ) { + return val * 2; +}; + +var y = mskrejectMap( x, [ 0, 1, 0, 1 ], clbk ); +// returns [ 2, 6 ] +``` + +The function supports the following parameters: + +- **x**: input array. +- **mask**: mask array. +- **clbk**: function to apply. +- **thisArg**: applied function execution context (_optional_). + +The `clbk` function is provided three arguments: + +- **value**: current unmasked array element. +- **index**: current unmasked array element index. +- **arr**: input array. + +To set the `clbk` function execution context, provide a `thisArg`. + +```javascript +var x = [ 1, 2, 3, 4 ]; + +var mask = [ 0, 1, 0, 1 ]; + +var context = { + `increase`: 3 +}; + +function clbk( value ) { + return value + this.increase; +} + +var out = mskrejectMap( x, mask, clbk, context ); +// returns [ 4, 6 ] +``` + +The function **always** returns a new "generic" array. + +#### mskreject.assign( x, mask, out, stride, offset, clbk\[, thisArg ] ) + +Applies a mask to a provided input array, maps the unmasked values according to the clbk function and assigns to elements in a provided output array. + +```javascript +var x = [ 1, 2, 3, 4 ]; + +var mask = [ 1, 0, 1, 0 ]; + +var out = [ 0, 0, 0, 0 ]; + +function clbk( val ) { + return val * 2; +} + +var arr = mskrejectMap.assign( x, mask, out, -2, out.length-1, clbk ); +// returns [ 0, 8, 0, 4 ] + +var bool = ( arr === out ); +// returns true +``` + +The function supports the following parameters: + +- **x**: input array. +- **mask**: mask array. +- **out**: output array. +- **stride**: output array stride. +- **offset**: output array offset. +- **clbk**: function to apply. +- **thisArg**: applied function execution context (_optional_). + +
+ + + +
+ +## Notes + +- If a `mask` array element is falsy, the corresponding element in `x` is **mapped** in the output array; otherwise, the corresponding element in `x` is "masked" and thus **excluded** from the output array. + +
+ + + +
+ +## Examples + + + +```javascript +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var mskrejectMap = require( '@stdlib/array/base/mskreject' ); + +// Generate a linearly spaced array: +var x = zeroTo( 20 ); +console.log( x ); + +// Generate a random mask: +var mask = bernoulli( x.length, 0.5, { + 'dtype': 'generic' +}); +console.log( mask ); + +// Filter an array using the mask: +var y = mskrejectMap( x, mask, function( val ){ + return val * 2; +} ); +console.log( y ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.assign.length.js b/lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.assign.length.js new file mode 100644 index 000000000000..3afda17a7ec4 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.assign.length.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var zeros = require( '@stdlib/array/zeros' ); +var isArray = require( '@stdlib/assert/is-array' ); +var isnan = require( '@stdlib/assert/is-nan' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var mskrejectMap = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var mask; + var out; + var x; + + x = zeroTo( len, 'generic' ); + mask = zeros( len, 'generic' ); + out = zeros( len, 'generic' ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = mskrejectMap.assign( x, mask, out, 1, 0, function( val ) { + return val * 2; + } ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) || isnan( v[ i%len ] ) ) { + 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/mskreject-map/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.js new file mode 100644 index 000000000000..e502d654b9ae --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.js @@ -0,0 +1,57 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isArray = require( '@stdlib/assert/is-array' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var pkg = require( './../package.json' ).name; +var mskrejectMap = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::copy:len=100', function benchmark( b ) { + var x; + var y; + var i; + var v; + + x = zeroTo( 100 ); + y = zeros( x.length ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = mskrejectMap( x, y, function( val ) { + return val * 2; + } ); + 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/mskreject-map/benchmark/benchmark.length.js b/lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.length.js new file mode 100644 index 000000000000..2fab9c668e21 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.length.js @@ -0,0 +1,99 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var isArray = require( '@stdlib/assert/is-array' ); +var pkg = require( './../package.json' ).name; +var mskrejectMap = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = zeroTo( len ); + var y = zeros( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = mskrejectMap( x, y, function( val ) { + return val * 2; + } ); + 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/mskreject-map/docs/repl.txt b/lib/node_modules/@stdlib/array/base/mskreject-map/docs/repl.txt new file mode 100644 index 000000000000..8b21af8550d8 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/docs/repl.txt @@ -0,0 +1,91 @@ + +{{alias}}( x, mask, clbk[, thisArg] ) + Returns a new array by applying a mask to a provided input array + and mapping the unmasked values according to the clbk function to + the provided input array. + + If a mask array element is falsy, the corresponding element in `x` is + mapped in the output array; otherwise, the corresponding element in `x` is + "masked" and thus excluded from the output array. + + Parameters + ---------- + x: ArrayLikeObject + Input array. + + mask: ArrayLikeObject + Mask array. + + clbk: Function + Mapping function. + + thisArg: any (optional) + Execution context. + + Returns + ------- + out: Array + Output array. + + Examples + -------- + > var x = [ 1, 2, 3, 4 ]; + > var y = {{alias}}( x, [ 0, 1, 0, 1 ], function clbk( val ) { + return val * 2; + } ) + [ 2, 6 ] + + +{{alias}}.assign( x, mask, out, stride, offset, clbk[, thisArg] ) + Applies a mask to a provided input array, maps the unmasked values + according to the clbk function and and assigns the unmasked values + to elements in a provided output array. + + If a mask array element is falsy, the corresponding element in `x` is + mapped and included in the output array; otherwise, the corresponding + element in `x` is "masked" and thus excluded from the output array. + + Parameters + ---------- + x: ArrayLikeObject + Input array. + + mask: ArrayLikeObject + Mask array. + + out: ArrayLikeObject + Output array. + + stride: integer + Output array stride. + + offset: integer + Output array offset. + + clbk: Function + Mapping function. + + thisArg: any (optional) + Execution context. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + > var x = [ 1, 2, 3, 4 ]; + > var m = [ 0, 1, 0, 1 ]; + > var out = [ 0, 0, 0, 0 ]; + > var scale = 5; + > var arr = {{alias}}.assign( x, m, out, 2, 0, function clbk( val ) { + return val * this; + }, scale ) + [ 5, 0, 15, 0 ] + > var bool = ( arr === out ) + true + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/mskreject-map/docs/types/index.d.ts new file mode 100644 index 000000000000..7174185adee8 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/docs/types/index.d.ts @@ -0,0 +1,57 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Returns a transformed element of input array. +* +* @param value - current array element +* @param index - current array element index +* @param arr - input array +* @returns The transformed array element +*/ +type ClbkType = ( this: U, value: T, index: number, arr: Collection | AccessorArrayLike ) => any; + +/** +* Returns a new array by applying a mask and mapping the unmasked values according to the clbk function to the provided input array. +* +* @param x - input array +* @param mask - mask array +* @param clbk - mapping function +* @param thisArg - function context +* @returns output array +* +* @example +* var x = [ 1, 2, 3, 4 ]; +* +* var y = mskrejectMap( x, [ 0, 1, 0, 1 ], function( val ) { +* return val * 2; +* } ); +* // returns [ 2, 6 ] +*/ +declare function mskrejectMap( x: Collection | AccessorArrayLike, mask: Collection, clbk: ClbkType, thisArg?: U ): Array; + + +// EXPORTS // + +export = mskrejectMap; diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/mskreject-map/docs/types/test.ts new file mode 100644 index 000000000000..0328f60ce17c --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/docs/types/test.ts @@ -0,0 +1,56 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import mskrejectMap from './index'; + +// TESTS // + +// The function returns an array... +{ + mskrejectMap( [ 1, 2, 3, 4 ], [ 0, 0, 0, 0 ], function( val ) { return val * 2 } ); // $ExpectType number[] + mskrejectMap( [ 1, 2, 3, 4 ], [ 0, 0, 0, 0 ], function( val ) { return val * 2 } ); // $ExpectType any[] + mskrejectMap( [ 1, 2, 3, 4 ], [ 0, 0, 0, 0 ], function( val ) { return val * 2 } ); // $ExpectType number[] + mskrejectMap( [ '1', '2', '3', '4' ], [ 0, 0, 0, 0 ], function( val ) { return val } ); // $ExpectType string[] +} + +// The compiler throws an error if the function is provided a first argument which is not an array-like object... +{ + mskrejectMap( 1, [ 0, 0 ] ); // $ExpectError + mskrejectMap( true, [ 0, 0 ] ); // $ExpectError + mskrejectMap( false, [ 0, 0 ] ); // $ExpectError + mskrejectMap( null, [ 0, 0 ] ); // $ExpectError + mskrejectMap( void 0, [ 0, 0 ] ); // $ExpectError + mskrejectMap( {}, [ 0, 0 ] ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... +{ + mskrejectMap( [], 1 ); // $ExpectError + mskrejectMap( [], true ); // $ExpectError + mskrejectMap( [], false ); // $ExpectError + mskrejectMap( [], null ); // $ExpectError + mskrejectMap( [], void 0 ); // $ExpectError + mskrejectMap( [], {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + mskrejectMap(); // $ExpectError + mskrejectMap( [] ); // $ExpectError + mskrejectMap( [], [], [] ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/examples/index.js b/lib/node_modules/@stdlib/array/base/mskreject-map/examples/index.js new file mode 100644 index 000000000000..b412fe4070bb --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/examples/index.js @@ -0,0 +1,42 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var mskrejectMap = require( './../lib' ); + +// Generate a linearly spaced array: +var x = zeroTo( 20 ); +console.log( x ); + +// Generate a random mask: +var mask = bernoulli( x.length, 0.5, { + 'dtype': 'generic' +}); +console.log( mask ); + +// Callback function's execution context +var inc = 5; + +// Filter an array using the mask: +var y = mskrejectMap( x, mask, function( val ) { + return val + this; +}, inc ); +console.log( y ); diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/lib/assign.js b/lib/node_modules/@stdlib/array/base/mskreject-map/lib/assign.js new file mode 100644 index 000000000000..bc04e791bd1f --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/lib/assign.js @@ -0,0 +1,237 @@ +/** +* @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' ); + + +// FUNCTIONS // + +/** +* Applies a mask to an indexed array, maps the unmasked values according to the clbk function and assigns to elements in an indexed output array. +* +* @private +* @param {Collection} x - input array +* @param {IntegerArray} mask - mask array +* @param {Collection} out - output array +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @param {Function} clbk - function to apply +* @param {*} [thisArg] - function context +* @returns {Collection} output array +* +* @example +* var x = [ 1, 2, 3, 4 ]; +* var mask = [ 0, 1, 0, 1 ]; +* +* var out = [ 0, 0, 0, 0 ]; +* +* var arr = indexed( x, mask, out, 1, 0, function( val ) { +* return val * 2; +* } ); +* // returns [ 2, 6, 0, 0 ] +*/ +function indexed( x, mask, out, stride, offset, clbk, thisArg ) { + var io; + var i; + + io = offset; + for ( i = 0; i < x.length; i++ ) { + if ( !mask[ i ] ) { + out[ io ] = clbk.call(thisArg, x[ i ], i, x ); + io += stride; + } + } + return out; +} + +/** +* Applies a mask to an accessor array, maps the unmasked values according to the clbk function and assigns to elements in an accessor output array. +* +* @private +* @param {Object} x - input array object +* @param {Object} mask - mask array object +* @param {Object} out - output array object +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @param {Function} clbk - function to apply +* @param {*} [thisArg] - function context +* @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 mask = toAccessorArray( [ 0, 1, 0, 1 ] ); +* +* var out = toAccessorArray( [ 0, 0, 0, 0 ] ); +* var arr = accessors( arraylike2object( x ), arraylike2object( mask ), arraylike2object( out ), 1, 0, function( val ) { +* return val * 2; +* } ); +* +* var v = arr.get( 0 ); +* // returns 2 +* +* v = arr.get( 1 ); +* // returns 6 +*/ +function accessors( x, mask, out, stride, offset, clbk, thisArg ) { + var xdata; + var mdata; + var odata; + var xget; + var mget; + var oset; + var io; + var i; + + xdata = x.data; + mdata = mask.data; + odata = out.data; + + xget = x.accessors[ 0 ]; + mget = mask.accessors[ 0 ]; + oset = out.accessors[ 1 ]; + + io = offset; + for ( i = 0; i < xdata.length; i++ ) { + if ( !mget( mdata, i ) ) { + oset( odata, io, clbk.call( thisArg, xget( xdata, i ), i, xdata ) ); + io += stride; + } + } + return odata; +} + +/** +* Applies a mask to a complex array, maps the unmasked values according to the clbk function and assigns to elements in a complex output array. +* +* @private +* @param {Collection} x - real-valued floating-point input array view +* @param {Object} mask - mask array object +* @param {Collection} out - real-valued floating-point output array view +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @param {Function} clbk - function to apply +* @param {*} [thisArg] - function context +* @returns {Collection} output array view +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var mask = [ 0, 1, 0, 1 ]; +* +* var out = new Float64Array( 8 ); +* +* var arr = complex( x, arraylike2object( mask ), out, 1, 0, function( val ) { +* return val * 2; +* } ); +* // returns [ 2.0, 4.0, 10.0, 12.0, 0.0, 0.0, 0.0, 0.0 ] +*/ +function complex( x, mask, out, stride, offset, clbk, thisArg ) { + var mdata; + var mget; + var io; + var so; + var i; + var j; + + mdata = mask.data; + mget = mask.accessors[ 0 ]; + + 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 < mdata.length; i++ ) { + if ( !mget( mdata, i ) ) { + j = i * 2; + out[ io ] = clbk.call( thisArg, x[ j ], j, x ); + out[ io+1 ] = clbk.call( thisArg, x[ j+1 ], j+1, x ); + io += so; + } + } + return out; +} + + +// MAIN // + +/** +* Applies a mask to a provided input array, maps the unmasked values according to the clbk function and assigns to elements in a provided output array. +* +* @param {Collection} x - input array +* @param {Collection} mask - mask array +* @param {Collection} out - output array +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @param {Function} clbk - function to apply +* @param {*} [thisArg] - function context +* @returns {Collection} output array +* +* @example +* var x = [ 1, 2, 3, 4 ]; +* var mask = [ 0, 1, 0, 1 ]; +* +* var out = [ 0, 0 ]; +* var arr = assign( x, mask, out, 1, 0, function( val ) { +* return val * 2; +* } ); +* // returns [ 2, 6 ] +* +* var bool = ( arr === out ); +* // returns true +*/ +function assign( x, mask, out, stride, offset, clbk, thisArg ) { + var xo; + var mo; + var oo; + + xo = arraylike2object( x ); + mo = arraylike2object( mask ); + oo = arraylike2object( out ); + if ( + xo.accessorProtocol || + mo.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 ) + ) { + complex( reinterpret( x, 0 ), mo, reinterpret( out, 0 ), stride, offset, clbk, thisArg ); // eslint-disable-line max-len + return out; + } + accessors( xo, mo, oo, stride, offset, clbk, thisArg ); + return out; + } + indexed( x, mask, out, stride, offset, clbk, thisArg ); + return out; +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/lib/index.js b/lib/node_modules/@stdlib/array/base/mskreject-map/lib/index.js new file mode 100644 index 000000000000..825e3ad37fc6 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/lib/index.js @@ -0,0 +1,67 @@ +/** +* @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'; + +/** +* Apply a mask to a provided input array and map the unmasked values according to the clbk function provided. +* +* @module @stdlib/array/base/mskreject-map +* +* @example +* var mskrejectMap = require( '@stdlib/array/base/mskreject-map' ); +* +* var x = [ 1, 2, 3, 4 ]; +* var mask = [ 0, 1, 0, 1 ]; +* +* var y = mskrejectMap( x, mask, function( val ) { +* return val * 2; +} ); +* // returns [ 2, 6 ] +* +* @example +* var mskrejectMap = require( '@stdlib/array/base/mskreject-map' ); +* +* var x = [ 1, 2, 3, 4 ]; +* var mask = [ 0, 1, 0, 1 ]; +* +* var out = [ 0, 0 ]; +* var arr = mskrejectMap.assign( x, mask, out, 1, 0, function( val ) { +* return val + this; +* }, 5 ); +* // returns [ 6, 8 ] +* +* 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/mskreject-map/lib/main.js b/lib/node_modules/@stdlib/array/base/mskreject-map/lib/main.js new file mode 100644 index 000000000000..bf61b6dae2ab --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/lib/main.js @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolveGetter = require( '@stdlib/array/base/resolve-getter' ); + + +// MAIN // + +/** +* Returns a new array by applying a mask to a provided input array and mapping the unmasked values according to the clbk function provided. +* +* @param {Collection} x - input array +* @param {Collection} mask - mask array +* @param {Function} clbk - function to apply +* @param {*} [thisArg] - function context +* @returns {Array} output array +* +* @example +* var x = [ 1, 2, 3, 4 ]; +* var mask = [ 0, 1, 0, 1 ]; +* +* var y = mskrejectMap( x, mask, function( val ) { +* return val * 2; +} ); +* // returns [ 2, 6 ] +*/ +function mskrejectMap( x, mask, clbk, thisArg ) { + var xget; + var mget; + var out; + var i; + + // Resolve accessors for retrieving array elements: + xget = resolveGetter( x ); + mget = resolveGetter( mask ); + + // Extract each desired element from the provided array... + out = []; + for ( i = 0; i < x.length; i++ ) { + if ( !mget( mask, i ) ) { + out.push( clbk.call( thisArg, xget( x, i ), i, x ) ); // use `Array#push` to ensure "fast" elements + } + } + return out; +} + + +// EXPORTS // + +module.exports = mskrejectMap; diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/package.json b/lib/node_modules/@stdlib/array/base/mskreject-map/package.json new file mode 100644 index 000000000000..42327a19f78b --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/array/base/mskreject-map", + "version": "0.0.0", + "description": "Apply a mask to a provided input array and map the unmasked values according to the clbk function provided.", + "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", + "mask", + "reject", + "filter" + ] +} diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.assign.js b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.assign.js new file mode 100644 index 000000000000..cdfcaa307578 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.assign.js @@ -0,0 +1,311 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var Int32Array = require( '@stdlib/array/int32' ); +var isSameComplex64Array = require( '@stdlib/assert/is-same-complex64array' ); +var zeros = require( '@stdlib/array/zeros' ); +var mskrejectMap = require( './../lib/assign.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof mskrejectMap, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function rejects array elements (generic)', function test( t ) { + var expected; + var actual; + var mask; + var out; + var x; + + x = [ 1, 2, 3, 4 ]; + + function clbk( val ) { + return val * 2; + } + + mask = [ 1, 0, 1, 0 ]; + out = zeros( 2, 'generic' ); + actual = mskrejectMap( x, mask, out, 1, 0, clbk ); + expected = [ 4, 8 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + mask = [ 1, 1, 1, 1 ]; + out = zeros( 0, 'generic' ); + actual = mskrejectMap( x, mask, out, 1, 0, clbk ); + expected = []; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + mask = [ 1, 1, 1, 0 ]; + out = zeros( 1, 'generic' ); + actual = mskrejectMap( x, mask, out, 1, 0, clbk ); + expected = [ 8 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + mask = [ 0, 0, 0, 0 ]; + out = zeros( 4, 'generic' ); + actual = mskrejectMap( x, mask, out, 1, 0, clbk ); + expected = [ 2, 4, 6, 8 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + mask = [ 1, 0, 1, 0 ]; + out = zeros( 4, 'generic' ); + actual = mskrejectMap( x, mask, out, -2, out.length-1, clbk ); + expected = [ 0, 8, 0, 4 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function rejects array elements (real typed array)', function test( t ) { + var expected; + var actual; + var mask; + var out; + var x; + var inc = 5; + + x = new Int32Array( [ 1, 2, 3, 4 ] ); + + function clbk( val ) { + return val + this; + } + + mask = [ 1, 0, 1, 0 ]; + out = zeros( 2, 'int32' ); + actual = mskrejectMap( x, mask, out, 1, 0, clbk, inc ); + expected = new Int32Array( [ 7, 9 ] ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + mask = [ 1, 1, 1, 1 ]; + out = zeros( 0, 'int32' ); + actual = mskrejectMap( x, mask, out, 1, 0, clbk, inc ); + expected = new Int32Array( [] ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + mask = [ 1, 1, 1, 0 ]; + out = zeros( 1, 'int32' ); + actual = mskrejectMap( x, mask, out, 1, 0, clbk, inc ); + expected = new Int32Array( [ 9 ] ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + mask = [ 0, 0, 0, 0 ]; + out = zeros( 4, 'int32' ); + actual = mskrejectMap( x, mask, out, 1, 0, clbk, inc ); + expected = new Int32Array( [ 6, 7, 8, 9 ] ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + mask = [ 1, 0, 1, 0 ]; + out = zeros( 4, 'int32' ); + actual = mskrejectMap( x, mask, out, -2, out.length-1, clbk, map ); + expected = new Int32Array( [ 0, 9, 0, 7 ] ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function rejects array elements (complex typed array)', function test( t ) { + var expected; + var actual; + var mask; + var out; + var x; + var scale = 5; + + x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + function clbk ( val ) { + return val * this; + } + + mask = [ 1, 0, 1, 0 ]; + out = zeros( 2, 'complex64' ); + actual = mskrejectMap( x, mask, out, 1, 0, clbk, scale ); + expected = new Complex64Array( [ scale * 3.0, scale * 4.0, scale * 7.0, scale * 8.0 ] ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameComplex64Array( actual, expected ), true, 'returns expected value' ); + + mask = [ 1, 1, 1, 1 ]; + out = zeros( 0, 'complex64' ); + actual = mskrejectMap( x, mask, out, 1, 0, clbk, scale ); + expected = new Complex64Array( [] ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameComplex64Array( actual, expected ), true, 'returns expected value' ); + + mask = [ 1, 1, 1, 0 ]; + out = zeros( 1, 'complex64' ); + actual = mskrejectMap( x, mask, out, 1, 0, clbk, scale ); + expected = new Complex64Array( [ scale * 7.0, scale * 8.0 ] ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameComplex64Array( actual, expected ), true, 'returns expected value' ); + + mask = [ 0, 0, 0, 0 ]; + out = zeros( 4, 'complex64' ); + actual = mskrejectMap( x, mask, out, 1, 0, clbk, scale ); + expected = new Complex64Array( [ scale * 1.0, scale * 2.0, scale * 3.0, scale * 4.0, scale * 5.0, scale * 6.0, scale * 7.0, scale * 8.0 ] ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameComplex64Array( actual, expected ), true, 'returns expected value' ); + + mask = [ 1, 0, 1, 0 ]; + out = zeros( 4, 'complex64' ); + actual = mskrejectMap( x, mask, out, -2, out.length-1, clbk, scale ); + expected = new Complex64Array( [ 0.0, 0.0, scale * 7.0, scale * 8.0, 0.0, 0.0, scale * 3.0, scale * 4.0 ] ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameComplex64Array( actual, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function rejects array elements (accessors)', function test( t ) { + var expected; + var actual; + var mask; + var out; + var x; + + x = toAccessorArray( [ 1, 2, 3, 4 ] ); + + function clbk( val ) { + return val * 2; + } + + mask = toAccessorArray( [ 1, 0, 1, 0 ] ); + out = toAccessorArray( zeros( 2, 'generic' ) ); + actual = mskrejectMap( x, mask, out, 1, 0, clbk ); + expected = [ 4, 8 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + isEqual( actual, expected ); + + mask = toAccessorArray( [ 1, 1, 1, 1 ] ); + out = toAccessorArray( zeros( 0, 'generic' ) ); + actual = mskrejectMap( x, mask, out, 1, 0, clbk ); + expected = []; + + t.strictEqual( actual, out, 'returns expected value' ); + isEqual( actual, expected ); + + mask = toAccessorArray( [ 1, 1, 1, 0 ] ); + out = toAccessorArray( zeros( 1, 'generic' ) ); + actual = mskrejectMap( x, mask, out, 1, 0, clbk ); + expected = [ 8 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + isEqual( actual, expected ); + + mask = toAccessorArray( [ 0, 0, 0, 0 ] ); + out = toAccessorArray( zeros( 4, 'generic' ) ); + actual = mskrejectMap( x, mask, out, 1, 0, clbk ); + expected = [ 2, 4, 6, 8 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + isEqual( actual, expected ); + + mask = toAccessorArray( [ 1, 0, 1, 0 ] ); + out = toAccessorArray( zeros( 4, 'generic' ) ); + actual = mskrejectMap( x, mask, out, -2, out.length-1, clbk ); + expected = [ 0, 8, 0, 4 ]; + + 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 masks all input array values', function test( t ) { + var expected; + var actual; + var mask; + var out; + var x; + + mask = [ 1, 1, 1, 1 ]; + + function clbk( val ) { + return val * 2; + } + + x = [ 1, 2, 3, 4 ]; + out = [ 0, 0, 0, 0 ]; + expected = [ 0, 0, 0, 0 ]; + actual = mskrejectMap( x, mask, 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 = mskrejectMap( x, mask, out, 1, 0, clbk ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Int32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + out = [ 0, 0, 0, 0 ]; + expected = [ 0, 0, 0, 0 ]; + actual = mskrejectMap( x, mask, out, 1, 0, clbk ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + out = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + expected = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + actual = mskrejectMap( x, mask, out, 1, 0, clbk ); + t.strictEqual( isSameComplex64Array( actual, expected ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.js b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.js new file mode 100644 index 000000000000..e746a0254a5b --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.js @@ -0,0 +1,41 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var hasMethod = require( '@stdlib/assert/is-method' ); +var mskrejectMap = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof mskrejectMap, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( hasOwnProp( mskrejectMap, 'assign' ), true, 'returns expected value' ); + t.strictEqual( hasMethod( mskrejectMap, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js new file mode 100644 index 000000000000..be046b798fcb --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js @@ -0,0 +1,109 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var isSameComplex64 = require( '@stdlib/assert/is-same-complex64' ); +var isArray = require( '@stdlib/assert/is-array' ); +var mskrejectMap = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof mskrejectMap, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function rejects array elements', function test( t ) { + var expected; + var actual; + var mask; + var x; + + x = [ 1, 2, 3, 4 ]; + + function clbk( val ) { + return val * 2; + } + + mask = [ 0, 1, 0, 1 ]; + actual = mskrejectMap( x, mask, clbk ); + expected = [ 2, 6 ]; + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.notEqual( actual, x, 'returns new array' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + mask = [ 1, 1, 1, 1 ]; + actual = mskrejectMap( x, mask, clbk ); + expected = []; + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.notEqual( actual, x, 'returns new array' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + mask = [ 0, 0, 0, 1 ]; + actual = mskrejectMap( x, mask, clbk ); + expected = [ 2, 4, 6 ]; + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.notEqual( actual, x, 'returns new array' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + mask = [ 1, 1, 1, 1 ]; + actual = mskrejectMap( x, mask, clbk ); + expected = []; + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.notEqual( actual, x, 'returns new array' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function rejects array elements (accessors)', function test( t ) { + var expected; + var actual; + var mask; + var x; + var i; + var scale = 5; + + function clbk( val ) { + return val * this; + } + + x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + mask = [ 0, 1, 0, 1 ]; + actual = mskrejectMap( x, mask, clbk, scale ); + expected = [ scale * x.get( 0 ), scale * x.get( 2 ) ]; + + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.notEqual( actual, x, 'returns different reference' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( isSameComplex64( actual[ i ], expected[ i ] ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function returns an empty array if provided empty arrays', function test( t ) { + t.deepEqual( mskrejectMap( [], [], clbk, scale ), [], 'returns expected value' ); + t.end(); +}); From e842f264a2f75b55bdd63d6e5a7aa244412accaa Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Mon, 4 Mar 2024 10:08:36 +0530 Subject: [PATCH 02/14] fixed linting issues --- .../@stdlib/array/base/mskreject-map/README.md | 12 ++++++------ .../@stdlib/array/base/mskreject-map/docs/repl.txt | 14 ++++++++------ .../array/base/mskreject-map/examples/index.js | 4 ++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/README.md b/lib/node_modules/@stdlib/array/base/mskreject-map/README.md index f0be87dbda19..ae7b214ec6ec 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/README.md +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/README.md @@ -37,9 +37,9 @@ Returns a new array by applying a mask and mapping the unmasked values according ```javascript var x = [ 1, 2, 3, 4 ]; -function clbk( val ) { - return val * 2; -}; +function clbk( val ) { + return val * 2; +} var y = mskrejectMap( x, [ 0, 1, 0, 1 ], clbk ); // returns [ 2, 6 ] @@ -66,7 +66,7 @@ var x = [ 1, 2, 3, 4 ]; var mask = [ 0, 1, 0, 1 ]; var context = { - `increase`: 3 + increase: 3 }; function clbk( value ) { @@ -134,7 +134,7 @@ The function supports the following parameters: ```javascript var zeroTo = require( '@stdlib/array/base/zero-to' ); var bernoulli = require( '@stdlib/random/array/bernoulli' ); -var mskrejectMap = require( '@stdlib/array/base/mskreject' ); +var mskrejectMap = require( '@stdlib/array/base/mskreject-map' ); // Generate a linearly spaced array: var x = zeroTo( 20 ); @@ -147,7 +147,7 @@ var mask = bernoulli( x.length, 0.5, { console.log( mask ); // Filter an array using the mask: -var y = mskrejectMap( x, mask, function( val ){ +var y = mskrejectMap( x, mask, function clbk( val ) { return val * 2; } ); console.log( y ); diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/docs/repl.txt b/lib/node_modules/@stdlib/array/base/mskreject-map/docs/repl.txt index 8b21af8550d8..ceb46ef0930f 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/docs/repl.txt @@ -30,9 +30,10 @@ Examples -------- > var x = [ 1, 2, 3, 4 ]; - > var y = {{alias}}( x, [ 0, 1, 0, 1 ], function clbk( val ) { - return val * 2; - } ) + > function clbk( val ) { + return val * 2; + } + > var y = {{alias}}( x, [ 0, 1, 0, 1 ], clbk ) [ 2, 6 ] @@ -79,9 +80,10 @@ > var m = [ 0, 1, 0, 1 ]; > var out = [ 0, 0, 0, 0 ]; > var scale = 5; - > var arr = {{alias}}.assign( x, m, out, 2, 0, function clbk( val ) { - return val * this; - }, scale ) + > function clbk( val ) { + return val * this; + } + > var arr = {{alias}}.assign( x, m, out, 2, 0, clbk, scale ) [ 5, 0, 15, 0 ] > var bool = ( arr === out ) true diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/examples/index.js b/lib/node_modules/@stdlib/array/base/mskreject-map/examples/index.js index b412fe4070bb..46a6cbd9a3ec 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/examples/index.js +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/examples/index.js @@ -36,7 +36,7 @@ console.log( mask ); var inc = 5; // Filter an array using the mask: -var y = mskrejectMap( x, mask, function( val ) { - return val + this; +var y = mskrejectMap( x, mask, function clbk( val ) { + return val * this; }, inc ); console.log( y ); From 6a53f68d5b79b9bdbe365e04e58e672027802c25 Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Mon, 4 Mar 2024 10:36:58 +0530 Subject: [PATCH 03/14] fix README examples --- .../@stdlib/array/base/mskreject-map/README.md | 10 ++++++---- .../@stdlib/array/base/mskreject-map/docs/repl.txt | 8 ++------ .../@stdlib/array/base/mskreject-map/examples/index.js | 8 +++++--- .../array/base/mskreject-map/test/test.assign.js | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/README.md b/lib/node_modules/@stdlib/array/base/mskreject-map/README.md index ae7b214ec6ec..0aceb205576e 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/README.md +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/README.md @@ -66,7 +66,7 @@ var x = [ 1, 2, 3, 4 ]; var mask = [ 0, 1, 0, 1 ]; var context = { - increase: 3 + `increase`: 3 }; function clbk( value ) { @@ -146,10 +146,12 @@ var mask = bernoulli( x.length, 0.5, { }); console.log( mask ); -// Filter an array using the mask: -var y = mskrejectMap( x, mask, function clbk( val ) { +function clbk( val ) { return val * 2; -} ); +} + +// Filter an array using the mask: +var y = mskrejectMap( x, mask, clbk ); console.log( y ); ``` diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/docs/repl.txt b/lib/node_modules/@stdlib/array/base/mskreject-map/docs/repl.txt index ceb46ef0930f..f16edbefcf61 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/docs/repl.txt @@ -30,9 +30,7 @@ Examples -------- > var x = [ 1, 2, 3, 4 ]; - > function clbk( val ) { - return val * 2; - } + > function clbk( val ) { return val * 2; } > var y = {{alias}}( x, [ 0, 1, 0, 1 ], clbk ) [ 2, 6 ] @@ -80,9 +78,7 @@ > var m = [ 0, 1, 0, 1 ]; > var out = [ 0, 0, 0, 0 ]; > var scale = 5; - > function clbk( val ) { - return val * this; - } + > function clbk( val ) { return val * this; } > var arr = {{alias}}.assign( x, m, out, 2, 0, clbk, scale ) [ 5, 0, 15, 0 ] > var bool = ( arr === out ) diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/examples/index.js b/lib/node_modules/@stdlib/array/base/mskreject-map/examples/index.js index 46a6cbd9a3ec..77de65c2dcd1 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/examples/index.js +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/examples/index.js @@ -35,8 +35,10 @@ console.log( mask ); // Callback function's execution context var inc = 5; -// Filter an array using the mask: -var y = mskrejectMap( x, mask, function clbk( val ) { +function clbk( val ) { return val * this; -}, inc ); +} + +// Filter an array using the mask: +var y = mskrejectMap( x, mask, clbk, inc ); console.log( y ); diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.assign.js b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.assign.js index cdfcaa307578..d6081c54a528 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.assign.js +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.assign.js @@ -141,7 +141,7 @@ tape( 'the function rejects array elements (real typed array)', function test( t mask = [ 1, 0, 1, 0 ]; out = zeros( 4, 'int32' ); - actual = mskrejectMap( x, mask, out, -2, out.length-1, clbk, map ); + actual = mskrejectMap( x, mask, out, -2, out.length-1, clbk, inc ); expected = new Int32Array( [ 0, 9, 0, 7 ] ); t.strictEqual( actual, out, 'returns expected value' ); From 421e62bf1b1d0429cdd33364e9aa6a572a3da4e7 Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Mon, 4 Mar 2024 10:54:58 +0530 Subject: [PATCH 04/14] fixed examples --- .../@stdlib/array/base/mskreject-map/README.md | 8 +++----- .../@stdlib/array/base/mskreject-map/examples/index.js | 7 ++----- .../@stdlib/array/base/mskreject-map/test/test.main.js | 3 +++ 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/README.md b/lib/node_modules/@stdlib/array/base/mskreject-map/README.md index 0aceb205576e..d9996eb7475c 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/README.md +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/README.md @@ -65,15 +65,13 @@ var x = [ 1, 2, 3, 4 ]; var mask = [ 0, 1, 0, 1 ]; -var context = { - `increase`: 3 -}; +var increase = 3; function clbk( value ) { - return value + this.increase; + return value + this; } -var out = mskrejectMap( x, mask, clbk, context ); +var out = mskrejectMap( x, mask, clbk, increase ); // returns [ 4, 6 ] ``` diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/examples/index.js b/lib/node_modules/@stdlib/array/base/mskreject-map/examples/index.js index 77de65c2dcd1..8346e538a215 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/examples/index.js +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/examples/index.js @@ -32,13 +32,10 @@ var mask = bernoulli( x.length, 0.5, { }); console.log( mask ); -// Callback function's execution context -var inc = 5; - function clbk( val ) { - return val * this; + return val * 2; } // Filter an array using the mask: -var y = mskrejectMap( x, mask, clbk, inc ); +var y = mskrejectMap( x, mask, clbk ); console.log( y ); diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js index be046b798fcb..0cc41291ecf5 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js @@ -104,6 +104,9 @@ tape( 'the function rejects array elements (accessors)', function test( t ) { }); tape( 'the function returns an empty array if provided empty arrays', function test( t ) { + function clbk( val ) { + return val * 2; + } t.deepEqual( mskrejectMap( [], [], clbk, scale ), [], 'returns expected value' ); t.end(); }); From 49e0bd440ec018513f3497cbc166f250b8566c34 Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Mon, 4 Mar 2024 11:13:36 +0530 Subject: [PATCH 05/14] fixed tests --- .../@stdlib/array/base/mskreject-map/test/test.assign.js | 4 ++-- .../@stdlib/array/base/mskreject-map/test/test.main.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.assign.js b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.assign.js index d6081c54a528..64120c149e98 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.assign.js +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.assign.js @@ -153,14 +153,14 @@ tape( 'the function rejects array elements (real typed array)', function test( t tape( 'the function rejects array elements (complex typed array)', function test( t ) { var expected; var actual; + var scale = 5; var mask; var out; var x; - var scale = 5; x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - function clbk ( val ) { + function clbk( val ) { return val * this; } diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js index 0cc41291ecf5..29eb0b494bfa 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js @@ -81,10 +81,10 @@ tape( 'the function rejects array elements', function test( t ) { tape( 'the function rejects array elements (accessors)', function test( t ) { var expected; var actual; + var scale = 5; var mask; var x; var i; - var scale = 5; function clbk( val ) { return val * this; @@ -107,6 +107,6 @@ tape( 'the function returns an empty array if provided empty arrays', function t function clbk( val ) { return val * 2; } - t.deepEqual( mskrejectMap( [], [], clbk, scale ), [], 'returns expected value' ); + t.deepEqual( mskrejectMap( [], [], clbk ), [], 'returns expected value' ); t.end(); }); From 13fbf701f99bd65a661f6b8cfc0933bb9e730192 Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Mon, 4 Mar 2024 11:49:22 +0530 Subject: [PATCH 06/14] updated tests --- .../array/base/mskreject-map/test/test.assign.js | 2 +- .../array/base/mskreject-map/test/test.main.js | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.assign.js b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.assign.js index 64120c149e98..b94db8e18729 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.assign.js +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.assign.js @@ -98,8 +98,8 @@ tape( 'the function rejects array elements (real typed array)', function test( t var actual; var mask; var out; - var x; var inc = 5; + var x; x = new Int32Array( [ 1, 2, 3, 4 ] ); diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js index 29eb0b494bfa..3d3434e98f22 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js @@ -68,13 +68,6 @@ tape( 'the function rejects array elements', function test( t ) { t.notEqual( actual, x, 'returns new array' ); t.deepEqual( actual, expected, 'returns expected value' ); - mask = [ 1, 1, 1, 1 ]; - actual = mskrejectMap( x, mask, clbk ); - expected = []; - t.strictEqual( isArray( actual ), true, 'returns expected value' ); - t.notEqual( actual, x, 'returns new array' ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); }); @@ -84,6 +77,7 @@ tape( 'the function rejects array elements (accessors)', function test( t ) { var scale = 5; var mask; var x; + var y; var i; function clbk( val ) { @@ -91,9 +85,11 @@ tape( 'the function rejects array elements (accessors)', function test( t ) { } x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + y = new Complex64Array( [ scale * 1.0, scale * 2.0, scale * 3.0, scale * 4.0, scale * 5.0, scale * 6.0, scale * 7.0, scale * 8.0 ] ); + mask = [ 0, 1, 0, 1 ]; actual = mskrejectMap( x, mask, clbk, scale ); - expected = [ scale * x.get( 0 ), scale * x.get( 2 ) ]; + expected = [ y.get( 0 ), y.get( 2 ) ]; t.strictEqual( isArray( actual ), true, 'returns expected value' ); t.notEqual( actual, x, 'returns different reference' ); From 7d3175202ee2897717393394bc628e4f2e1b237a Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Mon, 4 Mar 2024 12:04:10 +0530 Subject: [PATCH 07/14] added tests --- .../base/mskreject-map/test/test.main.js | 54 ++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js index 3d3434e98f22..8245d09484dd 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js @@ -21,8 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var Complex64Array = require( '@stdlib/array/complex64' ); -var isSameComplex64 = require( '@stdlib/assert/is-same-complex64' ); var isArray = require( '@stdlib/assert/is-array' ); var mskrejectMap = require( './../lib' ); @@ -71,32 +69,40 @@ tape( 'the function rejects array elements', function test( t ) { t.end(); }); -tape( 'the function rejects array elements (accessors)', function test( t ) { - var expected; - var actual; - var scale = 5; - var mask; - var x; - var y; - var i; +tape( 'the function returns an empty array if provided empty arrays', function test( t ) { + function clbk( val ) { + return val * 2; + } + t.deepEqual( mskrejectMap( [], [], clbk ), [], 'returns expected value' ); + t.end(); +}); - function clbk( val ) { - return val * this; - } +tape( 'the function works correctly with different callback functions', function test( t ) { + var expected; + var actual; + var mask; + var x; - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - y = new Complex64Array( [ scale * 1.0, scale * 2.0, scale * 3.0, scale * 4.0, scale * 5.0, scale * 6.0, scale * 7.0, scale * 8.0 ] ); + x = [ 1, 2, 3, 4 ]; - mask = [ 0, 1, 0, 1 ]; - actual = mskrejectMap( x, mask, clbk, scale ); - expected = [ y.get( 0 ), y.get( 2 ) ]; + function clbk1( val ) { + return val * 2; + } - t.strictEqual( isArray( actual ), true, 'returns expected value' ); - t.notEqual( actual, x, 'returns different reference' ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( isSameComplex64( actual[ i ], expected[ i ] ), true, 'returns expected value' ); - } - t.end(); + function clbk2( val ) { + return val * val; + } + + mask = [ 0, 1, 0, 1 ]; + actual = mskrejectMap( x, mask, clbk1 ); + expected = [ 2, 6 ]; + t.deepEqual( actual, expected, 'returns expected value with callback 1' ); + + actual = mskrejectMap( x, mask, clbk2 ); + expected = [ 1, 9 ]; + t.deepEqual( actual, expected, 'returns expected value with callback 2' ); + + t.end(); }); tape( 'the function returns an empty array if provided empty arrays', function test( t ) { From 54d126e842abb1b7b21b555c26a57d1f4c90e153 Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Sun, 10 Mar 2024 11:45:03 +0530 Subject: [PATCH 08/14] fixed Unexpected this --- .../@stdlib/array/base/mskreject-map/test/test.assign.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.assign.js b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.assign.js index b94db8e18729..3ef154a7ede6 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.assign.js +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.assign.js @@ -104,7 +104,7 @@ tape( 'the function rejects array elements (real typed array)', function test( t x = new Int32Array( [ 1, 2, 3, 4 ] ); function clbk( val ) { - return val + this; + return val + this; // eslint-disable-line no-invalid-this } mask = [ 1, 0, 1, 0 ]; @@ -161,7 +161,7 @@ tape( 'the function rejects array elements (complex typed array)', function test x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); function clbk( val ) { - return val * this; + return val * this; // eslint-disable-line no-invalid-this } mask = [ 1, 0, 1, 0 ]; From 469ef5565118ff1b1c42f752c93ae83bbe38e6d1 Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Sun, 10 Mar 2024 11:57:16 +0530 Subject: [PATCH 09/14] fixed indentation --- .../base/mskreject-map/test/test.main.js | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js index 8245d09484dd..8d244a0ba2f1 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js @@ -70,39 +70,39 @@ tape( 'the function rejects array elements', function test( t ) { }); tape( 'the function returns an empty array if provided empty arrays', function test( t ) { - function clbk( val ) { - return val * 2; - } - t.deepEqual( mskrejectMap( [], [], clbk ), [], 'returns expected value' ); - t.end(); + function clbk( val ) { + return val * 2; + } + t.deepEqual( mskrejectMap( [], [], clbk ), [], 'returns expected value' ); + t.end(); }); tape( 'the function works correctly with different callback functions', function test( t ) { - var expected; - var actual; - var mask; - var x; + var expected; + var actual; + var mask; + var x; - x = [ 1, 2, 3, 4 ]; + x = [ 1, 2, 3, 4 ]; - function clbk1( val ) { - return val * 2; - } + function clbk1( val ) { + return val * 2; + } - function clbk2( val ) { - return val * val; - } + function clbk2( val ) { + return val * val; + } - mask = [ 0, 1, 0, 1 ]; - actual = mskrejectMap( x, mask, clbk1 ); - expected = [ 2, 6 ]; - t.deepEqual( actual, expected, 'returns expected value with callback 1' ); + mask = [ 0, 1, 0, 1 ]; + actual = mskrejectMap( x, mask, clbk1 ); + expected = [ 2, 6 ]; + t.deepEqual( actual, expected, 'returns expected value with callback 1' ); - actual = mskrejectMap( x, mask, clbk2 ); - expected = [ 1, 9 ]; - t.deepEqual( actual, expected, 'returns expected value with callback 2' ); + actual = mskrejectMap( x, mask, clbk2 ); + expected = [ 1, 9 ]; + t.deepEqual( actual, expected, 'returns expected value with callback 2' ); - t.end(); + t.end(); }); tape( 'the function returns an empty array if provided empty arrays', function test( t ) { From 1bf4dca61bcd1e2c7edd7c9f3ee916611eaf2eb5 Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Sun, 10 Mar 2024 12:10:27 +0530 Subject: [PATCH 10/14] fixed benchmarks --- .../base/mskreject-map/benchmark/benchmark.assign.length.js | 2 +- .../@stdlib/array/base/mskreject-map/benchmark/benchmark.js | 2 +- .../array/base/mskreject-map/benchmark/benchmark.length.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.assign.length.js b/lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.assign.length.js index 3afda17a7ec4..70d168ed480d 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.assign.length.js +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.assign.length.js @@ -62,7 +62,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = mskrejectMap.assign( x, mask, out, 1, 0, function( val ) { + v = mskrejectMap.assign( x, mask, out, 1, 0, function clbk( val ) { return val * 2; } ); if ( typeof v !== 'object' ) { diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.js index e502d654b9ae..3cf2e754d93b 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.js @@ -41,7 +41,7 @@ bench( pkg+'::copy:len=100', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = mskrejectMap( x, y, function( val ) { + v = mskrejectMap( x, y, function clbk( val ) { return val * 2; } ); if ( typeof v !== 'object' ) { diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.length.js b/lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.length.js index 2fab9c668e21..b7ae1eb1e116 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.length.js +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.length.js @@ -55,7 +55,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = mskrejectMap( x, y, function( val ) { + v = mskrejectMap( x, y, function clbk( val ) { return val * 2; } ); if ( typeof v !== 'object' ) { From e6dec929613b8b7cb060a502c7a2cf563834e75b Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Sun, 10 Mar 2024 12:15:40 +0530 Subject: [PATCH 11/14] fixed benchmark.js --- .../@stdlib/array/base/mskreject-map/benchmark/benchmark.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.js index 3cf2e754d93b..fe825af1b4db 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/benchmark/benchmark.js @@ -42,7 +42,7 @@ bench( pkg+'::copy:len=100', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { v = mskrejectMap( x, y, function clbk( val ) { - return val * 2; + return val * 2; } ); if ( typeof v !== 'object' ) { b.fail( 'should return an array' ); From 65fd960a6aa47fd8782139c11bf4942790625a1c Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sat, 13 Apr 2024 20:32:06 -0400 Subject: [PATCH 12/14] chore: update descriptions and minor clean-up --- .../@stdlib/array/base/mskreject-map/README.md | 8 ++++---- .../@stdlib/array/base/mskreject-map/docs/repl.txt | 12 +++++------- .../array/base/mskreject-map/docs/types/index.d.ts | 2 +- .../@stdlib/array/base/mskreject-map/lib/assign.js | 8 ++++---- .../@stdlib/array/base/mskreject-map/lib/index.js | 4 ++-- .../@stdlib/array/base/mskreject-map/lib/main.js | 4 ++-- .../@stdlib/array/base/mskreject-map/package.json | 2 +- .../array/base/mskreject-map/test/test.main.js | 6 +++--- 8 files changed, 22 insertions(+), 24 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/README.md b/lib/node_modules/@stdlib/array/base/mskreject-map/README.md index d9996eb7475c..591eb893568d 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/README.md +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/README.md @@ -18,9 +18,9 @@ limitations under the License. --> -# mskreject-map +# mskrejectMap -> Apply a mask to a provided input array and map the unmasked values according to the clbk function provided. +> Apply a mask to a provided input array and map the unmasked values according to a callback function.
@@ -32,7 +32,7 @@ var mskrejectMap = require( '@stdlib/array/base/mskreject-map' ); #### mskrejectMap( x, mask, clbk\[, thisArg ] ) -Returns a new array by applying a mask and mapping the unmasked values according to the clbk function to the provided input array. +Returns a new array by applying a mask and mapping the unmasked values according to a callback function. ```javascript var x = [ 1, 2, 3, 4 ]; @@ -79,7 +79,7 @@ The function **always** returns a new "generic" array. #### mskreject.assign( x, mask, out, stride, offset, clbk\[, thisArg ] ) -Applies a mask to a provided input array, maps the unmasked values according to the clbk function and assigns to elements in a provided output array. +Applies a mask to a provided input array, maps the unmasked values according to a callback function, and assigns to elements in a provided output array. ```javascript var x = [ 1, 2, 3, 4 ]; diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/docs/repl.txt b/lib/node_modules/@stdlib/array/base/mskreject-map/docs/repl.txt index f16edbefcf61..a55f0d5d9240 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/docs/repl.txt @@ -1,8 +1,7 @@ {{alias}}( x, mask, clbk[, thisArg] ) Returns a new array by applying a mask to a provided input array - and mapping the unmasked values according to the clbk function to - the provided input array. + and mapping the unmasked values according to a callback function. If a mask array element is falsy, the corresponding element in `x` is mapped in the output array; otherwise, the corresponding element in `x` is @@ -36,12 +35,12 @@ {{alias}}.assign( x, mask, out, stride, offset, clbk[, thisArg] ) - Applies a mask to a provided input array, maps the unmasked values - according to the clbk function and and assigns the unmasked values + Applies a mask to a provided input array, maps the unmasked values + according to a callback function, and assigns the unmasked values to elements in a provided output array. - If a mask array element is falsy, the corresponding element in `x` is - mapped and included in the output array; otherwise, the corresponding + If a mask array element is falsy, the corresponding element in `x` is + mapped and included in the output array; otherwise, the corresponding element in `x` is "masked" and thus excluded from the output array. Parameters @@ -86,4 +85,3 @@ See Also -------- - diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/mskreject-map/docs/types/index.d.ts index 7174185adee8..fcf6b7deb969 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/docs/types/index.d.ts @@ -33,7 +33,7 @@ import { Collection, AccessorArrayLike } from '@stdlib/types/array'; type ClbkType = ( this: U, value: T, index: number, arr: Collection | AccessorArrayLike ) => any; /** -* Returns a new array by applying a mask and mapping the unmasked values according to the clbk function to the provided input array. +* Returns a new array by applying a mask and mapping the unmasked values according to a callback function. * * @param x - input array * @param mask - mask array diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/lib/assign.js b/lib/node_modules/@stdlib/array/base/mskreject-map/lib/assign.js index bc04e791bd1f..f4d8e12fac5a 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/lib/assign.js +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/lib/assign.js @@ -28,7 +28,7 @@ var reinterpret = require( '@stdlib/strided/base/reinterpret-complex' ); // FUNCTIONS // /** -* Applies a mask to an indexed array, maps the unmasked values according to the clbk function and assigns to elements in an indexed output array. +* Applies a mask to an indexed array, maps the unmasked values according to a callback function, and assigns to elements in an indexed output array. * * @private * @param {Collection} x - input array @@ -66,7 +66,7 @@ function indexed( x, mask, out, stride, offset, clbk, thisArg ) { } /** -* Applies a mask to an accessor array, maps the unmasked values according to the clbk function and assigns to elements in an accessor output array. +* Applies a mask to an accessor array, maps the unmasked values according to a callback function, and assigns to elements in an accessor output array. * * @private * @param {Object} x - input array object @@ -125,7 +125,7 @@ function accessors( x, mask, out, stride, offset, clbk, thisArg ) { } /** -* Applies a mask to a complex array, maps the unmasked values according to the clbk function and assigns to elements in a complex output array. +* Applies a mask to a complex array, maps the unmasked values according to a callback function, and assigns to elements in a complex output array. * * @private * @param {Collection} x - real-valued floating-point input array view @@ -179,7 +179,7 @@ function complex( x, mask, out, stride, offset, clbk, thisArg ) { // MAIN // /** -* Applies a mask to a provided input array, maps the unmasked values according to the clbk function and assigns to elements in a provided output array. +* Applies a mask to a provided input array, maps the unmasked values according to a callback function, and assigns to elements in a provided output array. * * @param {Collection} x - input array * @param {Collection} mask - mask array diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/lib/index.js b/lib/node_modules/@stdlib/array/base/mskreject-map/lib/index.js index 825e3ad37fc6..6d7da2187a1f 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/lib/index.js +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Apply a mask to a provided input array and map the unmasked values according to the clbk function provided. +* Apply a mask to a provided input array and map the unmasked values according to a callback function. * * @module @stdlib/array/base/mskreject-map * @@ -31,7 +31,7 @@ * * var y = mskrejectMap( x, mask, function( val ) { * return val * 2; -} ); +* } ); * // returns [ 2, 6 ] * * @example diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/lib/main.js b/lib/node_modules/@stdlib/array/base/mskreject-map/lib/main.js index bf61b6dae2ab..fc6bacc2a9f2 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/lib/main.js @@ -26,7 +26,7 @@ var resolveGetter = require( '@stdlib/array/base/resolve-getter' ); // MAIN // /** -* Returns a new array by applying a mask to a provided input array and mapping the unmasked values according to the clbk function provided. +* Returns a new array by applying a mask to a provided input array and mapping the unmasked values according to a callback function. * * @param {Collection} x - input array * @param {Collection} mask - mask array @@ -40,7 +40,7 @@ var resolveGetter = require( '@stdlib/array/base/resolve-getter' ); * * var y = mskrejectMap( x, mask, function( val ) { * return val * 2; -} ); +* } ); * // returns [ 2, 6 ] */ function mskrejectMap( x, mask, clbk, thisArg ) { diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/package.json b/lib/node_modules/@stdlib/array/base/mskreject-map/package.json index 42327a19f78b..1a1f7650b051 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/package.json +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/array/base/mskreject-map", "version": "0.0.0", - "description": "Apply a mask to a provided input array and map the unmasked values according to the clbk function provided.", + "description": "Apply a mask to a provided input array and map the unmasked values according to a callback function.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js index 8d244a0ba2f1..6e0289a66ae7 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/test/test.main.js @@ -77,7 +77,7 @@ tape( 'the function returns an empty array if provided empty arrays', function t t.end(); }); -tape( 'the function works correctly with different callback functions', function test( t ) { +tape( 'the function applies a mask to a provided input array and maps the unmasked values according to different callback functions', function test( t ) { var expected; var actual; var mask; @@ -96,11 +96,11 @@ tape( 'the function works correctly with different callback functions', function mask = [ 0, 1, 0, 1 ]; actual = mskrejectMap( x, mask, clbk1 ); expected = [ 2, 6 ]; - t.deepEqual( actual, expected, 'returns expected value with callback 1' ); + t.deepEqual( actual, expected, 'returns expected value' ); actual = mskrejectMap( x, mask, clbk2 ); expected = [ 1, 9 ]; - t.deepEqual( actual, expected, 'returns expected value with callback 2' ); + t.deepEqual( actual, expected, 'returns expected value' ); t.end(); }); From 0fca740fca655def4bcb21517c8700e81d12f8d8 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sat, 13 Apr 2024 21:27:30 -0400 Subject: [PATCH 13/14] fix: update TypeScript definitions --- .../base/mskreject-map/docs/types/index.d.ts | 103 +++++++++++++++++- 1 file changed, 99 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/mskreject-map/docs/types/index.d.ts index fcf6b7deb969..b5d77563b9b3 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/docs/types/index.d.ts @@ -23,14 +23,94 @@ import { Collection, AccessorArrayLike } from '@stdlib/types/array'; /** -* Returns a transformed element of input array. +* Returns a transformed element. +* +* @param value - current array element +* @returns transformed array element +*/ +type Unary = ( this: U, value: T ) => V; + +/** +* Returns a transformed element. +* +* @param value - current array element +* @param index - current array element index +* @returns transformed array element +*/ +type Binary = ( this: U, value: T, index: number ) => V; + +/** +* Returns a transformed element. * * @param value - current array element * @param index - current array element index * @param arr - input array -* @returns The transformed array element +* @returns transformed array element */ -type ClbkType = ( this: U, value: T, index: number, arr: Collection | AccessorArrayLike ) => any; +type Ternary = ( this: U, value: T, index: number, arr: Collection | AccessorArrayLike ) => V; + +/** +* Returns a transformed element. +* +* @param value - current array element +* @param index - current array element index +* @param arr - input array +* @returns transformed array element +*/ +type Callback = Unary | Binary | Ternary; + +/** +* Interface describing `mskrejectMap`. +*/ +interface MskrejectMap { + /** + * Returns a new array by applying a mask and mapping the unmasked values according to a callback function. + * + * @param x - input array + * @param mask - mask array + * @param clbk - mapping function + * @param thisArg - function context + * @returns output array + * + * @example + * var x = [ 1, 2, 3, 4 ]; + * + * var y = mskrejectMap( x, [ 0, 1, 0, 1 ], function( val ) { + * return val * 2; + * } ); + * // returns [ 2, 6 ] + */ + ( x: Collection | AccessorArrayLike, mask: Collection, clbk: Callback, thisArg?: U ): Array; + + /** + * Applies a mask to a provided input array, maps the unmasked values according to a callback function, and assigns to elements in a provided output array. + * + * @param x - input array + * @param mask - mask array + * @param out - output array + * @param stride - output array stride + * @param offset - output array offset + * @param clbk - mapping function + * @param thisArg - function context + * @returns output array + * + * @example + * var x = [ 1, 2, 3, 4 ]; + * var mask = [ 1, 0, 1, 0 ]; + * var out = [ 0, 0, 0, 0 ]; + * + * function clbk( val ) { + * return val * 2; + * } + * + * var arr = mskrejectMap.assign( x, mask, out, -2, out.length-1, clbk ); + * // returns [ 0, 8, 0, 4 ] + * + * var bool = ( arr === out ); + * // returns true + */ + assign( x: Collection | AccessorArrayLike, mask: Collection, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: U ): Collection; +} /** * Returns a new array by applying a mask and mapping the unmasked values according to a callback function. @@ -48,8 +128,23 @@ type ClbkType = ( this: U, value: T, index: number, arr: Collection | A * return val * 2; * } ); * // returns [ 2, 6 ] +* +* @example +* var x = [ 1, 2, 3, 4 ]; +* var mask = [ 1, 0, 1, 0 ]; +* var out = [ 0, 0, 0, 0 ]; +* +* function clbk( val ) { +* return val * 2; +* } +* +* var arr = mskrejectMap.assign( x, mask, out, -2, out.length-1, clbk ); +* // returns [ 0, 8, 0, 4 ] +* +* var bool = ( arr === out ); +* // returns true */ -declare function mskrejectMap( x: Collection | AccessorArrayLike, mask: Collection, clbk: ClbkType, thisArg?: U ): Array; +declare var mskrejectMap: MskrejectMap; // EXPORTS // From 1756b731e469cc74068e61f8cad711820dc977f4 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Mon, 22 Apr 2024 21:31:52 -0400 Subject: [PATCH 14/14] chore: fix heading --- lib/node_modules/@stdlib/array/base/mskreject-map/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/base/mskreject-map/README.md b/lib/node_modules/@stdlib/array/base/mskreject-map/README.md index 591eb893568d..ececbf936e90 100644 --- a/lib/node_modules/@stdlib/array/base/mskreject-map/README.md +++ b/lib/node_modules/@stdlib/array/base/mskreject-map/README.md @@ -77,7 +77,7 @@ var out = mskrejectMap( x, mask, clbk, increase ); The function **always** returns a new "generic" array. -#### mskreject.assign( x, mask, out, stride, offset, clbk\[, thisArg ] ) +#### mskrejectMap.assign( x, mask, out, stride, offset, clbk\[, thisArg ] ) Applies a mask to a provided input array, maps the unmasked values according to a callback function, and assigns to elements in a provided output array.