Skip to content

Commit 355f267

Browse files
committed
test: add tests
--- 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 129673d commit 355f267

File tree

2 files changed

+670
-118
lines changed

2 files changed

+670
-118
lines changed

lib/node_modules/@stdlib/ndarray/flatten-by/lib/main.js

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ var COL_MAJOR = 'column-major';
8181
* // returns [ 2.0, 4.0, 6.0, 8.0, 10.0, 12.0 ]
8282
*/
8383
function flattenBy( x, options, fcn, thisArg ) {
84+
var hasOpts;
8485
var nargs;
8586
var view;
8687
var opts;
@@ -96,6 +97,7 @@ function flattenBy( x, options, fcn, thisArg ) {
9697
}
9798
nargs = arguments.length;
9899
xsh = getShape( x );
100+
hasOpts = false;
99101

100102
// Define default options:
101103
opts = {
@@ -113,46 +115,50 @@ function flattenBy( x, options, fcn, thisArg ) {
113115
if ( !isPlainObject( options ) ) {
114116
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
115117
}
118+
hasOpts = true;
116119
cb = fcn;
117120
}
118121
} else { // Case: flattenBy( x, options, fcn, thisArg )
119122
if ( !isPlainObject( options ) ) {
120123
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
121124
}
125+
hasOpts = true;
122126
cb = fcn;
123127
ctx = thisArg;
124128
}
125129
if ( !isFunction( cb ) ) {
126130
throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', cb ) );
127131
}
128-
if ( hasOwnProp( options, 'depth' ) ) {
129-
if ( !isNonNegativeInteger( options.depth ) ) {
130-
throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', options.depth ) );
132+
if ( hasOpts ) {
133+
if ( hasOwnProp( options, 'depth' ) ) {
134+
if ( !isNonNegativeInteger( options.depth ) ) {
135+
throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', options.depth ) );
136+
}
137+
opts.depth = options.depth;
131138
}
132-
opts.depth = options.depth;
133-
}
134-
if ( hasOwnProp( options, 'order' ) ) {
135-
if ( options.order === 'any' ) {
136-
// When 'any', we want to flatten according to the physical layout of the data in memory...
137-
o = strides2order( getStrides( x ) );
138-
if ( o === 1 ) {
139-
// Data is currently arranged in row-major order:
140-
opts.order = ROW_MAJOR;
141-
} else if ( o === 2 ) {
142-
// Data is currently arranged in column-major order:
143-
opts.order = COL_MAJOR;
144-
} else { // o === 0 || o === 3 (i.e., neither row- nor column-major || both row- and column-major
145-
// When the data is either both row- and column-major (e.g., a one-dimensional ndarray) or neither row- nor column-major (e.g., unordered strides), fallback to flattening according to the stated order of the input ndarray:
139+
if ( hasOwnProp( options, 'order' ) ) {
140+
if ( options.order === 'any' ) {
141+
// When 'any', we want to flatten according to the physical layout of the data in memory...
142+
o = strides2order( getStrides( x ) );
143+
if ( o === 1 ) {
144+
// Data is currently arranged in row-major order:
145+
opts.order = ROW_MAJOR;
146+
} else if ( o === 2 ) {
147+
// Data is currently arranged in column-major order:
148+
opts.order = COL_MAJOR;
149+
} else { // o === 0 || o === 3 (i.e., neither row- nor column-major || both row- and column-major
150+
// When the data is either both row- and column-major (e.g., a one-dimensional ndarray) or neither row- nor column-major (e.g., unordered strides), fallback to flattening according to the stated order of the input ndarray:
151+
opts.order = getOrder( x );
152+
}
153+
} else if ( options.order === 'same' ) {
154+
// When 'same', we want to flatten according to the stated order of the input ndarray:
146155
opts.order = getOrder( x );
156+
} else if ( isOrder( options.order ) ) {
157+
// When provided a specific order, flatten according to that order regardless of the order of the input ndarray:
158+
opts.order = options.order;
159+
} else {
160+
throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );
147161
}
148-
} else if ( options.order === 'same' ) {
149-
// When 'same', we want to flatten according to the stated order of the input ndarray:
150-
opts.order = getOrder( x );
151-
} else if ( isOrder( options.order ) ) {
152-
// When provided a specific order, flatten according to that order regardless of the order of the input ndarray:
153-
opts.order = options.order;
154-
} else {
155-
throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );
156162
}
157163
}
158164
// Create an output ndarray having contiguous memory:

0 commit comments

Comments
 (0)