Skip to content

Commit 0d360b3

Browse files
committed
feat: return index array as part of the results object
1 parent 8a64351 commit 0d360b3

File tree

6 files changed

+33
-1
lines changed

6 files changed

+33
-1
lines changed

lib/node_modules/@stdlib/ndarray/base/unary-loop-interchange-order/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ The function returns an object having the following properties:
6464
- **sh**: ordered dimensions.
6565
- **sx**: input array strides sorted in loop order.
6666
- **sy**: output array strides sorted in loop order.
67+
- **idx**: dimension indices sorted in loop order.
6768

6869
For all returned arrays, the first element corresponds to the innermost loop, and the last element corresponds to the outermost loop.
6970

lib/node_modules/@stdlib/ndarray/base/unary-loop-interchange-order/docs/repl.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- sh: ordered dimensions.
88
- sx: input array strides sorted in loop order.
99
- sy: output array strides sorted in loop order.
10+
- idx: dimension indices sorted in loop order.
1011

1112
For all returned arrays, the first element corresponds to the innermost
1213
loop, and the last element corresponds to the outermost loop.
@@ -39,6 +40,9 @@
3940
out.sy: Array<integer>
4041
Output array strides sorted in loop order.
4142

43+
out.idx: Array<integer>
44+
Dimension indices sorted in loop order.
45+
4246
Examples
4347
--------
4448
> var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] );

lib/node_modules/@stdlib/ndarray/base/unary-loop-interchange-order/docs/types/index.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ interface LoopOrderObject {
4040
* Output array strides sorted in loop order.
4141
*/
4242
sy: Array<number>;
43+
44+
/**
45+
* Dimension indices sorted in loop order.
46+
*/
47+
idx: Array<number>;
4348
}
4449

4550
/**
@@ -52,6 +57,7 @@ interface LoopOrderObject {
5257
* - **sh**: dimensions sorted in loop order.
5358
* - **sx**: input ndarray strides sorted in loop order.
5459
* - **sy**: output ndarray strides sorted in loop order.
60+
* - **idx**: dimension indices sorted in loop order.
5561
*
5662
* - When iterating over the elements of a multi-dimensional array, accessing elements which are closer in memory can improve performance. To this end, loop interchange is a technique used in loop nest optimization to improve locality of reference and take advantage of CPU cache.
5763
*
@@ -83,6 +89,9 @@ interface LoopOrderObject {
8389
*
8490
* var ssy = o.sy;
8591
* // returns [ 6, -2, 1 ]
92+
*
93+
* var idx = o.idx;
94+
* // returns [ 2, 1, 0 ]
8695
*/
8796
declare function unaryLoopOrder( shape: ArrayLike<number>, stridesX: ArrayLike<number>, stridesY: ArrayLike<number> ): LoopOrderObject;
8897

lib/node_modules/@stdlib/ndarray/base/unary-loop-interchange-order/lib/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
*
4343
* var ssy = o.sy;
4444
* // returns [ 6, -2, 1 ]
45+
*
46+
* var idx = o.idx;
47+
* // returns [ 2, 1, 0 ]
4548
*/
4649

4750
// MODULES //

lib/node_modules/@stdlib/ndarray/base/unary-loop-interchange-order/lib/main.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var sort2ins = require( './sort2ins.js' );
3838
* - **sh**: dimensions sorted in loop order.
3939
* - **sx**: input ndarray strides sorted in loop order.
4040
* - **sy**: output ndarray strides sorted in loop order.
41+
* - **idx**: dimension indices sorted in loop order.
4142
*
4243
* @param {NonNegativeIntegerArray} sh - array dimensions
4344
* @param {IntegerArray} sx - input array stride lengths
@@ -61,6 +62,9 @@ var sort2ins = require( './sort2ins.js' );
6162
*
6263
* var ssy = o.sy;
6364
* // returns [ 6, -2, 1 ]
65+
*
66+
* var idx = o.idx;
67+
* // returns [ 2, 1, 0 ]
6468
*/
6569
function loopOrder( sh, sx, sy ) {
6670
var idx;
@@ -79,7 +83,8 @@ function loopOrder( sh, sx, sy ) {
7983
return {
8084
'sh': sh,
8185
'sx': sx,
82-
'sy': sy
86+
'sy': sy,
87+
'idx': idx
8388
};
8489
}
8590

lib/node_modules/@stdlib/ndarray/base/unary-loop-interchange-order/test/test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ tape( 'the function returns loop interchange data (row-major)', function test( t
5757
t.strictEqual( isArray( o.sy ), true, 'returns expected value' );
5858
t.deepEqual( o.sy, [ 1, 2, -4 ], 'returns expected value' );
5959

60+
t.strictEqual( isArray( o.idx ), true, 'returns expected value' );
61+
t.deepEqual( o.idx, [ 2, 1, 0 ], 'returns expected value' );
62+
6063
t.end();
6164
});
6265

@@ -84,6 +87,9 @@ tape( 'the function returns loop interchange data (column-major)', function test
8487
t.strictEqual( isArray( o.sy ), true, 'returns expected value' );
8588
t.deepEqual( o.sy, [ -1, 4, 8 ], 'returns expected value' );
8689

90+
t.strictEqual( isArray( o.idx ), true, 'returns expected value' );
91+
t.deepEqual( o.idx, [ 0, 1, 2 ], 'returns expected value' );
92+
8793
t.end();
8894
});
8995

@@ -111,6 +117,9 @@ tape( 'the function returns loop interchange data (mixed order)', function test(
111117
t.strictEqual( isArray( o.sy ), true, 'returns expected value' );
112118
t.deepEqual( o.sy, [ -8, -4, 1 ], 'returns expected value' );
113119

120+
t.strictEqual( isArray( o.idx ), true, 'returns expected value' );
121+
t.deepEqual( o.idx, [ 2, 1, 0 ], 'returns expected value' );
122+
114123
t.end();
115124
});
116125

@@ -119,5 +128,6 @@ tape( 'if provided empty arrays, the function returns empty arrays', function te
119128
t.deepEqual( o.sh, [], 'returns expected value' );
120129
t.deepEqual( o.sx, [], 'returns expected value' );
121130
t.deepEqual( o.sy, [], 'returns expected value' );
131+
t.deepEqual( o.idx, [], 'returns expected value' );
122132
t.end();
123133
});

0 commit comments

Comments
 (0)