Skip to content

Commit 4d54abb

Browse files
Jaysukh-409kgryte
andauthored
feat: add boolean dtype support to array/base/none
PR-URL: #2424 Ref: #2304 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com> Signed-off-by: Athan Reines <kgryte@gmail.com>
1 parent 28023eb commit 4d54abb

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

lib/node_modules/@stdlib/array/base/none/lib/main.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222

2323
var isComplex128Array = require( '@stdlib/array/base/assert/is-complex128array' );
2424
var isComplex64Array = require( '@stdlib/array/base/assert/is-complex64array' );
25+
var isBooleanArray = require( '@stdlib/array/base/assert/is-booleanarray' );
2526
var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
2627
var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' );
2728
var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' );
29+
var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' );
2830

2931

3032
// FUNCTIONS //
@@ -130,6 +132,10 @@ function none( x ) {
130132
if ( isComplex64Array( x ) ) {
131133
return internal( reinterpret64( x, 0 ) );
132134
}
135+
// If provided a boolean array, reinterpret as a typed array and test whether all elements are false...
136+
if ( isBooleanArray( x ) ) {
137+
return internal( reinterpretBoolean( x, 0 ) );
138+
}
133139
return accessors( obj );
134140
}
135141
return internal( x );

lib/node_modules/@stdlib/array/base/none/test/test.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var AccessorArray = require( '@stdlib/array/base/accessor' );
2525
var Float64Array = require( '@stdlib/array/float64' );
2626
var Complex64Array = require( '@stdlib/array/complex64' );
2727
var Complex128Array = require( '@stdlib/array/complex128' );
28+
var BooleanArray = require( '@stdlib/array/bool' );
2829
var none = require( './../lib' );
2930

3031

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

78+
tape( 'if provided an empty collection, the function returns `true` (boolean array)', function test( t ) {
79+
var out;
80+
var arr;
81+
82+
arr = new BooleanArray( [] );
83+
out = none( arr );
84+
85+
t.strictEqual( out, true, 'returns expected value' );
86+
t.end();
87+
});
88+
7789
tape( 'if provided an empty collection, the function returns `true` (accessor)', function test( t ) {
7890
var out;
7991
var arr;
@@ -107,7 +119,7 @@ tape( 'the function returns `true` if all elements are falsy (real typed array)'
107119
t.end();
108120
});
109121

110-
tape( 'the function returns `true` if all elements are falsy (real typed array)', function test( t ) {
122+
tape( 'the function returns `true` if all elements are falsy (complex typed array)', function test( t ) {
111123
var out;
112124
var arr;
113125

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

138+
tape( 'the function returns `true` if all elements are falsy (boolean array)', function test( t ) {
139+
var out;
140+
var arr;
141+
142+
arr = new BooleanArray( [ false, false, false, false ] );
143+
out = none( arr );
144+
145+
t.strictEqual( out, true, 'returns expected value' );
146+
t.end();
147+
});
148+
126149
tape( 'the function returns `true` if all elements are falsy (accessor)', function test( t ) {
127150
var out;
128151
var arr;
@@ -188,6 +211,17 @@ tape( 'the function returns `false` if one or more elements are truthy (complex
188211
t.end();
189212
});
190213

214+
tape( 'the function returns `false` if one or more elements are truthy (boolean array)', function test( t ) {
215+
var out;
216+
var arr;
217+
218+
arr = new BooleanArray( [ false, true, false, false ] );
219+
out = none( arr );
220+
221+
t.strictEqual( out, false, 'returns expected value' );
222+
t.end();
223+
});
224+
191225
tape( 'the function returns `false` if one or more elements are truthy (accessor)', function test( t ) {
192226
var out;
193227
var arr;

0 commit comments

Comments
 (0)