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 Jun 25, 2024
1 parent 08ecf2f commit d272d02
Show file tree
Hide file tree
Showing 7 changed files with 276 additions and 5 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<section class="release" id="unreleased">

## Unreleased (2024-06-24)
## Unreleased (2024-06-25)

<section class="packages">

Expand Down Expand Up @@ -939,6 +939,7 @@ This release closes the following issue:

##### Features

- [`c04e29b`](https://github.com/stdlib-js/stdlib/commit/c04e29bf919dcc5f1368fecd977db696041ff8db) - add boolean dtype support to `array/base/mskfilter` [(#2450)](https://github.com/stdlib-js/stdlib/pull/2450)
- [`d34ae78`](https://github.com/stdlib-js/stdlib/commit/d34ae789c63908f3edd1e7a746abd4cc60619b27) - add `assign` method

</section>
Expand Down Expand Up @@ -1164,6 +1165,7 @@ This release closes the following issue:

##### Features

- [`760979b`](https://github.com/stdlib-js/stdlib/commit/760979b6efafb5c235daa718c17d7eb5cef82237) - add boolean dtype support to `array/base/take` [(#2453)](https://github.com/stdlib-js/stdlib/pull/2453)
- [`3a57fb4`](https://github.com/stdlib-js/stdlib/commit/3a57fb47211679fa520b5e1613b41aebd30eccf6) - add `assign` method and add support for an index accessor array

</section>
Expand Down Expand Up @@ -2258,6 +2260,8 @@ A total of 13 people contributed to this release. Thank you to the following con

<details>

- [`c04e29b`](https://github.com/stdlib-js/stdlib/commit/c04e29bf919dcc5f1368fecd977db696041ff8db) - **feat:** add boolean dtype support to `array/base/mskfilter` [(#2450)](https://github.com/stdlib-js/stdlib/pull/2450) _(by Jaysukh Makvana, Athan Reines)_
- [`760979b`](https://github.com/stdlib-js/stdlib/commit/760979b6efafb5c235daa718c17d7eb5cef82237) - **feat:** add boolean dtype support to `array/base/take` [(#2453)](https://github.com/stdlib-js/stdlib/pull/2453) _(by Jaysukh Makvana, Athan Reines)_
- [`c41435f`](https://github.com/stdlib-js/stdlib/commit/c41435fa51e75a6329d78b8e801590476ece06af) - **feat:** add boolean dtype support to `array/base/cuany` [(#2446)](https://github.com/stdlib-js/stdlib/pull/2446) _(by Jaysukh Makvana)_
- [`3c451db`](https://github.com/stdlib-js/stdlib/commit/3c451db98b94e5d89a2aaffca29c4ca93835605f) - **feat:** add boolean dtype support to `array/base/cuevery` [(#2447)](https://github.com/stdlib-js/stdlib/pull/2447) _(by Jaysukh Makvana)_
- [`fbc42b4`](https://github.com/stdlib-js/stdlib/commit/fbc42b4c66cf695c6c114f64bf3eff65186026f0) - **feat:** add `includes` method to `array/bool` [(#2441)](https://github.com/stdlib-js/stdlib/pull/2441) _(by Jaysukh Makvana)_
Expand Down
53 changes: 52 additions & 1 deletion base/mskfilter/lib/assign.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
// MODULES //

var isComplexDataType = require( './../../../base/assert/is-complex-floating-point-data-type' );
var isBooleanDataType = require( './../../../base/assert/is-boolean-data-type' );
var arraylike2object = require( './../../../base/arraylike2object' );
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex' );
var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' );


// FUNCTIONS //
Expand Down Expand Up @@ -163,6 +165,48 @@ function complex( x, mask, out, stride, offset ) {
return out;
}

/**
* Applies a mask to a boolean array and assigns unmasked values to elements in a boolean output array.
*
* @private
* @param {Collection} x - boolean input array view
* @param {Object} mask - mask array object
* @param {Collection} out - boolean output array view
* @param {integer} stride - output array stride
* @param {NonNegativeInteger} offset - output array offset
* @returns {Collection} output array view
*
* @example
* var Uint8Array = require( '@stdlib/array/uint8' );
* var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
*
* var x = new Uint8Array( [ 1, 0, 0, 1 ] );
* var mask = [ 0, 1, 0, 1 ];
*
* var out = new Uint8Array( 4 );
*
* var arr = boolean( x, arraylike2object( mask ), out, 1, 0 );
* // returns <Uint8Array>[ 0, 1, 0, 0 ]
*/
function boolean( x, mask, out, stride, offset ) {
var mdata;
var mget;
var io;
var i;

mdata = mask.data;
mget = mask.accessors[ 0 ];

io = offset;
for ( i = 0; i < mdata.length; i++ ) {
if ( mget( mdata, i ) ) {
out[ io ] = x[ i ];
io += stride;
}
}
return out;
}


// MAIN //

Expand Down Expand Up @@ -200,14 +244,21 @@ function assign( x, mask, out, stride, offset ) {
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...
// Note: we only explicitly support a limited set of dtype-to-dtype pairs, 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 ); // eslint-disable-line max-len
return out;
}
if (
isBooleanDataType( xo.dtype ) &&
isBooleanDataType( oo.dtype )
) {
boolean( reinterpretBoolean( x, 0 ), mo, reinterpretBoolean( out, 0 ), stride, offset ); // eslint-disable-line max-len
return out;
}
accessors( xo, mo, oo, stride, offset );
return out;
}
Expand Down
60 changes: 60 additions & 0 deletions base/mskfilter/test/test.assign.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@

var tape = require( 'tape' );
var Complex64Array = require( './../../../complex64' );
var BooleanArray = require( './../../../bool' );
var toAccessorArray = require( './../../../base/to-accessor-array' );
var Int32Array = require( './../../../int32' );
var isSameComplex64Array = require( '@stdlib/assert/is-same-complex64array' );
var isSameBooleanArray = require( '@stdlib/assert/is-same-booleanarray' );
var zeros = require( './../../../zeros' );
var mskfilter = require( './../lib/assign.js' );

Expand Down Expand Up @@ -193,6 +195,58 @@ tape( 'the function filters array elements (complex typed array)', function test
t.end();
});

tape( 'the function filters array elements (boolean array)', function test( t ) {
var expected;
var actual;
var mask;
var out;
var x;

x = new BooleanArray( [ true, false, false, true ] );

mask = [ 0, 1, 0, 1 ];
out = new BooleanArray( 2 );
actual = mskfilter( x, mask, out, 1, 0 );
expected = new BooleanArray( [ false, true ] );

t.strictEqual( actual, out, 'returns expected value' );
t.strictEqual( isSameBooleanArray( actual, expected ), true, 'returns expected value' );

mask = [ 0, 0, 0, 0 ];
out = new BooleanArray( 0 );
actual = mskfilter( x, mask, out, 1, 0 );
expected = new BooleanArray( [] );

t.strictEqual( actual, out, 'returns expected value' );
t.strictEqual( isSameBooleanArray( actual, expected ), true, 'returns expected value' );

mask = [ 0, 0, 0, 1 ];
out = new BooleanArray( 1 );
actual = mskfilter( x, mask, out, 1, 0 );
expected = new BooleanArray( [ true ] );

t.strictEqual( actual, out, 'returns expected value' );
t.strictEqual( isSameBooleanArray( actual, expected ), true, 'returns expected value' );

mask = [ 1, 1, 1, 1 ];
out = new BooleanArray( 4 );
actual = mskfilter( x, mask, out, 1, 0 );
expected = new BooleanArray( [ true, false, false, true ] );

t.strictEqual( actual, out, 'returns expected value' );
t.strictEqual( isSameBooleanArray( actual, expected ), true, 'returns expected value' );

mask = [ 0, 1, 0, 1 ];
out = new BooleanArray( 4 );
actual = mskfilter( x, mask, out, -2, out.length-1 );
expected = new BooleanArray( [ false, true, false, false ] );

t.strictEqual( actual, out, 'returns expected value' );
t.strictEqual( isSameBooleanArray( actual, expected ), true, 'returns expected value' );

t.end();
});

tape( 'the function filters array elements (accessors)', function test( t ) {
var expected;
var actual;
Expand Down Expand Up @@ -285,5 +339,11 @@ tape( 'the function returns leaves an output array unchanged if provided a secon
actual = mskfilter( x, mask, out, 1, 0 );
t.strictEqual( isSameComplex64Array( actual, expected ), true, 'returns expected value' );

x = new BooleanArray( [ true, false, false, true ] );
out = new BooleanArray( [ false, false, false, false ] );
expected = new BooleanArray( [ false, false, false, false ] );
actual = mskfilter( x, mask, out, 1, 0 );
t.strictEqual( isSameBooleanArray( actual, expected ), true, 'returns expected value' );

t.end();
});
13 changes: 13 additions & 0 deletions base/mskfilter/test/test.main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

var tape = require( 'tape' );
var Complex64Array = require( './../../../complex64' );
var BooleanArray = require( './../../../bool' );
var isSameComplex64 = require( '@stdlib/assert/is-same-complex64' );
var isArray = require( '@stdlib/assert/is-array' );
var mskfilter = require( './../lib' );
Expand Down Expand Up @@ -91,6 +92,18 @@ tape( 'the function filters array elements (accessors)', function test( t ) {
for ( i = 0; i < expected.length; i++ ) {
t.strictEqual( isSameComplex64( actual[ i ], expected[ i ] ), true, 'returns expected value' );
}

x = new BooleanArray( [ true, false, false, true ] );
mask = [ 0, 1, 0, 1 ];
actual = mskfilter( x, mask );
expected = [ x.get( 1 ), x.get( 3 ) ];

t.strictEqual( isArray( actual ), true, 'returns expected value' );
t.notEqual( actual, x, 'returns different reference' );
for ( i = 0; i < expected.length; i++ ) {
t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' );
}

t.end();
});

Expand Down
63 changes: 62 additions & 1 deletion base/take/lib/assign.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
// MODULES //

var isComplexDataType = require( './../../../base/assert/is-complex-floating-point-data-type' );
var isBooleanDataType = require( './../../../base/assert/is-boolean-data-type' );
var arraylike2object = require( './../../../base/arraylike2object' );
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex' );
var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' );
var ind = require( '@stdlib/ndarray/base/ind' ).factory;


Expand Down Expand Up @@ -191,6 +193,58 @@ function complex( x, indices, mode, out, stride, offset ) {
return out;
}

/**
* Takes elements from a boolean array and assigns the values to elements in a boolean output array.
*
* @private
* @param {Collection} x - boolean value input array view
* @param {Object} indices - index array object
* @param {string} mode - index mode
* @param {Collection} out - boolean value output array view
* @param {integer} stride - output array stride
* @param {NonNegativeInteger} offset - output array offset
* @returns {Collection} output array view
*
* @example
* var Uint8Array = require( '@stdlib/array/uint8' );
* var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
*
* var x = new Uint8Array( [ 1, 0, 0, 1 ] );
* var indices = [ 0, 0, 1, 1 ];
*
* var out = new Uint8Array( 4 );
*
* var arr = boolean( x, arraylike2object( indices ), 'throw', out, 1, 0 );
* // returns <Uint8Array>[ 1, 1, 0, 0 ]
*/
function boolean( x, indices, mode, out, stride, offset ) {
var getIndex;
var idata;
var iget;
var max;
var io;
var i;
var j;

idata = indices.data;
iget = indices.accessors[ 0 ];

// Resolve a function for returning an index according to the specified index mode:
getIndex = ind( mode );

// Resolve the maximum index:
max = x.length - 1;

// Extract each desired element from the provided array...
io = offset;
for ( i = 0; i < idata.length; i++ ) {
j = getIndex( iget( idata, i ), max );
out[ io ] = x[ j ];
io += stride;
}
return out;
}


// MAIN //

Expand Down Expand Up @@ -229,14 +283,21 @@ function assign( x, indices, mode, out, stride, offset ) {
io.accessorProtocol ||
oo.accessorProtocol
) {
// Note: we only explicitly support complex-to-complex, as this function should not be concerned with casting rules, etc. That is left to userland...
// Note: we only explicitly support a limited set of dtype-to-dtype pairs, 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 ), io, mode, reinterpret( out, 0 ), stride, offset ); // eslint-disable-line max-len
return out;
}
if (
isBooleanDataType( xo.dtype ) &&
isBooleanDataType( oo.dtype )
) {
boolean( reinterpretBoolean( x, 0 ), io, mode, reinterpretBoolean( out, 0 ), stride, offset ); // eslint-disable-line max-len
return out;
}
accessors( xo, io, mode, oo, stride, offset );
return out;
}
Expand Down
Loading

0 comments on commit d272d02

Please sign in to comment.