From 4f9ea8778e8c9b207e781ff83cbbf22f5f77a809 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 3 May 2026 20:40:02 +0500 Subject: [PATCH 1/2] feat: add ndarray/base/while-each --- .../@stdlib/ndarray/base/while-each/README.md | 200 ++ .../benchmark.10d_blocked_columnmajor.js | 157 ++ .../benchmark.10d_blocked_rowmajor.js | 157 ++ .../benchmark/benchmark.10d_columnmajor.js | 157 ++ .../benchmark/benchmark.10d_rowmajor.js | 157 ++ .../benchmark/benchmark.11d_columnmajor.js | 157 ++ .../benchmark/benchmark.11d_rowmajor.js | 157 ++ .../benchmark/benchmark.1d_columnmajor.js | 146 ++ .../benchmark/benchmark.1d_rowmajor.js | 146 ++ .../benchmark.2d_blocked_columnmajor.js | 158 ++ .../benchmark.2d_blocked_rowmajor.js | 158 ++ .../benchmark/benchmark.2d_columnmajor.js | 158 ++ .../benchmark/benchmark.2d_rowmajor.js | 158 ++ .../benchmark.2d_rowmajor_accessors.js | 184 ++ ...benchmark.2d_rowmajor_accessors_complex.js | 187 ++ .../benchmark.3d_blocked_columnmajor.js | 158 ++ .../benchmark.3d_blocked_rowmajor.js | 158 ++ .../benchmark/benchmark.3d_columnmajor.js | 158 ++ .../benchmark/benchmark.3d_rowmajor.js | 158 ++ .../benchmark.4d_blocked_columnmajor.js | 157 ++ .../benchmark.4d_blocked_rowmajor.js | 157 ++ .../benchmark/benchmark.4d_columnmajor.js | 157 ++ .../benchmark/benchmark.4d_rowmajor.js | 157 ++ .../benchmark.5d_blocked_columnmajor.js | 157 ++ .../benchmark.5d_blocked_rowmajor.js | 157 ++ .../benchmark/benchmark.5d_columnmajor.js | 157 ++ .../benchmark/benchmark.5d_rowmajor.js | 157 ++ .../benchmark.6d_blocked_columnmajor.js | 157 ++ .../benchmark.6d_blocked_rowmajor.js | 157 ++ .../benchmark/benchmark.6d_columnmajor.js | 157 ++ .../benchmark/benchmark.6d_rowmajor.js | 157 ++ .../benchmark.7d_blocked_columnmajor.js | 157 ++ .../benchmark.7d_blocked_rowmajor.js | 157 ++ .../benchmark/benchmark.7d_columnmajor.js | 157 ++ .../benchmark/benchmark.7d_rowmajor.js | 157 ++ .../benchmark.8d_blocked_columnmajor.js | 157 ++ .../benchmark.8d_blocked_rowmajor.js | 157 ++ .../benchmark/benchmark.8d_columnmajor.js | 157 ++ .../benchmark/benchmark.8d_rowmajor.js | 157 ++ .../benchmark.9d_blocked_columnmajor.js | 157 ++ .../benchmark.9d_blocked_rowmajor.js | 157 ++ .../benchmark/benchmark.9d_columnmajor.js | 157 ++ .../benchmark/benchmark.9d_rowmajor.js | 157 ++ .../ndarray/base/while-each/docs/repl.txt | 75 + .../base/while-each/docs/types/index.d.ts | 143 ++ .../base/while-each/docs/types/test.ts | 134 ++ .../ndarray/base/while-each/examples/index.js | 77 + .../@stdlib/ndarray/base/while-each/lib/0d.js | 86 + .../base/while-each/lib/0d_accessors.js | 100 + .../ndarray/base/while-each/lib/10d.js | 224 +++ .../base/while-each/lib/10d_accessors.js | 242 +++ .../base/while-each/lib/10d_blocked.js | 322 ++++ .../while-each/lib/10d_blocked_accessors.js | 340 ++++ .../@stdlib/ndarray/base/while-each/lib/1d.js | 111 ++ .../base/while-each/lib/1d_accessors.js | 129 ++ .../@stdlib/ndarray/base/while-each/lib/2d.js | 142 ++ .../base/while-each/lib/2d_accessors.js | 160 ++ .../ndarray/base/while-each/lib/2d_blocked.js | 168 ++ .../while-each/lib/2d_blocked_accessors.js | 186 ++ .../@stdlib/ndarray/base/while-each/lib/3d.js | 152 ++ .../base/while-each/lib/3d_accessors.js | 170 ++ .../ndarray/base/while-each/lib/3d_blocked.js | 189 ++ .../while-each/lib/3d_blocked_accessors.js | 207 +++ .../@stdlib/ndarray/base/while-each/lib/4d.js | 162 ++ .../base/while-each/lib/4d_accessors.js | 180 ++ .../ndarray/base/while-each/lib/4d_blocked.js | 208 +++ .../while-each/lib/4d_blocked_accessors.js | 226 +++ .../@stdlib/ndarray/base/while-each/lib/5d.js | 172 ++ .../base/while-each/lib/5d_accessors.js | 190 ++ .../ndarray/base/while-each/lib/5d_blocked.js | 227 +++ .../while-each/lib/5d_blocked_accessors.js | 245 +++ .../@stdlib/ndarray/base/while-each/lib/6d.js | 184 ++ .../base/while-each/lib/6d_accessors.js | 202 ++ .../ndarray/base/while-each/lib/6d_blocked.js | 246 +++ .../while-each/lib/6d_blocked_accessors.js | 264 +++ .../@stdlib/ndarray/base/while-each/lib/7d.js | 194 ++ .../base/while-each/lib/7d_accessors.js | 212 +++ .../ndarray/base/while-each/lib/7d_blocked.js | 265 +++ .../while-each/lib/7d_blocked_accessors.js | 283 +++ .../@stdlib/ndarray/base/while-each/lib/8d.js | 204 +++ .../base/while-each/lib/8d_accessors.js | 222 +++ .../ndarray/base/while-each/lib/8d_blocked.js | 284 +++ .../while-each/lib/8d_blocked_accessors.js | 302 +++ .../@stdlib/ndarray/base/while-each/lib/9d.js | 214 +++ .../base/while-each/lib/9d_accessors.js | 232 +++ .../ndarray/base/while-each/lib/9d_blocked.js | 303 +++ .../while-each/lib/9d_blocked_accessors.js | 321 ++++ .../ndarray/base/while-each/lib/index.js | 70 + .../ndarray/base/while-each/lib/main.js | 226 +++ .../@stdlib/ndarray/base/while-each/lib/nd.js | 131 ++ .../base/while-each/lib/nd_accessors.js | 149 ++ .../ndarray/base/while-each/package.json | 66 + .../ndarray/base/while-each/test/test.0d.js | 192 ++ .../ndarray/base/while-each/test/test.1d.js | 321 ++++ .../ndarray/base/while-each/test/test.2d.js | 1470 +++++++++++++++ .../ndarray/base/while-each/test/test.3d.js | 1622 +++++++++++++++++ .../ndarray/base/while-each/test/test.js | 56 + 97 files changed, 20039 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.10d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.10d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.10d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.10d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.11d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.11d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.1d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.1d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.2d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.2d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.2d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.2d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.2d_rowmajor_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.2d_rowmajor_accessors_complex.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.3d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.3d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.3d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.3d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.4d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.4d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.4d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.4d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.5d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.5d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.5d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.5d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.6d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.6d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.6d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.6d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.7d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.7d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.7d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.7d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.8d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.8d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.8d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.8d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.9d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.9d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.9d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.9d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/0d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/0d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/10d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/10d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/10d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/10d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/1d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/1d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/2d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/2d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/2d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/2d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/3d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/3d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/3d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/3d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/4d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/4d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/4d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/4d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/6d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/6d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/6d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/6d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/7d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/7d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/7d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/7d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/8d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/8d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/8d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/8d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/9d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/9d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/9d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/9d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/nd.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/lib/nd_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/test/test.0d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/test/test.1d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/test/test.2d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/test/test.3d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/while-each/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/README.md b/lib/node_modules/@stdlib/ndarray/base/while-each/README.md new file mode 100644 index 000000000000..030411dfe319 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/README.md @@ -0,0 +1,200 @@ + + +# whileEach + +> While a test condition is true, invoke a callback function for each element in an ndarray. + +
+ +
+ + + +
+ +## Usage + +```javascript +var whileEach = require( '@stdlib/ndarray/base/while-each' ); +``` + +#### whileEach( arrays, predicate, fcn\[, thisArg] ) + +While a test condition is true, invokes a callback function for each element in an ndarray. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var naryFunction = require( '@stdlib/utils/nary-function' ); +var log = require( '@stdlib/console/log' ); + +function predicate( value ) { + return value === value; +} + +// Create data buffers: +var xbuf = new Float64Array( 12 ); + +// Define the shape of the array: +var shape = [ 3, 1, 2 ]; + +// Define the array strides: +var sx = [ 4, 4, 1 ]; + +// Define the index offset: +var ox = 1; + +// Create an ndarray-like object: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': shape, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Apply the callback function: +whileEach( [ x ], predicate, naryFunction( log, 1 ) ); +``` + +The function accepts the following arguments: + +- **arrays**: array-like object containing an input ndarray. +- **predicate**: predicate function which determines whether to continue iterating. +- **fcn**: callback to apply. +- **thisArg**: callback execution context. + +Both the predicate function and the callback function are provided the following arguments: + +- **value**: current array element. +- **indices**: current array element indices. +- **arr**: the input ndarray. + +
+ + + +
+ +## Notes + +- The provided ndarray should be an object with the following properties: + + - **dtype**: data type. + - **data**: data buffer. + - **shape**: dimensions. + - **strides**: stride lengths. + - **offset**: index offset. + - **order**: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style). + +- For very high-dimensional ndarrays which are non-contiguous, one should consider copying the underlying data to contiguous memory before applying a callback function in order to achieve better performance. + +
+ + + +
+ +## Examples + + + +```javascript +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var naryFunction = require( '@stdlib/utils/nary-function' ); +var log = require( '@stdlib/console/log' ); +var whileEach = require( '@stdlib/ndarray/base/while-each' ); + +function predicate( value ) { + return value < 6; +} + +var x = { + 'dtype': 'generic', + 'data': zeroTo( 10 ), + 'shape': [ 5, 2 ], + 'strides': [ -2, 1 ], + 'offset': 8, + 'order': 'row-major' +}; + +log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); +whileEach( [ x ], predicate, naryFunction( log, 1 ) ); + +x = { + 'dtype': 'generic', + 'data': zeroTo( 10 ), + 'shape': [ 5, 2 ], + 'strides': [ 1, -5 ], + 'offset': 5, + 'order': 'column-major' +}; + +log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); +whileEach( [ x ], predicate, naryFunction( log, 1 ) ); + +x = { + 'dtype': 'generic', + 'data': zeroTo( 18 ), + 'shape': [ 2, 3, 3 ], + 'strides': [ 9, 3, 1 ], + 'offset': 0, + 'order': 'row-major' +}; + +log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); +whileEach( [ x ], predicate, naryFunction( log, 1 ) ); + +x = { + 'dtype': 'generic', + 'data': zeroTo( 18 ), + 'shape': [ 2, 3, 3 ], + 'strides': [ -1, -2, -6 ], + 'offset': 17, + 'order': 'column-major' +}; + +log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); +whileEach( [ x ], predicate, naryFunction( log, 1 ) ); +``` + +
+ + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.10d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.10d_blocked_columnmajor.js new file mode 100644 index 000000000000..5109b674143c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.10d_blocked_columnmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/10d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/10.0 ) ); + sh = [ len, len, len, len, len, len, len, len, len, len ]; + len *= pow( len, 9 ); + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.10d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.10d_blocked_rowmajor.js new file mode 100644 index 000000000000..af0d1073b222 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.10d_blocked_rowmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/10d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/10.0 ) ); + sh = [ len, len, len, len, len, len, len, len, len, len ]; + len *= pow( len, 9 ); + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.10d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.10d_columnmajor.js new file mode 100644 index 000000000000..72b16595be1e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.10d_columnmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/10d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/10.0 ) ); + sh = [ len, len, len, len, len, len, len, len, len, len ]; + len *= pow( len, 9 ); + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.10d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.10d_rowmajor.js new file mode 100644 index 000000000000..a78cbf6dbe12 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.10d_rowmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/10d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/10.0 ) ); + sh = [ len, len, len, len, len, len, len, len, len, len ]; + len *= pow( len, 9 ); + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.11d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.11d_columnmajor.js new file mode 100644 index 000000000000..9a1787c13b41 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.11d_columnmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/nd.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ 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, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), 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, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.11d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.11d_rowmajor.js new file mode 100644 index 000000000000..6f727be780d1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.11d_rowmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/nd.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ 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, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), 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, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.1d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.1d_columnmajor.js new file mode 100644 index 000000000000..6de1cef60a9d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.1d_columnmajor.js @@ -0,0 +1,146 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( [ x ], predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.1d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.1d_rowmajor.js new file mode 100644 index 000000000000..83ecb82fa8c6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.1d_rowmajor.js @@ -0,0 +1,146 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( [ x ], predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.2d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.2d_blocked_columnmajor.js new file mode 100644 index 000000000000..41d64e95eedc --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.2d_blocked_columnmajor.js @@ -0,0 +1,158 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/2d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.2d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.2d_blocked_rowmajor.js new file mode 100644 index 000000000000..bd7eb0151a75 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.2d_blocked_rowmajor.js @@ -0,0 +1,158 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/2d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.2d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.2d_columnmajor.js new file mode 100644 index 000000000000..0caa1aee7d59 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.2d_columnmajor.js @@ -0,0 +1,158 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/2d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.2d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.2d_rowmajor.js new file mode 100644 index 000000000000..2f3551c022d9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.2d_rowmajor.js @@ -0,0 +1,158 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/2d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.2d_rowmajor_accessors.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.2d_rowmajor_accessors.js new file mode 100644 index 000000000000..1b948d135891 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.2d_rowmajor_accessors.js @@ -0,0 +1,184 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/2d_accessors.js' ); + + +// VARIABLES // + +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; +} + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::accessors:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::accessors:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::accessors:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.2d_rowmajor_accessors_complex.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.2d_rowmajor_accessors_complex.js new file mode 100644 index 000000000000..4235a175b121 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.2d_rowmajor_accessors_complex.js @@ -0,0 +1,187 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ctors = require( '@stdlib/array/typed-complex-ctors' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var realf = require( '@stdlib/complex/float32/real' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/2d_accessors.js' ); + + +// VARIABLES // + +var types = [ 'complex64' ]; +var order = 'row-major'; +var VALUE = new Complex64( 10.0, -10.0 ); + + +// 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 ); +} + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {Complex64} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + var re = realf( value ); + return re === re; +} + +/** +* Returns a constant. +* +* @private +* @returns {number} constant value +*/ +function fcn() { + return VALUE; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var xbuf; + var x; + + xbuf = discreteUniform( len*2, -100, 100 ); + x = { + 'dtype': xtype, + 'data': new ( ctors( xtype ) )( xbuf.buffer ), + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( xbuf[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( xbuf[ 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 f; + var i; + var j; + + min = 1; // 10^min + max = 5; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::accessors:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::accessors:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::accessors:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.3d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.3d_blocked_columnmajor.js new file mode 100644 index 000000000000..ee10104b206e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.3d_blocked_columnmajor.js @@ -0,0 +1,158 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var cbrt = require( '@stdlib/math/base/special/cbrt' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/3d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( cbrt( len ) ); + sh = [ len, len, len ]; + len *= len * len; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.3d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.3d_blocked_rowmajor.js new file mode 100644 index 000000000000..c702c13395a6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.3d_blocked_rowmajor.js @@ -0,0 +1,158 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var cbrt = require( '@stdlib/math/base/special/cbrt' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/3d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( cbrt( len ) ); + sh = [ len, len, len ]; + len *= len * len; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.3d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.3d_columnmajor.js new file mode 100644 index 000000000000..81e2cd82c7a5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.3d_columnmajor.js @@ -0,0 +1,158 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var cbrt = require( '@stdlib/math/base/special/cbrt' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/3d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( cbrt( len ) ); + sh = [ len, len, len ]; + len *= len * len; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.3d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.3d_rowmajor.js new file mode 100644 index 000000000000..5f94f3068e41 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.3d_rowmajor.js @@ -0,0 +1,158 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var cbrt = require( '@stdlib/math/base/special/cbrt' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/3d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( cbrt( len ) ); + sh = [ len, len, len ]; + len *= len * len; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.4d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.4d_blocked_columnmajor.js new file mode 100644 index 000000000000..9d321b871f41 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.4d_blocked_columnmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/4d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/4.0 ) ); + sh = [ len, len, len, len ]; + len *= len * len * len; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.4d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.4d_blocked_rowmajor.js new file mode 100644 index 000000000000..c3d9364338c9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.4d_blocked_rowmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/4d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/4.0 ) ); + sh = [ len, len, len, len ]; + len *= len * len * len; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.4d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.4d_columnmajor.js new file mode 100644 index 000000000000..7721fbab3d69 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.4d_columnmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/4d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/4.0 ) ); + sh = [ len, len, len, len ]; + len *= len * len * len; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.4d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.4d_rowmajor.js new file mode 100644 index 000000000000..3ef11c4689e1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.4d_rowmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/4d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/4.0 ) ); + sh = [ len, len, len, len ]; + len *= len * len * len; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.5d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.5d_blocked_columnmajor.js new file mode 100644 index 000000000000..18bab35a0465 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.5d_blocked_columnmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/5d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/5.0 ) ); + sh = [ len, len, len, len, len ]; + len *= pow( len, 4 ); + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.5d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.5d_blocked_rowmajor.js new file mode 100644 index 000000000000..8602393a5d45 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.5d_blocked_rowmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/5d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/5.0 ) ); + sh = [ len, len, len, len, len ]; + len *= pow( len, 4 ); + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.5d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.5d_columnmajor.js new file mode 100644 index 000000000000..d8946c14b8ee --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.5d_columnmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/5d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/5.0 ) ); + sh = [ len, len, len, len, len ]; + len *= pow( len, 4 ); + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.5d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.5d_rowmajor.js new file mode 100644 index 000000000000..da17e4831c8a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.5d_rowmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/5d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/5.0 ) ); + sh = [ len, len, len, len, len ]; + len *= pow( len, 4 ); + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.6d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.6d_blocked_columnmajor.js new file mode 100644 index 000000000000..047a305e15c3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.6d_blocked_columnmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/6d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/6.0 ) ); + sh = [ len, len, len, len, len, len ]; + len *= pow( len, 5 ); + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.6d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.6d_blocked_rowmajor.js new file mode 100644 index 000000000000..78248911ed12 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.6d_blocked_rowmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/6d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/6.0 ) ); + sh = [ len, len, len, len, len, len ]; + len *= pow( len, 5 ); + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.6d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.6d_columnmajor.js new file mode 100644 index 000000000000..96f091e599fb --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.6d_columnmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/6d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/6.0 ) ); + sh = [ len, len, len, len, len, len ]; + len *= pow( len, 5 ); + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.6d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.6d_rowmajor.js new file mode 100644 index 000000000000..e626915b3975 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.6d_rowmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/6d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/6.0 ) ); + sh = [ len, len, len, len, len, len ]; + len *= pow( len, 5 ); + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.7d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.7d_blocked_columnmajor.js new file mode 100644 index 000000000000..66c6200cc777 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.7d_blocked_columnmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/7d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/7.0 ) ); + sh = [ len, len, len, len, len, len, len ]; + len *= pow( len, 6 ); + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.7d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.7d_blocked_rowmajor.js new file mode 100644 index 000000000000..4a1f66dce77d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.7d_blocked_rowmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/7d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/7.0 ) ); + sh = [ len, len, len, len, len, len, len ]; + len *= pow( len, 6 ); + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.7d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.7d_columnmajor.js new file mode 100644 index 000000000000..3b11d9842698 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.7d_columnmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/7d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/7.0 ) ); + sh = [ len, len, len, len, len, len, len ]; + len *= pow( len, 6 ); + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.7d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.7d_rowmajor.js new file mode 100644 index 000000000000..f7512919c5ad --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.7d_rowmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/7d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/7.0 ) ); + sh = [ len, len, len, len, len, len, len ]; + len *= pow( len, 6 ); + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.8d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.8d_blocked_columnmajor.js new file mode 100644 index 000000000000..1503d5e7b2f8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.8d_blocked_columnmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/8d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/8.0 ) ); + sh = [ len, len, len, len, len, len, len, len ]; + len *= pow( len, 7 ); + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.8d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.8d_blocked_rowmajor.js new file mode 100644 index 000000000000..1503d5e7b2f8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.8d_blocked_rowmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/8d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/8.0 ) ); + sh = [ len, len, len, len, len, len, len, len ]; + len *= pow( len, 7 ); + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.8d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.8d_columnmajor.js new file mode 100644 index 000000000000..b5bbcc5d3915 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.8d_columnmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/8d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/8.0 ) ); + sh = [ len, len, len, len, len, len, len, len ]; + len *= pow( len, 7 ); + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.8d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.8d_rowmajor.js new file mode 100644 index 000000000000..b088d462dae4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.8d_rowmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/8d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/8.0 ) ); + sh = [ len, len, len, len, len, len, len, len ]; + len *= pow( len, 7 ); + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.9d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.9d_blocked_columnmajor.js new file mode 100644 index 000000000000..a2066abd2453 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.9d_blocked_columnmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/9d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/9.0 ) ); + sh = [ len, len, len, len, len, len, len, len, len ]; + len *= pow( len, 8 ); + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.9d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.9d_blocked_rowmajor.js new file mode 100644 index 000000000000..47a7e257190a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.9d_blocked_rowmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/9d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/9.0 ) ); + sh = [ len, len, len, len, len, len, len, len, len ]; + len *= pow( len, 8 ); + f = createBenchmark( len, sh, t1 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.9d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.9d_columnmajor.js new file mode 100644 index 000000000000..cdcbceaa4450 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.9d_columnmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/9d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/9.0 ) ); + sh = [ len, len, len, len, len, len, len, len, len ]; + len *= pow( len, 8 ); + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.9d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.9d_rowmajor.js new file mode 100644 index 000000000000..7004ed4cb249 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/benchmark/benchmark.9d_rowmajor.js @@ -0,0 +1,157 @@ +/** +* @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 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var whileEach = require( './../lib/9d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @returns {boolean} result +*/ +function predicate( value ) { + return value === value; +} + +/** +* Callback invoked for each element in an ndarray. +* +* @private +* @param {number} value - array element +* @throws {Error} unexpected error +*/ +function fcn( value ) { + if ( isnan( value ) ) { + throw new Error( 'unexpected error' ); + } +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, -100, 100 ); + x = { + 'dtype': xtype, + 'data': x, + '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++ ) { + whileEach( x, predicate, fcn ); + if ( isnan( x.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.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 f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + + len = floor( pow( len, 1.0/9.0 ) ); + sh = [ len, len, len, len, len, len, len, len, len ]; + len *= pow( len, 8 ); + f = createBenchmark( len, sh, t1 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join(','), order, t1 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/while-each/docs/repl.txt new file mode 100644 index 000000000000..2ff8f90d5ab5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/docs/repl.txt @@ -0,0 +1,75 @@ + +{{alias}}( arrays, predicate, fcn[, thisArg] ) + While a test condition is true, invokes a callback function for each + element in an ndarray. + + If the predicate function returns a falsy value, the function returns + immediately without invoking the callback function for the current array + element or any subsequent elements. + + A 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). + + Both the predicate function and the callback function are provided the + following arguments: + + - value: current array element. + - indices: current array element indices. + - arr: the input ndarray. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing an input ndarray. + + predicate: Function + Predicate function. + + fcn: Function + Callback function. + + thisArg: any (optional) + Callback function execution context. + + Examples + -------- + // Define ndarray data and meta data... + > var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var dtype = 'float64'; + > var shape = [ 2, 2 ]; + > var sx = [ 2, 1 ]; + > var ox = 0; + > var order = 'row-major'; + + // Define a predicate function... + > function p( v ) { return v < 3.0; }; + + // Define a callback function... + > function f( v ) { if ( v !== v ) { throw new Error( '...' ); } }; + + // Using an ndarray... + > var x = {{alias:@stdlib/ndarray/ctor}}( dtype, xbuf, shape, sx, ox, order ); + > {{alias}}( [ x ], p, f ); + + // Using a minimal ndarray-like object... + > xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > x = { + ... 'dtype': dtype, + ... 'data': xbuf, + ... 'shape': shape, + ... 'strides': sx, + ... 'offset': ox, + ... 'order': order + ... }; + > {{alias}}( [ x ], p, f ); + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/while-each/docs/types/index.d.ts new file mode 100644 index 000000000000..649cd20bb3b2 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/docs/types/index.d.ts @@ -0,0 +1,143 @@ +/* +* @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 { typedndarray } from '@stdlib/types/ndarray'; + +/** +* Callback invoked for each element in an ndarray. +*/ +type Nullary = ( this: ThisArg ) => void; + +/** +* Callback invoked for each element in an ndarray. +* +* @param value - current array element +*/ +type Unary = ( this: ThisArg, value: T ) => void; + +/** +* Callback invoked for each element in an ndarray. +* +* @param value - current array element +* @param indices - current array element indices +*/ +type Binary = ( this: ThisArg, value: T, indices: Array ) => void; + +/** +* Callback invoked for each element in an ndarray. +* +* @param value - current array element +* @param indices - current array element indices +* @param arr - input array +*/ +type Ternary = ( this: ThisArg, value: T, indices: Array, arr: U ) => void; + +/** +* Callback invoked for each element in an ndarray. +* +* @param value - current array element +* @param indices - current array element indices +* @param arr - input array +*/ +type Callback = Nullary | Unary | Binary | Ternary; + +/** +* Predicate function invoked for each element in an ndarray. +*/ +type NullaryPredicate = () => boolean; + +/** +* Predicate function invoked for each element in an ndarray. +* +* @param value - current array element +*/ +type UnaryPredicate = ( value: T ) => boolean; + +/** +* Predicate function invoked for each element in an ndarray. +* +* @param value - current array element +* @param indices - current array element indices +*/ +type BinaryPredicate = ( value: T, indices: Array ) => boolean; + +/** +* Predicate function invoked for each element in an ndarray. +* +* @param value - current array element +* @param indices - current array element indices +* @param arr - input array +*/ +type TernaryPredicate = ( value: T, indices: Array, arr: U ) => boolean; + +/** +* Predicate function invoked for each element in an ndarray. +* +* @param value - current array element +* @param indices - current array element indices +* @param arr - input array +*/ +type Predicate = NullaryPredicate | UnaryPredicate | BinaryPredicate | TernaryPredicate; + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @param arrays - array-like object containing an input ndarray +* @param predicate - predicate function +* @param fcn - callback function +* @param thisArg - callback function execution context +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value === value; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( 12 ); +* +* // Define the shape of the array: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create the input ndarray: +* var x = ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' ); +* +* // Apply the callback function: +* whileEach( [ x ], predicate, naryFunction( log, 1 ) ); +*/ +declare function whileEach = typedndarray, ThisArg = unknown>( arrays: ArrayLike, predicate: Predicate, fcn: Callback, thisArg?: ThisParameterType> ): void; + + +// EXPORTS // + +export = whileEach; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/while-each/docs/types/test.ts new file mode 100644 index 000000000000..ced3b151f0df --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/docs/types/test.ts @@ -0,0 +1,134 @@ +/* +* @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 empty = require( '@stdlib/ndarray/empty' ); +import whileEach = require( './index' ); + +/** +* Predicate function. +* +* @param v - ndarray element +* @returns result +*/ +function predicate( v: any ): boolean { + return v === v; +} + +/** +* Callback function. +* +* @param v - ndarray element +* @throws unexpected error +*/ +function clbk( v: any ): void { + if ( v !== v ) { + throw new Error( 'unexpected error' ); + } +} + + +// TESTS // + +// The function returns `undefined`... +{ + const x = empty( [ 2, 2 ] ); + const arrays = [ x ]; + + whileEach( arrays, predicate, clbk ); // $ExpectType void + whileEach( arrays, predicate, clbk, {} ); // $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... +{ + whileEach( 5, predicate, clbk ); // $ExpectError + whileEach( true, predicate, clbk ); // $ExpectError + whileEach( false, predicate, clbk ); // $ExpectError + whileEach( null, predicate, clbk ); // $ExpectError + whileEach( undefined, predicate, clbk ); // $ExpectError + whileEach( {}, predicate, clbk ); // $ExpectError + whileEach( [ 1 ], predicate, clbk ); // $ExpectError + whileEach( ( x: number ): number => x, predicate, clbk ); // $ExpectError + + whileEach( 5, predicate, clbk, {} ); // $ExpectError + whileEach( true, predicate, clbk, {} ); // $ExpectError + whileEach( false, predicate, clbk, {} ); // $ExpectError + whileEach( null, predicate, clbk, {} ); // $ExpectError + whileEach( undefined, predicate, clbk, {} ); // $ExpectError + whileEach( {}, predicate, clbk, {} ); // $ExpectError + whileEach( [ 1 ], predicate, clbk, {} ); // $ExpectError + whileEach( ( x: number ): number => x, predicate, clbk, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a predicate function... +{ + const x = empty( [ 2, 2 ] ); + const arrays = [ x ]; + + whileEach( arrays, '10', clbk ); // $ExpectError + whileEach( arrays, 5, clbk ); // $ExpectError + whileEach( arrays, true, clbk ); // $ExpectError + whileEach( arrays, false, clbk ); // $ExpectError + whileEach( arrays, null, clbk ); // $ExpectError + whileEach( arrays, undefined, clbk ); // $ExpectError + whileEach( arrays, [], clbk ); // $ExpectError + whileEach( arrays, {}, clbk ); // $ExpectError + + whileEach( arrays, '10', clbk, {} ); // $ExpectError + whileEach( arrays, 5, clbk, {} ); // $ExpectError + whileEach( arrays, true, clbk, {} ); // $ExpectError + whileEach( arrays, false, clbk, {} ); // $ExpectError + whileEach( arrays, null, clbk, {} ); // $ExpectError + whileEach( arrays, undefined, clbk, {} ); // $ExpectError + whileEach( arrays, [], clbk, {} ); // $ExpectError + whileEach( arrays, {}, clbk, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a callback function... +{ + const x = empty( [ 2, 2 ] ); + const arrays = [ x ]; + + whileEach( arrays, predicate, '10' ); // $ExpectError + whileEach( arrays, predicate, 5 ); // $ExpectError + whileEach( arrays, predicate, true ); // $ExpectError + whileEach( arrays, predicate, false ); // $ExpectError + whileEach( arrays, predicate, null ); // $ExpectError + whileEach( arrays, predicate, undefined ); // $ExpectError + whileEach( arrays, predicate, [] ); // $ExpectError + whileEach( arrays, predicate, {} ); // $ExpectError + + whileEach( arrays, predicate, '10', {} ); // $ExpectError + whileEach( arrays, predicate, 5, {} ); // $ExpectError + whileEach( arrays, predicate, true, {} ); // $ExpectError + whileEach( arrays, predicate, false, {} ); // $ExpectError + whileEach( arrays, predicate, null, {} ); // $ExpectError + whileEach( arrays, predicate, undefined, {} ); // $ExpectError + whileEach( arrays, predicate, [], {} ); // $ExpectError + whileEach( arrays, predicate, {}, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = empty( [ 2, 2 ] ); + const arrays = [ x ]; + + whileEach(); // $ExpectError + whileEach( arrays ); // $ExpectError + whileEach( arrays, predicate ); // $ExpectError + whileEach( arrays, predicate, clbk, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/while-each/examples/index.js new file mode 100644 index 000000000000..9846281a3f80 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/examples/index.js @@ -0,0 +1,77 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var naryFunction = require( '@stdlib/utils/nary-function' ); +var log = require( '@stdlib/console/log' ); +var whileEach = require( './../lib' ); + +function predicate( value ) { + return value < 6; +} + +var x = { + 'dtype': 'generic', + 'data': zeroTo( 10 ), + 'shape': [ 5, 2 ], + 'strides': [ -2, 1 ], + 'offset': 8, + 'order': 'row-major' +}; + +log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); +whileEach( [ x ], predicate, naryFunction( log, 2 ) ); + +x = { + 'dtype': 'generic', + 'data': zeroTo( 10 ), + 'shape': [ 5, 2 ], + 'strides': [ 1, -5 ], + 'offset': 5, + 'order': 'column-major' +}; + +log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); +whileEach( [ x ], predicate, naryFunction( log, 2 ) ); + +x = { + 'dtype': 'generic', + 'data': zeroTo( 18 ), + 'shape': [ 2, 3, 3 ], + 'strides': [ 9, 3, 1 ], + 'offset': 0, + 'order': 'row-major' +}; + +log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); +whileEach( [ x ], predicate, naryFunction( log, 2 ) ); + +x = { + 'dtype': 'generic', + 'data': zeroTo( 18 ), + 'shape': [ 2, 3, 3 ], + 'strides': [ -1, -2, -6 ], + 'offset': 17, + 'order': 'column-major' +}; + +log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); +whileEach( [ x ], predicate, naryFunction( log, 2 ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/0d.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/0d.js new file mode 100644 index 000000000000..991c9a36f2bc --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/0d.js @@ -0,0 +1,86 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 2 ); +* +* // Define the shape of the array: +* var shape = []; +* +* // Define the array strides: +* var sx = [ 0 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Apply the callback function: +* whileEach0d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function whileEach0d( x, predicate, fcn, thisArg ) { + var v = x.data[ x.offset ]; + if ( !predicate( v, [], x.ref ) ) { + return; + } + fcn.call( thisArg, v, [], x.ref ); +} + + +// EXPORTS // + +module.exports = whileEach0d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/0d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/0d_accessors.js new file mode 100644 index 000000000000..bc8743304a38 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/0d_accessors.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'; + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* function fcn( value ) { +* log( '%s', value.toString() ); +* } +* +* // Create a data buffer: +* var xbuf = new Complex64Array( 4 ); +* +* // Define the shape of the array: +* var shape = []; +* +* // Define the array strides: +* var sx = [ 0 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the callback function: +* whileEach0d( x, predicate, fcn, {} ); +*/ +function whileEach0d( x, predicate, fcn, thisArg ) { + var v = x.accessors[ 0 ]( x.data, x.offset ); + if ( !predicate( v, [], x.ref ) ) { + return; + } + fcn.call( thisArg, v, [], x.ref ); +} + + +// EXPORTS // + +module.exports = whileEach0d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/10d.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/10d.js new file mode 100644 index 000000000000..11c88a87c0a6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/10d.js @@ -0,0 +1,224 @@ +/** +* @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 strides2order = require( '@stdlib/ndarray/base/strides2order' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var reverse = require( '@stdlib/array/base/reverse' ); +var take = require( '@stdlib/array/base/take-indexed' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 12, 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Apply the callback function: +* whileEach10d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function whileEach10d( x, predicate, fcn, thisArg ) { // eslint-disable-line max-statements + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var dx8; + var dx9; + var idx; + var ind; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var S8; + var S9; + var sx; + var ix; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + var i9; + var v; + + // 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; + sx = x.strides; + idx = zeroTo( sh.length ); + if ( strides2order( sx ) === 1 ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 9 ]; + S1 = sh[ 8 ]; + S2 = sh[ 7 ]; + S3 = sh[ 6 ]; + S4 = sh[ 5 ]; + S5 = sh[ 4 ]; + S6 = sh[ 3 ]; + S7 = sh[ 2 ]; + S8 = sh[ 1 ]; + S9 = sh[ 0 ]; + dx0 = sx[ 9 ]; // offset increment for innermost loop + dx1 = sx[ 8 ] - ( S0*sx[9] ); + dx2 = sx[ 7 ] - ( S1*sx[8] ); + dx3 = sx[ 6 ] - ( S2*sx[7] ); + dx4 = sx[ 5 ] - ( S3*sx[6] ); + dx5 = sx[ 4 ] - ( S4*sx[5] ); + dx6 = sx[ 3 ] - ( S5*sx[4] ); + dx7 = sx[ 2 ] - ( S6*sx[3] ); + dx8 = sx[ 1 ] - ( S7*sx[2] ); + dx9 = sx[ 0 ] - ( S8*sx[1] ); // offset increment for outermost loop + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + S6 = sh[ 6 ]; + S7 = sh[ 7 ]; + S8 = sh[ 8 ]; + S9 = sh[ 9 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); + dx5 = sx[ 5 ] - ( S4*sx[4] ); + dx6 = sx[ 6 ] - ( S5*sx[5] ); + dx7 = sx[ 7 ] - ( S6*sx[6] ); + dx8 = sx[ 8 ] - ( S7*sx[7] ); + dx9 = sx[ 9 ] - ( S8*sx[8] ); // offset increment for outermost loop + idx = reverse( idx ); + } + // Set a pointer to the first indexed element: + ix = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.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++ ) { + v = xbuf[ ix ]; + ind = take( [ i9, i8, i7, i6, i5, i4, i3, i2, i1, i0 ], idx ); // eslint-disable-line max-len + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + ix += dx7; + } + ix += dx8; + } + ix += dx9; + } +} + + +// EXPORTS // + +module.exports = whileEach10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/10d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/10d_accessors.js new file mode 100644 index 000000000000..1e170f493ba3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/10d_accessors.js @@ -0,0 +1,242 @@ +/** +* @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 strides2order = require( '@stdlib/ndarray/base/strides2order' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var reverse = require( '@stdlib/array/base/reverse' ); +var take = require( '@stdlib/array/base/take-indexed' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* function fcn( value ) { +* log( '%s', value.toString() ); +* } +* +* // Create a data buffer: +* var xbuf = new Complex64Array( 12 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 4, 4, 4, 4, 4, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the callback function: +* whileEach10d( x, predicate, fcn, {} ); +*/ +function whileEach10d( x, predicate, fcn, thisArg ) { // eslint-disable-line max-statements + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var dx8; + var dx9; + var idx; + var ind; + var get; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var S8; + var S9; + var sx; + var ix; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + var i9; + var v; + + // 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; + sx = x.strides; + idx = zeroTo( sh.length ); + if ( strides2order( sx ) === 1 ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 9 ]; + S1 = sh[ 8 ]; + S2 = sh[ 7 ]; + S3 = sh[ 6 ]; + S4 = sh[ 5 ]; + S5 = sh[ 4 ]; + S6 = sh[ 3 ]; + S7 = sh[ 2 ]; + S8 = sh[ 1 ]; + S9 = sh[ 0 ]; + dx0 = sx[ 9 ]; // offset increment for innermost loop + dx1 = sx[ 8 ] - ( S0*sx[9] ); + dx2 = sx[ 7 ] - ( S1*sx[8] ); + dx3 = sx[ 6 ] - ( S2*sx[7] ); + dx4 = sx[ 5 ] - ( S3*sx[6] ); + dx5 = sx[ 4 ] - ( S4*sx[5] ); + dx6 = sx[ 3 ] - ( S5*sx[4] ); + dx7 = sx[ 2 ] - ( S6*sx[3] ); + dx8 = sx[ 1 ] - ( S7*sx[2] ); + dx9 = sx[ 0 ] - ( S8*sx[1] ); // offset increment for outermost loop + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + S6 = sh[ 6 ]; + S7 = sh[ 7 ]; + S8 = sh[ 8 ]; + S9 = sh[ 9 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); + dx5 = sx[ 5 ] - ( S4*sx[4] ); + dx6 = sx[ 6 ] - ( S5*sx[5] ); + dx7 = sx[ 7 ] - ( S6*sx[6] ); + dx8 = sx[ 8 ] - ( S7*sx[7] ); + dx9 = sx[ 9 ] - ( S8*sx[8] ); // offset increment for outermost loop + idx = reverse( idx ); + } + // Set a pointer to the first indexed element: + ix = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache accessor: + get = x.accessors[ 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++ ) { + v = get( xbuf, ix ); + ind = take( [ i9, i8, i7, i6, i5, i4, i3, i2, i1, i0 ], idx ); // eslint-disable-line max-len + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + ix += dx7; + } + ix += dx8; + } + ix += dx9; + } +} + + +// EXPORTS // + +module.exports = whileEach10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/10d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/10d_blocked.js new file mode 100644 index 000000000000..f9fb87d31c0f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/10d_blocked.js @@ -0,0 +1,322 @@ +/** +* @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/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var take = require( '@stdlib/array/base/take-indexed' ); +var reverse = require( '@stdlib/array/base/reverse' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 12, 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Apply the callback function: +* blockedwhileEach10d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function blockedwhileEach10d( x, predicate, fcn, thisArg ) { // eslint-disable-line max-statements, max-lines-per-function + var bsize; + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var dx8; + var dx9; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var ox6; + var ox7; + var ox8; + var ox9; + var idx; + var ind; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var s8; + var s9; + var sx; + var ox; + var ix; + 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; + var v; + + // 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( x.shape, x.strides ); + sh = o.sh; + sx = o.sx; + idx = reverse( o.idx ); + + // Determine the block size: + bsize = blockSize( x.dtype ); + + // Set a pointer to the first indexed element: + ox = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache the offset increment for the innermost loop: + dx0 = sx[0]; + + // Iterate over blocks... + for ( j9 = sh[9]; j9 > 0; ) { + if ( j9 < bsize ) { + s9 = j9; + j9 = 0; + } else { + s9 = bsize; + j9 -= bsize; + } + ox9 = ox + ( j9*sx[9] ); + for ( j8 = sh[8]; j8 > 0; ) { + if ( j8 < bsize ) { + s8 = j8; + j8 = 0; + } else { + s8 = bsize; + j8 -= bsize; + } + dx9 = sx[9] - ( s8*sx[8] ); + ox8 = ox9 + ( j8*sx[8] ); + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + dx8 = sx[8] - ( s7*sx[7] ); + ox7 = ox8 + ( j7*sx[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + dx7 = sx[7] - ( s6*sx[6] ); + ox6 = ox7 + ( j6*sx[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dx6 = sx[6] - ( s5*sx[5] ); + ox5 = ox6 + ( j5*sx[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dx5 = sx[5] - ( s4*sx[4] ); + ox4 = ox5 + ( j4*sx[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dx4 = sx[4] - ( s3*sx[3] ); + ox3 = ox4 + ( j3*sx[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + ox2 = ox3 + ( j2*sx[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + ox1 = ox2 + ( j1*sx[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first input ndarray element in the current block: + ix = ox1 + ( j0*sx[0] ); + + // Compute the loop offset increment: + dx1 = sx[1] - ( s0*sx[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++ ) { + v = xbuf[ ix ]; + ind = take( [ j9+i9, j8+i8, j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], idx ); + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + ix += dx7; + } + ix += dx8; + } + ix += dx9; + } + } + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhileEach10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/10d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/10d_blocked_accessors.js new file mode 100644 index 000000000000..93f98a1e8ffa --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/10d_blocked_accessors.js @@ -0,0 +1,340 @@ +/** +* @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/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var take = require( '@stdlib/array/base/take-indexed' ); +var reverse = require( '@stdlib/array/base/reverse' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* function fcn( value ) { +* log( '%s', value.toString() ); +* } +* +* // Create a data buffer: +* var xbuf = new Complex64Array( 8 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 4, 4, 4, 4, 4, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the callback function: +* blockedwhileEach10d( x, predicate, fcn, {} ); +*/ +function blockedwhileEach10d( x, predicate, fcn, thisArg ) { // eslint-disable-line max-statements, max-lines-per-function + var bsize; + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var dx8; + var dx9; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var ox6; + var ox7; + var ox8; + var ox9; + var idx; + var ind; + var get; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var s8; + var s9; + var sx; + var ox; + var ix; + 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; + var v; + + // 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( x.shape, x.strides ); + sh = o.sh; + sx = o.sx; + idx = reverse( o.idx ); + + // Determine the block size: + bsize = blockSize( x.dtype ); + + // Set a pointer to the first indexed element: + ox = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache the offset increment for the innermost loop: + dx0 = sx[0]; + + // Cache accessor: + get = x.accessors[0]; + + // Iterate over blocks... + for ( j9 = sh[9]; j9 > 0; ) { + if ( j9 < bsize ) { + s9 = j9; + j9 = 0; + } else { + s9 = bsize; + j9 -= bsize; + } + ox9 = ox + ( j9*sx[9] ); + for ( j8 = sh[8]; j8 > 0; ) { + if ( j8 < bsize ) { + s8 = j8; + j8 = 0; + } else { + s8 = bsize; + j8 -= bsize; + } + dx9 = sx[9] - ( s8*sx[8] ); + ox8 = ox9 + ( j8*sx[8] ); + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + dx8 = sx[8] - ( s7*sx[7] ); + ox7 = ox8 + ( j7*sx[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + dx7 = sx[7] - ( s6*sx[6] ); + ox6 = ox7 + ( j6*sx[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dx6 = sx[6] - ( s5*sx[5] ); + ox5 = ox6 + ( j5*sx[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dx5 = sx[5] - ( s4*sx[4] ); + ox4 = ox5 + ( j4*sx[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dx4 = sx[4] - ( s3*sx[3] ); + ox3 = ox4 + ( j3*sx[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + ox2 = ox3 + ( j2*sx[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + ox1 = ox2 + ( j1*sx[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first input ndarray element in the current block: + ix = ox1 + ( j0*sx[0] ); + + // Compute the loop offset increment: + dx1 = sx[1] - ( s0*sx[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++ ) { + v = get( xbuf, ix ); + ind = take( [ j9+i9, j8+i8, j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], idx ); + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + ix += dx7; + } + ix += dx8; + } + ix += dx9; + } + } + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhileEach10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/1d.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/1d.js new file mode 100644 index 000000000000..bc81cd34be5a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/1d.js @@ -0,0 +1,111 @@ +/** +* @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 // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 8 ); +* +* // Define the shape of the array: +* var shape = [ 4 ]; +* +* // Define the array strides: +* var sx = [ 2 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Apply the callback function: +* whileEach1d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function whileEach1d( x, predicate, fcn, thisArg ) { + var xbuf; + var dx0; + var ind; + var S0; + var ix; + var i0; + var v; + + // Note on variable naming convention: S#, dx#, 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 ]; + dx0 = x.strides[ 0 ]; + + // Set a pointer to the first indexed element: + ix = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Iterate over the ndarray dimensions... + for ( i0 = 0; i0 < S0; i0++ ) { + v = xbuf[ ix ]; + ind = [ i0 ]; + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } +} + + +// EXPORTS // + +module.exports = whileEach1d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/1d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/1d_accessors.js new file mode 100644 index 000000000000..8b211034e25f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/1d_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 // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* function fcn( value ) { +* log( '%s', value.toString() ); +* } +* +* // Create a data buffer: +* var xbuf = new Complex64Array( 8 ); +* +* // Define the shape of the array: +* var shape = [ 4 ]; +* +* // Define the array strides: +* var sx = [ 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the callback function: +* whileEach1d( x, predicate, fcn, {} ); +*/ +function whileEach1d( x, predicate, fcn, thisArg ) { + var xbuf; + var dx0; + var ind; + var get; + var S0; + var ix; + var i0; + var v; + + // Note on variable naming convention: S#, dx#, dy#, 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 ]; + dx0 = x.strides[ 0 ]; + + // Set a pointer to the first indexed element: + ix = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache accessor: + get = x.accessors[ 0 ]; + + // Iterate over the ndarray dimensions... + for ( i0 = 0; i0 < S0; i0++ ) { + v = get( xbuf, ix ); + ind = [ i0 ]; + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } +} + + +// EXPORTS // + +module.exports = whileEach1d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/2d.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/2d.js new file mode 100644 index 000000000000..02d8a87c7f35 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/2d.js @@ -0,0 +1,142 @@ +/** +* @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 strides2order = require( '@stdlib/ndarray/base/strides2order' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var reverse = require( '@stdlib/array/base/reverse' ); +var take = require( '@stdlib/array/base/take-indexed' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 8 ); +* +* // Define the shape of the array: +* var shape = [ 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Apply the callback function: +* whileEach2d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function whileEach2d( x, predicate, fcn, thisArg ) { + var xbuf; + var dx0; + var dx1; + var idx; + var ind; + var sh; + var S0; + var S1; + var sx; + var ix; + var i0; + var i1; + var v; + + // 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; + sx = x.strides; + idx = zeroTo( sh.length ); + if ( strides2order( sx ) === 1 ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 1 ]; + S1 = sh[ 0 ]; + dx0 = sx[ 1 ]; // offset increment for innermost loop + dx1 = sx[ 0 ] - ( S0*sx[1] ); // offset increment for outermost loop + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); // offset increment for outermost loop + idx = reverse( idx ); + } + // Set a pointer to the first indexed element: + ix = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Iterate over the ndarray dimensions... + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + v = xbuf[ ix ]; + ind = take( [ i1, i0 ], idx ); + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } +} + + +// EXPORTS // + +module.exports = whileEach2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/2d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/2d_accessors.js new file mode 100644 index 000000000000..8b03293e44ea --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/2d_accessors.js @@ -0,0 +1,160 @@ +/** +* @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 strides2order = require( '@stdlib/ndarray/base/strides2order' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var reverse = require( '@stdlib/array/base/reverse' ); +var take = require( '@stdlib/array/base/take-indexed' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* function fcn( value ) { +* log( '%s', value.toString() ); +* } +* +* // Create a data buffer: +* var xbuf = new Complex64Array( 8 ); +* +* // Define the shape of the array: +* var shape = [ 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the callback function: +* whileEach2d( x, predicate, fcn, {} ); +*/ +function whileEach2d( x, predicate, fcn, thisArg ) { + var xbuf; + var dx0; + var dx1; + var idx; + var ind; + var get; + var sh; + var S0; + var S1; + var sx; + var ix; + var i0; + var i1; + var v; + + // 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; + sx = x.strides; + idx = zeroTo( sh.length ); + if ( strides2order( sx ) === 1 ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 1 ]; + S1 = sh[ 0 ]; + dx0 = sx[ 1 ]; // offset increment for innermost loop + dx1 = sx[ 0 ] - ( S0*sx[1] ); // offset increment for outermost loop + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); // offset increment for outermost loop + idx = reverse( idx ); + } + // Set a pointer to the first indexed element: + ix = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache accessor: + get = x.accessors[ 0 ]; + + // Iterate over the ndarray dimensions... + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + v = get( xbuf, ix ); + ind = take( [ i1, i0 ], idx ); + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } +} + + +// EXPORTS // + +module.exports = whileEach2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/2d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/2d_blocked.js new file mode 100644 index 000000000000..75c4d7b49bc1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/2d_blocked.js @@ -0,0 +1,168 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var take = require( '@stdlib/array/base/take-indexed' ); +var reverse = require( '@stdlib/array/base/reverse' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 8 ); +* +* // Define the shape of the array: +* var shape = [ 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Apply the callback function: +* blockedwhileEach2d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function blockedwhileEach2d( x, predicate, fcn, thisArg ) { + var bsize; + var xbuf; + var dx0; + var dx1; + var ox1; + var idx; + var ind; + var sh; + var s0; + var s1; + var sx; + var ox; + var ix; + var i0; + var i1; + var j0; + var j1; + var o; + var v; + + // 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( x.shape, x.strides ); + sh = o.sh; + sx = o.sx; + idx = reverse( o.idx ); + + // Determine the block size: + bsize = blockSize( x.dtype ); + + // Set a pointer to the first indexed element: + ox = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache the offset increment for the innermost loop: + dx0 = sx[0]; + + // Iterate over blocks... + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + ox1 = ox + ( j1*sx[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first input ndarray element in the current block: + ix = ox1 + ( j0*sx[0] ); + + // Compute the loop offset increment: + dx1 = sx[1] - ( s0*sx[0] ); + + // Iterate over the ndarray dimensions... + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + v = xbuf[ ix ]; + ind = take( [ j1+i1, j0+i0 ], idx ); + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhileEach2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/2d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/2d_blocked_accessors.js new file mode 100644 index 000000000000..75011bc1555b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/2d_blocked_accessors.js @@ -0,0 +1,186 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var take = require( '@stdlib/array/base/take-indexed' ); +var reverse = require( '@stdlib/array/base/reverse' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* function fcn( value ) { +* log( '%s', value.toString() ); +* } +* +* // Create a data buffer: +* var xbuf = new Complex64Array( 8 ); +* +* // Define the shape of the array: +* var shape = [ 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the callback function: +* blockedwhileEach2d( x, predicate, fcn, {} ); +*/ +function blockedwhileEach2d( x, predicate, fcn, thisArg ) { + var bsize; + var xbuf; + var dx0; + var dx1; + var ox1; + var idx; + var ind; + var get; + var sh; + var s0; + var s1; + var sx; + var ox; + var ix; + var i0; + var i1; + var j0; + var j1; + var o; + var v; + + // 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( x.shape, x.strides ); + sh = o.sh; + sx = o.sx; + idx = reverse( o.idx ); + + // Determine the block size: + bsize = blockSize( x.dtype ); + + // Set a pointer to the first indexed element: + ox = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache the offset increment for the innermost loop: + dx0 = sx[0]; + + // Cache accessor: + get = x.accessors[0]; + + // Iterate over blocks... + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + ox1 = ox + ( j1*sx[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first input ndarray element in the current block: + ix = ox1 + ( j0*sx[0] ); + + // Compute the loop offset increment: + dx1 = sx[1] - ( s0*sx[0] ); + + // Iterate over the ndarray dimensions... + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + v = get( xbuf, ix ); + ind = take( [ j1+i1, j0+i0 ], idx ); + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhileEach2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/3d.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/3d.js new file mode 100644 index 000000000000..417f6bcbb4d8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/3d.js @@ -0,0 +1,152 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var strides2order = require( '@stdlib/ndarray/base/strides2order' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var reverse = require( '@stdlib/array/base/reverse' ); +var take = require( '@stdlib/array/base/take-indexed' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the shape of the array: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Apply the callback function: +* whileEach3d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function whileEach3d( x, predicate, fcn, thisArg ) { + var xbuf; + var dx0; + var dx1; + var dx2; + var idx; + var ind; + var sh; + var S0; + var S1; + var S2; + var sx; + var ix; + var i0; + var i1; + var i2; + var v; + + // 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; + sx = x.strides; + idx = zeroTo( sh.length ); + if ( strides2order( sx ) === 1 ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 2 ]; + S1 = sh[ 1 ]; + S2 = sh[ 0 ]; + dx0 = sx[ 2 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[2] ); + dx2 = sx[ 0 ] - ( S1*sx[1] ); // offset increment for outermost loop + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); // offset increment for outermost loop + idx = reverse( idx ); + } + // Set a pointer to the first indexed element: + ix = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Iterate over the ndarray dimensions... + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + v = xbuf[ ix ]; + ind = take( [ i2, i1, i0 ], idx ); + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } +} + + +// EXPORTS // + +module.exports = whileEach3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/3d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/3d_accessors.js new file mode 100644 index 000000000000..d01071f43bb8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/3d_accessors.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 strides2order = require( '@stdlib/ndarray/base/strides2order' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var reverse = require( '@stdlib/array/base/reverse' ); +var take = require( '@stdlib/array/base/take-indexed' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* function fcn( value ) { +* log( '%s', value.toString() ); +* } +* +* // Create a data buffer: +* var xbuf = new Complex64Array( 8 ); +* +* // Define the shape of the array: +* var shape = [ 1, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the callback function: +* whileEach3d( x, predicate, fcn, {} ); +*/ +function whileEach3d( x, predicate, fcn, thisArg ) { + var xbuf; + var dx0; + var dx1; + var dx2; + var idx; + var ind; + var get; + var sh; + var S0; + var S1; + var S2; + var sx; + var ix; + var i0; + var i1; + var i2; + var v; + + // 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; + sx = x.strides; + idx = zeroTo( sh.length ); + if ( strides2order( sx ) === 1 ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 2 ]; + S1 = sh[ 1 ]; + S2 = sh[ 0 ]; + dx0 = sx[ 2 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[2] ); + dx2 = sx[ 0 ] - ( S1*sx[1] ); // offset increment for outermost loop + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); // offset increment for outermost loop + idx = reverse( idx ); + } + // Set a pointer to the first indexed element: + ix = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache accessor: + get = x.accessors[ 0 ]; + + // Iterate over the ndarray dimensions... + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + v = get( xbuf, ix ); + ind = take( [ i2, i1, i0 ], idx ); + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } +} + + +// EXPORTS // + +module.exports = whileEach3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/3d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/3d_blocked.js new file mode 100644 index 000000000000..e40e73ff4b5c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/3d_blocked.js @@ -0,0 +1,189 @@ +/** +* @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/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var take = require( '@stdlib/array/base/take-indexed' ); +var reverse = require( '@stdlib/array/base/reverse' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the shape of the array: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Apply the callback function: +* blockedwhileEach3d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function blockedwhileEach3d( x, predicate, fcn, thisArg ) { + var bsize; + var xbuf; + var dx0; + var dx1; + var dx2; + var ox1; + var ox2; + var idx; + var ind; + var sh; + var s0; + var s1; + var s2; + var sx; + var ox; + var ix; + var i0; + var i1; + var i2; + var j0; + var j1; + var j2; + var o; + var v; + + // 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( x.shape, x.strides ); + sh = o.sh; + sx = o.sx; + idx = reverse( o.idx ); + + // Determine the block size: + bsize = blockSize( x.dtype ); + + // Set a pointer to the first indexed element: + ox = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache the offset increment for the innermost loop: + dx0 = sx[0]; + + // Iterate over blocks... + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + ox2 = ox + ( j2*sx[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + ox1 = ox2 + ( j1*sx[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first input ndarray element in the current block: + ix = ox1 + ( j0*sx[0] ); + + // Compute the loop offset increment: + dx1 = sx[1] - ( s0*sx[0] ); + + // Iterate over the ndarray dimensions... + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + v = xbuf[ ix ]; + ind = take( [ j2+i2, j1+i1, j0+i0 ], idx ); + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhileEach3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/3d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/3d_blocked_accessors.js new file mode 100644 index 000000000000..949e2d13f8e8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/3d_blocked_accessors.js @@ -0,0 +1,207 @@ +/** +* @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/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var take = require( '@stdlib/array/base/take-indexed' ); +var reverse = require( '@stdlib/array/base/reverse' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* function fcn( value ) { +* log( '%s', value.toString() ); +* } +* +* // Create a data buffer: +* var xbuf = new Complex64Array( 8 ); +* +* // Define the shape of the array: +* var shape = [ 1, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the callback function: +* blockedwhileEach3d( x, predicate, fcn, {} ); +*/ +function blockedwhileEach3d( x, predicate, fcn, thisArg ) { + var bsize; + var xbuf; + var dx0; + var dx1; + var dx2; + var ox1; + var ox2; + var idx; + var ind; + var get; + var sh; + var s0; + var s1; + var s2; + var sx; + var ox; + var ix; + var i0; + var i1; + var i2; + var j0; + var j1; + var j2; + var o; + var v; + + // 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( x.shape, x.strides ); + sh = o.sh; + sx = o.sx; + idx = reverse( o.idx ); + + // Determine the block size: + bsize = blockSize( x.dtype ); + + // Set a pointer to the first indexed element: + ox = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache the offset increment for the innermost loop: + dx0 = sx[0]; + + // Cache accessor: + get = x.accessors[0]; + + // Iterate over blocks... + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + ox2 = ox + ( j2*sx[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + ox1 = ox2 + ( j1*sx[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first input ndarray element in the current block: + ix = ox1 + ( j0*sx[0] ); + + // Compute the loop offset increment: + dx1 = sx[1] - ( s0*sx[0] ); + + // Iterate over the ndarray dimensions... + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + v = get( xbuf, ix ); + ind = take( [ j2+i2, j1+i1, j0+i0 ], idx ); + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhileEach3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/4d.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/4d.js new file mode 100644 index 000000000000..820148650354 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/4d.js @@ -0,0 +1,162 @@ +/** +* @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 strides2order = require( '@stdlib/ndarray/base/strides2order' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var reverse = require( '@stdlib/array/base/reverse' ); +var take = require( '@stdlib/array/base/take-indexed' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the shape of the array: +* var shape = [ 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Apply the callback function: +* whileEach4d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function whileEach4d( x, predicate, fcn, thisArg ) { + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var idx; + var ind; + var sh; + var S0; + var S1; + var S2; + var S3; + var sx; + var ix; + var i0; + var i1; + var i2; + var i3; + var v; + + // 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; + sx = x.strides; + idx = zeroTo( sh.length ); + if ( strides2order( sx ) === 1 ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 3 ]; + S1 = sh[ 2 ]; + S2 = sh[ 1 ]; + S3 = sh[ 0 ]; + dx0 = sx[ 3 ]; // offset increment for innermost loop + dx1 = sx[ 2 ] - ( S0*sx[3] ); + dx2 = sx[ 1 ] - ( S1*sx[2] ); + dx3 = sx[ 0 ] - ( S2*sx[1] ); // offset increment for outermost loop + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); // offset increment for outermost loop + idx = reverse( idx ); + } + // Set a pointer to the first indexed element: + ix = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.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++ ) { + v = xbuf[ ix ]; + ind = take( [ i3, i2, i1, i0 ], idx ); + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } +} + + +// EXPORTS // + +module.exports = whileEach4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/4d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/4d_accessors.js new file mode 100644 index 000000000000..c5f3b924bef5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/4d_accessors.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 strides2order = require( '@stdlib/ndarray/base/strides2order' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var reverse = require( '@stdlib/array/base/reverse' ); +var take = require( '@stdlib/array/base/take-indexed' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* function fcn( value ) { +* log( '%s', value.toString() ); +* } +* +* // Create a data buffer: +* var xbuf = new Complex64Array( 8 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the callback function: +* whileEach4d( x, predicate, fcn, {} ); +*/ +function whileEach4d( x, predicate, fcn, thisArg ) { + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var idx; + var ind; + var get; + var sh; + var S0; + var S1; + var S2; + var S3; + var sx; + var ix; + var i0; + var i1; + var i2; + var i3; + var v; + + // 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; + sx = x.strides; + idx = zeroTo( sh.length ); + if ( strides2order( sx ) === 1 ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 3 ]; + S1 = sh[ 2 ]; + S2 = sh[ 1 ]; + S3 = sh[ 0 ]; + dx0 = sx[ 3 ]; // offset increment for innermost loop + dx1 = sx[ 2 ] - ( S0*sx[3] ); + dx2 = sx[ 1 ] - ( S1*sx[2] ); + dx3 = sx[ 0 ] - ( S2*sx[1] ); // offset increment for outermost loop + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); // offset increment for outermost loop + idx = reverse( idx ); + } + // Set a pointer to the first indexed element: + ix = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache accessor: + get = x.accessors[ 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++ ) { + v = get( xbuf, ix ); + ind = take( [ i3, i2, i1, i0 ], idx ); + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } +} + + +// EXPORTS // + +module.exports = whileEach4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/4d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/4d_blocked.js new file mode 100644 index 000000000000..de95893b1274 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/4d_blocked.js @@ -0,0 +1,208 @@ +/** +* @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/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var take = require( '@stdlib/array/base/take-indexed' ); +var reverse = require( '@stdlib/array/base/reverse' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the shape of the array: +* var shape = [ 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Apply the callback function: +* blockedwhileEach4d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function blockedwhileEach4d( x, predicate, fcn, thisArg ) { + var bsize; + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var ox1; + var ox2; + var ox3; + var idx; + var ind; + var sh; + var s0; + var s1; + var s2; + var s3; + var sx; + var ox; + var ix; + var i0; + var i1; + var i2; + var i3; + var j0; + var j1; + var j2; + var j3; + var o; + var v; + + // 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( x.shape, x.strides ); + sh = o.sh; + sx = o.sx; + idx = reverse( o.idx ); + + // Determine the block size: + bsize = blockSize( x.dtype ); + + // Set a pointer to the first indexed element: + ox = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache the offset increment for the innermost loop: + dx0 = sx[0]; + + // Iterate over blocks... + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + ox3 = ox + ( j3*sx[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + ox2 = ox3 + ( j2*sx[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + ox1 = ox2 + ( j1*sx[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first input ndarray element in the current block: + ix = ox1 + ( j0*sx[0] ); + + // Compute the loop offset increment: + dx1 = sx[1] - ( s0*sx[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++ ) { + v = xbuf[ ix ]; + ind = take( [ j3+i3, j2+i2, j1+i1, j0+i0 ], idx ); // eslint-disable-line max-len + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhileEach4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/4d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/4d_blocked_accessors.js new file mode 100644 index 000000000000..414f7753be26 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/4d_blocked_accessors.js @@ -0,0 +1,226 @@ +/** +* @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/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var take = require( '@stdlib/array/base/take-indexed' ); +var reverse = require( '@stdlib/array/base/reverse' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* function fcn( value ) { +* log( '%s', value.toString() ); +* } +* +* // Create a data buffer: +* var xbuf = new Complex64Array( 8 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the callback function: +* blockedwhileEach4d( x, predicate, fcn, {} ); +*/ +function blockedwhileEach4d( x, predicate, fcn, thisArg ) { + var bsize; + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var ox1; + var ox2; + var ox3; + var idx; + var ind; + var get; + var sh; + var s0; + var s1; + var s2; + var s3; + var sx; + var ox; + var ix; + var i0; + var i1; + var i2; + var i3; + var j0; + var j1; + var j2; + var j3; + var o; + var v; + + // 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( x.shape, x.strides ); + sh = o.sh; + sx = o.sx; + idx = reverse( o.idx ); + + // Determine the block size: + bsize = blockSize( x.dtype ); + + // Set a pointer to the first indexed element: + ox = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache the offset increment for the innermost loop: + dx0 = sx[0]; + + // Cache accessor: + get = x.accessors[0]; + + // Iterate over blocks... + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + ox3 = ox + ( j3*sx[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + ox2 = ox3 + ( j2*sx[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + ox1 = ox2 + ( j1*sx[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first input ndarray element in the current block: + ix = ox1 + ( j0*sx[0] ); + + // Compute the loop offset increment: + dx1 = sx[1] - ( s0*sx[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++ ) { + v = get( xbuf, ix ); + ind = take( [ j3+i3, j2+i2, j1+i1, j0+i0 ], idx ); // eslint-disable-line max-len + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhileEach4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d.js new file mode 100644 index 000000000000..8d0d4291cdec --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d.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'; + +// MODULES // + +var strides2order = require( '@stdlib/ndarray/base/strides2order' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var reverse = require( '@stdlib/array/base/reverse' ); +var take = require( '@stdlib/array/base/take-indexed' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Apply the callback function: +* whileEach5d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function whileEach5d( x, predicate, fcn, thisArg ) { + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var idx; + var ind; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var sx; + var ix; + var i0; + var i1; + var i2; + var i3; + var i4; + var v; + + // 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; + sx = x.strides; + idx = zeroTo( sh.length ); + if ( strides2order( sx ) === 1 ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 4 ]; + S1 = sh[ 3 ]; + S2 = sh[ 2 ]; + S3 = sh[ 1 ]; + S4 = sh[ 0 ]; + dx0 = sx[ 4 ]; // offset increment for innermost loop + dx1 = sx[ 3 ] - ( S0*sx[4] ); + dx2 = sx[ 2 ] - ( S1*sx[3] ); + dx3 = sx[ 1 ] - ( S2*sx[2] ); + dx4 = sx[ 0 ] - ( S3*sx[1] ); // offset increment for outermost loop + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); // offset increment for outermost loop + idx = reverse( idx ); + } + // Set a pointer to the first indexed element: + ix = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.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++ ) { + v = xbuf[ ix ]; + ind = take( [ i4, i3, i2, i1, i0 ], idx ); + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } +} + + +// EXPORTS // + +module.exports = whileEach5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d_accessors.js new file mode 100644 index 000000000000..e8fb98bff757 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d_accessors.js @@ -0,0 +1,190 @@ +/** +* @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 strides2order = require( '@stdlib/ndarray/base/strides2order' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var reverse = require( '@stdlib/array/base/reverse' ); +var take = require( '@stdlib/array/base/take-indexed' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* function fcn( value ) { +* log( '%s', value.toString() ); +* } +* +* // Create a data buffer: +* var xbuf = new Complex64Array( 8 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the callback function: +* whileEach5d( x, predicate, fcn, {} ); +*/ +function whileEach5d( x, predicate, fcn, thisArg ) { + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var idx; + var ind; + var get; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var sx; + var ix; + var i0; + var i1; + var i2; + var i3; + var i4; + var v; + + // 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; + sx = x.strides; + idx = zeroTo( sh.length ); + if ( strides2order( sx ) === 1 ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 4 ]; + S1 = sh[ 3 ]; + S2 = sh[ 2 ]; + S3 = sh[ 1 ]; + S4 = sh[ 0 ]; + dx0 = sx[ 4 ]; // offset increment for innermost loop + dx1 = sx[ 3 ] - ( S0*sx[4] ); + dx2 = sx[ 2 ] - ( S1*sx[3] ); + dx3 = sx[ 1 ] - ( S2*sx[2] ); + dx4 = sx[ 0 ] - ( S3*sx[1] ); // offset increment for outermost loop + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); // offset increment for outermost loop + idx = reverse( idx ); + } + // Set a pointer to the first indexed element: + ix = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache accessor: + get = x.accessors[ 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++ ) { + v = get( xbuf, ix ); + ind = take( [ i4, i3, i2, i1, i0 ], idx ); + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } +} + + +// EXPORTS // + +module.exports = whileEach5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d_blocked.js new file mode 100644 index 000000000000..528d620e4627 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d_blocked.js @@ -0,0 +1,227 @@ +/** +* @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/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var take = require( '@stdlib/array/base/take-indexed' ); +var reverse = require( '@stdlib/array/base/reverse' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Apply the callback function: +* blockedwhileEach5d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function blockedwhileEach5d( x, predicate, fcn, thisArg ) { + var bsize; + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var ox1; + var ox2; + var ox3; + var ox4; + var idx; + var ind; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var sx; + var ox; + var ix; + var i0; + var i1; + var i2; + var i3; + var i4; + var j0; + var j1; + var j2; + var j3; + var j4; + var o; + var v; + + // 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( x.shape, x.strides ); + sh = o.sh; + sx = o.sx; + idx = reverse( o.idx ); + + // Determine the block size: + bsize = blockSize( x.dtype ); + + // Set a pointer to the first indexed element: + ox = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache the offset increment for the innermost loop: + dx0 = sx[0]; + + // Iterate over blocks... + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + ox4 = ox + ( j4*sx[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dx4 = sx[4] - ( s3*sx[3] ); + ox3 = ox4 + ( j3*sx[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + ox2 = ox3 + ( j2*sx[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + ox1 = ox2 + ( j1*sx[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first input ndarray element in the current block: + ix = ox1 + ( j0*sx[0] ); + + // Compute the loop offset increment: + dx1 = sx[1] - ( s0*sx[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++ ) { + v = xbuf[ ix ]; + ind = take( [ j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], idx ); // eslint-disable-line max-len + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhileEach5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d_blocked_accessors.js new file mode 100644 index 000000000000..a66f7203be26 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d_blocked_accessors.js @@ -0,0 +1,245 @@ +/** +* @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/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var take = require( '@stdlib/array/base/take-indexed' ); +var reverse = require( '@stdlib/array/base/reverse' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* function fcn( value ) { +* log( '%s', value.toString() ); +* } +* +* // Create a data buffer: +* var xbuf = new Complex64Array( 8 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the callback function: +* blockedwhileEach5d( x, predicate, fcn, {} ); +*/ +function blockedwhileEach5d( x, predicate, fcn, thisArg ) { + var bsize; + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var ox1; + var ox2; + var ox3; + var ox4; + var idx; + var ind; + var get; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var sx; + var ox; + var ix; + var i0; + var i1; + var i2; + var i3; + var i4; + var j0; + var j1; + var j2; + var j3; + var j4; + var o; + var v; + + // 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( x.shape, x.strides ); + sh = o.sh; + sx = o.sx; + idx = reverse( o.idx ); + + // Determine the block size: + bsize = blockSize( x.dtype ); + + // Set a pointer to the first indexed element: + ox = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache the offset increment for the innermost loop: + dx0 = sx[0]; + + // Cache accessor: + get = x.accessors[0]; + + // Iterate over blocks... + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + ox4 = ox + ( j4*sx[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dx4 = sx[4] - ( s3*sx[3] ); + ox3 = ox4 + ( j3*sx[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + ox2 = ox3 + ( j2*sx[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + ox1 = ox2 + ( j1*sx[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first input ndarray element in the current block: + ix = ox1 + ( j0*sx[0] ); + + // Compute the loop offset increment: + dx1 = sx[1] - ( s0*sx[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++ ) { + v = get( xbuf, ix ); + ind = take( [ j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], idx ); // eslint-disable-line max-len + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhileEach5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/6d.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/6d.js new file mode 100644 index 000000000000..d561dca9e29b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/6d.js @@ -0,0 +1,184 @@ +/** +* @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 strides2order = require( '@stdlib/ndarray/base/strides2order' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var reverse = require( '@stdlib/array/base/reverse' ); +var take = require( '@stdlib/array/base/take-indexed' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Apply the callback function: +* whileEach6d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function whileEach6d( x, predicate, fcn, thisArg ) { + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var idx; + var ind; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var sx; + var ix; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var v; + + // 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; + sx = x.strides; + idx = zeroTo( sh.length ); + if ( strides2order( sx ) === 1 ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 5 ]; + S1 = sh[ 4 ]; + S2 = sh[ 3 ]; + S3 = sh[ 2 ]; + S4 = sh[ 1 ]; + S5 = sh[ 0 ]; + dx0 = sx[ 5 ]; // offset increment for innermost loop + dx1 = sx[ 4 ] - ( S0*sx[5] ); + dx2 = sx[ 3 ] - ( S1*sx[4] ); + dx3 = sx[ 2 ] - ( S2*sx[3] ); + dx4 = sx[ 1 ] - ( S3*sx[2] ); + dx5 = sx[ 0 ] - ( S4*sx[1] ); // offset increment for outermost loop + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); + dx5 = sx[ 5 ] - ( S4*sx[4] ); // offset increment for outermost loop + idx = reverse( idx ); + } + // Set a pointer to the first indexed element: + ix = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.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++ ) { + v = xbuf[ ix ]; + ind = take( [ i5, i4, i3, i2, i1, i0 ], idx ); + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } +} + + +// EXPORTS // + +module.exports = whileEach6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/6d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/6d_accessors.js new file mode 100644 index 000000000000..cfe1e5e7a805 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/6d_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. +*/ + +/* eslint-disable max-depth */ + +'use strict'; + +// MODULES // + +var strides2order = require( '@stdlib/ndarray/base/strides2order' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var reverse = require( '@stdlib/array/base/reverse' ); +var take = require( '@stdlib/array/base/take-indexed' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* function fcn( value ) { +* log( '%s', value.toString() ); +* } +* +* // Create a data buffer: +* var xbuf = new Complex64Array( 8 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 4, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the callback function: +* whileEach6d( x, predicate, fcn, {} ); +*/ +function whileEach6d( x, predicate, fcn, thisArg ) { + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var idx; + var ind; + var get; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var sx; + var ix; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var v; + + // 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; + sx = x.strides; + idx = zeroTo( sh.length ); + if ( strides2order( sx ) === 1 ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 5 ]; + S1 = sh[ 4 ]; + S2 = sh[ 3 ]; + S3 = sh[ 2 ]; + S4 = sh[ 1 ]; + S5 = sh[ 0 ]; + dx0 = sx[ 5 ]; // offset increment for innermost loop + dx1 = sx[ 4 ] - ( S0*sx[5] ); + dx2 = sx[ 3 ] - ( S1*sx[4] ); + dx3 = sx[ 2 ] - ( S2*sx[3] ); + dx4 = sx[ 1 ] - ( S3*sx[2] ); + dx5 = sx[ 0 ] - ( S4*sx[1] ); // offset increment for outermost loop + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); + dx5 = sx[ 5 ] - ( S4*sx[4] ); // offset increment for outermost loop + idx = reverse( idx ); + } + // Set a pointer to the first indexed element: + ix = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache accessor: + get = x.accessors[ 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++ ) { + v = get( xbuf, ix ); + ind = take( [ i5, i4, i3, i2, i1, i0 ], idx ); + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } +} + + +// EXPORTS // + +module.exports = whileEach6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/6d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/6d_blocked.js new file mode 100644 index 000000000000..5b247a12b238 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/6d_blocked.js @@ -0,0 +1,246 @@ +/** +* @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/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var take = require( '@stdlib/array/base/take-indexed' ); +var reverse = require( '@stdlib/array/base/reverse' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Apply the callback function: +* blockedwhileEach6d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function blockedwhileEach6d( x, predicate, fcn, thisArg ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var idx; + var ind; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var sx; + var ox; + var ix; + 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; + var v; + + // 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( x.shape, x.strides ); + sh = o.sh; + sx = o.sx; + idx = reverse( o.idx ); + + // Determine the block size: + bsize = blockSize( x.dtype ); + + // Set a pointer to the first indexed element: + ox = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache the offset increment for the innermost loop: + dx0 = sx[0]; + + // Iterate over blocks... + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + ox5 = ox + ( j5*sx[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dx5 = sx[5] - ( s4*sx[4] ); + ox4 = ox5 + ( j4*sx[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dx4 = sx[4] - ( s3*sx[3] ); + ox3 = ox4 + ( j3*sx[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + ox2 = ox3 + ( j2*sx[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + ox1 = ox2 + ( j1*sx[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first input ndarray element in the current block: + ix = ox1 + ( j0*sx[0] ); + + // Compute the loop offset increment: + dx1 = sx[1] - ( s0*sx[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++ ) { + v = xbuf[ ix ]; + ind = take( [ j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], idx ); // eslint-disable-line max-len + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhileEach6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/6d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/6d_blocked_accessors.js new file mode 100644 index 000000000000..37a388f308d0 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/6d_blocked_accessors.js @@ -0,0 +1,264 @@ +/** +* @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/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var take = require( '@stdlib/array/base/take-indexed' ); +var reverse = require( '@stdlib/array/base/reverse' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* function fcn( value ) { +* log( '%s', value.toString() ); +* } +* +* // Create a data buffer: +* var xbuf = new Complex64Array( 8 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 4, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the callback function: +* blockedwhileEach6d( x, predicate, fcn, {} ); +*/ +function blockedwhileEach6d( x, predicate, fcn, thisArg ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var idx; + var ind; + var get; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var sx; + var ox; + var ix; + 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; + var v; + + // 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( x.shape, x.strides ); + sh = o.sh; + sx = o.sx; + idx = reverse( o.idx ); + + // Determine the block size: + bsize = blockSize( x.dtype ); + + // Set a pointer to the first indexed element: + ox = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache the offset increment for the innermost loop: + dx0 = sx[0]; + + // Cache accessor: + get = x.accessors[0]; + + // Iterate over blocks... + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + ox5 = ox + ( j5*sx[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dx5 = sx[5] - ( s4*sx[4] ); + ox4 = ox5 + ( j4*sx[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dx4 = sx[4] - ( s3*sx[3] ); + ox3 = ox4 + ( j3*sx[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + ox2 = ox3 + ( j2*sx[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + ox1 = ox2 + ( j1*sx[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first input ndarray element in the current block: + ix = ox1 + ( j0*sx[0] ); + + // Compute the loop offset increment: + dx1 = sx[1] - ( s0*sx[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++ ) { + v = get( xbuf, ix ); + ind = take( [ j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], idx ); // eslint-disable-line max-len + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhileEach6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/7d.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/7d.js new file mode 100644 index 000000000000..d9e114693ebf --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/7d.js @@ -0,0 +1,194 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-depth */ + +'use strict'; + +// MODULES // + +var strides2order = require( '@stdlib/ndarray/base/strides2order' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var reverse = require( '@stdlib/array/base/reverse' ); +var take = require( '@stdlib/array/base/take-indexed' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Apply the callback function: +* whileEach7d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function whileEach7d( x, predicate, fcn, thisArg ) { + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var idx; + var ind; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var sx; + var ix; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var v; + + // 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; + sx = x.strides; + idx = zeroTo( sh.length ); + if ( strides2order( sx ) === 1 ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 6 ]; + S1 = sh[ 5 ]; + S2 = sh[ 4 ]; + S3 = sh[ 3 ]; + S4 = sh[ 2 ]; + S5 = sh[ 1 ]; + S6 = sh[ 0 ]; + dx0 = sx[ 6 ]; // offset increment for innermost loop + dx1 = sx[ 5 ] - ( S0*sx[6] ); + dx2 = sx[ 4 ] - ( S1*sx[5] ); + dx3 = sx[ 3 ] - ( S2*sx[4] ); + dx4 = sx[ 2 ] - ( S3*sx[3] ); + dx5 = sx[ 1 ] - ( S4*sx[2] ); + dx6 = sx[ 0 ] - ( S5*sx[1] ); // offset increment for outermost loop + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + S6 = sh[ 6 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); + dx5 = sx[ 5 ] - ( S4*sx[4] ); + dx6 = sx[ 6 ] - ( S5*sx[5] ); // offset increment for outermost loop + idx = reverse( idx ); + } + // Set a pointer to the first indexed element: + ix = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.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++ ) { + v = xbuf[ ix ]; + ind = take( [ i6, i5, i4, i3, i2, i1, i0 ], idx ); // eslint-disable-line max-len + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } +} + + +// EXPORTS // + +module.exports = whileEach7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/7d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/7d_accessors.js new file mode 100644 index 000000000000..bf7c84c420e5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/7d_accessors.js @@ -0,0 +1,212 @@ +/** +* @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 strides2order = require( '@stdlib/ndarray/base/strides2order' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var reverse = require( '@stdlib/array/base/reverse' ); +var take = require( '@stdlib/array/base/take-indexed' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* function fcn( value ) { +* log( '%s', value.toString() ); +* } +* +* // Create a data buffer: +* var xbuf = new Complex64Array( 8 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 1, 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 4, 4, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the callback function: +* whileEach7d( x, predicate, fcn, {} ); +*/ +function whileEach7d( x, predicate, fcn, thisArg ) { + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var idx; + var ind; + var get; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var sx; + var ix; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var v; + + // 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; + sx = x.strides; + idx = zeroTo( sh.length ); + if ( strides2order( sx ) === 1 ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 6 ]; + S1 = sh[ 5 ]; + S2 = sh[ 4 ]; + S3 = sh[ 3 ]; + S4 = sh[ 2 ]; + S5 = sh[ 1 ]; + S6 = sh[ 0 ]; + dx0 = sx[ 6 ]; // offset increment for innermost loop + dx1 = sx[ 5 ] - ( S0*sx[6] ); + dx2 = sx[ 4 ] - ( S1*sx[5] ); + dx3 = sx[ 3 ] - ( S2*sx[4] ); + dx4 = sx[ 2 ] - ( S3*sx[3] ); + dx5 = sx[ 1 ] - ( S4*sx[2] ); + dx6 = sx[ 0 ] - ( S5*sx[1] ); // offset increment for outermost loop + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + S6 = sh[ 6 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); + dx5 = sx[ 5 ] - ( S4*sx[4] ); + dx6 = sx[ 6 ] - ( S5*sx[5] ); // offset increment for outermost loop + idx = reverse( idx ); + } + // Set a pointer to the first indexed element: + ix = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache accessor: + get = x.accessors[ 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++ ) { + v = get( xbuf, ix ); + ind = take( [ i6, i5, i4, i3, i2, i1, i0 ], idx ); // eslint-disable-line max-len + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } +} + + +// EXPORTS // + +module.exports = whileEach7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/7d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/7d_blocked.js new file mode 100644 index 000000000000..2dc3de6a3cd5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/7d_blocked.js @@ -0,0 +1,265 @@ +/** +* @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/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var take = require( '@stdlib/array/base/take-indexed' ); +var reverse = require( '@stdlib/array/base/reverse' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Apply the callback function: +* blockedwhileEach7d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function blockedwhileEach7d( x, predicate, fcn, thisArg ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var ox6; + var idx; + var ind; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var sx; + var ox; + var ix; + 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; + var v; + + // 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( x.shape, x.strides ); + sh = o.sh; + sx = o.sx; + idx = reverse( o.idx ); + + // Determine the block size: + bsize = blockSize( x.dtype ); + + // Set a pointer to the first indexed element: + ox = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache the offset increment for the innermost loop: + dx0 = sx[0]; + + // Iterate over blocks... + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + ox6 = ox + ( j6*sx[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dx6 = sx[6] - ( s5*sx[5] ); + ox5 = ox6 + ( j5*sx[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dx5 = sx[5] - ( s4*sx[4] ); + ox4 = ox5 + ( j4*sx[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dx4 = sx[4] - ( s3*sx[3] ); + ox3 = ox4 + ( j3*sx[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + ox2 = ox3 + ( j2*sx[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + ox1 = ox2 + ( j1*sx[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first input ndarray element in the current block: + ix = ox1 + ( j0*sx[0] ); + + // Compute the loop offset increment: + dx1 = sx[1] - ( s0*sx[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++ ) { + v = xbuf[ ix ]; + ind = take( [ j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], idx ); + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhileEach7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/7d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/7d_blocked_accessors.js new file mode 100644 index 000000000000..38baa5e4e79e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/7d_blocked_accessors.js @@ -0,0 +1,283 @@ +/** +* @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/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var take = require( '@stdlib/array/base/take-indexed' ); +var reverse = require( '@stdlib/array/base/reverse' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* function fcn( value ) { +* log( '%s', value.toString() ); +* } +* +* // Create a data buffer: +* var xbuf = new Complex64Array( 8 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 1, 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 4, 4, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the callback function: +* blockedwhileEach7d( x, predicate, fcn, {} ); +*/ +function blockedwhileEach7d( x, predicate, fcn, thisArg ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var ox6; + var idx; + var ind; + var get; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var sx; + var ox; + var ix; + 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; + var v; + + // 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( x.shape, x.strides ); + sh = o.sh; + sx = o.sx; + idx = reverse( o.idx ); + + // Determine the block size: + bsize = blockSize( x.dtype ); + + // Set a pointer to the first indexed element: + ox = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache the offset increment for the innermost loop: + dx0 = sx[0]; + + // Cache accessor: + get = x.accessors[0]; + + // Iterate over blocks... + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + ox6 = ox + ( j6*sx[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dx6 = sx[6] - ( s5*sx[5] ); + ox5 = ox6 + ( j5*sx[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dx5 = sx[5] - ( s4*sx[4] ); + ox4 = ox5 + ( j4*sx[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dx4 = sx[4] - ( s3*sx[3] ); + ox3 = ox4 + ( j3*sx[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + ox2 = ox3 + ( j2*sx[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + ox1 = ox2 + ( j1*sx[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first input ndarray element in the current block: + ix = ox1 + ( j0*sx[0] ); + + // Compute the loop offset increment: + dx1 = sx[1] - ( s0*sx[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++ ) { + v = get( xbuf, ix ); + ind = take( [ j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], idx ); + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhileEach7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/8d.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/8d.js new file mode 100644 index 000000000000..f81a062c4871 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/8d.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. +*/ + +/* eslint-disable max-depth */ + +'use strict'; + +// MODULES // + +var strides2order = require( '@stdlib/ndarray/base/strides2order' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var reverse = require( '@stdlib/array/base/reverse' ); +var take = require( '@stdlib/array/base/take-indexed' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Apply the callback function: +* whileEach8d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function whileEach8d( x, predicate, fcn, thisArg ) { + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var idx; + var ind; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var sx; + var ix; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var v; + + // 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; + sx = x.strides; + idx = zeroTo( sh.length ); + if ( strides2order( sx ) === 1 ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 7 ]; + S1 = sh[ 6 ]; + S2 = sh[ 5 ]; + S3 = sh[ 4 ]; + S4 = sh[ 3 ]; + S5 = sh[ 2 ]; + S6 = sh[ 1 ]; + S7 = sh[ 0 ]; + dx0 = sx[ 7 ]; // offset increment for innermost loop + dx1 = sx[ 6 ] - ( S0*sx[7] ); + dx2 = sx[ 5 ] - ( S1*sx[6] ); + dx3 = sx[ 4 ] - ( S2*sx[5] ); + dx4 = sx[ 3 ] - ( S3*sx[4] ); + dx5 = sx[ 2 ] - ( S4*sx[3] ); + dx6 = sx[ 1 ] - ( S5*sx[2] ); + dx7 = sx[ 0 ] - ( S6*sx[1] ); // offset increment for outermost loop + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + S6 = sh[ 6 ]; + S7 = sh[ 7 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); + dx5 = sx[ 5 ] - ( S4*sx[4] ); + dx6 = sx[ 6 ] - ( S5*sx[5] ); + dx7 = sx[ 7 ] - ( S6*sx[6] ); // offset increment for outermost loop + idx = reverse( idx ); + } + // Set a pointer to the first indexed element: + ix = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.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++ ) { + v = xbuf[ ix ]; + ind = take( [ i7, i6, i5, i4, i3, i2, i1, i0 ], idx ); // eslint-disable-line max-len + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + ix += dx7; + } +} + + +// EXPORTS // + +module.exports = whileEach8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/8d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/8d_accessors.js new file mode 100644 index 000000000000..d3eac294f091 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/8d_accessors.js @@ -0,0 +1,222 @@ +/** +* @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 strides2order = require( '@stdlib/ndarray/base/strides2order' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var reverse = require( '@stdlib/array/base/reverse' ); +var take = require( '@stdlib/array/base/take-indexed' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* function fcn( value ) { +* log( '%s', value.toString() ); +* } +* +* // Create a data buffer: +* var xbuf = new Complex64Array( 8 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 1, 1, 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 4, 4, 4, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the callback function: +* whileEach8d( x, predicate, fcn, {} ); +*/ +function whileEach8d( x, predicate, fcn, thisArg ) { + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var idx; + var ind; + var get; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var sx; + var ix; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var v; + + // 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; + sx = x.strides; + idx = zeroTo( sh.length ); + if ( strides2order( sx ) === 1 ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 7 ]; + S1 = sh[ 6 ]; + S2 = sh[ 5 ]; + S3 = sh[ 4 ]; + S4 = sh[ 3 ]; + S5 = sh[ 2 ]; + S6 = sh[ 1 ]; + S7 = sh[ 0 ]; + dx0 = sx[ 7 ]; // offset increment for innermost loop + dx1 = sx[ 6 ] - ( S0*sx[7] ); + dx2 = sx[ 5 ] - ( S1*sx[6] ); + dx3 = sx[ 4 ] - ( S2*sx[5] ); + dx4 = sx[ 3 ] - ( S3*sx[4] ); + dx5 = sx[ 2 ] - ( S4*sx[3] ); + dx6 = sx[ 1 ] - ( S5*sx[2] ); + dx7 = sx[ 0 ] - ( S6*sx[1] ); // offset increment for outermost loop + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + S6 = sh[ 6 ]; + S7 = sh[ 7 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); + dx5 = sx[ 5 ] - ( S4*sx[4] ); + dx6 = sx[ 6 ] - ( S5*sx[5] ); + dx7 = sx[ 7 ] - ( S6*sx[6] ); // offset increment for outermost loop + idx = reverse( idx ); + } + // Set a pointer to the first indexed element: + ix = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache accessor: + get = x.accessors[ 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++ ) { + v = get( xbuf, ix ); + ind = take( [ i7, i6, i5, i4, i3, i2, i1, i0 ], idx ); // eslint-disable-line max-len + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + ix += dx7; + } +} + + +// EXPORTS // + +module.exports = whileEach8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/8d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/8d_blocked.js new file mode 100644 index 000000000000..4450a796bbb5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/8d_blocked.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. +*/ + +/* eslint-disable max-depth, max-len */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var take = require( '@stdlib/array/base/take-indexed' ); +var reverse = require( '@stdlib/array/base/reverse' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Apply the callback function: +* blockedwhileEach8d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function blockedwhileEach8d( x, predicate, fcn, thisArg ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var ox6; + var ox7; + var idx; + var ind; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var sx; + var ox; + var ix; + 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; + var v; + + // 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( x.shape, x.strides ); + sh = o.sh; + sx = o.sx; + idx = reverse( o.idx ); + + // Determine the block size: + bsize = blockSize( x.dtype ); + + // Set a pointer to the first indexed element: + ox = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache the offset increment for the innermost loop: + dx0 = sx[0]; + + // Iterate over blocks... + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + ox7 = ox + ( j7*sx[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + dx7 = sx[7] - ( s6*sx[6] ); + ox6 = ox7 + ( j6*sx[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dx6 = sx[6] - ( s5*sx[5] ); + ox5 = ox6 + ( j5*sx[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dx5 = sx[5] - ( s4*sx[4] ); + ox4 = ox5 + ( j4*sx[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dx4 = sx[4] - ( s3*sx[3] ); + ox3 = ox4 + ( j3*sx[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + ox2 = ox3 + ( j2*sx[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + ox1 = ox2 + ( j1*sx[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first input ndarray element in the current block: + ix = ox1 + ( j0*sx[0] ); + + // Compute the loop offset increment: + dx1 = sx[1] - ( s0*sx[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++ ) { + v = xbuf[ ix ]; + ind = take( [ j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], idx ); + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + ix += dx7; + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhileEach8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/8d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/8d_blocked_accessors.js new file mode 100644 index 000000000000..e2269cf18509 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/8d_blocked_accessors.js @@ -0,0 +1,302 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-depth, max-len */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var take = require( '@stdlib/array/base/take-indexed' ); +var reverse = require( '@stdlib/array/base/reverse' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* function fcn( value ) { +* log( '%s', value.toString() ); +* } +* +* // Create a data buffer: +* var xbuf = new Complex64Array( 8 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 1, 1, 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 4, 4, 4, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the callback function: +* blockedwhileEach8d( x, predicate, fcn, {} ); +*/ +function blockedwhileEach8d( x, predicate, fcn, thisArg ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var ox6; + var ox7; + var idx; + var ind; + var get; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var sx; + var ox; + var ix; + 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; + var v; + + // 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( x.shape, x.strides ); + sh = o.sh; + sx = o.sx; + idx = reverse( o.idx ); + + // Determine the block size: + bsize = blockSize( x.dtype ); + + // Set a pointer to the first indexed element: + ox = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache the offset increment for the innermost loop: + dx0 = sx[0]; + + // Cache accessor: + get = x.accessors[0]; + + // Iterate over blocks... + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + ox7 = ox + ( j7*sx[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + dx7 = sx[7] - ( s6*sx[6] ); + ox6 = ox7 + ( j6*sx[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dx6 = sx[6] - ( s5*sx[5] ); + ox5 = ox6 + ( j5*sx[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dx5 = sx[5] - ( s4*sx[4] ); + ox4 = ox5 + ( j4*sx[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dx4 = sx[4] - ( s3*sx[3] ); + ox3 = ox4 + ( j3*sx[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + ox2 = ox3 + ( j2*sx[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + ox1 = ox2 + ( j1*sx[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first input ndarray element in the current block: + ix = ox1 + ( j0*sx[0] ); + + // Compute the loop offset increment: + dx1 = sx[1] - ( s0*sx[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++ ) { + v = get( xbuf, ix ); + ind = take( [ j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], idx ); + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + ix += dx7; + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhileEach8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/9d.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/9d.js new file mode 100644 index 000000000000..e2b73d56c160 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/9d.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. +*/ + +/* eslint-disable max-depth */ + +'use strict'; + +// MODULES // + +var strides2order = require( '@stdlib/ndarray/base/strides2order' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var reverse = require( '@stdlib/array/base/reverse' ); +var take = require( '@stdlib/array/base/take-indexed' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Apply the callback function: +* whileEach9d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function whileEach9d( x, predicate, fcn, thisArg ) { + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var dx8; + var idx; + var ind; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var S8; + var sx; + var ix; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + var v; + + // 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; + sx = x.strides; + idx = zeroTo( sh.length ); + if ( strides2order( sx ) === 1 ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 8 ]; + S1 = sh[ 7 ]; + S2 = sh[ 6 ]; + S3 = sh[ 5 ]; + S4 = sh[ 4 ]; + S5 = sh[ 3 ]; + S6 = sh[ 2 ]; + S7 = sh[ 1 ]; + S8 = sh[ 0 ]; + dx0 = sx[ 8 ]; // offset increment for innermost loop + dx1 = sx[ 7 ] - ( S0*sx[8] ); + dx2 = sx[ 6 ] - ( S1*sx[7] ); + dx3 = sx[ 5 ] - ( S2*sx[6] ); + dx4 = sx[ 4 ] - ( S3*sx[5] ); + dx5 = sx[ 3 ] - ( S4*sx[4] ); + dx6 = sx[ 2 ] - ( S5*sx[3] ); + dx7 = sx[ 1 ] - ( S6*sx[2] ); + dx8 = sx[ 0 ] - ( S7*sx[1] ); // offset increment for outermost loop + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + S6 = sh[ 6 ]; + S7 = sh[ 7 ]; + S8 = sh[ 8 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); + dx5 = sx[ 5 ] - ( S4*sx[4] ); + dx6 = sx[ 6 ] - ( S5*sx[5] ); + dx7 = sx[ 7 ] - ( S6*sx[6] ); + dx8 = sx[ 8 ] - ( S7*sx[7] ); // offset increment for outermost loop + idx = reverse( idx ); + } + // Set a pointer to the first indexed element: + ix = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.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++ ) { + v = xbuf[ ix ]; + ind = take( [ i8, i7, i6, i5, i4, i3, i2, i1, i0 ], idx ); // eslint-disable-line max-len + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + ix += dx7; + } + ix += dx8; + } +} + + +// EXPORTS // + +module.exports = whileEach9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/9d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/9d_accessors.js new file mode 100644 index 000000000000..bea6ba368595 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/9d_accessors.js @@ -0,0 +1,232 @@ +/** +* @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 strides2order = require( '@stdlib/ndarray/base/strides2order' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var reverse = require( '@stdlib/array/base/reverse' ); +var take = require( '@stdlib/array/base/take-indexed' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* function fcn( value ) { +* log( '%s', value.toString() ); +* } +* +* // Create a data buffer: +* var xbuf = new Complex64Array( 8 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 4, 4, 4, 4, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the callback function: +* whileEach9d( x, predicate, fcn, {} ); +*/ +function whileEach9d( x, predicate, fcn, thisArg ) { + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var dx8; + var idx; + var ind; + var get; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var S8; + var sx; + var ix; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + var v; + + // 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; + sx = x.strides; + idx = zeroTo( sh.length ); + if ( strides2order( sx ) === 1 ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 8 ]; + S1 = sh[ 7 ]; + S2 = sh[ 6 ]; + S3 = sh[ 5 ]; + S4 = sh[ 4 ]; + S5 = sh[ 3 ]; + S6 = sh[ 2 ]; + S7 = sh[ 1 ]; + S8 = sh[ 0 ]; + dx0 = sx[ 8 ]; // offset increment for innermost loop + dx1 = sx[ 7 ] - ( S0*sx[8] ); + dx2 = sx[ 6 ] - ( S1*sx[7] ); + dx3 = sx[ 5 ] - ( S2*sx[6] ); + dx4 = sx[ 4 ] - ( S3*sx[5] ); + dx5 = sx[ 3 ] - ( S4*sx[4] ); + dx6 = sx[ 2 ] - ( S5*sx[3] ); + dx7 = sx[ 1 ] - ( S6*sx[2] ); + dx8 = sx[ 0 ] - ( S7*sx[1] ); // offset increment for outermost loop + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + S6 = sh[ 6 ]; + S7 = sh[ 7 ]; + S8 = sh[ 8 ]; + dx0 = sx[ 0 ]; // offset increment for innermost loop + dx1 = sx[ 1 ] - ( S0*sx[0] ); + dx2 = sx[ 2 ] - ( S1*sx[1] ); + dx3 = sx[ 3 ] - ( S2*sx[2] ); + dx4 = sx[ 4 ] - ( S3*sx[3] ); + dx5 = sx[ 5 ] - ( S4*sx[4] ); + dx6 = sx[ 6 ] - ( S5*sx[5] ); + dx7 = sx[ 7 ] - ( S6*sx[6] ); + dx8 = sx[ 8 ] - ( S7*sx[7] ); // offset increment for outermost loop + idx = reverse( idx ); + } + // Set a pointer to the first indexed element: + ix = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache accessor: + get = x.accessors[ 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++ ) { + v = get( xbuf, ix ); + ind = take( [ i8, i7, i6, i5, i4, i3, i2, i1, i0 ], idx ); // eslint-disable-line max-len + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + ix += dx7; + } + ix += dx8; + } +} + + +// EXPORTS // + +module.exports = whileEach9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/9d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/9d_blocked.js new file mode 100644 index 000000000000..c871a89338bb --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/9d_blocked.js @@ -0,0 +1,303 @@ +/** +* @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/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var take = require( '@stdlib/array/base/take-indexed' ); +var reverse = require( '@stdlib/array/base/reverse' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Apply the callback function: +* blockedwhileEach9d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function blockedwhileEach9d( x, predicate, fcn, thisArg ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var dx8; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var ox6; + var ox7; + var ox8; + var idx; + var ind; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var s8; + var sx; + var ox; + var ix; + 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; + var v; + + // 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( x.shape, x.strides ); + sh = o.sh; + sx = o.sx; + idx = reverse( o.idx ); + + // Determine the block size: + bsize = blockSize( x.dtype ); + + // Set a pointer to the first indexed element: + ox = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache the offset increment for the innermost loop: + dx0 = sx[0]; + + // Iterate over blocks... + for ( j8 = sh[8]; j8 > 0; ) { + if ( j8 < bsize ) { + s8 = j8; + j8 = 0; + } else { + s8 = bsize; + j8 -= bsize; + } + ox8 = ox + ( j8*sx[8] ); + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + dx8 = sx[8] - ( s7*sx[7] ); + ox7 = ox8 + ( j7*sx[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + dx7 = sx[7] - ( s6*sx[6] ); + ox6 = ox7 + ( j6*sx[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dx6 = sx[6] - ( s5*sx[5] ); + ox5 = ox6 + ( j5*sx[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dx5 = sx[5] - ( s4*sx[4] ); + ox4 = ox5 + ( j4*sx[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dx4 = sx[4] - ( s3*sx[3] ); + ox3 = ox4 + ( j3*sx[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + ox2 = ox3 + ( j2*sx[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + ox1 = ox2 + ( j1*sx[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first input ndarray element in the current block: + ix = ox1 + ( j0*sx[0] ); + + // Compute the loop offset increment: + dx1 = sx[1] - ( s0*sx[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++ ) { + v = xbuf[ ix ]; + ind = take( [ j8+i8, j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], idx ); + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + ix += dx7; + } + ix += dx8; + } + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhileEach9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/9d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/9d_blocked_accessors.js new file mode 100644 index 000000000000..f5750dac347e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/9d_blocked_accessors.js @@ -0,0 +1,321 @@ +/** +* @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/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var take = require( '@stdlib/array/base/take-indexed' ); +var reverse = require( '@stdlib/array/base/reverse' ); + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* function fcn( value ) { +* log( '%s', value.toString() ); +* } +* +* // Create a data buffer: +* var xbuf = new Complex64Array( 8 ); +* +* // Define the shape of the array: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 4, 4, 4, 4, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the callback function: +* blockedwhileEach9d( x, predicate, fcn, {} ); +*/ +function blockedwhileEach9d( x, predicate, fcn, thisArg ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var dx8; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + var ox6; + var ox7; + var ox8; + var idx; + var ind; + var get; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var s8; + var sx; + var ox; + var ix; + 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; + var v; + + // 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( x.shape, x.strides ); + sh = o.sh; + sx = o.sx; + idx = reverse( o.idx ); + + // Determine the block size: + bsize = blockSize( x.dtype ); + + // Set a pointer to the first indexed element: + ox = x.offset; + + // Cache a reference to the input ndarray buffer: + xbuf = x.data; + + // Cache the offset increment for the innermost loop: + dx0 = sx[0]; + + // Cache accessor: + get = x.accessors[0]; + + // Iterate over blocks... + for ( j8 = sh[8]; j8 > 0; ) { + if ( j8 < bsize ) { + s8 = j8; + j8 = 0; + } else { + s8 = bsize; + j8 -= bsize; + } + ox8 = ox + ( j8*sx[8] ); + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + dx8 = sx[8] - ( s7*sx[7] ); + ox7 = ox8 + ( j7*sx[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + dx7 = sx[7] - ( s6*sx[6] ); + ox6 = ox7 + ( j6*sx[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dx6 = sx[6] - ( s5*sx[5] ); + ox5 = ox6 + ( j5*sx[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dx5 = sx[5] - ( s4*sx[4] ); + ox4 = ox5 + ( j4*sx[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dx4 = sx[4] - ( s3*sx[3] ); + ox3 = ox4 + ( j3*sx[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dx3 = sx[3] - ( s2*sx[2] ); + ox2 = ox3 + ( j2*sx[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dx2 = sx[2] - ( s1*sx[1] ); + ox1 = ox2 + ( j1*sx[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first input ndarray element in the current block: + ix = ox1 + ( j0*sx[0] ); + + // Compute the loop offset increment: + dx1 = sx[1] - ( s0*sx[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++ ) { + v = get( xbuf, ix ); + ind = take( [ j8+i8, j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], idx ); + if ( !predicate( v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + ix += dx7; + } + ix += dx8; + } + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedwhileEach9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/index.js new file mode 100644 index 000000000000..ab86f859bc70 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/index.js @@ -0,0 +1,70 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* While a test condition is true, invoke a callback function for each element in an ndarray. +* +* @module @stdlib/ndarray/base/while-each +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var log = require( '@stdlib/console/log' ); +* var whileEach = require( '@stdlib/ndarray/base/while-each' ); +* +* function predicate( value ) { +* return value === value; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the shape of the array: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an ndarray-like objects: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Apply the callback function: +* whileEach( [ x ], predicate, naryFunction( log, 1 ) ); +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/main.js new file mode 100644 index 000000000000..207fee9f76ef --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/main.js @@ -0,0 +1,226 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var iterationOrder = require( '@stdlib/ndarray/base/iteration-order' ); +var ndarray2object = require( '@stdlib/ndarray/base/ndarraylike2object' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var blockedaccessorWhileEach2d = require( './2d_blocked_accessors.js' ); +var blockedaccessorWhileEach3d = require( './3d_blocked_accessors.js' ); +var blockedaccessorWhileEach4d = require( './4d_blocked_accessors.js' ); +var blockedaccessorWhileEach5d = require( './5d_blocked_accessors.js' ); +var blockedaccessorWhileEach6d = require( './6d_blocked_accessors.js' ); +var blockedaccessorWhileEach7d = require( './7d_blocked_accessors.js' ); +var blockedaccessorWhileEach8d = require( './8d_blocked_accessors.js' ); +var blockedaccessorWhileEach9d = require( './9d_blocked_accessors.js' ); +var blockedaccessorWhileEach10d = require( './10d_blocked_accessors.js' ); +var blockedWhileEach2d = require( './2d_blocked.js' ); +var blockedWhileEach3d = require( './3d_blocked.js' ); +var blockedWhileEach4d = require( './4d_blocked.js' ); +var blockedWhileEach5d = require( './5d_blocked.js' ); +var blockedWhileEach6d = require( './6d_blocked.js' ); +var blockedWhileEach7d = require( './7d_blocked.js' ); +var blockedWhileEach8d = require( './8d_blocked.js' ); +var blockedWhileEach9d = require( './9d_blocked.js' ); +var blockedWhileEach10d = require( './10d_blocked.js' ); +var accessorWhileEach0d = require( './0d_accessors.js' ); +var accessorWhileEach1d = require( './1d_accessors.js' ); +var accessorWhileEach2d = require( './2d_accessors.js' ); +var accessorWhileEach3d = require( './3d_accessors.js' ); +var accessorWhileEach4d = require( './4d_accessors.js' ); +var accessorWhileEach5d = require( './5d_accessors.js' ); +var accessorWhileEach6d = require( './6d_accessors.js' ); +var accessorWhileEach7d = require( './7d_accessors.js' ); +var accessorWhileEach8d = require( './8d_accessors.js' ); +var accessorWhileEach9d = require( './9d_accessors.js' ); +var accessorWhileEach10d = require( './10d_accessors.js' ); +var accessorWhileEachnd = require( './nd_accessors.js' ); +var whileEach0d = require( './0d.js' ); +var whileEach1d = require( './1d.js' ); +var whileEach2d = require( './2d.js' ); +var whileEach3d = require( './3d.js' ); +var whileEach4d = require( './4d.js' ); +var whileEach5d = require( './5d.js' ); +var whileEach6d = require( './6d.js' ); +var whileEach7d = require( './7d.js' ); +var whileEach8d = require( './8d.js' ); +var whileEach9d = require( './9d.js' ); +var whileEach10d = require( './10d.js' ); +var whileEachnd = require( './nd.js' ); + + +// VARIABLES // + +var WHILE_EACH = [ + whileEach0d, + whileEach1d, + whileEach2d, + whileEach3d, + whileEach4d, + whileEach5d, + whileEach6d, + whileEach7d, + whileEach8d, + whileEach9d, + whileEach10d +]; +var ACCESSOR_WHILE_EACH = [ + accessorWhileEach0d, + accessorWhileEach1d, + accessorWhileEach2d, + accessorWhileEach3d, + accessorWhileEach4d, + accessorWhileEach5d, + accessorWhileEach6d, + accessorWhileEach7d, + accessorWhileEach8d, + accessorWhileEach9d, + accessorWhileEach10d +]; +var BLOCKED_WHILE_EACH = [ + blockedWhileEach2d, // 0 + blockedWhileEach3d, + blockedWhileEach4d, + blockedWhileEach5d, + blockedWhileEach6d, + blockedWhileEach7d, + blockedWhileEach8d, + blockedWhileEach9d, + blockedWhileEach10d // 8 +]; +var BLOCKED_ACCESSOR_WHILE_EACH = [ + blockedaccessorWhileEach2d, // 0 + blockedaccessorWhileEach3d, + blockedaccessorWhileEach4d, + blockedaccessorWhileEach5d, + blockedaccessorWhileEach6d, + blockedaccessorWhileEach7d, + blockedaccessorWhileEach8d, + blockedaccessorWhileEach9d, + blockedaccessorWhileEach10d // 8 +]; +var MAX_DIMS = WHILE_EACH.length - 1; + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* ## Notes +* +* - A provided ndarray should be an object with the following properties: +* +* - **dtype**: data type. +* - **data**: data buffer. +* - **shape**: dimensions. +* - **strides**: stride lengths. +* - **offset**: index offset. +* - **order**: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style). +* +* @param {ArrayLikeObject} arrays - array-like object containing one input array +* @param {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} [thisArg] - callback function execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value === value; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the shape of the array: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Apply the callback function: +* whileEach( [ x ], predicate, naryFunction( log, 1 ) ); +*/ +function whileEach( arrays, predicate, fcn, thisArg ) { + var ndims; + var shx; + var x; + + // Unpack the ndarray and standardize ndarray meta data: + x = ndarray2object( arrays[ 0 ] ); + shx = x.shape; + ndims = shx.length; + + // Determine whether we can avoid iteration altogether... + if ( ndims === 0 ) { + if ( x.accessorProtocol ) { + return ACCESSOR_WHILE_EACH[ ndims ]( x, predicate, fcn, thisArg ); + } + return WHILE_EACH[ ndims ]( x, predicate, fcn, thisArg ); + } + // Check whether we were provided an empty ndarray... + if ( numel( shx ) === 0 ) { + return; + } + // Determine whether we can avoid blocked iteration... + if ( ndims <= MAX_DIMS && iterationOrder( x.strides ) !== 0 ) { + // So long as iteration 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 ( x.accessorProtocol ) { + return ACCESSOR_WHILE_EACH[ ndims ]( x, predicate, fcn, thisArg ); + } + return WHILE_EACH[ ndims ]( x, predicate, fcn, thisArg ); + } + // Determine whether we can perform blocked iteration... + if ( ndims <= MAX_DIMS ) { + if ( x.accessorProtocol ) { + return BLOCKED_ACCESSOR_WHILE_EACH[ ndims-2 ]( x, predicate, fcn, thisArg ); + } + return BLOCKED_WHILE_EACH[ ndims-2 ]( x, predicate, fcn, thisArg ); + } + // Fall-through to linear view iteration without regard for how data is stored in memory (i.e., take the slow path)... + if ( x.accessorProtocol ) { + return accessorWhileEachnd( x, predicate, fcn, thisArg ); + } + whileEachnd( x, predicate, fcn, thisArg ); +} + + +// EXPORTS // + +module.exports = whileEach; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/nd.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/nd.js new file mode 100644 index 000000000000..f10eadbeb232 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/nd.js @@ -0,0 +1,131 @@ +/** +* @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' ); +var ind2sub = require( '@stdlib/ndarray/base/ind2sub' ); + + +// VARIABLES // + +var MODE = 'throw'; + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 8 ); +* +* // Define the shape of the array: +* var shape = [ 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Apply the callback function: +* whileEachnd( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function whileEachnd( x, predicate, fcn, thisArg ) { + var xbuf; + var ordx; + var len; + var idx; + var sh; + var sx; + var ox; + var ix; + var i; + var v; + + sh = x.shape; + + // Compute the total number of elements over which to iterate: + len = numel( sh ); + + // Cache a reference to the input ndarray data buffer: + xbuf = x.data; + + // Cache a reference to the stride array: + sx = x.strides; + + // Cache the index of the first indexed element: + ox = x.offset; + + // Cache the array order: + ordx = x.order; + + // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory... + for ( i = 0; i < len; i++ ) { + ix = vind2bind( sh, sx, ox, ordx, i, MODE ); + idx = ind2sub( sh, sx, 0, ordx, i, MODE ); // return subscripts from the perspective of the ndarray view + v = xbuf[ ix ]; + if ( !predicate( v, idx, x.ref ) ) { + return; + } + fcn.call( thisArg, v, idx, x.ref ); + } +} + + +// EXPORTS // + +module.exports = whileEachnd; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/nd_accessors.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/nd_accessors.js new file mode 100644 index 000000000000..e06b7d0ea06c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/nd_accessors.js @@ -0,0 +1,149 @@ +/** +* @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' ); +var ind2sub = require( '@stdlib/ndarray/base/ind2sub' ); + + +// VARIABLES // + +var MODE = 'throw'; + + +// MAIN // + +/** +* While a test condition is true, invokes a callback function for each element in an ndarray. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @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 {Function} predicate - predicate function +* @param {Callback} fcn - callback function +* @param {*} thisArg - callback function execution context +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var log = require( '@stdlib/console/log' ); +* +* function predicate( value ) { +* return value !== null; +* } +* +* function fcn( value ) { +* log( '%s', value.toString() ); +* } +* +* // Create a data buffer: +* var xbuf = new Complex64Array( 8 ); +* +* // Define the shape of the array: +* var shape = [ 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create an ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Apply the callback function: +* whileEachnd( x, predicate, fcn, {} ); +*/ +function whileEachnd( x, predicate, fcn, thisArg ) { + var xbuf; + var ordx; + var len; + var get; + var idx; + var sh; + var sx; + var ox; + var ix; + var i; + var v; + + sh = x.shape; + + // Compute the total number of elements over which to iterate: + len = numel( sh ); + + // Cache a reference to the input ndarray data buffer: + xbuf = x.data; + + // Cache a reference to the stride array: + sx = x.strides; + + // Cache the index of the first indexed element: + ox = x.offset; + + // Cache the array order: + ordx = x.order; + + // Cache accessor: + get = x.accessors[ 0 ]; + + // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory... + for ( i = 0; i < len; i++ ) { + ix = vind2bind( sh, sx, ox, ordx, i, MODE ); + idx = ind2sub( sh, sx, 0, ordx, i, MODE ); // return subscripts from the perspective of the ndarray view + v = get( xbuf, ix ); + if ( !predicate( v, idx, x.ref ) ) { + return; + } + fcn.call( thisArg, v, idx, x.ref ); + } +} + + +// EXPORTS // + +module.exports = whileEachnd; diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/package.json b/lib/node_modules/@stdlib/ndarray/base/while-each/package.json new file mode 100644 index 000000000000..01f214559dfc --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/ndarray/base/while-each", + "version": "0.0.0", + "description": "While a test condition is true, invoke a callback function for each element in an ndarray.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "base", + "strided", + "array", + "ndarray", + "unary", + "apply", + "while", + "while-each", + "predicate", + "test", + "condition" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/test/test.0d.js b/lib/node_modules/@stdlib/ndarray/base/while-each/test/test.0d.js new file mode 100644 index 000000000000..0e0b37b6d7f5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/test/test.0d.js @@ -0,0 +1,192 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var whileEach = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof whileEach, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function invokes a callback function for the element of a 0-dimensional ndarray while a test condition is true', function test( t ) { + var expected; + var values; + var x; + + values = []; + x = scalar2ndarray( 4.0, { + 'dtype': 'float64' + }); + whileEach( [ x ], predicate, fcn ); + + expected = [ 4.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + values = []; + x = scalar2ndarray( 3.0, { + 'dtype': 'float64' + }); + whileEach( [ x ], predicate, fcn ); + + expected = []; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v % 2.0 === 0.0; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function invokes a callback function for the element of a 0-dimensional ndarray while a test condition is true (accessors)', function test( t ) { + var expected; + var values; + var x; + + values = []; + x = scalar2ndarray( new Complex128( 4.0, 0.0 ), { + 'dtype': 'complex128' + }); + whileEach( [ x ], predicate, fcn ); + + expected = [ + [ 4.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + values = []; + x = scalar2ndarray( new Complex128( 3.0, 0.0 ), { + 'dtype': 'complex128' + }); + whileEach( [ x ], predicate, fcn ); + + expected = []; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) % 2.0 === 0.0; + } + + function fcn( v ) { + values.push( [ real( v ), imag( v ) ] ); + } +}); + +tape( 'the function supports specifying the callback execution context (0-dimensional)', function test( t ) { + var expected; + var indices; + var arrays; + var values; + var ctx; + var x; + + x = scalar2ndarray( 4.0, { + 'dtype': 'float64' + }); + + indices = []; + values = []; + arrays = []; + + ctx = { + 'count': 0 + }; + whileEach( [ x ], predicate, fcn, ctx ); + + t.strictEqual( ctx.count, 1, 'returns expected value' ); + + expected = [ 4.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ [] ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ x ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( v ); + indices.push( idx ); + arrays.push( arr ); + } +}); + +tape( 'the function supports specifying the callback execution context (0-dimensional, predicate returns false)', function test( t ) { + var indices; + var arrays; + var values; + var ctx; + var x; + + x = scalar2ndarray( 4.0, { + 'dtype': 'float64' + }); + + indices = []; + values = []; + arrays = []; + + ctx = { + 'count': 0 + }; + whileEach( [ x ], predicate, fcn, ctx ); + + t.strictEqual( ctx.count, 0, 'returns expected value' ); + t.deepEqual( values, [], 'returns expected value' ); + t.deepEqual( indices, [], 'returns expected value' ); + t.deepEqual( arrays, [], 'returns expected value' ); + + t.end(); + + function predicate() { + return false; + } + + function fcn( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( v ); + indices.push( idx ); + arrays.push( arr ); + } +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/test/test.1d.js b/lib/node_modules/@stdlib/ndarray/base/while-each/test/test.1d.js new file mode 100644 index 000000000000..73e3a279c067 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/test/test.1d.js @@ -0,0 +1,321 @@ +/** +* @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 oneTo = require( '@stdlib/array/one-to' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var whileEach = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof whileEach, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function invokes a callback function for each element in a 1-dimensional ndarray while a test condition is true', function test( t ) { + var expected; + var values; + var x; + + values = []; + x = ndarray( 'float64', oneTo( 4, 'float64' ), [ 4 ], [ 1 ], 0, 'row-major' ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ 1.0, 2.0, 3.0, 4.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function stops invoking a callback function once a test condition becomes false (1-dimensional)', function test( t ) { + var expected; + var values; + var x; + + values = []; + x = ndarray( 'float64', oneTo( 4, 'float64' ), [ 4 ], [ 1 ], 0, 'row-major' ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ 1.0, 2.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v < 3.0; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function does not invoke a callback function if a test condition is false on the first iteration (1-dimensional)', function test( t ) { + var expected; + var values; + var x; + + values = []; + x = ndarray( 'float64', oneTo( 4, 'float64' ), [ 4 ], [ 1 ], 0, 'row-major' ); + + whileEach( [ x ], predicate, fcn ); + + expected = []; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return false; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function invokes a callback function for each element in a 1-dimensional ndarray while a test condition is true (negative strides, accessors)', function test( t ) { + var expected; + var values; + var x; + + values = []; + x = ndarray( 'complex128', oneTo( 4, 'complex128' ), [ 4 ], [ -1 ], 3, 'row-major' ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ + [ 4.0, 0.0 ], + [ 3.0, 0.0 ], + [ 2.0, 0.0 ], + [ 1.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn( v ) { + values.push( [ real( v ), imag( v ) ] ); + } +}); + +tape( 'the function invokes a callback function for each element in a 1-dimensional ndarray while a test condition is true (negative strides)', function test( t ) { + var expected; + var values; + var x; + + values = []; + x = ndarray( 'float64', oneTo( 4, 'float64' ), [ 4 ], [ -1 ], 3, 'row-major' ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ 4.0, 3.0, 2.0, 1.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function invokes a callback function for each element in a 1-dimensional ndarray while a test condition is true (accessors)', function test( t ) { + var expected; + var values; + var x; + + values = []; + x = ndarray( 'complex128', oneTo( 4, 'complex128' ), [ 4 ], [ 1 ], 0, 'row-major' ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ], + [ 3.0, 0.0 ], + [ 4.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn( v ) { + values.push( [ real( v ), imag( v ) ] ); + } +}); + +tape( 'the function stops invoking a callback function once a test condition becomes false (1-dimensional, accessors)', function test( t ) { + var expected; + var values; + var x; + + values = []; + x = ndarray( 'complex128', oneTo( 4, 'complex128' ), [ 4 ], [ 1 ], 0, 'row-major' ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) < 3.0; + } + + function fcn( v ) { + values.push( [ real( v ), imag( v ) ] ); + } +}); + +tape( 'the function supports specifying the callback execution context', function test( t ) { + var expected; + var indices; + var arrays; + var values; + var ctx; + var x; + + x = ndarray( 'float64', oneTo( 4, 'float64' ), [ 4 ], [ 1 ], 0, 'row-major' ); + + indices = []; + values = []; + arrays = []; + + ctx = { + 'count': 0 + }; + whileEach( [ x ], predicate, fcn, ctx ); + + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + expected = [ 1.0, 2.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0 ], + [ 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v < 3.0; + } + + function fcn( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( v ); + indices.push( idx ); + arrays.push( arr ); + } +}); + +tape( 'the function supports specifying the callback execution context (accessors)', function test( t ) { + var expected; + var indices; + var arrays; + var values; + var ctx; + var x; + + x = ndarray( 'complex128', oneTo( 4, 'complex128' ), [ 4 ], [ 1 ], 0, 'row-major' ); + + indices = []; + values = []; + arrays = []; + + ctx = { + 'count': 0 + }; + whileEach( [ x ], predicate, fcn, ctx ); + + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0 ], + [ 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) < 3.0; + } + + function fcn( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + arrays.push( arr ); + } +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/test/test.2d.js b/lib/node_modules/@stdlib/ndarray/base/while-each/test/test.2d.js new file mode 100644 index 000000000000..9b9951da8fa8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/test/test.2d.js @@ -0,0 +1,1470 @@ +/** +* @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 oneTo = require( '@stdlib/array/one-to' ); +var zeros = require( '@stdlib/array/zeros' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var whileEach = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof whileEach, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (row-major, singleton dimensions)', function test( t ) { + var expected; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 4, 1 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + values = []; + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ 1.0, 2.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v < 3.0; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (row-major, singleton dimensions, accessors)', function test( t ) { + var expected; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 4, 1 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + values = []; + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) < 3.0; + } + + function fcn( v ) { + values.push( [ real( v ), imag( v ) ] ); + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (row-major, contiguous)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ 1.0, 2.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v < 3.0; + } + + function fcn( v, idx ) { + values.push( v ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (row-major, contiguous, negative strides)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ -2, -1 ]; + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ 4.0, 3.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v > 2.0; + } + + function fcn( v, idx ) { + values.push( v ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (row-major, non-contiguous, same sign strides)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ 4, 2 ]; + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ 1.0, 3.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v < 5.0; + } + + function fcn( v, idx ) { + values.push( v ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (row-major, non-contiguous, mixed sign strides)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ 4, -2 ]; + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ 3.0, 1.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v < 7.0; + } + + function fcn( v, idx ) { + values.push( v ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (row-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var count; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ bsize*2, 2 ]; + st = [ -4, 2 ]; + o = strides2offset( sh, st ); + + count = 0; + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = numel( sh ); + t.strictEqual( count, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn() { + count += 1; + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (row-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var count; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 2, bsize*2 ]; + st = [ bsize*4, -2 ]; + o = strides2offset( sh, st ); + + count = 0; + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = numel( sh ); + t.strictEqual( count, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn() { + count += 1; + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (row-major, contiguous, accessors)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) < 3.0; + } + + function fcn( v, idx ) { + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (row-major, contiguous, negative strides, accessors)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ -2, -1 ]; + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ + [ 4.0, 0.0 ], + [ 3.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) > 2.0; + } + + function fcn( v, idx ) { + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (row-major, non-contiguous, same sign strides, accessors)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ 4, 2 ]; + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ + [ 1.0, 0.0 ], + [ 3.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) < 5.0; + } + + function fcn( v, idx ) { + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (row-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ 4, -2 ]; + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh )*2*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ + [ 3.0, 0.0 ], + [ 1.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) < 7.0; + } + + function fcn( v, idx ) { + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var count; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ bsize*2, 2 ]; + st = [ -4, 2 ]; + o = strides2offset( sh, st ); + + count = 0; + x = ndarray( dt, zeros( numel( sh )*4, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = numel( sh ); + t.strictEqual( count, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn() { + count += 1; + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var count; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 2, bsize*2 ]; + st = [ bsize*4, -2 ]; + o = strides2offset( sh, st ); + + count = 0; + x = ndarray( dt, zeros( numel( sh )*4, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = numel( sh ); + t.strictEqual( count, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn() { + count += 1; + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (column-major, singleton dimensions)', function test( t ) { + var expected; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 1, 4 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + values = []; + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ 1.0, 2.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v < 3.0; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (column-major, singleton dimensions, accessors)', function test( t ) { + var expected; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 1, 4 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + values = []; + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) < 3.0; + } + + function fcn( v ) { + values.push( [ real( v ), imag( v ) ] ); + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (column-major, contiguous)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ 1.0, 2.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 1, 0 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v < 3.0; + } + + function fcn( v, idx ) { + values.push( v ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (column-major, contiguous, negative strides)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ -1, -2 ]; + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ 4.0, 3.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 1, 0 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v > 2.0; + } + + function fcn( v, idx ) { + values.push( v ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (column-major, non-contiguous, same sign strides)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ 2, 4 ]; + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ 1.0, 3.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 1, 0 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v < 5.0; + } + + function fcn( v, idx ) { + values.push( v ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (column-major, non-contiguous, mixed sign strides)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ -2, 4 ]; + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ 3.0, 1.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 1, 0 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v < 7.0; + } + + function fcn( v, idx ) { + values.push( v ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (column-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var count; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ bsize*2, 2 ]; + st = [ 2, -bsize*4 ]; + o = strides2offset( sh, st ); + + count = 0; + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = numel( sh ); + t.strictEqual( count, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn() { + count += 1; + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (column-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var count; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ 2, bsize*2 ]; + st = [ -2, 4 ]; + o = strides2offset( sh, st ); + + count = 0; + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = numel( sh ); + t.strictEqual( count, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn() { + count += 1; + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (column-major, contiguous, accessors)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 1, 0 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) < 3.0; + } + + function fcn( v, idx ) { + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (column-major, contiguous, negative strides, accessors)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ -1, -2 ]; + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ + [ 4.0, 0.0 ], + [ 3.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 1, 0 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) > 2.0; + } + + function fcn( v, idx ) { + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (column-major, non-contiguous, same sign strides, accessors)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ 2, 4 ]; + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ + [ 1.0, 0.0 ], + [ 3.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 1, 0 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) < 5.0; + } + + function fcn( v, idx ) { + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (column-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ -2, 4 ]; + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh )*2*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ + [ 3.0, 0.0 ], + [ 1.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 1, 0 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) < 7.0; + } + + function fcn( v, idx ) { + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var count; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ bsize*2, 2 ]; + st = [ -2, bsize*2 ]; + o = strides2offset( sh, st ); + + count = 0; + x = ndarray( dt, zeros( numel( sh )*4, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = numel( sh ); + t.strictEqual( count, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn() { + count += 1; + } +}); + +tape( 'the function invokes a callback function for each element in a 2-dimensional ndarray while a test condition is true (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var count; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ 2, bsize*2 ]; + st = [ 2, -4 ]; + o = strides2offset( sh, st ); + + count = 0; + x = ndarray( dt, zeros( numel( sh )*4, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = numel( sh ); + t.strictEqual( count, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn() { + count += 1; + } +}); + +tape( 'the function supports specifying the callback execution context (row-major, contiguous)', function test( t ) { + var expected; + var indices; + var arrays; + var values; + var ctx; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + indices = []; + values = []; + arrays = []; + + ctx = { + 'count': 0 + }; + whileEach( [ x ], predicate, fcn, ctx ); + + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + expected = [ 1.0, 2.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v < 3.0; + } + + function fcn( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( v ); + indices.push( idx ); + arrays.push( arr ); + } +}); + +tape( 'the function supports specifying the callback execution context (row-major, contiguous, accessors)', function test( t ) { + var expected; + var indices; + var arrays; + var values; + var ctx; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + indices = []; + values = []; + arrays = []; + + ctx = { + 'count': 0 + }; + whileEach( [ x ], predicate, fcn, ctx ); + + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) < 3.0; + } + + function fcn( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + arrays.push( arr ); + } +}); + +tape( 'the function supports specifying the callback execution context (column-major, contiguous)', function test( t ) { + var expected; + var indices; + var arrays; + var values; + var ctx; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + indices = []; + values = []; + arrays = []; + + ctx = { + 'count': 0 + }; + whileEach( [ x ], predicate, fcn, ctx ); + + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + expected = [ 1.0, 2.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 1, 0 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v < 3.0; + } + + function fcn( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( v ); + indices.push( idx ); + arrays.push( arr ); + } +}); + +tape( 'the function supports specifying the callback execution context (column-major, contiguous, accessors)', function test( t ) { + var expected; + var indices; + var arrays; + var values; + var ctx; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + indices = []; + values = []; + arrays = []; + + ctx = { + 'count': 0 + }; + whileEach( [ x ], predicate, fcn, ctx ); + + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 1, 0 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) < 3.0; + } + + function fcn( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + arrays.push( arr ); + } +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/test/test.3d.js b/lib/node_modules/@stdlib/ndarray/base/while-each/test/test.3d.js new file mode 100644 index 000000000000..0d8e1c5c8fff --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/test/test.3d.js @@ -0,0 +1,1622 @@ +/** +* @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 oneTo = require( '@stdlib/array/one-to' ); +var zeros = require( '@stdlib/array/zeros' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var whileEach = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof whileEach, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (row-major, singleton dimensions)', function test( t ) { + var expected; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 4, 1, 1 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + values = []; + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ 1.0, 2.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v < 3.0; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (row-major, singleton dimensions, accessors)', function test( t ) { + var expected; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 4, 1, 1 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + values = []; + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) < 3.0; + } + + function fcn( v ) { + values.push( [ real( v ), imag( v ) ] ); + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (row-major, contiguous)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ 1.0, 2.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 0, 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v < 3.0; + } + + function fcn( v, idx ) { + values.push( v ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (row-major, contiguous, negative strides)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = [ -2, -2, -1 ]; + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ 4.0, 3.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 0, 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v > 2.0; + } + + function fcn( v, idx ) { + values.push( v ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (row-major, non-contiguous, same sign strides)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = [ 4, 4, 2 ]; + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ 1.0, 3.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 0, 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v < 5.0; + } + + function fcn( v, idx ) { + values.push( v ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (row-major, non-contiguous, mixed sign strides)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = [ 4, -4, -2 ]; + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ 3.0, 1.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 0, 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v < 7.0; + } + + function fcn( v, idx ) { + values.push( v ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (row-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var count; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ bsize*2, 1, 2 ]; + st = [ -4, 4, 2 ]; + o = strides2offset( sh, st ); + + count = 0; + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = numel( sh ); + t.strictEqual( count, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn() { + count += 1; + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (row-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var count; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 2, bsize*2, 1 ]; + st = [ bsize*4, -2, 2 ]; + o = strides2offset( sh, st ); + + count = 0; + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = numel( sh ); + t.strictEqual( count, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn() { + count += 1; + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (row-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var count; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, bsize*2 ]; + st = [ bsize*4, -bsize*4, 2 ]; + o = strides2offset( sh, st ); + + count = 0; + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = numel( sh ); + t.strictEqual( count, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn() { + count += 1; + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (row-major, contiguous, accessors)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 0, 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) < 3.0; + } + + function fcn( v, idx ) { + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (row-major, contiguous, negative strides, accessors)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = [ -2, -2, -1 ]; + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ + [ 4.0, 0.0 ], + [ 3.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 0, 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) > 2.0; + } + + function fcn( v, idx ) { + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (row-major, non-contiguous, same sign strides, accessors)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = [ 4, 4, 2 ]; + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ + [ 1.0, 0.0 ], + [ 3.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 0, 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) < 5.0; + } + + function fcn( v, idx ) { + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (row-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = [ 4, -4, -2 ]; + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh )*2*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ + [ 3.0, 0.0 ], + [ 1.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 0, 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) < 7.0; + } + + function fcn( v, idx ) { + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var count; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ bsize*2, 1, 2 ]; + st = [ -4, 4, 2 ]; + o = strides2offset( sh, st ); + + count = 0; + x = ndarray( dt, zeros( numel( sh )*4, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = numel( sh ); + t.strictEqual( count, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn() { + count += 1; + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var count; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 2, bsize*2, 1 ]; + st = [ bsize*4, -2, -2 ]; + o = strides2offset( sh, st ); + + count = 0; + x = ndarray( dt, zeros( numel( sh )*4, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = numel( sh ); + t.strictEqual( count, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn() { + count += 1; + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var count; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, bsize*2 ]; + st = [ bsize*4, -bsize*4, -2 ]; + o = strides2offset( sh, st ); + + count = 0; + x = ndarray( dt, zeros( numel( sh )*4, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = numel( sh ); + t.strictEqual( count, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn() { + count += 1; + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (column-major, singleton dimensions)', function test( t ) { + var expected; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 1, 1, 4 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + values = []; + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ 1.0, 2.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v < 3.0; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (column-major, singleton dimensions, accessors)', function test( t ) { + var expected; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 1, 1, 4 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + values = []; + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) < 3.0; + } + + function fcn( v ) { + values.push( [ real( v ), imag( v ) ] ); + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (column-major, contiguous)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ 1.0, 2.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 1, 0, 0 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v < 3.0; + } + + function fcn( v, idx ) { + values.push( v ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (column-major, contiguous, negative strides)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = [ -1, -2, -2 ]; + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ 4.0, 3.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 1, 0, 0 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v > 2.0; + } + + function fcn( v, idx ) { + values.push( v ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (column-major, non-contiguous, same sign strides)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = [ 2, 4, 4 ]; + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ 1.0, 3.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 1, 0, 0 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v < 5.0; + } + + function fcn( v, idx ) { + values.push( v ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (column-major, non-contiguous, mixed sign strides)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = [ -2, 4, 4 ]; + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ 3.0, 1.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 1, 0, 0 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v < 7.0; + } + + function fcn( v, idx ) { + values.push( v ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (column-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var count; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ bsize*2, 1, 2 ]; + st = [ 2, -bsize*4, bsize*4 ]; + o = strides2offset( sh, st ); + + count = 0; + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = numel( sh ); + t.strictEqual( count, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn() { + count += 1; + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (column-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var count; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ 2, bsize*2, 1 ]; + st = [ -2, 4, bsize*8 ]; + o = strides2offset( sh, st ); + + count = 0; + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = numel( sh ); + t.strictEqual( count, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn() { + count += 1; + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (column-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var count; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, bsize*2 ]; + st = [ -2, 4, 4 ]; + o = strides2offset( sh, st ); + + count = 0; + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = numel( sh ); + t.strictEqual( count, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn() { + count += 1; + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (column-major, contiguous, accessors)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 1, 0, 0 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) < 3.0; + } + + function fcn( v, idx ) { + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (column-major, contiguous, negative strides, accessors)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = [ -1, -2, -2 ]; + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ + [ 4.0, 0.0 ], + [ 3.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 1, 0, 0 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) > 2.0; + } + + function fcn( v, idx ) { + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (column-major, non-contiguous, same sign strides, accessors)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = [ 2, 4, 4 ]; + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ + [ 1.0, 0.0 ], + [ 3.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 1, 0, 0 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) < 5.0; + } + + function fcn( v, idx ) { + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (column-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var expected; + var indices; + var values; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = [ -2, -4, 4 ]; + o = strides2offset( sh, st ); + + values = []; + indices = []; + x = ndarray( dt, oneTo( numel( sh )*2*2, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = [ + [ 3.0, 0.0 ], + [ 1.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 1, 0, 0 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) < 7.0; + } + + function fcn( v, idx ) { + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var count; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ bsize*2, 1, 2 ]; + st = [ -2, bsize*4, bsize*4 ]; + o = strides2offset( sh, st ); + + count = 0; + x = ndarray( dt, zeros( numel( sh )*4, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = numel( sh ); + t.strictEqual( count, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn() { + count += 1; + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var count; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ 2, bsize*2, 1 ]; + st = [ 2, -4, bsize*8 ]; + o = strides2offset( sh, st ); + + count = 0; + x = ndarray( dt, zeros( numel( sh )*4, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = numel( sh ); + t.strictEqual( count, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn() { + count += 1; + } +}); + +tape( 'the function invokes a callback function for each element in a 3-dimensional ndarray while a test condition is true (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var count; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, bsize*2 ]; + st = [ 2, -4, 4 ]; + o = strides2offset( sh, st ); + + count = 0; + x = ndarray( dt, zeros( numel( sh )*4, dt ), sh, st, o, ord ); + + whileEach( [ x ], predicate, fcn ); + + expected = numel( sh ); + t.strictEqual( count, expected, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn() { + count += 1; + } +}); + +tape( 'the function supports specifying the callback execution context (row-major, contiguous)', function test( t ) { + var expected; + var indices; + var arrays; + var values; + var ctx; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + indices = []; + values = []; + arrays = []; + + ctx = { + 'count': 0 + }; + whileEach( [ x ], predicate, fcn, ctx ); + + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + expected = [ 1.0, 2.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 0, 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v < 3.0; + } + + function fcn( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( v ); + indices.push( idx ); + arrays.push( arr ); + } +}); + +tape( 'the function supports specifying the callback execution context (row-major, contiguous, accessors)', function test( t ) { + var expected; + var indices; + var arrays; + var values; + var ctx; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + indices = []; + values = []; + arrays = []; + + ctx = { + 'count': 0 + }; + whileEach( [ x ], predicate, fcn, ctx ); + + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 0, 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) < 3.0; + } + + function fcn( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + arrays.push( arr ); + } +}); + +tape( 'the function supports specifying the callback execution context (column-major, contiguous)', function test( t ) { + var expected; + var indices; + var arrays; + var values; + var ctx; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + indices = []; + values = []; + arrays = []; + + ctx = { + 'count': 0 + }; + whileEach( [ x ], predicate, fcn, ctx ); + + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + expected = [ 1.0, 2.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 1, 0, 0 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v < 3.0; + } + + function fcn( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( v ); + indices.push( idx ); + arrays.push( arr ); + } +}); + +tape( 'the function supports specifying the callback execution context (column-major, contiguous, accessors)', function test( t ) { + var expected; + var indices; + var arrays; + var values; + var ctx; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + indices = []; + values = []; + arrays = []; + + ctx = { + 'count': 0 + }; + whileEach( [ x ], predicate, fcn, ctx ); + + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 1, 0, 0 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) < 3.0; + } + + function fcn( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + arrays.push( arr ); + } +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/test/test.js b/lib/node_modules/@stdlib/ndarray/base/while-each/test/test.js new file mode 100644 index 000000000000..ab0fba6f2da9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/test/test.js @@ -0,0 +1,56 @@ +/** +* @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 ones = require( '@stdlib/array/ones' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var whileEach = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof whileEach, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function does not invoke a provided callback function if provided an empty input ndarray', function test( t ) { + var count; + var x; + + count = 0; + x = ndarray( 'float64', ones( 8, 'float64' ), [ 0 ], [ 1 ], 0, 'row-major' ); + + whileEach( [ x ], predicate, fcn ); + t.strictEqual( count, 0, 'returns expected value' ); + + t.end(); + + function predicate() { + return true; + } + + function fcn() { + count += 1; + } +}); From e8a4191b2f89e3830c6f763709c047a93856c876 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 3 May 2026 21:32:11 +0500 Subject: [PATCH 2/2] fix: apply suggestions from code review --- lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d.js | 2 ++ .../@stdlib/ndarray/base/while-each/lib/5d_accessors.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d.js index 8d0d4291cdec..f0a986ca2906 100644 --- a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d.js +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d.js @@ -16,6 +16,8 @@ * limitations under the License. */ +/* eslint-disable max-depth */ + 'use strict'; // MODULES // diff --git a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d_accessors.js index e8fb98bff757..afe027f89f01 100644 --- a/lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/while-each/lib/5d_accessors.js @@ -16,6 +16,8 @@ * limitations under the License. */ +/* eslint-disable max-depth */ + 'use strict'; // MODULES //