Skip to content

Commit 01bc84c

Browse files
committed
refactor: use array utility
--- 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: 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 997af88 commit 01bc84c

File tree

1 file changed

+3
-27
lines changed
  • lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-dispatch/lib

1 file changed

+3
-27
lines changed

lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-dispatch/lib/main.js

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ var takeIndexed = require( '@stdlib/array/base/take-indexed' );
5151
var zeroTo = require( '@stdlib/array/base/zero-to' );
5252
var join = require( '@stdlib/array/base/join' );
5353
var copy = require( '@stdlib/array/base/copy' );
54+
var insertAt = require( '@stdlib/array/base/insert-at' );
5455
var everyBy = require( '@stdlib/array/base/every-by' );
5556
var objectAssign = require( '@stdlib/object/assign' );
5657
var format = require( '@stdlib/string/format' );
@@ -79,31 +80,6 @@ function types2enums( types ) {
7980
return out;
8081
}
8182

82-
/**
83-
* Reorders a list of ndarrays such that the output ndarray is the second ndarray argument when passing along to a resolved lower-level strided function.
84-
*
85-
* @private
86-
* @param {Array<ndarray>} arrays - list of input ndarrays
87-
* @param {ndarray} output - output ndarray
88-
* @returns {Array<ndarray>} reordered list
89-
*/
90-
function reorder( arrays, output ) { // TODO: consider replacing with an `array/base/*` utility which expands an input array by inserting a specified value at a specified index and returns a new array
91-
var out;
92-
var i;
93-
var j;
94-
95-
out = [];
96-
for ( i = 0, j = 0; i <= arrays.length; i++ ) {
97-
if ( i === 1 ) {
98-
out.push( output );
99-
} else {
100-
out.push( arrays[ j ] );
101-
j += 1;
102-
}
103-
}
104-
return out;
105-
}
106-
10783

10884
// MAIN //
10985

@@ -353,7 +329,7 @@ setReadOnly( UnaryStrided1dDispatch.prototype, 'apply', function apply( x ) {
353329
f = this._table.default;
354330
}
355331
// Perform the reduction:
356-
unaryReduceStrided1d( f, reorder( args, y ), opts.dims );
332+
unaryReduceStrided1d( f, insertAt( args, 1, y ), opts.dims );
357333

358334
// Check whether we need to reinsert singleton dimensions which can be useful for broadcasting the returned output array to the shape of the original input array...
359335
if ( opts.keepdims ) {
@@ -504,7 +480,7 @@ setReadOnly( UnaryStrided1dDispatch.prototype, 'assign', function assign( x ) {
504480
f = this._table.default;
505481
}
506482
// Perform the reduction:
507-
unaryReduceStrided1d( f, reorder( args, y ), opts.dims ); // note: we assume that this lower-level function handles further validation of the output ndarray (e.g., expected shape, etc)
483+
unaryReduceStrided1d( f, insertAt( args, 1, y ), opts.dims ); // note: we assume that this lower-level function handles further validation of the output ndarray (e.g., expected shape, etc)
508484

509485
return y;
510486
});

0 commit comments

Comments
 (0)