Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 | 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 62x 62x 62x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 9x 9x 9x 9x 9x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 3x 3x 71x 71x 71x 6x 6x 71x 71x 74x 1x 1x 1x 74x 1x 1x 1x 1x 1x 1x 1x 69x 69x 71x 71x 71x 71x 71x 71x 71x 71x 74x 2x 1x 1x 1x 1x 69x 69x 69x 72x 160x 160x 4x 4x 156x 156x 156x 156x 160x 36x 36x 160x 65x 72x 5x 5x 60x 71x 3x 1x 1x 2x 2x 57x 57x 57x 57x 57x 57x 69x 8x 8x 11x 8x 8x 11x 8x 8x 8x 8x 8x 8x 8x 8x 8x 4x 4x 4x 4x 49x 49x 49x 49x 49x 49x 49x 74x 25x 25x 25x 25x 25x 25x 25x 25x 16x 16x 8x 8x 8x 8x 16x 8x 8x 8x 8x 16x 8x 8x 8x 8x 16x 8x 8x 8x 8x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 8x 8x 8x 8x 9x 9x 9x 9x 9x 9x 4x 4x 5x 5x 25x 25x 24x 24x 24x 24x 24x 12x 12x 12x 12x 74x 5x 5x 5x 5x 5x | /**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-disable max-lines */
'use strict';
// MODULES //
var format = require( '@stdlib/string/format' );
var isComplexDataType = require( '@stdlib/ndarray/base/assert/is-complex-floating-point-data-type' );
var isRealDataType = require( '@stdlib/ndarray/base/assert/is-real-data-type' );
var isComplexArray = require( '@stdlib/array/base/assert/is-complex-typed-array' );
var isBooleanArray = require( '@stdlib/array/base/assert/is-booleanarray' );
var isUint8Array = require( '@stdlib/assert/is-uint8array' );
var iterationOrder = require( '@stdlib/ndarray/base/iteration-order' );
var strides2order = require( '@stdlib/ndarray/base/strides2order' );
var anyIsEntryIn = require( '@stdlib/array/base/any-is-entry-in' );
var castReturn = require( '@stdlib/complex/base/cast-return' );
var complexCtors = require( '@stdlib/complex/ctors' );
var minmaxViewBufferIndex = require( '@stdlib/ndarray/base/minmax-view-buffer-index' );
var ndarray2object = require( '@stdlib/ndarray/base/ndarraylike2object' );
var reinterpretComplex = require( '@stdlib/strided/base/reinterpret-complex' );
var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' );
var gscal = require( '@stdlib/blas/base/gscal' );
var blockedaccessorwhere2d = require( './2d_blocked_accessors.js' );
var blockedaccessorwhere3d = require( './3d_blocked_accessors.js' );
var blockedaccessorwhere4d = require( './4d_blocked_accessors.js' );
var blockedaccessorwhere5d = require( './5d_blocked_accessors.js' );
var blockedaccessorwhere6d = require( './6d_blocked_accessors.js' );
var blockedaccessorwhere7d = require( './7d_blocked_accessors.js' );
var blockedaccessorwhere8d = require( './8d_blocked_accessors.js' );
var blockedaccessorwhere9d = require( './9d_blocked_accessors.js' );
var blockedaccessorwhere10d = require( './10d_blocked_accessors.js' );
var blockedwhere2d = require( './2d_blocked.js' );
var blockedwhere3d = require( './3d_blocked.js' );
var blockedwhere4d = require( './4d_blocked.js' );
var blockedwhere5d = require( './5d_blocked.js' );
var blockedwhere6d = require( './6d_blocked.js' );
var blockedwhere7d = require( './7d_blocked.js' );
var blockedwhere8d = require( './8d_blocked.js' );
var blockedwhere9d = require( './9d_blocked.js' );
var blockedwhere10d = require( './10d_blocked.js' );
var accessorwhere0d = require( './0d_accessors.js' );
var accessorwhere1d = require( './1d_accessors.js' );
var accessorwhere2d = require( './2d_accessors.js' );
var accessorwhere3d = require( './3d_accessors.js' );
var accessorwhere4d = require( './4d_accessors.js' );
var accessorwhere5d = require( './5d_accessors.js' );
var accessorwhere6d = require( './6d_accessors.js' );
var accessorwhere7d = require( './7d_accessors.js' );
var accessorwhere8d = require( './8d_accessors.js' );
var accessorwhere9d = require( './9d_accessors.js' );
var accessorwhere10d = require( './10d_accessors.js' );
var accessorwherend = require( './nd_accessors.js' );
var where0d = require( './0d.js' );
var where1d = require( './1d.js' );
var where2d = require( './2d.js' );
var where3d = require( './3d.js' );
var where4d = require( './4d.js' );
var where5d = require( './5d.js' );
var where6d = require( './6d.js' );
var where7d = require( './7d.js' );
var where8d = require( './8d.js' );
var where9d = require( './9d.js' );
var where10d = require( './10d.js' );
var wherend = require( './nd.js' );
// VARIABLES //
var WHERE = [
where0d,
where1d,
where2d,
where3d,
where4d,
where5d,
where6d,
where7d,
where8d,
where9d,
where10d
];
var ACCESSOR_WHERE = [
accessorwhere0d,
accessorwhere1d,
accessorwhere2d,
accessorwhere3d,
accessorwhere4d,
accessorwhere5d,
accessorwhere6d,
accessorwhere7d,
accessorwhere8d,
accessorwhere9d,
accessorwhere10d
];
var BLOCKED_WHERE = [
blockedwhere2d, // 0
blockedwhere3d,
blockedwhere4d,
blockedwhere5d,
blockedwhere6d,
blockedwhere7d,
blockedwhere8d,
blockedwhere9d,
blockedwhere10d // 8
];
var BLOCKED_ACCESSOR_WHERE = [
blockedaccessorwhere2d, // 0
blockedaccessorwhere3d,
blockedaccessorwhere4d,
blockedaccessorwhere5d,
blockedaccessorwhere6d,
blockedaccessorwhere7d,
blockedaccessorwhere8d,
blockedaccessorwhere9d,
blockedaccessorwhere10d // 8
];
var MAX_DIMS = WHERE.length - 1;
// TODO: consider adding a package utility for mapping a complex dtype to its complementary real-valued counterpart
var COMPLEX_TO_REAL = { // WARNING: this table needs to be manually updated if we add support for additional complex number dtypes
'complex128': 'float64',
'complex64': 'float32',
'complex32': 'float16'
};
// FUNCTIONS //
/**
* Returns a boolean indicating if at least one ndarray data buffer implements the accessor protocol.
*
* @private
* @param {ndarrayLike} x - first ndarray
* @param {ndarrayLike} y - second ndarray
* @param {ndarrayLike} z - third ndarray
* @param {ndarrayLike} w - fourth ndarray
* @returns {boolean} boolean indicating whether an ndarray data buffer implements the accessor protocol
*/
function hasAccessors( x, y, z, w ) {
return anyIsEntryIn( [ x, y, z, w ], 'accessorProtocol', true );
}
/**
* Converts a boolean ndarray to an 8-bit unsigned integer ndarray.
*
* ## Notes
*
* - The function mutates the input ndarray object.
*
* @private
* @param {Object} x - input ndarray object
* @returns {Object} output ndarray object
*/
function boolean2uint8( x ) {
x.data = reinterpretBoolean( x.data, 0 );
x.accessorProtocol = false;
return x;
}
/**
* Converts a complex-valued floating-point ndarray to a real-valued floating-point ndarray.
*
* ## Notes
*
* - The function mutates the input ndarray object.
*
* @private
* @param {Object} x - input ndarray object
* @returns {Object} output ndarray object
*/
function complex2real( x ) {
var ndims = x.shape.length;
x.data = reinterpretComplex( x.data, 0 );
x.accessorProtocol = false;
x.dtype = COMPLEX_TO_REAL[ String( x.dtype ) ];
x.strides = gscal( ndims, 2, x.strides, 1 );
x.offset *= 2;
// Append a trailing dimension where each element is the real and imaginary component for a corresponding element in the original input ndarray (note: this means that a two-dimensional complex-valued ndarray becomes a three-dimensional real-valued ndarray; while this does entail additional loop overhead, it is still significantly faster than sending complex-valued ndarrays down the accessor path):
x.shape.push( 2 ); // real and imaginary components
// Augment the strides, where we assume that real and imaginary components are adjacent in memory...
if ( ndims === 0 ) {
x.strides[ 0 ] = 1;
} else {
x.strides.push( 1 );
}
return x;
}
// MAIN //
/**
* Applies a condition to elements in two input ndarrays and assigns results to elements in an output ndarray.
*
* ## Notes
*
* - Each provided ndarray should be an object with the following properties:
*
* - **dtype**: data type.
* - **data**: data buffer.
* - **shape**: dimensions.
* - **strides**: stride lengths.
* - **offset**: index offset.
* - **order**: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style).
*
* @param {ArrayLikeObject<Object>} arrays - array-like object containing one condition array, two input arrays, and one output array
* @throws {Error} arrays must have the same number of dimensions
* @throws {Error} arrays must have the same shape
* @throws {TypeError} condition array must be a boolean or uint8 ndarray
* @returns {void}
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
* var Uint8Array = require( '@stdlib/array/uint8' );
*
* // Create data buffers:
* var cbuf = new Uint8Array( [ 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1 ] );
* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
* var ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] );
* var obuf = new Float64Array( 6 );
*
* // Define the shape of the input and output arrays:
* var shape = [ 3, 1, 2 ];
*
* // Define the array strides:
* var sc = [ 4, 4, 1 ];
* var sx = [ 4, 4, 1 ];
* var sy = [ 4, 4, 1 ];
* var so = [ 2, 2, 1 ];
*
* // Define the index offsets:
* var oc = 1;
* var ox = 1;
* var oy = 1;
* var oo = 0;
*
* // Create the input and output ndarray-like objects:
* var condition = {
* 'dtype': 'uint8',
* 'data': cbuf,
* 'shape': shape,
* 'strides': sc,
* 'offset': oc,
* 'order': 'row-major'
* };
* var x = {
* 'dtype': 'float64',
* 'data': xbuf,
* 'shape': shape,
* 'strides': sx,
* 'offset': ox,
* 'order': 'row-major'
* };
* var y = {
* 'dtype': 'float64',
* 'data': ybuf,
* 'shape': shape,
* 'strides': sy,
* 'offset': oy,
* 'order': 'row-major'
* };
* var out = {
* 'dtype': 'float64',
* 'data': obuf,
* 'shape': shape,
* 'strides': so,
* 'offset': oo,
* 'order': 'row-major'
* };
*
* // Apply the condition:
* where( [ condition, x, y, out ] );
*
* console.log( out.data );
* // => <Float64Array>[ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ]
*/
function where( arrays ) { // eslint-disable-line max-statements
var ndims;
var cmmv;
var xmmv;
var ymmv;
var ommv;
var shc;
var shx;
var shy;
var sho;
var ioc;
var iox;
var ioy;
var ioo;
var len;
var ord;
var sc;
var sx;
var sy;
var so;
var oc;
var ox;
var oy;
var oo;
var ns;
var c;
var x;
var y;
var o;
var d;
var i;
// Unpack the ndarrays and standardize ndarray meta data:
c = ndarray2object( arrays[ 0 ] );
x = ndarray2object( arrays[ 1 ] );
y = ndarray2object( arrays[ 2 ] );
o = ndarray2object( arrays[ 3 ] );
// Verify that the input and output arrays have the same number of dimensions...
shc = c.shape;
shx = x.shape;
shy = y.shape;
sho = o.shape;
ndims = shc.length;
if ( ndims !== shx.length || ndims !== shy.length || ndims !== sho.length ) { // eslint-disable-line max-len
throw new Error( format( 'invalid arguments. Arrays must have the same number of dimensions (i.e., same rank). ndims(c) == %d. ndims(x) == %d. ndims(y) == %d. ndims(o) == %d.', shc.length, shx.length, shy.length, sho.length ) );
}
if ( !isBooleanArray( c.data ) && !isUint8Array( c.data ) ) {
throw new TypeError( format( 'invalid arguments. Condition array must be a boolean or uint8 ndarray. c.dtype=%s', c.dtype ) );
}
// Always reinterpret condition array to uint8
if ( isBooleanArray( c.data ) ) {
c = boolean2uint8( c );
}
// Check for known array types which can be reinterpreted for better iteration performance...
if ( isBooleanArray( x.data ) && isBooleanArray( y.data ) && isBooleanArray( o.data ) ) { // eslint-disable-line max-len
x = boolean2uint8( x );
y = boolean2uint8( y );
o = boolean2uint8( o );
} else if ( isComplexArray( x.data ) && isComplexArray( y.data ) && isComplexArray( o.data ) ) { // eslint-disable-line max-len
x = complex2real( x );
y = complex2real( y );
o = complex2real( o );
c.shape.push( 2 ); // real and imaginary components
c.strides.push( 0 ); // broadcast
}
// 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)...
else if ( isComplexDataType( o.dtype ) ) {
if ( isRealDataType( x.dtype ) ) {
x.accessorProtocol = true;
x.accessors[ 0 ] = castReturn( x.accessors[ 0 ], 2, complexCtors( String( o.dtype ) ) ); // eslint-disable-line max-len
}
if ( isRealDataType( y.dtype ) ) {
y.accessorProtocol = true;
y.accessors[ 0 ] = castReturn( y.accessors[ 0 ], 2, complexCtors( String( o.dtype ) ) ); // eslint-disable-line max-len
}
}
shc = c.shape;
shx = x.shape;
shy = y.shape;
sho = o.shape;
ndims = shc.length;
// Determine whether we can avoid iteration altogether...
if ( ndims === 0 ) {
if ( hasAccessors( c, x, y, o ) ) {
return ACCESSOR_WHERE[ ndims ]( c, x, y, o );
}
return WHERE[ ndims ]( c, x, y, o );
}
// Verify that the input and output arrays have the same dimensions...
len = 1; // number of elements
ns = 0; // number of singleton dimensions
for ( i = 0; i < ndims; i++ ) {
d = shc[ i ];
if ( d !== shx[ i ] || d !== shy[ i ] || d !== sho[ i ] ) {
throw new Error( 'invalid arguments. Arrays must have the same shape.' );
}
// Note that, if one of the dimensions is `0`, the length will be `0`...
len *= d;
// Check whether the current dimension is a singleton dimension...
if ( d === 1 ) {
ns += 1;
}
}
// Check whether we were provided empty ndarrays...
if ( len === 0 ) {
return;
}
// Determine whether the ndarrays are one-dimensional and thus readily translate to one-dimensional strided arrays...
if ( ndims === 1 ) {
if ( hasAccessors( c, x, y, o ) ) {
return ACCESSOR_WHERE[ ndims ]( c, x, y, o );
}
return WHERE[ ndims ]( c, x, y, o );
}
sc = c.strides;
sx = x.strides;
sy = y.strides;
so = o.strides;
// Determine whether the ndarray has only **one** non-singleton dimension (e.g., ndims=4, shape=[10,1,1,1]) so that we can treat the ndarrays as being equivalent to one-dimensional strided arrays...
if ( ns === ndims-1 ) {
// Get the index of the non-singleton dimension...
for ( i = 0; i < ndims; i++ ) {
if ( shc[ i ] !== 1 ) {
break;
}
}
c.shape = [ shc[i] ];
x.shape = c.shape;
y.shape = c.shape;
o.shape = c.shape;
c.strides = [ sc[i] ];
x.strides = [ sx[i] ];
y.strides = [ sy[i] ];
o.strides = [ so[i] ];
if ( hasAccessors( c, x, y, o ) ) {
return ACCESSOR_WHERE[ 1 ]( c, x, y, o );
}
return WHERE[ 1 ]( c, x, y, o );
}
ioc = iterationOrder( sc ); // +/-1
iox = iterationOrder( sx ); // +/-1
ioy = iterationOrder( sy ); // +/-1
ioo = iterationOrder( so ); // +/-1
// Determine whether we can avoid blocked iteration...
ord = strides2order( sc );
if ( ioc !== 0 && iox !== 0 && ioy !== 0 && ioo !== 0 && ord === strides2order( sx ) && ord === strides2order( sy ) && ord === strides2order( so ) ) { // eslint-disable-line max-len
// Determine the minimum and maximum linear indices which are accessible by the array views:
cmmv = minmaxViewBufferIndex( shc, sc, c.offset );
xmmv = minmaxViewBufferIndex( shx, sx, x.offset );
ymmv = minmaxViewBufferIndex( shy, sy, y.offset );
ommv = minmaxViewBufferIndex( sho, so, o.offset );
// Determine whether we can ignore shape (and strides) and treat the ndarrays as linear one-dimensional strided arrays...
if ( len === ( cmmv[1]-cmmv[0]+1 ) && len === ( xmmv[1]-xmmv[0]+1 ) && len === ( ymmv[1]-ymmv[0]+1 ) && len === ( ommv[1]-ommv[0]+1 ) ) { // eslint-disable-line max-len
// Note: the above is equivalent to @stdlib/ndarray/base/assert/is-contiguous, but in-lined so we can retain computed values...
if ( ioc === 1 ) {
oc = cmmv[ 0 ];
} else {
oc = cmmv[ 1 ];
}
if ( iox === 1 ) {
ox = xmmv[ 0 ];
} else {
ox = xmmv[ 1 ];
}
if ( ioy === 1 ) {
oy = ymmv[ 0 ];
} else {
oy = ymmv[ 1 ];
}
if ( ioo === 1 ) {
oo = ommv[ 0 ];
} else {
oo = ommv[ 1 ];
}
c.shape = [ len ];
x.shape = c.shape;
y.shape = c.shape;
o.shape = c.shape;
c.strides = [ ioc ];
x.strides = [ iox ];
y.strides = [ ioy ];
o.strides = [ ioo ];
c.offset = oc;
x.offset = ox;
y.offset = oy;
o.offset = oo;
if ( hasAccessors( c, x, y, o ) ) {
return ACCESSOR_WHERE[ 1 ]( c, x, y, o );
}
return WHERE[ 1 ]( c, x, y, o );
}
// At least one ndarray is non-contiguous, so we cannot directly use one-dimensional array functionality...
// Determine whether we can use simple nested loops...
if ( ndims <= MAX_DIMS ) {
// 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...
if ( hasAccessors( c, x, y, o ) ) {
return ACCESSOR_WHERE[ ndims ]( c, x, y, o, ord === 1 );
}
return WHERE[ ndims ]( c, x, y, o, ord === 1 );
}
// Fall-through to blocked iteration...
}
// At this point, we're either dealing with non-contiguous n-dimensional arrays, high dimensional n-dimensional arrays, and/or arrays having differing memory layouts, so our only hope is that we can still perform blocked iteration...
// Determine whether we can perform blocked iteration...
if ( ndims <= MAX_DIMS ) {
if ( hasAccessors( c, x, y, o ) ) {
return BLOCKED_ACCESSOR_WHERE[ ndims-2 ]( c, x, y, o );
}
return BLOCKED_WHERE[ ndims-2 ]( c, x, y, o );
}
// Fall-through to linear view iteration without regard for how data is stored in memory (i.e., take the slow path)...
if ( hasAccessors( c, x, y, o ) ) {
return accessorwherend( c, x, y, o );
}
wherend( c, x, y, o );
}
// EXPORTS //
module.exports = where;
|