You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/node_modules/@stdlib/ndarray/base/where/README.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -129,6 +129,10 @@ Each provided ndarray should be an object with the following properties:
129
129
130
130
## Notes
131
131
132
+
-`condition` ndarray must be a `boolean` or `uint8` ndarray.
133
+
-`condition`, `x`, `y`, and `out` ndarrays must have the same shape.
134
+
-`x` and `y` must have the same data type.
135
+
- The function **mutates** the input ndarrays shapes and strides if necessary.
132
136
- For very high-dimensional ndarrays which are non-contiguous, one should consider copying the underlying data to contiguous memory before conditionally assigning elements in order to achieve better performance.
thrownewError(format('invalid arguments. Condition array must be a boolean or uint8 ndarray. c.dtype=%s',c.dtype));
335
+
}
336
+
337
+
if(x.dtype!==y.dtype){
338
+
thrownewError(format('invalid arguments. Input arrays must have the same data type. x.dtype=%s, y.dtype=%s',x.dtype,y.dtype));
339
+
}
340
+
331
341
// Always reinterpret condition array to uint8
332
342
if(isBooleanArray(c.data)){
333
343
c=boolean2uint8(c);
@@ -342,6 +352,7 @@ function where( arrays ) {
342
352
x=complex2real(x);
343
353
y=complex2real(y);
344
354
o=complex2real(o);
355
+
345
356
c.shape.push(2);// real and imaginary components
346
357
c.strides.push(0);// broadcast
347
358
}
@@ -363,7 +374,7 @@ function where( arrays ) {
363
374
}
364
375
// Determine whether we can avoid iteration altogether...
365
376
if(ndims===0){
366
-
if(hasAccessors(x,y,o)){
377
+
if(hasAccessors(c,x,y,o)){
367
378
returnACCESSOR_WHERE[ndims](c,x,y,o);
368
379
}
369
380
returnWHERE[ndims](c,x,y,o);
@@ -390,7 +401,7 @@ function where( arrays ) {
390
401
}
391
402
// Determine whether the ndarrays are one-dimensional and thus readily translate to one-dimensional strided arrays...
392
403
if(ndims===1){
393
-
if(hasAccessors(x,y,o)){
404
+
if(hasAccessors(c,x,y,o)){
394
405
returnACCESSOR_WHERE[ndims](c,x,y,o);
395
406
}
396
407
returnWHERE[ndims](c,x,y,o);
@@ -416,7 +427,7 @@ function where( arrays ) {
416
427
x.strides=[sx[i]];
417
428
y.strides=[sy[i]];
418
429
o.strides=[so[i]];
419
-
if(hasAccessors(x,y,o)){
430
+
if(hasAccessors(c,x,y,o)){
420
431
returnACCESSOR_WHERE[1](c,x,y,o);
421
432
}
422
433
returnWHERE[1](c,x,y,o);
@@ -470,7 +481,7 @@ function where( arrays ) {
470
481
x.offset=ox;
471
482
y.offset=oy;
472
483
o.offset=oo;
473
-
if(hasAccessors(x,y,o)){
484
+
if(hasAccessors(c,x,y,o)){
474
485
returnACCESSOR_WHERE[1](c,x,y,o);
475
486
}
476
487
returnWHERE[1](c,x,y,o);
@@ -480,7 +491,7 @@ function where( arrays ) {
480
491
// Determine whether we can use simple nested loops...
481
492
if(ndims<=MAX_DIMS){
482
493
// So long as iteration for each respective array always moves in the same direction (i.e., no mixed sign strides), we can leverage cache-optimal (i.e., normal) nested loops without resorting to blocked iteration...
483
-
if(hasAccessors(x,y,o)){
494
+
if(hasAccessors(c,x,y,o)){
484
495
returnACCESSOR_WHERE[ndims](c,x,y,o,ord===1);
485
496
}
486
497
returnWHERE[ndims](c,x,y,o,ord===1);
@@ -491,13 +502,13 @@ function where( arrays ) {
491
502
492
503
// Determine whether we can perform blocked iteration...
493
504
if(ndims<=MAX_DIMS){
494
-
if(hasAccessors(x,y,o)){
505
+
if(hasAccessors(c,x,y,o)){
495
506
returnBLOCKED_ACCESSOR_WHERE[ndims-2](c,x,y,o);
496
507
}
497
508
returnBLOCKED_WHERE[ndims-2](c,x,y,o);
498
509
}
499
510
// Fall-through to linear view iteration without regard for how data is stored in memory (i.e., take the slow path)...
0 commit comments