Skip to content

Commit 27ae143

Browse files
committed
fix: apply suggestions from code review
--- 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: passed - 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 048aacc commit 27ae143

2 files changed

Lines changed: 19 additions & 11 deletions

File tree

lib/node_modules/@stdlib/ndarray/base/unflatten/benchmark/benchmark.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var unflatten = require( './../lib' );
3232

3333
// MAIN //
3434

35-
bench( format( '%s::base_ndarray, 2d, row-major', pkg ), function benchmark( b ) {
35+
bench( format( '%s:ctor=base,ndims=2,order=row-major', pkg ), function benchmark( b ) {
3636
var strides;
3737
var values;
3838
var buffer;
@@ -75,7 +75,7 @@ bench( format( '%s::base_ndarray, 2d, row-major', pkg ), function benchmark( b )
7575
b.end();
7676
});
7777

78-
bench( format( '%s::ndarray, 2d, row-major', pkg ), function benchmark( b ) {
78+
bench( format( '%s:ctor=ndarray,ndims=2,order=row-major', pkg ), function benchmark( b ) {
7979
var strides;
8080
var values;
8181
var buffer;
@@ -118,7 +118,7 @@ bench( format( '%s::ndarray, 2d, row-major', pkg ), function benchmark( b ) {
118118
b.end();
119119
});
120120

121-
bench( format( '%s::base_ndarray, 2d, column-major', pkg ), function benchmark( b ) {
121+
bench( format( '%s:ctor=base,ndims=2,order=column-major', pkg ), function benchmark( b ) {
122122
var strides;
123123
var values;
124124
var buffer;
@@ -161,7 +161,7 @@ bench( format( '%s::base_ndarray, 2d, column-major', pkg ), function benchmark(
161161
b.end();
162162
});
163163

164-
bench( format( '%s::ndarray, 2d, column-major', pkg ), function benchmark( b ) {
164+
bench( format( '%s:ctor=ndarray,ndims=2,order=column-major', pkg ), function benchmark( b ) {
165165
var strides;
166166
var values;
167167
var buffer;

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
// MODULES //
2222

23-
var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' );
23+
var isRowMajorString = require( '@stdlib/ndarray/base/assert/is-row-major-string' );
24+
var strides2order = require( '@stdlib/ndarray/base/strides2order' );
2425
var normalizeIndex = require( '@stdlib/ndarray/base/normalize-index' );
2526
var getDType = require( '@stdlib/ndarray/base/dtype' );
2627
var getShape = require( '@stdlib/ndarray/base/shape' );
@@ -61,16 +62,23 @@ function unflatten( x, dim, sizes, writable ) {
6162
var sh;
6263
var st;
6364
var S2;
65+
var o;
6466
var d;
6567
var i;
6668

6769
sh = getShape( x, false );
6870
st = getStrides( x, false );
6971
ord = getOrder( x );
70-
isrm = isRowMajor( ord );
72+
o = strides2order( st );
73+
if ( o === 0 || o === 3 ) {
74+
// Fallback to stated layout when unable to infer the underlying physical layout:
75+
isrm = isRowMajorString( ord );
76+
} else {
77+
isrm = ( o === 1 );
78+
}
7179

7280
// Normalize the dimension to be unflattened:
73-
d = normalizeIndex( dim, sh.length - 1 );
81+
d = normalizeIndex( dim, sh.length-1 );
7482

7583
// Compute the output shape:
7684
shape = unflattenShape( sh, d, sizes );
@@ -90,13 +98,13 @@ function unflatten( x, dim, sizes, writable ) {
9098
// Compute strides for the unflattened dimensions...
9199
if ( isrm ) {
92100
strides[ d+S2-1 ] = st[ d ];
93-
for ( i = S2-2; i >= 0; i-- ) {
94-
strides[ d+i ] = strides[ d+i+1 ] * sizes[ i+1 ];
101+
for ( i = S2-1; i > 0; i-- ) {
102+
strides[ d+i-1 ] = strides[ d+i ] * sizes[ i ];
95103
}
96104
} else {
97105
strides[ d ] = st[ d ];
98-
for ( i = 1; i < S2; i++ ) {
99-
strides[ d+i ] = strides[ d+i-1 ] * sizes[ i-1 ];
106+
for ( i = 0; i < S2-1; i++ ) {
107+
strides[ d+i+1 ] = strides[ d+i ] * sizes[ i ];
100108
}
101109
}
102110
return new x.constructor( getDType( x ), getData( x ), shape, strides, getOffset( x ), ord, { // eslint-disable-line max-len

0 commit comments

Comments
 (0)