From c65133f38cf4958ce2b758191b6235d9f45e7d6c Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Mon, 2 Mar 2026 22:58:58 +0200 Subject: [PATCH 01/33] feat: create 2d version with its tests and benchmarks --- .../@stdlib/ndarray/base/where/README.md | 61 ++++ .../benchmark/benchmark.2d_columnmajor.js | 169 ++++++++++ .../where/benchmark/benchmark.2d_rowmajor.js | 170 ++++++++++ .../@stdlib/ndarray/base/where/lib/2d.js | 214 +++++++++++++ .../@stdlib/ndarray/base/where/package.json | 59 ++++ .../@stdlib/ndarray/base/where/test/test.js | 299 ++++++++++++++++++ 6 files changed, 972 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/2d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/test/test.js 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..0dc6e4faddad --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/README.md @@ -0,0 +1,61 @@ + + +# Where + +> Apply a condition to elements in two input ndarrays and assign results to elements in an output ndarray. + +
+ +
+ + + +
+ + +
+ + + +
+ +
+ + + + + +* * * + + + + + + + + + + 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..277059844f1b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_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 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 pkg = require( './../package.json' ).name; +var where2d = require( './../lib/2d.js' ); + + +// VARIABLES // + +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} xtype - first input ndarray data type +* @param {string} ytype - second input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var condition; + var out; + var x; + var y; + condition = filledarrayBy( len, 'uint8', bernoulli( 0.5 ) ); + x = filledarrayBy( len, xtype, discreteUniform( -100, 100 ) ); + y = filledarrayBy( len, ytype, discreteUniform( -100, 100 ) ); + out = filledarray( 0.0, len, xtype ); + + condition = { + 'dtype': 'uint8', + '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': xtype, + '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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],order='+order+',xtype='+t1+',ytype='+t2, f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],order='+order+',xtype='+t1+',ytype='+t2, f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, t1, t2 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],order='+order+',xtype='+t1+',ytype='+t2, 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..cb5ff0c56e5d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_rowmajor.js @@ -0,0 +1,170 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var discreteUniform = require( '@stdlib/random/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 pkg = require( './../package.json' ).name; +var where2d = require( './../lib/2d.js' ); + + +// VARIABLES // + +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} xtype - first input ndarray data type +* @param {string} ytype - second input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var condition; + var out; + var x; + var y; + + condition = filledarrayBy( len, 'uint8', bernoulli( 0.5 ) ); + x = filledarrayBy( len, xtype, discreteUniform( -100, 100 ) ); + y = filledarrayBy( len, ytype, discreteUniform( -100, 100 ) ); + out = filledarray( 0.0, len, xtype ); + + condition = { + 'dtype': 'uint8', + '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': xtype, + '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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],order='+order+',xtype='+t1+',ytype='+t2, f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],order='+order+',xtype='+t1+',ytype='+t2, f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, t1, t2 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],order='+order+',xtype='+t1+',ytype='+t2, f ); + } + } +} + +main(); 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..848b1e7e5bad --- /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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} 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/package.json b/lib/node_modules/@stdlib/ndarray/base/where/package.json new file mode 100644 index 000000000000..1e1b24a090b2 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/package.json @@ -0,0 +1,59 @@ +{ + "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", + "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.js b/lib/node_modules/@stdlib/ndarray/base/where/test/test.js new file mode 100644 index 000000000000..2d245d4f80b5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/test/test.js @@ -0,0 +1,299 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +var where2d = require( './../lib/2d.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof where2d, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function selects elements from `x` when the condition is truthy, and from `y` otherwise (row-major)', function test( t ) { + var condition; + var out; + var x; + var y; + + // All-true condition: output must equal x entirely + condition = { + 'dtype': 'uint8', + 'data': new Uint8Array( [ 1, 1, 1, 1 ] ), + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + y = { + 'dtype': 'float64', + 'data': new Float64Array( [ 5.0, 6.0, 7.0, 8.0 ] ), + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + out = { + 'dtype': 'float64', + 'data': new Float64Array( 4 ), + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + + where2d( condition, x, y, out, true ); + + t.strictEqual( out.data[ 0 ], 1.0, 'returns expected value' ); + t.strictEqual( out.data[ 1 ], 2.0, 'returns expected value' ); + t.strictEqual( out.data[ 2 ], 3.0, 'returns expected value' ); + t.strictEqual( out.data[ 3 ], 4.0, 'returns expected value' ); + + // All-false condition: output must equal y entirely + condition.data = new Uint8Array( [ 0, 0, 0, 0 ] ); + out.data = new Float64Array( 4 ); + + where2d( condition, x, y, out, true ); + + t.strictEqual( out.data[ 0 ], 5.0, 'returns expected value' ); + t.strictEqual( out.data[ 1 ], 6.0, 'returns expected value' ); + t.strictEqual( out.data[ 2 ], 7.0, 'returns expected value' ); + t.strictEqual( out.data[ 3 ], 8.0, 'returns expected value' ); + + // Mixed condition: [ 1, 0, 0, 1 ] → [ x0, y1, y2, x3 ] + condition.data = new Uint8Array( [ 1, 0, 0, 1 ] ); + out.data = new Float64Array( 4 ); + + where2d( condition, x, y, out, true ); + + t.strictEqual( out.data[ 0 ], 1.0, 'returns expected value' ); + t.strictEqual( out.data[ 1 ], 6.0, 'returns expected value' ); + t.strictEqual( out.data[ 2 ], 7.0, 'returns expected value' ); + t.strictEqual( out.data[ 3 ], 4.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function selects elements from `x` when the condition is truthy, and from `y` otherwise (column-major)', function test( t ) { + var condition; + var out; + var x; + var y; + + condition = { + 'dtype': 'uint8', + 'data': new Uint8Array( [ 1, 0, 0, 1 ] ), + 'shape': [ 2, 2 ], + 'strides': [ 1, 2 ], + 'offset': 0, + 'order': 'column-major' + }; + x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), + 'shape': [ 2, 2 ], + 'strides': [ 1, 2 ], + 'offset': 0, + 'order': 'column-major' + }; + y = { + 'dtype': 'float64', + 'data': new Float64Array( [ 5.0, 6.0, 7.0, 8.0 ] ), + 'shape': [ 2, 2 ], + 'strides': [ 1, 2 ], + 'offset': 0, + 'order': 'column-major' + }; + out = { + 'dtype': 'float64', + 'data': new Float64Array( 4 ), + 'shape': [ 2, 2 ], + 'strides': [ 1, 2 ], + 'offset': 0, + 'order': 'column-major' + }; + + where2d( condition, x, y, out, false ); + + t.strictEqual( out.data[ 0 ], 1.0, 'returns expected value' ); + t.strictEqual( out.data[ 1 ], 6.0, 'returns expected value' ); + t.strictEqual( out.data[ 2 ], 7.0, 'returns expected value' ); + t.strictEqual( out.data[ 3 ], 4.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports non-zero offsets', function test( t ) { + var condition; + var out; + var x; + var y; + + condition = { + 'dtype': 'uint8', + 'data': new Uint8Array( [ 1, 0, 1, 0 ] ), + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 99.0, 2.0, 3.0, 4.0, 5.0 ] ), + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': 1, + 'order': 'row-major' + }; + y = { + 'dtype': 'float64', + 'data': new Float64Array( [ 10.0, 20.0, 30.0, 40.0 ] ), + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + out = { + 'dtype': 'float64', + 'data': new Float64Array( 4 ), + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + + where2d( condition, x, y, out, true ); + + t.strictEqual( out.data[ 0 ], 2.0, 'returns expected value' ); + t.strictEqual( out.data[ 1 ], 20.0, 'returns expected value' ); + t.strictEqual( out.data[ 2 ], 4.0, 'returns expected value' ); + t.strictEqual( out.data[ 3 ], 40.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports non-unit strides', function test( t ) { + var condition; + var out; + var x; + var y; + + condition = { + 'dtype': 'uint8', + 'data': new Uint8Array( [ 0, 1, 1, 0 ] ), + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), + 'shape': [ 2, 2 ], + 'strides': [ 4, 1 ], + 'offset': 1, + 'order': 'row-major' + }; + y = { + 'dtype': 'float64', + 'data': new Float64Array( [ 10.0, 20.0, 30.0, 40.0 ] ), + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + out = { + 'dtype': 'float64', + 'data': new Float64Array( 4 ), + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + + where2d( condition, x, y, out, true ); + + t.strictEqual( out.data[ 0 ], 10.0, 'returns expected value' ); + t.strictEqual( out.data[ 1 ], 3.0, 'returns expected value' ); + t.strictEqual( out.data[ 2 ], 6.0, 'returns expected value' ); + t.strictEqual( out.data[ 3 ], 40.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns without doing anything when provided a shape with a zero dimension', function test( t ) { + var condition; + var out; + var x; + var y; + + condition = { + 'dtype': 'uint8', + 'data': new Uint8Array( 0 ), + 'shape': [ 0, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + x = { + 'dtype': 'float64', + 'data': new Float64Array( 0 ), + 'shape': [ 0, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + y = { + 'dtype': 'float64', + 'data': new Float64Array( 0 ), + 'shape': [ 0, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + out = { + 'dtype': 'float64', + 'data': new Float64Array( 0 ), + 'shape': [ 0, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + + where2d( condition, x, y, out, true ); + + t.strictEqual( out.data.length, 0, 'returns expected value' ); + t.end(); +}); From 148d9d103e02923aca2b5b8f31a0b4f4aa0ff9c6 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Wed, 4 Mar 2026 22:43:43 +0200 Subject: [PATCH 02/33] feat: add 0d implementation --- .../@stdlib/ndarray/base/where/lib/0d.js | 129 ++++++++++++++++++ .../ndarray/base/where/lib/0d_accessors.js | 129 ++++++++++++++++++ 2 files changed, 258 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/0d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/0d_accessors.js 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..ec0d8b92d1da --- /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 ]; +} + + +// 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..1e96e56121e9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/0d_accessors.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.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 ) ); +} + + +// EXPORTS // + +module.exports = where0d; From 2a17361388d563c16ebafc0a50de4dc3fdb7fdb7 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Wed, 4 Mar 2026 23:26:16 +0200 Subject: [PATCH 03/33] feat: add 2d accessors implementation --- .../ndarray/base/where/lib/2d_accessors.js | 220 ++++++++++++++++++ 1 file changed, 220 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/2d_accessors.js 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..8cc812765be0 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_accessors.js @@ -0,0 +1,220 @@ +/** +* @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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} 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; + + // Cache accessors + getx = x.accessors[ 0 ]; + gety = y.accessors[ 0 ]; + getc = condition.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 ) ); + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } +} + + +// EXPORTS // + +module.exports = where2d; From e3729ee8fa125fb2cb36ab8ea1dee60e7d4e81fc Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Wed, 4 Mar 2026 23:26:34 +0200 Subject: [PATCH 04/33] feat: add 2d blocked implementation --- .../ndarray/base/where/lib/2d_blocked.js | 255 ++++++++++++++++++ 1 file changed, 255 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/2d_blocked.js 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..a00f420279ce --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_blocked.js @@ -0,0 +1,255 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); +var take = require( '@stdlib/array/base/take-indexed' ); + + +// 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, 5.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 using x as the reference array. + o = loopOrder( x.shape, x.strides, out.strides ); + sh = o.sh; + sx = o.sx; + so = o.sy; + + // Apply the same dimension permutation to condition and y strides so that + sc = take( condition.strides, o.idx ); + sy = take( y.strides, o.idx ); + + // 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; From cec872e9693dc8185c02fec3212211d7784abd45 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Wed, 4 Mar 2026 23:39:52 +0200 Subject: [PATCH 05/33] perf: use ternary loopOrder instead of unary --- .../ndarray/base/where/lib/2d_blocked.js | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) 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 index a00f420279ce..8afe001594e2 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_blocked.js @@ -20,9 +20,8 @@ // MODULES // -var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var loopOrder = require( '@stdlib/ndarray/base/ternary-loop-interchange-order' ); var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); -var take = require( '@stdlib/array/base/take-indexed' ); // MAIN // @@ -167,15 +166,15 @@ function blockedwhere2d( condition, x, y, out ) { // 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 using x as the reference array. - o = loopOrder( x.shape, x.strides, out.strides ); - sh = o.sh; - sx = o.sx; - so = o.sy; - - // Apply the same dimension permutation to condition and y strides so that - sc = take( condition.strides, o.idx ); - sy = take( y.strides, o.idx ); + // 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 ); From 1c48565c6c2279e2b01da2317f70b3d3a9a55332 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Wed, 4 Mar 2026 23:46:28 +0200 Subject: [PATCH 06/33] refactor: use proper indentation to follow editorconfig --- .../@stdlib/ndarray/base/where/lib/2d_accessors.js | 10 +++++----- .../@stdlib/ndarray/base/where/lib/2d_blocked.js | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) 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 index 8cc812765be0..768cb14a9b82 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_accessors.js @@ -192,11 +192,11 @@ function where2d( condition, x, y, out, isRowMajor ) { ybuf = y.data; obuf = out.data; - // Cache accessors - getx = x.accessors[ 0 ]; - gety = y.accessors[ 0 ]; - getc = condition.accessors[ 0 ]; - seto = out.accessors[ 1 ]; + // Cache accessors + getx = x.accessors[ 0 ]; + gety = y.accessors[ 0 ]; + getc = condition.accessors[ 0 ]; + seto = out.accessors[ 1 ]; // Iterate over the ndarray dimensions... for ( i1 = 0; i1 < S1; i1++ ) { 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 index 8afe001594e2..4ca7048e761b 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_blocked.js @@ -168,12 +168,12 @@ function blockedwhere2d( condition, x, y, out ) { // 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; + + // 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; + sy = o.sz; so = o.sw; // Determine the block size: @@ -191,7 +191,7 @@ function blockedwhere2d( condition, x, y, out ) { ybuf = y.data; obuf = out.data; - // Cache offset increments for the innermost loop... + // Cache offset increments for the innermost loop... dc0 = sc[ 0 ]; dx0 = sx[ 0 ]; dy0 = sy[ 0 ]; From ccad894518bf07a717687e84b3fb5ce2d70c8e23 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Wed, 4 Mar 2026 23:49:58 +0200 Subject: [PATCH 07/33] refactor: disable max-len rule --- lib/node_modules/@stdlib/ndarray/base/where/lib/0d_accessors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 1e96e56121e9..8b3cb4bc1158 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/0d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/0d_accessors.js @@ -120,7 +120,7 @@ * // => [ 1.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 ) ); + 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 } From 2df0faf8af8239d580eea4195940d9c4f6cdd4c5 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Thu, 5 Mar 2026 00:03:40 +0200 Subject: [PATCH 08/33] docs: fix the jsdoc to set the accessors --- .../ndarray/base/where/lib/0d_accessors.js | 50 +++++++++++++------ .../ndarray/base/where/lib/2d_accessors.js | 50 +++++++++++++------ 2 files changed, 70 insertions(+), 30 deletions(-) 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 index 8b3cb4bc1158..8c28cf1251c4 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/0d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/0d_accessors.js @@ -55,14 +55,16 @@ * @returns {void} * * @example -* var Float64Array = require( '@stdlib/array/float64' ); -* var Uint8Array = require( '@stdlib/array/uint8' ); +* 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 Uint8Array( [ 1 ] ); -* var xbuf = new Float64Array( [ 1.0 ] ); -* var ybuf = new Float64Array( [ 2.0 ] ); -* var obuf = new Float64Array( 1 ); +* 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 = []; @@ -79,6 +81,15 @@ * 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': 'uint8', @@ -86,38 +97,47 @@ * 'shape': shape, * 'strides': sc, * 'offset': oc, -* 'order': 'row-major' +* 'order': 'row-major', +* 'accessors': [ getter, setter ] * }; * var x = { -* 'dtype': 'float64', +* 'dtype': 'complex64', * 'data': xbuf, * 'shape': shape, * 'strides': sx, * 'offset': ox, -* 'order': 'row-major' +* 'order': 'row-major', +* 'accessors': [ getter, setter ] * }; * var y = { -* 'dtype': 'float64', +* 'dtype': 'complex64', * 'data': ybuf, * 'shape': shape, * 'strides': sy, * 'offset': oy, -* 'order': 'row-major' +* 'order': 'row-major', +* 'accessors': [ getter, setter ] * }; * var out = { -* 'dtype': 'float64', +* 'dtype': 'complex64', * 'data': obuf, * 'shape': shape, * 'strides': so, * 'offset': oo, -* 'order': 'row-major' +* 'order': 'row-major', +* 'accessors': [ getter, setter ] * }; * * // Apply the condition: * where0d( condition, x, y, out ); * -* console.log( out.data ); -* // => [ 1.0 ] +* 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 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 index 768cb14a9b82..6a7d12f9030d 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_accessors.js @@ -56,14 +56,16 @@ * @returns {void} * * @example -* var Float64Array = require( '@stdlib/array/float64' ); -* var Uint8Array = require( '@stdlib/array/uint8' ); +* 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 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 ); +* 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 ]; @@ -80,6 +82,15 @@ * 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': 'uint8', @@ -87,38 +98,47 @@ * 'shape': shape, * 'strides': sc, * 'offset': oc, -* 'order': 'row-major' +* 'order': 'row-major', +* 'accessors': [ getter, setter ] * }; * var x = { -* 'dtype': 'float64', +* 'dtype': 'complex64', * 'data': xbuf, * 'shape': shape, * 'strides': sx, * 'offset': ox, -* 'order': 'row-major' +* 'order': 'row-major', +* 'accessors': [ getter, setter ] * }; * var y = { -* 'dtype': 'float64', +* 'dtype': 'complex64', * 'data': ybuf, * 'shape': shape, * 'strides': sy, * 'offset': oy, -* 'order': 'row-major' +* 'order': 'row-major', +* 'accessors': [ getter, setter ] * }; * var out = { -* 'dtype': 'float64', +* 'dtype': 'complex64', * 'data': obuf, * 'shape': shape, * 'strides': so, * 'offset': oo, -* 'order': 'row-major' +* 'order': 'row-major', +* 'accessors': [ getter, setter ] * }; * * // Apply the condition: * where2d( condition, x, y, out, true ); * -* console.log( out.data ); -* // => [ 1.0, -2.0, -3.0, 4.0 ] +* 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; From 5b71c611114eb8f53a8924d9067ec168fed0cbb0 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Thu, 5 Mar 2026 00:31:02 +0200 Subject: [PATCH 09/33] fix: create getters and setters cache variables --- lib/node_modules/@stdlib/ndarray/base/where/lib/0d.js | 2 +- .../@stdlib/ndarray/base/where/lib/2d_accessors.js | 8 ++++++-- .../@stdlib/ndarray/base/where/lib/2d_blocked.js | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/0d.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/0d.js index ec0d8b92d1da..4b2d066dde26 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/0d.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/0d.js @@ -120,7 +120,7 @@ * // => [ 1.0 ] */ function where0d( condition, x, y, out ) { - out.data[ out.offset ] = ( condition.data[ condition.offset ] ) ? x.data[ x.offset ] : y.data[ y.offset ]; + out.data[ out.offset ] = ( condition.data[ condition.offset ] ) ? x.data[ x.offset ] : y.data[ y.offset ]; // eslint-disable-line max-len } 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 index 6a7d12f9030d..823adb1a0cc2 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_accessors.js @@ -145,6 +145,10 @@ function where2d( condition, x, y, out, isRowMajor ) { var xbuf; var ybuf; var obuf; + var getc; + var getx; + var gety; + var seto; var dc0; var dc1; var dx0; @@ -213,15 +217,15 @@ function where2d( condition, x, y, out, isRowMajor ) { obuf = out.data; // Cache accessors + getc = condition.accessors[ 0 ]; getx = x.accessors[ 0 ]; gety = y.accessors[ 0 ]; - getc = condition.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 ) ); + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len ic += dc0; ix += dx0; iy += dy0; 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 index 4ca7048e761b..4972c535f5d7 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_blocked.js @@ -123,7 +123,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * blockedwhere2d( condition, x, y, out ); * * console.log( out.data ); -* // => [ 2.0, 20.0, 30.0, 5.0 ] +* // => [ 2.0, 20.0, 30.0, 7.0 ] */ function blockedwhere2d( condition, x, y, out ) { var bsize; @@ -167,7 +167,7 @@ function blockedwhere2d( condition, x, y, out ) { // 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 ); + 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; From c1ddf9bf2689239eaf77303dc0821ca409780b1c Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Thu, 5 Mar 2026 00:59:54 +0200 Subject: [PATCH 10/33] feat: add 2d blocked accessors --- .../ndarray/base/where/lib/2d_accessors.js | 2 +- .../base/where/lib/2d_blocked_accessors.js | 284 ++++++++++++++++++ 2 files changed, 285 insertions(+), 1 deletion(-) create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/2d_blocked_accessors.js 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 index 823adb1a0cc2..a34e80e9d1f0 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_accessors.js @@ -93,7 +93,7 @@ * * // Create the ndarray-like objects: * var condition = { -* 'dtype': 'uint8', +* 'dtype': 'bool', * 'data': cbuf, * 'shape': shape, * 'strides': sc, 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..440dfceee7de --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_blocked_accessors.js @@ -0,0 +1,284 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// 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 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 ) ); + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } + ic += dc1; + ix += dx1; + iy += dy1; + io += do1; + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhere2d; From b672f6663f1d5262681efc82211090dad23f2c66 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Thu, 5 Mar 2026 01:25:04 +0200 Subject: [PATCH 11/33] feat: add 1d and its accessors version --- .../@stdlib/ndarray/base/where/lib/1d.js | 172 +++++++++++++++ .../ndarray/base/where/lib/1d_accessors.js | 202 ++++++++++++++++++ .../base/where/lib/2d_blocked_accessors.js | 2 +- 3 files changed, 375 insertions(+), 1 deletion(-) create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/1d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/1d_accessors.js 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..2bbd193c81b1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/1d.js @@ -0,0 +1,172 @@ +/** +* @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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} 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 dc0; + var dx0; + var dy0; + var do0; + var S0; + var ic; + var ix; + var iy; + var io; + var i0; + + // 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: dimensions and loop offset (pointer) increments... + S0 = x.shape[ 0 ]; + dc0 = condition.strides[ 0 ]; + dx0 = x.strides[ 0 ]; + dy0 = y.strides[ 0 ]; + do0 = 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 ( i0 = 0; i0 < S0; i0++ ) { + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; + ic += dc0; + ix += dx0; + iy += dy0; + io += do0; + } +} + + +// 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..ac9b27263e4e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/1d_accessors.js @@ -0,0 +1,202 @@ +/** +* @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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} 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 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 dc0; + var dx0; + var dy0; + var do0; + var S0; + var ic; + var ix; + var iy; + var io; + var i0; + + // 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: dimensions and loop offset (pointer) increments... + S0 = x.shape[ 0 ]; + dc0 = condition.strides[ 0 ]; + dx0 = x.strides[ 0 ]; + dy0 = y.strides[ 0 ]; + do0 = 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 ( 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; + } +} + + +// EXPORTS // + +module.exports = where1d; 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 index 440dfceee7de..8ee14429f6de 100644 --- 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 @@ -263,7 +263,7 @@ function blockedwhere2d( condition, x, y, out ) { // 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 ) ); + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len ic += dc0; ix += dx0; iy += dy0; From f470119eabebcd8a529b96e2ed847c8a90d34c89 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Thu, 5 Mar 2026 16:21:34 +0200 Subject: [PATCH 12/33] feat: add 3d implementations --- .../ndarray/base/where/lib/1d_accessors.js | 2 +- .../@stdlib/ndarray/base/where/lib/3d.js | 236 +++++++++++++ .../ndarray/base/where/lib/3d_accessors.js | 270 +++++++++++++++ .../ndarray/base/where/lib/3d_blocked.js | 289 ++++++++++++++++ .../base/where/lib/3d_blocked_accessors.js | 324 ++++++++++++++++++ 5 files changed, 1120 insertions(+), 1 deletion(-) create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/3d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/3d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/3d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/3d_blocked_accessors.js 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 index ac9b27263e4e..eb9a003f0783 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/1d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/1d_accessors.js @@ -188,7 +188,7 @@ function where1d( condition, x, y, out ) { // Iterate over the ndarray dimensions... for ( i0 = 0; i0 < S0; i0++ ) { - seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len ic += dc0; ix += dx0; iy += dy0; 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..a9daa0468938 --- /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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} 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..2063cc2d54f9 --- /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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} 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..daee38886601 --- /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 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 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 output 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 ) { + 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..79b82778829e --- /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 ) { + 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 ); + + // 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 ) ); + 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; From fefa9ab1936a9580ef5d261903923ca52c3f1d18 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Thu, 5 Mar 2026 17:08:17 +0200 Subject: [PATCH 13/33] feat: add 4d implementations --- .../@stdlib/ndarray/base/where/lib/4d.js | 258 +++++++++++++ .../ndarray/base/where/lib/4d_accessors.js | 292 ++++++++++++++ .../ndarray/base/where/lib/4d_blocked.js | 325 ++++++++++++++++ .../base/where/lib/4d_blocked_accessors.js | 359 ++++++++++++++++++ 4 files changed, 1234 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/4d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/4d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/4d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/4d_blocked_accessors.js 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..7e9d72e6f5e1 --- /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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} 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 ) { + 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..71fe05836f99 --- /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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} 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 ) { + 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 ) ); + 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..0d69e5036bf6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/4d_blocked.js @@ -0,0 +1,325 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-depth */ + +'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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} 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' +* }; +* +* // 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 ) { + 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 ); + + // 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 ]; + 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..a86b7dfdcfb5 --- /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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} 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 ) { + 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 ); + + // 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 ) ); + 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; From 1fba26161d9ed00602c91a729345d1043a2794cf Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Fri, 6 Mar 2026 00:19:56 +0200 Subject: [PATCH 14/33] feat: add 5d implementations --- .../@stdlib/ndarray/base/where/lib/5d.js | 281 +++++++++++++ .../ndarray/base/where/lib/5d_accessors.js | 316 ++++++++++++++ .../ndarray/base/where/lib/5d_blocked.js | 359 ++++++++++++++++ .../base/where/lib/5d_blocked_accessors.js | 393 ++++++++++++++++++ 4 files changed, 1349 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/5d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/5d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/5d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/5d_blocked_accessors.js 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..a82bda751b06 --- /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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} 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 ) { + 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..b227d6283d41 --- /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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} 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 ) { + 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 ) ); + 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..0f4d11cb9d0f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/5d_blocked.js @@ -0,0 +1,359 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-depth */ + +'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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} 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: +* 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 + 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 ); + + // 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 ]; + 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..cb7b8bd082e9 --- /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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} 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 + 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 ); + + // 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 ) ); + 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; From b89c478e7d9443fe37b592178925fc6ef54f295f Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Fri, 6 Mar 2026 01:01:38 +0200 Subject: [PATCH 15/33] feat: add 6d implementations --- .../@stdlib/ndarray/base/where/lib/6d.js | 304 +++++++++++++ .../ndarray/base/where/lib/6d_accessors.js | 339 ++++++++++++++ .../ndarray/base/where/lib/6d_blocked.js | 393 ++++++++++++++++ .../base/where/lib/6d_blocked_accessors.js | 427 ++++++++++++++++++ 4 files changed, 1463 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/6d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/6d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/6d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/6d_blocked_accessors.js 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..898fe0af7471 --- /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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} 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 ) { + 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 ]; + 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..f900be2f795e --- /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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} 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 ) { + 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 ) ); + 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..c1bb1500cc5c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/6d_blocked.js @@ -0,0 +1,393 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-depth */ + +'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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} 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: +* 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 + 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 ); + + // 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 ]; + 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..abc75a5936b7 --- /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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} 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 + 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 ); + + // 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 ) ); + 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; From c93b3411f954f78769b315037861350da467d887 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Fri, 6 Mar 2026 01:34:26 +0200 Subject: [PATCH 16/33] feat: add 7d implementations --- .../@stdlib/ndarray/base/where/lib/7d.js | 323 ++++++++++++ .../ndarray/base/where/lib/7d_accessors.js | 358 +++++++++++++ .../ndarray/base/where/lib/7d_blocked.js | 443 ++++++++++++++++ .../base/where/lib/7d_blocked_accessors.js | 477 ++++++++++++++++++ 4 files changed, 1601 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/7d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/7d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/7d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/7d_blocked_accessors.js 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..c14ee13125e2 --- /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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} 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..6cea86ee3267 --- /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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} 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 ) ); + 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..79a397126e83 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/7d_blocked.js @@ -0,0 +1,443 @@ +/** +* @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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} 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: +* 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 + 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 ); + + // 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++ ) { + 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; + } + } + } + } + } + } + } + } +} + + +// 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..a943f90b9f18 --- /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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} 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 + 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 ); + + // 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++ ) { + 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; + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhere7d; From 4b2706ecebd5502ac5278af45aa13bc8eeb709c9 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Fri, 6 Mar 2026 02:11:29 +0200 Subject: [PATCH 17/33] feat: add 8d implementations --- .../@stdlib/ndarray/base/where/lib/8d.js | 348 ++++++++++++ .../ndarray/base/where/lib/8d_accessors.js | 383 ++++++++++++++ .../ndarray/base/where/lib/8d_blocked.js | 461 ++++++++++++++++ .../base/where/lib/8d_blocked_accessors.js | 495 ++++++++++++++++++ 4 files changed, 1687 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/8d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/8d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/8d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/8d_blocked_accessors.js 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..1e81cbd95acf --- /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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} 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 + 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..3242d26e389e --- /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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} 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 + 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 ) ); + 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..441d664f7906 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/8d_blocked.js @@ -0,0 +1,461 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-depth, max-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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} 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: +* 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..4894840952c2 --- /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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} 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; From 5d33b18c2d6d1338696fb7b740a00446476c494f Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Fri, 6 Mar 2026 02:32:15 +0200 Subject: [PATCH 18/33] feat: add 9d implementations --- .../@stdlib/ndarray/base/where/lib/9d.js | 370 ++++++++++++ .../ndarray/base/where/lib/9d_accessors.js | 405 ++++++++++++++ .../ndarray/base/where/lib/9d_blocked.js | 495 ++++++++++++++++ .../base/where/lib/9d_blocked_accessors.js | 529 ++++++++++++++++++ 4 files changed, 1799 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/9d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/9d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/9d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/9d_blocked_accessors.js 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..3de33356108e --- /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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} 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 + 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 ]; + 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..7a53dae58ce9 --- /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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} 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 + 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 ) ); + 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..999676886ae9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/9d_blocked.js @@ -0,0 +1,495 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-depth, max-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 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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} 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: +* 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..8323d4e860b9 --- /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 */ + +'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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} 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; From d4450cf9f3706ff6adbeda3c982f0dd35826d0c0 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Fri, 6 Mar 2026 02:44:10 +0200 Subject: [PATCH 19/33] feat: add 10d implementations --- .../@stdlib/ndarray/base/where/lib/10d.js | 392 ++++++++++++ .../ndarray/base/where/lib/10d_accessors.js | 427 +++++++++++++ .../ndarray/base/where/lib/10d_blocked.js | 529 ++++++++++++++++ .../base/where/lib/10d_blocked_accessors.js | 563 ++++++++++++++++++ 4 files changed, 1911 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/10d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/10d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/10d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/10d_blocked_accessors.js 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..bae4921e557e --- /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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} 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 + 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 ]; + 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..dd49701c4cb8 --- /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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} 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 + 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 ) ); + 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..41ed39fc2fb7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/10d_blocked.js @@ -0,0 +1,529 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-depth, max-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 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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} 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: +* 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..a0e84117e473 --- /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 */ + +'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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} 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; From 8af00b1e17ea0c20bd55512ea047a646c9295337 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Fri, 6 Mar 2026 03:25:18 +0200 Subject: [PATCH 20/33] feat: add nd implementations --- .../@stdlib/ndarray/base/where/lib/nd.js | 200 +++++++++++++++ .../ndarray/base/where/lib/nd_accessors.js | 235 ++++++++++++++++++ 2 files changed, 435 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/nd.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/nd_accessors.js 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..20291441e483 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/nd.js @@ -0,0 +1,200 @@ +/** +* @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 {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} 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, 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 ); + 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..931a5134d9a5 --- /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 input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {Object} 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 ) ); + } +} + + +// EXPORTS // + +module.exports = wherend; From afcc970942dba25b80becbbc6ed82e21e838693b Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Fri, 6 Mar 2026 03:29:28 +0200 Subject: [PATCH 21/33] feat(WIP): create main.js and index.js --- .../@stdlib/ndarray/base/where/lib/index.js | 100 ++++ .../@stdlib/ndarray/base/where/lib/main.js | 495 ++++++++++++++++++ 2 files changed, 595 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/lib/main.js 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..76d1cfa1e0ca --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/main.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. +*/ + +'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 iterationOrder = require( '@stdlib/ndarray/base/iteration-order' ); +var strides2order = require( '@stdlib/ndarray/base/strides2order' ); +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 // + +/** +* 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 once 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 +* @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 ) { + 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 ] ); + + // Always reinterpret condition array to uint8 + if ( isBooleanArray(c.data) ) { + c = boolean2uint8(c); + } + + // Check for known array types which can be reinterpreted for better iteration performance... + if ( isBooleanArray( x.data ) && isBooleanArray( y.data ) && isBooleanArray( o.data ) ) { + x = boolean2uint8( x ); + y = boolean2uint8( y ); + o = boolean2uint8( o ); + } else if ( isComplexArray( x.data ) && isComplexArray( y.data ) && isComplexArray( o.data ) ) { + x = complex2real( x ); + y = complex2real( y ); + o = complex2real( o ); + c.shape.push( 2 ); // real and imaginary components + c.strides.push( 0 ); // broadcast + } + // 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 ( (isRealDataType( x.dtype ) && isRealDataType( y.dtype ) ) && isComplexDataType( o.dtype ) ) { + x.accessorProtocol = true; + y.accessorProtocol = true; + x.accessors[ 0 ] = castReturn( x.accessors[ 0 ], 2, complexCtors( String( o.dtype ) ) ); // eslint-disable-line max-len + y.accessors[ 0 ] = castReturn( y.accessors[ 0 ], 2, complexCtors( String( o.dtype ) ) ); // eslint-disable-line max-len + } + // 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 ) { + 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 ) ); + } + // Determine whether we can avoid iteration altogether... + if ( ndims === 0 ) { + if ( c.accessorProtocol || x.accessorProtocol || y.accessorProtocol || o.accessorProtocol ) { + 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 ( c.accessorProtocol || x.accessorProtocol || y.accessorProtocol || o.accessorProtocol ) { + 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 ( x.accessorProtocol || y.accessorProtocol || o.accessorProtocol ) { + 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 ) ) { + // 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 ) ) { + // 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 ) { + oy = xmmv[ 0 ]; + } else { + oy = 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 ( c.accessorProtocol || x.accessorProtocol || y.accessorProtocol || o.accessorProtocol ) { + 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 ( c.accessorProtocol || x.accessorProtocol || y.accessorProtocol || o.accessorProtocol ) { + 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 ( c.accessorProtocol || x.accessorProtocol || y.accessorProtocol || o.accessorProtocol ) { + 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 ( c.accessorProtocol || x.accessorProtocol || y.accessorProtocol || o.accessorProtocol ) { + return accessorwherend( c, x, y, o ); + } + wherend( c, x, y, o ); +} + + +// EXPORTS // + +module.exports = where; From 372165af1972d91c622d858ef39669b82b8bf012 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Sat, 7 Mar 2026 02:43:48 +0200 Subject: [PATCH 22/33] test: add tests --- .../@stdlib/ndarray/base/where/lib/main.js | 4 +- .../ndarray/base/where/test/test.0d.js | 85 + .../ndarray/base/where/test/test.1d.js | 204 ++ .../ndarray/base/where/test/test.2d.js | 1717 +++++++++++++++++ .../@stdlib/ndarray/base/where/test/test.js | 355 ++-- 5 files changed, 2121 insertions(+), 244 deletions(-) create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/test/test.0d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/test/test.1d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/test/test.2d.js diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js index 76d1cfa1e0ca..4f6555039ae1 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js @@ -430,9 +430,9 @@ function where( arrays ) { oc = cmmv[ 1 ]; } if ( iox === 1 ) { - oy = xmmv[ 0 ]; + ox = xmmv[ 0 ]; } else { - oy = xmmv[ 1 ]; + ox = xmmv[ 1 ]; } if ( ioy === 1 ) { oy = ymmv[ 0 ]; 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..09cc2512468b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/test/test.0d.js @@ -0,0 +1,85 @@ +/** +* @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 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 n 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 n 0-dimensional input ndarray to an output ndarray (accessors)', function test( t ) { + var condition; + var out; + var x; + var y; + + condition = ndarray( 'uint8', toAccessorArray( [ 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..4b85b3b39608 --- /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 = [ + 0, + 0, + 0, + 0 + ]; + xbuf = [ + 1.0, + 2.0, + 3.0, + 4.0 + ]; + ybuf = [ + -1.0, + -2.0, + -3.0, + -4.0 + ]; + condition = ndarray( 'generic', toAccessorArray( 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..13162cc922d4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/test/test.2d.js @@ -0,0 +1,1717 @@ +/** +* @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 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 = [ + 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', toAccessorArray( 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 = [ + 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', toAccessorArray( 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 = [ + 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', toAccessorArray( 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 = [ + 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', toAccessorArray( 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 = [ + 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', toAccessorArray( 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', toAccessorArray( 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', toAccessorArray( 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 = [ + 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', toAccessorArray( 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 ); + + 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 = [ + 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 ); + + 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 = [ + 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 ); + + 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 = [ + 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', toAccessorArray( 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 = [ + 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', toAccessorArray( 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', toAccessorArray( 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', toAccessorArray( 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 index 2d245d4f80b5..76fb081a185a 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/test/test.js @@ -21,279 +21,150 @@ // MODULES // var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array/float64' ); -var Uint8Array = require( '@stdlib/array/uint8' ); -var where2d = require( './../lib/2d.js' ); +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 where2d, 'function', 'main export is a function' ); + t.strictEqual( typeof where, 'function', 'main export is a function' ); t.end(); }); -tape( 'the function selects elements from `x` when the condition is truthy, and from `y` otherwise (row-major)', function test( t ) { +tape( 'the function throws an error if provided ndarrays which doesnot have the same shape', function test( t ) { var condition; + var values; var out; var x; var y; - - // All-true condition: output must equal x entirely - condition = { - 'dtype': 'uint8', - 'data': new Uint8Array( [ 1, 1, 1, 1 ] ), - 'shape': [ 2, 2 ], - 'strides': [ 2, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), - 'shape': [ 2, 2 ], - 'strides': [ 2, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - y = { - 'dtype': 'float64', - 'data': new Float64Array( [ 5.0, 6.0, 7.0, 8.0 ] ), - 'shape': [ 2, 2 ], - 'strides': [ 2, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - out = { - 'dtype': 'float64', - 'data': new Float64Array( 4 ), - 'shape': [ 2, 2 ], - 'strides': [ 2, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - - where2d( condition, x, y, out, true ); - - t.strictEqual( out.data[ 0 ], 1.0, 'returns expected value' ); - t.strictEqual( out.data[ 1 ], 2.0, 'returns expected value' ); - t.strictEqual( out.data[ 2 ], 3.0, 'returns expected value' ); - t.strictEqual( out.data[ 3 ], 4.0, 'returns expected value' ); - - // All-false condition: output must equal y entirely - condition.data = new Uint8Array( [ 0, 0, 0, 0 ] ); - out.data = new Float64Array( 4 ); - - where2d( condition, x, y, out, true ); - - t.strictEqual( out.data[ 0 ], 5.0, 'returns expected value' ); - t.strictEqual( out.data[ 1 ], 6.0, 'returns expected value' ); - t.strictEqual( out.data[ 2 ], 7.0, 'returns expected value' ); - t.strictEqual( out.data[ 3 ], 8.0, 'returns expected value' ); - - // Mixed condition: [ 1, 0, 0, 1 ] → [ x0, y1, y2, x3 ] - condition.data = new Uint8Array( [ 1, 0, 0, 1 ] ); - out.data = new Float64Array( 4 ); - - where2d( condition, x, y, out, true ); - - t.strictEqual( out.data[ 0 ], 1.0, 'returns expected value' ); - t.strictEqual( out.data[ 1 ], 6.0, 'returns expected value' ); - t.strictEqual( out.data[ 2 ], 7.0, 'returns expected value' ); - t.strictEqual( out.data[ 3 ], 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function selects elements from `x` when the condition is truthy, and from `y` otherwise (column-major)', function test( t ) { - var condition; - var out; - var x; - var y; - - condition = { - 'dtype': 'uint8', - 'data': new Uint8Array( [ 1, 0, 0, 1 ] ), - 'shape': [ 2, 2 ], - 'strides': [ 1, 2 ], - 'offset': 0, - 'order': 'column-major' - }; - x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), - 'shape': [ 2, 2 ], - 'strides': [ 1, 2 ], - 'offset': 0, - 'order': 'column-major' - }; - y = { - 'dtype': 'float64', - 'data': new Float64Array( [ 5.0, 6.0, 7.0, 8.0 ] ), - 'shape': [ 2, 2 ], - 'strides': [ 1, 2 ], - 'offset': 0, - 'order': 'column-major' - }; - out = { - 'dtype': 'float64', - 'data': new Float64Array( 4 ), - 'shape': [ 2, 2 ], - 'strides': [ 1, 2 ], - 'offset': 0, - 'order': 'column-major' - }; - - where2d( condition, x, y, out, false ); - - t.strictEqual( out.data[ 0 ], 1.0, 'returns expected value' ); - t.strictEqual( out.data[ 1 ], 6.0, 'returns expected value' ); - t.strictEqual( out.data[ 2 ], 7.0, 'returns expected value' ); - t.strictEqual( out.data[ 3 ], 4.0, 'returns expected value' ); - + var i; + + condition = ndarray( 'uint8', [ 1, 0, 0, 1 ], [ 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(); -}); -tape( 'the function supports non-zero offsets', function test( t ) { - var condition; - var out; - var x; - var y; - - condition = { - 'dtype': 'uint8', - 'data': new Uint8Array( [ 1, 0, 1, 0 ] ), - 'shape': [ 2, 2 ], - 'strides': [ 2, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 99.0, 2.0, 3.0, 4.0, 5.0 ] ), - 'shape': [ 2, 2 ], - 'strides': [ 2, 1 ], - 'offset': 1, - 'order': 'row-major' - }; - y = { - 'dtype': 'float64', - 'data': new Float64Array( [ 10.0, 20.0, 30.0, 40.0 ] ), - 'shape': [ 2, 2 ], - 'strides': [ 2, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - out = { - 'dtype': 'float64', - 'data': new Float64Array( 4 ), - 'shape': [ 2, 2 ], - 'strides': [ 2, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - - where2d( condition, x, y, out, true ); - - t.strictEqual( out.data[ 0 ], 2.0, 'returns expected value' ); - t.strictEqual( out.data[ 1 ], 20.0, 'returns expected value' ); - t.strictEqual( out.data[ 2 ], 4.0, 'returns expected value' ); - t.strictEqual( out.data[ 3 ], 40.0, 'returns expected value' ); - - 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 supports non-unit strides', function test( t ) { +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; - condition = { - 'dtype': 'uint8', - 'data': new Uint8Array( [ 0, 1, 1, 0 ] ), - 'shape': [ 2, 2 ], - 'strides': [ 2, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), - 'shape': [ 2, 2 ], - 'strides': [ 4, 1 ], - 'offset': 1, - 'order': 'row-major' - }; - y = { - 'dtype': 'float64', - 'data': new Float64Array( [ 10.0, 20.0, 30.0, 40.0 ] ), - 'shape': [ 2, 2 ], - 'strides': [ 2, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - out = { - 'dtype': 'float64', - 'data': new Float64Array( 4 ), - 'shape': [ 2, 2 ], - 'strides': [ 2, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - - where2d( condition, x, y, out, true ); - - t.strictEqual( out.data[ 0 ], 10.0, 'returns expected value' ); - t.strictEqual( out.data[ 1 ], 3.0, 'returns expected value' ); - t.strictEqual( out.data[ 2 ], 6.0, 'returns expected value' ); - t.strictEqual( out.data[ 3 ], 40.0, 'returns expected value' ); + 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 returns without doing anything when provided a shape with a zero dimension', function test( t ) { +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; - condition = { - 'dtype': 'uint8', - 'data': new Uint8Array( 0 ), - 'shape': [ 0, 2 ], - 'strides': [ 2, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - x = { - 'dtype': 'float64', - 'data': new Float64Array( 0 ), - 'shape': [ 0, 2 ], - 'strides': [ 2, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - y = { - 'dtype': 'float64', - 'data': new Float64Array( 0 ), - 'shape': [ 0, 2 ], - 'strides': [ 2, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - out = { - 'dtype': 'float64', - 'data': new Float64Array( 0 ), - 'shape': [ 0, 2 ], - 'strides': [ 2, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - - where2d( condition, x, y, out, true ); + 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.strictEqual( out.data.length, 0, 'returns expected value' ); t.end(); }); From f5228723e35acf6eec1245b4800c319ca9de69b5 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Sat, 7 Mar 2026 03:36:50 +0200 Subject: [PATCH 23/33] docs: add examples, docs and README.md --- .../@stdlib/ndarray/base/where/README.md | 169 +++++++++++++++++- .../benchmark/benchmark.2d_columnmajor.js | 31 ++-- .../where/benchmark/benchmark.2d_rowmajor.js | 34 ++-- .../@stdlib/ndarray/base/where/docs/repl.txt | 89 +++++++++ .../ndarray/base/where/docs/types/index.d.ts | 76 ++++++++ .../ndarray/base/where/docs/types/test.ts | 59 ++++++ .../ndarray/base/where/examples/index.js | 68 +++++++ .../@stdlib/ndarray/base/where/package.json | 2 + 8 files changed, 493 insertions(+), 35 deletions(-) create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/examples/index.js diff --git a/lib/node_modules/@stdlib/ndarray/base/where/README.md b/lib/node_modules/@stdlib/ndarray/base/where/README.md index 0dc6e4faddad..eefdd4018093 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/where/README.md @@ -20,7 +20,7 @@ limitations under the License. # Where -> Apply a condition to elements in two input ndarrays and assign results to elements in an output ndarray. +> Applies a condition to elements in two input ndarrays and assigns results to elements in an output ndarray.
@@ -30,32 +30,187 @@ limitations under the License.
+## 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, 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 = { + '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 ] +``` + +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 + +- 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' +}; +var x = { + 'dtype': 'generic', + 'data': filledarrayBy( N, 'generic', discreteUniform( 0, 100 ) ), + 'shape': shape, + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}; +var y = { + 'dtype': 'generic', + 'data': filledarrayBy( N, 'generic', discreteUniform( -100, 0 ) ), + 'shape': shape, + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}; +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( condition.data, condition.shape, condition.strides, condition.offset, condition.order ) ); // eslint-disable-line max-len +console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); +console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) ); +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.2d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_columnmajor.js index 277059844f1b..82d76a63dabb 100644 --- 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 @@ -30,6 +30,7 @@ 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' ); @@ -48,22 +49,24 @@ var order = 'column-major'; * @private * @param {PositiveInteger} len - ndarray length * @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} xtype - first input ndarray data type -* @param {string} ytype - second input ndarray data type +* @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, xtype, ytype ) { +function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { var condition; var out; var x; var y; - condition = filledarrayBy( len, 'uint8', bernoulli( 0.5 ) ); + 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, xtype ); + out = filledarray( 0.0, len, otype ); condition = { - 'dtype': 'uint8', + 'dtype': ctype, 'data': condition, 'shape': shape, 'strides': shape2strides( shape, order ), @@ -87,7 +90,7 @@ function createBenchmark( len, shape, xtype, ytype ) { 'order': order }; out = { - 'dtype': xtype, + 'dtype': otype, 'data': out, 'shape': shape, 'strides': shape2strides( shape, order ), @@ -136,6 +139,7 @@ function main() { var sh; var t1; var t2; + var t3; var f; var i; var j; @@ -146,22 +150,23 @@ function main() { for ( j = 0; j < types.length; j++ ) { t1 = types[ j ]; t2 = types[ j ]; + t3 = types[ j ]; for ( i = min; i <= max; i++ ) { len = pow( 10, i ); sh = [ len/2, 2 ]; - f = createBenchmark( len, sh, t1, t2 ); - bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],order='+order+',xtype='+t1+',ytype='+t2, f ); + f = createBenchmark( len, sh, 'uint8', 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, 'uint8', t1, t2, t3 ), f ); sh = [ 2, len/2 ]; - f = createBenchmark( len, sh, t1, t2 ); - bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],order='+order+',xtype='+t1+',ytype='+t2, f ); + f = createBenchmark( len, sh, 'uint8', 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, 'uint8', t1, t2, t3 ), f ); len = floor( sqrt( len ) ); sh = [ len, len ]; len *= len; - f = createBenchmark( len, sh, t1, t2 ); - bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],order='+order+',xtype='+t1+',ytype='+t2, f ); + f = createBenchmark( len, sh, 'uint8', 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, 'uint8', t1, t2, t3 ), f ); } } } 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 index cb5ff0c56e5d..fa3d581c4e0d 100644 --- 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 @@ -30,6 +30,7 @@ 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' ); @@ -37,7 +38,7 @@ var where2d = require( './../lib/2d.js' ); // VARIABLES // var types = [ 'float64' ]; -var order = 'row-major'; +var order = 'column-major'; // FUNCTIONS // @@ -48,23 +49,24 @@ var order = 'row-major'; * @private * @param {PositiveInteger} len - ndarray length * @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} xtype - first input ndarray data type -* @param {string} ytype - second input ndarray data type +* @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, xtype, ytype ) { +function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { var condition; var out; var x; var y; - - condition = filledarrayBy( len, 'uint8', bernoulli( 0.5 ) ); + 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, xtype ); + out = filledarray( 0.0, len, otype ); condition = { - 'dtype': 'uint8', + 'dtype': ctype, 'data': condition, 'shape': shape, 'strides': shape2strides( shape, order ), @@ -88,7 +90,7 @@ function createBenchmark( len, shape, xtype, ytype ) { 'order': order }; out = { - 'dtype': xtype, + 'dtype': otype, 'data': out, 'shape': shape, 'strides': shape2strides( shape, order ), @@ -137,6 +139,7 @@ function main() { var sh; var t1; var t2; + var t3; var f; var i; var j; @@ -147,22 +150,23 @@ function main() { for ( j = 0; j < types.length; j++ ) { t1 = types[ j ]; t2 = types[ j ]; + t3 = types[ j ]; for ( i = min; i <= max; i++ ) { len = pow( 10, i ); sh = [ len/2, 2 ]; - f = createBenchmark( len, sh, t1, t2 ); - bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],order='+order+',xtype='+t1+',ytype='+t2, f ); + f = createBenchmark( len, sh, 'uint8', 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, 'uint8', t1, t2, t3 ), f ); sh = [ 2, len/2 ]; - f = createBenchmark( len, sh, t1, t2 ); - bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],order='+order+',xtype='+t1+',ytype='+t2, f ); + f = createBenchmark( len, sh, 'uint8', 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, 'uint8', t1, t2, t3 ), f ); len = floor( sqrt( len ) ); sh = [ len, len ]; len *= len; - f = createBenchmark( len, sh, t1, t2 ); - bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],order='+order+',xtype='+t1+',ytype='+t2, f ); + f = createBenchmark( len, sh, 'uint8', 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, 'uint8', t1, t2, t3 ), f ); } } } 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..6ad4eed0821b --- /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': dtype, + ... '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..805cda7e9a7d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/docs/types/index.d.ts @@ -0,0 +1,76 @@ +/* +* @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 +* +* @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( 'float64', 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..5846660d5763 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/docs/types/test.ts @@ -0,0 +1,59 @@ +/* +* @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 ] ); + 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..6273a8599825 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/examples/index.js @@ -0,0 +1,68 @@ +/** +* @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' +}; +var x = { + 'dtype': 'generic', + 'data': filledarrayBy( N, 'generic', discreteUniform( 0, 100 ) ), + 'shape': shape, + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}; +var y = { + 'dtype': 'generic', + 'data': filledarrayBy( N, 'generic', discreteUniform( -100, 0 ) ), + 'shape': shape, + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}; +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( condition.data, condition.shape, condition.strides, condition.offset, condition.order ) ); // eslint-disable-line max-len +console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); +console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) ); +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/package.json b/lib/node_modules/@stdlib/ndarray/base/where/package.json index 1e1b24a090b2..68798c41732d 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/package.json +++ b/lib/node_modules/@stdlib/ndarray/base/where/package.json @@ -16,6 +16,8 @@ "main": "./lib", "directories": { "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", "lib": "./lib", "test": "./test" }, From 8fb5a0bb30dad900463ca6ac295a2548e4d7ee14 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Mon, 16 Mar 2026 03:16:39 +0200 Subject: [PATCH 24/33] test: add up to 3d tests and benchmarks --- .../benchmark/benchmark.11d_columnmajor.js | 178 ++ .../where/benchmark/benchmark.11d_rowmajor.js | 178 ++ .../benchmark/benchmark.1d_columnmajor.js | 171 ++ .../where/benchmark/benchmark.1d_rowmajor.js | 171 ++ .../benchmark.2d_blocked_columnmajor.js | 181 ++ .../benchmark.2d_blocked_rowmajor.js | 181 ++ .../benchmark/benchmark.2d_columnmajor.js | 47 +- .../where/benchmark/benchmark.2d_rowmajor.js | 49 +- .../benchmark.2d_rowmajor_accessors.js | 214 ++ ...benchmark.2d_rowmajor_accessors_complex.js | 230 +++ .../benchmark.3d_blocked_columnmajor.js | 179 ++ .../benchmark.3d_blocked_rowmajor.js | 179 ++ .../benchmark/benchmark.3d_columnmajor.js | 179 ++ .../where/benchmark/benchmark.3d_rowmajor.js | 181 ++ .../ndarray/base/where/test/test.3d.js | 1717 +++++++++++++++++ 15 files changed, 3994 insertions(+), 41 deletions(-) create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.11d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.11d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.1d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.1d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_rowmajor_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_rowmajor_accessors_complex.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.3d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.3d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.3d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.3d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/test/test.3d.js 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..d2a92d123d66 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.11d_columnmajor.js @@ -0,0 +1,178 @@ +/** +* @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} xtype - first input ndarray data type +* @param {string} ytype - second input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { + var condition; + var x; + var y; + var out; + + 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..ff7058ec332e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.11d_rowmajor.js @@ -0,0 +1,178 @@ +/** +* @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} xtype - first input ndarray data type +* @param {string} ytype - second input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { + var condition; + var x; + var y; + var out; + + 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..fbe8418a21ee --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.1d_columnmajor.js @@ -0,0 +1,171 @@ +/** +* @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 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..7362564b621d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.1d_rowmajor.js @@ -0,0 +1,171 @@ +/** +* @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 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 index 82d76a63dabb..a011c253cdc6 100644 --- 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 @@ -37,6 +37,7 @@ var where2d = require( './../lib/2d.js' ); // VARIABLES // +var conditionTypes = [ 'uint8' ]; var types = [ 'float64' ]; var order = 'column-major'; @@ -60,6 +61,7 @@ function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { 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 ) ); @@ -140,33 +142,38 @@ function main() { 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 ( j = 0; j < types.length; j++ ) { - t1 = types[ j ]; - t2 = types[ j ]; - t3 = types[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2 ]; - f = createBenchmark( len, sh, 'uint8', 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, 'uint8', t1, t2, t3 ), f ); - - sh = [ 2, len/2 ]; - f = createBenchmark( len, sh, 'uint8', 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, 'uint8', t1, t2, t3 ), f ); - - len = floor( sqrt( len ) ); - sh = [ len, len ]; - len *= len; - f = createBenchmark( len, sh, 'uint8', 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, 'uint8', t1, t2, t3 ), f ); + 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 ); + } } } } 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 index fa3d581c4e0d..4f545e2c3b07 100644 --- 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 @@ -37,8 +37,9 @@ var where2d = require( './../lib/2d.js' ); // VARIABLES // +var conditionTypes = [ 'uint8' ]; var types = [ 'float64' ]; -var order = 'column-major'; +var order = 'row-major'; // FUNCTIONS // @@ -60,6 +61,7 @@ function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { 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 ) ); @@ -140,33 +142,38 @@ function main() { 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 ( j = 0; j < types.length; j++ ) { - t1 = types[ j ]; - t2 = types[ j ]; - t3 = types[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2 ]; - f = createBenchmark( len, sh, 'uint8', 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, 'uint8', t1, t2, t3 ), f ); - - sh = [ 2, len/2 ]; - f = createBenchmark( len, sh, 'uint8', 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, 'uint8', t1, t2, t3 ), f ); - - len = floor( sqrt( len ) ); - sh = [ len, len ]; - len *= len; - f = createBenchmark( len, sh, 'uint8', 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, 'uint8', t1, t2, t3 ), f ); + 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 ); + } } } } 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..8c3a41da3b3a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_rowmajor_accessors.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'; + +// 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..6010c4d5fc00 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_rowmajor_accessors_complex.js @@ -0,0 +1,230 @@ +/** +* @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 ) ); + ybuf = filledarrayBy( len*2, abtype[ ytype ], discreteUniform( -100, 100 ) ); + obuf = filledarray( 0.0, len*2, abtype[ otype ] ); + + stride = shape2strides( shape, order ); + // broadcast extra dimension along last axis for the condition array for complex compatibility. + cshape = [ ...shape, 2 ]; + cstrides = [ ...stride, 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..f43928635451 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.3d_blocked_columnmajor.js @@ -0,0 +1,179 @@ +/** +* @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} xtype - first input ndarray data type +* @param {string} ytype - second input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { + var condition; + var x; + var y; + var out; + + 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..a93128bdfc9f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.3d_blocked_rowmajor.js @@ -0,0 +1,179 @@ +/** +* @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} xtype - first input ndarray data type +* @param {string} ytype - second input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { + var condition; + var x; + var y; + var out; + + 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..8dfa96c2f84d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.3d_columnmajor.js @@ -0,0 +1,179 @@ +/** +* @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} xtype - first input ndarray data type +* @param {string} ytype - second input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { + var condition; + var x; + var y; + var out; + + 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..649aab583d9d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.3d_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.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} xtype - first input ndarray data type +* @param {string} ytype - second input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { + var condition; + var x; + var y; + var out; + + 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 ); + console.log("Finished first benchmark"); + 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/test/test.3d.js b/lib/node_modules/@stdlib/ndarray/base/where/test/test.3d.js new file mode 100644 index 000000000000..4309f8f56b0e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/test/test.3d.js @@ -0,0 +1,1717 @@ +/** +* @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 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 = [ + 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', toAccessorArray( 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 = [ + 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', toAccessorArray( 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 = [ + 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', toAccessorArray( 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 = [ + 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', toAccessorArray( 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 = [ + 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', toAccessorArray( 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', toAccessorArray( 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', toAccessorArray( 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 = [ + 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', toAccessorArray( 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 ); + + 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 = [ + 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 ); + + 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 = [ + 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 ); + + 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 = [ + 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', toAccessorArray( 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 = [ + 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', toAccessorArray( 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', toAccessorArray( 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', toAccessorArray( 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(); +}); From e5a8f91cad0f19d3c0d44ad4f714130d2c29e8e4 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Mon, 16 Mar 2026 03:16:39 +0200 Subject: [PATCH 25/33] test: add up to 3d tests and benchmarks --- .../benchmark/benchmark.11d_columnmajor.js | 180 ++ .../where/benchmark/benchmark.11d_rowmajor.js | 180 ++ .../benchmark/benchmark.1d_columnmajor.js | 169 ++ .../where/benchmark/benchmark.1d_rowmajor.js | 169 ++ .../benchmark.2d_blocked_columnmajor.js | 181 ++ .../benchmark.2d_blocked_rowmajor.js | 181 ++ .../benchmark/benchmark.2d_columnmajor.js | 47 +- .../where/benchmark/benchmark.2d_rowmajor.js | 49 +- .../benchmark.2d_rowmajor_accessors.js | 213 ++ ...benchmark.2d_rowmajor_accessors_complex.js | 231 +++ .../benchmark.3d_blocked_columnmajor.js | 181 ++ .../benchmark.3d_blocked_rowmajor.js | 181 ++ .../benchmark/benchmark.3d_columnmajor.js | 181 ++ .../where/benchmark/benchmark.3d_rowmajor.js | 182 ++ .../ndarray/base/where/test/test.3d.js | 1717 +++++++++++++++++ 15 files changed, 4001 insertions(+), 41 deletions(-) create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.11d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.11d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.1d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.1d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_rowmajor_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.2d_rowmajor_accessors_complex.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.3d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.3d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.3d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/benchmark/benchmark.3d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/where/test/test.3d.js 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 index 82d76a63dabb..a011c253cdc6 100644 --- 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 @@ -37,6 +37,7 @@ var where2d = require( './../lib/2d.js' ); // VARIABLES // +var conditionTypes = [ 'uint8' ]; var types = [ 'float64' ]; var order = 'column-major'; @@ -60,6 +61,7 @@ function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { 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 ) ); @@ -140,33 +142,38 @@ function main() { 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 ( j = 0; j < types.length; j++ ) { - t1 = types[ j ]; - t2 = types[ j ]; - t3 = types[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2 ]; - f = createBenchmark( len, sh, 'uint8', 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, 'uint8', t1, t2, t3 ), f ); - - sh = [ 2, len/2 ]; - f = createBenchmark( len, sh, 'uint8', 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, 'uint8', t1, t2, t3 ), f ); - - len = floor( sqrt( len ) ); - sh = [ len, len ]; - len *= len; - f = createBenchmark( len, sh, 'uint8', 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, 'uint8', t1, t2, t3 ), f ); + 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 ); + } } } } 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 index fa3d581c4e0d..4f545e2c3b07 100644 --- 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 @@ -37,8 +37,9 @@ var where2d = require( './../lib/2d.js' ); // VARIABLES // +var conditionTypes = [ 'uint8' ]; var types = [ 'float64' ]; -var order = 'column-major'; +var order = 'row-major'; // FUNCTIONS // @@ -60,6 +61,7 @@ function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { 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 ) ); @@ -140,33 +142,38 @@ function main() { 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 ( j = 0; j < types.length; j++ ) { - t1 = types[ j ]; - t2 = types[ j ]; - t3 = types[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2 ]; - f = createBenchmark( len, sh, 'uint8', 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, 'uint8', t1, t2, t3 ), f ); - - sh = [ 2, len/2 ]; - f = createBenchmark( len, sh, 'uint8', 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, 'uint8', t1, t2, t3 ), f ); - - len = floor( sqrt( len ) ); - sh = [ len, len ]; - len *= len; - f = createBenchmark( len, sh, 'uint8', 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, 'uint8', t1, t2, t3 ), f ); + 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 ); + } } } } 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..65e43c83d066 --- /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 ) ); + ybuf = filledarrayBy( len*2, abtype[ ytype ], discreteUniform( -100, 100 ) ); + 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/test/test.3d.js b/lib/node_modules/@stdlib/ndarray/base/where/test/test.3d.js new file mode 100644 index 000000000000..4309f8f56b0e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/where/test/test.3d.js @@ -0,0 +1,1717 @@ +/** +* @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 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 = [ + 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', toAccessorArray( 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 = [ + 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', toAccessorArray( 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 = [ + 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', toAccessorArray( 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 = [ + 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', toAccessorArray( 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 = [ + 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', toAccessorArray( 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', toAccessorArray( 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', toAccessorArray( 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 = [ + 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', toAccessorArray( 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 ); + + 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 = [ + 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 ); + + 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 = [ + 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 ); + + 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 = [ + 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', toAccessorArray( 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 = [ + 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', toAccessorArray( 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', toAccessorArray( 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', toAccessorArray( 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(); +}); From 559c59c366c48cbdd2727750d04a684ac89976de Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Tue, 17 Mar 2026 00:43:58 +0200 Subject: [PATCH 26/33] docs: update ndarray/base README.md --- lib/node_modules/@stdlib/ndarray/base/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/node_modules/@stdlib/ndarray/base/README.md b/lib/node_modules/@stdlib/ndarray/base/README.md index cff48beea53c..da7efa4ca4aa 100644 --- a/lib/node_modules/@stdlib/ndarray/base/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/README.md @@ -214,6 +214,7 @@ var o = ns; - [`unary( arrays, fcn )`][@stdlib/ndarray/base/unary]: apply a unary callback to elements in an input ndarray and assign results to elements in an output ndarray. - [`unflattenShape( shape, dim, sizes )`][@stdlib/ndarray/base/unflatten-shape]: expand a dimension over multiple dimensions. - [`vind2bind( shape, strides, offset, order, idx, mode )`][@stdlib/ndarray/base/vind2bind]: convert a linear index in an array view to a linear index in an underlying data buffer. +- [`where( arrays )`][@stdlib/ndarray/base/where]: Applies a condition to elements in two input ndarrays and assigns results to elements in an output ndarray. - [`wrapIndex( idx, max )`][@stdlib/ndarray/base/wrap-index]: wrap an index on the interval `[0,max]`. - [`zerosLike( x )`][@stdlib/ndarray/base/zeros-like]: create a zero-filled ndarray having the same shape and data type as a provided ndarray. - [`zeros( dtype, shape, order )`][@stdlib/ndarray/base/zeros]: create a zero-filled ndarray having a specified shape and data type. @@ -616,6 +617,8 @@ console.log( objectKeys( ns ) ); [@stdlib/ndarray/base/vind2bind]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind +[@stdlib/ndarray/base/where]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/where + [@stdlib/ndarray/base/wrap-index]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/wrap-index [@stdlib/ndarray/base/zeros-like]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/zeros-like From 1205cdcf4ea928f0c71f6b25021d2d2363e7924b Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Tue, 17 Mar 2026 01:35:58 +0200 Subject: [PATCH 27/33] refactor: remove lint warnings --- lib/node_modules/@stdlib/ndarray/base/README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/README.md b/lib/node_modules/@stdlib/ndarray/base/README.md index da7efa4ca4aa..cff48beea53c 100644 --- a/lib/node_modules/@stdlib/ndarray/base/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/README.md @@ -214,7 +214,6 @@ var o = ns; - [`unary( arrays, fcn )`][@stdlib/ndarray/base/unary]: apply a unary callback to elements in an input ndarray and assign results to elements in an output ndarray. - [`unflattenShape( shape, dim, sizes )`][@stdlib/ndarray/base/unflatten-shape]: expand a dimension over multiple dimensions. - [`vind2bind( shape, strides, offset, order, idx, mode )`][@stdlib/ndarray/base/vind2bind]: convert a linear index in an array view to a linear index in an underlying data buffer. -- [`where( arrays )`][@stdlib/ndarray/base/where]: Applies a condition to elements in two input ndarrays and assigns results to elements in an output ndarray. - [`wrapIndex( idx, max )`][@stdlib/ndarray/base/wrap-index]: wrap an index on the interval `[0,max]`. - [`zerosLike( x )`][@stdlib/ndarray/base/zeros-like]: create a zero-filled ndarray having the same shape and data type as a provided ndarray. - [`zeros( dtype, shape, order )`][@stdlib/ndarray/base/zeros]: create a zero-filled ndarray having a specified shape and data type. @@ -617,8 +616,6 @@ console.log( objectKeys( ns ) ); [@stdlib/ndarray/base/vind2bind]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/vind2bind -[@stdlib/ndarray/base/where]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/where - [@stdlib/ndarray/base/wrap-index]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/wrap-index [@stdlib/ndarray/base/zeros-like]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/zeros-like From 3735e430a1cb75e49be96a296bde8eb3377120c7 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Tue, 17 Mar 2026 19:47:03 +0200 Subject: [PATCH 28/33] refactor: apply the requested changes --- .../@stdlib/ndarray/base/where/README.md | 13 ++++--- .../ndarray/base/where/examples/index.js | 9 +++-- .../@stdlib/ndarray/base/where/lib/main.js | 36 +++++++++++++------ 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/where/README.md b/lib/node_modules/@stdlib/ndarray/base/where/README.md index eefdd4018093..0478f18ced03 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/where/README.md @@ -20,7 +20,7 @@ limitations under the License. # Where -> Applies a condition to elements in two input ndarrays and assigns results to elements in an output ndarray. +> Apply a condition to elements in two input ndarrays and assign results to elements in an output ndarray.
@@ -160,6 +160,8 @@ var condition = { '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 ) ), @@ -168,6 +170,8 @@ var x = { '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 ) ), @@ -176,6 +180,8 @@ var y = { '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' ), @@ -186,11 +192,8 @@ var out = { }; where( [ condition, x, y, out ] ); - -console.log( ndarray2array( condition.data, condition.shape, condition.strides, condition.offset, condition.order ) ); // eslint-disable-line max-len -console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); -console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) ); 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/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/where/examples/index.js index 6273a8599825..29d4d9cad23b 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/examples/index.js @@ -36,6 +36,8 @@ var condition = { '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 ) ), @@ -44,6 +46,8 @@ var x = { '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 ) ), @@ -52,6 +56,8 @@ var y = { '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' ), @@ -62,7 +68,4 @@ var out = { }; where( [ condition, x, y, out ] ); -console.log( ndarray2array( condition.data, condition.shape, condition.strides, condition.offset, condition.order ) ); // eslint-disable-line max-len -console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); -console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) ); 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/main.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js index 4f6555039ae1..2db3e3d9b1db 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js @@ -27,6 +27,7 @@ var isComplexArray = require( '@stdlib/array/base/assert/is-complex-typed-array' var isBooleanArray = require( '@stdlib/array/base/assert/is-booleanarray' ); 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' ); @@ -128,7 +129,7 @@ var BLOCKED_ACCESSOR_WHERE = [ blockedaccessorwhere9d, blockedaccessorwhere10d // 8 ]; -var MAX_DIMS = where.length - 1; +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 @@ -140,6 +141,19 @@ var COMPLEX_TO_REAL = { // WARNING: this table needs to be manually updated if w // 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 +* @returns {boolean} boolean indicating whether an ndarray data buffer implements the accessor protocol +*/ +function hasAccessors( x, y, z ) { + return anyIsEntryIn( [ x, y, z ], 'accessorProtocol', true ); +} + /** * Converts a boolean ndarray to an 8-bit unsigned integer ndarray. * @@ -206,7 +220,7 @@ function complex2real( x ) { * - **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 once condition array, two input arrays, and one output array +* @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 * @returns {void} @@ -315,8 +329,8 @@ function where( arrays ) { o = ndarray2object( arrays[ 3 ] ); // Always reinterpret condition array to uint8 - if ( isBooleanArray(c.data) ) { - c = boolean2uint8(c); + if ( isBooleanArray( c.data ) ) { + c = boolean2uint8( c ); } // Check for known array types which can be reinterpreted for better iteration performance... @@ -349,7 +363,7 @@ function where( arrays ) { } // Determine whether we can avoid iteration altogether... if ( ndims === 0 ) { - if ( c.accessorProtocol || x.accessorProtocol || y.accessorProtocol || o.accessorProtocol ) { + if ( hasAccessors( x, y, o ) ) { return ACCESSOR_WHERE[ ndims ]( c, x, y, o ); } return WHERE[ ndims ]( c, x, y, o ); @@ -376,7 +390,7 @@ function where( arrays ) { } // Determine whether the ndarrays are one-dimensional and thus readily translate to one-dimensional strided arrays... if ( ndims === 1 ) { - if ( c.accessorProtocol || x.accessorProtocol || y.accessorProtocol || o.accessorProtocol ) { + if ( hasAccessors( x, y, o ) ) { return ACCESSOR_WHERE[ ndims ]( c, x, y, o ); } return WHERE[ ndims ]( c, x, y, o ); @@ -402,7 +416,7 @@ function where( arrays ) { x.strides = [ sx[i] ]; y.strides = [ sy[i] ]; o.strides = [ so[i] ]; - if ( x.accessorProtocol || y.accessorProtocol || o.accessorProtocol ) { + if ( hasAccessors( x, y, o ) ) { return ACCESSOR_WHERE[ 1 ]( c, x, y, o ); } return WHERE[ 1 ]( c, x, y, o ); @@ -456,7 +470,7 @@ function where( arrays ) { x.offset = ox; y.offset = oy; o.offset = oo; - if ( c.accessorProtocol || x.accessorProtocol || y.accessorProtocol || o.accessorProtocol ) { + if ( hasAccessors( x, y, o ) ) { return ACCESSOR_WHERE[ 1 ]( c, x, y, o ); } return WHERE[ 1 ]( c, x, y, o ); @@ -466,7 +480,7 @@ function where( arrays ) { // 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 ( c.accessorProtocol || x.accessorProtocol || y.accessorProtocol || o.accessorProtocol ) { + if ( hasAccessors( x, y, o ) ) { return ACCESSOR_WHERE[ ndims ]( c, x, y, o, ord === 1 ); } return WHERE[ ndims ]( c, x, y, o, ord === 1 ); @@ -477,13 +491,13 @@ function where( arrays ) { // Determine whether we can perform blocked iteration... if ( ndims <= MAX_DIMS ) { - if ( c.accessorProtocol || x.accessorProtocol || y.accessorProtocol || o.accessorProtocol ) { + if ( hasAccessors( 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 ( c.accessorProtocol || x.accessorProtocol || y.accessorProtocol || o.accessorProtocol ) { + if ( hasAccessors( x, y, o ) ) { return accessorwherend( c, x, y, o ); } wherend( c, x, y, o ); From 72309133d2f0a10cf6a7e6fc02caf5596970e97c Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Wed, 18 Mar 2026 01:07:34 +0200 Subject: [PATCH 29/33] refactor: refactor main.js logic and edge cases handling --- .../@stdlib/ndarray/base/where/README.md | 4 ++ .../@stdlib/ndarray/base/where/docs/repl.txt | 2 +- .../ndarray/base/where/docs/types/index.d.ts | 4 +- .../ndarray/base/where/docs/types/test.ts | 4 +- .../ndarray/base/where/lib/0d_accessors.js | 2 +- .../@stdlib/ndarray/base/where/lib/main.js | 25 +++++--- .../ndarray/base/where/test/test.1d.js | 2 +- .../@stdlib/ndarray/base/where/test/test.js | 61 +++++++++++++++++++ 8 files changed, 92 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/where/README.md b/lib/node_modules/@stdlib/ndarray/base/where/README.md index 0478f18ced03..f66f36aa72e8 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/where/README.md @@ -129,6 +129,10 @@ Each provided ndarray should be an object with the following properties: ## Notes +- `condition` ndarray must be a `boolean` or `uint8` ndarray. +- `condition`, `x`, `y`, and `out` ndarrays must have the same shape. +- `x` and `y` must have the same data type. +- The function **mutates** the input ndarrays shapes and strides if necessary. - 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. diff --git a/lib/node_modules/@stdlib/ndarray/base/where/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/where/docs/repl.txt index 6ad4eed0821b..76ca5f5c4589 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/where/docs/repl.txt @@ -49,7 +49,7 @@ // Using minimal ndarray-like objects... > condition = { - ... 'dtype': dtype, + ... 'dtype': 'uint8', ... 'data': cbuf, ... 'shape': shape, ... 'strides': sc, 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 index 805cda7e9a7d..7bf01a59b97b 100644 --- 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 @@ -29,6 +29,8 @@ import { ndarray } from '@stdlib/types/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 {Error} condition array must be a boolean or uint8 ndarray +* @throws {Error} x and y ndarrays must have the same dtype * * @example * var Float64Array = require( '@stdlib/array/float64' ); @@ -57,7 +59,7 @@ import { ndarray } from '@stdlib/types/ndarray'; * var oo = 0; * * // Create the input and output ndarrays: -* var condition = ndarray( 'float64', cbuf, shape, sc, oc, 'row-major' ); +* 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' ); 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 index 5846660d5763..ce13ebab15d8 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/base/where/docs/types/test.ts @@ -24,7 +24,9 @@ import where = require( './index' ); // The function returns `undefined`... { - const condition = zeros( [ 2, 2 ] ); + const condition = zeros( [ 2, 2 ], { + 'dtype': 'uint8' + }); const x = zeros( [ 2, 2 ] ); const y = zeros( [ 2, 2 ] ); const out = zeros( [ 2, 2 ] ); 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 index 8c28cf1251c4..267f16ef2198 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/0d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/0d_accessors.js @@ -92,7 +92,7 @@ * * // Create the ndarray-like objects: * var condition = { -* 'dtype': 'uint8', +* 'dtype': 'bool', * 'data': cbuf, * 'shape': shape, * 'strides': sc, diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js index 2db3e3d9b1db..a45b92da396b 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js @@ -223,6 +223,8 @@ function complex2real( x ) { * @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 {Error} condition array must be a boolean or uint8 ndarray +* @throws {Error} x and y ndarrays must have the same dtype * @returns {void} * * @example @@ -328,6 +330,14 @@ function where( arrays ) { y = ndarray2object( arrays[ 2 ] ); o = ndarray2object( arrays[ 3 ] ); + if ( !isBooleanArray( c.data ) && c.dtype !== 'bool' && c.dtype !== 'uint8') { + throw new Error( format( 'invalid arguments. Condition array must be a boolean or uint8 ndarray. c.dtype=%s', c.dtype ) ); + } + + if ( x.dtype !== y.dtype ) { + throw new Error( format( 'invalid arguments. Input arrays must have the same data type. x.dtype=%s, y.dtype=%s', x.dtype, y.dtype ) ); + } + // Always reinterpret condition array to uint8 if ( isBooleanArray( c.data ) ) { c = boolean2uint8( c ); @@ -342,6 +352,7 @@ function where( arrays ) { x = complex2real( x ); y = complex2real( y ); o = complex2real( o ); + c.shape.push( 2 ); // real and imaginary components c.strides.push( 0 ); // broadcast } @@ -363,7 +374,7 @@ function where( arrays ) { } // Determine whether we can avoid iteration altogether... if ( ndims === 0 ) { - if ( hasAccessors( x, y, o ) ) { + if ( hasAccessors( c, x, y, o ) ) { return ACCESSOR_WHERE[ ndims ]( c, x, y, o ); } return WHERE[ ndims ]( c, x, y, o ); @@ -390,7 +401,7 @@ function where( arrays ) { } // Determine whether the ndarrays are one-dimensional and thus readily translate to one-dimensional strided arrays... if ( ndims === 1 ) { - if ( hasAccessors( x, y, o ) ) { + if ( hasAccessors( c, x, y, o ) ) { return ACCESSOR_WHERE[ ndims ]( c, x, y, o ); } return WHERE[ ndims ]( c, x, y, o ); @@ -416,7 +427,7 @@ function where( arrays ) { x.strides = [ sx[i] ]; y.strides = [ sy[i] ]; o.strides = [ so[i] ]; - if ( hasAccessors( x, y, o ) ) { + if ( hasAccessors( c, x, y, o ) ) { return ACCESSOR_WHERE[ 1 ]( c, x, y, o ); } return WHERE[ 1 ]( c, x, y, o ); @@ -470,7 +481,7 @@ function where( arrays ) { x.offset = ox; y.offset = oy; o.offset = oo; - if ( hasAccessors( x, y, o ) ) { + if ( hasAccessors( c, x, y, o ) ) { return ACCESSOR_WHERE[ 1 ]( c, x, y, o ); } return WHERE[ 1 ]( c, x, y, o ); @@ -480,7 +491,7 @@ function where( arrays ) { // Determine whether we can use simple nested loops... if ( ndims <= MAX_DIMS ) { // So long as iteration for each respective array always moves in the same direction (i.e., no mixed sign strides), we can leverage cache-optimal (i.e., normal) nested loops without resorting to blocked iteration... - if ( hasAccessors( x, y, o ) ) { + 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 ); @@ -491,13 +502,13 @@ function where( arrays ) { // Determine whether we can perform blocked iteration... if ( ndims <= MAX_DIMS ) { - if ( hasAccessors( x, y, o ) ) { + 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( x, y, o ) ) { + if ( hasAccessors( c, x, y, o ) ) { return accessorwherend( c, x, y, o ); } wherend( c, x, y, o ); 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 index 4b85b3b39608..0647babd239c 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/test/test.1d.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/test/test.1d.js @@ -191,7 +191,7 @@ tape( 'the function conditionally assigns elements from a 1-dimensional input nd -3.0, -4.0 ]; - condition = ndarray( 'generic', toAccessorArray( cbuf ), [ 4 ], [ 1 ], 0, 'row-major' ); + condition = ndarray( 'uint8', toAccessorArray( 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' ); diff --git a/lib/node_modules/@stdlib/ndarray/base/where/test/test.js b/lib/node_modules/@stdlib/ndarray/base/where/test/test.js index 76fb081a185a..9feb7faea48f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/test/test.js @@ -37,6 +37,37 @@ tape( 'main export is a function', function test( t ) { t.end(); }); +tape( 'the function throws an error if provided input ndarrays which doesnot have the same data types', function test( t ) { + var condition; + var values; + var out; + var x; + var y; + var i; + + condition = ndarray( 'uint8', [ 1, 0, 0, 1 ], [ 4 ], [ 1 ], 0, 'row-major' ); + x = ndarray( 'float32', [ 1.0, 2.0, 3.0, 4.0 ], [ 4 ], [ 1 ], 0, 'row-major' ); + out = ndarray( 'generic', zeros( 8, 'generic' ), [ 4 ], [ 1 ], 0, 'row-major' ); + + values = [ + 'float64', + 'complex64', + 'uint8', + 'bool' + ]; + 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() { + y = ndarray( value, [ -1.0, -2.0, -3.0, -4.0 ], [ 4 ], [ 1 ], 0, 'row-major' ); + where( [ condition, x, y, out ] ); + }; + } +}); + tape( 'the function throws an error if provided ndarrays which doesnot have the same shape', function test( t ) { var condition; var values; @@ -68,6 +99,36 @@ tape( 'the function throws an error if provided ndarrays which doesnot have the } }); +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; From 0c3a27cc59ea993c93ac081d47be1308e1e8b7cd Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Wed, 25 Mar 2026 01:46:13 +0200 Subject: [PATCH 30/33] chore: apply requested changes --- .../@stdlib/ndarray/base/where/README.md | 21 +++--- .../@stdlib/ndarray/base/where/docs/repl.txt | 4 +- .../ndarray/base/where/docs/types/index.d.ts | 1 - .../@stdlib/ndarray/base/where/lib/main.js | 53 +++++++++------ .../ndarray/base/where/test/test.0d.js | 7 +- .../ndarray/base/where/test/test.1d.js | 6 +- .../ndarray/base/where/test/test.2d.js | 64 +++++++++---------- .../ndarray/base/where/test/test.3d.js | 64 +++++++++---------- .../@stdlib/ndarray/base/where/test/test.js | 36 ++--------- 9 files changed, 119 insertions(+), 137 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/where/README.md b/lib/node_modules/@stdlib/ndarray/base/where/README.md index f66f36aa72e8..4776ddd936ff 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/where/README.md @@ -47,24 +47,24 @@ 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 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 = [ 4, 4, 1 ]; -var sx = [ 4, 4, 1 ]; -var sy = [ 4, 4, 1 ]; +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 = 1; -var ox = 1; -var oy = 1; +var oc = 0; +var ox = 0; +var oy = 0; var oo = 0; // Create the input and output ndarrays: @@ -105,7 +105,7 @@ var out = { where( [ condition, x, y, out ] ); console.log( out.data ); -// => [ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ] +// => [ 1.0, -2.0, -3.0, 4.0, -5.0, 6.0 ] ``` The function accepts the following arguments: @@ -131,7 +131,6 @@ Each provided ndarray should be an object with the following properties: - `condition` ndarray must be a `boolean` or `uint8` ndarray. - `condition`, `x`, `y`, and `out` ndarrays must have the same shape. -- `x` and `y` must have the same data type. - The function **mutates** the input ndarrays shapes and strides if necessary. - 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. diff --git a/lib/node_modules/@stdlib/ndarray/base/where/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/where/docs/repl.txt index 76ca5f5c4589..09594d8e8d39 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/where/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( arrays ) - Applies a condition to elements in two input ndarrays - and assigns results to elements in an output ndarray. + 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: 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 index 7bf01a59b97b..f7c33111a5bf 100644 --- 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 @@ -30,7 +30,6 @@ import { ndarray } from '@stdlib/types/ndarray'; * @throws arrays must have the same number of dimensions * @throws arrays must have the same shape * @throws {Error} condition array must be a boolean or uint8 ndarray -* @throws {Error} x and y ndarrays must have the same dtype * * @example * var Float64Array = require( '@stdlib/array/float64' ); diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js index a45b92da396b..eb3260f6949c 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js @@ -16,6 +16,8 @@ * limitations under the License. */ +/* eslint-disable max-lines */ + 'use strict'; // MODULES // @@ -25,6 +27,7 @@ var isComplexDataType = require( '@stdlib/ndarray/base/assert/is-complex-floatin 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' ); @@ -148,10 +151,11 @@ var COMPLEX_TO_REAL = { // WARNING: this table needs to be manually updated if w * @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 ) { - return anyIsEntryIn( [ x, y, z ], 'accessorProtocol', true ); +function hasAccessors( x, y, z, w ) { + return anyIsEntryIn( [ x, y, z, w ], 'accessorProtocol', true ); } /** @@ -224,7 +228,6 @@ function complex2real( x ) { * @throws {Error} arrays must have the same number of dimensions * @throws {Error} arrays must have the same shape * @throws {Error} condition array must be a boolean or uint8 ndarray -* @throws {Error} x and y ndarrays must have the same dtype * @returns {void} * * @example @@ -292,7 +295,7 @@ function complex2real( x ) { * console.log( out.data ); * // => [ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ] */ -function where( arrays ) { +function where( arrays ) { // eslint-disable-line max-statements var ndims; var cmmv; var xmmv; @@ -330,12 +333,18 @@ function where( arrays ) { y = ndarray2object( arrays[ 2 ] ); o = ndarray2object( arrays[ 3 ] ); - if ( !isBooleanArray( c.data ) && c.dtype !== 'bool' && c.dtype !== 'uint8') { - throw new Error( format( 'invalid arguments. Condition array must be a boolean or uint8 ndarray. c.dtype=%s', c.dtype ) ); + // 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 ( x.dtype !== y.dtype ) { - throw new Error( format( 'invalid arguments. Input arrays must have the same data type. x.dtype=%s, y.dtype=%s', x.dtype, y.dtype ) ); + if ( !isBooleanArray( c.data ) && !isUint8Array( c.data ) ) { + throw new Error( format( 'invalid arguments. Condition array must be a boolean or uint8 ndarray. c.dtype=%s', c.dtype ) ); } // Always reinterpret condition array to uint8 @@ -344,11 +353,11 @@ function where( arrays ) { } // Check for known array types which can be reinterpreted for better iteration performance... - if ( isBooleanArray( x.data ) && isBooleanArray( y.data ) && isBooleanArray( o.data ) ) { + if ( isBooleanArray( x.data ) && isBooleanArray( y.data ) && isBooleanArray( o.data ) ) { // eslint-disable-line max-len x = boolean2uint8( x ); y = boolean2uint8( y ); o = boolean2uint8( o ); - } else if ( isComplexArray( x.data ) && isComplexArray( y.data ) && isComplexArray( o.data ) ) { + } 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 ); @@ -357,21 +366,23 @@ function where( arrays ) { c.strides.push( 0 ); // broadcast } // 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 ( (isRealDataType( x.dtype ) && isRealDataType( y.dtype ) ) && isComplexDataType( o.dtype ) ) { - x.accessorProtocol = true; - y.accessorProtocol = true; - x.accessors[ 0 ] = castReturn( x.accessors[ 0 ], 2, complexCtors( String( o.dtype ) ) ); // eslint-disable-line max-len - y.accessors[ 0 ] = castReturn( y.accessors[ 0 ], 2, complexCtors( String( o.dtype ) ) ); // eslint-disable-line max-len + 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 + } } - // 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 ) { - 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 ) ); - } + // Determine whether we can avoid iteration altogether... if ( ndims === 0 ) { if ( hasAccessors( c, x, y, o ) ) { @@ -439,7 +450,7 @@ function where( arrays ) { // 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 ) ) { + 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 ); @@ -447,7 +458,7 @@ function where( arrays ) { 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 ) ) { + 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 ]; 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 index 09cc2512468b..9ba478752cec 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/test/test.0d.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/test/test.0d.js @@ -25,6 +25,7 @@ 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' ); @@ -38,7 +39,7 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function assigns elements from n 0-dimensional input ndarray to an output ndarray', function test( t ) { +tape( 'the function assigns elements from a 0-dimensional input ndarray to an output ndarray', function test( t ) { var condition; var expected; var out; @@ -66,13 +67,13 @@ tape( 'the function assigns elements from n 0-dimensional input ndarray to an ou t.end(); }); -tape( 'the function assigns elements from n 0-dimensional input ndarray to an output ndarray (accessors)', function test( t ) { +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', toAccessorArray( [ 1 ] ), [], [ 0 ], 0, 'row-major' ); + 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' ); 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 index 0647babd239c..7c6424f85b69 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/test/test.1d.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/test/test.1d.js @@ -173,12 +173,12 @@ tape( 'the function conditionally assigns elements from a 1-dimensional input nd var x; var y; - cbuf = [ + cbuf = new Uint8Array([ 0, 0, 0, 0 - ]; + ]); xbuf = [ 1.0, 2.0, @@ -191,7 +191,7 @@ tape( 'the function conditionally assigns elements from a 1-dimensional input nd -3.0, -4.0 ]; - condition = ndarray( 'uint8', toAccessorArray( cbuf ), [ 4 ], [ 1 ], 0, 'row-major' ); + 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' ); 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 index 13162cc922d4..6a090312756e 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/test/test.2d.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/test/test.2d.js @@ -123,12 +123,12 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd st = shape2strides( sh, ord ); o = strides2offset( sh, st ); - cbuf = [ + cbuf = new Uint8Array([ 1, 1, 1, 1 - ]; + ]); xbuf = [ 1.0, 2.0, @@ -142,7 +142,7 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd -4.0 ]; - condition = ndarray( 'uint8', toAccessorArray( cbuf ), sh, st, o, ord ); + 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 ); @@ -583,12 +583,12 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd st = shape2strides( sh, ord ); o = strides2offset( sh, st ); - cbuf = [ + cbuf = new Uint8Array([ 1, 1, 1, 1 - ]; + ]); xbuf = [ 1.0, 2.0, @@ -602,7 +602,7 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd -4.0 ]; - condition = ndarray( 'uint8', toAccessorArray( cbuf ), sh, st, o, ord ); + 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 ); @@ -634,12 +634,12 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd st = [ -2, -1 ]; o = strides2offset( sh, st ); - cbuf = [ + cbuf = new Uint8Array([ 1, 1, 1, 1 - ]; + ]); xbuf = [ 1.0, 2.0, @@ -653,7 +653,7 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd -4.0 ]; - condition = ndarray( 'uint8', toAccessorArray( cbuf ), sh, st, o, ord ); + 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 ); @@ -686,7 +686,7 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd st = [ 4, 1 ]; o = strides2offset( sh, st ); - cbuf = [ + cbuf = new Uint8Array([ 1, 1, 1, @@ -695,7 +695,7 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd 1, 1, 1 - ]; + ]); xbuf = [ 1.0, 2.0, @@ -718,7 +718,7 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd ]; obuf = zeros( 8, 'generic' ); - condition = ndarray( 'uint8', toAccessorArray( cbuf ), sh, st, o, ord ); + 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 ); @@ -751,7 +751,7 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd st = [ 4, -1 ]; o = strides2offset( sh, st ); - cbuf = [ + cbuf = new Uint8Array([ 1, 1, 1, @@ -760,7 +760,7 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd 1, 1, 1 - ]; + ]); xbuf = [ 1.0, 2.0, @@ -783,7 +783,7 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd ]; obuf = zeros( 8, 'generic' ); - condition = ndarray( 'uint8', toAccessorArray( cbuf ), sh, st, o, ord ); + 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 ); @@ -826,7 +826,7 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd gfill( numel( sh ), -1.0, ybuf, st[ 1 ] ); obuf = zeros( numel( sh )*2, 'generic' ); - condition = ndarray( 'uint8', toAccessorArray( cbuf ), sh, st, o, ord ); + 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 ); @@ -869,7 +869,7 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd gfill( numel( sh ), -1.0, ybuf, st[ 1 ] ); obuf = zeros( numel( sh )*2, 'generic' ); - condition = ndarray( 'uint8', toAccessorArray( cbuf ), sh, st, o, ord ); + 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 ); @@ -959,12 +959,12 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd st = shape2strides( sh, ord ); o = strides2offset( sh, st ); - cbuf = [ + cbuf = new Uint8Array([ 1, 1, 1, 1 - ]; + ]); xbuf = [ 1.0, 2.0, @@ -978,7 +978,7 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd -4.0 ]; - condition = ndarray( 'uint8', toAccessorArray( cbuf ), sh, st, o, ord ); + 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 ); @@ -1419,12 +1419,12 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd st = shape2strides( sh, ord ); o = strides2offset( sh, st ); - cbuf = [ + cbuf = new Uint8Array([ 1, 1, 1, 1 - ]; + ]); xbuf = [ 1.0, 2.0, @@ -1470,12 +1470,12 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd st = [ -1, -2 ]; o = strides2offset( sh, st ); - cbuf = [ + cbuf = new Uint8Array([ 1, 1, 1, 1 - ]; + ]); xbuf = [ 1.0, 2.0, @@ -1522,7 +1522,7 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd st = [ 1, 4 ]; o = strides2offset( sh, st ); - cbuf = [ + cbuf = new Uint8Array([ 1, 1, 1, @@ -1531,7 +1531,7 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd 1, 1, 1 - ]; + ]); xbuf = [ 1.0, 2.0, @@ -1554,7 +1554,7 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd ]; obuf = zeros( 8, dt ); - condition = ndarray( 'uint8', toAccessorArray( cbuf ), sh, st, o, ord ); + 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 ); @@ -1587,7 +1587,7 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd st = [ 1, -4 ]; o = strides2offset( sh, st ); - cbuf = [ + cbuf = new Uint8Array([ 1, 1, 1, @@ -1596,7 +1596,7 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd 1, 1, 1 - ]; + ]); xbuf = [ 1.0, 2.0, @@ -1619,7 +1619,7 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd ]; obuf = zeros( 8, dt ); - condition = ndarray( 'uint8', toAccessorArray( cbuf ), sh, st, o, ord ); + 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 ); @@ -1662,7 +1662,7 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd gfill( numel( sh ), -1.0, ybuf, st[ 0 ] ); obuf = zeros( numel( sh )*2, dt ); - condition = ndarray( 'uint8', toAccessorArray( cbuf ), sh, st, o, ord ); + 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 ); @@ -1704,7 +1704,7 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd gfill( numel( sh ), -1.0, ybuf, st[ 0 ] ); obuf = zeros( numel( sh )*2, dt ); - condition = ndarray( 'uint8', toAccessorArray( cbuf ), sh, st, o, ord ); + 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 ); 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 index 4309f8f56b0e..59a21f468d73 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/test/test.3d.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/test/test.3d.js @@ -123,12 +123,12 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd st = shape2strides( sh, ord ); o = strides2offset( sh, st ); - cbuf = [ + cbuf = new Uint8Array([ 1, 1, 1, 1 - ]; + ]); xbuf = [ 1.0, 2.0, @@ -142,7 +142,7 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd -4.0 ]; - condition = ndarray( 'uint8', toAccessorArray( cbuf ), sh, st, o, ord ); + 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 ); @@ -583,12 +583,12 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd st = shape2strides( sh, ord ); o = strides2offset( sh, st ); - cbuf = [ + cbuf = new Uint8Array([ 1, 1, 1, 1 - ]; + ]); xbuf = [ 1.0, 2.0, @@ -602,7 +602,7 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd -4.0 ]; - condition = ndarray( 'uint8', toAccessorArray( cbuf ), sh, st, o, ord ); + 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 ); @@ -634,12 +634,12 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd st = [ -2, -2, -1 ]; o = strides2offset( sh, st ); - cbuf = [ + cbuf = new Uint8Array([ 1, 1, 1, 1 - ]; + ]); xbuf = [ 1.0, 2.0, @@ -653,7 +653,7 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd -4.0 ]; - condition = ndarray( 'uint8', toAccessorArray( cbuf ), sh, st, o, ord ); + 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 ); @@ -686,7 +686,7 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd st = [ 4, 2, 1 ]; o = strides2offset( sh, st ); - cbuf = [ + cbuf = new Uint8Array([ 1, 1, 1, @@ -695,7 +695,7 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd 1, 1, 1 - ]; + ]); xbuf = [ 1.0, 2.0, @@ -718,7 +718,7 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd ]; obuf = zeros( 8, 'generic' ); - condition = ndarray( 'uint8', toAccessorArray( cbuf ), sh, st, o, ord ); + 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 ); @@ -751,7 +751,7 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd st = [ 4, -2, 1 ]; o = strides2offset( sh, st ); - cbuf = [ + cbuf = new Uint8Array([ 1, 1, 1, @@ -760,7 +760,7 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd 1, 1, 1 - ]; + ]); xbuf = [ 1.0, 2.0, @@ -783,7 +783,7 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd ]; obuf = zeros( 8, 'generic' ); - condition = ndarray( 'uint8', toAccessorArray( cbuf ), sh, st, o, ord ); + 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 ); @@ -826,7 +826,7 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd gfill( numel( sh ), -1.0, ybuf, st[ 2 ] ); obuf = zeros( numel( sh )*2, 'generic' ); - condition = ndarray( 'uint8', toAccessorArray( cbuf ), sh, st, o, ord ); + 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 ); @@ -869,7 +869,7 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd gfill( numel( sh ), -1.0, ybuf, st[ 2 ] ); obuf = zeros( numel( sh )*2, 'generic' ); - condition = ndarray( 'uint8', toAccessorArray( cbuf ), sh, st, o, ord ); + 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 ); @@ -959,12 +959,12 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd st = shape2strides( sh, ord ); o = strides2offset( sh, st ); - cbuf = [ + cbuf = new Uint8Array([ 1, 1, 1, 1 - ]; + ]); xbuf = [ 1.0, 2.0, @@ -978,7 +978,7 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd -4.0 ]; - condition = ndarray( 'uint8', toAccessorArray( cbuf ), sh, st, o, ord ); + 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 ); @@ -1419,12 +1419,12 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd st = shape2strides( sh, ord ); o = strides2offset( sh, st ); - cbuf = [ + cbuf = new Uint8Array([ 1, 1, 1, 1 - ]; + ]); xbuf = [ 1.0, 2.0, @@ -1470,12 +1470,12 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd st = [ -1, -1, -2 ]; o = strides2offset( sh, st ); - cbuf = [ + cbuf = new Uint8Array([ 1, 1, 1, 1 - ]; + ]); xbuf = [ 1.0, 2.0, @@ -1522,7 +1522,7 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd st = [ 1, 2, 4 ]; o = strides2offset( sh, st ); - cbuf = [ + cbuf = new Uint8Array([ 1, 1, 1, @@ -1531,7 +1531,7 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd 1, 1, 1 - ]; + ]); xbuf = [ 1.0, 2.0, @@ -1554,7 +1554,7 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd ]; obuf = zeros( 8, dt ); - condition = ndarray( 'uint8', toAccessorArray( cbuf ), sh, st, o, ord ); + 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 ); @@ -1587,7 +1587,7 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd st = [ 1, -2, -4 ]; o = strides2offset( sh, st ); - cbuf = [ + cbuf = new Uint8Array([ 1, 1, 1, @@ -1596,7 +1596,7 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd 1, 1, 1 - ]; + ]); xbuf = [ 1.0, 2.0, @@ -1619,7 +1619,7 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd ]; obuf = zeros( 8, dt ); - condition = ndarray( 'uint8', toAccessorArray( cbuf ), sh, st, o, ord ); + 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 ); @@ -1662,7 +1662,7 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd gfill( numel( sh ), -1.0, ybuf, st[ 0 ] ); obuf = zeros( numel( sh )*2, dt ); - condition = ndarray( 'uint8', toAccessorArray( cbuf ), sh, st, o, ord ); + 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 ); @@ -1704,7 +1704,7 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd gfill( numel( sh ), -1.0, ybuf, st[ 0 ] ); obuf = zeros( numel( sh )*2, dt ); - condition = ndarray( 'uint8', toAccessorArray( cbuf ), sh, st, o, ord ); + 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 ); diff --git a/lib/node_modules/@stdlib/ndarray/base/where/test/test.js b/lib/node_modules/@stdlib/ndarray/base/where/test/test.js index 9feb7faea48f..e7bc66566ae6 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/test/test.js @@ -37,46 +37,18 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function throws an error if provided input ndarrays which doesnot have the same data types', function test( t ) { - var condition; - var values; - var out; - var x; - var y; - var i; - - condition = ndarray( 'uint8', [ 1, 0, 0, 1 ], [ 4 ], [ 1 ], 0, 'row-major' ); - x = ndarray( 'float32', [ 1.0, 2.0, 3.0, 4.0 ], [ 4 ], [ 1 ], 0, 'row-major' ); - out = ndarray( 'generic', zeros( 8, 'generic' ), [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - 'float64', - 'complex64', - 'uint8', - 'bool' - ]; - 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() { - y = ndarray( value, [ -1.0, -2.0, -3.0, -4.0 ], [ 4 ], [ 1 ], 0, 'row-major' ); - where( [ condition, x, y, out ] ); - }; - } -}); - tape( 'the function throws an error if provided ndarrays which doesnot have the same shape', function test( t ) { var condition; var values; + var cbuf; var out; var x; var y; var i; - condition = ndarray( 'uint8', [ 1, 0, 0, 1 ], [ 4 ], [ 1 ], 0, 'row-major' ); + 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' ); From 95e9b66b8a1cbd2f84faad9053c8caa7e5c2bb60 Mon Sep 17 00:00:00 2001 From: Loay Ahmed Date: Wed, 25 Mar 2026 18:18:39 +0200 Subject: [PATCH 31/33] Update main.js Co-authored-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Signed-off-by: Loay Ahmed --- lib/node_modules/@stdlib/ndarray/base/where/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js index eb3260f6949c..3cb6b7dbafd7 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js @@ -367,7 +367,7 @@ function where( arrays ) { // eslint-disable-line max-statements } // 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 )) { + if ( isRealDataType( x.dtype ) ) { x.accessorProtocol = true; x.accessors[ 0 ] = castReturn( x.accessors[ 0 ], 2, complexCtors( String( o.dtype ) ) ); // eslint-disable-line max-len } From fb2a747230fe5c8f288064e3f28cd0b3367b2cca Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Wed, 25 Mar 2026 20:02:39 +0200 Subject: [PATCH 32/33] chore: apply requested changes --- .../@stdlib/ndarray/base/where/README.md | 1 - ...benchmark.2d_rowmajor_accessors_complex.js | 6 +-- .../ndarray/base/where/docs/types/index.d.ts | 2 +- .../ndarray/base/where/lib/0d_accessors.js | 4 ++ .../@stdlib/ndarray/base/where/lib/10d.js | 8 ++-- .../ndarray/base/where/lib/10d_accessors.js | 8 ++-- .../ndarray/base/where/lib/10d_blocked.js | 7 ++- .../base/where/lib/10d_blocked_accessors.js | 6 +-- .../@stdlib/ndarray/base/where/lib/1d.js | 40 ++++++++--------- .../ndarray/base/where/lib/1d_accessors.js | 44 ++++++++++--------- .../@stdlib/ndarray/base/where/lib/2d.js | 12 ++--- .../ndarray/base/where/lib/2d_accessors.js | 18 +++++--- .../base/where/lib/2d_blocked_accessors.js | 4 ++ .../@stdlib/ndarray/base/where/lib/3d.js | 4 +- .../ndarray/base/where/lib/3d_accessors.js | 4 +- .../ndarray/base/where/lib/3d_blocked.js | 8 ++-- .../base/where/lib/3d_blocked_accessors.js | 6 +-- .../@stdlib/ndarray/base/where/lib/4d.js | 6 +-- .../ndarray/base/where/lib/4d_accessors.js | 8 ++-- .../ndarray/base/where/lib/4d_blocked.js | 11 +++-- .../base/where/lib/4d_blocked_accessors.js | 10 ++--- .../@stdlib/ndarray/base/where/lib/5d.js | 6 +-- .../ndarray/base/where/lib/5d_accessors.js | 8 ++-- .../ndarray/base/where/lib/5d_blocked.js | 11 +++-- .../base/where/lib/5d_blocked_accessors.js | 10 ++--- .../@stdlib/ndarray/base/where/lib/6d.js | 8 ++-- .../ndarray/base/where/lib/6d_accessors.js | 8 ++-- .../ndarray/base/where/lib/6d_blocked.js | 11 +++-- .../base/where/lib/6d_blocked_accessors.js | 10 ++--- .../@stdlib/ndarray/base/where/lib/7d.js | 4 +- .../ndarray/base/where/lib/7d_accessors.js | 6 +-- .../ndarray/base/where/lib/7d_blocked.js | 15 +++---- .../base/where/lib/7d_blocked_accessors.js | 14 +++--- .../@stdlib/ndarray/base/where/lib/8d.js | 6 +-- .../ndarray/base/where/lib/8d_accessors.js | 8 ++-- .../ndarray/base/where/lib/8d_blocked.js | 5 +-- .../base/where/lib/8d_blocked_accessors.js | 4 +- .../@stdlib/ndarray/base/where/lib/9d.js | 8 ++-- .../ndarray/base/where/lib/9d_accessors.js | 8 ++-- .../ndarray/base/where/lib/9d_blocked.js | 7 ++- .../base/where/lib/9d_blocked_accessors.js | 6 +-- .../@stdlib/ndarray/base/where/lib/main.js | 6 +-- .../@stdlib/ndarray/base/where/lib/nd.js | 17 +++---- .../ndarray/base/where/lib/nd_accessors.js | 6 +-- .../ndarray/base/where/test/test.2d.js | 10 +++-- .../ndarray/base/where/test/test.3d.js | 8 ++-- .../@stdlib/ndarray/base/where/test/test.js | 4 +- 47 files changed, 217 insertions(+), 214 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/where/README.md b/lib/node_modules/@stdlib/ndarray/base/where/README.md index 4776ddd936ff..227f88dde87c 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/where/README.md @@ -131,7 +131,6 @@ Each provided ndarray should be an object with the following properties: - `condition` ndarray must be a `boolean` or `uint8` ndarray. - `condition`, `x`, `y`, and `out` ndarrays must have the same shape. -- The function **mutates** the input ndarrays shapes and strides if necessary. - 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. 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 index 65e43c83d066..6f5220287062 100644 --- 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 @@ -99,11 +99,11 @@ function createBenchmark( len, shape, ctype, xtype, ytype, otype ) { var y; cbuf = filledarrayBy( len, ctype, bernoulli( 0.5 ) ); - xbuf = filledarrayBy( len*2, abtype[ xtype ], discreteUniform( -100, 100 ) ); - ybuf = filledarrayBy( len*2, abtype[ ytype ], discreteUniform( -100, 100 ) ); + 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. + // Broadcast extra dimension along last axis for the condition array for complex compatibility. stride = shape2strides( shape, order ); cshape = shape.slice(); cshape.push( 1 ); 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 index f7c33111a5bf..7594d1962465 100644 --- 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 @@ -29,7 +29,7 @@ import { ndarray } from '@stdlib/types/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 {Error} condition array must be a boolean or uint8 ndarray +* @throws condition array must be a boolean or uint8 ndarray * * @example * var Float64Array = require( '@stdlib/array/float64' ); 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 index 267f16ef2198..9d978e5f01b2 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/0d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/0d_accessors.js @@ -31,6 +31,7 @@ * @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 @@ -38,6 +39,7 @@ * @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 @@ -45,6 +47,7 @@ * @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 @@ -52,6 +55,7 @@ * @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 diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/10d.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/10d.js index bae4921e557e..9a0085a3463f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/10d.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/10d.js @@ -33,14 +33,14 @@ * @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 input ndarray meta data +* @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 input ndarray meta data +* @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 @@ -122,7 +122,7 @@ * 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 +function where10d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements, max-lines-per-function var cbuf; var xbuf; var ybuf; @@ -333,7 +333,7 @@ function where10d( condition, x, y, out, isRowMajor ) { // eslint-disable-line m 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 ]; + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; // eslint-disable-line max-len ic += dc0; ix += dx0; iy += dy0; 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 index dd49701c4cb8..2ff07aaa0632 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/10d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/10d_accessors.js @@ -34,7 +34,7 @@ * @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 input ndarray meta data +* @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 @@ -42,7 +42,7 @@ * @param {NonNegativeInteger} x.offset - index offset * @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) * @param {Array} x.accessors - data buffer accessors -* @param {Object} y - object containing input ndarray meta data +* @param {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 @@ -147,7 +147,7 @@ * var im = imagf( v ); * // returns 2.0 */ -function where10d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements +function where10d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements, max-lines-per-function var cbuf; var xbuf; var ybuf; @@ -368,7 +368,7 @@ function where10d( condition, x, y, out, isRowMajor ) { // eslint-disable-line m 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 ) ); + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len ic += dc0; ix += dx0; iy += dy0; 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 index 41ed39fc2fb7..97d684b4abb0 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/10d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/10d_blocked.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable max-depth, max-len */ +/* eslint-disable max-depth, max-len, max-lines */ 'use strict'; @@ -39,14 +39,14 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 input ndarray meta data +* @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 input ndarray meta data +* @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 @@ -60,7 +60,6 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 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 index a0e84117e473..801472edcbfc 100644 --- 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 @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable max-depth, max-len */ +/* eslint-disable max-depth, max-len, max-lines */ 'use strict'; @@ -40,7 +40,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 input ndarray meta data +* @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 @@ -48,7 +48,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @param {NonNegativeInteger} x.offset - index offset * @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) * @param {Array} x.accessors - data buffer accessors -* @param {Object} y - object containing input ndarray meta data +* @param {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 diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/1d.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/1d.js index 2bbd193c81b1..70e0649a1d04 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/1d.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/1d.js @@ -31,14 +31,14 @@ * @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 input ndarray meta data +* @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 input ndarray meta data +* @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 @@ -61,7 +61,7 @@ * // 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 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: @@ -124,25 +124,23 @@ function where1d( condition, x, y, out ) { var xbuf; var ybuf; var obuf; - var dc0; - var dx0; - var dy0; - var do0; - var S0; + var dout; + var dc; + var dx; + var dy; var ic; var ix; var iy; var io; - var i0; - - // Note on variable naming convention: S#, dc#, dx#, dy#, do#, i# where # corresponds to the loop number, with `0` being the innermost loop... + var S; + var i; // Extract loop variables: dimensions and loop offset (pointer) increments... - S0 = x.shape[ 0 ]; - dc0 = condition.strides[ 0 ]; - dx0 = x.strides[ 0 ]; - dy0 = y.strides[ 0 ]; - do0 = out.strides[ 0 ]; + 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; @@ -157,12 +155,12 @@ function where1d( condition, x, y, out ) { obuf = out.data; // Iterate over the ndarray dimensions... - for ( i0 = 0; i0 < S0; i0++ ) { + for ( i = 0; i < S; i++ ) { obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; - ic += dc0; - ix += dx0; - iy += dy0; - io += do0; + ic += dc; + ix += dx; + iy += dy; + io += dout; } } 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 index eb9a003f0783..af7afc0df3f2 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/1d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/1d_accessors.js @@ -31,20 +31,23 @@ * @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 input ndarray meta data +* @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 {Object} y - object containing input ndarray meta data +* @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 @@ -52,6 +55,7 @@ * @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 @@ -148,25 +152,23 @@ function where1d( condition, x, y, out ) { var getx; var gety; var seto; - var dc0; - var dx0; - var dy0; - var do0; - var S0; + var dout; + var dc; + var dx; + var dy; var ic; var ix; var iy; var io; - var i0; - - // Note on variable naming convention: S#, dc#, dx#, dy#, do#, i# where # corresponds to the loop number, with `0` being the innermost loop... + var i; + var S; // Extract loop variables: dimensions and loop offset (pointer) increments... - S0 = x.shape[ 0 ]; - dc0 = condition.strides[ 0 ]; - dx0 = x.strides[ 0 ]; - dy0 = y.strides[ 0 ]; - do0 = out.strides[ 0 ]; + 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; @@ -180,19 +182,19 @@ function where1d( condition, x, y, out ) { ybuf = y.data; obuf = out.data; - // Cache accessors + // Cache accessors: getc = condition.accessors[ 0 ]; getx = x.accessors[ 0 ]; gety = y.accessors[ 0 ]; seto = out.accessors[ 1 ]; // Iterate over the ndarray dimensions... - for ( i0 = 0; i0 < S0; i0++ ) { + for ( i = 0; i < S; i++ ) { 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 += dc; + ix += dx; + iy += dy; + io += dout; } } diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/2d.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/2d.js index 848b1e7e5bad..6377911b2240 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/2d.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/2d.js @@ -31,14 +31,14 @@ * @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 input ndarray meta data +* @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 input ndarray meta data +* @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 @@ -159,8 +159,8 @@ function where2d( condition, x, y, out, 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 + 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 ]; @@ -171,8 +171,8 @@ function where2d( condition, x, y, out, isRowMajor ) { // 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 + 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 ]; 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 index a34e80e9d1f0..cdae1c4f4d5e 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/2d_accessors.js @@ -31,20 +31,23 @@ * @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 input ndarray meta data +* @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 {Object} y - object containing input ndarray meta data +* @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 @@ -52,6 +55,7 @@ * @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} * @@ -183,8 +187,8 @@ function where2d( condition, x, y, out, 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 + 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 ]; @@ -195,8 +199,8 @@ function where2d( condition, x, y, out, isRowMajor ) { // 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 + 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 ]; @@ -216,7 +220,7 @@ function where2d( condition, x, y, out, isRowMajor ) { ybuf = y.data; obuf = out.data; - // Cache accessors + // Cache accessors: getc = condition.accessors[ 0 ]; getx = x.accessors[ 0 ]; gety = y.accessors[ 0 ]; 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 index 8ee14429f6de..afb16e352854 100644 --- 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 @@ -37,6 +37,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 @@ -44,6 +45,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 @@ -51,6 +53,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 @@ -58,6 +61,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/3d.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/3d.js index a9daa0468938..aa352e68b1fa 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/3d.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/3d.js @@ -31,14 +31,14 @@ * @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 input ndarray meta data +* @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 input ndarray meta data +* @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 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 index 2063cc2d54f9..4cbc4b1f404f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/3d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/3d_accessors.js @@ -32,7 +32,7 @@ * @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 input ndarray meta data +* @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 @@ -40,7 +40,7 @@ * @param {NonNegativeInteger} x.offset - index offset * @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) * @param {Array} x.accessors - data buffer accessors -* @param {Object} y - object containing input ndarray meta data +* @param {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 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 index daee38886601..4627115cdd03 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/3d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/3d_blocked.js @@ -32,21 +32,21 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * 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 ndarray meta data +* @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 input ndarray meta data +* @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 output ndarray meta data +* @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 @@ -126,7 +126,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * console.log( out.data ); * // => [ -2.0, -3.0, 6.0, 7.0, 10.0, 11.0 ] */ -function blockedwhere3d( condition, x, y, out ) { +function blockedwhere3d( condition, x, y, out ) { // eslint-disable-line max-statements var bsize; var cbuf; var xbuf; 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 index 79b82778829e..e8e9f6c0c298 100644 --- 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 @@ -151,7 +151,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * var im = imagf( v ); * // returns 2.0 */ -function blockedwhere3d( condition, x, y, out ) { +function blockedwhere3d( condition, x, y, out ) { // eslint-disable-line max-statements var bsize; var cbuf; var xbuf; @@ -208,7 +208,7 @@ function blockedwhere3d( condition, x, y, out ) { // 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 ); + 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; @@ -297,7 +297,7 @@ function blockedwhere3d( condition, x, y, out ) { 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 ) ); + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len ic += dc0; ix += dx0; iy += dy0; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/4d.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/4d.js index 7e9d72e6f5e1..a00c9de0acdd 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/4d.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/4d.js @@ -31,14 +31,14 @@ * @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 input ndarray meta data +* @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 input ndarray meta data +* @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 @@ -120,7 +120,7 @@ * console.log( out.data ); * // => [ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ] */ -function where4d( condition, x, y, out, isRowMajor ) { +function where4d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements var cbuf; var xbuf; var ybuf; 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 index 71fe05836f99..a881753720cb 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/4d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/4d_accessors.js @@ -32,7 +32,7 @@ * @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 input ndarray meta data +* @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 @@ -40,7 +40,7 @@ * @param {NonNegativeInteger} x.offset - index offset * @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) * @param {Array} x.accessors - data buffer accessors -* @param {Object} y - object containing input ndarray meta data +* @param {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 @@ -144,7 +144,7 @@ * var im = imagf( v ); * // returns 2.0 */ -function where4d( condition, x, y, out, isRowMajor ) { +function where4d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements var cbuf; var xbuf; var ybuf; @@ -263,7 +263,7 @@ function where4d( condition, x, y, out, isRowMajor ) { 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 ) ); + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len ic += dc0; ix += dx0; iy += dy0; 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 index 0d69e5036bf6..dcf7a7b29299 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/4d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/4d_blocked.js @@ -39,14 +39,14 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 input ndarray meta data +* @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 input ndarray meta data +* @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 @@ -60,7 +60,6 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 @@ -128,7 +127,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * console.log( out.data ); * // => [ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ] */ -function blockedwhere4d( condition, x, y, out ) { +function blockedwhere4d( condition, x, y, out ) { // eslint-disable-line max-statements var bsize; var cbuf; var xbuf; @@ -192,7 +191,7 @@ function blockedwhere4d( condition, x, y, out ) { // 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 ); + 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; @@ -292,7 +291,7 @@ function blockedwhere4d( condition, x, y, out ) { 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 ]; + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; // eslint-disable-line max-len ic += dc0; ix += dx0; iy += dy0; 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 index a86b7dfdcfb5..fb3d24d1bd58 100644 --- 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 @@ -40,7 +40,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 input ndarray meta data +* @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 @@ -48,7 +48,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @param {NonNegativeInteger} x.offset - index offset * @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) * @param {Array} x.accessors - data buffer accessors -* @param {Object} y - object containing input ndarray meta data +* @param {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 @@ -152,7 +152,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * var im = imagf( v ); * // returns 2.0 */ -function blockedwhere4d( condition, x, y, out ) { +function blockedwhere4d( condition, x, y, out ) { // eslint-disable-line max-statements var bsize; var cbuf; var xbuf; @@ -220,7 +220,7 @@ function blockedwhere4d( condition, x, y, out ) { // 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 ); + 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; @@ -326,7 +326,7 @@ function blockedwhere4d( condition, x, y, out ) { 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 ) ); + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len ic += dc0; ix += dx0; iy += dy0; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/5d.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/5d.js index a82bda751b06..70a3478e94eb 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/5d.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/5d.js @@ -31,14 +31,14 @@ * @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 input ndarray meta data +* @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 input ndarray meta data +* @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 @@ -120,7 +120,7 @@ * console.log( out.data ); * // => [ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ] */ -function where5d( condition, x, y, out, isRowMajor ) { +function where5d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements var cbuf; var xbuf; var ybuf; 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 index b227d6283d41..32ff030709a4 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/5d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/5d_accessors.js @@ -32,7 +32,7 @@ * @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 input ndarray meta data +* @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 @@ -40,7 +40,7 @@ * @param {NonNegativeInteger} x.offset - index offset * @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) * @param {Array} x.accessors - data buffer accessors -* @param {Object} y - object containing input ndarray meta data +* @param {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 @@ -145,7 +145,7 @@ * var im = imagf( v ); * // returns -2.0 */ -function where5d( condition, x, y, out, isRowMajor ) { +function where5d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements var cbuf; var xbuf; var ybuf; @@ -282,7 +282,7 @@ function where5d( condition, x, y, out, isRowMajor ) { 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 ) ); + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len ic += dc0; ix += dx0; iy += dy0; 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 index 0f4d11cb9d0f..d992fce939aa 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/5d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/5d_blocked.js @@ -39,14 +39,14 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 input ndarray meta data +* @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 input ndarray meta data +* @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 @@ -60,7 +60,6 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 @@ -128,7 +127,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * 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 +function blockedwhere5d( condition, x, y, out ) { // eslint-disable-line max-statements, max-lines-per-function var bsize; var cbuf; var xbuf; @@ -203,7 +202,7 @@ function blockedwhere5d( condition, x, y, out ) { // eslint-disable-line max-sta // 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 ); + 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; @@ -320,7 +319,7 @@ function blockedwhere5d( condition, x, y, out ) { // eslint-disable-line max-sta 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 ]; + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; // eslint-disable-line max-len ic += dc0; ix += dx0; iy += dy0; 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 index cb7b8bd082e9..396086302320 100644 --- 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 @@ -40,7 +40,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 input ndarray meta data +* @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 @@ -48,7 +48,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @param {NonNegativeInteger} x.offset - index offset * @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) * @param {Array} x.accessors - data buffer accessors -* @param {Object} y - object containing input ndarray meta data +* @param {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 @@ -152,7 +152,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * var im = imagf( v ); * // returns 2.0 */ -function blockedwhere5d( condition, x, y, out ) { // eslint-disable-line max-statements +function blockedwhere5d( condition, x, y, out ) { // eslint-disable-line max-statements, max-lines-per-function var bsize; var cbuf; var xbuf; @@ -231,7 +231,7 @@ function blockedwhere5d( condition, x, y, out ) { // eslint-disable-line max-sta // 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 ); + 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; @@ -354,7 +354,7 @@ function blockedwhere5d( condition, x, y, out ) { // eslint-disable-line max-sta 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 ) ); + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len ic += dc0; ix += dx0; iy += dy0; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/6d.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/6d.js index 898fe0af7471..1c169a043353 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/6d.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/6d.js @@ -33,14 +33,14 @@ * @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 input ndarray meta data +* @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 input ndarray meta data +* @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 @@ -122,7 +122,7 @@ * console.log( out.data ); * // => [ -2.0, -3.0, 6.0, 7.0, -10.0, -11.0 ] */ -function where6d( condition, x, y, out, isRowMajor ) { +function where6d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements var cbuf; var xbuf; var ybuf; @@ -265,7 +265,7 @@ function where6d( condition, x, y, out, isRowMajor ) { 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 ]; + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; // eslint-disable-line max-len ic += dc0; ix += dx0; iy += dy0; 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 index f900be2f795e..28bc5aede8e4 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/6d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/6d_accessors.js @@ -34,7 +34,7 @@ * @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 input ndarray meta data +* @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 @@ -42,7 +42,7 @@ * @param {NonNegativeInteger} x.offset - index offset * @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) * @param {Array} x.accessors - data buffer accessors -* @param {Object} y - object containing input ndarray meta data +* @param {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 @@ -147,7 +147,7 @@ * var im = imagf( v ); * // returns 2.0 */ -function where6d( condition, x, y, out, isRowMajor ) { +function where6d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements var cbuf; var xbuf; var ybuf; @@ -300,7 +300,7 @@ function where6d( condition, x, y, out, isRowMajor ) { 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 ) ); + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len ic += dc0; ix += dx0; iy += dy0; 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 index c1bb1500cc5c..342046a04f4f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/6d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/6d_blocked.js @@ -39,14 +39,14 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 input ndarray meta data +* @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 input ndarray meta data +* @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 @@ -60,7 +60,6 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 @@ -128,7 +127,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * 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 +function blockedwhere6d( condition, x, y, out ) { // eslint-disable-line max-statements, max-lines-per-function var bsize; var cbuf; var xbuf; @@ -214,7 +213,7 @@ function blockedwhere6d( condition, x, y, out ) { // eslint-disable-line max-sta // 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 ); + 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; @@ -348,7 +347,7 @@ function blockedwhere6d( condition, x, y, out ) { // eslint-disable-line max-sta 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 ]; + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; // eslint-disable-line max-len ic += dc0; ix += dx0; iy += dy0; 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 index abc75a5936b7..e5c536f2915d 100644 --- 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 @@ -40,7 +40,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 input ndarray meta data +* @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 @@ -48,7 +48,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @param {NonNegativeInteger} x.offset - index offset * @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) * @param {Array} x.accessors - data buffer accessors -* @param {Object} y - object containing input ndarray meta data +* @param {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 @@ -152,7 +152,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * var im = imagf( v ); * // returns 2.0 */ -function blockedwhere6d( condition, x, y, out ) { // eslint-disable-line max-statements +function blockedwhere6d( condition, x, y, out ) { // eslint-disable-line max-statements, max-lines-per-function var bsize; var cbuf; var xbuf; @@ -242,7 +242,7 @@ function blockedwhere6d( condition, x, y, out ) { // eslint-disable-line max-sta // 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 ); + 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; @@ -382,7 +382,7 @@ function blockedwhere6d( condition, x, y, out ) { // eslint-disable-line max-sta 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 ) ); + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len ic += dc0; ix += dx0; iy += dy0; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/7d.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/7d.js index c14ee13125e2..440fa9e3fe55 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/7d.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/7d.js @@ -33,14 +33,14 @@ * @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 input ndarray meta data +* @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 input ndarray meta data +* @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 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 index 6cea86ee3267..6f1a89af8950 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/7d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/7d_accessors.js @@ -34,7 +34,7 @@ * @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 input ndarray meta data +* @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 @@ -42,7 +42,7 @@ * @param {NonNegativeInteger} x.offset - index offset * @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) * @param {Array} x.accessors - data buffer accessors -* @param {Object} y - object containing input ndarray meta data +* @param {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 @@ -317,7 +317,7 @@ function where7d( condition, x, y, out, isRowMajor ) { // eslint-disable-line ma 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 ) ); + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len ic += dc0; ix += dx0; iy += dy0; 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 index 79a397126e83..2d5bdbf78c97 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/7d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/7d_blocked.js @@ -39,14 +39,14 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 input ndarray meta data +* @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 input ndarray meta data +* @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 @@ -60,7 +60,6 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 @@ -128,7 +127,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * 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 +function blockedwhere7d( condition, x, y, out ) { // eslint-disable-line max-statements, max-lines-per-function var bsize; var cbuf; var xbuf; @@ -225,7 +224,7 @@ function blockedwhere7d( condition, x, y, out ) { // eslint-disable-line max-sta // 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 ); + 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; @@ -390,9 +389,9 @@ function blockedwhere7d( condition, x, y, out ) { // eslint-disable-line max-sta 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 ]; + 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; 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 index a943f90b9f18..8dcc9f69ae43 100644 --- 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 @@ -40,7 +40,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 input ndarray meta data +* @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 @@ -48,7 +48,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @param {NonNegativeInteger} x.offset - index offset * @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) * @param {Array} x.accessors - data buffer accessors -* @param {Object} y - object containing input ndarray meta data +* @param {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 @@ -152,7 +152,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * var im = imagf( v ); * // returns 2.0 */ -function blockedwhere7d( condition, x, y, out ) { // eslint-disable-line max-statements +function blockedwhere7d( condition, x, y, out ) { // eslint-disable-line max-statements, max-lines-per-function var bsize; var cbuf; var xbuf; @@ -253,7 +253,7 @@ function blockedwhere7d( condition, x, y, out ) { // eslint-disable-line max-sta // 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 ); + 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; @@ -424,9 +424,9 @@ function blockedwhere7d( condition, x, y, out ) { // eslint-disable-line max-sta 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 ) ); + 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; diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/8d.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/8d.js index 1e81cbd95acf..e062723362ce 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/8d.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/8d.js @@ -33,14 +33,14 @@ * @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 input ndarray meta data +* @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 input ndarray meta data +* @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 @@ -122,7 +122,7 @@ * 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 +function where8d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements, max-lines-per-function var cbuf; var xbuf; var ybuf; 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 index 3242d26e389e..d44f4233af11 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/8d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/8d_accessors.js @@ -34,7 +34,7 @@ * @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 input ndarray meta data +* @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 @@ -42,7 +42,7 @@ * @param {NonNegativeInteger} x.offset - index offset * @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) * @param {Array} x.accessors - data buffer accessors -* @param {Object} y - object containing input ndarray meta data +* @param {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 @@ -147,7 +147,7 @@ * var im = imagf( v ); * // returns 2.0 */ -function where8d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements +function where8d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements, max-lines-per-function var cbuf; var xbuf; var ybuf; @@ -334,7 +334,7 @@ function where8d( condition, x, y, out, isRowMajor ) { // eslint-disable-line ma 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 ) ); + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len ic += dc0; ix += dx0; iy += dy0; 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 index 441d664f7906..fa53b67cb3f9 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/8d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/8d_blocked.js @@ -39,14 +39,14 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 input ndarray meta data +* @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 input ndarray meta data +* @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 @@ -60,7 +60,6 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 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 index 4894840952c2..0bc562789f47 100644 --- 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 @@ -40,7 +40,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 input ndarray meta data +* @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 @@ -48,7 +48,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @param {NonNegativeInteger} x.offset - index offset * @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) * @param {Array} x.accessors - data buffer accessors -* @param {Object} y - object containing input ndarray meta data +* @param {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 diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/9d.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/9d.js index 3de33356108e..31d9f07f364a 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/9d.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/9d.js @@ -33,14 +33,14 @@ * @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 input ndarray meta data +* @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 input ndarray meta data +* @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 @@ -122,7 +122,7 @@ * 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 +function where9d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements, max-lines-per-function var cbuf; var xbuf; var ybuf; @@ -316,7 +316,7 @@ function where9d( condition, x, y, out, isRowMajor ) { // eslint-disable-line ma 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 ]; + obuf[ io ] = ( cbuf[ ic ] ) ? xbuf[ ix ] : ybuf[ iy ]; // eslint-disable-line max-len ic += dc0; ix += dx0; iy += dy0; 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 index 7a53dae58ce9..dd8a36838581 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/9d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/9d_accessors.js @@ -34,7 +34,7 @@ * @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 input ndarray meta data +* @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 @@ -42,7 +42,7 @@ * @param {NonNegativeInteger} x.offset - index offset * @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) * @param {Array} x.accessors - data buffer accessors -* @param {Object} y - object containing input ndarray meta data +* @param {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 @@ -147,7 +147,7 @@ * var im = imagf( v ); * // returns 2.0 */ -function where9d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements +function where9d( condition, x, y, out, isRowMajor ) { // eslint-disable-line max-statements, max-lines-per-function var cbuf; var xbuf; var ybuf; @@ -351,7 +351,7 @@ function where9d( condition, x, y, out, isRowMajor ) { // eslint-disable-line ma 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 ) ); + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len ic += dc0; ix += dx0; iy += dy0; 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 index 999676886ae9..44a4e5d61e96 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/9d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/9d_blocked.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable max-depth, max-len */ +/* eslint-disable max-depth, max-len, max-lines */ 'use strict'; @@ -39,14 +39,14 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 input ndarray meta data +* @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 input ndarray meta data +* @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 @@ -60,7 +60,6 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 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 index 8323d4e860b9..93ccb9cafcc4 100644 --- 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 @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable max-depth, max-len */ +/* eslint-disable max-depth, max-len, max-lines */ 'use strict'; @@ -40,7 +40,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @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 input ndarray meta data +* @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 @@ -48,7 +48,7 @@ var blockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); * @param {NonNegativeInteger} x.offset - index offset * @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) * @param {Array} x.accessors - data buffer accessors -* @param {Object} y - object containing input ndarray meta data +* @param {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 diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js index 3cb6b7dbafd7..0b02e4b1bf2b 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js @@ -227,7 +227,7 @@ function complex2real( x ) { * @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 {Error} condition array must be a boolean or uint8 ndarray +* @throws {TypeError} condition array must be a boolean or uint8 ndarray * @returns {void} * * @example @@ -288,7 +288,7 @@ function complex2real( x ) { * 'offset': oo, * 'order': 'row-major' * }; - +* * // Apply the condition: * where( [ condition, x, y, out ] ); * @@ -344,7 +344,7 @@ function where( arrays ) { // eslint-disable-line max-statements } if ( !isBooleanArray( c.data ) && !isUint8Array( c.data ) ) { - throw new Error( format( 'invalid arguments. Condition array must be a boolean or uint8 ndarray. c.dtype=%s', c.dtype ) ); + throw new TypeError( format( 'invalid arguments. Condition array must be a boolean or uint8 ndarray. c.dtype=%s', c.dtype ) ); } // Always reinterpret condition array to uint8 diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/nd.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/nd.js index 20291441e483..f0316088fd9f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/nd.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/nd.js @@ -24,11 +24,6 @@ var numel = require( '@stdlib/ndarray/base/numel' ); var vind2bind = require( '@stdlib/ndarray/base/vind2bind' ); -// VARIABLES // - -var MODE = 'throw'; - - // MAIN // /** @@ -42,14 +37,14 @@ var MODE = 'throw'; * @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 input ndarray meta data +* @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 input ndarray meta data +* @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 @@ -186,10 +181,10 @@ function wherend( condition, x, y, out ) { // 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 ); + 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 ]; } } 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 index 931a5134d9a5..dec10b812ed8 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/nd_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/nd_accessors.js @@ -43,7 +43,7 @@ var MODE = 'throw'; * @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 input ndarray meta data +* @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 @@ -51,7 +51,7 @@ var MODE = 'throw'; * @param {NonNegativeInteger} x.offset - index offset * @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) * @param {Array} x.accessors - data buffer accessors -* @param {Object} y - object containing input ndarray meta data +* @param {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 @@ -225,7 +225,7 @@ function wherend( condition, x, y, out ) { 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 ) ); + seto( obuf, io, ( getc( cbuf, ic ) ) ? getx( xbuf, ix ) : gety( ybuf, iy ) ); // eslint-disable-line max-len } } 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 index 6a090312756e..40aa5b2bdf28 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/test/test.2d.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/test/test.2d.js @@ -16,6 +16,8 @@ * limitations under the License. */ +/* eslint-disable max-lines */ + 'use strict'; // MODULES // @@ -85,7 +87,7 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd -4.0 ]); - condition = ndarray('uint8', cbuf, sh, st, o, ord); + 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 ); @@ -981,7 +983,7 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd 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 ); + out = ndarray( dt, toAccessorArray( zeros( numel( sh ), dt ) ), sh, st, o, ord ); // eslint-disable-line max-len where( [ condition, x, y, out ] ); @@ -1441,7 +1443,7 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd 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 ); + out = ndarray( dt, toAccessorArray( zeros( numel( sh ), dt ) ), sh, st, o, ord ); // eslint-disable-line max-len where( [ condition, x, y, out ] ); @@ -1492,7 +1494,7 @@ tape( 'the function conditionally assigns elements from a 2-dimensional input nd 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 ); + out = ndarray( dt, toAccessorArray( zeros( numel( sh ), dt ) ), sh, st, o, ord ); // eslint-disable-line max-len where( [ condition, x, y, out ] ); 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 index 59a21f468d73..1cabc58ba915 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/test/test.3d.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/test/test.3d.js @@ -16,6 +16,8 @@ * limitations under the License. */ +/* eslint-disable max-lines */ + 'use strict'; // MODULES // @@ -981,7 +983,7 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd 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 ); + out = ndarray( dt, toAccessorArray( zeros( numel( sh ), dt ) ), sh, st, o, ord ); // eslint-disable-line max-len where( [ condition, x, y, out ] ); @@ -1441,7 +1443,7 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd 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 ); + out = ndarray( dt, toAccessorArray( zeros( numel( sh ), dt ) ), sh, st, o, ord ); // eslint-disable-line max-len where( [ condition, x, y, out ] ); @@ -1492,7 +1494,7 @@ tape( 'the function conditionally assigns elements from a 3-dimensional input nd 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 ); + out = ndarray( dt, toAccessorArray( zeros( numel( sh ), dt ) ), sh, st, o, ord ); // eslint-disable-line max-len where( [ condition, x, y, out ] ); diff --git a/lib/node_modules/@stdlib/ndarray/base/where/test/test.js b/lib/node_modules/@stdlib/ndarray/base/where/test/test.js index e7bc66566ae6..8ea2ed79e00c 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/test/test.js @@ -37,7 +37,7 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function throws an error if provided ndarrays which doesnot have the same shape', function test( t ) { +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; @@ -46,7 +46,7 @@ tape( 'the function throws an error if provided ndarrays which doesnot have the var y; var i; - cbuf = new BooleanArray([ 1, 0, 0, 1 ]); + 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' ); From 56b0665e175fdc2852601789dc09aa9aa71bbcb6 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Mon, 30 Mar 2026 18:30:08 +0200 Subject: [PATCH 33/33] fix: remove always condition array reinterpretation --- .../@stdlib/ndarray/base/where/lib/main.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js index 0b02e4b1bf2b..b51583c4cc38 100644 --- a/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/where/lib/main.js @@ -347,16 +347,15 @@ function where( arrays ) { // eslint-disable-line max-statements throw new TypeError( format( 'invalid arguments. Condition array must be a boolean or uint8 ndarray. c.dtype=%s', c.dtype ) ); } - // Always reinterpret condition array to uint8 - if ( isBooleanArray( c.data ) ) { - c = boolean2uint8( c ); - } - // 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 ); @@ -364,6 +363,10 @@ function where( arrays ) { // eslint-disable-line max-statements 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 ) ) {