diff --git a/lib/index.js b/lib/index.js index d4afb79d..d4d4d3df 100644 --- a/lib/index.js +++ b/lib/index.js @@ -355,6 +355,15 @@ setReadOnly( ns, 'mostlySafeCasts', require( './../mostly-safe-casts' ) ); */ setReadOnly( ns, 'mskfilter', require( './../mskfilter' ) ); +/** +* @name mskreject +* @memberof ns +* @readonly +* @constructor +* @see {@link module:@stdlib/array/mskreject} +*/ +setReadOnly( ns, 'mskreject', require( './../mskreject' ) ); + /** * @name nans * @memberof ns diff --git a/mskfilter/README.md b/mskfilter/README.md index 38d44af3..48c7672b 100644 --- a/mskfilter/README.md +++ b/mskfilter/README.md @@ -27,7 +27,7 @@ limitations under the License. ## Usage ```javascript -var mskfilter = require( '@stdlib/array/base/mskfilter' ); +var mskfilter = require( '@stdlib/array/mskfilter' ); ``` #### mskfilter( x, mask ) @@ -46,33 +46,6 @@ The function supports the following parameters: - **x**: input array. - **mask**: mask array. -The function **always** returns a new "generic" array. - -#### mskfilter.assign( x, mask, out, stride, offset ) - -Applies a mask to a provided input array and assigns unmasked values to elements in a provided output array. - -```javascript -var x = [ 1, 2, 3, 4 ]; -var mask = [ 0, 1, 0, 1 ]; - -var out = [ 0, 0, 0, 0 ]; - -var arr = mskfilter.assign( x, mask, out, -2, out.length-1 ); -// returns [ 0, 4, 0, 2 ] - -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. - @@ -82,6 +55,7 @@ The function supports the following parameters: ## Notes - If a `mask` array element is truthy, the corresponding element in `x` is **included** in the output array; otherwise, the corresponding element in `x` is "masked" and thus **excluded** from the output array. +- If provided an input array having a recognized [data type][@stdlib/array/dtypes], the function returns an array having the same [data type][@stdlib/array/dtypes] as the input array. Otherwise, the function **always** returns a "generic" array. @@ -94,12 +68,12 @@ The function supports the following parameters: ```javascript -var zeroTo = require( '@stdlib/array/base/zero-to' ); +var zeroTo = require( '@stdlib/array/zero-to' ); var bernoulli = require( '@stdlib/random/array/bernoulli' ); -var mskfilter = require( '@stdlib/array/base/mskfilter' ); +var mskfilter = require( '@stdlib/array/mskfilter' ); // Generate a linearly spaced array: -var x = zeroTo( 20 ); +var x = zeroTo( 20, 'generic' ); console.log( x ); // Generate a random mask: @@ -129,6 +103,8 @@ console.log( y ); diff --git a/mskreject/README.md b/mskreject/README.md new file mode 100644 index 00000000..527add16 --- /dev/null +++ b/mskreject/README.md @@ -0,0 +1,110 @@ + + +# mskreject + +> Apply a mask to a provided input array. + +
+ +## Usage + +```javascript +var mskreject = require( '@stdlib/array/mskreject' ); +``` + +#### mskreject( x, mask ) + +Returns a new array by applying a mask to a provided input array. + +```javascript +var x = [ 1, 2, 3, 4 ]; + +var y = mskreject( x, [ 0, 1, 0, 1 ] ); +// returns [ 1, 3 ] +``` + +The function supports the following parameters: + +- **x**: input array. +- **mask**: mask array. + +
+ + + +
+ +## Notes + +- If a `mask` array element is falsy, the corresponding element in `x` is **included** in the output array; otherwise, the corresponding element in `x` is "masked" and thus **excluded** from the output array. +- If provided an input array having a recognized [data type][@stdlib/array/dtypes], the function returns an array having the same [data type][@stdlib/array/dtypes] as the input array. Otherwise, the function **always** returns a "generic" array. + +
+ + + +
+ +## Examples + + + +```javascript +var zeroTo = require( '@stdlib/array/zero-to' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var mskreject = require( '@stdlib/array/mskreject' ); + +// Generate a linearly spaced array: +var x = zeroTo( 20, 'generic' ); +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 = mskreject( x, mask ); +console.log( y ); +``` + +
+ + + + + + + + + + + + + + diff --git a/mskreject/benchmark/benchmark.js b/mskreject/benchmark/benchmark.js new file mode 100644 index 00000000..dbc22a84 --- /dev/null +++ b/mskreject/benchmark/benchmark.js @@ -0,0 +1,55 @@ +/** +* @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( './../../base/zero-to' ); +var zeros = require( './../../base/zeros' ); +var pkg = require( './../package.json' ).name; +var mskreject = 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 = mskreject( x, y ); + 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/mskreject/benchmark/benchmark.length.js b/mskreject/benchmark/benchmark.length.js new file mode 100644 index 00000000..809ebfdb --- /dev/null +++ b/mskreject/benchmark/benchmark.length.js @@ -0,0 +1,97 @@ +/** +* @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( './../../base/zero-to' ); +var zeros = require( './../../base/zeros' ); +var isArray = require( '@stdlib/assert/is-array' ); +var pkg = require( './../package.json' ).name; +var mskreject = 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 = mskreject( x, y ); + 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/mskreject/docs/repl.txt b/mskreject/docs/repl.txt new file mode 100644 index 00000000..661b765f --- /dev/null +++ b/mskreject/docs/repl.txt @@ -0,0 +1,30 @@ + +{{alias}}( x, mask ) + Returns a new array by applying a mask to a provided input array. + + If a mask array element is falsy, the corresponding element in `x` is + included in the output array; otherwise, the corresponding element in `x` is + "masked" and thus excluded from the output array. + + Parameters + ---------- + x: Array|TypedArray|Object + Input array. + + mask: Array|TypedArray|Object + Mask array. + + Returns + ------- + out: Array|TypedArray|Object + Output array. + + Examples + -------- + > var x = [ 1, 2, 3, 4 ]; + > var y = {{alias}}( x, [ 0, 1, 0, 1 ] ) + [ 1, 3 ] + + See Also + -------- + diff --git a/mskreject/docs/types/index.d.ts b/mskreject/docs/types/index.d.ts new file mode 100644 index 00000000..c258f131 --- /dev/null +++ b/mskreject/docs/types/index.d.ts @@ -0,0 +1,43 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Collection } from '@stdlib/types/array'; + +/** +* Returns a new array by applying a mask to a provided input array. +* +* @param x - input array +* @param mask - mask array +* @returns output array +* +* @example +* var x = [ 1, 2, 3, 4 ]; +* +* var y = mskreject( x, [ 0, 1, 0, 1 ] ); +* // returns [ 1, 3 ] +*/ +declare function mskreject( x: Collection, mask: Collection ): Collection; // FIXME: use type maps once associated PR merged + + +// EXPORTS // + +export = mskreject; diff --git a/mskreject/docs/types/test.ts b/mskreject/docs/types/test.ts new file mode 100644 index 00000000..51a69f8a --- /dev/null +++ b/mskreject/docs/types/test.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. +*/ + +import mskreject = require( './index' ); + + +// TESTS // + +// The function returns an array... +{ + mskreject( [ 1, 2, 3, 4 ], [ 0, 0, 0, 0 ] ); // $ExpectType Collection + mskreject( [ 1, 2, 3, 4 ], [ 0, 0, 0, 0 ] ); // $ExpectType Collection + mskreject( [ 1, 2, 3, 4 ], [ 0, 0, 0, 0 ] ); // $ExpectType Collection + mskreject( [ '1', '2', '3', '4' ], [ 0, 0, 0, 0 ] ); // $ExpectType Collection +} + +// The compiler throws an error if the function is provided a first argument which is not an array-like object... +{ + mskreject( 1, [ 0, 0 ] ); // $ExpectError + mskreject( true, [ 0, 0 ] ); // $ExpectError + mskreject( false, [ 0, 0 ] ); // $ExpectError + mskreject( null, [ 0, 0 ] ); // $ExpectError + mskreject( void 0, [ 0, 0 ] ); // $ExpectError + mskreject( {}, [ 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... +{ + mskreject( [], 1 ); // $ExpectError + mskreject( [], true ); // $ExpectError + mskreject( [], false ); // $ExpectError + mskreject( [], null ); // $ExpectError + mskreject( [], void 0 ); // $ExpectError + mskreject( [], {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + mskreject(); // $ExpectError + mskreject( [] ); // $ExpectError + mskreject( [], [], [] ); // $ExpectError +} diff --git a/mskreject/examples/index.js b/mskreject/examples/index.js new file mode 100644 index 00000000..5cb8fb6f --- /dev/null +++ b/mskreject/examples/index.js @@ -0,0 +1,37 @@ +/** +* @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( './../../zero-to' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var mskreject = require( './../lib' ); + +// Generate a linearly spaced array: +var x = zeroTo( 20, 'generic' ); +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 = mskreject( x, mask ); +console.log( y ); diff --git a/mskreject/lib/index.js b/mskreject/lib/index.js new file mode 100644 index 00000000..6ab9c333 --- /dev/null +++ b/mskreject/lib/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Apply a mask to a provided input array. +* +* @module @stdlib/array/mskreject +* +* @example +* var mskreject = require( '@stdlib/array/mskreject' ); +* +* var x = [ 1, 2, 3, 4 ]; +* var mask = [ 0, 1, 0, 1 ]; +* +* var y = mskreject( x, mask ); +* // returns [ 1, 3 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/mskreject/lib/main.js b/mskreject/lib/main.js new file mode 100644 index 00000000..e23318ce --- /dev/null +++ b/mskreject/lib/main.js @@ -0,0 +1,80 @@ +/** +* @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 isCollection = require( '@stdlib/assert/is-collection' ); +var base = require( './../../base/mskreject' ); +var countFalsy = require( './../../base/count-falsy' ); +var zeros = require( './../../zeros' ); +var dtype = require( './../../dtype' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns a new array by applying a mask to a provided input array. +* +* @param {Collection} x - input array +* @param {Collection} mask - mask array +* @throws {TypeError} first argument must be a collection +* @throws {TypeError} second argument must be a collection +* @throws {Error} must provide collections of equal length +* @returns {Collection} output array +* +* @example +* var x = [ 1, 2, 3, 4 ]; +* var mask = [ 0, 1, 0, 1 ]; +* +* var y = mskreject( x, mask ); +* // returns [ 1, 3 ] +* +* @example +* var Int32Array = require( '@stdlib/array/int32' ); +* +* var x = new Int32Array( [ 1, 2, 3, 4 ] ); +* var mask = [ 0, 1, 0, 1 ]; +* +* var y = mskreject( x, mask ); +* // returns [ 1, 3 ] +*/ +function mskreject( x, mask ) { + var dt; + if ( !isCollection( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); + } + if ( !isCollection( mask ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', mask ) ); + } + if ( x.length !== mask.length ) { + throw new Error( format( 'invalid arguments. Must provide equal length array-like objects.' ) ); + } + dt = dtype( x ); + if ( dt === 'generic' || dt === null ) { + return base( x, mask ); + } + return base.assign( x, mask, zeros( countFalsy( mask ), dt ), 1, 0 ); +} + + +// EXPORTS // + +module.exports = mskreject; diff --git a/mskreject/package.json b/mskreject/package.json new file mode 100644 index 00000000..c3d2ab2b --- /dev/null +++ b/mskreject/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/array/mskreject", + "version": "0.0.0", + "description": "Apply a mask to a provided input array.", + "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", + "filter", + "reject" + ] +} diff --git a/mskreject/test/test.js b/mskreject/test/test.js new file mode 100644 index 00000000..a770556b --- /dev/null +++ b/mskreject/test/test.js @@ -0,0 +1,277 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var toAccessorArray = require( './../../base/to-accessor-array' ); +var Complex64Array = require( './../../complex64' ); +var Int32Array = require( './../../int32' ); +var isSameComplex64Array = require( '@stdlib/assert/is-same-complex64array' ); +var isArray = require( '@stdlib/assert/is-array' ); +var isInt32Array = require( '@stdlib/assert/is-int32array' ); +var zeros = require( './../../zeros' ); +var mskreject = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof mskreject, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not a collection', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + mskreject( value, [] ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not a collection', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + mskreject( [], value ); + }; + } +}); + +tape( 'the function throws an error if provided collections of unequal length', function test( t ) { + var values; + var i; + + values = [ + [], + [ 1 ], + [ 1, 2 ], + [ 1, 2, 3 ], + [ 1, 2, 3, 4 ], + [ 1, 2, 3, 4, 5, 6 ], + [ 1, 2, 3, 4, 5, 6, 7 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + mskreject( value, zeros( 5, 'generic' ) ); + }; + } +}); + +tape( 'the function filters array elements (generic)', function test( t ) { + var expected; + var actual; + var mask; + var x; + + x = [ 1, 2, 3, 4 ]; + + mask = [ 0, 1, 0, 1 ]; + actual = mskreject( x, mask ); + expected = [ 1, 3 ]; + 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 = mskreject( x, mask ); + expected = []; + 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, 0 ]; + actual = mskreject( x, mask ); + expected = [ 4 ]; + 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, 0 ]; + actual = mskreject( x, mask ); + expected = [ 1, 2, 3, 4 ]; + 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 filters array elements (accessors)', function test( t ) { + var expected; + var actual; + var mask; + var x; + + x = toAccessorArray( [ 1, 2, 3, 4 ] ); + + mask = toAccessorArray( [ 0, 1, 0, 1 ] ); + actual = mskreject( x, mask ); + expected = [ 1, 3 ]; + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.notEqual( actual, x, 'returns new array' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + mask = toAccessorArray( [ 1, 1, 1, 1 ] ); + actual = mskreject( x, mask ); + expected = []; + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.notEqual( actual, x, 'returns new array' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + mask = toAccessorArray( [ 1, 1, 1, 0 ] ); + actual = mskreject( x, mask ); + expected = [ 4 ]; + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.notEqual( actual, x, 'returns new array' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + mask = toAccessorArray( [ 0, 0, 0, 0 ] ); + actual = mskreject( x, mask ); + expected = [ 1, 2, 3, 4 ]; + 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 filters array elements (real typed array)', function test( t ) { + var expected; + var actual; + var mask; + var x; + + x = new Int32Array( [ 1, 2, 3, 4 ] ); + + mask = [ 0, 1, 0, 1 ]; + actual = mskreject( x, mask ); + expected = [ 1, 3 ]; + t.strictEqual( isInt32Array( 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 = mskreject( x, mask ); + expected = []; + t.strictEqual( isInt32Array( actual ), true, 'returns expected value' ); + t.notEqual( actual, x, 'returns new array' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + mask = [ 1, 1, 1, 0 ]; + actual = mskreject( x, mask ); + expected = [ 4 ]; + t.strictEqual( isInt32Array( actual ), true, 'returns expected value' ); + t.notEqual( actual, x, 'returns new array' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + mask = [ 0, 0, 0, 0 ]; + actual = mskreject( x, mask ); + expected = [ 1, 2, 3, 4 ]; + t.strictEqual( isInt32Array( actual ), true, 'returns expected value' ); + t.notEqual( actual, x, 'returns new array' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function filters array elements (complex typed array)', 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 ] ); + + mask = [ 1, 0, 1, 0 ]; + actual = mskreject( x, mask ); + expected = new Complex64Array( [ 3.0, 4.0, 7.0, 8.0 ] ); + t.notEqual( actual, x, 'returns new array' ); + t.strictEqual( isSameComplex64Array( actual, expected ), true, 'returns expected value' ); + + mask = [ 1, 1, 1, 1 ]; + actual = mskreject( x, mask ); + expected = new Complex64Array( [] ); + t.notEqual( actual, x, 'returns new array' ); + t.strictEqual( isSameComplex64Array( actual, expected ), true, 'returns expected value' ); + + mask = [ 1, 1, 1, 0 ]; + actual = mskreject( x, mask ); + expected = new Complex64Array( [ 7.0, 8.0 ] ); + t.notEqual( actual, x, 'returns new array' ); + t.strictEqual( isSameComplex64Array( actual, expected ), true, 'returns expected value' ); + + mask = [ 0, 0, 0, 0 ]; + actual = mskreject( x, mask ); + expected = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + t.notEqual( actual, x, 'returns new array' ); + t.strictEqual( isSameComplex64Array( actual, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array if provided empty arrays', function test( t ) { + t.deepEqual( mskreject( [], [] ), [], 'returns expected value' ); + t.deepEqual( mskreject( new Int32Array( [] ), [] ), new Int32Array( [] ), 'returns expected value' ); + t.end(); +});