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 Feb 20, 2024
1 parent 26d4f6d commit 8f44f1e
Show file tree
Hide file tree
Showing 13 changed files with 910 additions and 31 deletions.
9 changes: 9 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 7 additions & 31 deletions mskfilter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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.

</section>

<!-- /.usage -->
Expand All @@ -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.

</section>

Expand All @@ -94,12 +68,12 @@ The function supports the following parameters:
<!-- eslint no-undef: "error" -->

```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:
Expand Down Expand Up @@ -129,6 +103,8 @@ console.log( y );

<section class="links">

[@stdlib/array/dtypes]: https://github.com/stdlib-js/array/tree/main/dtypes

</section>

<!-- /.links -->
110 changes: 110 additions & 0 deletions mskreject/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<!--
@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

> Apply a mask to a provided input array.
<section class="usage">

## 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.

</section>

<!-- /.usage -->

<section class="notes">

## 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.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

```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 );
```

</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">

[@stdlib/array/dtypes]: https://github.com/stdlib-js/array/tree/main/dtypes

</section>

<!-- /.links -->
55 changes: 55 additions & 0 deletions 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 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 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: 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
--------

Loading

0 comments on commit 8f44f1e

Please sign in to comment.