Skip to content

Commit 6134859

Browse files
committed
fix: flatten nested arrays in (co)lexicographic order
This commit addresses a bug in flattening behavior. Prior to this commit, if provided a nested array, the implementation would flatten in lexicographic order (i.e., innermost nested array dimensions iterate fastest). However, this lead to surprising behavior when the desired storage order was column-major in which an ndarray did not match the visual layout of the input nested arrays. This commit fixes this issue and matches NumPy behavior in which nested arrays are flattened such that the storage order matches the desired output array storage order. Ref: #268
1 parent 0342d6f commit 6134859

File tree

1 file changed

+1
-1
lines changed
  • lib/node_modules/@stdlib/ndarray/array/lib

1 file changed

+1
-1
lines changed

Diff for: lib/node_modules/@stdlib/ndarray/array/lib/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ function array() {
321321
}
322322
} else if ( buffer ) {
323323
if ( btype === 'generic' && opts.flatten ) {
324-
buffer = flatten( buffer, osh || arrayShape( buffer ), false );
324+
buffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' );
325325
}
326326
if ( buffer.length !== len ) {
327327
throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' );

0 commit comments

Comments
 (0)