From f335956e2268e935e4f70cd4b994d1f77c15b268 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 10 May 2026 18:06:16 +0500 Subject: [PATCH] feat: add ndarray/base/until-each --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/base/until-each/README.md | 200 +++ .../benchmark.10d_blocked_columnmajor.js | 156 ++ .../benchmark.10d_blocked_rowmajor.js | 156 ++ .../benchmark/benchmark.10d_columnmajor.js | 156 ++ .../benchmark/benchmark.10d_rowmajor.js | 156 ++ .../benchmark/benchmark.11d_columnmajor.js | 156 ++ .../benchmark/benchmark.11d_rowmajor.js | 156 ++ .../benchmark/benchmark.1d_columnmajor.js | 145 ++ .../benchmark/benchmark.1d_rowmajor.js | 145 ++ .../benchmark.2d_blocked_columnmajor.js | 157 ++ .../benchmark.2d_blocked_rowmajor.js | 157 ++ .../benchmark/benchmark.2d_columnmajor.js | 157 ++ .../benchmark/benchmark.2d_rowmajor.js | 157 ++ .../benchmark.2d_rowmajor_accessors.js | 183 ++ ...benchmark.2d_rowmajor_accessors_complex.js | 184 ++ .../benchmark.3d_blocked_columnmajor.js | 157 ++ .../benchmark.3d_blocked_rowmajor.js | 157 ++ .../benchmark/benchmark.3d_columnmajor.js | 157 ++ .../benchmark/benchmark.3d_rowmajor.js | 157 ++ .../benchmark.4d_blocked_columnmajor.js | 156 ++ .../benchmark.4d_blocked_rowmajor.js | 156 ++ .../benchmark/benchmark.4d_columnmajor.js | 156 ++ .../benchmark/benchmark.4d_rowmajor.js | 156 ++ .../benchmark.5d_blocked_columnmajor.js | 156 ++ .../benchmark.5d_blocked_rowmajor.js | 156 ++ .../benchmark/benchmark.5d_columnmajor.js | 156 ++ .../benchmark/benchmark.5d_rowmajor.js | 156 ++ .../benchmark.6d_blocked_columnmajor.js | 156 ++ .../benchmark.6d_blocked_rowmajor.js | 156 ++ .../benchmark/benchmark.6d_columnmajor.js | 156 ++ .../benchmark/benchmark.6d_rowmajor.js | 156 ++ .../benchmark.7d_blocked_columnmajor.js | 156 ++ .../benchmark.7d_blocked_rowmajor.js | 156 ++ .../benchmark/benchmark.7d_columnmajor.js | 156 ++ .../benchmark/benchmark.7d_rowmajor.js | 156 ++ .../benchmark.8d_blocked_columnmajor.js | 156 ++ .../benchmark.8d_blocked_rowmajor.js | 156 ++ .../benchmark/benchmark.8d_columnmajor.js | 156 ++ .../benchmark/benchmark.8d_rowmajor.js | 156 ++ .../benchmark.9d_blocked_columnmajor.js | 156 ++ .../benchmark.9d_blocked_rowmajor.js | 156 ++ .../benchmark/benchmark.9d_columnmajor.js | 156 ++ .../benchmark/benchmark.9d_rowmajor.js | 156 ++ .../ndarray/base/until-each/docs/repl.txt | 70 + .../base/until-each/docs/types/index.d.ts | 143 ++ .../base/until-each/docs/types/test.ts | 134 ++ .../ndarray/base/until-each/examples/index.js | 77 + .../@stdlib/ndarray/base/until-each/lib/0d.js | 86 + .../base/until-each/lib/0d_accessors.js | 100 ++ .../ndarray/base/until-each/lib/10d.js | 224 +++ .../base/until-each/lib/10d_accessors.js | 242 +++ .../base/until-each/lib/10d_blocked.js | 322 ++++ .../until-each/lib/10d_blocked_accessors.js | 340 ++++ .../@stdlib/ndarray/base/until-each/lib/1d.js | 111 ++ .../base/until-each/lib/1d_accessors.js | 129 ++ .../@stdlib/ndarray/base/until-each/lib/2d.js | 142 ++ .../base/until-each/lib/2d_accessors.js | 160 ++ .../ndarray/base/until-each/lib/2d_blocked.js | 168 ++ .../until-each/lib/2d_blocked_accessors.js | 186 +++ .../@stdlib/ndarray/base/until-each/lib/3d.js | 152 ++ .../base/until-each/lib/3d_accessors.js | 170 ++ .../ndarray/base/until-each/lib/3d_blocked.js | 189 +++ .../until-each/lib/3d_blocked_accessors.js | 207 +++ .../@stdlib/ndarray/base/until-each/lib/4d.js | 162 ++ .../base/until-each/lib/4d_accessors.js | 180 ++ .../ndarray/base/until-each/lib/4d_blocked.js | 208 +++ .../until-each/lib/4d_blocked_accessors.js | 226 +++ .../@stdlib/ndarray/base/until-each/lib/5d.js | 174 ++ .../base/until-each/lib/5d_accessors.js | 192 +++ .../ndarray/base/until-each/lib/5d_blocked.js | 227 +++ .../until-each/lib/5d_blocked_accessors.js | 245 +++ .../@stdlib/ndarray/base/until-each/lib/6d.js | 184 ++ .../base/until-each/lib/6d_accessors.js | 202 +++ .../ndarray/base/until-each/lib/6d_blocked.js | 246 +++ .../until-each/lib/6d_blocked_accessors.js | 264 +++ .../@stdlib/ndarray/base/until-each/lib/7d.js | 194 +++ .../base/until-each/lib/7d_accessors.js | 212 +++ .../ndarray/base/until-each/lib/7d_blocked.js | 265 +++ .../until-each/lib/7d_blocked_accessors.js | 283 ++++ .../@stdlib/ndarray/base/until-each/lib/8d.js | 204 +++ .../base/until-each/lib/8d_accessors.js | 222 +++ .../ndarray/base/until-each/lib/8d_blocked.js | 284 ++++ .../until-each/lib/8d_blocked_accessors.js | 302 ++++ .../@stdlib/ndarray/base/until-each/lib/9d.js | 214 +++ .../base/until-each/lib/9d_accessors.js | 232 +++ .../ndarray/base/until-each/lib/9d_blocked.js | 303 ++++ .../until-each/lib/9d_blocked_accessors.js | 321 ++++ .../ndarray/base/until-each/lib/index.js | 70 + .../ndarray/base/until-each/lib/main.js | 226 +++ .../@stdlib/ndarray/base/until-each/lib/nd.js | 131 ++ .../base/until-each/lib/nd_accessors.js | 149 ++ .../ndarray/base/until-each/package.json | 66 + .../ndarray/base/until-each/test/test.0d.js | 229 +++ .../ndarray/base/until-each/test/test.1d.js | 195 +++ .../ndarray/base/until-each/test/test.2d.js | 1312 +++++++++++++++ .../ndarray/base/until-each/test/test.3d.js | 1485 +++++++++++++++++ .../ndarray/base/until-each/test/test.js | 59 + 97 files changed, 19613 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.10d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.10d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.10d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.10d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.11d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.11d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.1d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.1d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.2d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.2d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.2d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.2d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.2d_rowmajor_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.2d_rowmajor_accessors_complex.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.3d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.3d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.3d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.3d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.4d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.4d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.4d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.4d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.5d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.5d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.5d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.5d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.6d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.6d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.6d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.6d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.7d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.7d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.7d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.7d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.8d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.8d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.8d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.8d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.9d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.9d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.9d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.9d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/0d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/0d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/10d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/10d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/10d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/10d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/1d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/1d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/2d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/2d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/2d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/2d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/3d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/3d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/3d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/3d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/4d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/4d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/4d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/4d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/5d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/5d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/5d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/5d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/6d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/6d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/6d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/6d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/7d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/7d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/7d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/7d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/8d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/8d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/8d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/8d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/9d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/9d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/9d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/9d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/nd.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/lib/nd_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/test/test.0d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/test/test.1d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/test/test.2d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/test/test.3d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/until-each/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/README.md b/lib/node_modules/@stdlib/ndarray/base/until-each/README.md new file mode 100644 index 000000000000..d6d23c865ce6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/README.md @@ -0,0 +1,200 @@ + + +# untilEach + +> Invoke a callback function for each element in an ndarray until a predicate function returns a truthy value. + +
+ +
+ + + +
+ +## Usage + +```javascript +var untilEach = require( '@stdlib/ndarray/base/until-each' ); +``` + +#### untilEach( arrays, predicate, fcn\[, thisArg] ) + +Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. + +```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: +untilEach( [ x ], predicate, naryFunction( log, 1 ) ); +``` + +The function accepts the following arguments: + +- **arrays**: array-like object containing an input ndarray. +- **predicate**: predicate function. +- **fcn**: callback to apply. +- **thisArg**: callback execution context. + +The predicate and callback functions are both 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 untilEach = require( '@stdlib/ndarray/base/until-each' ); + +function predicate( value ) { + return ( value > 5 ); +} + +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 ) ); +untilEach( [ 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 ) ); +untilEach( [ 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 ) ); +untilEach( [ 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 ) ); +untilEach( [ x ], predicate, naryFunction( log, 2 ) ); +``` + +
+ + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.10d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.10d_blocked_columnmajor.js new file mode 100644 index 000000000000..44c0fcff469d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.10d_blocked_columnmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/10d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.10d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.10d_blocked_rowmajor.js new file mode 100644 index 000000000000..0bd3de162d6b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.10d_blocked_rowmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/10d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.10d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.10d_columnmajor.js new file mode 100644 index 000000000000..be1774c904ff --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.10d_columnmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/10d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.10d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.10d_rowmajor.js new file mode 100644 index 000000000000..2724add02389 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.10d_rowmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/10d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.11d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.11d_columnmajor.js new file mode 100644 index 000000000000..142ab0c890af --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.11d_columnmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/nd.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.11d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.11d_rowmajor.js new file mode 100644 index 000000000000..c63add3e0358 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.11d_rowmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/nd.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.1d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.1d_columnmajor.js new file mode 100644 index 000000000000..c07d064ffbdb --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.1d_columnmajor.js @@ -0,0 +1,145 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var 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 untilEach = require( './../lib' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( [ 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/until-each/benchmark/benchmark.1d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.1d_rowmajor.js new file mode 100644 index 000000000000..a32811594496 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.1d_rowmajor.js @@ -0,0 +1,145 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var 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 untilEach = require( './../lib' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( [ 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/until-each/benchmark/benchmark.2d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.2d_blocked_columnmajor.js new file mode 100644 index 000000000000..b8bda2229c25 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.2d_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 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 untilEach = require( './../lib/2d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.2d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.2d_blocked_rowmajor.js new file mode 100644 index 000000000000..b5225c37129a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.2d_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 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 untilEach = require( './../lib/2d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.2d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.2d_columnmajor.js new file mode 100644 index 000000000000..316044ca4435 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.2d_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 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 untilEach = require( './../lib/2d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.2d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.2d_rowmajor.js new file mode 100644 index 000000000000..e2da979380cd --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.2d_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 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 untilEach = require( './../lib/2d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.2d_rowmajor_accessors.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.2d_rowmajor_accessors.js new file mode 100644 index 000000000000..a7e77e4b3a90 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.2d_rowmajor_accessors.js @@ -0,0 +1,183 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = 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 +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.2d_rowmajor_accessors_complex.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.2d_rowmajor_accessors_complex.js new file mode 100644 index 000000000000..c35b91fd8ff9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.2d_rowmajor_accessors_complex.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 ctors = require( '@stdlib/array/typed-complex-ctors' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var untilEach = 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 +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.3d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.3d_blocked_columnmajor.js new file mode 100644 index 000000000000..efe673ad0580 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.3d_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 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 untilEach = require( './../lib/3d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.3d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.3d_blocked_rowmajor.js new file mode 100644 index 000000000000..a15e79650a61 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.3d_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 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 untilEach = require( './../lib/3d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.3d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.3d_columnmajor.js new file mode 100644 index 000000000000..c96d9e2cabed --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.3d_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 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 untilEach = require( './../lib/3d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.3d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.3d_rowmajor.js new file mode 100644 index 000000000000..5c9af2145a06 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.3d_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 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 untilEach = require( './../lib/3d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.4d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.4d_blocked_columnmajor.js new file mode 100644 index 000000000000..1da13b0bf25b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.4d_blocked_columnmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/4d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.4d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.4d_blocked_rowmajor.js new file mode 100644 index 000000000000..40376dd4f356 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.4d_blocked_rowmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/4d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.4d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.4d_columnmajor.js new file mode 100644 index 000000000000..a285149d8e71 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.4d_columnmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/4d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.4d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.4d_rowmajor.js new file mode 100644 index 000000000000..c2c7ee6f3bfa --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.4d_rowmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/4d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.5d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.5d_blocked_columnmajor.js new file mode 100644 index 000000000000..a632252c8c8c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.5d_blocked_columnmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/5d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.5d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.5d_blocked_rowmajor.js new file mode 100644 index 000000000000..8b73d2055324 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.5d_blocked_rowmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/5d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.5d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.5d_columnmajor.js new file mode 100644 index 000000000000..9bc5f699b0a0 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.5d_columnmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/5d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.5d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.5d_rowmajor.js new file mode 100644 index 000000000000..b2980531c7f5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.5d_rowmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/5d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.6d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.6d_blocked_columnmajor.js new file mode 100644 index 000000000000..aa1d6923ac65 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.6d_blocked_columnmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/6d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.6d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.6d_blocked_rowmajor.js new file mode 100644 index 000000000000..8dc95bd56c8d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.6d_blocked_rowmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/6d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.6d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.6d_columnmajor.js new file mode 100644 index 000000000000..9d353d2ff843 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.6d_columnmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/6d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.6d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.6d_rowmajor.js new file mode 100644 index 000000000000..084d9e7328d1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.6d_rowmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/6d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.7d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.7d_blocked_columnmajor.js new file mode 100644 index 000000000000..ba5d2dd2711b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.7d_blocked_columnmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/7d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.7d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.7d_blocked_rowmajor.js new file mode 100644 index 000000000000..32e373202458 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.7d_blocked_rowmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/7d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.7d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.7d_columnmajor.js new file mode 100644 index 000000000000..0f8cb4614fc6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.7d_columnmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/7d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.7d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.7d_rowmajor.js new file mode 100644 index 000000000000..67e3eed79d7c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.7d_rowmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/7d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.8d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.8d_blocked_columnmajor.js new file mode 100644 index 000000000000..fa0af8b00933 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.8d_blocked_columnmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/8d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.8d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.8d_blocked_rowmajor.js new file mode 100644 index 000000000000..fa0af8b00933 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.8d_blocked_rowmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/8d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.8d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.8d_columnmajor.js new file mode 100644 index 000000000000..4289c7efb408 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.8d_columnmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/8d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.8d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.8d_rowmajor.js new file mode 100644 index 000000000000..bdc23c64d4ee --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.8d_rowmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/8d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.9d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.9d_blocked_columnmajor.js new file mode 100644 index 000000000000..9effa8a7a625 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.9d_blocked_columnmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/9d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.9d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.9d_blocked_rowmajor.js new file mode 100644 index 000000000000..5473822f60ca --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.9d_blocked_rowmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/9d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.9d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.9d_columnmajor.js new file mode 100644 index 000000000000..b50a5d2b6d9c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.9d_columnmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/9d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/benchmark/benchmark.9d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.9d_rowmajor.js new file mode 100644 index 000000000000..c3a3bf792ff8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/benchmark/benchmark.9d_rowmajor.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib/9d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Predicate function invoked for each element in an ndarray. +* +* @private +* @returns {boolean} boolean indicating whether to stop iterating +*/ +function predicate() { + return false; +} + +/** +* 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++ ) { + untilEach( 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/until-each/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/until-each/docs/repl.txt new file mode 100644 index 000000000000..60aa897e0b2f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/docs/repl.txt @@ -0,0 +1,70 @@ + +{{alias}}( arrays, predicate, fcn[, thisArg] ) + Invokes a callback function for each element in an ndarray until a predicate + function returns a truthy value. + + 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). + + The predicate and callback functions are both 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}}( [ 0.0, 0.0, 0.0, 0.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 !== v ); }; + + // 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}}( [ 0.0, 0.0, 0.0, 0.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/until-each/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/until-each/docs/types/index.d.ts new file mode 100644 index 000000000000..7fbbfe523761 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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'; + +/** +* Predicate function invoked for each element in an ndarray. +*/ +type NullaryPredicate = ( this: ThisArg ) => boolean; + +/** +* Predicate function invoked for each element in an ndarray. +* +* @param value - current array element +*/ +type UnaryPredicate = ( this: ThisArg, 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 = ( this: ThisArg, 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 = ( this: ThisArg, 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; + +/** +* 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; + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* // 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: +* untilEach( [ x ], predicate, naryFunction( log, 1 ) ); +*/ +declare function untilEach = typedndarray, ThisArg = unknown>( arrays: ArrayLike, predicate: Predicate, fcn: Callback, thisArg?: ThisParameterType> ): void; + + +// EXPORTS // + +export = untilEach; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/until-each/docs/types/test.ts new file mode 100644 index 000000000000..4d984aa44b50 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 untilEach = require( './index' ); + +/** +* Predicate function. +* +* @param v - ndarray element +* @returns boolean indicating whether to stop iterating +*/ +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 ]; + + untilEach( arrays, predicate, clbk ); // $ExpectType void + untilEach( 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... +{ + untilEach( 5, predicate, clbk ); // $ExpectError + untilEach( true, predicate, clbk ); // $ExpectError + untilEach( false, predicate, clbk ); // $ExpectError + untilEach( null, predicate, clbk ); // $ExpectError + untilEach( undefined, predicate, clbk ); // $ExpectError + untilEach( {}, predicate, clbk ); // $ExpectError + untilEach( [ 1 ], predicate, clbk ); // $ExpectError + untilEach( ( x: number ): number => x, predicate, clbk ); // $ExpectError + + untilEach( 5, predicate, clbk, {} ); // $ExpectError + untilEach( true, predicate, clbk, {} ); // $ExpectError + untilEach( false, predicate, clbk, {} ); // $ExpectError + untilEach( null, predicate, clbk, {} ); // $ExpectError + untilEach( undefined, predicate, clbk, {} ); // $ExpectError + untilEach( {}, predicate, clbk, {} ); // $ExpectError + untilEach( [ 1 ], predicate, clbk, {} ); // $ExpectError + untilEach( ( 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 ]; + + untilEach( arrays, '10', clbk ); // $ExpectError + untilEach( arrays, 5, clbk ); // $ExpectError + untilEach( arrays, true, clbk ); // $ExpectError + untilEach( arrays, false, clbk ); // $ExpectError + untilEach( arrays, null, clbk ); // $ExpectError + untilEach( arrays, undefined, clbk ); // $ExpectError + untilEach( arrays, [], clbk ); // $ExpectError + untilEach( arrays, {}, clbk ); // $ExpectError + + untilEach( arrays, '10', clbk, {} ); // $ExpectError + untilEach( arrays, 5, clbk, {} ); // $ExpectError + untilEach( arrays, true, clbk, {} ); // $ExpectError + untilEach( arrays, false, clbk, {} ); // $ExpectError + untilEach( arrays, null, clbk, {} ); // $ExpectError + untilEach( arrays, undefined, clbk, {} ); // $ExpectError + untilEach( arrays, [], clbk, {} ); // $ExpectError + untilEach( 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 ]; + + untilEach( arrays, predicate, '10' ); // $ExpectError + untilEach( arrays, predicate, 5 ); // $ExpectError + untilEach( arrays, predicate, true ); // $ExpectError + untilEach( arrays, predicate, false ); // $ExpectError + untilEach( arrays, predicate, null ); // $ExpectError + untilEach( arrays, predicate, undefined ); // $ExpectError + untilEach( arrays, predicate, [] ); // $ExpectError + untilEach( arrays, predicate, {} ); // $ExpectError + + untilEach( arrays, predicate, '10', {} ); // $ExpectError + untilEach( arrays, predicate, 5, {} ); // $ExpectError + untilEach( arrays, predicate, true, {} ); // $ExpectError + untilEach( arrays, predicate, false, {} ); // $ExpectError + untilEach( arrays, predicate, null, {} ); // $ExpectError + untilEach( arrays, predicate, undefined, {} ); // $ExpectError + untilEach( arrays, predicate, [], {} ); // $ExpectError + untilEach( 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 ]; + + untilEach(); // $ExpectError + untilEach( arrays ); // $ExpectError + untilEach( arrays, predicate ); // $ExpectError + untilEach( arrays, predicate, clbk, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/until-each/examples/index.js new file mode 100644 index 000000000000..eb6b9d18089f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 untilEach = require( './../lib' ); + +function predicate( value ) { + return ( value > 5 ); +} + +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 ) ); +untilEach( [ 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 ) ); +untilEach( [ 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 ) ); +untilEach( [ 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 ) ); +untilEach( [ x ], predicate, naryFunction( log, 2 ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/0d.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/0d.js new file mode 100644 index 000000000000..be3f4496677d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* // 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: +* untilEach0d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function untilEach0d( x, predicate, fcn, thisArg ) { + var v = x.data[ x.offset ]; + if ( predicate.call( thisArg, v, [], x.ref ) ) { + return; + } + fcn.call( thisArg, v, [], x.ref ); +} + + +// EXPORTS // + +module.exports = untilEach0d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/0d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/0d_accessors.js new file mode 100644 index 000000000000..18d3b257f06f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* 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: +* untilEach0d( x, predicate, fcn, {} ); +*/ +function untilEach0d( x, predicate, fcn, thisArg ) { + var v = x.accessors[ 0 ]( x.data, x.offset ); + if ( predicate.call( thisArg, v, [], x.ref ) ) { + return; + } + fcn.call( thisArg, v, [], x.ref ); +} + + +// EXPORTS // + +module.exports = untilEach0d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/10d.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/10d.js new file mode 100644 index 000000000000..8f7d2da43591 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* // 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: +* untilEach10d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function untilEach10d( 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 ); + if ( predicate.call( thisArg, 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 = untilEach10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/10d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/10d_accessors.js new file mode 100644 index 000000000000..fccd3d9b42e9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* 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: +* untilEach10d( x, predicate, fcn, {} ); +*/ +function untilEach10d( x, predicate, fcn, thisArg ) { // eslint-disable-line max-statements + var xbuf; + var get; + 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; + + // 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 ); + if ( predicate.call( thisArg, 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 = untilEach10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/10d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/10d_blocked.js new file mode 100644 index 000000000000..ded6bb14bc2f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray via loop blocking until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* // 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: +* blockeduntilEach10d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function blockeduntilEach10d( 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.call( thisArg, 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 = blockeduntilEach10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/10d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/10d_blocked_accessors.js new file mode 100644 index 000000000000..70590f6558c4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray via loop blocking until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* 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: +* blockeduntilEach10d( x, predicate, fcn, {} ); +*/ +function blockeduntilEach10d( x, predicate, fcn, thisArg ) { // eslint-disable-line max-statements, max-lines-per-function + var bsize; + var xbuf; + var get; + 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]; + + // 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.call( thisArg, 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 = blockeduntilEach10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/1d.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/1d.js new file mode 100644 index 000000000000..9b26f75c40ed --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* // 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: +* untilEach1d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function untilEach1d( 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.call( thisArg, v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } +} + + +// EXPORTS // + +module.exports = untilEach1d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/1d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/1d_accessors.js new file mode 100644 index 000000000000..6ff1e22d2455 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* 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: +* untilEach1d( x, predicate, fcn, {} ); +*/ +function untilEach1d( x, predicate, fcn, thisArg ) { + var xbuf; + var dx0; + var get; + var ind; + 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.call( thisArg, v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } +} + + +// EXPORTS // + +module.exports = untilEach1d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/2d.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/2d.js new file mode 100644 index 000000000000..bdebe5ea4f39 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* // 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: +* untilEach2d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function untilEach2d( 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.call( thisArg, v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } +} + + +// EXPORTS // + +module.exports = untilEach2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/2d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/2d_accessors.js new file mode 100644 index 000000000000..1a0ffe0f5e2a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* 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: +* untilEach2d( x, predicate, fcn, {} ); +*/ +function untilEach2d( x, predicate, fcn, thisArg ) { + var xbuf; + var get; + 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; + + // 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.call( thisArg, v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } +} + + +// EXPORTS // + +module.exports = untilEach2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/2d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/2d_blocked.js new file mode 100644 index 000000000000..da6e2b9c9beb --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray via loop blocking until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* // 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: +* blockeduntilEach2d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function blockeduntilEach2d( 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.call( thisArg, v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + } + } +} + + +// EXPORTS // + +module.exports = blockeduntilEach2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/2d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/2d_blocked_accessors.js new file mode 100644 index 000000000000..b56f66bc55bd --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray via loop blocking until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* 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: +* blockeduntilEach2d( x, predicate, fcn, {} ); +*/ +function blockeduntilEach2d( x, predicate, fcn, thisArg ) { + var bsize; + var xbuf; + var get; + 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]; + + // 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.call( thisArg, v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + } + } +} + + +// EXPORTS // + +module.exports = blockeduntilEach2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/3d.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/3d.js new file mode 100644 index 000000000000..942cc28a4118 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* // 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: +* untilEach3d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function untilEach3d( 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.call( thisArg, v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } +} + + +// EXPORTS // + +module.exports = untilEach3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/3d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/3d_accessors.js new file mode 100644 index 000000000000..89516eb0dd2c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* 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: +* untilEach3d( x, predicate, fcn, {} ); +*/ +function untilEach3d( x, predicate, fcn, thisArg ) { + var xbuf; + var get; + 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; + + // 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.call( thisArg, v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } +} + + +// EXPORTS // + +module.exports = untilEach3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/3d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/3d_blocked.js new file mode 100644 index 000000000000..57a7f09cd332 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray via loop blocking until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* // 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: +* blockeduntilEach3d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function blockeduntilEach3d( 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.call( thisArg, v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockeduntilEach3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/3d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/3d_blocked_accessors.js new file mode 100644 index 000000000000..02fd01001074 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray via loop blocking until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* 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: +* blockeduntilEach3d( x, predicate, fcn, {} ); +*/ +function blockeduntilEach3d( x, predicate, fcn, thisArg ) { + var bsize; + var xbuf; + var get; + 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]; + + // 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.call( thisArg, v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockeduntilEach3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/4d.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/4d.js new file mode 100644 index 000000000000..605b592c6beb --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* // 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: +* untilEach4d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function untilEach4d( 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.call( thisArg, v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } +} + + +// EXPORTS // + +module.exports = untilEach4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/4d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/4d_accessors.js new file mode 100644 index 000000000000..df64b9afd00e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* 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: +* untilEach4d( x, predicate, fcn, {} ); +*/ +function untilEach4d( x, predicate, fcn, thisArg ) { + var xbuf; + var get; + 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; + + // 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.call( thisArg, v, ind, x.ref ) ) { + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } +} + + +// EXPORTS // + +module.exports = untilEach4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/4d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/4d_blocked.js new file mode 100644 index 000000000000..bb5b64884d85 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray via loop blocking until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* // 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: +* blockeduntilEach4d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function blockeduntilEach4d( 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.call( thisArg, v, ind, x.ref ) ) { // eslint-disable-line max-len + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockeduntilEach4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/4d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/4d_blocked_accessors.js new file mode 100644 index 000000000000..e59e07da5e3f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray via loop blocking until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* 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: +* blockeduntilEach4d( x, predicate, fcn, {} ); +*/ +function blockeduntilEach4d( x, predicate, fcn, thisArg ) { + var bsize; + var xbuf; + var get; + 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]; + + // 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.call( thisArg, v, ind, x.ref ) ) { // eslint-disable-line max-len + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockeduntilEach4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/5d.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/5d.js new file mode 100644 index 000000000000..d9b97215a48f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/5d.js @@ -0,0 +1,174 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* 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 // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* // 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: +* untilEach5d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function untilEach5d( 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.call( thisArg, 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 = untilEach5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/5d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/5d_accessors.js new file mode 100644 index 000000000000..b80994119b45 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/5d_accessors.js @@ -0,0 +1,192 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* 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 // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* 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: +* untilEach5d( x, predicate, fcn, {} ); +*/ +function untilEach5d( x, predicate, fcn, thisArg ) { + var xbuf; + var get; + 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; + + // 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.call( thisArg, 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 = untilEach5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/5d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/5d_blocked.js new file mode 100644 index 000000000000..1a662d0461bd --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray via loop blocking until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* // 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: +* blockeduntilEach5d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function blockeduntilEach5d( 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.call( thisArg, v, ind, x.ref ) ) { // eslint-disable-line max-len + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockeduntilEach5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/5d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/5d_blocked_accessors.js new file mode 100644 index 000000000000..c2bbeb199802 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray via loop blocking until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* 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: +* blockeduntilEach5d( x, predicate, fcn, {} ); +*/ +function blockeduntilEach5d( x, predicate, fcn, thisArg ) { + var bsize; + var xbuf; + var get; + 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]; + + // 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.call( thisArg, v, ind, x.ref ) ) { // eslint-disable-line max-len + return; + } + fcn.call( thisArg, v, ind, x.ref ); + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockeduntilEach5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/6d.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/6d.js new file mode 100644 index 000000000000..41c7d360fba1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* // 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: +* untilEach6d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function untilEach6d( 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.call( thisArg, 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 = untilEach6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/6d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/6d_accessors.js new file mode 100644 index 000000000000..f3f0ba734f66 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* 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: +* untilEach6d( x, predicate, fcn, {} ); +*/ +function untilEach6d( x, predicate, fcn, thisArg ) { + var xbuf; + var get; + 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; + + // 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.call( thisArg, 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 = untilEach6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/6d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/6d_blocked.js new file mode 100644 index 000000000000..3671ca9c539a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray via loop blocking until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* // 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: +* blockeduntilEach6d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function blockeduntilEach6d( 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.call( thisArg, v, ind, x.ref ) ) { // eslint-disable-line max-len + return; + } + fcn.call( thisArg, v, ind, x.ref ); // eslint-disable-line max-len + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockeduntilEach6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/6d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/6d_blocked_accessors.js new file mode 100644 index 000000000000..a848fc6cf050 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray via loop blocking until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* 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: +* blockeduntilEach6d( x, predicate, fcn, {} ); +*/ +function blockeduntilEach6d( x, predicate, fcn, thisArg ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var get; + 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]; + + // 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.call( thisArg, v, ind, x.ref ) ) { // eslint-disable-line max-len + return; + } + fcn.call( thisArg, v, ind, x.ref ); // eslint-disable-line max-len + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockeduntilEach6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/7d.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/7d.js new file mode 100644 index 000000000000..0b4c87b10eb1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* // 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: +* untilEach7d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function untilEach7d( 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.call( thisArg, v, ind, x.ref ) ) { // eslint-disable-line max-len + 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 = untilEach7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/7d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/7d_accessors.js new file mode 100644 index 000000000000..76ea6e66d645 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* 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: +* untilEach7d( x, predicate, fcn, {} ); +*/ +function untilEach7d( x, predicate, fcn, thisArg ) { + var xbuf; + var get; + 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; + + // 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.call( thisArg, v, ind, x.ref ) ) { // eslint-disable-line max-len + 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 = untilEach7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/7d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/7d_blocked.js new file mode 100644 index 000000000000..594e5975ac5c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray via loop blocking until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* // 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: +* blockeduntilEach7d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function blockeduntilEach7d( 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.call( thisArg, 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 = blockeduntilEach7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/7d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/7d_blocked_accessors.js new file mode 100644 index 000000000000..cca52ebc7365 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray via loop blocking until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* 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: +* blockeduntilEach7d( x, predicate, fcn, {} ); +*/ +function blockeduntilEach7d( x, predicate, fcn, thisArg ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var get; + 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]; + + // 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.call( thisArg, 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 = blockeduntilEach7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/8d.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/8d.js new file mode 100644 index 000000000000..1031667cc1ca --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* // 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: +* untilEach8d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function untilEach8d( 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.call( thisArg, v, ind, x.ref ) ) { // eslint-disable-line max-len + 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 = untilEach8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/8d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/8d_accessors.js new file mode 100644 index 000000000000..32630e49ba61 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* 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: +* untilEach8d( x, predicate, fcn, {} ); +*/ +function untilEach8d( x, predicate, fcn, thisArg ) { + var xbuf; + var get; + 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; + + // 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.call( thisArg, 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 = untilEach8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/8d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/8d_blocked.js new file mode 100644 index 000000000000..8f0c5aa1c47b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray via loop blocking until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* // 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: +* blockeduntilEach8d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function blockeduntilEach8d( 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.call( thisArg, 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 = blockeduntilEach8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/8d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/8d_blocked_accessors.js new file mode 100644 index 000000000000..140a98b091f3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray via loop blocking until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* 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: +* blockeduntilEach8d( x, predicate, fcn, {} ); +*/ +function blockeduntilEach8d( x, predicate, fcn, thisArg ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var get; + 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]; + + // 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.call( thisArg, 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 = blockeduntilEach8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/9d.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/9d.js new file mode 100644 index 000000000000..50244de42cac --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* // 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: +* untilEach9d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function untilEach9d( 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 ); + if ( predicate.call( thisArg, 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 = untilEach9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/9d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/9d_accessors.js new file mode 100644 index 000000000000..4ddaaecc32cb --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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, max-statements */ + +'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 // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* 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: +* untilEach9d( x, predicate, fcn, {} ); +*/ +function untilEach9d( x, predicate, fcn, thisArg ) { + var xbuf; + var get; + 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; + + // 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.call( thisArg, v, ind, x.ref ) ) { // eslint-disable-line max-len + 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 = untilEach9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/9d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/9d_blocked.js new file mode 100644 index 000000000000..34188318fd19 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray via loop blocking until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* // 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: +* blockeduntilEach9d( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function blockeduntilEach9d( 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.call( thisArg, 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 = blockeduntilEach9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/9d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/9d_blocked_accessors.js new file mode 100644 index 000000000000..e6382a8df63b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray via loop blocking until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* 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: +* blockeduntilEach9d( x, predicate, fcn, {} ); +*/ +function blockeduntilEach9d( x, predicate, fcn, thisArg ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var get; + 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]; + + // 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.call( thisArg, 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 = blockeduntilEach9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/index.js new file mode 100644 index 000000000000..093d0a9116ae --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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'; + +/** +* Invoke a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @module @stdlib/ndarray/base/until-each +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var naryFunction = require( '@stdlib/utils/nary-function' ); +* var log = require( '@stdlib/console/log' ); +* var untilEach = require( '@stdlib/ndarray/base/until-each' ); +* +* function predicate() { +* return false; +* } +* +* // 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: +* untilEach( [ x ], predicate, naryFunction( log, 1 ) ); +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/main.js new file mode 100644 index 000000000000..3f2cd0706fee --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 blockedaccessorUntilEach2d = require( './2d_blocked_accessors.js' ); +var blockedaccessorUntilEach3d = require( './3d_blocked_accessors.js' ); +var blockedaccessorUntilEach4d = require( './4d_blocked_accessors.js' ); +var blockedaccessorUntilEach5d = require( './5d_blocked_accessors.js' ); +var blockedaccessorUntilEach6d = require( './6d_blocked_accessors.js' ); +var blockedaccessorUntilEach7d = require( './7d_blocked_accessors.js' ); +var blockedaccessorUntilEach8d = require( './8d_blocked_accessors.js' ); +var blockedaccessorUntilEach9d = require( './9d_blocked_accessors.js' ); +var blockedaccessorUntilEach10d = require( './10d_blocked_accessors.js' ); +var blockedUntilEach2d = require( './2d_blocked.js' ); +var blockedUntilEach3d = require( './3d_blocked.js' ); +var blockedUntilEach4d = require( './4d_blocked.js' ); +var blockedUntilEach5d = require( './5d_blocked.js' ); +var blockedUntilEach6d = require( './6d_blocked.js' ); +var blockedUntilEach7d = require( './7d_blocked.js' ); +var blockedUntilEach8d = require( './8d_blocked.js' ); +var blockedUntilEach9d = require( './9d_blocked.js' ); +var blockedUntilEach10d = require( './10d_blocked.js' ); +var accessorUntilEach0d = require( './0d_accessors.js' ); +var accessorUntilEach1d = require( './1d_accessors.js' ); +var accessorUntilEach2d = require( './2d_accessors.js' ); +var accessorUntilEach3d = require( './3d_accessors.js' ); +var accessorUntilEach4d = require( './4d_accessors.js' ); +var accessorUntilEach5d = require( './5d_accessors.js' ); +var accessorUntilEach6d = require( './6d_accessors.js' ); +var accessorUntilEach7d = require( './7d_accessors.js' ); +var accessorUntilEach8d = require( './8d_accessors.js' ); +var accessorUntilEach9d = require( './9d_accessors.js' ); +var accessorUntilEach10d = require( './10d_accessors.js' ); +var accessorUntilEachnd = require( './nd_accessors.js' ); +var untilEach0d = require( './0d.js' ); +var untilEach1d = require( './1d.js' ); +var untilEach2d = require( './2d.js' ); +var untilEach3d = require( './3d.js' ); +var untilEach4d = require( './4d.js' ); +var untilEach5d = require( './5d.js' ); +var untilEach6d = require( './6d.js' ); +var untilEach7d = require( './7d.js' ); +var untilEach8d = require( './8d.js' ); +var untilEach9d = require( './9d.js' ); +var untilEach10d = require( './10d.js' ); +var untilEachnd = require( './nd.js' ); + + +// VARIABLES // + +var UNTIL_EACH = [ + untilEach0d, + untilEach1d, + untilEach2d, + untilEach3d, + untilEach4d, + untilEach5d, + untilEach6d, + untilEach7d, + untilEach8d, + untilEach9d, + untilEach10d +]; +var ACCESSOR_UNTIL_EACH = [ + accessorUntilEach0d, + accessorUntilEach1d, + accessorUntilEach2d, + accessorUntilEach3d, + accessorUntilEach4d, + accessorUntilEach5d, + accessorUntilEach6d, + accessorUntilEach7d, + accessorUntilEach8d, + accessorUntilEach9d, + accessorUntilEach10d +]; +var BLOCKED_UNTIL_EACH = [ + blockedUntilEach2d, // 0 + blockedUntilEach3d, + blockedUntilEach4d, + blockedUntilEach5d, + blockedUntilEach6d, + blockedUntilEach7d, + blockedUntilEach8d, + blockedUntilEach9d, + blockedUntilEach10d // 8 +]; +var BLOCKED_ACCESSOR_UNTIL_EACH = [ + blockedaccessorUntilEach2d, // 0 + blockedaccessorUntilEach3d, + blockedaccessorUntilEach4d, + blockedaccessorUntilEach5d, + blockedaccessorUntilEach6d, + blockedaccessorUntilEach7d, + blockedaccessorUntilEach8d, + blockedaccessorUntilEach9d, + blockedaccessorUntilEach10d // 8 +]; +var MAX_DIMS = UNTIL_EACH.length - 1; + + +// MAIN // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* ## 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() { +* return false; +* } +* +* // 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: +* untilEach( [ x ], predicate, naryFunction( log, 1 ) ); +*/ +function untilEach( 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_UNTIL_EACH[ ndims ]( x, predicate, fcn, thisArg ); + } + return UNTIL_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_UNTIL_EACH[ ndims ]( x, predicate, fcn, thisArg ); + } + return UNTIL_EACH[ ndims ]( x, predicate, fcn, thisArg ); + } + // Determine whether we can perform blocked iteration... + if ( ndims <= MAX_DIMS ) { + if ( x.accessorProtocol ) { + return BLOCKED_ACCESSOR_UNTIL_EACH[ ndims-2 ]( x, predicate, fcn, thisArg ); // eslint-disable-line max-len + } + return BLOCKED_UNTIL_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 accessorUntilEachnd( x, predicate, fcn, thisArg ); + } + untilEachnd( x, predicate, fcn, thisArg ); +} + + +// EXPORTS // + +module.exports = untilEach; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/nd.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/nd.js new file mode 100644 index 000000000000..e96e0270b4eb --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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() { +* return false; +* } +* +* // 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: +* untilEachnd( x, predicate, naryFunction( log, 1 ), {} ); +*/ +function untilEachnd( x, predicate, fcn, thisArg ) { + var xbuf; + var ordx; + var len; + var idx; + var sh; + var sx; + var ox; + var ix; + var v; + var i; + + 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.call( thisArg, v, idx, x.ref ) ) { + return; + } + fcn.call( thisArg, v, idx, x.ref ); + } +} + + +// EXPORTS // + +module.exports = untilEachnd; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/lib/nd_accessors.js b/lib/node_modules/@stdlib/ndarray/base/until-each/lib/nd_accessors.js new file mode 100644 index 000000000000..196021844745 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-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 // + +/** +* Invokes a callback function for each element in an ndarray until a predicate function returns a truthy value. +* +* @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 +* @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() { +* return false; +* } +* +* 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: +* untilEachnd( x, predicate, fcn, {} ); +*/ +function untilEachnd( x, predicate, fcn, thisArg ) { + var xbuf; + var ordx; + var len; + var get; + var idx; + var sh; + var sx; + var ox; + var ix; + var v; + var i; + + 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.call( thisArg, v, idx, x.ref ) ) { + return; + } + fcn.call( thisArg, v, idx, x.ref ); + } +} + + +// EXPORTS // + +module.exports = untilEachnd; diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/package.json b/lib/node_modules/@stdlib/ndarray/base/until-each/package.json new file mode 100644 index 000000000000..875856dc2798 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/ndarray/base/until-each", + "version": "0.0.0", + "description": "Invoke a callback function for each element in an ndarray until a predicate function returns a truthy value.", + "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", + "until", + "until-each", + "predicate", + "foreach", + "for-each" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ndarray/base/until-each/test/test.0d.js b/lib/node_modules/@stdlib/ndarray/base/until-each/test/test.0d.js new file mode 100644 index 000000000000..2ccada02f1bf --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/test/test.0d.js @@ -0,0 +1,229 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 untilEach = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof untilEach, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function invokes a callback for the element in a 0-dimensional ndarray when the predicate returns a falsy value', function test( t ) { + var expected; + var values; + var x; + + x = scalar2ndarray( 4.0, { + 'dtype': 'float64' + }); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ 4.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v < 0.0; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function does not invoke a callback for the element in a 0-dimensional ndarray when the predicate returns a truthy value', function test( t ) { + var expected; + var values; + var x; + + x = scalar2ndarray( 4.0, { + 'dtype': 'float64' + }); + + values = []; + untilEach( [ 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 for the element in a 0-dimensional ndarray when the predicate returns a falsy value (accessors)', function test( t ) { + var expected; + var values; + var x; + + x = scalar2ndarray( new Complex128( 3.0, 1.0 ), { + 'dtype': 'complex128' + }); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ + [ 3.0, 1.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) < 0.0; + } + + function fcn( v ) { + values.push( [ real( v ), imag( v ) ] ); + } +}); + +tape( 'the function does not invoke a callback for the element in a 0-dimensional ndarray when the predicate returns a truthy value (accessors)', function test( t ) { + var expected; + var values; + var x; + + x = scalar2ndarray( new Complex128( 4.0, 1.0 ), { + 'dtype': 'complex128' + }); + + values = []; + untilEach( [ 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', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var ctx; + var x; + + x = scalar2ndarray( 3.0, { + 'dtype': 'float64' + }); + + indices = []; + values = []; + arrays = []; + + ctx = {}; + untilEach( [ x ], predicate, fcn, ctx ); + + expected = [ 3.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( v ) { + return v < 0.0; + } + + function fcn( v, idx, arr ) { + t.strictEqual( this, ctx, 'returns expected context' ); // 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 values; + var arrays; + var ctx; + var x; + + x = scalar2ndarray( new Complex128( 3.0, 1.0 ), { + 'dtype': 'complex128' + }); + + indices = []; + values = []; + arrays = []; + + ctx = {}; + untilEach( [ x ], predicate, fcn, ctx ); + + expected = [ + [ 3.0, 1.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( v ) { + return real( v ) < 0.0; + } + + function fcn( v, idx, arr ) { + t.strictEqual( this, ctx, 'returns expected context' ); // 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/until-each/test/test.1d.js b/lib/node_modules/@stdlib/ndarray/base/until-each/test/test.1d.js new file mode 100644 index 000000000000..05487180863c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/test/test.1d.js @@ -0,0 +1,195 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var 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 untilEach = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof untilEach, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function invokes a callback for each element in a 1-dimensional ndarray until the predicate returns a truthy value', function test( t ) { + var expected; + var values; + var x; + + x = ndarray( 'float64', oneTo( 8, 'float64' ), [ 4 ], [ 1 ], 0, 'row-major' ); + + values = []; + untilEach( [ 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 for each element in a 1-dimensional ndarray until the predicate returns a truthy value (negative strides)', function test( t ) { + var expected; + var values; + var x; + + x = ndarray( 'float64', oneTo( 8, 'float64' ), [ 4 ], [ -1 ], 3, 'row-major' ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ 4.0, 3.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v <= 2.0; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function invokes a callback for each element in a 1-dimensional ndarray until the predicate returns a truthy value (accessors)', function test( t ) { + var expected; + var values; + var x; + + x = ndarray( 'complex128', oneTo( 8, 'complex128' ), [ 4 ], [ 1 ], 0, 'row-major' ); + + values = []; + untilEach( [ 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 values; + var arrays; + var ctx; + var x; + + x = ndarray( 'float64', oneTo( 8, 'float64' ), [ 4 ], [ 1 ], 0, 'row-major' ); + + indices = []; + values = []; + arrays = []; + + ctx = {}; + untilEach( [ x ], predicate, fcn, ctx ); + + 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 ) { + t.strictEqual( this, ctx, 'returns expected context' ); // 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 values; + var arrays; + var ctx; + var x; + + x = ndarray( 'complex128', oneTo( 8, 'complex128' ), [ 4 ], [ 1 ], 0, 'row-major' ); + + indices = []; + values = []; + arrays = []; + + ctx = {}; + untilEach( [ x ], predicate, fcn, ctx ); + + 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 ) { + t.strictEqual( this, ctx, 'returns expected context' ); // 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/until-each/test/test.2d.js b/lib/node_modules/@stdlib/ndarray/base/until-each/test/test.2d.js new file mode 100644 index 000000000000..76e71252d253 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/test/test.2d.js @@ -0,0 +1,1312 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 Complex128 = require( '@stdlib/complex/float64/ctor' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var untilEach = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof untilEach, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function invokes a callback for each element in a 2-dimensional ndarray until the predicate returns a truthy value (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 ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + values = []; + untilEach( [ 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 for each element in a 2-dimensional ndarray until the predicate returns a truthy value (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 ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ 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 for each element in a 2-dimensional ndarray until the predicate returns a truthy value (row-major, contiguous)', 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 = [ 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + values = []; + untilEach( [ 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 for each element in a 2-dimensional ndarray until the predicate returns a truthy value (row-major, contiguous, 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 = [ 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ 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 for each element in a 2-dimensional ndarray until the predicate returns a truthy value (row-major, contiguous, negative strides)', 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 = [ 2, 2 ]; + st = [ -2, -1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ 4.0, 3.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v <= 2.0; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function invokes a callback for each element in a 2-dimensional ndarray until the predicate returns a truthy value (row-major, contiguous, negative strides, 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 = [ 2, 2 ]; + st = [ -2, -1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ + [ 4.0, 0.0 ], + [ 3.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) <= 2.0; + } + + function fcn( v ) { + values.push( [ real( v ), imag( v ) ] ); + } +}); + +tape( 'the function invokes a callback for each element in a 2-dimensional ndarray until the predicate returns a truthy value (row-major, non-contiguous, same sign strides)', 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 = [ 2, 2 ]; + st = [ 4, 2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ 1.0, 3.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v >= 5.0; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function invokes a callback for each element in a 2-dimensional ndarray until the predicate returns a truthy value (row-major, non-contiguous, same sign strides, 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 = [ 2, 2 ]; + st = [ 4, 2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*4, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ + [ 1.0, 0.0 ], + [ 3.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) >= 5.0; + } + + function fcn( v ) { + values.push( [ real( v ), imag( v ) ] ); + } +}); + +tape( 'the function invokes a callback for each element in a 2-dimensional ndarray until the predicate returns a truthy value (row-major, non-contiguous, mixed sign strides)', 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 = [ 2, 2 ]; + st = [ 4, -2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ 3.0, 1.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v >= 5.0; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function invokes a callback for each element in a 2-dimensional ndarray until the predicate returns a truthy value (row-major, non-contiguous, mixed sign strides, 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 = [ 2, 2 ]; + st = [ 4, -2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*4, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ + [ 3.0, 0.0 ], + [ 1.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) >= 5.0; + } + + function fcn( v ) { + values.push( [ real( v ), imag( v ) ] ); + } +}); + +tape( 'the function invokes a callback for each element in a 2-dimensional ndarray until the predicate returns a truthy value (row-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var values; + var bsize; + 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 ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + x.set( sh[0]-1, 0, 101.0 ); + + values = []; + untilEach( [ 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 ) { + if ( v !== 0.0 ) { + values.push( v ); + } + } +}); + +tape( 'the function invokes a callback for each element in a 2-dimensional ndarray until the predicate returns a truthy value (row-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var values; + var bsize; + 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 ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + x.set( sh[0]-1, 0, 101.0 ); + + values = []; + untilEach( [ 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 ) { + if ( v !== 0.0 ) { + values.push( v ); + } + } +}); + +tape( 'the function invokes a callback for each element in a 2-dimensional ndarray until the predicate returns a truthy value (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var values; + var bsize; + 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 ); + + x = ndarray( dt, zeros( numel( sh )*4, dt ), sh, st, o, ord ); + x.set( sh[0]-1, 0, new Complex128( 101.0, 0.0 ) ); + + values = []; + untilEach( [ 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 ) { + if ( real( v ) !== 0.0 || imag( v ) !== 0.0 ) { + values.push( [ real( v ), imag( v ) ] ); + } + } +}); + +tape( 'the function invokes a callback for each element in a 2-dimensional ndarray until the predicate returns a truthy value (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var values; + var bsize; + 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 ); + + x = ndarray( dt, zeros( numel( sh )*4, dt ), sh, st, o, ord ); + x.set( sh[0]-1, 0, new Complex128( 101.0, 0.0 ) ); + + values = []; + untilEach( [ 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 ) { + if ( real( v ) !== 0.0 || imag( v ) !== 0.0 ) { + values.push( [ real( v ), imag( v ) ] ); + } + } +}); + +tape( 'the function invokes a callback for each element in a 2-dimensional ndarray until the predicate returns a truthy value (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 ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + values = []; + untilEach( [ 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 for each element in a 2-dimensional ndarray until the predicate returns a truthy value (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 ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ 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 for each element in a 2-dimensional ndarray until the predicate returns a truthy value (column-major, contiguous)', 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 = [ 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + values = []; + untilEach( [ 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 for each element in a 2-dimensional ndarray until the predicate returns a truthy value (column-major, contiguous, 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 = [ 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ 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 for each element in a 2-dimensional ndarray until the predicate returns a truthy value (column-major, contiguous, negative strides)', 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 = [ 2, 2 ]; + st = [ -1, -2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ 4.0, 3.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v <= 2.0; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function invokes a callback for each element in a 2-dimensional ndarray until the predicate returns a truthy value (column-major, contiguous, negative strides, 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 = [ 2, 2 ]; + st = [ -1, -2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ + [ 4.0, 0.0 ], + [ 3.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) <= 2.0; + } + + function fcn( v ) { + values.push( [ real( v ), imag( v ) ] ); + } +}); + +tape( 'the function invokes a callback for each element in a 2-dimensional ndarray until the predicate returns a truthy value (column-major, non-contiguous, same sign strides)', 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 = [ 2, 2 ]; + st = [ 2, 4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ 1.0, 3.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v >= 5.0; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function invokes a callback for each element in a 2-dimensional ndarray until the predicate returns a truthy value (column-major, non-contiguous, same sign strides, 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 = [ 2, 2 ]; + st = [ 2, 4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*4, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ + [ 1.0, 0.0 ], + [ 3.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) >= 5.0; + } + + function fcn( v ) { + values.push( [ real( v ), imag( v ) ] ); + } +}); + +tape( 'the function invokes a callback for each element in a 2-dimensional ndarray until the predicate returns a truthy value (column-major, non-contiguous, mixed sign strides)', 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 = [ 2, 2 ]; + st = [ -2, 4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ 3.0, 1.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v >= 5.0; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function invokes a callback for each element in a 2-dimensional ndarray until the predicate returns a truthy value (column-major, non-contiguous, mixed sign strides, 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 = [ 2, 2 ]; + st = [ -2, 4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*4, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ + [ 3.0, 0.0 ], + [ 1.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) >= 5.0; + } + + function fcn( v ) { + values.push( [ real( v ), imag( v ) ] ); + } +}); + +tape( 'the function invokes a callback for each element in a 2-dimensional ndarray until the predicate returns a truthy value (column-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var values; + var bsize; + 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 ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + x.set( sh[0]-1, 0, 101.0 ); + + values = []; + untilEach( [ 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 ) { + if ( v !== 0.0 ) { + values.push( v ); + } + } +}); + +tape( 'the function invokes a callback for each element in a 2-dimensional ndarray until the predicate returns a truthy value (column-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var values; + var bsize; + 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 ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + x.set( sh[0]-1, 0, 101.0 ); + + values = []; + untilEach( [ 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 ) { + if ( v !== 0.0 ) { + values.push( v ); + } + } +}); + +tape( 'the function invokes a callback for each element in a 2-dimensional ndarray until the predicate returns a truthy value (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var values; + var bsize; + 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 ); + + x = ndarray( dt, zeros( numel( sh )*4, dt ), sh, st, o, ord ); + x.set( sh[0]-1, 0, new Complex128( 101.0, 0.0 ) ); + + values = []; + untilEach( [ 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 ) { + if ( real( v ) !== 0.0 || imag( v ) !== 0.0 ) { + values.push( [ real( v ), imag( v ) ] ); + } + } +}); + +tape( 'the function invokes a callback for each element in a 2-dimensional ndarray until the predicate returns a truthy value (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var values; + var bsize; + 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 ); + + x = ndarray( dt, zeros( numel( sh )*4, dt ), sh, st, o, ord ); + x.set( sh[0]-1, 0, new Complex128( 101.0, 0.0 ) ); + + values = []; + untilEach( [ 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 ) { + if ( real( v ) !== 0.0 || imag( v ) !== 0.0 ) { + values.push( [ real( v ), imag( v ) ] ); + } + } +}); + +tape( 'the function supports specifying the callback execution context (row-major, contiguous)', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var ord; + var ctx; + 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 = {}; + untilEach( [ x ], predicate, fcn, ctx ); + + 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 ) { + t.strictEqual( this, ctx, 'returns expected context' ); // 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 values; + var arrays; + var ord; + var ctx; + 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 = {}; + untilEach( [ x ], predicate, fcn, ctx ); + + 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 ) { + t.strictEqual( this, ctx, 'returns expected context' ); // 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 values; + var arrays; + var ord; + var ctx; + 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 = {}; + untilEach( [ x ], predicate, fcn, ctx ); + + expected = [ 1.0, 2.0, 3.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ [ 0, 0 ], [ 1, 0 ], [ 0, 1 ] ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ x, x, x ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v >= 4.0; + } + + function fcn( v, idx, arr ) { + t.strictEqual( this, ctx, 'returns expected context' ); // 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 values; + var arrays; + var ord; + var ctx; + 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 = {}; + untilEach( [ x ], predicate, fcn, ctx ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ], + [ 3.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ [ 0, 0 ], [ 1, 0 ], [ 0, 1 ] ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ x, x, x ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) >= 4.0; + } + + function fcn( v, idx, arr ) { + t.strictEqual( this, ctx, 'returns expected context' ); // 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/until-each/test/test.3d.js b/lib/node_modules/@stdlib/ndarray/base/until-each/test/test.3d.js new file mode 100644 index 000000000000..a871ff3843da --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/test/test.3d.js @@ -0,0 +1,1485 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 Complex128 = require( '@stdlib/complex/float64/ctor' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var untilEach = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof untilEach, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (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 ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + values = []; + untilEach( [ 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 for each element in a 3-dimensional ndarray until the predicate returns a truthy value (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 ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ 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 for each element in a 3-dimensional ndarray until the predicate returns a truthy value (row-major, contiguous)', 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 = [ 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ 1.0, 2.0, 3.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v >= 4.0; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (row-major, contiguous, 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 = [ 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ], + [ 3.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) >= 4.0; + } + + function fcn( v ) { + values.push( [ real( v ), imag( v ) ] ); + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (row-major, contiguous, negative strides)', 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 = [ 2, 2, 2 ]; + st = [ -4, -2, -1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ 8.0, 7.0, 6.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v <= 5.0; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (row-major, contiguous, negative strides, 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 = [ 2, 2, 2 ]; + st = [ -4, -2, -1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ + [ 8.0, 0.0 ], + [ 7.0, 0.0 ], + [ 6.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) <= 5.0; + } + + function fcn( v ) { + values.push( [ real( v ), imag( v ) ] ); + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (row-major, non-contiguous, same sign strides)', 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 = [ 2, 1, 2 ]; + st = [ 4, 4, 2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ 1.0, 3.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v >= 5.0; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (row-major, non-contiguous, same sign strides, 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 = [ 2, 1, 2 ]; + st = [ 4, 4, 2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*4, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ + [ 1.0, 0.0 ], + [ 3.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) >= 5.0; + } + + function fcn( v ) { + values.push( [ real( v ), imag( v ) ] ); + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (row-major, non-contiguous, mixed sign strides)', 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 = [ 2, 2, 2 ]; + st = [ 4, -2, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ 3.0, 4.0, 1.0, 2.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v >= 5.0; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (row-major, non-contiguous, mixed sign strides, 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 = [ 2, 2, 2 ]; + st = [ 4, -2, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ + [ 3.0, 0.0 ], + [ 4.0, 0.0 ], + [ 1.0, 0.0 ], + [ 2.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) >= 5.0; + } + + function fcn( v ) { + values.push( [ real( v ), imag( v ) ] ); + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (row-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var values; + var bsize; + 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 ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + x.set( sh[0]-1, 0, 0, 101.0 ); + + values = []; + untilEach( [ 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 ) { + if ( v !== 0.0 ) { + values.push( v ); + } + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (row-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var values; + var bsize; + 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 ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + x.set( sh[0]-1, 0, 0, 101.0 ); + + values = []; + untilEach( [ 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 ) { + if ( v !== 0.0 ) { + values.push( v ); + } + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (row-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var values; + var bsize; + 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 ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + x.set( sh[0]-1, 0, 0, 101.0 ); + + values = []; + untilEach( [ 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 ) { + if ( v !== 0.0 ) { + values.push( v ); + } + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var values; + var bsize; + 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 ); + + x = ndarray( dt, zeros( numel( sh )*4, dt ), sh, st, o, ord ); + x.set( sh[0]-1, 0, 0, new Complex128( 101.0, 0.0 ) ); + + values = []; + untilEach( [ 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 ) { + if ( real( v ) !== 0.0 || imag( v ) !== 0.0 ) { + values.push( [ real( v ), imag( v ) ] ); + } + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var values; + var bsize; + 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 ); + + x = ndarray( dt, zeros( numel( sh )*4, dt ), sh, st, o, ord ); + x.set( sh[0]-1, 0, 0, new Complex128( 101.0, 0.0 ) ); + + values = []; + untilEach( [ 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 ) { + if ( real( v ) !== 0.0 || imag( v ) !== 0.0 ) { + values.push( [ real( v ), imag( v ) ] ); + } + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var values; + var bsize; + 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 ); + + x = ndarray( dt, zeros( numel( sh )*4, dt ), sh, st, o, ord ); + x.set( sh[0]-1, 0, 0, new Complex128( 101.0, 0.0 ) ); + + values = []; + untilEach( [ 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 ) { + if ( real( v ) !== 0.0 || imag( v ) !== 0.0 ) { + values.push( [ real( v ), imag( v ) ] ); + } + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (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 ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + values = []; + untilEach( [ 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 for each element in a 3-dimensional ndarray until the predicate returns a truthy value (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 ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ 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 for each element in a 3-dimensional ndarray until the predicate returns a truthy value (column-major, contiguous)', 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 = [ 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ 1.0, 2.0, 3.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v >= 4.0; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (column-major, contiguous, 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 = [ 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ], + [ 3.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) >= 4.0; + } + + function fcn( v ) { + values.push( [ real( v ), imag( v ) ] ); + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (column-major, contiguous, negative strides)', 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 = [ 2, 2, 2 ]; + st = [ -1, -2, -4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ 8.0, 7.0, 6.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v <= 5.0; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (column-major, contiguous, negative strides, 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 = [ 2, 2, 2 ]; + st = [ -1, -2, -4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ + [ 8.0, 0.0 ], + [ 7.0, 0.0 ], + [ 6.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) <= 5.0; + } + + function fcn( v ) { + values.push( [ real( v ), imag( v ) ] ); + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (column-major, non-contiguous, same sign strides)', 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 = [ 2, 1, 2 ]; + st = [ 2, 4, 4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ 1.0, 3.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v >= 5.0; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (column-major, non-contiguous, same sign strides, 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 = [ 2, 1, 2 ]; + st = [ 2, 4, 4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*4, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ + [ 1.0, 0.0 ], + [ 3.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) >= 5.0; + } + + function fcn( v ) { + values.push( [ real( v ), imag( v ) ] ); + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (column-major, non-contiguous, mixed sign strides)', 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 = [ 2, 2, 2 ]; + st = [ 1, -2, 4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ 3.0, 4.0, 1.0, 2.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v >= 5.0; + } + + function fcn( v ) { + values.push( v ); + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (column-major, non-contiguous, mixed sign strides, 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 = [ 2, 2, 2 ]; + st = [ 1, -2, 4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = [ + [ 3.0, 0.0 ], + [ 4.0, 0.0 ], + [ 1.0, 0.0 ], + [ 2.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) >= 5.0; + } + + function fcn( v ) { + values.push( [ real( v ), imag( v ) ] ); + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (column-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var values; + var bsize; + 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 ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + x.set( sh[0]-1, 0, 0, 101.0 ); + + values = []; + untilEach( [ 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 ) { + if ( v !== 0.0 ) { + values.push( v ); + } + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (column-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var values; + var bsize; + 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 ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + x.set( sh[0]-1, 0, 0, 101.0 ); + + values = []; + untilEach( [ 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 ) { + if ( v !== 0.0 ) { + values.push( v ); + } + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (column-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var values; + var bsize; + 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 ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + x.set( sh[0]-1, 0, 0, 101.0 ); + + values = []; + untilEach( [ 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 ) { + if ( v !== 0.0 ) { + values.push( v ); + } + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var values; + var bsize; + 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 ); + + x = ndarray( dt, zeros( numel( sh )*4, dt ), sh, st, o, ord ); + x.set( sh[0]-1, 0, 0, new Complex128( 101.0, 0.0 ) ); + + values = []; + untilEach( [ 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 ) { + if ( real( v ) !== 0.0 || imag( v ) !== 0.0 ) { + values.push( [ real( v ), imag( v ) ] ); + } + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var values; + var bsize; + 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 ); + + x = ndarray( dt, zeros( numel( sh )*4, dt ), sh, st, o, ord ); + x.set( sh[0]-1, 0, 0, new Complex128( 101.0, 0.0 ) ); + + values = []; + untilEach( [ 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 ) { + if ( real( v ) !== 0.0 || imag( v ) !== 0.0 ) { + values.push( [ real( v ), imag( v ) ] ); + } + } +}); + +tape( 'the function invokes a callback for each element in a 3-dimensional ndarray until the predicate returns a truthy value (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var values; + var bsize; + 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 ); + + x = ndarray( dt, zeros( numel( sh )*4, dt ), sh, st, o, ord ); + x.set( sh[0]-1, 0, 0, new Complex128( 101.0, 0.0 ) ); + + values = []; + untilEach( [ 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 ) { + if ( real( v ) !== 0.0 || imag( v ) !== 0.0 ) { + values.push( [ real( v ), imag( v ) ] ); + } + } +}); + +tape( 'the function supports specifying the callback execution context (row-major, contiguous)', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var ord; + var ctx; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 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 = {}; + untilEach( [ x ], predicate, fcn, ctx ); + + expected = [ 1.0, 2.0, 3.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ [ 0, 0, 0 ], [ 0, 0, 1 ], [ 0, 1, 0 ] ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ x, x, x ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v >= 4.0; + } + + function fcn( v, idx, arr ) { + t.strictEqual( this, ctx, 'returns expected context' ); // 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 values; + var arrays; + var ord; + var ctx; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 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 = {}; + untilEach( [ x ], predicate, fcn, ctx ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ], + [ 3.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ [ 0, 0, 0 ], [ 0, 0, 1 ], [ 0, 1, 0 ] ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ x, x, x ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) >= 4.0; + } + + function fcn( v, idx, arr ) { + t.strictEqual( this, ctx, 'returns expected context' ); // 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 values; + var arrays; + var ord; + var ctx; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 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 = {}; + untilEach( [ x ], predicate, fcn, ctx ); + + expected = [ 1.0, 2.0, 3.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ [ 0, 0, 0 ], [ 1, 0, 0 ], [ 0, 1, 0 ] ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ x, x, x ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v >= 4.0; + } + + function fcn( v, idx, arr ) { + t.strictEqual( this, ctx, 'returns expected context' ); // 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 values; + var arrays; + var ord; + var ctx; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 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 = {}; + untilEach( [ x ], predicate, fcn, ctx ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ], + [ 3.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ [ 0, 0, 0 ], [ 1, 0, 0 ], [ 0, 1, 0 ] ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ x, x, x ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return real( v ) >= 4.0; + } + + function fcn( v, idx, arr ) { + t.strictEqual( this, ctx, 'returns expected context' ); // 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/until-each/test/test.js b/lib/node_modules/@stdlib/ndarray/base/until-each/test/test.js new file mode 100644 index 000000000000..85c89d247aca --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/until-each/test/test.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var oneTo = require( '@stdlib/array/one-to' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var untilEach = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof untilEach, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function does not invoke the predicate or callback when provided an empty input ndarray', function test( t ) { + var expected; + var values; + var x; + + x = ndarray( 'float64', oneTo( 8, 'float64' ), [ 0 ], [ 1 ], 0, 'row-major' ); + + values = []; + untilEach( [ x ], predicate, fcn ); + + expected = []; + t.deepEqual( values, expected, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return v >= 5.0; + } + + function fcn( v ) { + values.push( v ); + } +});