diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/README.md b/lib/node_modules/@stdlib/ndarray/base/ternary/README.md new file mode 100644 index 000000000000..1e06350980e0 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/README.md @@ -0,0 +1,231 @@ + + +# Ternary + +> Apply a ternary callback to elements in input ndarrays and assign results to elements in an output ndarray. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var ternary = require( '@stdlib/ndarray/base/ternary' ); +``` + +#### ternary( arrays, fcn ) + +Applies a ternary callback to elements in input ndarrays and assigns results to elements in an output ndarray. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var add3 = require( '@stdlib/number/float64/base/add3' ); + +// 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +var wbuf = 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 ]; + +// Define the index offsets: +var ox = 0; +var oy = 0; +var oz = 0; +var ow = 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' +}; + +// Apply the ternary function: +ternary( [ x, y, z, w ], add3 ); + +console.log( w.data ); +// => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5 ] +``` + +The function accepts the following arguments: + +- **arrays**: array-like object containing three input ndarrays and one output ndarray. +- **fcn**: ternary 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 ternary 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 add3 = require( '@stdlib/number/float64/base/add3' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var ternary = require( '@stdlib/ndarray/base/ternary' ); + +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': filledarray( 0, N, 'generic' ), + 'shape': x.shape.slice(), + 'strides': shape2strides( x.shape, 'column-major' ), + 'offset': 0, + 'order': 'column-major' +}; + +ternary( [ x, y, z, w ], add3 ); +console.log( ndarray2array( w.data, w.shape, w.strides, w.offset, w.order ) ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/benchmark/benchmark.1d.js b/lib/node_modules/@stdlib/ndarray/base/ternary/benchmark/benchmark.1d.js new file mode 100644 index 000000000000..c29e03853657 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/benchmark/benchmark.1d.js @@ -0,0 +1,170 @@ +/** +* @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 add3 = require( '@stdlib/number/float64/base/add3' ); +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 ternary = 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} wtype - output ndarray data type +* @param {string} order - memory layout +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, wtype, order ) { + var x; + var y; + var z; + var w; + + x = discreteUniform( len, -100, 100, { + 'dtype': xtype + }); + y = discreteUniform( len, -100, 100, { + 'dtype': xtype + }); + z = discreteUniform( len, -100, 100, { + 'dtype': xtype + }); + w = filledarray( 0.0, len, wtype ); + + 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': wtype, + 'data': w, + '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++ ) { + ternary( [ x, y, z, w ], add3 ); + 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/ternary/benchmark/benchmark.2d.js b/lib/node_modules/@stdlib/ndarray/base/ternary/benchmark/benchmark.2d.js new file mode 100644 index 000000000000..77dfff3ccfe5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/benchmark/benchmark.2d.js @@ -0,0 +1,186 @@ +/** +* @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 add3 = require( '@stdlib/number/float64/base/add3' ); +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 ternary = 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} wtype - output ndarray data type +* @param {string} order - memory layout +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, wtype, order ) { + var isrm; + var x; + var y; + var z; + var w; + + 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 = filledarray( 0.0, len, wtype ); + + 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': wtype, + 'data': w, + '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++ ) { + ternary( x, y, z, w, isrm, add3 ); + 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/ternary/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/ternary/docs/repl.txt new file mode 100644 index 000000000000..218a7f800ac7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/docs/repl.txt @@ -0,0 +1,92 @@ + +{{alias}}( arrays, fcn ) + Applies a ternary 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 three input ndarrays and one output + ndarray. + + fcn: Function + Ternary 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}}( [ 0.5, 0.5, 0.5, 0.5 ] ); + > var wbuf = 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 ox = 0; + > var oy = 0; + > var oz = 0; + > var ow = 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 ); + > {{alias}}( [ x, y, z, w ], {{alias:@stdlib/number/float64/base/add3}} ); + > {{alias:@stdlib/ndarray/data-buffer}}( w ) + [ 6.5, 8.5, 10.5, 12.5 ] + + // 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 + ... }; + > {{alias}}( [ x, y, w, z ], {{alias:@stdlib/number/float64/base/add3}} ); + > {{alias:@stdlib/ndarray/data-buffer}}( w ) + [ 6.5, 8.5, 10.5, 12.5 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/ternary/docs/types/index.d.ts new file mode 100644 index 000000000000..982a5cd0eabb --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/docs/types/index.d.ts @@ -0,0 +1,88 @@ +/* +* @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 +* @returns result +*/ +type Ternary = ( x: any, y: any, z: any ) => any; + +/** +* Applies a ternary callback to elements in input ndarrays and assigns results to elements in an output ndarray. +* +* @param arrays - array-like object containing three input ndarrays and one output ndarray +* @param fcn - ternary callback +* @throws arrays must have the same number of dimensions +* @throws arrays must have the same shape +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var getData = require( '@stdlib/ndarray/data-buffer' ); +* var add3 = require( '@stdlib/number/float64/base/add3' ); +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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' ); +* +* // Apply the ternary function: +* ternary( [ x, y, z, w ], add3 ); +* +* console.log( getData( w ) ); +* // => [ 2.5, 4.5, 6.5, 8.5, 10.5, 12.5 ] +*/ +declare function ternary( arrays: ArrayLike, fcn: Ternary ): void; + + +// EXPORTS // + +export = ternary; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/ternary/docs/types/test.ts new file mode 100644 index 000000000000..b6dfa130544e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/docs/types/test.ts @@ -0,0 +1,78 @@ +/* +* @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 add3 = require( '@stdlib/number/float64/base/add3' ); +import ternary = 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 arrays = [ x, y, z, w ]; + + ternary( arrays, add3 ); // $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... +{ + ternary( 5, add3 ); // $ExpectError + ternary( true, add3 ); // $ExpectError + ternary( false, add3 ); // $ExpectError + ternary( null, add3 ); // $ExpectError + ternary( undefined, add3 ); // $ExpectError + ternary( {}, add3 ); // $ExpectError + ternary( [ 1 ], add3 ); // $ExpectError + ternary( ( x: number ): number => x, add3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a ternary function... +{ + const x = zeros( [ 2, 2 ] ); + const y = zeros( [ 2, 2 ] ); + const z = zeros( [ 2, 2 ] ); + const w = zeros( [ 2, 2 ] ); + const arrays = [ x, y, z, w ]; + + ternary( arrays, '10' ); // $ExpectError + ternary( arrays, 5 ); // $ExpectError + ternary( arrays, true ); // $ExpectError + ternary( arrays, false ); // $ExpectError + ternary( arrays, null ); // $ExpectError + ternary( arrays, undefined ); // $ExpectError + ternary( arrays, [] ); // $ExpectError + ternary( 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 arrays = [ x, y, z, w ]; + + ternary(); // $ExpectError + ternary( arrays ); // $ExpectError + ternary( arrays, add3, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/ternary/examples/index.js new file mode 100644 index 000000000000..c2dfcb3e639d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/examples/index.js @@ -0,0 +1,70 @@ +/** +* @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 add3 = require( '@stdlib/number/float64/base/add3' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var ternary = 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': filledarray( 0, N, 'generic' ), + 'shape': x.shape.slice(), + 'strides': shape2strides( x.shape, 'column-major' ), + 'offset': 0, + 'order': 'column-major' +}; + +ternary( [ x, y, z, w ], add3 ); +console.log( ndarray2array( w.data, w.shape, w.strides, w.offset, w.order ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/0d.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/0d.js new file mode 100644 index 000000000000..70d0c6d76156 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/0d.js @@ -0,0 +1,133 @@ +/** +* @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 ternary callback to elements in 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 intput 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 output 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 {Callback} fcn - ternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c ) { +* return a + b + c; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 2.0 ] ); +* var ybuf = new Float64Array( [ 3.0 ] ); +* var zbuf = new Float64Array( [ 4.0 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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' +* }; +* +* // Apply the ternary function: +* ternary0d( x, y, z, w, fcn ); +* +* console.log( w.data ); +* // => [ 9.0 ] +*/ +function ternary0d( x, y, z, w, fcn ) { + w.data[ w.offset ] = fcn( x.data[ x.offset ], y.data[ y.offset ], z.data[ z.offset ] ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = ternary0d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/0d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/0d_accessors.js new file mode 100644 index 000000000000..e8f4ab54852e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/0d_accessors.js @@ -0,0 +1,152 @@ +/** +* @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 ternary callback to elements in 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 output 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 {Callback} fcn - ternary 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 ) { +* return a + b + c; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( [ 1.0 ] ); +* var ybuf = toAccessorArray( [ 2.0 ] ); +* var zbuf = toAccessorArray( [ 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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 +* }; +* +* // Apply the ternary function: +* ternary0d( x, y, z, w, fcn ); +* +* var v = w.data.get( 0 ); +* // returns 3.5 +*/ +function ternary0d( x, y, z, w, fcn ) { + var xget; + var yget; + var zget; + var wset; + + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = z.accessors[ 0 ]; + wset = w.accessors[ 1 ]; + + wset( w.data, w.offset, fcn( xget( x.data, x.offset ), yget( y.data, y.offset ), zget( z.data, z.offset ) ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = ternary0d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/10d.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/10d.js new file mode 100644 index 000000000000..06d6110b5b3c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/10d.js @@ -0,0 +1,396 @@ +/** +* @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 ternary 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 output 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 {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - ternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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' +* }; +* +* // Apply the ternary function: +* ternary10d( x, y, z, w, true, fcn ); +* +* console.log( w.data ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5 ] +*/ +function ternary10d( x, y, z, w, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var wbuf; + var zbuf; + 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 dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dw6; + var dw7; + var dw8; + var dw9; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dz6; + var dz7; + var dz8; + var dz9; + 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 sw; + var sz; + var ix; + var iy; + var iw; + var iz; + 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#, dw#, dz#, 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; + 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] ); + 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] ); + 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] ); + } 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] ); + 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] ); + 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] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.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++ ) { + wbuf[ iw ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ] ); + ix += dx0; + iy += dy0; + iw += dw0; + iz += dz0; + } + ix += dx1; + iy += dy1; + iw += dw1; + iz += dz1; + } + ix += dx2; + iy += dy2; + iw += dw2; + iz += dz2; + } + ix += dx3; + iy += dy3; + iw += dw3; + iz += dz3; + } + ix += dx4; + iy += dy4; + iw += dw4; + iz += dz4; + } + ix += dx5; + iy += dy5; + iw += dw5; + iz += dz5; + } + ix += dx6; + iy += dy6; + iw += dw6; + iz += dz6; + } + ix += dx7; + iy += dy7; + iw += dw7; + iz += dz7; + } + ix += dx8; + iy += dy8; + iw += dw8; + iz += dz8; + } + ix += dx9; + iy += dy9; + iw += dw9; + iz += dz9; + } +} + + +// EXPORTS // + +module.exports = ternary10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/10d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/10d_accessors.js new file mode 100644 index 000000000000..f722a16f9e77 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/10d_accessors.js @@ -0,0 +1,416 @@ +/** +* @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 ternary 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 output 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 {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 ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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 +* }; +* +* // Apply the ternary function: +* ternary10d( x, y, z, w, true, fcn ); +* +* console.log( copy( w.data ) ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5 ] +*/ +function ternary10d( x, y, z, w, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var wbuf; + var zbuf; + var xget; + var yget; + var zget; + var wset; + 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 dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dw6; + var dw7; + var dw8; + var dw9; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dz6; + var dz7; + var dz8; + var dz9; + 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 sw; + var sz; + var ix; + var iy; + var iw; + var iz; + 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#, dw#, dz#, 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; + 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] ); + 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] ); + 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] ); + } 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] ); + 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] ); + 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] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache accessors: + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = w.accessors[ 0 ]; + wset = z.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++ ) { + wset( wbuf, iw, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iw += dw0; + iz += dz0; + } + ix += dx1; + iy += dy1; + iw += dw1; + iz += dz1; + } + ix += dx2; + iy += dy2; + iw += dw2; + iz += dz2; + } + ix += dx3; + iy += dy3; + iw += dw3; + iz += dz3; + } + ix += dx4; + iy += dy4; + iw += dw4; + iz += dz4; + } + ix += dx5; + iy += dy5; + iw += dw5; + iz += dz5; + } + ix += dx6; + iy += dy6; + iw += dw6; + iz += dz6; + } + ix += dx7; + iy += dy7; + iw += dw7; + iz += dz7; + } + ix += dx8; + iy += dy8; + iw += dw8; + iz += dz8; + } + ix += dx9; + iy += dy9; + iw += dw9; + iz += dz9; + } +} + + +// EXPORTS // + +module.exports = ternary10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/10d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/10d_blocked.js new file mode 100644 index 000000000000..c57a90daa564 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/10d_blocked.js @@ -0,0 +1,529 @@ +/** +* @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/ternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a ternary 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 output 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 {Callback} fcn - ternary callback +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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' +* }; +* +* // Apply the ternary function: +* blockedternary10d( x, y, z, w, fcn ); +* +* console.log( w.data ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5 ] +*/ +function blockedternary10d( x, y, z, w, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + 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 ox1; + var oy1; + var oz1; + var ow1; + var ox2; + var oy2; + var oz2; + var ow2; + var ox3; + var oy3; + var oz3; + var ow3; + var ox4; + var oy4; + var oz4; + var ow4; + var ox5; + var oy5; + var oz5; + var ow5; + var ox6; + var oy6; + var oz6; + var ow6; + var ox7; + var oy7; + var oz7; + var ow7; + var ox8; + var oy8; + var oz8; + var ow8; + var ox9; + var oy9; + var oz9; + var ow9; + 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 ox; + var oy; + var oz; + var ow; + var ix; + var iy; + var iz; + var iw; + 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#, 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 ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.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; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[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] ); + for ( j8 = sh[8]; j8 > 0; ) { + if ( j8 < bsize ) { + s8 = j8; + j8 = 0; + } else { + s8 = bsize; + j8 -= bsize; + } + ox8 = ox9 + ( j8*sx[8] ); + oy8 = oy9 + ( j8*sy[8] ); + oz8 = oz9 + ( j8*sz[8] ); + ow8 = ow9 + ( j8*sw[8] ); + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + ox7 = ox8 + ( j7*sx[7] ); + oy7 = oy8 + ( j7*sy[7] ); + oz7 = oz8 + ( j7*sz[7] ); + ow7 = ow8 + ( j7*sw[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + ox6 = ox7 + ( j6*sx[6] ); + oy6 = oy7 + ( j6*sy[6] ); + oz6 = oz7 + ( j6*sz[6] ); + ow6 = ow7 + ( j6*sw[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + ox5 = ox6 + ( j5*sx[5] ); + oy5 = oy6 + ( j5*sy[5] ); + oz5 = oz6 + ( j5*sz[5] ); + ow5 = ow6 + ( j5*sw[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oz4 = oz5 + ( j4*sz[4] ); + ow4 = ow5 + ( j4*sw[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oz3 = oz4 + ( j3*sz[3] ); + ow3 = ow4 + ( j3*sw[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[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] ); + + // 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] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + dz4 = sz[4] - ( s3*sz[3] ); + dw4 = sw[4] - ( s3*sw[3] ); + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + dz5 = sz[5] - ( s4*sz[4] ); + dw5 = sw[5] - ( s4*sw[4] ); + dx6 = sx[6] - ( s5*sx[5] ); + dy6 = sy[6] - ( s5*sy[5] ); + dz6 = sz[6] - ( s5*sz[5] ); + dw6 = sw[6] - ( s5*sw[5] ); + dx7 = sx[7] - ( s6*sx[6] ); + dy7 = sy[7] - ( s6*sy[6] ); + dz7 = sz[7] - ( s6*sz[6] ); + dw7 = sw[7] - ( s6*sw[6] ); + dx8 = sx[8] - ( s7*sx[7] ); + dy8 = sy[8] - ( s7*sy[7] ); + dz8 = sz[8] - ( s7*sz[7] ); + dw8 = sw[8] - ( s7*sw[7] ); + dx9 = sx[9] - ( s8*sx[8] ); + dy9 = sy[9] - ( s8*sy[8] ); + dz9 = sz[9] - ( s8*sz[8] ); + dw9 = sw[9] - ( s8*sw[8] ); + + // 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++ ) { + wbuf[ iw ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ] ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + } + ix += dx6; + iy += dy6; + iz += dz6; + iw += dw6; + } + ix += dx7; + iy += dy7; + iz += dz7; + iw += dw7; + } + ix += dx8; + iy += dy8; + iz += dz8; + iw += dw8; + } + ix += dx9; + iy += dy9; + iz += dz9; + iw += dw9; + } + } + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedternary10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/10d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/10d_blocked_accessors.js new file mode 100644 index 000000000000..74decee115c5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/10d_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 */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/ternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a ternary 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 output 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 {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 ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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, 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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 +* }; +* +* // Apply the ternary function: +* blockedternary10d( x, y, z, w, fcn ); +* +* console.log( copy( w.data ) ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5 ] +*/ +function blockedternary10d( x, y, z, w, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var xget; + var yget; + var zget; + var wset; + 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 ox1; + var oy1; + var oz1; + var ow1; + var ox2; + var oy2; + var oz2; + var ow2; + var ox3; + var oy3; + var oz3; + var ow3; + var ox4; + var oy4; + var oz4; + var ow4; + var ox5; + var oy5; + var oz5; + var ow5; + var ox6; + var oy6; + var oz6; + var ow6; + var ox7; + var oy7; + var oz7; + var ow7; + var ox8; + var oy8; + var oz8; + var ow8; + var ox9; + var oy9; + var oz9; + var ow9; + 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 ox; + var oy; + var oz; + var ow; + var ix; + var iy; + var iz; + var iw; + 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#, 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 ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.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; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + + // Cache accessors: + xget = x.accessors[0]; + yget = y.accessors[0]; + zget = z.accessors[0]; + wset = w.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] ); + for ( j8 = sh[8]; j8 > 0; ) { + if ( j8 < bsize ) { + s8 = j8; + j8 = 0; + } else { + s8 = bsize; + j8 -= bsize; + } + ox8 = ox9 + ( j8*sx[8] ); + oy8 = oy9 + ( j8*sy[8] ); + oz8 = oz9 + ( j8*sz[8] ); + ow8 = ow9 + ( j8*sw[8] ); + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + ox7 = ox8 + ( j7*sx[7] ); + oy7 = oy8 + ( j7*sy[7] ); + oz7 = oz8 + ( j7*sz[7] ); + ow7 = ow8 + ( j7*sw[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + ox6 = ox7 + ( j6*sx[6] ); + oy6 = oy7 + ( j6*sy[6] ); + oz6 = oz7 + ( j6*sz[6] ); + ow6 = ow7 + ( j6*sw[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + ox5 = ox6 + ( j5*sx[5] ); + oy5 = oy6 + ( j5*sy[5] ); + oz5 = oz6 + ( j5*sz[5] ); + ow5 = ow6 + ( j5*sw[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oz4 = oz5 + ( j4*sz[4] ); + ow4 = ow5 + ( j4*sw[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oz3 = oz4 + ( j3*sz[3] ); + ow3 = ow4 + ( j3*sw[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[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] ); + + // 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] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + dz4 = sz[4] - ( s3*sz[3] ); + dw4 = sw[4] - ( s3*sw[3] ); + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + dz5 = sz[5] - ( s4*sz[4] ); + dw5 = sw[5] - ( s4*sw[4] ); + dx6 = sx[6] - ( s5*sx[5] ); + dy6 = sy[6] - ( s5*sy[5] ); + dz6 = sz[6] - ( s5*sz[5] ); + dw6 = sw[6] - ( s5*sw[5] ); + dx7 = sx[7] - ( s6*sx[6] ); + dy7 = sy[7] - ( s6*sy[6] ); + dz7 = sz[7] - ( s6*sz[6] ); + dw7 = sw[7] - ( s6*sw[6] ); + dx8 = sx[8] - ( s7*sx[7] ); + dy8 = sy[8] - ( s7*sy[7] ); + dz8 = sz[8] - ( s7*sz[7] ); + dw8 = sw[8] - ( s7*sw[7] ); + dx9 = sx[9] - ( s8*sx[8] ); + dy9 = sy[9] - ( s8*sy[8] ); + dz9 = sz[9] - ( s8*sz[8] ); + dw9 = sw[9] - ( s8*sw[8] ); + + // 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++ ) { + wset( wbuf, iw, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + } + ix += dx6; + iy += dy6; + iz += dz6; + iw += dw6; + } + ix += dx7; + iy += dy7; + iz += dz7; + iw += dw7; + } + ix += dx8; + iy += dy8; + iz += dz8; + iw += dw8; + } + ix += dx9; + iy += dy9; + iz += dz9; + iw += dw9; + } + } + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedternary10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/1d.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/1d.js new file mode 100644 index 000000000000..6a89ebf3850f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/1d.js @@ -0,0 +1,176 @@ +/** +* @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 ternary callback to elements in 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 output 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 {Callback} fcn - ternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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' +* }; +* +* // Apply the ternary function: +* ternary1d( x, y, z, w, fcn ); +* +* console.log( w.data ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5 ] +*/ +function ternary1d( x, y, z, w, fcn ) { + var xbuf; + var ybuf; + var wbuf; + var zbuf; + var dx; + var dy; + var dw; + var dz; + var S0; + var ix; + var iy; + var iw; + var iz; + var i; + + // Note on variable naming convention: S#, 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... + S0 = x.shape[ 0 ]; + dx = x.strides[ 0 ]; + dy = y.strides[ 0 ]; + dz = z.strides[ 0 ]; + dw = w.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; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Iterate over the ndarray dimensions... + for ( i = 0; i < S0; i++ ) { + wbuf[ iw ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ] ); + ix += dx; + iy += dy; + iz += dz; + iw += dw; + } +} + + +// EXPORTS // + +module.exports = ternary1d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/1d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/1d_accessors.js new file mode 100644 index 000000000000..09771a9a1ccd --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/1d_accessors.js @@ -0,0 +1,192 @@ +/** +* @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 ternary callback to elements in one-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray via loop interchange. +* +* @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 intput 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 output 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 {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 ) { +* return a + b + c; +* } +* +* // Create data buffers: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0 ] ); +* var ybuf = toAccessorArray( [ 1.0, 1.0, 1.0 ] ); +* var zbuf = toAccessorArray( [ 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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 +* }; +* +* // Apply the ternary function: +* ternary1d( x, y, z, w, fcn ); +* +* console.log( copy( w.data ) ); +* // => [ 2.5, 3.5, 4.5 ] +*/ +function ternary1d( x, y, z, w, fcn ) { + var xbuf; + var ybuf; + var wbuf; + var zbuf; + var xget; + var yget; + var zget; + var wset; + var dx; + var dy; + var dw; + var dz; + var S0; + var ix; + var iy; + var iw; + var iz; + var i; + + // Note on variable naming convention: S#, 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... + S0 = x.shape[ 0 ]; + dx = x.strides[ 0 ]; + dy = y.strides[ 0 ]; + dz = z.strides[ 0 ]; + dw = w.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; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache accessors: + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = z.accessors[ 0 ]; + wset = w.accessors[ 1 ]; + + // Iterate over the ndarray dimensions... + for ( i = 0; i < S0; i++ ) { + wset( wbuf, iw, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ) ) ); // eslint-disable-line max-len + ix += dx; + iy += dy; + iz += dz; + iw += dw; + } +} + + +// EXPORTS // + +module.exports = ternary1d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/2d.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/2d.js new file mode 100644 index 000000000000..44306c38e8c3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/2d.js @@ -0,0 +1,218 @@ +/** +* @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 ternary 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 output 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 {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - ternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = new Float64Array( 12 ); +* +* // 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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' +* }; +* +* // Apply the ternary function: +* ternary2d( x, y, z, w, true, fcn ); +* +* console.log( w.data ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5 ] +*/ +function ternary2d( x, y, z, w, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var dx0; + var dx1; + var dy0; + var dy1; + var dz0; + var dz1; + var dw0; + var dw1; + var sh; + var S0; + var S1; + var sx; + var sy; + var sz; + var sw; + var ix; + var iy; + var iz; + var iw; + var i0; + var i1; + + // Note on variable naming convention: S#, dx#, dy#, dz#, dw#, 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; + 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] ); + } 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] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Iterate over the ndarray dimensions... + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + wbuf[ iw ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ] ); + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + } +} + + +// EXPORTS // + +module.exports = ternary2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/2d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/2d_accessors.js new file mode 100644 index 000000000000..1970f92efec3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/2d_accessors.js @@ -0,0 +1,238 @@ +/** +* @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 ternary 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 output 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 {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 ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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 +* }; +* +* // Apply the ternary function: +* ternary2d( x, y, z, w, true, fcn ); +* +* console.log( copy( w.data ) ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5 ] +*/ +function ternary2d( x, y, z, w, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var wbuf; + var zbuf; + var xget; + var yget; + var zget; + var wset; + var dx0; + var dx1; + var dy0; + var dy1; + var dw0; + var dw1; + var dz0; + var dz1; + var sh; + var S0; + var S1; + var sx; + var sy; + var sw; + var sz; + var ix; + var iy; + var iw; + var iz; + var i0; + var i1; + + // Note on variable naming convention: S#, dx#, dy#, dw#, dz#, 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; + 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] ); + dw0 = sw[ 1 ]; + dw1 = sw[ 0 ] - ( S0*sw[1] ); + dz0 = sz[ 1 ]; + dz1 = sz[ 0 ] - ( S0*sz[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] ); + dw0 = sw[ 0 ]; + dw1 = sw[ 1 ] - ( S0*sw[0] ); + dz0 = sz[ 0 ]; + dz1 = sz[ 1 ] - ( S0*sz[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; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache accessors: + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = z.accessors[ 0 ]; + wset = w.accessors[ 1 ]; + + // Iterate over the ndarray dimensions... + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + wset( wbuf, iw, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iw += dw0; + iz += dz0; + } + ix += dx1; + iy += dy1; + iw += dw1; + iz += dz1; + } +} + + +// EXPORTS // + +module.exports = ternary2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/2d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/2d_blocked.js new file mode 100644 index 000000000000..d8b4b5b79ccb --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/2d_blocked.js @@ -0,0 +1,255 @@ +/** +* @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 loopOrder = require( '@stdlib/ndarray/base/ternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a ternary 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 intput 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 output 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 {Callback} fcn - ternary callback +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = new Float64Array( 12 ); +* +* // 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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' +* }; +* +* // Apply the ternary function: +* blockedternary2d( x, y, z, w, fcn ); +* +* console.log( w.data ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5 ] +*/ +function blockedternary2d( x, y, z, w, fcn ) { + var bsize; + var xbuf; + var ybuf; + var wbuf; + var zbuf; + var dx0; + var dx1; + var dy0; + var dy1; + var dw0; + var dw1; + var dz0; + var dz1; + var ox1; + var oy1; + var ow1; + var oz1; + var sh; + var s0; + var s1; + var sx; + var sy; + var sw; + var sz; + var ox; + var oy; + var ow; + var oz; + var ix; + var iy; + var iw; + var iz; + var i0; + var i1; + var j0; + var j1; + var o; + + // Note on variable naming convention: s#, dx#, dy#, dz#, dw#, 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 ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.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; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[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] ); + 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] ); + + // 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] ); + + // Iterate over the ndarray dimensions... + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + wbuf[ iw ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ] ); + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + } + } + } +} + + +// EXPORTS // + +module.exports = blockedternary2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/2d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/2d_blocked_accessors.js new file mode 100644 index 000000000000..4a78b539cd3c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/2d_blocked_accessors.js @@ -0,0 +1,275 @@ +/** +* @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 loopOrder = require( '@stdlib/ndarray/base/ternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a ternary 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 output 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 {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 ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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 +* }; +* +* // Apply the ternary function: +* blockedternary2d( x, y, z, w, fcn ); +* +* console.log( copy( w.data ) ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5 ] +*/ +function blockedternary2d( x, y, z, w, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var xget; + var yget; + var zget; + var wset; + var dx0; + var dx1; + var dy0; + var dy1; + var dz0; + var dz1; + var dw0; + var dw1; + var ox1; + var oy1; + var oz1; + var ow1; + var sh; + var s0; + var s1; + var sx; + var sy; + var sz; + var sw; + var ox; + var oy; + var oz; + var ow; + var ix; + var iy; + var iz; + var iw; + var i0; + var i1; + var j0; + var j1; + var o; + + // Note on variable naming convention: s#, dx#, dy#, dz#, dw#, 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 ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.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; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + + // Cache accessors: + xget = x.accessors[0]; + yget = y.accessors[0]; + zget = z.accessors[0]; + wset = w.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] ); + 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] ); + + // 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] ); + + // Iterate over the ndarray dimensions... + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + wset( wbuf, iw, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + } + } + } +} + + +// EXPORTS // + +module.exports = blockedternary2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/3d.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/3d.js new file mode 100644 index 000000000000..55ce9678e2c5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/3d.js @@ -0,0 +1,240 @@ +/** +* @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 ternary callback to elements in 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 output 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 {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - ternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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' +* }; +* +* // Apply the ternary function: +* ternary3d( x, y, z, w, true, fcn ); +* +* console.log( w.data ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5 ] +*/ +function ternary3d( x, y, z, w, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + 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 sh; + var S0; + var S1; + var S2; + var sx; + var sy; + var sz; + var sw; + var ix; + var iy; + var iz; + var iw; + var i0; + var i1; + var i2; + + // Note on variable naming convention: S#, dx#, dy#, dz#, dw#, 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; + 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] ); + } 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] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Iterate over the ndarray dimensions... + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + wbuf[ iw ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ] ); + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + } +} + + +// EXPORTS // + +module.exports = ternary3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/3d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/3d_accessors.js new file mode 100644 index 000000000000..10bec1154acd --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/3d_accessors.js @@ -0,0 +1,256 @@ +/** +* @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 ternary callback to elements in 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 output 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 {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 ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 = [ 2, 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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 +* }; +* +* // Apply the ternary function: +* ternary3d( x, y, z, w, true, fcn ); +* +* console.log( copy( w.data ) ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5 ] +*/ +function ternary3d( x, y, z, w, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var wbuf; + var zbuf; + var xget; + var yget; + var zget; + var wset; + var dx0; + var dx1; + var dx2; + var dy0; + var dy1; + var dy2; + var dw0; + var dw1; + var dw2; + var dz0; + var dz1; + var dz2; + var sh; + var S0; + var S1; + var S2; + var sx; + var sy; + var sw; + var sz; + var ix; + var iy; + var iw; + var iz; + var i0; + var i1; + var i2; + + // Note on variable naming convention: S#, dx#, dy#, dw#, dz#, 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; + 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] ); + dw0 = sw[ 2 ]; + dw1 = sw[ 1 ] - ( S0*sw[2] ); + dw2 = sw[ 0 ] - ( S1*sw[1] ); + dz0 = sz[ 2 ]; + dz1 = sz[ 1 ] - ( S0*sz[2] ); + dz2 = sz[ 0 ] - ( S1*sz[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] ); + dw0 = sw[ 0 ]; + dw1 = sw[ 1 ] - ( S0*sw[0] ); + dw2 = sw[ 2 ] - ( S1*sw[1] ); + dz0 = sz[ 0 ]; + dz1 = sz[ 1 ] - ( S0*sz[0] ); + dz2 = sz[ 2 ] - ( S1*sz[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; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache accessors: + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = z.accessors[ 0 ]; + wset = w.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++ ) { + wset( wbuf, iw, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iw += dw0; + iz += dz0; + } + ix += dx1; + iy += dy1; + iw += dw1; + iz += dz1; + } + ix += dx2; + iy += dy2; + iw += dw2; + iz += dz2; + } +} + + +// EXPORTS // + +module.exports = ternary3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/3d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/3d_blocked.js new file mode 100644 index 000000000000..2c0da2218d0a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/3d_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-depth, max-statements */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/ternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a ternary 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 output 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 {Callback} fcn - ternary callback +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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' +* }; +* +* // Apply the ternary function: +* blockedternary3d( x, y, z, w, fcn ); +* +* console.log( w.data ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5 ] +*/ +function blockedternary3d( x, y, z, w, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + 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 ox1; + var oy1; + var oz1; + var ow1; + var ox2; + var oy2; + var oz2; + var ow2; + var sh; + var s0; + var s1; + var s2; + var sx; + var sy; + var sz; + var sw; + var ox; + var oy; + var oz; + var ow; + var ix; + var iy; + var iz; + var iw; + var i0; + var i1; + var i2; + var j0; + var j1; + var j2; + var o; + + // Note on variable naming convention: s#, dx#, dy#, dz#, dw#, 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 ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.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; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[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] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[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] ); + + // 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] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + + // Iterate over the ndarray dimensions... + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + wbuf[ iw ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ] ); + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedternary3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/3d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/3d_blocked_accessors.js new file mode 100644 index 000000000000..b0d2bba17478 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/3d_blocked_accessors.js @@ -0,0 +1,311 @@ +/** +* @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/ternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a ternary 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 output 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 {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 ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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 +* }; +* +* // Apply the ternary function: +* blockedternary3d( x, y, z, w, fcn ); +* +* console.log( copy( w.data ) ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5 ] +*/ +function blockedternary3d( x, y, z, w, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var xget; + var yget; + var zget; + var wset; + 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 ox1; + var oy1; + var oz1; + var ow1; + var ox2; + var oy2; + var oz2; + var ow2; + var sh; + var s0; + var s1; + var s2; + var sx; + var sy; + var sz; + var sw; + var ox; + var oy; + var oz; + var ow; + var ix; + var iy; + var iz; + var iw; + var i0; + var i1; + var i2; + var j0; + var j1; + var j2; + var o; + + // Note on variable naming convention: s#, dx#, dy#, dz#, dw#, 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 ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.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; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + + // Cache accessors: + xget = x.accessors[0]; + yget = y.accessors[0]; + zget = z.accessors[0]; + wset = w.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] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[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] ); + + // 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] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + + // Iterate over the ndarray dimensions... + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + wset( wbuf, iw, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedternary3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/4d.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/4d.js new file mode 100644 index 000000000000..72e14d524682 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/4d.js @@ -0,0 +1,262 @@ +/** +* @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 ternary 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 output 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 {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - ternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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' +* }; +* +* // Apply the ternary function: +* ternary4d( x, y, z, w, true, fcn ); +* +* console.log( w.data ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5 ] +*/ +function ternary4d( x, y, z, w, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var wbuf; + var zbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dy0; + var dy1; + var dy2; + var dy3; + var dw0; + var dw1; + var dw2; + var dw3; + var dz0; + var dz1; + var dz2; + var dz3; + var sh; + var S0; + var S1; + var S2; + var S3; + var sx; + var sy; + var sw; + var sz; + var ix; + var iy; + var iw; + var iz; + var i0; + var i1; + var i2; + var i3; + + // Note on variable naming convention: S#, dx#, dy#, dw#, dz#, 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; + 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] ); + dw0 = sw[ 3 ]; + dw1 = sw[ 2 ] - ( S0*sw[3] ); + dw2 = sw[ 1 ] - ( S1*sw[2] ); + dw3 = sw[ 0 ] - ( S2*sw[1] ); + dz0 = sz[ 3 ]; + dz1 = sz[ 2 ] - ( S0*sz[3] ); + dz2 = sz[ 1 ] - ( S1*sz[2] ); + dz3 = sz[ 0 ] - ( S2*sz[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] ); + dw0 = sw[ 0 ]; + dw1 = sw[ 1 ] - ( S0*sw[0] ); + dw2 = sw[ 2 ] - ( S1*sw[1] ); + dw3 = sw[ 3 ] - ( S2*sw[2] ); + dz0 = sz[ 0 ]; + dz1 = sz[ 1 ] - ( S0*sz[0] ); + dz2 = sz[ 2 ] - ( S1*sz[1] ); + dz3 = sz[ 3 ] - ( S2*sz[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; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.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++ ) { + wbuf[ iw ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ] ); + ix += dx0; + iy += dy0; + iw += dw0; + iz += dz0; + } + ix += dx1; + iy += dy1; + iw += dw1; + iz += dz1; + } + ix += dx2; + iy += dy2; + iw += dw2; + iz += dz2; + } + ix += dx3; + iy += dy3; + iw += dw3; + iz += dz3; + } +} + + +// EXPORTS // + +module.exports = ternary4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/4d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/4d_accessors.js new file mode 100644 index 000000000000..b9e875979cc3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/4d_accessors.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. +*/ + +'use strict'; + +// MAIN // + +/** +* Applies a ternary 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 output 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 {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 ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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 +* }; +* +* // Apply the ternary function: +* ternary4d( x, y, z, w, true, fcn ); +* +* console.log( copy( w.data ) ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5 ] +*/ +function ternary4d( x, y, z, w, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var wbuf; + var zbuf; + var xget; + var yget; + var zget; + var wset; + var dx0; + var dx1; + var dx2; + var dx3; + var dy0; + var dy1; + var dy2; + var dy3; + var dw0; + var dw1; + var dw2; + var dw3; + var dz0; + var dz1; + var dz2; + var dz3; + var sh; + var S0; + var S1; + var S2; + var S3; + var sx; + var sy; + var sw; + var sz; + var ix; + var iy; + var iw; + var iz; + var i0; + var i1; + var i2; + var i3; + + // Note on variable naming convention: S#, dx#, dy#, dw#, dz#, 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; + 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] ); + dw0 = sw[ 3 ]; + dw1 = sw[ 2 ] - ( S0*sw[3] ); + dw2 = sw[ 1 ] - ( S1*sw[2] ); + dw3 = sw[ 0 ] - ( S2*sw[1] ); + dz0 = sz[ 3 ]; + dz1 = sz[ 2 ] - ( S0*sz[3] ); + dz2 = sz[ 1 ] - ( S1*sz[2] ); + dz3 = sz[ 0 ] - ( S2*sz[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] ); + dw0 = sw[ 0 ]; + dw1 = sw[ 1 ] - ( S0*sw[0] ); + dw2 = sw[ 2 ] - ( S1*sw[1] ); + dw3 = sw[ 3 ] - ( S2*sw[2] ); + dz0 = sz[ 0 ]; + dz1 = sz[ 1 ] - ( S0*sz[0] ); + dz2 = sz[ 2 ] - ( S1*sz[1] ); + dz3 = sz[ 3 ] - ( S2*sz[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; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache accessors: + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = z.accessors[ 0 ]; + wset = w.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++ ) { + wset( wbuf, iw, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ) ) ); + ix += dx0; + iy += dy0; + iw += dw0; + iz += dz0; + } + ix += dx1; + iy += dy1; + iw += dw1; + iz += dz1; + } + ix += dx2; + iy += dy2; + iw += dw2; + iz += dz2; + } + ix += dx3; + iy += dy3; + iw += dw3; + iz += dz3; + } +} + + +// EXPORTS // + +module.exports = ternary4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/4d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/4d_blocked.js new file mode 100644 index 000000000000..60bed83748c9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/4d_blocked.js @@ -0,0 +1,325 @@ +/** +* @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/ternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a ternary 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 output 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 {Callback} fcn - ternary callback +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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' +* }; +* +* // Apply the ternary function: +* blockedternary4d( x, y, z, w, fcn ); +* +* console.log( w.data ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5 ] +*/ +function blockedternary4d( x, y, z, w, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + 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 ox1; + var oy1; + var oz1; + var ow1; + var ox2; + var oy2; + var oz2; + var ow2; + var ox3; + var oy3; + var oz3; + var ow3; + var sh; + var s0; + var s1; + var s2; + var s3; + var sx; + var sy; + var sz; + var sw; + var ox; + var oy; + var oz; + var ow; + var ix; + var iy; + var iz; + var iw; + 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#, 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 ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.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; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[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] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[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] ); + + // 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] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + + // 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++ ) { + wbuf[ iw ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ] ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedternary4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/4d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/4d_blocked_accessors.js new file mode 100644 index 000000000000..76ce1c544cec --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/4d_blocked_accessors.js @@ -0,0 +1,345 @@ +/** +* @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/ternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a ternary 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 output 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 {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 ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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 +* }; +* +* // Apply the ternary function: +* blockedternary4d( x, y, z, w, fcn ); +* +* console.log( copy( w.data ) ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5 ] +*/ +function blockedternary4d( x, y, z, w, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var xget; + var yget; + var zget; + var wset; + 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 ox1; + var oy1; + var oz1; + var ow1; + var ox2; + var oy2; + var oz2; + var ow2; + var ox3; + var oy3; + var oz3; + var ow3; + var sh; + var s0; + var s1; + var s2; + var s3; + var sx; + var sy; + var sz; + var sw; + var ox; + var oy; + var oz; + var ow; + var ix; + var iy; + var iz; + var iw; + 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#, 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 ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.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; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + + // Cache accessors: + xget = x.accessors[0]; + yget = y.accessors[0]; + zget = z.accessors[0]; + wset = w.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] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[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] ); + + // 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] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + + // 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++ ) { + wset( wbuf, iw, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedternary4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/5d.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/5d.js new file mode 100644 index 000000000000..7e07e7beaff5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/5d.js @@ -0,0 +1,284 @@ +/** +* @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 ternary 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 output 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 {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - ternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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' +* }; +* +* // Apply the ternary function: +* ternary5d( x, y, z, w, true, fcn ); +* +* console.log( w.data ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5 ] +*/ +function ternary5d( x, y, z, w, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var wbuf; + var zbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var sx; + var sy; + var sw; + var sz; + var ix; + var iy; + var iw; + var iz; + var i0; + var i1; + var i2; + var i3; + var i4; + + // Note on variable naming convention: S#, dx#, dy#, dw#, dz#, 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; + 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] ); + 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] ); + 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] ); + } 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] ); + 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] ); + 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] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.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++ ) { + wbuf[ iw ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ] ); + ix += dx0; + iy += dy0; + iw += dw0; + iz += dz0; + } + ix += dx1; + iy += dy1; + iw += dw1; + iz += dz1; + } + ix += dx2; + iy += dy2; + iw += dw2; + iz += dz2; + } + ix += dx3; + iy += dy3; + iw += dw3; + iz += dz3; + } + ix += dx4; + iy += dy4; + iw += dw4; + iz += dz4; + } +} + + +// EXPORTS // + +module.exports = ternary5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/5d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/5d_accessors.js new file mode 100644 index 000000000000..80e907254197 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/5d_accessors.js @@ -0,0 +1,300 @@ +/** +* @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 ternary 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 output 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 {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 ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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 +* }; +* +* // Apply the ternary function: +* ternary5d( x, y, z, w, true, fcn ); +* +* console.log( copy( w.data ) ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5 ] +*/ +function ternary5d( x, y, z, w, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var wbuf; + var zbuf; + var xget; + var yget; + var zget; + var wset; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var sx; + var sy; + var sw; + var sz; + var ix; + var iy; + var iw; + var iz; + var i0; + var i1; + var i2; + var i3; + var i4; + + // Note on variable naming convention: S#, dx#, dy#, dw#, dz#, 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; + 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] ); + 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] ); + 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] ); + } 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] ); + 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] ); + 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] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache accessors: + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = z.accessors[ 0 ]; + wset = w.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++ ) { + wset( wbuf, iw, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ) ) ); + ix += dx0; + iy += dy0; + iw += dw0; + iz += dz0; + } + ix += dx1; + iy += dy1; + iw += dw1; + iz += dz1; + } + ix += dx2; + iy += dy2; + iw += dw2; + iz += dz2; + } + ix += dx3; + iy += dy3; + iw += dw3; + iz += dz3; + } + ix += dx4; + iy += dy4; + iw += dw4; + iz += dz4; + } +} + + +// EXPORTS // + +module.exports = ternary5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/5d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/5d_blocked.js new file mode 100644 index 000000000000..0130f4cd0c9c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/5d_blocked.js @@ -0,0 +1,359 @@ +/** +* @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/ternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a ternary 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 output 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 {Callback} fcn - ternary callback +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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' +* }; +* +* // Apply the ternary function: +* blockedternary5d( x, y, z, w, fcn ); +* +* console.log( w.data ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5 ] +*/ +function blockedternary5d( x, y, z, w, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + 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 ox1; + var oy1; + var oz1; + var ow1; + var ox2; + var oy2; + var oz2; + var ow2; + var ox3; + var oy3; + var oz3; + var ow3; + var ox4; + var oy4; + var oz4; + var ow4; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var sx; + var sy; + var sz; + var sw; + var ox; + var oy; + var oz; + var ow; + var ix; + var iy; + var iz; + var iw; + 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#, 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 ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.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; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[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] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oz3 = oz4 + ( j3*sz[3] ); + ow3 = ow4 + ( j3*sw[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[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] ); + + // 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] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + dz4 = sz[4] - ( s3*sz[3] ); + dw4 = sw[4] - ( s3*sw[3] ); + + // 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++ ) { + wbuf[ iw ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ] ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedternary5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/5d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/5d_blocked_accessors.js new file mode 100644 index 000000000000..be8c994fe1ed --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/5d_blocked_accessors.js @@ -0,0 +1,379 @@ +/** +* @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/ternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a ternary 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 output 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 {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 ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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 +* }; +* +* // Apply the ternary function: +* blockedternary5d( x, y, z, w, fcn ); +* +* console.log( copy( w.data ) ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5 ] +*/ +function blockedternary5d( x, y, z, w, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var xget; + var yget; + var zget; + var wset; + 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 ox1; + var oy1; + var oz1; + var ow1; + var ox2; + var oy2; + var oz2; + var ow2; + var ox3; + var oy3; + var oz3; + var ow3; + var ox4; + var oy4; + var oz4; + var ow4; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var sx; + var sy; + var sz; + var sw; + var ox; + var oy; + var oz; + var ow; + var ix; + var iy; + var iz; + var iw; + 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#, 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 ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.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; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + + // Cache accessors: + xget = x.accessors[0]; + yget = y.accessors[0]; + zget = z.accessors[0]; + wset = w.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] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oz3 = oz4 + ( j3*sz[3] ); + ow3 = ow4 + ( j3*sw[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[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] ); + + // 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] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + dz4 = sz[4] - ( s3*sz[3] ); + dw4 = sw[4] - ( s3*sw[3] ); + + // 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++ ) { + wset( wbuf, iw, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedternary5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/6d.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/6d.js new file mode 100644 index 000000000000..305b7acf8da2 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/6d.js @@ -0,0 +1,308 @@ +/** +* @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 ternary 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 output 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 {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - ternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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' +* }; +* +* // Apply the ternary function: +* ternary6d( x, y, z, w, true, fcn ); +* +* console.log( w.data ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5 ] +*/ +function ternary6d( x, y, z, w, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var wbuf; + var zbuf; + 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 dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var sx; + var sy; + var sw; + var sz; + var ix; + var iy; + var iw; + var iz; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + + // Note on variable naming convention: S#, dx#, dy#, dw#, dz#, 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; + 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] ); + 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] ); + 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] ); + } 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] ); + 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] ); + 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] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.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++ ) { + wbuf[ iw ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ] ); + ix += dx0; + iy += dy0; + iw += dw0; + iz += dz0; + } + ix += dx1; + iy += dy1; + iw += dw1; + iz += dz1; + } + ix += dx2; + iy += dy2; + iw += dw2; + iz += dz2; + } + ix += dx3; + iy += dy3; + iw += dw3; + iz += dz3; + } + ix += dx4; + iy += dy4; + iw += dw4; + iz += dz4; + } + ix += dx5; + iy += dy5; + iw += dw5; + iz += dz5; + } +} + + +// EXPORTS // + +module.exports = ternary6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/6d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/6d_accessors.js new file mode 100644 index 000000000000..c75da7b7df2f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/6d_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, max-depth */ + +'use strict'; + +// MAIN // + +/** +* Applies a ternary 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 output 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 {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 ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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 +* }; +* +* // Apply the ternary function: +* ternary6d( x, y, z, w, true, fcn ); +* +* console.log( copy( w.data ) ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5 ] +*/ +function ternary6d( x, y, z, w, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var wbuf; + var zbuf; + var xget; + var yget; + var zget; + var wset; + 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 dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var sx; + var sy; + var sw; + var sz; + var ix; + var iy; + var iw; + var iz; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + + // Note on variable naming convention: S#, dx#, dy#, dw#, dz#, 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; + 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] ); + 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] ); + 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] ); + } 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] ); + 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] ); + 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] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache accessors: + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = z.accessors[ 0 ]; + wset = w.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++ ) { + wset( wbuf, iw, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iw += dw0; + iz += dz0; + } + ix += dx1; + iy += dy1; + iw += dw1; + iz += dz1; + } + ix += dx2; + iy += dy2; + iw += dw2; + iz += dz2; + } + ix += dx3; + iy += dy3; + iw += dw3; + iz += dz3; + } + ix += dx4; + iy += dy4; + iw += dw4; + iz += dz4; + } + ix += dx5; + iy += dy5; + iw += dw5; + iz += dz5; + } +} + + +// EXPORTS // + +module.exports = ternary6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/6d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/6d_blocked.js new file mode 100644 index 000000000000..6ac3b61c9463 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/6d_blocked.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/ternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a ternary 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 output 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 {Callback} fcn - ternary callback +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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' +* }; +* +* // Apply the ternary function: +* blockedternary6d( x, y, z, w, fcn ); +* +* console.log( w.data ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5 ] +*/ +function blockedternary6d( x, y, z, w, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + 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 ox1; + var oy1; + var oz1; + var ow1; + var ox2; + var oy2; + var oz2; + var ow2; + var ox3; + var oy3; + var oz3; + var ow3; + var ox4; + var oy4; + var oz4; + var ow4; + var ox5; + var oy5; + var oz5; + var ow5; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var sx; + var sy; + var sz; + var sw; + var ox; + var oy; + var oz; + var ow; + var ix; + var iy; + var iz; + var iw; + 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#, 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 ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.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; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[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] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oz4 = oz5 + ( j4*sz[4] ); + ow4 = ow5 + ( j4*sw[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oz3 = oz4 + ( j3*sz[3] ); + ow3 = ow4 + ( j3*sw[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[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] ); + + // 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] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + dz4 = sz[4] - ( s3*sz[3] ); + dw4 = sw[4] - ( s3*sw[3] ); + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + dz5 = sz[5] - ( s4*sz[4] ); + dw5 = sw[5] - ( s4*sw[4] ); + + // 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++ ) { + wbuf[ iw ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ] ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedternary6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/6d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/6d_blocked_accessors.js new file mode 100644 index 000000000000..50cef994b5bc --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/6d_blocked_accessors.js @@ -0,0 +1,413 @@ +/** +* @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/ternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a ternary 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 output 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 {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 ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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 +* }; +* +* // Apply the ternary function: +* blockedternary6d( x, y, z, w, fcn ); +* +* console.log( copy( w.data ) ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5 ] +*/ +function blockedternary6d( x, y, z, w, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var xget; + var yget; + var zget; + var wset; + 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 ox1; + var oy1; + var oz1; + var ow1; + var ox2; + var oy2; + var oz2; + var ow2; + var ox3; + var oy3; + var oz3; + var ow3; + var ox4; + var oy4; + var oz4; + var ow4; + var ox5; + var oy5; + var oz5; + var ow5; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var sx; + var sy; + var sz; + var sw; + var ox; + var oy; + var oz; + var ow; + var ix; + var iy; + var iz; + var iw; + 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#, 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 ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.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; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + + // Cache accessors: + xget = x.accessors[0]; + yget = y.accessors[0]; + zget = z.accessors[0]; + wset = w.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] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oz4 = oz5 + ( j4*sz[4] ); + ow4 = ow5 + ( j4*sw[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oz3 = oz4 + ( j3*sz[3] ); + ow3 = ow4 + ( j3*sw[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[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] ); + + // 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] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + dz4 = sz[4] - ( s3*sz[3] ); + dw4 = sw[4] - ( s3*sw[3] ); + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + dz5 = sz[5] - ( s4*sz[4] ); + dw5 = sw[5] - ( s4*sw[4] ); + + // 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++ ) { + wset( wbuf, iw, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedternary6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/7d.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/7d.js new file mode 100644 index 000000000000..016ccf211b72 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/7d.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, max-depth */ + +'use strict'; + +// MAIN // + +/** +* Applies a ternary 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 output 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 {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - ternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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' +* }; +* +* // Apply the ternary function: +* ternary7d( x, y, z, w, true, fcn ); +* +* console.log( w.data ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5 ] +*/ +function ternary7d( x, y, z, w, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var wbuf; + var zbuf; + 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 dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dw6; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dz6; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var sx; + var sy; + var sw; + var sz; + var ix; + var iy; + var iw; + var iz; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + + // Note on variable naming convention: S#, dx#, dy#, dw#, dz#, 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; + 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] ); + 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] ); + 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] ); + } 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] ); + 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] ); + 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] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iw = w.offset; + iz = z.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.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++ ) { + wbuf[ iw ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ] ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iw += dw0; + iz += dz0; + } + ix += dx1; + iy += dy1; + iw += dw1; + iz += dz1; + } + ix += dx2; + iy += dy2; + iw += dw2; + iz += dz2; + } + ix += dx3; + iy += dy3; + iw += dw3; + iz += dz3; + } + ix += dx4; + iy += dy4; + iw += dw4; + iz += dz4; + } + ix += dx5; + iy += dy5; + iw += dw5; + iz += dz5; + } + ix += dx6; + iy += dy6; + iw += dw6; + iz += dz6; + } +} + + +// EXPORTS // + +module.exports = ternary7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/7d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/7d_accessors.js new file mode 100644 index 000000000000..c36d0952b756 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/7d_accessors.js @@ -0,0 +1,350 @@ +/** +* @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 ternary 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 output 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 {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 ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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 +* }; +* +* // Apply the ternary function: +* ternary7d( x, y, z, w, true, fcn ); +* +* console.log( copy( w.data ) ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5 ] +*/ +function ternary7d( x, y, z, w, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var wbuf; + var zbuf; + var xget; + var yget; + var zget; + var wset; + 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 dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dw6; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dz6; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var sx; + var sy; + var sw; + var sz; + var ix; + var iy; + var iw; + var iz; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + + // Note on variable naming convention: S#, dx#, dy#, dz#, dw#, 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; + 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] ); + 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] ); + 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] ); + } 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] ); + 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] ); + 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] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache accessors: + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = z.accessors[ 0 ]; + wset = w.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++ ) { + wset( wbuf, iw, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ) ) ); + ix += dx0; + iy += dy0; + iw += dw0; + iz += dz0; + } + ix += dx1; + iy += dy1; + iw += dw1; + iz += dz1; + } + ix += dx2; + iy += dy2; + iw += dw2; + iz += dz2; + } + ix += dx3; + iy += dy3; + iw += dw3; + iz += dz3; + } + ix += dx4; + iy += dy4; + iw += dw4; + iz += dz4; + } + ix += dx5; + iy += dy5; + iw += dw5; + iz += dz5; + } + ix += dx6; + iy += dy6; + iw += dw6; + iz += dz6; + } +} + + +// EXPORTS // + +module.exports = ternary7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/7d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/7d_blocked.js new file mode 100644 index 000000000000..8310e36e86f1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/7d_blocked.js @@ -0,0 +1,427 @@ +/** +* @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/ternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a ternary 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 output 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 {Callback} fcn - ternary callback +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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' +* }; +* +* // Apply the ternary function: +* blockedternary7d( x, y, z, w, fcn ); +* +* console.log( w.data ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5 ] +*/ +function blockedternary7d( x, y, z, w, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + 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 ox1; + var oy1; + var oz1; + var ow1; + var ox2; + var oy2; + var oz2; + var ow2; + var ox3; + var oy3; + var oz3; + var ow3; + var ox4; + var oy4; + var oz4; + var ow4; + var ox5; + var oy5; + var oz5; + var ow5; + var ox6; + var oy6; + var oz6; + var ow6; + 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 ox; + var oy; + var oz; + var ow; + var ix; + var iy; + var iz; + var iw; + 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#, 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 ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.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; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[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] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + ox5 = ox6 + ( j5*sx[5] ); + oy5 = oy6 + ( j5*sy[5] ); + oz5 = oz6 + ( j5*sz[5] ); + ow5 = ow6 + ( j5*sw[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oz4 = oz5 + ( j4*sz[4] ); + ow4 = ow5 + ( j4*sw[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oz3 = oz4 + ( j3*sz[3] ); + ow3 = ow4 + ( j3*sw[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[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] ); + + // 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] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + dz4 = sz[4] - ( s3*sz[3] ); + dw4 = sw[4] - ( s3*sw[3] ); + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + dz5 = sz[5] - ( s4*sz[4] ); + dw5 = sw[5] - ( s4*sw[4] ); + dx6 = sx[6] - ( s5*sx[5] ); + dy6 = sy[6] - ( s5*sy[5] ); + dz6 = sz[6] - ( s5*sz[5] ); + dw6 = sw[6] - ( s5*sw[5] ); + + // 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++ ) { + wbuf[ iw ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ] ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + } + ix += dx6; + iy += dy6; + iz += dz6; + iw += dw6; + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedternary7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/7d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/7d_blocked_accessors.js new file mode 100644 index 000000000000..8a2fac0eb706 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/7d_blocked_accessors.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 */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/ternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a ternary 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 output 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 {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 ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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 +* }; +* +* // Apply the ternary function: +* blockedternary7d( x, y, z, w, fcn ); +* +* console.log( copy( w.data ) ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5 ] +*/ +function blockedternary7d( x, y, z, w, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var xget; + var yget; + var zget; + var wset; + 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 ox1; + var oy1; + var oz1; + var ow1; + var ox2; + var oy2; + var oz2; + var ow2; + var ox3; + var oy3; + var oz3; + var ow3; + var ox4; + var oy4; + var oz4; + var ow4; + var ox5; + var oy5; + var oz5; + var ow5; + var ox6; + var oy6; + var oz6; + var ow6; + 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 ox; + var oy; + var oz; + var ow; + var ix; + var iy; + var iz; + var iw; + 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#, 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 ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.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; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + + // Cache accessors: + xget = x.accessors[0]; + yget = y.accessors[0]; + zget = z.accessors[0]; + wset = w.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] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + ox5 = ox6 + ( j5*sx[5] ); + oy5 = oy6 + ( j5*sy[5] ); + oz5 = oz6 + ( j5*sz[5] ); + ow5 = ow6 + ( j5*sw[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oz4 = oz5 + ( j4*sz[4] ); + ow4 = ow5 + ( j4*sw[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oz3 = oz4 + ( j3*sz[3] ); + ow3 = ow4 + ( j3*sw[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[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] ); + + // 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] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + dz4 = sz[4] - ( s3*sz[3] ); + dw4 = sw[4] - ( s3*sw[3] ); + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + dz5 = sz[5] - ( s4*sz[4] ); + dw5 = sw[5] - ( s4*sw[4] ); + dx6 = sx[6] - ( s5*sx[5] ); + dy6 = sy[6] - ( s5*sy[5] ); + dz6 = sz[6] - ( s5*sz[5] ); + dw6 = sw[6] - ( s5*sw[5] ); + + // 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++ ) { + wset( wbuf, iw, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + } + ix += dx6; + iy += dy6; + iz += dz6; + iw += dw6; + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedternary7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/8d.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/8d.js new file mode 100644 index 000000000000..e06465483718 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/8d.js @@ -0,0 +1,352 @@ +/** +* @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 ternary 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 output 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 {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - ternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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' +* }; +* +* // Apply the ternary function: +* ternary8d( x, y, z, w, true, fcn ); +* +* console.log( w.data ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5 ] +*/ +function ternary8d( x, y, z, w, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var wbuf; + var zbuf; + 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 dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dw6; + var dw7; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dz6; + var dz7; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var sx; + var sy; + var sw; + var sz; + var ix; + var iy; + var iw; + var iz; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + + // Note on variable naming convention: S#, dx#, dy#, dw#, dz#, 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; + 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] ); + 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] ); + 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] ); + } 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] ); + 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] ); + 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] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.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++ ) { + wbuf[ iw ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ] ); + ix += dx0; + iy += dy0; + iw += dw0; + iz += dz0; + } + ix += dx1; + iy += dy1; + iw += dw1; + iz += dz1; + } + ix += dx2; + iy += dy2; + iw += dw2; + iz += dz2; + } + ix += dx3; + iy += dy3; + iw += dw3; + iz += dz3; + } + ix += dx4; + iy += dy4; + iw += dw4; + iz += dz4; + } + ix += dx5; + iy += dy5; + iw += dw5; + iz += dz5; + } + ix += dx6; + iy += dy6; + iw += dw6; + iz += dz6; + } + ix += dx7; + iy += dy7; + iw += dw7; + iz += dz7; + } +} + + +// EXPORTS // + +module.exports = ternary8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/8d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/8d_accessors.js new file mode 100644 index 000000000000..8999c0c16c54 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/8d_accessors.js @@ -0,0 +1,372 @@ +/** +* @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 ternary 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 output 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 {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 ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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 +* }; +* +* // Apply the ternary function: +* ternary8d( x, y, z, w, true, fcn ); +* +* console.log( copy( w.data ) ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5 ] +*/ +function ternary8d( x, y, z, w, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var wbuf; + var zbuf; + var xget; + var yget; + var zget; + var wset; + 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 dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dw6; + var dw7; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dz6; + var dz7; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var sx; + var sy; + var sw; + var sz; + var ix; + var iy; + var iw; + var iz; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + + // Note on variable naming convention: S#, dx#, dy#, dw#, dz#, 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; + 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] ); + 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] ); + 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] ); + } 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] ); + 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] ); + 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] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache accessors: + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = z.accessors[ 0 ]; + wset = w.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++ ) { + wset( wbuf, iw, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iw += dw0; + iz += dz0; + } + ix += dx1; + iy += dy1; + iw += dw1; + iz += dz1; + } + ix += dx2; + iy += dy2; + iw += dw2; + iz += dz2; + } + ix += dx3; + iy += dy3; + iw += dw3; + iz += dz3; + } + ix += dx4; + iy += dy4; + iw += dw4; + iz += dz4; + } + ix += dx5; + iy += dy5; + iw += dw5; + iz += dz5; + } + ix += dx6; + iy += dy6; + iw += dw6; + iz += dz6; + } + ix += dx7; + iy += dy7; + iw += dw7; + iz += dz7; + } +} + + +// EXPORTS // + +module.exports = ternary8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/8d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/8d_blocked.js new file mode 100644 index 000000000000..4a9dcb2e1362 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/8d_blocked.js @@ -0,0 +1,461 @@ +/** +* @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/ternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a ternary 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 output 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 {Callback} fcn - ternary callback +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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' +* }; +* +* // Apply the ternary function: +* blockedternary8d( x, y, z, w, fcn ); +* +* console.log( w.data ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5 ] +*/ +function blockedternary8d( x, y, z, w, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + 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 ox1; + var oy1; + var oz1; + var ow1; + var ox2; + var oy2; + var oz2; + var ow2; + var ox3; + var oy3; + var oz3; + var ow3; + var ox4; + var oy4; + var oz4; + var ow4; + var ox5; + var oy5; + var oz5; + var ow5; + var ox6; + var oy6; + var oz6; + var ow6; + var ox7; + var oy7; + var oz7; + var ow7; + 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 ox; + var oy; + var oz; + var ow; + var ix; + var iy; + var iz; + var iw; + 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#, 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 ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.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; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[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] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + ox6 = ox7 + ( j6*sx[6] ); + oy6 = oy7 + ( j6*sy[6] ); + oz6 = oz7 + ( j6*sz[6] ); + ow6 = ow7 + ( j6*sw[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + ox5 = ox6 + ( j5*sx[5] ); + oy5 = oy6 + ( j5*sy[5] ); + oz5 = oz6 + ( j5*sz[5] ); + ow5 = ow6 + ( j5*sw[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oz4 = oz5 + ( j4*sz[4] ); + ow4 = ow5 + ( j4*sw[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oz3 = oz4 + ( j3*sz[3] ); + ow3 = ow4 + ( j3*sw[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[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] ); + + // 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] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + dz4 = sz[4] - ( s3*sz[3] ); + dw4 = sw[4] - ( s3*sw[3] ); + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + dz5 = sz[5] - ( s4*sz[4] ); + dw5 = sw[5] - ( s4*sw[4] ); + dx6 = sx[6] - ( s5*sx[5] ); + dy6 = sy[6] - ( s5*sy[5] ); + dz6 = sz[6] - ( s5*sz[5] ); + dw6 = sw[6] - ( s5*sw[5] ); + dx7 = sx[7] - ( s6*sx[6] ); + dy7 = sy[7] - ( s6*sy[6] ); + dz7 = sz[7] - ( s6*sz[6] ); + dw7 = sw[7] - ( s6*sw[6] ); + + // 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++ ) { + wbuf[ iw ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ] ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + } + ix += dx6; + iy += dy6; + iz += dz6; + iw += dw6; + } + ix += dx7; + iy += dy7; + iz += dz7; + iw += dw7; + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedternary8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/8d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/8d_blocked_accessors.js new file mode 100644 index 000000000000..a4a42bc04561 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/8d_blocked_accessors.js @@ -0,0 +1,481 @@ +/** +* @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/ternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a ternary 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 output 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 {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 ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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 +* }; +* +* // Apply the ternary function: +* blockedternary8d( x, y, z, w, fcn ); +* +* console.log( copy( w.data ) ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5 ] +*/ +function blockedternary8d( x, y, z, w, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var xget; + var yget; + var zget; + var wset; + 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 ox1; + var oy1; + var oz1; + var ow1; + var ox2; + var oy2; + var oz2; + var ow2; + var ox3; + var oy3; + var oz3; + var ow3; + var ox4; + var oy4; + var oz4; + var ow4; + var ox5; + var oy5; + var oz5; + var ow5; + var ox6; + var oy6; + var oz6; + var ow6; + var ox7; + var oy7; + var oz7; + var ow7; + 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 ox; + var oy; + var oz; + var ow; + var ix; + var iy; + var iz; + var iw; + 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#, 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 ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.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; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + + // Cache accessors: + xget = x.accessors[0]; + yget = y.accessors[0]; + zget = z.accessors[0]; + wset = w.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] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + ox6 = ox7 + ( j6*sx[6] ); + oy6 = oy7 + ( j6*sy[6] ); + oz6 = oz7 + ( j6*sz[6] ); + ow6 = ow7 + ( j6*sw[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + ox5 = ox6 + ( j5*sx[5] ); + oy5 = oy6 + ( j5*sy[5] ); + oz5 = oz6 + ( j5*sz[5] ); + ow5 = ow6 + ( j5*sw[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oz4 = oz5 + ( j4*sz[4] ); + ow4 = ow5 + ( j4*sw[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oz3 = oz4 + ( j3*sz[3] ); + ow3 = ow4 + ( j3*sw[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[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] ); + + // 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] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + dz4 = sz[4] - ( s3*sz[3] ); + dw4 = sw[4] - ( s3*sw[3] ); + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + dz5 = sz[5] - ( s4*sz[4] ); + dw5 = sw[5] - ( s4*sw[4] ); + dx6 = sx[6] - ( s5*sx[5] ); + dy6 = sy[6] - ( s5*sy[5] ); + dz6 = sz[6] - ( s5*sz[5] ); + dw6 = sw[6] - ( s5*sw[5] ); + dx7 = sx[7] - ( s6*sx[6] ); + dy7 = sy[7] - ( s6*sy[6] ); + dz7 = sz[7] - ( s6*sz[6] ); + dw7 = sw[7] - ( s6*sw[6] ); + + // 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++ ) { + wset( wbuf, iw, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + } + ix += dx6; + iy += dy6; + iz += dz6; + iw += dw6; + } + ix += dx7; + iy += dy7; + iz += dz7; + iw += dw7; + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedternary8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/9d.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/9d.js new file mode 100644 index 000000000000..c0b95c8dc95b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/9d.js @@ -0,0 +1,374 @@ +/** +* @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 ternary 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 output 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 {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @param {Callback} fcn - ternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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' +* }; +* +* // Apply the ternary function: +* ternary9d( x, y, z, w, true, fcn ); +* +* console.log( w.data ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5 ] +*/ +function ternary9d( x, y, z, w, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var wbuf; + var zbuf; + 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 dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dw6; + var dw7; + var dw8; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dz6; + var dz7; + var dz8; + 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 sw; + var sz; + var ix; + var iy; + var iw; + var iz; + 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#, 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; + 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] ); + 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] ); + 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] ); + } 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] ); + 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] ); + 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] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.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++ ) { + wbuf[ iw ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ] ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iw += dw0; + iz += dz0; + } + ix += dx1; + iy += dy1; + iw += dw1; + iz += dz1; + } + ix += dx2; + iy += dy2; + iw += dw2; + iz += dz2; + } + ix += dx3; + iy += dy3; + iw += dw3; + iz += dz3; + } + ix += dx4; + iy += dy4; + iw += dw4; + iz += dz4; + } + ix += dx5; + iy += dy5; + iw += dw5; + iz += dz5; + } + ix += dx6; + iy += dy6; + iw += dw6; + iz += dz6; + } + ix += dx7; + iy += dy7; + iw += dw7; + iz += dz7; + } + ix += dx8; + iy += dy8; + iw += dw8; + iz += dz8; + } +} + + +// EXPORTS // + +module.exports = ternary9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/9d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/9d_accessors.js new file mode 100644 index 000000000000..1c3d757b5ec7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/9d_accessors.js @@ -0,0 +1,394 @@ +/** +* @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 ternary 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 output 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 {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 ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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 +* }; +* +* // Apply the ternary function: +* ternary9d( x, y, z, w, true, fcn ); +* +* console.log( copy( w.data ) ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5 ] +*/ +function ternary9d( x, y, z, w, isRowMajor, fcn ) { + var xbuf; + var ybuf; + var wbuf; + var zbuf; + var xget; + var yget; + var zget; + var wset; + 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 dw0; + var dw1; + var dw2; + var dw3; + var dw4; + var dw5; + var dw6; + var dw7; + var dw8; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var dz5; + var dz6; + var dz7; + var dz8; + 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 sw; + var sz; + var ix; + var iy; + var iw; + var iz; + 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#, dw#, dz#, 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; + 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] ); + 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] ); + 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] ); + } 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] ); + 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] ); + 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] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + iz = z.offset; + iw = w.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache accessors: + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = z.accessors[ 0 ]; + wset = w.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++ ) { + wset( wbuf, iw, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iw += dw0; + iz += dz0; + } + ix += dx1; + iy += dy1; + iw += dw1; + iz += dz1; + } + ix += dx2; + iy += dy2; + iw += dw2; + iz += dz2; + } + ix += dx3; + iy += dy3; + iw += dw3; + iz += dz3; + } + ix += dx4; + iy += dy4; + iw += dw4; + iz += dz4; + } + ix += dx5; + iy += dy5; + iw += dw5; + iz += dz5; + } + ix += dx6; + iy += dy6; + iw += dw6; + iz += dz6; + } + ix += dx7; + iy += dy7; + iw += dw7; + iz += dz7; + } + ix += dx8; + iy += dy8; + iw += dw8; + iz += dz8; + } +} + + +// EXPORTS // + +module.exports = ternary9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/9d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/9d_blocked.js new file mode 100644 index 000000000000..cf65a9c26a20 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/9d_blocked.js @@ -0,0 +1,495 @@ +/** +* @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/ternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a ternary 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 output 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 {Callback} fcn - ternary callback +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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' +* }; +* +* // Apply the ternary function: +* blockedternary9d( x, y, z, w, fcn ); +* +* console.log( w.data ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5 ] +*/ +function blockedternary9d( x, y, z, w, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + 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 ox1; + var oy1; + var oz1; + var ow1; + var ox2; + var oy2; + var oz2; + var ow2; + var ox3; + var oy3; + var oz3; + var ow3; + var ox4; + var oy4; + var oz4; + var ow4; + var ox5; + var oy5; + var oz5; + var ow5; + var ox6; + var oy6; + var oz6; + var ow6; + var ox7; + var oy7; + var oz7; + var ow7; + var ox8; + var oy8; + var oz8; + var ow8; + 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 ox; + var oy; + var oz; + var ow; + var ix; + var iy; + var iz; + var iw; + 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#, 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 ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.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; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[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] ); + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + ox7 = ox8 + ( j7*sx[7] ); + oy7 = oy8 + ( j7*sy[7] ); + oz7 = oz8 + ( j7*sz[7] ); + ow7 = ow8 + ( j7*sw[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + ox6 = ox7 + ( j6*sx[6] ); + oy6 = oy7 + ( j6*sy[6] ); + oz6 = oz7 + ( j6*sz[6] ); + ow6 = ow7 + ( j6*sw[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + ox5 = ox6 + ( j5*sx[5] ); + oy5 = oy6 + ( j5*sy[5] ); + oz5 = oz6 + ( j5*sz[5] ); + ow5 = ow6 + ( j5*sw[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oz4 = oz5 + ( j4*sz[4] ); + ow4 = ow5 + ( j4*sw[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oz3 = oz4 + ( j3*sz[3] ); + ow3 = ow4 + ( j3*sw[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[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] ); + + // 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] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + dz4 = sz[4] - ( s3*sz[3] ); + dw4 = sw[4] - ( s3*sw[3] ); + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + dz5 = sz[5] - ( s4*sz[4] ); + dw5 = sw[5] - ( s4*sw[4] ); + dx6 = sx[6] - ( s5*sx[5] ); + dy6 = sy[6] - ( s5*sy[5] ); + dz6 = sz[6] - ( s5*sz[5] ); + dw6 = sw[6] - ( s5*sw[5] ); + dx7 = sx[7] - ( s6*sx[6] ); + dy7 = sy[7] - ( s6*sy[6] ); + dz7 = sz[7] - ( s6*sz[6] ); + dw7 = sw[7] - ( s6*sw[6] ); + dx8 = sx[8] - ( s7*sx[7] ); + dy8 = sy[8] - ( s7*sy[7] ); + dz8 = sz[8] - ( s7*sz[7] ); + dw8 = sw[8] - ( s7*sw[7] ); + + // 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++ ) { + wbuf[ iw ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ] ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + } + ix += dx6; + iy += dy6; + iz += dz6; + iw += dw6; + } + ix += dx7; + iy += dy7; + iz += dz7; + iw += dw7; + } + ix += dx8; + iy += dy8; + iz += dz8; + iw += dw8; + } + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedternary9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/9d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/9d_blocked_accessors.js new file mode 100644 index 000000000000..e2534dc978dc --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/9d_blocked_accessors.js @@ -0,0 +1,515 @@ +/** +* @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/ternary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); + + +// MAIN // + +/** +* Applies a ternary 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 output 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 {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 ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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, 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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 +* }; +* +* // Apply the ternary function: +* blockedternary9d( x, y, z, w, fcn ); +* +* console.log( copy( w.data ) ); +* // => [ 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5 ] +*/ +function blockedternary9d( x, y, z, w, fcn ) { + var bsize; + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var xget; + var yget; + var zget; + var wset; + 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 ox1; + var oy1; + var oz1; + var ow1; + var ox2; + var oy2; + var oz2; + var ow2; + var ox3; + var oy3; + var oz3; + var ow3; + var ox4; + var oy4; + var oz4; + var ow4; + var ox5; + var oy5; + var oz5; + var ow5; + var ox6; + var oy6; + var oz6; + var ow6; + var ox7; + var oy7; + var oz7; + var ow7; + var ox8; + var oy8; + var oz8; + var ow8; + 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 ox; + var oy; + var oz; + var ow; + var ix; + var iy; + var iz; + var iw; + 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#, 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 ); + sh = o.sh; + sx = o.sx; + sy = o.sy; + sz = o.sz; + sw = o.sw; + + // Determine the block size: + bsize = blockSize( x.dtype, y.dtype, z.dtype, w.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; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache offset increments for the innermost loop... + dx0 = sx[0]; + dy0 = sy[0]; + dz0 = sz[0]; + dw0 = sw[0]; + + // Cache accessors: + xget = x.accessors[0]; + yget = y.accessors[0]; + zget = z.accessors[0]; + wset = w.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] ); + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + ox7 = ox8 + ( j7*sx[7] ); + oy7 = oy8 + ( j7*sy[7] ); + oz7 = oz8 + ( j7*sz[7] ); + ow7 = ow8 + ( j7*sw[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + ox6 = ox7 + ( j6*sx[6] ); + oy6 = oy7 + ( j6*sy[6] ); + oz6 = oz7 + ( j6*sz[6] ); + ow6 = ow7 + ( j6*sw[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + ox5 = ox6 + ( j5*sx[5] ); + oy5 = oy6 + ( j5*sy[5] ); + oz5 = oz6 + ( j5*sz[5] ); + ow5 = ow6 + ( j5*sw[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oz4 = oz5 + ( j4*sz[4] ); + ow4 = ow5 + ( j4*sw[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oz3 = oz4 + ( j3*sz[3] ); + ow3 = ow4 + ( j3*sw[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oz2 = oz3 + ( j2*sz[2] ); + ow2 = ow3 + ( j2*sw[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oz1 = oz2 + ( j1*sz[1] ); + ow1 = ow2 + ( j1*sw[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] ); + + // 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] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + dz2 = sz[2] - ( s1*sz[1] ); + dw2 = sw[2] - ( s1*sw[1] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + dz3 = sz[3] - ( s2*sz[2] ); + dw3 = sw[3] - ( s2*sw[2] ); + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + dz4 = sz[4] - ( s3*sz[3] ); + dw4 = sw[4] - ( s3*sw[3] ); + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + dz5 = sz[5] - ( s4*sz[4] ); + dw5 = sw[5] - ( s4*sw[4] ); + dx6 = sx[6] - ( s5*sx[5] ); + dy6 = sy[6] - ( s5*sy[5] ); + dz6 = sz[6] - ( s5*sz[5] ); + dw6 = sw[6] - ( s5*sw[5] ); + dx7 = sx[7] - ( s6*sx[6] ); + dy7 = sy[7] - ( s6*sy[6] ); + dz7 = sz[7] - ( s6*sz[6] ); + dw7 = sw[7] - ( s6*sw[6] ); + dx8 = sx[8] - ( s7*sx[7] ); + dy8 = sy[8] - ( s7*sy[7] ); + dz8 = sz[8] - ( s7*sz[7] ); + dw8 = sw[8] - ( s7*sw[7] ); + + // 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++ ) { + wset( wbuf, iw, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ) ) ); // eslint-disable-line max-len + ix += dx0; + iy += dy0; + iz += dz0; + iw += dw0; + } + ix += dx1; + iy += dy1; + iz += dz1; + iw += dw1; + } + ix += dx2; + iy += dy2; + iz += dz2; + iw += dw2; + } + ix += dx3; + iy += dy3; + iz += dz3; + iw += dw3; + } + ix += dx4; + iy += dy4; + iz += dz4; + iw += dw4; + } + ix += dx5; + iy += dy5; + iz += dz5; + iw += dw5; + } + ix += dx6; + iy += dy6; + iz += dz6; + iw += dw6; + } + ix += dx7; + iy += dy7; + iz += dz7; + iw += dw7; + } + ix += dx8; + iy += dy8; + iz += dz8; + iw += dw8; + } + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedternary9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/index.js new file mode 100644 index 000000000000..7242ddae67ed --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/index.js @@ -0,0 +1,77 @@ +/** +* @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 ternary callback to elements in input ndarrays and assign results to elements in an output ndarray. +* +* @module @stdlib/ndarray/base/ternary +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var getData = require( '@stdlib/ndarray/data-buffer' ); +* var ternary = require( '@stdlib/ndarray/base/ternary' ); +* +* function fcn( a, b, c ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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' ); +* +* // Apply the ternary function: +* ternary( [ x, y, z, w ], fcn ); +* +* console.log( getData( w ) ); +* // => [ 2.5, 4.5, 6.5, 8.5, 10.5, 12.5 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/main.js new file mode 100644 index 000000000000..596dece10b37 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/main.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. +*/ + +'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 blockedaccessorternary2d = require( './2d_blocked_accessors.js' ); +var blockedaccessorternary3d = require( './3d_blocked_accessors.js' ); +var blockedaccessorternary4d = require( './4d_blocked_accessors.js' ); +var blockedaccessorternary5d = require( './5d_blocked_accessors.js' ); +var blockedaccessorternary6d = require( './6d_blocked_accessors.js' ); +var blockedaccessorternary7d = require( './7d_blocked_accessors.js' ); +var blockedaccessorternary8d = require( './8d_blocked_accessors.js' ); +var blockedaccessorternary9d = require( './9d_blocked_accessors.js' ); +var blockedaccessorternary10d = require( './10d_blocked_accessors.js' ); +var blockedternary2d = require( './2d_blocked.js' ); +var blockedternary3d = require( './3d_blocked.js' ); +var blockedternary4d = require( './4d_blocked.js' ); +var blockedternary5d = require( './5d_blocked.js' ); +var blockedternary6d = require( './6d_blocked.js' ); +var blockedternary7d = require( './7d_blocked.js' ); +var blockedternary8d = require( './8d_blocked.js' ); +var blockedternary9d = require( './9d_blocked.js' ); +var blockedternary10d = require( './10d_blocked.js' ); +var accessorternary0d = require( './0d_accessors.js' ); +var accessorternary1d = require( './1d_accessors.js' ); +var accessorternary2d = require( './2d_accessors.js' ); +var accessorternary3d = require( './3d_accessors.js' ); +var accessorternary4d = require( './4d_accessors.js' ); +var accessorternary5d = require( './5d_accessors.js' ); +var accessorternary6d = require( './6d_accessors.js' ); +var accessorternary7d = require( './7d_accessors.js' ); +var accessorternary8d = require( './8d_accessors.js' ); +var accessorternary9d = require( './9d_accessors.js' ); +var accessorternary10d = require( './10d_accessors.js' ); +var accessorternarynd = require( './nd_accessors.js' ); +var ternary0d = require( './0d.js' ); +var ternary1d = require( './1d.js' ); +var ternary2d = require( './2d.js' ); +var ternary3d = require( './3d.js' ); +var ternary4d = require( './4d.js' ); +var ternary5d = require( './5d.js' ); +var ternary6d = require( './6d.js' ); +var ternary7d = require( './7d.js' ); +var ternary8d = require( './8d.js' ); +var ternary9d = require( './9d.js' ); +var ternary10d = require( './10d.js' ); +var ternarynd = require( './nd.js' ); + + +// VARIABLES // + +var TERNARY = [ + ternary0d, + ternary1d, + ternary2d, + ternary3d, + ternary4d, + ternary5d, + ternary6d, + ternary7d, + ternary8d, + ternary9d, + ternary10d +]; +var ACCESSOR_TERNARY = [ + accessorternary0d, + accessorternary1d, + accessorternary2d, + accessorternary3d, + accessorternary4d, + accessorternary5d, + accessorternary6d, + accessorternary7d, + accessorternary8d, + accessorternary9d, + accessorternary10d +]; +var BLOCKED_TERNARY = [ + blockedternary2d, // 0 + blockedternary3d, + blockedternary4d, + blockedternary5d, + blockedternary6d, + blockedternary7d, + blockedternary8d, + blockedternary9d, + blockedternary10d // 8 +]; +var BLOCKED_ACCESSOR_TERNARY = [ + blockedaccessorternary2d, // 0 + blockedaccessorternary3d, + blockedaccessorternary4d, + blockedaccessorternary5d, + blockedaccessorternary6d, + blockedaccessorternary7d, + blockedaccessorternary8d, + blockedaccessorternary9d, + blockedaccessorternary10d // 8 +]; +var MAX_DIMS = TERNARY.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 +* @returns {boolean} boolean indicating whether an ndarray data buffer implements the accessor protocol +*/ +function hasAccessors( x, y, z, w ) { + return anyIsEntryIn( [ x, y, z, w ], 'accessorProtocol', true ); +} + + +// MAIN // + +/** +* Applies a ternary 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 three input arrays and one output array +* @param {Callback} fcn - ternary 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 ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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' ); +* +* // Apply the ternary function: +* ternary( [ x, y, z, w ], fcn ); +* +* console.log( getData( w ) ); +* // => [ 2.5, 4.5, 6.5, 8.5, 10.5, 12.5 ] +*/ +function ternary( arrays, fcn ) { // eslint-disable-line max-statements + var ndims; + var xmmv; + var ymmv; + var wmmv; + var zmmv; + var shx; + var shy; + var shw; + var shz; + var iox; + var ioy; + var iow; + var ioz; + var len; + var ord; + var sx; + var sy; + var sw; + var sz; + var ox; + var oy; + var ow; + var oz; + var ns; + var x; + var y; + var w; + var z; + 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 ] ); + + // 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; + ndims = shx.length; + if ( + ndims !== shy.length || + ndims !== shw.length || + ndims !== shz.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(w) == %d. ndims(z) == %d.', ndims, shy.length, shz.length, shw.length ) ); + } + // Determine whether we can avoid iteration altogether... + if ( ndims === 0 ) { + if ( hasAccessors( x, y, z, w ) ) { + return ACCESSOR_TERNARY[ ndims ]( x, y, z, w, fcn ); + } + return TERNARY[ ndims ]( x, y, z, w, 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 !== shw[ i ] || d !== shz[ i ] ) { + 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 ) ) { + return ACCESSOR_TERNARY[ ndims ]( x, y, z, w, fcn ); + } + return TERNARY[ ndims ]( x, y, z, w, fcn ); + } + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.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; + x.strides = [ sx[i] ]; + y.strides = [ sy[i] ]; + z.strides = [ sz[i] ]; + w.strides = [ sw[i] ]; + if ( hasAccessors( x, y, w, z ) ) { + return ACCESSOR_TERNARY[ 1 ]( x, y, z, w, fcn ); + } + return TERNARY[ 1 ]( x, y, z, w, fcn ); + } + iox = iterationOrder( sx ); // +/-1 + ioy = iterationOrder( sy ); // +/-1 + ioz = iterationOrder( sz ); // +/-1 + iow = iterationOrder( sw ); // +/-1 + + // Determine whether we can avoid blocked iteration... + ord = strides2order( sx ); + if ( iox !== 0 && ioy !== 0 && iow !== 0 && ioz !== 0 && ord === strides2order( sy ) && ord === strides2order( sw ) && ord === strides2order( sz ) ) { // eslint-disable-line max-len + // 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 ); + + // 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 === ( wmmv[1]-wmmv[0]+1 ) && + len === ( zmmv[1]-zmmv[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 ]; + } + x.shape = [ len ]; + y.shape = x.shape; + z.shape = x.shape; + w.shape = x.shape; + x.strides = [ iox ]; + y.strides = [ ioy ]; + z.strides = [ ioz ]; + w.strides = [ iow ]; + x.offset = ox; + y.offset = oy; + z.offset = oz; + w.offset = ow; + if ( hasAccessors( x, y, z, w ) ) { + return ACCESSOR_TERNARY[ 1 ]( x, y, z, w, fcn ); + } + return TERNARY[ 1 ]( x, y, z, w, 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 ) ) { + return ACCESSOR_TERNARY[ ndims ]( x, y, z, w, ord === 1, fcn ); + } + return TERNARY[ ndims ]( x, y, z, w, ord === 1, fcn ); + } + // Fall-through to blocked 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 ) ) { + return BLOCKED_ACCESSOR_TERNARY[ ndims-2 ]( x, y, z, w, fcn ); + } + return BLOCKED_TERNARY[ ndims-2 ]( x, y, z, w, 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 ) ) { + return accessorternarynd( x, y, z, w, fcn ); + } + ternarynd( x, y, z, w, fcn ); +} + + +// EXPORTS // + +module.exports = ternary; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/nd.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/nd.js new file mode 100644 index 000000000000..6dcf8df5860e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/nd.js @@ -0,0 +1,194 @@ +/** +* @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 numel = require( '@stdlib/ndarray/base/numel' ); +var vind2bind = require( '@stdlib/ndarray/base/vind2bind' ); + + +// MAIN // + +/** +* Applies a ternary 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 output 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 {Callback} fcn - ternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn( a, b, c ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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' +* }; +* +* // Apply the ternary function: +* ternarynd( x, y, z, w, fcn ); +* +* console.log( w.data ); +* // => [ 2.5, 3.5, 4.5, 5.5 ] +*/ +function ternarynd( x, y, z, w, fcn ) { + var xbuf; + var ybuf; + var wbuf; + var zbuf; + var ordx; + var ordy; + var ordw; + var ordz; + var len; + var sh; + var sx; + var sy; + var sw; + var sz; + var ox; + var oy; + var ow; + var oz; + var ix; + var iy; + var iw; + var iz; + var i; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache references to the respective ndarray meta data... + sh = x.shape; + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + ox = x.offset; + oy = y.offset; + oz = z.offset; + ow = w.offset; + ordx = x.order; + ordy = y.order; + ordz = z.order; + ordw = w.order; + + // Compute the total number of elements over which to iterate... + len = numel( sh ); + + // 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' ); + wbuf[ iw ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ] ); + } +} + + +// EXPORTS // + +module.exports = ternarynd; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/lib/nd_accessors.js b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/nd_accessors.js new file mode 100644 index 000000000000..8a811182c8b5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/lib/nd_accessors.js @@ -0,0 +1,215 @@ +/** +* @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 numel = require( '@stdlib/ndarray/base/numel' ); +var vind2bind = require( '@stdlib/ndarray/base/vind2bind' ); + + +// MAIN // + +/** +* Applies a ternary callback to elements in n-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray via loop interchange. +* +* @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 output 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 {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 ) { +* return a + b + c; +* } +* +* // 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( [ 0.5, 0.5, 0.5, 0.5 ] ); +* var wbuf = 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 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 +* }; +* +* // Apply the ternary function: +* ternarynd( x, y, z, w, fcn ); +* +* console.log( copy( w.data ) ); +* // => [ 2.5, 3.5, 4.5, 5.5 ] +*/ +function ternarynd( x, y, z, w, fcn ) { + var xbuf; + var ybuf; + var wbuf; + var zbuf; + var xget; + var yget; + var zget; + var wset; + var ordx; + var ordy; + var ordw; + var ordz; + var len; + var sh; + var sx; + var sy; + var sw; + var sz; + var ox; + var oy; + var ow; + var oz; + var ix; + var iy; + var iw; + var iz; + var i; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + + // Cache accessors: + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = z.accessors[ 0 ]; + wset = w.accessors[ 1 ]; + + // Cache references to the respective ndarray meta data... + sh = x.shape; + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + ox = x.offset; + oy = y.offset; + oz = z.offset; + ow = w.offset; + ordx = x.order; + ordy = y.order; + ordz = z.order; + ordw = w.order; + + // Compute the total number of elements over which to iterate... + len = numel( sh ); + + // 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' ); + wset( wbuf, iw, fcn( xget( xbuf, ix ), yget( ybuf, iy ), zget( zbuf, iz ) ) ); + } +} + + +// EXPORTS // + +module.exports = ternarynd; diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/package.json b/lib/node_modules/@stdlib/ndarray/base/ternary/package.json new file mode 100644 index 000000000000..8bb3f4546ade --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/package.json @@ -0,0 +1,64 @@ +{ + "name": "@stdlib/ndarray/base/ternary", + "version": "0.0.0", + "description": "Apply a ternary 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": { + "benchmark": "./benchmark", + "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", + "ternary", + "apply", + "foreach", + "map", + "transform" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/test/test.0d.js b/lib/node_modules/@stdlib/ndarray/base/ternary/test/test.0d.js new file mode 100644 index 000000000000..c79f1b7399cd --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/test/test.0d.js @@ -0,0 +1,102 @@ +/** +* @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 scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var add3 = require( '@stdlib/number/float64/base/add3' ); +var zadd3 = require( '@stdlib/complex/float64/base/add3' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var ternary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ternary, 'function', 'main export is a function'); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 0-dimensional ndarrays', function test( t ) { + var expected; + var x; + var y; + var z; + var w; + + x = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); + + y = scalar2ndarray( 3.0, { + 'dtype': 'float64' + }); + + z = scalar2ndarray( 2.0, { + 'dtype': 'float64' + }); + + w = scalar2ndarray( 0.0, { + 'dtype': 'float64' + }); + + ternary( [ x, y, z, w ], add3 ); + + expected = new Float64Array( [ 10.0 ] ); + t.strictEqual( isSameFloat64Array( getData( w ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 0-dimensional ndarrays (accessors)', function test( t ) { + var expected; + var x; + var y; + var z; + var w; + + 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( 0.0, 0.0 ), { + 'dtype': 'complex128' + }); + + ternary( [ x, y, z, w ], zadd3 ); + + expected = new Complex128Array( [ 10.0, 10.0 ] ); + t.strictEqual( isSameComplex128Array( getData( w ), expected ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/test/test.1d.js b/lib/node_modules/@stdlib/ndarray/base/ternary/test/test.1d.js new file mode 100644 index 000000000000..3f5a9f8e6ab8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/test/test.1d.js @@ -0,0 +1,118 @@ +/** +* @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 zeros = require( '@stdlib/array/zeros' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var add3 = require( '@stdlib/number/float64/base/add3' ); +var zadd3 = require( '@stdlib/complex/float64/base/add3' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var ternary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ternary, 'function', 'main export is a function'); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 1-dimensional ndarrays', function test( t ) { + var expected; + var x; + var y; + var z; + var w; + + 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', zeros( 4, 'float64' ), [ 4 ], [ 1 ], 0, 'row-major' ); + + ternary( [ x, y, z, w ], add3 ); + + expected = new Float64Array([ + 4.0, + 5.0, + 6.0, + 7.0 + ]); + t.strictEqual( isSameFloat64Array( getData( w ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 1-dimensional ndarrays (empty arrays)', function test( t ) { + var expected; + var x; + var y; + var z; + var w; + + 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', zeros( 4, 'float64' ), [ 0 ], [ 1 ], 0, 'row-major' ); + + ternary( [ x, y, z, w ], add3 ); + + expected = new Float64Array([ + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( getData( w ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 1-dimensional ndarrays (accessors)', function test( t ) { + var expected; + var x; + var y; + var z; + var w; + + 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', zeros( 4, 'complex128' ), [ 4 ], [ 1 ], 0, 'row-major' ); + + ternary( [ x, y, z, w ], zadd3 ); + + expected = new Complex128Array([ + 4.0, + 5.0, + 6.0, + 7.0, + 8.0, + 9.0, + 10.0, + 11.0 + ]); + t.strictEqual( isSameComplex128Array( getData( w ), expected ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/ternary/test/test.2d.js b/lib/node_modules/@stdlib/ndarray/base/ternary/test/test.2d.js new file mode 100644 index 000000000000..6f7db80bd660 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/test/test.2d.js @@ -0,0 +1,1056 @@ +/** +* @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 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 add3 = require( '@stdlib/number/float64/base/add3' ); +var zadd3 = require( '@stdlib/complex/float64/base/add3' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var ternary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ternary, 'function', 'main export is a function'); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], add3 ); + + expected = new Float64Array([ + 3.0, + 6.0, + 9.0, + 12.0 + ]); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], zadd3 ); + + expected = new Complex128Array([ + 3.0, + 6.0, + 9.0, + 12.0, + 15.0, + 18.0, + 21.0, + 24.0 + ]); + t.strictEqual( isSameComplex128Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], add3 ); + + expected = new Float64Array([ + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], add3 ); + + expected = new Float64Array([ + 3.0, + 6.0, + 9.0, + 12.0 + ]); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], add3 ); + + expected = new Float64Array([ + 3.0, + 6.0, + 9.0, + 12.0 + ]); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], add3 ); + + expected = new Float64Array([ + 3.0, + 6.0, + 0.0, + 0.0, + 15.0, + 18.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], add3 ); + + expected = new Float64Array([ + 3.0, + 6.0, + 0.0, + 0.0, + 15.0, + 18.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], add3 ); + + expected = new Float64Array( x.length*2 ); + dfill( x.length, 3.0, expected, st[ 1 ] ); + + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], add3 ); + + expected = new Float64Array( x.length*2 ); + dfill( x.length, 3.0, expected, st[ 1 ] ); + + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], zadd3 ); + + expected = new Complex128Array([ + 3.0, + 6.0, + 9.0, + 12.0, + 15.0, + 18.0, + 21.0, + 24.0 + ]); + t.strictEqual( isSameComplex128Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], zadd3 ); + + expected = new Complex128Array([ + 3.0, + 6.0, + 9.0, + 12.0, + 15.0, + 18.0, + 21.0, + 24.0 + ]); + t.strictEqual( isSameComplex128Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], zadd3 ); + + expected = new Complex128Array([ + 3.0, + 6.0, + 9.0, + 12.0, + 0.0, + 0.0, + 0.0, + 0.0, + 27.0, + 30.0, + 33.0, + 36.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 ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], zadd3 ); + + expected = new Complex128Array([ + 3.0, + 6.0, + 9.0, + 12.0, + 0.0, + 0.0, + 0.0, + 0.0, + 27.0, + 30.0, + 33.0, + 36.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 ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], zadd3 ); + + expected = new Complex128Array( x.length*2 ); + zfill( x.length, new Complex128( 3.0, 3.0 ), expected, st[ 1 ] ); + + t.strictEqual( isSameComplex128Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], zadd3 ); + + expected = new Complex128Array( x.length*2 ); + zfill( x.length, new Complex128( 3.0, 3.0 ), expected, st[ 1 ] ); + + t.strictEqual( isSameComplex128Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], add3 ); + + expected = new Float64Array([ + 3.0, + 6.0, + 9.0, + 12.0 + ]); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], zadd3 ); + + expected = new Complex128Array([ + 3.0, + 6.0, + 9.0, + 12.0, + 15.0, + 18.0, + 21.0, + 24.0 + ]); + t.strictEqual( isSameComplex128Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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' ); + + ternary( [ x, x, x, y ], add3 ); + + 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 ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], add3 ); + + expected = new Float64Array([ + 3.0, + 6.0, + 9.0, + 12.0 + ]); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], add3 ); + + expected = new Float64Array([ + 3.0, + 6.0, + 9.0, + 12.0 + ]); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], add3 ); + + expected = new Float64Array([ + 3.0, + 6.0, + 0.0, + 0.0, + 15.0, + 18.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], add3 ); + + expected = new Float64Array([ + 3.0, + 6.0, + 0.0, + 0.0, + 15.0, + 18.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], add3 ); + + expected = new Float64Array( x.length*2 ); + dfill( x.length, 3.0, expected, st[ 0 ] ); + + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], add3 ); + + expected = new Float64Array( x.length*2 ); + dfill( x.length, 3.0, expected, st[ 0 ] ); + + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], zadd3 ); + + expected = new Complex128Array([ + 3.0, + 6.0, + 9.0, + 12.0, + 15.0, + 18.0, + 21.0, + 24.0 + ]); + t.strictEqual( isSameComplex128Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], zadd3 ); + + expected = new Complex128Array([ + 3.0, + 6.0, + 9.0, + 12.0, + 15.0, + 18.0, + 21.0, + 24.0 + ]); + t.strictEqual( isSameComplex128Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], zadd3 ); + + expected = new Complex128Array([ + 3.0, + 6.0, + 9.0, + 12.0, + 0.0, + 0.0, + 0.0, + 0.0, + 27.0, + 30.0, + 33.0, + 36.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 ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], zadd3 ); + + expected = new Complex128Array([ + 3.0, + 6.0, + 9.0, + 12.0, + 0.0, + 0.0, + 0.0, + 0.0, + 27.0, + 30.0, + 33.0, + 36.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 ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], zadd3 ); + + expected = new Complex128Array( x.length*2 ); + zfill( x.length, new Complex128( 3.0, 3.0 ), expected, st[ 0 ] ); + + t.strictEqual( isSameComplex128Array( getData( y ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a ternary callback to indexed elements of three 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 ); + + ternary( [ x, x, x, y ], zadd3 ); + + expected = new Complex128Array( x.length*2 ); + zfill( x.length, new Complex128( 3.0, 3.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/ternary/test/test.js b/lib/node_modules/@stdlib/ndarray/base/ternary/test/test.js new file mode 100644 index 000000000000..13b4b3c4252c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/ternary/test/test.js @@ -0,0 +1,163 @@ +/** +* @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 ternary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ternary, '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 ] ], + [ [ 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], + [ [ 1, 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1 ], [ 1, 1 ] ], + [ [ 2, 2, 1, 2 ], [ 2, 2, 1 ], [ 2, 1, 2 ], [ 2, 1, 2 ] ], + [ [ 1, 1, 4, 2, 2, 2 ], [ 0 ], [ 10, 2 ], [ 10, 2 ] ], + [ [ 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] ), Error, 'throws an error for index ' + i ); + } + t.end(); + + function add3( a, b, c ) { + return a + b + c; + } + + function badValue( sh1, sh2, sh3, sh4 ) { + return function badValue() { + var dtype; + var ord; + var st1; + var st2; + var st3; + var st4; + var o1; + var o2; + var o3; + var o4; + var x; + var y; + var z; + var w; + + ord = 'row-major'; + dtype = 'float64'; + + st1 = shape2strides( sh1, ord ); + st2 = shape2strides( sh2, ord ); + st3 = shape2strides( sh3, ord ); + st4 = shape2strides( sh4, ord ); + o1 = strides2offset( sh1, st1 ); + o2 = strides2offset( sh2, st2 ); + o3 = strides2offset( sh3, st3 ); + o4 = strides2offset( sh4, st4 ); + + 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 ); + + ternary( [ x, y, z, w ], add3 ); + }; + } +}); + +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 ] ], + [ [ 3, 3 ], [ 2, 2 ], [ 3, 3 ], [ 3, 3 ] ], + [ [ 5, 5, 5 ], [ 5, 5, 4 ], [ 5, 5, 4 ], [ 5, 5, 4 ] ], + [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 1, 1, 2 ], [ 1, 1, 2 ] ], + [ [ 1, 4 ], [ 3, 8 ], [ 4, 4 ], [ 4, 4 ] ], + [ [ 10, 2, 1 ], [ 1, 2, 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] ), Error, 'throws an error for index ' + i ); + } + t.end(); + + function add3( a, b, c ) { + return a + b + c; + } + + function badValue( sh1, sh2, sh3, sh4 ) { + return function badValue() { + var dtype; + var ord; + var st1; + var st2; + var st3; + var st4; + var o1; + var o2; + var o3; + var o4; + var x; + var y; + var z; + var w; + + ord = 'row-major'; + dtype = 'float64'; + + st1 = shape2strides( sh1, ord ); + st2 = shape2strides( sh2, ord ); + st3 = shape2strides( sh3, ord ); + st4 = shape2strides( sh4, ord ); + o1 = strides2offset( sh1, st1 ); + o2 = strides2offset( sh2, st2 ); + o3 = strides2offset( sh3, st3 ); + o4 = strides2offset( sh4, st4 ); + + 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 ); + + ternary( [ x, y, z, w ], add3 ); + }; + } +});