Skip to content

Commit 803764c

Browse files
committed
fix: avoid flattening due to user callback
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 11c3ab2 commit 803764c

File tree

1 file changed

+6
-63
lines changed
  • lib/node_modules/@stdlib/ndarray/base/every-by/lib

1 file changed

+6
-63
lines changed

lib/node_modules/@stdlib/ndarray/base/every-by/lib/main.js

Lines changed: 6 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
// MODULES //
2222

2323
var iterationOrder = require( '@stdlib/ndarray/base/iteration-order' );
24-
var minmaxViewBufferIndex = require( '@stdlib/ndarray/base/minmax-view-buffer-index' );
2524
var ndarray2object = require( '@stdlib/ndarray/base/ndarraylike2object' );
25+
var numel = require( '@stdlib/ndarray/base/numel' );
2626
var blockedaccessorevery2d = require( './2d_blocked_accessors.js' );
2727
var blockedaccessorevery3d = require( './3d_blocked_accessors.js' );
2828
var blockedaccessorevery4d = require( './4d_blocked_accessors.js' );
@@ -138,7 +138,7 @@ var MAX_DIMS = EVERY.length - 1;
138138
*
139139
* @param {ArrayLikeObject<Object>} arrays - array-like object containing one input array
140140
* @param {Function} clbk - callback function
141-
* @param {thisArg} thisArg - callback execution context
141+
* @param {thisArg} [thisArg] - callback execution context
142142
* @returns {boolean} result
143143
*
144144
* @example
@@ -176,18 +176,11 @@ var MAX_DIMS = EVERY.length - 1;
176176
* // returns true
177177
*/
178178
function everyBy( arrays, clbk, thisArg ) {
179-
var isCmplx;
180179
var ndims;
181-
var xmmv;
182180
var shx;
183181
var iox;
184182
var len;
185-
var sx;
186-
var ox;
187-
var ns;
188183
var x;
189-
var d;
190-
var i;
191184

192185
// Unpack the ndarray and standardize ndarray meta data:
193186
x = ndarray2object( arrays[ 0 ] );
@@ -201,20 +194,9 @@ function everyBy( arrays, clbk, thisArg ) {
201194
}
202195
return EVERY[ ndims ]( x, clbk, thisArg );
203196
}
204-
// Compute the number of elements and the number of singleton dimensions...
205-
len = 1; // number of elements
206-
ns = 0; // number of singleton dimensions
207-
for ( i = 0; i < ndims; i++ ) {
208-
d = shx[ i ];
197+
// Compute the number of elements:
198+
len = numel( shx );
209199

210-
// Note that, if one of the dimensions is `0`, the length will be `0`...
211-
len *= d;
212-
213-
// Check whether the current dimension is a singleton dimension...
214-
if ( d === 1 ) {
215-
ns += 1;
216-
}
217-
}
218200
// Check whether we were provided an empty ndarray...
219201
if ( len === 0 ) {
220202
return true;
@@ -226,48 +208,11 @@ function everyBy( arrays, clbk, thisArg ) {
226208
}
227209
return EVERY[ ndims ]( x, clbk, thisArg );
228210
}
229-
sx = x.strides;
230-
231-
// Determine whether the ndarray has only **one** non-singleton dimension (e.g., ndims=4, shape=[10,1,1,1]) so that we can treat an ndarray as being equivalent to a one-dimensional strided array...
232-
if ( ns === ndims-1 ) {
233-
// Get the index of the non-singleton dimension...
234-
for ( i = 0; i < ndims; i++ ) {
235-
if ( shx[ i ] !== 1 ) {
236-
break;
237-
}
238-
}
239-
x.shape = [ shx[i] ];
240-
x.strides = [ sx[i] ];
241-
if ( x.accessorProtocol ) {
242-
return ACCESSOR_EVERY[ 1 ]( x, clbk, thisArg );
243-
}
244-
return EVERY[ 1 ]( x, clbk, thisArg );
245-
}
246-
iox = iterationOrder( sx ); // +/-1
211+
// Determine the iteration order:
212+
iox = iterationOrder( x.strides ); // +/-1
247213

248214
// Determine whether we can avoid blocked iteration...
249215
if ( iox !== 0 ) {
250-
// Determine the minimum and maximum linear indices which are accessible by the array view:
251-
xmmv = minmaxViewBufferIndex( shx, sx, x.offset );
252-
253-
// Determine whether we can ignore shape (and strides) and treat the ndarray as a linear one-dimensional strided array...
254-
if ( len === ( xmmv[1]-xmmv[0]+1 ) || ( isCmplx && len*2 === ( xmmv[1]-xmmv[0]+1 ) ) ) { // eslint-disable-line max-len
255-
// Note: the above is equivalent to @stdlib/ndarray/base/assert/is-contiguous, but in-lined so we can retain computed values...
256-
if ( iox === 1 ) {
257-
ox = xmmv[ 0 ];
258-
} else {
259-
ox = xmmv[ 1 ];
260-
}
261-
x.shape = [ len ];
262-
x.strides = [ ( isCmplx ) ? iox*2 : iox ];
263-
x.offset = ox;
264-
if ( x.accessorProtocol ) {
265-
return ACCESSOR_EVERY[ 1 ]( x, clbk, thisArg );
266-
}
267-
return EVERY[ 1 ]( x, clbk, thisArg );
268-
}
269-
// The ndarray is non-contiguous, so we cannot directly use one-dimensional array functionality...
270-
271216
// Determine whether we can use simple nested loops...
272217
if ( ndims <= MAX_DIMS ) {
273218
// So long as iteration 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...
@@ -278,8 +223,6 @@ function everyBy( arrays, clbk, thisArg ) {
278223
}
279224
// Fall-through to blocked iteration...
280225
}
281-
// At this point, we're either dealing with a non-contiguous n-dimensional array or a high dimensional n-dimensional array, so our only hope is that we can still perform blocked iteration...
282-
283226
// Determine whether we can perform blocked iteration...
284227
if ( ndims <= MAX_DIMS ) {
285228
if ( x.accessorProtocol ) {

0 commit comments

Comments
 (0)