Skip to content

Commit b4502fb

Browse files
committed
fix: remove perf logic in order to ensure expected indices in callback
1 parent 59814ef commit b4502fb

File tree

1 file changed

+3
-70
lines changed
  • lib/node_modules/@stdlib/ndarray/base/map/lib

1 file changed

+3
-70
lines changed

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

Lines changed: 3 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
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' );
2625
var blockedaccessormap2d = require( './2d_blocked_accessors.js' );
2726
var blockedaccessormap3d = require( './3d_blocked_accessors.js' );
@@ -191,18 +190,11 @@ var MAX_DIMS = MAP.length -1;
191190
*/
192191
function map( arrays, fcn, thisArg ) {
193192
var ndims;
194-
var xmmv;
195-
var ymmv;
196193
var shx;
197194
var shy;
198195
var iox;
199196
var ioy;
200197
var len;
201-
var sx;
202-
var sy;
203-
var ox;
204-
var oy;
205-
var ns;
206198
var x;
207199
var y;
208200
var i;
@@ -228,19 +220,13 @@ function map( arrays, fcn, thisArg ) {
228220
}
229221
// Verify that the input and output arrays have the same dimensions...
230222
len = 1; // number of elements
231-
ns = 0; // number of singleton dimensions
232223
for ( i = 0; i < ndims; i++ ) {
233224
d = shx[ i ];
234225
if ( d !== shy[ i ] ) {
235226
throw new Error( 'invalid arguments. Array must have the same shape.' );
236227
}
237228
// Note that, if one of the dimensions is `0`, the length will be `0`...
238229
len *= d;
239-
240-
// Check whether the current dimension is a singleton dimension...
241-
if ( d === 1 ) {
242-
ns += 1;
243-
}
244230
}
245231
// Check whether we were provided empty ndarrays...
246232
if ( len === 0 ) {
@@ -253,63 +239,12 @@ function map( arrays, fcn, thisArg ) {
253239
}
254240
return MAP[ ndims ]( x, y, fcn, thisArg );
255241
}
256-
257-
sx = x.strides;
258-
sy = y.strides;
259-
260-
// 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...
261-
if ( ns === ndims-1 ) {
262-
// Get the index of the non-singleton dimension...
263-
for ( i = 0; i < ndims; i++ ) {
264-
if ( shx[ i ] !== 1 ) {
265-
break;
266-
}
267-
}
268-
x.shape = [ shx[i] ];
269-
y.shape = x.shape;
270-
x.strides = [ sx[i] ];
271-
y.strides = [ sy[i] ];
272-
if ( x.accessorProtocol || y.accessorProtocol ) {
273-
return ACCESSOR_MAP[ 1 ]( x, y, fcn, thisArg );
274-
}
275-
return MAP[ 1 ]( x, y, fcn, thisArg );
276-
}
277-
278-
iox = iterationOrder( sx ); // +/-1
279-
ioy = iterationOrder( sy ); // +/-1
242+
// Determine iteration order:
243+
iox = iterationOrder( x.strides ); // +/-1
244+
ioy = iterationOrder( y.strides ); // +/-1
280245

281246
// Determine whether we can avoid blocked iteration...
282247
if ( iox !== 0 && ioy !== 0 && iox === ioy ) {
283-
// Determine the minimum and maximum linear indices which are accessible by the array views:
284-
xmmv = minmaxViewBufferIndex( shx, sx, x.offset );
285-
ymmv = minmaxViewBufferIndex( shy, sy, y.offset );
286-
287-
// Determine whether we can ignore shape (and strides) and treat the ndarrays as linear one-dimensional strided arrays...
288-
if ( len === ( xmmv[1]-xmmv[0]+1 ) && len === ( ymmv[1]-ymmv[0]+1 ) ) {
289-
// Note: the above is equivalent to @stdlib/ndarray/base/assert/is-contiguous, but in-lined so we can retain computed values...
290-
if ( iox === 1 ) {
291-
ox = xmmv[ 0 ];
292-
} else {
293-
ox = xmmv[ 1 ];
294-
}
295-
if ( ioy === 1 ) {
296-
oy = ymmv[ 0 ];
297-
} else {
298-
oy = ymmv[ 1 ];
299-
}
300-
x.shape = [ len ];
301-
y.shape = x.shape;
302-
x.strides = [ iox ];
303-
y.strides = [ ioy ];
304-
x.offset = ox;
305-
y.offset = oy;
306-
if ( x.accessorProtocol || y.accessorProtocol ) {
307-
return ACCESSOR_MAP[ 1 ]( x, y, fcn, thisArg );
308-
}
309-
return MAP[ 1 ]( x, y, fcn, thisArg );
310-
}
311-
// At least one ndarray is non-contiguous, so we cannot directly use one-dimensional array functionality...
312-
313248
// Determine whether we can use simple nested loops...
314249
if ( ndims <= MAX_DIMS ) {
315250
// 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...
@@ -320,8 +255,6 @@ function map( arrays, fcn, thisArg ) {
320255
}
321256
// Fall-through to blocked iteration...
322257
}
323-
// 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...
324-
325258
// Determine whether we can perform blocked iteration...
326259
if ( ndims <= MAX_DIMS ) {
327260
if ( x.accessorProtocol || y.accessorProtocol ) {

0 commit comments

Comments
 (0)