Skip to content

Commit ece17b8

Browse files
committed
Auto-generated commit
1 parent 19d815b commit ece17b8

File tree

3 files changed

+153
-70
lines changed

3 files changed

+153
-70
lines changed

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,28 @@
112112

113113
<!-- /.package -->
114114

115+
<section class="package" id="ndarray-base-map-unreleased">
116+
117+
#### [@stdlib/ndarray/base/map](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/map)
118+
119+
<details>
120+
121+
<section class="bug-fixes">
122+
123+
##### Bug Fixes
124+
125+
- [`b4502fb`](https://github.com/stdlib-js/stdlib/commit/b4502fbc4da03910f86c66e68b53e93e99e3e933) - remove perf logic in order to ensure expected indices in callback
126+
127+
</section>
128+
129+
<!-- /.bug-fixes -->
130+
131+
</details>
132+
133+
</section>
134+
135+
<!-- /.package -->
136+
115137
<section class="package" id="ndarray-iter-unreleased">
116138

117139
#### [@stdlib/ndarray/iter](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter)
@@ -226,6 +248,8 @@ A total of 3 people contributed to this release. Thank you to the following cont
226248

227249
<details>
228250

251+
- [`b4502fb`](https://github.com/stdlib-js/stdlib/commit/b4502fbc4da03910f86c66e68b53e93e99e3e933) - **fix:** remove perf logic in order to ensure expected indices in callback _(by Athan Reines)_
252+
- [`59814ef`](https://github.com/stdlib-js/stdlib/commit/59814ef8589df3b9792a05f4ca46dcb92c9782e4) - **test:** add argument tests _(by Athan Reines)_
229253
- [`2825b42`](https://github.com/stdlib-js/stdlib/commit/2825b42e8cd7483d15dfed1c6b389bfcb86d7ca0) - **docs:** update related packages sections [(#3898)](https://github.com/stdlib-js/stdlib/pull/3898) _(by stdlib-bot)_
230254
- [`a299630`](https://github.com/stdlib-js/stdlib/commit/a299630d08a49ba51c6e3501fbd7d215338ca23a) - **fix:** avoid potential external mutation _(by Athan Reines)_
231255
- [`2d9de13`](https://github.com/stdlib-js/stdlib/commit/2d9de13da6f54c36452274c5179e1354c7be3f34) - **docs:** fix description _(by Athan Reines)_

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( './../../../base/iteration-order' );
24-
var minmaxViewBufferIndex = require( './../../../base/minmax-view-buffer-index' );
2524
var ndarray2object = require( './../../../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 ) {

map/test/test.js

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,3 +607,129 @@ tape( 'the function supports providing a callback execution context (options)',
607607
return z * 10.0;
608608
}
609609
});
610+
611+
tape( 'the function invokes a provided callback with three arguments (row-major)', function test( t ) {
612+
var expected;
613+
var indices;
614+
var values;
615+
var arrays;
616+
var ord;
617+
var sh;
618+
var st;
619+
var dt;
620+
var o;
621+
var x;
622+
var y;
623+
var i;
624+
625+
dt = 'float64';
626+
ord = 'row-major';
627+
sh = [ 2, 1, 2 ];
628+
st = shape2strides( sh, ord );
629+
o = strides2offset( sh, st );
630+
631+
x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord );
632+
633+
values = [];
634+
indices = [];
635+
arrays = [];
636+
y = map( x, scale );
637+
638+
expected = new Float64Array([
639+
10.0,
640+
10.0,
641+
10.0,
642+
10.0
643+
]);
644+
t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' );
645+
646+
expected = [
647+
[ 0, 0, 0 ],
648+
[ 0, 0, 1 ],
649+
[ 1, 0, 0 ],
650+
[ 1, 0, 1 ]
651+
];
652+
t.deepEqual( indices, expected, 'returns expected value' );
653+
654+
expected = [
655+
x,
656+
x,
657+
x,
658+
x
659+
];
660+
for ( i = 0; i < expected.length; i++ ) {
661+
t.strictEqual( arrays[ i ], expected[ i ], 'returns expected value' );
662+
}
663+
664+
t.end();
665+
666+
function scale( z, idx, arr ) {
667+
values.push( z );
668+
indices.push( idx );
669+
arrays.push( arr );
670+
return z * 10.0;
671+
}
672+
});
673+
674+
tape( 'the function invokes a provided callback with three arguments (column-major)', function test( t ) {
675+
var expected;
676+
var indices;
677+
var values;
678+
var arrays;
679+
var ord;
680+
var sh;
681+
var st;
682+
var dt;
683+
var o;
684+
var x;
685+
var y;
686+
var i;
687+
688+
dt = 'float64';
689+
ord = 'column-major';
690+
sh = [ 2, 1, 2 ];
691+
st = shape2strides( sh, ord );
692+
o = strides2offset( sh, st );
693+
694+
x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord );
695+
696+
values = [];
697+
indices = [];
698+
arrays = [];
699+
y = map( x, scale );
700+
701+
expected = new Float64Array([
702+
10.0,
703+
10.0,
704+
10.0,
705+
10.0
706+
]);
707+
t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' );
708+
709+
expected = [
710+
[ 0, 0, 0 ],
711+
[ 1, 0, 0 ],
712+
[ 0, 0, 1 ],
713+
[ 1, 0, 1 ]
714+
];
715+
t.deepEqual( indices, expected, 'returns expected value' );
716+
717+
expected = [
718+
x,
719+
x,
720+
x,
721+
x
722+
];
723+
for ( i = 0; i < expected.length; i++ ) {
724+
t.strictEqual( arrays[ i ], expected[ i ], 'returns expected value' );
725+
}
726+
727+
t.end();
728+
729+
function scale( z, idx, arr ) {
730+
values.push( z );
731+
indices.push( idx );
732+
arrays.push( arr );
733+
return z * 10.0;
734+
}
735+
});

0 commit comments

Comments
 (0)