Skip to content

Commit 56b0665

Browse files
committed
fix: remove always condition array reinterpretation
1 parent fb2a747 commit 56b0665

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

  • lib/node_modules/@stdlib/ndarray/base/where/lib

lib/node_modules/@stdlib/ndarray/base/where/lib/main.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,23 +347,26 @@ function where( arrays ) { // eslint-disable-line max-statements
347347
throw new TypeError( format( 'invalid arguments. Condition array must be a boolean or uint8 ndarray. c.dtype=%s', c.dtype ) );
348348
}
349349

350-
// Always reinterpret condition array to uint8
351-
if ( isBooleanArray( c.data ) ) {
352-
c = boolean2uint8( c );
353-
}
354-
355350
// Check for known array types which can be reinterpreted for better iteration performance...
356351
if ( isBooleanArray( x.data ) && isBooleanArray( y.data ) && isBooleanArray( o.data ) ) { // eslint-disable-line max-len
357352
x = boolean2uint8( x );
358353
y = boolean2uint8( y );
359354
o = boolean2uint8( o );
355+
356+
if ( isBooleanArray( c.data ) ) {
357+
c = boolean2uint8( c );
358+
}
360359
} else if ( isComplexArray( x.data ) && isComplexArray( y.data ) && isComplexArray( o.data ) ) { // eslint-disable-line max-len
361360
x = complex2real( x );
362361
y = complex2real( y );
363362
o = complex2real( o );
364363

365364
c.shape.push( 2 ); // real and imaginary components
366365
c.strides.push( 0 ); // broadcast
366+
367+
if ( isBooleanArray( c.data ) ) {
368+
c = boolean2uint8( c );
369+
}
367370
}
368371
// Determine whether we are casting a real data type to a complex data type and we need to use a specialized accessor (note: we don't support the other way, complex-to-real, as this is not an allowed (mostly) safe cast; note: we cannot create a specialized view for assigning only real components, as the imaginary component for each element in `y` also needs to be set to zero and while we could perform two passes, it's not clear it's worth the effort)...
369372
else if ( isComplexDataType( o.dtype ) ) {

0 commit comments

Comments
 (0)