Skip to content

feat: add boolean dtype support to array/base/any #2422

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 1 commit 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/any/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 any( x ) {
if ( isComplex64Array( x ) ) {
return internal( reinterpret64( x, 0 ) );
}
// If provided a boolean array, reinterpret as typed array and test for truthiness...
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/any/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 any = require( './../lib' );


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

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

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

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

tape( 'if provided an empty collection, the function returns `false` (accessor)', function test( t ) {
var out;
var arr;
Expand Down Expand Up @@ -107,7 +119,7 @@ tape( 'the function returns `true` if at least one element is truthy (real typed
t.end();
});

tape( 'the function returns `true` if at least one element is truthy (real typed array)', function test( t ) {
tape( 'the function returns `true` if at least one element is truthy (complex typed array)', function test( t ) {
var out;
var arr;

Expand All @@ -123,6 +135,17 @@ tape( 'the function returns `true` if at least one element is truthy (real typed
t.end();
});

tape( 'the function returns `true` if at least one element is truthy (boolean array)', function test( t ) {
var out;
var arr;

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

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

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

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

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

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

tape( 'the function returns `false` if all elements are falsy (accessor)', function test( t ) {
var out;
var arr;
Expand Down