From b97de5768e8dd5d6f4d8b027c43ac75a6a736947 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 21 Jun 2025 00:49:17 +0500 Subject: [PATCH 01/30] feat: add ndarray/base/find --- .../@stdlib/ndarray/base/find/README.md | 241 ++++++++++++++++++ .../benchmark/benchmark.1d_columnmajor.js | 141 ++++++++++ .../find/benchmark/benchmark.1d_rowmajor.js | 141 ++++++++++ .../benchmark.2d_blocked_columnmajor.js | 144 +++++++++++ .../benchmark.2d_blocked_rowmajor.js | 144 +++++++++++ .../benchmark/benchmark.2d_columnmajor.js | 144 +++++++++++ .../find/benchmark/benchmark.2d_rowmajor.js | 144 +++++++++++ .../benchmark.2d_rowmajor_accessors.js | 170 ++++++++++++ .../benchmark.3d_blocked_columnmajor.js | 144 +++++++++++ .../benchmark.3d_blocked_rowmajor.js | 144 +++++++++++ .../benchmark/benchmark.3d_columnmajor.js | 144 +++++++++++ .../find/benchmark/benchmark.3d_rowmajor.js | 144 +++++++++++ .../@stdlib/ndarray/base/find/docs/repl.txt | 59 +++++ .../ndarray/base/find/docs/types/index.d.ts | 116 +++++++++ .../ndarray/base/find/docs/types/test.ts | 102 ++++++++ .../ndarray/base/find/examples/index.js | 52 ++++ .../@stdlib/ndarray/base/find/lib/0d.js | 84 ++++++ .../ndarray/base/find/lib/0d_accessors.js | 87 +++++++ .../@stdlib/ndarray/base/find/lib/1d.js | 106 ++++++++ .../ndarray/base/find/lib/1d_accessors.js | 113 ++++++++ .../@stdlib/ndarray/base/find/lib/2d.js | 137 ++++++++++ .../ndarray/base/find/lib/2d_accessors.js | 144 +++++++++++ .../ndarray/base/find/lib/2d_blocked.js | 163 ++++++++++++ .../base/find/lib/2d_blocked_accessors.js | 170 ++++++++++++ .../@stdlib/ndarray/base/find/lib/3d.js | 147 +++++++++++ .../ndarray/base/find/lib/3d_accessors.js | 154 +++++++++++ .../ndarray/base/find/lib/3d_blocked.js | 184 +++++++++++++ .../base/find/lib/3d_blocked_accessors.js | 191 ++++++++++++++ .../@stdlib/ndarray/base/find/lib/index.js | 77 ++++++ .../@stdlib/ndarray/base/find/lib/main.js | 183 +++++++++++++ .../@stdlib/ndarray/base/find/lib/nd.js | 0 .../ndarray/base/find/lib/nd_accessors.js | 0 .../@stdlib/ndarray/base/find/package.json | 64 +++++ .../@stdlib/ndarray/base/find/test/test.js | 33 +++ 34 files changed, 4211 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/0d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/0d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/1d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/1d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/2d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/2d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/3d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/3d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/nd.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/nd_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/base/find/README.md b/lib/node_modules/@stdlib/ndarray/base/find/README.md new file mode 100644 index 000000000000..42cd2b8c93be --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/README.md @@ -0,0 +1,241 @@ + + +# find + +> Return the first element in an ndarray which pass a test implemented by a predicate function. + +
+ +
+ + + +
+ +## Usage + +```javascript +var find = require( '@stdlib/ndarray/base/find' ); +``` + +#### find( arrays, predicate\[, thisArg] ) + +Returns the first element in an ndarray which pass a test implemented by a predicate function. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +function clbk( value ) { + return value % 2.0 === 0.0; +} + +// Create a data buffer: +var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + +// Define the shape of the input array: +var shape = [ 3, 1, 2 ]; + +// Define the array strides: +var sx = [ 4, 4, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create the sentinel value ndarray-like object: +var sentinelValue = { + 'dtype': 'float64', + 'data': new Float64Array( [ -1.0 ] ), + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create the input ndarray-like object: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': shape, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Perform reduction: +var out = find( [ x, sentinelValue ], clbk ); +// returns 2.0 +``` + +The function accepts the following arguments: + +- **arrays**: array-like object containing an input ndarray and a zero-dimensional sentinel value ndarray. +- **predicate**: predicate function. +- **thisArg**: predicate function execution context (_optional_). + +Each provided ndarray should be an object with the following properties: + +- **dtype**: data type. +- **data**: data buffer. +- **shape**: dimensions. +- **strides**: stride lengths. +- **offset**: index offset. +- **order**: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style). + +The predicate function is provided the following arguments: + +- **value**: current array element. +- **indices**: current array element indices. +- **arr**: the input ndarray. + +To set the predicate function execution context, provide a `thisArg`. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +function clbk( value ) { + this.count += 1; + return value % 2.0 === 0.0; +} + +// Create a data buffer: +var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + +// Define the shape of the input array: +var shape = [ 3, 1, 2 ]; + +// Define the array strides: +var sx = [ 4, 4, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create the sentinel value ndarray-like object: +var sentinelValue = { + 'dtype': 'float64', + 'data': new Float64Array( [ -1.0 ] ), + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create the input ndarray-like object: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': shape, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +var ctx = { + 'count': 0 +}; + +// Test elements: +var out = find( [ x, sentinelValue ], clbk, ctx ); +// returns 2.0 + +var count = ctx.count; +// returns 2 +``` + +
+ + + +
+ +## Notes + +- For very high-dimensional ndarrays which are non-contiguous, one should consider copying the underlying data to contiguous memory before performing the operation in order to achieve better performance. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var find = require( '@stdlib/ndarray/base/find' ); + +function clbk( value ) { + return value % 2.0 === 0.0; +} + +var x = { + 'dtype': 'generic', + 'data': discreteUniform( 10, 0, 10, { + 'dtype': 'generic' + }), + 'shape': [ 5, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}; +console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); + +var sv = { + 'dtype': x.dtype, + 'data': [ -1 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': x.order +}; +console.log( 'Sentinel Value: %d', sv.data[ 0 ] ); + +var out = find( [ x, sv ], clbk ); +console.log( out ); +``` + +
+ + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_columnmajor.js new file mode 100644 index 000000000000..ee64d84bbcb8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_columnmajor.js @@ -0,0 +1,141 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 pkg = require( './../package.json' ).name; +var find = require( './../lib' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value % 2.0 === 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + var v; + + x = discreteUniform( len, 1, 100 ); + x = { + 'dtype': xtype, + 'data': x, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + v = { + 'dtype': xtype, + 'data': [ -1.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( [ x, v ], clbk ); + if ( typeof out !== 'boolean' ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !isnan( out ) ) { + 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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_rowmajor.js new file mode 100644 index 000000000000..6bc55850ed2c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_rowmajor.js @@ -0,0 +1,141 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 pkg = require( './../package.json' ).name; +var find = require( './../lib' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value % 2.0 === 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var sv; + var x; + + x = discreteUniform( len, 1, 100 ); + x = { + 'dtype': xtype, + 'data': x, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + sv = { + 'dtype': xtype, + 'data': [ -1.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( [ x, sv ], clbk ); + if ( isnan( out ) ) { + b.fail( 'should return NaN' ); + } + } + b.toc(); + if ( !isnan( out ) ) { + b.fail( 'should 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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_columnmajor.js new file mode 100644 index 000000000000..d81645b61512 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_columnmajor.js @@ -0,0 +1,144 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 pkg = require( './../package.json' ).name; +var find = require( './../lib/2d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value % 2.0 === 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, -1, clbk ); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out ) ) { + b.fail( 'should return 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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, t1 ); + bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_rowmajor.js new file mode 100644 index 000000000000..c12994a16349 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_rowmajor.js @@ -0,0 +1,144 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 pkg = require( './../package.json' ).name; +var find = require( './../lib/2d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value % 2.0 === 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, 101, clbk ); + if ( isnan( out ) ) { + b.fail( 'should return not return NaN' ); + } + } + b.toc(); + if ( isnan( out ) ) { + b.fail( 'should return 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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, t1 ); + bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_columnmajor.js new file mode 100644 index 000000000000..78d007c6c433 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_columnmajor.js @@ -0,0 +1,144 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 pkg = require( './../package.json' ).name; +var find = require( './../lib/2d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value % 2.0 === 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, 101, clbk ); + if ( isnan( out ) ) { + b.fail( 'should return not return NaN' ); + } + } + b.toc(); + if ( isnan( out ) ) { + b.fail( 'should return 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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, t1 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor.js new file mode 100644 index 000000000000..01f16079098e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor.js @@ -0,0 +1,144 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 pkg = require( './../package.json' ).name; +var find = require( './../lib/2d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value % 2.0 === 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, -1, clbk ); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out ) ) { + 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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, t1 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor_accessors.js new file mode 100644 index 000000000000..84690da0c9bf --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor_accessors.js @@ -0,0 +1,170 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 pkg = require( './../package.json' ).name; +var find = require( './../lib/2d_accessors.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value % 2.0 === 0.0; +} + +/** +* Returns an array data buffer element. +* +* @private +* @param {Collection} buf - data buffer +* @param {NonNegativeInteger} idx - element index +* @returns {*} element +*/ +function get( buf, idx ) { + return buf[ idx ]; +} + +/** +* Sets an array data buffer element. +* +* @private +* @param {Collection} buf - data buffer +* @param {NonNegativeInteger} idx - element index +* @param {*} value - value to set +*/ +function set( buf, idx, value ) { + buf[ idx ] = value; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, -1, clbk ); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out ) ) { + 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( pkg+'::accessors:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+'::accessors:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, t1 ); + bench( pkg+'::accessors:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_columnmajor.js new file mode 100644 index 000000000000..2e498ac791ab --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_columnmajor.js @@ -0,0 +1,144 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 pkg = require( './../package.json' ).name; +var find = require( './../lib/3d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value % 2.0 === 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, -1, clbk ); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out ) ) { + 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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + len = floor( cbrt( len ) ); + sh = [ len, len, len ]; + len *= len * len; + f = createBenchmark( len, sh, t1 ); + bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_rowmajor.js new file mode 100644 index 000000000000..56a974cbdbdb --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_rowmajor.js @@ -0,0 +1,144 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 pkg = require( './../package.json' ).name; +var find = require( './../lib/3d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value % 2.0 === 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, -1, clbk ); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out ) ) { + 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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + len = floor( cbrt( len ) ); + sh = [ len, len, len ]; + len *= len * len; + f = createBenchmark( len, sh, t1 ); + bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_columnmajor.js new file mode 100644 index 000000000000..1733db1f6c17 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_columnmajor.js @@ -0,0 +1,144 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 pkg = require( './../package.json' ).name; +var find = require( './../lib/3d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value % 2.0 === 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, -1, clbk ); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out ) ) { + 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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + len = floor( cbrt( len ) ); + sh = [ len, len, len ]; + len *= len * len; + f = createBenchmark( len, sh, t1 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_rowmajor.js new file mode 100644 index 000000000000..f8c25c61e6cd --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_rowmajor.js @@ -0,0 +1,144 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 pkg = require( './../package.json' ).name; +var find = require( './../lib/3d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value % 2.0 === 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, -1, clbk ); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out ) ) { + 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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + len = floor( cbrt( len ) ); + sh = [ len, len, len ]; + len *= len * len; + f = createBenchmark( len, sh, t1 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/find/docs/repl.txt new file mode 100644 index 000000000000..124c64b161ac --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/docs/repl.txt @@ -0,0 +1,59 @@ + +{{alias}}( arrays, predicate, thisArg ) + Returns the first element in an ndarray which pass a test implemented by a + predicate function. + + 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 function is 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 and a zero-dimensional + array containing the sentinel value. + + predicate: Function + Predicate function. + + thisArg: any (optional) + Predicate function execution context. + + Returns + ------- + out: any + result. + + Examples + -------- + // Define ndarray data and meta data... + > var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var dt = 'float64'; + > var sh = [ 2, 2 ]; + > var sx = [ 2, 1 ]; + > var ox = 0; + > var ord = 'row-major'; + + // Define a callback... + > function clbk( v ) { return v % 2.0 === 0.0; }; + + > var sv = {{alias:@stdlib/ndarray/from-scalar}}( -1.0, { 'dtype': dt } ); + > var x = {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); + > {{alias}}( [ x, sv ], clbk ) + 2.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/base/find/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/find/docs/types/index.d.ts new file mode 100644 index 000000000000..716f8bbd9581 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/docs/types/index.d.ts @@ -0,0 +1,116 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @returns boolean indicating whether an ndarray element passes a test +*/ +type Nullary = ( this: U ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - current array element +* @returns boolean indicating whether an ndarray element passes a test +*/ +type Unary = ( this: U, value: T ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - current array element +* @param indices - current array element indices +* @returns boolean indicating whether an ndarray element passes a test +*/ +type Binary = ( this: U, value: T, indices: Array ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - current array element +* @param indices - current array element indices +* @param arr - input array +* @returns boolean indicating whether an ndarray element passes a test +*/ +type Ternary = ( this: U, value: T, indices: Array, arr: typedndarray ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - current array element +* @param indices - current array element indices +* @param arr - input array +* @returns boolean indicating whether an ndarray element passes a test +*/ +type Predicate = Nullary | Unary | Binary | Ternary; + +/** +* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* +* @param arrays - array-like object containing one input ndarray and a zero-dimensional sentinel value ndarray +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns boolean indicating whether all elements pass a test +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create the input ndarray: +* var x = ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' ); +* +* // Create a zero-dimensional ndarray containing a sentinel value: +* var sv = scalar2ndarray( -1.0, { +* 'dtype': 'float64' +* }); +* +* // Perform reduction: +* var out = find( [ x, sv ], predicate ); +* // returns 2.0 +*/ +declare function find( arrays: ArrayLike>, predicate: Predicate, thisArg?: ThisParameterType> ): V; + + +// EXPORTS // + +export = find; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/find/docs/types/test.ts new file mode 100644 index 000000000000..0b5795a07113 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/docs/types/test.ts @@ -0,0 +1,102 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/// + +import zeros = require( '@stdlib/ndarray/zeros' ); +import find = require( './index' ); + +/** +* Predicate function. +* +* @param v - ndarray element +* @returns result +*/ +function clbk( v: any ): boolean { + return v > 0.0; +} + + +// TESTS // + +// The function returns a float64... +{ + const x = zeros( [ 2, 2 ] ); + const v = zeros( [] ); + const arrays = [ x, v ]; + + find( arrays, clbk ); // $ExpectType float64 + find( arrays, clbk, {} ); // $ExpectType float64 +} + +// The compiler throws an error if the function is provided a first argument which is not an array-like object containing ndarray-like objects... +{ + find( 5, clbk ); // $ExpectError + find( true, clbk ); // $ExpectError + find( false, clbk ); // $ExpectError + find( null, clbk ); // $ExpectError + find( undefined, clbk ); // $ExpectError + find( {}, clbk ); // $ExpectError + find( [ 1 ], clbk ); // $ExpectError + find( ( x: number ): number => x, clbk ); // $ExpectError + + find( 5, clbk, {} ); // $ExpectError + find( true, clbk, {} ); // $ExpectError + find( false, clbk, {} ); // $ExpectError + find( null, clbk, {} ); // $ExpectError + find( undefined, clbk, {} ); // $ExpectError + find( {}, clbk, {} ); // $ExpectError + find( [ 1 ], clbk, {} ); // $ExpectError + find( ( x: number ): number => x, clbk, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a callback function... +{ + const x = zeros( [ 2, 2 ] ); + const v = zeros( [] ); + const arrays = [ x, v ]; + + find( arrays, '10' ); // $ExpectError + find( arrays, 5 ); // $ExpectError + find( arrays, true ); // $ExpectError + find( arrays, false ); // $ExpectError + find( arrays, null ); // $ExpectError + find( arrays, undefined ); // $ExpectError + find( arrays, [] ); // $ExpectError + find( arrays, {} ); // $ExpectError + + find( arrays, '10', {} ); // $ExpectError + find( arrays, 5, {} ); // $ExpectError + find( arrays, true, {} ); // $ExpectError + find( arrays, false, {} ); // $ExpectError + find( arrays, null, {} ); // $ExpectError + find( arrays, undefined, {} ); // $ExpectError + find( arrays, [], {} ); // $ExpectError + find( arrays, {}, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ] ); + const v = zeros( [] ); + const arrays = [ x, v ]; + + find(); // $ExpectError + find( arrays ); // $ExpectError + find( arrays, clbk, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/find/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/find/examples/index.js new file mode 100644 index 000000000000..ffb7913ec216 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/examples/index.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var find = require( './../lib' ); + +function clbk( value ) { + return value % 2.0 === 0.0; +} + +var x = { + 'dtype': 'generic', + 'data': discreteUniform( 10, 0, 10, { + 'dtype': 'generic' + }), + 'shape': [ 5, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}; +console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); + +var sv = { + 'dtype': x.dtype, + 'data': [ -1 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': x.order +}; +console.log( 'Sentinel Value: %d', sv.data[ 0 ] ); + +var out = find( [ x, sv ], clbk ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/0d.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/0d.js new file mode 100644 index 000000000000..e59bbaf3d90e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/0d.js @@ -0,0 +1,84 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0 ] ); +* +* // Define the shape of the input array: +* var shape = []; +* +* // Define the array strides: +* var sx = [ 0 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Test elements: +* var out = find0d( x, -1, predicate ); +* // returns 2.0 +*/ +function find0d( x, sentinelValue, predicate, thisArg ) { + if ( predicate.call( thisArg, x.data[ x.offset ], [], x.ref ) ) { + return x.data[ x.offset ]; + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = find0d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/0d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/0d_accessors.js new file mode 100644 index 000000000000..2a947062bb6f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/0d_accessors.js @@ -0,0 +1,87 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = toAccessorArray( [ 1.0, 2.0 ] ); +* +* // Define the shape of the input array: +* var shape = []; +* +* // Define the array strides: +* var sx = [ 0 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Test elements: +* var out = find0d( x, -1, predicate ); +* // returns 2.0 +*/ +function find0d( x, sentinelValue, predicate, thisArg ) { + if ( predicate.call( thisArg, x.accessors[ 0 ]( x.data, x.offset ), [], x.ref ) ) { // eslint-disable-line max-len + return x.accessors[ 0 ]( x.data, x.offset ); + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = find0d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/1d.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/1d.js new file mode 100644 index 000000000000..74702ac9ed29 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/1d.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 4 ]; +* +* // Define the array strides: +* var sx = [ 2 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Test elements: +* var out = find1d( x, -1, predicate ); +* // returns -1 +*/ +function find1d( x, sentinelValue, predicate, thisArg ) { + var xbuf; + var dx0; + var S0; + var ix; + var i0; + + // 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++ ) { + if ( predicate.call( thisArg, xbuf[ ix ], [ i0 ], x.ref ) ) { + return xbuf[ ix ]; + } + ix += dx0; + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = find1d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/1d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/1d_accessors.js new file mode 100644 index 000000000000..3231261aed10 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/1d_accessors.js @@ -0,0 +1,113 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 4 ]; +* +* // Define the array strides: +* var sx = [ 2 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Test elements: +* var out = find1d( x, -1, predicate ); +* // returns -1 +*/ +function find1d( x, sentinelValue, predicate, thisArg ) { + var xbuf; + var get; + var dx0; + var S0; + var ix; + var i0; + + // 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; + + // Cache accessor: + get = x.accessors[ 0 ]; + + // Iterate over the ndarray dimensions... + for ( i0 = 0; i0 < S0; i0++ ) { + if ( predicate.call( thisArg, get( xbuf, ix ), [ i0 ], x.ref) ) { + return get( xbuf, ix ); + } + ix += dx0; + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = find1d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/2d.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d.js new file mode 100644 index 000000000000..9be4a19ad103 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d.js @@ -0,0 +1,137 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Test elements: +* var out = find2d( x, -1, predicate ); +* // returns 2.0 +*/ +function find2d( x, sentinelValue, predicate, thisArg ) { + var xbuf; + var idx; + var dx0; + var dx1; + var sh; + var S0; + var S1; + var sx; + var ix; + var i0; + var i1; + + // Note on variable naming convention: S#, dx#, 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++ ) { + if ( predicate.call( thisArg, xbuf[ ix ], take( [ i1, i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return xbuf[ ix ]; + } + ix += dx0; + } + ix += dx1; + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = find2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_accessors.js new file mode 100644 index 000000000000..b6331268b5c3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_accessors.js @@ -0,0 +1,144 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Test elements: +* var out = find2d( x, -1, predicate ); +* // returns 2.0 +*/ +function find2d( x, sentinelValue, predicate, thisArg ) { + var xbuf; + var idx; + var get; + var dx0; + var dx1; + var sh; + var S0; + var S1; + var sx; + var ix; + var i0; + var i1; + + // Note on variable naming convention: S#, dx#, 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++ ) { + if ( predicate.call( thisArg, get( xbuf, ix ), take( [ i1, i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return get( xbuf, ix ); + } + ix += dx0; + } + ix += dx1; + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = find2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked.js new file mode 100644 index 000000000000..b093cbd67ada --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked.js @@ -0,0 +1,163 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Test elements: +* var out = blockedfind2d( x, -1, predicate ); +* // returns 2.0 +*/ +function blockedfind2d( x, sentinelValue, predicate, thisArg ) { + var bsize; + var xbuf; + var idx; + var dx0; + var dx1; + var ox1; + var sh; + var s0; + var s1; + var sx; + var ox; + var ix; + var i0; + var i1; + var j0; + var j1; + var o; + + // Note on variable naming convention: s#, dx#, 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++ ) { + if ( predicate.call( thisArg, xbuf[ ix ], take( [ j1+i1, j0+i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return xbuf[ ix ]; + } + ix += dx0; + } + ix += dx1; + } + } + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = blockedfind2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked_accessors.js new file mode 100644 index 000000000000..f8a15643a432 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked_accessors.js @@ -0,0 +1,170 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Test elements: +* var out = blockedfind2d( x, -1, predicate ); +* // returns 2.0 +*/ +function blockedfind2d( x, sentinelValue, predicate, thisArg ) { + var bsize; + var xbuf; + var idx; + var get; + var dx0; + var dx1; + var ox1; + var sh; + var s0; + var s1; + var sx; + var ox; + var ix; + var i0; + var i1; + var j0; + var j1; + var o; + + // Note on variable naming convention: s#, dx#, 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++ ) { + if ( predicate.call( thisArg, get( xbuf, ix ), take( [ j1+i1, j0+i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return get( xbuf, ix ); + } + ix += dx0; + } + ix += dx1; + } + } + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = blockedfind2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d.js new file mode 100644 index 000000000000..1dc52398db9f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* // Define the shape of the input 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-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Test elements: +* var out = find3d( x,-1, predicate ); +* // returns 2.0 +*/ +function find3d( x, sentinelValue, predicate, thisArg ) { + var xbuf; + var idx; + var dx0; + var dx1; + var dx2; + var sh; + var S0; + var S1; + var S2; + var sx; + var ix; + var i0; + var i1; + var i2; + + // Note on variable naming convention: S#, dx#, 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++ ) { + if ( predicate.call( thisArg, xbuf[ ix ], take( [ i2, i1, i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return xbuf[ ix ]; + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = find3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_accessors.js new file mode 100644 index 000000000000..660372e38349 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_accessors.js @@ -0,0 +1,154 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Test elements: +* var out = find3d( x, -1, predicate ); +* // returns 2.0 +*/ +function find3d( x, sentinelValue, predicate, thisArg ) { + var xbuf; + var idx; + var get; + var dx0; + var dx1; + var dx2; + var sh; + var S0; + var S1; + var S2; + var sx; + var ix; + var i0; + var i1; + var i2; + + // Note on variable naming convention: S#, dx#, 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++ ) { + if ( predicate.call( thisArg, get( xbuf, ix ), take( [ i2, i1, i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return get( xbuf, ix ); + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = find3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked.js new file mode 100644 index 000000000000..485ee2d41999 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked.js @@ -0,0 +1,184 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* // Define the shape of the input 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-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Test elements: +* var out = blockedfind3d( x, -1, predicate ); +* // returns 2.0 +*/ +function blockedfind3d( x, sentinelValue, predicate, thisArg ) { + var bsize; + var xbuf; + var idx; + var dx0; + var dx1; + var dx2; + var ox1; + var ox2; + 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; + + // Note on variable naming convention: s#, dx#, 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++ ) { + if ( predicate.call( thisArg, xbuf[ ix ], take( [ j2+i2, j1+i1, j0+i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return xbuf[ ix ]; + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + } + } + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = blockedfind3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked_accessors.js new file mode 100644 index 000000000000..5eb56aa37b0d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked_accessors.js @@ -0,0 +1,191 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Test elements: +* var out = blockedfind3d( x, -1, predicate ); +* // returns 2.0 +*/ +function blockedfind3d( x, sentinelValue, predicate, thisArg ) { + var bsize; + var xbuf; + var idx; + var get; + var dx0; + var dx1; + var dx2; + var ox1; + var ox2; + 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; + + // Note on variable naming convention: s#, dx#, 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++ ) { + if ( predicate.call( thisArg, get( xbuf, ix ), take( [ j2+i2, j1+i1, j0+i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return get( xbuf, ix ); + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + } + } + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = blockedfind3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/index.js new file mode 100644 index 000000000000..6df7ec553b85 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/index.js @@ -0,0 +1,77 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/** +* Return the first element in an ndarray which pass a test implemented by a predicate function. +* +* @module @stdlib/ndarray/base/find +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var find = require( '@stdlib/ndarray/base/find' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* // Define the shape of the input 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-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create the sentinel value ndarray-like object: +* var sentinelValue = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ -1.0 ] ), +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* // Test elements: +* var out = find( [ x, sentinelValue ], predicate ); +* // returns 2.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/main.js new file mode 100644 index 000000000000..819634767030 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/main.js @@ -0,0 +1,183 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 blockedaccessorfind2d = require( './2d_blocked_accessors.js' ); +var blockedaccessorfind3d = require( './3d_blocked_accessors.js' ); +var blockedfind2d = require( './2d_blocked.js' ); +var blockedfind3d = require( './3d_blocked.js' ); +var accessorfind0d = require( './0d_accessors.js' ); +var accessorfind1d = require( './1d_accessors.js' ); +var accessorfind2d = require( './2d_accessors.js' ); +var accessorfind3d = require( './3d_accessors.js' ); +var accessorfindnd = require( './nd_accessors.js' ); +var find0d = require( './0d.js' ); +var find1d = require( './1d.js' ); +var find2d = require( './2d.js' ); +var find3d = require( './3d.js' ); +var findnd = require( './nd.js' ); + + +// VARIABLES // + +var FIND = [ + find0d, + find1d, + find2d, + find3d +]; +var ACCESSOR_FIND = [ + accessorfind0d, + accessorfind1d, + accessorfind2d, + accessorfind3d +]; +var BLOCKED_FIND = [ + blockedfind2d, // 0 + blockedfind3d +]; +var BLOCKED_ACCESSOR_FIND = [ + blockedaccessorfind2d, // 0 + blockedaccessorfind3d +]; +var MAX_DIMS = FIND.length - 1; + + +// MAIN // + +/** +* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* +* ## 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 and a zero-dimensional sentinel value ndarray +* @param {Function} predicate - predicate function +* @param {thisArg} [thisArg] - predicate function execution context +* @returns {*} result +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* // Define the shape of the input 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-like object: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create the sentinel value ndarray-like object: +* var sentinelValue = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ -1.0 ] ), +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Test elements: +* var out = find( [ x, sentinelValue ], predicate ); +* // returns 2.0 +*/ +function find( arrays, predicate, thisArg ) { + var ndims; + var shx; + var sv; + var x; + + // Unpack the ndarray and standardize ndarray meta data: + x = ndarray2object( arrays[ 0 ] ); + sv = ndarray2object( arrays[ 1 ] ); + + shx = x.shape; + ndims = shx.length; + + // Resolve the sentinel value: + sv = sv.accessors[ 0 ]( sv.data, sv.offset ); + + // Determine whether we can avoid iteration altogether... + if ( ndims === 0 ) { + if ( x.accessorProtocol ) { + return ACCESSOR_FIND[ ndims ]( x, sv, predicate, thisArg ); + } + return FIND[ ndims ]( x, sv, predicate, thisArg ); + } + // Check whether we were provided an empty ndarray... + if ( numel( shx ) === 0 ) { + return sv; + } + // 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_FIND[ ndims ]( x, sv, predicate, thisArg ); + } + return FIND[ ndims ]( x, sv, predicate, thisArg ); + } + // Determine whether we can perform blocked iteration... + if ( ndims <= MAX_DIMS ) { + if ( x.accessorProtocol ) { + return BLOCKED_ACCESSOR_FIND[ ndims-2 ]( x, sv, predicate, thisArg ); // eslint-disable-line max-len + } + return BLOCKED_FIND[ ndims-2 ]( x, sv, predicate, 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 accessorfindnd( x, sv, predicate, thisArg ); + } + return findnd( x, sv, predicate, thisArg ); +} + + +// EXPORTS // + +module.exports = find; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/nd.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/nd.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/nd_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/nd_accessors.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/lib/node_modules/@stdlib/ndarray/base/find/package.json b/lib/node_modules/@stdlib/ndarray/base/find/package.json new file mode 100644 index 000000000000..168f640c4d0d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/package.json @@ -0,0 +1,64 @@ +{ + "name": "@stdlib/ndarray/base/find", + "version": "0.0.0", + "description": "Return the first element in an ndarray which pass a test implemented by a predicate function.", + "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", + "find", + "search", + "callback", + "utility", + "utils" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ndarray/base/find/test/test.js b/lib/node_modules/@stdlib/ndarray/base/find/test/test.js new file mode 100644 index 000000000000..0bc61e85a748 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/test/test.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 find = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof find, 'function', 'main export is a function' ); + t.end(); +}); From dcab5b75a7ce466f5524c57ba2a352dbb222d180 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 21 Jun 2025 01:07:34 +0500 Subject: [PATCH 02/30] feat: add nd kernels --- .../benchmark/benchmark.1d_columnmajor.js | 4 +- .../find/benchmark/benchmark.1d_rowmajor.js | 6 +- .../benchmark.2d_blocked_columnmajor.js | 2 +- .../benchmark.2d_blocked_rowmajor.js | 4 +- .../benchmark/benchmark.2d_columnmajor.js | 4 +- .../@stdlib/ndarray/base/find/lib/nd.js | 128 +++++++++++++++++ .../ndarray/base/find/lib/nd_accessors.js | 135 ++++++++++++++++++ 7 files changed, 273 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_columnmajor.js index ee64d84bbcb8..a3af7b44bac7 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_columnmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_columnmajor.js @@ -92,12 +92,12 @@ function createBenchmark( len, shape, xtype ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { out = find( [ x, v ], clbk ); - if ( typeof out !== 'boolean' ) { + if ( isnan( out ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( !isnan( out ) ) { + if ( isnan( out ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_rowmajor.js index 6bc55850ed2c..141a89eccbb2 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_rowmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_rowmajor.js @@ -93,12 +93,12 @@ function createBenchmark( len, shape, xtype ) { for ( i = 0; i < b.iterations; i++ ) { out = find( [ x, sv ], clbk ); if ( isnan( out ) ) { - b.fail( 'should return NaN' ); + b.fail( 'should not return NaN' ); } } b.toc(); - if ( !isnan( out ) ) { - b.fail( 'should return NaN' ); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_columnmajor.js index d81645b61512..4d36f4ca445c 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_columnmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_columnmajor.js @@ -91,7 +91,7 @@ function createBenchmark( len, shape, xtype ) { } b.toc(); if ( isnan( out ) ) { - b.fail( 'should return not return NaN' ); + b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_rowmajor.js index c12994a16349..b78c64d5a03d 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_rowmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_rowmajor.js @@ -86,12 +86,12 @@ function createBenchmark( len, shape, xtype ) { for ( i = 0; i < b.iterations; i++ ) { out = find( x, 101, clbk ); if ( isnan( out ) ) { - b.fail( 'should return not return NaN' ); + b.fail( 'should not return NaN' ); } } b.toc(); if ( isnan( out ) ) { - b.fail( 'should return not return NaN' ); + b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_columnmajor.js index 78d007c6c433..8be20c40c7f0 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_columnmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_columnmajor.js @@ -86,12 +86,12 @@ function createBenchmark( len, shape, xtype ) { for ( i = 0; i < b.iterations; i++ ) { out = find( x, 101, clbk ); if ( isnan( out ) ) { - b.fail( 'should return not return NaN' ); + b.fail( 'should not return NaN' ); } } b.toc(); if ( isnan( out ) ) { - b.fail( 'should return not return NaN' ); + b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/nd.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/nd.js index e69de29bb2d1..6ad809fac05f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/nd.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/nd.js @@ -0,0 +1,128 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Test elements: +* var out = findnd( x, -1, predicate ); +* // returns 2.0 +*/ +function findnd( x, sentinelValue, predicate, thisArg ) { + var xbuf; + var ordx; + var idx; + var len; + var sh; + var sx; + var ox; + var ix; + 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 + if ( predicate.call( thisArg, xbuf[ ix ], idx, x.ref ) ) { + return xbuf[ ix ]; + } + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = findnd; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/nd_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/nd_accessors.js index e69de29bb2d1..8ff579ef6ef0 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/nd_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/nd_accessors.js @@ -0,0 +1,135 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Test elements: +* var out = findnd( x, -1, predicate ); +* // returns 2.0 +*/ +function findnd( x, sentinelValue, predicate, thisArg ) { + var xbuf; + var ordx; + var idx; + var len; + var get; + var sh; + var sx; + var ox; + var ix; + 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 + if ( predicate.call( thisArg, get( xbuf, ix ), idx, x.ref ) ) { + return get( xbuf, ix ); + } + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = findnd; From 66764f1b1d573827bf66cf2df8b6dcd8ec5c5188 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 21 Jun 2025 01:17:04 +0500 Subject: [PATCH 03/30] docs: fix return value --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/ndarray/base/find/lib/1d.js | 2 +- .../@stdlib/ndarray/base/find/lib/1d_accessors.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/1d.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/1d.js index 74702ac9ed29..e8993887a9ee 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/1d.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/1d.js @@ -69,7 +69,7 @@ * * // Test elements: * var out = find1d( x, -1, predicate ); -* // returns -1 +* // returns 2.0 */ function find1d( x, sentinelValue, predicate, thisArg ) { var xbuf; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/1d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/1d_accessors.js index 3231261aed10..a8c73424f37b 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/1d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/1d_accessors.js @@ -56,7 +56,7 @@ * var sx = [ 2 ]; * * // Define the index offset: -* var ox = 0; +* var ox = 1; * * // Create the input ndarray-like object: * var x = { @@ -72,7 +72,7 @@ * * // Test elements: * var out = find1d( x, -1, predicate ); -* // returns -1 +* // returns 2.0 */ function find1d( x, sentinelValue, predicate, thisArg ) { var xbuf; From 12a4b61d2844d76eef6f5d05ed1fde74c721f028 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 21 Jun 2025 15:16:02 +0500 Subject: [PATCH 04/30] fix: lint errors --- 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: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/ndarray/base/find/README.md | 4 ++++ lib/node_modules/@stdlib/ndarray/base/find/docs/repl.txt | 4 ++-- lib/node_modules/@stdlib/ndarray/base/find/lib/main.js | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/find/README.md b/lib/node_modules/@stdlib/ndarray/base/find/README.md index 42cd2b8c93be..89539f38e116 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/find/README.md @@ -32,10 +32,14 @@ limitations under the License. ## Usage + + ```javascript var find = require( '@stdlib/ndarray/base/find' ); ``` + + #### find( arrays, predicate\[, thisArg] ) Returns the first element in an ndarray which pass a test implemented by a predicate function. diff --git a/lib/node_modules/@stdlib/ndarray/base/find/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/find/docs/repl.txt index 124c64b161ac..6e648581835f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/find/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( arrays, predicate, thisArg ) +{{alias}}( arrays, predicate[, thisArg] ) Returns the first element in an ndarray which pass a test implemented by a predicate function. @@ -34,7 +34,7 @@ Returns ------- out: any - result. + Result. Examples -------- diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/main.js index 819634767030..b7069b7b5dfd 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/main.js @@ -18,6 +18,8 @@ 'use strict'; +/* eslint-disable stdlib/no-redeclare */ + // MODULES // var iterationOrder = require( '@stdlib/ndarray/base/iteration-order' ); From 76a9ba1b6a52fc35301205d2eafea2a8e6e6d661 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 21 Jun 2025 15:43:15 +0500 Subject: [PATCH 05/30] fix: lint error --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/ndarray/base/find/examples/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/node_modules/@stdlib/ndarray/base/find/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/find/examples/index.js index ffb7913ec216..9462e8dd5bfb 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/examples/index.js @@ -18,6 +18,8 @@ 'use strict'; +/* eslint-disable stdlib/no-redeclare */ + var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); var find = require( './../lib' ); From 44f5cba43972fa7bfc0f58da2edb13a305a5441f Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 21 Jun 2025 15:47:19 +0500 Subject: [PATCH 06/30] fix: lint error --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/ndarray/base/find/test/test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/node_modules/@stdlib/ndarray/base/find/test/test.js b/lib/node_modules/@stdlib/ndarray/base/find/test/test.js index 0bc61e85a748..7a5ce8218e6f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/test/test.js @@ -18,6 +18,8 @@ 'use strict'; +/* eslint-disable stdlib/no-redeclare */ + // MODULES // var tape = require( 'tape' ); From fa9ef2af4c5533f0174f14c670db29edd6238e16 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 21 Jun 2025 15:53:41 +0500 Subject: [PATCH 07/30] fix: lint errors --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../ndarray/base/find/benchmark/benchmark.1d_columnmajor.js | 2 ++ .../ndarray/base/find/benchmark/benchmark.1d_rowmajor.js | 2 ++ .../base/find/benchmark/benchmark.2d_blocked_columnmajor.js | 2 ++ .../base/find/benchmark/benchmark.2d_blocked_rowmajor.js | 2 ++ .../ndarray/base/find/benchmark/benchmark.2d_columnmajor.js | 2 ++ .../ndarray/base/find/benchmark/benchmark.2d_rowmajor.js | 2 ++ .../base/find/benchmark/benchmark.2d_rowmajor_accessors.js | 2 ++ .../base/find/benchmark/benchmark.3d_blocked_columnmajor.js | 2 ++ .../base/find/benchmark/benchmark.3d_blocked_rowmajor.js | 2 ++ .../ndarray/base/find/benchmark/benchmark.3d_columnmajor.js | 2 ++ .../ndarray/base/find/benchmark/benchmark.3d_rowmajor.js | 2 ++ 11 files changed, 22 insertions(+) diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_columnmajor.js index a3af7b44bac7..96436346d4fa 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_columnmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_columnmajor.js @@ -18,6 +18,8 @@ 'use strict'; +/* eslint-disable stdlib/no-redeclare */ + // MODULES // var bench = require( '@stdlib/bench' ); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_rowmajor.js index 141a89eccbb2..474854b25364 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_rowmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_rowmajor.js @@ -18,6 +18,8 @@ 'use strict'; +/* eslint-disable stdlib/no-redeclare */ + // MODULES // var bench = require( '@stdlib/bench' ); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_columnmajor.js index 4d36f4ca445c..fd111ccbd09a 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_columnmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_columnmajor.js @@ -18,6 +18,8 @@ 'use strict'; +/* eslint-disable stdlib/no-redeclare */ + // MODULES // var bench = require( '@stdlib/bench' ); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_rowmajor.js index b78c64d5a03d..c75880f523f3 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_rowmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_rowmajor.js @@ -18,6 +18,8 @@ 'use strict'; +/* eslint-disable stdlib/no-redeclare */ + // MODULES // var bench = require( '@stdlib/bench' ); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_columnmajor.js index 8be20c40c7f0..259063d118cf 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_columnmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_columnmajor.js @@ -18,6 +18,8 @@ 'use strict'; +/* eslint-disable stdlib/no-redeclare */ + // MODULES // var bench = require( '@stdlib/bench' ); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor.js index 01f16079098e..1e95d9c4c1f2 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor.js @@ -18,6 +18,8 @@ 'use strict'; +/* eslint-disable stdlib/no-redeclare */ + // MODULES // var bench = require( '@stdlib/bench' ); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor_accessors.js index 84690da0c9bf..aec34c1e2ea8 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor_accessors.js @@ -18,6 +18,8 @@ 'use strict'; +/* eslint-disable stdlib/no-redeclare */ + // MODULES // var bench = require( '@stdlib/bench' ); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_columnmajor.js index 2e498ac791ab..f3261eb8a03d 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_columnmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_columnmajor.js @@ -18,6 +18,8 @@ 'use strict'; +/* eslint-disable stdlib/no-redeclare */ + // MODULES // var bench = require( '@stdlib/bench' ); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_rowmajor.js index 56a974cbdbdb..8ddc7ded8475 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_rowmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_rowmajor.js @@ -18,6 +18,8 @@ 'use strict'; +/* eslint-disable stdlib/no-redeclare */ + // MODULES // var bench = require( '@stdlib/bench' ); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_columnmajor.js index 1733db1f6c17..d3be50533667 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_columnmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_columnmajor.js @@ -18,6 +18,8 @@ 'use strict'; +/* eslint-disable stdlib/no-redeclare */ + // MODULES // var bench = require( '@stdlib/bench' ); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_rowmajor.js index f8c25c61e6cd..023a3382f987 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_rowmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_rowmajor.js @@ -18,6 +18,8 @@ 'use strict'; +/* eslint-disable stdlib/no-redeclare */ + // MODULES // var bench = require( '@stdlib/bench' ); From d650d02f4f6ac1c0444883ae398b106a4e047b60 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 21 Jun 2025 16:38:00 +0500 Subject: [PATCH 08/30] bench: make consistent & worst case scenario --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../base/find/benchmark/benchmark.1d_columnmajor.js | 8 ++++---- .../ndarray/base/find/benchmark/benchmark.1d_rowmajor.js | 2 +- .../find/benchmark/benchmark.2d_blocked_columnmajor.js | 2 +- .../base/find/benchmark/benchmark.2d_blocked_rowmajor.js | 4 ++-- .../base/find/benchmark/benchmark.2d_columnmajor.js | 4 ++-- .../ndarray/base/find/benchmark/benchmark.2d_rowmajor.js | 2 +- .../find/benchmark/benchmark.2d_rowmajor_accessors.js | 2 +- .../find/benchmark/benchmark.3d_blocked_columnmajor.js | 2 +- .../base/find/benchmark/benchmark.3d_blocked_rowmajor.js | 2 +- .../base/find/benchmark/benchmark.3d_columnmajor.js | 2 +- .../ndarray/base/find/benchmark/benchmark.3d_rowmajor.js | 2 +- 11 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_columnmajor.js index 96436346d4fa..bb49e979cea9 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_columnmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_columnmajor.js @@ -46,7 +46,7 @@ var order = 'column-major'; * @returns {boolean} result */ function clbk( value ) { - return value % 2.0 === 0.0; + return value < 0.0; } /** @@ -59,8 +59,8 @@ function clbk( value ) { * @returns {Function} benchmark function */ function createBenchmark( len, shape, xtype ) { + var sv; var x; - var v; x = discreteUniform( len, 1, 100 ); x = { @@ -71,7 +71,7 @@ function createBenchmark( len, shape, xtype ) { 'offset': 0, 'order': order }; - v = { + sv = { 'dtype': xtype, 'data': [ -1.0 ], 'shape': [], @@ -93,7 +93,7 @@ function createBenchmark( len, shape, xtype ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = find( [ x, v ], clbk ); + out = find( [ x, sv ], clbk ); if ( isnan( out ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_rowmajor.js index 474854b25364..f1f94bc425a4 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_rowmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_rowmajor.js @@ -46,7 +46,7 @@ var order = 'row-major'; * @returns {boolean} result */ function clbk( value ) { - return value % 2.0 === 0.0; + return value < 0.0; } /** diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_columnmajor.js index fd111ccbd09a..3e4ee71aab0c 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_columnmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_columnmajor.js @@ -48,7 +48,7 @@ var order = 'column-major'; * @returns {boolean} result */ function clbk( value ) { - return value % 2.0 === 0.0; + return value < 0.0; } /** diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_rowmajor.js index c75880f523f3..87462510b266 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_rowmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_rowmajor.js @@ -48,7 +48,7 @@ var order = 'row-major'; * @returns {boolean} result */ function clbk( value ) { - return value % 2.0 === 0.0; + return value < 0.0; } /** @@ -86,7 +86,7 @@ function createBenchmark( len, shape, xtype ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = find( x, 101, clbk ); + out = find( x, -1, clbk ); if ( isnan( out ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_columnmajor.js index 259063d118cf..1c01b9db24c9 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_columnmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_columnmajor.js @@ -48,7 +48,7 @@ var order = 'column-major'; * @returns {boolean} result */ function clbk( value ) { - return value % 2.0 === 0.0; + return value < 0.0; } /** @@ -86,7 +86,7 @@ function createBenchmark( len, shape, xtype ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = find( x, 101, clbk ); + out = find( x, -1, clbk ); if ( isnan( out ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor.js index 1e95d9c4c1f2..208bdd40362e 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor.js @@ -48,7 +48,7 @@ var order = 'row-major'; * @returns {boolean} result */ function clbk( value ) { - return value % 2.0 === 0.0; + return value < 0.0; } /** diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor_accessors.js index aec34c1e2ea8..b8fa675dbcc1 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor_accessors.js @@ -48,7 +48,7 @@ var order = 'row-major'; * @returns {boolean} result */ function clbk( value ) { - return value % 2.0 === 0.0; + return value < 0.0; } /** diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_columnmajor.js index f3261eb8a03d..4955cf8b4fb4 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_columnmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_columnmajor.js @@ -48,7 +48,7 @@ var order = 'column-major'; * @returns {boolean} result */ function clbk( value ) { - return value % 2.0 === 0.0; + return value < 0.0; } /** diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_rowmajor.js index 8ddc7ded8475..de0a916ddbe6 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_rowmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_rowmajor.js @@ -48,7 +48,7 @@ var order = 'row-major'; * @returns {boolean} result */ function clbk( value ) { - return value % 2.0 === 0.0; + return value < 0.0; } /** diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_columnmajor.js index d3be50533667..241bb8c32b01 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_columnmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_columnmajor.js @@ -48,7 +48,7 @@ var order = 'column-major'; * @returns {boolean} result */ function clbk( value ) { - return value % 2.0 === 0.0; + return value < 0.0; } /** diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_rowmajor.js index 023a3382f987..ad2d374c65d1 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_rowmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_rowmajor.js @@ -48,7 +48,7 @@ var order = 'row-major'; * @returns {boolean} result */ function clbk( value ) { - return value % 2.0 === 0.0; + return value < 0.0; } /** From 2ca2802c9b89349f17260a32c0321f8221179b80 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 21 Jun 2025 17:02:51 +0500 Subject: [PATCH 09/30] chore: make consistent --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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 --- --- .../ndarray/base/find/docs/types/index.d.ts | 4 +-- .../ndarray/base/find/docs/types/test.ts | 25 ++++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/find/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/find/docs/types/index.d.ts index 716f8bbd9581..90a74a8da63b 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/find/docs/types/index.d.ts @@ -73,7 +73,7 @@ type Predicate = Nullary | Unary | Binary | Ternary; * @param arrays - array-like object containing one input ndarray and a zero-dimensional sentinel value ndarray * @param predicate - predicate function * @param thisArg - predicate function execution context -* @returns boolean indicating whether all elements pass a test +* @returns result * * @example * var Float64Array = require( '@stdlib/array/float64' ); @@ -108,7 +108,7 @@ type Predicate = Nullary | Unary | Binary | Ternary; * var out = find( [ x, sv ], predicate ); * // returns 2.0 */ -declare function find( arrays: ArrayLike>, predicate: Predicate, thisArg?: ThisParameterType> ): V; +declare function find( arrays: ArrayLike>, predicate: Predicate, thisArg?: ThisParameterType> ): T; // EXPORTS // diff --git a/lib/node_modules/@stdlib/ndarray/base/find/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/find/docs/types/test.ts index 0b5795a07113..47ca0c60900a 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/base/find/docs/types/test.ts @@ -19,6 +19,7 @@ /// import zeros = require( '@stdlib/ndarray/zeros' ); +import scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); import find = require( './index' ); /** @@ -34,14 +35,16 @@ function clbk( v: any ): boolean { // TESTS // -// The function returns a float64... +// The function returns a number... { const x = zeros( [ 2, 2 ] ); - const v = zeros( [] ); - const arrays = [ x, v ]; + const sv = scalar2ndarray( -1.0, { + 'dtype': 'float64' + } ); + const arrays = [ x, sv ]; - find( arrays, clbk ); // $ExpectType float64 - find( arrays, clbk, {} ); // $ExpectType float64 + find( arrays, clbk ); // $ExpectType number + find( arrays, clbk, {} ); // $ExpectType number } // The compiler throws an error if the function is provided a first argument which is not an array-like object containing ndarray-like objects... @@ -68,8 +71,10 @@ function clbk( v: any ): boolean { // The compiler throws an error if the function is provided a second argument which is not a callback function... { const x = zeros( [ 2, 2 ] ); - const v = zeros( [] ); - const arrays = [ x, v ]; + const sv = scalar2ndarray( -1.0, { + 'dtype': 'float64' + } ); + const arrays = [ x, sv ]; find( arrays, '10' ); // $ExpectError find( arrays, 5 ); // $ExpectError @@ -93,8 +98,10 @@ function clbk( v: any ): boolean { // The compiler throws an error if the function is provided an unsupported number of arguments... { const x = zeros( [ 2, 2 ] ); - const v = zeros( [] ); - const arrays = [ x, v ]; + const sv = scalar2ndarray( -1.0, { + 'dtype': 'float64' + } ); + const arrays = [ x, sv ]; find(); // $ExpectError find( arrays ); // $ExpectError From f7fe883ec61298be870102198d5c6da53bb1149e Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 21 Jun 2025 22:21:30 +0500 Subject: [PATCH 10/30] test: add tests upto 2d --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/base/find/test/test.0d.js | 94 ++ .../@stdlib/ndarray/base/find/test/test.1d.js | 201 +++ .../@stdlib/ndarray/base/find/test/test.2d.js | 1237 +++++++++++++++++ 3 files changed, 1532 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/test/test.0d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/test/test.1d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/test/test.2d.js diff --git a/lib/node_modules/@stdlib/ndarray/base/find/test/test.0d.js b/lib/node_modules/@stdlib/ndarray/base/find/test/test.0d.js new file mode 100644 index 000000000000..ac8f2ffb6287 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/test/test.0d.js @@ -0,0 +1,94 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var tape = require( 'tape' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var real = require( '@stdlib/complex/float64/real' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var find = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof find, 'function', 'main export is a function'); + t.end(); +}); + +tape( 'the function returns the first element in a 0-dimensional ndarray which passes a test implemented by a predicate function', function test( t ) { + var actual; + var sv; + var x; + + sv = scalar2ndarray( -1.0, { + 'dtype': 'float64' + }); + + x = scalar2ndarray( 4.0, { + 'dtype': 'float64' + }); + actual = find( [ x, sv ], clbk ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + x = scalar2ndarray( 3.0, { + 'dtype': 'float64' + }); + actual = find( [ x, sv ], clbk ); + t.strictEqual( actual, -1.0, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 === 0.0; + } +}); + +tape( 'the function returns the first element in a 0-dimensional ndarray which passes a test implemented by a predicate function (accessors)', function test( t ) { + var actual; + var sv; + var x; + + sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + 'dtype': 'complex128' + }); + + x = scalar2ndarray( new Complex128( 2.0, 0.0 ), { + 'dtype': 'complex128' + }); + actual = find( [ x, sv ], clbk ); + t.deepEqual( actual, new Complex128( 2.0, 0.0 ), 'returns expected value' ); + + x = scalar2ndarray( new Complex128( 3.0, 0.0 ), { + 'dtype': 'complex128' + }); + actual = find( [ x, sv ], clbk ); + t.deepEqual( actual, new Complex128( -1.0, 0.0 ), 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return real( v ) % 2.0 === 0; + } +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/test/test.1d.js b/lib/node_modules/@stdlib/ndarray/base/find/test/test.1d.js new file mode 100644 index 000000000000..22680dd403b9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/test/test.1d.js @@ -0,0 +1,201 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// 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 Complex128 = require( '@stdlib/complex/float64/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var find = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof find, 'function', 'main export is a function'); + t.end(); +}); + +tape( 'the function returns the first element in a 1-dimensional ndarray which passes a test implemented by a predicate function', function test( t ) { + var actual; + var sv; + var x; + + sv = scalar2ndarray( -1.0, { + 'dtype': 'float64' + }); + + x = ndarray( 'float64', oneTo( 8, 'float64' ), [ 4 ], [ 1 ], 0, 'row-major' ); + actual = find( [ x, sv ], clbk ); + t.strictEqual( actual, 2.0, 'returns expected value' ); + + x = ndarray( 'float64', oneTo( 8, 'float64' ), [ 4 ], [ 2 ], 0, 'row-major' ); + actual = find( [ x, sv ], clbk ); + t.strictEqual( actual, -1.0, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 === 0.0; + } +}); + +tape( 'the function returns the first element in a 1-dimensional ndarray which passes a test implemented by a predicate function (accessors)', function test( t ) { + var actual; + var sv; + var x; + + sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + 'dtype': 'complex128' + }); + + x = ndarray( 'complex128', oneTo( 8, 'complex128' ), [ 4 ], [ 1 ], 0, 'row-major' ); + actual = find( [ x, sv ], clbk ); + t.deepEqual( actual, new Complex128( 2.0, 0.0 ), 'returns expected value' ); + + x = ndarray( 'complex128', oneTo( 8, 'complex128' ), [ 4 ], [ 2 ], 0, 'row-major' ); + actual = find( [ x, sv ], clbk ); + t.deepEqual( actual, new Complex128( -1.0, 0.0 ), 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return real( v ) % 2.0 === 0.0; + } +}); + +tape( 'the function supports specifying the callback execution context', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var actual; + var ctx; + var sv; + var x; + + x = new ndarray( 'float64', oneTo( 8, 'float64'), [ 4 ], [ 1 ], 0, 'row-major' ); + sv = scalar2ndarray( -1.0, { + 'dtype': 'float64' + }); + + indices = []; + values = []; + arrays = []; + + ctx = { + 'count': 0 + }; + actual = find( [ x, sv ], clbk, ctx ); + + t.strictEqual( actual, 2.0, 'returns expected value' ); + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + expected = [ + 1.0, + 2.0 + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0 ], + [ 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function clbk( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( v ); + indices.push( idx ); + arrays.push( arr ); + return v % 2.0 === 0.0; + } +}); + +tape( 'the function supports specifying the callback execution context (accessors)', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var actual; + var ctx; + var sv; + var x; + + x = ndarray( 'complex128', oneTo( 8, 'complex128' ), [ 4 ], [ 1 ], 0, 'row-major' ); + sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + 'dtype': 'complex128' + }); + + indices = []; + values = []; + arrays = []; + + ctx = { + 'count': 0 + }; + actual = find( [ x, sv ], clbk, ctx ); + + t.deepEqual( actual, new Complex128( 2.0, 0.0 ), 'returns expected value' ); + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0 ], + [ 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function clbk( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + arrays.push( arr ); + return real( v ) % 2.0 === 0.0; + } +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/test/test.2d.js b/lib/node_modules/@stdlib/ndarray/base/find/test/test.2d.js new file mode 100644 index 000000000000..1bdb47aa25dd --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/test/test.2d.js @@ -0,0 +1,1237 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// 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 Complex128 = require( '@stdlib/complex/float64/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +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 ndarray = require( '@stdlib/ndarray/ctor' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var find = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof find, 'function', 'main export is a function'); + t.end(); +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, singleton dimensions)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( -1.0, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk ); + t.strictEqual( actual, 2.0, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 === 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, singleton dimensions, accessors)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk ); + t.deepEqual( actual, new Complex128( 2.0, 0.0 ), 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return real( v ) % 2.0 === 0.0; + } +}); + +tape( 'the function supports specifying the callback execution context (row-major, contiguous)', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var actual; + var ctx; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( -1.0, { + 'dtype': 'float64' + }); + + indices = []; + values = []; + arrays = []; + + ctx = { + 'count': 0 + }; + actual = find( [ x, sv ], clbk, ctx ); + + t.strictEqual( actual, 2.0, 'returns expected value' ); + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + expected = [ + 1.0, + 2.0 + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function clbk( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( v ); + indices.push( idx ); + arrays.push( arr ); + return v % 2.0 === 0.0; + } +}); + +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 actual; + var ctx; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + 'dtype': 'complex128' + }); + + indices = []; + values = []; + arrays = []; + + ctx = { + 'count': 0 + }; + actual = find( [ x, sv ], clbk, ctx ); + + t.deepEqual( actual, new Complex128( 2.0, 0.0 ), 'returns expected value' ); + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function clbk( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + arrays.push( arr ); + return real( v ) % 2.0 === 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, contiguous)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( -1.0, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk ); + t.strictEqual( actual, 2.0, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 === 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, contiguous, negative strides)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( -1.0, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 === 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, same sign strides)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( -1.0, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk ); + t.strictEqual( actual, 1.0, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 !== 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, mixed sign strides)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( -1.0, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk ); + t.strictEqual( actual, 3.0, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 !== 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, large arrays)', function test( t ) { + var actual; + var bsize; + var ord; + var sh; + var st; + var dt; + var sv; + 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, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + sv = scalar2ndarray( -1.0, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk ); + t.strictEqual( actual, 29.0, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 !== 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, large arrays)', function test( t ) { + var actual; + var bsize; + var ord; + var sh; + var st; + var dt; + var sv; + 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, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + sv = scalar2ndarray( -1.0, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk ); + t.strictEqual( actual, 15.0, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 !== 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, contiguous, accessors)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk ); + t.deepEqual( actual, new Complex128( 2.0, 0.0 ), 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return real( v ) % 2.0 === 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, contiguous, negative strides, accessors)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk ); + t.deepEqual( actual, new Complex128( 4.0, 0.0 ), 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return real( v ) % 2.0 === 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, same sign strides, accessors)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ 4, 2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( 8*2, dt ), sh, st, o, ord ); + sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk ); + t.deepEqual( actual, new Complex128( 1.0, 0.0 ), 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return real( v ) % 2.0 !== 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ -4, 2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( 8*2, dt ), sh, st, o, ord ); + sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk ); + t.deepEqual( actual, new Complex128( 5.0, 0.0 ), 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return real( v ) % 2.0 !== 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var actual; + var bsize; + var ord; + var sh; + var st; + var dt; + var sv; + 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, oneTo( numel( sh )*4, dt ), sh, st, o, ord ); + sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk ); + t.deepEqual( actual, new Complex128( 13.0, 0.0 ), 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return real( v ) % 2.0 !== 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var actual; + var bsize; + var ord; + var sh; + var st; + var dt; + var sv; + 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, oneTo( numel( sh )*4, dt ), sh, st, o, ord ); + sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk ); + t.deepEqual( actual, new Complex128( 7.0, 0.0 ), 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return real( v ) % 2.0 !== 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, singleton dimensions)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( -1.0, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk ); + t.strictEqual( actual, 2.0, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 === 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, singleton dimensions, accessors)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk ); + t.deepEqual( actual, new Complex128( 2.0, 0.0 ), 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return real( v ) % 2.0 === 0.0; + } +}); + +tape( 'the function returns the sentinel value if all elements in a 2-dimensional ndarray fail a test implemented by a predicate function (column-major, contiguous, accessors)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk ); + t.deepEqual( actual, new Complex128( -1.0, 0.0 ), 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return real( v ) < 0.0; + } +}); + +tape( 'the function supports specifying the callback execution context (column-major, contiguous)', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var actual; + var ctx; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( -1.0, { + 'dtype': 'float64' + }); + + indices = []; + values = []; + arrays = []; + + ctx = { + 'count': 0 + }; + actual = find( [ x, sv ], clbk, ctx ); + + t.strictEqual( actual, 2.0, 'returns expected value' ); + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + expected = [ + 1.0, + 2.0 + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 1, 0 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function clbk( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( v ); + indices.push( idx ); + arrays.push( arr ); + return v % 2.0 === 0.0; + } +}); + +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 actual; + var ctx; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + 'dtype': 'complex128' + }); + + indices = []; + values = []; + arrays = []; + + ctx = { + 'count': 0 + }; + actual = find( [ x, sv ], clbk, ctx ); + + t.deepEqual( actual, new Complex128( 2.0, 0.0 ), 'returns expected value' ); + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 1, 0 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function clbk( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + arrays.push( arr ); + return real( v ) % 2.0 === 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, contiguous)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( -1.0, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk ); + t.strictEqual( actual, 2.0, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 === 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, contiguous, negative strides)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( -1.0, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 === 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, same sign strides)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( -1.0, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk ); + t.strictEqual( actual, 1.0, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 !== 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, mixed sign strides)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( -1.0, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk ); + t.strictEqual( actual, 3.0, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 !== 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, large arrays)', function test( t ) { + var actual; + var bsize; + var ord; + var sh; + var st; + var dt; + var sv; + 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, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + sv = scalar2ndarray( -1.0, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk ); + t.strictEqual( actual, 49.0, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 !== 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, large arrays)', function test( t ) { + var actual; + var bsize; + var ord; + var sh; + var st; + var dt; + var sv; + 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, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + sv = scalar2ndarray( -1.0, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk ); + t.strictEqual( actual, 35.0, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 !== 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, contiguous, accessors)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk ); + t.deepEqual( actual, new Complex128( 2.0, 0.0 ), 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return real( v ) % 2.0 === 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, contiguous, negative strides, accessors)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk ); + t.deepEqual( actual, new Complex128( 4.0, 0.0 ), 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return real( v ) % 2.0 === 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, same sign strides, accessors)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ 2, 4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( 8*2, dt ), sh, st, o, ord ); + sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk ); + t.deepEqual( actual, new Complex128( 1.0, 0.0 ), 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return real( v ) % 2.0 !== 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ -2, 4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( 8*2, dt ), sh, st, o, ord ); + sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk ); + t.deepEqual( actual, new Complex128( 3.0, 0.0 ), 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return real( v ) % 2.0 !== 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var actual; + var bsize; + var ord; + var sh; + var st; + var dt; + var sv; + 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, oneTo( numel( sh )*4, dt ), sh, st, o, ord ); + sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk ); + t.deepEqual( actual, new Complex128( 7.0, 0.0 ), 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return real( v ) % 2.0 !== 0.0; + } +}); + +tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var actual; + var bsize; + var ord; + var sh; + var st; + var dt; + var sv; + 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, oneTo( numel( sh )*4, dt ), sh, st, o, ord ); + sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk ); + t.deepEqual( actual, new Complex128( 13.0, 0.0 ), 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return real( v ) % 2.0 !== 0.0; + } +}); From a776c3b37e8b5ccb3bcfdbdfa81e95cc467b672c Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 25 Jun 2025 09:59:33 +0000 Subject: [PATCH 11/30] refactor: add sentinel cases --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/base/find/test/test.1d.js | 35 +- .../@stdlib/ndarray/base/find/test/test.2d.js | 399 +++++++++++++----- 2 files changed, 303 insertions(+), 131 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/find/test/test.1d.js b/lib/node_modules/@stdlib/ndarray/base/find/test/test.1d.js index 22680dd403b9..0da9cf3493d4 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/test/test.1d.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/test/test.1d.js @@ -26,6 +26,7 @@ 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 isSameValue = require( '@stdlib/assert/is-same-value' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var ndarray = require( '@stdlib/ndarray/ctor' ); @@ -45,23 +46,26 @@ tape( 'the function returns the first element in a 1-dimensional ndarray which p var sv; var x; - sv = scalar2ndarray( -1.0, { + sv = scalar2ndarray( NaN, { 'dtype': 'float64' }); - x = ndarray( 'float64', oneTo( 8, 'float64' ), [ 4 ], [ 1 ], 0, 'row-major' ); - actual = find( [ x, sv ], clbk ); + + actual = find( [ x, sv ], clbk1 ); t.strictEqual( actual, 2.0, 'returns expected value' ); - x = ndarray( 'float64', oneTo( 8, 'float64' ), [ 4 ], [ 2 ], 0, 'row-major' ); - actual = find( [ x, sv ], clbk ); - t.strictEqual( actual, -1.0, 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); t.end(); - function clbk( v ) { + function clbk1( v ) { return v % 2.0 === 0.0; } + + function clbk2( v ) { + return v < 0.0; + } }); tape( 'the function returns the first element in a 1-dimensional ndarray which passes a test implemented by a predicate function (accessors)', function test( t ) { @@ -69,23 +73,26 @@ tape( 'the function returns the first element in a 1-dimensional ndarray which p var sv; var x; - sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + sv = scalar2ndarray( new Complex128( NaN, NaN ), { 'dtype': 'complex128' }); - x = ndarray( 'complex128', oneTo( 8, 'complex128' ), [ 4 ], [ 1 ], 0, 'row-major' ); - actual = find( [ x, sv ], clbk ); + + actual = find( [ x, sv ], clbk1 ); t.deepEqual( actual, new Complex128( 2.0, 0.0 ), 'returns expected value' ); - x = ndarray( 'complex128', oneTo( 8, 'complex128' ), [ 4 ], [ 2 ], 0, 'row-major' ); - actual = find( [ x, sv ], clbk ); - t.deepEqual( actual, new Complex128( -1.0, 0.0 ), 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); t.end(); - function clbk( v ) { + function clbk1( v ) { return real( v ) % 2.0 === 0.0; } + + function clbk2( v ) { + return real( v ) < 0.0; + } }); tape( 'the function supports specifying the callback execution context', function test( t ) { diff --git a/lib/node_modules/@stdlib/ndarray/base/find/test/test.2d.js b/lib/node_modules/@stdlib/ndarray/base/find/test/test.2d.js index 1bdb47aa25dd..b5ae5108ee72 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/test/test.2d.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/test/test.2d.js @@ -28,10 +28,10 @@ var real = require( '@stdlib/complex/float64/real' ); var imag = require( '@stdlib/complex/float64/imag' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); -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 isSameValue = require( '@stdlib/assert/is-same-value' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); var find = require( './../lib' ); @@ -62,18 +62,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); - sv = scalar2ndarray( -1.0, { + sv = scalar2ndarray( NaN, { 'dtype': 'float64' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.strictEqual( actual, 2.0, 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return v % 2.0 === 0.0; } + + function clbk2( v ) { + return v < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, singleton dimensions, accessors)', function test( t ) { @@ -93,18 +100,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); - sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + sv = scalar2ndarray( new Complex128( NaN, NaN ), { 'dtype': 'complex128' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.deepEqual( actual, new Complex128( 2.0, 0.0 ), 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return real( v ) % 2.0 === 0.0; } + + function clbk2( v ) { + return real( v ) < 0.0; + } }); tape( 'the function supports specifying the callback execution context (row-major, contiguous)', function test( t ) { @@ -129,7 +143,7 @@ tape( 'the function supports specifying the callback execution context (row-majo o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); - sv = scalar2ndarray( -1.0, { + sv = scalar2ndarray( NaN, { 'dtype': 'float64' }); @@ -196,7 +210,7 @@ tape( 'the function supports specifying the callback execution context (row-majo o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); - sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + sv = scalar2ndarray( new Complex128( NaN, NaN ), { 'dtype': 'complex128' }); @@ -258,18 +272,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); - sv = scalar2ndarray( -1.0, { + sv = scalar2ndarray( NaN, { 'dtype': 'float64' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.strictEqual( actual, 2.0, 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return v % 2.0 === 0.0; } + + function clbk2( v ) { + return v < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, contiguous, negative strides)', function test( t ) { @@ -289,18 +310,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); - sv = scalar2ndarray( -1.0, { + sv = scalar2ndarray( NaN, { 'dtype': 'float64' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.strictEqual( actual, 4.0, 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return v % 2.0 === 0.0; } + + function clbk2( v ) { + return v < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, same sign strides)', function test( t ) { @@ -320,18 +348,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); - sv = scalar2ndarray( -1.0, { + sv = scalar2ndarray( NaN, { 'dtype': 'float64' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.strictEqual( actual, 1.0, 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return v % 2.0 !== 0.0; } + + function clbk2( v ) { + return v < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, mixed sign strides)', function test( t ) { @@ -351,18 +386,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); - sv = scalar2ndarray( -1.0, { + sv = scalar2ndarray( NaN, { 'dtype': 'float64' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.strictEqual( actual, 3.0, 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return v % 2.0 !== 0.0; } + + function clbk2( v ) { + return v < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, large arrays)', function test( t ) { @@ -385,18 +427,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); - sv = scalar2ndarray( -1.0, { + sv = scalar2ndarray( NaN, { 'dtype': 'float64' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.strictEqual( actual, 29.0, 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return v % 2.0 !== 0.0; } + + function clbk2( v ) { + return v < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, large arrays)', function test( t ) { @@ -419,18 +468,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); - sv = scalar2ndarray( -1.0, { + sv = scalar2ndarray( NaN, { 'dtype': 'float64' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.strictEqual( actual, 15.0, 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return v % 2.0 !== 0.0; } + + function clbk2( v ) { + return v < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, contiguous, accessors)', function test( t ) { @@ -450,18 +506,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); - sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + sv = scalar2ndarray( new Complex128( NaN, NaN ), { 'dtype': 'complex128' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.deepEqual( actual, new Complex128( 2.0, 0.0 ), 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return real( v ) % 2.0 === 0.0; } + + function clbk2( v ) { + return real( v ) < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, contiguous, negative strides, accessors)', function test( t ) { @@ -481,18 +544,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); - sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + sv = scalar2ndarray( new Complex128( NaN, NaN ), { 'dtype': 'complex128' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.deepEqual( actual, new Complex128( 4.0, 0.0 ), 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return real( v ) % 2.0 === 0.0; } + + function clbk2( v ) { + return real( v ) < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, same sign strides, accessors)', function test( t ) { @@ -512,18 +582,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( 8*2, dt ), sh, st, o, ord ); - sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + sv = scalar2ndarray( new Complex128( NaN, NaN ), { 'dtype': 'complex128' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.deepEqual( actual, new Complex128( 1.0, 0.0 ), 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return real( v ) % 2.0 !== 0.0; } + + function clbk2( v ) { + return real( v ) < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { @@ -543,18 +620,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( 8*2, dt ), sh, st, o, ord ); - sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + sv = scalar2ndarray( new Complex128( NaN, NaN ), { 'dtype': 'complex128' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.deepEqual( actual, new Complex128( 5.0, 0.0 ), 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return real( v ) % 2.0 !== 0.0; } + + function clbk2( v ) { + return real( v ) < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, large arrays, accessors)', function test( t ) { @@ -577,18 +661,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh )*4, dt ), sh, st, o, ord ); - sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + sv = scalar2ndarray( new Complex128( NaN, NaN ), { 'dtype': 'complex128' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.deepEqual( actual, new Complex128( 13.0, 0.0 ), 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return real( v ) % 2.0 !== 0.0; } + + function clbk2( v ) { + return real( v ) < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, large arrays, accessors)', function test( t ) { @@ -611,18 +702,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh )*4, dt ), sh, st, o, ord ); - sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + sv = scalar2ndarray( new Complex128( NaN, NaN ), { 'dtype': 'complex128' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.deepEqual( actual, new Complex128( 7.0, 0.0 ), 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return real( v ) % 2.0 !== 0.0; } + + function clbk2( v ) { + return real( v ) < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, singleton dimensions)', function test( t ) { @@ -642,18 +740,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); - sv = scalar2ndarray( -1.0, { + sv = scalar2ndarray( NaN, { 'dtype': 'float64' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.strictEqual( actual, 2.0, 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return v % 2.0 === 0.0; } + + function clbk2( v ) { + return v < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, singleton dimensions, accessors)', function test( t ) { @@ -673,47 +778,23 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); - sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + sv = scalar2ndarray( new Complex128( NaN, NaN ), { 'dtype': 'complex128' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.deepEqual( actual, new Complex128( 2.0, 0.0 ), 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return real( v ) % 2.0 === 0.0; } -}); -tape( 'the function returns the sentinel value if all elements in a 2-dimensional ndarray fail a test implemented by a predicate function (column-major, contiguous, accessors)', function test( t ) { - var actual; - var ord; - var sh; - var st; - var dt; - var sv; - 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 ); - sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { - 'dtype': 'complex128' - }); - - actual = find( [ x, sv ], clbk ); - t.deepEqual( actual, new Complex128( -1.0, 0.0 ), 'returns expected value' ); - - t.end(); - - function clbk( v ) { + function clbk2( v ) { return real( v ) < 0.0; } }); @@ -740,7 +821,7 @@ tape( 'the function supports specifying the callback execution context (column-m o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); - sv = scalar2ndarray( -1.0, { + sv = scalar2ndarray( NaN, { 'dtype': 'float64' }); @@ -807,7 +888,7 @@ tape( 'the function supports specifying the callback execution context (column-m o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); - sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + sv = scalar2ndarray( new Complex128( NaN, NaN ), { 'dtype': 'complex128' }); @@ -869,18 +950,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); - sv = scalar2ndarray( -1.0, { + sv = scalar2ndarray( NaN, { 'dtype': 'float64' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.strictEqual( actual, 2.0, 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return v % 2.0 === 0.0; } + + function clbk2( v ) { + return v < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, contiguous, negative strides)', function test( t ) { @@ -900,18 +988,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); - sv = scalar2ndarray( -1.0, { + sv = scalar2ndarray( NaN, { 'dtype': 'float64' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.strictEqual( actual, 4.0, 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return v % 2.0 === 0.0; } + + function clbk2( v ) { + return v < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, same sign strides)', function test( t ) { @@ -931,18 +1026,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); - sv = scalar2ndarray( -1.0, { + sv = scalar2ndarray( NaN, { 'dtype': 'float64' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.strictEqual( actual, 1.0, 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return v % 2.0 !== 0.0; } + + function clbk2( v ) { + return v < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, mixed sign strides)', function test( t ) { @@ -962,18 +1064,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); - sv = scalar2ndarray( -1.0, { + sv = scalar2ndarray( NaN, { 'dtype': 'float64' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.strictEqual( actual, 3.0, 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return v % 2.0 !== 0.0; } + + function clbk2( v ) { + return v < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, large arrays)', function test( t ) { @@ -996,18 +1105,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); - sv = scalar2ndarray( -1.0, { + sv = scalar2ndarray( NaN, { 'dtype': 'float64' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.strictEqual( actual, 49.0, 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return v % 2.0 !== 0.0; } + + function clbk2( v ) { + return v < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, large arrays)', function test( t ) { @@ -1030,18 +1146,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); - sv = scalar2ndarray( -1.0, { + sv = scalar2ndarray( NaN, { 'dtype': 'float64' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.strictEqual( actual, 35.0, 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return v % 2.0 !== 0.0; } + + function clbk2( v ) { + return v < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, contiguous, accessors)', function test( t ) { @@ -1061,18 +1184,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); - sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + sv = scalar2ndarray( new Complex128( NaN, NaN ), { 'dtype': 'complex128' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.deepEqual( actual, new Complex128( 2.0, 0.0 ), 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return real( v ) % 2.0 === 0.0; } + + function clbk2( v ) { + return real( v ) < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, contiguous, negative strides, accessors)', function test( t ) { @@ -1092,18 +1222,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); - sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + sv = scalar2ndarray( new Complex128( NaN, NaN ), { 'dtype': 'complex128' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.deepEqual( actual, new Complex128( 4.0, 0.0 ), 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return real( v ) % 2.0 === 0.0; } + + function clbk2( v ) { + return real( v ) < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, same sign strides, accessors)', function test( t ) { @@ -1123,18 +1260,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( 8*2, dt ), sh, st, o, ord ); - sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + sv = scalar2ndarray( new Complex128( NaN, NaN ), { 'dtype': 'complex128' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.deepEqual( actual, new Complex128( 1.0, 0.0 ), 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return real( v ) % 2.0 !== 0.0; } + + function clbk2( v ) { + return real( v ) < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { @@ -1154,18 +1298,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( 8*2, dt ), sh, st, o, ord ); - sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + sv = scalar2ndarray( new Complex128( NaN, NaN ), { 'dtype': 'complex128' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.deepEqual( actual, new Complex128( 3.0, 0.0 ), 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return real( v ) % 2.0 !== 0.0; } + + function clbk2( v ) { + return real( v ) < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, large arrays, accessors)', function test( t ) { @@ -1188,18 +1339,25 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh )*4, dt ), sh, st, o, ord ); - sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + sv = scalar2ndarray( new Complex128( NaN, NaN ), { 'dtype': 'complex128' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.deepEqual( actual, new Complex128( 7.0, 0.0 ), 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return real( v ) % 2.0 !== 0.0; } + + function clbk2( v ) { + return real( v ) < 0.0; + } }); tape( 'the function returns the first element in a 2-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, large arrays, accessors)', function test( t ) { @@ -1222,16 +1380,23 @@ tape( 'the function returns the first element in a 2-dimensional ndarray which p o = strides2offset( sh, st ); x = ndarray( dt, oneTo( numel( sh )*4, dt ), sh, st, o, ord ); - sv = scalar2ndarray( new Complex128( -1.0, 0.0 ), { + sv = scalar2ndarray( new Complex128( NaN, NaN ), { 'dtype': 'complex128' }); - actual = find( [ x, sv ], clbk ); + actual = find( [ x, sv ], clbk1 ); t.deepEqual( actual, new Complex128( 13.0, 0.0 ), 'returns expected value' ); + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + t.end(); - function clbk( v ) { + function clbk1( v ) { return real( v ) % 2.0 !== 0.0; } + + function clbk2( v ) { + return real( v ) < 0.0; + } }); From c9734b51dad3716cb6febccc49ce8ae1611701b4 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 25 Jun 2025 10:14:12 +0000 Subject: [PATCH 12/30] test: add 3d tests --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/base/find/test/test.3d.js | 1525 +++++++++++++++++ 1 file changed, 1525 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/test/test.3d.js diff --git a/lib/node_modules/@stdlib/ndarray/base/find/test/test.3d.js b/lib/node_modules/@stdlib/ndarray/base/find/test/test.3d.js new file mode 100644 index 000000000000..b1cf83090230 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/test/test.3d.js @@ -0,0 +1,1525 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// 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 Complex128 = require( '@stdlib/complex/float64/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); +var isSameValue = require( '@stdlib/assert/is-same-value' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var find = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof find, 'function', 'main export is a function'); + t.end(); +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (row-major, singleton dimensions)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( NaN, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk1 ); + t.strictEqual( actual, 2.0, 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return v % 2.0 === 0.0; + } + + function clbk2( v ) { + return v < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (row-major, singleton dimensions, accessors)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( new Complex128( NaN, NaN ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk1 ); + t.deepEqual( actual, new Complex128( 2.0, 0.0 ), 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return real( v ) % 2.0 === 0.0; + } + + function clbk2( v ) { + return real( v ) < 0.0; + } +}); + +tape( 'the function supports specifying the callback execution context (row-major, contiguous)', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var actual; + var ctx; + var ord; + var sh; + var st; + var dt; + var sv; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + sv = scalar2ndarray( NaN, { + 'dtype': 'float64' + }); + + indices = []; + values = []; + arrays = []; + + ctx = { + 'count': 0 + }; + actual = find( [ x, sv ], clbk, ctx ); + + t.strictEqual( actual, 2.0, 'returns expected value' ); + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + expected = [ + 1.0, + 2.0 + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 0, 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function clbk( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( v ); + indices.push( idx ); + arrays.push( arr ); + return v % 2.0 === 0.0; + } +}); + +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 actual; + var ctx; + var ord; + var sh; + var st; + var dt; + var sv; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + sv = scalar2ndarray( new Complex128( NaN, NaN ), { + 'dtype': 'complex128' + }); + + indices = []; + values = []; + arrays = []; + + ctx = { + 'count': 0 + }; + actual = find( [ x, sv ], clbk, ctx ); + + t.deepEqual( actual, new Complex128( 2.0, 0.0 ), 'returns expected value' ); + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 0, 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function clbk( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + arrays.push( arr ); + return real( v ) % 2.0 === 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (row-major, contiguous)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + sv = scalar2ndarray( NaN, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk1 ); + t.strictEqual( actual, 2.0, 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return v % 2.0 === 0.0; + } + + function clbk2( v ) { + return v < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (row-major, contiguous, negative strides)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = [ -2, -2, -1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + sv = scalar2ndarray( NaN, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk1 ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return v % 2.0 === 0.0; + } + + function clbk2( v ) { + return v < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, same sign strides)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( NaN, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk1 ); + t.strictEqual( actual, 1.0, 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return v % 2.0 !== 0.0; + } + + function clbk2( v ) { + return v < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, mixed sign strides)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( NaN, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk1 ); + t.strictEqual( actual, 3.0, 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return v % 2.0 !== 0.0; + } + + function clbk2( v ) { + return v < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, large arrays)', function test( t ) { + var actual; + var bsize; + var ord; + var sh; + var st; + var dt; + var sv; + 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, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + sv = scalar2ndarray( NaN, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk1 ); + t.strictEqual( actual, 29.0, 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return v % 2.0 !== 0.0; + } + + function clbk2( v ) { + return v < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, large arrays)', function test( t ) { + var actual; + var bsize; + var ord; + var sh; + var st; + var dt; + var sv; + 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, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + sv = scalar2ndarray( NaN, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk1 ); + t.strictEqual( actual, 15.0, 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return v % 2.0 !== 0.0; + } + + function clbk2( v ) { + return v < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (row-major, contiguous, accessors)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + sv = scalar2ndarray( new Complex128( NaN, NaN ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk1 ); + t.deepEqual( actual, new Complex128( 2.0, 0.0 ), 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return real( v ) % 2.0 === 0.0; + } + + function clbk2( v ) { + return real( v ) < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (row-major, contiguous, negative strides, accessors)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = [ -2, -2, -1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + sv = scalar2ndarray( new Complex128( NaN, NaN ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk1 ); + t.deepEqual( actual, new Complex128( 4.0, 0.0 ), 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return real( v ) % 2.0 === 0.0; + } + + function clbk2( v ) { + return real( v ) < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, same sign strides, accessors)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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( 8*2, dt ), sh, st, o, ord ); + sv = scalar2ndarray( new Complex128( NaN, NaN ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk1 ); + t.deepEqual( actual, new Complex128( 1.0, 0.0 ), 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return real( v ) % 2.0 !== 0.0; + } + + function clbk2( v ) { + return real( v ) < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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( 8*2, dt ), sh, st, o, ord ); + sv = scalar2ndarray( new Complex128( NaN, NaN ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk1 ); + t.deepEqual( actual, new Complex128( 5.0, 0.0 ), 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return real( v ) % 2.0 !== 0.0; + } + + function clbk2( v ) { + return real( v ) < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var actual; + var bsize; + var ord; + var sh; + var st; + var dt; + var sv; + 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, oneTo( numel( sh )*4, dt ), sh, st, o, ord ); + sv = scalar2ndarray( new Complex128( NaN, NaN ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk1 ); + t.deepEqual( actual, new Complex128( 13.0, 0.0 ), 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return real( v ) % 2.0 !== 0.0; + } + + function clbk2( v ) { + return real( v ) < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var actual; + var bsize; + var ord; + var sh; + var st; + var dt; + var sv; + 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, oneTo( numel( sh )*4, dt ), sh, st, o, ord ); + sv = scalar2ndarray( new Complex128( NaN, NaN ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk1 ); + t.deepEqual( actual, new Complex128( 7.0, 0.0 ), 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return real( v ) % 2.0 !== 0.0; + } + + function clbk2( v ) { + return real( v ) < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var actual; + var bsize; + var ord; + var sh; + var st; + var dt; + var sv; + 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, oneTo( numel( sh )*4, dt ), sh, st, o, ord ); + sv = scalar2ndarray( new Complex128( NaN, NaN ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk1 ); + t.deepEqual( actual, new Complex128( 7.0, 0.0 ), 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return real( v ) % 2.0 !== 0.0; + } + + function clbk2( v ) { + return real( v ) < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (column-major, singleton dimensions)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( NaN, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk1 ); + t.strictEqual( actual, 2.0, 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return v % 2.0 === 0.0; + } + + function clbk2( v ) { + return v < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (column-major, singleton dimensions, accessors)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( new Complex128( NaN, NaN ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk1 ); + t.deepEqual( actual, new Complex128( 2.0, 0.0 ), 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return real( v ) % 2.0 === 0.0; + } + + function clbk2( v ) { + return real( v ) < 0.0; + } +}); + +tape( 'the function supports specifying the callback execution context (column-major, contiguous)', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var actual; + var ctx; + var ord; + var sh; + var st; + var dt; + var sv; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + sv = scalar2ndarray( NaN, { + 'dtype': 'float64' + }); + + indices = []; + values = []; + arrays = []; + + ctx = { + 'count': 0 + }; + actual = find( [ x, sv ], clbk, ctx ); + + t.strictEqual( actual, 2.0, 'returns expected value' ); + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + expected = [ + 1.0, + 2.0 + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 1, 0, 0 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function clbk( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( v ); + indices.push( idx ); + arrays.push( arr ); + return v % 2.0 === 0.0; + } +}); + +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 actual; + var ctx; + var ord; + var sh; + var st; + var dt; + var sv; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + sv = scalar2ndarray( new Complex128( NaN, NaN ), { + 'dtype': 'complex128' + }); + + indices = []; + values = []; + arrays = []; + + ctx = { + 'count': 0 + }; + actual = find( [ x, sv ], clbk, ctx ); + + t.deepEqual( actual, new Complex128( 2.0, 0.0 ), 'returns expected value' ); + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + expected = [ + [ 1.0, 0.0 ], + [ 2.0, 0.0 ] + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 1, 0, 0 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function clbk( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( [ real( v ), imag( v ) ] ); + indices.push( idx ); + arrays.push( arr ); + return real( v ) % 2.0 === 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (column-major, contiguous)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + sv = scalar2ndarray( NaN, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk1 ); + t.strictEqual( actual, 2.0, 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return v % 2.0 === 0.0; + } + + function clbk2( v ) { + return v < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (column-major, contiguous, negative strides)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = [ -1, -2, -2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh ), dt ), sh, st, o, ord ); + sv = scalar2ndarray( NaN, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk1 ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return v % 2.0 === 0.0; + } + + function clbk2( v ) { + return v < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, same sign strides)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( NaN, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk1 ); + t.strictEqual( actual, 1.0, 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return v % 2.0 !== 0.0; + } + + function clbk2( v ) { + return v < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, mixed sign strides)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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 ); + sv = scalar2ndarray( NaN, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk1 ); + t.strictEqual( actual, 3.0, 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return v % 2.0 !== 0.0; + } + + function clbk2( v ) { + return v < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, large arrays)', function test( t ) { + var actual; + var bsize; + var ord; + var sh; + var st; + var dt; + var sv; + 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, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + sv = scalar2ndarray( NaN, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk1 ); + t.strictEqual( actual, 17.0, 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return v % 2.0 !== 0.0; + } + + function clbk2( v ) { + return v < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, large arrays)', function test( t ) { + var actual; + var bsize; + var ord; + var sh; + var st; + var dt; + var sv; + 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, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + sv = scalar2ndarray( NaN, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk1 ); + t.strictEqual( actual, 35.0, 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return v % 2.0 !== 0.0; + } + + function clbk2( v ) { + return v < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, large arrays)', function test( t ) { + var actual; + var bsize; + var ord; + var sh; + var st; + var dt; + var sv; + 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, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + sv = scalar2ndarray( NaN, { + 'dtype': 'float64' + }); + + actual = find( [ x, sv ], clbk1 ); + t.strictEqual( actual, 35.0, 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.strictEqual( isSameValue( actual, NaN ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return v % 2.0 !== 0.0; + } + + function clbk2( v ) { + return v < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (column-major, contiguous, accessors)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + sv = scalar2ndarray( new Complex128( NaN, NaN ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk1 ); + t.deepEqual( actual, new Complex128( 2.0, 0.0 ), 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return real( v ) % 2.0 === 0.0; + } + + function clbk2( v ) { + return real( v ) < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (column-major, contiguous, negative strides, accessors)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = [ -1, -2, -2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, oneTo( numel( sh )*2, dt ), sh, st, o, ord ); + sv = scalar2ndarray( new Complex128( NaN, NaN ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk1 ); + t.deepEqual( actual, new Complex128( 4.0, 0.0 ), 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return real( v ) % 2.0 === 0.0; + } + + function clbk2( v ) { + return real( v ) < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, same sign strides, accessors)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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( 8*2, dt ), sh, st, o, ord ); + sv = scalar2ndarray( new Complex128( NaN, NaN ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk1 ); + t.deepEqual( actual, new Complex128( 1.0, 0.0 ), 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return real( v ) % 2.0 !== 0.0; + } + + function clbk2( v ) { + return real( v ) < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var sv; + 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( 8*2, dt ), sh, st, o, ord ); + sv = scalar2ndarray( new Complex128( NaN, NaN ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk1 ); + t.deepEqual( actual, new Complex128( 3.0, 0.0 ), 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return real( v ) % 2.0 !== 0.0; + } + + function clbk2( v ) { + return real( v ) < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var actual; + var bsize; + var ord; + var sh; + var st; + var dt; + var sv; + 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, oneTo( numel( sh )*4, dt ), sh, st, o, ord ); + sv = scalar2ndarray( new Complex128( NaN, NaN ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk1 ); + t.deepEqual( actual, new Complex128( 7.0, 0.0 ), 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return real( v ) % 2.0 !== 0.0; + } + + function clbk2( v ) { + return real( v ) < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var actual; + var bsize; + var ord; + var sh; + var st; + var dt; + var sv; + 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, oneTo( numel( sh )*4, dt ), sh, st, o, ord ); + sv = scalar2ndarray( new Complex128( NaN, NaN ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk1 ); + t.deepEqual( actual, new Complex128( 13.0, 0.0 ), 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return real( v ) % 2.0 !== 0.0; + } + + function clbk2( v ) { + return real( v ) < 0.0; + } +}); + +tape( 'the function returns the first element in a 3-dimensional ndarray which passes a test implemented by a predicate function (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var actual; + var bsize; + var ord; + var sh; + var st; + var dt; + var sv; + 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, oneTo( numel( sh )*4, dt ), sh, st, o, ord ); + sv = scalar2ndarray( new Complex128( NaN, NaN ), { + 'dtype': 'complex128' + }); + + actual = find( [ x, sv ], clbk1 ); + t.deepEqual( actual, new Complex128( 17.0, 0.0 ), 'returns expected value' ); + + actual = find( [ x, sv ], clbk2 ); + t.deepEqual( isSameValue( actual, new Complex128( NaN, NaN ) ), true, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return real( v ) % 2.0 !== 0.0; + } + + function clbk2( v ) { + return real( v ) < 0.0; + } +}); From 79eb09a3dbc6432ea350f6ab3ea546b3758883d8 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 25 Jun 2025 10:43:28 +0000 Subject: [PATCH 13/30] refactor: use as sentinel --- 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: na - 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: na - 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/find/README.md | 15 ++++++++------- .../find/benchmark/benchmark.1d_columnmajor.js | 12 ++++++------ .../base/find/benchmark/benchmark.1d_rowmajor.js | 12 ++++++------ .../benchmark/benchmark.2d_blocked_columnmajor.js | 12 ++++++------ .../benchmark/benchmark.2d_blocked_rowmajor.js | 12 ++++++------ .../find/benchmark/benchmark.2d_columnmajor.js | 12 ++++++------ .../base/find/benchmark/benchmark.2d_rowmajor.js | 12 ++++++------ .../benchmark/benchmark.2d_rowmajor_accessors.js | 12 ++++++------ .../benchmark/benchmark.3d_blocked_columnmajor.js | 12 ++++++------ .../benchmark/benchmark.3d_blocked_rowmajor.js | 12 ++++++------ .../find/benchmark/benchmark.3d_columnmajor.js | 12 ++++++------ .../base/find/benchmark/benchmark.3d_rowmajor.js | 12 ++++++------ .../@stdlib/ndarray/base/find/docs/repl.txt | 2 +- .../ndarray/base/find/docs/types/index.d.ts | 2 +- .../@stdlib/ndarray/base/find/docs/types/test.ts | 6 +++--- .../@stdlib/ndarray/base/find/examples/index.js | 11 ++++++----- .../@stdlib/ndarray/base/find/lib/0d.js | 2 +- .../@stdlib/ndarray/base/find/lib/0d_accessors.js | 2 +- .../@stdlib/ndarray/base/find/lib/1d.js | 2 +- .../@stdlib/ndarray/base/find/lib/1d_accessors.js | 2 +- .../@stdlib/ndarray/base/find/lib/2d.js | 2 +- .../@stdlib/ndarray/base/find/lib/2d_accessors.js | 2 +- .../@stdlib/ndarray/base/find/lib/2d_blocked.js | 2 +- .../ndarray/base/find/lib/2d_blocked_accessors.js | 2 +- .../@stdlib/ndarray/base/find/lib/3d.js | 2 +- .../@stdlib/ndarray/base/find/lib/3d_accessors.js | 2 +- .../@stdlib/ndarray/base/find/lib/3d_blocked.js | 2 +- .../ndarray/base/find/lib/3d_blocked_accessors.js | 2 +- .../@stdlib/ndarray/base/find/lib/index.js | 2 +- .../@stdlib/ndarray/base/find/lib/main.js | 2 +- .../@stdlib/ndarray/base/find/lib/nd.js | 2 +- .../@stdlib/ndarray/base/find/lib/nd_accessors.js | 2 +- 32 files changed, 101 insertions(+), 99 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/find/README.md b/lib/node_modules/@stdlib/ndarray/base/find/README.md index 89539f38e116..132b3e0babea 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/find/README.md @@ -68,7 +68,7 @@ var ox = 0; // Create the sentinel value ndarray-like object: var sentinelValue = { 'dtype': 'float64', - 'data': new Float64Array( [ -1.0 ] ), + 'data': new Float64Array( [ NaN ] ), 'shape': [], 'strides': [ 0 ], 'offset': 0, @@ -138,7 +138,7 @@ var ox = 0; // Create the sentinel value ndarray-like object: var sentinelValue = { 'dtype': 'float64', - 'data': new Float64Array( [ -1.0 ] ), + 'data': new Float64Array( [ NaN ] ), 'shape': [], 'strides': [ 0 ], 'offset': 0, @@ -189,6 +189,7 @@ var count = ctx.count; ```javascript var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Float64Array = require( '@stdlib/array/float64' ); var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); var find = require( '@stdlib/ndarray/base/find' ); @@ -197,9 +198,9 @@ function clbk( value ) { } var x = { - 'dtype': 'generic', - 'data': discreteUniform( 10, 0, 10, { - 'dtype': 'generic' + 'dtype': 'float64', + 'data': discreteUniform( 10, 0.0, 10.0, { + 'dtype': 'float64' }), 'shape': [ 5, 2 ], 'strides': [ 2, 1 ], @@ -209,8 +210,8 @@ var x = { console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); var sv = { - 'dtype': x.dtype, - 'data': [ -1 ], + 'dtype': 'float64', + 'data': new Float64Array( [ NaN ] ), 'shape': [], 'strides': [ 0 ], 'offset': 0, diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_columnmajor.js index bb49e979cea9..a19c28a700bc 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_columnmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_columnmajor.js @@ -23,7 +23,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); var pow = require( '@stdlib/math/base/special/pow' ); var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); @@ -73,7 +73,7 @@ function createBenchmark( len, shape, xtype ) { }; sv = { 'dtype': xtype, - 'data': [ -1.0 ], + 'data': [ NaN ], 'shape': [], 'strides': [ 0 ], 'offset': 0, @@ -94,13 +94,13 @@ function createBenchmark( len, shape, xtype ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { out = find( [ x, sv ], clbk ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); } } b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); } b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_rowmajor.js index f1f94bc425a4..60291be5ec2a 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_rowmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_rowmajor.js @@ -23,7 +23,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); var pow = require( '@stdlib/math/base/special/pow' ); var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); @@ -73,7 +73,7 @@ function createBenchmark( len, shape, xtype ) { }; sv = { 'dtype': xtype, - 'data': [ -1.0 ], + 'data': [ NaN ], 'shape': [], 'strides': [ 0 ], 'offset': 0, @@ -94,13 +94,13 @@ function createBenchmark( len, shape, xtype ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { out = find( [ x, sv ], clbk ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); } } b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); } b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_columnmajor.js index 3e4ee71aab0c..c3ec55813e6d 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_columnmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_columnmajor.js @@ -23,7 +23,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); var pow = require( '@stdlib/math/base/special/pow' ); var sqrt = require( '@stdlib/math/base/special/sqrt' ); var floor = require( '@stdlib/math/base/special/floor' ); @@ -86,14 +86,14 @@ function createBenchmark( len, shape, xtype ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = find( x, -1, clbk ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); } } b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); } b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_rowmajor.js index 87462510b266..2cdfde93ed37 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_rowmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_rowmajor.js @@ -23,7 +23,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); var pow = require( '@stdlib/math/base/special/pow' ); var sqrt = require( '@stdlib/math/base/special/sqrt' ); var floor = require( '@stdlib/math/base/special/floor' ); @@ -86,14 +86,14 @@ function createBenchmark( len, shape, xtype ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = find( x, -1, clbk ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); } } b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); } b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_columnmajor.js index 1c01b9db24c9..7a38d948d189 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_columnmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_columnmajor.js @@ -23,7 +23,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); var pow = require( '@stdlib/math/base/special/pow' ); var sqrt = require( '@stdlib/math/base/special/sqrt' ); var floor = require( '@stdlib/math/base/special/floor' ); @@ -86,14 +86,14 @@ function createBenchmark( len, shape, xtype ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = find( x, -1, clbk ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); } } b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); } b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor.js index 208bdd40362e..44a5847c6161 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor.js @@ -23,7 +23,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); var pow = require( '@stdlib/math/base/special/pow' ); var sqrt = require( '@stdlib/math/base/special/sqrt' ); var floor = require( '@stdlib/math/base/special/floor' ); @@ -86,14 +86,14 @@ function createBenchmark( len, shape, xtype ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = find( x, -1, clbk ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); } } b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); } b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor_accessors.js index b8fa675dbcc1..8bce9efca184 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor_accessors.js @@ -23,7 +23,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); var pow = require( '@stdlib/math/base/special/pow' ); var sqrt = require( '@stdlib/math/base/special/sqrt' ); var floor = require( '@stdlib/math/base/special/floor' ); @@ -112,14 +112,14 @@ function createBenchmark( len, shape, xtype ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = find( x, -1, clbk ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); } } b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); } b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_columnmajor.js index 4955cf8b4fb4..693c5e5d6d27 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_columnmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_columnmajor.js @@ -23,7 +23,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); var pow = require( '@stdlib/math/base/special/pow' ); var cbrt = require( '@stdlib/math/base/special/cbrt' ); var floor = require( '@stdlib/math/base/special/floor' ); @@ -86,14 +86,14 @@ function createBenchmark( len, shape, xtype ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = find( x, -1, clbk ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); } } b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); } b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_rowmajor.js index de0a916ddbe6..15cd576581e0 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_rowmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_rowmajor.js @@ -23,7 +23,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); var pow = require( '@stdlib/math/base/special/pow' ); var cbrt = require( '@stdlib/math/base/special/cbrt' ); var floor = require( '@stdlib/math/base/special/floor' ); @@ -86,14 +86,14 @@ function createBenchmark( len, shape, xtype ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = find( x, -1, clbk ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); } } b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); } b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_columnmajor.js index 241bb8c32b01..788e9a35ae16 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_columnmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_columnmajor.js @@ -23,7 +23,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); var pow = require( '@stdlib/math/base/special/pow' ); var cbrt = require( '@stdlib/math/base/special/cbrt' ); var floor = require( '@stdlib/math/base/special/floor' ); @@ -86,14 +86,14 @@ function createBenchmark( len, shape, xtype ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = find( x, -1, clbk ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); } } b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); } b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_rowmajor.js index ad2d374c65d1..f2298c74cacd 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_rowmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_rowmajor.js @@ -23,7 +23,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); var pow = require( '@stdlib/math/base/special/pow' ); var cbrt = require( '@stdlib/math/base/special/cbrt' ); var floor = require( '@stdlib/math/base/special/floor' ); @@ -86,14 +86,14 @@ function createBenchmark( len, shape, xtype ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = find( x, -1, clbk ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); } } b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); } b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/find/docs/repl.txt index 6e648581835f..80de3b4cdbd8 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/find/docs/repl.txt @@ -49,7 +49,7 @@ // Define a callback... > function clbk( v ) { return v % 2.0 === 0.0; }; - > var sv = {{alias:@stdlib/ndarray/from-scalar}}( -1.0, { 'dtype': dt } ); + > var sv = {{alias:@stdlib/ndarray/from-scalar}}( NaN, { 'dtype': 'float64' } ); > var x = {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); > {{alias}}( [ x, sv ], clbk ) 2.0 diff --git a/lib/node_modules/@stdlib/ndarray/base/find/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/find/docs/types/index.d.ts index 90a74a8da63b..acbd09cf9140 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/find/docs/types/index.d.ts @@ -100,7 +100,7 @@ type Predicate = Nullary | Unary | Binary | Ternary; * var x = ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' ); * * // Create a zero-dimensional ndarray containing a sentinel value: -* var sv = scalar2ndarray( -1.0, { +* var sv = scalar2ndarray( NaN, { * 'dtype': 'float64' * }); * diff --git a/lib/node_modules/@stdlib/ndarray/base/find/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/find/docs/types/test.ts index 47ca0c60900a..5aa20efc3ae6 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/base/find/docs/types/test.ts @@ -38,7 +38,7 @@ function clbk( v: any ): boolean { // The function returns a number... { const x = zeros( [ 2, 2 ] ); - const sv = scalar2ndarray( -1.0, { + const sv = scalar2ndarray( NaN, { 'dtype': 'float64' } ); const arrays = [ x, sv ]; @@ -71,7 +71,7 @@ function clbk( v: any ): boolean { // The compiler throws an error if the function is provided a second argument which is not a callback function... { const x = zeros( [ 2, 2 ] ); - const sv = scalar2ndarray( -1.0, { + const sv = scalar2ndarray( NaN, { 'dtype': 'float64' } ); const arrays = [ x, sv ]; @@ -98,7 +98,7 @@ function clbk( v: any ): boolean { // The compiler throws an error if the function is provided an unsupported number of arguments... { const x = zeros( [ 2, 2 ] ); - const sv = scalar2ndarray( -1.0, { + const sv = scalar2ndarray( NaN, { 'dtype': 'float64' } ); const arrays = [ x, sv ]; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/find/examples/index.js index 9462e8dd5bfb..39afad5a9dae 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/examples/index.js @@ -21,6 +21,7 @@ /* eslint-disable stdlib/no-redeclare */ var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Float64Array = require( '@stdlib/array/float64' ); var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); var find = require( './../lib' ); @@ -29,9 +30,9 @@ function clbk( value ) { } var x = { - 'dtype': 'generic', - 'data': discreteUniform( 10, 0, 10, { - 'dtype': 'generic' + 'dtype': 'float64', + 'data': discreteUniform( 10, 0.0, 10.0, { + 'dtype': 'float64' }), 'shape': [ 5, 2 ], 'strides': [ 2, 1 ], @@ -41,8 +42,8 @@ var x = { console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); var sv = { - 'dtype': x.dtype, - 'data': [ -1 ], + 'dtype': 'float64', + 'data': new Float64Array( [ NaN ] ), 'shape': [], 'strides': [ 0 ], 'offset': 0, diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/0d.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/0d.js index e59bbaf3d90e..df50c89e4282 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/0d.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/0d.js @@ -68,7 +68,7 @@ * }; * * // Test elements: -* var out = find0d( x, -1, predicate ); +* var out = find0d( x, NaN, predicate ); * // returns 2.0 */ function find0d( x, sentinelValue, predicate, thisArg ) { diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/0d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/0d_accessors.js index 2a947062bb6f..fd38521cbc70 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/0d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/0d_accessors.js @@ -71,7 +71,7 @@ * }; * * // Test elements: -* var out = find0d( x, -1, predicate ); +* var out = find0d( x, NaN, predicate ); * // returns 2.0 */ function find0d( x, sentinelValue, predicate, thisArg ) { diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/1d.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/1d.js index e8993887a9ee..12e85d97d375 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/1d.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/1d.js @@ -68,7 +68,7 @@ * }; * * // Test elements: -* var out = find1d( x, -1, predicate ); +* var out = find1d( x, NaN, predicate ); * // returns 2.0 */ function find1d( x, sentinelValue, predicate, thisArg ) { diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/1d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/1d_accessors.js index a8c73424f37b..560c6336f088 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/1d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/1d_accessors.js @@ -71,7 +71,7 @@ * }; * * // Test elements: -* var out = find1d( x, -1, predicate ); +* var out = find1d( x, NaN, predicate ); * // returns 2.0 */ function find1d( x, sentinelValue, predicate, thisArg ) { diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/2d.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d.js index 9be4a19ad103..a1232ca59a93 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/2d.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d.js @@ -76,7 +76,7 @@ var take = require( '@stdlib/array/base/take-indexed' ); * }; * * // Test elements: -* var out = find2d( x, -1, predicate ); +* var out = find2d( x, NaN, predicate ); * // returns 2.0 */ function find2d( x, sentinelValue, predicate, thisArg ) { diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_accessors.js index b6331268b5c3..42065c7e476f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_accessors.js @@ -79,7 +79,7 @@ var take = require( '@stdlib/array/base/take-indexed' ); * }; * * // Test elements: -* var out = find2d( x, -1, predicate ); +* var out = find2d( x, NaN, predicate ); * // returns 2.0 */ function find2d( x, sentinelValue, predicate, thisArg ) { diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked.js index b093cbd67ada..56210cb88842 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked.js @@ -76,7 +76,7 @@ var reverse = require( '@stdlib/array/base/reverse' ); * }; * * // Test elements: -* var out = blockedfind2d( x, -1, predicate ); +* var out = blockedfind2d( x, NaN, predicate ); * // returns 2.0 */ function blockedfind2d( x, sentinelValue, predicate, thisArg ) { diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked_accessors.js index f8a15643a432..51147434aa7d 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked_accessors.js @@ -79,7 +79,7 @@ var reverse = require( '@stdlib/array/base/reverse' ); * }; * * // Test elements: -* var out = blockedfind2d( x, -1, predicate ); +* var out = blockedfind2d( x, NaN, predicate ); * // returns 2.0 */ function blockedfind2d( x, sentinelValue, predicate, thisArg ) { diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d.js index 1dc52398db9f..ca3f53aaeb93 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d.js @@ -76,7 +76,7 @@ var take = require( '@stdlib/array/base/take-indexed' ); * }; * * // Test elements: -* var out = find3d( x,-1, predicate ); +* var out = find3d( x, NaN, predicate ); * // returns 2.0 */ function find3d( x, sentinelValue, predicate, thisArg ) { diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_accessors.js index 660372e38349..dd7ae0399fb2 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_accessors.js @@ -79,7 +79,7 @@ var take = require( '@stdlib/array/base/take-indexed' ); * }; * * // Test elements: -* var out = find3d( x, -1, predicate ); +* var out = find3d( x, NaN, predicate ); * // returns 2.0 */ function find3d( x, sentinelValue, predicate, thisArg ) { diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked.js index 485ee2d41999..66e72dd5146a 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked.js @@ -78,7 +78,7 @@ var reverse = require( '@stdlib/array/base/reverse' ); * }; * * // Test elements: -* var out = blockedfind3d( x, -1, predicate ); +* var out = blockedfind3d( x, NaN, predicate ); * // returns 2.0 */ function blockedfind3d( x, sentinelValue, predicate, thisArg ) { diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked_accessors.js index 5eb56aa37b0d..78b2b14072b1 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked_accessors.js @@ -81,7 +81,7 @@ var reverse = require( '@stdlib/array/base/reverse' ); * }; * * // Test elements: -* var out = blockedfind3d( x, -1, predicate ); +* var out = blockedfind3d( x, NaN, predicate ); * // returns 2.0 */ function blockedfind3d( x, sentinelValue, predicate, thisArg ) { diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/index.js index 6df7ec553b85..23e8587dbfe5 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/index.js @@ -56,7 +56,7 @@ * // Create the sentinel value ndarray-like object: * var sentinelValue = { * 'dtype': 'float64', -* 'data': new Float64Array( [ -1.0 ] ), +* 'data': new Float64Array( [ NaN ] ), * 'shape': [], * 'strides': [ 0 ], * 'offset': 0, diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/main.js index b7069b7b5dfd..b4316f888c7d 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/main.js @@ -119,7 +119,7 @@ var MAX_DIMS = FIND.length - 1; * // Create the sentinel value ndarray-like object: * var sentinelValue = { * 'dtype': 'float64', -* 'data': new Float64Array( [ -1.0 ] ), +* 'data': new Float64Array( [ NaN ] ), * 'shape': [], * 'strides': [ 0 ], * 'offset': 0, diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/nd.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/nd.js index 6ad809fac05f..f09c5c7c9a34 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/nd.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/nd.js @@ -80,7 +80,7 @@ var MODE = 'throw'; * }; * * // Test elements: -* var out = findnd( x, -1, predicate ); +* var out = findnd( x, NaN, predicate ); * // returns 2.0 */ function findnd( x, sentinelValue, predicate, thisArg ) { diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/nd_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/nd_accessors.js index 8ff579ef6ef0..01b5d32cb33a 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/nd_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/nd_accessors.js @@ -83,7 +83,7 @@ var MODE = 'throw'; * }; * * // Test elements: -* var out = findnd( x, -1, predicate ); +* var out = findnd( x, NaN, predicate ); * // returns 2.0 */ function findnd( x, sentinelValue, predicate, thisArg ) { From c62bd4d2239fc035cad5d225e525dbad813659d0 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 2 Jul 2025 04:16:42 +0000 Subject: [PATCH 14/30] docs: apply code review suggestions --- 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: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/base/find/README.md | 58 +++++++++---------- .../@stdlib/ndarray/base/find/package.json | 2 +- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/find/README.md b/lib/node_modules/@stdlib/ndarray/base/find/README.md index 132b3e0babea..ccdeb0328742 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/find/README.md @@ -20,7 +20,7 @@ limitations under the License. # find -> Return the first element in an ndarray which pass a test implemented by a predicate function. +> Return the first element in an ndarray which passes a test implemented by a predicate function.
@@ -42,14 +42,14 @@ var find = require( '@stdlib/ndarray/base/find' ); #### find( arrays, predicate\[, thisArg] ) -Returns the first element in an ndarray which pass a test implemented by a predicate function. +Returns the first element in an ndarray which passes a test implemented by a predicate function. ```javascript var Float64Array = require( '@stdlib/array/float64' ); -function clbk( value ) { +function isEven( value ) { return value % 2.0 === 0.0; } @@ -65,16 +65,6 @@ var sx = [ 4, 4, 1 ]; // Define the index offset: var ox = 0; -// Create the sentinel value ndarray-like object: -var sentinelValue = { - 'dtype': 'float64', - 'data': new Float64Array( [ NaN ] ), - 'shape': [], - 'strides': [ 0 ], - 'offset': 0, - 'order': 'row-major' -}; - // Create the input ndarray-like object: var x = { 'dtype': 'float64', @@ -85,14 +75,24 @@ var x = { 'order': 'row-major' }; +// Create the sentinel value ndarray-like object: +var sentinelValue = { + 'dtype': 'float64', + 'data': new Float64Array( [ NaN ] ), + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': 'row-major' +}; + // Perform reduction: -var out = find( [ x, sentinelValue ], clbk ); +var out = find( [ x, sentinelValue ], isEven ); // returns 2.0 ``` The function accepts the following arguments: -- **arrays**: array-like object containing an input ndarray and a zero-dimensional sentinel value ndarray. +- **arrays**: array-like object containing an input ndarray and a zero-dimensional ndarray containing a sentinel value which should be returned when no element in an input ndarray passes a test implemented by the predicate function. - **predicate**: predicate function. - **thisArg**: predicate function execution context (_optional_). @@ -118,7 +118,7 @@ To set the predicate function execution context, provide a `thisArg`. ```javascript var Float64Array = require( '@stdlib/array/float64' ); -function clbk( value ) { +function isEven( value ) { this.count += 1; return value % 2.0 === 0.0; } @@ -135,16 +135,6 @@ var sx = [ 4, 4, 1 ]; // Define the index offset: var ox = 0; -// Create the sentinel value ndarray-like object: -var sentinelValue = { - 'dtype': 'float64', - 'data': new Float64Array( [ NaN ] ), - 'shape': [], - 'strides': [ 0 ], - 'offset': 0, - 'order': 'row-major' -}; - // Create the input ndarray-like object: var x = { 'dtype': 'float64', @@ -155,12 +145,22 @@ var x = { 'order': 'row-major' }; +// Create the sentinel value ndarray-like object: +var sentinelValue = { + 'dtype': 'float64', + 'data': new Float64Array( [ NaN ] ), + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': 'row-major' +}; + var ctx = { 'count': 0 }; // Test elements: -var out = find( [ x, sentinelValue ], clbk, ctx ); +var out = find( [ x, sentinelValue ], isEven, ctx ); // returns 2.0 var count = ctx.count; @@ -193,7 +193,7 @@ var Float64Array = require( '@stdlib/array/float64' ); var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); var find = require( '@stdlib/ndarray/base/find' ); -function clbk( value ) { +function isEven( value ) { return value % 2.0 === 0.0; } @@ -219,7 +219,7 @@ var sv = { }; console.log( 'Sentinel Value: %d', sv.data[ 0 ] ); -var out = find( [ x, sv ], clbk ); +var out = find( [ x, sv ], isEven ); console.log( out ); ``` diff --git a/lib/node_modules/@stdlib/ndarray/base/find/package.json b/lib/node_modules/@stdlib/ndarray/base/find/package.json index 168f640c4d0d..d32a3ffbd30c 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/package.json +++ b/lib/node_modules/@stdlib/ndarray/base/find/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/ndarray/base/find", "version": "0.0.0", - "description": "Return the first element in an ndarray which pass a test implemented by a predicate function.", + "description": "Return the first element in an ndarray which passes a test implemented by a predicate function.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", From 5dc4859cee4ffc2208b8d8072a74dbefc4b6555a Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 2 Jul 2025 04:28:42 +0000 Subject: [PATCH 15/30] bench: apply suggestions from code review --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../base/find/benchmark/benchmark.1d_columnmajor.js | 7 +++++-- .../ndarray/base/find/benchmark/benchmark.1d_rowmajor.js | 7 +++++-- .../find/benchmark/benchmark.2d_blocked_columnmajor.js | 4 +++- .../base/find/benchmark/benchmark.2d_blocked_rowmajor.js | 4 +++- .../base/find/benchmark/benchmark.2d_columnmajor.js | 4 +++- .../ndarray/base/find/benchmark/benchmark.2d_rowmajor.js | 4 +++- .../base/find/benchmark/benchmark.2d_rowmajor_accessors.js | 4 +++- .../find/benchmark/benchmark.3d_blocked_columnmajor.js | 4 +++- .../base/find/benchmark/benchmark.3d_blocked_rowmajor.js | 4 +++- .../base/find/benchmark/benchmark.3d_columnmajor.js | 4 +++- .../ndarray/base/find/benchmark/benchmark.3d_rowmajor.js | 4 +++- 11 files changed, 37 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_columnmajor.js index a19c28a700bc..9370a94a26a5 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_columnmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_columnmajor.js @@ -27,6 +27,7 @@ var isInteger = require( '@stdlib/math/base/assert/is-integer' ); var pow = require( '@stdlib/math/base/special/pow' ); var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var filledarray = require( '@stdlib/array/filled' ); var pkg = require( './../package.json' ).name; var find = require( './../lib' ); @@ -62,7 +63,9 @@ function createBenchmark( len, shape, xtype ) { var sv; var x; - x = discreteUniform( len, 1, 100 ); + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); x = { 'dtype': xtype, 'data': x, @@ -73,7 +76,7 @@ function createBenchmark( len, shape, xtype ) { }; sv = { 'dtype': xtype, - 'data': [ NaN ], + 'data': filledarray( NaN, 1, xtype ), 'shape': [], 'strides': [ 0 ], 'offset': 0, diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_rowmajor.js index 60291be5ec2a..5ce17d8e2b0e 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_rowmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.1d_rowmajor.js @@ -27,6 +27,7 @@ var isInteger = require( '@stdlib/math/base/assert/is-integer' ); var pow = require( '@stdlib/math/base/special/pow' ); var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var filledarray = require( '@stdlib/array/filled' ); var pkg = require( './../package.json' ).name; var find = require( './../lib' ); @@ -62,7 +63,9 @@ function createBenchmark( len, shape, xtype ) { var sv; var x; - x = discreteUniform( len, 1, 100 ); + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); x = { 'dtype': xtype, 'data': x, @@ -73,7 +76,7 @@ function createBenchmark( len, shape, xtype ) { }; sv = { 'dtype': xtype, - 'data': [ NaN ], + 'data': filledarray( NaN, 1, xtype ), 'shape': [], 'strides': [ 0 ], 'offset': 0, diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_columnmajor.js index c3ec55813e6d..c2fd62320688 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_columnmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_columnmajor.js @@ -63,7 +63,9 @@ function clbk( value ) { function createBenchmark( len, shape, xtype ) { var x; - x = discreteUniform( len, 1, 100 ); + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); x = { 'dtype': xtype, 'data': x, diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_rowmajor.js index 2cdfde93ed37..c916682df589 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_rowmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_blocked_rowmajor.js @@ -63,7 +63,9 @@ function clbk( value ) { function createBenchmark( len, shape, xtype ) { var x; - x = discreteUniform( len, 1, 100 ); + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); x = { 'dtype': xtype, 'data': x, diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_columnmajor.js index 7a38d948d189..e8a364dde701 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_columnmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_columnmajor.js @@ -63,7 +63,9 @@ function clbk( value ) { function createBenchmark( len, shape, xtype ) { var x; - x = discreteUniform( len, 1, 100 ); + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); x = { 'dtype': xtype, 'data': x, diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor.js index 44a5847c6161..c762b487bb2b 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor.js @@ -63,7 +63,9 @@ function clbk( value ) { function createBenchmark( len, shape, xtype ) { var x; - x = discreteUniform( len, 1, 100 ); + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); x = { 'dtype': xtype, 'data': x, diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor_accessors.js index 8bce9efca184..4a45b9a1546f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.2d_rowmajor_accessors.js @@ -87,7 +87,9 @@ function set( buf, idx, value ) { function createBenchmark( len, shape, xtype ) { var x; - x = discreteUniform( len, 1, 100 ); + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); x = { 'dtype': xtype, 'data': x, diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_columnmajor.js index 693c5e5d6d27..cadd2d088398 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_columnmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_columnmajor.js @@ -63,7 +63,9 @@ function clbk( value ) { function createBenchmark( len, shape, xtype ) { var x; - x = discreteUniform( len, 1, 100 ); + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); x = { 'dtype': xtype, 'data': x, diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_rowmajor.js index 15cd576581e0..7921da841e64 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_rowmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_blocked_rowmajor.js @@ -63,7 +63,9 @@ function clbk( value ) { function createBenchmark( len, shape, xtype ) { var x; - x = discreteUniform( len, 1, 100 ); + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); x = { 'dtype': xtype, 'data': x, diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_columnmajor.js index 788e9a35ae16..152d4b9db19c 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_columnmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_columnmajor.js @@ -63,7 +63,9 @@ function clbk( value ) { function createBenchmark( len, shape, xtype ) { var x; - x = discreteUniform( len, 1, 100 ); + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); x = { 'dtype': xtype, 'data': x, diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_rowmajor.js index f2298c74cacd..7a757f22ecc8 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_rowmajor.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.3d_rowmajor.js @@ -63,7 +63,9 @@ function clbk( value ) { function createBenchmark( len, shape, xtype ) { var x; - x = discreteUniform( len, 1, 100 ); + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); x = { 'dtype': xtype, 'data': x, From 6c4416bea548fda5c768ae432d6b7b0c1780cfa2 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 2 Jul 2025 04:44:54 +0000 Subject: [PATCH 16/30] refactor: apply suggestions from code review --- 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: na - task: lint_package_json status: na - 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: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/base/find/docs/repl.txt | 14 ++++++++------ .../ndarray/base/find/docs/types/index.d.ts | 2 +- .../@stdlib/ndarray/base/find/examples/index.js | 4 ++-- .../@stdlib/ndarray/base/find/lib/0d.js | 2 +- .../@stdlib/ndarray/base/find/lib/0d_accessors.js | 2 +- .../@stdlib/ndarray/base/find/lib/1d.js | 2 +- .../@stdlib/ndarray/base/find/lib/1d_accessors.js | 2 +- .../@stdlib/ndarray/base/find/lib/2d.js | 2 +- .../@stdlib/ndarray/base/find/lib/2d_accessors.js | 2 +- .../@stdlib/ndarray/base/find/lib/2d_blocked.js | 2 +- .../ndarray/base/find/lib/2d_blocked_accessors.js | 2 +- .../@stdlib/ndarray/base/find/lib/3d.js | 2 +- .../@stdlib/ndarray/base/find/lib/3d_accessors.js | 2 +- .../@stdlib/ndarray/base/find/lib/3d_blocked.js | 2 +- .../ndarray/base/find/lib/3d_blocked_accessors.js | 2 +- .../@stdlib/ndarray/base/find/lib/index.js | 2 +- .../@stdlib/ndarray/base/find/lib/main.js | 2 +- .../@stdlib/ndarray/base/find/lib/nd.js | 2 +- .../@stdlib/ndarray/base/find/lib/nd_accessors.js | 2 +- 19 files changed, 27 insertions(+), 25 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/find/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/find/docs/repl.txt index 80de3b4cdbd8..d42560711d34 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/find/docs/repl.txt @@ -1,6 +1,6 @@ {{alias}}( arrays, predicate[, thisArg] ) - Returns the first element in an ndarray which pass a test implemented by a + Returns the first element in an ndarray which passes a test implemented by a predicate function. A provided "ndarray" should be an `object` with the following properties: @@ -23,7 +23,9 @@ ---------- arrays: ArrayLikeObject Array-like object containing an input ndarray and a zero-dimensional - array containing the sentinel value. + ndarray containing a sentinel value which should be returned when no + element in an input ndarray passes a test implemented by the predicate + function. predicate: Function Predicate function. @@ -38,6 +40,9 @@ Examples -------- + // Define a callback... + > function clbk( v ) { return v % 2.0 === 0.0; }; + // Define ndarray data and meta data... > var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); > var dt = 'float64'; @@ -46,11 +51,8 @@ > var ox = 0; > var ord = 'row-major'; - // Define a callback... - > function clbk( v ) { return v % 2.0 === 0.0; }; - - > var sv = {{alias:@stdlib/ndarray/from-scalar}}( NaN, { 'dtype': 'float64' } ); > var x = {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); + > var sv = {{alias:@stdlib/ndarray/from-scalar}}( NaN, { 'dtype': 'float64' } ); > {{alias}}( [ x, sv ], clbk ) 2.0 diff --git a/lib/node_modules/@stdlib/ndarray/base/find/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/find/docs/types/index.d.ts index acbd09cf9140..2f58f842b8da 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/find/docs/types/index.d.ts @@ -68,7 +68,7 @@ type Ternary = ( this: U, value: T, indices: Array, arr: typedndar type Predicate = Nullary | Unary | Binary | Ternary; /** -* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* Returns the first element in an ndarray which passes a test implemented by a predicate function. * * @param arrays - array-like object containing one input ndarray and a zero-dimensional sentinel value ndarray * @param predicate - predicate function diff --git a/lib/node_modules/@stdlib/ndarray/base/find/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/find/examples/index.js index 39afad5a9dae..ca4ccc10201f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/examples/index.js @@ -25,7 +25,7 @@ var Float64Array = require( '@stdlib/array/float64' ); var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); var find = require( './../lib' ); -function clbk( value ) { +function isEven( value ) { return value % 2.0 === 0.0; } @@ -51,5 +51,5 @@ var sv = { }; console.log( 'Sentinel Value: %d', sv.data[ 0 ] ); -var out = find( [ x, sv ], clbk ); +var out = find( [ x, sv ], isEven ); console.log( out ); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/0d.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/0d.js index df50c89e4282..30ccd13893c7 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/0d.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/0d.js @@ -21,7 +21,7 @@ // MAIN // /** -* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* Returns the first element in an ndarray which passes a test implemented by a predicate function. * * @private * @param {Object} x - object containing ndarray meta data diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/0d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/0d_accessors.js index fd38521cbc70..e7a1546364fa 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/0d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/0d_accessors.js @@ -21,7 +21,7 @@ // MAIN // /** -* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* Returns the first element in an ndarray which passes a test implemented by a predicate function. * * @private * @param {Object} x - object containing ndarray meta data diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/1d.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/1d.js index 12e85d97d375..7a9ddff579db 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/1d.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/1d.js @@ -21,7 +21,7 @@ // MAIN // /** -* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* Returns the first element in an ndarray which passes a test implemented by a predicate function. * * @private * @param {Object} x - object containing ndarray meta data diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/1d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/1d_accessors.js index 560c6336f088..39687ecc83d8 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/1d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/1d_accessors.js @@ -21,7 +21,7 @@ // MAIN // /** -* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* Returns the first element in an ndarray which passes a test implemented by a predicate function. * * @private * @param {Object} x - object containing ndarray meta data diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/2d.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d.js index a1232ca59a93..c017cc3107a1 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/2d.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d.js @@ -29,7 +29,7 @@ var take = require( '@stdlib/array/base/take-indexed' ); // MAIN // /** -* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* Returns the first element in an ndarray which passes a test implemented by a predicate function. * * @private * @param {Object} x - object containing ndarray meta data diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_accessors.js index 42065c7e476f..91180cfacade 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_accessors.js @@ -29,7 +29,7 @@ var take = require( '@stdlib/array/base/take-indexed' ); // MAIN // /** -* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* Returns the first element in an ndarray which passes a test implemented by a predicate function. * * @private * @param {Object} x - object containing ndarray meta data diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked.js index 56210cb88842..e92eb1c0af78 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked.js @@ -29,7 +29,7 @@ var reverse = require( '@stdlib/array/base/reverse' ); // MAIN // /** -* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* Returns the first element in an ndarray which passes a test implemented by a predicate function. * * @private * @param {Object} x - object containing ndarray meta data diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked_accessors.js index 51147434aa7d..795d492696d9 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked_accessors.js @@ -29,7 +29,7 @@ var reverse = require( '@stdlib/array/base/reverse' ); // MAIN // /** -* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* Returns the first element in an ndarray which passes a test implemented by a predicate function. * * @private * @param {Object} x - object containing ndarray meta data diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d.js index ca3f53aaeb93..2d2c3b32de82 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d.js @@ -29,7 +29,7 @@ var take = require( '@stdlib/array/base/take-indexed' ); // MAIN // /** -* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* Returns the first element in an ndarray which passes a test implemented by a predicate function. * * @private * @param {Object} x - object containing ndarray meta data diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_accessors.js index dd7ae0399fb2..f69b8c649762 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_accessors.js @@ -29,7 +29,7 @@ var take = require( '@stdlib/array/base/take-indexed' ); // MAIN // /** -* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* Returns the first element in an ndarray which passes a test implemented by a predicate function. * * @private * @param {Object} x - object containing ndarray meta data diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked.js index 66e72dd5146a..0888c11ab0e5 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked.js @@ -31,7 +31,7 @@ var reverse = require( '@stdlib/array/base/reverse' ); // MAIN // /** -* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* Returns the first element in an ndarray which passes a test implemented by a predicate function. * * @private * @param {Object} x - object containing ndarray meta data diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked_accessors.js index 78b2b14072b1..3df5bb4bc8a9 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked_accessors.js @@ -31,7 +31,7 @@ var reverse = require( '@stdlib/array/base/reverse' ); // MAIN // /** -* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* Returns the first element in an ndarray which passes a test implemented by a predicate function. * * @private * @param {Object} x - object containing ndarray meta data diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/index.js index 23e8587dbfe5..ce5ff4246f4d 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Return the first element in an ndarray which pass a test implemented by a predicate function. +* Return the first element in an ndarray which passes a test implemented by a predicate function. * * @module @stdlib/ndarray/base/find * diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/main.js index b4316f888c7d..3ca596fc2092 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/main.js @@ -69,7 +69,7 @@ var MAX_DIMS = FIND.length - 1; // MAIN // /** -* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* Returns the first element in an ndarray which passes a test implemented by a predicate function. * * ## Notes * diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/nd.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/nd.js index f09c5c7c9a34..b9a37e391f40 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/nd.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/nd.js @@ -33,7 +33,7 @@ var MODE = 'throw'; // MAIN // /** -* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* Returns the first element in an ndarray which passes a test implemented by a predicate function. * * @private * @param {Object} x - object containing ndarray meta data diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/nd_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/nd_accessors.js index 01b5d32cb33a..80308880e9ee 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/nd_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/nd_accessors.js @@ -33,7 +33,7 @@ var MODE = 'throw'; // MAIN // /** -* Returns the first element in an ndarray which pass a test implemented by a predicate function. +* Returns the first element in an ndarray which passes a test implemented by a predicate function. * * @private * @param {Object} x - object containing ndarray meta data From 4768153e654e5ea506916369edcbd8ffe6643c28 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 2 Jul 2025 05:29:56 +0000 Subject: [PATCH 17/30] feat: add 4d kernels --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../ndarray/base/find/lib/2d_blocked.js | 2 +- .../base/find/lib/2d_blocked_accessors.js | 2 +- .../@stdlib/ndarray/base/find/lib/3d.js | 2 +- .../ndarray/base/find/lib/3d_blocked.js | 2 +- .../base/find/lib/3d_blocked_accessors.js | 2 +- .../@stdlib/ndarray/base/find/lib/4d.js | 157 +++++++++++++ .../ndarray/base/find/lib/4d_accessors.js | 164 ++++++++++++++ .../ndarray/base/find/lib/4d_blocked.js | 203 +++++++++++++++++ .../base/find/lib/4d_blocked_accessors.js | 210 ++++++++++++++++++ 9 files changed, 739 insertions(+), 5 deletions(-) create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/4d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/4d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/4d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/4d_blocked_accessors.js diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked.js index e92eb1c0af78..5a5b0da6d61d 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked.js @@ -29,7 +29,7 @@ var reverse = require( '@stdlib/array/base/reverse' ); // MAIN // /** -* Returns the first element in an ndarray which passes a test implemented by a predicate function. +* Returns the first element in an ndarray which passes a test implemented by a predicate function via loop blocking. * * @private * @param {Object} x - object containing ndarray meta data diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked_accessors.js index 795d492696d9..536e20027a94 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/2d_blocked_accessors.js @@ -29,7 +29,7 @@ var reverse = require( '@stdlib/array/base/reverse' ); // MAIN // /** -* Returns the first element in an ndarray which passes a test implemented by a predicate function. +* Returns the first element in an ndarray which passes a test implemented by a predicate function via loop blocking. * * @private * @param {Object} x - object containing ndarray meta data diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d.js index 2d2c3b32de82..fd5b789563f5 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d.js @@ -76,7 +76,7 @@ var take = require( '@stdlib/array/base/take-indexed' ); * }; * * // Test elements: -* var out = find3d( x, NaN, predicate ); +* var out = find3d( x, NaN, predicate ); * // returns 2.0 */ function find3d( x, sentinelValue, predicate, thisArg ) { diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked.js index 0888c11ab0e5..2f008279025f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked.js @@ -31,7 +31,7 @@ var reverse = require( '@stdlib/array/base/reverse' ); // MAIN // /** -* Returns the first element in an ndarray which passes a test implemented by a predicate function. +* Returns the first element in an ndarray which passes a test implemented by a predicate function via loop blocking. * * @private * @param {Object} x - object containing ndarray meta data diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked_accessors.js index 3df5bb4bc8a9..b936f7961df2 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked_accessors.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/3d_blocked_accessors.js @@ -31,7 +31,7 @@ var reverse = require( '@stdlib/array/base/reverse' ); // MAIN // /** -* Returns the first element in an ndarray which passes a test implemented by a predicate function. +* Returns the first element in an ndarray which passes a test implemented by a predicate function via loop blocking. * * @private * @param {Object} x - object containing ndarray meta data diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/4d.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/4d.js new file mode 100644 index 000000000000..b64aa03da87a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/4d.js @@ -0,0 +1,157 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* // Define the shape of the input 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 the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Test elements: +* var out = find4d( x, NaN, predicate ); +* // returns 2.0 +*/ +function find4d( x, sentinelValue, predicate, thisArg ) { + var xbuf; + var idx; + var dx0; + var dx1; + var dx2; + var dx3; + var sh; + var S0; + var S1; + var S2; + var S3; + var sx; + var ix; + var i0; + var i1; + var i2; + var i3; + + // Note on variable naming convention: S#, dx#, 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++ ) { + if ( predicate.call( thisArg, xbuf[ ix ], take( [ i3, i2, i1, i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return xbuf[ ix ]; + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = find4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/4d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/4d_accessors.js new file mode 100644 index 000000000000..b09ba4c5fb0b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/4d_accessors.js @@ -0,0 +1,164 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Test elements: +* var out = find4d( x, NaN, predicate ); +* // returns 2.0 +*/ +function find4d( x, sentinelValue, predicate, thisArg ) { + var xbuf; + var idx; + var get; + var dx0; + var dx1; + var dx2; + var dx3; + var sh; + var S0; + var S1; + var S2; + var S3; + var sx; + var ix; + var i0; + var i1; + var i2; + var i3; + + // Note on variable naming convention: S#, dx#, 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++ ) { + if ( predicate.call( thisArg, get( xbuf, ix ), take( [ i3, i2, i1, i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return get( xbuf, ix ); + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = find4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/4d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/4d_blocked.js new file mode 100644 index 000000000000..a05d822891b4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/4d_blocked.js @@ -0,0 +1,203 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* // Define the shape of the input 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 the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Test elements: +* var out = blockedfind4d( x, NaN, predicate ); +* // returns 2.0 +*/ +function blockedfind4d( x, sentinelValue, predicate, thisArg ) { + var bsize; + var xbuf; + var idx; + var dx0; + var dx1; + var dx2; + var dx3; + var ox1; + var ox2; + var ox3; + 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; + + // Note on variable naming convention: s#, dx#, 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++ ) { + if ( predicate.call( thisArg, xbuf[ ix ], take( [ j3+i3, j2+i2, j1+i1, j0+i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return xbuf[ ix ]; + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + } + } + } + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = blockedfind4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/4d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/4d_blocked_accessors.js new file mode 100644 index 000000000000..e6735fea3f92 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/4d_blocked_accessors.js @@ -0,0 +1,210 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Test elements: +* var out = blockedfind4d( x, NaN, predicate ); +* // returns 2.0 +*/ +function blockedfind4d( x, sentinelValue, predicate, thisArg ) { + var bsize; + var xbuf; + var idx; + var get; + var dx0; + var dx1; + var dx2; + var dx3; + var ox1; + var ox2; + var ox3; + 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; + + // Note on variable naming convention: s#, dx#, 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++ ) { + if ( predicate.call( thisArg, get( xbuf, ix ), take( [ j3+i3, j2+i2, j1+i1, j0+i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return get( xbuf, ix ); + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + } + } + } + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = blockedfind4d; From f2ee3dc20d224b063844aa47ff8b84dd6ddc1981 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 2 Jul 2025 05:53:58 +0000 Subject: [PATCH 18/30] feat: add 5d kernels --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/base/find/lib/5d.js | 169 +++++++++++++ .../ndarray/base/find/lib/5d_accessors.js | 176 ++++++++++++++ .../ndarray/base/find/lib/5d_blocked.js | 222 +++++++++++++++++ .../base/find/lib/5d_blocked_accessors.js | 229 ++++++++++++++++++ 4 files changed, 796 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/5d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/5d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/5d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/5d_blocked_accessors.js diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/5d.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/5d.js new file mode 100644 index 000000000000..14090ee09f39 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/5d.js @@ -0,0 +1,169 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* // Define the shape of the input 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 the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Test elements: +* var out = find5d( x, NaN, predicate ); +* // returns 2.0 +*/ +function find5d( x, sentinelValue, predicate, thisArg ) { + var xbuf; + var idx; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + 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; + + // Note on variable naming convention: S#, dx#, 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++ ) { + if ( predicate.call( thisArg, xbuf[ ix ], take( [ i4, i3, i2, i1, i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return xbuf[ ix ]; + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = find5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/5d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/5d_accessors.js new file mode 100644 index 000000000000..4e475e2ef128 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/5d_accessors.js @@ -0,0 +1,176 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 1, 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 8, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Test elements: +* var out = find5d( x, NaN, predicate ); +* // returns 2.0 +*/ +function find5d( x, sentinelValue, predicate, thisArg ) { + var xbuf; + var idx; + var get; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + 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; + + // Note on variable naming convention: S#, dx#, 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++ ) { + if ( predicate.call( thisArg, get( xbuf, ix ), take( [ i4, i3, i2, i1, i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return get( xbuf, ix ); + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = find5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/5d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/5d_blocked.js new file mode 100644 index 000000000000..dc5fbc622e14 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/5d_blocked.js @@ -0,0 +1,222 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* // Define the shape of the input 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 the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Test elements: +* var out = blockedfind5d( x, NaN, predicate ); +* // returns 2.0 +*/ +function blockedfind5d( x, sentinelValue, predicate, thisArg ) { + var bsize; + var xbuf; + var idx; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var ox1; + var ox2; + var ox3; + var ox4; + 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; + + // Note on variable naming convention: s#, dx#, 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++ ) { + if ( predicate.call( thisArg, xbuf[ ix ], take( [ j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return xbuf[ ix ]; + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + } + } + } + } + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = blockedfind5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/5d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/5d_blocked_accessors.js new file mode 100644 index 000000000000..c73d158f22f7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/5d_blocked_accessors.js @@ -0,0 +1,229 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 1, 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 8, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Test elements: +* var out = blockedfind5d( x, NaN, predicate ); +* // returns 2.0 +*/ +function blockedfind5d( x, sentinelValue, predicate, thisArg ) { + var bsize; + var xbuf; + var idx; + var get; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var ox1; + var ox2; + var ox3; + var ox4; + 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; + + // Note on variable naming convention: s#, dx#, 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++ ) { + if ( predicate.call( thisArg, get( xbuf, ix ), take( [ j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return get( xbuf, ix ); + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + } + } + } + } + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = blockedfind5d; From f75fe1b4f4afc5d1de2205f4e49449c29409cd4d Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 2 Jul 2025 06:19:14 +0000 Subject: [PATCH 19/30] feat: add 6d kernels --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/base/find/lib/6d.js | 179 +++++++++++++ .../ndarray/base/find/lib/6d_accessors.js | 186 +++++++++++++ .../ndarray/base/find/lib/6d_blocked.js | 241 +++++++++++++++++ .../base/find/lib/6d_blocked_accessors.js | 248 ++++++++++++++++++ 4 files changed, 854 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/6d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/6d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/6d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/6d_blocked_accessors.js diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/6d.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/6d.js new file mode 100644 index 000000000000..db8f09a1f4bd --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/6d.js @@ -0,0 +1,179 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* // Define the shape of the input 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 the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Test elements: +* var out = find6d( x, NaN, predicate ); +* // returns 2.0 +*/ +function find6d( x, sentinelValue, predicate, thisArg ) { + var xbuf; + var idx; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + 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; + + // Note on variable naming convention: S#, dx#, 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++ ) { + if ( predicate.call( thisArg, xbuf[ ix ], take( [ i5, i4, i3, i2, i1, i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return xbuf[ ix ]; + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = find6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/6d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/6d_accessors.js new file mode 100644 index 000000000000..f0689f66be2a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/6d_accessors.js @@ -0,0 +1,186 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 1, 1, 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 8, 8, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Test elements: +* var out = find6d( x, NaN, predicate ); +* // returns 2.0 +*/ +function find6d( x, sentinelValue, predicate, thisArg ) { + var xbuf; + var idx; + var get; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + 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; + + // Note on variable naming convention: S#, dx#, 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++ ) { + if ( predicate.call( thisArg, get( xbuf, ix ), take( [ i5, i4, i3, i2, i1, i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return get( xbuf, ix ); + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = find6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/6d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/6d_blocked.js new file mode 100644 index 000000000000..2f81d0131cde --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/6d_blocked.js @@ -0,0 +1,241 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* // Define the shape of the input 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 the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Test elements: +* var out = blockedfind6d( x, NaN, predicate ); +* // returns 2.0 +*/ +function blockedfind6d( x, sentinelValue, predicate, thisArg ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var idx; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var ox1; + var ox2; + var ox3; + var ox4; + var ox5; + 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; + + // Note on variable naming convention: s#, dx#, 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++ ) { + if ( predicate.call( thisArg, xbuf[ ix ], take( [ j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return xbuf[ ix ]; + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + } + } + } + } + } + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = blockedfind6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/6d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/6d_blocked_accessors.js new file mode 100644 index 000000000000..f36326d26309 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/6d_blocked_accessors.js @@ -0,0 +1,248 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 1, 1, 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 8, 8, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Test elements: +* var out = blockedfind6d( x, NaN, predicate ); +* // returns 2.0 +*/ +function blockedfind6d( x, sentinelValue, predicate, thisArg ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var idx; + 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 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; + + // Note on variable naming convention: s#, dx#, 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++ ) { + if ( predicate.call( thisArg, get( xbuf, ix ), take( [ j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return get( xbuf, ix ); + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + } + } + } + } + } + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = blockedfind6d; From 85b845d4026ac2758663f34587de34e09c3c20dd Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 2 Jul 2025 06:33:42 +0000 Subject: [PATCH 20/30] feat: add 7d kernels --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/base/find/lib/7d.js | 189 +++++++++++++ .../ndarray/base/find/lib/7d_accessors.js | 196 +++++++++++++ .../ndarray/base/find/lib/7d_blocked.js | 260 +++++++++++++++++ .../base/find/lib/7d_blocked_accessors.js | 267 ++++++++++++++++++ 4 files changed, 912 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/7d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/7d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/7d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/7d_blocked_accessors.js diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/7d.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/7d.js new file mode 100644 index 000000000000..3d6ce32ecd4c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/7d.js @@ -0,0 +1,189 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* // Define the shape of the input 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 the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Test elements: +* var out = find7d( x, NaN, predicate ); +* // returns 2.0 +*/ +function find7d( x, sentinelValue, predicate, thisArg ) { + var xbuf; + var idx; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + 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; + + // Note on variable naming convention: S#, dx#, 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++ ) { + if ( predicate.call( thisArg, xbuf[ ix ], take( [ i6, i5, i4, i3, i2, i1, i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return xbuf[ ix ]; + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = find7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/7d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/7d_accessors.js new file mode 100644 index 000000000000..9de097f5d1ad --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/7d_accessors.js @@ -0,0 +1,196 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 1, 1, 1, 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 8, 8, 8, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Test elements: +* var out = find7d( x, NaN, predicate ); +* // returns 2.0 +*/ +function find7d( x, sentinelValue, predicate, thisArg ) { + var xbuf; + var idx; + var get; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + 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; + + // Note on variable naming convention: S#, dx#, 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++ ) { + if ( predicate.call( thisArg, get( xbuf, ix ), take( [ i6, i5, i4, i3, i2, i1, i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return get( xbuf, ix ); + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = find7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/7d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/7d_blocked.js new file mode 100644 index 000000000000..36ff1afcece9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/7d_blocked.js @@ -0,0 +1,260 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* // Define the shape of the input 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 the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Test elements: +* var out = blockedfind7d( x, NaN, predicate ); +* // returns 2.0 +*/ +function blockedfind7d( x, sentinelValue, predicate, thisArg ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var idx; + 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 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; + + // Note on variable naming convention: s#, dx#, 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++ ) { + if ( predicate.call( thisArg, xbuf[ ix ], take( [ j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], idx ), x.ref ) ) { + return xbuf[ ix ]; + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + } + } + } + } + } + } + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = blockedfind7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/7d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/7d_blocked_accessors.js new file mode 100644 index 000000000000..6c00ae1d9e75 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/7d_blocked_accessors.js @@ -0,0 +1,267 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 1, 1, 1, 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 8, 8, 8, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Test elements: +* var out = blockedfind7d( x, NaN, predicate ); +* // returns 2.0 +*/ +function blockedfind7d( x, sentinelValue, predicate, thisArg ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var idx; + 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 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; + + // Note on variable naming convention: s#, dx#, 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++ ) { + if ( predicate.call( thisArg, get( xbuf, ix ), take( [ j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], idx ), x.ref ) ) { + return get( xbuf, ix ); + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + } + } + } + } + } + } + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = blockedfind7d; From d7f8d348b57b3a190abfa6d44d286544961d4c89 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 2 Jul 2025 06:49:44 +0000 Subject: [PATCH 21/30] feat: add 8d kernels --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/base/find/lib/8d.js | 199 ++++++++++++ .../ndarray/base/find/lib/8d_accessors.js | 206 +++++++++++++ .../ndarray/base/find/lib/8d_blocked.js | 279 +++++++++++++++++ .../base/find/lib/8d_blocked_accessors.js | 286 ++++++++++++++++++ 4 files changed, 970 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/8d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/8d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/8d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/8d_blocked_accessors.js diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/8d.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/8d.js new file mode 100644 index 000000000000..7be5202779ad --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/8d.js @@ -0,0 +1,199 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* // Define the shape of the input 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 the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Test elements: +* var out = find8d( x, NaN, predicate ); +* // returns 2.0 +*/ +function find8d( x, sentinelValue, predicate, thisArg ) { + var xbuf; + var idx; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + 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; + + // Note on variable naming convention: S#, dx#, 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++ ) { + if ( predicate.call( thisArg, xbuf[ ix ], take( [ i7, i6, i5, i4, i3, i2, i1, i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return xbuf[ ix ]; + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + ix += dx7; + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = find8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/8d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/8d_accessors.js new file mode 100644 index 000000000000..06f5689ec836 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/8d_accessors.js @@ -0,0 +1,206 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 1, 1, 1, 1, 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 8, 8, 8, 8, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Test elements: +* var out = find8d( x, NaN, predicate ); +* // returns 2.0 +*/ +function find8d( x, sentinelValue, predicate, thisArg ) { + var xbuf; + var idx; + var get; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + 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; + + // Note on variable naming convention: S#, dx#, 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++ ) { + if ( predicate.call( thisArg, get( xbuf, ix ), take( [ i7, i6, i5, i4, i3, i2, i1, i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return get( xbuf, ix ); + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + ix += dx7; + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = find8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/8d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/8d_blocked.js new file mode 100644 index 000000000000..7964486c8b9b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/8d_blocked.js @@ -0,0 +1,279 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* // Define the shape of the input 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 the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Test elements: +* var out = blockedfind8d( x, NaN, predicate ); +* // returns 2.0 +*/ +function blockedfind8d( x, sentinelValue, predicate, thisArg ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var idx; + 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 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; + + // Note on variable naming convention: s#, dx#, 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++ ) { + if ( predicate.call( thisArg, xbuf[ ix ], take( [ j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], idx ), x.ref ) ) { + return xbuf[ ix ]; + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + ix += dx7; + } + } + } + } + } + } + } + } + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = blockedfind8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/8d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/8d_blocked_accessors.js new file mode 100644 index 000000000000..37920ae47aaf --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/8d_blocked_accessors.js @@ -0,0 +1,286 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 1, 1, 1, 1, 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 8, 8, 8, 8, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Test elements: +* var out = blockedfind8d( x, NaN, predicate ); +* // returns 2.0 +*/ +function blockedfind8d( x, sentinelValue, predicate, thisArg ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var idx; + 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 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; + + // Note on variable naming convention: s#, dx#, 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++ ) { + if ( predicate.call( thisArg, get( xbuf, ix ), take( [ j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], idx ), x.ref ) ) { + return get( xbuf, ix ); + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + ix += dx7; + } + } + } + } + } + } + } + } + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = blockedfind8d; From 2abe2348787869668a318cfeebac14f6c2c37b4c Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 2 Jul 2025 07:17:32 +0000 Subject: [PATCH 22/30] feat: add 9d kernels --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/base/find/lib/9d.js | 209 ++++++++++++ .../ndarray/base/find/lib/9d_accessors.js | 216 +++++++++++++ .../ndarray/base/find/lib/9d_blocked.js | 298 +++++++++++++++++ .../base/find/lib/9d_blocked_accessors.js | 305 ++++++++++++++++++ 4 files changed, 1028 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/9d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/9d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/9d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/9d_blocked_accessors.js diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/9d.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/9d.js new file mode 100644 index 000000000000..766b1d7855e4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/9d.js @@ -0,0 +1,209 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* // Define the shape of the input 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 the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Test elements: +* var out = find9d( x, NaN, predicate ); +* // returns 2.0 +*/ +function find9d( x, sentinelValue, predicate, thisArg ) { + var xbuf; + var idx; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var dx8; + 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; + + // Note on variable naming convention: S#, dx#, 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++ ) { + if ( predicate.call( thisArg, xbuf[ ix ], take( [ i8, i7, i6, i5, i4, i3, i2, i1, i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return xbuf[ ix ]; + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + ix += dx7; + } + ix += dx8; + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = find9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/9d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/9d_accessors.js new file mode 100644 index 000000000000..62ae74c98e4a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/9d_accessors.js @@ -0,0 +1,216 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 1, 1, 1, 1, 1, 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 8, 8, 8, 8, 8, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Test elements: +* var out = find9d( x, NaN, predicate ); +* // returns 2.0 +*/ +function find9d( x, sentinelValue, predicate, thisArg ) { + var xbuf; + var idx; + var get; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var dx8; + 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; + + // Note on variable naming convention: S#, dx#, 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++ ) { + if ( predicate.call( thisArg, get( xbuf, ix ), take( [ i8, i7, i6, i5, i4, i3, i2, i1, i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return get( xbuf, ix ); + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + ix += dx7; + } + ix += dx8; + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = find9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/9d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/9d_blocked.js new file mode 100644 index 000000000000..d563dee2b0de --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/9d_blocked.js @@ -0,0 +1,298 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* // Define the shape of the input 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 the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Test elements: +* var out = blockedfind9d( x, NaN, predicate ); +* // returns 2.0 +*/ +function blockedfind9d( x, sentinelValue, predicate, thisArg ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var idx; + 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 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; + + // Note on variable naming convention: s#, dx#, 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++ ) { + if ( predicate.call( thisArg, xbuf[ ix ], take( [ j8+i8, j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], idx ), x.ref ) ) { + return xbuf[ ix ]; + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + ix += dx7; + } + ix += dx8; + } + } + } + } + } + } + } + } + } + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = blockedfind9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/9d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/9d_blocked_accessors.js new file mode 100644 index 000000000000..947096a01ed4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/9d_blocked_accessors.js @@ -0,0 +1,305 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 1, 1, 1, 1, 1, 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 8, 8, 8, 8, 8, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Test elements: +* var out = blockedfind9d( x, NaN, predicate ); +* // returns 2.0 +*/ +function blockedfind9d( x, sentinelValue, predicate, thisArg ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var idx; + 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 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; + + // Note on variable naming convention: s#, dx#, 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++ ) { + if ( predicate.call( thisArg, get( xbuf, ix ), take( [ j8+i8, j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], idx ), x.ref ) ) { + return get( xbuf, ix ); + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + ix += dx7; + } + ix += dx8; + } + } + } + } + } + } + } + } + } + } + return true; +} + + +// EXPORTS // + +module.exports = blockedfind9d; From eecb8c9cef28a70eaab24f230501dff7ac879e6f Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 2 Jul 2025 07:31:01 +0000 Subject: [PATCH 23/30] feat: add 10d kernels --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/base/find/lib/10d.js | 219 ++++++++++++ .../ndarray/base/find/lib/10d_accessors.js | 226 ++++++++++++ .../ndarray/base/find/lib/10d_blocked.js | 317 +++++++++++++++++ .../base/find/lib/10d_blocked_accessors.js | 324 ++++++++++++++++++ 4 files changed, 1086 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/10d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/10d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/10d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/lib/10d_blocked_accessors.js diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/10d.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/10d.js new file mode 100644 index 000000000000..f1e2753b7177 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/10d.js @@ -0,0 +1,219 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* // Define the shape of the input 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 the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Test elements: +* var out = find10d( x, NaN, predicate ); +* // returns 2.0 +*/ +function find10d( x, sentinelValue, predicate, thisArg ) { // eslint-disable-line max-statements + var xbuf; + var idx; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var dx8; + var dx9; + 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; + + // Note on variable naming convention: S#, dx#, 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++ ) { + if ( predicate.call( thisArg, xbuf[ ix ], take( [ i9, i8, i7, i6, i5, i4, i3, i2, i1, i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return xbuf[ ix ]; + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + ix += dx7; + } + ix += dx8; + } + ix += dx9; + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = find10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/10d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/10d_accessors.js new file mode 100644 index 000000000000..981924d1efae --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/10d_accessors.js @@ -0,0 +1,226 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 8, 8, 8, 8, 8, 8, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Test elements: +* var out = find10d( x, NaN, predicate ); +* // returns 2.0 +*/ +function find10d( x, sentinelValue, predicate, thisArg ) { // eslint-disable-line max-statements + var xbuf; + var idx; + var get; + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dx5; + var dx6; + var dx7; + var dx8; + var dx9; + 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; + + // Note on variable naming convention: S#, dx#, 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++ ) { + if ( predicate.call( thisArg, get( xbuf, ix ), take( [ i9, i8, i7, i6, i5, i4, i3, i2, i1, i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len + return get( xbuf, ix ); + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + ix += dx7; + } + ix += dx8; + } + ix += dx9; + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = find10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/10d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/10d_blocked.js new file mode 100644 index 000000000000..7ed1ec711d7b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/10d_blocked.js @@ -0,0 +1,317 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* // Define the shape of the input 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 the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Test elements: +* var out = blockedfind10d( x, NaN, predicate ); +* // returns 2.0 +*/ +function blockedfind10d( x, sentinelValue, predicate, thisArg ) { // eslint-disable-line max-statements, max-lines-per-function + var bsize; + var xbuf; + var idx; + 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 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; + + // Note on variable naming convention: s#, dx#, 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++ ) { + if ( predicate.call( thisArg, xbuf[ ix ], take( [ j9+i9, j8+i8, j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], idx ), x.ref ) ) { + return xbuf[ ix ]; + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + ix += dx7; + } + ix += dx8; + } + ix += dx9; + } + } + } + } + } + } + } + } + } + } + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = blockedfind10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/10d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/10d_blocked_accessors.js new file mode 100644 index 000000000000..ae5123c14258 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/10d_blocked_accessors.js @@ -0,0 +1,324 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 // + +/** +* Returns the first element in an ndarray which passes a test implemented by a predicate function via loop blocking. +* +* @private +* @param {Object} x - object containing ndarray meta data +* @param {ndarrayLike} x.ref - reference to the original ndarray-like object +* @param {string} 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 {*} sentinelValue - sentinel value +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {*} result +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var accessors = require( '@stdlib/array/base/accessors' ); +* +* function predicate( value ) { +* return value % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 2, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 8, 8, 8, 8, 8, 8, 8, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create the input ndarray-like object: +* var x = { +* 'ref': null, +* 'dtype': 'generic', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': accessors( xbuf ).accessors +* }; +* +* // Test elements: +* var out = blockedfind10d( x, NaN, predicate ); +* // returns 2.0 +*/ +function blockedfind10d( x, sentinelValue, predicate, thisArg ) { // eslint-disable-line max-statements, max-lines-per-function + var bsize; + var xbuf; + var idx; + 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 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; + + // Note on variable naming convention: s#, dx#, 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++ ) { + if ( predicate.call( thisArg, get( xbuf, ix ), take( [ j9+i9, j8+i8, j7+i7, j6+i6, j5+i5, j4+i4, j3+i3, j2+i2, j1+i1, j0+i0 ], idx ), x.ref ) ) { + return get( xbuf, ix ); + } + ix += dx0; + } + ix += dx1; + } + ix += dx2; + } + ix += dx3; + } + ix += dx4; + } + ix += dx5; + } + ix += dx6; + } + ix += dx7; + } + ix += dx8; + } + ix += dx9; + } + } + } + } + } + } + } + } + } + } + } + return sentinelValue; +} + + +// EXPORTS // + +module.exports = blockedfind10d; From a17f0a443369ea3f30aafd32e4db8bd4f89b2a45 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 2 Jul 2025 10:39:48 +0000 Subject: [PATCH 24/30] bench: add benchmarks upto 5d --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../benchmark.4d_blocked_columnmajor.js | 147 ++++++++++++++++++ .../benchmark.4d_blocked_rowmajor.js | 147 ++++++++++++++++++ .../benchmark/benchmark.4d_columnmajor.js | 147 ++++++++++++++++++ .../find/benchmark/benchmark.4d_rowmajor.js | 147 ++++++++++++++++++ .../benchmark.5d_blocked_columnmajor.js | 147 ++++++++++++++++++ .../benchmark.5d_blocked_rowmajor.js | 147 ++++++++++++++++++ .../benchmark/benchmark.5d_columnmajor.js | 147 ++++++++++++++++++ .../find/benchmark/benchmark.5d_rowmajor.js | 147 ++++++++++++++++++ 8 files changed, 1176 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.4d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.4d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.4d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.4d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.5d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.5d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.5d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.5d_rowmajor.js diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.4d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.4d_blocked_columnmajor.js new file mode 100644 index 000000000000..8c96bd907f9c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.4d_blocked_columnmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/4d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.4d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.4d_blocked_rowmajor.js new file mode 100644 index 000000000000..ad256179362a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.4d_blocked_rowmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/4d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should return an integer' ); + } + 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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.4d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.4d_columnmajor.js new file mode 100644 index 000000000000..309cdd369916 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.4d_columnmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/4d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should return an integer' ); + } + 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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.4d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.4d_rowmajor.js new file mode 100644 index 000000000000..603e54a62daf --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.4d_rowmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/4d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.5d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.5d_blocked_columnmajor.js new file mode 100644 index 000000000000..ef5e26075f6e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.5d_blocked_columnmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/5d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.5d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.5d_blocked_rowmajor.js new file mode 100644 index 000000000000..3e4ee791c6ad --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.5d_blocked_rowmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/5d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.5d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.5d_columnmajor.js new file mode 100644 index 000000000000..818012d7b34a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.5d_columnmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/5d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should return an integer' ); + } + 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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.5d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.5d_rowmajor.js new file mode 100644 index 000000000000..a50c7949c139 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.5d_rowmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/5d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); From 3a313765dba79f0ef3d36477c95fc6f50b92a5d9 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 2 Jul 2025 10:50:29 +0000 Subject: [PATCH 25/30] bench: add 6d benchmarks --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../benchmark.6d_blocked_columnmajor.js | 147 ++++++++++++++++++ .../benchmark.6d_blocked_rowmajor.js | 147 ++++++++++++++++++ .../benchmark/benchmark.6d_columnmajor.js | 147 ++++++++++++++++++ .../find/benchmark/benchmark.6d_rowmajor.js | 147 ++++++++++++++++++ 4 files changed, 588 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.6d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.6d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.6d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.6d_rowmajor.js diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.6d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.6d_blocked_columnmajor.js new file mode 100644 index 000000000000..9d2b08796422 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.6d_blocked_columnmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/6d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.6d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.6d_blocked_rowmajor.js new file mode 100644 index 000000000000..d9ef4339c41d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.6d_blocked_rowmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/6d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.6d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.6d_columnmajor.js new file mode 100644 index 000000000000..2d6cdcbaa297 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.6d_columnmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/6d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.6d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.6d_rowmajor.js new file mode 100644 index 000000000000..6e4302b0b49a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.6d_rowmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/6d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); From 1595c41889e85fb5cef65fee8dad59b88fc08075 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 2 Jul 2025 11:02:11 +0000 Subject: [PATCH 26/30] bench: add 7d benchmarks --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../benchmark.7d_blocked_columnmajor.js | 147 ++++++++++++++++++ .../benchmark.7d_blocked_rowmajor.js | 147 ++++++++++++++++++ .../benchmark/benchmark.7d_columnmajor.js | 147 ++++++++++++++++++ .../find/benchmark/benchmark.7d_rowmajor.js | 147 ++++++++++++++++++ 4 files changed, 588 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.7d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.7d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.7d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.7d_rowmajor.js diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.7d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.7d_blocked_columnmajor.js new file mode 100644 index 000000000000..c01207a087b1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.7d_blocked_columnmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/7d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.7d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.7d_blocked_rowmajor.js new file mode 100644 index 000000000000..937aae9bb0f1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.7d_blocked_rowmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/7d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.7d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.7d_columnmajor.js new file mode 100644 index 000000000000..007cceb38aca --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.7d_columnmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/7d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.7d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.7d_rowmajor.js new file mode 100644 index 000000000000..713e6651ffdf --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.7d_rowmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/7d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); From 3d2d0cfda4936e2b6709dfe01999893004f99f85 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 2 Jul 2025 11:18:13 +0000 Subject: [PATCH 27/30] bench: add 8d benchmarks --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../benchmark.8d_blocked_columnmajor.js | 147 ++++++++++++++++++ .../benchmark.8d_blocked_rowmajor.js | 147 ++++++++++++++++++ .../benchmark/benchmark.8d_columnmajor.js | 147 ++++++++++++++++++ .../find/benchmark/benchmark.8d_rowmajor.js | 147 ++++++++++++++++++ 4 files changed, 588 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.8d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.8d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.8d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.8d_rowmajor.js diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.8d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.8d_blocked_columnmajor.js new file mode 100644 index 000000000000..8b7a5b161ebc --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.8d_blocked_columnmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/8d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.8d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.8d_blocked_rowmajor.js new file mode 100644 index 000000000000..8b7a5b161ebc --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.8d_blocked_rowmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/8d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.8d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.8d_columnmajor.js new file mode 100644 index 000000000000..95d68fef5b2a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.8d_columnmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/8d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.8d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.8d_rowmajor.js new file mode 100644 index 000000000000..f0ad47dc150b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.8d_rowmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/8d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); From 6cd22c07cb337e1f8c8920ac56a97a536f61f84f Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 2 Jul 2025 11:36:47 +0000 Subject: [PATCH 28/30] bench: add 9d benchmarks --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../benchmark.9d_blocked_columnmajor.js | 147 ++++++++++++++++++ .../benchmark.9d_blocked_rowmajor.js | 147 ++++++++++++++++++ .../benchmark/benchmark.9d_columnmajor.js | 147 ++++++++++++++++++ .../find/benchmark/benchmark.9d_rowmajor.js | 147 ++++++++++++++++++ 4 files changed, 588 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.9d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.9d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.9d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.9d_rowmajor.js diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.9d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.9d_blocked_columnmajor.js new file mode 100644 index 000000000000..0fbd12a341f2 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.9d_blocked_columnmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/9d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.9d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.9d_blocked_rowmajor.js new file mode 100644 index 000000000000..f3bf9034be38 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.9d_blocked_rowmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/9d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.9d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.9d_columnmajor.js new file mode 100644 index 000000000000..b990dacdaebd --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.9d_columnmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/9d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.9d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.9d_rowmajor.js new file mode 100644 index 000000000000..d9c06319f133 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.9d_rowmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/9d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); From 48360d7fbeec2c41f9f154976977f1a117ec78cc Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 2 Jul 2025 11:51:16 +0000 Subject: [PATCH 29/30] bench: add 10d benchmarks --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../benchmark.10d_blocked_columnmajor.js | 147 ++++++++++++++++++ .../benchmark.10d_blocked_rowmajor.js | 147 ++++++++++++++++++ .../benchmark/benchmark.10d_columnmajor.js | 147 ++++++++++++++++++ .../find/benchmark/benchmark.10d_rowmajor.js | 147 ++++++++++++++++++ 4 files changed, 588 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.10d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.10d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.10d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.10d_rowmajor.js diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.10d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.10d_blocked_columnmajor.js new file mode 100644 index 000000000000..89e3935f0413 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.10d_blocked_columnmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/10d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.10d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.10d_blocked_rowmajor.js new file mode 100644 index 000000000000..7ea8308cb6d3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.10d_blocked_rowmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/10d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.10d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.10d_columnmajor.js new file mode 100644 index 000000000000..9d3bb93d8d0a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.10d_columnmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/10d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.10d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.10d_rowmajor.js new file mode 100644 index 000000000000..971205ec4f6d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.10d_rowmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/10d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); From b55394c1205485663036834bfea584a14dd188e8 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 2 Jul 2025 12:00:41 +0000 Subject: [PATCH 30/30] bench: add 11d benchmarks --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../benchmark/benchmark.11d_columnmajor.js | 147 ++++++++++++++++++ .../find/benchmark/benchmark.11d_rowmajor.js | 147 ++++++++++++++++++ 2 files changed, 294 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.11d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.11d_rowmajor.js diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.11d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.11d_columnmajor.js new file mode 100644 index 000000000000..135d750c1806 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.11d_columnmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/nd.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.11d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.11d_rowmajor.js new file mode 100644 index 000000000000..359e5d430d98 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/find/benchmark/benchmark.11d_rowmajor.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/* eslint-disable stdlib/no-redeclare */ + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +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 pkg = require( './../package.json' ).name; +var find = require( './../lib/nd.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} value - ndarray element +* @returns {boolean} result +*/ +function clbk( value ) { + return value < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype ) { + var x; + + x = discreteUniform( len, 1, 100, { + 'dtype': xtype + }); + 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 out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = find( x, NaN, clbk ); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + } + b.toc(); + if ( isInteger( out ) ) { + b.fail( 'should not return an integer' ); + } + 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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1 ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+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( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f ); + } + } +} + +main();