From f679f3ae03b935f0fd8e5e9af0835320852ac0ed Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 4 Jun 2025 20:18:50 +0000 Subject: [PATCH 01/16] feat: add unaryReduceStrided1dBy --- 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: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - 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 --- --- .../base/unary-reduce-strided1d-by/README.md | 276 +++++++++++ .../unary-reduce-strided1d-by/docs/repl.txt | 106 ++++ .../examples/index.js | 54 +++ .../base/unary-reduce-strided1d-by/lib/0d.js | 129 +++++ .../lib/0d_accessors.js | 136 ++++++ .../base/unary-reduce-strided1d-by/lib/1d.js | 184 +++++++ .../lib/1d_accessors.js | 196 ++++++++ .../base/unary-reduce-strided1d-by/lib/2d.js | 210 ++++++++ .../lib/2d_accessors.js | 218 +++++++++ .../lib/2d_blocked.js | 244 ++++++++++ .../lib/2d_blocked_accessors.js | 252 ++++++++++ .../lib/callback_wrapper.js | 72 +++ .../unary-reduce-strided1d-by/lib/factory.js | 124 +++++ .../lib/increment_offsets.js | 46 ++ .../unary-reduce-strided1d-by/lib/index.js | 151 ++++++ .../lib/initialize_array_views.js | 57 +++ .../unary-reduce-strided1d-by/lib/main.js | 453 ++++++++++++++++++ .../base/unary-reduce-strided1d-by/lib/nd.js | 196 ++++++++ .../lib/nd_accessors.js | 204 ++++++++ .../unary-reduce-strided1d-by/lib/offsets.js | 42 ++ .../lib/reshape_strategy.js | 260 ++++++++++ .../lib/set_view_offsets.js | 52 ++ .../unary-reduce-strided1d-by/package.json | 64 +++ .../unary-reduce-strided1d-by/test/test.js | 35 ++ 24 files changed, 3761 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/0d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/0d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/1d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/1d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/callback_wrapper.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/factory.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/increment_offsets.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/initialize_array_views.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/nd.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/nd_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/offsets.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/reshape_strategy.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/set_view_offsets.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/README.md b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/README.md new file mode 100644 index 000000000000..6422acb6eef6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/README.md @@ -0,0 +1,276 @@ + + +# unaryReduceStrided1dBy + +> Perform a reduction over a list of specified dimensions in an input ndarray via a one-dimensional strided array reduction function, according to a callback function and assign results to a provided output ndarray. + +
+ +
+ + + +
+ +## Usage + +```javascript +var unaryReduceStrided1dBy = require( '@stdlib/ndarray/base/unary-reduce-strided1d-by' ); +``` + +#### unaryReduceStrided1dBy( fcn, arrays, dims\[, options], clbk\[, thisArg] ) + +Performs a reduction over a list of specified dimensions in an input ndarray via a one-dimensional strided array reduction function, according to a callback function and assigns results to a provided output ndarray. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); + +// Define a callback function: +function clbk( value ) { + return value * 2.0; +} + +// Create data buffers: +var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); + +// Define the array shapes: +var xsh = [ 1, 3, 2, 2 ]; +var ysh = [ 1, 3 ]; + +// Define the array strides: +var sx = [ 12, 4, 2, 1 ]; +var sy = [ 3, 1 ]; + +// Define the index offsets: +var ox = 0; +var oy = 0; + +// Create an input ndarray-like object: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an output ndarray-like object: +var y = { + 'dtype': 'float64', + 'data': ybuf, + 'shape': ysh, + 'strides': sy, + 'offset': oy, + 'order': 'row-major' +}; + +// Perform a reduction: +unaryReduceStrided1dBy( maxBy, [ x, y ], [ 2, 3 ], clbk ); + +var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +// returns [ [ 8.0, 16.0, 24.0 ] ] +``` + +The function accepts the following arguments: + +- **fcn**: function which will be applied to a one-dimensional subarray and should reduce the subarray to a single scalar value. +- **arrays**: array-like object containing one input ndarray and one output ndarray, followed by any additional ndarray arguments. +- **dims**: list of dimensions over which to perform a reduction. +- **options**: function options which are passed through to `fcn` (_optional_). +- **clbk**: callback function. +- **thisArg**: callback execution context (_optional_). + +Each provided ndarray should be an object with the following properties: + +- **dtype**: data type. +- **data**: data buffer. +- **shape**: dimensions. +- **strides**: stride lengths. +- **offset**: index offset. +- **order**: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style). + +The invoked callback function is provided the following arguments: + +- **value**: input ndarray element. +- **indices**: current ndarray element indices. +- **arr**: the input ndarray. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); + +// Define a callback function: +function clbk( value ) { + this.count += 1; + return value * 2.0; +} + +// Create data buffers: +var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); + +// Define the array shapes: +var xsh = [ 1, 3, 2, 2 ]; +var ysh = [ 1, 3 ]; + +// Define the array strides: +var sx = [ 12, 4, 2, 1 ]; +var sy = [ 3, 1 ]; + +// Define the index offsets: +var ox = 0; +var oy = 0; + +// Create an input ndarray-like object: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an output ndarray-like object: +var y = { + 'dtype': 'float64', + 'data': ybuf, + 'shape': ysh, + 'strides': sy, + 'offset': oy, + 'order': 'row-major' +}; + +// Define callback execution context: +var ctx = { + 'count': 0 +}; + +// Perform a reduction: +unaryReduceStrided1dBy( maxBy, [ x, y ], [ 2, 3 ], clbk, ctx ); + +var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +// returns [ [ 8.0, 16.0, 24.0 ] ] + +var count = ctx.count; +// returns 12 +``` + +#### TODO: document factory method + +
+ + + +
+ +## Notes + +- The output ndarray and any additional ndarray arguments are expected to have the same dimensions as the non-reduced dimensions of the input ndarray. When calling the reduction function, any additional ndarray arguments are provided as zero-dimensional ndarray-like objects. + +- The reduction function is expected to have the following signature: + + ```text + fcn( arrays[, options], clbk[, thisArg ] ) + ``` + + where + + - **arrays**: array containing a one-dimensional subarray of the input ndarray and any additional ndarray arguments as zero-dimensional ndarrays. + - **options**: function options (_optional_). + - **clbk**: callback function. + - **thisArg**: callback execution context (_optional_).s + +- For very high-dimensional ndarrays which are non-contiguous, one should consider copying the underlying data to contiguous memory before performing a reduction in order to achieve better performance. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +var unaryReduceStrided1dBy = require( '@stdlib/ndarray/base/unary-reduce-strided1d-by' ); + +function clbk( value ) { + return value * 2; +} + +var N = 10; +var x = { + 'dtype': 'generic', + 'data': discreteUniform( N, -5, 5, { + 'dtype': 'generic' + }), + 'shape': [ 1, 5, 2 ], + 'strides': [ 10, 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}; +var y = { + 'dtype': 'generic', + 'data': zeros( 2 ), + 'shape': [ 1, 5 ], + 'strides': [ 5, 1 ], + 'offset': 0, + 'order': 'row-major' +}; + +unaryReduceStrided1dBy( maxBy, [ x, y ], [ 2 ], clbk ); + +console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); +console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) ); +``` + +
+ + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/docs/repl.txt new file mode 100644 index 000000000000..1158c8958580 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/docs/repl.txt @@ -0,0 +1,106 @@ + +{{alias}}( fcn, arrays, dims[, options], clbk[, thisArg] ) + Performs a reduction over a list of specified dimensions in an input ndarray + via a one-dimensional strided array reduction function, according to a + callback function and assigns results to a provided output ndarray. + + Each provided "ndarray" should be an object with the following properties: + + - dtype: data type. + - data: data buffer. + - shape: dimensions. + - strides: stride lengths. + - offset: index offset. + - order: specifies whether an ndarray is row-major (C-style) or column-major + (Fortran-style). + + The output ndarray and any additional ndarray arguments are expected to have + the same dimensions as the non-reduced dimensions of the input ndarray. When + calling the reduction function, any additional ndarray arguments are + provided as zero-dimensional ndarray-like objects. + + Parameters + ---------- + fcn: Function + Function which will be applied to a one-dimensional subarray and should + reduce the subarray to a single scalar value. The function should have + the following signature: + + fcn( arrays[, options], clbk[, thisArg] ) + + where + + - arrays: array containing a one-dimensional subarray of the input + ndarray and any additional ndarray arguments as zero-dimensional + ndarrays. + - options: function options. + - clbk: callback function. + - thisArg: callback execution context. + + arrays: ArrayLikeObject + Array-like object containing one input ndarray and one output ndarray, + followed by any additional ndarray arguments. + + dims: Array + List of dimensions over which to perform a reduction. + + options: Object (optional) + Function options. + + clbk: Function + Callback function. + + thisArg: any (optional) + Callback execution context. + + Examples + -------- + // Define ndarray data and meta data... + > var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0 ] ); + > var dtype = 'float64'; + > var shx = [ 2, 2 ]; + > var shy = []; + > var sx = [ 2, 1 ]; + > var sy = [ 0 ]; + > var ox = 0; + > var oy = 0; + > var order = 'row-major'; + + // Define a callback function... + > function clbk( value ) { return value * 2.0; }; + + // Define a wrapper for a statistical function... + > function fcn( arrays, clbk, thisArg ) { + ... var x = arrays[ 0 ]; + ... var N = x.shape[ 0 ]; + ... var d = x.data; + ... var s = x.strides[ 0 ]; + ... var o = x.offset; + ... return {{alias:@stdlib/stats/base/max-by}}.ndarray( N, d, s, o, clbk, thisArg ); + ... }; + + // Using minimal ndarray-like objects... + > x = { + ... 'dtype': dtype, + ... 'data': xbuf, + ... 'shape': shx, + ... 'strides': sx, + ... 'offset': ox, + ... 'order': order + ... }; + > y = { + ... 'dtype': dtype, + ... 'data': ybuf, + ... 'shape': shy, + ... 'strides': sy, + ... 'offset': oy, + ... 'order': order + ... }; + > {{alias}}( fcn, [ x, y ], [ 0, 1 ], clbk ); + > y.data + [ 8.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/examples/index.js new file mode 100644 index 000000000000..60627600f7e1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/examples/index.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +var unaryReduceStrided1dBy = require( './../lib' ); + +function clbk( value ) { + return value * 2; +} + +var N = 10; +var x = { + 'dtype': 'generic', + 'data': discreteUniform( N, -5, 5, { + 'dtype': 'generic' + }), + 'shape': [ 1, 5, 2 ], + 'strides': [ 10, 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}; +var y = { + 'dtype': 'generic', + 'data': zeros( 5 ), + 'shape': [ 1, 5 ], + 'strides': [ 5, 1 ], + 'offset': 0, + 'order': 'row-major' +}; + +unaryReduceStrided1dBy( maxBy, [ x, y ], [ 2 ], clbk ); + +console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); +console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/0d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/0d.js new file mode 100644 index 000000000000..c0c14edacb38 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/0d.js @@ -0,0 +1,129 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over a list of specified dimensions in an input ndarray according to a callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {thisArg} thisArg - callback execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var ybuf = new Float64Array( [ 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 2, 2 ]; +* var ysh = []; +* +* // Define the array strides: +* var sx = [ 2, 1 ]; +* var sy = [ 0 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = []; +* var cdims = [ 0, 1 ]; +* +* // Perform a reduction: +* unary0d( maxBy, [ x, y ], strategy, ibuf, ldims, cdims, {}, false, clbk, {} ); +* +* var v = y.data; +* // returns [ 8.0 ] +*/ +function unary0d( fcn, arrays, strategy, ibuf, ldims, cdims, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len + var x; + var y; + var f; + + x = strategy( arrays[ 0 ] ); + y = arrays[ 1 ]; + f = wrap( arrays[ 0 ].ref, arrays[ 0 ], ibuf, ldims, [], cdims, clbk, thisArg ); // eslint-disable-line max-len + y.data[ y.offset ] = ( hasOpts ) ? fcn( [ x ], opts, f ) : fcn( [ x ], f ); +} + + +// EXPORTS // + +module.exports = unary0d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/0d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/0d_accessors.js new file mode 100644 index 000000000000..c43c5f4bdf71 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/0d_accessors.js @@ -0,0 +1,136 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over a list of specified dimensions in an input ndarray according to a callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {thisArg} thisArg - callback execution context +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ) ); +* var ybuf = toAccessorArray( new Float64Array( [ 0.0 ] ) ); +* +* // Define the array shapes: +* var xsh = [ 2, 2 ]; +* var ysh = []; +* +* // Define the array strides: +* var sx = [ 2, 1 ]; +* var sy = [ 0 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = []; +* var cdims = [ 0, 1 ]; +* +* // Perform a reduction: +* unary0d( maxBy, [ x, y ], strategy, ibuf, ldims, cdims, {}, false, clbk, {} ); +* +* var v = y.data.get( 0 ); +* // returns 8.0 +*/ +function unary0d( fcn, arrays, strategy, ibuf, ldims, cdims, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len + var x; + var y; + var f; + + x = strategy( arrays[ 0 ] ); + y = arrays[ 1 ]; + f = wrap( arrays[ 0 ].ref, arrays[ 0 ], ibuf, ldims, [], cdims, clbk, thisArg ); // eslint-disable-line max-len + if ( hasOpts ) { + y.accessors[ 1 ]( y.data, y.offset, fcn( [ x ], opts, f ) ); + } else { + y.accessors[ 1 ]( y.data, y.offset, fcn( [ x ], f ) ); + } +} + + +// EXPORTS // + +module.exports = unary0d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/1d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/1d.js new file mode 100644 index 000000000000..6234adc34563 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/1d.js @@ -0,0 +1,184 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-params */ + +'use strict'; + +// MODULES // + +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 3, 2, 2 ]; +* var ysh = [ 3 ]; +* +* // Define the array strides: +* var sx = [ 4, 2, 1 ]; +* var sy = [ 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0 ]; +* var cdims = [ 1, 2 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 4 ]; +* +* // Perform a reduction: +* unary1d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk, {} ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ 8.0, 16.0, 24.0 ] +*/ +function unary1d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len + var ybuf; + var dv0; + var sh; + var S0; + var iv; + var i0; + var y; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the output ndarray and associated shape: + y = arrays[ 1 ]; + sh = y.shape; + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + S0 = sh[ 0 ]; + dv0 = [ strides[0] ]; + for ( i = 1; i < arrays.length; i++ ) { + dv0.push( arrays[i].strides[0] ); + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Iterate over the non-reduced ndarray dimensions... + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i0 ], cdims, clbk, thisArg ); // eslint-disable-line max-len + ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); + incrementOffsets( iv, dv0 ); + } +} + + +// EXPORTS // + +module.exports = unary1d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/1d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/1d_accessors.js new file mode 100644 index 000000000000..d7357825e3d4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/1d_accessors.js @@ -0,0 +1,196 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-params */ + +'use strict'; + +// MODULES // + +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ) ); +* var ybuf = toAccessorArray( new Float64Array( [ 0.0, 0.0, 0.0 ] ) ); +* +* // Define the array shapes: +* var xsh = [ 3, 2, 2 ]; +* var ysh = [ 3 ]; +* +* // Define the array strides: +* var sx = [ 4, 2, 1 ]; +* var sy = [ 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0 ]; +* var cdims = [ 1, 2 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 4 ]; +* +* // Perform a reduction: +* unary1d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk, {} ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ 8.0, 16.0, 24.0 ] +*/ +function unary1d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len + var ybuf; + var set; + var dv0; + var sh; + var S0; + var iv; + var i0; + var y; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the output ndarray and associated shape: + y = arrays[ 1 ]; + sh = y.shape; + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + S0 = sh[ 0 ]; + dv0 = [ strides[0] ]; + for ( i = 1; i < arrays.length; i++ ) { + dv0.push( arrays[i].strides[0] ); + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache accessors: + set = y.accessors[ 1 ]; + + // Iterate over the non-reduced ndarray dimensions... + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i0 ], cdims, clbk, thisArg ); // eslint-disable-line max-len + if ( hasOpts ) { + set( ybuf, iv[1], fcn( v, opts, f ) ); + } else { + set( ybuf, iv[1], fcn( v, f ) ); + } + incrementOffsets( iv, dv0 ); + } +} + + +// EXPORTS // + +module.exports = unary1d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d.js new file mode 100644 index 000000000000..3369bc597c21 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d.js @@ -0,0 +1,210 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-params */ + +'use strict'; + +// MODULES // + +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {boolean} isRowMajor - boolean indicating whether the input ndarray is row-major +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 3, 2, 2 ]; +* var ysh = [ 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 4, 2, 1 ]; +* var sy = [ 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1 ]; +* var cdims = [ 2, 3 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 4 ]; +* +* // Perform a reduction: +* unary2d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ 8.0, 16.0, 24.0 ] ] +*/ +function unary2d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len + var ybuf; + var dv0; + var dv1; + var sh; + var S0; + var S1; + var sv; + var iv; + var i0; + var i1; + var y; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the output ndarray and associated shape: + y = arrays[ 1 ]; + sh = y.shape; + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 1 ]; + S1 = sh[ 0 ]; + dv0 = [ strides[1] ]; // offset increment for innermost loop + dv1 = [ strides[0] - ( S0*strides[1] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[1] ); + dv1.push( sv[0] - ( S0*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + dv0 = [ strides[0] ]; // offset increment for innermost loop + dv1 = [ strides[1] - ( S0*strides[0] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Iterate over the non-reduced ndarray dimensions... + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i1, i0 ], cdims, clbk, thisArg ); // eslint-disable-line max-len + ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } +} + + +// EXPORTS // + +module.exports = unary2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_accessors.js new file mode 100644 index 000000000000..488735a1d3dc --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_accessors.js @@ -0,0 +1,218 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-params */ + +'use strict'; + +// MODULES // + +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {boolean} isRowMajor - boolean indicating whether the input ndarray is row-major +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ) ); +* var ybuf = toAccessorArray( new Float64Array( [ 0.0, 0.0, 0.0 ] ) ); +* +* // Define the array shapes: +* var xsh = [ 1, 3, 2, 2 ]; +* var ysh = [ 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 4, 2, 1 ]; +* var sy = [ 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1 ]; +* var cdims = [ 2, 3 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 4 ]; +* +* // Perform a reduction: +* unary2d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ 6.0, 14.0, 22.0 ] ] +*/ +function unary2d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len + var ybuf; + var dv0; + var dv1; + var set; + var sh; + var S0; + var S1; + var sv; + var iv; + var i0; + var i1; + var y; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the output ndarray and associated shape: + y = arrays[ 1 ]; + sh = y.shape; + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 1 ]; + S1 = sh[ 0 ]; + dv0 = [ strides[1] ]; // offset increment for innermost loop + dv1 = [ strides[0] - ( S0*strides[1] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[1] ); + dv1.push( sv[0] - ( S0*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + dv0 = [ strides[0] ]; // offset increment for innermost loop + dv1 = [ strides[1] - ( S0*strides[0] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache accessors: + set = y.accessors[ 1 ]; + + // Iterate over the non-reduced ndarray dimensions... + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i1, i0 ], cdims, clbk, thisArg ); // eslint-disable-line max-len + set( ybuf, iv[1], ( hasOpts ) ? fcn( views, opts, f ) : fcn( views, f ) ); // eslint-disable-line max-len + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } +} + + +// EXPORTS // + +module.exports = unary2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_blocked.js new file mode 100644 index 000000000000..37efcc717bfd --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_blocked.js @@ -0,0 +1,244 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-params */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/unary-tiling-block-size' ); +var takeIndexed = require( '@stdlib/array/base/take-indexed' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to a callback function and assigns results to a provided output ndarray via loop blocking. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 3, 2, 2 ]; +* var ysh = [ 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 4, 2, 1 ]; +* var sy = [ 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1 ]; +* var cdims = [ 2, 3 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 4 ]; +* +* // Perform a reduction: +* blockedunary2d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ 8.0, 16.0, 24.0 ] ] +*/ +function blockedunary2d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len + var bsize; + var ybuf; + var dv0; + var dv1; + var ov1; + var sh; + var s0; + var s1; + var sv; + var ov; + var iv; + var i0; + var i1; + var j0; + var j1; + var N; + var x; + var y; + var v; + var o; + var k; + var f; + + // Note on variable naming convention: S#, dv#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + N = arrays.length; + x = arrays[ 0 ]; + y = arrays[ 1 ]; + + // Resolve the loop interchange order: + o = loopOrder( y.shape, strides, y.strides ); + sh = o.sh; + sv = [ o.sx, o.sy ]; + for ( k = 2; k < N; k++ ) { + sv.push( takeIndexed( arrays[k].strides, o.idx ) ); + } + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype ); + + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + ov = offsets( arrays ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache offset increments for the innermost loop... + dv0 = []; + for ( k = 0; k < N; k++ ) { + dv0.push( sv[k][0] ); + } + // Initialize loop variables... + ov1 = zeros( N ); + dv1 = zeros( N ); + iv = zeros( N ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over blocks... + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov1[ k ] = ov[k] + ( j1*sv[k][1] ); + } + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets and loop offset increments for the first ndarray elements in the current block... + for ( k = 0; k < N; k++ ) { + iv[ k ] = ov1[k] + ( j0*sv[k][0] ); + dv1[ k ] = sv[k][1] - ( s0*sv[k][0] ); + } + // Iterate over the non-reduced ndarray dimensions... + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j1+i1, j0+i0 ], cdims, clbk, thisArg ); // eslint-disable-line max-len + ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); // eslint-disable-line max-len + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + } + } +} + + +// EXPORTS // + +module.exports = blockedunary2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_blocked_accessors.js new file mode 100644 index 000000000000..9d8510c7df62 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_blocked_accessors.js @@ -0,0 +1,252 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-params */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/unary-tiling-block-size' ); +var takeIndexed = require( '@stdlib/array/base/take-indexed' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to a callback function and assigns results to a provided output ndarray via loop blocking. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ) ); +* var ybuf = toAccessorArray( new Float64Array( [ 0.0, 0.0, 0.0 ] ) ); +* +* // Define the array shapes: +* var xsh = [ 1, 3, 2, 2 ]; +* var ysh = [ 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 4, 2, 1 ]; +* var sy = [ 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1 ]; +* var cdims = [ 2, 3 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 4 ]; +* +* // Perform a reduction: +* blockedunary2d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ 6.0, 14.0, 22.0 ] ] +*/ +function blockedunary2d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len + var bsize; + var ybuf; + var set; + var dv0; + var dv1; + var ov1; + var sh; + var s0; + var s1; + var sv; + var ov; + var iv; + var i0; + var i1; + var j0; + var j1; + var N; + var x; + var y; + var v; + var o; + var k; + var f; + + // Note on variable naming convention: S#, dv#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + N = arrays.length; + x = arrays[ 0 ]; + y = arrays[ 1 ]; + + // Resolve the loop interchange order: + o = loopOrder( y.shape, strides, y.strides ); + sh = o.sh; + sv = [ o.sx, o.sy ]; + for ( k = 2; k < N; k++ ) { + sv.push( takeIndexed( arrays[k].strides, o.idx ) ); + } + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype ); + + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + ov = offsets( arrays ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache accessors: + set = y.accessors[1]; + + // Cache offset increments for the innermost loop... + dv0 = []; + for ( k = 0; k < N; k++ ) { + dv0.push( sv[k][0] ); + } + // Initialize loop variables... + ov1 = zeros( N ); + dv1 = zeros( N ); + iv = zeros( N ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over blocks... + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov1[ k ] = ov[k] + ( j1*sv[k][1] ); + } + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets and loop offset increments for the first ndarray elements in the current block... + for ( k = 0; k < N; k++ ) { + iv[ k ] = ov1[k] + ( j0*sv[k][0] ); + dv1[ k ] = sv[k][1] - ( s0*sv[k][0] ); + } + // Iterate over the non-reduced ndarray dimensions... + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j1+i1, j0+i0 ], cdims, clbk, thisArg ); // eslint-disable-line max-len + set( ybuf, iv[1], ( hasOpts ) ? fcn( views, opts, f ) : fcn( views, f ) ); // eslint-disable-line max-len + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + } + } +} + + +// EXPORTS // + +module.exports = blockedunary2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/callback_wrapper.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/callback_wrapper.js new file mode 100644 index 000000000000..657fc7de01a2 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/callback_wrapper.js @@ -0,0 +1,72 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var put = require( '@stdlib/array/base/put' ); +var ind2sub = require( '@stdlib/ndarray/base/ind2sub' ); +var zeros = require( '@stdlib/array/base/zeros' ); + + +// VARIABLES // + +var MODE = 'throw'; + + +// MAIN // + +/** +* Wraps a provided callback function. +* +* @private +* @param {ndarray} arr - input ndarray +* @param {ndarray} view - reduced view of the input ndarray +* @param {NonNegativeIntegerArray} idx - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - loop dimensions +* @param {NonNegativeIntegerArray} lidx - current loop iteration indices +* @param {NonNegativeIntegerArray} cdims - core dimensions +* @param {Function} clbk - callback function +* @param {thisArg} thisArg - callback execution context +* @returns {Function} callback wrapper +*/ +function wrap( arr, view, idx, ldims, lidx, cdims, clbk, thisArg ) { + var vidx = zeros( cdims.length ); + put( idx, ldims, lidx, MODE ); + return wrapper; + + /** + * Invokes a callback function. + * + * @private + * @param {*} v - value + * @param {NonNegativeIntegerArray} cidx - current core iteration indices + * @returns {*} result + */ + function wrapper( v, cidx ) { + ind2sub.assign( view.shape, view.strides, view.offset, view.order, cidx, MODE, vidx ); // eslint-disable-line max-len + put( idx, cdims, vidx, MODE ); + return clbk.call( thisArg, v, idx.slice(), arr ); + } +} + + +// EXPORTS // + +module.exports = wrap; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/factory.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/factory.js new file mode 100644 index 000000000000..e8ecc9b89c49 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/factory.js @@ -0,0 +1,124 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isFunction = require( '@stdlib/assert/is-function' ); +var format = require( '@stdlib/string/format' ); +var reduce = require( './main.js' ); + + +// MAIN // + +/** +* Return a function for performing a reduction over a list of specified dimensions in an input ndarray via a one-dimensional strided array reduction function, according to a callback function and assigning results to a provided output ndarray. +* +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @throws {TypeError} first argument must be a function +* @returns {Function} function for performing a reduction +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 3, 2, 2 ]; +* var ysh = [ 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 4, 2, 1 ]; +* var sy = [ 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Create a function for performing a reduction over subarrays: +* var max = factory( maxBy ); +* // returns +* +* // Perform a reduction: +* max( [ x, y ], [ 2, 3 ], clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ 8.0, 16.0, 24.0 ] ] +*/ +function factory( fcn ) { + if ( !isFunction( fcn ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', fcn ) ); + } + return reducer; + + /** + * Performs a reduction over a list of specified dimensions in an input ndarray via a one-dimensional strided array reduction function according to a callback function and assigns results to a provided output ndarray. + * + * @private + * @param {ArrayLikeObject} arrays - array-like object containing ndarrays + * @param {IntegerArray} dims - list of dimensions over which to perform a reduction + * @param {Options} [options] - function options + * @param {Function} clbk - callback function + * @param {thisArg} [thisArg] - callback execution context + * @returns {void} + */ + function reducer( arrays, dims, options, clbk, thisArg ) { + var nargs = arguments.length; + if ( nargs < 5 ) { + return reduce( fcn, arrays, dims, options ); + } + if ( nargs === 5 ) { + return reduce( fcn, arrays, dims, options, clbk ); + } + return reduce( fcn, arrays, dims, options, clbk, thisArg ); + } +} + + +// EXPORTS // + +module.exports = factory; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/increment_offsets.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/increment_offsets.js new file mode 100644 index 000000000000..7d525521b721 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/increment_offsets.js @@ -0,0 +1,46 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MAIN // + +/** +* Increments index offsets according to a list of increments. +* +* ## Notes +* +* - This function mutates the list of index offsets. +* +* @private +* @param {NonNegativeIntegerArray} offsets - list of index offsets +* @param {NonNegativeIntegerArray} inc - list of increments +* @returns {NonNegativeIntegerArray} updated offsets +*/ +function incrementOffsets( offsets, inc ) { + var i; + for ( i = 0; i < offsets.length; i++ ) { + offsets[ i ] += inc[ i ]; + } + return offsets; +} + + +// EXPORTS // + +module.exports = incrementOffsets; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/index.js new file mode 100644 index 000000000000..a6b352f88224 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/index.js @@ -0,0 +1,151 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Perform a reduction over a list of specified dimensions in an input ndarray via a one-dimensional strided array reduction function, according to a callback function and assign results to a provided output ndarray. +* +* @module @stdlib/ndarray/base/unary-reduce-strided1d-by +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* var unaryReduceStrided1dBy = require( '@stdlib/ndarray/base/unary-reduce-strided1d-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 3, 2, 2 ]; +* var ysh = [ 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 4, 2, 1 ]; +* var sy = [ 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Perform a reduction: +* unaryReduceStrided1dBy( wrapper, [ x, y ], [ 2, 3 ] ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ 10.0, 26.0, 42.0 ] ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* var unaryReduceStrided1dBy = require( '@stdlib/ndarray/base/unary-reduce-strided1d-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 3, 2, 2 ]; +* var ysh = [ 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 4, 2, 1 ]; +* var sy = [ 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Create a function for performing a reduction over subarrays: +* var max = unaryReduceStrided1dBy.factory( maxBy ); +* // returns +* +* // Perform a reduction: +* max( [ x, y ], [ 2, 3 ], clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ 10.0, 26.0, 42.0 ] ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var factory = require( './factory.js' ); + + +// MAIN // + +setReadOnly( main, 'factory', factory ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "factory": "main.factory" } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/initialize_array_views.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/initialize_array_views.js new file mode 100644 index 000000000000..f9f52252bed3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/initialize_array_views.js @@ -0,0 +1,57 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MAIN // + +/** +* Initialize ndarray-like objects for representing zero-dimensional sub-array views of ancillary ndarray arguments. +* +* ## Notes +* +* - This function ignores the first two ndarray-like objects, which are assumed to be the input and output ndarray, respectively. +* - This function mutates the provided output array. +* +* @private +* @param {ArrayLikeObject} arrays - list of ndarray-like objects +* @param {Array} out - output array +* @returns {Array} output array +*/ +function initializeViews( arrays, out ) { + var v; + var i; + + for ( i = 2; i < arrays.length; i++ ) { + v = arrays[ i ]; + out.push({ + 'dtype': v.dtype, + 'data': v.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': v.offset, + 'order': v.order + }); + } + return out; +} + + +// EXPORTS // + +module.exports = initializeViews; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/main.js new file mode 100644 index 000000000000..9f9953416c3f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/main.js @@ -0,0 +1,453 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isFunction = require( '@stdlib/assert/is-function' ); +var ndarray2object = require( '@stdlib/ndarray/base/ndarraylike2object' ); +var normalizeIndices = require( '@stdlib/ndarray/base/to-unique-normalized-indices' ); +var indicesComplement = require( '@stdlib/array/base/indices-complement' ); +var takeIndexed2 = require( '@stdlib/array/base/take-indexed2' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var iterationOrder = require( '@stdlib/ndarray/base/iteration-order' ); +var strides2order = require( '@stdlib/ndarray/base/strides2order' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var join = require( '@stdlib/array/base/join' ); +var format = require( '@stdlib/string/format' ); +var initializeViews = require( './initialize_array_views.js' ); +var reshapeStrategy = require( './reshape_strategy.js' ); +var blockedaccessorunary2d = require( './2d_blocked_accessors.js' ); +var blockedunary2d = require( './2d_blocked.js' ); +var accessorunary0d = require( './0d_accessors.js' ); +var accessorunary1d = require( './1d_accessors.js' ); +var accessorunary2d = require( './2d_accessors.js' ); +var accessorunarynd = require( './nd_accessors.js' ); +var unary0d = require( './0d.js' ); +var unary1d = require( './1d.js' ); +var unary2d = require( './2d.js' ); +var unarynd = require( './nd.js' ); + + +// VARIABLES // + +var UNARY = [ + unary0d, + unary1d, + unary2d +]; +var ACCESSOR_UNARY = [ + accessorunary0d, + accessorunary1d, + accessorunary2d +]; +var BLOCKED_UNARY = [ + blockedunary2d // 0 +]; +var BLOCKED_ACCESSOR_UNARY = [ + blockedaccessorunary2d // 0 +]; +var MAX_DIMS = UNARY.length - 1; + + +// MAIN // + +/** +* Performs a reduction over a list of specified dimensions in an input ndarray via a one-dimensional strided array reduction function, according to a callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {ArrayLikeObject} arrays - array-like object containing ndarrays +* @param {IntegerArray} dims - list of dimensions over which to perform a reduction +* @param {Options} [options] - function options +* @param {Function} clbk - callback function +* @param {*} [thisArg] - callback execution context +* @throws {Error} arrays must have the expected number of dimensions +* @throws {RangeError} dimension indices must not exceed input ndarray bounds +* @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions +* @throws {Error} must provide unique dimension indices +* @throws {Error} arrays must have the same loop dimension sizes +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 3, 2, 2 ]; +* var ysh = [ 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 4, 2, 1 ]; +* var sy = [ 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Perform a reduction: +* unaryReduceStrided1dBy( maxBy, [ x, y ], [ 2, 3 ], clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ 8.0, 16.0, 24.0 ] ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 3, 2, 2 ]; +* var ysh = []; +* +* // Define the array strides: +* var sx = [ 12, 4, 2, 1 ]; +* var sy = [ 0 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Perform a reduction: +* unaryReduceStrided1dBy( maxBy, [ x, y ], [ 0, 1, 2, 3 ], clbk ); +* +* var v = y.data; +* // returns [ 24.0 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 3, 2, 2 ]; +* var ysh = [ 3, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 2, 1 ]; +* var sy = [ 4, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Perform a reduction: +* unaryReduceStrided1dBy( maxBy, [ x, y ], [], clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ 2.0, 4.0 ], [ 6.0, 8.0 ] ], [ [ 10.0, 12.0 ], [ 14.0, 16.0 ] ], [ [ 18.0, 20.0 ], [ 22.0, 24.0 ] ] ] +*/ +function unaryReduceStrided1dBy( fcn, arrays, dims, options, clbk, thisArg ) { // eslint-disable-line max-statements + var workspace; + var strategy; + var views; + var ndims; + var ldims; + var nargs; + var opts; + var arr; + var tmp; + var len; + var shx; + var shc; + var shl; + var iox; + var ioy; + var ord; + var FLG; + var ctx; + var sc; + var sl; + var sy; + var ns; + var cb; + var d; + var s; + var N; + var M; + var K; + var x; + var y; + var i; + var j; + + nargs = arguments.length; + FLG = false; + + // Case: ( fcn, arrays, dims, clbk ) + if ( nargs < 5 ) { + opts = {}; + cb = options; + } + // Case: ( fcn, arrays, dims, options, clbk, thisArg ) + else if ( nargs > 5 ) { + FLG = true; + opts = options; + cb = clbk; + ctx = thisArg; + } + // Case: ( fcn, arrays, dims, clbk, thisArg ) + else if ( isFunction( options ) ) { + opts = {}; + cb = options; + ctx = clbk; + } + // Case: ( fcn, arrays, dims, options, clbk ) + else { + FLG = true; + opts = options; + cb = clbk; + } + // Standardize ndarray meta data... + N = arrays.length; + arr = []; + for ( i = 0; i < N; i++ ) { + arr.push( ndarray2object( arrays[ i ] ) ); + } + // Cache references to the input and output arrays: + x = arr[ 0 ]; + y = arr[ 1 ]; + + // Resolve the number of input array dimensions: + shx = x.shape; + ndims = shx.length; + + // Verify that we've been provided a list of unique dimension indices... + M = dims.length; + d = normalizeIndices( dims, ndims-1 ); + if ( d === null ) { + throw new RangeError( format( 'invalid argument. Third argument contains an out-of-bounds dimension index. Value: [%s].', join( dims, ',' ) ) ); + } + d.sort(); + if ( d.length !== M ) { + throw new Error( format( 'invalid argument. Third argument must contain a list of unique dimension indices. Value: [%s].', join( dims, ',' ) ) ); + } + // Check whether we've been provided a valid number of dimensions to reduce... + if ( M > ndims ) { + throw new RangeError( format( 'invalid argument. Number of specified dimensions cannot exceed the number of dimensions in the input array. Number of dimensions: %d. Value: [%s].', ndims, join( dims, ',' ) ) ); + } + // Verify that provided ndarrays have the expected number of dimensions... + K = ndims - M; + for ( i = 1; i < N; i++ ) { + if ( arr[ i ].shape.length !== K ) { + throw new Error( format( 'invalid argument. Arrays which are not being reduced must have the same number of non-reduced dimensions. Input array shape: [%s]. Number of non-reduced dimensions: %d. Array shape: [%s] (index: %d).', join( shx, ',' ), K, join( arr[ i ].shape, ',' ), i ) ); + } + } + // Initialize a workspace for storing iteration indices: + workspace = zeros( ndims ); + + // Resolve the non-reduced ("loop") dimensions and associated strides: + ldims = indicesComplement( shx.length, d ); + tmp = takeIndexed2( shx, x.strides, ldims ); + shl = tmp[ 0 ]; + sl = tmp[ 1 ]; + + // Resolve the reduced ("core") dimensions and associated strides: + tmp = takeIndexed2( shx, x.strides, d ); + shc = tmp[ 0 ]; + sc = tmp[ 1 ]; + + // Verify that the provided arrays have the same loop dimensions... + len = 1; // number of elements + ns = 0; // number of singleton dimensions + for ( i = 0; i < K; i++ ) { + s = shl[ i ]; + for ( j = 1; j < N; j++ ) { + if ( s !== arr[ j ].shape[ i ] ) { + throw new Error( format( 'invalid argument. Non-reduced dimensions must be consistent across all provided arrays. Input array shape: [%s]. Non-reduced dimension indices: [%s]. Non-reduced dimensions: [%s]. Array shape: [%s] (index: %d).', join( shx, ',' ), join( ldims, ',' ), join( shl, ',' ), join( arr[ j ].shape, ',' ), j ) ); + } + } + // Note that, if one of the dimensions is `0`, the length will be `0`... + len *= s; + + // Check whether the current dimension is a singleton dimension... + if ( s === 1 ) { + ns += 1; + } + } + // Check whether we were provided empty ndarrays... + if ( len === 0 || ( shc.length && numel( shc ) === 0 ) ) { + return; + } + // Initialize ndarray-like objects for representing sub-array views... + views = [ + { + 'dtype': x.dtype, + 'data': x.data, + 'shape': shc, + 'strides': sc, + 'offset': x.offset, + 'order': x.order + } + ]; + initializeViews( arr, views ); + + // Determine the strategy for reshaping sub-array views of the input array prior to performing a reduction: + strategy = reshapeStrategy( views[ 0 ] ); + + // Determine whether we can avoid iteration altogether... + if ( K === 0 ) { + if ( y.accessorProtocol ) { + return ACCESSOR_UNARY[ K ]( fcn, arr, strategy, workspace, ldims, d, opts, FLG, cb, ctx ); // eslint-disable-line max-len + } + return UNARY[ K ]( fcn, arr, strategy, workspace, ldims, d, opts, FLG, cb, ctx ); // eslint-disable-line max-len + } + // Determine whether we only have one loop dimension and can thus readily perform one-dimensional iteration... + if ( K === 1 ) { + if ( y.accessorProtocol ) { + return ACCESSOR_UNARY[ K ]( fcn, arr, strategy, workspace, views, ldims, d, sl, opts, FLG, cb, ctx ); // eslint-disable-line max-len + } + return UNARY[ K ]( fcn, arr, strategy, views, workspace, ldims, d, sl, opts, FLG, cb, ctx ); // eslint-disable-line max-len + } + sy = y.strides; + + // Determine whether the loop dimensions have only **one** non-singleton dimension (e.g., shape=[10,1,1,1]) so that we can treat loop iteration as being equivalent to one-dimensional iteration... + if ( ns === K-1 ) { + // Get the index of the non-singleton dimension... + for ( i = 0; i < K; i++ ) { + if ( shl[ i ] !== 1 ) { + break; + } + } + y.shape = [ shl[i] ]; + for ( j = 0; j < N; j++ ) { + arr[ j ].strides = [ arr[j].strides[i] ]; + } + sl = [ sl[i] ]; + if ( y.accessorProtocol ) { + return ACCESSOR_UNARY[ 1 ]( fcn, arr, strategy, views, workspace, ldims, d, sl, opts, FLG, cb, ctx ); // eslint-disable-line max-len + } + return UNARY[ 1 ]( fcn, arr, strategy, views, workspace, ldims, d, sl, opts, FLG, cb, ctx ); // eslint-disable-line max-len + } + iox = iterationOrder( sl ); // +/-1 + ioy = iterationOrder( sy ); // +/-1 + + // Determine whether we can avoid blocked iteration... + ord = strides2order( sl ); + if ( iox !== 0 && ioy !== 0 && ord === strides2order( sy ) && K <= MAX_DIMS ) { // eslint-disable-line max-len + // So long as iteration for each respective array always moves in the same direction (i.e., no mixed sign strides) and the memory layouts are the same, we can leverage cache-optimal (i.e., normal) nested loops without resorting to blocked iteration... + if ( y.accessorProtocol ) { + return ACCESSOR_UNARY[ K ]( fcn, arr, strategy, views, workspace, ldims, d, sl, ord === 1, opts, FLG, cb, ctx ); // eslint-disable-line max-len + } + return UNARY[ K ]( fcn, arr, strategy, views, workspace, ldims, d, sl, ord === 1, opts, FLG, cb, ctx ); // eslint-disable-line max-len + } + // At this point, we're either dealing with non-contiguous n-dimensional arrays, high dimensional n-dimensional arrays, and/or arrays having differing memory layouts, so our only hope is that we can still perform blocked iteration... + + // Determine whether we can perform blocked iteration... + if ( K <= MAX_DIMS ) { + if ( y.accessorProtocol ) { + return BLOCKED_ACCESSOR_UNARY[ K-2 ]( fcn, arr, strategy, views, workspace, ldims, d, sl, opts, FLG, cb, ctx ); // eslint-disable-line max-len + } + return BLOCKED_UNARY[ K-2 ]( fcn, arr, strategy, views, workspace, ldims, d, sl, opts, FLG, cb, ctx ); // eslint-disable-line max-len + } + // Fall-through to linear view iteration without regard for how data is stored in memory (i.e., take the slow path)... + if ( y.accessorProtocol ) { + return accessorunarynd( fcn, arr, strategy, views, workspace, ldims, d, sl, opts, FLG, cb, ctx ); // eslint-disable-line max-len + } + unarynd( fcn, arr, strategy, views, workspace, ldims, d, sl, opts, FLG, cb, ctx ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = unaryReduceStrided1dBy; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/nd.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/nd.js new file mode 100644 index 000000000000..6eaa62d6eb30 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/nd.js @@ -0,0 +1,196 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-params */ + +'use strict'; + +// MODULES // + +var numel = require( '@stdlib/ndarray/base/numel' ); +var vind2bind = require( '@stdlib/ndarray/base/vind2bind' ); +var ind2sub = require( '@stdlib/ndarray/base/ind2sub' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// VARIABLES // + +var MODE = 'throw'; + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to a callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 3, 2, 2 ]; +* var ysh = [ 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 4, 2, 1 ]; +* var sy = [ 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1 ]; +* var cdims = [ 2, 3 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 4 ]; +* +* // Perform a reduction: +* unarynd( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ 8.0, 16.0, 24.0 ] ] +*/ +function unarynd( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len + var ybuf; + var len; + var arr; + var sub; + var sh; + var iv; + var io; + var N; + var y; + var v; + var i; + var j; + var f; + + N = arrays.length; + + // Resolve the output ndarray and associated shape: + y = arrays[ 1 ]; + sh = y.shape; + + // Compute the total number of elements over which to iterate: + len = numel( sh ); + + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Iterate based on the linear **view** index, regardless as to how the data is stored in memory... + io = zeros( N ); + for ( i = 0; i < len; i++ ) { + for ( j = 0; j < N; j++ ) { + arr = arrays[ j ]; + io[ j ] = vind2bind( sh, arr.strides, iv[ j ], arr.order, i, MODE ); + } + setViewOffsets( views, io ); + v[ 0 ] = strategy( views[ 0 ] ); + sub = ind2sub( sh, strides, 0, arrays[0].order, i, MODE ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, sub, cdims, clbk, thisArg ); // eslint-disable-line max-len + ybuf[ io[1] ] = ( hasOpts ) ? fcn( v, f, opts ) : fcn( v, f ); + } +} + + +// EXPORTS // + +module.exports = unarynd; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/nd_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/nd_accessors.js new file mode 100644 index 000000000000..b2cd26041157 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/nd_accessors.js @@ -0,0 +1,204 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-params */ + +'use strict'; + +// MODULES // + +var numel = require( '@stdlib/ndarray/base/numel' ); +var vind2bind = require( '@stdlib/ndarray/base/vind2bind' ); +var ind2sub = require( '@stdlib/ndarray/base/ind2sub' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// VARIABLES // + +var MODE = 'throw'; + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to a callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ) ); +* var ybuf = toAccessorArray( new Float64Array( [ 0.0, 0.0, 0.0 ] ) ); +* +* // Define the array shapes: +* var xsh = [ 1, 3, 2, 2 ]; +* var ysh = [ 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 4, 2, 1 ]; +* var sy = [ 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1 ]; +* var cdims = [ 2, 3 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 4 ]; +* +* // Perform a reduction: +* unarynd( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ 6.0, 14.0, 22.0 ] ] +*/ +function unarynd( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len + var ybuf; + var len; + var arr; + var sub; + var set; + var sh; + var iv; + var io; + var N; + var y; + var v; + var i; + var j; + var f; + + N = arrays.length; + + // Resolve the output ndarray and associated shape: + y = arrays[ 1 ]; + sh = y.shape; + + // Compute the total number of elements over which to iterate: + len = numel( sh ); + + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache accessors: + set = y.accessors[ 1 ]; + + // Iterate based on the linear **view** index, regardless as to how the data is stored in memory... + io = zeros( N ); + for ( i = 0; i < len; i++ ) { + for ( j = 0; j < N; j++ ) { + arr = arrays[ j ]; + io[ j ] = vind2bind( sh, arr.strides, iv[ j ], arr.order, i, MODE ); + } + setViewOffsets( views, io ); + v[ 0 ] = strategy( views[ 0 ] ); + sub = ind2sub( sh, strides, 0, arrays[0].order, i, MODE ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, sub, cdims, clbk, thisArg ); // eslint-disable-line max-len + set( ybuf, io[1], ( hasOpts ) ? fcn( views, opts, f ) : fcn( views, f ) ); // eslint-disable-line max-len + } +} + + +// EXPORTS // + +module.exports = unarynd; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/offsets.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/offsets.js new file mode 100644 index 000000000000..a606628f5f3d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/offsets.js @@ -0,0 +1,42 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MAIN // + +/** +* Resolves index offsets from a list of ndarray-like objects. +* +* @private +* @param {ArrayLikeObject} arrays - list of ndarray-like objects +* @returns {NonNegativeIntegerArray} list of offsets +*/ +function offsets( arrays ) { + var out = []; + var i; + for ( i = 0; i < arrays.length; i++ ) { + out.push( arrays[ i ].offset ); + } + return out; +} + + +// EXPORTS // + +module.exports = offsets; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/reshape_strategy.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/reshape_strategy.js new file mode 100644 index 000000000000..aa8118f8f85a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/reshape_strategy.js @@ -0,0 +1,260 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var iterationOrder = require( '@stdlib/ndarray/base/iteration-order' ); +var minmaxViewBufferIndex = require( '@stdlib/ndarray/base/minmax-view-buffer-index' ).assign; +var ndarraylike2object = require( '@stdlib/ndarray/base/ndarraylike2object' ); +var assign = require( '@stdlib/ndarray/base/assign' ); +var ndarraylike2ndarray = require( '@stdlib/ndarray/base/ndarraylike2ndarray' ); +var emptyLike = require( '@stdlib/ndarray/base/empty-like' ); + + +// FUNCTIONS // + +/** +* Returns an input ndarray. +* +* @private +* @param {ndarrayLike} x - input ndarray +* @returns {ndarrayLike} input ndarray +*/ +function identity( x ) { + return x; +} + +/** +* Broadcasts a zero-dimensional ndarray to a one-dimensional ndarray view containing a single element. +* +* @private +* @param {ndarrayLike} x - input ndarray +* @returns {ndarrayLike} broadcasted ndarray view +*/ +function broadcast( x ) { + // NOTE: the following properties must be set in the exact same order as in `x` in order to ensure that the returned object has the same hidden shape as the input ndarray-like object... + return { + 'dtype': x.dtype, + 'data': x.data, + 'shape': [ 1 ], + 'strides': [ 0 ], + 'offset': x.offset, + 'order': x.order + }; +} + +/** +* Returns a function which returns an ndarray view in which the singleton dimensions are removed from an input ndarray having only a single non-singleton dimension. +* +* @private +* @param {ndarrayLike} arr - original ndarray +* @param {NonNegativeInteger} index - index of the non-singleton dimension +* @returns {Function} function for returning an ndarray view +*/ +function squeeze( arr, index ) { + var sh = [ arr.shape[ index ] ]; + var sx = [ arr.strides[ index ] ]; + return reshape; + + /** + * Returns an ndarray view in which the singleton dimensions are removed from an input ndarray having only a single non-singleton dimension. + * + * @private + * @param {ndarrayLike} x - input ndarray + * @returns {ndarrayLike} a squeezed ndarray view + */ + function reshape( x ) { + // NOTE: the following properties must be set in the exact same order as in `arr` in order to ensure that the returned object has the same hidden shape as the input ndarray-like object... + return { + 'dtype': x.dtype, + 'data': x.data, + 'shape': sh, + 'strides': sx, + 'offset': x.offset, + 'order': x.order + }; + } +} + +/** +* Returns a function which returns a one-dimensional ndarray view of a contiguous input ndarray having more than one dimension. +* +* @private +* @param {NonNegativeInteger} len - number of elements in an ndarray +* @param {integer} iox - iteration order +* @returns {Function} function for returning a one-dimensional ndarray view +*/ +function contiguous( len, iox ) { + var xmmv; + var ind; + var sh; + var sx; + + // Resolve the index of the min/max view buffer element which is the first indexed element... + if ( iox === 1 ) { + ind = 0; + } else { + ind = 1; + } + // Initialize an array for storing the min/max view buffer elements: + xmmv = [ 0, 0 ]; // [ min, max ] + + // Initialize the output one-dimensional view's shape and strides: + sh = [ len ]; + sx = [ iox ]; + + return reshape; + + /** + * Returns a one-dimensional ndarray view of a contiguous input ndarray having more than one dimension. + * + * @private + * @param {ndarrayLike} x - input ndarray + * @returns {ndarrayLike} a one-dimensional ndarray view + */ + function reshape( x ) { + // Resolve the minimum and maximum linear indices in the underlying data buffer which are accessible to the input ndarray view: + minmaxViewBufferIndex( x.shape, x.strides, x.offset, xmmv ); + + // NOTE: the following properties must be set in the exact same order as in `x` in order to ensure that the returned object has the same hidden shape as the input ndarray-like object... + return { + 'dtype': x.dtype, + 'data': x.data, + 'shape': sh, + 'strides': sx, + 'offset': xmmv[ ind ], // the index of the first indexed element + 'order': x.order + }; + } +} + +/** +* Returns a function which copies an input ndarray to a contiguous ndarray workspace. +* +* @private +* @param {NonNegativeInteger} len - number of elements in an ndarray +* @param {ndarrayLike} workspace - ndarray workspace +* @returns {Function} function which copies an input ndarray to a contiguous ndarray workspace +*/ +function copy( len, workspace ) { + // NOTE: the following properties must be set in the exact same order as in the input ndarray-like object in order to ensure that the returned object has the same hidden shape... + var view = { + 'dtype': workspace.dtype, + 'data': workspace.data, + 'shape': [ len ], + 'strides': [ 1 ], + 'offset': workspace.offset, + 'order': workspace.order + }; + return reshape; + + /** + * Copies an input ndarray to a contiguous ndarray workspace and returns a one-dimensional workspace view. + * + * @private + * @param {ndarrayLike} x - input ndarray + * @returns {ndarrayLike} one-dimensional workspace view + */ + function reshape( x ) { + assign( [ x, workspace ] ); + return view; + } +} + + +// MAIN // + +/** +* Returns a function for reshaping input ndarrays which have the same data type, shape, and strides as a provided ndarray. +* +* @private +* @param {ndarrayLike} x - input ndarray +* @param {string} x.dtype - input ndarray data type +* @param {Collection} x.data - input ndarray data buffer +* @param {NonNegativeIntegerArray} x.shape - input ndarray shape +* @param {IntegerArray} x.strides - input ndarray strides +* @param {NonNegativeInteger} x.offset - input ndarray index offset +* @param {string} x.order - input ndarray memory layout +* @returns {Function} function implementing a reshape strategy +*/ +function strategy( x ) { + var ndims; + var xmmv; + var len; + var iox; + var sh; + var ns; + var i; + + // Resolve the number of array dimensions: + sh = x.shape; + ndims = sh.length; + + // Check whether the ndarray is zero-dimensional... + if ( ndims === 0 ) { + return broadcast; + } + // Check whether the ndarray is already one-dimensional... + if ( ndims === 1 ) { + return identity; + } + // Determine the number of singleton dimensions... + len = 1; // number of elements + ns = 0; // number of singleton dimensions + for ( i = 0; i < ndims; i++ ) { + // Check whether the current dimension is a singleton dimension... + if ( sh[ i ] === 1 ) { + ns += 1; + } + len *= sh[ i ]; + } + // Determine whether the ndarray has only **one** non-singleton dimension (e.g., ndims=4, shape=[10,1,1,1]) so that we can simply create an ndarray view without the singleton dimensions... + if ( ns === ndims-1 ) { + // Get the index of the non-singleton dimension... + for ( i = 0; i < ndims; i++ ) { + if ( sh[ i ] !== 1 ) { + break; + } + } + return squeeze( x, i ); + } + iox = iterationOrder( x.strides ); // +/-1 + + // Determine whether we can avoid copying data... + if ( iox !== 0 ) { + // Determine the minimum and maximum linear indices which are accessible by the ndarray view: + xmmv = minmaxViewBufferIndex( sh, x.strides, x.offset, [ 0, 0 ] ); + + // Determine whether we can ignore shape (and strides) and create a new one-dimensional ndarray view... + if ( len === ( xmmv[1]-xmmv[0]+1 ) ) { + return contiguous( len, iox ); + } + // The ndarray is non-contiguous, so we cannot directly interpret as a one-dimensional ndarray... + + // Fall-through to copying to a workspace ndarray... + } + // At this point, we're dealing with a non-contiguous multi-dimensional ndarray, so we need to copy to a contiguous workspace: + return copy( len, ndarraylike2object( emptyLike( ndarraylike2ndarray( x ) ) ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = strategy; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/set_view_offsets.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/set_view_offsets.js new file mode 100644 index 000000000000..32628cee8817 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/set_view_offsets.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MAIN // + +/** +* Sets view offsets according to a list of index offsets. +* +* ## Notes +* +* - This function skips the second element in the list of index offsets, as that is assumed to correspond to the output ndarray which does not have a corresponding view. Meaning, the list of views is expected to have `N` elements, and the list of index offsets is expected to have `N+1` elements. +* - This function mutates the provides view objects. +* +* @private +* @param {Array} views - list of ndarray-like objects representing ndarray views +* @param {NonNegativeIntegerArray} offsets - list of index offsets +* @returns {Array} updated views +*/ +function setViewOffsets( views, offsets ) { + var i; + var j; + for ( i = 0, j = 0; i < offsets.length; i++ ) { + if ( i === 1 ) { // note: expected to correspond to the output ndarray which does not have a corresponding view + continue; + } + views[ j ].offset = offsets[ i ]; + j += 1; + } + return views; +} + + +// EXPORTS // + +module.exports = setViewOffsets; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/package.json b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/package.json new file mode 100644 index 000000000000..11a2e08c2e13 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/package.json @@ -0,0 +1,64 @@ +{ + "name": "@stdlib/ndarray/base/unary-reduce-strided1d-by", + "version": "0.0.0", + "description": "Perform a reduction over a list of specified dimensions in an input ndarray via a one-dimensional strided array reduction function, according to a callback function and assign results to a provided output ndarray.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "base", + "strided", + "array", + "ndarray", + "unary", + "reduce", + "reduction", + "accumulate", + "accumulation", + "vector" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/test/test.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/test/test.js new file mode 100644 index 000000000000..fd1a72b4f6a1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/test/test.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var unaryReduceStrided1dBy = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof unaryReduceStrided1dBy, 'function', 'main export is a function' ); + t.end(); +}); + +// FIXME: add tests From 5db0f5fa15fbc39bc37d2186e6c761df7b7f0454 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 4 Jun 2025 21:12:18 +0000 Subject: [PATCH 02/16] feat: add 3d kernels --- 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 --- --- .../base/unary-reduce-strided1d-by/lib/3d.js | 221 ++++++++++++++ .../lib/3d_accessors.js | 229 +++++++++++++++ .../lib/3d_blocked.js | 267 +++++++++++++++++ .../lib/3d_blocked_accessors.js | 275 ++++++++++++++++++ 4 files changed, 992 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_blocked_accessors.js diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d.js new file mode 100644 index 000000000000..059ccdfa665d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d.js @@ -0,0 +1,221 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-params */ + +'use strict'; + +// MODULES // + +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {boolean} isRowMajor - boolean indicating whether the input ndarray is row-major +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2 ]; +* var cdims = [ 3, 4 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 4 ]; +* +* // Perform a reduction: +* unary3d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ 8.0, 16.0, 24.0 ] ] ] +*/ +function unary3d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len + var ybuf; + var dv0; + var dv1; + var dv2; + var sh; + var S0; + var S1; + var S2; + var sv; + var iv; + var i0; + var i1; + var i2; + var y; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the output ndarray and associated shape: + y = arrays[ 1 ]; + sh = y.shape; + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 2 ]; + S1 = sh[ 1 ]; + S2 = sh[ 0 ]; + dv0 = [ strides[2] ]; // offset increment for innermost loop + dv1 = [ strides[1] - ( S0*strides[2] ) ]; + dv2 = [ strides[0] - ( S1*strides[1] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[2] ); + dv1.push( sv[1] - ( S0*sv[2] ) ); + dv2.push( sv[0] - ( S1*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + dv0 = [ strides[0] ]; // offset increment for innermost loop + dv1 = [ strides[1] - ( S0*strides[0] ) ]; + dv2 = [ strides[2] - ( S1*strides[1] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + dv2.push( sv[2] - ( S1*sv[1] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Iterate over the non-reduced ndarray dimensions... + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i2, i1, i0 ], cdims, clbk, thisArg ); // eslint-disable-line max-len + ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + } +} + + +// EXPORTS // + +module.exports = unary3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_accessors.js new file mode 100644 index 000000000000..b6d9f79eb9ac --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_accessors.js @@ -0,0 +1,229 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-params */ + +'use strict'; + +// MODULES // + +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {boolean} isRowMajor - boolean indicating whether the input ndarray is row-major +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ) ); +* var ybuf = toAccessorArray( new Float64Array( [ 0.0, 0.0, 0.0 ] ) ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2 ]; +* var cdims = [ 3, 4 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 4 ]; +* +* // Perform a reduction: +* unary3d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ 8.0, 16.0, 24.0 ] ] ] +*/ +function unary3d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len + var ybuf; + var set; + var dv0; + var dv1; + var dv2; + var sh; + var S0; + var S1; + var S2; + var sv; + var iv; + var i0; + var i1; + var i2; + var y; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the output ndarray and associated shape: + y = arrays[ 1 ]; + sh = y.shape; + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 2 ]; + S1 = sh[ 1 ]; + S2 = sh[ 0 ]; + dv0 = [ strides[2] ]; // offset increment for innermost loop + dv1 = [ strides[1] - ( S0*strides[2] ) ]; + dv2 = [ strides[0] - ( S1*strides[1] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[2] ); + dv1.push( sv[1] - ( S0*sv[2] ) ); + dv2.push( sv[0] - ( S1*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + dv0 = [ strides[0] ]; // offset increment for innermost loop + dv1 = [ strides[1] - ( S0*strides[0] ) ]; + dv2 = [ strides[2] - ( S1*strides[1] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + dv2.push( sv[2] - ( S1*sv[1] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache accessors: + set = y.accessors[ 1 ]; + + // Iterate over the non-reduced ndarray dimensions... + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i2, i1, i0 ], cdims, clbk, thisArg ); // eslint-disable-line max-len + set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); // eslint-disable-line max-len + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + } +} + + +// EXPORTS // + +module.exports = unary3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_blocked.js new file mode 100644 index 000000000000..999b0b1055e0 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_blocked.js @@ -0,0 +1,267 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-params, max-depth */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/unary-tiling-block-size' ); +var takeIndexed = require( '@stdlib/array/base/take-indexed' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to a callback function and assigns results to a provided output ndarray via loop blocking. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2 ]; +* var cdims = [ 3, 4 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 4 ]; +* +* // Perform a reduction: +* blockedunary3d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ 8.0, 16.0, 24.0 ] ] ] +*/ +function blockedunary3d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len + var bsize; + var ybuf; + var dv0; + var dv1; + var dv2; + var ov1; + var ov2; + var sh; + var s0; + var s1; + var s2; + var sv; + var ov; + var iv; + var i0; + var i1; + var i2; + var j0; + var j1; + var j2; + var N; + var x; + var y; + var v; + var o; + var k; + var f; + + // Note on variable naming convention: S#, dv#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + N = arrays.length; + x = arrays[ 0 ]; + y = arrays[ 1 ]; + + // Resolve the loop interchange order: + o = loopOrder( y.shape, strides, y.strides ); + sh = o.sh; + sv = [ o.sx, o.sy ]; + for ( k = 2; k < N; k++ ) { + sv.push( takeIndexed( arrays[k].strides, o.idx ) ); + } + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype ); + + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + ov = offsets( arrays ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache offset increments for the innermost loop... + dv0 = []; + for ( k = 0; k < N; k++ ) { + dv0.push( sv[k][0] ); + } + // Initialize loop variables... + ov1 = zeros( N ); + ov2 = zeros( N ); + dv1 = zeros( N ); + dv2 = zeros( N ); + iv = zeros( N ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over blocks... + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov2[ k ] = ov[k] + ( j2*sv[k][2] ); + } + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov1[ k ] = ov2[k] + ( j1*sv[k][1] ); + dv2[ k ] = sv[k][2] - ( s1*sv[k][1] ); + } + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets and loop offset increments for the first ndarray elements in the current block... + for ( k = 0; k < N; k++ ) { + iv[ k ] = ov1[k] + ( j0*sv[k][0] ); + dv1[ k ] = sv[k][1] - ( s0*sv[k][0] ); + } + // Iterate over the non-reduced ndarray dimensions... + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); // eslint-disable-line max-len + ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); // eslint-disable-line max-len + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedunary3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_blocked_accessors.js new file mode 100644 index 000000000000..4bf52cc73630 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_blocked_accessors.js @@ -0,0 +1,275 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-params, max-depth */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/unary-tiling-block-size' ); +var takeIndexed = require( '@stdlib/array/base/take-indexed' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to a callback function and assigns results to a provided output ndarray via loop blocking. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ) ); +* var ybuf = toAccessorArray( new Float64Array( [ 0.0, 0.0, 0.0 ] ) ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2 ]; +* var cdims = [ 3, 4 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 4 ]; +* +* // Perform a reduction: +* blockedunary3d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ 8.0, 16.0, 24.0 ] ] ] +*/ +function blockedunary3d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len + var bsize; + var ybuf; + var dv0; + var dv1; + var dv2; + var ov1; + var ov2; + var set; + var sh; + var s0; + var s1; + var s2; + var sv; + var ov; + var iv; + var i0; + var i1; + var i2; + var j0; + var j1; + var j2; + var N; + var x; + var y; + var v; + var o; + var k; + var f; + + // Note on variable naming convention: S#, dv#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + N = arrays.length; + x = arrays[ 0 ]; + y = arrays[ 1 ]; + + // Resolve the loop interchange order: + o = loopOrder( y.shape, strides, y.strides ); + sh = o.sh; + sv = [ o.sx, o.sy ]; + for ( k = 2; k < N; k++ ) { + sv.push( takeIndexed( arrays[k].strides, o.idx ) ); + } + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype ); + + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + ov = offsets( arrays ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache accessors: + set = y.accessors[ 1 ]; + + // Cache offset increments for the innermost loop... + dv0 = []; + for ( k = 0; k < N; k++ ) { + dv0.push( sv[k][0] ); + } + // Initialize loop variables... + ov1 = zeros( N ); + ov2 = zeros( N ); + dv1 = zeros( N ); + dv2 = zeros( N ); + iv = zeros( N ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over blocks... + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov2[ k ] = ov[k] + ( j2*sv[k][2] ); + } + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov1[ k ] = ov2[k] + ( j1*sv[k][1] ); + dv2[ k ] = sv[k][2] - ( s1*sv[k][1] ); + } + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets and loop offset increments for the first ndarray elements in the current block... + for ( k = 0; k < N; k++ ) { + iv[ k ] = ov1[k] + ( j0*sv[k][0] ); + dv1[ k ] = sv[k][1] - ( s0*sv[k][0] ); + } + // Iterate over the non-reduced ndarray dimensions... + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); // eslint-disable-line max-len + set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); // eslint-disable-line max-len + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedunary3d; From a8f3ab32227f967013f63bfe06fd46b71ea058ae Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 5 Jun 2025 02:08:38 -0700 Subject: [PATCH 03/16] docs: update descriptions --- 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: passed - task: lint_package_json status: passed - 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 --- --- .../@stdlib/ndarray/base/unary-reduce-strided1d-by/README.md | 4 ++-- .../ndarray/base/unary-reduce-strided1d-by/lib/factory.js | 2 +- .../ndarray/base/unary-reduce-strided1d-by/lib/index.js | 2 +- .../ndarray/base/unary-reduce-strided1d-by/lib/main.js | 2 +- .../ndarray/base/unary-reduce-strided1d-by/package.json | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/README.md b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/README.md index 6422acb6eef6..bbf37e9604e7 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/README.md @@ -20,7 +20,7 @@ limitations under the License. # unaryReduceStrided1dBy -> Perform a reduction over a list of specified dimensions in an input ndarray via a one-dimensional strided array reduction function, according to a callback function and assign results to a provided output ndarray. +> Perform a reduction over a list of specified dimensions in an input ndarray via a one-dimensional strided array reduction function accepting a callback and assign results to a provided output ndarray.
@@ -38,7 +38,7 @@ var unaryReduceStrided1dBy = require( '@stdlib/ndarray/base/unary-reduce-strided #### unaryReduceStrided1dBy( fcn, arrays, dims\[, options], clbk\[, thisArg] ) -Performs a reduction over a list of specified dimensions in an input ndarray via a one-dimensional strided array reduction function, according to a callback function and assigns results to a provided output ndarray. +Performs a reduction over a list of specified dimensions in an input ndarray via a one-dimensional strided array reduction function accepting a callback and assigns results to a provided output ndarray. diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/factory.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/factory.js index e8ecc9b89c49..47e39ebeeb72 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/factory.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/factory.js @@ -28,7 +28,7 @@ var reduce = require( './main.js' ); // MAIN // /** -* Return a function for performing a reduction over a list of specified dimensions in an input ndarray via a one-dimensional strided array reduction function, according to a callback function and assigning results to a provided output ndarray. +* Return a function for performing a reduction over a list of specified dimensions in an input ndarray via a one-dimensional strided array reduction function accepting a callback and assigning results to a provided output ndarray. * * @param {Function} fcn - wrapper for a one-dimensional strided array reduction function * @throws {TypeError} first argument must be a function diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/index.js index a6b352f88224..b833fe48d29d 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Perform a reduction over a list of specified dimensions in an input ndarray via a one-dimensional strided array reduction function, according to a callback function and assign results to a provided output ndarray. +* Perform a reduction over a list of specified dimensions in an input ndarray via a one-dimensional strided array reduction function accepting a callback and assign results to a provided output ndarray. * * @module @stdlib/ndarray/base/unary-reduce-strided1d-by * diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/main.js index 9f9953416c3f..05b1d42e54fb 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/main.js @@ -69,7 +69,7 @@ var MAX_DIMS = UNARY.length - 1; // MAIN // /** -* Performs a reduction over a list of specified dimensions in an input ndarray via a one-dimensional strided array reduction function, according to a callback function and assigns results to a provided output ndarray. +* Performs a reduction over a list of specified dimensions in an input ndarray via a one-dimensional strided array reduction function accepting a callback and assigns results to a provided output ndarray. * * @private * @param {Function} fcn - wrapper for a one-dimensional strided array reduction function diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/package.json b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/package.json index 11a2e08c2e13..56ba48e24f3f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/package.json +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/ndarray/base/unary-reduce-strided1d-by", "version": "0.0.0", - "description": "Perform a reduction over a list of specified dimensions in an input ndarray via a one-dimensional strided array reduction function, according to a callback function and assign results to a provided output ndarray.", + "description": "Perform a reduction over a list of specified dimensions in an input ndarray via a one-dimensional strided array reduction function accepting a callback and assign results to a provided output ndarray.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", From 3658ea257dc4295c06ee93925ca4ee3e545803f1 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 5 Jun 2025 02:12:01 -0700 Subject: [PATCH 04/16] fix: update argument handling --- 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 --- --- .../ndarray/base/unary-reduce-strided1d-by/lib/factory.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/factory.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/factory.js index 47e39ebeeb72..0f2f7c6e7192 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/factory.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/factory.js @@ -108,10 +108,10 @@ function factory( fcn ) { */ function reducer( arrays, dims, options, clbk, thisArg ) { var nargs = arguments.length; - if ( nargs < 5 ) { + if ( nargs < 4 ) { return reduce( fcn, arrays, dims, options ); } - if ( nargs === 5 ) { + if ( nargs === 4 ) { return reduce( fcn, arrays, dims, options, clbk ); } return reduce( fcn, arrays, dims, options, clbk, thisArg ); From 70f74885da4cca695f0624ee04ca3495f9a6134b Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 5 Jun 2025 02:21:03 -0700 Subject: [PATCH 05/16] chore: clean-up --- 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: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - 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 --- --- .../ndarray/base/unary-reduce-strided1d-by/README.md | 10 ++++++---- .../base/unary-reduce-strided1d-by/docs/repl.txt | 8 ++++---- .../base/unary-reduce-strided1d-by/examples/index.js | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/README.md b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/README.md index bbf37e9604e7..c5310d4c7ea2 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/README.md @@ -115,10 +115,12 @@ Each provided ndarray should be an object with the following properties: The invoked callback function is provided the following arguments: -- **value**: input ndarray element. -- **indices**: current ndarray element indices. +- **value**: current array element. +- **indices**: current array element indices. - **arr**: the input ndarray. +To set the callback execution context, provide a `thisArg`. + ```javascript @@ -206,7 +208,7 @@ var count = ctx.count; - **arrays**: array containing a one-dimensional subarray of the input ndarray and any additional ndarray arguments as zero-dimensional ndarrays. - **options**: function options (_optional_). - **clbk**: callback function. - - **thisArg**: callback execution context (_optional_).s + - **thisArg**: callback execution context (_optional_). - For very high-dimensional ndarrays which are non-contiguous, one should consider copying the underlying data to contiguous memory before performing a reduction in order to achieve better performance. @@ -228,7 +230,7 @@ var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); var unaryReduceStrided1dBy = require( '@stdlib/ndarray/base/unary-reduce-strided1d-by' ); function clbk( value ) { - return value * 2; + return value * 2.0; } var N = 10; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/docs/repl.txt index 1158c8958580..0e1952fdeeae 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/docs/repl.txt @@ -1,8 +1,8 @@ {{alias}}( fcn, arrays, dims[, options], clbk[, thisArg] ) Performs a reduction over a list of specified dimensions in an input ndarray - via a one-dimensional strided array reduction function, according to a - callback function and assigns results to a provided output ndarray. + via a one-dimensional strided array reduction function accepting a callback + and assigns results to a provided output ndarray. Each provided "ndarray" should be an object with the following properties: @@ -71,13 +71,13 @@ > function clbk( value ) { return value * 2.0; }; // Define a wrapper for a statistical function... - > function fcn( arrays, clbk, thisArg ) { + > function fcn( arrays, cb, ctx ) { ... var x = arrays[ 0 ]; ... var N = x.shape[ 0 ]; ... var d = x.data; ... var s = x.strides[ 0 ]; ... var o = x.offset; - ... return {{alias:@stdlib/stats/base/max-by}}.ndarray( N, d, s, o, clbk, thisArg ); + ... return {{alias:@stdlib/stats/base/max-by}}.ndarray( N, d, s, o, cb, ctx ); ... }; // Using minimal ndarray-like objects... diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/examples/index.js index 60627600f7e1..52babe071b17 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/examples/index.js @@ -25,7 +25,7 @@ var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); var unaryReduceStrided1dBy = require( './../lib' ); function clbk( value ) { - return value * 2; + return value * 2.0; } var N = 10; From b9c288c6a31cd3efb83452c1dda6d6e48a25e926 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 5 Jun 2025 02:41:17 -0700 Subject: [PATCH 06/16] chore: clean-up --- 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 --- --- .../unary-reduce-strided1d-by/lib/main.js | 50 +++++-------------- 1 file changed, 13 insertions(+), 37 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/main.js index 05b1d42e54fb..9ec541dc68ad 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/main.js @@ -16,6 +16,8 @@ * limitations under the License. */ +/* eslint-disable max-len */ + 'use strict'; // MODULES // @@ -259,7 +261,6 @@ function unaryReduceStrided1dBy( fcn, arrays, dims, options, clbk, thisArg ) { / var sc; var sl; var sy; - var ns; var cb; var d; var s; @@ -349,7 +350,6 @@ function unaryReduceStrided1dBy( fcn, arrays, dims, options, clbk, thisArg ) { / // Verify that the provided arrays have the same loop dimensions... len = 1; // number of elements - ns = 0; // number of singleton dimensions for ( i = 0; i < K; i++ ) { s = shl[ i ]; for ( j = 1; j < N; j++ ) { @@ -359,11 +359,6 @@ function unaryReduceStrided1dBy( fcn, arrays, dims, options, clbk, thisArg ) { / } // Note that, if one of the dimensions is `0`, the length will be `0`... len *= s; - - // Check whether the current dimension is a singleton dimension... - if ( s === 1 ) { - ns += 1; - } } // Check whether we were provided empty ndarrays... if ( len === 0 || ( shc.length && numel( shc ) === 0 ) ) { @@ -388,63 +383,44 @@ function unaryReduceStrided1dBy( fcn, arrays, dims, options, clbk, thisArg ) { / // Determine whether we can avoid iteration altogether... if ( K === 0 ) { if ( y.accessorProtocol ) { - return ACCESSOR_UNARY[ K ]( fcn, arr, strategy, workspace, ldims, d, opts, FLG, cb, ctx ); // eslint-disable-line max-len + return ACCESSOR_UNARY[ K ]( fcn, arr, strategy, workspace, ldims, d, opts, FLG, cb, ctx ); } - return UNARY[ K ]( fcn, arr, strategy, workspace, ldims, d, opts, FLG, cb, ctx ); // eslint-disable-line max-len + return UNARY[ K ]( fcn, arr, strategy, workspace, ldims, d, opts, FLG, cb, ctx ); } // Determine whether we only have one loop dimension and can thus readily perform one-dimensional iteration... if ( K === 1 ) { if ( y.accessorProtocol ) { - return ACCESSOR_UNARY[ K ]( fcn, arr, strategy, workspace, views, ldims, d, sl, opts, FLG, cb, ctx ); // eslint-disable-line max-len + return ACCESSOR_UNARY[ K ]( fcn, arr, strategy, workspace, views, ldims, d, sl, opts, FLG, cb, ctx ); } - return UNARY[ K ]( fcn, arr, strategy, views, workspace, ldims, d, sl, opts, FLG, cb, ctx ); // eslint-disable-line max-len + return UNARY[ K ]( fcn, arr, strategy, views, workspace, ldims, d, sl, opts, FLG, cb, ctx ); } sy = y.strides; - - // Determine whether the loop dimensions have only **one** non-singleton dimension (e.g., shape=[10,1,1,1]) so that we can treat loop iteration as being equivalent to one-dimensional iteration... - if ( ns === K-1 ) { - // Get the index of the non-singleton dimension... - for ( i = 0; i < K; i++ ) { - if ( shl[ i ] !== 1 ) { - break; - } - } - y.shape = [ shl[i] ]; - for ( j = 0; j < N; j++ ) { - arr[ j ].strides = [ arr[j].strides[i] ]; - } - sl = [ sl[i] ]; - if ( y.accessorProtocol ) { - return ACCESSOR_UNARY[ 1 ]( fcn, arr, strategy, views, workspace, ldims, d, sl, opts, FLG, cb, ctx ); // eslint-disable-line max-len - } - return UNARY[ 1 ]( fcn, arr, strategy, views, workspace, ldims, d, sl, opts, FLG, cb, ctx ); // eslint-disable-line max-len - } iox = iterationOrder( sl ); // +/-1 ioy = iterationOrder( sy ); // +/-1 // Determine whether we can avoid blocked iteration... ord = strides2order( sl ); - if ( iox !== 0 && ioy !== 0 && ord === strides2order( sy ) && K <= MAX_DIMS ) { // eslint-disable-line max-len + if ( iox !== 0 && ioy !== 0 && ord === strides2order( sy ) && K <= MAX_DIMS ) { // So long as iteration for each respective array always moves in the same direction (i.e., no mixed sign strides) and the memory layouts are the same, we can leverage cache-optimal (i.e., normal) nested loops without resorting to blocked iteration... if ( y.accessorProtocol ) { - return ACCESSOR_UNARY[ K ]( fcn, arr, strategy, views, workspace, ldims, d, sl, ord === 1, opts, FLG, cb, ctx ); // eslint-disable-line max-len + return ACCESSOR_UNARY[ K ]( fcn, arr, strategy, views, workspace, ldims, d, sl, ord === 1, opts, FLG, cb, ctx ); } - return UNARY[ K ]( fcn, arr, strategy, views, workspace, ldims, d, sl, ord === 1, opts, FLG, cb, ctx ); // eslint-disable-line max-len + return UNARY[ K ]( fcn, arr, strategy, views, workspace, ldims, d, sl, ord === 1, opts, FLG, cb, ctx ); } // At this point, we're either dealing with non-contiguous n-dimensional arrays, high dimensional n-dimensional arrays, and/or arrays having differing memory layouts, so our only hope is that we can still perform blocked iteration... // Determine whether we can perform blocked iteration... if ( K <= MAX_DIMS ) { if ( y.accessorProtocol ) { - return BLOCKED_ACCESSOR_UNARY[ K-2 ]( fcn, arr, strategy, views, workspace, ldims, d, sl, opts, FLG, cb, ctx ); // eslint-disable-line max-len + return BLOCKED_ACCESSOR_UNARY[ K-2 ]( fcn, arr, strategy, views, workspace, ldims, d, sl, opts, FLG, cb, ctx ); } - return BLOCKED_UNARY[ K-2 ]( fcn, arr, strategy, views, workspace, ldims, d, sl, opts, FLG, cb, ctx ); // eslint-disable-line max-len + return BLOCKED_UNARY[ K-2 ]( fcn, arr, strategy, views, workspace, ldims, d, sl, opts, FLG, cb, ctx ); } // Fall-through to linear view iteration without regard for how data is stored in memory (i.e., take the slow path)... if ( y.accessorProtocol ) { - return accessorunarynd( fcn, arr, strategy, views, workspace, ldims, d, sl, opts, FLG, cb, ctx ); // eslint-disable-line max-len + return accessorunarynd( fcn, arr, strategy, views, workspace, ldims, d, sl, opts, FLG, cb, ctx ); } - unarynd( fcn, arr, strategy, views, workspace, ldims, d, sl, opts, FLG, cb, ctx ); // eslint-disable-line max-len + unarynd( fcn, arr, strategy, views, workspace, ldims, d, sl, opts, FLG, cb, ctx ); } From 5882d9af29f0e7bdcf82f0b8d8cd7b71d8b5c6b6 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 5 Jun 2025 03:02:37 -0700 Subject: [PATCH 07/16] chore: clean-up --- 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 --- --- .../base/unary-reduce-strided1d-by/lib/0d.js | 17 +++++++++++++---- .../lib/0d_accessors.js | 19 ++++++++++++++----- .../lib/callback_wrapper.js | 12 ++++++------ 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/0d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/0d.js index c0c14edacb38..499964535ea7 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/0d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/0d.js @@ -16,10 +16,13 @@ * limitations under the License. */ +/* eslint-disable max-len */ + 'use strict'; // MODULES // +var without = require( '@stdlib/array/base/without' ); var wrap = require( './callback_wrapper.js' ); @@ -112,15 +115,21 @@ var wrap = require( './callback_wrapper.js' ); * var v = y.data; * // returns [ 8.0 ] */ -function unary0d( fcn, arrays, strategy, ibuf, ldims, cdims, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len +function unary0d( fcn, arrays, strategy, ibuf, ldims, cdims, opts, hasOpts, clbk, thisArg ) { + var arr; var x; var y; var f; - x = strategy( arrays[ 0 ] ); + x = arrays[ 0 ]; y = arrays[ 1 ]; - f = wrap( arrays[ 0 ].ref, arrays[ 0 ], ibuf, ldims, [], cdims, clbk, thisArg ); // eslint-disable-line max-len - y.data[ y.offset ] = ( hasOpts ) ? fcn( [ x ], opts, f ) : fcn( [ x ], f ); + + f = wrap( x.ref, x, ibuf, ldims, [], cdims, clbk, thisArg ); + + arr = without( arrays, 1 ); + arr[ 0 ] = strategy( x ); + + y.data[ y.offset ] = ( hasOpts ) ? fcn( arr, opts, f ) : fcn( arr, f ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/0d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/0d_accessors.js index c43c5f4bdf71..5fc701ad63cc 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/0d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/0d_accessors.js @@ -16,10 +16,13 @@ * limitations under the License. */ +/* eslint-disable max-len */ + 'use strict'; // MODULES // +var without = require( '@stdlib/array/base/without' ); var wrap = require( './callback_wrapper.js' ); @@ -115,18 +118,24 @@ var wrap = require( './callback_wrapper.js' ); * var v = y.data.get( 0 ); * // returns 8.0 */ -function unary0d( fcn, arrays, strategy, ibuf, ldims, cdims, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len +function unary0d( fcn, arrays, strategy, ibuf, ldims, cdims, opts, hasOpts, clbk, thisArg ) { + var arr; var x; var y; var f; - x = strategy( arrays[ 0 ] ); + x = arrays[ 0 ]; y = arrays[ 1 ]; - f = wrap( arrays[ 0 ].ref, arrays[ 0 ], ibuf, ldims, [], cdims, clbk, thisArg ); // eslint-disable-line max-len + + f = wrap( x.ref, x, ibuf, ldims, [], cdims, clbk, thisArg ); + + arr = without( arrays, 1 ); + arr[ 0 ] = strategy( x ); + if ( hasOpts ) { - y.accessors[ 1 ]( y.data, y.offset, fcn( [ x ], opts, f ) ); + y.accessors[ 1 ]( y.data, y.offset, fcn( arr, opts, f ) ); } else { - y.accessors[ 1 ]( y.data, y.offset, fcn( [ x ], f ) ); + y.accessors[ 1 ]( y.data, y.offset, fcn( arr, f ) ); } } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/callback_wrapper.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/callback_wrapper.js index 657fc7de01a2..eb54a7488f2a 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/callback_wrapper.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/callback_wrapper.js @@ -21,7 +21,7 @@ // MODULES // var put = require( '@stdlib/array/base/put' ); -var ind2sub = require( '@stdlib/ndarray/base/ind2sub' ); +var ind2sub = require( '@stdlib/ndarray/base/ind2sub' ).assign; var zeros = require( '@stdlib/array/base/zeros' ); @@ -47,7 +47,7 @@ var MODE = 'throw'; * @returns {Function} callback wrapper */ function wrap( arr, view, idx, ldims, lidx, cdims, clbk, thisArg ) { - var vidx = zeros( cdims.length ); + var cidx = zeros( cdims.length ); // workspace for storing core iteration indices put( idx, ldims, lidx, MODE ); return wrapper; @@ -56,12 +56,12 @@ function wrap( arr, view, idx, ldims, lidx, cdims, clbk, thisArg ) { * * @private * @param {*} v - value - * @param {NonNegativeIntegerArray} cidx - current core iteration indices + * @param {NonNegativeInteger} aidx - current array element index * @returns {*} result */ - function wrapper( v, cidx ) { - ind2sub.assign( view.shape, view.strides, view.offset, view.order, cidx, MODE, vidx ); // eslint-disable-line max-len - put( idx, cdims, vidx, MODE ); + function wrapper( v, aidx ) { + ind2sub( view.shape, view.strides, view.offset, view.order, aidx, MODE, cidx ); // eslint-disable-line max-len + put( idx, cdims, cidx, MODE ); return clbk.call( thisArg, v, idx.slice(), arr ); } } From 984f582c5f6e048cc94ac006e2062aea9b017a06 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 5 Jun 2025 03:19:33 -0700 Subject: [PATCH 08/16] chore: clean-up --- 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 --- --- .../base/unary-reduce-strided1d-by/lib/1d.js | 10 +++++++--- .../lib/1d_accessors.js | 16 ++++++++-------- .../base/unary-reduce-strided1d-by/lib/2d.js | 10 +++++++--- .../lib/2d_accessors.js | 12 ++++++++---- .../unary-reduce-strided1d-by/lib/2d_blocked.js | 8 ++++---- .../lib/2d_blocked_accessors.js | 8 ++++---- .../base/unary-reduce-strided1d-by/lib/3d.js | 10 +++++++--- .../lib/3d_accessors.js | 12 ++++++++---- .../unary-reduce-strided1d-by/lib/3d_blocked.js | 8 ++++---- .../lib/3d_blocked_accessors.js | 8 ++++---- 10 files changed, 61 insertions(+), 41 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/1d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/1d.js index 6234adc34563..07248e86fc14 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/1d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/1d.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable max-params */ +/* eslint-disable max-len, max-params */ 'use strict'; @@ -135,13 +135,14 @@ var wrap = require( './callback_wrapper.js' ); * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ 8.0, 16.0, 24.0 ] */ -function unary1d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len +function unary1d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { var ybuf; var dv0; var sh; var S0; var iv; var i0; + var x; var y; var v; var i; @@ -149,6 +150,9 @@ function unary1d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opt // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + // Cache a reference to the input ndarray: + x = arrays[ 0 ]; + // Resolve the output ndarray and associated shape: y = arrays[ 1 ]; sh = y.shape; @@ -172,7 +176,7 @@ function unary1d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opt for ( i0 = 0; i0 < S0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i0 ], cdims, clbk, thisArg ); // eslint-disable-line max-len + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ i0 ], cdims, clbk, thisArg ); ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/1d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/1d_accessors.js index d7357825e3d4..5057cd180254 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/1d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/1d_accessors.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable max-params */ +/* eslint-disable max-len, max-params */ 'use strict'; @@ -139,7 +139,7 @@ var wrap = require( './callback_wrapper.js' ); * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ 8.0, 16.0, 24.0 ] */ -function unary1d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len +function unary1d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { var ybuf; var set; var dv0; @@ -147,6 +147,7 @@ function unary1d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opt var S0; var iv; var i0; + var x; var y; var v; var i; @@ -154,6 +155,9 @@ function unary1d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opt // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + // Cache a reference to the input ndarray: + x = arrays[ 0 ]; + // Resolve the output ndarray and associated shape: y = arrays[ 1 ]; sh = y.shape; @@ -180,12 +184,8 @@ function unary1d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opt for ( i0 = 0; i0 < S0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i0 ], cdims, clbk, thisArg ); // eslint-disable-line max-len - if ( hasOpts ) { - set( ybuf, iv[1], fcn( v, opts, f ) ); - } else { - set( ybuf, iv[1], fcn( v, f ) ); - } + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ i0 ], cdims, clbk, thisArg ); + set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ): fcn( v, f ) ); incrementOffsets( iv, dv0 ); } } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d.js index 3369bc597c21..c65a26764ba0 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable max-params */ +/* eslint-disable max-len, max-params */ 'use strict'; @@ -136,7 +136,7 @@ var wrap = require( './callback_wrapper.js' ); * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ 8.0, 16.0, 24.0 ] ] */ -function unary2d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len +function unary2d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { var ybuf; var dv0; var dv1; @@ -147,6 +147,7 @@ function unary2d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR var iv; var i0; var i1; + var x; var y; var v; var i; @@ -154,6 +155,9 @@ function unary2d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + // Cache a reference to the input ndarray: + x = arrays[ 0 ]; + // Resolve the output ndarray and associated shape: y = arrays[ 1 ]; sh = y.shape; @@ -196,7 +200,7 @@ function unary2d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR for ( i0 = 0; i0 < S0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i1, i0 ], cdims, clbk, thisArg ); // eslint-disable-line max-len + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ i1, i0 ], cdims, clbk, thisArg ); ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_accessors.js index 488735a1d3dc..b54fdc3ac650 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_accessors.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable max-params */ +/* eslint-disable max-len, max-params */ 'use strict'; @@ -140,7 +140,7 @@ var wrap = require( './callback_wrapper.js' ); * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ 6.0, 14.0, 22.0 ] ] */ -function unary2d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len +function unary2d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { var ybuf; var dv0; var dv1; @@ -152,6 +152,7 @@ function unary2d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR var iv; var i0; var i1; + var x; var y; var v; var i; @@ -159,6 +160,9 @@ function unary2d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + // Cache a reference to the input ndarray: + x = arrays[ 0 ]; + // Resolve the output ndarray and associated shape: y = arrays[ 1 ]; sh = y.shape; @@ -204,8 +208,8 @@ function unary2d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR for ( i0 = 0; i0 < S0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i1, i0 ], cdims, clbk, thisArg ); // eslint-disable-line max-len - set( ybuf, iv[1], ( hasOpts ) ? fcn( views, opts, f ) : fcn( views, f ) ); // eslint-disable-line max-len + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ i1, i0 ], cdims, clbk, thisArg ); + set( ybuf, iv[1], ( hasOpts ) ? fcn( views, opts, f ) : fcn( views, f ) ); incrementOffsets( iv, dv0 ); } incrementOffsets( iv, dv1 ); diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_blocked.js index 37efcc717bfd..d87b5db1ae50 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_blocked.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable max-params */ +/* eslint-disable max-len, max-params */ 'use strict'; @@ -139,7 +139,7 @@ var wrap = require( './callback_wrapper.js' ); * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ 8.0, 16.0, 24.0 ] ] */ -function blockedunary2d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len +function blockedunary2d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { var bsize; var ybuf; var dv0; @@ -228,8 +228,8 @@ function blockedunary2d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strid for ( i0 = 0; i0 < s0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j1+i1, j0+i0 ], cdims, clbk, thisArg ); // eslint-disable-line max-len - ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); // eslint-disable-line max-len + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ j1+i1, j0+i0 ], cdims, clbk, thisArg ); + ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); incrementOffsets( iv, dv0 ); } incrementOffsets( iv, dv1 ); diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_blocked_accessors.js index 9d8510c7df62..801e9d2eb312 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_blocked_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_blocked_accessors.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable max-params */ +/* eslint-disable max-len, max-params */ 'use strict'; @@ -143,7 +143,7 @@ var wrap = require( './callback_wrapper.js' ); * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ 6.0, 14.0, 22.0 ] ] */ -function blockedunary2d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len +function blockedunary2d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { var bsize; var ybuf; var set; @@ -236,8 +236,8 @@ function blockedunary2d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strid for ( i0 = 0; i0 < s0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j1+i1, j0+i0 ], cdims, clbk, thisArg ); // eslint-disable-line max-len - set( ybuf, iv[1], ( hasOpts ) ? fcn( views, opts, f ) : fcn( views, f ) ); // eslint-disable-line max-len + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ j1+i1, j0+i0 ], cdims, clbk, thisArg ); + set( ybuf, iv[1], ( hasOpts ) ? fcn( views, opts, f ) : fcn( views, f ) ); incrementOffsets( iv, dv0 ); } incrementOffsets( iv, dv1 ); diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d.js index 059ccdfa665d..c40ea72e43ac 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable max-params */ +/* eslint-disable max-len, max-params */ 'use strict'; @@ -136,7 +136,7 @@ var wrap = require( './callback_wrapper.js' ); * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ 8.0, 16.0, 24.0 ] ] ] */ -function unary3d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len +function unary3d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { var ybuf; var dv0; var dv1; @@ -150,6 +150,7 @@ function unary3d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR var i0; var i1; var i2; + var x; var y; var v; var i; @@ -157,6 +158,9 @@ function unary3d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + // Cache a reference to the input ndarray: + x = arrays[ 0 ]; + // Resolve the output ndarray and associated shape: y = arrays[ 1 ]; sh = y.shape; @@ -206,7 +210,7 @@ function unary3d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR for ( i0 = 0; i0 < S0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i2, i1, i0 ], cdims, clbk, thisArg ); // eslint-disable-line max-len + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ i2, i1, i0 ], cdims, clbk, thisArg ); ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_accessors.js index b6d9f79eb9ac..dc9f191fd142 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_accessors.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable max-params */ +/* eslint-disable max-len, max-params */ 'use strict'; @@ -140,7 +140,7 @@ var wrap = require( './callback_wrapper.js' ); * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ 8.0, 16.0, 24.0 ] ] ] */ -function unary3d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len +function unary3d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { var ybuf; var set; var dv0; @@ -155,6 +155,7 @@ function unary3d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR var i0; var i1; var i2; + var x; var y; var v; var i; @@ -162,6 +163,9 @@ function unary3d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + // Cache a reference to the input ndarray: + x = arrays[ 0 ]; + // Resolve the output ndarray and associated shape: y = arrays[ 1 ]; sh = y.shape; @@ -214,8 +218,8 @@ function unary3d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR for ( i0 = 0; i0 < S0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i2, i1, i0 ], cdims, clbk, thisArg ); // eslint-disable-line max-len - set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); // eslint-disable-line max-len + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ i2, i1, i0 ], cdims, clbk, thisArg ); + set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); incrementOffsets( iv, dv0 ); } incrementOffsets( iv, dv1 ); diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_blocked.js index 999b0b1055e0..f91ef17cad9c 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_blocked.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable max-params, max-depth */ +/* eslint-disable max-len, max-params, max-depth */ 'use strict'; @@ -139,7 +139,7 @@ var wrap = require( './callback_wrapper.js' ); * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ 8.0, 16.0, 24.0 ] ] ] */ -function blockedunary3d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len +function blockedunary3d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { var bsize; var ybuf; var dv0; @@ -248,8 +248,8 @@ function blockedunary3d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strid for ( i0 = 0; i0 < s0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); // eslint-disable-line max-len - ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); // eslint-disable-line max-len + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); incrementOffsets( iv, dv0 ); } incrementOffsets( iv, dv1 ); diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_blocked_accessors.js index 4bf52cc73630..d70801bc1c86 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_blocked_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_blocked_accessors.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable max-params, max-depth */ +/* eslint-disable max-len, max-params, max-depth */ 'use strict'; @@ -143,7 +143,7 @@ var wrap = require( './callback_wrapper.js' ); * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ 8.0, 16.0, 24.0 ] ] ] */ -function blockedunary3d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len +function blockedunary3d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { var bsize; var ybuf; var dv0; @@ -256,8 +256,8 @@ function blockedunary3d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strid for ( i0 = 0; i0 < s0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); // eslint-disable-line max-len - set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); // eslint-disable-line max-len + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); incrementOffsets( iv, dv0 ); } incrementOffsets( iv, dv1 ); From 6643e14921d8a136207ae3ad0bd46d26d08572db Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Thu, 5 Jun 2025 18:37:35 +0000 Subject: [PATCH 09/16] feat: add 4d kernels --- 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 --- --- .../base/unary-reduce-strided1d-by/lib/4d.js | 233 ++++++++++++++ .../lib/4d_accessors.js | 241 ++++++++++++++ .../lib/4d_blocked.js | 290 +++++++++++++++++ .../lib/4d_blocked_accessors.js | 298 ++++++++++++++++++ 4 files changed, 1062 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_blocked_accessors.js diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d.js new file mode 100644 index 000000000000..3aee676bc8f6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d.js @@ -0,0 +1,233 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params */ + +'use strict'; + +// MODULES // + +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {boolean} isRowMajor - boolean indicating whether the input ndarray is row-major +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3 ]; +* var cdims = [ 4, 5 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* unary4d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] +*/ +function unary4d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { + var ybuf; + var dv0; + var dv1; + var dv2; + var dv3; + var sh; + var S0; + var S1; + var S2; + var S3; + var sv; + var iv; + var i0; + var i1; + var i2; + var i3; + var y; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the output ndarray and associated shape: + y = arrays[ 1 ]; + sh = y.shape; + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 3 ]; + S1 = sh[ 2 ]; + S2 = sh[ 1 ]; + S3 = sh[ 0 ]; + dv0 = [ strides[3] ]; // offset increment for innermost loop + dv1 = [ strides[2] - ( S0*strides[3] ) ]; + dv2 = [ strides[1] - ( S1*strides[2] ) ]; + dv3 = [ strides[0] - ( S2*strides[1] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[3] ); + dv1.push( sv[2] - ( S0*sv[3] ) ); + dv2.push( sv[1] - ( S1*sv[2] ) ); + dv3.push( sv[0] - ( S2*sv[1]) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + dv0 = [ strides[0] ]; // offset increment for innermost loop + dv1 = [ strides[1] - ( S0*strides[0] ) ]; + dv2 = [ strides[2] - ( S1*strides[1] ) ]; + dv3 = [ strides[3] - ( S2*strides[2] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + dv2.push( sv[2] - ( S1*sv[1] ) ); + dv3.push( sv[3] - ( S2*sv[2] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Iterate over the non-reduced ndarray dimensions... + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i3, i2, i1, i0 ], cdims, clbk, thisArg ); + ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv3 ); + } + } +} + + +// EXPORTS // + +module.exports = unary4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_accessors.js new file mode 100644 index 000000000000..c6a5b5b269f4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_accessors.js @@ -0,0 +1,241 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params */ + +'use strict'; + +// MODULES // + +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {boolean} isRowMajor - boolean indicating whether the input ndarray is row-major +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ) ); +* var ybuf = toAccessorArray( new Float64Array( [ 0.0, 0.0, 0.0 ] ) ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3 ]; +* var cdims = [ 4, 5 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* unary4d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] +*/ +function unary4d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { + var ybuf; + var dv0; + var dv1; + var dv2; + var dv3; + var set; + var sh; + var S0; + var S1; + var S2; + var S3; + var sv; + var iv; + var i0; + var i1; + var i2; + var i3; + var y; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the output ndarray and associated shape: + y = arrays[ 1 ]; + sh = y.shape; + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 3 ]; + S1 = sh[ 2 ]; + S2 = sh[ 1 ]; + S3 = sh[ 0 ]; + dv0 = [ strides[3] ]; // offset increment for innermost loop + dv1 = [ strides[2] - ( S0*strides[3] ) ]; + dv2 = [ strides[1] - ( S1*strides[2] ) ]; + dv3 = [ strides[0] - ( S2*strides[1] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[3] ); + dv1.push( sv[2] - ( S0*sv[3] ) ); + dv2.push( sv[1] - ( S1*sv[2] ) ); + dv3.push( sv[0] - ( S2*sv[1]) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + dv0 = [ strides[0] ]; // offset increment for innermost loop + dv1 = [ strides[1] - ( S0*strides[0] ) ]; + dv2 = [ strides[2] - ( S1*strides[1] ) ]; + dv3 = [ strides[3] - ( S2*strides[2] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + dv2.push( sv[2] - ( S1*sv[1] ) ); + dv3.push( sv[3] - ( S2*sv[2] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache accessors: + set = y.accessors[ 1 ]; + + // Iterate over the non-reduced ndarray dimensions... + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i3, i2, i1, i0 ], cdims, clbk, thisArg ); + set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv3 ); + } + } +} + + +// EXPORTS // + +module.exports = unary4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_blocked.js new file mode 100644 index 000000000000..7fa04cf56c1e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_blocked.js @@ -0,0 +1,290 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params, max-depth, max-statements */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/unary-tiling-block-size' ); +var takeIndexed = require( '@stdlib/array/base/take-indexed' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to a callback function and assigns results to a provided output ndarray via loop blocking. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3 ]; +* var cdims = [ 4, 5 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* blockedunary4d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] +*/ +function blockedunary4d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { + var bsize; + var ybuf; + var dv0; + var dv1; + var dv2; + var dv3; + var ov1; + var ov2; + var ov3; + var sh; + var s0; + var s1; + var s2; + var s3; + var sv; + var ov; + var iv; + var i0; + var i1; + var i2; + var i3; + var j0; + var j1; + var j2; + var j3; + var N; + var x; + var y; + var v; + var o; + var k; + var f; + + // Note on variable naming convention: S#, dv#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + N = arrays.length; + x = arrays[ 0 ]; + y = arrays[ 1 ]; + + // Resolve the loop interchange order: + o = loopOrder( y.shape, strides, y.strides ); + sh = o.sh; + sv = [ o.sx, o.sy ]; + for ( k = 2; k < N; k++ ) { + sv.push( takeIndexed( arrays[k].strides, o.idx ) ); + } + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype ); + + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + ov = offsets( arrays ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache offset increments for the innermost loop... + dv0 = []; + for ( k = 0; k < N; k++ ) { + dv0.push( sv[k][0] ); + } + // Initialize loop variables... + ov1 = zeros( N ); + ov2 = zeros( N ); + ov3 = zeros( N ); + dv1 = zeros( N ); + dv2 = zeros( N ); + dv3 = zeros( N ); + iv = zeros( N ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over blocks... + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov3[ k ] = ov[k] + ( j3*sv[k][3] ); + } + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov2[ k ] = ov3[k] + ( j2*sv[k][2] ); + dv3[ k ] = sv[k][3] - ( s2*sv[k][2] ); + } + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov1[ k ] = ov2[k] + ( j1*sv[k][1] ); + dv2[ k ] = sv[k][2] - ( s1*sv[k][1] ); + } + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets and loop offset increments for the first ndarray elements in the current block... + for ( k = 0; k < N; k++ ) { + iv[ k ] = ov1[k] + ( j0*sv[k][0] ); + dv1[ k ] = sv[k][1] - ( s0*sv[k][0] ); + } + // Iterate over the non-reduced ndarray dimensions... + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedunary4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_blocked_accessors.js new file mode 100644 index 000000000000..320157d6aa2f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_blocked_accessors.js @@ -0,0 +1,298 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params, max-depth, max-statements */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/unary-tiling-block-size' ); +var takeIndexed = require( '@stdlib/array/base/take-indexed' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to a callback function and assigns results to a provided output ndarray via loop blocking. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3 ]; +* var cdims = [ 4, 5 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* blockedunary4d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] +*/ +function blockedunary4d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { + var bsize; + var ybuf; + var set; + var dv0; + var dv1; + var dv2; + var dv3; + var ov1; + var ov2; + var ov3; + var sh; + var s0; + var s1; + var s2; + var s3; + var sv; + var ov; + var iv; + var i0; + var i1; + var i2; + var i3; + var j0; + var j1; + var j2; + var j3; + var N; + var x; + var y; + var v; + var o; + var k; + var f; + + // Note on variable naming convention: S#, dv#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + N = arrays.length; + x = arrays[ 0 ]; + y = arrays[ 1 ]; + + // Resolve the loop interchange order: + o = loopOrder( y.shape, strides, y.strides ); + sh = o.sh; + sv = [ o.sx, o.sy ]; + for ( k = 2; k < N; k++ ) { + sv.push( takeIndexed( arrays[k].strides, o.idx ) ); + } + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype ); + + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + ov = offsets( arrays ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache accessors: + set = y.accessors[ 1 ]; + + // Cache offset increments for the innermost loop... + dv0 = []; + for ( k = 0; k < N; k++ ) { + dv0.push( sv[k][0] ); + } + // Initialize loop variables... + ov1 = zeros( N ); + ov2 = zeros( N ); + ov3 = zeros( N ); + dv1 = zeros( N ); + dv2 = zeros( N ); + dv3 = zeros( N ); + iv = zeros( N ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over blocks... + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov3[ k ] = ov[k] + ( j3*sv[k][3] ); + } + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov2[ k ] = ov3[k] + ( j2*sv[k][2] ); + dv3[ k ] = sv[k][3] - ( s2*sv[k][2] ); + } + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov1[ k ] = ov2[k] + ( j1*sv[k][1] ); + dv2[ k ] = sv[k][2] - ( s1*sv[k][1] ); + } + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets and loop offset increments for the first ndarray elements in the current block... + for ( k = 0; k < N; k++ ) { + iv[ k ] = ov1[k] + ( j0*sv[k][0] ); + dv1[ k ] = sv[k][1] - ( s0*sv[k][0] ); + } + // Iterate over the non-reduced ndarray dimensions... + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedunary4d; From f9b2784a3090a4893cf9fbd7628721f5b71df60d Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Thu, 5 Jun 2025 18:54:28 +0000 Subject: [PATCH 10/16] feat: add 5d kernels --- 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 --- --- .../base/unary-reduce-strided1d-by/lib/5d.js | 246 ++++++++++++++ .../lib/5d_accessors.js | 254 ++++++++++++++ .../lib/5d_blocked.js | 313 +++++++++++++++++ .../lib/5d_blocked_accessors.js | 321 ++++++++++++++++++ 4 files changed, 1134 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_blocked_accessors.js diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d.js new file mode 100644 index 000000000000..7bb9a31f50bf --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d.js @@ -0,0 +1,246 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params */ + +'use strict'; + +// MODULES // + +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {boolean} isRowMajor - boolean indicating whether the input ndarray is row-major +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4 ]; +* var cdims = [ 5, 6 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* unary5d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] +*/ +function unary5d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { + var ybuf; + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var sv; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var y; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the output ndarray and associated shape: + y = arrays[ 1 ]; + sh = y.shape; + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 4 ]; + S1 = sh[ 3 ]; + S2 = sh[ 2 ]; + S3 = sh[ 1 ]; + S4 = sh[ 0 ]; + dv0 = [ strides[4] ]; // offset increment for innermost loop + dv1 = [ strides[3] - ( S0*strides[4] ) ]; + dv2 = [ strides[2] - ( S1*strides[3] ) ]; + dv3 = [ strides[1] - ( S2*strides[2] ) ]; + dv4 = [ strides[0] - ( S3*strides[1] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[4] ); + dv1.push( sv[3] - ( S0*sv[4] ) ); + dv2.push( sv[2] - ( S1*sv[3] ) ); + dv3.push( sv[1] - ( S2*sv[2] ) ); + dv4.push( sv[0] - ( S3*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + dv0 = [ strides[0] ]; // offset increment for innermost loop + dv1 = [ strides[1] - ( S0*strides[0] ) ]; + dv2 = [ strides[2] - ( S1*strides[1] ) ]; + dv3 = [ strides[3] - ( S2*strides[2] ) ]; + dv4 = [ strides[4] - ( S3*strides[3] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + dv2.push( sv[2] - ( S1*sv[1] ) ); + dv3.push( sv[3] - ( S2*sv[2] ) ); + dv4.push( sv[4] - ( S3*sv[3] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Iterate over the non-reduced ndarray dimensions... + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } +} + + +// EXPORTS // + +module.exports = unary5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_accessors.js new file mode 100644 index 000000000000..e49381072b04 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_accessors.js @@ -0,0 +1,254 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params */ + +'use strict'; + +// MODULES // + +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {boolean} isRowMajor - boolean indicating whether the input ndarray is row-major +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ) ); +* var ybuf = toAccessorArray( new Float64Array( [ 0.0, 0.0, 0.0 ] ) ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4 ]; +* var cdims = [ 5, 6 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* unary5d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] +*/ +function unary5d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { + var ybuf; + var set; + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var sv; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var y; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the output ndarray and associated shape: + y = arrays[ 1 ]; + sh = y.shape; + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 4 ]; + S1 = sh[ 3 ]; + S2 = sh[ 2 ]; + S3 = sh[ 1 ]; + S4 = sh[ 0 ]; + dv0 = [ strides[4] ]; // offset increment for innermost loop + dv1 = [ strides[3] - ( S0*strides[4] ) ]; + dv2 = [ strides[2] - ( S1*strides[3] ) ]; + dv3 = [ strides[1] - ( S2*strides[2] ) ]; + dv4 = [ strides[0] - ( S3*strides[1] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[4] ); + dv1.push( sv[3] - ( S0*sv[4] ) ); + dv2.push( sv[2] - ( S1*sv[3] ) ); + dv3.push( sv[1] - ( S2*sv[2] ) ); + dv4.push( sv[0] - ( S3*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + dv0 = [ strides[0] ]; // offset increment for innermost loop + dv1 = [ strides[1] - ( S0*strides[0] ) ]; + dv2 = [ strides[2] - ( S1*strides[1] ) ]; + dv3 = [ strides[3] - ( S2*strides[2] ) ]; + dv4 = [ strides[4] - ( S3*strides[3] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + dv2.push( sv[2] - ( S1*sv[1] ) ); + dv3.push( sv[3] - ( S2*sv[2] ) ); + dv4.push( sv[4] - ( S3*sv[3] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache accessors: + set = y.accessors[ 1 ]; + + // Iterate over the non-reduced ndarray dimensions... + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } +} + + +// EXPORTS // + +module.exports = unary5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_blocked.js new file mode 100644 index 000000000000..3504f92df656 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_blocked.js @@ -0,0 +1,313 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params, max-depth, max-statements */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/unary-tiling-block-size' ); +var takeIndexed = require( '@stdlib/array/base/take-indexed' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to a callback function and assigns results to a provided output ndarray via loop blocking. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4 ]; +* var cdims = [ 5, 6 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* blockedunary5d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] +*/ +function blockedunary5d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { + var bsize; + var ybuf; + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var ov1; + var ov2; + var ov3; + var ov4; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var sv; + var ov; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var j0; + var j1; + var j2; + var j3; + var j4; + var N; + var x; + var y; + var v; + var o; + var k; + var f; + + // Note on variable naming convention: S#, dv#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + N = arrays.length; + x = arrays[ 0 ]; + y = arrays[ 1 ]; + + // Resolve the loop interchange order: + o = loopOrder( y.shape, strides, y.strides ); + sh = o.sh; + sv = [ o.sx, o.sy ]; + for ( k = 2; k < N; k++ ) { + sv.push( takeIndexed( arrays[k].strides, o.idx ) ); + } + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype ); + + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + ov = offsets( arrays ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache offset increments for the innermost loop... + dv0 = []; + for ( k = 0; k < N; k++ ) { + dv0.push( sv[k][0] ); + } + // Initialize loop variables... + ov1 = zeros( N ); + ov2 = zeros( N ); + ov3 = zeros( N ); + ov4 = zeros( N ); + dv1 = zeros( N ); + dv2 = zeros( N ); + dv3 = zeros( N ); + dv4 = zeros( N ); + iv = zeros( N ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over blocks... + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov4[ k ] = ov[k] + ( j4*sv[k][4] ); + } + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv4[ k ] = sv[k][4] - ( s3*sv[k][3] ); + ov3[ k ] = ov4[k] + ( j3*sv[k][3] ); + } + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv3[ k ] = sv[k][3] - ( s2*sv[k][2] ); + ov2[ k ] = ov3[k] + ( j2*sv[k][2] ); + } + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv2[ k ] = sv[k][2] - ( s1*sv[k][1] ); + ov1[ k ] = ov2[k] + ( j1*sv[k][1] ); + } + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets and loop offset increments for the first ndarray elements in the current block... + for ( k = 0; k < N; k++ ) { + iv[ k ] = ov1[k] + ( j0*sv[k][0] ); + dv1[ k ] = sv[k][1] - ( s0*sv[k][0] ); + } + // Iterate over the non-reduced ndarray dimensions... + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedunary5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_blocked_accessors.js new file mode 100644 index 000000000000..9d30eeaa5460 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_blocked_accessors.js @@ -0,0 +1,321 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params, max-depth, max-statements */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/unary-tiling-block-size' ); +var takeIndexed = require( '@stdlib/array/base/take-indexed' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to a callback function and assigns results to a provided output ndarray via loop blocking. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4 ]; +* var cdims = [ 5, 6 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* blockedunary5d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] +*/ +function blockedunary5d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { + var bsize; + var ybuf; + var set; + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var ov1; + var ov2; + var ov3; + var ov4; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var sv; + var ov; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var j0; + var j1; + var j2; + var j3; + var j4; + var N; + var x; + var y; + var v; + var o; + var k; + var f; + + // Note on variable naming convention: S#, dv#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + N = arrays.length; + x = arrays[ 0 ]; + y = arrays[ 1 ]; + + // Resolve the loop interchange order: + o = loopOrder( y.shape, strides, y.strides ); + sh = o.sh; + sv = [ o.sx, o.sy ]; + for ( k = 2; k < N; k++ ) { + sv.push( takeIndexed( arrays[k].strides, o.idx ) ); + } + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype ); + + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + ov = offsets( arrays ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache accessors: + set = y.accessors[1]; + + // Cache offset increments for the innermost loop... + dv0 = []; + for ( k = 0; k < N; k++ ) { + dv0.push( sv[k][0] ); + } + // Initialize loop variables... + ov1 = zeros( N ); + ov2 = zeros( N ); + ov3 = zeros( N ); + ov4 = zeros( N ); + dv1 = zeros( N ); + dv2 = zeros( N ); + dv3 = zeros( N ); + dv4 = zeros( N ); + iv = zeros( N ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over blocks... + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov4[ k ] = ov[k] + ( j4*sv[k][4] ); + } + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv4[ k ] = sv[k][4] - ( s3*sv[k][3] ); + ov3[ k ] = ov4[k] + ( j3*sv[k][3] ); + } + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv3[ k ] = sv[k][3] - ( s2*sv[k][2] ); + ov2[ k ] = ov3[k] + ( j2*sv[k][2] ); + } + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv2[ k ] = sv[k][2] - ( s1*sv[k][1] ); + ov1[ k ] = ov2[k] + ( j1*sv[k][1] ); + } + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets and loop offset increments for the first ndarray elements in the current block... + for ( k = 0; k < N; k++ ) { + iv[ k ] = ov1[k] + ( j0*sv[k][0] ); + dv1[ k ] = sv[k][1] - ( s0*sv[k][0] ); + } + // Iterate over the non-reduced ndarray dimensions... + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedunary5d; From c17a77bae2bdc9acfd0546f60d7122efd9c465ee Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Thu, 5 Jun 2025 19:14:10 +0000 Subject: [PATCH 11/16] feat: add 6d kernels --- 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 --- --- .../base/unary-reduce-strided1d-by/lib/6d.js | 258 +++++++++++++ .../lib/6d_accessors.js | 266 ++++++++++++++ .../lib/6d_blocked.js | 336 +++++++++++++++++ .../lib/6d_blocked_accessors.js | 344 ++++++++++++++++++ 4 files changed, 1204 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_blocked_accessors.js diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d.js new file mode 100644 index 000000000000..d2411928afaf --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d.js @@ -0,0 +1,258 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params, max-depth */ + +'use strict'; + +// MODULES // + +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {boolean} isRowMajor - boolean indicating whether the input ndarray is row-major +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5 ]; +* var cdims = [ 6, 7 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* unary6d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] +*/ +function unary6d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { + var ybuf; + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var sv; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var y; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the output ndarray and associated shape: + y = arrays[ 1 ]; + sh = y.shape; + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 5 ]; + S1 = sh[ 4 ]; + S2 = sh[ 3 ]; + S3 = sh[ 2 ]; + S4 = sh[ 1 ]; + S5 = sh[ 0 ]; + dv0 = [ strides[5] ]; // offset increment for innermost loop + dv1 = [ strides[4] - ( S0*strides[5] ) ]; + dv2 = [ strides[3] - ( S1*strides[4] ) ]; + dv3 = [ strides[2] - ( S2*strides[3] ) ]; + dv4 = [ strides[1] - ( S3*strides[2] ) ]; + dv5 = [ strides[0] - ( S4*strides[1] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[5] ); + dv1.push( sv[4] - ( S0*sv[5] ) ); + dv2.push( sv[3] - ( S1*sv[4] ) ); + dv3.push( sv[2] - ( S2*sv[3] ) ); + dv4.push( sv[1] - ( S3*sv[2] ) ); + dv5.push( sv[0] - ( S4*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + dv0 = [ strides[0] ]; // offset increment for innermost loop + dv1 = [ strides[1] - ( S0*strides[0] ) ]; + dv2 = [ strides[2] - ( S1*strides[1] ) ]; + dv3 = [ strides[3] - ( S2*strides[2] ) ]; + dv4 = [ strides[4] - ( S3*strides[3] ) ]; + dv5 = [ strides[5] - ( S4*strides[4] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + dv2.push( sv[2] - ( S1*sv[1] ) ); + dv3.push( sv[3] - ( S2*sv[2] ) ); + dv4.push( sv[4] - ( S3*sv[3] ) ); + dv5.push( sv[5] - ( S4*sv[4] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Iterate over the non-reduced ndarray dimensions... + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } +} + + +// EXPORTS // + +module.exports = unary6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_accessors.js new file mode 100644 index 000000000000..368b16f9ac40 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_accessors.js @@ -0,0 +1,266 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params, max-depth */ + +'use strict'; + +// MODULES // + +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {boolean} isRowMajor - boolean indicating whether the input ndarray is row-major +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ) ); +* var ybuf = toAccessorArray( new Float64Array( [ 0.0, 0.0, 0.0 ] ) ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5 ]; +* var cdims = [ 6, 7 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* unary6d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] +*/ +function unary6d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { + var ybuf; + var set; + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var sv; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var y; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the output ndarray and associated shape: + y = arrays[ 1 ]; + sh = y.shape; + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 5 ]; + S1 = sh[ 4 ]; + S2 = sh[ 3 ]; + S3 = sh[ 2 ]; + S4 = sh[ 1 ]; + S5 = sh[ 0 ]; + dv0 = [ strides[5] ]; // offset increment for innermost loop + dv1 = [ strides[4] - ( S0*strides[5] ) ]; + dv2 = [ strides[3] - ( S1*strides[4] ) ]; + dv3 = [ strides[2] - ( S2*strides[3] ) ]; + dv4 = [ strides[1] - ( S3*strides[2] ) ]; + dv5 = [ strides[0] - ( S4*strides[1] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[5] ); + dv1.push( sv[4] - ( S0*sv[5] ) ); + dv2.push( sv[3] - ( S1*sv[4] ) ); + dv3.push( sv[2] - ( S2*sv[3] ) ); + dv4.push( sv[1] - ( S3*sv[2] ) ); + dv5.push( sv[0] - ( S4*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + dv0 = [ strides[0] ]; // offset increment for innermost loop + dv1 = [ strides[1] - ( S0*strides[0] ) ]; + dv2 = [ strides[2] - ( S1*strides[1] ) ]; + dv3 = [ strides[3] - ( S2*strides[2] ) ]; + dv4 = [ strides[4] - ( S3*strides[3] ) ]; + dv5 = [ strides[5] - ( S4*strides[4] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + dv2.push( sv[2] - ( S1*sv[1] ) ); + dv3.push( sv[3] - ( S2*sv[2] ) ); + dv4.push( sv[4] - ( S3*sv[3] ) ); + dv5.push( sv[5] - ( S4*sv[4] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache accessors: + set = y.accessors[ 1 ]; + + // Iterate over the non-reduced ndarray dimensions... + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } +} + + +// EXPORTS // + +module.exports = unary6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_blocked.js new file mode 100644 index 000000000000..f90916558a6f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_blocked.js @@ -0,0 +1,336 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params, max-depth, max-statements */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/unary-tiling-block-size' ); +var takeIndexed = require( '@stdlib/array/base/take-indexed' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to a callback function and assigns results to a provided output ndarray via loop blocking. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5 ]; +* var cdims = [ 6, 7 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* blockedunary6d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] +*/ +function blockedunary6d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { + var bsize; + var ybuf; + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var ov1; + var ov2; + var ov3; + var ov4; + var ov5; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var sv; + var ov; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var j0; + var j1; + var j2; + var j3; + var j4; + var j5; + var N; + var x; + var y; + var v; + var o; + var k; + var f; + + // Note on variable naming convention: S#, dv#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + N = arrays.length; + x = arrays[ 0 ]; + y = arrays[ 1 ]; + + // Resolve the loop interchange order: + o = loopOrder( y.shape, strides, y.strides ); + sh = o.sh; + sv = [ o.sx, o.sy ]; + for ( k = 2; k < N; k++ ) { + sv.push( takeIndexed( arrays[k].strides, o.idx ) ); + } + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype ); + + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + ov = offsets( arrays ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache offset increments for the innermost loop... + dv0 = []; + for ( k = 0; k < N; k++ ) { + dv0.push( sv[k][0] ); + } + // Initialize loop variables... + ov1 = zeros( N ); + ov2 = zeros( N ); + ov3 = zeros( N ); + ov4 = zeros( N ); + ov5 = zeros( N ); + dv1 = zeros( N ); + dv2 = zeros( N ); + dv3 = zeros( N ); + dv4 = zeros( N ); + dv5 = zeros( N ); + iv = zeros( N ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over blocks... + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov5[ k ] = ov[k] + ( j5*sv[k][5] ); + } + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv5 = sv[k][5] - ( s4*sv[k][4] ); + ov4[ k ] = ov5[k] + ( j4*sv[k][4] ); + } + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv4[ k ] = sv[k][4] - ( s3*sv[k][3] ); + ov3[ k ] = ov4[k] + ( j3*sv[k][3] ); + } + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv3[ k ] = sv[k][3] - ( s2*sv[k][2] ); + ov2[ k ] = ov3[k] + ( j2*sv[k][2] ); + } + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv2[ k ] = sv[k][2] - ( s1*sv[k][1] ); + ov1[ k ] = ov2[k] + ( j1*sv[k][1] ); + } + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets and loop offset increments for the first ndarray elements in the current block... + for ( k = 0; k < N; k++ ) { + iv[ k ] = ov1[k] + ( j0*sv[k][0] ); + dv1[ k ] = sv[k][1] - ( s0*sv[k][0] ); + } + // Iterate over the non-reduced ndarray dimensions... + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedunary6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_blocked_accessors.js new file mode 100644 index 000000000000..cceb023fded6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_blocked_accessors.js @@ -0,0 +1,344 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params, max-depth, max-statements */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/unary-tiling-block-size' ); +var takeIndexed = require( '@stdlib/array/base/take-indexed' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to a callback function and assigns results to a provided output ndarray via loop blocking. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5 ]; +* var cdims = [ 6, 7 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* blockedunary6d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] +*/ +function blockedunary6d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { + var bsize; + var ybuf; + var set; + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var ov1; + var ov2; + var ov3; + var ov4; + var ov5; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var sv; + var ov; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var j0; + var j1; + var j2; + var j3; + var j4; + var j5; + var N; + var x; + var y; + var v; + var o; + var k; + var f; + + // Note on variable naming convention: S#, dv#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + N = arrays.length; + x = arrays[ 0 ]; + y = arrays[ 1 ]; + + // Resolve the loop interchange order: + o = loopOrder( y.shape, strides, y.strides ); + sh = o.sh; + sv = [ o.sx, o.sy ]; + for ( k = 2; k < N; k++ ) { + sv.push( takeIndexed( arrays[k].strides, o.idx ) ); + } + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype ); + + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + ov = offsets( arrays ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache accessors: + set = y.accessors[1]; + + // Cache offset increments for the innermost loop... + dv0 = []; + for ( k = 0; k < N; k++ ) { + dv0.push( sv[k][0] ); + } + // Initialize loop variables... + ov1 = zeros( N ); + ov2 = zeros( N ); + ov3 = zeros( N ); + ov4 = zeros( N ); + ov5 = zeros( N ); + dv1 = zeros( N ); + dv2 = zeros( N ); + dv3 = zeros( N ); + dv4 = zeros( N ); + dv5 = zeros( N ); + iv = zeros( N ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over blocks... + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov5[ k ] = ov[k] + ( j5*sv[k][5] ); + } + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv5 = sv[k][5] - ( s4*sv[k][4] ); + ov4[ k ] = ov5[k] + ( j4*sv[k][4] ); + } + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv4[ k ] = sv[k][4] - ( s3*sv[k][3] ); + ov3[ k ] = ov4[k] + ( j3*sv[k][3] ); + } + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv3[ k ] = sv[k][3] - ( s2*sv[k][2] ); + ov2[ k ] = ov3[k] + ( j2*sv[k][2] ); + } + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv2[ k ] = sv[k][2] - ( s1*sv[k][1] ); + ov1[ k ] = ov2[k] + ( j1*sv[k][1] ); + } + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets and loop offset increments for the first ndarray elements in the current block... + for ( k = 0; k < N; k++ ) { + iv[ k ] = ov1[k] + ( j0*sv[k][0] ); + dv1[ k ] = sv[k][1] - ( s0*sv[k][0] ); + } + // Iterate over the non-reduced ndarray dimensions... + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedunary6d; From 27ddd9203169e9f5f5da5543da534abbea9be9d4 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Thu, 5 Jun 2025 19:24:39 +0000 Subject: [PATCH 12/16] feat: add 7d kernels --- 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 --- --- .../base/unary-reduce-strided1d-by/lib/7d.js | 270 +++++++++++++ .../lib/7d_accessors.js | 278 +++++++++++++ .../lib/7d_blocked.js | 359 +++++++++++++++++ .../lib/7d_blocked_accessors.js | 367 ++++++++++++++++++ 4 files changed, 1274 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_blocked_accessors.js diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d.js new file mode 100644 index 000000000000..81863383cd8f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d.js @@ -0,0 +1,270 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params, max-depth */ + +'use strict'; + +// MODULES // + +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {boolean} isRowMajor - boolean indicating whether the input ndarray is row-major +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5, 6 ]; +* var cdims = [ 7, 8 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* unary7d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] +*/ +function unary7d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { + var ybuf; + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var dv6; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var sv; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var y; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the output ndarray and associated shape: + y = arrays[ 1 ]; + sh = y.shape; + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 6 ]; + S1 = sh[ 5 ]; + S2 = sh[ 4 ]; + S3 = sh[ 3 ]; + S4 = sh[ 2 ]; + S5 = sh[ 1 ]; + S6 = sh[ 0 ]; + dv0 = [ strides[6] ]; // offset increment for innermost loop + dv1 = [ strides[5] - ( S0*strides[6] ) ]; + dv2 = [ strides[4] - ( S1*strides[5] ) ]; + dv3 = [ strides[3] - ( S2*strides[4] ) ]; + dv4 = [ strides[2] - ( S3*strides[3] ) ]; + dv5 = [ strides[1] - ( S4*strides[2] ) ]; + dv6 = [ strides[0] - ( S5*strides[1] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[6] ); + dv1.push( sv[5] - ( S0*sv[6] ) ); + dv2.push( sv[4] - ( S1*sv[5] ) ); + dv3.push( sv[3] - ( S2*sv[4] ) ); + dv4.push( sv[2] - ( S3*sv[3] ) ); + dv5.push( sv[1] - ( S4*sv[2] ) ); + dv6.push( sv[0] - ( S5*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + S6 = sh[ 6 ]; + dv0 = [ strides[0] ]; // offset increment for innermost loop + dv1 = [ strides[1] - ( S0*strides[0] ) ]; + dv2 = [ strides[2] - ( S1*strides[1] ) ]; + dv3 = [ strides[3] - ( S2*strides[2] ) ]; + dv4 = [ strides[4] - ( S3*strides[3] ) ]; + dv5 = [ strides[5] - ( S4*strides[4] ) ]; + dv6 = [ strides[6] - ( S5*strides[5] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + dv2.push( sv[2] - ( S1*sv[1] ) ); + dv3.push( sv[3] - ( S2*sv[2] ) ); + dv4.push( sv[4] - ( S3*sv[3] ) ); + dv5.push( sv[5] - ( S4*sv[4] ) ); + dv6.push( sv[6] - ( S5*sv[5] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Iterate over the non-reduced ndarray dimensions... + for ( i6 = 0; i6 < S6; i6++ ) { + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } + incrementOffsets( iv, dv6 ); + } +} + + +// EXPORTS // + +module.exports = unary7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_accessors.js new file mode 100644 index 000000000000..899c9bd30a67 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_accessors.js @@ -0,0 +1,278 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params, max-depth, max-statements */ + +'use strict'; + +// MODULES // + +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {boolean} isRowMajor - boolean indicating whether the input ndarray is row-major +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ) ); +* var ybuf = toAccessorArray( new Float64Array( [ 0.0, 0.0, 0.0 ] ) ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5, 6 ]; +* var cdims = [ 7, 8 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* unary7d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] +*/ +function unary7d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { + var ybuf; + var set; + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var dv6; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var sv; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var y; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the output ndarray and associated shape: + y = arrays[ 1 ]; + sh = y.shape; + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 6 ]; + S1 = sh[ 5 ]; + S2 = sh[ 4 ]; + S3 = sh[ 3 ]; + S4 = sh[ 2 ]; + S5 = sh[ 1 ]; + S6 = sh[ 0 ]; + dv0 = [ strides[6] ]; // offset increment for innermost loop + dv1 = [ strides[5] - ( S0*strides[6] ) ]; + dv2 = [ strides[4] - ( S1*strides[5] ) ]; + dv3 = [ strides[3] - ( S2*strides[4] ) ]; + dv4 = [ strides[2] - ( S3*strides[3] ) ]; + dv5 = [ strides[1] - ( S4*strides[2] ) ]; + dv6 = [ strides[0] - ( S5*strides[1] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[6] ); + dv1.push( sv[5] - ( S0*sv[6] ) ); + dv2.push( sv[4] - ( S1*sv[5] ) ); + dv3.push( sv[3] - ( S2*sv[4] ) ); + dv4.push( sv[2] - ( S3*sv[3] ) ); + dv5.push( sv[1] - ( S4*sv[2] ) ); + dv6.push( sv[0] - ( S5*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + S6 = sh[ 6 ]; + dv0 = [ strides[0] ]; // offset increment for innermost loop + dv1 = [ strides[1] - ( S0*strides[0] ) ]; + dv2 = [ strides[2] - ( S1*strides[1] ) ]; + dv3 = [ strides[3] - ( S2*strides[2] ) ]; + dv4 = [ strides[4] - ( S3*strides[3] ) ]; + dv5 = [ strides[5] - ( S4*strides[4] ) ]; + dv6 = [ strides[6] - ( S5*strides[5] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + dv2.push( sv[2] - ( S1*sv[1] ) ); + dv3.push( sv[3] - ( S2*sv[2] ) ); + dv4.push( sv[4] - ( S3*sv[3] ) ); + dv5.push( sv[5] - ( S4*sv[4] ) ); + dv6.push( sv[6] - ( S5*sv[5] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache accessors: + set = y.accessors[ 1 ]; + + // Iterate over the non-reduced ndarray dimensions... + for ( i6 = 0; i6 < S6; i6++ ) { + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } + incrementOffsets( iv, dv6 ); + } +} + + +// EXPORTS // + +module.exports = unary7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_blocked.js new file mode 100644 index 000000000000..1973cd453b31 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_blocked.js @@ -0,0 +1,359 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params, max-depth, max-statements */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/unary-tiling-block-size' ); +var takeIndexed = require( '@stdlib/array/base/take-indexed' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to a callback function and assigns results to a provided output ndarray via loop blocking. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5, 6 ]; +* var cdims = [ 7, 8 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* blockedunary7d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] +*/ +function blockedunary7d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { + var bsize; + var ybuf; + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var dv6; + var ov1; + var ov2; + var ov3; + var ov4; + var ov5; + var ov6; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var sv; + var ov; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var j0; + var j1; + var j2; + var j3; + var j4; + var j5; + var j6; + var N; + var x; + var y; + var v; + var o; + var k; + var f; + + // Note on variable naming convention: S#, dv#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + N = arrays.length; + x = arrays[ 0 ]; + y = arrays[ 1 ]; + + // Resolve the loop interchange order: + o = loopOrder( y.shape, strides, y.strides ); + sh = o.sh; + sv = [ o.sx, o.sy ]; + for ( k = 2; k < N; k++ ) { + sv.push( takeIndexed( arrays[k].strides, o.idx ) ); + } + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype ); + + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + ov = offsets( arrays ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache offset increments for the innermost loop... + dv0 = []; + for ( k = 0; k < N; k++ ) { + dv0.push( sv[k][0] ); + } + // Initialize loop variables... + ov1 = zeros( N ); + ov2 = zeros( N ); + ov3 = zeros( N ); + ov4 = zeros( N ); + ov5 = zeros( N ); + ov6 = zeros( N ); + dv1 = zeros( N ); + dv2 = zeros( N ); + dv3 = zeros( N ); + dv4 = zeros( N ); + dv5 = zeros( N ); + dv6 = zeros( N ); + iv = zeros( N ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over blocks... + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov6[ k ] = ov[k] + ( j6*sv[k][6] ); + } + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv6 = sv[k][6] - ( s5*sv[k][5] ); + ov5[ k ] = ov6[k] + ( j5*sv[k][5] ); + } + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv5 = sv[k][5] - ( s4*sv[k][4] ); + ov4[ k ] = ov5[k] + ( j4*sv[k][4] ); + } + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv4[ k ] = sv[k][4] - ( s3*sv[k][3] ); + ov3[ k ] = ov4[k] + ( j3*sv[k][3] ); + } + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv3[ k ] = sv[k][3] - ( s2*sv[k][2] ); + ov2[ k ] = ov3[k] + ( j2*sv[k][2] ); + } + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv2[ k ] = sv[k][2] - ( s1*sv[k][1] ); + ov1[ k ] = ov2[k] + ( j1*sv[k][1] ); + } + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets and loop offset increments for the first ndarray elements in the current block... + for ( k = 0; k < N; k++ ) { + iv[ k ] = ov1[k] + ( j0*sv[k][0] ); + dv1[ k ] = sv[k][1] - ( s0*sv[k][0] ); + } + // Iterate over the non-reduced ndarray dimensions... + for ( i6 = 0; i6 < s6; i6++ ) { + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } + incrementOffsets( iv, dv6 ); + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedunary7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_blocked_accessors.js new file mode 100644 index 000000000000..dc6eff0e8ac5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_blocked_accessors.js @@ -0,0 +1,367 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params, max-depth, max-statements */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/unary-tiling-block-size' ); +var takeIndexed = require( '@stdlib/array/base/take-indexed' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to a callback function and assigns results to a provided output ndarray via loop blocking. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5, 6 ]; +* var cdims = [ 7, 8 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* blockedunary7d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] +*/ +function blockedunary7d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { + var bsize; + var ybuf; + var set; + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var dv6; + var ov1; + var ov2; + var ov3; + var ov4; + var ov5; + var ov6; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var sv; + var ov; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var j0; + var j1; + var j2; + var j3; + var j4; + var j5; + var j6; + var N; + var x; + var y; + var v; + var o; + var k; + var f; + + // Note on variable naming convention: S#, dv#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + N = arrays.length; + x = arrays[ 0 ]; + y = arrays[ 1 ]; + + // Resolve the loop interchange order: + o = loopOrder( y.shape, strides, y.strides ); + sh = o.sh; + sv = [ o.sx, o.sy ]; + for ( k = 2; k < N; k++ ) { + sv.push( takeIndexed( arrays[k].strides, o.idx ) ); + } + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype ); + + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + ov = offsets( arrays ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache accessors: + set = y.accessors[ 1 ]; + + // Cache offset increments for the innermost loop... + dv0 = []; + for ( k = 0; k < N; k++ ) { + dv0.push( sv[k][0] ); + } + // Initialize loop variables... + ov1 = zeros( N ); + ov2 = zeros( N ); + ov3 = zeros( N ); + ov4 = zeros( N ); + ov5 = zeros( N ); + ov6 = zeros( N ); + dv1 = zeros( N ); + dv2 = zeros( N ); + dv3 = zeros( N ); + dv4 = zeros( N ); + dv5 = zeros( N ); + dv6 = zeros( N ); + iv = zeros( N ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over blocks... + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov6[ k ] = ov[k] + ( j6*sv[k][6] ); + } + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv6 = sv[k][6] - ( s5*sv[k][5] ); + ov5[ k ] = ov6[k] + ( j5*sv[k][5] ); + } + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv5 = sv[k][5] - ( s4*sv[k][4] ); + ov4[ k ] = ov5[k] + ( j4*sv[k][4] ); + } + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv4[ k ] = sv[k][4] - ( s3*sv[k][3] ); + ov3[ k ] = ov4[k] + ( j3*sv[k][3] ); + } + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv3[ k ] = sv[k][3] - ( s2*sv[k][2] ); + ov2[ k ] = ov3[k] + ( j2*sv[k][2] ); + } + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv2[ k ] = sv[k][2] - ( s1*sv[k][1] ); + ov1[ k ] = ov2[k] + ( j1*sv[k][1] ); + } + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets and loop offset increments for the first ndarray elements in the current block... + for ( k = 0; k < N; k++ ) { + iv[ k ] = ov1[k] + ( j0*sv[k][0] ); + dv1[ k ] = sv[k][1] - ( s0*sv[k][0] ); + } + // Iterate over the non-reduced ndarray dimensions... + for ( i6 = 0; i6 < s6; i6++ ) { + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } + incrementOffsets( iv, dv6 ); + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedunary7d; From 0229b71f2cd289af54014f817e0330accf3395bd Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Thu, 5 Jun 2025 20:37:05 +0000 Subject: [PATCH 13/16] feat: add remaining kernels --- 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 --- --- .../base/unary-reduce-strided1d-by/lib/10d.js | 306 ++++++++++++ .../lib/10d_accessors.js | 314 +++++++++++++ .../lib/10d_blocked.js | 428 +++++++++++++++++ .../lib/10d_blocked_accessors.js | 436 ++++++++++++++++++ .../base/unary-reduce-strided1d-by/lib/8d.js | 282 +++++++++++ .../lib/8d_accessors.js | 290 ++++++++++++ .../lib/8d_blocked.js | 382 +++++++++++++++ .../lib/8d_blocked_accessors.js | 390 ++++++++++++++++ .../base/unary-reduce-strided1d-by/lib/9d.js | 294 ++++++++++++ .../lib/9d_accessors.js | 302 ++++++++++++ .../lib/9d_blocked.js | 405 ++++++++++++++++ .../lib/9d_blocked_accessors.js | 413 +++++++++++++++++ 12 files changed, 4242 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_blocked_accessors.js diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d.js new file mode 100644 index 000000000000..d90dc2ed689f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d.js @@ -0,0 +1,306 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params, max-depth, max-statements */ + +'use strict'; + +// MODULES // + +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {boolean} isRowMajor - boolean indicating whether the input ndarray is row-major +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 3, 3, 3, 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]; +* var cdims = [ 10, 11 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 12, 12, 12, 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* unary10d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] ] ] ] +*/ +function unary10d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { + var ybuf; + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var dv6; + var dv7; + var dv8; + var dv9; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var S8; + var S9; + var sv; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + var i9; + var y; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the output ndarray and associated shape: + y = arrays[ 1 ]; + sh = y.shape; + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 9 ]; + S1 = sh[ 8 ]; + S2 = sh[ 7 ]; + S3 = sh[ 6 ]; + S4 = sh[ 5 ]; + S5 = sh[ 4 ]; + S6 = sh[ 3 ]; + S7 = sh[ 2 ]; + S8 = sh[ 1 ]; + S9 = sh[ 0 ]; + dv0 = [ strides[9] ]; // offset increment for innermost loop + dv1 = [ strides[8] - ( S0*strides[9] ) ]; + dv2 = [ strides[7] - ( S1*strides[8] ) ]; + dv3 = [ strides[6] - ( S2*strides[7] ) ]; + dv4 = [ strides[5] - ( S3*strides[6] ) ]; + dv5 = [ strides[4] - ( S4*strides[5] ) ]; + dv6 = [ strides[3] - ( S5*strides[4] ) ]; + dv7 = [ strides[2] - ( S6*strides[3] ) ]; + dv8 = [ strides[1] - ( S7*strides[2] ) ]; + dv9 = [ strides[0] - ( S8*strides[1] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[9] ); + dv1.push( sv[8] - ( S0*sv[9] ) ); + dv2.push( sv[7] - ( S1*sv[8] ) ); + dv3.push( sv[6] - ( S2*sv[7] ) ); + dv4.push( sv[5] - ( S3*sv[6] ) ); + dv5.push( sv[4] - ( S4*sv[5] ) ); + dv6.push( sv[3] - ( S5*sv[4] ) ); + dv7.push( sv[2] - ( S6*sv[3] ) ); + dv8.push( sv[1] - ( S7*sv[2] ) ); + dv9.push( sv[0] - ( S8*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + S6 = sh[ 6 ]; + S7 = sh[ 7 ]; + S8 = sh[ 8 ]; + S9 = sh[ 9 ]; + dv0 = [ strides[0] ]; // offset increment for innermost loop + dv1 = [ strides[1] - ( S0*strides[0] ) ]; + dv2 = [ strides[2] - ( S1*strides[1] ) ]; + dv3 = [ strides[3] - ( S2*strides[2] ) ]; + dv4 = [ strides[4] - ( S3*strides[3] ) ]; + dv5 = [ strides[5] - ( S4*strides[4] ) ]; + dv6 = [ strides[6] - ( S5*strides[5] ) ]; + dv7 = [ strides[7] - ( S6*strides[6] ) ]; + dv8 = [ strides[8] - ( S7*strides[7] ) ]; + dv9 = [ strides[9] - ( S8*strides[8] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + dv2.push( sv[2] - ( S1*sv[1] ) ); + dv3.push( sv[3] - ( S2*sv[2] ) ); + dv4.push( sv[4] - ( S3*sv[3] ) ); + dv5.push( sv[5] - ( S4*sv[4] ) ); + dv6.push( sv[6] - ( S5*sv[5] ) ); + dv7.push( sv[7] - ( S6*sv[6] ) ); + dv8.push( sv[8] - ( S7*sv[7] ) ); + dv8.push( sv[8] - ( S8*sv[8] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Iterate over the non-reduced ndarray dimensions... + for ( i9 = 0; i9 < S9; i9++ ) { + for ( i8 = 0; i8 < S8; i8++ ) { + for ( i7 = 0; i7 < S7; i7++ ) { + for ( i6 = 0; i6 < S6; i6++ ) { + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i9, i8, i7, i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } + incrementOffsets( iv, dv6 ); + } + incrementOffsets( iv, dv7 ); + } + incrementOffsets( iv, dv8 ); + } + incrementOffsets( iv, dv9 ); + } +} + + +// EXPORTS // + +module.exports = unary10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_accessors.js new file mode 100644 index 000000000000..ecca375f4311 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_accessors.js @@ -0,0 +1,314 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params, max-depth, max-statements */ + +'use strict'; + +// MODULES // + +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {boolean} isRowMajor - boolean indicating whether the input ndarray is row-major +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ) ); +* var ybuf = toAccessorArray( new Float64Array( [ 0.0, 0.0, 0.0 ] ) ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 3, 3, 3, 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]; +* var cdims = [ 10, 11 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 12, 12, 12, 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* unary10d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] ] ] ] +*/ +function unary10d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { + var ybuf; + var set; + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var dv6; + var dv7; + var dv8; + var dv9; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var S8; + var S9; + var sv; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + var i9; + var y; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the output ndarray and associated shape: + y = arrays[ 1 ]; + sh = y.shape; + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 9 ]; + S1 = sh[ 8 ]; + S2 = sh[ 7 ]; + S3 = sh[ 6 ]; + S4 = sh[ 5 ]; + S5 = sh[ 4 ]; + S6 = sh[ 3 ]; + S7 = sh[ 2 ]; + S8 = sh[ 1 ]; + S9 = sh[ 0 ]; + dv0 = [ strides[9] ]; // offset increment for innermost loop + dv1 = [ strides[8] - ( S0*strides[9] ) ]; + dv2 = [ strides[7] - ( S1*strides[8] ) ]; + dv3 = [ strides[6] - ( S2*strides[7] ) ]; + dv4 = [ strides[5] - ( S3*strides[6] ) ]; + dv5 = [ strides[4] - ( S4*strides[5] ) ]; + dv6 = [ strides[3] - ( S5*strides[4] ) ]; + dv7 = [ strides[2] - ( S6*strides[3] ) ]; + dv8 = [ strides[1] - ( S7*strides[2] ) ]; + dv9 = [ strides[0] - ( S8*strides[1] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[9] ); + dv1.push( sv[8] - ( S0*sv[9] ) ); + dv2.push( sv[7] - ( S1*sv[8] ) ); + dv3.push( sv[6] - ( S2*sv[7] ) ); + dv4.push( sv[5] - ( S3*sv[6] ) ); + dv5.push( sv[4] - ( S4*sv[5] ) ); + dv6.push( sv[3] - ( S5*sv[4] ) ); + dv7.push( sv[2] - ( S6*sv[3] ) ); + dv8.push( sv[1] - ( S7*sv[2] ) ); + dv9.push( sv[0] - ( S8*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + S6 = sh[ 6 ]; + S7 = sh[ 7 ]; + S8 = sh[ 8 ]; + S9 = sh[ 9 ]; + dv0 = [ strides[0] ]; // offset increment for innermost loop + dv1 = [ strides[1] - ( S0*strides[0] ) ]; + dv2 = [ strides[2] - ( S1*strides[1] ) ]; + dv3 = [ strides[3] - ( S2*strides[2] ) ]; + dv4 = [ strides[4] - ( S3*strides[3] ) ]; + dv5 = [ strides[5] - ( S4*strides[4] ) ]; + dv6 = [ strides[6] - ( S5*strides[5] ) ]; + dv7 = [ strides[7] - ( S6*strides[6] ) ]; + dv8 = [ strides[8] - ( S7*strides[7] ) ]; + dv9 = [ strides[9] - ( S8*strides[8] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + dv2.push( sv[2] - ( S1*sv[1] ) ); + dv3.push( sv[3] - ( S2*sv[2] ) ); + dv4.push( sv[4] - ( S3*sv[3] ) ); + dv5.push( sv[5] - ( S4*sv[4] ) ); + dv6.push( sv[6] - ( S5*sv[5] ) ); + dv7.push( sv[7] - ( S6*sv[6] ) ); + dv8.push( sv[8] - ( S7*sv[7] ) ); + dv8.push( sv[8] - ( S8*sv[8] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache accessors: + set = y.accessors[ 1 ]; + + // Iterate over the non-reduced ndarray dimensions... + for ( i9 = 0; i9 < S9; i9++ ) { + for ( i8 = 0; i8 < S8; i8++ ) { + for ( i7 = 0; i7 < S7; i7++ ) { + for ( i6 = 0; i6 < S6; i6++ ) { + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i9, i8, i7, i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } + incrementOffsets( iv, dv6 ); + } + incrementOffsets( iv, dv7 ); + } + incrementOffsets( iv, dv8 ); + } + incrementOffsets( iv, dv9 ); + } +} + + +// EXPORTS // + +module.exports = unary10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_blocked.js new file mode 100644 index 000000000000..64c7bbf4f718 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_blocked.js @@ -0,0 +1,428 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params, max-depth, max-statements */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/unary-tiling-block-size' ); +var takeIndexed = require( '@stdlib/array/base/take-indexed' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to a callback function and assigns results to a provided output ndarray via loop blocking. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 3, 3, 3, 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]; +* var cdims = [ 10, 11 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 12, 12, 12, 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* blockedunary10d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] ] ] ] +*/ +function blockedunary10d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { + var bsize; + var ybuf; + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var dv6; + var dv7; + var dv8; + var dv9; + var ov1; + var ov2; + var ov3; + var ov4; + var ov5; + var ov6; + var ov7; + var ov8; + var ov9; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var s8; + var s9; + var sv; + var ov; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + var i9; + var j0; + var j1; + var j2; + var j3; + var j4; + var j5; + var j6; + var j7; + var j8; + var j9; + var N; + var x; + var y; + var v; + var o; + var k; + var f; + + // Note on variable naming convention: S#, dv#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + N = arrays.length; + x = arrays[ 0 ]; + y = arrays[ 1 ]; + + // Resolve the loop interchange order: + o = loopOrder( y.shape, strides, y.strides ); + sh = o.sh; + sv = [ o.sx, o.sy ]; + for ( k = 2; k < N; k++ ) { + sv.push( takeIndexed( arrays[k].strides, o.idx ) ); + } + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype ); + + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + ov = offsets( arrays ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache offset increments for the innermost loop... + dv0 = []; + for ( k = 0; k < N; k++ ) { + dv0.push( sv[k][0] ); + } + // Initialize loop variables... + ov1 = zeros( N ); + ov2 = zeros( N ); + ov3 = zeros( N ); + ov4 = zeros( N ); + ov5 = zeros( N ); + ov6 = zeros( N ); + ov7 = zeros( N ); + ov8 = zeros( N ); + ov9 = zeros( N ); + dv1 = zeros( N ); + dv2 = zeros( N ); + dv3 = zeros( N ); + dv4 = zeros( N ); + dv5 = zeros( N ); + dv6 = zeros( N ); + dv7 = zeros( N ); + dv8 = zeros( N ); + dv9 = zeros( N ); + iv = zeros( N ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over blocks... + for ( j9 = sh[9]; j9 > 0; ) { + if ( j9 < bsize ) { + s9 = j9; + j9 = 0; + } else { + s9 = bsize; + j9 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov9[ k ] = ov[k] + ( j9*sv[k][9] ); + } + for ( j8 = sh[8]; j8 > 0; ) { + if ( j8 < bsize ) { + s8 = j8; + j8 = 0; + } else { + s8 = bsize; + j8 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv9 = sv[k][9] - ( s8*sv[k][8] ); + ov8[ k ] = ov9[k] + ( j8*sv[k][8] ); + } + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv8 = sv[k][8] - ( s7*sv[k][7] ); + ov7[ k ] = ov8[k] + ( j7*sv[k][7] ); + } + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv7 = sv[k][7] - ( s6*sv[k][6] ); + ov6[ k ] = ov7[k] + ( j6*sv[k][6] ); + } + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv6 = sv[k][6] - ( s5*sv[k][5] ); + ov5[ k ] = ov6[k] + ( j5*sv[k][5] ); + } + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv5 = sv[k][5] - ( s4*sv[k][4] ); + ov4[ k ] = ov5[k] + ( j4*sv[k][4] ); + } + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv4[ k ] = sv[k][4] - ( s3*sv[k][3] ); + ov3[ k ] = ov4[k] + ( j3*sv[k][3] ); + } + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv3[ k ] = sv[k][3] - ( s2*sv[k][2] ); + ov2[ k ] = ov3[k] + ( j2*sv[k][2] ); + } + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv2[ k ] = sv[k][2] - ( s1*sv[k][1] ); + ov1[ k ] = ov2[k] + ( j1*sv[k][1] ); + } + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets and loop offset increments for the first ndarray elements in the current block... + for ( k = 0; k < N; k++ ) { + iv[ k ] = ov1[k] + ( j0*sv[k][0] ); + dv1[ k ] = sv[k][1] - ( s0*sv[k][0] ); + } + // Iterate over the non-reduced ndarray dimensions... + for ( i9 = 0; i9 < s9; i9++ ) { + for ( i8 = 0; i8 < s8; i8++ ) { + for ( i7 = 0; i7 < s7; i7++ ) { + for ( i6 = 0; i6 < s6; i6++ ) { + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j9+i9, j8+i8, j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } + incrementOffsets( iv, dv6 ); + } + incrementOffsets( iv, dv7 ); + } + incrementOffsets( iv, dv8 ); + } + incrementOffsets( iv, dv9 ); + } + } + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedunary10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_blocked_accessors.js new file mode 100644 index 000000000000..2490f15ce7a0 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_blocked_accessors.js @@ -0,0 +1,436 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params, max-depth, max-statements */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/unary-tiling-block-size' ); +var takeIndexed = require( '@stdlib/array/base/take-indexed' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to a callback function and assigns results to a provided output ndarray via loop blocking. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 3, 3, 3, 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]; +* var cdims = [ 10, 11 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 12, 12, 12, 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* blockedunary10d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] ] ] ] +*/ +function blockedunary10d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { + var bsize; + var ybuf; + var set; + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var dv6; + var dv7; + var dv8; + var dv9; + var ov1; + var ov2; + var ov3; + var ov4; + var ov5; + var ov6; + var ov7; + var ov8; + var ov9; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var s8; + var s9; + var sv; + var ov; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + var i9; + var j0; + var j1; + var j2; + var j3; + var j4; + var j5; + var j6; + var j7; + var j8; + var j9; + var N; + var x; + var y; + var v; + var o; + var k; + var f; + + // Note on variable naming convention: S#, dv#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + N = arrays.length; + x = arrays[ 0 ]; + y = arrays[ 1 ]; + + // Resolve the loop interchange order: + o = loopOrder( y.shape, strides, y.strides ); + sh = o.sh; + sv = [ o.sx, o.sy ]; + for ( k = 2; k < N; k++ ) { + sv.push( takeIndexed( arrays[k].strides, o.idx ) ); + } + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype ); + + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + ov = offsets( arrays ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache accessors: + set = y.accessors[ 1 ]; + + // Cache offset increments for the innermost loop... + dv0 = []; + for ( k = 0; k < N; k++ ) { + dv0.push( sv[k][0] ); + } + // Initialize loop variables... + ov1 = zeros( N ); + ov2 = zeros( N ); + ov3 = zeros( N ); + ov4 = zeros( N ); + ov5 = zeros( N ); + ov6 = zeros( N ); + ov7 = zeros( N ); + ov8 = zeros( N ); + ov9 = zeros( N ); + dv1 = zeros( N ); + dv2 = zeros( N ); + dv3 = zeros( N ); + dv4 = zeros( N ); + dv5 = zeros( N ); + dv6 = zeros( N ); + dv7 = zeros( N ); + dv8 = zeros( N ); + dv9 = zeros( N ); + iv = zeros( N ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over blocks... + for ( j9 = sh[9]; j9 > 0; ) { + if ( j9 < bsize ) { + s9 = j9; + j9 = 0; + } else { + s9 = bsize; + j9 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov9[ k ] = ov[k] + ( j9*sv[k][9] ); + } + for ( j8 = sh[8]; j8 > 0; ) { + if ( j8 < bsize ) { + s8 = j8; + j8 = 0; + } else { + s8 = bsize; + j8 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv9 = sv[k][9] - ( s8*sv[k][8] ); + ov8[ k ] = ov9[k] + ( j8*sv[k][8] ); + } + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv8 = sv[k][8] - ( s7*sv[k][7] ); + ov7[ k ] = ov8[k] + ( j7*sv[k][7] ); + } + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv7 = sv[k][7] - ( s6*sv[k][6] ); + ov6[ k ] = ov7[k] + ( j6*sv[k][6] ); + } + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv6 = sv[k][6] - ( s5*sv[k][5] ); + ov5[ k ] = ov6[k] + ( j5*sv[k][5] ); + } + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv5 = sv[k][5] - ( s4*sv[k][4] ); + ov4[ k ] = ov5[k] + ( j4*sv[k][4] ); + } + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv4[ k ] = sv[k][4] - ( s3*sv[k][3] ); + ov3[ k ] = ov4[k] + ( j3*sv[k][3] ); + } + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv3[ k ] = sv[k][3] - ( s2*sv[k][2] ); + ov2[ k ] = ov3[k] + ( j2*sv[k][2] ); + } + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv2[ k ] = sv[k][2] - ( s1*sv[k][1] ); + ov1[ k ] = ov2[k] + ( j1*sv[k][1] ); + } + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets and loop offset increments for the first ndarray elements in the current block... + for ( k = 0; k < N; k++ ) { + iv[ k ] = ov1[k] + ( j0*sv[k][0] ); + dv1[ k ] = sv[k][1] - ( s0*sv[k][0] ); + } + // Iterate over the non-reduced ndarray dimensions... + for ( i9 = 0; i9 < s9; i9++ ) { + for ( i8 = 0; i8 < s8; i8++ ) { + for ( i7 = 0; i7 < s7; i7++ ) { + for ( i6 = 0; i6 < s6; i6++ ) { + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j9+i9, j8+i8, j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } + incrementOffsets( iv, dv6 ); + } + incrementOffsets( iv, dv7 ); + } + incrementOffsets( iv, dv8 ); + } + incrementOffsets( iv, dv9 ); + } + } + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedunary10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d.js new file mode 100644 index 000000000000..b276c73d08a1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d.js @@ -0,0 +1,282 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params, max-depth, max-statements */ + +'use strict'; + +// MODULES // + +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {boolean} isRowMajor - boolean indicating whether the input ndarray is row-major +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 1, 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 3, 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5, 6, 7 ]; +* var cdims = [ 8, 9 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 12, 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* unary8d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] ] +*/ +function unary8d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { + var ybuf; + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var dv6; + var dv7; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var sv; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var y; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the output ndarray and associated shape: + y = arrays[ 1 ]; + sh = y.shape; + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 7 ]; + S1 = sh[ 6 ]; + S2 = sh[ 5 ]; + S3 = sh[ 4 ]; + S4 = sh[ 3 ]; + S5 = sh[ 2 ]; + S6 = sh[ 1 ]; + S7 = sh[ 0 ]; + dv0 = [ strides[7] ]; // offset increment for innermost loop + dv1 = [ strides[6] - ( S0*strides[7] ) ]; + dv2 = [ strides[5] - ( S1*strides[6] ) ]; + dv3 = [ strides[4] - ( S2*strides[5] ) ]; + dv4 = [ strides[3] - ( S3*strides[4] ) ]; + dv5 = [ strides[2] - ( S4*strides[3] ) ]; + dv6 = [ strides[1] - ( S5*strides[2] ) ]; + dv7 = [ strides[0] - ( S6*strides[1] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[7] ); + dv1.push( sv[6] - ( S0*sv[7] ) ); + dv2.push( sv[5] - ( S1*sv[6] ) ); + dv3.push( sv[4] - ( S2*sv[5] ) ); + dv4.push( sv[3] - ( S3*sv[4] ) ); + dv5.push( sv[2] - ( S4*sv[3] ) ); + dv6.push( sv[1] - ( S5*sv[2] ) ); + dv7.push( sv[0] - ( S6*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + S6 = sh[ 6 ]; + S7 = sh[ 7 ]; + dv0 = [ strides[0] ]; // offset increment for innermost loop + dv1 = [ strides[1] - ( S0*strides[0] ) ]; + dv2 = [ strides[2] - ( S1*strides[1] ) ]; + dv3 = [ strides[3] - ( S2*strides[2] ) ]; + dv4 = [ strides[4] - ( S3*strides[3] ) ]; + dv5 = [ strides[5] - ( S4*strides[4] ) ]; + dv6 = [ strides[6] - ( S5*strides[5] ) ]; + dv7 = [ strides[7] - ( S6*strides[6] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + dv2.push( sv[2] - ( S1*sv[1] ) ); + dv3.push( sv[3] - ( S2*sv[2] ) ); + dv4.push( sv[4] - ( S3*sv[3] ) ); + dv5.push( sv[5] - ( S4*sv[4] ) ); + dv6.push( sv[6] - ( S5*sv[5] ) ); + dv7.push( sv[7] - ( S6*sv[6] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Iterate over the non-reduced ndarray dimensions... + for ( i7 = 0; i7 < S7; i7++ ) { + for ( i6 = 0; i6 < S6; i6++ ) { + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i7, i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } + incrementOffsets( iv, dv6 ); + } + incrementOffsets( iv, dv7 ); + } +} + + +// EXPORTS // + +module.exports = unary8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_accessors.js new file mode 100644 index 000000000000..5b4047b6f7d0 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_accessors.js @@ -0,0 +1,290 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params, max-depth, max-statements */ + +'use strict'; + +// MODULES // + +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {boolean} isRowMajor - boolean indicating whether the input ndarray is row-major +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ) ); +* var ybuf = toAccessorArray( new Float64Array( [ 0.0, 0.0, 0.0 ] ) ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 1, 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 3, 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5, 6, 7 ]; +* var cdims = [ 8, 9 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 12, 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* unary8d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] ] +*/ +function unary8d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { + var ybuf; + var set; + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var dv6; + var dv7; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var sv; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var y; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the output ndarray and associated shape: + y = arrays[ 1 ]; + sh = y.shape; + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 7 ]; + S1 = sh[ 6 ]; + S2 = sh[ 5 ]; + S3 = sh[ 4 ]; + S4 = sh[ 3 ]; + S5 = sh[ 2 ]; + S6 = sh[ 1 ]; + S7 = sh[ 0 ]; + dv0 = [ strides[7] ]; // offset increment for innermost loop + dv1 = [ strides[6] - ( S0*strides[7] ) ]; + dv2 = [ strides[5] - ( S1*strides[6] ) ]; + dv3 = [ strides[4] - ( S2*strides[5] ) ]; + dv4 = [ strides[3] - ( S3*strides[4] ) ]; + dv5 = [ strides[2] - ( S4*strides[3] ) ]; + dv6 = [ strides[1] - ( S5*strides[2] ) ]; + dv7 = [ strides[0] - ( S6*strides[1] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[7] ); + dv1.push( sv[6] - ( S0*sv[7] ) ); + dv2.push( sv[5] - ( S1*sv[6] ) ); + dv3.push( sv[4] - ( S2*sv[5] ) ); + dv4.push( sv[3] - ( S3*sv[4] ) ); + dv5.push( sv[2] - ( S4*sv[3] ) ); + dv6.push( sv[1] - ( S5*sv[2] ) ); + dv7.push( sv[0] - ( S6*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + S6 = sh[ 6 ]; + S7 = sh[ 7 ]; + dv0 = [ strides[0] ]; // offset increment for innermost loop + dv1 = [ strides[1] - ( S0*strides[0] ) ]; + dv2 = [ strides[2] - ( S1*strides[1] ) ]; + dv3 = [ strides[3] - ( S2*strides[2] ) ]; + dv4 = [ strides[4] - ( S3*strides[3] ) ]; + dv5 = [ strides[5] - ( S4*strides[4] ) ]; + dv6 = [ strides[6] - ( S5*strides[5] ) ]; + dv7 = [ strides[7] - ( S6*strides[6] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + dv2.push( sv[2] - ( S1*sv[1] ) ); + dv3.push( sv[3] - ( S2*sv[2] ) ); + dv4.push( sv[4] - ( S3*sv[3] ) ); + dv5.push( sv[5] - ( S4*sv[4] ) ); + dv6.push( sv[6] - ( S5*sv[5] ) ); + dv7.push( sv[7] - ( S6*sv[6] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache accessors: + set = y.accessors[ 1 ]; + + // Iterate over the non-reduced ndarray dimensions... + for ( i7 = 0; i7 < S7; i7++ ) { + for ( i6 = 0; i6 < S6; i6++ ) { + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i7, i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } + incrementOffsets( iv, dv6 ); + } + incrementOffsets( iv, dv7 ); + } +} + + +// EXPORTS // + +module.exports = unary8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_blocked.js new file mode 100644 index 000000000000..1f5c384e9868 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_blocked.js @@ -0,0 +1,382 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params, max-depth, max-statements */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/unary-tiling-block-size' ); +var takeIndexed = require( '@stdlib/array/base/take-indexed' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to a callback function and assigns results to a provided output ndarray via loop blocking. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 1, 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 3, 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5, 6, 7 ]; +* var cdims = [ 8, 9 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 12, 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* blockedunary8d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] ] +*/ +function blockedunary8d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { + var bsize; + var ybuf; + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var dv6; + var dv7; + var ov1; + var ov2; + var ov3; + var ov4; + var ov5; + var ov6; + var ov7; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var sv; + var ov; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var j0; + var j1; + var j2; + var j3; + var j4; + var j5; + var j6; + var j7; + var N; + var x; + var y; + var v; + var o; + var k; + var f; + + // Note on variable naming convention: S#, dv#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + N = arrays.length; + x = arrays[ 0 ]; + y = arrays[ 1 ]; + + // Resolve the loop interchange order: + o = loopOrder( y.shape, strides, y.strides ); + sh = o.sh; + sv = [ o.sx, o.sy ]; + for ( k = 2; k < N; k++ ) { + sv.push( takeIndexed( arrays[k].strides, o.idx ) ); + } + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype ); + + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + ov = offsets( arrays ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache offset increments for the innermost loop... + dv0 = []; + for ( k = 0; k < N; k++ ) { + dv0.push( sv[k][0] ); + } + // Initialize loop variables... + ov1 = zeros( N ); + ov2 = zeros( N ); + ov3 = zeros( N ); + ov4 = zeros( N ); + ov5 = zeros( N ); + ov6 = zeros( N ); + ov7 = zeros( N ); + dv1 = zeros( N ); + dv2 = zeros( N ); + dv3 = zeros( N ); + dv4 = zeros( N ); + dv5 = zeros( N ); + dv6 = zeros( N ); + dv7 = zeros( N ); + iv = zeros( N ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over blocks... + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov7[ k ] = ov[k] + ( j7*sv[k][7] ); + } + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv7 = sv[k][7] - ( s6*sv[k][6] ); + ov6[ k ] = ov7[k] + ( j6*sv[k][6] ); + } + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv6 = sv[k][6] - ( s5*sv[k][5] ); + ov5[ k ] = ov6[k] + ( j5*sv[k][5] ); + } + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv5 = sv[k][5] - ( s4*sv[k][4] ); + ov4[ k ] = ov5[k] + ( j4*sv[k][4] ); + } + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv4[ k ] = sv[k][4] - ( s3*sv[k][3] ); + ov3[ k ] = ov4[k] + ( j3*sv[k][3] ); + } + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv3[ k ] = sv[k][3] - ( s2*sv[k][2] ); + ov2[ k ] = ov3[k] + ( j2*sv[k][2] ); + } + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv2[ k ] = sv[k][2] - ( s1*sv[k][1] ); + ov1[ k ] = ov2[k] + ( j1*sv[k][1] ); + } + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets and loop offset increments for the first ndarray elements in the current block... + for ( k = 0; k < N; k++ ) { + iv[ k ] = ov1[k] + ( j0*sv[k][0] ); + dv1[ k ] = sv[k][1] - ( s0*sv[k][0] ); + } + // Iterate over the non-reduced ndarray dimensions... + for ( i7 = 0; i7 < s7; i7++ ) { + for ( i6 = 0; i6 < s6; i6++ ) { + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } + incrementOffsets( iv, dv6 ); + } + incrementOffsets( iv, dv7 ); + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedunary8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_blocked_accessors.js new file mode 100644 index 000000000000..202234aff326 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_blocked_accessors.js @@ -0,0 +1,390 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params, max-depth, max-statements */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/unary-tiling-block-size' ); +var takeIndexed = require( '@stdlib/array/base/take-indexed' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to a callback function and assigns results to a provided output ndarray via loop blocking. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 1, 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 3, 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5, 6, 7 ]; +* var cdims = [ 8, 9 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 12, 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* blockedunary8d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] ] +*/ +function blockedunary8d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { + var bsize; + var ybuf; + var set; + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var dv6; + var dv7; + var ov1; + var ov2; + var ov3; + var ov4; + var ov5; + var ov6; + var ov7; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var sv; + var ov; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var j0; + var j1; + var j2; + var j3; + var j4; + var j5; + var j6; + var j7; + var N; + var x; + var y; + var v; + var o; + var k; + var f; + + // Note on variable naming convention: S#, dv#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + N = arrays.length; + x = arrays[ 0 ]; + y = arrays[ 1 ]; + + // Resolve the loop interchange order: + o = loopOrder( y.shape, strides, y.strides ); + sh = o.sh; + sv = [ o.sx, o.sy ]; + for ( k = 2; k < N; k++ ) { + sv.push( takeIndexed( arrays[k].strides, o.idx ) ); + } + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype ); + + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + ov = offsets( arrays ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache accessors: + set = y.accessors[ 1 ]; + + // Cache offset increments for the innermost loop... + dv0 = []; + for ( k = 0; k < N; k++ ) { + dv0.push( sv[k][0] ); + } + // Initialize loop variables... + ov1 = zeros( N ); + ov2 = zeros( N ); + ov3 = zeros( N ); + ov4 = zeros( N ); + ov5 = zeros( N ); + ov6 = zeros( N ); + ov7 = zeros( N ); + dv1 = zeros( N ); + dv2 = zeros( N ); + dv3 = zeros( N ); + dv4 = zeros( N ); + dv5 = zeros( N ); + dv6 = zeros( N ); + dv7 = zeros( N ); + iv = zeros( N ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over blocks... + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov7[ k ] = ov[k] + ( j7*sv[k][7] ); + } + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv7 = sv[k][7] - ( s6*sv[k][6] ); + ov6[ k ] = ov7[k] + ( j6*sv[k][6] ); + } + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv6 = sv[k][6] - ( s5*sv[k][5] ); + ov5[ k ] = ov6[k] + ( j5*sv[k][5] ); + } + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv5 = sv[k][5] - ( s4*sv[k][4] ); + ov4[ k ] = ov5[k] + ( j4*sv[k][4] ); + } + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv4[ k ] = sv[k][4] - ( s3*sv[k][3] ); + ov3[ k ] = ov4[k] + ( j3*sv[k][3] ); + } + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv3[ k ] = sv[k][3] - ( s2*sv[k][2] ); + ov2[ k ] = ov3[k] + ( j2*sv[k][2] ); + } + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv2[ k ] = sv[k][2] - ( s1*sv[k][1] ); + ov1[ k ] = ov2[k] + ( j1*sv[k][1] ); + } + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets and loop offset increments for the first ndarray elements in the current block... + for ( k = 0; k < N; k++ ) { + iv[ k ] = ov1[k] + ( j0*sv[k][0] ); + dv1[ k ] = sv[k][1] - ( s0*sv[k][0] ); + } + // Iterate over the non-reduced ndarray dimensions... + for ( i7 = 0; i7 < s7; i7++ ) { + for ( i6 = 0; i6 < s6; i6++ ) { + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } + incrementOffsets( iv, dv6 ); + } + incrementOffsets( iv, dv7 ); + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedunary8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d.js new file mode 100644 index 000000000000..8210c74ff0df --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d.js @@ -0,0 +1,294 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params, max-depth, max-statements */ + +'use strict'; + +// MODULES // + +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {boolean} isRowMajor - boolean indicating whether the input ndarray is row-major +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 1, 1, 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 3, 3, 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]; +* var cdims = [ 9, 10 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 12, 12, 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* unary9d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] ] ] +*/ +function unary9d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { + var ybuf; + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var dv6; + var dv7; + var dv8; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var S8; + var sv; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + var y; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the output ndarray and associated shape: + y = arrays[ 1 ]; + sh = y.shape; + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 8 ]; + S1 = sh[ 7 ]; + S2 = sh[ 6 ]; + S3 = sh[ 5 ]; + S4 = sh[ 4 ]; + S5 = sh[ 3 ]; + S6 = sh[ 2 ]; + S7 = sh[ 1 ]; + S8 = sh[ 0 ]; + dv0 = [ strides[8] ]; // offset increment for innermost loop + dv1 = [ strides[7] - ( S0*strides[8] ) ]; + dv2 = [ strides[6] - ( S1*strides[7] ) ]; + dv3 = [ strides[5] - ( S2*strides[6] ) ]; + dv4 = [ strides[4] - ( S3*strides[5] ) ]; + dv5 = [ strides[3] - ( S4*strides[4] ) ]; + dv6 = [ strides[2] - ( S5*strides[3] ) ]; + dv7 = [ strides[1] - ( S6*strides[2] ) ]; + dv8 = [ strides[0] - ( S7*strides[1] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[8] ); + dv1.push( sv[7] - ( S0*sv[8] ) ); + dv2.push( sv[6] - ( S1*sv[7] ) ); + dv3.push( sv[5] - ( S2*sv[6] ) ); + dv4.push( sv[4] - ( S3*sv[5] ) ); + dv5.push( sv[3] - ( S4*sv[4] ) ); + dv6.push( sv[2] - ( S5*sv[3] ) ); + dv7.push( sv[1] - ( S6*sv[2] ) ); + dv8.push( sv[0] - ( S7*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + S6 = sh[ 6 ]; + S7 = sh[ 7 ]; + S8 = sh[ 8 ]; + dv0 = [ strides[0] ]; // offset increment for innermost loop + dv1 = [ strides[1] - ( S0*strides[0] ) ]; + dv2 = [ strides[2] - ( S1*strides[1] ) ]; + dv3 = [ strides[3] - ( S2*strides[2] ) ]; + dv4 = [ strides[4] - ( S3*strides[3] ) ]; + dv5 = [ strides[5] - ( S4*strides[4] ) ]; + dv6 = [ strides[6] - ( S5*strides[5] ) ]; + dv7 = [ strides[7] - ( S6*strides[6] ) ]; + dv8 = [ strides[8] - ( S7*strides[7] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + dv2.push( sv[2] - ( S1*sv[1] ) ); + dv3.push( sv[3] - ( S2*sv[2] ) ); + dv4.push( sv[4] - ( S3*sv[3] ) ); + dv5.push( sv[5] - ( S4*sv[4] ) ); + dv6.push( sv[6] - ( S5*sv[5] ) ); + dv7.push( sv[7] - ( S6*sv[6] ) ); + dv8.push( sv[8] - ( S7*sv[7] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Iterate over the non-reduced ndarray dimensions... + for ( i8 = 0; i8 < S8; i8++ ) { + for ( i7 = 0; i7 < S7; i7++ ) { + for ( i6 = 0; i6 < S6; i6++ ) { + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i8, i7, i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } + incrementOffsets( iv, dv6 ); + } + incrementOffsets( iv, dv7 ); + } + incrementOffsets( iv, dv8 ); + } +} + + +// EXPORTS // + +module.exports = unary9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_accessors.js new file mode 100644 index 000000000000..1f7c11a72f0a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_accessors.js @@ -0,0 +1,302 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params, max-depth, max-statements */ + +'use strict'; + +// MODULES // + +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to callback function and assigns results to a provided output ndarray. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {boolean} isRowMajor - boolean indicating whether the input ndarray is row-major +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ) ); +* var ybuf = toAccessorArray( new Float64Array( [ 0.0, 0.0, 0.0 ] ) ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 1, 1, 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 3, 3, 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]; +* var cdims = [ 9, 10 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 12, 12, 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* unary9d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] ] ] +*/ +function unary9d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isRowMajor, opts, hasOpts, clbk, thisArg ) { + var ybuf; + var set; + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var dv6; + var dv7; + var dv8; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var S8; + var sv; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + var y; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the output ndarray and associated shape: + y = arrays[ 1 ]; + sh = y.shape; + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 8 ]; + S1 = sh[ 7 ]; + S2 = sh[ 6 ]; + S3 = sh[ 5 ]; + S4 = sh[ 4 ]; + S5 = sh[ 3 ]; + S6 = sh[ 2 ]; + S7 = sh[ 1 ]; + S8 = sh[ 0 ]; + dv0 = [ strides[8] ]; // offset increment for innermost loop + dv1 = [ strides[7] - ( S0*strides[8] ) ]; + dv2 = [ strides[6] - ( S1*strides[7] ) ]; + dv3 = [ strides[5] - ( S2*strides[6] ) ]; + dv4 = [ strides[4] - ( S3*strides[5] ) ]; + dv5 = [ strides[3] - ( S4*strides[4] ) ]; + dv6 = [ strides[2] - ( S5*strides[3] ) ]; + dv7 = [ strides[1] - ( S6*strides[2] ) ]; + dv8 = [ strides[0] - ( S7*strides[1] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[8] ); + dv1.push( sv[7] - ( S0*sv[8] ) ); + dv2.push( sv[6] - ( S1*sv[7] ) ); + dv3.push( sv[5] - ( S2*sv[6] ) ); + dv4.push( sv[4] - ( S3*sv[5] ) ); + dv5.push( sv[3] - ( S4*sv[4] ) ); + dv6.push( sv[2] - ( S5*sv[3] ) ); + dv7.push( sv[1] - ( S6*sv[2] ) ); + dv8.push( sv[0] - ( S7*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + S6 = sh[ 6 ]; + S7 = sh[ 7 ]; + S8 = sh[ 8 ]; + dv0 = [ strides[0] ]; // offset increment for innermost loop + dv1 = [ strides[1] - ( S0*strides[0] ) ]; + dv2 = [ strides[2] - ( S1*strides[1] ) ]; + dv3 = [ strides[3] - ( S2*strides[2] ) ]; + dv4 = [ strides[4] - ( S3*strides[3] ) ]; + dv5 = [ strides[5] - ( S4*strides[4] ) ]; + dv6 = [ strides[6] - ( S5*strides[5] ) ]; + dv7 = [ strides[7] - ( S6*strides[6] ) ]; + dv8 = [ strides[8] - ( S7*strides[7] ) ]; // offset increment for outermost loop + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + dv2.push( sv[2] - ( S1*sv[1] ) ); + dv3.push( sv[3] - ( S2*sv[2] ) ); + dv4.push( sv[4] - ( S3*sv[3] ) ); + dv5.push( sv[5] - ( S4*sv[4] ) ); + dv6.push( sv[6] - ( S5*sv[5] ) ); + dv7.push( sv[7] - ( S6*sv[6] ) ); + dv8.push( sv[8] - ( S7*sv[7] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache accessors: + set = y.accessors[ 1 ]; + + // Iterate over the non-reduced ndarray dimensions... + for ( i8 = 0; i8 < S8; i8++ ) { + for ( i7 = 0; i7 < S7; i7++ ) { + for ( i6 = 0; i6 < S6; i6++ ) { + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i8, i7, i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } + incrementOffsets( iv, dv6 ); + } + incrementOffsets( iv, dv7 ); + } + incrementOffsets( iv, dv8 ); + } +} + + +// EXPORTS // + +module.exports = unary9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_blocked.js new file mode 100644 index 000000000000..db663c643fd2 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_blocked.js @@ -0,0 +1,405 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params, max-depth, max-statements */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/unary-tiling-block-size' ); +var takeIndexed = require( '@stdlib/array/base/take-indexed' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to a callback function and assigns results to a provided output ndarray via loop blocking. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 1, 1, 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 3, 3, 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]; +* var cdims = [ 9, 10 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 12, 12, 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* blockedunary9d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] ] ] +*/ +function blockedunary9d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { + var bsize; + var ybuf; + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var dv6; + var dv7; + var dv8; + var ov1; + var ov2; + var ov3; + var ov4; + var ov5; + var ov6; + var ov7; + var ov8; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var s8; + var sv; + var ov; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + var j0; + var j1; + var j2; + var j3; + var j4; + var j5; + var j6; + var j7; + var j8; + var N; + var x; + var y; + var v; + var o; + var k; + var f; + + // Note on variable naming convention: S#, dv#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + N = arrays.length; + x = arrays[ 0 ]; + y = arrays[ 1 ]; + + // Resolve the loop interchange order: + o = loopOrder( y.shape, strides, y.strides ); + sh = o.sh; + sv = [ o.sx, o.sy ]; + for ( k = 2; k < N; k++ ) { + sv.push( takeIndexed( arrays[k].strides, o.idx ) ); + } + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype ); + + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + ov = offsets( arrays ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache offset increments for the innermost loop... + dv0 = []; + for ( k = 0; k < N; k++ ) { + dv0.push( sv[k][0] ); + } + // Initialize loop variables... + ov1 = zeros( N ); + ov2 = zeros( N ); + ov3 = zeros( N ); + ov4 = zeros( N ); + ov5 = zeros( N ); + ov6 = zeros( N ); + ov7 = zeros( N ); + ov8 = zeros( N ); + dv1 = zeros( N ); + dv2 = zeros( N ); + dv3 = zeros( N ); + dv4 = zeros( N ); + dv5 = zeros( N ); + dv6 = zeros( N ); + dv7 = zeros( N ); + dv8 = zeros( N ); + iv = zeros( N ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over blocks... + for ( j8 = sh[8]; j8 > 0; ) { + if ( j8 < bsize ) { + s8 = j8; + j8 = 0; + } else { + s8 = bsize; + j8 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov8[ k ] = ov[k] + ( j8*sv[k][8] ); + } + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv8 = sv[k][8] - ( s7*sv[k][7] ); + ov7[ k ] = ov8[k] + ( j7*sv[k][7] ); + } + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv7 = sv[k][7] - ( s6*sv[k][6] ); + ov6[ k ] = ov7[k] + ( j6*sv[k][6] ); + } + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv6 = sv[k][6] - ( s5*sv[k][5] ); + ov5[ k ] = ov6[k] + ( j5*sv[k][5] ); + } + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv5 = sv[k][5] - ( s4*sv[k][4] ); + ov4[ k ] = ov5[k] + ( j4*sv[k][4] ); + } + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv4[ k ] = sv[k][4] - ( s3*sv[k][3] ); + ov3[ k ] = ov4[k] + ( j3*sv[k][3] ); + } + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv3[ k ] = sv[k][3] - ( s2*sv[k][2] ); + ov2[ k ] = ov3[k] + ( j2*sv[k][2] ); + } + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv2[ k ] = sv[k][2] - ( s1*sv[k][1] ); + ov1[ k ] = ov2[k] + ( j1*sv[k][1] ); + } + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets and loop offset increments for the first ndarray elements in the current block... + for ( k = 0; k < N; k++ ) { + iv[ k ] = ov1[k] + ( j0*sv[k][0] ); + dv1[ k ] = sv[k][1] - ( s0*sv[k][0] ); + } + // Iterate over the non-reduced ndarray dimensions... + for ( i8 = 0; i8 < s8; i8++ ) { + for ( i7 = 0; i7 < s7; i7++ ) { + for ( i6 = 0; i6 < s6; i6++ ) { + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j8+i8, j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } + incrementOffsets( iv, dv6 ); + } + incrementOffsets( iv, dv7 ); + } + incrementOffsets( iv, dv8 ); + } + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedunary9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_blocked_accessors.js new file mode 100644 index 000000000000..5dfb305545ff --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_blocked_accessors.js @@ -0,0 +1,413 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params, max-depth, max-statements */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/unary-tiling-block-size' ); +var takeIndexed = require( '@stdlib/array/base/take-indexed' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var incrementOffsets = require( './increment_offsets.js' ); +var setViewOffsets = require( './set_view_offsets.js' ); +var offsets = require( './offsets.js' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Performs a reduction over an input ndarray according to a callback function and assigns results to a provided output ndarray via loop blocking. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function +* @param {Array} arrays - ndarrays +* @param {Function} strategy - input ndarray reshape strategy +* @param {Array} views - initialized ndarray-like objects representing sub-array views +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {IntegerArray} strides - loop dimension strides for the input ndarray +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a reduction function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback exection context +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var maxBy = require( '@stdlib/stats/base/ndarray/max-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the array shapes: +* var xsh = [ 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ]; +* var ysh = [ 1, 1, 1, 1, 1, 1, 1, 1, 3 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ]; +* var sy = [ 3, 3, 3, 3, 3, 3, 3, 3, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create an input ndarray-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Create an output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': ysh, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* +* // Initialize ndarray-like objects representing sub-array views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* } +* ]; +* +* // Define a reshape strategy: +* function strategy( x ) { +* return { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 4 ], +* 'strides': [ 1 ], +* 'offset': x.offset, +* 'order': x.order +* }; +* } +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]; +* var cdims = [ 9, 10 ]; +* +* // Resolve the loop dimension strides for the input array: +* var slx = [ 12, 12, 12, 12, 12, 12, 12, 12, 4 ]; +* +* // Perform a reduction: +* blockedunary9d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); +* // returns [ [ [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] ] ] +*/ +function blockedunary9d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { + var bsize; + var ybuf; + var set; + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var dv6; + var dv7; + var dv8; + var ov1; + var ov2; + var ov3; + var ov4; + var ov5; + var ov6; + var ov7; + var ov8; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var s8; + var sv; + var ov; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + var j0; + var j1; + var j2; + var j3; + var j4; + var j5; + var j6; + var j7; + var j8; + var N; + var x; + var y; + var v; + var o; + var k; + var f; + + // Note on variable naming convention: S#, dv#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + N = arrays.length; + x = arrays[ 0 ]; + y = arrays[ 1 ]; + + // Resolve the loop interchange order: + o = loopOrder( y.shape, strides, y.strides ); + sh = o.sh; + sv = [ o.sx, o.sy ]; + for ( k = 2; k < N; k++ ) { + sv.push( takeIndexed( arrays[k].strides, o.idx ) ); + } + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype ); + + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + ov = offsets( arrays ); + + // Cache a reference to the output ndarray buffer: + ybuf = y.data; + + // Cache accessors: + set = y.accessors[ 1 ]; + + // Cache offset increments for the innermost loop... + dv0 = []; + for ( k = 0; k < N; k++ ) { + dv0.push( sv[k][0] ); + } + // Initialize loop variables... + ov1 = zeros( N ); + ov2 = zeros( N ); + ov3 = zeros( N ); + ov4 = zeros( N ); + ov5 = zeros( N ); + ov6 = zeros( N ); + ov7 = zeros( N ); + ov8 = zeros( N ); + dv1 = zeros( N ); + dv2 = zeros( N ); + dv3 = zeros( N ); + dv4 = zeros( N ); + dv5 = zeros( N ); + dv6 = zeros( N ); + dv7 = zeros( N ); + dv8 = zeros( N ); + iv = zeros( N ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over blocks... + for ( j8 = sh[8]; j8 > 0; ) { + if ( j8 < bsize ) { + s8 = j8; + j8 = 0; + } else { + s8 = bsize; + j8 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov8[ k ] = ov[k] + ( j8*sv[k][8] ); + } + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv8 = sv[k][8] - ( s7*sv[k][7] ); + ov7[ k ] = ov8[k] + ( j7*sv[k][7] ); + } + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv7 = sv[k][7] - ( s6*sv[k][6] ); + ov6[ k ] = ov7[k] + ( j6*sv[k][6] ); + } + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv6 = sv[k][6] - ( s5*sv[k][5] ); + ov5[ k ] = ov6[k] + ( j5*sv[k][5] ); + } + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv5 = sv[k][5] - ( s4*sv[k][4] ); + ov4[ k ] = ov5[k] + ( j4*sv[k][4] ); + } + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv4[ k ] = sv[k][4] - ( s3*sv[k][3] ); + ov3[ k ] = ov4[k] + ( j3*sv[k][3] ); + } + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv3[ k ] = sv[k][3] - ( s2*sv[k][2] ); + ov2[ k ] = ov3[k] + ( j2*sv[k][2] ); + } + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + for ( k = 0; k < N; k++ ) { + dv2[ k ] = sv[k][2] - ( s1*sv[k][1] ); + ov1[ k ] = ov2[k] + ( j1*sv[k][1] ); + } + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets and loop offset increments for the first ndarray elements in the current block... + for ( k = 0; k < N; k++ ) { + iv[ k ] = ov1[k] + ( j0*sv[k][0] ); + dv1[ k ] = sv[k][1] - ( s0*sv[k][0] ); + } + // Iterate over the non-reduced ndarray dimensions... + for ( i8 = 0; i8 < s8; i8++ ) { + for ( i7 = 0; i7 < s7; i7++ ) { + for ( i6 = 0; i6 < s6; i6++ ) { + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategy( views[ 0 ] ); + f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j8+i8, j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } + incrementOffsets( iv, dv6 ); + } + incrementOffsets( iv, dv7 ); + } + incrementOffsets( iv, dv8 ); + } + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedunary9d; From d6a9e1493ea83ed59640f2b6310a1254fd09f196 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Thu, 5 Jun 2025 20:40:24 +0000 Subject: [PATCH 14/16] chore: add imports --- 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 --- --- .../unary-reduce-strided1d-by/lib/main.js | 72 +++++++++++++++++-- 1 file changed, 68 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/main.js index 9ec541dc68ad..bdb2c586e247 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/main.js @@ -36,14 +36,46 @@ var format = require( '@stdlib/string/format' ); var initializeViews = require( './initialize_array_views.js' ); var reshapeStrategy = require( './reshape_strategy.js' ); var blockedaccessorunary2d = require( './2d_blocked_accessors.js' ); +var blockedaccessorunary3d = require( './3d_blocked_accessors.js' ); +var blockedaccessorunary4d = require( './4d_blocked_accessors.js' ); +var blockedaccessorunary5d = require( './5d_blocked_accessors.js' ); +var blockedaccessorunary6d = require( './6d_blocked_accessors.js' ); +var blockedaccessorunary7d = require( './7d_blocked_accessors.js' ); +var blockedaccessorunary8d = require( './8d_blocked_accessors.js' ); +var blockedaccessorunary9d = require( './9d_blocked_accessors.js' ); +var blockedaccessorunary10d = require( './10d_blocked_accessors.js' ); var blockedunary2d = require( './2d_blocked.js' ); +var blockedunary3d = require( './3d_blocked.js' ); +var blockedunary4d = require( './4d_blocked.js' ); +var blockedunary5d = require( './5d_blocked.js' ); +var blockedunary6d = require( './6d_blocked.js' ); +var blockedunary7d = require( './7d_blocked.js' ); +var blockedunary8d = require( './8d_blocked.js' ); +var blockedunary9d = require( './9d_blocked.js' ); +var blockedunary10d = require( './10d_blocked.js' ); var accessorunary0d = require( './0d_accessors.js' ); var accessorunary1d = require( './1d_accessors.js' ); var accessorunary2d = require( './2d_accessors.js' ); +var accessorunary3d = require( './3d_accessors.js' ); +var accessorunary4d = require( './4d_accessors.js' ); +var accessorunary5d = require( './5d_accessors.js' ); +var accessorunary6d = require( './6d_accessors.js' ); +var accessorunary7d = require( './7d_accessors.js' ); +var accessorunary8d = require( './8d_accessors.js' ); +var accessorunary9d = require( './9d_accessors.js' ); +var accessorunary10d = require( './10d_accessors.js' ); var accessorunarynd = require( './nd_accessors.js' ); var unary0d = require( './0d.js' ); var unary1d = require( './1d.js' ); var unary2d = require( './2d.js' ); +var unary3d = require( './3d.js' ); +var unary4d = require( './4d.js' ); +var unary5d = require( './5d.js' ); +var unary6d = require( './6d.js' ); +var unary7d = require( './7d.js' ); +var unary8d = require( './8d.js' ); +var unary9d = require( './9d.js' ); +var unary10d = require( './10d.js' ); var unarynd = require( './nd.js' ); @@ -52,18 +84,50 @@ var unarynd = require( './nd.js' ); var UNARY = [ unary0d, unary1d, - unary2d + unary2d, + unary3d, + unary4d, + unary5d, + unary6d, + unary7d, + unary8d, + unary9d, + unary10d ]; var ACCESSOR_UNARY = [ accessorunary0d, accessorunary1d, - accessorunary2d + accessorunary2d, + accessorunary3d, + accessorunary4d, + accessorunary5d, + accessorunary6d, + accessorunary7d, + accessorunary8d, + accessorunary9d, + accessorunary10d ]; var BLOCKED_UNARY = [ - blockedunary2d // 0 + blockedunary2d, // 0 + blockedunary3d, + blockedunary4d, + blockedunary5d, + blockedunary6d, + blockedunary7d, + blockedunary8d, + blockedunary9d, + blockedunary10d // 8 ]; var BLOCKED_ACCESSOR_UNARY = [ - blockedaccessorunary2d // 0 + blockedaccessorunary2d, // 0 + blockedaccessorunary3d, + blockedaccessorunary4d, + blockedaccessorunary5d, + blockedaccessorunary6d, + blockedaccessorunary7d, + blockedaccessorunary8d, + blockedaccessorunary9d, + blockedaccessorunary10d // 8 ]; var MAX_DIMS = UNARY.length - 1; From 0bfe875d14c8943dd7ef010daf2776081ccc6fe3 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 5 Jun 2025 18:19:37 -0700 Subject: [PATCH 15/16] chore: clean-up --- 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 --- --- .../ndarray/base/unary-reduce-strided1d-by/lib/10d.js | 8 ++++++-- .../base/unary-reduce-strided1d-by/lib/10d_accessors.js | 8 ++++++-- .../base/unary-reduce-strided1d-by/lib/10d_blocked.js | 4 ++-- .../lib/10d_blocked_accessors.js | 4 ++-- .../ndarray/base/unary-reduce-strided1d-by/lib/4d.js | 6 +++++- .../base/unary-reduce-strided1d-by/lib/4d_accessors.js | 6 +++++- .../base/unary-reduce-strided1d-by/lib/4d_blocked.js | 2 +- .../unary-reduce-strided1d-by/lib/4d_blocked_accessors.js | 2 +- .../ndarray/base/unary-reduce-strided1d-by/lib/5d.js | 6 +++++- .../base/unary-reduce-strided1d-by/lib/5d_accessors.js | 6 +++++- .../base/unary-reduce-strided1d-by/lib/5d_blocked.js | 2 +- .../unary-reduce-strided1d-by/lib/5d_blocked_accessors.js | 2 +- .../ndarray/base/unary-reduce-strided1d-by/lib/6d.js | 6 +++++- .../base/unary-reduce-strided1d-by/lib/6d_accessors.js | 6 +++++- .../base/unary-reduce-strided1d-by/lib/6d_blocked.js | 2 +- .../unary-reduce-strided1d-by/lib/6d_blocked_accessors.js | 2 +- .../ndarray/base/unary-reduce-strided1d-by/lib/7d.js | 6 +++++- .../base/unary-reduce-strided1d-by/lib/7d_accessors.js | 6 +++++- .../base/unary-reduce-strided1d-by/lib/7d_blocked.js | 2 +- .../unary-reduce-strided1d-by/lib/7d_blocked_accessors.js | 2 +- .../ndarray/base/unary-reduce-strided1d-by/lib/8d.js | 6 +++++- .../base/unary-reduce-strided1d-by/lib/8d_accessors.js | 6 +++++- .../base/unary-reduce-strided1d-by/lib/8d_blocked.js | 4 ++-- .../unary-reduce-strided1d-by/lib/8d_blocked_accessors.js | 4 ++-- .../ndarray/base/unary-reduce-strided1d-by/lib/9d.js | 6 +++++- .../base/unary-reduce-strided1d-by/lib/9d_accessors.js | 6 +++++- .../base/unary-reduce-strided1d-by/lib/9d_blocked.js | 4 ++-- .../unary-reduce-strided1d-by/lib/9d_blocked_accessors.js | 4 ++-- 28 files changed, 92 insertions(+), 36 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d.js index d90dc2ed689f..4ae959dba3d5 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d.js @@ -171,6 +171,7 @@ function unary10d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, is var i7; var i8; var i9; + var x; var y; var v; var i; @@ -178,6 +179,9 @@ function unary10d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, is // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + // Cache a reference to the input ndarray: + x = arrays[ 0 ]; + // Resolve the output ndarray and associated shape: y = arrays[ 1 ]; sh = y.shape; @@ -251,7 +255,7 @@ function unary10d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, is dv6.push( sv[6] - ( S5*sv[5] ) ); dv7.push( sv[7] - ( S6*sv[6] ) ); dv8.push( sv[8] - ( S7*sv[7] ) ); - dv8.push( sv[8] - ( S8*sv[8] ) ); + dv9.push( sv[9] - ( S8*sv[8] ) ); } } // Resolve a list of pointers to the first indexed elements in the respective ndarrays: @@ -276,7 +280,7 @@ function unary10d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, is for ( i0 = 0; i0 < S0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i9, i8, i7, i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ i9, i8, i7, i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_accessors.js index ecca375f4311..a487cd266359 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_accessors.js @@ -176,6 +176,7 @@ function unary10d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, is var i7; var i8; var i9; + var x; var y; var v; var i; @@ -183,6 +184,9 @@ function unary10d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, is // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + // Cache a reference to the input ndarray: + x = arrays[ 0 ]; + // Resolve the output ndarray and associated shape: y = arrays[ 1 ]; sh = y.shape; @@ -256,7 +260,7 @@ function unary10d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, is dv6.push( sv[6] - ( S5*sv[5] ) ); dv7.push( sv[7] - ( S6*sv[6] ) ); dv8.push( sv[8] - ( S7*sv[7] ) ); - dv8.push( sv[8] - ( S8*sv[8] ) ); + dv9.push( sv[9] - ( S8*sv[8] ) ); } } // Resolve a list of pointers to the first indexed elements in the respective ndarrays: @@ -284,7 +288,7 @@ function unary10d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, is for ( i0 = 0; i0 < S0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i9, i8, i7, i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ i9, i8, i7, i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_blocked.js index 64c7bbf4f718..abbd1eecbb6b 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_blocked.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable max-len, max-params, max-depth, max-statements */ +/* eslint-disable max-len, max-params, max-depth, max-statements, max-lines-per-function */ 'use strict'; @@ -388,7 +388,7 @@ function blockedunary10d( fcn, arrays, strategy, views, ibuf, ldims, cdims, stri for ( i0 = 0; i0 < s0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j9+i9, j8+i8, j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ j9+i9, j8+i8, j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_blocked_accessors.js index 2490f15ce7a0..99e9322f4176 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_blocked_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_blocked_accessors.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable max-len, max-params, max-depth, max-statements */ +/* eslint-disable max-len, max-params, max-depth, max-statements, max-lines-per-function */ 'use strict'; @@ -396,7 +396,7 @@ function blockedunary10d( fcn, arrays, strategy, views, ibuf, ldims, cdims, stri for ( i0 = 0; i0 < s0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j9+i9, j8+i8, j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ j9+i9, j8+i8, j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d.js index 3aee676bc8f6..6f06438ad901 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d.js @@ -153,6 +153,7 @@ function unary4d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR var i1; var i2; var i3; + var x; var y; var v; var i; @@ -160,6 +161,9 @@ function unary4d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + // Cache a reference to the input ndarray: + x = arrays[ 0 ]; + // Resolve the output ndarray and associated shape: y = arrays[ 1 ]; sh = y.shape; @@ -216,7 +220,7 @@ function unary4d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR for ( i0 = 0; i0 < S0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i3, i2, i1, i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ i3, i2, i1, i0 ], cdims, clbk, thisArg ); ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_accessors.js index c6a5b5b269f4..864bb2a8c1da 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_accessors.js @@ -158,6 +158,7 @@ function unary4d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR var i1; var i2; var i3; + var x; var y; var v; var i; @@ -165,6 +166,9 @@ function unary4d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + // Cache a reference to the input ndarray: + x = arrays[ 0 ]; + // Resolve the output ndarray and associated shape: y = arrays[ 1 ]; sh = y.shape; @@ -224,7 +228,7 @@ function unary4d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR for ( i0 = 0; i0 < S0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i3, i2, i1, i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ i3, i2, i1, i0 ], cdims, clbk, thisArg ); set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_blocked.js index 7fa04cf56c1e..f3cf303d4e8e 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_blocked.js @@ -268,7 +268,7 @@ function blockedunary4d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strid for ( i0 = 0; i0 < s0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_blocked_accessors.js index 320157d6aa2f..cd6e67461698 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_blocked_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_blocked_accessors.js @@ -276,7 +276,7 @@ function blockedunary4d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strid for ( i0 = 0; i0 < s0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d.js index 7bb9a31f50bf..0dfa5b92d17c 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d.js @@ -156,6 +156,7 @@ function unary5d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR var i2; var i3; var i4; + var x; var y; var v; var i; @@ -163,6 +164,9 @@ function unary5d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + // Cache a reference to the input ndarray: + x = arrays[ 0 ]; + // Resolve the output ndarray and associated shape: y = arrays[ 1 ]; sh = y.shape; @@ -226,7 +230,7 @@ function unary5d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR for ( i0 = 0; i0 < S0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_accessors.js index e49381072b04..f517cb6e4799 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_accessors.js @@ -161,6 +161,7 @@ function unary5d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR var i2; var i3; var i4; + var x; var y; var v; var i; @@ -168,6 +169,9 @@ function unary5d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + // Cache a reference to the input ndarray: + x = arrays[ 0 ]; + // Resolve the output ndarray and associated shape: y = arrays[ 1 ]; sh = y.shape; @@ -234,7 +238,7 @@ function unary5d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR for ( i0 = 0; i0 < S0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_blocked.js index 3504f92df656..fff3da5c5ea5 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_blocked.js @@ -288,7 +288,7 @@ function blockedunary5d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strid for ( i0 = 0; i0 < s0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_blocked_accessors.js index 9d30eeaa5460..96da3d3761bd 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_blocked_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_blocked_accessors.js @@ -296,7 +296,7 @@ function blockedunary5d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strid for ( i0 = 0; i0 < s0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d.js index d2411928afaf..deeff6aabd53 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d.js @@ -159,6 +159,7 @@ function unary6d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR var i3; var i4; var i5; + var x; var y; var v; var i; @@ -166,6 +167,9 @@ function unary6d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + // Cache a reference to the input ndarray: + x = arrays[ 0 ]; + // Resolve the output ndarray and associated shape: y = arrays[ 1 ]; sh = y.shape; @@ -236,7 +240,7 @@ function unary6d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR for ( i0 = 0; i0 < S0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_accessors.js index 368b16f9ac40..cda2374d07c4 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_accessors.js @@ -164,6 +164,7 @@ function unary6d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR var i3; var i4; var i5; + var x; var y; var v; var i; @@ -171,6 +172,9 @@ function unary6d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + // Cache a reference to the input ndarray: + x = arrays[ 0 ]; + // Resolve the output ndarray and associated shape: y = arrays[ 1 ]; sh = y.shape; @@ -244,7 +248,7 @@ function unary6d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR for ( i0 = 0; i0 < S0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_blocked.js index f90916558a6f..d6d42b1cc519 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_blocked.js @@ -308,7 +308,7 @@ function blockedunary6d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strid for ( i0 = 0; i0 < s0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_blocked_accessors.js index cceb023fded6..ebbc6e6211da 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_blocked_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_blocked_accessors.js @@ -316,7 +316,7 @@ function blockedunary6d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strid for ( i0 = 0; i0 < s0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d.js index 81863383cd8f..4f101545f508 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d.js @@ -162,6 +162,7 @@ function unary7d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR var i4; var i5; var i6; + var x; var y; var v; var i; @@ -169,6 +170,9 @@ function unary7d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + // Cache a reference to the input ndarray: + x = arrays[ 0 ]; + // Resolve the output ndarray and associated shape: y = arrays[ 1 ]; sh = y.shape; @@ -246,7 +250,7 @@ function unary7d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR for ( i0 = 0; i0 < S0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_accessors.js index 899c9bd30a67..72c83e9087ec 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_accessors.js @@ -167,6 +167,7 @@ function unary7d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR var i4; var i5; var i6; + var x; var y; var v; var i; @@ -174,6 +175,9 @@ function unary7d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + // Cache a reference to the input ndarray: + x = arrays[ 0 ]; + // Resolve the output ndarray and associated shape: y = arrays[ 1 ]; sh = y.shape; @@ -254,7 +258,7 @@ function unary7d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR for ( i0 = 0; i0 < S0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_blocked.js index 1973cd453b31..2c8036cd8f24 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_blocked.js @@ -328,7 +328,7 @@ function blockedunary7d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strid for ( i0 = 0; i0 < s0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_blocked_accessors.js index dc6eff0e8ac5..94636a4f08cd 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_blocked_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_blocked_accessors.js @@ -336,7 +336,7 @@ function blockedunary7d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strid for ( i0 = 0; i0 < s0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d.js index b276c73d08a1..bbd0cd3339fe 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d.js @@ -165,6 +165,7 @@ function unary8d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR var i5; var i6; var i7; + var x; var y; var v; var i; @@ -172,6 +173,9 @@ function unary8d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + // Cache a reference to the input ndarray: + x = arrays[ 0 ]; + // Resolve the output ndarray and associated shape: y = arrays[ 1 ]; sh = y.shape; @@ -256,7 +260,7 @@ function unary8d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR for ( i0 = 0; i0 < S0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i7, i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ i7, i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_accessors.js index 5b4047b6f7d0..4b82554b13c3 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_accessors.js @@ -170,6 +170,7 @@ function unary8d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR var i5; var i6; var i7; + var x; var y; var v; var i; @@ -177,6 +178,9 @@ function unary8d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + // Cache a reference to the input ndarray: + x = arrays[ 0 ]; + // Resolve the output ndarray and associated shape: y = arrays[ 1 ]; sh = y.shape; @@ -264,7 +268,7 @@ function unary8d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR for ( i0 = 0; i0 < S0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i7, i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ i7, i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_blocked.js index 1f5c384e9868..eaccfec3aa7a 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_blocked.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable max-len, max-params, max-depth, max-statements */ +/* eslint-disable max-len, max-params, max-depth, max-statements, max-lines-per-function */ 'use strict'; @@ -348,7 +348,7 @@ function blockedunary8d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strid for ( i0 = 0; i0 < s0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_blocked_accessors.js index 202234aff326..72174b4c6dd8 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_blocked_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_blocked_accessors.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable max-len, max-params, max-depth, max-statements */ +/* eslint-disable max-len, max-params, max-depth, max-statements, max-lines-per-function */ 'use strict'; @@ -356,7 +356,7 @@ function blockedunary8d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strid for ( i0 = 0; i0 < s0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d.js index 8210c74ff0df..e82b81573ff3 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d.js @@ -168,6 +168,7 @@ function unary9d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR var i6; var i7; var i8; + var x; var y; var v; var i; @@ -175,6 +176,9 @@ function unary9d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + // Cache a reference to the input ndarray: + x = arrays[ 0 ]; + // Resolve the output ndarray and associated shape: y = arrays[ 1 ]; sh = y.shape; @@ -266,7 +270,7 @@ function unary9d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR for ( i0 = 0; i0 < S0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i8, i7, i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ i8, i7, i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_accessors.js index 1f7c11a72f0a..415a0a5a1138 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_accessors.js @@ -173,6 +173,7 @@ function unary9d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR var i6; var i7; var i8; + var x; var y; var v; var i; @@ -180,6 +181,9 @@ function unary9d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + // Cache a reference to the input ndarray: + x = arrays[ 0 ]; + // Resolve the output ndarray and associated shape: y = arrays[ 1 ]; sh = y.shape; @@ -274,7 +278,7 @@ function unary9d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, isR for ( i0 = 0; i0 < S0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ i8, i7, i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ i8, i7, i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_blocked.js index db663c643fd2..947e6f7047c0 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_blocked.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable max-len, max-params, max-depth, max-statements */ +/* eslint-disable max-len, max-params, max-depth, max-statements, max-lines-per-function */ 'use strict'; @@ -368,7 +368,7 @@ function blockedunary9d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strid for ( i0 = 0; i0 < s0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j8+i8, j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ j8+i8, j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); ybuf[ iv[1] ] = ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ); incrementOffsets( iv, dv0 ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_blocked_accessors.js index 5dfb305545ff..3aa8f4389892 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_blocked_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_blocked_accessors.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable max-len, max-params, max-depth, max-statements */ +/* eslint-disable max-len, max-params, max-depth, max-statements, max-lines-per-function */ 'use strict'; @@ -376,7 +376,7 @@ function blockedunary9d( fcn, arrays, strategy, views, ibuf, ldims, cdims, strid for ( i0 = 0; i0 < s0; i0++ ) { setViewOffsets( views, iv ); v[ 0 ] = strategy( views[ 0 ] ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, [ j8+i8, j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, [ j8+i8, j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); set( ybuf, iv[1], ( hasOpts ) ? fcn( v, opts, f ) : fcn( v, f ) ); incrementOffsets( iv, dv0 ); } From 8aee56cf7b526bb332fcf574389cdeeaf69cf272 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 5 Jun 2025 18:28:22 -0700 Subject: [PATCH 16/16] chore: clean-up --- 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 --- --- .../base/unary-reduce-strided1d-by/lib/10d.js | 2 +- .../lib/10d_accessors.js | 2 +- .../unary-reduce-strided1d-by/lib/10d_blocked.js | 2 +- .../lib/10d_blocked_accessors.js | 2 +- .../base/unary-reduce-strided1d-by/lib/2d.js | 2 +- .../lib/2d_accessors.js | 2 +- .../unary-reduce-strided1d-by/lib/2d_blocked.js | 2 +- .../lib/2d_blocked_accessors.js | 2 +- .../base/unary-reduce-strided1d-by/lib/3d.js | 2 +- .../lib/3d_accessors.js | 2 +- .../unary-reduce-strided1d-by/lib/3d_blocked.js | 2 +- .../lib/3d_blocked_accessors.js | 2 +- .../base/unary-reduce-strided1d-by/lib/4d.js | 2 +- .../lib/4d_accessors.js | 2 +- .../unary-reduce-strided1d-by/lib/4d_blocked.js | 2 +- .../lib/4d_blocked_accessors.js | 2 +- .../base/unary-reduce-strided1d-by/lib/5d.js | 2 +- .../lib/5d_accessors.js | 2 +- .../unary-reduce-strided1d-by/lib/5d_blocked.js | 2 +- .../lib/5d_blocked_accessors.js | 2 +- .../base/unary-reduce-strided1d-by/lib/6d.js | 2 +- .../lib/6d_accessors.js | 2 +- .../unary-reduce-strided1d-by/lib/6d_blocked.js | 2 +- .../lib/6d_blocked_accessors.js | 2 +- .../base/unary-reduce-strided1d-by/lib/7d.js | 2 +- .../lib/7d_accessors.js | 2 +- .../unary-reduce-strided1d-by/lib/7d_blocked.js | 2 +- .../lib/7d_blocked_accessors.js | 2 +- .../base/unary-reduce-strided1d-by/lib/8d.js | 2 +- .../lib/8d_accessors.js | 2 +- .../unary-reduce-strided1d-by/lib/8d_blocked.js | 2 +- .../lib/8d_blocked_accessors.js | 2 +- .../base/unary-reduce-strided1d-by/lib/9d.js | 2 +- .../lib/9d_accessors.js | 2 +- .../unary-reduce-strided1d-by/lib/9d_blocked.js | 2 +- .../lib/9d_blocked_accessors.js | 2 +- .../base/unary-reduce-strided1d-by/lib/nd.js | 14 +++++++++----- .../lib/nd_accessors.js | 16 ++++++++++------ 38 files changed, 55 insertions(+), 47 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d.js index 4ae959dba3d5..a94245633a65 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d.js @@ -131,7 +131,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 12, 12, 12, 12, 12, 12, 4 ]; * * // Perform a reduction: -* unary10d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* unary10d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_accessors.js index a487cd266359..c9062b9c5230 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_accessors.js @@ -135,7 +135,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 12, 12, 12, 12, 12, 12, 4 ]; * * // Perform a reduction: -* unary10d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* unary10d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_blocked.js index abbd1eecbb6b..f49f42f319b1 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_blocked.js @@ -134,7 +134,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 12, 12, 12, 12, 12, 12, 4 ]; * * // Perform a reduction: -* blockedunary10d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* blockedunary10d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_blocked_accessors.js index 99e9322f4176..8742d596d30d 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_blocked_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/10d_blocked_accessors.js @@ -138,7 +138,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 12, 12, 12, 12, 12, 12, 4 ]; * * // Perform a reduction: -* blockedunary10d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* blockedunary10d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d.js index c65a26764ba0..5d5bec01642e 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d.js @@ -131,7 +131,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 4 ]; * * // Perform a reduction: -* unary2d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* unary2d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ 8.0, 16.0, 24.0 ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_accessors.js index b54fdc3ac650..e60f7bd8162f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_accessors.js @@ -135,7 +135,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 4 ]; * * // Perform a reduction: -* unary2d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* unary2d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ 6.0, 14.0, 22.0 ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_blocked.js index d87b5db1ae50..8b1052e7754c 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_blocked.js @@ -134,7 +134,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 4 ]; * * // Perform a reduction: -* blockedunary2d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* blockedunary2d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ 8.0, 16.0, 24.0 ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_blocked_accessors.js index 801e9d2eb312..62927ae5dc09 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_blocked_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/2d_blocked_accessors.js @@ -138,7 +138,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 4 ]; * * // Perform a reduction: -* blockedunary2d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* blockedunary2d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ 6.0, 14.0, 22.0 ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d.js index c40ea72e43ac..f87edbe15620 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d.js @@ -131,7 +131,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 4 ]; * * // Perform a reduction: -* unary3d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* unary3d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ 8.0, 16.0, 24.0 ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_accessors.js index dc9f191fd142..9dd25c70a06b 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_accessors.js @@ -135,7 +135,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 4 ]; * * // Perform a reduction: -* unary3d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* unary3d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ 8.0, 16.0, 24.0 ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_blocked.js index f91ef17cad9c..b8d96d82efd0 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_blocked.js @@ -134,7 +134,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 4 ]; * * // Perform a reduction: -* blockedunary3d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* blockedunary3d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ 8.0, 16.0, 24.0 ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_blocked_accessors.js index d70801bc1c86..97152360df56 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_blocked_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/3d_blocked_accessors.js @@ -138,7 +138,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 4 ]; * * // Perform a reduction: -* blockedunary3d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* blockedunary3d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ 8.0, 16.0, 24.0 ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d.js index 6f06438ad901..2a214db69830 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d.js @@ -131,7 +131,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 4 ]; * * // Perform a reduction: -* unary4d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* unary4d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_accessors.js index 864bb2a8c1da..a5d147dfb3a1 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_accessors.js @@ -135,7 +135,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 4 ]; * * // Perform a reduction: -* unary4d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* unary4d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_blocked.js index f3cf303d4e8e..bebc7b898b9f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_blocked.js @@ -134,7 +134,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 4 ]; * * // Perform a reduction: -* blockedunary4d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* blockedunary4d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_blocked_accessors.js index cd6e67461698..e9dd867f7709 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_blocked_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/4d_blocked_accessors.js @@ -138,7 +138,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 4 ]; * * // Perform a reduction: -* blockedunary4d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* blockedunary4d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d.js index 0dfa5b92d17c..c31e85f83e9c 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d.js @@ -131,7 +131,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 12, 4 ]; * * // Perform a reduction: -* unary5d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* unary5d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_accessors.js index f517cb6e4799..e801be91d2ac 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_accessors.js @@ -135,7 +135,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 12, 4 ]; * * // Perform a reduction: -* unary5d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* unary5d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_blocked.js index fff3da5c5ea5..9558dbf34110 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_blocked.js @@ -134,7 +134,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 12, 4 ]; * * // Perform a reduction: -* blockedunary5d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* blockedunary5d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_blocked_accessors.js index 96da3d3761bd..09c7312051ed 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_blocked_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/5d_blocked_accessors.js @@ -138,7 +138,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 12, 4 ]; * * // Perform a reduction: -* blockedunary5d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* blockedunary5d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d.js index deeff6aabd53..85881fd61106 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d.js @@ -131,7 +131,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 12, 12, 4 ]; * * // Perform a reduction: -* unary6d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* unary6d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_accessors.js index cda2374d07c4..9fde07e65c88 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_accessors.js @@ -135,7 +135,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 12, 12, 4 ]; * * // Perform a reduction: -* unary6d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* unary6d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_blocked.js index d6d42b1cc519..47f21f5f20cf 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_blocked.js @@ -134,7 +134,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 12, 12, 4 ]; * * // Perform a reduction: -* blockedunary6d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* blockedunary6d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_blocked_accessors.js index ebbc6e6211da..eb15a2ef3bbb 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_blocked_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/6d_blocked_accessors.js @@ -138,7 +138,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 12, 12, 4 ]; * * // Perform a reduction: -* blockedunary6d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* blockedunary6d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d.js index 4f101545f508..c29cd06aed91 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d.js @@ -131,7 +131,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 12, 12, 12, 4 ]; * * // Perform a reduction: -* unary7d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* unary7d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_accessors.js index 72c83e9087ec..40a000d5466d 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_accessors.js @@ -135,7 +135,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 12, 12, 12, 4 ]; * * // Perform a reduction: -* unary7d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* unary7d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_blocked.js index 2c8036cd8f24..1fe41020e919 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_blocked.js @@ -134,7 +134,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 12, 12, 12, 4 ]; * * // Perform a reduction: -* blockedunary7d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* blockedunary7d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_blocked_accessors.js index 94636a4f08cd..13247fed09f7 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_blocked_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/7d_blocked_accessors.js @@ -138,7 +138,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 12, 12, 12, 4 ]; * * // Perform a reduction: -* blockedunary7d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* blockedunary7d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d.js index bbd0cd3339fe..6600c4676df3 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d.js @@ -131,7 +131,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 12, 12, 12, 12, 4 ]; * * // Perform a reduction: -* unary8d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* unary8d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_accessors.js index 4b82554b13c3..c448bc85c820 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_accessors.js @@ -135,7 +135,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 12, 12, 12, 12, 4 ]; * * // Perform a reduction: -* unary8d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* unary8d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_blocked.js index eaccfec3aa7a..88bb5d74c850 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_blocked.js @@ -134,7 +134,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 12, 12, 12, 12, 4 ]; * * // Perform a reduction: -* blockedunary8d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* blockedunary8d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_blocked_accessors.js index 72174b4c6dd8..6b506d41ac62 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_blocked_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/8d_blocked_accessors.js @@ -138,7 +138,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 12, 12, 12, 12, 4 ]; * * // Perform a reduction: -* blockedunary8d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* blockedunary8d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d.js index e82b81573ff3..90a4d09901a2 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d.js @@ -131,7 +131,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 12, 12, 12, 12, 12, 4 ]; * * // Perform a reduction: -* unary9d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* unary9d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_accessors.js index 415a0a5a1138..d295f439b96b 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_accessors.js @@ -135,7 +135,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 12, 12, 12, 12, 12, 4 ]; * * // Perform a reduction: -* unary9d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk ); +* unary9d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, true, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_blocked.js index 947e6f7047c0..3721c25855d1 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_blocked.js @@ -134,7 +134,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 12, 12, 12, 12, 12, 4 ]; * * // Perform a reduction: -* blockedunary9d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* blockedunary9d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_blocked_accessors.js index 3aa8f4389892..3c641aac7d78 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_blocked_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/9d_blocked_accessors.js @@ -138,7 +138,7 @@ var wrap = require( './callback_wrapper.js' ); * var slx = [ 12, 12, 12, 12, 12, 12, 12, 12, 4 ]; * * // Perform a reduction: -* blockedunary9d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* blockedunary9d( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ [ [ [ [ [ [ [ 8.0, 16.0, 24.0 ] ] ] ] ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/nd.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/nd.js index 6eaa62d6eb30..7700bb844e3e 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/nd.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/nd.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable max-params */ +/* eslint-disable max-len, max-params */ 'use strict'; @@ -137,12 +137,12 @@ var MODE = 'throw'; * var slx = [ 12, 4 ]; * * // Perform a reduction: -* unarynd( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* unarynd( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ 8.0, 16.0, 24.0 ] ] */ -function unarynd( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len +function unarynd( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { var ybuf; var len; var arr; @@ -151,6 +151,7 @@ function unarynd( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opt var iv; var io; var N; + var x; var y; var v; var i; @@ -159,6 +160,9 @@ function unarynd( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opt N = arrays.length; + // Cache a reference to the input ndarray: + x = arrays[ 0 ]; + // Resolve the output ndarray and associated shape: y = arrays[ 1 ]; sh = y.shape; @@ -184,8 +188,8 @@ function unarynd( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opt } setViewOffsets( views, io ); v[ 0 ] = strategy( views[ 0 ] ); - sub = ind2sub( sh, strides, 0, arrays[0].order, i, MODE ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, sub, cdims, clbk, thisArg ); // eslint-disable-line max-len + sub = ind2sub( sh, strides, 0, x.order, i, MODE ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, sub, cdims, clbk, thisArg ); ybuf[ io[1] ] = ( hasOpts ) ? fcn( v, f, opts ) : fcn( v, f ); } } diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/nd_accessors.js b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/nd_accessors.js index b2cd26041157..c41c30adba1f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/nd_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-by/lib/nd_accessors.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable max-params */ +/* eslint-disable max-len, max-params */ 'use strict'; @@ -141,12 +141,12 @@ var MODE = 'throw'; * var slx = [ 12, 4 ]; * * // Perform a reduction: -* unarynd( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk ); +* unarynd( maxBy, [ x, y ], strategy, views, ibuf, ldims, cdims, slx, {}, false, clbk, {} ); * * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); * // returns [ [ 6.0, 14.0, 22.0 ] ] */ -function unarynd( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { // eslint-disable-line max-len +function unarynd( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opts, hasOpts, clbk, thisArg ) { var ybuf; var len; var arr; @@ -156,6 +156,7 @@ function unarynd( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opt var iv; var io; var N; + var x; var y; var v; var i; @@ -164,6 +165,9 @@ function unarynd( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opt N = arrays.length; + // Cache a reference to the input ndarray: + x = arrays[ 0 ]; + // Resolve the output ndarray and associated shape: y = arrays[ 1 ]; sh = y.shape; @@ -192,9 +196,9 @@ function unarynd( fcn, arrays, strategy, views, ibuf, ldims, cdims, strides, opt } setViewOffsets( views, io ); v[ 0 ] = strategy( views[ 0 ] ); - sub = ind2sub( sh, strides, 0, arrays[0].order, i, MODE ); - f = wrap( arrays[ 0 ].ref, views[ 0 ], ibuf, ldims, sub, cdims, clbk, thisArg ); // eslint-disable-line max-len - set( ybuf, io[1], ( hasOpts ) ? fcn( views, opts, f ) : fcn( views, f ) ); // eslint-disable-line max-len + sub = ind2sub( sh, strides, 0, x.order, i, MODE ); + f = wrap( x.ref, views[ 0 ], ibuf, ldims, sub, cdims, clbk, thisArg ); + set( ybuf, io[1], ( hasOpts ) ? fcn( views, opts, f ) : fcn( views, f ) ); } }