Skip to content

Commit 3ce09af

Browse files
committed
fix: ensure separate array instance for each memory layout
--- 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: passed - 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 974d32e commit 3ce09af

File tree

3 files changed

+71
-6
lines changed

3 files changed

+71
-6
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
var zeroTo = require( '@stdlib/array/base/zero-to' );
2424
var copy = require( '@stdlib/array/base/copy-indexed' );
2525
var take = require( '@stdlib/array/base/take-indexed' );
26-
var filled = require( '@stdlib/array/base/filled' );
2726
var strides2order = require( '@stdlib/ndarray/base/strides2order' );
2827
var sort2ins = require( './sort2ins.js' );
2928

@@ -97,7 +96,7 @@ function loopOrder( sh, sx, sy, sz ) {
9796
oz = strides2order( sz );
9897

9998
// Determine which array should be used to generate the loop order:
100-
tmp = filled( [], 4 );
99+
tmp = [ [], [], [], [] ];
101100
tmp[ ox ].push( sx );
102101
tmp[ oy ].push( sy );
103102
tmp[ oz ].push( sz );
@@ -132,9 +131,9 @@ function loopOrder( sh, sx, sy, sz ) {
132131

133132
// Permute the shape and array strides based on the sorted strides:
134133
sh = take( sh, idx );
135-
sx = ( sx === arr ) ? arr : take( sx, idx );
136-
sy = ( sy === arr ) ? arr : take( sy, idx );
137-
sz = ( sz === arr ) ? arr : take( sz, idx );
134+
sx = take( sx, idx );
135+
sy = take( sy, idx );
136+
sz = take( sz, idx );
138137

139138
return {
140139
'sh': sh,

lib/node_modules/@stdlib/ndarray/base/binary-loop-interchange-order/lib/sort2ins.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*
2828
* - The first array is sorted in increasing order according to absolute value.
2929
* - The algorithm has space complexity `O(1)` and worst case time complexity `O(N^2)`.
30-
* - The algorithm is efficient for small arrays (typically `N <= 20``) and is particularly efficient for sorting arrays which are already substantially sorted.
30+
* - The algorithm is efficient for small arrays (typically `N <= 20`) and is particularly efficient for sorting arrays which are already substantially sorted.
3131
* - The algorithm is **stable**, meaning that the algorithm does **not** change the order of array elements which are equal or equivalent.
3232
* - The input arrays are sorted in-place (i.e., the input arrays are mutated).
3333
*

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,72 @@ tape( 'the function returns loop interchange data (mixed order)', function test(
132132
t.end();
133133
});
134134

135+
tape( 'the function returns loop interchange data (mostly disorganized)', function test( t ) {
136+
var sh;
137+
var sx;
138+
var sy;
139+
var sz;
140+
var o;
141+
142+
sh = [ 4, 2, 2 ];
143+
sx = [ -2, 4, 1 ]; // disorganized
144+
sy = [ -4, 2, 1 ]; // row-major
145+
sz = [ -8, -2, 4 ]; // disorganized
146+
147+
o = loopOrder( sh, sx, sy, sz );
148+
149+
t.notEqual( o.sh, sh, 'returns new array' );
150+
t.strictEqual( isArray( o.sh ), true, 'returns expected value' );
151+
t.deepEqual( o.sh, [ 2, 2, 4 ], 'returns expected value' );
152+
153+
t.notEqual( o.sx, sx, 'returns new array' );
154+
t.strictEqual( isArray( o.sx ), true, 'returns expected value' );
155+
t.deepEqual( o.sx, [ 1, 4, -2 ], 'returns expected value' );
156+
157+
t.notEqual( o.sy, sy, 'returns new array' );
158+
t.strictEqual( isArray( o.sy ), true, 'returns expected value' );
159+
t.deepEqual( o.sy, [ 1, 2, -4 ], 'returns expected value' );
160+
161+
t.notEqual( o.sz, sz, 'returns new array' );
162+
t.strictEqual( isArray( o.sz ), true, 'returns expected value' );
163+
t.deepEqual( o.sz, [ 4, -2, -8 ], 'returns expected value' );
164+
165+
t.end();
166+
});
167+
168+
tape( 'the function returns loop interchange data (all disorganized)', function test( t ) {
169+
var sh;
170+
var sx;
171+
var sy;
172+
var sz;
173+
var o;
174+
175+
sh = [ 4, 2, 2 ];
176+
sx = [ -2, 4, 1 ]; // disorganized
177+
sy = [ 1, -4, 2 ]; // disorganized
178+
sz = [ -8, -2, 4 ]; // disorganized
179+
180+
o = loopOrder( sh, sx, sy, sz );
181+
182+
t.notEqual( o.sh, sh, 'returns new array' );
183+
t.strictEqual( isArray( o.sh ), true, 'returns expected value' );
184+
t.deepEqual( o.sh, [ 2, 4, 2 ], 'returns expected value' );
185+
186+
t.notEqual( o.sx, sx, 'returns new array' );
187+
t.strictEqual( isArray( o.sx ), true, 'returns expected value' );
188+
t.deepEqual( o.sx, [ 1, -2, 4 ], 'returns expected value' );
189+
190+
t.notEqual( o.sy, sy, 'returns new array' );
191+
t.strictEqual( isArray( o.sy ), true, 'returns expected value' );
192+
t.deepEqual( o.sy, [ 2, 1, -4 ], 'returns expected value' );
193+
194+
t.notEqual( o.sz, sz, 'returns new array' );
195+
t.strictEqual( isArray( o.sz ), true, 'returns expected value' );
196+
t.deepEqual( o.sz, [ 4, -8, -2 ], 'returns expected value' );
197+
198+
t.end();
199+
});
200+
135201
tape( 'if provided empty arrays, the function returns empty arrays', function test( t ) {
136202
var o = loopOrder( [], [], [], [] );
137203
t.deepEqual( o.sh, [], 'returns expected value' );

0 commit comments

Comments
 (0)