Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Jan 28, 2024
1 parent 2b04a61 commit 0846952
Show file tree
Hide file tree
Showing 14 changed files with 711 additions and 5 deletions.
9 changes: 9 additions & 0 deletions base/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,15 @@ setReadOnly( ns, 'mskbinary2d', require( './../../base/mskbinary2d' ) );
*/
setReadOnly( ns, 'mskfilter', require( './../../base/mskfilter' ) );

/**
* @name mskreject
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/base/mskreject}
*/
setReadOnly( ns, 'mskreject', require( './../../base/mskreject' ) );

/**
* @name mskunary2d
* @memberof ns
Expand Down
104 changes: 104 additions & 0 deletions base/mskreject/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<!--
@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.
-->

# mskreject

> Return a new array by applying a mask to a provided input array.
<section class="usage">

## Usage

```javascript
var mskreject = require( '@stdlib/array/base/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 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- The function **always** returns a new "generic" 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.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var zeroTo = require( '@stdlib/array/base/zero-to' );
var bernoulli = require( '@stdlib/random/array/bernoulli' );
var mskreject = require( '@stdlib/array/base/mskreject' );

// Generate a linearly spaced array:
var x = zeroTo( 20 );

// Generate a random mask:
var mask = bernoulli( x.length, 0.5, {
'dtype': 'generic'
});

// Filter an array using the mask:
var y = mskreject( x, mask );

console.log( x );
console.log( mask );
console.log( y );
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

</section>

<!-- /.links -->
55 changes: 55 additions & 0 deletions base/mskreject/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -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();
});
97 changes: 97 additions & 0 deletions base/mskreject/benchmark/benchmark.length.js
Original file line number Diff line number Diff line change
@@ -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();
30 changes: 30 additions & 0 deletions base/mskreject/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -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: ArrayLikeObject
Input array.

mask: ArrayLikeObject
Mask array.

Returns
-------
out: Array
Output array.

Examples
--------
> var x = [ 1, 2, 3, 4 ];
> var y = {{alias}}( x, [ 0, 1, 0, 1 ] )
[ 1, 3 ]

See Also
--------

43 changes: 43 additions & 0 deletions base/mskreject/docs/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -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

/// <reference types="@stdlib/types"/>

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<T = unknown>( x: Collection<T>, mask: Collection ): Array<T>;


// EXPORTS //

export = mskreject;
Loading

0 comments on commit 0846952

Please sign in to comment.