Skip to content

Commit 351db28

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 01bc84c commit 351db28

File tree

1 file changed

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

1 file changed

+3
-27
lines changed

lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-by/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

@@ -402,7 +378,7 @@ setReadOnly( UnaryStrided1dDispatchBy.prototype, 'apply', function apply( x ) {
402378
f = this._table.default;
403379
}
404380
// Perform the reduction:
405-
unaryReduceStrided1dBy( f, reorder( args, y ), opts.dims, clbk, thisArg );
381+
unaryReduceStrided1dBy( f, insertAt( args, 1, y ), opts.dims, clbk, thisArg );
406382

407383
// 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...
408384
if ( opts.keepdims ) {
@@ -589,7 +565,7 @@ setReadOnly( UnaryStrided1dDispatchBy.prototype, 'assign', function assign( x )
589565
f = this._table.default;
590566
}
591567
// Perform the reduction:
592-
unaryReduceStrided1dBy( f, reorder( args, y ), opts.dims, clbk, thisArg ); // note: we assume that this lower-level function handles further validation of the output ndarray (e.g., expected shape, etc)
568+
unaryReduceStrided1dBy( f, insertAt( args, 1, y ), opts.dims, clbk, thisArg ); // note: we assume that this lower-level function handles further validation of the output ndarray (e.g., expected shape, etc)
593569

594570
return y;
595571
});

0 commit comments

Comments
 (0)