Skip to content

feat: add boolean dtype support to array/base/none #2424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/node_modules/@stdlib/array/base/none/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@

var isComplex128Array = require( '@stdlib/array/base/assert/is-complex128array' );
var isComplex64Array = require( '@stdlib/array/base/assert/is-complex64array' );
var isBooleanArray = require( '@stdlib/array/base/assert/is-booleanarray' );
var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' );
var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' );
var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' );


// FUNCTIONS //
Expand Down Expand Up @@ -130,6 +132,10 @@ function none( x ) {
if ( isComplex64Array( x ) ) {
return internal( reinterpret64( x, 0 ) );
}
// If provided a boolean array, reinterpret as a typed array and test whether all elements are false...
if ( isBooleanArray( x ) ) {
return internal( reinterpretBoolean( x, 0 ) );
}
return accessors( obj );
}
return internal( x );
Expand Down
36 changes: 35 additions & 1 deletion lib/node_modules/@stdlib/array/base/none/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var AccessorArray = require( '@stdlib/array/base/accessor' );
var Float64Array = require( '@stdlib/array/float64' );
var Complex64Array = require( '@stdlib/array/complex64' );
var Complex128Array = require( '@stdlib/array/complex128' );
var BooleanArray = require( '@stdlib/array/bool' );
var none = require( './../lib' );


Expand Down Expand Up @@ -74,6 +75,17 @@ tape( 'if provided an empty collection, the function returns `true` (complex typ
t.end();
});

tape( 'if provided an empty collection, the function returns `true` (boolean array)', function test( t ) {
var out;
var arr;

arr = new BooleanArray( [] );
out = none( arr );

t.strictEqual( out, true, 'returns expected value' );
t.end();
});

tape( 'if provided an empty collection, the function returns `true` (accessor)', function test( t ) {
var out;
var arr;
Expand Down Expand Up @@ -107,7 +119,7 @@ tape( 'the function returns `true` if all elements are falsy (real typed array)'
t.end();
});

tape( 'the function returns `true` if all elements are falsy (real typed array)', function test( t ) {
tape( 'the function returns `true` if all elements are falsy (complex typed array)', function test( t ) {
var out;
var arr;

Expand All @@ -123,6 +135,17 @@ tape( 'the function returns `true` if all elements are falsy (real typed array)'
t.end();
});

tape( 'the function returns `true` if all elements are falsy (boolean array)', function test( t ) {
var out;
var arr;

arr = new BooleanArray( [ false, false, false, false ] );
out = none( arr );

t.strictEqual( out, true, 'returns expected value' );
t.end();
});

tape( 'the function returns `true` if all elements are falsy (accessor)', function test( t ) {
var out;
var arr;
Expand Down Expand Up @@ -188,6 +211,17 @@ tape( 'the function returns `false` if one or more elements are truthy (complex
t.end();
});

tape( 'the function returns `false` if one or more elements are truthy (boolean array)', function test( t ) {
var out;
var arr;

arr = new BooleanArray( [ false, true, false, false ] );
out = none( arr );

t.strictEqual( out, false, 'returns expected value' );
t.end();
});

tape( 'the function returns `false` if one or more elements are truthy (accessor)', function test( t ) {
var out;
var arr;
Expand Down
Loading