diff --git a/lib/node_modules/@stdlib/ndarray/base/where/README.md b/lib/node_modules/@stdlib/ndarray/base/where/README.md new file mode 100644 index 000000000000..227f88dde87c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/README.md @@ -0,0 +1,221 @@ + + +# Where + +> Apply a condition to elements in two input ndarrays and assign results to elements in an output ndarray. + +
+ +
+ + + +
+ +## Usage + +```javascript +var where = require( '@stdlib/ndarray/base/where' ); +``` + +#### where( arrays ) + +Applies a condition to elements in two input ndarrays and assigns results to elements in an output ndarray. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var Uint8Array = require( '@stdlib/array/uint8' ); + +// Create data buffers: +var cbuf = new Uint8Array( [ 1, 0, 0, 1, 0, 1 ] ); +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 obuf = new Float64Array( 6 ); + +// Define the shape of the input and output arrays: +var shape = [ 3, 1, 2 ]; + +// Define the array strides: +var sc = [ 2, 2, 1 ]; +var sx = [ 2, 2, 1 ]; +var sy = [ 2, 2, 1 ]; +var so = [ 2, 2, 1 ]; + +// Define the index offsets: +var oc = 0; +var ox = 0; +var oy = 0; +var oo = 0; + +// Create the input and output ndarrays: +var condition = { + 'dtype': 'uint8', + 'data': cbuf, + 'shape': shape, + 'strides': sc, + 'offset': oc, + 'order': 'row-major' +}; +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 out = { + 'dtype': 'float64', + 'data': obuf, + 'shape': shape, + 'strides': so, + 'offset': oo, + 'order': 'row-major' +}; + +// Apply the condition: +where( [ condition, x, y, out ] ); + +console.log( out.data ); +// => [ 1.0, -2.0, -3.0, 4.0, -5.0, 6.0 ] +``` + +The function accepts the following arguments: + +- **arrays**: array-like object containing three input ndarrays and one 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). + +
+ + + +
+ +## Notes + +- `condition` ndarray must be a `boolean` or `uint8` ndarray. +- `condition`, `x`, `y`, and `out` ndarrays must have the same shape. +- For very high-dimensional ndarrays which are non-contiguous, one should consider copying the underlying data to contiguous memory before conditionally assigning elements in order to achieve better performance. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var bernoulli = require( '@stdlib/random/base/bernoulli' ).factory; +var filledarray = require( '@stdlib/array/filled' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var where = require( '@stdlib/ndarray/base/where' ); + +var N = 10; +var shape = [ 5, 2 ]; +var condition = { + 'dtype': 'uint8', + 'data': filledarrayBy( N, 'uint8', bernoulli( 0.5 ) ), + 'shape': shape, + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}; +console.log( ndarray2array( condition.data, condition.shape, condition.strides, condition.offset, condition.order ) ); // eslint-disable-line max-len + +var x = { + 'dtype': 'generic', + 'data': filledarrayBy( N, 'generic', discreteUniform( 0, 100 ) ), + 'shape': shape, + '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, 0 ) ), + 'shape': shape, + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}; +console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) ); + +var out = { + 'dtype': 'generic', + 'data': filledarray( 0, N, 'generic' ), + 'shape': shape.slice(), + 'strides': shape2strides( shape, 'column-major' ), + 'offset': 0, + 'order': 'column-major' +}; + +where( [ condition, x, y, out ] ); +console.log( ndarray2array( out.data, out.shape, out.strides, out.offset, out.order ) ); // eslint-disable-line max-len + +``` + +
+ + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.11d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.11d_columnmajor.js new file mode 100644 index 000000000000..ad1bec8e5c92 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.11d_columnmajor.js @@ -0,0 +1,180 @@ +/** +* @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/base/discrete-uniform' ).factory; +var bernoulli = require( '@stdlib/random/base/bernoulli' ).factory; +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var where = require( './../lib/nd.js' ); + + +// VARIABLES // + +var conditionTypes = [ 'uint8' ]; +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} ctype - first input ndarray data type +* @param {string} xtype - second input ndarray data type +* @param {string} ytype - third input ndarray data type +* @param {string} otype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { + var condition; + var out; + var x; + var y; + + condition = filledarrayBy( len, ctype, bernoulli( 0.5 ) ); + x = filledarrayBy( len, xtype, discreteUniform( -100, 100 ) ); + y = filledarrayBy( len, ytype, discreteUniform( -100, 100 ) ); + out = filledarray( 0.0, len, otype ); + + condition = { + 'dtype': ctype, + 'data': condition, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + x = { + 'dtype': xtype, + 'data': x, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + out = { + 'dtype': otype, + 'data': out, + '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++ ) { + where( condition, x, y, out ); + if ( isnan( out.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out.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 sh; + var t1; + var t2; + var t3; + var tc; + var f; + var i; + var j; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < types.length; k++ ) { + t1 = types[ k ]; + t2 = types[ k ]; + t3 = types[ k ]; + for ( j = 0; j < conditionTypes.length; j++ ) { + tc = conditionTypes[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + + len = floor( pow( len, 1.0/11.0 ) ); + sh = [ len, len, len, len, len, len, len, len, len, len, len ]; + len *= pow( len, 10 ); + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + } + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.11d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.11d_rowmajor.js new file mode 100644 index 000000000000..5a98f02cea17 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.11d_rowmajor.js @@ -0,0 +1,180 @@ +/** +* @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/base/discrete-uniform' ).factory; +var bernoulli = require( '@stdlib/random/base/bernoulli' ).factory; +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var where = require( './../lib/nd.js' ); + + +// VARIABLES // + +var conditionTypes = [ 'uint8' ]; +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} ctype - first input ndarray data type +* @param {string} xtype - second input ndarray data type +* @param {string} ytype - third input ndarray data type +* @param {string} otype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { + var condition; + var out; + var x; + var y; + + condition = filledarrayBy( len, ctype, bernoulli( 0.5 ) ); + x = filledarrayBy( len, xtype, discreteUniform( -100, 100 ) ); + y = filledarrayBy( len, ytype, discreteUniform( -100, 100 ) ); + out = filledarray( 0.0, len, otype ); + + condition = { + 'dtype': ctype, + 'data': condition, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + x = { + 'dtype': xtype, + 'data': x, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + out = { + 'dtype': otype, + 'data': out, + '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++ ) { + where( condition, x, y, out ); + if ( isnan( out.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out.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 sh; + var t1; + var t2; + var t3; + var tc; + var f; + var i; + var j; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < types.length; k++ ) { + t1 = types[ k ]; + t2 = types[ k ]; + t3 = types[ k ]; + for ( j = 0; j < conditionTypes.length; j++ ) { + tc = conditionTypes[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + + len = floor( pow( len, 1.0/11.0 ) ); + sh = [ len, len, len, len, len, len, len, len, len, len, len ]; + len *= pow( len, 10 ); + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + } + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.1d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.1d_columnmajor.js new file mode 100644 index 000000000000..d18a02e61962 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.1d_columnmajor.js @@ -0,0 +1,169 @@ +/** +* @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/base/discrete-uniform' ).factory; +var bernoulli = require( '@stdlib/random/base/bernoulli' ).factory; +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var filledarray = require( '@stdlib/array/filled' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var where1d = require( './../lib/1d.js' ); + + +// VARIABLES // + +var conditionTypes = [ 'uint8' ]; +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} ctype - first input ndarray data type +* @param {string} xtype - second input ndarray data type +* @param {string} ytype - third input ndarray data type +* @param {string} otype - fourth input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { + var condition; + var out; + var x; + var y; + + condition = filledarrayBy( len, ctype, bernoulli( 0.5 ) ); + x = filledarrayBy( len, xtype, discreteUniform( -100, 100 ) ); + y = filledarrayBy( len, ytype, discreteUniform( -100, 100 ) ); + out = filledarray( 0.0, len, otype ); + + condition = { + 'dtype': ctype, + 'data': condition, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + x = { + 'dtype': xtype, + 'data': x, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + out = { + 'dtype': otype, + 'data': out, + '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++ ) { + where1d( condition, x, y, out ); + if ( isnan( out.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out.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 sh; + var t1; + var t2; + var t3; + var tc; + var f; + var i; + var j; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < types.length; k++ ) { + t1 = types[ k ]; + t2 = types[ k ]; + t3 = types[ k ]; + for ( j = 0; j < conditionTypes.length; j++ ) { + tc = conditionTypes[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + } + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.1d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.1d_rowmajor.js new file mode 100644 index 000000000000..f422d792785c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.1d_rowmajor.js @@ -0,0 +1,169 @@ +/** +* @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/base/discrete-uniform' ).factory; +var bernoulli = require( '@stdlib/random/base/bernoulli' ).factory; +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var filledarray = require( '@stdlib/array/filled' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var where1d = require( './../lib/1d.js' ); + + +// VARIABLES // + +var conditionTypes = [ 'uint8' ]; +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} ctype - first input ndarray data type +* @param {string} xtype - second input ndarray data type +* @param {string} ytype - third input ndarray data type +* @param {string} otype - fourth input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { + var condition; + var out; + var x; + var y; + + condition = filledarrayBy( len, ctype, bernoulli( 0.5 ) ); + x = filledarrayBy( len, xtype, discreteUniform( -100, 100 ) ); + y = filledarrayBy( len, ytype, discreteUniform( -100, 100 ) ); + out = filledarray( 0.0, len, otype ); + + condition = { + 'dtype': ctype, + 'data': condition, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + x = { + 'dtype': xtype, + 'data': x, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + out = { + 'dtype': otype, + 'data': out, + '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++ ) { + where1d( condition, x, y, out ); + if ( isnan( out.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out.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 sh; + var t1; + var t2; + var t3; + var tc; + var f; + var i; + var j; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < types.length; k++ ) { + t1 = types[ k ]; + t2 = types[ k ]; + t3 = types[ k ]; + for ( j = 0; j < conditionTypes.length; j++ ) { + tc = conditionTypes[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + } + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_blocked_columnmajor.js new file mode 100644 index 000000000000..3552265d8895 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_blocked_columnmajor.js @@ -0,0 +1,181 @@ +/** +* @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/base/discrete-uniform' ).factory; +var bernoulli = require( '@stdlib/random/base/bernoulli' ).factory; +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var filledarray = require( '@stdlib/array/filled' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var where2d = require( './../lib/2d_blocked.js' ); + + +// VARIABLES // + +var conditionTypes = [ 'uint8' ]; +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} ctype - first input ndarray data type +* @param {string} xtype - second input ndarray data type +* @param {string} ytype - third input ndarray data type +* @param {string} otype - fourth input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { + var condition; + var out; + var x; + var y; + + condition = filledarrayBy( len, ctype, bernoulli( 0.5 ) ); + x = filledarrayBy( len, xtype, discreteUniform( -100, 100 ) ); + y = filledarrayBy( len, ytype, discreteUniform( -100, 100 ) ); + out = filledarray( 0.0, len, otype ); + + condition = { + 'dtype': ctype, + 'data': condition, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + x = { + 'dtype': xtype, + 'data': x, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + out = { + 'dtype': otype, + 'data': out, + '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++ ) { + where2d( condition, x, y, out ); + if ( isnan( out.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out.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 sh; + var t1; + var t2; + var t3; + var tc; + var f; + var i; + var j; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < types.length; k++ ) { + t1 = types[ k ]; + t2 = types[ k ]; + t3 = types[ k ]; + for ( j = 0; j < conditionTypes.length; j++ ) { + tc = conditionTypes[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2 ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + } + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_blocked_rowmajor.js new file mode 100644 index 000000000000..9fab1fd2b9c1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_blocked_rowmajor.js @@ -0,0 +1,181 @@ +/** +* @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/base/discrete-uniform' ).factory; +var bernoulli = require( '@stdlib/random/base/bernoulli' ).factory; +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var filledarray = require( '@stdlib/array/filled' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var where2d = require( './../lib/2d_blocked.js' ); + + +// VARIABLES // + +var conditionTypes = [ 'uint8' ]; +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} ctype - first input ndarray data type +* @param {string} xtype - second input ndarray data type +* @param {string} ytype - third input ndarray data type +* @param {string} otype - fourth input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { + var condition; + var out; + var x; + var y; + + condition = filledarrayBy( len, ctype, bernoulli( 0.5 ) ); + x = filledarrayBy( len, xtype, discreteUniform( -100, 100 ) ); + y = filledarrayBy( len, ytype, discreteUniform( -100, 100 ) ); + out = filledarray( 0.0, len, otype ); + + condition = { + 'dtype': ctype, + 'data': condition, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + x = { + 'dtype': xtype, + 'data': x, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + out = { + 'dtype': otype, + 'data': out, + '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++ ) { + where2d( condition, x, y, out ); + if ( isnan( out.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out.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 sh; + var t1; + var t2; + var t3; + var tc; + var f; + var i; + var j; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < types.length; k++ ) { + t1 = types[ k ]; + t2 = types[ k ]; + t3 = types[ k ]; + for ( j = 0; j < conditionTypes.length; j++ ) { + tc = conditionTypes[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2 ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + } + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_columnmajor.js new file mode 100644 index 000000000000..a011c253cdc6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_columnmajor.js @@ -0,0 +1,181 @@ +/** +* @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/base/discrete-uniform' ).factory; +var bernoulli = require( '@stdlib/random/base/bernoulli' ).factory; +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var filledarray = require( '@stdlib/array/filled' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var where2d = require( './../lib/2d.js' ); + + +// VARIABLES // + +var conditionTypes = [ 'uint8' ]; +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} ctype - first input ndarray data type +* @param {string} xtype - second input ndarray data type +* @param {string} ytype - third input ndarray data type +* @param {string} otype - fourth input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { + var condition; + var out; + var x; + var y; + + condition = filledarrayBy( len, ctype, bernoulli( 0.5 ) ); + x = filledarrayBy( len, xtype, discreteUniform( -100, 100 ) ); + y = filledarrayBy( len, ytype, discreteUniform( -100, 100 ) ); + out = filledarray( 0.0, len, otype ); + + condition = { + 'dtype': ctype, + 'data': condition, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + x = { + 'dtype': xtype, + 'data': x, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + out = { + 'dtype': otype, + 'data': out, + '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++ ) { + where2d( condition, x, y, out, false ); + if ( isnan( out.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out.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 sh; + var t1; + var t2; + var t3; + var tc; + var f; + var i; + var j; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < types.length; k++ ) { + t1 = types[ k ]; + t2 = types[ k ]; + t3 = types[ k ]; + for ( j = 0; j < conditionTypes.length; j++ ) { + tc = conditionTypes[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2 ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + } + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_rowmajor.js new file mode 100644 index 000000000000..4f545e2c3b07 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_rowmajor.js @@ -0,0 +1,181 @@ +/** +* @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/base/discrete-uniform' ).factory; +var bernoulli = require( '@stdlib/random/base/bernoulli' ).factory; +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var filledarray = require( '@stdlib/array/filled' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var where2d = require( './../lib/2d.js' ); + + +// VARIABLES // + +var conditionTypes = [ 'uint8' ]; +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} ctype - first input ndarray data type +* @param {string} xtype - second input ndarray data type +* @param {string} ytype - third input ndarray data type +* @param {string} otype - fourth input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { + var condition; + var out; + var x; + var y; + + condition = filledarrayBy( len, ctype, bernoulli( 0.5 ) ); + x = filledarrayBy( len, xtype, discreteUniform( -100, 100 ) ); + y = filledarrayBy( len, ytype, discreteUniform( -100, 100 ) ); + out = filledarray( 0.0, len, otype ); + + condition = { + 'dtype': ctype, + 'data': condition, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + x = { + 'dtype': xtype, + 'data': x, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + out = { + 'dtype': otype, + 'data': out, + '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++ ) { + where2d( condition, x, y, out, true ); + if ( isnan( out.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out.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 sh; + var t1; + var t2; + var t3; + var tc; + var f; + var i; + var j; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < types.length; k++ ) { + t1 = types[ k ]; + t2 = types[ k ]; + t3 = types[ k ]; + for ( j = 0; j < conditionTypes.length; j++ ) { + tc = conditionTypes[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2 ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + } + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_rowmajor_accessors.js b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_rowmajor_accessors.js new file mode 100644 index 000000000000..1e61c3c94fcf --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_rowmajor_accessors.js @@ -0,0 +1,213 @@ +/** +* @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/base/discrete-uniform' ).factory; +var bernoulli = require( '@stdlib/random/base/bernoulli' ).factory; +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var filledarray = require( '@stdlib/array/filled' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var where2d = require( './../lib/2d_accessors.js' ); + + +// VARIABLES // + +var conditionTypes = [ 'uint8' ]; +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Returns an array data buffer element. +* +* @private +* @param {Collection} buf - data buffer +* @param {NonNegativeInteger} idx - element index +* @returns {*} element +*/ +function get( buf, idx ) { + return buf[ idx ]; +} + +/** +* Sets an array data buffer element. +* +* @private +* @param {Collection} buf - data buffer +* @param {NonNegativeInteger} idx - element index +* @param {*} value - value to set +*/ +function set( buf, idx, value ) { + buf[ idx ] = value; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} ctype - first input ndarray data type +* @param {string} xtype - second input ndarray data type +* @param {string} ytype - third input ndarray data type +* @param {string} otype - fourth input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { + var condition; + var out; + var x; + var y; + + condition = filledarrayBy( len, ctype, bernoulli( 0.5 ) ); + x = filledarrayBy( len, xtype, discreteUniform( -100, 100 ) ); + y = filledarrayBy( len, ytype, discreteUniform( -100, 100 ) ); + out = filledarray( 0.0, len, otype ); + + condition = { + 'dtype': ctype, + 'data': condition, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order, + 'accessorProtocol': true, + 'accessors': [ get, set ] + }; + x = { + 'dtype': xtype, + 'data': x, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order, + 'accessorProtocol': true, + 'accessors': [ get, set ] + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order, + 'accessorProtocol': true, + 'accessors': [ get, set ] + }; + out = { + 'dtype': otype, + 'data': out, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order, + 'accessorProtocol': true, + 'accessors': [ get, set ] + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + where2d( condition, x, y, out, true ); + if ( isnan( out.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out.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 sh; + var t1; + var t2; + var t3; + var tc; + var f; + var i; + var j; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < types.length; k++ ) { + t1 = types[ k ]; + t2 = types[ k ]; + t3 = types[ k ]; + for ( j = 0; j < conditionTypes.length; j++ ) { + tc = conditionTypes[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2 ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s::accessors:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s::accessors:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s::accessors:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + } + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_rowmajor_accessors_complex.js b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_rowmajor_accessors_complex.js new file mode 100644 index 000000000000..6f5220287062 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_rowmajor_accessors_complex.js @@ -0,0 +1,231 @@ +/** +* @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/base/discrete-uniform' ).factory; +var bernoulli = require( '@stdlib/random/base/bernoulli' ).factory; +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var filledarray = require( '@stdlib/array/filled' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var ctors = require( '@stdlib/array/ctors' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var where2d = require( './../lib/2d_accessors.js' ); + + +// VARIABLES // + +var conditionTypes = [ 'bool' ]; +var types = [ 'complex64' ]; +var order = 'row-major'; +var abtype = { + 'complex64': 'float32', + 'complex128': 'float64' +}; + + +// FUNCTIONS // + +/** +* Returns an array data buffer element. +* +* @private +* @param {Collection} buf - data buffer +* @param {NonNegativeInteger} idx - element index +* @returns {*} element +*/ +function get( buf, idx ) { + return buf.get( idx ); +} + +/** +* Sets an array data buffer element. +* +* @private +* @param {Collection} buf - data buffer +* @param {NonNegativeInteger} idx - element index +* @param {*} value - value to set +*/ +function set( buf, idx, value ) { + buf.set( value, idx ); +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} ctype - first input ndarray data type +* @param {string} xtype - second input ndarray data type +* @param {string} ytype - third input ndarray data type +* @param {string} otype - fourth input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { + var condition; + var cstrides; + var cshape; + var stride; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + var x; + var y; + + cbuf = filledarrayBy( len, ctype, bernoulli( 0.5 ) ); + xbuf = filledarrayBy( len*2, abtype[ xtype ], discreteUniform( -100, 100 ) ); // eslint-disable-line max-len + ybuf = filledarrayBy( len*2, abtype[ ytype ], discreteUniform( -100, 100 ) ); // eslint-disable-line max-len + obuf = filledarray( 0.0, len*2, abtype[ otype ] ); + + // Broadcast extra dimension along last axis for the condition array for complex compatibility. + stride = shape2strides( shape, order ); + cshape = shape.slice(); + cshape.push( 1 ); + cstrides = stride.slice(); + cstrides.push( 0 ); + condition = { + 'dtype': ctype, + 'data': new ( ctors( ctype ) )( cbuf.buffer ), + 'shape': cshape, + 'strides': cstrides, + 'offset': 0, + 'order': order, + 'accessorProtocol': true, + 'accessors': [ get, set ] + }; + x = { + 'dtype': xtype, + 'data': new ( ctors( xtype ) )( xbuf.buffer ), + 'shape': shape, + 'strides': stride, + 'offset': 0, + 'order': order, + 'accessorProtocol': true, + 'accessors': [ get, set ] + }; + y = { + 'dtype': ytype, + 'data': new ( ctors( ytype ) )( ybuf.buffer ), + 'shape': shape, + 'strides': stride, + 'offset': 0, + 'order': order, + 'accessorProtocol': true, + 'accessors': [ get, set ] + }; + out = { + 'dtype': otype, + 'data': new ( ctors( otype ) )( obuf.buffer ), + 'shape': shape, + 'strides': stride, + 'offset': 0, + 'order': order, + 'accessorProtocol': true, + 'accessors': [ get, set ] + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + where2d( condition, x, y, out, true ); + if ( isnan( obuf[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( obuf[ 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 sh; + var t1; + var t2; + var t3; + var tc; + var f; + var i; + var j; + var k; + + min = 1; // 10^min + max = 5; // 10^max + + for ( k = 0; k < types.length; k++ ) { + t1 = types[ k ]; + t2 = types[ k ]; + t3 = types[ k ]; + for ( j = 0; j < conditionTypes.length; j++ ) { + tc = conditionTypes[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2 ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s::accessors:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s::accessors:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s::accessors:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + } + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.3d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.3d_blocked_columnmajor.js new file mode 100644 index 000000000000..dcbb0c62979a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.3d_blocked_columnmajor.js @@ -0,0 +1,181 @@ +/** +* @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/base/discrete-uniform' ).factory; +var bernoulli = require( '@stdlib/random/base/bernoulli' ).factory; +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var filledarray = require( '@stdlib/array/filled' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var where3d = require( './../lib/3d_blocked.js' ); + + +// VARIABLES // + +var conditionTypes = [ 'uint8' ]; +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} ctype - first input ndarray data type +* @param {string} xtype - second input ndarray data type +* @param {string} ytype - third input ndarray data type +* @param {string} otype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { + var condition; + var out; + var x; + var y; + + condition = filledarrayBy( len, ctype, bernoulli( 0.5 ) ); + x = filledarrayBy( len, xtype, discreteUniform( -100, 100 ) ); + y = filledarrayBy( len, ytype, discreteUniform( -100, 100 ) ); + out = filledarray( 0.0, len, otype ); + + condition = { + 'dtype': ctype, + 'data': condition, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + x = { + 'dtype': xtype, + 'data': x, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + out = { + 'dtype': otype, + 'data': out, + '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++ ) { + where3d( condition, x, y, out ); + if ( isnan( out.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out.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 sh; + var t1; + var t2; + var t3; + var tc; + var f; + var i; + var j; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < types.length; k++ ) { + t1 = types[ k ]; + t2 = types[ k ]; + t3 = types[ k ]; + for ( j = 0; j < conditionTypes.length; j++ ) { + tc = conditionTypes[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1 ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + + sh = [ 1, 2, len/2 ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + + len = floor( sqrt( len ) ); + sh = [ len, len, len ]; + len *= len; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + } + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.3d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.3d_blocked_rowmajor.js new file mode 100644 index 000000000000..3707105c1454 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.3d_blocked_rowmajor.js @@ -0,0 +1,181 @@ +/** +* @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/base/discrete-uniform' ).factory; +var bernoulli = require( '@stdlib/random/base/bernoulli' ).factory; +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var filledarray = require( '@stdlib/array/filled' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var where3d = require( './../lib/3d_blocked.js' ); + + +// VARIABLES // + +var conditionTypes = [ 'uint8' ]; +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} ctype - first input ndarray data type +* @param {string} xtype - second input ndarray data type +* @param {string} ytype - third input ndarray data type +* @param {string} otype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { + var condition; + var out; + var x; + var y; + + condition = filledarrayBy( len, ctype, bernoulli( 0.5 ) ); + x = filledarrayBy( len, xtype, discreteUniform( -100, 100 ) ); + y = filledarrayBy( len, ytype, discreteUniform( -100, 100 ) ); + out = filledarray( 0.0, len, otype ); + + condition = { + 'dtype': ctype, + 'data': condition, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + x = { + 'dtype': xtype, + 'data': x, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + out = { + 'dtype': otype, + 'data': out, + '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++ ) { + where3d( condition, x, y, out ); + if ( isnan( out.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out.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 sh; + var t1; + var t2; + var t3; + var tc; + var f; + var i; + var j; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < types.length; k++ ) { + t1 = types[ k ]; + t2 = types[ k ]; + t3 = types[ k ]; + for ( j = 0; j < conditionTypes.length; j++ ) { + tc = conditionTypes[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1 ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + + sh = [ 1, 2, len/2 ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + + len = floor( sqrt( len ) ); + sh = [ len, len, len ]; + len *= len; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + } + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.3d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.3d_columnmajor.js new file mode 100644 index 000000000000..9a36839bd9e3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.3d_columnmajor.js @@ -0,0 +1,181 @@ +/** +* @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/base/discrete-uniform' ).factory; +var bernoulli = require( '@stdlib/random/base/bernoulli' ).factory; +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var filledarray = require( '@stdlib/array/filled' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var where3d = require( './../lib/3d.js' ); + + +// VARIABLES // + +var conditionTypes = [ 'uint8' ]; +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} ctype - first input ndarray data type +* @param {string} xtype - second input ndarray data type +* @param {string} ytype - third input ndarray data type +* @param {string} otype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { + var condition; + var out; + var x; + var y; + + condition = filledarrayBy( len, ctype, bernoulli( 0.5 ) ); + x = filledarrayBy( len, xtype, discreteUniform( -100, 100 ) ); + y = filledarrayBy( len, ytype, discreteUniform( -100, 100 ) ); + out = filledarray( 0.0, len, otype ); + + condition = { + 'dtype': ctype, + 'data': condition, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + x = { + 'dtype': xtype, + 'data': x, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + out = { + 'dtype': otype, + 'data': out, + '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++ ) { + where3d( condition, x, y, out, false ); + if ( isnan( out.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out.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 sh; + var t1; + var t2; + var t3; + var tc; + var f; + var i; + var j; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < types.length; k++ ) { + t1 = types[ k ]; + t2 = types[ k ]; + t3 = types[ k ]; + for ( j = 0; j < conditionTypes.length; j++ ) { + tc = conditionTypes[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1 ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + + sh = [ 1, 2, len/2 ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + + len = floor( sqrt( len ) ); + sh = [ len, len, len ]; + len *= len; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + } + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.3d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.3d_rowmajor.js new file mode 100644 index 000000000000..0c927ad70e68 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.3d_rowmajor.js @@ -0,0 +1,182 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var bernoulli = require( '@stdlib/random/base/bernoulli' ).factory; +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var filledarray = require( '@stdlib/array/filled' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var where3d = require( './../lib/3d.js' ); + + +// VARIABLES // + +var conditionTypes = [ 'uint8' ]; +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} ctype - first input ndarray data type +* @param {string} xtype - second input ndarray data type +* @param {string} ytype - third input ndarray data type +* @param {string} otype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { + var condition; + var out; + var x; + var y; + + condition = filledarrayBy( len, ctype, bernoulli( 0.5 ) ); + x = filledarrayBy( len, xtype, discreteUniform( -100, 100 ) ); + y = filledarrayBy( len, ytype, discreteUniform( -100, 100 ) ); + out = filledarray( 0.0, len, otype ); + + condition = { + 'dtype': ctype, + 'data': condition, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + x = { + 'dtype': xtype, + 'data': x, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + out = { + 'dtype': otype, + 'data': out, + '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(); + console.log(b.iterations); + for ( i = 0; i < b.iterations; i++ ) { + where3d( condition, x, y, out, true ); + if ( isnan( out.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out.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 sh; + var t1; + var t2; + var t3; + var tc; + var f; + var i; + var j; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < types.length; k++ ) { + t1 = types[ k ]; + t2 = types[ k ]; + t3 = types[ k ]; + for ( j = 0; j < conditionTypes.length; j++ ) { + tc = conditionTypes[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1 ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + + sh = [ 1, 2, len/2 ]; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + + len = floor( sqrt( len ) ); + sh = [ len, len, len ]; + len *= len; + f = createBenchmark( len, sh, tc, t1, t2, t3 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],order=%s,ctype=%s,xtype=%s,ytype=%s,otype=%s', pkg, sh.length, len, sh.join( ',' ), order, tc, t1, t2, t3 ), f ); + } + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/where/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/where/docs/repl.txt new file mode 100644 index 000000000000..09594d8e8d39 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/docs/repl.txt @@ -0,0 +1,89 @@ + +{{alias}}( arrays ) + Applies a condition to elements in two input ndarrays and assigns 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. + + Examples + -------- + // Define ndarray data and meta data... + > var cbuf = new {{alias:@stdlib/array/uint8}}( [ 1, 0, 0, 1 ] ); + > var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var ybuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); + > var obuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); + > var dtype = 'float64'; + > var shape = [ 2, 2 ]; + > var sc = [ 2, 1 ]; + > var sx = [ 2, 1 ]; + > var sy = [ 2, 1 ]; + > var so = [ 2, 1 ]; + > var oc = 0; + > var ox = 0; + > var oy = 0; + > var oo = 0; + > var order = 'row-major'; + + // Using ndarrays... + > var condition = {{alias:@stdlib/ndarray/ctor}}( 'uint8', cbuf, shape, sc, oc, order ); + > 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 out = {{alias:@stdlib/ndarray/ctor}}( dtype, obuf, shape, so, oo, order ); + > {{alias}}( [ condition, x, y, out ] ); + > out.data + [ 1.0, -2.0, -3.0, 4.0 ] + + // Using minimal ndarray-like objects... + > condition = { + ... 'dtype': 'uint8', + ... 'data': cbuf, + ... 'shape': shape, + ... 'strides': sc, + ... 'offset': oc, + ... 'order': order + ... }; + > 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 + ... }; + > out = { + ... 'dtype': dtype, + ... 'data': obuf, + ... 'shape': shape, + ... 'strides': so, + ... 'offset': oo, + ... 'order': order + ... }; + > {{alias}}( [ condition, x, y, out ] ); + > out.data + [ 1.0, -2.0, -3.0, 4.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/base/where/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/where/docs/types/index.d.ts new file mode 100644 index 000000000000..7594d1962465 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/docs/types/index.d.ts @@ -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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { ArrayLike } from '@stdlib/types/array'; +import { ndarray } from '@stdlib/types/ndarray'; + +/** +* Applies a condition to elements in two input ndarrays and assigns results to elements in an output ndarray. +* +* @param arrays - array-like object containing three input ndarrays and one output ndarray +* @throws arrays must have the same number of dimensions +* @throws arrays must have the same shape +* @throws condition array must be a boolean or uint8 ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create data buffers: +* var cbuf = new Uint8Array( [ 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1 ] ); +* 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, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] ); +* var obuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sc = [ 4, 4, 1 ]; +* var sx = [ 4, 4, 1 ]; +* var sy = [ 4, 4, 1 ]; +* var so = [ 2, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 1; +* var ox = 1; +* var oy = 1; +* var oo = 0; +* +* // Create the input and output ndarrays: +* var condition = ndarray( 'uint8', cbuf, shape, sc, oc, 'row-major' ); +* var x = ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' ); +* var y = ndarray( 'float64', ybuf, shape, sy, oy, 'row-major' ); +* var out = ndarray( 'float64', obuf, shape, so, oo, 'row-major' ); +* +* // Apply the condition: +* where( [ condition, x, y, out ] ); +* +* console.log( out.data ); +* // => [ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ] +*/ +declare function where( arrays: ArrayLike ): void; + + +// EXPORTS // + +export = where; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/where/docs/types/test.ts new file mode 100644 index 000000000000..ce13ebab15d8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/docs/types/test.ts @@ -0,0 +1,61 @@ +/* +* @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 where = require( './index' ); + + +// TESTS // + +// The function returns `undefined`... +{ + const condition = zeros( [ 2, 2 ], { + 'dtype': 'uint8' + }); + const x = zeros( [ 2, 2 ] ); + const y = zeros( [ 2, 2 ] ); + const out = zeros( [ 2, 2 ] ); + const arrays = [ condition, x, y, out ]; + + where( arrays ); // $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... +{ + where( '5' ); // $ExpectError + where( 5 ); // $ExpectError + where( true ); // $ExpectError + where( false ); // $ExpectError + where( null ); // $ExpectError + where( undefined ); // $ExpectError + where( {} ); // $ExpectError + where( [ 1 ] ); // $ExpectError + where( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const condition = zeros( [ 2, 2 ] ); + const x = zeros( [ 2, 2 ] ); + const y = zeros( [ 2, 2 ] ); + const out = zeros( [ 2, 2 ] ); + const arrays = [ condition, x, y, out ]; + + where(); // $ExpectError + where( arrays, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/where/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/where/examples/index.js new file mode 100644 index 000000000000..29d4d9cad23b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/examples/index.js @@ -0,0 +1,71 @@ +/** +* @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 bernoulli = require( '@stdlib/random/base/bernoulli' ).factory; +var filledarray = require( '@stdlib/array/filled' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var where = require( './../lib' ); + +var N = 10; +var shape = [ 5, 2 ]; +var condition = { + 'dtype': 'uint8', + 'data': filledarrayBy( N, 'uint8', bernoulli( 0.5 ) ), + 'shape': shape, + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}; +console.log( ndarray2array( condition.data, condition.shape, condition.strides, condition.offset, condition.order ) ); // eslint-disable-line max-len + +var x = { + 'dtype': 'generic', + 'data': filledarrayBy( N, 'generic', discreteUniform( 0, 100 ) ), + 'shape': shape, + '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, 0 ) ), + 'shape': shape, + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}; +console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) ); + +var out = { + 'dtype': 'generic', + 'data': filledarray( 0, N, 'generic' ), + 'shape': shape.slice(), + 'strides': shape2strides( shape, 'column-major' ), + 'offset': 0, + 'order': 'column-major' +}; + +where( [ condition, x, y, out ] ); +console.log( ndarray2array( out.data, out.shape, out.strides, out.offset, out.order ) ); // eslint-disable-line max-len diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/0d.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/0d.js new file mode 100644 index 000000000000..4b2d066dde26 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/0d.js @@ -0,0 +1,129 @@ +/** +* @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 condition to two zero-dimensional input ndarrays according to a zero-dimensional boolean ndarray and assigns the result to elements in a zero-dimensional output ndarray. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* +* // Create data buffers: +* var cbuf = new Uint8Array( [ 1 ] ); +* var xbuf = new Float64Array( [ 1.0 ] ); +* var ybuf = new Float64Array( [ 2.0 ] ); +* var obuf = new Float64Array( 1 ); +* +* // Define the shape of the arrays (0-dimensional = scalar): +* var shape = []; +* +* // Define the array strides: +* var sc = [ 0 ]; +* var sx = [ 0 ]; +* var sy = [ 0 ]; +* var so = [ 0 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 0; +* var oy = 0; +* var oo = 0; +* +* // Create the ndarray-like objects: +* var condition = { +* 'dtype': 'uint8', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major' +* }; +* 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 out = { +* 'dtype': 'float64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major' +* }; +* +* // Apply the condition: +* where0d( condition, x, y, out ); +* +* console.log( out.data ); +* // => [ 1.0 ] +*/ +function where0d( condition, x, y, out ) { + out.data[ out.offset ] = ( condition.data[ condition.offset ] ) ? x.data[ x.offset ] : y.data[ y.offset ]; // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = where0d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/0d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/0d_accessors.js new file mode 100644 index 000000000000..9d978e5f01b2 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/0d_accessors.js @@ -0,0 +1,153 @@ +/** +* @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 condition to two zero-dimensional input ndarrays according to a zero-dimensional boolean ndarray and assigns the result to elements in a zero-dimensional output ndarray. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} condition.accessors - data buffer accessors +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} out.accessors - data buffer accessors +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var BooleanArray = require( '@stdlib/array/bool' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var cbuf = new BooleanArray( [ 1 ] ); +* var xbuf = new Complex64Array( [ 1.0, 2.0 ] ); +* var ybuf = new Complex64Array( [ 3.0, 4.0 ] ); +* var obuf = new Complex64Array( 1 ); +* +* // Define the shape of the arrays (0-dimensional = scalar): +* var shape = []; +* +* // Define the array strides: +* var sc = [ 0 ]; +* var sx = [ 0 ]; +* var sy = [ 0 ]; +* var so = [ 0 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 0; +* var oy = 0; +* var oo = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the ndarray-like objects: +* var condition = { +* 'dtype': 'bool', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var out = { +* 'dtype': 'complex64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the condition: +* where0d( condition, x, y, out ); +* +* var v = out.data.get( 0 ); +* +* var re = realf( v ); +* // returns 1.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function where0d( condition, x, y, out ) { + out.accessors[ 1 ]( out.data, out.offset, ( condition.accessors[ 0 ]( condition.data, condition.offset ) ) ? x.accessors[ 0 ]( x.data, x.offset ) : y.accessors[ 0 ]( y.data, y.offset ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = where0d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/10d.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/10d.js new file mode 100644 index 000000000000..9a0085a3463f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/10d.js @@ -0,0 +1,392 @@ +/** +* @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 */ + +'use strict'; + +// MAIN // + +/** +* Applies a condition to two ten-dimensional input ndarrays according to a ten-dimensional boolean ndarray and assigns results to elements in a ten-dimensional output ndarray. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* +* // Create data buffers: +* var cbuf = new Uint8Array( [ 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1 ] ); +* 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, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] ); +* var obuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sc = [ 12, 12, 12, 12, 12, 12, 12, 4, 4, 1 ]; +* var sx = [ 12, 12, 12, 12, 12, 12, 12, 4, 4, 1 ]; +* var sy = [ 12, 12, 12, 12, 12, 12, 12, 4, 4, 1 ]; +* var so = [ 6, 6, 6, 6, 6, 6, 6, 2, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 1; +* var ox = 1; +* var oy = 1; +* var oo = 0; +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'uint8', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major' +* }; +* 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 out = { +* 'dtype': 'float64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major' +* }; +* +* // Apply the condition: +* where10d( condition, x, y, out, true ); +* +* console.log( out.data ); +* // => [ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ] +*/ +function where10d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements, max-lines-per-function + var cbuf; + var xbuf; + var ybuf; + var obuf; + var dc0; + var dc1; + var dc2; + var dc3; + var dc4; + var dc5; + var dc6; + var dc7; + var dc8; + var dc9; + 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 do0; + var do1; + var do2; + var do3; + var do4; + var do5; + var do6; + var do7; + var do8; + var do9; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var S8; + var S9; + var sc; + var sx; + var sy; + var so; + var ic; + var ix; + var iy; + var io; + 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#, dc#, dx#, dy#, do#, 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; + sc = condition.strides; + sx = x.strides; + sy = y.strides; + so = out.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 ]; + dc0 = sc[ 9 ]; // offset increment for innermost loop + dc1 = sc[ 8 ] - ( S0*sc[9] ); + dc2 = sc[ 7 ] - ( S1*sc[8] ); + dc3 = sc[ 6 ] - ( S2*sc[7] ); + dc4 = sc[ 5 ] - ( S3*sc[6] ); + dc5 = sc[ 4 ] - ( S4*sc[5] ); + dc6 = sc[ 3 ] - ( S5*sc[4] ); + dc7 = sc[ 2 ] - ( S6*sc[3] ); + dc8 = sc[ 1 ] - ( S7*sc[2] ); + dc9 = sc[ 0 ] - ( S8*sc[1] ); // offset increment for outermost loop + dx0 = sx[ 9 ]; + 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] ); + 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] ); + do0 = so[ 9 ]; + do1 = so[ 8 ] - ( S0*so[9] ); + do2 = so[ 7 ] - ( S1*so[8] ); + do3 = so[ 6 ] - ( S2*so[7] ); + do4 = so[ 5 ] - ( S3*so[6] ); + do5 = so[ 4 ] - ( S4*so[5] ); + do6 = so[ 3 ] - ( S5*so[4] ); + do7 = so[ 2 ] - ( S6*so[3] ); + do8 = so[ 1 ] - ( S7*so[2] ); + do9 = so[ 0 ] - ( S8*so[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 ]; + dc0 = sc[ 0 ]; // offset increment for innermost loop + dc1 = sc[ 1 ] - ( S0*sc[0] ); + dc2 = sc[ 2 ] - ( S1*sc[1] ); + dc3 = sc[ 3 ] - ( S2*sc[2] ); + dc4 = sc[ 4 ] - ( S3*sc[3] ); + dc5 = sc[ 5 ] - ( S4*sc[4] ); + dc6 = sc[ 6 ] - ( S5*sc[5] ); + dc7 = sc[ 7 ] - ( S6*sc[6] ); + dc8 = sc[ 8 ] - ( S7*sc[7] ); + dc9 = sc[ 9 ] - ( S8*sc[8] ); // offset increment for outermost loop + dx0 = sx[ 0 ]; + 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] ); + 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] ); + do0 = so[ 0 ]; + do1 = so[ 1 ] - ( S0*so[0] ); + do2 = so[ 2 ] - ( S1*so[1] ); + do3 = so[ 3 ] - ( S2*so[2] ); + do4 = so[ 4 ] - ( S3*so[3] ); + do5 = so[ 5 ] - ( S4*so[4] ); + do6 = so[ 6 ] - ( S5*so[5] ); + do7 = so[ 7 ] - ( S6*so[6] ); + do8 = so[ 8 ] - ( S7*so[7] ); + do9 = so[ 9 ] - ( S8*so[8] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ic = condition.offset; + ix = x.offset; + iy = y.offset; + io = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.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++ ) { + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; // eslint-disable-line max-len + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + ic += dc4; + ix += dx4; + iy += dy4; + io += do4; + } + ic += dc5; + ix += dx5; + iy += dy5; + io += do5; + } + ic += dc6; + ix += dx6; + iy += dy6; + io += do6; + } + ic += dc7; + ix += dx7; + iy += dy7; + io += do7; + } + ic += dc8; + ix += dx8; + iy += dy8; + io += do8; + } + ic += dc9; + ix += dx9; + iy += dy9; + io += do9; + } +} + + +// EXPORTS // + +module.exports = where10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/10d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/10d_accessors.js new file mode 100644 index 000000000000..2ff07aaa0632 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/10d_accessors.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 */ + +'use strict'; + +// MAIN // + +/** +* Applies a condition to two ten-dimensional input ndarrays according to a ten-dimensional boolean ndarray and assigns results to elements in a ten-dimensional output ndarray. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} condition.accessors - data buffer accessors +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} out.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var BooleanArray = require( '@stdlib/array/bool' ); +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var cbuf = new BooleanArray( [ 1, 0, 0, 1, 0, 1, 1, 0 ] ); +* var xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0] ); +* var ybuf = new Complex64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 ] ); +* var obuf = new Complex64Array( 4 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sc = [ 4, 4, 4, 4, 4, 4, 4, 4, 2, 1 ]; +* var sx = [ 4, 4, 4, 4, 4, 4, 4, 4, 2, 1 ]; +* var sy = [ 4, 4, 4, 4, 4, 4, 4, 4, 2, 1 ]; +* var so = [ 4, 4, 4, 4, 4, 4, 4, 4, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 0; +* var oy = 0; +* var oo = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'bool', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var out = { +* 'dtype': 'complex64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the condition: +* where10d( condition, x, y, out, true ); +* +* var v = out.data.get( 0 ); +* +* var re = realf( v ); +* // returns 1.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function where10d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements, max-lines-per-function + var cbuf; + var xbuf; + var ybuf; + var obuf; + var getc; + var getx; + var gety; + var seto; + var dc0; + var dc1; + var dc2; + var dc3; + var dc4; + var dc5; + var dc6; + var dc7; + var dc8; + var dc9; + 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 do0; + var do1; + var do2; + var do3; + var do4; + var do5; + var do6; + var do7; + var do8; + var do9; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var S8; + var S9; + var sc; + var sx; + var sy; + var so; + var ic; + var ix; + var iy; + var io; + 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#, dc#, dx#, dy#, do#, 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; + sc = condition.strides; + sx = x.strides; + sy = y.strides; + so = out.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 ]; + dc0 = sc[ 9 ]; // offset increment for innermost loop + dc1 = sc[ 8 ] - ( S0*sc[9] ); + dc2 = sc[ 7 ] - ( S1*sc[8] ); + dc3 = sc[ 6 ] - ( S2*sc[7] ); + dc4 = sc[ 5 ] - ( S3*sc[6] ); + dc5 = sc[ 4 ] - ( S4*sc[5] ); + dc6 = sc[ 3 ] - ( S5*sc[4] ); + dc7 = sc[ 2 ] - ( S6*sc[3] ); + dc8 = sc[ 1 ] - ( S7*sc[2] ); + dc9 = sc[ 0 ] - ( S8*sc[1] ); // offset increment for outermost loop + dx0 = sx[ 9 ]; + 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] ); + 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] ); + do0 = so[ 9 ]; + do1 = so[ 8 ] - ( S0*so[9] ); + do2 = so[ 7 ] - ( S1*so[8] ); + do3 = so[ 6 ] - ( S2*so[7] ); + do4 = so[ 5 ] - ( S3*so[6] ); + do5 = so[ 4 ] - ( S4*so[5] ); + do6 = so[ 3 ] - ( S5*so[4] ); + do7 = so[ 2 ] - ( S6*so[3] ); + do8 = so[ 1 ] - ( S7*so[2] ); + do9 = so[ 0 ] - ( S8*so[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 ]; + dc0 = sc[ 0 ]; // offset increment for innermost loop + dc1 = sc[ 1 ] - ( S0*sc[0] ); + dc2 = sc[ 2 ] - ( S1*sc[1] ); + dc3 = sc[ 3 ] - ( S2*sc[2] ); + dc4 = sc[ 4 ] - ( S3*sc[3] ); + dc5 = sc[ 5 ] - ( S4*sc[4] ); + dc6 = sc[ 6 ] - ( S5*sc[5] ); + dc7 = sc[ 7 ] - ( S6*sc[6] ); + dc8 = sc[ 8 ] - ( S7*sc[7] ); + dc9 = sc[ 9 ] - ( S8*sc[8] ); // offset increment for outermost loop + dx0 = sx[ 0 ]; + 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] ); + 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] ); + do0 = so[ 0 ]; + do1 = so[ 1 ] - ( S0*so[0] ); + do2 = so[ 2 ] - ( S1*so[1] ); + do3 = so[ 3 ] - ( S2*so[2] ); + do4 = so[ 4 ] - ( S3*so[3] ); + do5 = so[ 5 ] - ( S4*so[4] ); + do6 = so[ 6 ] - ( S5*so[5] ); + do7 = so[ 7 ] - ( S6*so[6] ); + do8 = so[ 8 ] - ( S7*so[7] ); + do9 = so[ 9 ] - ( S8*so[8] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ic = condition.offset; + ix = x.offset; + iy = y.offset; + io = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache accessors: + getc = condition.accessors[ 0 ]; + getx = x.accessors[ 0 ]; + gety = y.accessors[ 0 ]; + seto = out.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++ ) { + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + ic += dc4; + ix += dx4; + iy += dy4; + io += do4; + } + ic += dc5; + ix += dx5; + iy += dy5; + io += do5; + } + ic += dc6; + ix += dx6; + iy += dy6; + io += do6; + } + ic += dc7; + ix += dx7; + iy += dy7; + io += do7; + } + ic += dc8; + ix += dx8; + iy += dy8; + io += do8; + } + ic += dc9; + ix += dx9; + iy += dy9; + io += do9; + } +} + + +// EXPORTS // + +module.exports = where10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/10d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/10d_blocked.js new file mode 100644 index 000000000000..97d684b4abb0 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/10d_blocked.js @@ -0,0 +1,528 @@ +/** +* @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-len, max-lines */ + +'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 condition to two ten-dimensional input ndarrays according to a ten-dimensional boolean ndarray and assigns results to elements in a ten-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* +* // Create data buffers: +* var cbuf = new Uint8Array( [ 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1 ] ); +* 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, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] ); +* var obuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sc = [ 12, 12, 12, 12, 12, 12, 12, 4, 4, 1 ]; +* var sx = [ 12, 12, 12, 12, 12, 12, 12, 4, 4, 1 ]; +* var sy = [ 12, 12, 12, 12, 12, 12, 12, 4, 4, 1 ]; +* var so = [ 6, 6, 6, 6, 6, 6, 6, 2, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 1; +* var ox = 1; +* var oy = 1; +* var oo = 0; +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'uint8', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major' +* }; +* 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 out = { +* 'dtype': 'float64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major' +* }; +* +* // Apply the condition: +* blockedwhere10d( condition, x, y, out ); +* +* console.log( out.data ); +* // => [ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ] +*/ +function blockedwhere10d( condition, x, y, out ) { // eslint-disable-line max-statements, max-lines-per-function + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var dc0; + var dc1; + var dc2; + var dc3; + var dc4; + var dc5; + var dc6; + var dc7; + var dc8; + var dc9; + 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 do0; + var do1; + var do2; + var do3; + var do4; + var do5; + var do6; + var do7; + var do8; + var do9; + var oc1; + var oc2; + var oc3; + var oc4; + var oc5; + var oc6; + var oc7; + var oc8; + var oc9; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var ox6; + var ox7; + var ox8; + var ox9; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oy6; + var oy7; + var oy8; + var oy9; + var oo1; + var oo2; + var oo3; + var oo4; + var oo5; + var oo6; + var oo7; + var oo8; + var oo9; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var s8; + var s9; + var sc; + var sx; + var sy; + var so; + var oc; + var ox; + var oy; + var oo; + var ic; + var ix; + var iy; + var io; + 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#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( condition.shape, condition.strides, x.strides, y.strides, out.strides ); + + // Strides output as follows: sx, sy, sz, sw. According to arguments order respectively.. + sh = o.sh; + sc = o.sx; + sx = o.sy; + sy = o.sz; + so = o.sw; + + // Determine the block size: + bsize = blockSize( condition.dtype, x.dtype, y.dtype, out.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + oc = condition.offset; + ox = x.offset; + oy = y.offset; + oo = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache offset increments for the innermost loop... + dc0 = sc[0]; + dx0 = sx[0]; + dy0 = sy[0]; + do0 = so[0]; + + // Iterate over blocks... + for ( j9 = sh[9]; j9 > 0; ) { + if ( j9 < bsize ) { + s9 = j9; + j9 = 0; + } else { + s9 = bsize; + j9 -= bsize; + } + oc9 = oc + ( j9*sc[9] ); + ox9 = ox + ( j9*sx[9] ); + oy9 = oy + ( j9*sy[9] ); + oo9 = oo + ( j9*so[9] ); + for ( j8 = sh[8]; j8 > 0; ) { + if ( j8 < bsize ) { + s8 = j8; + j8 = 0; + } else { + s8 = bsize; + j8 -= bsize; + } + dc9 = sc[9] - ( s8*sc[8] ); + dx9 = sx[9] - ( s8*sx[8] ); + dy9 = sy[9] - ( s8*sy[8] ); + do9 = so[9] - ( s8*so[8] ); + oc8 = oc9 + ( j8*sc[8] ); + ox8 = ox9 + ( j8*sx[8] ); + oy8 = oy9 + ( j8*sy[8] ); + oo8 = oo9 + ( j8*so[8] ); + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + dc8 = sc[8] - ( s7*sc[7] ); + dx8 = sx[8] - ( s7*sx[7] ); + dy8 = sy[8] - ( s7*sy[7] ); + do8 = so[8] - ( s7*so[7] ); + oc7 = oc8 + ( j7*sc[7] ); + ox7 = ox8 + ( j7*sx[7] ); + oy7 = oy8 + ( j7*sy[7] ); + oo7 = oo8 + ( j7*so[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + dc7 = sc[7] - ( s6*sc[6] ); + dx7 = sx[7] - ( s6*sx[6] ); + dy7 = sy[7] - ( s6*sy[6] ); + do7 = so[7] - ( s6*so[6] ); + oc6 = oc7 + ( j6*sc[6] ); + ox6 = ox7 + ( j6*sx[6] ); + oy6 = oy7 + ( j6*sy[6] ); + oo6 = oo7 + ( j6*so[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dc6 = sc[6] - ( s5*sc[5] ); + dx6 = sx[6] - ( s5*sx[5] ); + dy6 = sy[6] - ( s5*sy[5] ); + do6 = so[6] - ( s5*so[5] ); + oc5 = oc6 + ( j5*sc[5] ); + ox5 = ox6 + ( j5*sx[5] ); + oy5 = oy6 + ( j5*sy[5] ); + oo5 = oo6 + ( j5*so[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dc5 = sc[5] - ( s4*sc[4] ); + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + do5 = so[5] - ( s4*so[4] ); + oc4 = oc5 + ( j4*sc[4] ); + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oo4 = oo5 + ( j4*so[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dc4 = sc[4] - ( s3*sc[3] ); + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + do4 = so[4] - ( s3*so[3] ); + oc3 = oc4 + ( j3*sc[3] ); + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oo3 = oo4 + ( j3*so[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dc3 = sc[3] - ( s2*sc[2] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + do3 = so[3] - ( s2*so[2] ); + oc2 = oc3 + ( j2*sc[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oo2 = oo3 + ( j2*so[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dc2 = sc[2] - ( s1*sc[1] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + do2 = so[2] - ( s1*so[1] ); + oc1 = oc2 + ( j1*sc[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oo1 = oo2 + ( j1*so[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... + ic = oc1 + ( j0*sc[0] ); + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + io = oo1 + ( j0*so[0] ); + + // Compute loop offset increments... + dc1 = sc[1] - ( s0*sc[0] ); + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + do1 = so[1] - ( s0*so[0] ); + + // Iterate over the ndarray dimensions... + for ( i9 = 0; i9 < s9; i9++ ) { + for ( i8 = 0; i8 < s8; i8++ ) { + for ( i7 = 0; i7 < s7; i7++ ) { + for ( i6 = 0; i6 < s6; i6++ ) { + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + ic += dc4; + ix += dx4; + iy += dy4; + io += do4; + } + ic += dc5; + ix += dx5; + iy += dy5; + io += do5; + } + ic += dc6; + ix += dx6; + iy += dy6; + io += do6; + } + ic += dc7; + ix += dx7; + iy += dy7; + io += do7; + } + ic += dc8; + ix += dx8; + iy += dy8; + io += do8; + } + ic += dc9; + ix += dx9; + iy += dy9; + io += do9; + } + } + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhere10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/10d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/10d_blocked_accessors.js new file mode 100644 index 000000000000..801472edcbfc --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/10d_blocked_accessors.js @@ -0,0 +1,563 @@ +/** +* @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-len, max-lines */ + +'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 condition to two ten-dimensional input ndarrays according to a ten-dimensional boolean ndarray and assigns results to elements in a ten-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} condition.accessors - data buffer accessors +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} out.accessors - data buffer accessors +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var BooleanArray = require( '@stdlib/array/bool' ) +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var cbuf = new BooleanArray( [ 1, 0, 0, 1, 0, 1, 1, 0 ] ); +* var xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = new Complex64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 ] ); +* var obuf = new Complex64Array( 4 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sc = [ 4, 4, 4, 4, 4, 4, 4, 4, 2, 1 ]; +* var sx = [ 4, 4, 4, 4, 4, 4, 4, 4, 2, 1 ]; +* var sy = [ 4, 4, 4, 4, 4, 4, 4, 4, 2, 1 ]; +* var so = [ 4, 4, 4, 4, 4, 4, 4, 4, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 0; +* var oy = 0; +* var oo = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'bool', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var out = { +* 'dtype': 'complex64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the condition: +* blockedwhere10d( condition, x, y, out ); +* +* var v = out.data.get( 0 ); +* +* var re = realf( v ); +* // returns 1.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function blockedwhere10d( condition, x, y, out ) { // eslint-disable-line max-statements, max-lines-per-function + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var getc; + var getx; + var gety; + var seto; + var dc0; + var dc1; + var dc2; + var dc3; + var dc4; + var dc5; + var dc6; + var dc7; + var dc8; + var dc9; + 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 do0; + var do1; + var do2; + var do3; + var do4; + var do5; + var do6; + var do7; + var do8; + var do9; + var oc1; + var oc2; + var oc3; + var oc4; + var oc5; + var oc6; + var oc7; + var oc8; + var oc9; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var ox6; + var ox7; + var ox8; + var ox9; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oy6; + var oy7; + var oy8; + var oy9; + var oo1; + var oo2; + var oo3; + var oo4; + var oo5; + var oo6; + var oo7; + var oo8; + var oo9; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var s8; + var s9; + var sc; + var sx; + var sy; + var so; + var oc; + var ox; + var oy; + var oo; + var ic; + var ix; + var iy; + var io; + 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#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( condition.shape, condition.strides, x.strides, y.strides, out.strides ); + + // Strides output as follows: sx, sy, sz, sw. According to arguments order respectively.. + sh = o.sh; + sc = o.sx; + sx = o.sy; + sy = o.sz; + so = o.sw; + + // Determine the block size: + bsize = blockSize( condition.dtype, x.dtype, y.dtype, out.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + oc = condition.offset; + ox = x.offset; + oy = y.offset; + oo = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache offset increments for the innermost loop... + dc0 = sc[0]; + dx0 = sx[0]; + dy0 = sy[0]; + do0 = so[0]; + + // Cache accessors: + getc = condition.accessors[0]; + getx = x.accessors[0]; + gety = y.accessors[0]; + seto = out.accessors[1]; + + // Iterate over blocks... + for ( j9 = sh[9]; j9 > 0; ) { + if ( j9 < bsize ) { + s9 = j9; + j9 = 0; + } else { + s9 = bsize; + j9 -= bsize; + } + oc9 = oc + ( j9*sc[9] ); + ox9 = ox + ( j9*sx[9] ); + oy9 = oy + ( j9*sy[9] ); + oo9 = oo + ( j9*so[9] ); + for ( j8 = sh[8]; j8 > 0; ) { + if ( j8 < bsize ) { + s8 = j8; + j8 = 0; + } else { + s8 = bsize; + j8 -= bsize; + } + dc9 = sc[9] - ( s8*sc[8] ); + dx9 = sx[9] - ( s8*sx[8] ); + dy9 = sy[9] - ( s8*sy[8] ); + do9 = so[9] - ( s8*so[8] ); + oc8 = oc9 + ( j8*sc[8] ); + ox8 = ox9 + ( j8*sx[8] ); + oy8 = oy9 + ( j8*sy[8] ); + oo8 = oo9 + ( j8*so[8] ); + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + dc8 = sc[8] - ( s7*sc[7] ); + dx8 = sx[8] - ( s7*sx[7] ); + dy8 = sy[8] - ( s7*sy[7] ); + do8 = so[8] - ( s7*so[7] ); + oc7 = oc8 + ( j7*sc[7] ); + ox7 = ox8 + ( j7*sx[7] ); + oy7 = oy8 + ( j7*sy[7] ); + oo7 = oo8 + ( j7*so[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + dc7 = sc[7] - ( s6*sc[6] ); + dx7 = sx[7] - ( s6*sx[6] ); + dy7 = sy[7] - ( s6*sy[6] ); + do7 = so[7] - ( s6*so[6] ); + oc6 = oc7 + ( j6*sc[6] ); + ox6 = ox7 + ( j6*sx[6] ); + oy6 = oy7 + ( j6*sy[6] ); + oo6 = oo7 + ( j6*so[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dc6 = sc[6] - ( s5*sc[5] ); + dx6 = sx[6] - ( s5*sx[5] ); + dy6 = sy[6] - ( s5*sy[5] ); + do6 = so[6] - ( s5*so[5] ); + oc5 = oc6 + ( j5*sc[5] ); + ox5 = ox6 + ( j5*sx[5] ); + oy5 = oy6 + ( j5*sy[5] ); + oo5 = oo6 + ( j5*so[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dc5 = sc[5] - ( s4*sc[4] ); + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + do5 = so[5] - ( s4*so[4] ); + oc4 = oc5 + ( j4*sc[4] ); + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oo4 = oo5 + ( j4*so[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dc4 = sc[4] - ( s3*sc[3] ); + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + do4 = so[4] - ( s3*so[3] ); + oc3 = oc4 + ( j3*sc[3] ); + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oo3 = oo4 + ( j3*so[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dc3 = sc[3] - ( s2*sc[2] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + do3 = so[3] - ( s2*so[2] ); + oc2 = oc3 + ( j2*sc[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oo2 = oo3 + ( j2*so[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dc2 = sc[2] - ( s1*sc[1] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + do2 = so[2] - ( s1*so[1] ); + oc1 = oc2 + ( j1*sc[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oo1 = oo2 + ( j1*so[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... + ic = oc1 + ( j0*sc[0] ); + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + io = oo1 + ( j0*so[0] ); + + // Compute loop offset increments... + dc1 = sc[1] - ( s0*sc[0] ); + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + do1 = so[1] - ( s0*so[0] ); + + // Iterate over the ndarray dimensions... + for ( i9 = 0; i9 < s9; i9++ ) { + for ( i8 = 0; i8 < s8; i8++ ) { + for ( i7 = 0; i7 < s7; i7++ ) { + for ( i6 = 0; i6 < s6; i6++ ) { + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + ic += dc4; + ix += dx4; + iy += dy4; + io += do4; + } + ic += dc5; + ix += dx5; + iy += dy5; + io += do5; + } + ic += dc6; + ix += dx6; + iy += dy6; + io += do6; + } + ic += dc7; + ix += dx7; + iy += dy7; + io += do7; + } + ic += dc8; + ix += dx8; + iy += dy8; + io += do8; + } + ic += dc9; + ix += dx9; + iy += dy9; + io += do9; + } + } + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhere10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/1d.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/1d.js new file mode 100644 index 000000000000..70e0649a1d04 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/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'; + +// MAIN // + +/** +* Applies a condition to two one-dimensional input ndarrays according to a one-dimensional boolean ndarray and assigns results to elements in a one-dimensional output ndarray. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* +* // Create data buffers: +* var cbuf = new Uint8Array( [ 1, 0, 1, 0 ] ); +* 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, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 ] ); +* var obuf = new Float64Array( 4 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 4 ]; +* +* // Define the array strides: +* var sc = [ 1 ]; +* var sx = [ 2 ]; +* var sy = [ 2 ]; +* var so = [ 1 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 0; +* var oy = 0; +* var oo = 0; +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'uint8', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major' +* }; +* 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 out = { +* 'dtype': 'float64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major' +* }; +* +* // Apply the condition: +* where1d( condition, x, y, out ); +* +* console.log( out.data ); +* // => [ 1.0, -3.0, 5.0, -7.0 ] +*/ +function where1d( condition, x, y, out ) { + var cbuf; + var xbuf; + var ybuf; + var obuf; + var dout; + var dc; + var dx; + var dy; + var ic; + var ix; + var iy; + var io; + var S; + var i; + + // Extract loop variables: dimensions and loop offset (pointer) increments... + S = x.shape[ 0 ]; + dc = condition.strides[ 0 ]; + dx = x.strides[ 0 ]; + dy = y.strides[ 0 ]; + dout = out.strides[ 0 ]; + + // Set the pointers to the first indexed elements in the respective ndarrays... + ic = condition.offset; + ix = x.offset; + iy = y.offset; + io = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Iterate over the ndarray dimensions... + for ( i = 0; i < S; i++ ) { + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; + ic += dc; + ix += dx; + iy += dy; + io += dout; + } +} + + +// EXPORTS // + +module.exports = where1d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/1d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/1d_accessors.js new file mode 100644 index 000000000000..af7afc0df3f2 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/1d_accessors.js @@ -0,0 +1,204 @@ +/** +* @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 condition to two one-dimensional input ndarrays according to a one-dimensional boolean ndarray and assigns results to elements in a one-dimensional output ndarray. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} condition.accessors - data buffer accessors +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} out.accessors - data buffer accessors +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var BooleanArray = require( '@stdlib/array/bool' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var cbuf = new BooleanArray( [ 1, 0, 1, 0, 1, 0, 1, 0 ] ); +* var xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = new Complex64Array( [-1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0] ); +* var obuf = new Complex64Array( 4 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 4 ]; +* +* // Define the array strides: +* var sc = [ 1 ]; +* var sx = [ 1 ]; +* var sy = [ 1 ]; +* var so = [ 1 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 0; +* var oy = 0; +* var oo = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'bool', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var out = { +* 'dtype': 'complex64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the condition: +* where1d( condition, x, y, out ); +* +* var v = out.data.get( 0 ); +* +* var re = realf( v ); +* // returns 1.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function where1d( condition, x, y, out ) { + var cbuf; + var xbuf; + var ybuf; + var obuf; + var getc; + var getx; + var gety; + var seto; + var dout; + var dc; + var dx; + var dy; + var ic; + var ix; + var iy; + var io; + var i; + var S; + + // Extract loop variables: dimensions and loop offset (pointer) increments... + S = x.shape[ 0 ]; + dc = condition.strides[ 0 ]; + dx = x.strides[ 0 ]; + dy = y.strides[ 0 ]; + dout = out.strides[ 0 ]; + + // Set the pointers to the first indexed elements in the respective ndarrays... + ic = condition.offset; + ix = x.offset; + iy = y.offset; + io = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache accessors: + getc = condition.accessors[ 0 ]; + getx = x.accessors[ 0 ]; + gety = y.accessors[ 0 ]; + seto = out.accessors[ 1 ]; + + // Iterate over the ndarray dimensions... + for ( i = 0; i < S; i++ ) { + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len + ic += dc; + ix += dx; + iy += dy; + io += dout; + } +} + + +// EXPORTS // + +module.exports = where1d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/2d.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/2d.js new file mode 100644 index 000000000000..6377911b2240 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/2d.js @@ -0,0 +1,214 @@ +/** +* @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 condition to two two-dimensional input ndarrays according to a two-dimensional boolean ndarray and assigns results to elements in a two-dimensional output ndarray. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* +* // Create data buffers: +* var cbuf = new Uint8Array( [ 1, 0, 0, 1 ] ); +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); +* var obuf = new Float64Array( 4 ); +* +* // Define the shape of the arrays: +* var shape = [ 2, 2 ]; +* +* // Define the array strides: +* var sc = [ 2, 1 ]; +* var sx = [ 2, 1 ]; +* var sy = [ 2, 1 ]; +* var so = [ 2, 1 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 0; +* var oy = 0; +* var oo = 0; +* +* // Create the ndarray-like objects: +* var condition = { +* 'dtype': 'uint8', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major' +* }; +* 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 out = { +* 'dtype': 'float64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major' +* }; +* +* // Apply the condition: +* where2d( condition, x, y, out, true ); +* +* console.log( out.data ); +* // => [ 1.0, -2.0, -3.0, 4.0 ] +*/ +function where2d( condition, x, y, out, isRowMajor ) { + var cbuf; + var xbuf; + var ybuf; + var obuf; + var dc0; + var dc1; + var dx0; + var dx1; + var dy0; + var dy1; + var do0; + var do1; + var sh; + var S0; + var S1; + var sc; + var sx; + var sy; + var so; + var ic; + var ix; + var iy; + var io; + var i0; + var i1; + + // Note on variable naming convention: S#, dc#, dx#, dy#, do#, 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 = condition.shape; + sc = condition.strides; + sx = x.strides; + sy = y.strides; + so = out.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 1 ]; + S1 = sh[ 0 ]; + dc0 = sc[ 1 ]; // offset increment for innermost loop + dc1 = sc[ 0 ] - ( S0*sc[1] ); // offset increment for outermost loop + dx0 = sx[ 1 ]; + dx1 = sx[ 0 ] - ( S0*sx[1] ); + dy0 = sy[ 1 ]; + dy1 = sy[ 0 ] - ( S0*sy[1] ); + do0 = so[ 1 ]; + do1 = so[ 0 ] - ( S0*so[1] ); + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + dc0 = sc[ 0 ]; // offset increment for innermost loop + dc1 = sc[ 1 ] - ( S0*sc[0] ); // offset increment for outermost loop + dx0 = sx[ 0 ]; + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + do0 = so[ 0 ]; + do1 = so[ 1 ] - ( S0*so[0] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ic = condition.offset; + ix = x.offset; + iy = y.offset; + io = out.offset; + + // Cache references to the ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Iterate over the ndarray dimensions... + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } +} + + +// EXPORTS // + +module.exports = where2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_accessors.js new file mode 100644 index 000000000000..cdae1c4f4d5e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_accessors.js @@ -0,0 +1,248 @@ +/** +* @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 condition to two two-dimensional input ndarrays according to a two-dimensional boolean ndarray and assigns results to elements in a two-dimensional output ndarray. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} condition.accessors - data buffer accessors +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} out.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var BooleanArray = require( '@stdlib/array/bool' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var cbuf = new BooleanArray( [ 1, 0, 0, 1 ] ); +* var xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = new Complex64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 ] ); +* var obuf = new Complex64Array( 4 ); +* +* // Define the shape of the arrays: +* var shape = [ 2, 2 ]; +* +* // Define the array strides: +* var sc = [ 2, 1 ]; +* var sx = [ 2, 1 ]; +* var sy = [ 2, 1 ]; +* var so = [ 2, 1 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 0; +* var oy = 0; +* var oo = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the ndarray-like objects: +* var condition = { +* 'dtype': 'bool', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var out = { +* 'dtype': 'complex64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the condition: +* where2d( condition, x, y, out, true ); +* +* var v = out.data.get( 0 ); +* +* var re = realf( v ); +* // returns 1.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function where2d( condition, x, y, out, isRowMajor ) { + var cbuf; + var xbuf; + var ybuf; + var obuf; + var getc; + var getx; + var gety; + var seto; + var dc0; + var dc1; + var dx0; + var dx1; + var dy0; + var dy1; + var do0; + var do1; + var sh; + var S0; + var S1; + var sc; + var sx; + var sy; + var so; + var ic; + var ix; + var iy; + var io; + var i0; + var i1; + + // Note on variable naming convention: S#, dc#, dx#, dy#, do#, 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 = condition.shape; + sc = condition.strides; + sx = x.strides; + sy = y.strides; + so = out.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 1 ]; + S1 = sh[ 0 ]; + dc0 = sc[ 1 ]; // offset increment for innermost loop + dc1 = sc[ 0 ] - ( S0*sc[1] ); // offset increment for outermost loop + dx0 = sx[ 1 ]; + dx1 = sx[ 0 ] - ( S0*sx[1] ); + dy0 = sy[ 1 ]; + dy1 = sy[ 0 ] - ( S0*sy[1] ); + do0 = so[ 1 ]; + do1 = so[ 0 ] - ( S0*so[1] ); + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + dc0 = sc[ 0 ]; // offset increment for innermost loop + dc1 = sc[ 1 ] - ( S0*sc[0] ); // offset increment for outermost loop + dx0 = sx[ 0 ]; + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + do0 = so[ 0 ]; + do1 = so[ 1 ] - ( S0*so[0] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ic = condition.offset; + ix = x.offset; + iy = y.offset; + io = out.offset; + + // Cache references to the ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache accessors: + getc = condition.accessors[ 0 ]; + getx = x.accessors[ 0 ]; + gety = y.accessors[ 0 ]; + seto = out.accessors[ 1 ]; + + // Iterate over the ndarray dimensions... + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } +} + + +// EXPORTS // + +module.exports = where2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_blocked.js new file mode 100644 index 000000000000..4972c535f5d7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_blocked.js @@ -0,0 +1,254 @@ +/** +* @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 condition to two two-dimensional input ndarrays according to a two-dimensional boolean ndarray and assigns results to elements in a two-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* +* // Create data buffers: +* var cbuf = new Uint8Array( [ 1, 0, 0, 1 ] ); +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = new Float64Array( [ 10.0, 20.0, 30.0, 40.0 ] ); +* var obuf = new Float64Array( 4 ); +* +* // Define the shape of the arrays: +* var shape = [ 2, 2 ]; +* +* // Define the array strides: +* var sc = [ 2, 1 ]; +* var sx = [ 4, 1 ]; +* var sy = [ 2, 1 ]; +* var so = [ 2, 1 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 1; +* var oy = 0; +* var oo = 0; +* +* // Create the ndarray-like objects: +* var condition = { +* 'dtype': 'uint8', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major' +* }; +* 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 out = { +* 'dtype': 'float64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major' +* }; +* +* // Apply the condition: +* blockedwhere2d( condition, x, y, out ); +* +* console.log( out.data ); +* // => [ 2.0, 20.0, 30.0, 7.0 ] +*/ +function blockedwhere2d( condition, x, y, out ) { + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var dc0; + var dc1; + var dx0; + var dx1; + var dy0; + var dy1; + var do0; + var do1; + var oc1; + var ox1; + var oy1; + var oo1; + var sh; + var s0; + var s1; + var sc; + var sx; + var sy; + var so; + var oc; + var ox; + var oy; + var oo; + var ic; + var ix; + var iy; + var io; + var i0; + var i1; + var j0; + var j1; + var o; + + // Note on variable naming convention: s#, dc#, dx#, dy#, do#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( condition.shape, condition.strides, x.strides, y.strides, out.strides ); // eslint-disable-line max-len + + // Strides output as follows: sx, sy, sz, sw. According to arguments order respectively.. + sh = o.sh; + sc = o.sx; + sx = o.sy; + sy = o.sz; + so = o.sw; + + // Determine the block size: + bsize = blockSize( condition.dtype, x.dtype, y.dtype, out.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + oc = condition.offset; + ox = x.offset; + oy = y.offset; + oo = out.offset; + + // Cache references to the inputs and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache offset increments for the innermost loop... + dc0 = sc[ 0 ]; + dx0 = sx[ 0 ]; + dy0 = sy[ 0 ]; + do0 = so[ 0 ]; + + // Iterate over blocks... + for ( j1 = sh[ 1 ]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + oc1 = oc + ( j1*sc[ 1 ] ); + ox1 = ox + ( j1*sx[ 1 ] ); + oy1 = oy + ( j1*sy[ 1 ] ); + oo1 = oo + ( j1*so[ 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 inputs and output ndarray elements in the current block... + ic = oc1 + ( j0*sc[ 0 ] ); + ix = ox1 + ( j0*sx[ 0 ] ); + iy = oy1 + ( j0*sy[ 0 ] ); + io = oo1 + ( j0*so[ 0 ] ); + + // Compute loop offset increments... + dc1 = sc[ 1 ] - ( s0*sc[ 0 ] ); + dx1 = sx[ 1 ] - ( s0*sx[ 0 ] ); + dy1 = sy[ 1 ] - ( s0*sy[ 0 ] ); + do1 = so[ 1 ] - ( s0*so[ 0 ] ); + + // Iterate over the ndarray dimensions... + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhere2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_blocked_accessors.js new file mode 100644 index 000000000000..afb16e352854 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_blocked_accessors.js @@ -0,0 +1,288 @@ +/** +* @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 condition to two two-dimensional input ndarrays according to a two-dimensional boolean ndarray and assigns results to elements in a two-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} condition.accessors - data buffer accessors +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} out.accessors - data buffer accessors +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var BooleanArray = require( '@stdlib/array/bool' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var cbuf = new BooleanArray( [ 1, 0, 0, 1 ] ); +* var xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = new Complex64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 ] ); +* var obuf = new Complex64Array( 4 ); +* +* // Define the shape of the arrays: +* var shape = [ 2, 2 ]; +* +* // Define the array strides: +* var sc = [ 2, 1 ]; +* var sx = [ 2, 1 ]; +* var sy = [ 2, 1 ]; +* var so = [ 2, 1 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 0; +* var oy = 0; +* var oo = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the ndarray-like objects: +* var condition = { +* 'dtype': 'bool', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var out = { +* 'dtype': 'complex64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the condition: +* blockedwhere2d( condition, x, y, out ); +* +* var v = out.data.get( 0 ); +* +* var re = realf( v ); +* // returns 1.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function blockedwhere2d( condition, x, y, out ) { + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var getc; + var getx; + var gety; + var seto; + var dc0; + var dc1; + var dx0; + var dx1; + var dy0; + var dy1; + var do0; + var do1; + var oc1; + var ox1; + var oy1; + var oo1; + var sh; + var s0; + var s1; + var sc; + var sx; + var sy; + var so; + var oc; + var ox; + var oy; + var oo; + var ic; + var ix; + var iy; + var io; + var i0; + var i1; + var j0; + var j1; + var o; + + // Note on variable naming convention: s#, dc#, dx#, dy#, do#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( condition.shape, condition.strides, x.strides, y.strides, out.strides ); // eslint-disable-line max-len + + // Strides output as follows: sx, sy, sz, sw. According to arguments order respectively.. + sh = o.sh; + sc = o.sx; + sx = o.sy; + sy = o.sz; + so = o.sw; + + // Determine the block size: + bsize = blockSize( condition.dtype, x.dtype, y.dtype, out.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + oc = condition.offset; + ox = x.offset; + oy = y.offset; + oo = out.offset; + + // Cache references to the inputs and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache offset increments for the innermost loop... + dc0 = sc[ 0 ]; + dx0 = sx[ 0 ]; + dy0 = sy[ 0 ]; + do0 = so[ 0 ]; + + // Cache accessors: + getc = condition.accessors[ 0 ]; + getx = x.accessors[ 0 ]; + gety = y.accessors[ 0 ]; + seto = out.accessors[ 1 ]; + + // Iterate over blocks... + for ( j1 = sh[ 1 ]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + oc1 = oc + ( j1*sc[ 1 ] ); + ox1 = ox + ( j1*sx[ 1 ] ); + oy1 = oy + ( j1*sy[ 1 ] ); + oo1 = oo + ( j1*so[ 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 inputs and output ndarray elements in the current block... + ic = oc1 + ( j0*sc[ 0 ] ); + ix = ox1 + ( j0*sx[ 0 ] ); + iy = oy1 + ( j0*sy[ 0 ] ); + io = oo1 + ( j0*so[ 0 ] ); + + // Compute loop offset increments... + dc1 = sc[ 1 ] - ( s0*sc[ 0 ] ); + dx1 = sx[ 1 ] - ( s0*sx[ 0 ] ); + dy1 = sy[ 1 ] - ( s0*sy[ 0 ] ); + do1 = so[ 1 ] - ( s0*so[ 0 ] ); + + // Iterate over the ndarray dimensions... + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhere2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/3d.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/3d.js new file mode 100644 index 000000000000..aa352e68b1fa --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/3d.js @@ -0,0 +1,236 @@ +/** +* @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 condition to two three-dimensional input ndarrays according to a three-dimensional boolean ndarray and assigns results to elements in a three-dimensional output ndarray. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* +* // Create data buffers: +* var cbuf = new Uint8Array( [ 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1 ] ); +* 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, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] ); +* var obuf = new Float64Array( 6 ); +* +* // Define the shape of the arrays: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sc = [ 4, 4, 1 ]; +* var sx = [ 4, 4, 1 ]; +* var sy = [ 4, 4, 1 ]; +* var so = [ 2, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 1; +* var ox = 1; +* var oy = 1; +* var oo = 0; +* +* // Create the ndarray-like objects: +* var condition = { +* 'dtype': 'uint8', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major' +* }; +* 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 out = { +* 'dtype': 'float64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major' +* }; +* +* // Apply the condition: +* where3d( condition, x, y, out, true ); +* +* console.log( out.data ); +* // => [ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ] +*/ +function where3d( condition, x, y, out, isRowMajor ) { + var cbuf; + var xbuf; + var ybuf; + var obuf; + var dc0; + var dc1; + var dc2; + var dx0; + var dx1; + var dx2; + var dy0; + var dy1; + var dy2; + var do0; + var do1; + var do2; + var sh; + var S0; + var S1; + var S2; + var sc; + var sx; + var sy; + var so; + var ic; + var ix; + var iy; + var io; + var i0; + var i1; + var i2; + + // Note on variable naming convention: S#, dc#, dx#, dy#, do#, 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; + sc = condition.strides; + sx = x.strides; + sy = y.strides; + so = out.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 2 ]; + S1 = sh[ 1 ]; + S2 = sh[ 0 ]; + dc0 = sc[ 2 ]; // offset increment for innermost loop + dc1 = sc[ 1 ] - ( S0*sc[2] ); + dc2 = sc[ 0 ] - ( S1*sc[1] ); // offset increment for outermost loop + dx0 = sx[ 2 ]; + dx1 = sx[ 1 ] - ( S0*sx[2] ); + dx2 = sx[ 0 ] - ( S1*sx[1] ); + dy0 = sy[ 2 ]; + dy1 = sy[ 1 ] - ( S0*sy[2] ); + dy2 = sy[ 0 ] - ( S1*sy[1] ); + do0 = so[ 2 ]; + do1 = so[ 1 ] - ( S0*so[2] ); + do2 = so[ 0 ] - ( S1*so[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 ]; + dc0 = sc[ 0 ]; // offset increment for innermost loop + dc1 = sc[ 1 ] - ( S0*sc[0] ); + dc2 = sc[ 2 ] - ( S1*sc[1] ); // offset increment for outermost loop + dx0 = sx[ 0 ]; + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + do0 = so[ 0 ]; + do1 = so[ 1 ] - ( S0*so[0] ); + do2 = so[ 2 ] - ( S1*so[1] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ic = condition.offset; + ix = x.offset; + iy = y.offset; + io = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Iterate over the ndarray dimensions... + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } +} + + +// EXPORTS // + +module.exports = where3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/3d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/3d_accessors.js new file mode 100644 index 000000000000..4cbc4b1f404f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/3d_accessors.js @@ -0,0 +1,270 @@ +/** +* @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 condition to two three-dimensional input ndarrays according to a three-dimensional boolean ndarray and assigns results to elements in a three-dimensional output ndarray. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} condition.accessors - data buffer accessors +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} out.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var BooleanArray = require( '@stdlib/array/bool' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var cbuf = new BooleanArray( [ 1, 0, 0, 1, 0, 1, 1, 0 ] ); +* var xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = new Complex64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 ] ); +* var obuf = new Complex64Array( 4 ); +* +* // Define the shape of the arrays: +* var shape = [ 1, 2, 2 ]; +* +* // Define the array strides: +* var sc = [ 4, 2, 1 ]; +* var sx = [ 4, 2, 1 ]; +* var sy = [ 4, 2, 1 ]; +* var so = [ 4, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 0; +* var oy = 0; +* var oo = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the ndarray-like objects: +* var condition = { +* 'dtype': 'bool', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var out = { +* 'dtype': 'complex64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the condition: +* where3d( condition, x, y, out, true ); +* +* var v = out.data.get( 0 ); +* +* var re = realf( v ); +* // returns 1.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function where3d( condition, x, y, out, isRowMajor ) { + var cbuf; + var xbuf; + var ybuf; + var obuf; + var getc; + var getx; + var gety; + var seto; + var dc0; + var dc1; + var dc2; + var dx0; + var dx1; + var dx2; + var dy0; + var dy1; + var dy2; + var do0; + var do1; + var do2; + var sh; + var S0; + var S1; + var S2; + var sc; + var sx; + var sy; + var so; + var ic; + var ix; + var iy; + var io; + var i0; + var i1; + var i2; + + // Note on variable naming convention: S#, dc#, dx#, dy#, do#, 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; + sc = condition.strides; + sx = x.strides; + sy = y.strides; + so = out.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 2 ]; + S1 = sh[ 1 ]; + S2 = sh[ 0 ]; + dc0 = sc[ 2 ]; // offset increment for innermost loop + dc1 = sc[ 1 ] - ( S0*sc[2] ); + dc2 = sc[ 0 ] - ( S1*sc[1] ); // offset increment for outermost loop + dx0 = sx[ 2 ]; + dx1 = sx[ 1 ] - ( S0*sx[2] ); + dx2 = sx[ 0 ] - ( S1*sx[1] ); + dy0 = sy[ 2 ]; + dy1 = sy[ 1 ] - ( S0*sy[2] ); + dy2 = sy[ 0 ] - ( S1*sy[1] ); + do0 = so[ 2 ]; + do1 = so[ 1 ] - ( S0*so[2] ); + do2 = so[ 0 ] - ( S1*so[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 ]; + dc0 = sc[ 0 ]; // offset increment for innermost loop + dc1 = sc[ 1 ] - ( S0*sc[0] ); + dc2 = sc[ 2 ] - ( S1*sc[1] ); // offset increment for outermost loop + dx0 = sx[ 0 ]; + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + do0 = so[ 0 ]; + do1 = so[ 1 ] - ( S0*so[0] ); + do2 = so[ 2 ] - ( S1*so[1] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ic = condition.offset; + ix = x.offset; + iy = y.offset; + io = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache accessors: + getc = condition.accessors[ 0 ]; + getx = x.accessors[ 0 ]; + gety = y.accessors[ 0 ]; + seto = out.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++ ) { + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } +} + + +// EXPORTS // + +module.exports = where3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/3d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/3d_blocked.js new file mode 100644 index 000000000000..4627115cdd03 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/3d_blocked.js @@ -0,0 +1,289 @@ +/** +* @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 */ + +'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 condition to two three-dimensional input ndarrays according to a three-dimensional boolean ndarray and assigns results to elements in a three-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create data buffers: +* var cbuf = new Uint8Array( [ 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0 ] ); +* 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, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] ); +* var obuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sc = [ 4, 4, 1 ]; +* var sx = [ 4, 4, 1 ]; +* var sy = [ 4, 4, 1 ]; +* var so = [ 2, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 1; +* var ox = 1; +* var oy = 1; +* var oo = 0; +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'uint8', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major' +* }; +* 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 out = { +* 'dtype': 'float64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major' +* }; +* +* // Apply the condition: +* blockedwhere3d( condition, x, y, out ); +* +* console.log( out.data ); +* // => [ -2.0, -3.0, 6.0, 7.0, 10.0, 11.0 ] +*/ +function blockedwhere3d( condition, x, y, out ) { // eslint-disable-line max-statements + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var dc0; + var dc1; + var dc2; + var dx0; + var dx1; + var dx2; + var dy0; + var dy1; + var dy2; + var do0; + var do1; + var do2; + var oc1; + var oc2; + var ox1; + var ox2; + var oy1; + var oy2; + var oo1; + var oo2; + var sh; + var s0; + var s1; + var s2; + var sc; + var sx; + var sy; + var so; + var oc; + var ox; + var oy; + var oo; + var ic; + var ix; + var iy; + var io; + var i0; + var i1; + var i2; + var j0; + var j1; + var j2; + var o; + + // Note on variable naming convention: s#, dc#, dx#, dy#, do#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( condition.shape, condition.strides, x.strides, y.strides, out.strides ); // eslint-disable-line max-len + + // Strides output as follows: sx, sy, sz, sw. According to arguments order respectively.. + sh = o.sh; + sc = o.sx; + sx = o.sy; + sy = o.sz; + so = o.sw; + + // Determine the block size: + bsize = blockSize( condition.dtype, x.dtype, y.dtype, out.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + oc = condition.offset; + ox = x.offset; + oy = y.offset; + oo = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache offset increments for the innermost loop... + dc0 = sc[0]; + dx0 = sx[0]; + dy0 = sy[0]; + do0 = so[0]; + + // Iterate over blocks... + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + oc2 = oc + ( j2*sc[2] ); + ox2 = ox + ( j2*sx[2] ); + oy2 = oy + ( j2*sy[2] ); + oo2 = oo + ( j2*so[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dc2 = sc[2] - ( s1*sc[1] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + do2 = so[2] - ( s1*so[1] ); + oc1 = oc2 + ( j1*sc[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oo1 = oo2 + ( j1*so[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... + ic = oc1 + ( j0*sc[0] ); + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + io = oo1 + ( j0*so[0] ); + + // Compute loop offset increments... + dc1 = sc[1] - ( s0*sc[0] ); + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + do1 = so[1] - ( s0*so[0] ); + + // Iterate over the ndarray dimensions... + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; // eslint-disable-line max-len + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhere3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/3d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/3d_blocked_accessors.js new file mode 100644 index 000000000000..e8e9f6c0c298 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/3d_blocked_accessors.js @@ -0,0 +1,324 @@ +/** +* @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 */ + +'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 condition to two three-dimensional input ndarrays according to a three-dimensional boolean ndarray and assigns results to elements in a three-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} condition.accessors - data buffer accessors +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} out.accessors - data buffer accessors +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var BooleanArray = require( '@stdlib/array/bool' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var cbuf = new BooleanArray( [ 1, 0, 0, 1, 0, 1, 1, 0 ] ); +* var xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = new Complex64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 ] ); +* var obuf = new Complex64Array( 4 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 2, 2 ]; +* +* // Define the array strides: +* var sc = [ 4, 2, 1 ]; +* var sx = [ 4, 2, 1 ]; +* var sy = [ 4, 2, 1 ]; +* var so = [ 4, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 0; +* var oy = 0; +* var oo = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'bool', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var out = { +* 'dtype': 'complex64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the condition: +* blockedwhere3d( condition, x, y, out ); +* +* var v = out.data.get( 0 ); +* +* var re = realf( v ); +* // returns 1.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function blockedwhere3d( condition, x, y, out ) { // eslint-disable-line max-statements + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var getc; + var getx; + var gety; + var seto; + var dc0; + var dc1; + var dc2; + var dx0; + var dx1; + var dx2; + var dy0; + var dy1; + var dy2; + var do0; + var do1; + var do2; + var oc1; + var oc2; + var ox1; + var ox2; + var oy1; + var oy2; + var oo1; + var oo2; + var sh; + var s0; + var s1; + var s2; + var sc; + var sx; + var sy; + var so; + var oc; + var ox; + var oy; + var oo; + var ic; + var ix; + var iy; + var io; + var i0; + var i1; + var i2; + var j0; + var j1; + var j2; + var o; + + // Note on variable naming convention: s#, dc#, dx#, dy#, do#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( condition.shape, condition.strides, x.strides, y.strides, out.strides ); // eslint-disable-line max-len + + // Strides output as follows: sx, sy, sz, sw. According to arguments order respectively.. + sh = o.sh; + sc = o.sx; + sx = o.sy; + sy = o.sz; + so = o.sw; + + // Determine the block size: + bsize = blockSize( condition.dtype, x.dtype, y.dtype, out.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + oc = condition.offset; + ox = x.offset; + oy = y.offset; + oo = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache offset increments for the innermost loop... + dc0 = sc[0]; + dx0 = sx[0]; + dy0 = sy[0]; + do0 = so[0]; + + // Cache accessors: + getc = condition.accessors[ 0 ]; + getx = x.accessors[ 0 ]; + gety = y.accessors[ 0 ]; + seto = out.accessors[ 1 ]; + + // Iterate over blocks... + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + oc2 = oc + ( j2*sc[2] ); + ox2 = ox + ( j2*sx[2] ); + oy2 = oy + ( j2*sy[2] ); + oo2 = oo + ( j2*so[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dc2 = sc[2] - ( s1*sc[1] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + do2 = so[2] - ( s1*so[1] ); + oc1 = oc2 + ( j1*sc[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oo1 = oo2 + ( j1*so[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... + ic = oc1 + ( j0*sc[0] ); + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + io = oo1 + ( j0*so[0] ); + + // Compute loop offset increments... + dc1 = sc[1] - ( s0*sc[0] ); + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + do1 = so[1] - ( s0*so[0] ); + + // Iterate over the ndarray dimensions... + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhere3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/4d.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/4d.js new file mode 100644 index 000000000000..a00c9de0acdd --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/4d.js @@ -0,0 +1,258 @@ +/** +* @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 condition to two four-dimensional input ndarrays according to a four-dimensional boolean ndarray and assigns results to elements in a four-dimensional output ndarray. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* +* // Create data buffers: +* var cbuf = new Uint8Array( [ 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1 ] ); +* 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, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] ); +* var obuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sc = [ 12, 4, 4, 1 ]; +* var sx = [ 12, 4, 4, 1 ]; +* var sy = [ 12, 4, 4, 1 ]; +* var so = [ 6, 2, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 1; +* var ox = 1; +* var oy = 1; +* var oo = 0; +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'uint8', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major' +* }; +* 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 out = { +* 'dtype': 'float64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major' +* }; +* +* // Apply the condition: +* where4d( condition, x, y, out, true ); +* +* console.log( out.data ); +* // => [ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ] +*/ +function where4d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements + var cbuf; + var xbuf; + var ybuf; + var obuf; + var dc0; + var dc1; + var dc2; + var dc3; + var dx0; + var dx1; + var dx2; + var dx3; + var dy0; + var dy1; + var dy2; + var dy3; + var do0; + var do1; + var do2; + var do3; + var sh; + var S0; + var S1; + var S2; + var S3; + var sc; + var sx; + var sy; + var so; + var ic; + var ix; + var iy; + var io; + var i0; + var i1; + var i2; + var i3; + + // Note on variable naming convention: S#, dc#, dx#, dy#, do#, 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; + sc = condition.strides; + sx = x.strides; + sy = y.strides; + so = out.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 ]; + dc0 = sc[ 3 ]; // offset increment for innermost loop + dc1 = sc[ 2 ] - ( S0*sc[3] ); + dc2 = sc[ 1 ] - ( S1*sc[2] ); + dc3 = sc[ 0 ] - ( S2*sc[1] ); // offset increment for outermost loop + dx0 = sx[ 3 ]; + dx1 = sx[ 2 ] - ( S0*sx[3] ); + dx2 = sx[ 1 ] - ( S1*sx[2] ); + dx3 = sx[ 0 ] - ( S2*sx[1] ); + dy0 = sy[ 3 ]; + dy1 = sy[ 2 ] - ( S0*sy[3] ); + dy2 = sy[ 1 ] - ( S1*sy[2] ); + dy3 = sy[ 0 ] - ( S2*sy[1] ); + do0 = so[ 3 ]; + do1 = so[ 2 ] - ( S0*so[3] ); + do2 = so[ 1 ] - ( S1*so[2] ); + do3 = so[ 0 ] - ( S2*so[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 ]; + dc0 = sc[ 0 ]; // offset increment for innermost loop + dc1 = sc[ 1 ] - ( S0*sc[0] ); + dc2 = sc[ 2 ] - ( S1*sc[1] ); + dc3 = sc[ 3 ] - ( S2*sc[2] ); // offset increment for outermost loop + dx0 = sx[ 0 ]; + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + do0 = so[ 0 ]; + do1 = so[ 1 ] - ( S0*so[0] ); + do2 = so[ 2 ] - ( S1*so[1] ); + do3 = so[ 3 ] - ( S2*so[2] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ic = condition.offset; + ix = x.offset; + iy = y.offset; + io = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.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++ ) { + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } +} + + +// EXPORTS // + +module.exports = where4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/4d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/4d_accessors.js new file mode 100644 index 000000000000..a881753720cb --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/4d_accessors.js @@ -0,0 +1,292 @@ +/** +* @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 condition to two four-dimensional input ndarrays according to a four-dimensional boolean ndarray and assigns results to elements in a four-dimensional output ndarray. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} condition.accessors - data buffer accessors +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} out.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var BooleanArray = require( '@stdlib/array/bool' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var cbuf = new BooleanArray( [ 1, 0, 0, 1, 0, 1, 1, 0 ] ); +* var xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = new Complex64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 ] ); +* var obuf = new Complex64Array( 4 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sc = [ 4, 4, 2, 1 ]; +* var sx = [ 4, 4, 2, 1 ]; +* var sy = [ 4, 4, 2, 1 ]; +* var so = [ 4, 4, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 0; +* var oy = 0; +* var oo = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'bool', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var out = { +* 'dtype': 'complex64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the condition: +* where4d( condition, x, y, out, true ); +* +* var v = out.data.get( 0 ); +* +* var re = realf( v ); +* // returns 1.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function where4d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements + var cbuf; + var xbuf; + var ybuf; + var obuf; + var getc; + var getx; + var gety; + var seto; + var dc0; + var dc1; + var dc2; + var dc3; + var dx0; + var dx1; + var dx2; + var dx3; + var dy0; + var dy1; + var dy2; + var dy3; + var do0; + var do1; + var do2; + var do3; + var sh; + var S0; + var S1; + var S2; + var S3; + var sc; + var sx; + var sy; + var so; + var ic; + var ix; + var iy; + var io; + var i0; + var i1; + var i2; + var i3; + + // Note on variable naming convention: S#, dc#, dx#, dy#, do#, 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; + sc = condition.strides; + sx = x.strides; + sy = y.strides; + so = out.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 ]; + dc0 = sc[ 3 ]; // offset increment for innermost loop + dc1 = sc[ 2 ] - ( S0*sc[3] ); + dc2 = sc[ 1 ] - ( S1*sc[2] ); + dc3 = sc[ 0 ] - ( S2*sc[1] ); // offset increment for outermost loop + dx0 = sx[ 3 ]; + dx1 = sx[ 2 ] - ( S0*sx[3] ); + dx2 = sx[ 1 ] - ( S1*sx[2] ); + dx3 = sx[ 0 ] - ( S2*sx[1] ); + dy0 = sy[ 3 ]; + dy1 = sy[ 2 ] - ( S0*sy[3] ); + dy2 = sy[ 1 ] - ( S1*sy[2] ); + dy3 = sy[ 0 ] - ( S2*sy[1] ); + do0 = so[ 3 ]; + do1 = so[ 2 ] - ( S0*so[3] ); + do2 = so[ 1 ] - ( S1*so[2] ); + do3 = so[ 0 ] - ( S2*so[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 ]; + dc0 = sc[ 0 ]; // offset increment for innermost loop + dc1 = sc[ 1 ] - ( S0*sc[0] ); + dc2 = sc[ 2 ] - ( S1*sc[1] ); + dc3 = sc[ 3 ] - ( S2*sc[2] ); // offset increment for outermost loop + dx0 = sx[ 0 ]; + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + do0 = so[ 0 ]; + do1 = so[ 1 ] - ( S0*so[0] ); + do2 = so[ 2 ] - ( S1*so[1] ); + do3 = so[ 3 ] - ( S2*so[2] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ic = condition.offset; + ix = x.offset; + iy = y.offset; + io = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache accessors: + getc = condition.accessors[ 0 ]; + getx = x.accessors[ 0 ]; + gety = y.accessors[ 0 ]; + seto = out.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++ ) { + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } +} + + +// EXPORTS // + +module.exports = where4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/4d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/4d_blocked.js new file mode 100644 index 000000000000..dcf7a7b29299 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/4d_blocked.js @@ -0,0 +1,324 @@ +/** +* @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 */ + +'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 condition to two four-dimensional input ndarrays according to a four-dimensional boolean ndarray and assigns results to elements in a four-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* +* // Create data buffers: +* var cbuf = new Uint8Array( [ 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1 ] ); +* 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, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] ); +* var obuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sc = [ 12, 4, 4, 1 ]; +* var sx = [ 12, 4, 4, 1 ]; +* var sy = [ 12, 4, 4, 1 ]; +* var so = [ 6, 2, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 1; +* var ox = 1; +* var oy = 1; +* var oo = 0; +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'uint8', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major' +* }; +* 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 out = { +* 'dtype': 'float64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major' +* }; +* +* // Copy elements: +* blockedwhere4d( condition, x, y, out ); +* +* console.log( out.data ); +* // => [ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ] +*/ +function blockedwhere4d( condition, x, y, out ) { // eslint-disable-line max-statements + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var dc0; + var dc1; + var dc2; + var dc3; + var dx0; + var dx1; + var dx2; + var dx3; + var dy0; + var dy1; + var dy2; + var dy3; + var do0; + var do1; + var do2; + var do3; + var oc1; + var oc2; + var oc3; + var ox1; + var ox2; + var ox3; + var oy1; + var oy2; + var oy3; + var oo1; + var oo2; + var oo3; + var sh; + var s0; + var s1; + var s2; + var s3; + var sc; + var sx; + var sy; + var so; + var oc; + var ox; + var oy; + var oo; + var ic; + var ix; + var iy; + var io; + var i0; + var i1; + var i2; + var i3; + var j0; + var j1; + var j2; + var j3; + var o; + + // Note on variable naming convention: s#, dc#, dx#, dy#, do#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( condition.shape, condition.strides, x.strides, y.strides, out.strides ); // eslint-disable-line max-len + + // Strides output as follows: sx, sy, sz, sw. According to arguments order respectively.. + sh = o.sh; + sc = o.sx; + sx = o.sy; + sy = o.sz; + so = o.sw; + + // Determine the block size: + bsize = blockSize( condition.dtype, x.dtype, y.dtype, o.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + oc = condition.offset; + ox = x.offset; + oy = y.offset; + oo = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache offset increments for the innermost loop... + dc0 = sc[0]; + dx0 = sx[0]; + dy0 = sy[0]; + do0 = so[0]; + + // Iterate over blocks... + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + oc3 = oc + ( j3*sc[3] ); + ox3 = ox + ( j3*sx[3] ); + oy3 = oy + ( j3*sy[3] ); + oo3 = oo + ( j3*so[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dc3 = sc[3] - ( s2*sc[2] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + do3 = so[3] - ( s2*so[2] ); + oc2 = oc3 + ( j2*sc[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oo2 = oo3 + ( j2*so[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dc2 = sc[2] - ( s1*sc[1] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + do2 = so[2] - ( s1*so[1] ); + oc1 = oc2 + ( j1*sc[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oo1 = oo2 + ( j1*so[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... + ic = oc1 + ( j0*sc[0] ); + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + io = oo1 + ( j0*so[0] ); + + // Compute loop offset increments... + dc1 = sc[1] - ( s0*sc[0] ); + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + do1 = so[1] - ( s0*so[0] ); + + // Iterate over the ndarray dimensions... + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; // eslint-disable-line max-len + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhere4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/4d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/4d_blocked_accessors.js new file mode 100644 index 000000000000..fb3d24d1bd58 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/4d_blocked_accessors.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 */ + +'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 condition to two four-dimensional input ndarrays according to a four-dimensional boolean ndarray and assigns results to elements in a four-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} condition.accessors - data buffer accessors +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} out.accessors - data buffer accessors +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var BooleanArray = require( '@stdlib/array/bool' ) +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var cbuf = new BooleanArray( [ 1, 0, 0, 1, 0, 1, 1, 0 ] ); +* var xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = new Complex64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 ] ); +* var obuf = new Complex64Array( 4 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sc = [ 4, 4, 2, 1 ]; +* var sx = [ 4, 4, 2, 1 ]; +* var sy = [ 4, 4, 2, 1 ]; +* var so = [ 4, 4, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 0; +* var oy = 0; +* var oo = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'uint8', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var out = { +* 'dtype': 'float64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Copy elements: +* blockedwhere4d( condition, x, y, out ); +* +* var v = out.data.get( 0 ); +* +* var re = realf( v ); +* // returns 1.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function blockedwhere4d( condition, x, y, out ) { // eslint-disable-line max-statements + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var getc; + var getx; + var gety; + var seto; + var dc0; + var dc1; + var dc2; + var dc3; + var dx0; + var dx1; + var dx2; + var dx3; + var dy0; + var dy1; + var dy2; + var dy3; + var do0; + var do1; + var do2; + var do3; + var oc1; + var oc2; + var oc3; + var ox1; + var ox2; + var ox3; + var oy1; + var oy2; + var oy3; + var oo1; + var oo2; + var oo3; + var sh; + var s0; + var s1; + var s2; + var s3; + var sc; + var sx; + var sy; + var so; + var oc; + var ox; + var oy; + var oo; + var ic; + var ix; + var iy; + var io; + var i0; + var i1; + var i2; + var i3; + var j0; + var j1; + var j2; + var j3; + var o; + + // Note on variable naming convention: s#, dc#, dx#, dy#, do#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( condition.shape, condition.strides, x.strides, y.strides, out.strides ); // eslint-disable-line max-len + + // Strides output as follows: sx, sy, sz, sw. According to arguments order respectively.. + sh = o.sh; + sc = o.sx; + sx = o.sy; + sy = o.sz; + so = o.sw; + + // Determine the block size: + bsize = blockSize( condition.dtype, x.dtype, y.dtype, o.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + oc = condition.offset; + ox = x.offset; + oy = y.offset; + oo = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache offset increments for the innermost loop... + dc0 = sc[0]; + dx0 = sx[0]; + dy0 = sy[0]; + do0 = so[0]; + + // Cache accessors: + getc = condition.accessors[ 0 ]; + getx = x.accessors[ 0 ]; + gety = y.accessors[ 0 ]; + seto = out.accessors[ 1 ]; + + // Iterate over blocks... + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + oc3 = oc + ( j3*sc[3] ); + ox3 = ox + ( j3*sx[3] ); + oy3 = oy + ( j3*sy[3] ); + oo3 = oo + ( j3*so[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dc3 = sc[3] - ( s2*sc[2] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + do3 = so[3] - ( s2*so[2] ); + oc2 = oc3 + ( j2*sc[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oo2 = oo3 + ( j2*so[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dc2 = sc[2] - ( s1*sc[1] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + do2 = so[2] - ( s1*so[1] ); + oc1 = oc2 + ( j1*sc[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oo1 = oo2 + ( j1*so[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... + ic = oc1 + ( j0*sc[0] ); + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + io = oo1 + ( j0*so[0] ); + + // Compute loop offset increments... + dc1 = sc[1] - ( s0*sc[0] ); + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + do1 = so[1] - ( s0*so[0] ); + + // Iterate over the ndarray dimensions... + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhere4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/5d.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/5d.js new file mode 100644 index 000000000000..70a3478e94eb --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/5d.js @@ -0,0 +1,281 @@ +/** +* @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 condition to two five-dimensional input ndarrays according to a five-dimensional boolean ndarray and assigns results to elements in a five-dimensional output ndarray. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* +* // Create data buffers: +* var cbuf = new Uint8Array( [ 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1 ] ); +* 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, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] ); +* var obuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sc = [ 12, 12, 4, 4, 1 ]; +* var sx = [ 12, 12, 4, 4, 1 ]; +* var sy = [ 12, 12, 4, 4, 1 ]; +* var so = [ 6, 6, 2, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 1; +* var ox = 1; +* var oy = 1; +* var oo = 0; +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'uint8', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major' +* }; +* 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 out = { +* 'dtype': 'float64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major' +* }; +* +* // Apply the condition: +* where5d( condition, x, y, out, true ); +* +* console.log( out.data ); +* // => [ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ] +*/ +function where5d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements + var cbuf; + var xbuf; + var ybuf; + var obuf; + var dc0; + var dc1; + var dc2; + var dc3; + var dc4; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var do0; + var do1; + var do2; + var do3; + var do4; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var sc; + var sx; + var sy; + var so; + var ic; + var ix; + var iy; + var io; + var i0; + var i1; + var i2; + var i3; + var i4; + + // Note on variable naming convention: S#, dc#, dx#, dy#, do#, 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; + sc = condition.strides; + sx = x.strides; + sy = y.strides; + so = out.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 ]; + dc0 = sc[ 4 ]; // offset increment for innermost loop + dc1 = sc[ 3 ] - ( S0*sc[4] ); + dc2 = sc[ 2 ] - ( S1*sc[3] ); + dc3 = sc[ 1 ] - ( S2*sc[2] ); + dc4 = sc[ 0 ] - ( S3*sc[1] ); // offset increment for outermost loop + dx0 = sx[ 4 ]; + dx1 = sx[ 3 ] - ( S0*sx[4] ); + dx2 = sx[ 2 ] - ( S1*sx[3] ); + dx3 = sx[ 1 ] - ( S2*sx[2] ); + dx4 = sx[ 0 ] - ( S3*sx[1] ); + 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] ); + do0 = so[ 4 ]; + do1 = so[ 3 ] - ( S0*so[4] ); + do2 = so[ 2 ] - ( S1*so[3] ); + do3 = so[ 1 ] - ( S2*so[2] ); + do4 = so[ 0 ] - ( S3*so[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 ]; + dc0 = sc[ 0 ]; // offset increment for innermost loop + dc1 = sc[ 1 ] - ( S0*sc[0] ); + dc2 = sc[ 2 ] - ( S1*sc[1] ); + dc3 = sc[ 3 ] - ( S2*sc[2] ); + dc4 = sc[ 4 ] - ( S3*sc[3] ); // offset increment for outermost loop + dx0 = sx[ 0 ]; + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); + 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] ); + do0 = so[ 0 ]; + do1 = so[ 1 ] - ( S0*so[0] ); + do2 = so[ 2 ] - ( S1*so[1] ); + do3 = so[ 3 ] - ( S2*so[2] ); + do4 = so[ 4 ] - ( S3*so[3] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ic = condition.offset; + ix = x.offset; + iy = y.offset; + io = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.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++ ) { + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + ic += dc4; + ix += dx4; + iy += dy4; + io += do4; + } +} + + +// EXPORTS // + +module.exports = where5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/5d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/5d_accessors.js new file mode 100644 index 000000000000..32ff030709a4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/5d_accessors.js @@ -0,0 +1,316 @@ +/** +* @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 condition to two five-dimensional input ndarrays according to a five-dimensional boolean ndarray and assigns results to elements in a five-dimensional output ndarray. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} condition.accessors - data buffer accessors +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} out.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var BooleanArray = require( '@stdlib/array/bool' ); +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var cbuf = new BooleanArray( [ 1, 0, 0, 1, 0, 1, 1, 0 ] ); +* var xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0] ); +* var ybuf = new Complex64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 ] ); +* var obuf = new Complex64Array( 4 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sc = [ 4, 4, 4, 2, 1 ]; +* var sx = [ 4, 4, 4, 2, 1 ]; +* var sy = [ 4, 4, 4, 2, 1 ]; +* var so = [ 4, 4, 4, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 0; +* var oy = 0; +* var oo = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'bool', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var out = { +* 'dtype': 'complex64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the condition: +* where5d( condition, x, y, out, true ); +* +* var v = y.data.get( 0 ); +* +* var re = realf( v ); +* // returns -1.0 +* +* var im = imagf( v ); +* // returns -2.0 +*/ +function where5d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements + var cbuf; + var xbuf; + var ybuf; + var obuf; + var getc; + var getx; + var gety; + var seto; + var dc0; + var dc1; + var dc2; + var dc3; + var dc4; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var do0; + var do1; + var do2; + var do3; + var do4; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var sc; + var sx; + var sy; + var so; + var ic; + var ix; + var iy; + var io; + var i0; + var i1; + var i2; + var i3; + var i4; + + // Note on variable naming convention: S#, dc#, dx#, dy#, do#, 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; + sc = condition.strides; + sx = x.strides; + sy = y.strides; + so = out.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 ]; + dc0 = sc[ 4 ]; // offset increment for innermost loop + dc1 = sc[ 3 ] - ( S0*sc[4] ); + dc2 = sc[ 2 ] - ( S1*sc[3] ); + dc3 = sc[ 1 ] - ( S2*sc[2] ); + dc4 = sc[ 0 ] - ( S3*sc[1] ); // offset increment for outermost loop + dx0 = sx[ 4 ]; + dx1 = sx[ 3 ] - ( S0*sx[4] ); + dx2 = sx[ 2 ] - ( S1*sx[3] ); + dx3 = sx[ 1 ] - ( S2*sx[2] ); + dx4 = sx[ 0 ] - ( S3*sx[1] ); + 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] ); + do0 = so[ 4 ]; + do1 = so[ 3 ] - ( S0*so[4] ); + do2 = so[ 2 ] - ( S1*so[3] ); + do3 = so[ 1 ] - ( S2*so[2] ); + do4 = so[ 0 ] - ( S3*so[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 ]; + dc0 = sc[ 0 ]; // offset increment for innermost loop + dc1 = sc[ 1 ] - ( S0*sc[0] ); + dc2 = sc[ 2 ] - ( S1*sc[1] ); + dc3 = sc[ 3 ] - ( S2*sc[2] ); + dc4 = sc[ 4 ] - ( S3*sc[3] ); // offset increment for outermost loop + dx0 = sx[ 0 ]; + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); + 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] ); + do0 = so[ 0 ]; + do1 = so[ 1 ] - ( S0*so[0] ); + do2 = so[ 2 ] - ( S1*so[1] ); + do3 = so[ 3 ] - ( S2*so[2] ); + do4 = so[ 4 ] - ( S3*so[3] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ic = condition.offset; + ix = x.offset; + iy = y.offset; + io = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache accessors: + getc = condition.accessors[ 0 ]; + getx = x.accessors[ 0 ]; + gety = y.accessors[ 0 ]; + seto = out.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++ ) { + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + ic += dc4; + ix += dx4; + iy += dy4; + io += do4; + } +} + + +// EXPORTS // + +module.exports = where5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/5d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/5d_blocked.js new file mode 100644 index 000000000000..d992fce939aa --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/5d_blocked.js @@ -0,0 +1,358 @@ +/** +* @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 */ + +'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 condition to two five-dimensional input ndarrays according to a five-dimensional boolean ndarray and assigns results to elements in a five-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* +* // Create data buffers: +* var cbuf = new Uint8Array( [ 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1 ] ); +* 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, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] ); +* var obuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sc = [ 12, 12, 4, 4, 1 ]; +* var sx = [ 12, 12, 4, 4, 1 ]; +* var sy = [ 12, 12, 4, 4, 1 ]; +* var so = [ 6, 6, 2, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 1; +* var ox = 1; +* var oy = 1; +* var oo = 0; +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'uint8', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major' +* }; +* 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 out = { +* 'dtype': 'float64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major' +* }; +* +* // Apply the condition: +* blockedwhere5d( condition, x, y, out ); +* +* console.log( out.data ); +* // => [ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ] +*/ +function blockedwhere5d( condition, x, y, out ) { // eslint-disable-line max-statements, max-lines-per-function + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var dc0; + var dc1; + var dc2; + var dc3; + var dc4; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var do0; + var do1; + var do2; + var do3; + var do4; + var oc1; + var oc2; + var oc3; + var oc4; + var ox1; + var ox2; + var ox3; + var ox4; + var oy1; + var oy2; + var oy3; + var oy4; + var oo1; + var oo2; + var oo3; + var oo4; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var sc; + var sx; + var sy; + var so; + var oc; + var ox; + var oy; + var oo; + var ic; + var ix; + var iy; + var io; + 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#, dc#, dx#, dy#, do#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( condition.shape, condition.strides, x.strides, y.strides, out.strides ); // eslint-disable-line max-len + + // Strides output as follows: sx, sy, sz, sw. According to arguments order respectively.. + sh = o.sh; + sc = o.sx; + sx = o.sy; + sy = o.sz; + so = o.sw; + + // Determine the block size: + bsize = blockSize( condition.dtype, x.dtype, y.dtype, out.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + oc = condition.offset; + ox = x.offset; + oy = y.offset; + oo = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache offset increments for the innermost loop... + dc0 = sc[0]; + dx0 = sx[0]; + dy0 = sy[0]; + do0 = so[0]; + + // Iterate over blocks... + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + oc4 = oc + ( j4*sc[4] ); + ox4 = ox + ( j4*sx[4] ); + oy4 = oy + ( j4*sy[4] ); + oo4 = oo + ( j4*so[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dc4 = sc[4] - ( s3*sc[3] ); + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + do4 = so[4] - ( s3*so[3] ); + oc3 = oc4 + ( j3*sc[3] ); + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oo3 = oo4 + ( j3*so[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dc3 = sc[3] - ( s2*sc[2] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + do3 = so[3] - ( s2*so[2] ); + oc2 = oc3 + ( j2*sc[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oo2 = oo3 + ( j2*so[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dc2 = sc[2] - ( s1*sc[1] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + do2 = so[2] - ( s1*so[1] ); + oc1 = oc2 + ( j1*sc[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oo1 = oo2 + ( j1*so[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... + ic = oc1 + ( j0*sc[0] ); + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + io = oo1 + ( j0*so[0] ); + + // Compute loop offset increments... + dc1 = sc[1] - ( s0*sc[0] ); + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + do1 = so[1] - ( s0*so[0] ); + + // Iterate over the ndarray dimensions... + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; // eslint-disable-line max-len + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + ic += dc4; + ix += dx4; + iy += dy4; + io += do4; + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhere5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/5d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/5d_blocked_accessors.js new file mode 100644 index 000000000000..396086302320 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/5d_blocked_accessors.js @@ -0,0 +1,393 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-depth */ + +'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 condition to two five-dimensional input ndarrays according to a five-dimensional boolean ndarray and assigns results to elements in a five-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} condition.accessors - data buffer accessors +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} out.accessors - data buffer accessors +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var BooleanArray = require( '@stdlib/array/bool' ) +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var cbuf = new BooleanArray( [ 1, 0, 0, 1, 0, 1, 1, 0 ] ); +* var xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = new Complex64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 ] ); +* var obuf = new Complex64Array( 4 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sc = [ 4, 4, 4, 2, 1 ]; +* var sx = [ 4, 4, 4, 2, 1 ]; +* var sy = [ 4, 4, 4, 2, 1 ]; +* var so = [ 4, 4, 4, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 0; +* var oy = 0; +* var oo = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'bool', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var out = { +* 'dtype': 'complex64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the condition: +* blockedwhere5d( condition, x, y, out ); +* +* var v = out.data.get( 0 ); +* +* var re = realf( v ); +* // returns 1.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function blockedwhere5d( condition, x, y, out ) { // eslint-disable-line max-statements, max-lines-per-function + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var getc; + var getx; + var gety; + var seto; + var dc0; + var dc1; + var dc2; + var dc3; + var dc4; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var do0; + var do1; + var do2; + var do3; + var do4; + var oc1; + var oc2; + var oc3; + var oc4; + var ox1; + var ox2; + var ox3; + var ox4; + var oy1; + var oy2; + var oy3; + var oy4; + var oo1; + var oo2; + var oo3; + var oo4; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var sc; + var sx; + var sy; + var so; + var oc; + var ox; + var oy; + var oo; + var ic; + var ix; + var iy; + var io; + 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#, dc#, dx#, dy#, do#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( condition.shape, condition.strides, x.strides, y.strides, out.strides ); // eslint-disable-line max-len + + // Strides output as follows: sx, sy, sz, sw. According to arguments order respectively.. + sh = o.sh; + sc = o.sx; + sx = o.sy; + sy = o.sz; + so = o.sw; + + // Determine the block size: + bsize = blockSize( condition.dtype, x.dtype, y.dtype, out.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + oc = condition.offset; + ox = x.offset; + oy = y.offset; + oo = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache offset increments for the innermost loop... + dc0 = sc[0]; + dx0 = sx[0]; + dy0 = sy[0]; + do0 = so[0]; + + // Cache accessors: + getc = condition.accessors[ 0 ]; + getx = x.accessors[ 0 ]; + gety = y.accessors[ 0 ]; + seto = out.accessors[ 1 ]; + + // Iterate over blocks... + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + oc4 = oc + ( j4*sc[4] ); + ox4 = ox + ( j4*sx[4] ); + oy4 = oy + ( j4*sy[4] ); + oo4 = oo + ( j4*so[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dc4 = sc[4] - ( s3*sc[3] ); + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + do4 = so[4] - ( s3*so[3] ); + oc3 = oc4 + ( j3*sc[3] ); + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oo3 = oo4 + ( j3*so[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dc3 = sc[3] - ( s2*sc[2] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + do3 = so[3] - ( s2*so[2] ); + oc2 = oc3 + ( j2*sc[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oo2 = oo3 + ( j2*so[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dc2 = sc[2] - ( s1*sc[1] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + do2 = so[2] - ( s1*so[1] ); + oc1 = oc2 + ( j1*sc[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oo1 = oo2 + ( j1*so[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... + ic = oc1 + ( j0*sc[0] ); + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + io = oo1 + ( j0*so[0] ); + + // Compute loop offset increments... + dc1 = sc[1] - ( s0*sc[0] ); + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + do1 = so[1] - ( s0*so[0] ); + + // Iterate over the ndarray dimensions... + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + ic += dc4; + ix += dx4; + iy += dy4; + io += do4; + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhere5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/6d.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/6d.js new file mode 100644 index 000000000000..1c169a043353 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/6d.js @@ -0,0 +1,304 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-depth */ + +'use strict'; + +// MAIN // + +/** +* Applies a condition to two six-dimensional input ndarrays according to a six-dimensional boolean ndarray and assigns results to elements in a six-dimensional output ndarray. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* +* // Create data buffers: +* var cbuf = new Uint8Array( [ 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1 ] ); +* 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, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] ); +* var obuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sc = [ 12, 12, 12, 4, 4, 1 ]; +* var sx = [ 12, 12, 12, 4, 4, 1 ]; +* var sy = [ 12, 12, 12, 4, 4, 1 ]; +* var so = [ 6, 6, 6, 2, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 1; +* var ox = 1; +* var oy = 1; +* var oo = 0; +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'uint8', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major' +* }; +* 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 out = { +* 'dtype': 'float64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major' +* }; +* +* // Apply the condition: +* where6d( condition, x, y, out, true ); +* +* console.log( out.data ); +* // => [ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ] +*/ +function where6d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements + var cbuf; + var xbuf; + var ybuf; + var obuf; + var dc0; + var dc1; + var dc2; + var dc3; + var dc4; + var dc5; + 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 do0; + var do1; + var do2; + var do3; + var do4; + var do5; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var sc; + var sx; + var sy; + var so; + var ic; + var ix; + var iy; + var io; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + + // Note on variable naming convention: S#, dx#, dy#, 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; + sc = condition.strides; + sx = x.strides; + sy = y.strides; + so = out.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 ]; + dc0 = sc[ 5 ]; // offset increment for innermost loop + dc1 = sc[ 4 ] - ( S0*sc[5] ); + dc2 = sc[ 3 ] - ( S1*sc[4] ); + dc3 = sc[ 2 ] - ( S2*sc[3] ); + dc4 = sc[ 1 ] - ( S3*sc[2] ); + dc5 = sc[ 0 ] - ( S4*sc[1] ); // offset increment for outermost loop + dx0 = sx[ 5 ]; + 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] ); + 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] ); + do0 = so[ 5 ]; + do1 = so[ 4 ] - ( S0*so[5] ); + do2 = so[ 3 ] - ( S1*so[4] ); + do3 = so[ 2 ] - ( S2*so[3] ); + do4 = so[ 1 ] - ( S3*so[2] ); + do5 = so[ 0 ] - ( S4*so[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 ]; + dc0 = sc[ 0 ]; // offset increment for innermost loop + dc1 = sc[ 1 ] - ( S0*sc[0] ); + dc2 = sc[ 2 ] - ( S1*sc[1] ); + dc3 = sc[ 3 ] - ( S2*sc[2] ); + dc4 = sc[ 4 ] - ( S3*sc[3] ); + dc5 = sc[ 5 ] - ( S4*sc[4] ); // offset increment for outermost loop + dx0 = sx[ 0 ]; + 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] ); + 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] ); + do0 = so[ 0 ]; + do1 = so[ 1 ] - ( S0*so[0] ); + do2 = so[ 2 ] - ( S1*so[1] ); + do3 = so[ 3 ] - ( S2*so[2] ); + do4 = so[ 4 ] - ( S3*so[3] ); + do5 = so[ 5 ] - ( S4*so[4] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ic = condition.offset; + ix = x.offset; + iy = y.offset; + io = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.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++ ) { + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; // eslint-disable-line max-len + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + ic += dc4; + ix += dx4; + iy += dy4; + io += do4; + } + ic += dc5; + ix += dx5; + iy += dy5; + io += do5; + } +} + + +// EXPORTS // + +module.exports = where6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/6d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/6d_accessors.js new file mode 100644 index 000000000000..28bc5aede8e4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/6d_accessors.js @@ -0,0 +1,339 @@ +/** +* @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 */ + +'use strict'; + +// MAIN // + +/** +* Applies a condition to two six-dimensional input ndarrays according to a six-dimensional boolean ndarray and assigns results to elements in a six-dimensional output ndarray. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} condition.accessors - data buffer accessors +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} out.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var BooleanArray = require( '@stdlib/array/bool' ); +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var cbuf = new BooleanArray( [ 1, 0, 0, 1, 0, 1, 1, 0 ] ); +* var xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0] ); +* var ybuf = new Complex64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 ] ); +* var obuf = new Complex64Array( 4 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sc = [ 4, 4, 4, 4, 2, 1 ]; +* var sx = [ 4, 4, 4, 4, 2, 1 ]; +* var sy = [ 4, 4, 4, 4, 2, 1 ]; +* var so = [ 4, 4, 4, 4, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 0; +* var oy = 0; +* var oo = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'bool', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var out = { +* 'dtype': 'complex64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the condition: +* where6d( condition, x, y, out, true ); +* +* var v = out.data.get( 0 ); +* +* var re = realf( v ); +* // returns 1.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function where6d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements + var cbuf; + var xbuf; + var ybuf; + var obuf; + var getc; + var getx; + var gety; + var seto; + var dc0; + var dc1; + var dc2; + var dc3; + var dc4; + var dc5; + 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 do0; + var do1; + var do2; + var do3; + var do4; + var do5; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var sc; + var sx; + var sy; + var so; + var ic; + var ix; + var iy; + var io; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + + // Note on variable naming convention: S#, dx#, dy#, 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; + sc = condition.strides; + sx = x.strides; + sy = y.strides; + so = out.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 ]; + dc0 = sc[ 5 ]; // offset increment for innermost loop + dc1 = sc[ 4 ] - ( S0*sc[5] ); + dc2 = sc[ 3 ] - ( S1*sc[4] ); + dc3 = sc[ 2 ] - ( S2*sc[3] ); + dc4 = sc[ 1 ] - ( S3*sc[2] ); + dc5 = sc[ 0 ] - ( S4*sc[1] ); // offset increment for outermost loop + dx0 = sx[ 5 ]; + 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] ); + 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] ); + do0 = so[ 5 ]; + do1 = so[ 4 ] - ( S0*so[5] ); + do2 = so[ 3 ] - ( S1*so[4] ); + do3 = so[ 2 ] - ( S2*so[3] ); + do4 = so[ 1 ] - ( S3*so[2] ); + do5 = so[ 0 ] - ( S4*so[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 ]; + dc0 = sc[ 0 ]; // offset increment for innermost loop + dc1 = sc[ 1 ] - ( S0*sc[0] ); + dc2 = sc[ 2 ] - ( S1*sc[1] ); + dc3 = sc[ 3 ] - ( S2*sc[2] ); + dc4 = sc[ 4 ] - ( S3*sc[3] ); + dc5 = sc[ 5 ] - ( S4*sc[4] ); // offset increment for outermost loop + dx0 = sx[ 0 ]; + 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] ); + 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] ); + do0 = so[ 0 ]; + do1 = so[ 1 ] - ( S0*so[0] ); + do2 = so[ 2 ] - ( S1*so[1] ); + do3 = so[ 3 ] - ( S2*so[2] ); + do4 = so[ 4 ] - ( S3*so[3] ); + do5 = so[ 5 ] - ( S4*so[4] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ic = condition.offset; + ix = x.offset; + iy = y.offset; + io = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache accessors: + getc = condition.accessors[ 0 ]; + getx = x.accessors[ 0 ]; + gety = y.accessors[ 0 ]; + seto = out.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++ ) { + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + ic += dc4; + ix += dx4; + iy += dy4; + io += do4; + } + ic += dc5; + ix += dx5; + iy += dy5; + io += do5; + } +} + + +// EXPORTS // + +module.exports = where6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/6d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/6d_blocked.js new file mode 100644 index 000000000000..342046a04f4f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/6d_blocked.js @@ -0,0 +1,392 @@ +/** +* @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 */ + +'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 condition to two six-dimensional input ndarrays according to a six-dimensional boolean ndarray and assigns results to elements in a six-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* +* // Create data buffers: +* var cbuf = new Uint8Array( [ 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1 ] ); +* 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, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] ); +* var obuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sc = [ 12, 12, 12, 4, 4, 1 ]; +* var sx = [ 12, 12, 12, 4, 4, 1 ]; +* var sy = [ 12, 12, 12, 4, 4, 1 ]; +* var so = [ 6, 6, 6, 2, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 1; +* var ox = 1; +* var oy = 1; +* var oo = 0; +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'uint8', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major' +* }; +* 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 out = { +* 'dtype': 'float64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major' +* }; +* +* // Apply the condition: +* blockedwhere6d( condition, x, y, out ); +* +* console.log( out.data ); +* // => [ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ] +*/ +function blockedwhere6d( condition, x, y, out ) { // eslint-disable-line max-statements, max-lines-per-function + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var dc0; + var dc1; + var dc2; + var dc3; + var dc4; + var dc5; + 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 do0; + var do1; + var do2; + var do3; + var do4; + var do5; + var oc1; + var oc2; + var oc3; + var oc4; + var oc5; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oo1; + var oo2; + var oo3; + var oo4; + var oo5; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var sc; + var sx; + var sy; + var so; + var oc; + var ox; + var oy; + var oo; + var ic; + var ix; + var iy; + var io; + 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#, dc#, dx#, dy#, do#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( condition.shape, condition.strides, x.strides, y.strides, out.strides ); // eslint-disable-line max-len + + // Strides output as follows: sx, sy, sz, sw. According to arguments order respectively.. + sh = o.sh; + sc = o.sx; + sx = o.sy; + sy = o.sz; + so = o.sw; + + // Determine the block size: + bsize = blockSize( condition.dtype, x.dtype, y.dtype, out.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + oc = condition.offset; + ox = x.offset; + oy = y.offset; + oo = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache offset increments for the innermost loop... + dc0 = sc[0]; + dx0 = sx[0]; + dy0 = sy[0]; + do0 = so[0]; + + // Iterate over blocks... + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + oc5 = oc - ( j5*sc[5] ); + ox5 = ox + ( j5*sx[5] ); + oy5 = oy + ( j5*sy[5] ); + oo5 = oo + ( j5*so[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dc5 = sc[5] - ( s4*sc[4] ); + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + do5 = so[5] - ( s4*so[4] ); + oc4 = oc5 + ( j4*sc[4] ); + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oo4 = oo5 + ( j4*so[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dc4 = sc[4] - ( s3*sc[3] ); + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + do4 = so[4] - ( s3*so[3] ); + oc3 = oc4 + ( j3*sc[3] ); + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oo3 = oo4 + ( j3*so[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dc3 = sc[3] - ( s2*sc[2] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + do3 = so[3] - ( s2*so[2] ); + oc2 = oc3 + ( j2*sc[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oo2 = oo3 + ( j2*so[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dc2 = sc[2] - ( s1*sc[1] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + do2 = so[2] - ( s1*so[1] ); + oc1 = oc2 + ( j1*sc[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oo1 = oo2 + ( j1*so[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... + ic = oc1 + ( j0*sc[0] ); + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + io = oo1 + ( j0*so[0] ); + + // Compute loop offset increments... + dc1 = sc[1] - ( s0*sc[0] ); + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + do1 = so[1] - ( s0*so[0] ); + + // Iterate over the ndarray dimensions... + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; // eslint-disable-line max-len + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + ic += dc4; + ix += dx4; + iy += dy4; + io += do4; + } + ic += dc5; + ix += dx5; + iy += dy5; + io += do5; + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhere6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/6d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/6d_blocked_accessors.js new file mode 100644 index 000000000000..e5c536f2915d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/6d_blocked_accessors.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 */ + +'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 condition to two six-dimensional input ndarrays according to a six-dimensional boolean ndarray and assigns results to elements in a six-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} condition.accessors - data buffer accessors +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} out.accessors - data buffer accessors +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var BooleanArray = require( '@stdlib/array/bool' ) +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var cbuf = new BooleanArray( [ 1, 0, 0, 1, 0, 1, 1, 0 ] ); +* var xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = new Complex64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 ] ); +* var obuf = new Complex64Array( 4 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sc = [ 4, 4, 4, 4, 2, 1 ]; +* var sx = [ 4, 4, 4, 4, 2, 1 ]; +* var sy = [ 4, 4, 4, 4, 2, 1 ]; +* var so = [ 4, 4, 4, 4, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 0; +* var oy = 0; +* var oo = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'bool', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var out = { +* 'dtype': 'complex64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the condition: +* blockedwhere6d( condition, x, y, out ); +* +* var v = out.data.get( 0 ); +* +* var re = realf( v ); +* // returns 1.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function blockedwhere6d( condition, x, y, out ) { // eslint-disable-line max-statements, max-lines-per-function + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var getc; + var getx; + var gety; + var seto; + var dc0; + var dc1; + var dc2; + var dc3; + var dc4; + var dc5; + 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 do0; + var do1; + var do2; + var do3; + var do4; + var do5; + var oc1; + var oc2; + var oc3; + var oc4; + var oc5; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oo1; + var oo2; + var oo3; + var oo4; + var oo5; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var sc; + var sx; + var sy; + var so; + var oc; + var ox; + var oy; + var oo; + var ic; + var ix; + var iy; + var io; + 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#, dc#, dx#, dy#, do#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( condition.shape, condition.strides, x.strides, y.strides, out.strides ); // eslint-disable-line max-len + + // Strides output as follows: sx, sy, sz, sw. According to arguments order respectively.. + sh = o.sh; + sc = o.sx; + sx = o.sy; + sy = o.sz; + so = o.sw; + + // Determine the block size: + bsize = blockSize( condition.dtype, x.dtype, y.dtype, out.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + oc = condition.offset; + ox = x.offset; + oy = y.offset; + oo = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache offset increments for the innermost loop... + dc0 = sc[0]; + dx0 = sx[0]; + dy0 = sy[0]; + do0 = so[0]; + + // Cache accessors: + getc = condition.accessors[ 0 ]; + getx = x.accessors[ 0 ]; + gety = y.accessors[ 0 ]; + seto = out.accessors[ 1 ]; + + // Iterate over blocks... + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + oc5 = oc - ( j5*sc[5] ); + ox5 = ox + ( j5*sx[5] ); + oy5 = oy + ( j5*sy[5] ); + oo5 = oo + ( j5*so[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dc5 = sc[5] - ( s4*sc[4] ); + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + do5 = so[5] - ( s4*so[4] ); + oc4 = oc5 + ( j4*sc[4] ); + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oo4 = oo5 + ( j4*so[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dc4 = sc[4] - ( s3*sc[3] ); + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + do4 = so[4] - ( s3*so[3] ); + oc3 = oc4 + ( j3*sc[3] ); + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oo3 = oo4 + ( j3*so[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dc3 = sc[3] - ( s2*sc[2] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + do3 = so[3] - ( s2*so[2] ); + oc2 = oc3 + ( j2*sc[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oo2 = oo3 + ( j2*so[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dc2 = sc[2] - ( s1*sc[1] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + do2 = so[2] - ( s1*so[1] ); + oc1 = oc2 + ( j1*sc[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oo1 = oo2 + ( j1*so[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... + ic = oc1 + ( j0*sc[0] ); + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + io = oo1 + ( j0*so[0] ); + + // Compute loop offset increments... + dc1 = sc[1] - ( s0*sc[0] ); + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + do1 = so[1] - ( s0*so[0] ); + + // Iterate over the ndarray dimensions... + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + ic += dc4; + ix += dx4; + iy += dy4; + io += do4; + } + ic += dc5; + ix += dx5; + iy += dy5; + io += do5; + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhere6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/7d.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/7d.js new file mode 100644 index 000000000000..440fa9e3fe55 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/7d.js @@ -0,0 +1,323 @@ +/** +* @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 */ + +'use strict'; + +// MAIN // + +/** +* Applies a condition to two seven-dimensional input ndarrays according to a seven-dimensional boolean ndarray and assigns results to elements in a seven-dimensional output ndarray. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* +* // Create data buffers: +* var cbuf = new Uint8Array( [ 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1 ] ); +* 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, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] ); +* var obuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sc = [ 12, 12, 12, 12, 4, 4, 1 ]; +* var sx = [ 12, 12, 12, 12, 4, 4, 1 ]; +* var sy = [ 12, 12, 12, 12, 4, 4, 1 ]; +* var so = [ 6, 6, 6, 6, 2, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 1; +* var ox = 1; +* var oy = 1; +* var oo = 0; +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'uint8', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major' +* }; +* 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 out = { +* 'dtype': 'float64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major' +* }; +* +* // Apply the condition: +* where7d( condition, x, y, out, true ); +* +* console.log( out.data ); +* // => [ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ] +*/ +function where7d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements + var cbuf; + var xbuf; + var ybuf; + var obuf; + var dc0; + var dc1; + var dc2; + var dc3; + var dc4; + var dc5; + var dc6; + 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 do0; + var do1; + var do2; + var do3; + var do4; + var do5; + var do6; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var sc; + var sx; + var sy; + var so; + var ic; + var ix; + var iy; + var io; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + + // Note on variable naming convention: S#, dc#, dx#, dy#, do#, 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; + sc = condition.strides; + sx = x.strides; + sy = y.strides; + so = out.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 ]; + dc0 = sc[ 6 ]; // offset increment for innermost loop + dc1 = sc[ 5 ] - ( S0*sc[6] ); + dc2 = sc[ 4 ] - ( S1*sc[5] ); + dc3 = sc[ 3 ] - ( S2*sc[4] ); + dc4 = sc[ 2 ] - ( S3*sc[3] ); + dc5 = sc[ 1 ] - ( S4*sc[2] ); + dc6 = sc[ 0 ] - ( S5*sc[1] ); // offset increment for outermost loop + dx0 = sx[ 6 ]; + 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] ); + 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] ); + do0 = so[ 6 ]; + do1 = so[ 5 ] - ( S0*so[6] ); + do2 = so[ 4 ] - ( S1*so[5] ); + do3 = so[ 3 ] - ( S2*so[4] ); + do4 = so[ 2 ] - ( S3*so[3] ); + do5 = so[ 1 ] - ( S4*so[2] ); + do6 = so[ 0 ] - ( S5*so[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 ]; + dc0 = sc[ 0 ]; // offset increment for innermost loop + dc1 = sc[ 1 ] - ( S0*sc[0] ); + dc2 = sc[ 2 ] - ( S1*sc[1] ); + dc3 = sc[ 3 ] - ( S2*sc[2] ); + dc4 = sc[ 4 ] - ( S3*sc[3] ); + dc5 = sc[ 5 ] - ( S4*sc[4] ); + dc6 = sc[ 6 ] - ( S5*sc[5] ); // offset increment for outermost loop + dx0 = sx[ 0 ]; + 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] ); + 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] ); + do0 = so[ 0 ]; + do1 = so[ 1 ] - ( S0*so[0] ); + do2 = so[ 2 ] - ( S1*so[1] ); + do3 = so[ 3 ] - ( S2*so[2] ); + do4 = so[ 4 ] - ( S3*so[3] ); + do5 = so[ 5 ] - ( S4*so[4] ); + do6 = so[ 6 ] - ( S5*so[5] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ic = condition.offset; + ix = x.offset; + iy = y.offset; + io = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.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++ ) { + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + ic += dc4; + ix += dx4; + iy += dy4; + io += do4; + } + ic += dc5; + ix += dx5; + iy += dy5; + io += do5; + } + ic += dc6; + ix += dx6; + iy += dy6; + io += do6; + } +} + +module.exports = where7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/7d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/7d_accessors.js new file mode 100644 index 000000000000..6f1a89af8950 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/7d_accessors.js @@ -0,0 +1,358 @@ +/** +* @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 */ + +'use strict'; + +// MAIN // + +/** +* Applies a condition to two seven-dimensional input ndarrays according to a seven-dimensional boolean ndarray and assigns results to elements in a seven-dimensional output ndarray. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} condition.accessors - data buffer accessors +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} out.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var BooleanArray = require( '@stdlib/array/bool' ); +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var cbuf = new BooleanArray( [ 1, 0, 0, 1, 0, 1, 1, 0 ] ); +* var xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0] ); +* var ybuf = new Complex64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 ] ); +* var obuf = new Complex64Array( 4 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sc = [ 4, 4, 4, 4, 4, 2, 1 ]; +* var sx = [ 4, 4, 4, 4, 4, 2, 1 ]; +* var sy = [ 4, 4, 4, 4, 4, 2, 1 ]; +* var so = [ 4, 4, 4, 4, 4, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 0; +* var oy = 0; +* var oo = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'bool', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var out = { +* 'dtype': 'complex64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the condition: +* where7d( condition, x, y, out, true ); +* +* var v = out.data.get( 0 ); +* +* var re = realf( v ); +* // returns 1.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function where7d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements + var cbuf; + var xbuf; + var ybuf; + var obuf; + var getc; + var getx; + var gety; + var seto; + var dc0; + var dc1; + var dc2; + var dc3; + var dc4; + var dc5; + var dc6; + 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 do0; + var do1; + var do2; + var do3; + var do4; + var do5; + var do6; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var sc; + var sx; + var sy; + var so; + var ic; + var ix; + var iy; + var io; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + + // Note on variable naming convention: S#, dc#, dx#, dy#, do#, 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; + sc = condition.strides; + sx = x.strides; + sy = y.strides; + so = out.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 ]; + dc0 = sc[ 6 ]; // offset increment for innermost loop + dc1 = sc[ 5 ] - ( S0*sc[6] ); + dc2 = sc[ 4 ] - ( S1*sc[5] ); + dc3 = sc[ 3 ] - ( S2*sc[4] ); + dc4 = sc[ 2 ] - ( S3*sc[3] ); + dc5 = sc[ 1 ] - ( S4*sc[2] ); + dc6 = sc[ 0 ] - ( S5*sc[1] ); // offset increment for outermost loop + dx0 = sx[ 6 ]; + 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] ); + 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] ); + do0 = so[ 6 ]; + do1 = so[ 5 ] - ( S0*so[6] ); + do2 = so[ 4 ] - ( S1*so[5] ); + do3 = so[ 3 ] - ( S2*so[4] ); + do4 = so[ 2 ] - ( S3*so[3] ); + do5 = so[ 1 ] - ( S4*so[2] ); + do6 = so[ 0 ] - ( S5*so[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 ]; + dc0 = sc[ 0 ]; // offset increment for innermost loop + dc1 = sc[ 1 ] - ( S0*sc[0] ); + dc2 = sc[ 2 ] - ( S1*sc[1] ); + dc3 = sc[ 3 ] - ( S2*sc[2] ); + dc4 = sc[ 4 ] - ( S3*sc[3] ); + dc5 = sc[ 5 ] - ( S4*sc[4] ); + dc6 = sc[ 6 ] - ( S5*sc[5] ); // offset increment for outermost loop + dx0 = sx[ 0 ]; + 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] ); + 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] ); + do0 = so[ 0 ]; + do1 = so[ 1 ] - ( S0*so[0] ); + do2 = so[ 2 ] - ( S1*so[1] ); + do3 = so[ 3 ] - ( S2*so[2] ); + do4 = so[ 4 ] - ( S3*so[3] ); + do5 = so[ 5 ] - ( S4*so[4] ); + do6 = so[ 6 ] - ( S5*so[5] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ic = condition.offset; + ix = x.offset; + iy = y.offset; + io = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache accessors: + getc = condition.accessors[ 0 ]; + getx = x.accessors[ 0 ]; + gety = y.accessors[ 0 ]; + seto = out.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++ ) { + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + ic += dc4; + ix += dx4; + iy += dy4; + io += do4; + } + ic += dc5; + ix += dx5; + iy += dy5; + io += do5; + } + ic += dc6; + ix += dx6; + iy += dy6; + io += do6; + } +} + +module.exports = where7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/7d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/7d_blocked.js new file mode 100644 index 000000000000..2d5bdbf78c97 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/7d_blocked.js @@ -0,0 +1,442 @@ +/** +* @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 */ + +'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 condition to two seven-dimensional input ndarrays according to a seven-dimensional boolean ndarray and assigns results to elements in a seven-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* +* // Create data buffers: +* var cbuf = new Uint8Array( [ 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1 ] ); +* 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, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] ); +* var obuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sc = [ 12, 12, 12, 12, 4, 4, 1 ]; +* var sx = [ 12, 12, 12, 12, 4, 4, 1 ]; +* var sy = [ 12, 12, 12, 12, 4, 4, 1 ]; +* var so = [ 6, 6, 6, 6, 2, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 1; +* var ox = 1; +* var oy = 1; +* var oo = 0; +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'uint8', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major' +* }; +* 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 out = { +* 'dtype': 'float64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major' +* }; +* +* // Apply the condition: +* blockedwhere7d( condition, x, y, out ); +* +* console.log( out.data ); +* // => [ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ] +*/ +function blockedwhere7d( condition, x, y, out ) { // eslint-disable-line max-statements, max-lines-per-function + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var dc0; + var dc1; + var dc2; + var dc3; + var dc4; + var dc5; + var dc6; + 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 do0; + var do1; + var do2; + var do3; + var do4; + var do5; + var do6; + var oc1; + var oc2; + var oc3; + var oc4; + var oc5; + var oc6; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var ox6; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oy6; + var oo1; + var oo2; + var oo3; + var oo4; + var oo5; + var oo6; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var sc; + var sx; + var sy; + var so; + var oc; + var ox; + var oy; + var oo; + var ic; + var ix; + var iy; + var io; + 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#, dc#, dx#, dy#, do#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( condition.shape, condition.strides, x.strides, y.strides, out.strides ); // eslint-disable-line max-len + + // Strides output as follows: sx, sy, sz, sw. According to arguments order respectively.. + sh = o.sh; + sc = o.sx; + sx = o.sy; + sy = o.sz; + so = o.sw; + + // Determine the block size: + bsize = blockSize( condition.dtype, x.dtype, y.dtype, out.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + oc = condition.offset; + ox = x.offset; + oy = y.offset; + oo = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache offset increments for the innermost loop... + dc0 = sc[0]; + dx0 = sx[0]; + dy0 = sy[0]; + do0 = so[0]; + + // Iterate over blocks... + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + oc6 = oc - ( j6*sc[6] ); + ox6 = ox + ( j6*sx[6] ); + oy6 = oy + ( j6*sy[6] ); + oo6 = oo + ( j6*so[6] ); + + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + + dc6 = sc[6] - ( s5*sc[5] ); + dx6 = sx[6] - ( s5*sx[5] ); + dy6 = sy[6] - ( s5*sy[5] ); + do6 = so[6] - ( s5*so[5] ); + + oc5 = oc6 + ( j5*sc[5] ); + ox5 = ox6 + ( j5*sx[5] ); + oy5 = oy6 + ( j5*sy[5] ); + oo5 = oo6 + ( j5*so[5] ); + + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + + dc5 = sc[5] - ( s4*sc[4] ); + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + do5 = so[5] - ( s4*so[4] ); + + oc4 = oc5 + ( j4*sc[4] ); + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oo4 = oo5 + ( j4*so[4] ); + + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + + dc4 = sc[4] - ( s3*sc[3] ); + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + do4 = so[4] - ( s3*so[3] ); + + oc3 = oc4 + ( j3*sc[3] ); + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oo3 = oo4 + ( j3*so[3] ); + + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + + dc3 = sc[3] - ( s2*sc[2] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + do3 = so[3] - ( s2*so[2] ); + + oc2 = oc3 + ( j2*sc[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oo2 = oo3 + ( j2*so[2] ); + + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + + dc2 = sc[2] - ( s1*sc[1] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + do2 = so[2] - ( s1*so[1] ); + + oc1 = oc2 + ( j1*sc[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oo1 = oo2 + ( j1*so[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... + ic = oc1 + ( j0*sc[0] ); + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + io = oo1 + ( j0*so[0] ); + + // Compute loop offset increments... + dc1 = sc[1] - ( s0*sc[0] ); + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + do1 = so[1] - ( s0*so[0] ); + + // Iterate over the ndarray dimensions... + for ( i6 = 0; i6 < s6; i6++ ) { + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { // eslint-disable-line max-len + for ( i0 = 0; i0 < s0; i0++ ) { // eslint-disable-line max-len + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; // eslint-disable-line max-len + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + ic += dc4; + ix += dx4; + iy += dy4; + io += do4; + } + ic += dc5; + ix += dx5; + iy += dy5; + io += do5; + } + ic += dc6; + ix += dx6; + iy += dy6; + io += do6; + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhere7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/7d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/7d_blocked_accessors.js new file mode 100644 index 000000000000..8dcc9f69ae43 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/7d_blocked_accessors.js @@ -0,0 +1,477 @@ +/** +* @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 */ + +'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 condition to two seven-dimensional input ndarrays according to a seven-dimensional boolean ndarray and assigns results to elements in a seven-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} condition.accessors - data buffer accessors +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} out.accessors - data buffer accessors +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var BooleanArray = require( '@stdlib/array/bool' ) +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var cbuf = new BooleanArray( [ 1, 0, 0, 1, 0, 1, 1, 0 ] ); +* var xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = new Complex64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 ] ); +* var obuf = new Complex64Array( 4 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sc = [ 4, 4, 4, 4, 4, 2, 1 ]; +* var sx = [ 4, 4, 4, 4, 4, 2, 1 ]; +* var sy = [ 4, 4, 4, 4, 4, 2, 1 ]; +* var so = [ 4, 4, 4, 4, 4, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 0; +* var oy = 0; +* var oo = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'bool', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var out = { +* 'dtype': 'complex64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the condition: +* blockedwhere7d( condition, x, y, out ); +* +* var v = out.data.get( 0 ); +* +* var re = realf( v ); +* // returns 1.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function blockedwhere7d( condition, x, y, out ) { // eslint-disable-line max-statements, max-lines-per-function + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var getc; + var getx; + var gety; + var seto; + var dc0; + var dc1; + var dc2; + var dc3; + var dc4; + var dc5; + var dc6; + 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 do0; + var do1; + var do2; + var do3; + var do4; + var do5; + var do6; + var oc1; + var oc2; + var oc3; + var oc4; + var oc5; + var oc6; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var ox6; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oy6; + var oo1; + var oo2; + var oo3; + var oo4; + var oo5; + var oo6; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var sc; + var sx; + var sy; + var so; + var oc; + var ox; + var oy; + var oo; + var ic; + var ix; + var iy; + var io; + 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#, dc#, dx#, dy#, do#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( condition.shape, condition.strides, x.strides, y.strides, out.strides ); // eslint-disable-line max-len + + // Strides output as follows: sx, sy, sz, sw. According to arguments order respectively.. + sh = o.sh; + sc = o.sx; + sx = o.sy; + sy = o.sz; + so = o.sw; + + // Determine the block size: + bsize = blockSize( condition.dtype, x.dtype, y.dtype, out.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + oc = condition.offset; + ox = x.offset; + oy = y.offset; + oo = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache offset increments for the innermost loop... + dc0 = sc[0]; + dx0 = sx[0]; + dy0 = sy[0]; + do0 = so[0]; + + // Cache accessors: + getc = condition.accessors[0]; + getx = x.accessors[0]; + gety = y.accessors[0]; + seto = out.accessors[1]; + + // Iterate over blocks... + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + oc6 = oc - ( j6*sc[6] ); + ox6 = ox + ( j6*sx[6] ); + oy6 = oy + ( j6*sy[6] ); + oo6 = oo + ( j6*so[6] ); + + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + + dc6 = sc[6] - ( s5*sc[5] ); + dx6 = sx[6] - ( s5*sx[5] ); + dy6 = sy[6] - ( s5*sy[5] ); + do6 = so[6] - ( s5*so[5] ); + + oc5 = oc6 + ( j5*sc[5] ); + ox5 = ox6 + ( j5*sx[5] ); + oy5 = oy6 + ( j5*sy[5] ); + oo5 = oo6 + ( j5*so[5] ); + + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + + dc5 = sc[5] - ( s4*sc[4] ); + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + do5 = so[5] - ( s4*so[4] ); + + oc4 = oc5 + ( j4*sc[4] ); + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oo4 = oo5 + ( j4*so[4] ); + + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + + dc4 = sc[4] - ( s3*sc[3] ); + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + do4 = so[4] - ( s3*so[3] ); + + oc3 = oc4 + ( j3*sc[3] ); + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oo3 = oo4 + ( j3*so[3] ); + + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + + dc3 = sc[3] - ( s2*sc[2] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + do3 = so[3] - ( s2*so[2] ); + + oc2 = oc3 + ( j2*sc[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oo2 = oo3 + ( j2*so[2] ); + + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + + dc2 = sc[2] - ( s1*sc[1] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + do2 = so[2] - ( s1*so[1] ); + + oc1 = oc2 + ( j1*sc[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oo1 = oo2 + ( j1*so[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... + ic = oc1 + ( j0*sc[0] ); + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + io = oo1 + ( j0*so[0] ); + + // Compute loop offset increments... + dc1 = sc[1] - ( s0*sc[0] ); + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + do1 = so[1] - ( s0*so[0] ); + + // Iterate over the ndarray dimensions... + for ( i6 = 0; i6 < s6; i6++ ) { + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { // eslint-disable-line max-len + for ( i0 = 0; i0 < s0; i0++ ) { // eslint-disable-line max-len + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + ic += dc4; + ix += dx4; + iy += dy4; + io += do4; + } + ic += dc5; + ix += dx5; + iy += dy5; + io += do5; + } + ic += dc6; + ix += dx6; + iy += dy6; + io += do6; + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhere7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/8d.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/8d.js new file mode 100644 index 000000000000..e062723362ce --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/8d.js @@ -0,0 +1,348 @@ +/** +* @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 */ + +'use strict'; + +// MAIN // + +/** +* Applies a condition to two eight-dimensional input ndarrays according to a eight-dimensional boolean ndarray and assigns results to elements in a eight-dimensional output ndarray. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* +* // Create data buffers: +* var cbuf = new Uint8Array( [ 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1 ] ); +* 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, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] ); +* var obuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sc = [ 12, 12, 12, 12, 12, 4, 4, 1 ]; +* var sx = [ 12, 12, 12, 12, 12, 4, 4, 1 ]; +* var sy = [ 12, 12, 12, 12, 12, 4, 4, 1 ]; +* var so = [ 6, 6, 6, 6, 6, 2, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 1; +* var ox = 1; +* var oy = 1; +* var oo = 0; +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'uint8', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major' +* }; +* 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 out = { +* 'dtype': 'float64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major' +* }; +* +* // Apply the condition: +* where8d( condition, x, y, out, true ); +* +* console.log( out.data ); +* // => [ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ] +*/ +function where8d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements, max-lines-per-function + var cbuf; + var xbuf; + var ybuf; + var obuf; + var dc0; + var dc1; + var dc2; + var dc3; + var dc4; + var dc5; + var dc6; + var dc7; + 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 do0; + var do1; + var do2; + var do3; + var do4; + var do5; + var do6; + var do7; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var sc; + var sx; + var sy; + var so; + var ic; + var ix; + var iy; + var io; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + + // Note on variable naming convention: S#, dc#, dx#, dy#, do#, 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; + sc = condition.strides; + sx = x.strides; + sy = y.strides; + so = out.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 ]; + dc0 = sc[ 7 ]; // offset increment for innermost loop + dc1 = sc[ 6 ] - ( S0*sc[7] ); + dc2 = sc[ 5 ] - ( S1*sc[6] ); + dc3 = sc[ 4 ] - ( S2*sc[5] ); + dc4 = sc[ 3 ] - ( S3*sc[4] ); + dc5 = sc[ 2 ] - ( S4*sc[3] ); + dc6 = sc[ 1 ] - ( S5*sc[2] ); + dc7 = sc[ 0 ] - ( S6*sc[1] ); // offset increment for outermost loop + dx0 = sx[ 7 ]; + 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] ); + 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] ); + do0 = so[ 7 ]; + do1 = so[ 6 ] - ( S0*so[7] ); + do2 = so[ 5 ] - ( S1*so[6] ); + do3 = so[ 4 ] - ( S2*so[5] ); + do4 = so[ 3 ] - ( S3*so[4] ); + do5 = so[ 2 ] - ( S4*so[3] ); + do6 = so[ 1 ] - ( S5*so[2] ); + do7 = so[ 0 ] - ( S6*so[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 ]; + dc0 = sc[ 0 ]; // offset increment for innermost loop + dc1 = sc[ 1 ] - ( S0*sc[0] ); + dc2 = sc[ 2 ] - ( S1*sc[1] ); + dc3 = sc[ 3 ] - ( S2*sc[2] ); + dc4 = sc[ 4 ] - ( S3*sc[3] ); + dc5 = sc[ 5 ] - ( S4*sc[4] ); + dc6 = sc[ 6 ] - ( S5*sc[5] ); + dc7 = sc[ 7 ] - ( S6*sc[6] ); // offset increment for outermost loop + dx0 = sx[ 0 ]; + 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] ); + 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] ); + do0 = so[ 0 ]; + do1 = so[ 1 ] - ( S0*so[0] ); + do2 = so[ 2 ] - ( S1*so[1] ); + do3 = so[ 3 ] - ( S2*so[2] ); + do4 = so[ 4 ] - ( S3*so[3] ); + do5 = so[ 5 ] - ( S4*so[4] ); + do6 = so[ 6 ] - ( S5*so[5] ); + do7 = so[ 7 ] - ( S6*so[6] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ic = condition.offset; + ix = x.offset; + iy = y.offset; + io = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.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++ ) { + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + ic += dc4; + ix += dx4; + iy += dy4; + io += do4; + } + ic += dc5; + ix += dx5; + iy += dy5; + io += do5; + } + ic += dc6; + ix += dx6; + iy += dy6; + io += do6; + } + ic += dc7; + ix += dx7; + iy += dy7; + io += do7; + } +} + + +// EXPORTS // + +module.exports = where8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/8d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/8d_accessors.js new file mode 100644 index 000000000000..d44f4233af11 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/8d_accessors.js @@ -0,0 +1,383 @@ +/** +* @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 */ + +'use strict'; + +// MAIN // + +/** +* Applies a condition to two eight-dimensional input ndarrays according to a eight-dimensional boolean ndarray and assigns results to elements in a eight-dimensional output ndarray. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} condition.accessors - data buffer accessors +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} out.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var BooleanArray = require( '@stdlib/array/bool' ); +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var cbuf = new BooleanArray( [ 1, 0, 0, 1, 0, 1, 1, 0 ] ); +* var xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0] ); +* var ybuf = new Complex64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 ] ); +* var obuf = new Complex64Array( 4 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sc = [ 4, 4, 4, 4, 4, 4, 2, 1 ]; +* var sx = [ 4, 4, 4, 4, 4, 4, 2, 1 ]; +* var sy = [ 4, 4, 4, 4, 4, 4, 2, 1 ]; +* var so = [ 4, 4, 4, 4, 4, 4, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 0; +* var oy = 0; +* var oo = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'bool', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var out = { +* 'dtype': 'complex64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the condition: +* where8d( condition, x, y, out, true ); +* +* var v = out.data.get( 0 ); +* +* var re = realf( v ); +* // returns 1.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function where8d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements, max-lines-per-function + var cbuf; + var xbuf; + var ybuf; + var obuf; + var getc; + var getx; + var gety; + var seto; + var dc0; + var dc1; + var dc2; + var dc3; + var dc4; + var dc5; + var dc6; + var dc7; + 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 do0; + var do1; + var do2; + var do3; + var do4; + var do5; + var do6; + var do7; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var sc; + var sx; + var sy; + var so; + var ic; + var ix; + var iy; + var io; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + + // Note on variable naming convention: S#, dc#, dx#, dy#, do#, 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; + sc = condition.strides; + sx = x.strides; + sy = y.strides; + so = out.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 ]; + dc0 = sc[ 7 ]; // offset increment for innermost loop + dc1 = sc[ 6 ] - ( S0*sc[7] ); + dc2 = sc[ 5 ] - ( S1*sc[6] ); + dc3 = sc[ 4 ] - ( S2*sc[5] ); + dc4 = sc[ 3 ] - ( S3*sc[4] ); + dc5 = sc[ 2 ] - ( S4*sc[3] ); + dc6 = sc[ 1 ] - ( S5*sc[2] ); + dc7 = sc[ 0 ] - ( S6*sc[1] ); // offset increment for outermost loop + dx0 = sx[ 7 ]; + 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] ); + 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] ); + do0 = so[ 7 ]; + do1 = so[ 6 ] - ( S0*so[7] ); + do2 = so[ 5 ] - ( S1*so[6] ); + do3 = so[ 4 ] - ( S2*so[5] ); + do4 = so[ 3 ] - ( S3*so[4] ); + do5 = so[ 2 ] - ( S4*so[3] ); + do6 = so[ 1 ] - ( S5*so[2] ); + do7 = so[ 0 ] - ( S6*so[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 ]; + dc0 = sc[ 0 ]; // offset increment for innermost loop + dc1 = sc[ 1 ] - ( S0*sc[0] ); + dc2 = sc[ 2 ] - ( S1*sc[1] ); + dc3 = sc[ 3 ] - ( S2*sc[2] ); + dc4 = sc[ 4 ] - ( S3*sc[3] ); + dc5 = sc[ 5 ] - ( S4*sc[4] ); + dc6 = sc[ 6 ] - ( S5*sc[5] ); + dc7 = sc[ 7 ] - ( S6*sc[6] ); // offset increment for outermost loop + dx0 = sx[ 0 ]; + 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] ); + 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] ); + do0 = so[ 0 ]; + do1 = so[ 1 ] - ( S0*so[0] ); + do2 = so[ 2 ] - ( S1*so[1] ); + do3 = so[ 3 ] - ( S2*so[2] ); + do4 = so[ 4 ] - ( S3*so[3] ); + do5 = so[ 5 ] - ( S4*so[4] ); + do6 = so[ 6 ] - ( S5*so[5] ); + do7 = so[ 7 ] - ( S6*so[6] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ic = condition.offset; + ix = x.offset; + iy = y.offset; + io = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache accessors: + getc = condition.accessors[ 0 ]; + getx = x.accessors[ 0 ]; + gety = y.accessors[ 0 ]; + seto = out.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++ ) { + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + ic += dc4; + ix += dx4; + iy += dy4; + io += do4; + } + ic += dc5; + ix += dx5; + iy += dy5; + io += do5; + } + ic += dc6; + ix += dx6; + iy += dy6; + io += do6; + } + ic += dc7; + ix += dx7; + iy += dy7; + io += do7; + } +} + + +// EXPORTS // + +module.exports = where8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/8d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/8d_blocked.js new file mode 100644 index 000000000000..fa53b67cb3f9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/8d_blocked.js @@ -0,0 +1,460 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-depth, max-len */ + +'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 condition to two eight-dimensional input ndarrays according to a eight-dimensional boolean ndarray and assigns results to elements in a eight-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* +* // Create data buffers: +* var cbuf = new Uint8Array( [ 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1 ] ); +* 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, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] ); +* var obuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sc = [ 12, 12, 12, 12, 12, 4, 4, 1 ]; +* var sx = [ 12, 12, 12, 12, 12, 4, 4, 1 ]; +* var sy = [ 12, 12, 12, 12, 12, 4, 4, 1 ]; +* var so = [ 6, 6, 6, 6, 6, 2, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 1; +* var ox = 1; +* var oy = 1; +* var oo = 0; +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'uint8', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major' +* }; +* 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 out = { +* 'dtype': 'float64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major' +* }; +* +* // Apply the condition: +* blockedwhere8d( condition, x, y, out ); +* +* console.log( out.data ); +* // => [ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ] +*/ +function blockedwhere8d( condition, x, y, out ) { // eslint-disable-line max-statements, max-lines-per-function + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var dc0; + var dc1; + var dc2; + var dc3; + var dc4; + var dc5; + var dc6; + var dc7; + 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 do0; + var do1; + var do2; + var do3; + var do4; + var do5; + var do6; + var do7; + var oc1; + var oc2; + var oc3; + var oc4; + var oc5; + var oc6; + var oc7; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var ox6; + var ox7; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oy6; + var oy7; + var oo1; + var oo2; + var oo3; + var oo4; + var oo5; + var oo6; + var oo7; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var sc; + var sx; + var sy; + var so; + var oc; + var ox; + var oy; + var oo; + var ic; + var ix; + var iy; + var io; + 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#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( condition.shape, condition.strides, x.strides, y.strides, out.strides ); + + // Strides output as follows: sx, sy, sz, sw. According to arguments order respectively.. + sh = o.sh; + sc = o.sx; + sx = o.sy; + sy = o.sz; + so = o.sw; + + // Determine the block size: + bsize = blockSize( condition.dtype, x.dtype, y.dtype, out.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + oc = condition.offset; + ox = x.offset; + oy = y.offset; + oo = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache offset increments for the innermost loop... + dc0 = sc[0]; + dx0 = sx[0]; + dy0 = sy[0]; + do0 = so[0]; + + // Iterate over blocks... + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + oc7 = oc + ( j7*sc[7] ); + ox7 = ox + ( j7*sx[7] ); + oy7 = oy + ( j7*sy[7] ); + oo7 = oo + ( j7*so[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + dc7 = sc[7] - ( s6*sc[6] ); + dx7 = sx[7] - ( s6*sx[6] ); + dy7 = sy[7] - ( s6*sy[6] ); + do7 = so[7] - ( s6*so[6] ); + oc6 = oc7 + ( j6*sc[6] ); + ox6 = ox7 + ( j6*sx[6] ); + oy6 = oy7 + ( j6*sy[6] ); + oo6 = oo7 + ( j6*so[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dc6 = sc[6] - ( s5*sc[5] ); + dx6 = sx[6] - ( s5*sx[5] ); + dy6 = sy[6] - ( s5*sy[5] ); + do6 = so[6] - ( s5*so[5] ); + oc5 = oc6 + ( j5*sc[5] ); + ox5 = ox6 + ( j5*sx[5] ); + oy5 = oy6 + ( j5*sy[5] ); + oo5 = oo6 + ( j5*so[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dc5 = sc[5] - ( s4*sc[4] ); + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + do5 = so[5] - ( s4*so[4] ); + oc4 = oc5 + ( j4*sc[4] ); + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oo4 = oo5 + ( j4*so[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dc4 = sc[4] - ( s3*sc[3] ); + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + do4 = so[4] - ( s3*so[3] ); + oc3 = oc4 + ( j3*sc[3] ); + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oo3 = oo4 + ( j3*so[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dc3 = sc[3] - ( s2*sc[2] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + do3 = so[3] - ( s2*so[2] ); + oc2 = oc3 + ( j2*sc[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oo2 = oo3 + ( j2*so[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dc2 = sc[2] - ( s1*sc[1] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + do2 = so[2] - ( s1*so[1] ); + oc1 = oc2 + ( j1*sc[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oo1 = oo2 + ( j1*so[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... + ic = oc1 + ( j0*sc[0] ); + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + io = oo1 + ( j0*so[0] ); + + // Compute loop offset increments... + dc1 = sc[1] - ( s0*sc[0] ); + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + do1 = so[1] - ( s0*so[0] ); + + // Iterate over the ndarray dimensions... + for ( i7 = 0; i7 < s7; i7++ ) { + for ( i6 = 0; i6 < s6; i6++ ) { + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + ic += dc4; + ix += dx4; + iy += dy4; + io += do4; + } + ic += dc5; + ix += dx5; + iy += dy5; + io += do5; + } + ic += dc6; + ix += dx6; + iy += dy6; + io += do6; + } + ic += dc7; + ix += dx7; + iy += dy7; + io += do7; + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhere8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/8d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/8d_blocked_accessors.js new file mode 100644 index 000000000000..0bc562789f47 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/8d_blocked_accessors.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-len */ + +'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 condition to two eight-dimensional input ndarrays according to a eight-dimensional boolean ndarray and assigns results to elements in a eight-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} condition.accessors - data buffer accessors +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} out.accessors - data buffer accessors +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var BooleanArray = require( '@stdlib/array/bool' ) +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var cbuf = new BooleanArray( [ 1, 0, 0, 1, 0, 1, 1, 0 ] ); +* var xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = new Complex64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 ] ); +* var obuf = new Complex64Array( 4 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sc = [ 4, 4, 4, 4, 4, 4, 2, 1 ]; +* var sx = [ 4, 4, 4, 4, 4, 4, 2, 1 ]; +* var sy = [ 4, 4, 4, 4, 4, 4, 2, 1 ]; +* var so = [ 4, 4, 4, 4, 4, 4, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 0; +* var oy = 0; +* var oo = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'bool', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var out = { +* 'dtype': 'complex64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the condition: +* blockedwhere8d( condition, x, y, out ); +* +* var v = out.data.get( 0 ); +* +* var re = realf( v ); +* // returns 1.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function blockedwhere8d( condition, x, y, out ) { // eslint-disable-line max-statements, max-lines-per-function + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var getc; + var getx; + var gety; + var seto; + var dc0; + var dc1; + var dc2; + var dc3; + var dc4; + var dc5; + var dc6; + var dc7; + 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 do0; + var do1; + var do2; + var do3; + var do4; + var do5; + var do6; + var do7; + var oc1; + var oc2; + var oc3; + var oc4; + var oc5; + var oc6; + var oc7; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var ox6; + var ox7; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oy6; + var oy7; + var oo1; + var oo2; + var oo3; + var oo4; + var oo5; + var oo6; + var oo7; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var sc; + var sx; + var sy; + var so; + var oc; + var ox; + var oy; + var oo; + var ic; + var ix; + var iy; + var io; + 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#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( condition.shape, condition.strides, x.strides, y.strides, out.strides ); + + // Strides output as follows: sx, sy, sz, sw. According to arguments order respectively.. + sh = o.sh; + sc = o.sx; + sx = o.sy; + sy = o.sz; + so = o.sw; + + // Determine the block size: + bsize = blockSize( condition.dtype, x.dtype, y.dtype, out.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + oc = condition.offset; + ox = x.offset; + oy = y.offset; + oo = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache offset increments for the innermost loop... + dc0 = sc[0]; + dx0 = sx[0]; + dy0 = sy[0]; + do0 = so[0]; + + // Cache accessors: + getc = condition.accessors[0]; + getx = x.accessors[0]; + gety = y.accessors[0]; + seto = out.accessors[1]; + + // Iterate over blocks... + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + oc7 = oc + ( j7*sc[7] ); + ox7 = ox + ( j7*sx[7] ); + oy7 = oy + ( j7*sy[7] ); + oo7 = oo + ( j7*so[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + dc7 = sc[7] - ( s6*sc[6] ); + dx7 = sx[7] - ( s6*sx[6] ); + dy7 = sy[7] - ( s6*sy[6] ); + do7 = so[7] - ( s6*so[6] ); + oc6 = oc7 + ( j6*sc[6] ); + ox6 = ox7 + ( j6*sx[6] ); + oy6 = oy7 + ( j6*sy[6] ); + oo6 = oo7 + ( j6*so[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dc6 = sc[6] - ( s5*sc[5] ); + dx6 = sx[6] - ( s5*sx[5] ); + dy6 = sy[6] - ( s5*sy[5] ); + do6 = so[6] - ( s5*so[5] ); + oc5 = oc6 + ( j5*sc[5] ); + ox5 = ox6 + ( j5*sx[5] ); + oy5 = oy6 + ( j5*sy[5] ); + oo5 = oo6 + ( j5*so[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dc5 = sc[5] - ( s4*sc[4] ); + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + do5 = so[5] - ( s4*so[4] ); + oc4 = oc5 + ( j4*sc[4] ); + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oo4 = oo5 + ( j4*so[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dc4 = sc[4] - ( s3*sc[3] ); + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + do4 = so[4] - ( s3*so[3] ); + oc3 = oc4 + ( j3*sc[3] ); + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oo3 = oo4 + ( j3*so[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dc3 = sc[3] - ( s2*sc[2] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + do3 = so[3] - ( s2*so[2] ); + oc2 = oc3 + ( j2*sc[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oo2 = oo3 + ( j2*so[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dc2 = sc[2] - ( s1*sc[1] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + do2 = so[2] - ( s1*so[1] ); + oc1 = oc2 + ( j1*sc[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oo1 = oo2 + ( j1*so[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... + ic = oc1 + ( j0*sc[0] ); + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + io = oo1 + ( j0*so[0] ); + + // Compute loop offset increments... + dc1 = sc[1] - ( s0*sc[0] ); + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + do1 = so[1] - ( s0*so[0] ); + + // Iterate over the ndarray dimensions... + for ( i7 = 0; i7 < s7; i7++ ) { + for ( i6 = 0; i6 < s6; i6++ ) { + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + ic += dc4; + ix += dx4; + iy += dy4; + io += do4; + } + ic += dc5; + ix += dx5; + iy += dy5; + io += do5; + } + ic += dc6; + ix += dx6; + iy += dy6; + io += do6; + } + ic += dc7; + ix += dx7; + iy += dy7; + io += do7; + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhere8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/9d.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/9d.js new file mode 100644 index 000000000000..31d9f07f364a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/9d.js @@ -0,0 +1,370 @@ +/** +* @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 */ + +'use strict'; + +// MAIN // + +/** +* Applies a condition to two nine-dimensional input ndarrays according to a nine-dimensional boolean ndarray and assigns results to elements in a nine-dimensional output ndarray. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* +* // Create data buffers: +* var cbuf = new Uint8Array( [ 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1 ] ); +* 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, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] ); +* var obuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sc = [ 12, 12, 12, 12, 12, 12, 4, 4, 1 ]; +* var sx = [ 12, 12, 12, 12, 12, 12, 4, 4, 1 ]; +* var sy = [ 12, 12, 12, 12, 12, 12, 4, 4, 1 ]; +* var so = [ 6, 6, 6, 6, 6, 6, 2, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 1; +* var ox = 1; +* var oy = 1; +* var oo = 0; +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'uint8', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major' +* }; +* 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 out = { +* 'dtype': 'float64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major' +* }; +* +* // Apply the condition: +* where9d( condition, x, y, out, true ); +* +* console.log( out.data ); +* // => [ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ] +*/ +function where9d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements, max-lines-per-function + var cbuf; + var xbuf; + var ybuf; + var obuf; + var dc0; + var dc1; + var dc2; + var dc3; + var dc4; + var dc5; + var dc6; + var dc7; + var dc8; + 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 do0; + var do1; + var do2; + var do3; + var do4; + var do5; + var do6; + var do7; + var do8; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var S8; + var sc; + var sx; + var sy; + var so; + var ic; + var ix; + var iy; + var io; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + + // Note on variable naming convention: S#, dc#, dx#, dy#, do#, 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; + sc = condition.strides; + sx = x.strides; + sy = y.strides; + so = out.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 ]; + dc0 = sc[ 8 ]; // offset increment for innermost loop + dc1 = sc[ 7 ] - ( S0*sc[8] ); + dc2 = sc[ 6 ] - ( S1*sc[7] ); + dc3 = sc[ 5 ] - ( S2*sc[6] ); + dc4 = sc[ 4 ] - ( S3*sc[5] ); + dc5 = sc[ 3 ] - ( S4*sc[4] ); + dc6 = sc[ 2 ] - ( S5*sc[3] ); + dc7 = sc[ 1 ] - ( S6*sc[2] ); + dc8 = sc[ 0 ] - ( S7*sc[1] ); // offset increment for outermost loop + dx0 = sx[ 8 ]; + 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] ); + 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] ); + do0 = so[ 8 ]; + do1 = so[ 7 ] - ( S0*so[8] ); + do2 = so[ 6 ] - ( S1*so[7] ); + do3 = so[ 5 ] - ( S2*so[6] ); + do4 = so[ 4 ] - ( S3*so[5] ); + do5 = so[ 3 ] - ( S4*so[4] ); + do6 = so[ 2 ] - ( S5*so[3] ); + do7 = so[ 1 ] - ( S6*so[2] ); + do8 = so[ 0 ] - ( S7*so[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 ]; + dc0 = sc[ 0 ]; // offset increment for innermost loop + dc1 = sc[ 1 ] - ( S0*sc[0] ); + dc2 = sc[ 2 ] - ( S1*sc[1] ); + dc3 = sc[ 3 ] - ( S2*sc[2] ); + dc4 = sc[ 4 ] - ( S3*sc[3] ); + dc5 = sc[ 5 ] - ( S4*sc[4] ); + dc6 = sc[ 6 ] - ( S5*sc[5] ); + dc7 = sc[ 7 ] - ( S6*sc[6] ); + dc8 = sc[ 8 ] - ( S7*sc[7] ); // offset increment for outermost loop + dx0 = sx[ 0 ]; + 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] ); + 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] ); + do0 = so[ 0 ]; + do1 = so[ 1 ] - ( S0*so[0] ); + do2 = so[ 2 ] - ( S1*so[1] ); + do3 = so[ 3 ] - ( S2*so[2] ); + do4 = so[ 4 ] - ( S3*so[3] ); + do5 = so[ 5 ] - ( S4*so[4] ); + do6 = so[ 6 ] - ( S5*so[5] ); + do7 = so[ 7 ] - ( S6*so[6] ); + do8 = so[ 8 ] - ( S7*so[7] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ic = condition.offset; + ix = x.offset; + iy = y.offset; + io = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.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++ ) { + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; // eslint-disable-line max-len + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + ic += dc4; + ix += dx4; + iy += dy4; + io += do4; + } + ic += dc5; + ix += dx5; + iy += dy5; + io += do5; + } + ic += dc6; + ix += dx6; + iy += dy6; + io += do6; + } + ic += dc7; + ix += dx7; + iy += dy7; + io += do7; + } + ic += dc8; + ix += dx8; + iy += dy8; + io += do8; + } +} + + +// EXPORTS // + +module.exports = where9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/9d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/9d_accessors.js new file mode 100644 index 000000000000..dd8a36838581 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/9d_accessors.js @@ -0,0 +1,405 @@ +/** +* @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 */ + +'use strict'; + +// MAIN // + +/** +* Applies a condition to two nine-dimensional input ndarrays according to a nine-dimensional boolean ndarray and assigns results to elements in a nine-dimensional output ndarray. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} condition.accessors - data buffer accessors +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} out.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var BooleanArray = require( '@stdlib/array/bool' ); +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var cbuf = new BooleanArray( [ 1, 0, 0, 1, 0, 1, 1, 0 ] ); +* var xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0] ); +* var ybuf = new Complex64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 ] ); +* var obuf = new Complex64Array( 4 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sc = [ 4, 4, 4, 4, 4, 4, 4, 2, 1 ]; +* var sx = [ 4, 4, 4, 4, 4, 4, 4, 2, 1 ]; +* var sy = [ 4, 4, 4, 4, 4, 4, 4, 2, 1 ]; +* var so = [ 4, 4, 4, 4, 4, 4, 4, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 0; +* var oy = 0; +* var oo = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'bool', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var out = { +* 'dtype': 'complex64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the condition: +* where9d( condition, x, y, out, true ); +* +* var v = out.data.get( 0 ); +* +* var re = realf( v ); +* // returns 1.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function where9d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements, max-lines-per-function + var cbuf; + var xbuf; + var ybuf; + var obuf; + var getc; + var getx; + var gety; + var seto; + var dc0; + var dc1; + var dc2; + var dc3; + var dc4; + var dc5; + var dc6; + var dc7; + var dc8; + 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 do0; + var do1; + var do2; + var do3; + var do4; + var do5; + var do6; + var do7; + var do8; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var S8; + var sc; + var sx; + var sy; + var so; + var ic; + var ix; + var iy; + var io; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + + // Note on variable naming convention: S#, dc#, dx#, dy#, do#, 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; + sc = condition.strides; + sx = x.strides; + sy = y.strides; + so = out.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 ]; + dc0 = sc[ 8 ]; // offset increment for innermost loop + dc1 = sc[ 7 ] - ( S0*sc[8] ); + dc2 = sc[ 6 ] - ( S1*sc[7] ); + dc3 = sc[ 5 ] - ( S2*sc[6] ); + dc4 = sc[ 4 ] - ( S3*sc[5] ); + dc5 = sc[ 3 ] - ( S4*sc[4] ); + dc6 = sc[ 2 ] - ( S5*sc[3] ); + dc7 = sc[ 1 ] - ( S6*sc[2] ); + dc8 = sc[ 0 ] - ( S7*sc[1] ); // offset increment for outermost loop + dx0 = sx[ 8 ]; + 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] ); + 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] ); + do0 = so[ 8 ]; + do1 = so[ 7 ] - ( S0*so[8] ); + do2 = so[ 6 ] - ( S1*so[7] ); + do3 = so[ 5 ] - ( S2*so[6] ); + do4 = so[ 4 ] - ( S3*so[5] ); + do5 = so[ 3 ] - ( S4*so[4] ); + do6 = so[ 2 ] - ( S5*so[3] ); + do7 = so[ 1 ] - ( S6*so[2] ); + do8 = so[ 0 ] - ( S7*so[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 ]; + dc0 = sc[ 0 ]; // offset increment for innermost loop + dc1 = sc[ 1 ] - ( S0*sc[0] ); + dc2 = sc[ 2 ] - ( S1*sc[1] ); + dc3 = sc[ 3 ] - ( S2*sc[2] ); + dc4 = sc[ 4 ] - ( S3*sc[3] ); + dc5 = sc[ 5 ] - ( S4*sc[4] ); + dc6 = sc[ 6 ] - ( S5*sc[5] ); + dc7 = sc[ 7 ] - ( S6*sc[6] ); + dc8 = sc[ 8 ] - ( S7*sc[7] ); // offset increment for outermost loop + dx0 = sx[ 0 ]; + 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] ); + 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] ); + do0 = so[ 0 ]; + do1 = so[ 1 ] - ( S0*so[0] ); + do2 = so[ 2 ] - ( S1*so[1] ); + do3 = so[ 3 ] - ( S2*so[2] ); + do4 = so[ 4 ] - ( S3*so[3] ); + do5 = so[ 5 ] - ( S4*so[4] ); + do6 = so[ 6 ] - ( S5*so[5] ); + do7 = so[ 7 ] - ( S6*so[6] ); + do8 = so[ 8 ] - ( S7*so[7] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ic = condition.offset; + ix = x.offset; + iy = y.offset; + io = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache accessors: + getc = condition.accessors[ 0 ]; + getx = x.accessors[ 0 ]; + gety = y.accessors[ 0 ]; + seto = out.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++ ) { + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + ic += dc4; + ix += dx4; + iy += dy4; + io += do4; + } + ic += dc5; + ix += dx5; + iy += dy5; + io += do5; + } + ic += dc6; + ix += dx6; + iy += dy6; + io += do6; + } + ic += dc7; + ix += dx7; + iy += dy7; + io += do7; + } + ic += dc8; + ix += dx8; + iy += dy8; + io += do8; + } +} + + +// EXPORTS // + +module.exports = where9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/9d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/9d_blocked.js new file mode 100644 index 000000000000..44a4e5d61e96 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/9d_blocked.js @@ -0,0 +1,494 @@ +/** +* @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-len, max-lines */ + +'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 condition to two nine-dimensional input ndarrays according to a nine-dimensional boolean ndarray and assigns results to elements in a nine-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* +* // Create data buffers: +* var cbuf = new Uint8Array( [ 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1 ] ); +* 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, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] ); +* var obuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sc = [ 12, 12, 12, 12, 12, 12, 4, 4, 1 ]; +* var sx = [ 12, 12, 12, 12, 12, 12, 4, 4, 1 ]; +* var sy = [ 12, 12, 12, 12, 12, 12, 4, 4, 1 ]; +* var so = [ 6, 6, 6, 6, 6, 6, 2, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 1; +* var ox = 1; +* var oy = 1; +* var oo = 0; +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'uint8', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major' +* }; +* 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 out = { +* 'dtype': 'float64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major' +* }; +* +* // Apply the condition: +* blockedwhere9d( condition, x, y, out ); +* +* console.log( out.data ); +* // => [ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ] +*/ +function blockedwhere9d( condition, x, y, out ) { // eslint-disable-line max-statements, max-lines-per-function + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var dc0; + var dc1; + var dc2; + var dc3; + var dc4; + var dc5; + var dc6; + var dc7; + var dc8; + 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 do0; + var do1; + var do2; + var do3; + var do4; + var do5; + var do6; + var do7; + var do8; + var oc1; + var oc2; + var oc3; + var oc4; + var oc5; + var oc6; + var oc7; + var oc8; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var ox6; + var ox7; + var ox8; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oy6; + var oy7; + var oy8; + var oo1; + var oo2; + var oo3; + var oo4; + var oo5; + var oo6; + var oo7; + var oo8; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var s8; + var sc; + var sx; + var sy; + var so; + var oc; + var ox; + var oy; + var oo; + var ic; + var ix; + var iy; + var io; + 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#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( condition.shape, condition.strides, x.strides, y.strides, out.strides ); + + // Strides output as follows: sx, sy, sz, sw. According to arguments order respectively.. + sh = o.sh; + sc = o.sx; + sx = o.sy; + sy = o.sz; + so = o.sw; + + // Determine the block size: + bsize = blockSize( condition.dtype, x.dtype, y.dtype, out.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + oc = condition.offset; + ox = x.offset; + oy = y.offset; + oo = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache offset increments for the innermost loop... + dc0 = sc[0]; + dx0 = sx[0]; + dy0 = sy[0]; + do0 = so[0]; + + // Iterate over blocks... + for ( j8 = sh[8]; j8 > 0; ) { + if ( j8 < bsize ) { + s8 = j8; + j8 = 0; + } else { + s8 = bsize; + j8 -= bsize; + } + oc8 = oc + ( j8*sc[8] ); + ox8 = ox + ( j8*sx[8] ); + oy8 = oy + ( j8*sy[8] ); + oo8 = oo + ( j8*so[8] ); + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + dc8 = sc[8] - ( s7*sc[7] ); + dx8 = sx[8] - ( s7*sx[7] ); + dy8 = sy[8] - ( s7*sy[7] ); + do8 = so[8] - ( s7*so[7] ); + oc7 = oc8 + ( j7*sc[7] ); + ox7 = ox8 + ( j7*sx[7] ); + oy7 = oy8 + ( j7*sy[7] ); + oo7 = oo8 + ( j7*so[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + dc7 = sc[7] - ( s6*sc[6] ); + dx7 = sx[7] - ( s6*sx[6] ); + dy7 = sy[7] - ( s6*sy[6] ); + do7 = so[7] - ( s6*so[6] ); + oc6 = oc7 + ( j6*sc[6] ); + ox6 = ox7 + ( j6*sx[6] ); + oy6 = oy7 + ( j6*sy[6] ); + oo6 = oo7 + ( j6*so[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dc6 = sc[6] - ( s5*sc[5] ); + dx6 = sx[6] - ( s5*sx[5] ); + dy6 = sy[6] - ( s5*sy[5] ); + do6 = so[6] - ( s5*so[5] ); + oc5 = oc6 + ( j5*sc[5] ); + ox5 = ox6 + ( j5*sx[5] ); + oy5 = oy6 + ( j5*sy[5] ); + oo5 = oo6 + ( j5*so[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dc5 = sc[5] - ( s4*sc[4] ); + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + do5 = so[5] - ( s4*so[4] ); + oc4 = oc5 + ( j4*sc[4] ); + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oo4 = oo5 + ( j4*so[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dc4 = sc[4] - ( s3*sc[3] ); + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + do4 = so[4] - ( s3*so[3] ); + oc3 = oc4 + ( j3*sc[3] ); + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oo3 = oo4 + ( j3*so[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dc3 = sc[3] - ( s2*sc[2] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + do3 = so[3] - ( s2*so[2] ); + oc2 = oc3 + ( j2*sc[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oo2 = oo3 + ( j2*so[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dc2 = sc[2] - ( s1*sc[1] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + do2 = so[2] - ( s1*so[1] ); + oc1 = oc2 + ( j1*sc[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oo1 = oo2 + ( j1*so[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... + ic = oc1 + ( j0*sc[0] ); + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + io = oo1 + ( j0*so[0] ); + + // Compute loop offset increments... + dc1 = sc[1] - ( s0*sc[0] ); + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + do1 = so[1] - ( s0*so[0] ); + + // Iterate over the ndarray dimensions... + for ( i8 = 0; i8 < s8; i8++ ) { + for ( i7 = 0; i7 < s7; i7++ ) { + for ( i6 = 0; i6 < s6; i6++ ) { + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + ic += dc4; + ix += dx4; + iy += dy4; + io += do4; + } + ic += dc5; + ix += dx5; + iy += dy5; + io += do5; + } + ic += dc6; + ix += dx6; + iy += dy6; + io += do6; + } + ic += dc7; + ix += dx7; + iy += dy7; + io += do7; + } + ic += dc8; + ix += dx8; + iy += dy8; + io += do8; + } + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhere9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/9d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/9d_blocked_accessors.js new file mode 100644 index 000000000000..93ccb9cafcc4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/9d_blocked_accessors.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-len, max-lines */ + +'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 condition to two nine-dimensional input ndarrays according to a nine-dimensional boolean ndarray and assigns results to elements in a nine-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} condition.accessors - data buffer accessors +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} out.accessors - data buffer accessors +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var BooleanArray = require( '@stdlib/array/bool' ) +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var cbuf = new BooleanArray( [ 1, 0, 0, 1, 0, 1, 1, 0 ] ); +* var xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = new Complex64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 ] ); +* var obuf = new Complex64Array( 4 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sc = [ 4, 4, 4, 4, 4, 4, 4, 2, 1 ]; +* var sx = [ 4, 4, 4, 4, 4, 4, 4, 2, 1 ]; +* var sy = [ 4, 4, 4, 4, 4, 4, 4, 2, 1 ]; +* var so = [ 4, 4, 4, 4, 4, 4, 4, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 0; +* var oy = 0; +* var oo = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'bool', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var out = { +* 'dtype': 'complex64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the condition: +* blockedwhere9d( condition, x, y, out ); +* +* var v = out.data.get( 0 ); +* +* var re = realf( v ); +* // returns 1.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function blockedwhere9d( condition, x, y, out ) { // eslint-disable-line max-statements, max-lines-per-function + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var getc; + var getx; + var gety; + var seto; + var dc0; + var dc1; + var dc2; + var dc3; + var dc4; + var dc5; + var dc6; + var dc7; + var dc8; + 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 do0; + var do1; + var do2; + var do3; + var do4; + var do5; + var do6; + var do7; + var do8; + var oc1; + var oc2; + var oc3; + var oc4; + var oc5; + var oc6; + var oc7; + var oc8; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var ox6; + var ox7; + var ox8; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oy6; + var oy7; + var oy8; + var oo1; + var oo2; + var oo3; + var oo4; + var oo5; + var oo6; + var oo7; + var oo8; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var s8; + var sc; + var sx; + var sy; + var so; + var oc; + var ox; + var oy; + var oo; + var ic; + var ix; + var iy; + var io; + 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#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( condition.shape, condition.strides, x.strides, y.strides, out.strides ); + + // Strides output as follows: sx, sy, sz, sw. According to arguments order respectively.. + sh = o.sh; + sc = o.sx; + sx = o.sy; + sy = o.sz; + so = o.sw; + + // Determine the block size: + bsize = blockSize( condition.dtype, x.dtype, y.dtype, out.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + oc = condition.offset; + ox = x.offset; + oy = y.offset; + oo = out.offset; + + // Cache references to the input and output ndarray buffers... + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache offset increments for the innermost loop... + dc0 = sc[0]; + dx0 = sx[0]; + dy0 = sy[0]; + do0 = so[0]; + + // Cache accessors: + getc = condition.accessors[0]; + getx = x.accessors[0]; + gety = y.accessors[0]; + seto = out.accessors[1]; + + // Iterate over blocks... + for ( j8 = sh[8]; j8 > 0; ) { + if ( j8 < bsize ) { + s8 = j8; + j8 = 0; + } else { + s8 = bsize; + j8 -= bsize; + } + oc8 = oc + ( j8*sc[8] ); + ox8 = ox + ( j8*sx[8] ); + oy8 = oy + ( j8*sy[8] ); + oo8 = oo + ( j8*so[8] ); + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + dc8 = sc[8] - ( s7*sc[7] ); + dx8 = sx[8] - ( s7*sx[7] ); + dy8 = sy[8] - ( s7*sy[7] ); + do8 = so[8] - ( s7*so[7] ); + oc7 = oc8 + ( j7*sc[7] ); + ox7 = ox8 + ( j7*sx[7] ); + oy7 = oy8 + ( j7*sy[7] ); + oo7 = oo8 + ( j7*so[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + dc7 = sc[7] - ( s6*sc[6] ); + dx7 = sx[7] - ( s6*sx[6] ); + dy7 = sy[7] - ( s6*sy[6] ); + do7 = so[7] - ( s6*so[6] ); + oc6 = oc7 + ( j6*sc[6] ); + ox6 = ox7 + ( j6*sx[6] ); + oy6 = oy7 + ( j6*sy[6] ); + oo6 = oo7 + ( j6*so[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dc6 = sc[6] - ( s5*sc[5] ); + dx6 = sx[6] - ( s5*sx[5] ); + dy6 = sy[6] - ( s5*sy[5] ); + do6 = so[6] - ( s5*so[5] ); + oc5 = oc6 + ( j5*sc[5] ); + ox5 = ox6 + ( j5*sx[5] ); + oy5 = oy6 + ( j5*sy[5] ); + oo5 = oo6 + ( j5*so[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dc5 = sc[5] - ( s4*sc[4] ); + dx5 = sx[5] - ( s4*sx[4] ); + dy5 = sy[5] - ( s4*sy[4] ); + do5 = so[5] - ( s4*so[4] ); + oc4 = oc5 + ( j4*sc[4] ); + ox4 = ox5 + ( j4*sx[4] ); + oy4 = oy5 + ( j4*sy[4] ); + oo4 = oo5 + ( j4*so[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dc4 = sc[4] - ( s3*sc[3] ); + dx4 = sx[4] - ( s3*sx[3] ); + dy4 = sy[4] - ( s3*sy[3] ); + do4 = so[4] - ( s3*so[3] ); + oc3 = oc4 + ( j3*sc[3] ); + ox3 = ox4 + ( j3*sx[3] ); + oy3 = oy4 + ( j3*sy[3] ); + oo3 = oo4 + ( j3*so[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dc3 = sc[3] - ( s2*sc[2] ); + dx3 = sx[3] - ( s2*sx[2] ); + dy3 = sy[3] - ( s2*sy[2] ); + do3 = so[3] - ( s2*so[2] ); + oc2 = oc3 + ( j2*sc[2] ); + ox2 = ox3 + ( j2*sx[2] ); + oy2 = oy3 + ( j2*sy[2] ); + oo2 = oo3 + ( j2*so[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dc2 = sc[2] - ( s1*sc[1] ); + dx2 = sx[2] - ( s1*sx[1] ); + dy2 = sy[2] - ( s1*sy[1] ); + do2 = so[2] - ( s1*so[1] ); + oc1 = oc2 + ( j1*sc[1] ); + ox1 = ox2 + ( j1*sx[1] ); + oy1 = oy2 + ( j1*sy[1] ); + oo1 = oo2 + ( j1*so[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... + ic = oc1 + ( j0*sc[0] ); + ix = ox1 + ( j0*sx[0] ); + iy = oy1 + ( j0*sy[0] ); + io = oo1 + ( j0*so[0] ); + + // Compute loop offset increments... + dc1 = sc[1] - ( s0*sc[0] ); + dx1 = sx[1] - ( s0*sx[0] ); + dy1 = sy[1] - ( s0*sy[0] ); + do1 = so[1] - ( s0*so[0] ); + + // Iterate over the ndarray dimensions... + for ( i8 = 0; i8 < s8; i8++ ) { + for ( i7 = 0; i7 < s7; i7++ ) { + for ( i6 = 0; i6 < s6; i6++ ) { + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + ic += dc2; + ix += dx2; + iy += dy2; + io += do2; + } + ic += dc3; + ix += dx3; + iy += dy3; + io += do3; + } + ic += dc4; + ix += dx4; + iy += dy4; + io += do4; + } + ic += dc5; + ix += dx5; + iy += dy5; + io += do5; + } + ic += dc6; + ix += dx6; + iy += dy6; + io += do6; + } + ic += dc7; + ix += dx7; + iy += dy7; + io += do7; + } + ic += dc8; + ix += dx8; + iy += dy8; + io += do8; + } + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhere9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/index.js new file mode 100644 index 000000000000..986d7ebdc4f8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/index.js @@ -0,0 +1,100 @@ +/** +* @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 condition to elements in two input ndarrays and assign results to elements in an output ndarray. +* +* @module @stdlib/ndarray/base/where +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* var where = require( '@stdlib/ndarray/base/where' ); +* +* // Create data buffers: +* var cbuf = new Uint8Array( [ 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1 ] ); +* 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, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] ); +* var obuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sc = [ 4, 4, 1 ]; +* var sx = [ 4, 4, 1 ]; +* var sy = [ 4, 4, 1 ]; +* var so = [ 2, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 1; +* var ox = 1; +* var oy = 1; +* var oo = 0; +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'uint8', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major' +* }; +* 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 out = { +* 'dtype': 'float64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major' +* }; +* +* // Apply the condition: +* where( [ condition, x, y, out ] ); +* +* console.log( out.data ); +* // => [ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js new file mode 100644 index 000000000000..b51583c4cc38 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js @@ -0,0 +1,534 @@ +/** +* @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-lines */ + +'use strict'; + +// MODULES // + +var format = require( '@stdlib/string/format' ); +var isComplexDataType = require( '@stdlib/ndarray/base/assert/is-complex-floating-point-data-type' ); +var isRealDataType = require( '@stdlib/ndarray/base/assert/is-real-data-type' ); +var isComplexArray = require( '@stdlib/array/base/assert/is-complex-typed-array' ); +var isBooleanArray = require( '@stdlib/array/base/assert/is-booleanarray' ); +var isUint8Array = require( '@stdlib/assert/is-uint8array' ); +var iterationOrder = require( '@stdlib/ndarray/base/iteration-order' ); +var strides2order = require( '@stdlib/ndarray/base/strides2order' ); +var anyIsEntryIn = require( '@stdlib/array/base/any-is-entry-in' ); +var castReturn = require( '@stdlib/complex/base/cast-return' ); +var complexCtors = require( '@stdlib/complex/ctors' ); +var minmaxViewBufferIndex = require( '@stdlib/ndarray/base/minmax-view-buffer-index' ); +var ndarray2object = require( '@stdlib/ndarray/base/ndarraylike2object' ); +var reinterpretComplex = require( '@stdlib/strided/base/reinterpret-complex' ); +var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' ); +var gscal = require( '@stdlib/blas/base/gscal' ); +var blockedaccessorwhere2d = require( './2d_blocked_accessors.js' ); +var blockedaccessorwhere3d = require( './3d_blocked_accessors.js' ); +var blockedaccessorwhere4d = require( './4d_blocked_accessors.js' ); +var blockedaccessorwhere5d = require( './5d_blocked_accessors.js' ); +var blockedaccessorwhere6d = require( './6d_blocked_accessors.js' ); +var blockedaccessorwhere7d = require( './7d_blocked_accessors.js' ); +var blockedaccessorwhere8d = require( './8d_blocked_accessors.js' ); +var blockedaccessorwhere9d = require( './9d_blocked_accessors.js' ); +var blockedaccessorwhere10d = require( './10d_blocked_accessors.js' ); +var blockedwhere2d = require( './2d_blocked.js' ); +var blockedwhere3d = require( './3d_blocked.js' ); +var blockedwhere4d = require( './4d_blocked.js' ); +var blockedwhere5d = require( './5d_blocked.js' ); +var blockedwhere6d = require( './6d_blocked.js' ); +var blockedwhere7d = require( './7d_blocked.js' ); +var blockedwhere8d = require( './8d_blocked.js' ); +var blockedwhere9d = require( './9d_blocked.js' ); +var blockedwhere10d = require( './10d_blocked.js' ); +var accessorwhere0d = require( './0d_accessors.js' ); +var accessorwhere1d = require( './1d_accessors.js' ); +var accessorwhere2d = require( './2d_accessors.js' ); +var accessorwhere3d = require( './3d_accessors.js' ); +var accessorwhere4d = require( './4d_accessors.js' ); +var accessorwhere5d = require( './5d_accessors.js' ); +var accessorwhere6d = require( './6d_accessors.js' ); +var accessorwhere7d = require( './7d_accessors.js' ); +var accessorwhere8d = require( './8d_accessors.js' ); +var accessorwhere9d = require( './9d_accessors.js' ); +var accessorwhere10d = require( './10d_accessors.js' ); +var accessorwherend = require( './nd_accessors.js' ); +var where0d = require( './0d.js' ); +var where1d = require( './1d.js' ); +var where2d = require( './2d.js' ); +var where3d = require( './3d.js' ); +var where4d = require( './4d.js' ); +var where5d = require( './5d.js' ); +var where6d = require( './6d.js' ); +var where7d = require( './7d.js' ); +var where8d = require( './8d.js' ); +var where9d = require( './9d.js' ); +var where10d = require( './10d.js' ); +var wherend = require( './nd.js' ); + + +// VARIABLES // + +var WHERE = [ + where0d, + where1d, + where2d, + where3d, + where4d, + where5d, + where6d, + where7d, + where8d, + where9d, + where10d +]; +var ACCESSOR_WHERE = [ + accessorwhere0d, + accessorwhere1d, + accessorwhere2d, + accessorwhere3d, + accessorwhere4d, + accessorwhere5d, + accessorwhere6d, + accessorwhere7d, + accessorwhere8d, + accessorwhere9d, + accessorwhere10d +]; +var BLOCKED_WHERE = [ + blockedwhere2d, // 0 + blockedwhere3d, + blockedwhere4d, + blockedwhere5d, + blockedwhere6d, + blockedwhere7d, + blockedwhere8d, + blockedwhere9d, + blockedwhere10d // 8 +]; +var BLOCKED_ACCESSOR_WHERE = [ + blockedaccessorwhere2d, // 0 + blockedaccessorwhere3d, + blockedaccessorwhere4d, + blockedaccessorwhere5d, + blockedaccessorwhere6d, + blockedaccessorwhere7d, + blockedaccessorwhere8d, + blockedaccessorwhere9d, + blockedaccessorwhere10d // 8 +]; +var MAX_DIMS = WHERE.length - 1; + +// TODO: consider adding a package utility for mapping a complex dtype to its complementary real-valued counterpart +var COMPLEX_TO_REAL = { // WARNING: this table needs to be manually updated if we add support for additional complex number dtypes + 'complex128': 'float64', + 'complex64': 'float32', + 'complex32': 'float16' +}; + + +// 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 ); +} + +/** +* Converts a boolean ndarray to an 8-bit unsigned integer ndarray. +* +* ## Notes +* +* - The function mutates the input ndarray object. +* +* @private +* @param {Object} x - input ndarray object +* @returns {Object} output ndarray object +*/ +function boolean2uint8( x ) { + x.data = reinterpretBoolean( x.data, 0 ); + x.accessorProtocol = false; + return x; +} + +/** +* Converts a complex-valued floating-point ndarray to a real-valued floating-point ndarray. +* +* ## Notes +* +* - The function mutates the input ndarray object. +* +* @private +* @param {Object} x - input ndarray object +* @returns {Object} output ndarray object +*/ +function complex2real( x ) { + var ndims = x.shape.length; + + x.data = reinterpretComplex( x.data, 0 ); + x.accessorProtocol = false; + x.dtype = COMPLEX_TO_REAL[ String( x.dtype ) ]; + x.strides = gscal( ndims, 2, x.strides, 1 ); + x.offset *= 2; + + // Append a trailing dimension where each element is the real and imaginary component for a corresponding element in the original input ndarray (note: this means that a two-dimensional complex-valued ndarray becomes a three-dimensional real-valued ndarray; while this does entail additional loop overhead, it is still significantly faster than sending complex-valued ndarrays down the accessor path): + x.shape.push( 2 ); // real and imaginary components + + // Augment the strides, where we assume that real and imaginary components are adjacent in memory... + if ( ndims === 0 ) { + x.strides[ 0 ] = 1; + } else { + x.strides.push( 1 ); + } + return x; +} + + +// MAIN // + +/** +* Applies a condition to elements in two 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 one condition array, two input arrays, and one output array +* @throws {Error} arrays must have the same number of dimensions +* @throws {Error} arrays must have the same shape +* @throws {TypeError} condition array must be a boolean or uint8 ndarray +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* +* // Create data buffers: +* var cbuf = new Uint8Array( [ 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1 ] ); +* 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, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] ); +* var obuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sc = [ 4, 4, 1 ]; +* var sx = [ 4, 4, 1 ]; +* var sy = [ 4, 4, 1 ]; +* var so = [ 2, 2, 1 ]; +* +* // Define the index offsets: +* var oc = 1; +* var ox = 1; +* var oy = 1; +* var oo = 0; +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'uint8', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major' +* }; +* 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 out = { +* 'dtype': 'float64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major' +* }; +* +* // Apply the condition: +* where( [ condition, x, y, out ] ); +* +* console.log( out.data ); +* // => [ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ] +*/ +function where( arrays ) { // eslint-disable-line max-statements + var ndims; + var cmmv; + var xmmv; + var ymmv; + var ommv; + var shc; + var shx; + var shy; + var sho; + var ioc; + var iox; + var ioy; + var ioo; + var len; + var ord; + var sc; + var sx; + var sy; + var so; + var oc; + var ox; + var oy; + var oo; + var ns; + var c; + var x; + var y; + var o; + var d; + var i; + + // Unpack the ndarrays and standardize ndarray meta data: + c = ndarray2object( arrays[ 0 ] ); + x = ndarray2object( arrays[ 1 ] ); + y = ndarray2object( arrays[ 2 ] ); + o = ndarray2object( arrays[ 3 ] ); + + // Verify that the input and output arrays have the same number of dimensions... + shc = c.shape; + shx = x.shape; + shy = y.shape; + sho = o.shape; + ndims = shc.length; + if ( ndims !== shx.length || ndims !== shy.length || ndims !== sho.length ) { // eslint-disable-line max-len + throw new Error( format( 'invalid arguments. Arrays must have the same number of dimensions (i.e., same rank). ndims(c) == %d. ndims(x) == %d. ndims(y) == %d. ndims(o) == %d.', shc.length, shx.length, shy.length, sho.length ) ); + } + + if ( !isBooleanArray( c.data ) && !isUint8Array( c.data ) ) { + throw new TypeError( format( 'invalid arguments. Condition array must be a boolean or uint8 ndarray. c.dtype=%s', c.dtype ) ); + } + + // Check for known array types which can be reinterpreted for better iteration performance... + if ( isBooleanArray( x.data ) && isBooleanArray( y.data ) && isBooleanArray( o.data ) ) { // eslint-disable-line max-len + x = boolean2uint8( x ); + y = boolean2uint8( y ); + o = boolean2uint8( o ); + + if ( isBooleanArray( c.data ) ) { + c = boolean2uint8( c ); + } + } else if ( isComplexArray( x.data ) && isComplexArray( y.data ) && isComplexArray( o.data ) ) { // eslint-disable-line max-len + x = complex2real( x ); + y = complex2real( y ); + o = complex2real( o ); + + c.shape.push( 2 ); // real and imaginary components + c.strides.push( 0 ); // broadcast + + if ( isBooleanArray( c.data ) ) { + c = boolean2uint8( c ); + } + } + // Determine whether we are casting a real data type to a complex data type and we need to use a specialized accessor (note: we don't support the other way, complex-to-real, as this is not an allowed (mostly) safe cast; note: we cannot create a specialized view for assigning only real components, as the imaginary component for each element in `y` also needs to be set to zero and while we could perform two passes, it's not clear it's worth the effort)... + else if ( isComplexDataType( o.dtype ) ) { + if ( isRealDataType( x.dtype ) ) { + x.accessorProtocol = true; + x.accessors[ 0 ] = castReturn( x.accessors[ 0 ], 2, complexCtors( String( o.dtype ) ) ); // eslint-disable-line max-len + } + if ( isRealDataType( y.dtype ) ) { + y.accessorProtocol = true; + y.accessors[ 0 ] = castReturn( y.accessors[ 0 ], 2, complexCtors( String( o.dtype ) ) ); // eslint-disable-line max-len + } + } + + shc = c.shape; + shx = x.shape; + shy = y.shape; + sho = o.shape; + ndims = shc.length; + + // Determine whether we can avoid iteration altogether... + if ( ndims === 0 ) { + if ( hasAccessors( c, x, y, o ) ) { + return ACCESSOR_WHERE[ ndims ]( c, x, y, o ); + } + return WHERE[ ndims ]( c, x, y, o ); + } + // 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 = shc[ i ]; + if ( d !== shx[ i ] || d !== shy[ i ] || d !== sho[ 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( c, x, y, o ) ) { + return ACCESSOR_WHERE[ ndims ]( c, x, y, o ); + } + return WHERE[ ndims ]( c, x, y, o ); + } + sc = c.strides; + sx = x.strides; + sy = y.strides; + so = o.strides; + + // Determine whether the ndarray has 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 ( shc[ i ] !== 1 ) { + break; + } + } + c.shape = [ shc[i] ]; + x.shape = c.shape; + y.shape = c.shape; + o.shape = c.shape; + c.strides = [ sc[i] ]; + x.strides = [ sx[i] ]; + y.strides = [ sy[i] ]; + o.strides = [ so[i] ]; + if ( hasAccessors( c, x, y, o ) ) { + return ACCESSOR_WHERE[ 1 ]( c, x, y, o ); + } + return WHERE[ 1 ]( c, x, y, o ); + } + ioc = iterationOrder( sc ); // +/-1 + iox = iterationOrder( sx ); // +/-1 + ioy = iterationOrder( sy ); // +/-1 + ioo = iterationOrder( so ); // +/-1 + + // Determine whether we can avoid blocked iteration... + ord = strides2order( sc ); + if ( ioc !== 0 && iox !== 0 && ioy !== 0 && ioo !== 0 && ord === strides2order( sx ) && ord === strides2order( sy ) && ord === strides2order( so ) ) { // eslint-disable-line max-len + // Determine the minimum and maximum linear indices which are accessible by the array views: + cmmv = minmaxViewBufferIndex( shc, sc, c.offset ); + xmmv = minmaxViewBufferIndex( shx, sx, x.offset ); + ymmv = minmaxViewBufferIndex( shy, sy, y.offset ); + ommv = minmaxViewBufferIndex( sho, so, o.offset ); + + // Determine whether we can ignore shape (and strides) and treat the ndarrays as linear one-dimensional strided arrays... + if ( len === ( cmmv[1]-cmmv[0]+1 ) && len === ( xmmv[1]-xmmv[0]+1 ) && len === ( ymmv[1]-ymmv[0]+1 ) && len === ( ommv[1]-ommv[0]+1 ) ) { // eslint-disable-line max-len + // Note: the above is equivalent to @stdlib/ndarray/base/assert/is-contiguous, but in-lined so we can retain computed values... + if ( ioc === 1 ) { + oc = cmmv[ 0 ]; + } else { + oc = cmmv[ 1 ]; + } + if ( iox === 1 ) { + ox = xmmv[ 0 ]; + } else { + ox = xmmv[ 1 ]; + } + if ( ioy === 1 ) { + oy = ymmv[ 0 ]; + } else { + oy = ymmv[ 1 ]; + } + if ( ioo === 1 ) { + oo = ommv[ 0 ]; + } else { + oo = ommv[ 1 ]; + } + c.shape = [ len ]; + x.shape = c.shape; + y.shape = c.shape; + o.shape = c.shape; + c.strides = [ ioc ]; + x.strides = [ iox ]; + y.strides = [ ioy ]; + o.strides = [ ioo ]; + c.offset = oc; + x.offset = ox; + y.offset = oy; + o.offset = oo; + if ( hasAccessors( c, x, y, o ) ) { + return ACCESSOR_WHERE[ 1 ]( c, x, y, o ); + } + return WHERE[ 1 ]( c, x, y, o ); + } + // 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( c, x, y, o ) ) { + return ACCESSOR_WHERE[ ndims ]( c, x, y, o, ord === 1 ); + } + return WHERE[ ndims ]( c, x, y, o, ord === 1 ); + } + // 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( c, x, y, o ) ) { + return BLOCKED_ACCESSOR_WHERE[ ndims-2 ]( c, x, y, o ); + } + return BLOCKED_WHERE[ ndims-2 ]( c, x, y, o ); + } + // Fall-through to linear view iteration without regard for how data is stored in memory (i.e., take the slow path)... + if ( hasAccessors( c, x, y, o ) ) { + return accessorwherend( c, x, y, o ); + } + wherend( c, x, y, o ); +} + + +// EXPORTS // + +module.exports = where; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/nd.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/nd.js new file mode 100644 index 000000000000..f0316088fd9f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/nd.js @@ -0,0 +1,195 @@ +/** +* @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 condition to two n-dimensional input ndarrays according to a n-dimensional boolean ndarray and assigns results to elements in a n-dimensional output ndarray. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* +* // Create data buffers: +* var cbuf = new Uint8Array( [ 1, 0, 0, 1, 0, 1, 1, 0 ] ); +* 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, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 ] ); +* var obuf = new Float64Array( 4 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 2, 2 ]; +* +* // Define the array strides: +* var sc = [ 4, 1 ]; +* var sx = [ 4, 1 ]; +* var sy = [ 4, 1 ]; +* var so = [ 2, 1 ]; +* +* // Define the index offsets: +* var oc = 1; +* var ox = 1; +* var oy = 1; +* var oo = 0; +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'uint8', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major' +* }; +* 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 out = { +* 'dtype': 'float64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major' +* }; +* +* // Apply condition: +* wherend( condition, x, y, out ); +* +* console.log( out.data ); +* // => [ -2.0, -3.0, 6.0, 7.0 ] +*/ +function wherend( condition, x, y, out ) { + var cbuf; + var xbuf; + var ybuf; + var obuf; + var ordc; + var ordx; + var ordy; + var ordo; + var len; + var sh; + var sc; + var sx; + var sy; + var so; + var oc; + var ox; + var oy; + var oo; + var ic; + var ix; + var iy; + var io; + var i; + + sh = condition.shape; + + // Compute the total number of elements over which to iterate: + len = numel( sh ); + + // Cache references to the input and output ndarray data buffers: + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache references to the respective stride arrays: + sc = condition.strides; + sx = x.strides; + sy = y.strides; + so = out.strides; + + // Cache the indices of the first indexed elements in the respective ndarrays: + oc = condition.offset; + ox = x.offset; + oy = y.offset; + oo = out.offset; + + // Cache the respective array orders: + ordc = condition.order; + ordx = x.order; + ordy = y.order; + ordo = out.order; + + // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory... + for ( i = 0; i < len; i++ ) { + ic = vind2bind( sh, sc, oc, ordc, i, 'throw' ); + ix = vind2bind( sh, sx, ox, ordx, i, 'throw' ); + iy = vind2bind( sh, sy, oy, ordy, i, 'throw' ); + io = vind2bind( sh, so, oo, ordo, i, 'throw' ); + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; + } +} + + +// EXPORTS // + +module.exports = wherend; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/nd_accessors.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/nd_accessors.js new file mode 100644 index 000000000000..dec10b812ed8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/nd_accessors.js @@ -0,0 +1,235 @@ +/** +* @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' ); + + +// VARIABLES // + +var MODE = 'throw'; + + +// MAIN // + +/** +* Applies a condition to two n-dimensional input ndarrays according to a n-dimensional boolean ndarray and assigns results to elements in a n-dimensional output ndarray. +* +* @private +* @param {Object} condition - object containing boolean condition ndarray meta data +* @param {*} condition.dtype - data type +* @param {Collection} condition.data - data buffer +* @param {NonNegativeIntegerArray} condition.shape - dimensions +* @param {IntegerArray} condition.strides - stride lengths +* @param {NonNegativeInteger} condition.offset - index offset +* @param {string} condition.order - specifies whether `condition` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} condition.accessors - data buffer accessors +* @param {Object} x - object containing first 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 second 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} out - object containing output ndarray meta data +* @param {*} out.dtype - data type +* @param {Collection} out.data - data buffer +* @param {NonNegativeIntegerArray} out.shape - dimensions +* @param {IntegerArray} out.strides - stride lengths +* @param {NonNegativeInteger} out.offset - index offset +* @param {string} out.order - specifies whether `out` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} out.accessors - data buffer accessors +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var BooleanArray = require( '@stdlib/array/bool' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var cbuf = new BooleanArray( [ 1, 0, 0, 1, 0, 1, 1, 0 ] ); +* var xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = new Complex64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 ] ); +* var obuf = new Complex64Array( 4 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 2, 2 ]; +* +* // Define the array strides: +* var sc = [ 2, 1 ]; +* var sx = [ 2, 1 ]; +* var sy = [ 2, 1 ]; +* var so = [ 2, 1 ]; +* +* // Define the index offsets: +* var oc = 0; +* var ox = 0; +* var oy = 0; +* var oo = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var condition = { +* 'dtype': 'bool', +* 'data': cbuf, +* 'shape': shape, +* 'strides': sc, +* 'offset': oc, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var out = { +* 'dtype': 'complex64', +* 'data': obuf, +* 'shape': shape, +* 'strides': so, +* 'offset': oo, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply condition: +* wherend( condition, x, y, out ); +* +* var v = out.data.get( 0 ); +* +* var re = realf( v ); +* // returns 1.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function wherend( condition, x, y, out ) { + var cbuf; + var xbuf; + var ybuf; + var getc; + var getx; + var gety; + var seto; + var obuf; + var ordc; + var ordx; + var ordy; + var ordo; + var len; + var sh; + var sc; + var sx; + var sy; + var so; + var oc; + var ox; + var oy; + var oo; + var ic; + var ix; + var iy; + var io; + var i; + + sh = condition.shape; + + // Compute the total number of elements over which to iterate: + len = numel( sh ); + + // Cache references to the input and output ndarray data buffers: + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache references to the respective stride arrays: + sc = condition.strides; + sx = x.strides; + sy = y.strides; + so = out.strides; + + // Cache the indices of the first indexed elements in the respective ndarrays: + oc = condition.offset; + ox = x.offset; + oy = y.offset; + oo = out.offset; + + // Cache the respective array orders: + ordc = condition.order; + ordx = x.order; + ordy = y.order; + ordo = out.order; + + // Cache accessors: + getc = condition.accessors[ 0 ]; + getx = x.accessors[ 0 ]; + gety = y.accessors[ 0 ]; + seto = out.accessors[ 1 ]; + + // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory... + for ( i = 0; i < len; i++ ) { + ic = vind2bind( sh, sc, oc, ordc, i, MODE ); + ix = vind2bind( sh, sx, ox, ordx, i, MODE ); + iy = vind2bind( sh, sy, oy, ordy, i, MODE ); + io = vind2bind( sh, so, oo, ordo, i, MODE ); + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len + } +} + + +// EXPORTS // + +module.exports = wherend; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/package.json b/lib/node_modules/@stdlib/ndarray/base/where/package.json new file mode 100644 index 000000000000..68798c41732d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/package.json @@ -0,0 +1,61 @@ +{ + "name": "@stdlib/ndarray/base/where", + "version": "0.0.0", + "description": "Apply a condition to elements in two 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", + "where", + "copy" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ndarray/base/where/test/test.0d.js b/lib/node_modules/@stdlib/ndarray/base/where/test/test.0d.js new file mode 100644 index 000000000000..9ba478752cec --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/test/test.0d.js @@ -0,0 +1,86 @@ +/** +* @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 isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var isSameAccessorArray = require( '@stdlib/assert/is-same-accessor-array' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var where = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof where, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function assigns elements from a 0-dimensional input ndarray to an output ndarray', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = scalar2ndarray( 0, { + 'dtype': 'uint8' + }); + x = scalar2ndarray( 10.0, { + 'dtype': 'float64' + }); + y = scalar2ndarray( -10.0, { + 'dtype': 'float64' + }); + out = scalar2ndarray( 0.0, { + 'dtype': 'float64' + }); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array( [ -10.0 ] ); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns elements from a 0-dimensional input ndarray to an output ndarray (accessors)', function test( t ) { + var condition; + var out; + var x; + var y; + + condition = ndarray( 'uint8', new Uint8Array( [ 1 ]), [], [ 0 ], 0, 'row-major' ); + x = ndarray( 'generic', toAccessorArray( [ 1.0 ] ), [], [ 0 ], 0, 'row-major' ); + y = ndarray( 'generic', toAccessorArray( [ -1.0 ] ), [], [ 0 ], 0, 'row-major' ); + out = ndarray( 'generic', toAccessorArray( [ 0.0 ] ), [], [ 0 ], 0, 'row-major' ); + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, x.data ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/where/test/test.1d.js b/lib/node_modules/@stdlib/ndarray/base/where/test/test.1d.js new file mode 100644 index 000000000000..7c6424f85b69 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/test/test.1d.js @@ -0,0 +1,204 @@ +/** +* @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 isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var isSameAccessorArray = require( '@stdlib/assert/is-same-accessor-array' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +var zeros = require( '@stdlib/array/zeros' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var where = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof where, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 1-dimensional input ndarray to an output ndarray', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var out; + var x; + var y; + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1, + 0, + 0, + 1, + 0 + ]); + xbuf = new Float64Array([ + 0.0, + 1.0, + 0.0, + 2.0, + 0.0, + 3.0, + 0.0, + 4.0 + ]); + ybuf = new Float64Array([ + 0.0, + -1.0, + 0.0, + -2.0, + 0.0, + -3.0, + 0.0, + -4.0 + ]); + condition = ndarray( 'uint8', cbuf, [ 4 ], [ 2 ], 1, 'row-major' ); + x = ndarray( 'float64', xbuf, [ 4 ], [ 2 ], 1, 'row-major' ); + y = ndarray( 'float64', ybuf, [ 4 ], [ 2 ], 1, 'row-major' ); + out = ndarray( 'float64', zeros( 8, 'float64' ), [ 4 ], [ 2 ], 1, 'row-major' ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 0.0, + -1.0, + 0.0, + 2.0, + 0.0, + -3.0, + 0.0, + -4.0 + ]); + + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 1-dimensional input ndarray to an output ndarray (empty array)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var out; + var x; + var y; + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1, + 0, + 0, + 1, + 0 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 3.0, + 4.0, + 5.0, + 6.0, + 7.0, + 8.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + -3.0, + -4.0, + -5.0, + -6.0, + -7.0, + -8.0 + ]); + condition = ndarray( 'uint8', cbuf, [ 0 ], [ 1 ], 0, 'row-major' ); + x = ndarray( 'float64', xbuf, [ 0 ], [ 1 ], 0, 'row-major' ); + y = ndarray( 'float64', ybuf, [ 0 ], [ 1 ], 0, 'row-major' ); + out = ndarray( 'float64', zeros( 8, 'float64' ), [ 0 ], [ 1 ], 0, 'row-major' ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 1-dimensional input ndarray to an output ndarray (accessors)', function test( t ) { + var condition; + var cbuf; + var xbuf; + var ybuf; + var out; + var x; + var y; + + cbuf = new Uint8Array([ + 0, + 0, + 0, + 0 + ]); + xbuf = [ + 1.0, + 2.0, + 3.0, + 4.0 + ]; + ybuf = [ + -1.0, + -2.0, + -3.0, + -4.0 + ]; + condition = ndarray( 'uint8', cbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + x = ndarray( 'generic', toAccessorArray( xbuf ), [ 4 ], [ 1 ], 0, 'row-major' ); + y = ndarray( 'generic', toAccessorArray( ybuf ), [ 4 ], [ 1 ], 0, 'row-major' ); + out = ndarray( 'generic', toAccessorArray( zeros( 4, 'generic' ) ), [ 4 ], [ 1 ], 0, 'row-major' ); + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, y.data ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/where/test/test.2d.js b/lib/node_modules/@stdlib/ndarray/base/where/test/test.2d.js new file mode 100644 index 000000000000..40aa5b2bdf28 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/test/test.2d.js @@ -0,0 +1,1719 @@ +/** +* @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-lines */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var isSameAccessorArray = require( '@stdlib/assert/is-same-accessor-array' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +var zeros = require( '@stdlib/array/zeros' ); +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 gfill = require( '@stdlib/blas/ext/base/gfill' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var where = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof where, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (row-major, singleton dimensions)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var out; + 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 ); + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + -3.0, + -4.0 + ]); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 1.0, + -2.0, + 3.0, + 4.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (row-major, singleton dimensions, accessors)', function test( t ) { + var condition; + var cbuf; + var xbuf; + var ybuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'row-major'; + sh = [ 4, 1 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 1, + 1, + 1 + ]); + xbuf = [ + 1.0, + 2.0, + 3.0, + 4.0 + ]; + ybuf = [ + -1.0, + -2.0, + -3.0, + -4.0 + ]; + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( zeros( numel( sh ), 'generic' ) ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( x.data, out.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (row-major, empty)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var out; + var x; + var y; + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + -3.0, + -4.0 + ]); + + condition = ndarray( 'uint8', cbuf, [ 0, 0 ], [ 1, 1 ], 0, 'row-major' ); + x = ndarray( 'float64', xbuf, [ 0, 0 ], [ 1, 1 ], 0, 'row-major' ); + y = ndarray( 'float64', ybuf, [ 0, 0 ], [ 1, 1 ], 0, 'row-major' ); + out = ndarray( 'float64', zeros( 4, 'float64' ), [ 0, 0 ], [ 1, 1 ], 0, 'row-major' ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (row-major, contiguous)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var out; + 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 ); + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + -3.0, + -4.0 + ]); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 1.0, + -2.0, + 3.0, + 4.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (row-major, contiguous, negative strides)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var out; + 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 ); + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + -3.0, + -4.0 + ]); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 1.0, + -2.0, + 3.0, + 4.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (row-major, non-contiguous, same sign strides)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + 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 ); + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1, + 0, + 1, + 0, + 0 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 0.0, + 0.0, + 3.0, + 4.0, + 0.0, + 0.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + 0.0, + 0.0, + -3.0, + -4.0, + 0.0, + 0.0 + ]); + obuf = zeros( 8, dt ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, obuf, sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 1.0, + -2.0, + 0.0, + 0.0, + -3.0, + 4.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (row-major, non-contiguous, mixed sign strides)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + 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 ); + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1, + 0, + 1, + 0, + 0 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 0.0, + 0.0, + 3.0, + 4.0, + 0.0, + 0.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + 0.0, + 0.0, + -3.0, + -4.0, + 0.0, + 0.0 + ]); + obuf = zeros( 8, dt ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, obuf, sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 1.0, + -2.0, + 0.0, + 0.0, + -3.0, + 4.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (row-major, non-contiguous, large arrays)', function test( t ) { + var condition; + var expected; + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + 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 ); + + cbuf = new Uint8Array( numel( sh )*2 ); // zeros condition array + xbuf = new Float64Array( numel( sh )*2 ); + dfill( numel( sh ), 1.0, xbuf, st[ 1 ] ); + ybuf = new Float64Array( numel( sh )*2 ); + dfill( numel( sh ), -1.0, ybuf, st[ 1 ] ); + obuf = zeros( numel( sh )*2, dt ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, obuf, sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array( y.length*2 ); + dfill( y.length, -1.0, expected, st[ 1 ] ); + + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (row-major, non-contiguous, large arrays)', function test( t ) { + var condition; + var expected; + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + 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 ); + + cbuf = new Uint8Array( numel( sh )*2 ); // zeros condition array + xbuf = new Float64Array( numel( sh )*2 ); + dfill( numel( sh ), 1.0, xbuf, st[ 1 ] ); + ybuf = new Float64Array( numel( sh )*2 ); + dfill( numel( sh ), -1.0, ybuf, st[ 1 ] ); + obuf = zeros( numel( sh )*2, dt ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, obuf, sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array( y.length*2 ); + dfill( y.length, -1.0, expected, st[ 1 ] ); + + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (row-major, contiguous, accessors)', function test( t ) { + var condition; + var cbuf; + var xbuf; + var ybuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 1, + 1, + 1 + ]); + xbuf = [ + 1.0, + 2.0, + 3.0, + 4.0 + ]; + ybuf = [ + -1.0, + -2.0, + -3.0, + -4.0 + ]; + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( zeros( numel( sh ), 'generic' ) ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, x.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (row-major, contiguous, negative strides, accessors)', function test( t ) { + var condition; + var cbuf; + var xbuf; + var ybuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ -2, -1 ]; + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 1, + 1, + 1 + ]); + xbuf = [ + 1.0, + 2.0, + 3.0, + 4.0 + ]; + ybuf = [ + -1.0, + -2.0, + -3.0, + -4.0 + ]; + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( zeros( numel( sh ), 'generic' ) ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, x.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (row-major, non-contiguous, same sign strides, accessors)', function test( t ) { + var condition; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ 4, 1 ]; + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1 + ]); + xbuf = [ + 1.0, + 2.0, + 0.0, + 0.0, + 3.0, + 4.0, + 0.0, + 0.0 + ]; + ybuf = [ + -1.0, + -2.0, + 0.0, + 0.0, + -3.0, + -4.0, + 0.0, + 0.0 + ]; + obuf = zeros( 8, 'generic' ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( obuf ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, x.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (row-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var condition; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ 4, -1 ]; + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1 + ]); + xbuf = [ + 1.0, + 2.0, + 0.0, + 0.0, + 3.0, + 4.0, + 0.0, + 0.0 + ]; + ybuf = [ + -1.0, + -2.0, + 0.0, + 0.0, + -3.0, + -4.0, + 0.0, + 0.0 + ]; + obuf = zeros( 8, 'generic' ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( obuf ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, x.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var condition; + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'row-major'; + + bsize = blockSize( 'generic' ); + sh = [ bsize*2, 2 ]; + st = [ -4, 2 ]; + o = strides2offset( sh, st ); + + cbuf = zeros( numel( sh )*2, 'uint8' ); // zeros condition array + xbuf = zeros( numel( sh )*2, 'generic' ); + gfill( numel( sh ), 1.0, xbuf, st[ 1 ] ); + ybuf = zeros( numel( sh )*2, 'generic' ); + gfill( numel( sh ), -1.0, ybuf, st[ 1 ] ); + obuf = zeros( numel( sh )*2, 'generic' ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( obuf ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, y.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var condition; + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'row-major'; + + bsize = blockSize( 'generic' ); + sh = [ 2, bsize*2 ]; + st = [ bsize*4, -2 ]; + o = strides2offset( sh, st ); + + cbuf = zeros( numel( sh )*2, 'uint8' ); // zeros condition array + xbuf = zeros( numel( sh )*2, 'generic' ); + gfill( numel( sh ), 1.0, xbuf, st[ 1 ] ); + ybuf = zeros( numel( sh )*2, 'generic' ); + gfill( numel( sh ), -1.0, ybuf, st[ 1 ] ); + obuf = zeros( numel( sh )*2, 'generic' ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( obuf ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, y.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (column-major, singleton dimensions)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var out; + 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 ); + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + -3.0, + -4.0 + ]); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 1.0, + -2.0, + 3.0, + 4.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (column-major, singleton dimensions, accessors)', function test( t ) { + var condition; + var cbuf; + var xbuf; + var ybuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'column-major'; + sh = [ 4, 1 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 1, + 1, + 1 + ]); + xbuf = [ + 1.0, + 2.0, + 3.0, + 4.0 + ]; + ybuf = [ + -1.0, + -2.0, + -3.0, + -4.0 + ]; + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( zeros( numel( sh ), dt ) ), sh, st, o, ord ); // eslint-disable-line max-len + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, x.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (column-major, empty)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var out; + var x; + var y; + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + -3.0, + -4.0 + ]); + + condition = ndarray( 'uint8', cbuf, [ 0, 0 ], [ 1, 1 ], 0, 'column-major' ); + x = ndarray( 'float64', xbuf, [ 0, 0 ], [ 1, 1 ], 0, 'column-major' ); + y = ndarray( 'float64', ybuf, [ 0, 0 ], [ 1, 1 ], 0, 'column-major' ); + out = ndarray( 'float64', zeros( 4, 'float64' ), [ 0, 0 ], [ 1, 1 ], 0, 'column-major' ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (column-major, contiguous)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var out; + 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 ); + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + -3.0, + -4.0 + ]); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 1.0, + -2.0, + 3.0, + 4.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (column-major, contiguous, negative strides)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var out; + 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 ); + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + -3.0, + -4.0 + ]); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 1.0, + -2.0, + 3.0, + 4.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (column-major, non-contiguous, same sign strides)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + 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 ); + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1, + 0, + 1, + 0, + 0 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 0.0, + 0.0, + 3.0, + 4.0, + 0.0, + 0.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + 0.0, + 0.0, + -3.0, + -4.0, + 0.0, + 0.0 + ]); + obuf = zeros( 8, dt ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, obuf, sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 1.0, + -2.0, + 0.0, + 0.0, + -3.0, + 4.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (column-major, non-contiguous, mixed sign strides)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + 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 ); + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1, + 0, + 1, + 0, + 0 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 0.0, + 0.0, + 3.0, + 4.0, + 0.0, + 0.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + 0.0, + 0.0, + -3.0, + -4.0, + 0.0, + 0.0 + ]); + obuf = zeros( 8, dt ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, obuf, sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 1.0, + -2.0, + 0.0, + 0.0, + -3.0, + 4.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (column-major, non-contiguous, large arrays)', function test( t ) { + var condition; + var expected; + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + 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 ); + + cbuf = new Uint8Array( numel( sh )*2 ); // zeros condition array + xbuf = new Float64Array( numel( sh )*2 ); + dfill( numel( sh ), 1.0, xbuf, st[ 0 ] ); + ybuf = zeros( numel( sh )*2, dt ); + dfill( numel( sh ), -1.0, ybuf, st[ 0 ] ); + obuf = zeros( numel( sh )*2, dt ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, obuf, sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array( y.length*2 ); + dfill( y.length, -1.0, expected, st[ 0 ] ); + + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (column-major, non-contiguous, large arrays)', function test( t ) { + var condition; + var expected; + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + 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 ); + + cbuf = new Uint8Array( numel( sh )*2 ); // zeros condition array + xbuf = new Float64Array( numel( sh )*2 ); + dfill( numel( sh ), 1.0, xbuf, st[ 0 ] ); + ybuf = new Float64Array( numel( sh )*2 ); + dfill( numel( sh ), -1.0, ybuf, st[ 0 ] ); + obuf = zeros( numel( sh )*2, dt ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, obuf, sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array( y.length*2 ); + dfill( y.length, -1.0, expected, st[ 0 ] ); + + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (column-major, contiguous, accessors)', function test( t ) { + var condition; + var cbuf; + var xbuf; + var ybuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 1, + 1, + 1 + ]); + xbuf = [ + 1.0, + 2.0, + 3.0, + 4.0 + ]; + ybuf = [ + -1.0, + -2.0, + -3.0, + -4.0 + ]; + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( zeros( numel( sh ), dt ) ), sh, st, o, ord ); // eslint-disable-line max-len + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, x.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (column-major, contiguous, negative strides, accessors)', function test( t ) { + var condition; + var cbuf; + var xbuf; + var ybuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ -1, -2 ]; + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 1, + 1, + 1 + ]); + xbuf = [ + 1.0, + 2.0, + 3.0, + 4.0 + ]; + ybuf = [ + -1.0, + -2.0, + -3.0, + -4.0 + ]; + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( zeros( numel( sh ), dt ) ), sh, st, o, ord ); // eslint-disable-line max-len + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, x.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (column-major, non-contiguous, same sign strides, accessors)', function test( t ) { + var condition; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ 1, 4 ]; + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1 + ]); + xbuf = [ + 1.0, + 2.0, + 0.0, + 0.0, + 3.0, + 4.0, + 0.0, + 0.0 + ]; + ybuf = [ + -1.0, + -2.0, + 0.0, + 0.0, + -3.0, + -4.0, + 0.0, + 0.0 + ]; + obuf = zeros( 8, dt ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( obuf ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, x.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (column-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var condition; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ 1, -4 ]; + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1 + ]); + xbuf = [ + 1.0, + 2.0, + 0.0, + 0.0, + 3.0, + 4.0, + 0.0, + 0.0 + ]; + ybuf = [ + -1.0, + -2.0, + 0.0, + 0.0, + -3.0, + -4.0, + 0.0, + 0.0 + ]; + obuf = zeros( 8, dt ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( obuf ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, x.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var condition; + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'column-major'; + + bsize = blockSize( 'generic' ); + sh = [ bsize*2, 2 ]; + st = [ 2, -bsize*4 ]; + o = strides2offset( sh, st ); + + cbuf = zeros( numel( sh )*2, 'uint8' ); // zeros condition array + xbuf = zeros( numel( sh )*2, dt ); + gfill( numel( sh ), 1.0, xbuf, st[ 0 ] ); + ybuf = zeros( numel( sh )*2, dt ); + gfill( numel( sh ), -1.0, ybuf, st[ 0 ] ); + obuf = zeros( numel( sh )*2, dt ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( obuf ), sh, st, o, ord ); + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, y.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 2-dimensional input ndarray to an output ndarray (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var condition; + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'column-major'; + + bsize = blockSize( 'generic' ); + sh = [ 2, bsize*2 ]; + st = [ -2, 4 ]; + o = strides2offset( sh, st ); + + cbuf = zeros( numel( sh )*2, 'uint8' ); // zeros condition array + xbuf = zeros( numel( sh )*2, dt ); + gfill( numel( sh ), 1.0, xbuf, st[ 0 ] ); + ybuf = zeros( numel( sh )*2, dt ); + gfill( numel( sh ), -1.0, ybuf, st[ 0 ] ); + obuf = zeros( numel( sh )*2, dt ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( obuf ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, y.data ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/where/test/test.3d.js b/lib/node_modules/@stdlib/ndarray/base/where/test/test.3d.js new file mode 100644 index 000000000000..1cabc58ba915 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/test/test.3d.js @@ -0,0 +1,1719 @@ +/** +* @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-lines */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var isSameAccessorArray = require( '@stdlib/assert/is-same-accessor-array' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +var zeros = require( '@stdlib/array/zeros' ); +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 gfill = require( '@stdlib/blas/ext/base/gfill' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var where = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof where, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (row-major, singleton dimensions)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 4, 1, 1 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + -3.0, + -4.0 + ]); + + condition = ndarray('uint8', cbuf, sh, st, o, ord); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 1.0, + -2.0, + 3.0, + 4.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (row-major, singleton dimensions, accessors)', function test( t ) { + var condition; + var cbuf; + var xbuf; + var ybuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'row-major'; + sh = [ 4, 1, 1 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 1, + 1, + 1 + ]); + xbuf = [ + 1.0, + 2.0, + 3.0, + 4.0 + ]; + ybuf = [ + -1.0, + -2.0, + -3.0, + -4.0 + ]; + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( zeros( numel( sh ), 'generic' ) ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( x.data, out.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (row-major, empty)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var out; + var x; + var y; + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + -3.0, + -4.0 + ]); + + condition = ndarray( 'uint8', cbuf, [ 0, 0, 0 ], [ 1, 1, 1 ], 0, 'row-major' ); + x = ndarray( 'float64', xbuf, [ 0, 0, 0 ], [ 1, 1, 1 ], 0, 'row-major' ); + y = ndarray( 'float64', ybuf, [ 0, 0, 0 ], [ 1, 1, 1 ], 0, 'row-major' ); + out = ndarray( 'float64', zeros( 4, 'float64' ), [ 0, 0, 0 ], [ 1, 1, 1 ], 0, 'row-major' ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (row-major, contiguous)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + -3.0, + -4.0 + ]); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 1.0, + -2.0, + 3.0, + 4.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (row-major, contiguous, negative strides)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = [ -2, -2, -1 ]; + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + -3.0, + -4.0 + ]); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 1.0, + -2.0, + 3.0, + 4.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (row-major, non-contiguous, same sign strides)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = [ 4, 2, 1 ]; + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1, + 0, + 1, + 0, + 0 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 0.0, + 0.0, + 3.0, + 4.0, + 0.0, + 0.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + 0.0, + 0.0, + -3.0, + -4.0, + 0.0, + 0.0 + ]); + obuf = zeros( 8, dt ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, obuf, sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 1.0, + -2.0, + 0.0, + 0.0, + -3.0, + 4.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (row-major, non-contiguous, mixed sign strides)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = [ 4, -2, 1 ]; + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1, + 0, + 1, + 0, + 0 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 0.0, + 0.0, + 3.0, + 4.0, + 0.0, + 0.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + 0.0, + 0.0, + -3.0, + -4.0, + 0.0, + 0.0 + ]); + obuf = zeros( 8, dt ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, obuf, sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 1.0, + -2.0, + 0.0, + 0.0, + -3.0, + 4.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (row-major, non-contiguous, large arrays)', function test( t ) { + var condition; + var expected; + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + 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, 1 ]; + st = [ bsize*4, 2, -2 ]; + o = strides2offset( sh, st ); + + cbuf = new Uint8Array( numel( sh )*2 ); // zeros condition array + xbuf = new Float64Array( numel( sh )*2 ); + dfill( numel( sh ), 1.0, xbuf, st[ 2 ] ); + ybuf = new Float64Array( numel( sh )*2 ); + dfill( numel( sh ), -1.0, ybuf, st[ 2 ] ); + obuf = zeros( numel( sh )*2, dt ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, obuf, sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array( y.length*2 ); + dfill( y.length, -1.0, expected, st[ 2 ] ); + + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (row-major, non-contiguous, large arrays)', function test( t ) { + var condition; + var expected; + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, bsize*2 ]; + st = [ bsize*4, bsize*4, -2 ]; + o = strides2offset( sh, st ); + + cbuf = new Uint8Array( numel( sh )*2 ); // zeros condition array + xbuf = new Float64Array( numel( sh )*2 ); + dfill( numel( sh ), 1.0, xbuf, st[ 2 ] ); + ybuf = new Float64Array( numel( sh )*2 ); + dfill( numel( sh ), -1.0, ybuf, st[ 2 ] ); + obuf = zeros( numel( sh )*2, dt ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, obuf, sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array( y.length*2 ); + dfill( y.length, -1.0, expected, st[ 2 ] ); + + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (row-major, contiguous, accessors)', function test( t ) { + var condition; + var cbuf; + var xbuf; + var ybuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 1, + 1, + 1 + ]); + xbuf = [ + 1.0, + 2.0, + 3.0, + 4.0 + ]; + ybuf = [ + -1.0, + -2.0, + -3.0, + -4.0 + ]; + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( zeros( numel( sh ), 'generic' ) ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, x.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (row-major, contiguous, negative strides, accessors)', function test( t ) { + var condition; + var cbuf; + var xbuf; + var ybuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = [ -2, -2, -1 ]; + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 1, + 1, + 1 + ]); + xbuf = [ + 1.0, + 2.0, + 3.0, + 4.0 + ]; + ybuf = [ + -1.0, + -2.0, + -3.0, + -4.0 + ]; + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( zeros( numel( sh ), 'generic' ) ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, x.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (row-major, non-contiguous, same sign strides, accessors)', function test( t ) { + var condition; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = [ 4, 2, 1 ]; + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1 + ]); + xbuf = [ + 1.0, + 2.0, + 0.0, + 0.0, + 3.0, + 4.0, + 0.0, + 0.0 + ]; + ybuf = [ + -1.0, + -2.0, + 0.0, + 0.0, + -3.0, + -4.0, + 0.0, + 0.0 + ]; + obuf = zeros( 8, 'generic' ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( obuf ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, x.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (row-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var condition; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = [ 4, -2, 1 ]; + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1 + ]); + xbuf = [ + 1.0, + 2.0, + 0.0, + 0.0, + 3.0, + 4.0, + 0.0, + 0.0 + ]; + ybuf = [ + -1.0, + -2.0, + 0.0, + 0.0, + -3.0, + -4.0, + 0.0, + 0.0 + ]; + obuf = zeros( 8, 'generic' ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( obuf ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, x.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var condition; + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'row-major'; + + bsize = blockSize( 'generic' ); + sh = [ 2, bsize*2, 1 ]; + st = [ bsize*4, 2, -2 ]; + o = strides2offset( sh, st ); + + cbuf = zeros( numel( sh )*2, 'uint8' ); // zeros condition array + xbuf = zeros( numel( sh )*2, 'generic' ); + gfill( numel( sh ), 1.0, xbuf, st[ 2 ] ); + ybuf = zeros( numel( sh )*2, 'generic' ); + gfill( numel( sh ), -1.0, ybuf, st[ 2 ] ); + obuf = zeros( numel( sh )*2, 'generic' ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( obuf ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, y.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var condition; + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'row-major'; + + bsize = blockSize( 'generic' ); + sh = [ 2, 1, bsize*2 ]; + st = [ bsize*4, bsize*4, -2 ]; + o = strides2offset( sh, st ); + + cbuf = zeros( numel( sh )*2, 'uint8' ); // zeros condition array + xbuf = zeros( numel( sh )*2, 'generic' ); + gfill( numel( sh ), 1.0, xbuf, st[ 2 ] ); + ybuf = zeros( numel( sh )*2, 'generic' ); + gfill( numel( sh ), -1.0, ybuf, st[ 2 ] ); + obuf = zeros( numel( sh )*2, 'generic' ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( obuf ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, y.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (column-major, singleton dimensions)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 1, 1, 4 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + -3.0, + -4.0 + ]); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 1.0, + -2.0, + 3.0, + 4.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (column-major, singleton dimensions, accessors)', function test( t ) { + var condition; + var cbuf; + var xbuf; + var ybuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'column-major'; + sh = [ 4, 1, 1 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 1, + 1, + 1 + ]); + xbuf = [ + 1.0, + 2.0, + 3.0, + 4.0 + ]; + ybuf = [ + -1.0, + -2.0, + -3.0, + -4.0 + ]; + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( zeros( numel( sh ), dt ) ), sh, st, o, ord ); // eslint-disable-line max-len + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, x.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (column-major, empty)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var out; + var x; + var y; + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + -3.0, + -4.0 + ]); + + condition = ndarray( 'uint8', cbuf, [ 0, 0, 0 ], [ 1, 1, 1 ], 0, 'column-major' ); + x = ndarray( 'float64', xbuf, [ 0, 0, 0 ], [ 1, 1, 1 ], 0, 'column-major' ); + y = ndarray( 'float64', ybuf, [ 0, 0, 0 ], [ 1, 1, 1 ], 0, 'column-major' ); + out = ndarray( 'float64', zeros( 4, 'float64' ), [ 0, 0, 0 ], [ 1, 1, 1 ], 0, 'column-major' ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (column-major, contiguous)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + -3.0, + -4.0 + ]); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 1.0, + -2.0, + 3.0, + 4.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (column-major, contiguous, negative strides)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = [ -1, -1, -2 ]; + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + -3.0, + -4.0 + ]); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 1.0, + -2.0, + 3.0, + 4.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (column-major, non-contiguous, same sign strides)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = [ 1, 2, 4 ]; + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1, + 0, + 1, + 0, + 0 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 0.0, + 0.0, + 3.0, + 4.0, + 0.0, + 0.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + 0.0, + 0.0, + -3.0, + -4.0, + 0.0, + 0.0 + ]); + obuf = zeros( 8, dt ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, obuf, sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 1.0, + -2.0, + 0.0, + 0.0, + -3.0, + 4.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (column-major, non-contiguous, mixed sign strides)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = [ 1, -2, -4 ]; + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 0, + 1, + 1, + 0, + 1, + 0, + 0 + ]); + xbuf = new Float64Array([ + 1.0, + 2.0, + 0.0, + 0.0, + 3.0, + 4.0, + 0.0, + 0.0 + ]); + ybuf = new Float64Array([ + -1.0, + -2.0, + 0.0, + 0.0, + -3.0, + -4.0, + 0.0, + 0.0 + ]); + obuf = zeros( 8, dt ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, obuf, sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array([ + 1.0, + -2.0, + 0.0, + 0.0, + -3.0, + 4.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (column-major, non-contiguous, large arrays)', function test( t ) { + var condition; + var expected; + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + 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, 1 ]; + st = [ -2, 4, bsize*8 ]; + o = strides2offset( sh, st ); + + cbuf = new Uint8Array( numel( sh )*2 ); // zeros condition array + xbuf = new Float64Array( numel( sh )*2 ); + dfill( numel( sh ), 1.0, xbuf, st[ 0 ] ); + ybuf = zeros( numel( sh )*2, dt ); + dfill( numel( sh ), -1.0, ybuf, st[ 0 ] ); + obuf = zeros( numel( sh )*2, dt ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, obuf, sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array( y.length*2 ); + dfill( y.length, -1.0, expected, st[ 0 ] ); + + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (column-major, non-contiguous, large arrays)', function test( t ) { + var condition; + var expected; + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, bsize*2 ]; + st = [ -2, 4, 4 ]; + o = strides2offset( sh, st ); + + cbuf = new Uint8Array( numel( sh )*2 ); // zeros condition array + xbuf = new Float64Array( numel( sh )*2 ); + dfill( numel( sh ), 1.0, xbuf, st[ 0 ] ); + ybuf = new Float64Array( numel( sh )*2 ); + dfill( numel( sh ), -1.0, ybuf, st[ 0 ] ); + obuf = zeros( numel( sh )*2, dt ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, xbuf, sh, st, o, ord ); + y = ndarray( dt, ybuf, sh, st, o, ord ); + out = ndarray( dt, obuf, sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + expected = new Float64Array( y.length*2 ); + dfill( y.length, -1.0, expected, st[ 0 ] ); + + t.strictEqual( isSameFloat64Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (column-major, contiguous, accessors)', function test( t ) { + var condition; + var cbuf; + var xbuf; + var ybuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 1, + 1, + 1 + ]); + xbuf = [ + 1.0, + 2.0, + 3.0, + 4.0 + ]; + ybuf = [ + -1.0, + -2.0, + -3.0, + -4.0 + ]; + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( zeros( numel( sh ), dt ) ), sh, st, o, ord ); // eslint-disable-line max-len + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, x.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (column-major, contiguous, negative strides, accessors)', function test( t ) { + var condition; + var cbuf; + var xbuf; + var ybuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = [ -1, -1, -2 ]; + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 1, + 1, + 1 + ]); + xbuf = [ + 1.0, + 2.0, + 3.0, + 4.0 + ]; + ybuf = [ + -1.0, + -2.0, + -3.0, + -4.0 + ]; + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( zeros( numel( sh ), dt ) ), sh, st, o, ord ); // eslint-disable-line max-len + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, x.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (column-major, non-contiguous, same sign strides, accessors)', function test( t ) { + var condition; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = [ 1, 2, 4 ]; + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1 + ]); + xbuf = [ + 1.0, + 2.0, + 0.0, + 0.0, + 3.0, + 4.0, + 0.0, + 0.0 + ]; + ybuf = [ + -1.0, + -2.0, + 0.0, + 0.0, + -3.0, + -4.0, + 0.0, + 0.0 + ]; + obuf = zeros( 8, dt ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( obuf ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, x.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (column-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var condition; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = [ 1, -2, -4 ]; + o = strides2offset( sh, st ); + + cbuf = new Uint8Array([ + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1 + ]); + xbuf = [ + 1.0, + 2.0, + 0.0, + 0.0, + 3.0, + 4.0, + 0.0, + 0.0 + ]; + ybuf = [ + -1.0, + -2.0, + 0.0, + 0.0, + -3.0, + -4.0, + 0.0, + 0.0 + ]; + obuf = zeros( 8, dt ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( obuf ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, x.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var condition; + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'column-major'; + + bsize = blockSize( 'generic' ); + sh = [ 2, bsize*2, 1 ]; + st = [ -2, 4, bsize*8 ]; + o = strides2offset( sh, st ); + + cbuf = zeros( numel( sh )*2, 'uint8' ); // zeros condition array + xbuf = zeros( numel( sh )*2, dt ); + gfill( numel( sh ), 1.0, xbuf, st[ 0 ] ); + ybuf = zeros( numel( sh )*2, dt ); + gfill( numel( sh ), -1.0, ybuf, st[ 0 ] ); + obuf = zeros( numel( sh )*2, dt ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( obuf ), sh, st, o, ord ); + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, y.data ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from a 3-dimensional input ndarray to an output ndarray (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var condition; + var bsize; + var cbuf; + var xbuf; + var ybuf; + var obuf; + var out; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'generic'; + ord = 'column-major'; + + bsize = blockSize( 'generic' ); + sh = [ 2, 1, bsize*2 ]; + st = [ -2, 4, 4 ]; + o = strides2offset( sh, st ); + + cbuf = zeros( numel( sh )*2, 'uint8' ); // zeros condition array + xbuf = zeros( numel( sh )*2, dt ); + gfill( numel( sh ), 1.0, xbuf, st[ 0 ] ); + ybuf = zeros( numel( sh )*2, dt ); + gfill( numel( sh ), -1.0, ybuf, st[ 0 ] ); + obuf = zeros( numel( sh )*2, dt ); + + condition = ndarray( 'uint8', cbuf, sh, st, o, ord ); + x = ndarray( dt, toAccessorArray( xbuf ), sh, st, o, ord ); + y = ndarray( dt, toAccessorArray( ybuf ), sh, st, o, ord ); + out = ndarray( dt, toAccessorArray( obuf ), sh, st, o, ord ); + + where( [ condition, x, y, out ] ); + + t.strictEqual( isSameAccessorArray( out.data, y.data ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/where/test/test.js b/lib/node_modules/@stdlib/ndarray/base/where/test/test.js new file mode 100644 index 000000000000..8ea2ed79e00c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/test/test.js @@ -0,0 +1,203 @@ +/** +* @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 BooleanArray = require( '@stdlib/array/bool' ); +var zeros = require( '@stdlib/array/zeros' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var where = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof where, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided ndarrays which do not have the same shape', function test( t ) { + var condition; + var values; + var cbuf; + var out; + var x; + var y; + var i; + + cbuf = new BooleanArray( [ 1, 0, 0, 1 ] ); + + condition = ndarray( 'uint8', cbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + x = ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0 ], [ 4 ], [ 1 ], 0, 'row-major' ); + y = ndarray( 'generic', [ -1.0, -2.0, -3.0, -4.0 ], [ 4 ], [ 1 ], 0, 'row-major' ); + + values = [ + [ 2 ], + [ 3 ], + [ 5 ], + [ 6 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + out = ndarray( 'float64', zeros( 8, 'float64' ), value, [ 1 ], 0, 'row-major' ); + where( [ condition, x, y, out ] ); + }; + } +}); + +tape( 'the function throws an error if provided a non-boolean or uint8 condition ndarray', function test( t ) { + var condition; + var values; + var out; + var x; + var y; + var i; + + x = ndarray( 'float32', [ 1.0, 2.0, 3.0, 4.0 ], [ 4 ], [ 1 ], 0, 'row-major' ); + y = ndarray( 'float32', [ -1.0, -2.0, -3.0, -4.0 ], [ 4 ], [ 1 ], 0, 'row-major' ); + out = ndarray( 'float32', zeros( 4, 'float32' ), [ 4 ], [ 1 ], 0, 'row-major' ); + + values = [ + 'float64', + 'complex64', + 'binary' + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + condition = ndarray( value, [ 1, 0, 0, 1 ], [ 4 ], [ 1 ], 0, 'row-major' ); + where( [ condition, x, y, out ] ); + }; + } +}); + +tape( 'the function conditionally assigns elements from an input ndarray to an output ndarray (boolean)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var out; + var x; + var y; + + cbuf = new BooleanArray([ + true, + false, + false, + true + ]); + xbuf = new BooleanArray([ + true, + true, + true, + true + ]); + ybuf = new BooleanArray([ + false, + false, + false, + false + ]); + + condition = ndarray( 'bool', cbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + x = ndarray( 'bool', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + y = ndarray( 'bool', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); + out = ndarray( 'bool', zeros( 4, 'bool' ), [ 4 ], [ 1 ], 0, 'row-major' ); + + where( [ condition, x, y, out ] ); + + expected = new BooleanArray( [ true, false, false, true ] ); + + t.deepEqual( expected, out.data, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function conditionally assigns elements from an input ndarray to an output ndarray (complex)', function test( t ) { + var condition; + var expected; + var cbuf; + var xbuf; + var ybuf; + var out; + var x; + var y; + + cbuf = new BooleanArray([ + true, + false, + false, + true + ]); + xbuf = new Complex128Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0 + ]); + ybuf = new Complex128Array([ + -10.0, + -10.0, + -10.0, + -10.0, + -10.0, + -10.0, + -10.0, + -10.0 + ]); + condition = ndarray( 'bool', cbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + x = ndarray( 'complex128', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + y = ndarray( 'complex128', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); + out = ndarray( 'complex128', zeros( 4, 'complex128' ), [ 4 ], [ 1 ], 0, 'row-major' ); + + where( [ condition, x, y, out ] ); + + expected = new Complex128Array([ + 10.0, + 10.0, + -10.0, + -10.0, + -10.0, + -10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameComplex128Array( out.data, expected ), true, 'returns expected value' ); + + t.end(); +});