From 7522b07faf776f7e3c543ce33447d4eef8ecba0b Mon Sep 17 00:00:00 2001 From: headlessNode Date: Fri, 30 Jan 2026 19:43:01 +0500 Subject: [PATCH 1/4] feat: add ndarray/base/quaternary --- 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: passed - 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: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/base/quaternary/README.md | 251 ++++ .../base/quaternary/benchmark/benchmark.1d.js | 182 +++ .../base/quaternary/benchmark/benchmark.2d.js | 198 +++ .../ndarray/base/quaternary/docs/repl.txt | 104 ++ .../base/quaternary/docs/types/index.d.ts | 91 ++ .../base/quaternary/docs/types/test.ts | 81 ++ .../ndarray/base/quaternary/examples/index.js | 80 ++ .../@stdlib/ndarray/base/quaternary/lib/0d.js | 151 +++ .../base/quaternary/lib/0d_accessors.js | 174 +++ .../ndarray/base/quaternary/lib/10d.js | 460 +++++++ .../base/quaternary/lib/10d_accessors.js | 484 ++++++++ .../base/quaternary/lib/10d_blocked.js | 603 +++++++++ .../quaternary/lib/10d_blocked_accessors.js | 627 ++++++++++ .../@stdlib/ndarray/base/quaternary/lib/1d.js | 201 +++ .../base/quaternary/lib/1d_accessors.js | 225 ++++ .../@stdlib/ndarray/base/quaternary/lib/2d.js | 250 ++++ .../base/quaternary/lib/2d_accessors.js | 274 +++++ .../ndarray/base/quaternary/lib/2d_blocked.js | 291 +++++ .../quaternary/lib/2d_blocked_accessors.js | 315 +++++ .../@stdlib/ndarray/base/quaternary/lib/3d.js | 278 +++++ .../base/quaternary/lib/3d_accessors.js | 302 +++++ .../ndarray/base/quaternary/lib/3d_blocked.js | 330 +++++ .../quaternary/lib/3d_blocked_accessors.js | 354 ++++++ .../@stdlib/ndarray/base/quaternary/lib/4d.js | 304 +++++ .../base/quaternary/lib/4d_accessors.js | 328 +++++ .../ndarray/base/quaternary/lib/4d_blocked.js | 369 ++++++ .../quaternary/lib/4d_blocked_accessors.js | 393 ++++++ .../@stdlib/ndarray/base/quaternary/lib/5d.js | 330 +++++ .../base/quaternary/lib/5d_accessors.js | 354 ++++++ .../ndarray/base/quaternary/lib/5d_blocked.js | 408 +++++++ .../quaternary/lib/5d_blocked_accessors.js | 432 +++++++ .../@stdlib/ndarray/base/quaternary/lib/6d.js | 356 ++++++ .../base/quaternary/lib/6d_accessors.js | 380 ++++++ .../ndarray/base/quaternary/lib/6d_blocked.js | 447 +++++++ .../quaternary/lib/6d_blocked_accessors.js | 471 ++++++++ .../@stdlib/ndarray/base/quaternary/lib/7d.js | 382 ++++++ .../base/quaternary/lib/7d_accessors.js | 406 +++++++ .../ndarray/base/quaternary/lib/7d_blocked.js | 486 ++++++++ .../quaternary/lib/7d_blocked_accessors.js | 510 ++++++++ .../@stdlib/ndarray/base/quaternary/lib/8d.js | 408 +++++++ .../base/quaternary/lib/8d_accessors.js | 432 +++++++ .../ndarray/base/quaternary/lib/8d_blocked.js | 525 ++++++++ .../quaternary/lib/8d_blocked_accessors.js | 549 +++++++++ .../@stdlib/ndarray/base/quaternary/lib/9d.js | 434 +++++++ .../base/quaternary/lib/9d_accessors.js | 458 +++++++ .../ndarray/base/quaternary/lib/9d_blocked.js | 564 +++++++++ .../quaternary/lib/9d_blocked_accessors.js | 588 +++++++++ .../ndarray/base/quaternary/lib/index.js | 81 ++ .../ndarray/base/quaternary/lib/main.js | 449 +++++++ .../@stdlib/ndarray/base/quaternary/lib/nd.js | 227 ++++ .../base/quaternary/lib/nd_accessors.js | 251 ++++ .../ndarray/base/quaternary/package.json | 63 + .../ndarray/base/quaternary/test/test.0d.js | 132 ++ .../ndarray/base/quaternary/test/test.1d.js | 145 +++ .../ndarray/base/quaternary/test/test.2d.js | 1076 +++++++++++++++++ .../ndarray/base/quaternary/test/test.js | 168 +++ 56 files changed, 19212 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/benchmark/benchmark.1d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/benchmark/benchmark.2d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/0d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/0d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/10d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/10d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/10d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/10d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/1d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/1d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/2d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/2d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/2d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/2d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/3d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/3d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/3d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/3d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/4d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/4d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/4d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/4d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/5d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/5d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/5d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/5d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/6d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/6d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/6d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/6d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/7d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/7d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/7d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/7d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/8d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/8d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/8d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/8d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/9d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/9d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/9d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/9d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/nd.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/lib/nd_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/test/test.0d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/test/test.1d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/test/test.2d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/quaternary/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/README.md b/lib/node_modules/@stdlib/ndarray/base/quaternary/README.md new file mode 100644 index 000000000000..e12bff921b37 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/README.md @@ -0,0 +1,251 @@ + + +# Quaternary + +> Apply a quaternary callback to elements in input ndarrays and assign results to elements in an output ndarray. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var quaternary = require( '@stdlib/ndarray/base/quaternary' ); +``` + +#### quaternary( arrays, fcn ) + +Applies a quaternary callback to elements in input ndarrays and assigns results to elements in an output ndarray. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var add4 = require( '@stdlib/number/float64/base/add4' ); + +// Create data buffers: +var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var ybuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +var zbuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +var wbuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +var ubuf = new Float64Array( 6 ); + +// Define the shape of the input and output arrays: +var shape = [ 3, 1, 2 ]; + +// Define the array strides: +var sx = [ 2, 2, 1 ]; +var sy = [ 2, 2, 1 ]; +var sz = [ 2, 2, 1 ]; +var sw = [ 2, 2, 1 ]; +var su = [ 2, 2, 1 ]; + +// Define the index offsets: +var ox = 0; +var oy = 0; +var oz = 0; +var ow = 0; +var ou = 0; + +// Create the input and output ndarray-like objects: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': shape, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; +var y = { + 'dtype': 'float64', + 'data': ybuf, + 'shape': shape, + 'strides': sy, + 'offset': oy, + 'order': 'row-major' +}; +var z = { + 'dtype': 'float64', + 'data': zbuf, + 'shape': shape, + 'strides': sz, + 'offset': oz, + 'order': 'row-major' +}; +var w = { + 'dtype': 'float64', + 'data': wbuf, + 'shape': shape, + 'strides': sw, + 'offset': ow, + 'order': 'row-major' +}; +var u = { + 'dtype': 'float64', + 'data': ubuf, + 'shape': shape, + 'strides': su, + 'offset': ou, + 'order': 'row-major' +}; + +// Apply the quaternary function: +quaternary( [ x, y, z, w, u ], add4 ); + +console.log( u.data ); +// => [ 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] +``` + +The function accepts the following arguments: + +- **arrays**: array-like object containing four input ndarrays and one output ndarray. +- **fcn**: quaternary function to apply. + +
+ + + + + +
+ +## Notes + +- 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). + +- For very high-dimensional ndarrays which are non-contiguous, one should consider copying the underlying data to contiguous memory before applying a quaternary function in order to achieve better performance. + +
+ + + + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var filledarray = require( '@stdlib/array/filled' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var add4 = require( '@stdlib/number/float64/base/add4' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var quaternary = require( '@stdlib/ndarray/base/quaternary' ); + +var N = 10; +var x = { + 'dtype': 'generic', + 'data': filledarrayBy( N, 'generic', discreteUniform( -100, 100 ) ), + 'shape': [ 5, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}; +console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); + +var y = { + 'dtype': 'generic', + 'data': filledarrayBy( N, 'generic', discreteUniform( -100, 100 ) ), + 'shape': x.shape.slice(), + 'strides': shape2strides( x.shape, 'column-major' ), + 'offset': 0, + 'order': 'column-major' +}; +console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) ); + +var z = { + 'dtype': 'generic', + 'data': filledarrayBy( N, 'generic', discreteUniform( -100, 100 ) ), + 'shape': x.shape.slice(), + 'strides': shape2strides( x.shape, 'row-major' ), + 'offset': 0, + 'order': 'row-major' +}; +console.log( ndarray2array( z.data, z.shape, z.strides, z.offset, z.order ) ); + +var w = { + 'dtype': 'generic', + 'data': filledarrayBy( N, 'generic', discreteUniform( -100, 100 ) ), + 'shape': x.shape.slice(), + 'strides': shape2strides( x.shape, 'column-major' ), + 'offset': 0, + 'order': 'column-major' +}; +console.log( ndarray2array( w.data, w.shape, w.strides, w.offset, w.order ) ); + +var u = { + 'dtype': 'generic', + 'data': filledarray( 0, N, 'generic' ), + 'shape': x.shape.slice(), + 'strides': shape2strides( x.shape, 'row-major' ), + 'offset': 0, + 'order': 'row-major' +}; + +quaternary( [ x, y, z, w, u ], add4 ); +console.log( ndarray2array( u.data, u.shape, u.strides, u.offset, u.order ) ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/benchmark/benchmark.1d.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/benchmark/benchmark.1d.js new file mode 100644 index 000000000000..54f2133e3009 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/benchmark/benchmark.1d.js @@ -0,0 +1,182 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 bench = require( '@stdlib/bench' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var filledarray = require( '@stdlib/array/filled' ); +var add4 = require( '@stdlib/number/float64/base/add4' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var orders = require( '@stdlib/ndarray/orders' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var quaternary = require( './../lib' ); + + +// VARIABLES // + +var TYPES = [ + 'float64' +]; +var ORDERS = orders(); + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} utype - output ndarray data type +* @param {string} order - memory layout +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, utype, order ) { + var x; + var y; + var z; + var w; + var u; + + x = discreteUniform( len, -100, 100, { + 'dtype': xtype + }); + y = discreteUniform( len, -100, 100, { + 'dtype': xtype + }); + z = discreteUniform( len, -100, 100, { + 'dtype': xtype + }); + w = discreteUniform( len, -100, 100, { + 'dtype': xtype + }); + u = filledarray( 0.0, len, utype ); + + x = { + 'dtype': xtype, + 'data': x, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + y = { + 'dtype': xtype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + z = { + 'dtype': xtype, + 'data': z, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + w = { + 'dtype': xtype, + 'data': w, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + u = { + 'dtype': utype, + 'data': u, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + quaternary( [ x, y, z, w, u ], add4 ); + if ( isnan( w.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( w.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var ord; + var sh; + var t1; + var t2; + var f; + var i; + var j; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < ORDERS.length; k++ ) { + ord = ORDERS[ k ]; + for ( j = 0; j < TYPES.length; j++ ) { + t1 = TYPES[ j ]; + t2 = TYPES[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len ]; + f = createBenchmark( len, sh, t1, t2, ord ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join(','), ord, ord, t1, t2 ), f ); + } + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/benchmark/benchmark.2d.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/benchmark/benchmark.2d.js new file mode 100644 index 000000000000..9edfc87fe1ef --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/benchmark/benchmark.2d.js @@ -0,0 +1,198 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 bench = require( '@stdlib/bench' ); +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var add4 = require( '@stdlib/number/float64/base/add4' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var orders = require( '@stdlib/ndarray/orders' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var quaternary = require( './../lib/2d.js' ); + + +// VARIABLES // + +var TYPES = [ + 'float64' +]; +var ORDERS = orders(); + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} utype - output ndarray data type +* @param {string} order - memory layout +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, utype, order ) { + var isrm; + var x; + var y; + var z; + var w; + var u; + + isrm = isRowMajor( order ); + + x = discreteUniform( len, -100, 100, { + 'dtype': xtype + }); + y = discreteUniform( len, -100, 100, { + 'dtype': xtype + }); + z = discreteUniform( len, -100, 100, { + 'dtype': xtype + }); + w = discreteUniform( len, -100, 100, { + 'dtype': xtype + }); + u = filledarray( 0.0, len, utype ); + + x = { + 'dtype': xtype, + 'data': x, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + y = { + 'dtype': xtype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + z = { + 'dtype': xtype, + 'data': z, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + w = { + 'dtype': xtype, + 'data': w, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + u = { + 'dtype': utype, + 'data': u, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + quaternary( x, y, z, w, u, isrm, add4 ); + if ( isnan( w.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( w.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var ord; + var sh; + var t1; + var t2; + var f; + var i; + var j; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < ORDERS.length; k++ ) { + ord = ORDERS[ k ]; + for ( j = 0; j < TYPES.length; j++ ) { + t1 = TYPES[ j ]; + t2 = TYPES[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2 ]; + f = createBenchmark( len, sh, t1, t2, ord ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join(','), ord, ord, t1, t2 ), f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2, ord ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join(','), ord, ord, t1, t2 ), f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, t1, t2, ord ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join(','), ord, ord, t1, t2 ), f ); + } + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/quaternary/docs/repl.txt new file mode 100644 index 000000000000..1115a36af3ae --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/docs/repl.txt @@ -0,0 +1,104 @@ + +{{alias}}( arrays, fcn ) + Applies a quaternary callback to elements in input ndarrays and assign + results to elements in an 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). + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing four input ndarrays and one output + ndarray. + + fcn: Function + Quaternary callback. + + 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}}( [ 5.0, 6.0, 7.0, 8.0 ] ); + > var zbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0, 1.0, 1.0 ] ); + > var wbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0, 1.0, 1.0 ] ); + > var ubuf = new {{alias:@stdlib/array/float64}}( 4 ); + > var dtype = 'float64'; + > var shape = [ 2, 2 ]; + > var sx = [ 2, 1 ]; + > var sy = [ 2, 1 ]; + > var sz = [ 2, 1 ]; + > var sw = [ 2, 1 ]; + > var su = [ 2, 1 ]; + > var ox = 0; + > var oy = 0; + > var oz = 0; + > var ow = 0; + > var ou = 0; + > var order = 'row-major'; + + // Using ndarrays... + > var x = {{alias:@stdlib/ndarray/ctor}}( dtype, xbuf, shape, sx, ox, order ); + > var y = {{alias:@stdlib/ndarray/ctor}}( dtype, ybuf, shape, sy, oy, order ); + > var z = {{alias:@stdlib/ndarray/ctor}}( dtype, zbuf, shape, sz, oz, order ); + > var w = {{alias:@stdlib/ndarray/ctor}}( dtype, wbuf, shape, sw, ow, order ); + > var u = {{alias:@stdlib/ndarray/ctor}}( dtype, ubuf, shape, su, ou, order ); + > {{alias}}( [ x, y, z, w, u ], {{alias:@stdlib/number/float64/base/add4}} ); + > {{alias:@stdlib/ndarray/data-buffer}}( u ) + [ 8.0, 10.0, 12.0, 14.0 ] + + // Using minimal ndarray-like objects... + > x = { + ... 'dtype': dtype, + ... 'data': xbuf, + ... 'shape': shape, + ... 'strides': sx, + ... 'offset': ox, + ... 'order': order + ... }; + > y = { + ... 'dtype': dtype, + ... 'data': ybuf, + ... 'shape': shape, + ... 'strides': sy, + ... 'offset': oy, + ... 'order': order + ... }; + > z = { + ... 'dtype': dtype, + ... 'data': zbuf, + ... 'shape': shape, + ... 'strides': sz, + ... 'offset': oz, + ... 'order': order + ... }; + > w = { + ... 'dtype': dtype, + ... 'data': wbuf, + ... 'shape': shape, + ... 'strides': sw, + ... 'offset': ow, + ... 'order': order + ... }; + > u = { + ... 'dtype': dtype, + ... 'data': ubuf, + ... 'shape': shape, + ... 'strides': su, + ... 'offset': ou, + ... 'order': order + ... }; + > {{alias}}( [ x, y, z, w, u ], {{alias:@stdlib/number/float64/base/add4}} ); + > {{alias:@stdlib/ndarray/data-buffer}}( u ) + [ 8.0, 10.0, 12.0, 14.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/quaternary/docs/types/index.d.ts new file mode 100644 index 000000000000..30c7ad99f638 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/docs/types/index.d.ts @@ -0,0 +1,91 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { ArrayLike } from '@stdlib/types/array'; +import { ndarray } from '@stdlib/types/ndarray'; + +/** +* Callback invoked for ndarray elements. +* +* @param x - first ndarray element +* @param y - second ndarray element +* @param z - third ndarray element +* @param w - fourth ndarray element +* @returns result +*/ +type Quaternary = ( x: any, y: any, z: any, w: any ) => any; + +/** +* Applies a quaternary callback to elements in input ndarrays and assigns results to elements in an output ndarray. +* +* @param arrays - array-like object containing four input ndarrays and one output ndarray +* @param fcn - quaternary callback +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var getData = require( '@stdlib/ndarray/data-buffer' ); +* var add4 = require( '@stdlib/number/float64/base/add4' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var zbuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var wbuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var ubuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 2, 1 ]; +* var sy = [ 2, 2, 1 ]; +* var sz = [ 2, 2, 1 ]; +* var sw = [ 2, 2, 1 ]; +* var su = [ 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarrays: +* var x = new ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' ); +* var y = new ndarray( 'float64', ybuf, shape, sy, oy, 'row-major' ); +* var z = new ndarray( 'float64', zbuf, shape, sz, oz, 'row-major' ); +* var w = new ndarray( 'float64', wbuf, shape, sw, ow, 'row-major' ); +* var u = new ndarray( 'float64', ubuf, shape, su, ou, 'row-major' ); +* +* // Apply the quaternary function: +* quaternary( [ x, y, z, w, u ], add4 ); +* +* console.log( getData( u ) ); +* // => [ 4.0, 6.0, 8.0, 10.0, 12.0, 14.0 ] +*/ +declare function quaternary( arrays: ArrayLike, fcn: Quaternary ): void; + + +// EXPORTS // + +export = quaternary; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/quaternary/docs/types/test.ts new file mode 100644 index 000000000000..cfeb5dc9e929 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/docs/types/test.ts @@ -0,0 +1,81 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import add4 = require( '@stdlib/number/float64/base/add4' ); +import quaternary = require( './index' ); + + +// TESTS // + +// The function returns `undefined`... +{ + const x = zeros( [ 2, 2 ] ); + const y = zeros( [ 2, 2 ] ); + const z = zeros( [ 2, 2 ] ); + const w = zeros( [ 2, 2 ] ); + const u = zeros( [ 2, 2 ] ); + const arrays = [ x, y, z, w, u ]; + + quaternary( arrays, add4 ); // $ExpectType void +} + +// The compiler throws an error if the function is provided a first argument which is not an array-like object containing ndarray-like objects... +{ + quaternary( 5, add4 ); // $ExpectError + quaternary( true, add4 ); // $ExpectError + quaternary( false, add4 ); // $ExpectError + quaternary( null, add4 ); // $ExpectError + quaternary( undefined, add4 ); // $ExpectError + quaternary( {}, add4 ); // $ExpectError + quaternary( [ 1 ], add4 ); // $ExpectError + quaternary( ( x: number ): number => x, add4 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a quaternary function... +{ + const x = zeros( [ 2, 2 ] ); + const y = zeros( [ 2, 2 ] ); + const z = zeros( [ 2, 2 ] ); + const w = zeros( [ 2, 2 ] ); + const u = zeros( [ 2, 2 ] ); + const arrays = [ x, y, z, w, u ]; + + quaternary( arrays, '10' ); // $ExpectError + quaternary( arrays, 5 ); // $ExpectError + quaternary( arrays, true ); // $ExpectError + quaternary( arrays, false ); // $ExpectError + quaternary( arrays, null ); // $ExpectError + quaternary( arrays, undefined ); // $ExpectError + quaternary( arrays, [] ); // $ExpectError + quaternary( arrays, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ] ); + const y = zeros( [ 2, 2 ] ); + const z = zeros( [ 2, 2 ] ); + const w = zeros( [ 2, 2 ] ); + const u = zeros( [ 2, 2 ] ); + const arrays = [ x, y, z, w, u ]; + + quaternary(); // $ExpectError + quaternary( arrays ); // $ExpectError + quaternary( arrays, add4, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/examples/index.js new file mode 100644 index 000000000000..9ad9a2cdace6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/examples/index.js @@ -0,0 +1,80 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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/base/discrete-uniform' ).factory; +var filledarray = require( '@stdlib/array/filled' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var add4 = require( '@stdlib/number/float64/base/add4' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var quaternary = require( './../lib' ); + +var N = 10; +var x = { + 'dtype': 'generic', + 'data': filledarrayBy( N, 'generic', discreteUniform( -100, 100 ) ), + 'shape': [ 5, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}; +console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); + +var y = { + 'dtype': 'generic', + 'data': filledarrayBy( N, 'generic', discreteUniform( -100, 100 ) ), + 'shape': x.shape.slice(), + 'strides': shape2strides( x.shape, 'column-major' ), + 'offset': 0, + 'order': 'column-major' +}; +console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) ); + +var z = { + 'dtype': 'generic', + 'data': filledarrayBy( N, 'generic', discreteUniform( -100, 100 ) ), + 'shape': x.shape.slice(), + 'strides': shape2strides( x.shape, 'row-major' ), + 'offset': 0, + 'order': 'row-major' +}; +console.log( ndarray2array( z.data, z.shape, z.strides, z.offset, z.order ) ); + +var w = { + 'dtype': 'generic', + 'data': filledarrayBy( N, 'generic', discreteUniform( -100, 100 ) ), + 'shape': x.shape.slice(), + 'strides': shape2strides( x.shape, 'column-major' ), + 'offset': 0, + 'order': 'column-major' +}; +console.log( ndarray2array( w.data, w.shape, w.strides, w.offset, w.order ) ); + +var u = { + 'dtype': 'generic', + 'data': filledarray( 0, N, 'generic' ), + 'shape': x.shape.slice(), + 'strides': shape2strides( x.shape, 'row-major' ), + 'offset': 0, + 'order': 'row-major' +}; + +quaternary( [ x, y, z, w, u ], add4 ); +console.log( ndarray2array( u.data, u.shape, u.strides, u.offset, u.order ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/0d.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/0d.js new file mode 100644 index 000000000000..5fa69347fffa --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/0d.js @@ -0,0 +1,151 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 // + +/** +* Applies a quaternary callback to elements in a zero-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Callback} fcn - quaternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0 ] ); +* var ybuf = new Float64Array( [ 2.0 ] ); +* var zbuf = new Float64Array( [ 3.0 ] ); +* var wbuf = new Float64Array( [ 4.0 ] ); +* var ubuf = new Float64Array( [ 0.0 ] ); +* +* // Define the shape of the input and output arrays: +* var shape = []; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 0 ]; +* var sz = [ 0 ]; +* var sw = [ 0 ]; +* var su = [ 0 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* var z = { +* 'dtype': 'float64', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major' +* }; +* var w = { +* 'dtype': 'float64', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major' +* }; +* var u = { +* 'dtype': 'float64', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major' +* }; +* +* // Apply the quaternary function: +* quaternary0d( x, y, z, w, u, fcn ); +* +* console.log( u.data ); +* // => [ 10.0 ] +*/ +function quaternary0d( x, y, z, w, u, fcn ) { + u.data[ u.offset ] = fcn( x.data[ x.offset ], y.data[ y.offset ], z.data[ z.offset ], w.data[ w.offset ] ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = quaternary0d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/0d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/0d_accessors.js new file mode 100644 index 000000000000..0da627c8747b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/0d_accessors.js @@ -0,0 +1,174 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 // + +/** +* Applies a quaternary callback to elements in a zero-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} z.accessors - data buffer accessors +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} w.accessors - data buffer accessors +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} u.accessors - data buffer accessors +* @param {Callback} fcn - quaternary callback +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( [ 1.0 ] ); +* var ybuf = toAccessorArray( [ 2.0 ] ); +* var zbuf = toAccessorArray( [ 3.0 ] ); +* var wbuf = toAccessorArray( [ 4.0 ] ); +* var ubuf = toAccessorArray( [ 0.0 ] ); +* +* // Define the shape of the input and output arrays: +* var shape = []; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 0 ]; +* var sz = [ 0 ]; +* var sw = [ 0 ]; +* var su = [ 0 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* var y = { +* 'dtype': 'generic', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* var z = { +* 'dtype': 'generic', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major', +* 'accessors': accessors( zbuf ).accessors +* }; +* var w = { +* 'dtype': 'generic', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major', +* 'accessors': accessors( wbuf ).accessors +* }; +* var u = { +* 'dtype': 'generic', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major', +* 'accessors': accessors( ubuf ).accessors +* }; +* +* // Apply the quaternary function: +* quaternary0d( x, y, z, w, u, fcn ); +* +* var v = u.data.get( 0 ); +* // returns 10.0 +*/ +function quaternary0d( x, y, z, w, u, fcn ) { + var xget; + var yget; + var zget; + var wget; + var uset; + + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = z.accessors[ 0 ]; + wget = w.accessors[ 0 ]; + uset = u.accessors[ 1 ]; + + uset( u.data, u.offset, fcn( xget( x.data, x.offset ), yget( y.data, y.offset ), zget( z.data, z.offset ), wget( w.data, w.offset ) ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = quaternary0d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/10d.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/10d.js new file mode 100644 index 000000000000..0b20819cc841 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/10d.js @@ -0,0 +1,460 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-statements, max-depth, max-lines-per-function */ + +'use strict'; + +// MAIN // + +/** +* Applies a quaternary callback to elements in ten-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - quaternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = new Float64Array( 8 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 8, 8, 8, 8, 8, 8, 4, 2, 1 ]; +* var sy = [ 8, 8, 8, 8, 8, 8, 8, 4, 2, 1 ]; +* var sz = [ 8, 8, 8, 8, 8, 8, 8, 4, 2, 1 ]; +* var sw = [ 8, 8, 8, 8, 8, 8, 8, 4, 2, 1 ]; +* var su = [ 8, 8, 8, 8, 8, 8, 8, 4, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* var z = { +* 'dtype': 'float64', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major' +* }; +* var w = { +* 'dtype': 'float64', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major' +* }; +* var u = { +* 'dtype': 'float64', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major' +* }; +* +* // Apply the quaternary function: +* quaternary10d( x, y, z, w, u, true, fcn ); +* +* console.log( u.data ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] +*/ +function quaternary10d( x, y, z, w, u, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var dx8; + var dx9; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dy7; + var dy8; + var dy9; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dz6; + var dz7; + var dz8; + var dz9; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dw6; + var dw7; + var dw8; + var dw9; + var du0; + var du1; + var du2; + var du3; + var du4; + var du5; + var du6; + var du7; + var du8; + var du9; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var S8; + var S9; + var sx; + var sy; + var sz; + var sw; + var su; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + var i9; + + // Note on variable naming convention: S#, dx#, dy#, dz#, dw#, du#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = x.shape; + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + su = u.strides; + 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 ]; + dx0 = sx[ 9 ]; // offset increment for innermost loop + dx1 = sx[ 8 ] - ( S0*sx[9] ); + dx2 = sx[ 7 ] - ( S1*sx[8] ); + dx3 = sx[ 6 ] - ( S2*sx[7] ); + dx4 = sx[ 5 ] - ( S3*sx[6] ); + dx5 = sx[ 4 ] - ( S4*sx[5] ); + dx6 = sx[ 3 ] - ( S5*sx[4] ); + dx7 = sx[ 2 ] - ( S6*sx[3] ); + dx8 = sx[ 1 ] - ( S7*sx[2] ); + dx9 = sx[ 0 ] - ( S8*sx[1] ); // offset increment for outermost loop + dy0 = sy[ 9 ]; + dy1 = sy[ 8 ] - ( S0*sy[9] ); + dy2 = sy[ 7 ] - ( S1*sy[8] ); + dy3 = sy[ 6 ] - ( S2*sy[7] ); + dy4 = sy[ 5 ] - ( S3*sy[6] ); + dy5 = sy[ 4 ] - ( S4*sy[5] ); + dy6 = sy[ 3 ] - ( S5*sy[4] ); + dy7 = sy[ 2 ] - ( S6*sy[3] ); + dy8 = sy[ 1 ] - ( S7*sy[2] ); + dy9 = sy[ 0 ] - ( S8*sy[1] ); + dz0 = sz[ 9 ]; + dz1 = sz[ 8 ] - ( S0*sz[9] ); + dz2 = sz[ 7 ] - ( S1*sz[8] ); + dz3 = sz[ 6 ] - ( S2*sz[7] ); + dz4 = sz[ 5 ] - ( S3*sz[6] ); + dz5 = sz[ 4 ] - ( S4*sz[5] ); + dz6 = sz[ 3 ] - ( S5*sz[4] ); + dz7 = sz[ 2 ] - ( S6*sz[3] ); + dz8 = sz[ 1 ] - ( S7*sz[2] ); + dz9 = sz[ 0 ] - ( S8*sz[1] ); + dw0 = sw[ 9 ]; + dw1 = sw[ 8 ] - ( S0*sw[9] ); + dw2 = sw[ 7 ] - ( S1*sw[8] ); + dw3 = sw[ 6 ] - ( S2*sw[7] ); + dw4 = sw[ 5 ] - ( S3*sw[6] ); + dw5 = sw[ 4 ] - ( S4*sw[5] ); + dw6 = sw[ 3 ] - ( S5*sw[4] ); + dw7 = sw[ 2 ] - ( S6*sw[3] ); + dw8 = sw[ 1 ] - ( S7*sw[2] ); + dw9 = sw[ 0 ] - ( S8*sw[1] ); + du0 = su[ 9 ]; + du1 = su[ 8 ] - ( S0*su[9] ); + du2 = su[ 7 ] - ( S1*su[8] ); + du3 = su[ 6 ] - ( S2*su[7] ); + du4 = su[ 5 ] - ( S3*su[6] ); + du5 = su[ 4 ] - ( S4*su[5] ); + du6 = su[ 3 ] - ( S5*su[4] ); + du7 = su[ 2 ] - ( S6*su[3] ); + du8 = su[ 1 ] - ( S7*su[2] ); + du9 = su[ 0 ] - ( S8*su[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 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); + dx5 = sx[ 5 ] - ( S4*sx[4] ); + dx6 = sx[ 6 ] - ( S5*sx[5] ); + dx7 = sx[ 7 ] - ( S6*sx[6] ); + dx8 = sx[ 8 ] - ( S7*sx[7] ); + dx9 = sx[ 9 ] - ( S8*sx[8] ); // offset increment for outermost loop + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dy4 = sy[ 4 ] - ( S3*sy[3] ); + dy5 = sy[ 5 ] - ( S4*sy[4] ); + dy6 = sy[ 6 ] - ( S5*sy[5] ); + dy7 = sy[ 7 ] - ( S6*sy[6] ); + dy8 = sy[ 8 ] - ( S7*sy[7] ); + dy9 = sy[ 9 ] - ( S8*sy[8] ); + dz0 = sz[ 0 ]; + dz1 = sz[ 1 ] - ( S0*sz[0] ); + dz2 = sz[ 2 ] - ( S1*sz[1] ); + dz3 = sz[ 3 ] - ( S2*sz[2] ); + dz4 = sz[ 4 ] - ( S3*sz[3] ); + dz5 = sz[ 5 ] - ( S4*sz[4] ); + dz6 = sz[ 6 ] - ( S5*sz[5] ); + dz7 = sz[ 7 ] - ( S6*sz[6] ); + dz8 = sz[ 8 ] - ( S7*sz[7] ); + dz9 = sz[ 9 ] - ( S8*sz[8] ); + dw0 = sw[ 0 ]; + dw1 = sw[ 1 ] - ( S0*sw[0] ); + dw2 = sw[ 2 ] - ( S1*sw[1] ); + dw3 = sw[ 3 ] - ( S2*sw[2] ); + dw4 = sw[ 4 ] - ( S3*sw[3] ); + dw5 = sw[ 5 ] - ( S4*sw[4] ); + dw6 = sw[ 6 ] - ( S5*sw[5] ); + dw7 = sw[ 7 ] - ( S6*sw[6] ); + dw8 = sw[ 8 ] - ( S7*sw[7] ); + dw9 = sw[ 9 ] - ( S8*sw[8] ); + du0 = su[ 0 ]; + du1 = su[ 1 ] - ( S0*su[0] ); + du2 = su[ 2 ] - ( S1*su[1] ); + du3 = su[ 3 ] - ( S2*su[2] ); + du4 = su[ 4 ] - ( S3*su[3] ); + du5 = su[ 5 ] - ( S4*su[4] ); + du6 = su[ 6 ] - ( S5*su[5] ); + du7 = su[ 7 ] - ( S6*su[6] ); + du8 = su[ 8 ] - ( S7*su[7] ); + du9 = su[ 9 ] - ( S8*su[8] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + iu = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Iterate over the 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++ ) { + ubuf[ iu ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ], wbuf[ iw ] ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + iu += du4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + iu += du5; + } + ix += dx6; + iy += dy6; + iz += dz6; + iw += dw6; + iu += du6; + } + ix += dx7; + iy += dy7; + iz += dz7; + iw += dw7; + iu += du7; + } + ix += dx8; + iy += dy8; + iz += dz8; + iw += dw8; + iu += du8; + } + ix += dx9; + iy += dy9; + iz += dz9; + iw += dw9; + iu += du9; + } +} + + +// EXPORTS // + +module.exports = quaternary10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/10d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/10d_accessors.js new file mode 100644 index 000000000000..9a34cad4531a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/10d_accessors.js @@ -0,0 +1,484 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-statements, max-depth, max-lines-per-function */ + +'use strict'; + +// MAIN // + +/** +* Applies a quaternary callback to elements in ten-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} z.accessors - data buffer accessors +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} w.accessors - data buffer accessors +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} u.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - quaternary callback +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var copy = require( '@stdlib/array/base/copy' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = toAccessorArray( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = toAccessorArray( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = toAccessorArray( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 8, 8, 8, 8, 8, 8, 4, 2, 1 ]; +* var sy = [ 8, 8, 8, 8, 8, 8, 8, 4, 2, 1 ]; +* var sz = [ 8, 8, 8, 8, 8, 8, 8, 4, 2, 1 ]; +* var sw = [ 8, 8, 8, 8, 8, 8, 8, 4, 2, 1 ]; +* var su = [ 8, 8, 8, 8, 8, 8, 8, 4, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* var y = { +* 'dtype': 'generic', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* var z = { +* 'dtype': 'generic', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major', +* 'accessors': accessors( zbuf ).accessors +* }; +* var w = { +* 'dtype': 'generic', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major', +* 'accessors': accessors( wbuf ).accessors +* }; +* var u = { +* 'dtype': 'generic', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major', +* 'accessors': accessors( ubuf ).accessors +* }; +* +* // Apply the quaternary function: +* quaternary10d( x, y, z, w, u, true, fcn ); +* +* console.log( copy( u.data ) ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] +*/ +function quaternary10d( x, y, z, w, u, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var xget; + var yget; + var zget; + var wget; + var uset; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var dx8; + var dx9; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dy7; + var dy8; + var dy9; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dz6; + var dz7; + var dz8; + var dz9; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dw6; + var dw7; + var dw8; + var dw9; + var du0; + var du1; + var du2; + var du3; + var du4; + var du5; + var du6; + var du7; + var du8; + var du9; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var S8; + var S9; + var sx; + var sy; + var sz; + var sw; + var su; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + var i9; + + // Note on variable naming convention: S#, dx#, dy#, dz#, dw#, du#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = x.shape; + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + su = u.strides; + 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 ]; + dx0 = sx[ 9 ]; // offset increment for innermost loop + dx1 = sx[ 8 ] - ( S0*sx[9] ); + dx2 = sx[ 7 ] - ( S1*sx[8] ); + dx3 = sx[ 6 ] - ( S2*sx[7] ); + dx4 = sx[ 5 ] - ( S3*sx[6] ); + dx5 = sx[ 4 ] - ( S4*sx[5] ); + dx6 = sx[ 3 ] - ( S5*sx[4] ); + dx7 = sx[ 2 ] - ( S6*sx[3] ); + dx8 = sx[ 1 ] - ( S7*sx[2] ); + dx9 = sx[ 0 ] - ( S8*sx[1] ); // offset increment for outermost loop + dy0 = sy[ 9 ]; + dy1 = sy[ 8 ] - ( S0*sy[9] ); + dy2 = sy[ 7 ] - ( S1*sy[8] ); + dy3 = sy[ 6 ] - ( S2*sy[7] ); + dy4 = sy[ 5 ] - ( S3*sy[6] ); + dy5 = sy[ 4 ] - ( S4*sy[5] ); + dy6 = sy[ 3 ] - ( S5*sy[4] ); + dy7 = sy[ 2 ] - ( S6*sy[3] ); + dy8 = sy[ 1 ] - ( S7*sy[2] ); + dy9 = sy[ 0 ] - ( S8*sy[1] ); + dz0 = sz[ 9 ]; + dz1 = sz[ 8 ] - ( S0*sz[9] ); + dz2 = sz[ 7 ] - ( S1*sz[8] ); + dz3 = sz[ 6 ] - ( S2*sz[7] ); + dz4 = sz[ 5 ] - ( S3*sz[6] ); + dz5 = sz[ 4 ] - ( S4*sz[5] ); + dz6 = sz[ 3 ] - ( S5*sz[4] ); + dz7 = sz[ 2 ] - ( S6*sz[3] ); + dz8 = sz[ 1 ] - ( S7*sz[2] ); + dz9 = sz[ 0 ] - ( S8*sz[1] ); + dw0 = sw[ 9 ]; + dw1 = sw[ 8 ] - ( S0*sw[9] ); + dw2 = sw[ 7 ] - ( S1*sw[8] ); + dw3 = sw[ 6 ] - ( S2*sw[7] ); + dw4 = sw[ 5 ] - ( S3*sw[6] ); + dw5 = sw[ 4 ] - ( S4*sw[5] ); + dw6 = sw[ 3 ] - ( S5*sw[4] ); + dw7 = sw[ 2 ] - ( S6*sw[3] ); + dw8 = sw[ 1 ] - ( S7*sw[2] ); + dw9 = sw[ 0 ] - ( S8*sw[1] ); + du0 = su[ 9 ]; + du1 = su[ 8 ] - ( S0*su[9] ); + du2 = su[ 7 ] - ( S1*su[8] ); + du3 = su[ 6 ] - ( S2*su[7] ); + du4 = su[ 5 ] - ( S3*su[6] ); + du5 = su[ 4 ] - ( S4*su[5] ); + du6 = su[ 3 ] - ( S5*su[4] ); + du7 = su[ 2 ] - ( S6*su[3] ); + du8 = su[ 1 ] - ( S7*su[2] ); + du9 = su[ 0 ] - ( S8*su[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 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); + dx5 = sx[ 5 ] - ( S4*sx[4] ); + dx6 = sx[ 6 ] - ( S5*sx[5] ); + dx7 = sx[ 7 ] - ( S6*sx[6] ); + dx8 = sx[ 8 ] - ( S7*sx[7] ); + dx9 = sx[ 9 ] - ( S8*sx[8] ); // offset increment for outermost loop + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dy4 = sy[ 4 ] - ( S3*sy[3] ); + dy5 = sy[ 5 ] - ( S4*sy[4] ); + dy6 = sy[ 6 ] - ( S5*sy[5] ); + dy7 = sy[ 7 ] - ( S6*sy[6] ); + dy8 = sy[ 8 ] - ( S7*sy[7] ); + dy9 = sy[ 9 ] - ( S8*sy[8] ); + dz0 = sz[ 0 ]; + dz1 = sz[ 1 ] - ( S0*sz[0] ); + dz2 = sz[ 2 ] - ( S1*sz[1] ); + dz3 = sz[ 3 ] - ( S2*sz[2] ); + dz4 = sz[ 4 ] - ( S3*sz[3] ); + dz5 = sz[ 5 ] - ( S4*sz[4] ); + dz6 = sz[ 6 ] - ( S5*sz[5] ); + dz7 = sz[ 7 ] - ( S6*sz[6] ); + dz8 = sz[ 8 ] - ( S7*sz[7] ); + dz9 = sz[ 9 ] - ( S8*sz[8] ); + dw0 = sw[ 0 ]; + dw1 = sw[ 1 ] - ( S0*sw[0] ); + dw2 = sw[ 2 ] - ( S1*sw[1] ); + dw3 = sw[ 3 ] - ( S2*sw[2] ); + dw4 = sw[ 4 ] - ( S3*sw[3] ); + dw5 = sw[ 5 ] - ( S4*sw[4] ); + dw6 = sw[ 6 ] - ( S5*sw[5] ); + dw7 = sw[ 7 ] - ( S6*sw[6] ); + dw8 = sw[ 8 ] - ( S7*sw[7] ); + dw9 = sw[ 9 ] - ( S8*sw[8] ); + du0 = su[ 0 ]; + du1 = su[ 1 ] - ( S0*su[0] ); + du2 = su[ 2 ] - ( S1*su[1] ); + du3 = su[ 3 ] - ( S2*su[2] ); + du4 = su[ 4 ] - ( S3*su[3] ); + du5 = su[ 5 ] - ( S4*su[4] ); + du6 = su[ 6 ] - ( S5*su[5] ); + du7 = su[ 7 ] - ( S6*su[6] ); + du8 = su[ 8 ] - ( S7*su[7] ); + du9 = su[ 9 ] - ( S8*su[8] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + iu = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache accessors: + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = z.accessors[ 0 ]; + wget = w.accessors[ 0 ]; + uset = u.accessors[ 1 ]; + + // Iterate over the 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++ ) { + uset( ubuf, iu, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ), wget( wbuf, iw ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + iu += du4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + iu += du5; + } + ix += dx6; + iy += dy6; + iz += dz6; + iw += dw6; + iu += du6; + } + ix += dx7; + iy += dy7; + iz += dz7; + iw += dw7; + iu += du7; + } + ix += dx8; + iy += dy8; + iz += dz8; + iw += dw8; + iu += du8; + } + ix += dx9; + iy += dy9; + iz += dz9; + iw += dw9; + iu += du9; + } +} + + +// EXPORTS // + +module.exports = quaternary10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/10d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/10d_blocked.js new file mode 100644 index 000000000000..809ae20d8d28 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/10d_blocked.js @@ -0,0 +1,603 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-depth, max-statements, max-lines-per-function, max-len */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/quaternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/quaternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a quaternary callback to elements in ten-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Callback} fcn - quaternary callback +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // 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( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = new Float64Array( 12 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 2, 3, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 12, 6, 2, 1 ]; +* var sy = [ 12, 12, 12, 12, 12, 12, 12, 6, 2, 1 ]; +* var sz = [ 12, 12, 12, 12, 12, 12, 12, 6, 2, 1 ]; +* var sw = [ 12, 12, 12, 12, 12, 12, 12, 6, 2, 1 ]; +* var su = [ 12, 12, 12, 12, 12, 12, 12, 6, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* var z = { +* 'dtype': 'float64', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major' +* }; +* var w = { +* 'dtype': 'float64', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major' +* }; +* var u = { +* 'dtype': 'float64', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major' +* }; +* +* // Apply the quaternary function: +* blockedquaternary10d( x, y, z, w, u, fcn ); +* +* console.log( u.data ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0 ] +*/ +function blockedquaternary10d( x, y, z, w, u, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var dx8; + var dx9; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dy7; + var dy8; + var dy9; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dz6; + var dz7; + var dz8; + var dz9; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dw6; + var dw7; + var dw8; + var dw9; + var du0; + var du1; + var du2; + var du3; + var du4; + var du5; + var du6; + var du7; + var du8; + var du9; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var ox6; + var ox7; + var ox8; + var ox9; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oy6; + var oy7; + var oy8; + var oy9; + var oz1; + var oz2; + var oz3; + var oz4; + var oz5; + var oz6; + var oz7; + var oz8; + var oz9; + var ow1; + var ow2; + var ow3; + var ow4; + var ow5; + var ow6; + var ow7; + var ow8; + var ow9; + var ou1; + var ou2; + var ou3; + var ou4; + var ou5; + var ou6; + var ou7; + var ou8; + var ou9; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var s8; + var s9; + var sx; + var sy; + var sz; + var sw; + var su; + var ox; + var oy; + var oz; + var ow; + var ou; + var ix; + var iy; + var iz; + var iw; + var iu; + 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 o; + + // Note on variable naming convention: s#, dx#, dy#, dz#, dw#, du#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( x.shape, x.strides, y.strides, z.strides, w.strides, u.strides ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + su = o.su; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.dtype, u.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ox = x.offset; + oy = y.offset; + oz = z.offset; + ow = w.offset; + ou = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + du0 = su[0]; + + // Iterate over blocks... + for ( j9 = sh[9]; j9 > 0; ) { + if ( j9 < bsize ) { + s9 = j9; + j9 = 0; + } else { + s9 = bsize; + j9 -= bsize; + } + ox9 = ox + ( j9*sx[9] ); + oy9 = oy + ( j9*sy[9] ); + oz9 = oz + ( j9*sz[9] ); + ow9 = ow + ( j9*sw[9] ); + ou9 = ou + ( j9*su[9] ); + for ( j8 = sh[8]; j8 > 0; ) { + if ( j8 < bsize ) { + s8 = j8; + j8 = 0; + } else { + s8 = bsize; + j8 -= bsize; + } + dx9 = sx[9] - ( s8*sx[8] ); + dy9 = sy[9] - ( s8*sy[8] ); + dz9 = sz[9] - ( s8*sz[8] ); + dw9 = sw[9] - ( s8*sw[8] ); + du9 = su[9] - ( s8*su[8] ); + ox8 = ox9 + ( j8*sx[8] ); + oy8 = oy9 + ( j8*sy[8] ); + oz8 = oz9 + ( j8*sz[8] ); + ow8 = ow9 + ( j8*sw[8] ); + ou8 = ou9 + ( j8*su[8] ); + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + dx8 = sx[8] - ( s7*sx[7] ); + dy8 = sy[8] - ( s7*sy[7] ); + dz8 = sz[8] - ( s7*sz[7] ); + dw8 = sw[8] - ( s7*sw[7] ); + du8 = su[8] - ( s7*su[7] ); + ox7 = ox8 + ( j7*sx[7] ); + oy7 = oy8 + ( j7*sy[7] ); + oz7 = oz8 + ( j7*sz[7] ); + ow7 = ow8 + ( j7*sw[7] ); + ou7 = ou8 + ( j7*su[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + dx7 = sx[7] - ( s6*sx[6] ); + dy7 = sy[7] - ( s6*sy[6] ); + dz7 = sz[7] - ( s6*sz[6] ); + dw7 = sw[7] - ( s6*sw[6] ); + du7 = su[7] - ( s6*su[6] ); + ox6 = ox7 + ( j6*sx[6] ); + oy6 = oy7 + ( j6*sy[6] ); + oz6 = oz7 + ( j6*sz[6] ); + ow6 = ow7 + ( j6*sw[6] ); + ou6 = ou7 + ( j6*su[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dx6 = sx[6] - ( s5*sx[5] ); + dy6 = sy[6] - ( s5*sy[5] ); + dz6 = sz[6] - ( s5*sz[5] ); + dw6 = sw[6] - ( s5*sw[5] ); + du6 = su[6] - ( s5*su[5] ); + ox5 = ox6 + ( j5*sx[5] ); + oy5 = oy6 + ( j5*sy[5] ); + oz5 = oz6 + ( j5*sz[5] ); + ow5 = ow6 + ( j5*sw[5] ); + ou5 = ou6 + ( j5*su[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + dz5 = sz[5] - ( s4*sz[4] ); + dw5 = sw[5] - ( s4*sw[4] ); + du5 = su[5] - ( s4*su[4] ); + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oz4 = oz5 + ( j4*sz[4] ); + ow4 = ow5 + ( j4*sw[4] ); + ou4 = ou5 + ( j4*su[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + dz4 = sz[4] - ( s3*sz[3] ); + dw4 = sw[4] - ( s3*sw[3] ); + du4 = su[4] - ( s3*su[3] ); + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oz3 = oz4 + ( j3*sz[3] ); + ow3 = ow4 + ( j3*sw[3] ); + ou3 = ou4 + ( j3*su[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + du3 = su[3] - ( s2*su[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + ou2 = ou3 + ( j2*su[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + du2 = su[2] - ( s1*su[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[1] ); + ou1 = ou2 + ( j1*su[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets for the first input and output ndarray elements in the current block... + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + iz = oz1 + ( j0*sz[0] ); + iw = ow1 + ( j0*sw[0] ); + iu = ou1 + ( j0*su[0] ); + + // Compute loop offset increments... + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + dz1 = sz[1] - ( s0*sz[0] ); + dw1 = sw[1] - ( s0*sw[0] ); + du1 = su[1] - ( s0*su[0] ); + + // Iterate over the 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++ ) { + ubuf[ iu ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ], wbuf[ iw ] ); + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + iu += du4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + iu += du5; + } + ix += dx6; + iy += dy6; + iz += dz6; + iw += dw6; + iu += du6; + } + ix += dx7; + iy += dy7; + iz += dz7; + iw += dw7; + iu += du7; + } + ix += dx8; + iy += dy8; + iz += dz8; + iw += dw8; + iu += du8; + } + ix += dx9; + iy += dy9; + iz += dz9; + iw += dw9; + iu += du9; + } + } + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedquaternary10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/10d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/10d_blocked_accessors.js new file mode 100644 index 000000000000..ed42851f9538 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/10d_blocked_accessors.js @@ -0,0 +1,627 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-depth, max-statements, max-lines-per-function, max-len, max-lines */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/quaternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/quaternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a quaternary callback to elements in ten-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} z.accessors - data buffer accessors +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} w.accessors - data buffer accessors +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} u.accessors - data buffer accessors +* @param {Callback} fcn - quaternary callback +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var copy = require( '@stdlib/array/base/copy' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // 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( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ) ); +* var zbuf = toAccessorArray( new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ) ); +* var wbuf = toAccessorArray( new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ) ); +* var ubuf = toAccessorArray( new Float64Array( 12 ) ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 2, 3, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 12, 6, 2, 1 ]; +* var sy = [ 12, 12, 12, 12, 12, 12, 12, 6, 2, 1 ]; +* var sz = [ 12, 12, 12, 12, 12, 12, 12, 6, 2, 1 ]; +* var sw = [ 12, 12, 12, 12, 12, 12, 12, 6, 2, 1 ]; +* var su = [ 12, 12, 12, 12, 12, 12, 12, 6, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* var y = { +* 'dtype': 'generic', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* var z = { +* 'dtype': 'generic', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major', +* 'accessors': accessors( zbuf ).accessors +* }; +* var w = { +* 'dtype': 'generic', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major', +* 'accessors': accessors( wbuf ).accessors +* }; +* var u = { +* 'dtype': 'generic', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major', +* 'accessors': accessors( ubuf ).accessors +* }; +* +* // Apply the ternary function: +* blockedquaternary10d( x, y, z, w, u, fcn ); +* +* console.log( copy( u.data ) ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0 ] +*/ +function blockedquaternary10d( x, y, z, w, u, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var xget; + var yget; + var zget; + var wget; + var uset; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var dx8; + var dx9; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dy7; + var dy8; + var dy9; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dz6; + var dz7; + var dz8; + var dz9; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dw6; + var dw7; + var dw8; + var dw9; + var du0; + var du1; + var du2; + var du3; + var du4; + var du5; + var du6; + var du7; + var du8; + var du9; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var ox6; + var ox7; + var ox8; + var ox9; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oy6; + var oy7; + var oy8; + var oy9; + var oz1; + var oz2; + var oz3; + var oz4; + var oz5; + var oz6; + var oz7; + var oz8; + var oz9; + var ow1; + var ow2; + var ow3; + var ow4; + var ow5; + var ow6; + var ow7; + var ow8; + var ow9; + var ou1; + var ou2; + var ou3; + var ou4; + var ou5; + var ou6; + var ou7; + var ou8; + var ou9; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var s8; + var s9; + var sx; + var sy; + var sz; + var sw; + var su; + var ox; + var oy; + var oz; + var ow; + var ou; + var ix; + var iy; + var iz; + var iw; + var iu; + 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 o; + + // Note on variable naming convention: s#, dx#, dy#, dz#, dw#, du#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( x.shape, x.strides, y.strides, z.strides, w.strides, u.strides ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + su = o.su; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.dtype, u.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ox = x.offset; + oy = y.offset; + oz = z.offset; + ow = w.offset; + ou = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + du0 = su[0]; + + // Cache accessors: + xget = x.accessors[0]; + yget = y.accessors[0]; + zget = z.accessors[0]; + wget = w.accessors[0]; + uset = u.accessors[1]; + + // Iterate over blocks... + for ( j9 = sh[9]; j9 > 0; ) { + if ( j9 < bsize ) { + s9 = j9; + j9 = 0; + } else { + s9 = bsize; + j9 -= bsize; + } + ox9 = ox + ( j9*sx[9] ); + oy9 = oy + ( j9*sy[9] ); + oz9 = oz + ( j9*sz[9] ); + ow9 = ow + ( j9*sw[9] ); + ou9 = ou + ( j9*su[9] ); + for ( j8 = sh[8]; j8 > 0; ) { + if ( j8 < bsize ) { + s8 = j8; + j8 = 0; + } else { + s8 = bsize; + j8 -= bsize; + } + dx9 = sx[9] - ( s8*sx[8] ); + dy9 = sy[9] - ( s8*sy[8] ); + dz9 = sz[9] - ( s8*sz[8] ); + dw9 = sw[9] - ( s8*sw[8] ); + du9 = su[9] - ( s8*su[8] ); + ox8 = ox9 + ( j8*sx[8] ); + oy8 = oy9 + ( j8*sy[8] ); + oz8 = oz9 + ( j8*sz[8] ); + ow8 = ow9 + ( j8*sw[8] ); + ou8 = ou9 + ( j8*su[8] ); + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + dx8 = sx[8] - ( s7*sx[7] ); + dy8 = sy[8] - ( s7*sy[7] ); + dz8 = sz[8] - ( s7*sz[7] ); + dw8 = sw[8] - ( s7*sw[7] ); + du8 = su[8] - ( s7*su[7] ); + ox7 = ox8 + ( j7*sx[7] ); + oy7 = oy8 + ( j7*sy[7] ); + oz7 = oz8 + ( j7*sz[7] ); + ow7 = ow8 + ( j7*sw[7] ); + ou7 = ou8 + ( j7*su[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + dx7 = sx[7] - ( s6*sx[6] ); + dy7 = sy[7] - ( s6*sy[6] ); + dz7 = sz[7] - ( s6*sz[6] ); + dw7 = sw[7] - ( s6*sw[6] ); + du7 = su[7] - ( s6*su[6] ); + ox6 = ox7 + ( j6*sx[6] ); + oy6 = oy7 + ( j6*sy[6] ); + oz6 = oz7 + ( j6*sz[6] ); + ow6 = ow7 + ( j6*sw[6] ); + ou6 = ou7 + ( j6*su[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dx6 = sx[6] - ( s5*sx[5] ); + dy6 = sy[6] - ( s5*sy[5] ); + dz6 = sz[6] - ( s5*sz[5] ); + dw6 = sw[6] - ( s5*sw[5] ); + du6 = su[6] - ( s5*su[5] ); + ox5 = ox6 + ( j5*sx[5] ); + oy5 = oy6 + ( j5*sy[5] ); + oz5 = oz6 + ( j5*sz[5] ); + ow5 = ow6 + ( j5*sw[5] ); + ou5 = ou6 + ( j5*su[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + dz5 = sz[5] - ( s4*sz[4] ); + dw5 = sw[5] - ( s4*sw[4] ); + du5 = su[5] - ( s4*su[4] ); + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oz4 = oz5 + ( j4*sz[4] ); + ow4 = ow5 + ( j4*sw[4] ); + ou4 = ou5 + ( j4*su[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + dz4 = sz[4] - ( s3*sz[3] ); + dw4 = sw[4] - ( s3*sw[3] ); + du4 = su[4] - ( s3*su[3] ); + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oz3 = oz4 + ( j3*sz[3] ); + ow3 = ow4 + ( j3*sw[3] ); + ou3 = ou4 + ( j3*su[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + du3 = su[3] - ( s2*su[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + ou2 = ou3 + ( j2*su[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + du2 = su[2] - ( s1*su[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[1] ); + ou1 = ou2 + ( j1*su[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets for the first input and output ndarray elements in the current block... + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + iz = oz1 + ( j0*sz[0] ); + iw = ow1 + ( j0*sw[0] ); + iu = ou1 + ( j0*su[0] ); + + // Compute loop offset increments... + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + dz1 = sz[1] - ( s0*sz[0] ); + dw1 = sw[1] - ( s0*sw[0] ); + du1 = su[1] - ( s0*su[0] ); + + // Iterate over the 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++ ) { + uset( ubuf, iu, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ), wget( wbuf, iw ) ) ); + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + iu += du4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + iu += du5; + } + ix += dx6; + iy += dy6; + iz += dz6; + iw += dw6; + iu += du6; + } + ix += dx7; + iy += dy7; + iz += dz7; + iw += dw7; + iu += du7; + } + ix += dx8; + iy += dy8; + iz += dz8; + iw += dw8; + iu += du8; + } + ix += dx9; + iy += dy9; + iz += dz9; + iw += dw9; + iu += du9; + } + } + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedquaternary10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/1d.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/1d.js new file mode 100644 index 000000000000..050340aad66e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/1d.js @@ -0,0 +1,201 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 // + +/** +* Applies a quaternary callback to elements in a one-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Callback} fcn - quaternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var ybuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 5 ]; +* +* // Define the array strides: +* var sx = [ 1 ]; +* var sy = [ 1 ]; +* var sz = [ 1 ]; +* var sw = [ 1 ]; +* var su = [ 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* var z = { +* 'dtype': 'float64', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major' +* }; +* var w = { +* 'dtype': 'float64', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major' +* }; +* var u = { +* 'dtype': 'float64', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major' +* }; +* +* // Apply the quaternary function: +* quaternary1d( x, y, z, w, u, fcn ); +* +* console.log( u.data ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0 ] +*/ +function quaternary1d( x, y, z, w, u, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var dx; + var dy; + var dz; + var dw; + var du; + var S0; + var ix; + var iy; + var iz; + var iw; + var iu; + var i; + + // Note on variable naming convention: S#, where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables: dimensions and loop offset (pointer) increments... + S0 = x.shape[ 0 ]; + dx = x.strides[ 0 ]; + dy = y.strides[ 0 ]; + dz = z.strides[ 0 ]; + dw = w.strides[ 0 ]; + du = u.strides[ 0 ]; + + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + iu = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Iterate over the ndarray dimensions... + for ( i = 0; i < S0; i++ ) { + ubuf[ iu ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ], wbuf[ iw ] ); + ix += dx; + iy += dy; + iz += dz; + iw += dw; + iu += du; + } +} + + +// EXPORTS // + +module.exports = quaternary1d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/1d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/1d_accessors.js new file mode 100644 index 000000000000..2cad81b6dc56 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/1d_accessors.js @@ -0,0 +1,225 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 // + +/** +* Applies a quaternary callback to elements in a one-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} z.accessors - data buffer accessors +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} w.accessors - data buffer accessors +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} u.accessors - data buffer accessors +* @param {Callback} fcn - quaternary callback +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var copy = require( '@stdlib/array/base/copy' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0 ] ); +* var ybuf = toAccessorArray( [ 1.0, 1.0, 1.0 ] ); +* var zbuf = toAccessorArray( [ 2.0, 2.0, 2.0 ] ); +* var wbuf = toAccessorArray( [ 3.0, 3.0, 3.0 ] ); +* var ubuf = toAccessorArray( [ 0.0, 0.0, 0.0 ] ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 3 ]; +* +* // Define the array strides: +* var sx = [ 1 ]; +* var sy = [ 1 ]; +* var sz = [ 1 ]; +* var sw = [ 1 ]; +* var su = [ 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* var y = { +* 'dtype': 'generic', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* var z = { +* 'dtype': 'generic', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major', +* 'accessors': accessors( zbuf ).accessors +* }; +* var w = { +* 'dtype': 'generic', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major', +* 'accessors': accessors( wbuf ).accessors +* }; +* var u = { +* 'dtype': 'generic', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major', +* 'accessors': accessors( ubuf ).accessors +* }; +* +* // Apply the quaternary function: +* quaternary1d( x, y, z, w, u, fcn ); +* +* console.log( copy( u.data ) ); +* // => [ 7.0, 8.0, 9.0 ] +*/ +function quaternary1d( x, y, z, w, u, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var xget; + var yget; + var zget; + var wget; + var uset; + var dx; + var dy; + var dz; + var dw; + var du; + var S0; + var ix; + var iy; + var iz; + var iw; + var iu; + var i; + + // Note on variable naming convention: S#, where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables: dimensions and loop offset (pointer) increments... + S0 = x.shape[ 0 ]; + dx = x.strides[ 0 ]; + dy = y.strides[ 0 ]; + dz = z.strides[ 0 ]; + dw = w.strides[ 0 ]; + du = u.strides[ 0 ]; + + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + iu = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache accessors: + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = z.accessors[ 0 ]; + wget = w.accessors[ 0 ]; + uset = u.accessors[ 1 ]; + + // Iterate over the ndarray dimensions... + for ( i = 0; i < S0; i++ ) { + uset( ubuf, iu, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ), wget( wbuf, iw ) ) ); // eslint-disable-line max-len + ix += dx; + iy += dy; + iz += dz; + iw += dw; + iu += du; + } +} + + +// EXPORTS // + +module.exports = quaternary1d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/2d.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/2d.js new file mode 100644 index 000000000000..14a6cf584e30 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/2d.js @@ -0,0 +1,250 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 // + +/** +* Applies a quaternary callback to elements in two-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - quaternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var ybuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 3, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 1 ]; +* var sy = [ 2, 1 ]; +* var sz = [ 2, 1 ]; +* var sw = [ 2, 1 ]; +* var su = [ 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* var z = { +* 'dtype': 'float64', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major' +* }; +* var w = { +* 'dtype': 'float64', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major' +* }; +* var u = { +* 'dtype': 'float64', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major' +* }; +* +* // Apply the quaternary function: +* quaternary2d( x, y, z, w, u, true, fcn ); +* +* console.log( u.data ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] +*/ +function quaternary2d( x, y, z, w, u, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var dx0; + var dx1; + var dy0; + var dy1; + var dz0; + var dz1; + var dw0; + var dw1; + var du0; + var du1; + var sh; + var S0; + var S1; + var sx; + var sy; + var sz; + var sw; + var su; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + + // Note on variable naming convention: S#, dx#, dy#, dz#, dw#, du#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = x.shape; + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + su = u.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 1 ]; + S1 = sh[ 0 ]; + dx0 = sx[ 1 ]; // offset increment for innermost loop + dx1 = sx[ 0 ] - ( S0*sx[1] ); // offset increment for outermost loop + dy0 = sy[ 1 ]; + dy1 = sy[ 0 ] - ( S0*sy[1] ); + dz0 = sz[ 1 ]; + dz1 = sz[ 0 ] - ( S0*sz[1] ); + dw0 = sw[ 1 ]; + dw1 = sw[ 0 ] - ( S0*sw[1] ); + du0 = su[ 1 ]; + du1 = su[ 0 ] - ( S0*su[1] ); + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); // offset increment for outermost loop + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dz0 = sz[ 0 ]; + dz1 = sz[ 1 ] - ( S0*sz[0] ); + dw0 = sw[ 0 ]; + dw1 = sw[ 1 ] - ( S0*sw[0] ); + du0 = su[ 0 ]; + du1 = su[ 1 ] - ( S0*su[0] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + iu = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Iterate over the ndarray dimensions... + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + ubuf[ iu ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ], wbuf[ iw ] ); + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } +} + + +// EXPORTS // + +module.exports = quaternary2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/2d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/2d_accessors.js new file mode 100644 index 000000000000..250f91891aa5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/2d_accessors.js @@ -0,0 +1,274 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 // + +/** +* Applies a quaternary callback to elements in two-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} z.accessors - data buffer accessors +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} w.accessors - data buffer accessors +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} u.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - quaternary callback +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var copy = require( '@stdlib/array/base/copy' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var ybuf = toAccessorArray( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = toAccessorArray( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = toAccessorArray( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 3, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 1 ]; +* var sy = [ 2, 1 ]; +* var sz = [ 2, 1 ]; +* var sw = [ 2, 1 ]; +* var su = [ 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* var y = { +* 'dtype': 'generic', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* var z = { +* 'dtype': 'generic', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major', +* 'accessors': accessors( zbuf ).accessors +* }; +* var w = { +* 'dtype': 'generic', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major', +* 'accessors': accessors( wbuf ).accessors +* }; +* var u = { +* 'dtype': 'generic', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major', +* 'accessors': accessors( ubuf ).accessors +* }; +* +* // Apply the quaternary function: +* quaternary2d( x, y, z, w, u, true, fcn ); +* +* console.log( copy( u.data ) ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] +*/ +function quaternary2d( x, y, z, w, u, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var xget; + var yget; + var zget; + var wget; + var uset; + var dx0; + var dx1; + var dy0; + var dy1; + var dz0; + var dz1; + var dw0; + var dw1; + var du0; + var du1; + var sh; + var S0; + var S1; + var sx; + var sy; + var sz; + var sw; + var su; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + + // Note on variable naming convention: S#, dx#, dy#, dz#, dw#, du#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = x.shape; + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + su = u.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 1 ]; + S1 = sh[ 0 ]; + dx0 = sx[ 1 ]; // offset increment for innermost loop + dx1 = sx[ 0 ] - ( S0*sx[1] ); // offset increment for outermost loop + dy0 = sy[ 1 ]; + dy1 = sy[ 0 ] - ( S0*sy[1] ); + dz0 = sz[ 1 ]; + dz1 = sz[ 0 ] - ( S0*sz[1] ); + dw0 = sw[ 1 ]; + dw1 = sw[ 0 ] - ( S0*sw[1] ); + du0 = su[ 1 ]; + du1 = su[ 0 ] - ( S0*su[1] ); + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); // offset increment for outermost loop + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dz0 = sz[ 0 ]; + dz1 = sz[ 1 ] - ( S0*sz[0] ); + dw0 = sw[ 0 ]; + dw1 = sw[ 1 ] - ( S0*sw[0] ); + du0 = su[ 0 ]; + du1 = su[ 1 ] - ( S0*su[0] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + iu = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache accessors: + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = z.accessors[ 0 ]; + wget = w.accessors[ 0 ]; + uset = u.accessors[ 1 ]; + + // Iterate over the ndarray dimensions... + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + uset( ubuf, iu, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ), wget( wbuf, iw ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } +} + + +// EXPORTS // + +module.exports = quaternary2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/2d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/2d_blocked.js new file mode 100644 index 000000000000..3e2e57514ec7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/2d_blocked.js @@ -0,0 +1,291 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-statements */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/quaternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/quaternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a quaternary callback to elements in two-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Callback} fcn - quaternary callback +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var ybuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 3, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 1 ]; +* var sy = [ 2, 1 ]; +* var sz = [ 2, 1 ]; +* var sw = [ 2, 1 ]; +* var su = [ 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* var z = { +* 'dtype': 'float64', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major' +* }; +* var w = { +* 'dtype': 'float64', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major' +* }; +* var u = { +* 'dtype': 'float64', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major' +* }; +* +* // Apply the quaternary function: +* blockedquaternary2d( x, y, z, w, u, fcn ); +* +* console.log( u.data ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] +*/ +function blockedquaternary2d( x, y, z, w, u, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var dx0; + var dx1; + var dy0; + var dy1; + var dz0; + var dz1; + var dw0; + var dw1; + var du0; + var du1; + var ox1; + var oy1; + var oz1; + var ow1; + var ou1; + var sh; + var s0; + var s1; + var sx; + var sy; + var sz; + var sw; + var su; + var ox; + var oy; + var oz; + var ow; + var ou; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + var j0; + var j1; + var o; + + // Note on variable naming convention: s#, dx#, dy#, dz#, dw#, du#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( x.shape, x.strides, y.strides, z.strides, w.strides, u.strides ); // eslint-disable-line max-len + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + su = o.su; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.dtype, u.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ox = x.offset; + oy = y.offset; + oz = z.offset; + ow = w.offset; + ou = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + du0 = su[0]; + + // Iterate over blocks... + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + ox1 = ox + ( j1*sx[1] ); + oy1 = oy + ( j1*sy[1] ); + oz1 = oz + ( j1*sz[1] ); + ow1 = ow + ( j1*sw[1] ); + ou1 = ou + ( j1*su[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets for the first input and output ndarray elements in the current block... + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + iz = oz1 + ( j0*sz[0] ); + iw = ow1 + ( j0*sw[0] ); + iu = ou1 + ( j0*su[0] ); + + // Compute loop offset increments... + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + dz1 = sz[1] - ( s0*sz[0] ); + dw1 = sw[1] - ( s0*sw[0] ); + du1 = su[1] - ( s0*su[0] ); + + // Iterate over the ndarray dimensions... + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + ubuf[ iu ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ], wbuf[ iw ] ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + } + } +} + + +// EXPORTS // + +module.exports = blockedquaternary2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/2d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/2d_blocked_accessors.js new file mode 100644 index 000000000000..e67ec8e53dd3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/2d_blocked_accessors.js @@ -0,0 +1,315 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-statements */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/quaternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/quaternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a quaternary callback to elements in two-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} z.accessors - data buffer accessors +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} w.accessors - data buffer accessors +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} u.accessors - data buffer accessors +* @param {Callback} fcn - quaternary callback +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var copy = require( '@stdlib/array/base/copy' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( [ 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( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = toAccessorArray( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = toAccessorArray( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = toAccessorArray( [ 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 shape of the input and output arrays: +* var shape = [ 6, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 1 ]; +* var sy = [ 2, 1 ]; +* var sz = [ 2, 1 ]; +* var sw = [ 2, 1 ]; +* var su = [ 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* var y = { +* 'dtype': 'generic', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* var z = { +* 'dtype': 'generic', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major', +* 'accessors': accessors( zbuf ).accessors +* }; +* var w = { +* 'dtype': 'generic', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major', +* 'accessors': accessors( wbuf ).accessors +* }; +* var u = { +* 'dtype': 'generic', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major', +* 'accessors': accessors( ubuf ).accessors +* }; +* +* // Apply the quaternary function: +* blockedquaternary2d( x, y, z, w, u, fcn ); +* +* console.log( copy( u.data ) ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0 ] +*/ +function blockedquaternary2d( x, y, z, w, u, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var xget; + var yget; + var zget; + var wget; + var uset; + var dx0; + var dx1; + var dy0; + var dy1; + var dz0; + var dz1; + var dw0; + var dw1; + var du0; + var du1; + var ox1; + var oy1; + var oz1; + var ow1; + var ou1; + var sh; + var s0; + var s1; + var sx; + var sy; + var sz; + var sw; + var su; + var ox; + var oy; + var oz; + var ow; + var ou; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + var j0; + var j1; + var o; + + // Note on variable naming convention: s#, dx#, dy#, dz#, dw#, du#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( x.shape, x.strides, y.strides, z.strides, w.strides, u.strides ); // eslint-disable-line max-len + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + su = o.su; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.dtype, u.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ox = x.offset; + oy = y.offset; + oz = z.offset; + ow = w.offset; + ou = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + du0 = su[0]; + + // Cache accessors: + xget = x.accessors[0]; + yget = y.accessors[0]; + zget = z.accessors[0]; + wget = w.accessors[0]; + uset = u.accessors[1]; + + // Iterate over blocks... + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + ox1 = ox + ( j1*sx[1] ); + oy1 = oy + ( j1*sy[1] ); + oz1 = oz + ( j1*sz[1] ); + ow1 = ow + ( j1*sw[1] ); + ou1 = ou + ( j1*su[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets for the first input and output ndarray elements in the current block... + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + iz = oz1 + ( j0*sz[0] ); + iw = ow1 + ( j0*sw[0] ); + iu = ou1 + ( j0*su[0] ); + + // Compute loop offset increments... + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + dz1 = sz[1] - ( s0*sz[0] ); + dw1 = sw[1] - ( s0*sw[0] ); + du1 = su[1] - ( s0*su[0] ); + + // Iterate over the ndarray dimensions... + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + uset( ubuf, iu, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ), wget( wbuf, iw ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + } + } +} + + +// EXPORTS // + +module.exports = blockedquaternary2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/3d.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/3d.js new file mode 100644 index 000000000000..2c34f3df331a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/3d.js @@ -0,0 +1,278 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-statements */ + +'use strict'; + +// MAIN // + +/** +* Applies a quaternary callback to elements in a three-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - quaternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // 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( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = new Float64Array( 12 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 3, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 2, 1 ]; +* var sy = [ 4, 2, 1 ]; +* var sz = [ 4, 2, 1 ]; +* var sw = [ 4, 2, 1 ]; +* var su = [ 4, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* var z = { +* 'dtype': 'float64', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major' +* }; +* var w = { +* 'dtype': 'float64', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major' +* }; +* var u = { +* 'dtype': 'float64', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major' +* }; +* +* // Apply the quaternary function: +* quaternary3d( x, y, z, w, u, true, fcn ); +* +* console.log( u.data ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0 ] +*/ +function quaternary3d( x, y, z, w, u, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var dx0; + var dx1; + var dx2; + var dy0; + var dy1; + var dy2; + var dz0; + var dz1; + var dz2; + var dw0; + var dw1; + var dw2; + var du0; + var du1; + var du2; + var sh; + var S0; + var S1; + var S2; + var sx; + var sy; + var sz; + var sw; + var su; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + var i2; + + // Note on variable naming convention: S#, dx#, dy#, dz#, dw#, du#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = x.shape; + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + su = u.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 2 ]; + S1 = sh[ 1 ]; + S2 = sh[ 0 ]; + dx0 = sx[ 2 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[2] ); + dx2 = sx[ 0 ] - ( S1*sx[1] ); // offset increment for outermost loop + dy0 = sy[ 2 ]; + dy1 = sy[ 1 ] - ( S0*sy[2] ); + dy2 = sy[ 0 ] - ( S1*sy[1] ); + dz0 = sz[ 2 ]; + dz1 = sz[ 1 ] - ( S0*sz[2] ); + dz2 = sz[ 0 ] - ( S1*sz[1] ); + dw0 = sw[ 2 ]; + dw1 = sw[ 1 ] - ( S0*sw[2] ); + dw2 = sw[ 0 ] - ( S1*sw[1] ); + du0 = su[ 2 ]; + du1 = su[ 1 ] - ( S0*su[2] ); + du2 = su[ 0 ] - ( S1*su[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 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); // offset increment for outermost loop + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dz0 = sz[ 0 ]; + dz1 = sz[ 1 ] - ( S0*sz[0] ); + dz2 = sz[ 2 ] - ( S1*sz[1] ); + dw0 = sw[ 0 ]; + dw1 = sw[ 1 ] - ( S0*sw[0] ); + dw2 = sw[ 2 ] - ( S1*sw[1] ); + du0 = su[ 0 ]; + du1 = su[ 1 ] - ( S0*su[0] ); + du2 = su[ 2 ] - ( S1*su[1] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + iu = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Iterate over the ndarray dimensions... + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + ubuf[ iu ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ], wbuf[ iw ] ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } +} + + +// EXPORTS // + +module.exports = quaternary3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/3d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/3d_accessors.js new file mode 100644 index 000000000000..816eba6ac32b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/3d_accessors.js @@ -0,0 +1,302 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-statements */ + +'use strict'; + +// MAIN // + +/** +* Applies a quaternary callback to elements in a three-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} z.accessors - data buffer accessors +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} w.accessors - data buffer accessors +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} u.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - quaternary callback +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var copy = require( '@stdlib/array/base/copy' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( [ 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( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = toAccessorArray( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = toAccessorArray( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = toAccessorArray( [ 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 shape of the input and output arrays: +* var shape = [ 3, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 2, 1 ]; +* var sy = [ 4, 2, 1 ]; +* var sz = [ 4, 2, 1 ]; +* var sw = [ 4, 2, 1 ]; +* var su = [ 4, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* var y = { +* 'dtype': 'generic', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* var z = { +* 'dtype': 'generic', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major', +* 'accessors': accessors( zbuf ).accessors +* }; +* var w = { +* 'dtype': 'generic', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major', +* 'accessors': accessors( wbuf ).accessors +* }; +* var u = { +* 'dtype': 'generic', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major', +* 'accessors': accessors( ubuf ).accessors +* }; +* +* // Apply the quaternary function: +* quaternary3d( x, y, z, w, u, true, fcn ); +* +* console.log( copy( u.data ) ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0 ] +*/ +function quaternary3d( x, y, z, w, u, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var xget; + var yget; + var zget; + var wget; + var uset; + var dx0; + var dx1; + var dx2; + var dy0; + var dy1; + var dy2; + var dz0; + var dz1; + var dz2; + var dw0; + var dw1; + var dw2; + var du0; + var du1; + var du2; + var sh; + var S0; + var S1; + var S2; + var sx; + var sy; + var sz; + var sw; + var su; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + var i2; + + // Note on variable naming convention: S#, dx#, dy#, dz#, dw#, du#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = x.shape; + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + su = u.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 2 ]; + S1 = sh[ 1 ]; + S2 = sh[ 0 ]; + dx0 = sx[ 2 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[2] ); + dx2 = sx[ 0 ] - ( S1*sx[1] ); // offset increment for outermost loop + dy0 = sy[ 2 ]; + dy1 = sy[ 1 ] - ( S0*sy[2] ); + dy2 = sy[ 0 ] - ( S1*sy[1] ); + dz0 = sz[ 2 ]; + dz1 = sz[ 1 ] - ( S0*sz[2] ); + dz2 = sz[ 0 ] - ( S1*sz[1] ); + dw0 = sw[ 2 ]; + dw1 = sw[ 1 ] - ( S0*sw[2] ); + dw2 = sw[ 0 ] - ( S1*sw[1] ); + du0 = su[ 2 ]; + du1 = su[ 1 ] - ( S0*su[2] ); + du2 = su[ 0 ] - ( S1*su[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 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); // offset increment for outermost loop + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dz0 = sz[ 0 ]; + dz1 = sz[ 1 ] - ( S0*sz[0] ); + dz2 = sz[ 2 ] - ( S1*sz[1] ); + dw0 = sw[ 0 ]; + dw1 = sw[ 1 ] - ( S0*sw[0] ); + dw2 = sw[ 2 ] - ( S1*sw[1] ); + du0 = su[ 0 ]; + du1 = su[ 1 ] - ( S0*su[0] ); + du2 = su[ 2 ] - ( S1*su[1] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + iu = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache accessors: + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = z.accessors[ 0 ]; + wget = w.accessors[ 0 ]; + uset = u.accessors[ 1 ]; + + // Iterate over the ndarray dimensions... + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + uset( ubuf, iu, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ), wget( wbuf, iw ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } +} + + +// EXPORTS // + +module.exports = quaternary3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/3d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/3d_blocked.js new file mode 100644 index 000000000000..520a7bf3b975 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/3d_blocked.js @@ -0,0 +1,330 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-depth, max-statements */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/quaternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/quaternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a quaternary callback to elements in three-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Callback} fcn - quaternary callback +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // 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( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = new Float64Array( 12 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 3, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 2, 1 ]; +* var sy = [ 4, 2, 1 ]; +* var sz = [ 4, 2, 1 ]; +* var sw = [ 4, 2, 1 ]; +* var su = [ 4, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* var z = { +* 'dtype': 'float64', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major' +* }; +* var w = { +* 'dtype': 'float64', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major' +* }; +* var u = { +* 'dtype': 'float64', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major' +* }; +* +* // Apply the quaternary function: +* blockedquaternary3d( x, y, z, w, u, fcn ); +* +* console.log( u.data ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0 ] +*/ +function blockedquaternary3d( x, y, z, w, u, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var dx0; + var dx1; + var dx2; + var dy0; + var dy1; + var dy2; + var dz0; + var dz1; + var dz2; + var dw0; + var dw1; + var dw2; + var du0; + var du1; + var du2; + var ox1; + var ox2; + var oy1; + var oy2; + var oz1; + var oz2; + var ow1; + var ow2; + var ou1; + var ou2; + var sh; + var s0; + var s1; + var s2; + var sx; + var sy; + var sz; + var sw; + var su; + var ox; + var oy; + var oz; + var ow; + var ou; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + var i2; + var j0; + var j1; + var j2; + var o; + + // Note on variable naming convention: s#, dx#, dy#, dz#, dw#, du#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( x.shape, x.strides, y.strides, z.strides, w.strides, u.strides ); // eslint-disable-line max-len + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + su = o.su; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.dtype, u.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ox = x.offset; + oy = y.offset; + oz = z.offset; + ow = w.offset; + ou = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + du0 = su[0]; + + // Iterate over blocks... + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + ox2 = ox + ( j2*sx[2] ); + oy2 = oy + ( j2*sy[2] ); + oz2 = oz + ( j2*sz[2] ); + ow2 = ow + ( j2*sw[2] ); + ou2 = ou + ( j2*su[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + du2 = su[2] - ( s1*su[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[1] ); + ou1 = ou2 + ( j1*su[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets for the first input and output ndarray elements in the current block... + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + iz = oz1 + ( j0*sz[0] ); + iw = ow1 + ( j0*sw[0] ); + iu = ou1 + ( j0*su[0] ); + + // Compute loop offset increments... + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + dz1 = sz[1] - ( s0*sz[0] ); + dw1 = sw[1] - ( s0*sw[0] ); + du1 = su[1] - ( s0*su[0] ); + + // Iterate over the ndarray dimensions... + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + ubuf[ iu ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ], wbuf[ iw ] ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedquaternary3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/3d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/3d_blocked_accessors.js new file mode 100644 index 000000000000..ff988fc34046 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/3d_blocked_accessors.js @@ -0,0 +1,354 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-depth, max-statements */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/quaternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/quaternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a quaternary callback to elements in three-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} z.accessors - data buffer accessors +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} w.accessors - data buffer accessors +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} u.accessors - data buffer accessors +* @param {Callback} fcn - quaternary callback +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var copy = require( '@stdlib/array/base/copy' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( [ 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( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = toAccessorArray( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = toAccessorArray( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = toAccessorArray( [ 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 shape of the input and output arrays: +* var shape = [ 3, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 2, 1 ]; +* var sy = [ 4, 2, 1 ]; +* var sz = [ 4, 2, 1 ]; +* var sw = [ 4, 2, 1 ]; +* var su = [ 4, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* var y = { +* 'dtype': 'generic', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* var z = { +* 'dtype': 'generic', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major', +* 'accessors': accessors( zbuf ).accessors +* }; +* var w = { +* 'dtype': 'generic', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major', +* 'accessors': accessors( wbuf ).accessors +* }; +* var u = { +* 'dtype': 'generic', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major', +* 'accessors': accessors( ubuf ).accessors +* }; +* +* // Apply the quaternary function: +* blockedquaternary3d( x, y, z, w, u, fcn ); +* +* console.log( copy( u.data ) ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0 ] +*/ +function blockedquaternary3d( x, y, z, w, u, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var xget; + var yget; + var zget; + var wget; + var uset; + var dx0; + var dx1; + var dx2; + var dy0; + var dy1; + var dy2; + var dz0; + var dz1; + var dz2; + var dw0; + var dw1; + var dw2; + var du0; + var du1; + var du2; + var ox1; + var ox2; + var oy1; + var oy2; + var oz1; + var oz2; + var ow1; + var ow2; + var ou1; + var ou2; + var sh; + var s0; + var s1; + var s2; + var sx; + var sy; + var sz; + var sw; + var su; + var ox; + var oy; + var oz; + var ow; + var ou; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + var i2; + var j0; + var j1; + var j2; + var o; + + // Note on variable naming convention: s#, dx#, dy#, dz#, dw#, du#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( x.shape, x.strides, y.strides, z.strides, w.strides, u.strides ); // eslint-disable-line max-len + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + su = o.su; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.dtype, u.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ox = x.offset; + oy = y.offset; + oz = z.offset; + ow = w.offset; + ou = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + du0 = su[0]; + + // Cache accessors: + xget = x.accessors[0]; + yget = y.accessors[0]; + zget = z.accessors[0]; + wget = w.accessors[0]; + uset = u.accessors[1]; + + // Iterate over blocks... + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + ox2 = ox + ( j2*sx[2] ); + oy2 = oy + ( j2*sy[2] ); + oz2 = oz + ( j2*sz[2] ); + ow2 = ow + ( j2*sw[2] ); + ou2 = ou + ( j2*su[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + du2 = su[2] - ( s1*su[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[1] ); + ou1 = ou2 + ( j1*su[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets for the first input and output ndarray elements in the current block... + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + iz = oz1 + ( j0*sz[0] ); + iw = ow1 + ( j0*sw[0] ); + iu = ou1 + ( j0*su[0] ); + + // Compute loop offset increments... + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + dz1 = sz[1] - ( s0*sz[0] ); + dw1 = sw[1] - ( s0*sw[0] ); + du1 = su[1] - ( s0*su[0] ); + + // Iterate over the ndarray dimensions... + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + uset( ubuf, iu, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ), wget( wbuf, iw ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedquaternary3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/4d.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/4d.js new file mode 100644 index 000000000000..d9a523067ef0 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/4d.js @@ -0,0 +1,304 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-statements */ + +'use strict'; + +// MAIN // + +/** +* Applies a quaternary callback to elements in four-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - quaternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // 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( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = new Float64Array( 12 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 3, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 4, 2, 1 ]; +* var sy = [ 12, 4, 2, 1 ]; +* var sz = [ 12, 4, 2, 1 ]; +* var sw = [ 12, 4, 2, 1 ]; +* var su = [ 12, 4, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* var z = { +* 'dtype': 'float64', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major' +* }; +* var w = { +* 'dtype': 'float64', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major' +* }; +* var u = { +* 'dtype': 'float64', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major' +* }; +* +* // Apply the quaternary function: +* quaternary4d( x, y, z, w, u, true, fcn ); +* +* console.log( u.data ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0 ] +*/ +function quaternary4d( x, y, z, w, u, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dy0; + var dy1; + var dy2; + var dy3; + var dz0; + var dz1; + var dz2; + var dz3; + var dw0; + var dw1; + var dw2; + var dw3; + var du0; + var du1; + var du2; + var du3; + var sh; + var S0; + var S1; + var S2; + var S3; + var sx; + var sy; + var sz; + var sw; + var su; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + var i2; + var i3; + + // Note on variable naming convention: S#, dx#, dy#, dz#, dw#, du#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = x.shape; + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + su = u.strides; + 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 ]; + dx0 = sx[ 3 ]; // offset increment for innermost loop + dx1 = sx[ 2 ] - ( S0*sx[3] ); + dx2 = sx[ 1 ] - ( S1*sx[2] ); + dx3 = sx[ 0 ] - ( S2*sx[1] ); // offset increment for outermost loop + dy0 = sy[ 3 ]; + dy1 = sy[ 2 ] - ( S0*sy[3] ); + dy2 = sy[ 1 ] - ( S1*sy[2] ); + dy3 = sy[ 0 ] - ( S2*sy[1] ); + dz0 = sz[ 3 ]; + dz1 = sz[ 2 ] - ( S0*sz[3] ); + dz2 = sz[ 1 ] - ( S1*sz[2] ); + dz3 = sz[ 0 ] - ( S2*sz[1] ); + dw0 = sw[ 3 ]; + dw1 = sw[ 2 ] - ( S0*sw[3] ); + dw2 = sw[ 1 ] - ( S1*sw[2] ); + dw3 = sw[ 0 ] - ( S2*sw[1] ); + du0 = su[ 3 ]; + du1 = su[ 2 ] - ( S0*su[3] ); + du2 = su[ 1 ] - ( S1*su[2] ); + du3 = su[ 0 ] - ( S2*su[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 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); // offset increment for outermost loop + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dz0 = sz[ 0 ]; + dz1 = sz[ 1 ] - ( S0*sz[0] ); + dz2 = sz[ 2 ] - ( S1*sz[1] ); + dz3 = sz[ 3 ] - ( S2*sz[2] ); + dw0 = sw[ 0 ]; + dw1 = sw[ 1 ] - ( S0*sw[0] ); + dw2 = sw[ 2 ] - ( S1*sw[1] ); + dw3 = sw[ 3 ] - ( S2*sw[2] ); + du0 = su[ 0 ]; + du1 = su[ 1 ] - ( S0*su[0] ); + du2 = su[ 2 ] - ( S1*su[1] ); + du3 = su[ 3 ] - ( S2*su[2] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + iu = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Iterate over the 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++ ) { + ubuf[ iu ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ], wbuf[ iw ] ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } +} + + +// EXPORTS // + +module.exports = quaternary4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/4d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/4d_accessors.js new file mode 100644 index 000000000000..71b1a509f128 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/4d_accessors.js @@ -0,0 +1,328 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-statements */ + +'use strict'; + +// MAIN // + +/** +* Applies a quaternary callback to elements in four-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} z.accessors - data buffer accessors +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} w.accessors - data buffer accessors +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} u.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - quaternary callback +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var copy = require( '@stdlib/array/base/copy' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = toAccessorArray( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = toAccessorArray( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = toAccessorArray( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 4, 2, 1 ]; +* var sy = [ 8, 4, 2, 1 ]; +* var sz = [ 8, 4, 2, 1 ]; +* var sw = [ 8, 4, 2, 1 ]; +* var su = [ 8, 4, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* var y = { +* 'dtype': 'generic', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* var z = { +* 'dtype': 'generic', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major', +* 'accessors': accessors( zbuf ).accessors +* }; +* var w = { +* 'dtype': 'generic', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major', +* 'accessors': accessors( wbuf ).accessors +* }; +* var u = { +* 'dtype': 'generic', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major', +* 'accessors': accessors( ubuf ).accessors +* }; +* +* // Apply the quaternary function: +* quaternary4d( x, y, z, w, u, true, fcn ); +* +* console.log( copy( u.data ) ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] +*/ +function quaternary4d( x, y, z, w, u, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var xget; + var yget; + var zget; + var wget; + var uset; + var dx0; + var dx1; + var dx2; + var dx3; + var dy0; + var dy1; + var dy2; + var dy3; + var dz0; + var dz1; + var dz2; + var dz3; + var dw0; + var dw1; + var dw2; + var dw3; + var du0; + var du1; + var du2; + var du3; + var sh; + var S0; + var S1; + var S2; + var S3; + var sx; + var sy; + var sz; + var sw; + var su; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + var i2; + var i3; + + // Note on variable naming convention: S#, dx#, dy#, dz#, dw#, du#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = x.shape; + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + su = u.strides; + 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 ]; + dx0 = sx[ 3 ]; // offset increment for innermost loop + dx1 = sx[ 2 ] - ( S0*sx[3] ); + dx2 = sx[ 1 ] - ( S1*sx[2] ); + dx3 = sx[ 0 ] - ( S2*sx[1] ); // offset increment for outermost loop + dy0 = sy[ 3 ]; + dy1 = sy[ 2 ] - ( S0*sy[3] ); + dy2 = sy[ 1 ] - ( S1*sy[2] ); + dy3 = sy[ 0 ] - ( S2*sy[1] ); + dz0 = sz[ 3 ]; + dz1 = sz[ 2 ] - ( S0*sz[3] ); + dz2 = sz[ 1 ] - ( S1*sz[2] ); + dz3 = sz[ 0 ] - ( S2*sz[1] ); + dw0 = sw[ 3 ]; + dw1 = sw[ 2 ] - ( S0*sw[3] ); + dw2 = sw[ 1 ] - ( S1*sw[2] ); + dw3 = sw[ 0 ] - ( S2*sw[1] ); + du0 = su[ 3 ]; + du1 = su[ 2 ] - ( S0*su[3] ); + du2 = su[ 1 ] - ( S1*su[2] ); + du3 = su[ 0 ] - ( S2*su[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 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); // offset increment for outermost loop + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dz0 = sz[ 0 ]; + dz1 = sz[ 1 ] - ( S0*sz[0] ); + dz2 = sz[ 2 ] - ( S1*sz[1] ); + dz3 = sz[ 3 ] - ( S2*sz[2] ); + dw0 = sw[ 0 ]; + dw1 = sw[ 1 ] - ( S0*sw[0] ); + dw2 = sw[ 2 ] - ( S1*sw[1] ); + dw3 = sw[ 3 ] - ( S2*sw[2] ); + du0 = su[ 0 ]; + du1 = su[ 1 ] - ( S0*su[0] ); + du2 = su[ 2 ] - ( S1*su[1] ); + du3 = su[ 3 ] - ( S2*su[2] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + iu = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache accessors: + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = z.accessors[ 0 ]; + wget = w.accessors[ 0 ]; + uset = u.accessors[ 1 ]; + + // Iterate over the 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++ ) { + uset( ubuf, iu, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ), wget( wbuf, iw ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } +} + + +// EXPORTS // + +module.exports = quaternary4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/4d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/4d_blocked.js new file mode 100644 index 000000000000..cab28fb08836 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/4d_blocked.js @@ -0,0 +1,369 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-depth, max-statements */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/quaternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/quaternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a quaternary callback to elements in four-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Callback} fcn - quaternary callback +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // 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( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = new Float64Array( 12 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 2, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 6, 2, 2, 1 ]; +* var sy = [ 6, 2, 2, 1 ]; +* var sz = [ 6, 2, 2, 1 ]; +* var sw = [ 6, 2, 2, 1 ]; +* var su = [ 6, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* var z = { +* 'dtype': 'float64', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major' +* }; +* var w = { +* 'dtype': 'float64', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major' +* }; +* var u = { +* 'dtype': 'float64', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major' +* }; +* +* // Apply the quaternary function: +* blockedquaternary4d( x, y, z, w, u, fcn ); +* +* console.log( u.data ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0 ] +*/ +function blockedquaternary4d( x, y, z, w, u, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dy0; + var dy1; + var dy2; + var dy3; + var dz0; + var dz1; + var dz2; + var dz3; + var dw0; + var dw1; + var dw2; + var dw3; + var du0; + var du1; + var du2; + var du3; + var ox1; + var ox2; + var ox3; + var oy1; + var oy2; + var oy3; + var oz1; + var oz2; + var oz3; + var ow1; + var ow2; + var ow3; + var ou1; + var ou2; + var ou3; + var sh; + var s0; + var s1; + var s2; + var s3; + var sx; + var sy; + var sz; + var sw; + var su; + var ox; + var oy; + var oz; + var ow; + var ou; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + var i2; + var i3; + var j0; + var j1; + var j2; + var j3; + var o; + + // Note on variable naming convention: s#, dx#, dy#, dz#, dw#, du#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( x.shape, x.strides, y.strides, z.strides, w.strides, u.strides ); // eslint-disable-line max-len + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + su = o.su; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.dtype, u.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ox = x.offset; + oy = y.offset; + oz = z.offset; + ow = w.offset; + ou = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + du0 = su[0]; + + // Iterate over blocks... + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + ox3 = ox + ( j3*sx[3] ); + oy3 = oy + ( j3*sy[3] ); + oz3 = oz + ( j3*sz[3] ); + ow3 = ow + ( j3*sw[3] ); + ou3 = ou + ( j3*su[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + du3 = su[3] - ( s2*su[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + ou2 = ou3 + ( j2*su[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + du2 = su[2] - ( s1*su[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[1] ); + ou1 = ou2 + ( j1*su[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets for the first input and output ndarray elements in the current block... + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + iz = oz1 + ( j0*sz[0] ); + iw = ow1 + ( j0*sw[0] ); + iu = ou1 + ( j0*su[0] ); + + // Compute loop offset increments... + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + dz1 = sz[1] - ( s0*sz[0] ); + dw1 = sw[1] - ( s0*sw[0] ); + du1 = su[1] - ( s0*su[0] ); + + // Iterate over the 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++ ) { + ubuf[ iu ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ], wbuf[ iw ] ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedquaternary4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/4d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/4d_blocked_accessors.js new file mode 100644 index 000000000000..19b11cafb684 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/4d_blocked_accessors.js @@ -0,0 +1,393 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-depth, max-statements */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/quaternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/quaternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a quaternary callback to elements in four-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} z.accessors - data buffer accessors +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} w.accessors - data buffer accessors +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} u.accessors - data buffer accessors +* @param {Callback} fcn - quaternary callback +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var copy = require( '@stdlib/array/base/copy' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( [ 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( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = toAccessorArray( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = toAccessorArray( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = toAccessorArray( [ 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 shape of the input and output arrays: +* var shape = [ 2, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 6, 2, 2, 1 ]; +* var sy = [ 6, 2, 2, 1 ]; +* var sz = [ 6, 2, 2, 1 ]; +* var sw = [ 6, 2, 2, 1 ]; +* var su = [ 6, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* var y = { +* 'dtype': 'generic', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* var z = { +* 'dtype': 'generic', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major', +* 'accessors': accessors( zbuf ).accessors +* }; +* var w = { +* 'dtype': 'generic', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major', +* 'accessors': accessors( wbuf ).accessors +* }; +* var u = { +* 'dtype': 'generic', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major', +* 'accessors': accessors( ubuf ).accessors +* }; +* +* // Apply the quaternary function: +* blockedquaternary4d( x, y, z, w, u, fcn ); +* +* console.log( copy( u.data ) ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0 ] +*/ +function blockedquaternary4d( x, y, z, w, u, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var xget; + var yget; + var zget; + var wget; + var uset; + var dx0; + var dx1; + var dx2; + var dx3; + var dy0; + var dy1; + var dy2; + var dy3; + var dz0; + var dz1; + var dz2; + var dz3; + var dw0; + var dw1; + var dw2; + var dw3; + var du0; + var du1; + var du2; + var du3; + var ox1; + var ox2; + var ox3; + var oy1; + var oy2; + var oy3; + var oz1; + var oz2; + var oz3; + var ow1; + var ow2; + var ow3; + var ou1; + var ou2; + var ou3; + var sh; + var s0; + var s1; + var s2; + var s3; + var sx; + var sy; + var sz; + var sw; + var su; + var ox; + var oy; + var oz; + var ow; + var ou; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + var i2; + var i3; + var j0; + var j1; + var j2; + var j3; + var o; + + // Note on variable naming convention: s#, dx#, dy#, dz#, dw#, du#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( x.shape, x.strides, y.strides, z.strides, w.strides, u.strides ); // eslint-disable-line max-len + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + su = o.su; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.dtype, u.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ox = x.offset; + oy = y.offset; + oz = z.offset; + ow = w.offset; + ou = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + du0 = su[0]; + + // Cache accessors: + xget = x.accessors[0]; + yget = y.accessors[0]; + zget = z.accessors[0]; + wget = w.accessors[0]; + uset = u.accessors[1]; + + // Iterate over blocks... + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + ox3 = ox + ( j3*sx[3] ); + oy3 = oy + ( j3*sy[3] ); + oz3 = oz + ( j3*sz[3] ); + ow3 = ow + ( j3*sw[3] ); + ou3 = ou + ( j3*su[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + du3 = su[3] - ( s2*su[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + ou2 = ou3 + ( j2*su[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + du2 = su[2] - ( s1*su[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[1] ); + ou1 = ou2 + ( j1*su[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets for the first input and output ndarray elements in the current block... + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + iz = oz1 + ( j0*sz[0] ); + iw = ow1 + ( j0*sw[0] ); + iu = ou1 + ( j0*su[0] ); + + // Compute loop offset increments... + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + dz1 = sz[1] - ( s0*sz[0] ); + dw1 = sw[1] - ( s0*sw[0] ); + du1 = su[1] - ( s0*su[0] ); + + // Iterate over the 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++ ) { + uset( ubuf, iu, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ), wget( wbuf, iw ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedquaternary4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/5d.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/5d.js new file mode 100644 index 000000000000..983cf598aeb5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/5d.js @@ -0,0 +1,330 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-statements */ + +'use strict'; + +// MAIN // + +/** +* Applies a quaternary callback to elements in five-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - quaternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = new Float64Array( 8 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 8, 4, 2, 1 ]; +* var sy = [ 8, 8, 4, 2, 1 ]; +* var sz = [ 8, 8, 4, 2, 1 ]; +* var sw = [ 8, 8, 4, 2, 1 ]; +* var su = [ 8, 8, 4, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* var z = { +* 'dtype': 'float64', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major' +* }; +* var w = { +* 'dtype': 'float64', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major' +* }; +* var u = { +* 'dtype': 'float64', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major' +* }; +* +* // Apply the quaternary function: +* quaternary5d( x, y, z, w, u, true, fcn ); +* +* console.log( u.data ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] +*/ +function quaternary5d( x, y, z, w, u, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var du0; + var du1; + var du2; + var du3; + var du4; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var sx; + var sy; + var sz; + var sw; + var su; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + var i2; + var i3; + var i4; + + // Note on variable naming convention: S#, dx#, dy#, dz#, dw#, du#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = x.shape; + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + su = u.strides; + 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 ]; + dx0 = sx[ 4 ]; // offset increment for innermost loop + dx1 = sx[ 3 ] - ( S0*sx[4] ); + dx2 = sx[ 2 ] - ( S1*sx[3] ); + dx3 = sx[ 1 ] - ( S2*sx[2] ); + dx4 = sx[ 0 ] - ( S3*sx[1] ); // offset increment for outermost loop + dy0 = sy[ 4 ]; + dy1 = sy[ 3 ] - ( S0*sy[4] ); + dy2 = sy[ 2 ] - ( S1*sy[3] ); + dy3 = sy[ 1 ] - ( S2*sy[2] ); + dy4 = sy[ 0 ] - ( S3*sy[1] ); + dz0 = sz[ 4 ]; + dz1 = sz[ 3 ] - ( S0*sz[4] ); + dz2 = sz[ 2 ] - ( S1*sz[3] ); + dz3 = sz[ 1 ] - ( S2*sz[2] ); + dz4 = sz[ 0 ] - ( S3*sz[1] ); + dw0 = sw[ 4 ]; + dw1 = sw[ 3 ] - ( S0*sw[4] ); + dw2 = sw[ 2 ] - ( S1*sw[3] ); + dw3 = sw[ 1 ] - ( S2*sw[2] ); + dw4 = sw[ 0 ] - ( S3*sw[1] ); + du0 = su[ 4 ]; + du1 = su[ 3 ] - ( S0*su[4] ); + du2 = su[ 2 ] - ( S1*su[3] ); + du3 = su[ 1 ] - ( S2*su[2] ); + du4 = su[ 0 ] - ( S3*su[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 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); // offset increment for outermost loop + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dy4 = sy[ 4 ] - ( S3*sy[3] ); + dz0 = sz[ 0 ]; + dz1 = sz[ 1 ] - ( S0*sz[0] ); + dz2 = sz[ 2 ] - ( S1*sz[1] ); + dz3 = sz[ 3 ] - ( S2*sz[2] ); + dz4 = sz[ 4 ] - ( S3*sz[3] ); + dw0 = sw[ 0 ]; + dw1 = sw[ 1 ] - ( S0*sw[0] ); + dw2 = sw[ 2 ] - ( S1*sw[1] ); + dw3 = sw[ 3 ] - ( S2*sw[2] ); + dw4 = sw[ 4 ] - ( S3*sw[3] ); + du0 = su[ 0 ]; + du1 = su[ 1 ] - ( S0*su[0] ); + du2 = su[ 2 ] - ( S1*su[1] ); + du3 = su[ 3 ] - ( S2*su[2] ); + du4 = su[ 4 ] - ( S3*su[3] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + iu = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Iterate over the 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++ ) { + ubuf[ iu ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ], wbuf[ iw ] ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + iu += du4; + } +} + + +// EXPORTS // + +module.exports = quaternary5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/5d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/5d_accessors.js new file mode 100644 index 000000000000..395ebdbdc4e6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/5d_accessors.js @@ -0,0 +1,354 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-statements */ + +'use strict'; + +// MAIN // + +/** +* Applies a quaternary callback to elements in five-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} z.accessors - data buffer accessors +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} w.accessors - data buffer accessors +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} u.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - quaternary callback +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var copy = require( '@stdlib/array/base/copy' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = toAccessorArray( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = toAccessorArray( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = toAccessorArray( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 8, 4, 2, 1 ]; +* var sy = [ 8, 8, 4, 2, 1 ]; +* var sz = [ 8, 8, 4, 2, 1 ]; +* var sw = [ 8, 8, 4, 2, 1 ]; +* var su = [ 8, 8, 4, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* var y = { +* 'dtype': 'generic', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* var z = { +* 'dtype': 'generic', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major', +* 'accessors': accessors( zbuf ).accessors +* }; +* var w = { +* 'dtype': 'generic', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major', +* 'accessors': accessors( wbuf ).accessors +* }; +* var u = { +* 'dtype': 'generic', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major', +* 'accessors': accessors( ubuf ).accessors +* }; +* +* // Apply the quaternary function: +* quaternary5d( x, y, z, w, u, true, fcn ); +* +* console.log( copy( u.data ) ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] +*/ +function quaternary5d( x, y, z, w, u, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var xget; + var yget; + var zget; + var wget; + var uset; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var du0; + var du1; + var du2; + var du3; + var du4; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var sx; + var sy; + var sz; + var sw; + var su; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + var i2; + var i3; + var i4; + + // Note on variable naming convention: S#, dx#, dy#, dz#, dw#, du#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = x.shape; + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + su = u.strides; + 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 ]; + dx0 = sx[ 4 ]; // offset increment for innermost loop + dx1 = sx[ 3 ] - ( S0*sx[4] ); + dx2 = sx[ 2 ] - ( S1*sx[3] ); + dx3 = sx[ 1 ] - ( S2*sx[2] ); + dx4 = sx[ 0 ] - ( S3*sx[1] ); // offset increment for outermost loop + dy0 = sy[ 4 ]; + dy1 = sy[ 3 ] - ( S0*sy[4] ); + dy2 = sy[ 2 ] - ( S1*sy[3] ); + dy3 = sy[ 1 ] - ( S2*sy[2] ); + dy4 = sy[ 0 ] - ( S3*sy[1] ); + dz0 = sz[ 4 ]; + dz1 = sz[ 3 ] - ( S0*sz[4] ); + dz2 = sz[ 2 ] - ( S1*sz[3] ); + dz3 = sz[ 1 ] - ( S2*sz[2] ); + dz4 = sz[ 0 ] - ( S3*sz[1] ); + dw0 = sw[ 4 ]; + dw1 = sw[ 3 ] - ( S0*sw[4] ); + dw2 = sw[ 2 ] - ( S1*sw[3] ); + dw3 = sw[ 1 ] - ( S2*sw[2] ); + dw4 = sw[ 0 ] - ( S3*sw[1] ); + du0 = su[ 4 ]; + du1 = su[ 3 ] - ( S0*su[4] ); + du2 = su[ 2 ] - ( S1*su[3] ); + du3 = su[ 1 ] - ( S2*su[2] ); + du4 = su[ 0 ] - ( S3*su[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 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); // offset increment for outermost loop + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dy4 = sy[ 4 ] - ( S3*sy[3] ); + dz0 = sz[ 0 ]; + dz1 = sz[ 1 ] - ( S0*sz[0] ); + dz2 = sz[ 2 ] - ( S1*sz[1] ); + dz3 = sz[ 3 ] - ( S2*sz[2] ); + dz4 = sz[ 4 ] - ( S3*sz[3] ); + dw0 = sw[ 0 ]; + dw1 = sw[ 1 ] - ( S0*sw[0] ); + dw2 = sw[ 2 ] - ( S1*sw[1] ); + dw3 = sw[ 3 ] - ( S2*sw[2] ); + dw4 = sw[ 4 ] - ( S3*sw[3] ); + du0 = su[ 0 ]; + du1 = su[ 1 ] - ( S0*su[0] ); + du2 = su[ 2 ] - ( S1*su[1] ); + du3 = su[ 3 ] - ( S2*su[2] ); + du4 = su[ 4 ] - ( S3*su[3] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + iu = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache accessors: + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = z.accessors[ 0 ]; + wget = w.accessors[ 0 ]; + uset = u.accessors[ 1 ]; + + // Iterate over the 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++ ) { + uset( ubuf, iu, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ), wget( wbuf, iw ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + iu += du4; + } +} + + +// EXPORTS // + +module.exports = quaternary5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/5d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/5d_blocked.js new file mode 100644 index 000000000000..567fced55e9a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/5d_blocked.js @@ -0,0 +1,408 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-depth, max-statements, max-lines-per-function */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/quaternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/quaternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a quaternary callback to elements in five-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Callback} fcn - quaternary callback +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // 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( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = new Float64Array( 12 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 2, 3, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 6, 2, 1 ]; +* var sy = [ 12, 12, 6, 2, 1 ]; +* var sz = [ 12, 12, 6, 2, 1 ]; +* var sw = [ 12, 12, 6, 2, 1 ]; +* var su = [ 12, 12, 6, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* var z = { +* 'dtype': 'float64', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major' +* }; +* var w = { +* 'dtype': 'float64', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major' +* }; +* var u = { +* 'dtype': 'float64', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major' +* }; +* +* // Apply the quaternary function: +* blockedquaternary5d( x, y, z, w, u, fcn ); +* +* console.log( u.data ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0 ] +*/ +function blockedquaternary5d( x, y, z, w, u, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var du0; + var du1; + var du2; + var du3; + var du4; + var ox1; + var ox2; + var ox3; + var ox4; + var oy1; + var oy2; + var oy3; + var oy4; + var oz1; + var oz2; + var oz3; + var oz4; + var ow1; + var ow2; + var ow3; + var ow4; + var ou1; + var ou2; + var ou3; + var ou4; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var sx; + var sy; + var sz; + var sw; + var su; + var ox; + var oy; + var oz; + var ow; + var ou; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + var i2; + var i3; + var i4; + var j0; + var j1; + var j2; + var j3; + var j4; + var o; + + // Note on variable naming convention: s#, dx#, dy#, dz#, dw#, du#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( x.shape, x.strides, y.strides, z.strides, w.strides, u.strides ); // eslint-disable-line max-len + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + su = o.su; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.dtype, u.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ox = x.offset; + oy = y.offset; + oz = z.offset; + ow = w.offset; + ou = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + du0 = su[0]; + + // Iterate over blocks... + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + ox4 = ox + ( j4*sx[4] ); + oy4 = oy + ( j4*sy[4] ); + oz4 = oz + ( j4*sz[4] ); + ow4 = ow + ( j4*sw[4] ); + ou4 = ou + ( j4*su[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + dz4 = sz[4] - ( s3*sz[3] ); + dw4 = sw[4] - ( s3*sw[3] ); + du4 = su[4] - ( s3*su[3] ); + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oz3 = oz4 + ( j3*sz[3] ); + ow3 = ow4 + ( j3*sw[3] ); + ou3 = ou4 + ( j3*su[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + du3 = su[3] - ( s2*su[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + ou2 = ou3 + ( j2*su[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + du2 = su[2] - ( s1*su[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[1] ); + ou1 = ou2 + ( j1*su[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets for the first input and output ndarray elements in the current block... + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + iz = oz1 + ( j0*sz[0] ); + iw = ow1 + ( j0*sw[0] ); + iu = ou1 + ( j0*su[0] ); + + // Compute loop offset increments... + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + dz1 = sz[1] - ( s0*sz[0] ); + dw1 = sw[1] - ( s0*sw[0] ); + du1 = su[1] - ( s0*su[0] ); + + // Iterate over the 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++ ) { + ubuf[ iu ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ], wbuf[ iw ] ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + iu += du4; + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedquaternary5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/5d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/5d_blocked_accessors.js new file mode 100644 index 000000000000..2dd37d52de8d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/5d_blocked_accessors.js @@ -0,0 +1,432 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-depth, max-statements, max-lines-per-function */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/quaternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/quaternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a quaternary callback to elements in five-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} z.accessors - data buffer accessors +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} w.accessors - data buffer accessors +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} u.accessors - data buffer accessors +* @param {Callback} fcn - ternary callback +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var copy = require( '@stdlib/array/base/copy' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( [ 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( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = toAccessorArray( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = toAccessorArray( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = toAccessorArray( [ 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 shape of the input and output arrays: +* var shape = [ 1, 1, 2, 3, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 6, 2, 1 ]; +* var sy = [ 12, 12, 6, 2, 1 ]; +* var sz = [ 12, 12, 6, 2, 1 ]; +* var sw = [ 12, 12, 6, 2, 1 ]; +* var su = [ 12, 12, 6, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* var y = { +* 'dtype': 'generic', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* var z = { +* 'dtype': 'generic', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major', +* 'accessors': accessors( zbuf ).accessors +* }; +* var w = { +* 'dtype': 'generic', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major', +* 'accessors': accessors( wbuf ).accessors +* }; +* var u = { +* 'dtype': 'generic', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major', +* 'accessors': accessors( ubuf ).accessors +* }; +* +* // Apply the ternary function: +* blockedquaternary5d( x, y, z, w, u, fcn ); +* +* console.log( copy( u.data ) ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0 ] +*/ +function blockedquaternary5d( x, y, z, w, u, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var xget; + var yget; + var zget; + var wget; + var uset; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var du0; + var du1; + var du2; + var du3; + var du4; + var ox1; + var ox2; + var ox3; + var ox4; + var oy1; + var oy2; + var oy3; + var oy4; + var oz1; + var oz2; + var oz3; + var oz4; + var ow1; + var ow2; + var ow3; + var ow4; + var ou1; + var ou2; + var ou3; + var ou4; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var sx; + var sy; + var sz; + var sw; + var su; + var ox; + var oy; + var oz; + var ow; + var ou; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + var i2; + var i3; + var i4; + var j0; + var j1; + var j2; + var j3; + var j4; + var o; + + // Note on variable naming convention: s#, dx#, dy#, dz#, dw#,du#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( x.shape, x.strides, y.strides, z.strides, w.strides, u.strides ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + su = o.su; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.dtype, u.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ox = x.offset; + oy = y.offset; + oz = z.offset; + ow = w.offset; + ou = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + du0 = su[0]; + + // Cache accessors: + xget = x.accessors[0]; + yget = y.accessors[0]; + zget = z.accessors[0]; + wget = w.accessors[0]; + uset = u.accessors[1]; + + // Iterate over blocks... + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + ox4 = ox + ( j4*sx[4] ); + oy4 = oy + ( j4*sy[4] ); + oz4 = oz + ( j4*sz[4] ); + ow4 = ow + ( j4*sw[4] ); + ou4 = ou + ( j4*su[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + dz4 = sz[4] - ( s3*sz[3] ); + dw4 = sw[4] - ( s3*sw[3] ); + du4 = su[4] - ( s3*su[3] ); + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oz3 = oz4 + ( j3*sz[3] ); + ow3 = ow4 + ( j3*sw[3] ); + ou3 = ou4 + ( j3*su[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + du3 = su[3] - ( s2*su[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + ou2 = ou3 + ( j2*su[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + du2 = su[2] - ( s1*su[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[1] ); + ou1 = ou2 + ( j1*su[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets for the first input and output ndarray elements in the current block... + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + iz = oz1 + ( j0*sz[0] ); + iw = ow1 + ( j0*sw[0] ); + iu = ou1 + ( j0*su[0] ); + + // Compute loop offset increments... + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + dz1 = sz[1] - ( s0*sz[0] ); + dw1 = sw[1] - ( s0*sw[0] ); + du1 = su[1] - ( s0*su[0] ); + + // Iterate over the 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++ ) { + uset( ubuf, iu, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ), wget( wbuf, iw ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + iu += du4; + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedquaternary5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/6d.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/6d.js new file mode 100644 index 000000000000..dcbb9b28b539 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/6d.js @@ -0,0 +1,356 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-statements, max-depth */ + +'use strict'; + +// MAIN // + +/** +* Applies a quaternary callback to elements in six-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - quaternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = new Float64Array( 8 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 8, 8, 4, 2, 1 ]; +* var sy = [ 8, 8, 8, 4, 2, 1 ]; +* var sz = [ 8, 8, 8, 4, 2, 1 ]; +* var sw = [ 8, 8, 8, 4, 2, 1 ]; +* var su = [ 8, 8, 8, 4, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* var z = { +* 'dtype': 'float64', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major' +* }; +* var w = { +* 'dtype': 'float64', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major' +* }; +* var u = { +* 'dtype': 'float64', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major' +* }; +* +* // Apply the quaternary function: +* quaternary6d( x, y, z, w, u, true, fcn ); +* +* console.log( u.data ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] +*/ +function quaternary6d( x, y, z, w, u, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var du0; + var du1; + var du2; + var du3; + var du4; + var du5; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var sx; + var sy; + var sz; + var sw; + var su; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + + // Note on variable naming convention: S#, dx#, dy#, dz#, dw#, du#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = x.shape; + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + su = u.strides; + 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 ]; + dx0 = sx[ 5 ]; // offset increment for innermost loop + dx1 = sx[ 4 ] - ( S0*sx[5] ); + dx2 = sx[ 3 ] - ( S1*sx[4] ); + dx3 = sx[ 2 ] - ( S2*sx[3] ); + dx4 = sx[ 1 ] - ( S3*sx[2] ); + dx5 = sx[ 0 ] - ( S4*sx[1] ); // offset increment for outermost loop + dy0 = sy[ 5 ]; + dy1 = sy[ 4 ] - ( S0*sy[5] ); + dy2 = sy[ 3 ] - ( S1*sy[4] ); + dy3 = sy[ 2 ] - ( S2*sy[3] ); + dy4 = sy[ 1 ] - ( S3*sy[2] ); + dy5 = sy[ 0 ] - ( S4*sy[1] ); + dz0 = sz[ 5 ]; + dz1 = sz[ 4 ] - ( S0*sz[5] ); + dz2 = sz[ 3 ] - ( S1*sz[4] ); + dz3 = sz[ 2 ] - ( S2*sz[3] ); + dz4 = sz[ 1 ] - ( S3*sz[2] ); + dz5 = sz[ 0 ] - ( S4*sz[1] ); + dw0 = sw[ 5 ]; + dw1 = sw[ 4 ] - ( S0*sw[5] ); + dw2 = sw[ 3 ] - ( S1*sw[4] ); + dw3 = sw[ 2 ] - ( S2*sw[3] ); + dw4 = sw[ 1 ] - ( S3*sw[2] ); + dw5 = sw[ 0 ] - ( S4*sw[1] ); + du0 = su[ 5 ]; + du1 = su[ 4 ] - ( S0*su[5] ); + du2 = su[ 3 ] - ( S1*su[4] ); + du3 = su[ 2 ] - ( S2*su[3] ); + du4 = su[ 1 ] - ( S3*su[2] ); + du5 = su[ 0 ] - ( S4*su[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 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); + dx5 = sx[ 5 ] - ( S4*sx[4] ); // offset increment for outermost loop + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dy4 = sy[ 4 ] - ( S3*sy[3] ); + dy5 = sy[ 5 ] - ( S4*sy[4] ); + dz0 = sz[ 0 ]; + dz1 = sz[ 1 ] - ( S0*sz[0] ); + dz2 = sz[ 2 ] - ( S1*sz[1] ); + dz3 = sz[ 3 ] - ( S2*sz[2] ); + dz4 = sz[ 4 ] - ( S3*sz[3] ); + dz5 = sz[ 5 ] - ( S4*sz[4] ); + dw0 = sw[ 0 ]; + dw1 = sw[ 1 ] - ( S0*sw[0] ); + dw2 = sw[ 2 ] - ( S1*sw[1] ); + dw3 = sw[ 3 ] - ( S2*sw[2] ); + dw4 = sw[ 4 ] - ( S3*sw[3] ); + dw5 = sw[ 5 ] - ( S4*sw[4] ); + du0 = su[ 0 ]; + du1 = su[ 1 ] - ( S0*su[0] ); + du2 = su[ 2 ] - ( S1*su[1] ); + du3 = su[ 3 ] - ( S2*su[2] ); + du4 = su[ 4 ] - ( S3*su[3] ); + du5 = su[ 5 ] - ( S4*su[4] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + iu = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Iterate over the 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++ ) { + ubuf[ iu ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ], wbuf[ iw ] ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + iu += du4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + iu += du5; + } +} + + +// EXPORTS // + +module.exports = quaternary6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/6d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/6d_accessors.js new file mode 100644 index 000000000000..cfa8e2e9a9b9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/6d_accessors.js @@ -0,0 +1,380 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-statements, max-depth, max-lines-per-function */ + +'use strict'; + +// MAIN // + +/** +* Applies a quaternary callback to elements in six-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} z.accessors - data buffer accessors +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} w.accessors - data buffer accessors +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} u.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - quaternary callback +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var copy = require( '@stdlib/array/base/copy' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = toAccessorArray( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = toAccessorArray( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = toAccessorArray( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 8, 8, 4, 2, 1 ]; +* var sy = [ 8, 8, 8, 4, 2, 1 ]; +* var sz = [ 8, 8, 8, 4, 2, 1 ]; +* var sw = [ 8, 8, 8, 4, 2, 1 ]; +* var su = [ 8, 8, 8, 4, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* var y = { +* 'dtype': 'generic', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* var z = { +* 'dtype': 'generic', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major', +* 'accessors': accessors( zbuf ).accessors +* }; +* var w = { +* 'dtype': 'generic', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major', +* 'accessors': accessors( wbuf ).accessors +* }; +* var u = { +* 'dtype': 'generic', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major', +* 'accessors': accessors( ubuf ).accessors +* }; +* +* // Apply the quaternary function: +* quaternary6d( x, y, z, w, u, true, fcn ); +* +* console.log( copy( u.data ) ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] +*/ +function quaternary6d( x, y, z, w, u, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var xget; + var yget; + var zget; + var wget; + var uset; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var du0; + var du1; + var du2; + var du3; + var du4; + var du5; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var sx; + var sy; + var sz; + var sw; + var su; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + + // Note on variable naming convention: S#, dx#, dy#, dz#, dw#, du#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = x.shape; + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + su = u.strides; + 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 ]; + dx0 = sx[ 5 ]; // offset increment for innermost loop + dx1 = sx[ 4 ] - ( S0*sx[5] ); + dx2 = sx[ 3 ] - ( S1*sx[4] ); + dx3 = sx[ 2 ] - ( S2*sx[3] ); + dx4 = sx[ 1 ] - ( S3*sx[2] ); + dx5 = sx[ 0 ] - ( S4*sx[1] ); // offset increment for outermost loop + dy0 = sy[ 5 ]; + dy1 = sy[ 4 ] - ( S0*sy[5] ); + dy2 = sy[ 3 ] - ( S1*sy[4] ); + dy3 = sy[ 2 ] - ( S2*sy[3] ); + dy4 = sy[ 1 ] - ( S3*sy[2] ); + dy5 = sy[ 0 ] - ( S4*sy[1] ); + dz0 = sz[ 5 ]; + dz1 = sz[ 4 ] - ( S0*sz[5] ); + dz2 = sz[ 3 ] - ( S1*sz[4] ); + dz3 = sz[ 2 ] - ( S2*sz[3] ); + dz4 = sz[ 1 ] - ( S3*sz[2] ); + dz5 = sz[ 0 ] - ( S4*sz[1] ); + dw0 = sw[ 5 ]; + dw1 = sw[ 4 ] - ( S0*sw[5] ); + dw2 = sw[ 3 ] - ( S1*sw[4] ); + dw3 = sw[ 2 ] - ( S2*sw[3] ); + dw4 = sw[ 1 ] - ( S3*sw[2] ); + dw5 = sw[ 0 ] - ( S4*sw[1] ); + du0 = su[ 5 ]; + du1 = su[ 4 ] - ( S0*su[5] ); + du2 = su[ 3 ] - ( S1*su[4] ); + du3 = su[ 2 ] - ( S2*su[3] ); + du4 = su[ 1 ] - ( S3*su[2] ); + du5 = su[ 0 ] - ( S4*su[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 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); + dx5 = sx[ 5 ] - ( S4*sx[4] ); // offset increment for outermost loop + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dy4 = sy[ 4 ] - ( S3*sy[3] ); + dy5 = sy[ 5 ] - ( S4*sy[4] ); + dz0 = sz[ 0 ]; + dz1 = sz[ 1 ] - ( S0*sz[0] ); + dz2 = sz[ 2 ] - ( S1*sz[1] ); + dz3 = sz[ 3 ] - ( S2*sz[2] ); + dz4 = sz[ 4 ] - ( S3*sz[3] ); + dz5 = sz[ 5 ] - ( S4*sz[4] ); + dw0 = sw[ 0 ]; + dw1 = sw[ 1 ] - ( S0*sw[0] ); + dw2 = sw[ 2 ] - ( S1*sw[1] ); + dw3 = sw[ 3 ] - ( S2*sw[2] ); + dw4 = sw[ 4 ] - ( S3*sw[3] ); + dw5 = sw[ 5 ] - ( S4*sw[4] ); + du0 = su[ 0 ]; + du1 = su[ 1 ] - ( S0*su[0] ); + du2 = su[ 2 ] - ( S1*su[1] ); + du3 = su[ 3 ] - ( S2*su[2] ); + du4 = su[ 4 ] - ( S3*su[3] ); + du5 = su[ 5 ] - ( S4*su[4] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + iu = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache accessors: + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = z.accessors[ 0 ]; + wget = w.accessors[ 0 ]; + uset = u.accessors[ 1 ]; + + // Iterate over the 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++ ) { + uset( ubuf, iu, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ), wget( wbuf, iw ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + iu += du4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + iu += du5; + } +} + + +// EXPORTS // + +module.exports = quaternary6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/6d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/6d_blocked.js new file mode 100644 index 000000000000..3809796f0018 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/6d_blocked.js @@ -0,0 +1,447 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-depth, max-statements, max-lines-per-function */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/quaternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/quaternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a quaternary callback to elements in six-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Callback} fcn - quaternary callback +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // 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( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = new Float64Array( 12 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 2, 3, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 6, 2, 1 ]; +* var sy = [ 12, 12, 12, 6, 2, 1 ]; +* var sz = [ 12, 12, 12, 6, 2, 1 ]; +* var sw = [ 12, 12, 12, 6, 2, 1 ]; +* var su = [ 12, 12, 12, 6, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* var z = { +* 'dtype': 'float64', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major' +* }; +* var w = { +* 'dtype': 'float64', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major' +* }; +* var u = { +* 'dtype': 'float64', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major' +* }; +* +* // Apply the quaternary function: +* blockedquaternary6d( x, y, z, w, u, fcn ); +* +* console.log( u.data ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0 ] +*/ +function blockedquaternary6d( x, y, z, w, u, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var du0; + var du1; + var du2; + var du3; + var du4; + var du5; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oz1; + var oz2; + var oz3; + var oz4; + var oz5; + var ow1; + var ow2; + var ow3; + var ow4; + var ow5; + var ou1; + var ou2; + var ou3; + var ou4; + var ou5; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var sx; + var sy; + var sz; + var sw; + var su; + var ox; + var oy; + var oz; + var ow; + var ou; + var ix; + var iy; + var iz; + var iw; + var iu; + 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 o; + + // Note on variable naming convention: s#, dx#, dy#, dz#, dw#, du#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( x.shape, x.strides, y.strides, z.strides, w.strides, u.strides ); // eslint-disable-line max-len + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + su = o.su; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.dtype, u.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ox = x.offset; + oy = y.offset; + oz = z.offset; + ow = w.offset; + ou = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + du0 = su[0]; + + // Iterate over blocks... + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + ox5 = ox + ( j5*sx[5] ); + oy5 = oy + ( j5*sy[5] ); + oz5 = oz + ( j5*sz[5] ); + ow5 = ow + ( j5*sw[5] ); + ou5 = ou + ( j5*su[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + dz5 = sz[5] - ( s4*sz[4] ); + dw5 = sw[5] - ( s4*sw[4] ); + du5 = su[5] - ( s4*su[4] ); + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oz4 = oz5 + ( j4*sz[4] ); + ow4 = ow5 + ( j4*sw[4] ); + ou4 = ou5 + ( j4*su[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + dz4 = sz[4] - ( s3*sz[3] ); + dw4 = sw[4] - ( s3*sw[3] ); + du4 = su[4] - ( s3*su[3] ); + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oz3 = oz4 + ( j3*sz[3] ); + ow3 = ow4 + ( j3*sw[3] ); + ou3 = ou4 + ( j3*su[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + du3 = su[3] - ( s2*su[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + ou2 = ou3 + ( j2*su[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + du2 = su[2] - ( s1*su[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[1] ); + ou1 = ou2 + ( j1*su[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets for the first input and output ndarray elements in the current block... + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + iz = oz1 + ( j0*sz[0] ); + iw = ow1 + ( j0*sw[0] ); + iu = ou1 + ( j0*su[0] ); + + // Compute loop offset increments... + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + dz1 = sz[1] - ( s0*sz[0] ); + dw1 = sw[1] - ( s0*sw[0] ); + du1 = su[1] - ( s0*su[0] ); + + // Iterate over the 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++ ) { + ubuf[ iu ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ], wbuf[ iw ] ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + iu += du4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + iu += du5; + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedquaternary6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/6d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/6d_blocked_accessors.js new file mode 100644 index 000000000000..ac2d8ebc02dc --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/6d_blocked_accessors.js @@ -0,0 +1,471 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-depth, max-statements, max-lines-per-function */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/quaternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/quaternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a quaternary callback to elements in six-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} z.accessors - data buffer accessors +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} w.accessors - data buffer accessors +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} u.accessors - data buffer accessors +* @param {Callback} fcn - quaternary callback +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var copy = require( '@stdlib/array/base/copy' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( [ 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( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = toAccessorArray( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = toAccessorArray( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = toAccessorArray( [ 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 shape of the input and output arrays: +* var shape = [ 1, 1, 1, 2, 3, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 6, 2, 1 ]; +* var sy = [ 12, 12, 12, 6, 2, 1 ]; +* var sz = [ 12, 12, 12, 6, 2, 1 ]; +* var sw = [ 12, 12, 12, 6, 2, 1 ]; +* var su = [ 12, 12, 12, 6, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* var y = { +* 'dtype': 'generic', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* var z = { +* 'dtype': 'generic', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major', +* 'accessors': accessors( zbuf ).accessors +* }; +* var w = { +* 'dtype': 'generic', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major', +* 'accessors': accessors( wbuf ).accessors +* }; +* var u = { +* 'dtype': 'generic', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major', +* 'accessors': accessors( ubuf ).accessors +* }; +* +* // Apply the quaternary function: +* blockedquaternary6d( x, y, z, w, u, fcn ); +* +* console.log( copy( u.data ) ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0 ] +*/ +function blockedquaternary6d( x, y, z, w, u, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var xget; + var yget; + var zget; + var wget; + var uset; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var du0; + var du1; + var du2; + var du3; + var du4; + var du5; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oz1; + var oz2; + var oz3; + var oz4; + var oz5; + var ow1; + var ow2; + var ow3; + var ow4; + var ow5; + var ou1; + var ou2; + var ou3; + var ou4; + var ou5; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var sx; + var sy; + var sz; + var sw; + var su; + var ox; + var oy; + var oz; + var ow; + var ou; + var ix; + var iy; + var iz; + var iw; + var iu; + 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 o; + + // Note on variable naming convention: s#, dx#, dy#, dz#, dw#, du#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( x.shape, x.strides, y.strides, z.strides, w.strides, u.strides ); // eslint-disable-line max-len + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + su = o.su; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.dtype, u.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ox = x.offset; + oy = y.offset; + oz = z.offset; + ow = w.offset; + ou = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + du0 = su[0]; + + // Cache accessors: + xget = x.accessors[0]; + yget = y.accessors[0]; + zget = z.accessors[0]; + wget = w.accessors[0]; + uset = u.accessors[1]; + + // Iterate over blocks... + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + ox5 = ox + ( j5*sx[5] ); + oy5 = oy + ( j5*sy[5] ); + oz5 = oz + ( j5*sz[5] ); + ow5 = ow + ( j5*sw[5] ); + ou5 = ou + ( j5*su[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + dz5 = sz[5] - ( s4*sz[4] ); + dw5 = sw[5] - ( s4*sw[4] ); + du5 = su[5] - ( s4*su[4] ); + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oz4 = oz5 + ( j4*sz[4] ); + ow4 = ow5 + ( j4*sw[4] ); + ou4 = ou5 + ( j4*su[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + dz4 = sz[4] - ( s3*sz[3] ); + dw4 = sw[4] - ( s3*sw[3] ); + du4 = su[4] - ( s3*su[3] ); + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oz3 = oz4 + ( j3*sz[3] ); + ow3 = ow4 + ( j3*sw[3] ); + ou3 = ou4 + ( j3*su[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + du3 = su[3] - ( s2*su[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + ou2 = ou3 + ( j2*su[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + du2 = su[2] - ( s1*su[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[1] ); + ou1 = ou2 + ( j1*su[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets for the first input and output ndarray elements in the current block... + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + iz = oz1 + ( j0*sz[0] ); + iw = ow1 + ( j0*sw[0] ); + iu = ou1 + ( j0*su[0] ); + + // Compute loop offset increments... + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + dz1 = sz[1] - ( s0*sz[0] ); + dw1 = sw[1] - ( s0*sw[0] ); + du1 = su[1] - ( s0*su[0] ); + + // Iterate over the 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++ ) { + uset( ubuf, iu, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ), wget( wbuf, iw ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + iu += du4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + iu += du5; + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedquaternary6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/7d.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/7d.js new file mode 100644 index 000000000000..9909f377e8a0 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/7d.js @@ -0,0 +1,382 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-statements, max-depth, max-lines-per-function */ + +'use strict'; + +// MAIN // + +/** +* Applies a quaternary callback to elements in seven-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - quaternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = new Float64Array( 8 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 8, 8, 8, 4, 2, 1 ]; +* var sy = [ 8, 8, 8, 8, 4, 2, 1 ]; +* var sz = [ 8, 8, 8, 8, 4, 2, 1 ]; +* var sw = [ 8, 8, 8, 8, 4, 2, 1 ]; +* var su = [ 8, 8, 8, 8, 4, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* var z = { +* 'dtype': 'float64', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major' +* }; +* var w = { +* 'dtype': 'float64', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major' +* }; +* var u = { +* 'dtype': 'float64', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major' +* }; +* +* // Apply the quaternary function: +* quaternary7d( x, y, z, w, u, true, fcn ); +* +* console.log( u.data ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] +*/ +function quaternary7d( x, y, z, w, u, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dz6; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dw6; + var du0; + var du1; + var du2; + var du3; + var du4; + var du5; + var du6; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var sx; + var sy; + var sz; + var sw; + var su; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + + // Note on variable naming convention: S#, dx#, dy#, dz#, dw#, du#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = x.shape; + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + su = u.strides; + 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 ]; + dx0 = sx[ 6 ]; // offset increment for innermost loop + dx1 = sx[ 5 ] - ( S0*sx[6] ); + dx2 = sx[ 4 ] - ( S1*sx[5] ); + dx3 = sx[ 3 ] - ( S2*sx[4] ); + dx4 = sx[ 2 ] - ( S3*sx[3] ); + dx5 = sx[ 1 ] - ( S4*sx[2] ); + dx6 = sx[ 0 ] - ( S5*sx[1] ); // offset increment for outermost loop + dy0 = sy[ 6 ]; + dy1 = sy[ 5 ] - ( S0*sy[6] ); + dy2 = sy[ 4 ] - ( S1*sy[5] ); + dy3 = sy[ 3 ] - ( S2*sy[4] ); + dy4 = sy[ 2 ] - ( S3*sy[3] ); + dy5 = sy[ 1 ] - ( S4*sy[2] ); + dy6 = sy[ 0 ] - ( S5*sy[1] ); + dz0 = sz[ 6 ]; + dz1 = sz[ 5 ] - ( S0*sz[6] ); + dz2 = sz[ 4 ] - ( S1*sz[5] ); + dz3 = sz[ 3 ] - ( S2*sz[4] ); + dz4 = sz[ 2 ] - ( S3*sz[3] ); + dz5 = sz[ 1 ] - ( S4*sz[2] ); + dz6 = sz[ 0 ] - ( S5*sz[1] ); + dw0 = sw[ 6 ]; + dw1 = sw[ 5 ] - ( S0*sw[6] ); + dw2 = sw[ 4 ] - ( S1*sw[5] ); + dw3 = sw[ 3 ] - ( S2*sw[4] ); + dw4 = sw[ 2 ] - ( S3*sw[3] ); + dw5 = sw[ 1 ] - ( S4*sw[2] ); + dw6 = sw[ 0 ] - ( S5*sw[1] ); + du0 = su[ 6 ]; + du1 = su[ 5 ] - ( S0*su[6] ); + du2 = su[ 4 ] - ( S1*su[5] ); + du3 = su[ 3 ] - ( S2*su[4] ); + du4 = su[ 2 ] - ( S3*su[3] ); + du5 = su[ 1 ] - ( S4*su[2] ); + du6 = su[ 0 ] - ( S5*su[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 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); + dx5 = sx[ 5 ] - ( S4*sx[4] ); + dx6 = sx[ 6 ] - ( S5*sx[5] ); // offset increment for outermost loop + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dy4 = sy[ 4 ] - ( S3*sy[3] ); + dy5 = sy[ 5 ] - ( S4*sy[4] ); + dy6 = sy[ 6 ] - ( S5*sy[5] ); + dz0 = sz[ 0 ]; + dz1 = sz[ 1 ] - ( S0*sz[0] ); + dz2 = sz[ 2 ] - ( S1*sz[1] ); + dz3 = sz[ 3 ] - ( S2*sz[2] ); + dz4 = sz[ 4 ] - ( S3*sz[3] ); + dz5 = sz[ 5 ] - ( S4*sz[4] ); + dz6 = sz[ 6 ] - ( S5*sz[5] ); + dw0 = sw[ 0 ]; + dw1 = sw[ 1 ] - ( S0*sw[0] ); + dw2 = sw[ 2 ] - ( S1*sw[1] ); + dw3 = sw[ 3 ] - ( S2*sw[2] ); + dw4 = sw[ 4 ] - ( S3*sw[3] ); + dw5 = sw[ 5 ] - ( S4*sw[4] ); + dw6 = sw[ 6 ] - ( S5*sw[5] ); + du0 = su[ 0 ]; + du1 = su[ 1 ] - ( S0*su[0] ); + du2 = su[ 2 ] - ( S1*su[1] ); + du3 = su[ 3 ] - ( S2*su[2] ); + du4 = su[ 4 ] - ( S3*su[3] ); + du5 = su[ 5 ] - ( S4*su[4] ); + du6 = su[ 6 ] - ( S5*su[5] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + iu = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Iterate over the 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++ ) { + ubuf[ iu ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ], wbuf[ iw ] ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + iu += du4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + iu += du5; + } + ix += dx6; + iy += dy6; + iz += dz6; + iw += dw6; + iu += du6; + } +} + + +// EXPORTS // + +module.exports = quaternary7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/7d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/7d_accessors.js new file mode 100644 index 000000000000..26d4151f8987 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/7d_accessors.js @@ -0,0 +1,406 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-statements, max-depth, max-lines-per-function */ + +'use strict'; + +// MAIN // + +/** +* Applies a quaternary callback to elements in seven-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} z.accessors - data buffer accessors +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} w.accessors - data buffer accessors +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} u.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - quaternary callback +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var copy = require( '@stdlib/array/base/copy' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = toAccessorArray( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = toAccessorArray( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = toAccessorArray( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 8, 8, 8, 4, 2, 1 ]; +* var sy = [ 8, 8, 8, 8, 4, 2, 1 ]; +* var sz = [ 8, 8, 8, 8, 4, 2, 1 ]; +* var sw = [ 8, 8, 8, 8, 4, 2, 1 ]; +* var su = [ 8, 8, 8, 8, 4, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* var y = { +* 'dtype': 'generic', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* var z = { +* 'dtype': 'generic', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major', +* 'accessors': accessors( zbuf ).accessors +* }; +* var w = { +* 'dtype': 'generic', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major', +* 'accessors': accessors( wbuf ).accessors +* }; +* var u = { +* 'dtype': 'generic', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major', +* 'accessors': accessors( ubuf ).accessors +* }; +* +* // Apply the quaternary function: +* quaternary7d( x, y, z, w, u, true, fcn ); +* +* console.log( copy( u.data ) ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] +*/ +function quaternary7d( x, y, z, w, u, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var xget; + var yget; + var zget; + var wget; + var uset; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dz6; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dw6; + var du0; + var du1; + var du2; + var du3; + var du4; + var du5; + var du6; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var sx; + var sy; + var sz; + var sw; + var su; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + + // Note on variable naming convention: S#, dx#, dy#, dz#, dw#, du#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = x.shape; + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + su = u.strides; + 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 ]; + dx0 = sx[ 6 ]; // offset increment for innermost loop + dx1 = sx[ 5 ] - ( S0*sx[6] ); + dx2 = sx[ 4 ] - ( S1*sx[5] ); + dx3 = sx[ 3 ] - ( S2*sx[4] ); + dx4 = sx[ 2 ] - ( S3*sx[3] ); + dx5 = sx[ 1 ] - ( S4*sx[2] ); + dx6 = sx[ 0 ] - ( S5*sx[1] ); // offset increment for outermost loop + dy0 = sy[ 6 ]; + dy1 = sy[ 5 ] - ( S0*sy[6] ); + dy2 = sy[ 4 ] - ( S1*sy[5] ); + dy3 = sy[ 3 ] - ( S2*sy[4] ); + dy4 = sy[ 2 ] - ( S3*sy[3] ); + dy5 = sy[ 1 ] - ( S4*sy[2] ); + dy6 = sy[ 0 ] - ( S5*sy[1] ); + dz0 = sz[ 6 ]; + dz1 = sz[ 5 ] - ( S0*sz[6] ); + dz2 = sz[ 4 ] - ( S1*sz[5] ); + dz3 = sz[ 3 ] - ( S2*sz[4] ); + dz4 = sz[ 2 ] - ( S3*sz[3] ); + dz5 = sz[ 1 ] - ( S4*sz[2] ); + dz6 = sz[ 0 ] - ( S5*sz[1] ); + dw0 = sw[ 6 ]; + dw1 = sw[ 5 ] - ( S0*sw[6] ); + dw2 = sw[ 4 ] - ( S1*sw[5] ); + dw3 = sw[ 3 ] - ( S2*sw[4] ); + dw4 = sw[ 2 ] - ( S3*sw[3] ); + dw5 = sw[ 1 ] - ( S4*sw[2] ); + dw6 = sw[ 0 ] - ( S5*sw[1] ); + du0 = su[ 6 ]; + du1 = su[ 5 ] - ( S0*su[6] ); + du2 = su[ 4 ] - ( S1*su[5] ); + du3 = su[ 3 ] - ( S2*su[4] ); + du4 = su[ 2 ] - ( S3*su[3] ); + du5 = su[ 1 ] - ( S4*su[2] ); + du6 = su[ 0 ] - ( S5*su[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 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); + dx5 = sx[ 5 ] - ( S4*sx[4] ); + dx6 = sx[ 6 ] - ( S5*sx[5] ); // offset increment for outermost loop + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dy4 = sy[ 4 ] - ( S3*sy[3] ); + dy5 = sy[ 5 ] - ( S4*sy[4] ); + dy6 = sy[ 6 ] - ( S5*sy[5] ); + dz0 = sz[ 0 ]; + dz1 = sz[ 1 ] - ( S0*sz[0] ); + dz2 = sz[ 2 ] - ( S1*sz[1] ); + dz3 = sz[ 3 ] - ( S2*sz[2] ); + dz4 = sz[ 4 ] - ( S3*sz[3] ); + dz5 = sz[ 5 ] - ( S4*sz[4] ); + dz6 = sz[ 6 ] - ( S5*sz[5] ); + dw0 = sw[ 0 ]; + dw1 = sw[ 1 ] - ( S0*sw[0] ); + dw2 = sw[ 2 ] - ( S1*sw[1] ); + dw3 = sw[ 3 ] - ( S2*sw[2] ); + dw4 = sw[ 4 ] - ( S3*sw[3] ); + dw5 = sw[ 5 ] - ( S4*sw[4] ); + dw6 = sw[ 6 ] - ( S5*sw[5] ); + du0 = su[ 0 ]; + du1 = su[ 1 ] - ( S0*su[0] ); + du2 = su[ 2 ] - ( S1*su[1] ); + du3 = su[ 3 ] - ( S2*su[2] ); + du4 = su[ 4 ] - ( S3*su[3] ); + du5 = su[ 5 ] - ( S4*su[4] ); + du6 = su[ 6 ] - ( S5*su[5] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + iu = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache accessors: + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = z.accessors[ 0 ]; + wget = w.accessors[ 0 ]; + uset = u.accessors[ 1 ]; + + // Iterate over the 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++ ) { + uset( ubuf, iu, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ), wget( wbuf, iw ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + iu += du4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + iu += du5; + } + ix += dx6; + iy += dy6; + iz += dz6; + iw += dw6; + iu += du6; + } +} + + +// EXPORTS // + +module.exports = quaternary7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/7d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/7d_blocked.js new file mode 100644 index 000000000000..9760e12816f4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/7d_blocked.js @@ -0,0 +1,486 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-depth, max-statements, max-lines-per-function, max-len */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/quaternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/quaternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a quaternary callback to elements in seven-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Callback} fcn - quaternary callback +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // 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( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = new Float64Array( 12 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 2, 3, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 6, 2, 1 ]; +* var sy = [ 12, 12, 12, 12, 6, 2, 1 ]; +* var sz = [ 12, 12, 12, 12, 6, 2, 1 ]; +* var sw = [ 12, 12, 12, 12, 6, 2, 1 ]; +* var su = [ 12, 12, 12, 12, 6, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* var z = { +* 'dtype': 'float64', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major' +* }; +* var w = { +* 'dtype': 'float64', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major' +* }; +* var u = { +* 'dtype': 'float64', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major' +* }; +* +* // Apply the quaternary function: +* blockedquaternary7d( x, y, z, w, u, fcn ); +* +* console.log( u.data ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0 ] +*/ +function blockedquaternary7d( x, y, z, w, u, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dz6; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dw6; + var du0; + var du1; + var du2; + var du3; + var du4; + var du5; + var du6; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var ox6; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oy6; + var oz1; + var oz2; + var oz3; + var oz4; + var oz5; + var oz6; + var ow1; + var ow2; + var ow3; + var ow4; + var ow5; + var ow6; + var ou1; + var ou2; + var ou3; + var ou4; + var ou5; + var ou6; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var sx; + var sy; + var sz; + var sw; + var su; + var ox; + var oy; + var oz; + var ow; + var ou; + var ix; + var iy; + var iz; + var iw; + var iu; + 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 o; + + // Note on variable naming convention: s#, dx#, dy#, dz#, dw#, du#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( x.shape, x.strides, y.strides, z.strides, w.strides, u.strides ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + su = o.su; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.dtype, u.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ox = x.offset; + oy = y.offset; + oz = z.offset; + ow = w.offset; + ou = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + du0 = su[0]; + + // Iterate over blocks... + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + ox6 = ox + ( j6*sx[6] ); + oy6 = oy + ( j6*sy[6] ); + oz6 = oz + ( j6*sz[6] ); + ow6 = ow + ( j6*sw[6] ); + ou6 = ou + ( j6*su[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dx6 = sx[6] - ( s5*sx[5] ); + dy6 = sy[6] - ( s5*sy[5] ); + dz6 = sz[6] - ( s5*sz[5] ); + dw6 = sw[6] - ( s5*sw[5] ); + du6 = su[6] - ( s5*su[5] ); + ox5 = ox6 + ( j5*sx[5] ); + oy5 = oy6 + ( j5*sy[5] ); + oz5 = oz6 + ( j5*sz[5] ); + ow5 = ow6 + ( j5*sw[5] ); + ou5 = ou6 + ( j5*su[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + dz5 = sz[5] - ( s4*sz[4] ); + dw5 = sw[5] - ( s4*sw[4] ); + du5 = su[5] - ( s4*su[4] ); + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oz4 = oz5 + ( j4*sz[4] ); + ow4 = ow5 + ( j4*sw[4] ); + ou4 = ou5 + ( j4*su[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + dz4 = sz[4] - ( s3*sz[3] ); + dw4 = sw[4] - ( s3*sw[3] ); + du4 = su[4] - ( s3*su[3] ); + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oz3 = oz4 + ( j3*sz[3] ); + ow3 = ow4 + ( j3*sw[3] ); + ou3 = ou4 + ( j3*su[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + du3 = su[3] - ( s2*su[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + ou2 = ou3 + ( j2*su[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + du2 = su[2] - ( s1*su[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[1] ); + ou1 = ou2 + ( j1*su[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets for the first input and output ndarray elements in the current block... + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + iz = oz1 + ( j0*sz[0] ); + iw = ow1 + ( j0*sw[0] ); + iu = ou1 + ( j0*su[0] ); + + // Compute loop offset increments... + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + dz1 = sz[1] - ( s0*sz[0] ); + dw1 = sw[1] - ( s0*sw[0] ); + du1 = su[1] - ( s0*su[0] ); + + // Iterate over the 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++ ) { + ubuf[ iu ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ], wbuf[ iw ] ); + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + iu += du4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + iu += du5; + } + ix += dx6; + iy += dy6; + iz += dz6; + iw += dw6; + iu += du6; + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedquaternary7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/7d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/7d_blocked_accessors.js new file mode 100644 index 000000000000..9cc1ea383250 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/7d_blocked_accessors.js @@ -0,0 +1,510 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-depth, max-statements, max-lines-per-function, max-len */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/quaternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/quaternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a quaternary callback to elements in seven-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} z.accessors - data buffer accessors +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} w.accessors - data buffer accessors +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} u.accessors - data buffer accessors +* @param {Callback} fcn - quaternary callback +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var copy = require( '@stdlib/array/base/copy' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( [ 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( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = toAccessorArray( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = toAccessorArray( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = toAccessorArray( [ 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 shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 2, 3, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 6, 2, 1 ]; +* var sy = [ 12, 12, 12, 12, 6, 2, 1 ]; +* var sz = [ 12, 12, 12, 12, 6, 2, 1 ]; +* var sw = [ 12, 12, 12, 12, 6, 2, 1 ]; +* var su = [ 12, 12, 12, 12, 6, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* var y = { +* 'dtype': 'generic', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* var z = { +* 'dtype': 'generic', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major', +* 'accessors': accessors( zbuf ).accessors +* }; +* var w = { +* 'dtype': 'generic', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major', +* 'accessors': accessors( wbuf ).accessors +* }; +* var u = { +* 'dtype': 'generic', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major', +* 'accessors': accessors( ubuf ).accessors +* }; +* +* // Apply the quaternary function: +* blockedquaternary7d( x, y, z, w, u, fcn ); +* +* console.log( copy( u.data ) ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0 ] +*/ +function blockedquaternary7d( x, y, z, w, u, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var xget; + var yget; + var zget; + var wget; + var uset; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dz6; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dw6; + var du0; + var du1; + var du2; + var du3; + var du4; + var du5; + var du6; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var ox6; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oy6; + var oz1; + var oz2; + var oz3; + var oz4; + var oz5; + var oz6; + var ow1; + var ow2; + var ow3; + var ow4; + var ow5; + var ow6; + var ou1; + var ou2; + var ou3; + var ou4; + var ou5; + var ou6; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var sx; + var sy; + var sz; + var sw; + var su; + var ox; + var oy; + var oz; + var ow; + var ou; + var ix; + var iy; + var iz; + var iw; + var iu; + 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 o; + + // Note on variable naming convention: s#, dx#, dy#, dz#, dw#, du#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( x.shape, x.strides, y.strides, z.strides, w.strides, u.strides ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + su = o.su; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.dtype, u.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ox = x.offset; + oy = y.offset; + oz = z.offset; + ow = w.offset; + ou = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + du0 = su[0]; + + // Cache accessors: + xget = x.accessors[0]; + yget = y.accessors[0]; + zget = z.accessors[0]; + wget = w.accessors[0]; + uset = u.accessors[1]; + + // Iterate over blocks... + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + ox6 = ox + ( j6*sx[6] ); + oy6 = oy + ( j6*sy[6] ); + oz6 = oz + ( j6*sz[6] ); + ow6 = ow + ( j6*sw[6] ); + ou6 = ou + ( j6*su[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dx6 = sx[6] - ( s5*sx[5] ); + dy6 = sy[6] - ( s5*sy[5] ); + dz6 = sz[6] - ( s5*sz[5] ); + dw6 = sw[6] - ( s5*sw[5] ); + du6 = su[6] - ( s5*su[5] ); + ox5 = ox6 + ( j5*sx[5] ); + oy5 = oy6 + ( j5*sy[5] ); + oz5 = oz6 + ( j5*sz[5] ); + ow5 = ow6 + ( j5*sw[5] ); + ou5 = ou6 + ( j5*su[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + dz5 = sz[5] - ( s4*sz[4] ); + dw5 = sw[5] - ( s4*sw[4] ); + du5 = su[5] - ( s4*su[4] ); + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oz4 = oz5 + ( j4*sz[4] ); + ow4 = ow5 + ( j4*sw[4] ); + ou4 = ou5 + ( j4*su[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + dz4 = sz[4] - ( s3*sz[3] ); + dw4 = sw[4] - ( s3*sw[3] ); + du4 = su[4] - ( s3*su[3] ); + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oz3 = oz4 + ( j3*sz[3] ); + ow3 = ow4 + ( j3*sw[3] ); + ou3 = ou4 + ( j3*su[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + du3 = su[3] - ( s2*su[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + ou2 = ou3 + ( j2*su[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + du2 = su[2] - ( s1*su[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[1] ); + ou1 = ou2 + ( j1*su[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets for the first input and output ndarray elements in the current block... + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + iz = oz1 + ( j0*sz[0] ); + iw = ow1 + ( j0*sw[0] ); + iu = ou1 + ( j0*su[0] ); + + // Compute loop offset increments... + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + dz1 = sz[1] - ( s0*sz[0] ); + dw1 = sw[1] - ( s0*sw[0] ); + du1 = su[1] - ( s0*su[0] ); + + // Iterate over the 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++ ) { + uset( ubuf, iu, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ), wget( wbuf, iw ) ) ); + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + iu += du4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + iu += du5; + } + ix += dx6; + iy += dy6; + iz += dz6; + iw += dw6; + iu += du6; + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedquaternary7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/8d.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/8d.js new file mode 100644 index 000000000000..4c0fdf662bee --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/8d.js @@ -0,0 +1,408 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-statements, max-depth, max-lines-per-function, max-len */ + +'use strict'; + +// MAIN // + +/** +* Applies a quaternary callback to elements in eight-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - quaternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = new Float64Array( 8 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 8, 8, 8, 8, 4, 2, 1 ]; +* var sy = [ 8, 8, 8, 8, 8, 4, 2, 1 ]; +* var sz = [ 8, 8, 8, 8, 8, 4, 2, 1 ]; +* var sw = [ 8, 8, 8, 8, 8, 4, 2, 1 ]; +* var su = [ 8, 8, 8, 8, 8, 4, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* var z = { +* 'dtype': 'float64', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major' +* }; +* var w = { +* 'dtype': 'float64', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major' +* }; +* var u = { +* 'dtype': 'float64', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major' +* }; +* +* // Apply the quaternary function: +* quaternary8d( x, y, z, w, u, true, fcn ); +* +* console.log( u.data ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] +*/ +function quaternary8d( x, y, z, w, u, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dy7; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dz6; + var dz7; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dw6; + var dw7; + var du0; + var du1; + var du2; + var du3; + var du4; + var du5; + var du6; + var du7; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var sx; + var sy; + var sz; + var sw; + var su; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + + // Note on variable naming convention: S#, dx#, dy#, dz#, dw#, du#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = x.shape; + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + su = u.strides; + 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 ]; + dx0 = sx[ 7 ]; // offset increment for innermost loop + dx1 = sx[ 6 ] - ( S0*sx[7] ); + dx2 = sx[ 5 ] - ( S1*sx[6] ); + dx3 = sx[ 4 ] - ( S2*sx[5] ); + dx4 = sx[ 3 ] - ( S3*sx[4] ); + dx5 = sx[ 2 ] - ( S4*sx[3] ); + dx6 = sx[ 1 ] - ( S5*sx[2] ); + dx7 = sx[ 0 ] - ( S6*sx[1] ); // offset increment for outermost loop + dy0 = sy[ 7 ]; + dy1 = sy[ 6 ] - ( S0*sy[7] ); + dy2 = sy[ 5 ] - ( S1*sy[6] ); + dy3 = sy[ 4 ] - ( S2*sy[5] ); + dy4 = sy[ 3 ] - ( S3*sy[4] ); + dy5 = sy[ 2 ] - ( S4*sy[3] ); + dy6 = sy[ 1 ] - ( S5*sy[2] ); + dy7 = sy[ 0 ] - ( S6*sy[1] ); + dz0 = sz[ 7 ]; + dz1 = sz[ 6 ] - ( S0*sz[7] ); + dz2 = sz[ 5 ] - ( S1*sz[6] ); + dz3 = sz[ 4 ] - ( S2*sz[5] ); + dz4 = sz[ 3 ] - ( S3*sz[4] ); + dz5 = sz[ 2 ] - ( S4*sz[3] ); + dz6 = sz[ 1 ] - ( S5*sz[2] ); + dz7 = sz[ 0 ] - ( S6*sz[1] ); + dw0 = sw[ 7 ]; + dw1 = sw[ 6 ] - ( S0*sw[7] ); + dw2 = sw[ 5 ] - ( S1*sw[6] ); + dw3 = sw[ 4 ] - ( S2*sw[5] ); + dw4 = sw[ 3 ] - ( S3*sw[4] ); + dw5 = sw[ 2 ] - ( S4*sw[3] ); + dw6 = sw[ 1 ] - ( S5*sw[2] ); + dw7 = sw[ 0 ] - ( S6*sw[1] ); + du0 = su[ 7 ]; + du1 = su[ 6 ] - ( S0*su[7] ); + du2 = su[ 5 ] - ( S1*su[6] ); + du3 = su[ 4 ] - ( S2*su[5] ); + du4 = su[ 3 ] - ( S3*su[4] ); + du5 = su[ 2 ] - ( S4*su[3] ); + du6 = su[ 1 ] - ( S5*su[2] ); + du7 = su[ 0 ] - ( S6*su[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 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); + dx5 = sx[ 5 ] - ( S4*sx[4] ); + dx6 = sx[ 6 ] - ( S5*sx[5] ); + dx7 = sx[ 7 ] - ( S6*sx[6] ); // offset increment for outermost loop + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dy4 = sy[ 4 ] - ( S3*sy[3] ); + dy5 = sy[ 5 ] - ( S4*sy[4] ); + dy6 = sy[ 6 ] - ( S5*sy[5] ); + dy7 = sy[ 7 ] - ( S6*sy[6] ); + dz0 = sz[ 0 ]; + dz1 = sz[ 1 ] - ( S0*sz[0] ); + dz2 = sz[ 2 ] - ( S1*sz[1] ); + dz3 = sz[ 3 ] - ( S2*sz[2] ); + dz4 = sz[ 4 ] - ( S3*sz[3] ); + dz5 = sz[ 5 ] - ( S4*sz[4] ); + dz6 = sz[ 6 ] - ( S5*sz[5] ); + dz7 = sz[ 7 ] - ( S6*sz[6] ); + dw0 = sw[ 0 ]; + dw1 = sw[ 1 ] - ( S0*sw[0] ); + dw2 = sw[ 2 ] - ( S1*sw[1] ); + dw3 = sw[ 3 ] - ( S2*sw[2] ); + dw4 = sw[ 4 ] - ( S3*sw[3] ); + dw5 = sw[ 5 ] - ( S4*sw[4] ); + dw6 = sw[ 6 ] - ( S5*sw[5] ); + dw7 = sw[ 7 ] - ( S6*sw[6] ); + du0 = su[ 0 ]; + du1 = su[ 1 ] - ( S0*su[0] ); + du2 = su[ 2 ] - ( S1*su[1] ); + du3 = su[ 3 ] - ( S2*su[2] ); + du4 = su[ 4 ] - ( S3*su[3] ); + du5 = su[ 5 ] - ( S4*su[4] ); + du6 = su[ 6 ] - ( S5*su[5] ); + du7 = su[ 7 ] - ( S6*su[6] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + iu = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Iterate over the 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++ ) { + ubuf[ iu ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ], wbuf[ iw ] ); + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + iu += du4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + iu += du5; + } + ix += dx6; + iy += dy6; + iz += dz6; + iw += dw6; + iu += du6; + } + ix += dx7; + iy += dy7; + iz += dz7; + iw += dw7; + iu += du7; + } +} + + +// EXPORTS // + +module.exports = quaternary8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/8d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/8d_accessors.js new file mode 100644 index 000000000000..4d642c5fddd1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/8d_accessors.js @@ -0,0 +1,432 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-statements, max-depth, max-lines-per-function */ + +'use strict'; + +// MAIN // + +/** +* Applies a quaternary callback to elements in eight-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} z.accessors - data buffer accessors +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} w.accessors - data buffer accessors +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} u.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - ternary callback +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var copy = require( '@stdlib/array/base/copy' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = toAccessorArray( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = toAccessorArray( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = toAccessorArray( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 8, 8, 8, 8, 4, 2, 1 ]; +* var sy = [ 8, 8, 8, 8, 8, 4, 2, 1 ]; +* var sz = [ 8, 8, 8, 8, 8, 4, 2, 1 ]; +* var sw = [ 8, 8, 8, 8, 8, 4, 2, 1 ]; +* var su = [ 8, 8, 8, 8, 8, 4, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* var y = { +* 'dtype': 'generic', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* var z = { +* 'dtype': 'generic', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major', +* 'accessors': accessors( zbuf ).accessors +* }; +* var w = { +* 'dtype': 'generic', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major', +* 'accessors': accessors( wbuf ).accessors +* }; +* var u = { +* 'dtype': 'generic', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major', +* 'accessors': accessors( ubuf ).accessors +* }; +* +* // Apply the ternary function: +* quaternary8d( x, y, z, w, u, true, fcn ); +* +* console.log( copy( u.data ) ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] +*/ +function quaternary8d( x, y, z, w, u, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var xget; + var yget; + var zget; + var wget; + var uset; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dy7; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dz6; + var dz7; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dw6; + var dw7; + var du0; + var du1; + var du2; + var du3; + var du4; + var du5; + var du6; + var du7; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var sx; + var sy; + var sz; + var sw; + var su; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + + // Note on variable naming convention: S#, dx#, dy#, dz#, dw#, du# i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = x.shape; + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + su = u.strides; + 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 ]; + dx0 = sx[ 7 ]; // offset increment for innermost loop + dx1 = sx[ 6 ] - ( S0*sx[7] ); + dx2 = sx[ 5 ] - ( S1*sx[6] ); + dx3 = sx[ 4 ] - ( S2*sx[5] ); + dx4 = sx[ 3 ] - ( S3*sx[4] ); + dx5 = sx[ 2 ] - ( S4*sx[3] ); + dx6 = sx[ 1 ] - ( S5*sx[2] ); + dx7 = sx[ 0 ] - ( S6*sx[1] ); // offset increment for outermost loop + dy0 = sy[ 7 ]; + dy1 = sy[ 6 ] - ( S0*sy[7] ); + dy2 = sy[ 5 ] - ( S1*sy[6] ); + dy3 = sy[ 4 ] - ( S2*sy[5] ); + dy4 = sy[ 3 ] - ( S3*sy[4] ); + dy5 = sy[ 2 ] - ( S4*sy[3] ); + dy6 = sy[ 1 ] - ( S5*sy[2] ); + dy7 = sy[ 0 ] - ( S6*sy[1] ); + dz0 = sz[ 7 ]; + dz1 = sz[ 6 ] - ( S0*sz[7] ); + dz2 = sz[ 5 ] - ( S1*sz[6] ); + dz3 = sz[ 4 ] - ( S2*sz[5] ); + dz4 = sz[ 3 ] - ( S3*sz[4] ); + dz5 = sz[ 2 ] - ( S4*sz[3] ); + dz6 = sz[ 1 ] - ( S5*sz[2] ); + dz7 = sz[ 0 ] - ( S6*sz[1] ); + dw0 = sw[ 7 ]; + dw1 = sw[ 6 ] - ( S0*sw[7] ); + dw2 = sw[ 5 ] - ( S1*sw[6] ); + dw3 = sw[ 4 ] - ( S2*sw[5] ); + dw4 = sw[ 3 ] - ( S3*sw[4] ); + dw5 = sw[ 2 ] - ( S4*sw[3] ); + dw6 = sw[ 1 ] - ( S5*sw[2] ); + dw7 = sw[ 0 ] - ( S6*sw[1] ); + du0 = su[ 7 ]; + du1 = su[ 6 ] - ( S0*su[7] ); + du2 = su[ 5 ] - ( S1*su[6] ); + du3 = su[ 4 ] - ( S2*su[5] ); + du4 = su[ 3 ] - ( S3*su[4] ); + du5 = su[ 2 ] - ( S4*su[3] ); + du6 = su[ 1 ] - ( S5*su[2] ); + du7 = su[ 0 ] - ( S5*su[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 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); + dx5 = sx[ 5 ] - ( S4*sx[4] ); + dx6 = sx[ 6 ] - ( S5*sx[5] ); + dx7 = sx[ 7 ] - ( S6*sx[6] ); // offset increment for outermost loop + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dy4 = sy[ 4 ] - ( S3*sy[3] ); + dy5 = sy[ 5 ] - ( S4*sy[4] ); + dy6 = sy[ 6 ] - ( S5*sy[5] ); + dy7 = sy[ 7 ] - ( S6*sy[6] ); + dz0 = sz[ 0 ]; + dz1 = sz[ 1 ] - ( S0*sz[0] ); + dz2 = sz[ 2 ] - ( S1*sz[1] ); + dz3 = sz[ 3 ] - ( S2*sz[2] ); + dz4 = sz[ 4 ] - ( S3*sz[3] ); + dz5 = sz[ 5 ] - ( S4*sz[4] ); + dz6 = sz[ 6 ] - ( S5*sz[5] ); + dz7 = sz[ 7 ] - ( S6*sz[6] ); + dw0 = sw[ 0 ]; + dw1 = sw[ 1 ] - ( S0*sw[0] ); + dw2 = sw[ 2 ] - ( S1*sw[1] ); + dw3 = sw[ 3 ] - ( S2*sw[2] ); + dw4 = sw[ 4 ] - ( S3*sw[3] ); + dw5 = sw[ 5 ] - ( S4*sw[4] ); + dw6 = sw[ 6 ] - ( S5*sw[5] ); + dw7 = sw[ 7 ] - ( S6*sw[6] ); + du0 = sw[ 0 ]; + du1 = sw[ 1 ] - ( S0*sw[0] ); + du2 = sw[ 2 ] - ( S1*sw[1] ); + du3 = sw[ 3 ] - ( S2*sw[2] ); + du4 = sw[ 4 ] - ( S3*sw[3] ); + du5 = sw[ 5 ] - ( S4*sw[4] ); + du6 = sw[ 6 ] - ( S5*sw[5] ); + du7 = sw[ 7 ] - ( S6*sw[6] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + iu = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache accessors: + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = z.accessors[ 0 ]; + wget = w.accessors[ 0 ]; + uset = u.accessors[ 1 ]; + + // Iterate over the 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++ ) { + uset( ubuf, iu, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ), wget( wbuf, iw ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + iu += du4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + iu += du5; + } + ix += dx6; + iy += dy6; + iz += dz6; + iw += dw6; + iu += du6; + } + ix += dx7; + iy += dy7; + iz += dz7; + iw += dw7; + iu += du7; + } +} + + +// EXPORTS // + +module.exports = quaternary8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/8d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/8d_blocked.js new file mode 100644 index 000000000000..c07d6deebefe --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/8d_blocked.js @@ -0,0 +1,525 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-depth, max-statements, max-lines-per-function, max-lines, max-len */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/quaternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/quaternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a quaternary callback to elements in eight-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Callback} fcn - quaternary callback +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // 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( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = new Float64Array( 12 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 2, 3, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 6, 2, 1 ]; +* var sy = [ 12, 12, 12, 12, 12, 6, 2, 1 ]; +* var sz = [ 12, 12, 12, 12, 12, 6, 2, 1 ]; +* var sw = [ 12, 12, 12, 12, 12, 6, 2, 1 ]; +* var su = [ 12, 12, 12, 12, 12, 6, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* var z = { +* 'dtype': 'float64', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major' +* }; +* var w = { +* 'dtype': 'float64', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major' +* }; +* var u = { +* 'dtype': 'float64', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major' +* }; +* +* // Apply the quaternary function: +* blockedquaternary8d( x, y, z, w, u, fcn ); +* +* console.log( u.data ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0 ] +*/ +function blockedquaternary8d( x, y, z, w, u, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dy7; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dz6; + var dz7; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dw6; + var dw7; + var du0; + var du1; + var du2; + var du3; + var du4; + var du5; + var du6; + var du7; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var ox6; + var ox7; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oy6; + var oy7; + var oz1; + var oz2; + var oz3; + var oz4; + var oz5; + var oz6; + var oz7; + var ow1; + var ow2; + var ow3; + var ow4; + var ow5; + var ow6; + var ow7; + var ou1; + var ou2; + var ou3; + var ou4; + var ou5; + var ou6; + var ou7; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var sx; + var sy; + var sz; + var sw; + var su; + var ox; + var oy; + var oz; + var ow; + var ou; + var ix; + var iy; + var iz; + var iw; + var iu; + 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 o; + + // Note on variable naming convention: s#, dx#, dy#, dz#, dw#, du#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( x.shape, x.strides, y.strides, z.strides, w.strides, u.strides ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + su = o.su; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.dtype, u.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ox = x.offset; + oy = y.offset; + oz = z.offset; + ow = w.offset; + ou = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + du0 = su[0]; + + // Iterate over blocks... + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + ox7 = ox + ( j7*sx[7] ); + oy7 = oy + ( j7*sy[7] ); + oz7 = oz + ( j7*sz[7] ); + ow7 = ow + ( j7*sw[7] ); + ou7 = ou + ( j7*su[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + dx7 = sx[7] - ( s6*sx[6] ); + dy7 = sy[7] - ( s6*sy[6] ); + dz7 = sz[7] - ( s6*sz[6] ); + dw7 = sw[7] - ( s6*sw[6] ); + du7 = su[7] - ( s6*su[6] ); + ox6 = ox7 + ( j6*sx[6] ); + oy6 = oy7 + ( j6*sy[6] ); + oz6 = oz7 + ( j6*sz[6] ); + ow6 = ow7 + ( j6*sw[6] ); + ou6 = ou7 + ( j6*su[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dx6 = sx[6] - ( s5*sx[5] ); + dy6 = sy[6] - ( s5*sy[5] ); + dz6 = sz[6] - ( s5*sz[5] ); + dw6 = sw[6] - ( s5*sw[5] ); + du6 = su[6] - ( s5*su[5] ); + ox5 = ox6 + ( j5*sx[5] ); + oy5 = oy6 + ( j5*sy[5] ); + oz5 = oz6 + ( j5*sz[5] ); + ow5 = ow6 + ( j5*sw[5] ); + ou5 = ou6 + ( j5*su[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + dz5 = sz[5] - ( s4*sz[4] ); + dw5 = sw[5] - ( s4*sw[4] ); + du5 = su[5] - ( s4*su[4] ); + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oz4 = oz5 + ( j4*sz[4] ); + ow4 = ow5 + ( j4*sw[4] ); + ou4 = ou5 + ( j4*su[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + dz4 = sz[4] - ( s3*sz[3] ); + dw4 = sw[4] - ( s3*sw[3] ); + du4 = su[4] - ( s3*su[3] ); + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oz3 = oz4 + ( j3*sz[3] ); + ow3 = ow4 + ( j3*sw[3] ); + ou3 = ou4 + ( j3*su[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + du3 = su[3] - ( s2*su[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + ou2 = ou3 + ( j2*su[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + du2 = su[2] - ( s1*su[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[1] ); + ou1 = ou2 + ( j1*su[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets for the first input and output ndarray elements in the current block... + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + iz = oz1 + ( j0*sz[0] ); + iw = ow1 + ( j0*sw[0] ); + iu = ou1 + ( j0*su[0] ); + + // Compute loop offset increments... + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + dz1 = sz[1] - ( s0*sz[0] ); + dw1 = sw[1] - ( s0*sw[0] ); + du1 = su[1] - ( s0*su[0] ); + + // Iterate over the 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++ ) { + ubuf[ iu ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ], wbuf[ iw ] ); + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + iu += du4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + iu += du5; + } + ix += dx6; + iy += dy6; + iz += dz6; + iw += dw6; + iu += du6; + } + ix += dx7; + iy += dy7; + iz += dz7; + iw += dw7; + iu += du7; + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedquaternary8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/8d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/8d_blocked_accessors.js new file mode 100644 index 000000000000..7e0909b831c4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/8d_blocked_accessors.js @@ -0,0 +1,549 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-depth, max-statements, max-lines-per-function, max-lines, max-len */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/quaternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/quaternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a quaternary callback to elements in eight-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} z.accessors - data buffer accessors +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} w.accessors - data buffer accessors +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} u.accessors - data buffer accessors +* @param {Callback} fcn - quaternary callback +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var copy = require( '@stdlib/array/base/copy' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( [ 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( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = toAccessorArray( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = toAccessorArray( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = toAccessorArray( [ 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 shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 2, 3, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 6, 2, 1 ]; +* var sy = [ 12, 12, 12, 12, 12, 6, 2, 1 ]; +* var sz = [ 12, 12, 12, 12, 12, 6, 2, 1 ]; +* var sw = [ 12, 12, 12, 12, 12, 6, 2, 1 ]; +* var su = [ 12, 12, 12, 12, 12, 6, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* var y = { +* 'dtype': 'generic', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* var z = { +* 'dtype': 'generic', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major', +* 'accessors': accessors( zbuf ).accessors +* }; +* var w = { +* 'dtype': 'generic', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major', +* 'accessors': accessors( wbuf ).accessors +* }; +* var u = { +* 'dtype': 'generic', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major', +* 'accessors': accessors( ubuf ).accessors +* }; +* +* // Apply the quaternary function: +* blockedquaternary8d( x, y, z, w, u, fcn ); +* +* console.log( copy( u.data ) ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0 ] +*/ +function blockedquaternary8d( x, y, z, w, u, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var xget; + var yget; + var zget; + var wget; + var uset; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dy7; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dz6; + var dz7; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dw6; + var dw7; + var du0; + var du1; + var du2; + var du3; + var du4; + var du5; + var du6; + var du7; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var ox6; + var ox7; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oy6; + var oy7; + var oz1; + var oz2; + var oz3; + var oz4; + var oz5; + var oz6; + var oz7; + var ow1; + var ow2; + var ow3; + var ow4; + var ow5; + var ow6; + var ow7; + var ou1; + var ou2; + var ou3; + var ou4; + var ou5; + var ou6; + var ou7; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var sx; + var sy; + var sz; + var sw; + var su; + var ox; + var oy; + var oz; + var ow; + var ou; + var ix; + var iy; + var iz; + var iw; + var iu; + 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 o; + + // Note on variable naming convention: s#, dx#, dy#, dz#, dw#, du#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( x.shape, x.strides, y.strides, z.strides, w.strides, u.strides ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + su = o.su; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.dtype, u.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ox = x.offset; + oy = y.offset; + oz = z.offset; + ow = w.offset; + ou = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + du0 = su[0]; + + // Cache accessors: + xget = x.accessors[0]; + yget = y.accessors[0]; + zget = z.accessors[0]; + wget = w.accessors[0]; + uset = u.accessors[1]; + + // Iterate over blocks... + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + ox7 = ox + ( j7*sx[7] ); + oy7 = oy + ( j7*sy[7] ); + oz7 = oz + ( j7*sz[7] ); + ow7 = ow + ( j7*sw[7] ); + ou7 = ou + ( j7*su[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + dx7 = sx[7] - ( s6*sx[6] ); + dy7 = sy[7] - ( s6*sy[6] ); + dz7 = sz[7] - ( s6*sz[6] ); + dw7 = sw[7] - ( s6*sw[6] ); + du7 = su[7] - ( s6*su[6] ); + ox6 = ox7 + ( j6*sx[6] ); + oy6 = oy7 + ( j6*sy[6] ); + oz6 = oz7 + ( j6*sz[6] ); + ow6 = ow7 + ( j6*sw[6] ); + ou6 = ou7 + ( j6*su[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dx6 = sx[6] - ( s5*sx[5] ); + dy6 = sy[6] - ( s5*sy[5] ); + dz6 = sz[6] - ( s5*sz[5] ); + dw6 = sw[6] - ( s5*sw[5] ); + du6 = su[6] - ( s5*su[5] ); + ox5 = ox6 + ( j5*sx[5] ); + oy5 = oy6 + ( j5*sy[5] ); + oz5 = oz6 + ( j5*sz[5] ); + ow5 = ow6 + ( j5*sw[5] ); + ou5 = ou6 + ( j5*su[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + dz5 = sz[5] - ( s4*sz[4] ); + dw5 = sw[5] - ( s4*sw[4] ); + du5 = su[5] - ( s4*su[4] ); + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oz4 = oz5 + ( j4*sz[4] ); + ow4 = ow5 + ( j4*sw[4] ); + ou4 = ou5 + ( j4*su[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + dz4 = sz[4] - ( s3*sz[3] ); + dw4 = sw[4] - ( s3*sw[3] ); + du4 = su[4] - ( s3*su[3] ); + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oz3 = oz4 + ( j3*sz[3] ); + ow3 = ow4 + ( j3*sw[3] ); + ou3 = ou4 + ( j3*su[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + du3 = su[3] - ( s2*su[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + ou2 = ou3 + ( j2*su[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + du2 = su[2] - ( s1*su[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[1] ); + ou1 = ou2 + ( j1*su[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets for the first input and output ndarray elements in the current block... + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + iz = oz1 + ( j0*sz[0] ); + iw = ow1 + ( j0*sw[0] ); + iu = ou1 + ( j0*su[0] ); + + // Compute loop offset increments... + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + dz1 = sz[1] - ( s0*sz[0] ); + dw1 = sw[1] - ( s0*sw[0] ); + du1 = su[1] - ( s0*su[0] ); + + // Iterate over the 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++ ) { + uset( ubuf, iu, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ), wget( wbuf, iw ) ) ); + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + iu += du4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + iu += du5; + } + ix += dx6; + iy += dy6; + iz += dz6; + iw += dw6; + iu += du6; + } + ix += dx7; + iy += dy7; + iz += dz7; + iw += dw7; + iu += du7; + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedquaternary8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/9d.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/9d.js new file mode 100644 index 000000000000..61f0b70f4a74 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/9d.js @@ -0,0 +1,434 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-statements, max-depth, max-lines-per-function */ + +'use strict'; + +// MAIN // + +/** +* Applies a quaternary callback to elements in nine-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - quaternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = new Float64Array( 8 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 8, 8, 8, 8, 8, 4, 2, 1 ]; +* var sy = [ 8, 8, 8, 8, 8, 8, 4, 2, 1 ]; +* var sz = [ 8, 8, 8, 8, 8, 8, 4, 2, 1 ]; +* var sw = [ 8, 8, 8, 8, 8, 8, 4, 2, 1 ]; +* var su = [ 8, 8, 8, 8, 8, 8, 4, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* var z = { +* 'dtype': 'float64', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major' +* }; +* var w = { +* 'dtype': 'float64', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major' +* }; +* var u = { +* 'dtype': 'float64', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major' +* }; +* +* // Apply the quaternary function: +* quaternary9d( x, y, z, w, u, true, fcn ); +* +* console.log( u.data ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] +*/ +function quaternary9d( x, y, z, w, u, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var dx8; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dy7; + var dy8; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dz6; + var dz7; + var dz8; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dw6; + var dw7; + var dw8; + var du0; + var du1; + var du2; + var du3; + var du4; + var du5; + var du6; + var du7; + var du8; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var S8; + var sx; + var sy; + var sz; + var sw; + var su; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + + // Note on variable naming convention: S#, dx#, dy#, dz#, dw#, du#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = x.shape; + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + su = u.strides; + 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 ]; + dx0 = sx[ 8 ]; // offset increment for innermost loop + dx1 = sx[ 7 ] - ( S0*sx[8] ); + dx2 = sx[ 6 ] - ( S1*sx[7] ); + dx3 = sx[ 5 ] - ( S2*sx[6] ); + dx4 = sx[ 4 ] - ( S3*sx[5] ); + dx5 = sx[ 3 ] - ( S4*sx[4] ); + dx6 = sx[ 2 ] - ( S5*sx[3] ); + dx7 = sx[ 1 ] - ( S6*sx[2] ); + dx8 = sx[ 0 ] - ( S7*sx[1] ); // offset increment for outermost loop + dy0 = sy[ 8 ]; + dy1 = sy[ 7 ] - ( S0*sy[8] ); + dy2 = sy[ 6 ] - ( S1*sy[7] ); + dy3 = sy[ 5 ] - ( S2*sy[6] ); + dy4 = sy[ 4 ] - ( S3*sy[5] ); + dy5 = sy[ 3 ] - ( S4*sy[4] ); + dy6 = sy[ 2 ] - ( S5*sy[3] ); + dy7 = sy[ 1 ] - ( S6*sy[2] ); + dy8 = sy[ 0 ] - ( S7*sy[1] ); + dz0 = sz[ 8 ]; + dz1 = sz[ 7 ] - ( S0*sz[8] ); + dz2 = sz[ 6 ] - ( S1*sz[7] ); + dz3 = sz[ 5 ] - ( S2*sz[6] ); + dz4 = sz[ 4 ] - ( S3*sz[5] ); + dz5 = sz[ 3 ] - ( S4*sz[4] ); + dz6 = sz[ 2 ] - ( S5*sz[3] ); + dz7 = sz[ 1 ] - ( S6*sz[2] ); + dz8 = sz[ 0 ] - ( S7*sz[1] ); + dw0 = sw[ 8 ]; + dw1 = sw[ 7 ] - ( S0*sw[8] ); + dw2 = sw[ 6 ] - ( S1*sw[7] ); + dw3 = sw[ 5 ] - ( S2*sw[6] ); + dw4 = sw[ 4 ] - ( S3*sw[5] ); + dw5 = sw[ 3 ] - ( S4*sw[4] ); + dw6 = sw[ 2 ] - ( S5*sw[3] ); + dw7 = sw[ 1 ] - ( S6*sw[2] ); + dw8 = sw[ 0 ] - ( S7*sw[1] ); + du0 = su[ 8 ]; + du1 = su[ 7 ] - ( S0*su[8] ); + du2 = su[ 6 ] - ( S1*su[7] ); + du3 = su[ 5 ] - ( S2*su[6] ); + du4 = su[ 4 ] - ( S3*su[5] ); + du5 = su[ 3 ] - ( S4*su[4] ); + du6 = su[ 2 ] - ( S5*su[3] ); + du7 = su[ 1 ] - ( S6*su[2] ); + du8 = su[ 0 ] - ( S7*su[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 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); + dx5 = sx[ 5 ] - ( S4*sx[4] ); + dx6 = sx[ 6 ] - ( S5*sx[5] ); + dx7 = sx[ 7 ] - ( S6*sx[6] ); + dx8 = sx[ 8 ] - ( S7*sx[7] ); // offset increment for outermost loop + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dy4 = sy[ 4 ] - ( S3*sy[3] ); + dy5 = sy[ 5 ] - ( S4*sy[4] ); + dy6 = sy[ 6 ] - ( S5*sy[5] ); + dy7 = sy[ 7 ] - ( S6*sy[6] ); + dy8 = sy[ 8 ] - ( S7*sy[7] ); + dz0 = sz[ 0 ]; + dz1 = sz[ 1 ] - ( S0*sz[0] ); + dz2 = sz[ 2 ] - ( S1*sz[1] ); + dz3 = sz[ 3 ] - ( S2*sz[2] ); + dz4 = sz[ 4 ] - ( S3*sz[3] ); + dz5 = sz[ 5 ] - ( S4*sz[4] ); + dz6 = sz[ 6 ] - ( S5*sz[5] ); + dz7 = sz[ 7 ] - ( S6*sz[6] ); + dz8 = sz[ 8 ] - ( S7*sz[7] ); + dw0 = sw[ 0 ]; + dw1 = sw[ 1 ] - ( S0*sw[0] ); + dw2 = sw[ 2 ] - ( S1*sw[1] ); + dw3 = sw[ 3 ] - ( S2*sw[2] ); + dw4 = sw[ 4 ] - ( S3*sw[3] ); + dw5 = sw[ 5 ] - ( S4*sw[4] ); + dw6 = sw[ 6 ] - ( S5*sw[5] ); + dw7 = sw[ 7 ] - ( S6*sw[6] ); + dw8 = sw[ 8 ] - ( S7*sw[7] ); + du0 = su[ 0 ]; + du1 = su[ 1 ] - ( S0*su[0] ); + du2 = su[ 2 ] - ( S1*su[1] ); + du3 = su[ 3 ] - ( S2*su[2] ); + du4 = su[ 4 ] - ( S3*su[3] ); + du5 = su[ 5 ] - ( S4*su[4] ); + du6 = su[ 6 ] - ( S5*su[5] ); + du7 = su[ 7 ] - ( S6*su[6] ); + du8 = su[ 8 ] - ( S7*su[7] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + iu = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Iterate over the 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++ ) { + ubuf[ iu ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ], wbuf[ iw ] ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + iu += du4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + iu += du5; + } + ix += dx6; + iy += dy6; + iz += dz6; + iw += dw6; + iu += du6; + } + ix += dx7; + iy += dy7; + iz += dz7; + iw += dw7; + iu += du7; + } + ix += dx8; + iy += dy8; + iz += dz8; + iw += dw8; + iu += du8; + } +} + + +// EXPORTS // + +module.exports = quaternary9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/9d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/9d_accessors.js new file mode 100644 index 000000000000..a7d749257cd2 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/9d_accessors.js @@ -0,0 +1,458 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-statements, max-depth, max-lines-per-function */ + +'use strict'; + +// MAIN // + +/** +* Applies a quaternary callback to elements in nine-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} z.accessors - data buffer accessors +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} w.accessors - data buffer accessors +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} u.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - quaternary callback +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var copy = require( '@stdlib/array/base/copy' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = toAccessorArray( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = toAccessorArray( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = toAccessorArray( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 8, 8, 8, 8, 8, 4, 2, 1 ]; +* var sy = [ 8, 8, 8, 8, 8, 8, 4, 2, 1 ]; +* var sz = [ 8, 8, 8, 8, 8, 8, 4, 2, 1 ]; +* var sw = [ 8, 8, 8, 8, 8, 8, 4, 2, 1 ]; +* var su = [ 8, 8, 8, 8, 8, 8, 4, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* var y = { +* 'dtype': 'generic', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* var z = { +* 'dtype': 'generic', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major', +* 'accessors': accessors( zbuf ).accessors +* }; +* var w = { +* 'dtype': 'generic', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major', +* 'accessors': accessors( wbuf ).accessors +* }; +* var u = { +* 'dtype': 'generic', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major', +* 'accessors': accessors( ubuf ).accessors +* }; +* +* // Apply the quaternary function: +* quaternary9d( x, y, z, w, u, true, fcn ); +* +* console.log( copy( u.data ) ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] +*/ +function quaternary9d( x, y, z, w, u, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var xget; + var yget; + var zget; + var wget; + var uset; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var dx8; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dy7; + var dy8; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dz6; + var dz7; + var dz8; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dw6; + var dw7; + var dw8; + var du0; + var du1; + var du2; + var du3; + var du4; + var du5; + var du6; + var du7; + var du8; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var S8; + var sx; + var sy; + var sz; + var sw; + var su; + var ix; + var iy; + var iz; + var iw; + var iu; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + + // Note on variable naming convention: S#, dx#, dy#, dz#, dw#, du#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = x.shape; + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + su = u.strides; + 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 ]; + dx0 = sx[ 8 ]; // offset increment for innermost loop + dx1 = sx[ 7 ] - ( S0*sx[8] ); + dx2 = sx[ 6 ] - ( S1*sx[7] ); + dx3 = sx[ 5 ] - ( S2*sx[6] ); + dx4 = sx[ 4 ] - ( S3*sx[5] ); + dx5 = sx[ 3 ] - ( S4*sx[4] ); + dx6 = sx[ 2 ] - ( S5*sx[3] ); + dx7 = sx[ 1 ] - ( S6*sx[2] ); + dx8 = sx[ 0 ] - ( S7*sx[1] ); // offset increment for outermost loop + dy0 = sy[ 8 ]; + dy1 = sy[ 7 ] - ( S0*sy[8] ); + dy2 = sy[ 6 ] - ( S1*sy[7] ); + dy3 = sy[ 5 ] - ( S2*sy[6] ); + dy4 = sy[ 4 ] - ( S3*sy[5] ); + dy5 = sy[ 3 ] - ( S4*sy[4] ); + dy6 = sy[ 2 ] - ( S5*sy[3] ); + dy7 = sy[ 1 ] - ( S6*sy[2] ); + dy8 = sy[ 0 ] - ( S7*sy[1] ); + dz0 = sz[ 8 ]; + dz1 = sz[ 7 ] - ( S0*sz[8] ); + dz2 = sz[ 6 ] - ( S1*sz[7] ); + dz3 = sz[ 5 ] - ( S2*sz[6] ); + dz4 = sz[ 4 ] - ( S3*sz[5] ); + dz5 = sz[ 3 ] - ( S4*sz[4] ); + dz6 = sz[ 2 ] - ( S5*sz[3] ); + dz7 = sz[ 1 ] - ( S6*sz[2] ); + dz8 = sz[ 0 ] - ( S7*sz[1] ); + dw0 = sw[ 8 ]; + dw1 = sw[ 7 ] - ( S0*sw[8] ); + dw2 = sw[ 6 ] - ( S1*sw[7] ); + dw3 = sw[ 5 ] - ( S2*sw[6] ); + dw4 = sw[ 4 ] - ( S3*sw[5] ); + dw5 = sw[ 3 ] - ( S4*sw[4] ); + dw6 = sw[ 2 ] - ( S5*sw[3] ); + dw7 = sw[ 1 ] - ( S6*sw[2] ); + dw8 = sw[ 0 ] - ( S7*sw[1] ); + du0 = su[ 8 ]; + du1 = su[ 7 ] - ( S0*su[8] ); + du2 = su[ 6 ] - ( S1*su[7] ); + du3 = su[ 5 ] - ( S2*su[6] ); + du4 = su[ 4 ] - ( S3*su[5] ); + du5 = su[ 3 ] - ( S4*su[4] ); + du6 = su[ 2 ] - ( S5*su[3] ); + du7 = su[ 1 ] - ( S6*su[2] ); + du8 = su[ 0 ] - ( S7*su[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 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); + dx5 = sx[ 5 ] - ( S4*sx[4] ); + dx6 = sx[ 6 ] - ( S5*sx[5] ); + dx7 = sx[ 7 ] - ( S6*sx[6] ); + dx8 = sx[ 8 ] - ( S7*sx[7] ); // offset increment for outermost loop + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dy4 = sy[ 4 ] - ( S3*sy[3] ); + dy5 = sy[ 5 ] - ( S4*sy[4] ); + dy6 = sy[ 6 ] - ( S5*sy[5] ); + dy7 = sy[ 7 ] - ( S6*sy[6] ); + dy8 = sy[ 8 ] - ( S7*sy[7] ); + dz0 = sz[ 0 ]; + dz1 = sz[ 1 ] - ( S0*sz[0] ); + dz2 = sz[ 2 ] - ( S1*sz[1] ); + dz3 = sz[ 3 ] - ( S2*sz[2] ); + dz4 = sz[ 4 ] - ( S3*sz[3] ); + dz5 = sz[ 5 ] - ( S4*sz[4] ); + dz6 = sz[ 6 ] - ( S5*sz[5] ); + dz7 = sz[ 7 ] - ( S6*sz[6] ); + dz8 = sz[ 8 ] - ( S7*sz[7] ); + dw0 = sw[ 0 ]; + dw1 = sw[ 1 ] - ( S0*sw[0] ); + dw2 = sw[ 2 ] - ( S1*sw[1] ); + dw3 = sw[ 3 ] - ( S2*sw[2] ); + dw4 = sw[ 4 ] - ( S3*sw[3] ); + dw5 = sw[ 5 ] - ( S4*sw[4] ); + dw6 = sw[ 6 ] - ( S5*sw[5] ); + dw7 = sw[ 7 ] - ( S6*sw[6] ); + dw8 = sw[ 8 ] - ( S7*sw[7] ); + du0 = su[ 0 ]; + du1 = su[ 1 ] - ( S0*su[0] ); + du2 = su[ 2 ] - ( S1*su[1] ); + du3 = su[ 3 ] - ( S2*su[2] ); + du4 = su[ 4 ] - ( S3*su[3] ); + du5 = su[ 5 ] - ( S4*su[4] ); + du6 = su[ 6 ] - ( S5*su[5] ); + du7 = su[ 7 ] - ( S6*su[6] ); + du8 = su[ 8 ] - ( S7*su[7] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + iu = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache accessors: + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = z.accessors[ 0 ]; + wget = w.accessors[ 0 ]; + uset = u.accessors[ 1 ]; + + // Iterate over the 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++ ) { + uset( ubuf, iu, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ), wget( wbuf, iw ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + iu += du4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + iu += du5; + } + ix += dx6; + iy += dy6; + iz += dz6; + iw += dw6; + iu += du6; + } + ix += dx7; + iy += dy7; + iz += dz7; + iw += dw7; + iu += du7; + } + ix += dx8; + iy += dy8; + iz += dz8; + iw += dw8; + iu += du8; + } +} + + +// EXPORTS // + +module.exports = quaternary9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/9d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/9d_blocked.js new file mode 100644 index 000000000000..a1a83af391df --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/9d_blocked.js @@ -0,0 +1,564 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-depth, max-statements, max-lines-per-function, max-len, max-lines */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/quaternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/quaternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a quaternary callback to elements in nine-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Callback} fcn - quaternary callback +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // 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( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = new Float64Array( 12 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 1, 2, 3, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 6, 2, 1 ]; +* var sy = [ 12, 12, 12, 12, 12, 12, 6, 2, 1 ]; +* var sz = [ 12, 12, 12, 12, 12, 12, 6, 2, 1 ]; +* var sw = [ 12, 12, 12, 12, 12, 12, 6, 2, 1 ]; +* var su = [ 12, 12, 12, 12, 12, 12, 6, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* var z = { +* 'dtype': 'float64', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major' +* }; +* var w = { +* 'dtype': 'float64', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major' +* }; +* var u = { +* 'dtype': 'float64', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major' +* }; +* +* // Apply the quaternary function: +* blockedquaternary9d( x, y, z, w, u, fcn ); +* +* console.log( u.data ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0 ] +*/ +function blockedquaternary9d( x, y, z, w, u, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var dx8; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dy7; + var dy8; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dz6; + var dz7; + var dz8; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dw6; + var dw7; + var dw8; + var du0; + var du1; + var du2; + var du3; + var du4; + var du5; + var du6; + var du7; + var du8; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var ox6; + var ox7; + var ox8; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oy6; + var oy7; + var oy8; + var oz1; + var oz2; + var oz3; + var oz4; + var oz5; + var oz6; + var oz7; + var oz8; + var ow1; + var ow2; + var ow3; + var ow4; + var ow5; + var ow6; + var ow7; + var ow8; + var ou1; + var ou2; + var ou3; + var ou4; + var ou5; + var ou6; + var ou7; + var ou8; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var s8; + var sx; + var sy; + var sz; + var sw; + var su; + var ox; + var oy; + var oz; + var ow; + var ou; + var ix; + var iy; + var iz; + var iw; + var iu; + 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 o; + + // Note on variable naming convention: s#, dx#, dy#, dz#, dw#, du#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( x.shape, x.strides, y.strides, z.strides, w.strides, u.strides ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + su = o.su; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.dtype, u.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ox = x.offset; + oy = y.offset; + oz = z.offset; + ow = w.offset; + ou = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + du0 = su[0]; + + // Iterate over blocks... + for ( j8 = sh[8]; j8 > 0; ) { + if ( j8 < bsize ) { + s8 = j8; + j8 = 0; + } else { + s8 = bsize; + j8 -= bsize; + } + ox8 = ox + ( j8*sx[8] ); + oy8 = oy + ( j8*sy[8] ); + oz8 = oz + ( j8*sz[8] ); + ow8 = ow + ( j8*sw[8] ); + ou8 = ou + ( j8*su[8] ); + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + dx8 = sx[8] - ( s7*sx[7] ); + dy8 = sy[8] - ( s7*sy[7] ); + dz8 = sz[8] - ( s7*sz[7] ); + dw8 = sw[8] - ( s7*sw[7] ); + du8 = su[8] - ( s7*su[7] ); + ox7 = ox8 + ( j7*sx[7] ); + oy7 = oy8 + ( j7*sy[7] ); + oz7 = oz8 + ( j7*sz[7] ); + ow7 = ow8 + ( j7*sw[7] ); + ou7 = ou8 + ( j7*su[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + dx7 = sx[7] - ( s6*sx[6] ); + dy7 = sy[7] - ( s6*sy[6] ); + dz7 = sz[7] - ( s6*sz[6] ); + dw7 = sw[7] - ( s6*sw[6] ); + du7 = su[7] - ( s6*su[6] ); + ox6 = ox7 + ( j6*sx[6] ); + oy6 = oy7 + ( j6*sy[6] ); + oz6 = oz7 + ( j6*sz[6] ); + ow6 = ow7 + ( j6*sw[6] ); + ou6 = ou7 + ( j6*su[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dx6 = sx[6] - ( s5*sx[5] ); + dy6 = sy[6] - ( s5*sy[5] ); + dz6 = sz[6] - ( s5*sz[5] ); + dw6 = sw[6] - ( s5*sw[5] ); + du6 = su[6] - ( s5*su[5] ); + ox5 = ox6 + ( j5*sx[5] ); + oy5 = oy6 + ( j5*sy[5] ); + oz5 = oz6 + ( j5*sz[5] ); + ow5 = ow6 + ( j5*sw[5] ); + ou5 = ou6 + ( j5*su[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + dz5 = sz[5] - ( s4*sz[4] ); + dw5 = sw[5] - ( s4*sw[4] ); + du5 = su[5] - ( s4*su[4] ); + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oz4 = oz5 + ( j4*sz[4] ); + ow4 = ow5 + ( j4*sw[4] ); + ou4 = ou5 + ( j4*su[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + dz4 = sz[4] - ( s3*sz[3] ); + dw4 = sw[4] - ( s3*sw[3] ); + du4 = su[4] - ( s3*su[3] ); + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oz3 = oz4 + ( j3*sz[3] ); + ow3 = ow4 + ( j3*sw[3] ); + ou3 = ou4 + ( j3*su[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + du3 = su[3] - ( s2*su[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + ou2 = ou3 + ( j2*su[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + du2 = su[2] - ( s1*su[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[1] ); + ou1 = ou2 + ( j1*su[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets for the first input and output ndarray elements in the current block... + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + iz = oz1 + ( j0*sz[0] ); + iw = ow1 + ( j0*sw[0] ); + iu = ou1 + ( j0*su[0] ); + + // Compute loop offset increments... + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + dz1 = sz[1] - ( s0*sz[0] ); + dw1 = sw[1] - ( s0*sw[0] ); + du1 = su[1] - ( s0*su[0] ); + + // Iterate over the 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++ ) { + ubuf[ iu ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ], wbuf[ iw ] ); + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + iu += du4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + iu += du5; + } + ix += dx6; + iy += dy6; + iz += dz6; + iw += dw6; + iu += du6; + } + ix += dx7; + iy += dy7; + iz += dz7; + iw += dw7; + iu += du7; + } + ix += dx8; + iy += dy8; + iz += dz8; + iw += dw8; + iu += du8; + } + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedquaternary9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/9d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/9d_blocked_accessors.js new file mode 100644 index 000000000000..2b36ccced219 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/9d_blocked_accessors.js @@ -0,0 +1,588 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-depth, max-statements, max-lines-per-function, max-len */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/quaternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/quaternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a quaternary callback to elements in nine-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} z.accessors - data buffer accessors +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} w.accessors - data buffer accessors +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} u.accessors - data buffer accessors +* @param {Callback} fcn - ternary callback +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var copy = require( '@stdlib/array/base/copy' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // 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( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ) ); +* var zbuf = toAccessorArray( new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ) ); +* var wbuf = toAccessorArray( new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ) ); +* var ubuf = toAccessorArray( new Float64Array( 12 ) ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 1, 2, 3, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 6, 2, 1 ]; +* var sy = [ 12, 12, 12, 12, 12, 12, 6, 2, 1 ]; +* var sz = [ 12, 12, 12, 12, 12, 12, 6, 2, 1 ]; +* var sw = [ 12, 12, 12, 12, 12, 12, 6, 2, 1 ]; +* var su = [ 12, 12, 12, 12, 12, 12, 6, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* var y = { +* 'dtype': 'generic', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* var z = { +* 'dtype': 'generic', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major', +* 'accessors': accessors( zbuf ).accessors +* }; +* var w = { +* 'dtype': 'generic', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major', +* 'accessors': accessors( wbuf ).accessors +* }; +* var u = { +* 'dtype': 'generic', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major', +* 'accessors': accessors( ubuf ).accessors +* }; +* +* // Apply the ternary function: +* blockedquaternary9d( x, y, z, w, u, fcn ); +* +* console.log( copy( u.data ) ); +* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0 ] +*/ +function blockedquaternary9d( x, y, z, w, u, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var xget; + var yget; + var zget; + var wget; + var uset; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var dx8; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dy7; + var dy8; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dz6; + var dz7; + var dz8; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dw6; + var dw7; + var dw8; + var du0; + var du1; + var du2; + var du3; + var du4; + var du5; + var du6; + var du7; + var du8; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var ox6; + var ox7; + var ox8; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oy6; + var oy7; + var oy8; + var oz1; + var oz2; + var oz3; + var oz4; + var oz5; + var oz6; + var oz7; + var oz8; + var ow1; + var ow2; + var ow3; + var ow4; + var ow5; + var ow6; + var ow7; + var ow8; + var ou1; + var ou2; + var ou3; + var ou4; + var ou5; + var ou6; + var ou7; + var ou8; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var s8; + var sx; + var sy; + var sz; + var sw; + var su; + var ox; + var oy; + var oz; + var ow; + var ou; + var ix; + var iy; + var iz; + var iw; + var iu; + 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 o; + + // Note on variable naming convention: s#, dx#, dy#, dz#, dw#, du#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( x.shape, x.strides, y.strides, z.strides, w.strides, u.strides ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + su = o.su; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.dtype, u.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ox = x.offset; + oy = y.offset; + oz = z.offset; + ow = w.offset; + ou = u.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + du0 = su[0]; + + // Cache accessors: + xget = x.accessors[0]; + yget = y.accessors[0]; + zget = z.accessors[0]; + wget = w.accessors[0]; + uset = u.accessors[1]; + + // Iterate over blocks... + for ( j8 = sh[8]; j8 > 0; ) { + if ( j8 < bsize ) { + s8 = j8; + j8 = 0; + } else { + s8 = bsize; + j8 -= bsize; + } + ox8 = ox + ( j8*sx[8] ); + oy8 = oy + ( j8*sy[8] ); + oz8 = oz + ( j8*sz[8] ); + ow8 = ow + ( j8*sw[8] ); + ou8 = ou + ( j8*su[8] ); + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + dx8 = sx[8] - ( s7*sx[7] ); + dy8 = sy[8] - ( s7*sy[7] ); + dz8 = sz[8] - ( s7*sz[7] ); + dw8 = sw[8] - ( s7*sw[7] ); + du8 = su[8] - ( s7*su[7] ); + ox7 = ox8 + ( j7*sx[7] ); + oy7 = oy8 + ( j7*sy[7] ); + oz7 = oz8 + ( j7*sz[7] ); + ow7 = ow8 + ( j7*sw[7] ); + ou7 = ou8 + ( j7*su[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + dx7 = sx[7] - ( s6*sx[6] ); + dy7 = sy[7] - ( s6*sy[6] ); + dz7 = sz[7] - ( s6*sz[6] ); + dw7 = sw[7] - ( s6*sw[6] ); + du7 = su[7] - ( s6*su[6] ); + ox6 = ox7 + ( j6*sx[6] ); + oy6 = oy7 + ( j6*sy[6] ); + oz6 = oz7 + ( j6*sz[6] ); + ow6 = ow7 + ( j6*sw[6] ); + ou6 = ou7 + ( j6*su[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dx6 = sx[6] - ( s5*sx[5] ); + dy6 = sy[6] - ( s5*sy[5] ); + dz6 = sz[6] - ( s5*sz[5] ); + dw6 = sw[6] - ( s5*sw[5] ); + du6 = su[6] - ( s5*su[5] ); + ox5 = ox6 + ( j5*sx[5] ); + oy5 = oy6 + ( j5*sy[5] ); + oz5 = oz6 + ( j5*sz[5] ); + ow5 = ow6 + ( j5*sw[5] ); + ou5 = ou6 + ( j5*su[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + dz5 = sz[5] - ( s4*sz[4] ); + dw5 = sw[5] - ( s4*sw[4] ); + du5 = su[5] - ( s4*su[4] ); + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oz4 = oz5 + ( j4*sz[4] ); + ow4 = ow5 + ( j4*sw[4] ); + ou4 = ou5 + ( j4*su[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + dz4 = sz[4] - ( s3*sz[3] ); + dw4 = sw[4] - ( s3*sw[3] ); + du4 = su[4] - ( s3*su[3] ); + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oz3 = oz4 + ( j3*sz[3] ); + ow3 = ow4 + ( j3*sw[3] ); + ou3 = ou4 + ( j3*su[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + du3 = su[3] - ( s2*su[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + ou2 = ou3 + ( j2*su[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + du2 = su[2] - ( s1*su[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[1] ); + ou1 = ou2 + ( j1*su[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets for the first input and output ndarray elements in the current block... + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + iz = oz1 + ( j0*sz[0] ); + iw = ow1 + ( j0*sw[0] ); + iu = ou1 + ( j0*su[0] ); + + // Compute loop offset increments... + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + dz1 = sz[1] - ( s0*sz[0] ); + dw1 = sw[1] - ( s0*sw[0] ); + du1 = su[1] - ( s0*su[0] ); + + // Iterate over the 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++ ) { + uset( ubuf, iu, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ), wget( wbuf, iw ) ) ); + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + iu += du0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + iu += du1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + iu += du2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + iu += du3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + iu += du4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + iu += du5; + } + ix += dx6; + iy += dy6; + iz += dz6; + iw += dw6; + iu += du6; + } + ix += dx7; + iy += dy7; + iz += dz7; + iw += dw7; + iu += du7; + } + ix += dx8; + iy += dy8; + iz += dz8; + iw += dw8; + iu += du8; + } + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedquaternary9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/index.js new file mode 100644 index 000000000000..3585bb8bac32 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/index.js @@ -0,0 +1,81 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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'; + +/** +* Apply a quaternary callback to elements in input ndarrays and assign results to elements in an output ndarray. +* +* @module @stdlib/ndarray/base/quaternary +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var getData = require( '@stdlib/ndarray/data-buffer' ); +* var quaternary = require( '@stdlib/ndarray/base/quaternary' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var zbuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var wbuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var ubuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 2, 1 ]; +* var sy = [ 2, 2, 1 ]; +* var sz = [ 2, 2, 1 ]; +* var sw = [ 2, 2, 1 ]; +* var su = [ 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarrays: +* var x = new ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' ); +* var y = new ndarray( 'float64', ybuf, shape, sy, oy, 'row-major' ); +* var z = new ndarray( 'float64', zbuf, shape, sz, oz, 'row-major' ); +* var w = new ndarray( 'float64', wbuf, shape, sw, ow, 'row-major' ); +* var u = new ndarray( 'float64', ubuf, shape, su, ou, 'row-major' ); +* +* // Apply the quaternary function: +* quaternary( [ x, y, z, w, u ], fcn ); +* +* console.log( getData( u ) ); +* // => [ 4.0, 6.0, 8.0, 10.0, 12.0, 14.0 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/main.js new file mode 100644 index 000000000000..edb135aa2cf4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/main.js @@ -0,0 +1,449 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-statements, max-lines-per-function */ + +'use strict'; + +// MODULES // + +var iterationOrder = require( '@stdlib/ndarray/base/iteration-order' ); +var minmaxViewBufferIndex = require( '@stdlib/ndarray/base/minmax-view-buffer-index' ); +var ndarray2object = require( '@stdlib/ndarray/base/ndarraylike2object' ); +var strides2order = require( '@stdlib/ndarray/base/strides2order' ); +var anyIsEntryIn = require( '@stdlib/array/base/any-is-entry-in' ); +var format = require( '@stdlib/string/format' ); +var blockedaccessorquaternary2d = require( './2d_blocked_accessors.js' ); +var blockedaccessorquaternary3d = require( './3d_blocked_accessors.js' ); +var blockedaccessorquaternary4d = require( './4d_blocked_accessors.js' ); +var blockedaccessorquaternary5d = require( './5d_blocked_accessors.js' ); +var blockedaccessorquaternary6d = require( './6d_blocked_accessors.js' ); +var blockedaccessorquaternary7d = require( './7d_blocked_accessors.js' ); +var blockedaccessorquaternary8d = require( './8d_blocked_accessors.js' ); +var blockedaccessorquaternary9d = require( './9d_blocked_accessors.js' ); +var blockedaccessorquaternary10d = require( './10d_blocked_accessors.js' ); +var blockedquaternary2d = require( './2d_blocked.js' ); +var blockedquaternary3d = require( './3d_blocked.js' ); +var blockedquaternary4d = require( './4d_blocked.js' ); +var blockedquaternary5d = require( './5d_blocked.js' ); +var blockedquaternary6d = require( './6d_blocked.js' ); +var blockedquaternary7d = require( './7d_blocked.js' ); +var blockedquaternary8d = require( './8d_blocked.js' ); +var blockedquaternary9d = require( './9d_blocked.js' ); +var blockedquaternary10d = require( './10d_blocked.js' ); +var accessorquaternary0d = require( './0d_accessors.js' ); +var accessorquaternary1d = require( './1d_accessors.js' ); +var accessorquaternary2d = require( './2d_accessors.js' ); +var accessorquaternary3d = require( './3d_accessors.js' ); +var accessorquaternary4d = require( './4d_accessors.js' ); +var accessorquaternary5d = require( './5d_accessors.js' ); +var accessorquaternary6d = require( './6d_accessors.js' ); +var accessorquaternary7d = require( './7d_accessors.js' ); +var accessorquaternary8d = require( './8d_accessors.js' ); +var accessorquaternary9d = require( './9d_accessors.js' ); +var accessorquaternary10d = require( './10d_accessors.js' ); +var accessorquaternarynd = require( './nd_accessors.js' ); +var quaternary0d = require( './0d.js' ); +var quaternary1d = require( './1d.js' ); +var quaternary2d = require( './2d.js' ); +var quaternary3d = require( './3d.js' ); +var quaternary4d = require( './4d.js' ); +var quaternary5d = require( './5d.js' ); +var quaternary6d = require( './6d.js' ); +var quaternary7d = require( './7d.js' ); +var quaternary8d = require( './8d.js' ); +var quaternary9d = require( './9d.js' ); +var quaternary10d = require( './10d.js' ); +var quaternarynd = require( './nd.js' ); + + +// VARIABLES // + +var QUATERNARY = [ + quaternary0d, + quaternary1d, + quaternary2d, + quaternary3d, + quaternary4d, + quaternary5d, + quaternary6d, + quaternary7d, + quaternary8d, + quaternary9d, + quaternary10d +]; +var ACCESSOR_QUATERNARY = [ + accessorquaternary0d, + accessorquaternary1d, + accessorquaternary2d, + accessorquaternary3d, + accessorquaternary4d, + accessorquaternary5d, + accessorquaternary6d, + accessorquaternary7d, + accessorquaternary8d, + accessorquaternary9d, + accessorquaternary10d +]; +var BLOCKED_QUATERNARY = [ + blockedquaternary2d, // 0 + blockedquaternary3d, + blockedquaternary4d, + blockedquaternary5d, + blockedquaternary6d, + blockedquaternary7d, + blockedquaternary8d, + blockedquaternary9d, + blockedquaternary10d // 8 +]; +var BLOCKED_ACCESSOR_QUATERNARY = [ + blockedaccessorquaternary2d, // 0 + blockedaccessorquaternary3d, + blockedaccessorquaternary4d, + blockedaccessorquaternary5d, + blockedaccessorquaternary6d, + blockedaccessorquaternary7d, + blockedaccessorquaternary8d, + blockedaccessorquaternary9d, + blockedaccessorquaternary10d // 8 +]; +var MAX_DIMS = QUATERNARY.length - 1; + + +// FUNCTIONS // + +/** +* Returns a boolean indicating if at least one ndarray data buffer implements the accessor protocol. +* +* @private +* @param {ndarrayLike} x - first ndarray +* @param {ndarrayLike} y - second ndarray +* @param {ndarrayLike} z - third ndarray +* @param {ndarrayLike} w - fourth ndarray +* @param {ndarrayLike} u - fifth ndarray +* @returns {boolean} boolean indicating whether an ndarray data buffer implements the accessor protocol +*/ +function hasAccessors( x, y, z, w, u ) { + return anyIsEntryIn( [ x, y, z, w, u ], 'accessorProtocol', true ); +} + + +// MAIN // + +/** +* Applies a quaternary callback to elements in input ndarrays and assigns results to elements in an output ndarray. +* +* ## Notes +* +* - 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). +* +* @param {ArrayLikeObject} arrays - array-like object containing four input arrays and one output array +* @param {Callback} fcn - quaternary callback +* @throws {Error} arrays must have the same number of dimensions +* @throws {Error} arrays must have the same shape +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var getData = require( '@stdlib/ndarray/data-buffer' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var zbuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var wbuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var ubuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 2, 1 ]; +* var sy = [ 2, 2, 1 ]; +* var sz = [ 2, 2, 1 ]; +* var sw = [ 2, 2, 1 ]; +* var su = [ 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarrays: +* var x = new ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' ); +* var y = new ndarray( 'float64', ybuf, shape, sy, oy, 'row-major' ); +* var z = new ndarray( 'float64', zbuf, shape, sz, oz, 'row-major' ); +* var w = new ndarray( 'float64', wbuf, shape, sw, ow, 'row-major' ); +* var u = new ndarray( 'float64', ubuf, shape, su, ou, 'row-major' ); +* +* // Apply the quaternary function: +* quaternary( [ x, y, z, w, u ], fcn ); +* +* console.log( getData( u ) ); +* // => [ 4.0, 6.0, 8.0, 10.0, 12.0, 14.0 ] +*/ +function quaternary( arrays, fcn ) { + var ndims; + var xmmv; + var ymmv; + var zmmv; + var wmmv; + var ummv; + var shx; + var shy; + var shz; + var shw; + var shu; + var iox; + var ioy; + var ioz; + var iow; + var iou; + var len; + var ord; + var sx; + var sy; + var sz; + var sw; + var su; + var ox; + var oy; + var oz; + var ow; + var ou; + var ns; + var x; + var y; + var z; + var w; + var u; + var d; + var i; + + // Unpack the ndarrays and standardize ndarray meta data: + x = ndarray2object( arrays[ 0 ] ); + y = ndarray2object( arrays[ 1 ] ); + z = ndarray2object( arrays[ 2 ] ); + w = ndarray2object( arrays[ 3 ] ); + u = ndarray2object( arrays[ 4 ] ); + + // Verify that the input and output arrays have the same number of dimensions... + shx = x.shape; + shy = y.shape; + shz = z.shape; + shw = w.shape; + shu = u.shape; + ndims = shx.length; + if ( + ndims !== shy.length || + ndims !== shz.length || + ndims !== shw.length || + ndims !== shu.length + ) { + throw new Error( format( 'invalid arguments. Arrays must have the same number of dimensions (i.e., same rank). ndims(x) == %d. ndims(y) == %d. ndims(z) == %d. ndims(w) == %d. ndims(u) == %d.', ndims, shy.length, shz.length, shw.length, shu.length ) ); + } + // Determine whether we can avoid iteration altogether... + if ( ndims === 0 ) { + if ( hasAccessors( x, y, z, w, u ) ) { + return ACCESSOR_QUATERNARY[ ndims ]( x, y, z, w, u, fcn ); + } + return QUATERNARY[ ndims ]( x, y, z, w, u, fcn ); + } + // Verify that the input and output arrays have the same dimensions... + len = 1; // number of elements + ns = 0; // number of singleton dimensions + for ( i = 0; i < ndims; i++ ) { + d = shx[ i ]; + if ( d !== shy[ i ] || d !== shz[ i ] || d !== shw[ i ] || d !== shu[ i ] ) { // eslint-disable-line max-len + throw new Error( 'invalid arguments. Arrays must have the same shape.' ); + } + // Note that, if one of the dimensions is `0`, the length will be `0`... + len *= d; + + // Check whether the current dimension is a singleton dimension... + if ( d === 1 ) { + ns += 1; + } + } + // Check whether we were provided empty ndarrays... + if ( len === 0 ) { + return; + } + // Determine whether the ndarrays are one-dimensional and thus readily translate to one-dimensional strided arrays... + if ( ndims === 1 ) { + if ( hasAccessors( x, y, z, w, u ) ) { + return ACCESSOR_QUATERNARY[ ndims ]( x, y, z, w, u, fcn ); + } + return QUATERNARY[ ndims ]( x, y, z, w, u, fcn ); + } + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + su = u.strides; + + // Determine whether the ndarrays have only **one** non-singleton dimension (e.g., ndims=4, shape=[10,1,1,1]) so that we can treat the ndarrays as being equivalent to one-dimensional strided arrays... + if ( ns === ndims-1 ) { + // Get the index of the non-singleton dimension... + for ( i = 0; i < ndims; i++ ) { + if ( shx[ i ] !== 1 ) { + break; + } + } + x.shape = [ shx[i] ]; + y.shape = x.shape; + z.shape = x.shape; + w.shape = x.shape; + u.shape = x.shape; + x.strides = [ sx[i] ]; + y.strides = [ sy[i] ]; + z.strides = [ sz[i] ]; + w.strides = [ sw[i] ]; + u.strides = [ su[i] ]; + if ( hasAccessors( x, y, z, w, u ) ) { + return ACCESSOR_QUATERNARY[ 1 ]( x, y, z, w, u, fcn ); + } + return QUATERNARY[ 1 ]( x, y, z, w, u, fcn ); + } + iox = iterationOrder( sx ); // +/-1 + ioy = iterationOrder( sy ); // +/-1 + ioz = iterationOrder( sz ); // +/-1 + iow = iterationOrder( sw ); // +/-1 + iou = iterationOrder( su ); // +/-1 + + // Determine whether we can avoid blocked iteration... + ord = strides2order( sx ); + if ( + iox !== 0 && + ioy !== 0 && + ioz !== 0 && + iow !== 0 && + iou !== 0 && + ord === strides2order( sy ) && + ord === strides2order( sz ) && + ord === strides2order( sw ) && + ord === strides2order( su ) + ) { + // Determine the minimum and maximum linear indices which are accessible by the array views: + xmmv = minmaxViewBufferIndex( shx, sx, x.offset ); + ymmv = minmaxViewBufferIndex( shy, sy, y.offset ); + zmmv = minmaxViewBufferIndex( shz, sz, z.offset ); + wmmv = minmaxViewBufferIndex( shw, sw, w.offset ); + ummv = minmaxViewBufferIndex( shu, su, u.offset ); + + // Determine whether we can ignore shape (and strides) and treat the ndarrays as linear one-dimensional strided arrays... + if ( + len === ( xmmv[1]-xmmv[0]+1 ) && + len === ( ymmv[1]-ymmv[0]+1 ) && + len === ( zmmv[1]-zmmv[0]+1 ) && + len === ( wmmv[1]-wmmv[0]+1 ) && + len === ( ummv[1]-ummv[0]+1 ) + ) { + // Note: the above is equivalent to @stdlib/ndarray/base/assert/is-contiguous, but in-lined so we can retain computed values... + if ( iox === 1 ) { + ox = xmmv[ 0 ]; + } else { + ox = xmmv[ 1 ]; + } + if ( ioy === 1 ) { + oy = ymmv[ 0 ]; + } else { + oy = ymmv[ 1 ]; + } + if ( ioz === 1 ) { + oz = zmmv[ 0 ]; + } else { + oz = zmmv[ 1 ]; + } + if ( iow === 1 ) { + ow = wmmv[ 0 ]; + } else { + ow = wmmv[ 1 ]; + } + if ( iou === 1 ) { + ou = ummv[ 0 ]; + } else { + ou = ummv[ 1 ]; + } + x.shape = [ len ]; + y.shape = x.shape; + z.shape = x.shape; + w.shape = x.shape; + u.shape = x.shape; + x.strides = [ iox ]; + y.strides = [ ioy ]; + z.strides = [ ioz ]; + w.strides = [ iow ]; + u.strides = [ iou ]; + x.offset = ox; + y.offset = oy; + z.offset = oz; + w.offset = ow; + u.offset = ou; + if ( hasAccessors( x, y, z, w, u ) ) { + return ACCESSOR_QUATERNARY[ 1 ]( x, y, z, w, u, fcn ); + } + return QUATERNARY[ 1 ]( x, y, z, w, u, fcn ); + } + // At least one ndarray is non-contiguous, so we cannot directly use one-dimensional array functionality... + + // Determine whether we can use simple nested loops... + if ( ndims <= MAX_DIMS ) { + // So long as iteration for each respective array always moves in the same direction (i.e., no mixed sign strides), we can leverage cache-optimal (i.e., normal) nested loops without resorting to blocked iteration... + if ( hasAccessors( x, y, z, w, u ) ) { + return ACCESSOR_QUATERNARY[ ndims ]( x, y, z, w, u, ord === 1, fcn ); // eslint-disable-line max-len + } + return QUATERNARY[ ndims ]( x, y, z, w, u, ord === 1, fcn ); + } + // Fall-through to linear view iteration... + } + // 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 ( ndims <= MAX_DIMS ) { + if ( hasAccessors( x, y, z, w, u ) ) { + return BLOCKED_ACCESSOR_QUATERNARY[ ndims-2 ]( x, y, z, w, u, fcn ); + } + return BLOCKED_QUATERNARY[ ndims-2 ]( x, y, z, w, u, fcn ); + } + + // Fall-through to linear view iteration without regard for how data is stored in memory (i.e., take the slow path)... + if ( hasAccessors( x, y, z, w, u ) ) { + return accessorquaternarynd( x, y, z, w, u, fcn ); + } + quaternarynd( x, y, z, w, u, fcn ); +} + + +// EXPORTS // + +module.exports = quaternary; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/nd.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/nd.js new file mode 100644 index 000000000000..aedd49c7d6f1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/nd.js @@ -0,0 +1,227 @@ +/** +* @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 numel = require( '@stdlib/ndarray/base/numel' ); +var vind2bind = require( '@stdlib/ndarray/base/vind2bind' ); + + +// MAIN // + +/** +* Applies a quaternary callback to elements in n-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Callback} fcn - quaternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var ybuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 4 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 4, 1 ]; +* var sy = [ 4, 4, 4, 1 ]; +* var sz = [ 4, 4, 4, 1 ]; +* var sw = [ 4, 4, 4, 1 ]; +* var su = [ 4, 4, 4, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* var z = { +* 'dtype': 'float64', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major' +* }; +* var w = { +* 'dtype': 'float64', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major' +* }; +* var u = { +* 'dtype': 'float64', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major' +* }; +* +* // Apply the quaternary function: +* quaternarynd( x, y, z, w, u, fcn ); +* +* console.log( u.data ); +* // => [ 7.0, 8.0, 9.0, 10.0 ] +*/ +function quaternarynd( x, y, z, w, u, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var ordx; + var ordy; + var ordz; + var ordw; + var ordu; + var len; + var sh; + var sx; + var sy; + var sz; + var sw; + var su; + var ox; + var oy; + var oz; + var ow; + var ou; + var ix; + var iy; + var iz; + var iw; + var iu; + var i; + + sh = x.shape; + + // Compute the total number of elements over which to iterate: + len = numel( sh ); + + // Cache references to the input and output ndarray buffers: + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache references to the respective stride arrays: + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + su = u.strides; + + // Cache the indices of the first indexed elements in the respective ndarrays: + ox = x.offset; + oy = y.offset; + oz = z.offset; + ow = w.offset; + ou = u.offset; + + // Cache the respective array orders: + ordx = x.order; + ordy = y.order; + ordz = z.order; + ordw = w.order; + ordu = u.order; + + // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory... + for ( i = 0; i < len; i++ ) { + ix = vind2bind( sh, sx, ox, ordx, i, 'throw' ); + iy = vind2bind( sh, sy, oy, ordy, i, 'throw' ); + iz = vind2bind( sh, sz, oz, ordz, i, 'throw' ); + iw = vind2bind( sh, sw, ow, ordw, i, 'throw' ); + iu = vind2bind( sh, su, ou, ordu, i, 'throw' ); + ubuf[ iu ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ], wbuf[ iw ] ); + } +} + + +// EXPORTS // + +module.exports = quaternarynd; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/nd_accessors.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/nd_accessors.js new file mode 100644 index 000000000000..98f7e4b2e40b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/nd_accessors.js @@ -0,0 +1,251 @@ +/** +* @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 numel = require( '@stdlib/ndarray/base/numel' ); +var vind2bind = require( '@stdlib/ndarray/base/vind2bind' ); + + +// MAIN // + +/** +* Applies a quaternary callback to elements in n-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} z.accessors - data buffer accessors +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} w.accessors - data buffer accessors +* @param {Object} u - object containing output ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} u.accessors - data buffer accessors +* @param {Callback} fcn - quaternary callback +* @returns {void} +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* var copy = require( '@stdlib/array/base/copy' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var ybuf = toAccessorArray( [ 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = toAccessorArray( [ 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = toAccessorArray( [ 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0 ] ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 4 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 4, 1 ]; +* var sy = [ 4, 4, 4, 1 ]; +* var sz = [ 4, 4, 4, 1 ]; +* var sw = [ 4, 4, 4, 1 ]; +* var su = [ 4, 4, 4, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* var y = { +* 'dtype': 'generic', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': accessors( ybuf ).accessors +* }; +* var z = { +* 'dtype': 'generic', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major', +* 'accessors': accessors( zbuf ).accessors +* }; +* var w = { +* 'dtype': 'generic', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major', +* 'accessors': accessors( wbuf ).accessors +* }; +* var u = { +* 'dtype': 'generic', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major', +* 'accessors': accessors( ubuf ).accessors +* }; +* +* // Apply the quaternary function: +* quaternarynd( x, y, z, w, u, fcn ); +* +* console.log( copy( u.data ) ); +* // => [ 7.0, 8.0, 9.0, 10.0 ] +*/ +function quaternarynd( x, y, z, w, u, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var xget; + var yget; + var zget; + var wget; + var uset; + var ordx; + var ordy; + var ordz; + var ordw; + var ordu; + var len; + var sh; + var sx; + var sy; + var sz; + var sw; + var su; + var ox; + var oy; + var oz; + var ow; + var ou; + var ix; + var iy; + var iz; + var iw; + var iu; + var i; + + sh = x.shape; + + // Compute the total number of elements over which to iterate: + len = numel( sh ); + + // Cache references to the input and output ndarray buffers: + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + + // Cache references to the respective stride arrays: + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + su = u.strides; + + // Cache the indices of the first indexed elements in the respective ndarrays: + ox = x.offset; + oy = y.offset; + oz = z.offset; + ow = w.offset; + ou = u.offset; + + // Cache the respective array orders: + ordx = x.order; + ordy = y.order; + ordz = z.order; + ordw = w.order; + ordu = u.order; + + // Cache accessors: + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = z.accessors[ 0 ]; + wget = w.accessors[ 0 ]; + uset = u.accessors[ 1 ]; + + // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory... + for ( i = 0; i < len; i++ ) { + ix = vind2bind( sh, sx, ox, ordx, i, 'throw' ); + iy = vind2bind( sh, sy, oy, ordy, i, 'throw' ); + iz = vind2bind( sh, sz, oz, ordz, i, 'throw' ); + iw = vind2bind( sh, sw, ow, ordw, i, 'throw' ); + iu = vind2bind( sh, su, ou, ordu, i, 'throw' ); + uset( ubuf, iu, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ), wget( wbuf, iw ) ) ); // eslint-disable-line max-len + } +} + + +// EXPORTS // + +module.exports = quaternarynd; diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/package.json b/lib/node_modules/@stdlib/ndarray/base/quaternary/package.json new file mode 100644 index 000000000000..d2cc5dd53f2f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/package.json @@ -0,0 +1,63 @@ +{ + "name": "@stdlib/ndarray/base/quaternary", + "version": "0.0.0", + "description": "Apply a quaternary callback to elements in input ndarrays and assign results to elements in an 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", + "quaternary", + "apply", + "foreach", + "map", + "transform" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/test/test.0d.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/test/test.0d.js new file mode 100644 index 000000000000..9cc8d3f80a35 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/test/test.0d.js @@ -0,0 +1,132 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var add4 = require( '@stdlib/number/float64/base/add4' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var quaternary = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Computes the sum of four double-precision complex floating-point numbers. +* +* @private +* @param {Complex128} z1 - first complex number +* @param {Complex128} z2 - second complex number +* @param {Complex128} z3 - third complex number +* @param {Complex128} z4 - fourth complex number +* @returns {Complex128} result +*/ +function zadd4( z1, z2, z3, z4 ) { + var re = real( z1 ) + real( z2 ) + real( z3 ) + real( z4 ); + var im = imag( z1 ) + imag( z2 ) + imag( z3 ) + imag( z4 ); + return new Complex128( re, im ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof quaternary, 'function', 'main export is a function'); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 0-dimensional ndarrays', function test( t ) { + var expected; + var x; + var y; + var z; + var w; + var u; + + x = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); + + y = scalar2ndarray( 3.0, { + 'dtype': 'float64' + }); + + z = scalar2ndarray( 2.0, { + 'dtype': 'float64' + }); + + w = scalar2ndarray( 1.0, { + 'dtype': 'float64' + }); + + u = scalar2ndarray( 0.0, { + 'dtype': 'float64' + }); + + quaternary( [ x, y, z, w, u ], add4 ); + + expected = new Float64Array( [ 11.0 ] ); + t.strictEqual( isSameFloat64Array( getData( u ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 0-dimensional ndarrays (accessors)', function test( t ) { + var expected; + var x; + var y; + var z; + var w; + var u; + + x = scalar2ndarray( new Complex128( 5.0, 5.0 ), { + 'dtype': 'complex128' + }); + + y = scalar2ndarray( new Complex128( 3.0, 3.0 ), { + 'dtype': 'complex128' + }); + + z = scalar2ndarray( new Complex128( 2.0, 2.0 ), { + 'dtype': 'complex128' + }); + + w = scalar2ndarray( new Complex128( 1.0, 1.0 ), { + 'dtype': 'complex128' + }); + + u = scalar2ndarray( new Complex128( 0.0, 0.0 ), { + 'dtype': 'complex128' + }); + + quaternary( [ x, y, z, w, u ], zadd4 ); + + expected = new Complex128Array( [ 11.0, 11.0 ] ); + t.strictEqual( isSameComplex128Array( getData( u ), expected ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/test/test.1d.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/test/test.1d.js new file mode 100644 index 000000000000..58d8b04ceb4f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/test/test.1d.js @@ -0,0 +1,145 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var zeros = require( '@stdlib/array/zeros' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var add4 = require( '@stdlib/number/float64/base/add4' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var quaternary = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Computes the sum of four double-precision complex floating-point numbers. +* +* @private +* @param {Complex128} z1 - first complex number +* @param {Complex128} z2 - second complex number +* @param {Complex128} z3 - third complex number +* @param {Complex128} z4 - fourth complex number +* @returns {Complex128} result +*/ +function zadd4( z1, z2, z3, z4 ) { + var re = real( z1 ) + real( z2 ) + real( z3 ) + real( z4 ); + var im = imag( z1 ) + imag( z2 ) + imag( z3 ) + imag( z4 ); + return new Complex128( re, im ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof quaternary, 'function', 'main export is a function'); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 1-dimensional ndarrays', function test( t ) { + var expected; + var x; + var y; + var z; + var w; + var u; + + x = ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + y = ndarray( 'float64', new Float64Array( [ 1.0, 1.0, 1.0, 1.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + z = ndarray( 'float64', new Float64Array( [ 2.0, 2.0, 2.0, 2.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + w = ndarray( 'float64', new Float64Array( [ 1.0, 1.0, 1.0, 1.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + u = ndarray( 'float64', zeros( 4, 'float64' ), [ 4 ], [ 1 ], 0, 'row-major' ); + + quaternary( [ x, y, z, w, u ], add4 ); + + expected = new Float64Array([ + 5.0, + 6.0, + 7.0, + 8.0 + ]); + t.strictEqual( isSameFloat64Array( getData( u ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 1-dimensional ndarrays (empty arrays)', function test( t ) { + var expected; + var x; + var y; + var z; + var w; + var u; + + x = ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 0 ], [ 1 ], 0, 'row-major' ); + y = ndarray( 'float64', new Float64Array( [ 1.0, 1.0, 1.0, 1.0 ] ), [ 0 ], [ 1 ], 0, 'row-major' ); + z = ndarray( 'float64', new Float64Array( [ 2.0, 2.0, 2.0, 2.0 ] ), [ 0 ], [ 1 ], 0, 'row-major' ); + w = ndarray( 'float64', new Float64Array( [ 1.0, 1.0, 1.0, 1.0 ] ), [ 0 ], [ 1 ], 0, 'row-major' ); + u = ndarray( 'float64', zeros( 4, 'float64' ), [ 0 ], [ 1 ], 0, 'row-major' ); + + quaternary( [ x, y, z, w, u ], add4 ); + + expected = new Float64Array([ + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( getData( u ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 1-dimensional ndarrays (accessors)', function test( t ) { + var expected; + var x; + var y; + var z; + var w; + var u; + + x = ndarray( 'complex128', new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + y = ndarray( 'complex128', new Complex128Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + z = ndarray( 'complex128', new Complex128Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + w = ndarray( 'complex128', new Complex128Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + u = ndarray( 'complex128', zeros( 4, 'complex128' ), [ 4 ], [ 1 ], 0, 'row-major' ); + + quaternary( [ x, y, z, w, u ], zadd4 ); + + expected = new Complex128Array([ + 5.0, + 6.0, + 7.0, + 8.0, + 9.0, + 10.0, + 11.0, + 12.0 + ]); + t.strictEqual( isSameComplex128Array( getData( u ), expected ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/test/test.2d.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/test/test.2d.js new file mode 100644 index 000000000000..0a734978ea21 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/test/test.2d.js @@ -0,0 +1,1076 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var zeros = require( '@stdlib/array/zeros' ); +var oneTo = require( '@stdlib/array/one-to' ); +var ones = require( '@stdlib/array/ones' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var dfill = require( '@stdlib/blas/ext/base/dfill' ); +var zfill = require( '@stdlib/blas/ext/base/zfill' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var add4 = require( '@stdlib/number/float64/base/add4' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var quaternary = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Computes the sum of four double-precision complex floating-point numbers. +* +* @private +* @param {Complex128} z1 - first complex number +* @param {Complex128} z2 - second complex number +* @param {Complex128} z3 - third complex number +* @param {Complex128} z4 - fourth complex number +* @returns {Complex128} result +*/ +function zadd4( z1, z2, z3, z4 ) { + var re = real( z1 ) + real( z2 ) + real( z3 ) + real( z4 ); + var im = imag( z1 ) + imag( z2 ) + imag( z3 ) + imag( z4 ); + return new Complex128( re, im ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof quaternary, 'function', 'main export is a function'); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (row-major, singleton dimensions)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 4, 1 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], add4 ); + + expected = new Float64Array([ + 4.0, + 8.0, + 12.0, + 16.0 + ]); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (row-major, singleton dimensions, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 4, 1 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, new Complex128Array( oneTo( numel( sh ) * 2, 'float64' ) ), sh, st, o, ord ); + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], zadd4 ); + + expected = new Complex128Array([ + 4.0, + 8.0, + 12.0, + 16.0, + 20.0, + 24.0, + 28.0, + 32.0 + ]); + t.strictEqual( isSameComplex128Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (row-major, empty)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 0 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( 2, dt ), sh, st, o, ord ); + y = ndarray( dt, zeros( 2, dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], add4 ); + + expected = new Float64Array([ + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (row-major, contiguous)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], add4 ); + + expected = new Float64Array([ + 4.0, + 8.0, + 12.0, + 16.0 + ]); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (row-major, contiguous, negative strides)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ -2, -1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], add4 ); + + expected = new Float64Array([ + 4.0, + 8.0, + 12.0, + 16.0 + ]); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (row-major, non-contiguous, same sign strides)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ 4, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( 8, dt ), sh, st, o, ord ); + y = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], add4 ); + + expected = new Float64Array([ + 4.0, + 8.0, + 0.0, + 0.0, + 20.0, + 24.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (row-major, non-contiguous, mixed sign strides)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ 4, -1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( 8, dt ), sh, st, o, ord ); + y = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], add4 ); + + expected = new Float64Array([ + 4.0, + 8.0, + 0.0, + 0.0, + 20.0, + 24.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (row-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ bsize*2, 2 ]; + st = [ -4, 2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, ones( numel( sh ) * 2, dt ), sh, st, o, ord ); + y = ndarray( dt, zeros( numel( sh ) * 2, dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], add4 ); + + expected = new Float64Array( x.length*2 ); + dfill( x.length, 4.0, expected, st[ 1 ] ); + + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (row-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 2, bsize*2 ]; + st = [ bsize*4, -2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, ones( numel( sh )*2, dt ), sh, st, o, ord ); + y = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], add4 ); + + expected = new Float64Array( x.length*2 ); + dfill( x.length, 4.0, expected, st[ 1 ] ); + + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (row-major, contiguous, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, new Complex128Array( oneTo( numel( sh ) * 2, 'float64' ) ), sh, st, o, ord ); + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], zadd4 ); + + expected = new Complex128Array([ + 4.0, + 8.0, + 12.0, + 16.0, + 20.0, + 24.0, + 28.0, + 32.0 + ]); + t.strictEqual( isSameComplex128Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (row-major, contiguous, negative strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ -2, -1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, new Complex128Array( oneTo( numel( sh ) * 2, 'float64' ) ), sh, st, o, ord ); + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], zadd4 ); + + expected = new Complex128Array([ + 4.0, + 8.0, + 12.0, + 16.0, + 20.0, + 24.0, + 28.0, + 32.0 + ]); + t.strictEqual( isSameComplex128Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (row-major, non-contiguous, same sign strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ 4, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, new Complex128Array( oneTo( numel( sh ) * 4, 'float64' ) ), sh, st, o, ord ); + y = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], zadd4 ); + + expected = new Complex128Array([ + 4.0, + 8.0, + 12.0, + 16.0, + 0.0, + 0.0, + 0.0, + 0.0, + 36.0, + 40.0, + 44.0, + 48.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameComplex128Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (row-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ 4, -1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, new Complex128Array( oneTo( numel( sh ) * 4, 'float64' ) ), sh, st, o, ord ); + y = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], zadd4 ); + + expected = new Complex128Array([ + 4.0, + 8.0, + 12.0, + 16.0, + 0.0, + 0.0, + 0.0, + 0.0, + 36.0, + 40.0, + 44.0, + 48.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameComplex128Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'complex128'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ bsize*2, 2 ]; + st = [ -4, 2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, new Complex128Array( ones( numel( sh ) * 4, 'float64' ) ), sh, st, o, ord ); + y = ndarray( dt, zeros( numel( sh ) * 2, dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], zadd4 ); + + expected = new Complex128Array( x.length*2 ); + zfill( x.length, new Complex128( 4.0, 4.0 ), expected, st[ 1 ] ); + + t.strictEqual( isSameComplex128Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'complex128'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 2, bsize*2 ]; + st = [ bsize*4, -2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, new Complex128Array( ones( numel( sh ) * 4, 'float64' ) ), sh, st, o, ord ); + y = ndarray( dt, zeros( numel( sh ) * 2, dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], zadd4 ); + + expected = new Complex128Array( x.length*2 ); + zfill( x.length, new Complex128( 4.0, 4.0 ), expected, st[ 1 ] ); + + t.strictEqual( isSameComplex128Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (column-major, singleton dimensions)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 1, 4 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], add4 ); + + expected = new Float64Array([ + 4.0, + 8.0, + 12.0, + 16.0 + ]); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (column-major, singleton dimensions, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 4, 1 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, new Complex128Array( oneTo( numel( sh ) * 2, 'float64' ) ), sh, st, o, ord ); + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], zadd4 ); + + expected = new Complex128Array([ + 4.0, + 8.0, + 12.0, + 16.0, + 20.0, + 24.0, + 28.0, + 32.0 + ]); + t.strictEqual( isSameComplex128Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (column-major, empty)', function test( t ) { + var expected; + var x; + var y; + + x = ndarray( 'float64', oneTo( 4, 'float64' ), [ 0, 0 ], [ 1, 1 ], 0, 'column-major' ); + y = ndarray( 'float64', zeros( 4, 'float64' ), [ 0, 0 ], [ 1, 1 ], 0, 'column-major' ); + + quaternary( [ x, x, x, x, y ], add4 ); + + expected = new Float64Array([ + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (column-major, contiguous)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], add4 ); + + expected = new Float64Array([ + 4.0, + 8.0, + 12.0, + 16.0 + ]); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (column-major, contiguous, negative strides)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ -1, -2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], add4 ); + + expected = new Float64Array([ + 4.0, + 8.0, + 12.0, + 16.0 + ]); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (column-major, non-contiguous, same sign strides)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ 1, 4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( 8, dt ), sh, st, o, ord ); + y = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], add4 ); + + expected = new Float64Array([ + 4.0, + 8.0, + 0.0, + 0.0, + 20.0, + 24.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (column-major, non-contiguous, mixed sign strides)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ 1, -4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( 8, dt ), sh, st, o, ord ); + y = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], add4 ); + + expected = new Float64Array([ + 4.0, + 8.0, + 0.0, + 0.0, + 20.0, + 24.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (column-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ bsize*2, 2 ]; + st = [ 2, -bsize*4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, ones( numel( sh )*2, dt ), sh, st, o, ord ); + y = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], add4 ); + + expected = new Float64Array( x.length*2 ); + dfill( x.length, 4.0, expected, st[ 0 ] ); + + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (column-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ 2, bsize*2 ]; + st = [ -2, 4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, ones( numel( sh )*2, dt ), sh, st, o, ord ); + y = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], add4 ); + + expected = new Float64Array( x.length*2 ); + dfill( x.length, 4.0, expected, st[ 0 ] ); + + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (column-major, contiguous, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, new Complex128Array( oneTo( numel( sh ) * 2, 'float64' ) ), sh, st, o, ord ); + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], zadd4 ); + + expected = new Complex128Array([ + 4.0, + 8.0, + 12.0, + 16.0, + 20.0, + 24.0, + 28.0, + 32.0 + ]); + t.strictEqual( isSameComplex128Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (column-major, contiguous, negative strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ -1, -2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, new Complex128Array( oneTo( numel( sh ) * 2, 'float64' ) ), sh, st, o, ord ); + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], zadd4 ); + + expected = new Complex128Array([ + 4.0, + 8.0, + 12.0, + 16.0, + 20.0, + 24.0, + 28.0, + 32.0 + ]); + t.strictEqual( isSameComplex128Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (column-major, non-contiguous, same sign strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ 1, 4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, new Complex128Array( oneTo( numel( sh ) * 4, 'float64' ) ), sh, st, o, ord ); + y = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], zadd4 ); + + expected = new Complex128Array([ + 4.0, + 8.0, + 12.0, + 16.0, + 0.0, + 0.0, + 0.0, + 0.0, + 36.0, + 40.0, + 44.0, + 48.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameComplex128Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (column-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ 1, -4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, new Complex128Array( oneTo( numel( sh ) * 4, 'float64' ) ), sh, st, o, ord ); + y = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], zadd4 ); + + expected = new Complex128Array([ + 4.0, + 8.0, + 12.0, + 16.0, + 0.0, + 0.0, + 0.0, + 0.0, + 36.0, + 40.0, + 44.0, + 48.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameComplex128Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'complex128'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ bsize*2, 2 ]; + st = [ 2, -bsize*4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, new Complex128Array( ones( numel( sh ) * 4, 'float64' ) ), sh, st, o, ord ); + y = ndarray( dt, zeros( numel( sh ) * 2, dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], zadd4 ); + + expected = new Complex128Array( x.length*2 ); + zfill( x.length, new Complex128( 4.0, 4.0 ), expected, st[ 0 ] ); + + t.strictEqual( isSameComplex128Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a quaternary callback to indexed elements of four 2-dimensional ndarrays (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'complex128'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ 2, bsize*2 ]; + st = [ -2, 4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, new Complex128Array( ones( numel( sh ) * 4, 'float64' ) ), sh, st, o, ord ); + y = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + quaternary( [ x, x, x, x, y ], zadd4 ); + + expected = new Complex128Array( x.length*2 ); + zfill( x.length, new Complex128( 4.0, 4.0 ), expected, st[ 0 ] ); + + t.strictEqual( isSameComplex128Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/test/test.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/test/test.js new file mode 100644 index 000000000000..3e90d099a0ff --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/test/test.js @@ -0,0 +1,168 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/array/zeros' ); +var ones = require( '@stdlib/array/ones' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var add4 = require( '@stdlib/number/float64/base/add4' ); +var quaternary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof quaternary, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided input and output ndarrays which do not have the same number of dimensions', function test( t ) { + var shapes; + var i; + + shapes = [ + [ [ 4, 2, 1 ], [ 4, 2, 1 ], [ 4, 2, 1 ], [ 4, 2, 1 ], [ 4, 2 ] ], + [ [ 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], + [ [ 1, 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1 ], [ 1, 1 ] ], + [ [ 2, 2, 1, 2 ], [ 2, 2, 1 ], [ 2, 2, 1 ], [ 2, 1, 2 ], [ 2, 1, 2 ] ], + [ [ 1, 1, 4, 2, 2, 2 ], [ 0 ], [ 10, 2 ], [ 10, 2 ], [ 10, 2 ] ], + [ [ 1, 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1, 1, 1 ], [ 1, 1, 1, 1, 1 ] ] + ]; + + for ( i = 0; i < shapes.length; i++ ) { + t.throws( badValue( shapes[i][0], shapes[i][1], shapes[i][2], shapes[i][3], shapes[i][4] ), Error, 'throws an error for index ' + i ); + } + t.end(); + + function badValue( sh1, sh2, sh3, sh4, sh5 ) { + return function badValue() { + var dtype; + var ord; + var st1; + var st2; + var st3; + var st4; + var st5; + var o1; + var o2; + var o3; + var o4; + var o5; + var x; + var y; + var z; + var w; + var u; + + ord = 'row-major'; + dtype = 'float64'; + + st1 = shape2strides( sh1, ord ); + st2 = shape2strides( sh2, ord ); + st3 = shape2strides( sh3, ord ); + st4 = shape2strides( sh4, ord ); + st5 = shape2strides( sh5, ord ); + o1 = strides2offset( sh1, st1 ); + o2 = strides2offset( sh2, st2 ); + o3 = strides2offset( sh3, st3 ); + o4 = strides2offset( sh4, st4 ); + o5 = strides2offset( sh5, st5 ); + + x = ndarray( dtype, ones( numel( sh1 ), dtype ), sh1, st1, o1, ord ); + y = ndarray( dtype, ones( numel( sh2 ), dtype ), sh2, st2, o2, ord ); + z = ndarray( dtype, ones( numel( sh3 ), dtype ), sh3, st3, o3, ord ); + w = ndarray( dtype, zeros( numel( sh4 ), dtype ), sh4, st4, o4, ord ); + u = ndarray( dtype, zeros( numel( sh5 ), dtype ), sh5, st5, o5, ord ); + + quaternary( [ x, y, z, w, u ], add4 ); + }; + } +}); + +tape( 'the function throws an error if provided input and output ndarrays which do not have the same shape', function test( t ) { + var shapes; + var i; + + shapes = [ + [ [ 4, 2, 1 ], [ 4, 2, 2 ], [ 4, 2, 1 ], [ 4, 2, 1 ], [ 4, 2, 1 ] ], + [ [ 3, 3 ], [ 2, 2 ], [ 3, 3 ], [ 3, 3 ], [ 3, 3 ] ], + [ [ 5, 5, 5 ], [ 5, 5, 4 ], [ 5, 5, 4 ], [ 5, 5, 4 ], [ 5, 5, 4 ] ], + [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 1, 1, 2 ], [ 1, 1, 2 ], [ 1, 1, 2 ] ], + [ [ 1, 4 ], [ 3, 8 ], [ 4, 4 ], [ 4, 4 ], [ 4, 4 ] ], + [ [ 10, 2, 1 ], [ 1, 2, 10 ], [ 2, 1, 10 ], [ 2, 1, 10 ], [ 2, 1, 10 ] ] + ]; + + for ( i = 0; i < shapes.length; i++ ) { + t.throws( badValue( shapes[i][0], shapes[i][1], shapes[i][2], shapes[i][3], shapes[i][4] ), Error, 'throws an error for index ' + i ); + } + t.end(); + + function badValue( sh1, sh2, sh3, sh4, sh5 ) { + return function badValue() { + var dtype; + var ord; + var st1; + var st2; + var st3; + var st4; + var st5; + var o1; + var o2; + var o3; + var o4; + var o5; + var x; + var y; + var z; + var w; + var u; + + ord = 'row-major'; + dtype = 'float64'; + + st1 = shape2strides( sh1, ord ); + st2 = shape2strides( sh2, ord ); + st3 = shape2strides( sh3, ord ); + st4 = shape2strides( sh4, ord ); + st5 = shape2strides( sh5, ord ); + o1 = strides2offset( sh1, st1 ); + o2 = strides2offset( sh2, st2 ); + o3 = strides2offset( sh3, st3 ); + o4 = strides2offset( sh4, st4 ); + o5 = strides2offset( sh5, st5 ); + + x = ndarray( dtype, ones( numel( sh1 ), dtype ), sh1, st1, o1, ord ); + y = ndarray( dtype, ones( numel( sh2 ), dtype ), sh2, st2, o2, ord ); + z = ndarray( dtype, ones( numel( sh3 ), dtype ), sh3, st3, o3, ord ); + w = ndarray( dtype, zeros( numel( sh4 ), dtype ), sh4, st4, o4, ord ); + u = ndarray( dtype, zeros( numel( sh5 ), dtype ), sh5, st5, o5, ord ); + + quaternary( [ x, y, z, w, u ], add4 ); + }; + } +}); From dff8313f2b313c1343d692f08a0aad57ad82c065 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Fri, 30 Jan 2026 20:08:54 +0500 Subject: [PATCH 2/4] docs: apply suggestion from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/ndarray/base/quaternary/lib/nd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/nd.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/nd.js index aedd49c7d6f1..d59e652d40da 100644 --- a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/nd.js +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/nd.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 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. From 15978e0219b8615505b182be518518ae3e3911b2 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Fri, 30 Jan 2026 20:09:21 +0500 Subject: [PATCH 3/4] docs: apply suggestion from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../@stdlib/ndarray/base/quaternary/lib/nd_accessors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/nd_accessors.js b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/nd_accessors.js index 98f7e4b2e40b..abca4a594258 100644 --- a/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/nd_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/lib/nd_accessors.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 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. From 2c579fef6934c38085268b0a2601e92f780c7e73 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Fri, 30 Jan 2026 20:29:19 +0500 Subject: [PATCH 4/4] fix: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/ndarray/base/quaternary/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/ndarray/base/quaternary/package.json b/lib/node_modules/@stdlib/ndarray/base/quaternary/package.json index d2cc5dd53f2f..e55e16b308ae 100644 --- a/lib/node_modules/@stdlib/ndarray/base/quaternary/package.json +++ b/lib/node_modules/@stdlib/ndarray/base/quaternary/package.json @@ -15,6 +15,7 @@ ], "main": "./lib", "directories": { + "benchmark": "./benchmark", "doc": "./docs", "example": "./examples", "lib": "./lib",