From e5df1e774bbc3c4ddfd601a3919ec34a57aa715a Mon Sep 17 00:00:00 2001 From: headlessNode Date: Tue, 29 Sep 2026 13:35:42 +0500 Subject: [PATCH 1/3] feat: add blas/ext/base/find-index-between --- .../blas/ext/find-index-between/README.md | 291 ++++ .../benchmark/benchmark.assign.js | 121 ++ .../find-index-between/benchmark/benchmark.js | 114 ++ .../blas/ext/find-index-between/docs/repl.txt | 159 +++ .../find-index-between/docs/types/index.d.ts | 293 ++++ .../ext/find-index-between/docs/types/test.ts | 470 ++++++ .../ext/find-index-between/examples/index.js | 44 + .../blas/ext/find-index-between/lib/assign.js | 190 +++ .../blas/ext/find-index-between/lib/base.js | 110 ++ .../find-index-between/lib/broadcast_index.js | 56 + .../blas/ext/find-index-between/lib/index.js | 97 ++ .../blas/ext/find-index-between/lib/main.js | 182 +++ .../blas/ext/find-index-between/package.json | 66 + .../find-index-between/test/test.assign.js | 1266 +++++++++++++++++ .../blas/ext/find-index-between/test/test.js | 39 + .../ext/find-index-between/test/test.main.js | 1062 ++++++++++++++ 16 files changed, 4560 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index-between/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index-between/benchmark/benchmark.assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index-between/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index-between/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index-between/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index-between/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index-between/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index-between/lib/assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index-between/lib/base.js create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index-between/lib/broadcast_index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index-between/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index-between/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index-between/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index-between/test/test.assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index-between/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index-between/test/test.main.js diff --git a/lib/node_modules/@stdlib/blas/ext/find-index-between/README.md b/lib/node_modules/@stdlib/blas/ext/find-index-between/README.md new file mode 100644 index 000000000000..b325ba0f456d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index-between/README.md @@ -0,0 +1,291 @@ + + +# findIndexBetween + +> Return the index of the first element along an [ndarray][@stdlib/ndarray/ctor] dimension which passes a test implemented by a predicate function within a specified range. + +
+ +## Usage + +```javascript +var findIndexBetween = require( '@stdlib/blas/ext/find-index-between' ); +``` + +#### findIndexBetween( x, fromIndex, toIndex\[, options], clbk\[, thisArg] ) + +Returns the index of the first element along an [ndarray][@stdlib/ndarray/ctor] dimension which passes a test implemented by a predicate function within a specified range. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +function isEven( v ) { + return v % 2.0 === 0.0; +} + +// Create an input ndarray: +var x = array( [ 2.0, 1.0, 3.0, 4.0, 5.0, 6.0 ] ); +// returns + +// Perform operation: +var out = findIndexBetween( x, 1, 4, isEven ); +// returns [ 3 ] +``` + +The function has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have at least one dimension. +- **fromIndex**: index from which to begin searching. May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having an integer index or "generic" [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the non-reduced dimensions of the input [ndarray][@stdlib/ndarray/ctor]. For example, given the input shape `[2, 3, 4]` and `options.dim=0`, a provided [ndarray][@stdlib/ndarray/ctor] must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. If provided a negative integer, the index at which to begin searching along a dimension is determined by counting backward from the last element (where `-1` refers to the last element). +- **toIndex**: index at which to stop searching (exclusive). May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having an integer index or "generic" [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the non-reduced dimensions of the input [ndarray][@stdlib/ndarray/ctor]. For example, given the input shape `[2, 3, 4]` and `options.dim=0`, a provided [ndarray][@stdlib/ndarray/ctor] must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. If provided a negative integer, the index at which to stop searching along a dimension is determined by counting backward from the last element (where `-1` refers to the last element). +- **options**: function options (_optional_). +- **clbk**: callback function. +- **thisArg**: callback execution context (_optional_). + +The invoked callback is provided three arguments: + +- **value**: current array element. +- **idx**: current array element index. +- **array**: input ndarray. + +To set the callback execution context, provide a `thisArg`. + + + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +function isEven( v ) { + this.count += 1; + return v % 2.0 === 0.0; +} + +var x = array( [ 2.0, 1.0, 3.0, 4.0, 5.0, 6.0 ] ); + +var ctx = { + 'count': 0 +}; +var out = findIndexBetween( x, 1, 4, isEven, ctx ); +// returns [ 3 ] + +var count = ctx.count; +// returns 3 +``` + +The function accepts the following options: + +- **dtype**: output ndarray [data type][@stdlib/ndarray/dtypes]. Must be an integer index or generic [data type][@stdlib/ndarray/dtypes]. +- **dim**: dimension over which to perform operation. If provided a negative integer, the dimension along which to perform the operation is determined by counting backward from the last dimension (where `-1` refers to the last dimension). Default: `-1`. +- **keepdims**: boolean indicating whether the reduced dimensions should be included in the returned [ndarray][@stdlib/ndarray/ctor] as singleton dimensions. Default: `false`. + +If no element along an [ndarray][@stdlib/ndarray/ctor] dimension passes a test implemented by the predicate function, the corresponding element in the returned [ndarray][@stdlib/ndarray/ctor] is `-1`. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +function isEven( v ) { + return v % 2.0 === 0.0; +} + +// Create an input ndarray: +var x = array( [ 1.0, 3.0, 5.0, 7.0 ] ); +// returns + +// Perform operation: +var out = findIndexBetween( x, 0, 4, isEven ); +// returns [ -1 ] +``` + +By default, the function performs the operation over elements in the last dimension. To perform the operation over a different dimension, provide a `dim` option. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +function isEven( v ) { + return v % 2.0 === 0.0; +} + +var x = array( [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ] ); + +var opts = { + 'dim': 0 +}; + +var out = findIndexBetween( x, 0, 2, opts, isEven ); +// returns [ -1, 0 ] +``` + +By default, the function excludes reduced dimensions from the output [ndarray][@stdlib/ndarray/ctor]. To include the reduced dimensions as singleton dimensions, set the `keepdims` option to `true`. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +function isEven( v ) { + return v % 2.0 === 0.0; +} + +var x = array( [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ] ); + +var opts = { + 'dim': 0, + 'keepdims': true +}; + +var out = findIndexBetween( x, 0, 2, opts, isEven ); +// returns [ [ -1, 0 ] ] +``` + +By default, the function returns an [ndarray][@stdlib/ndarray/ctor] having a [data type][@stdlib/ndarray/dtypes] determined by the function's output data type [policy][@stdlib/ndarray/output-dtype-policies]. To override the default behavior, set the `dtype` option. + +```javascript +var dtype = require( '@stdlib/ndarray/dtype' ); +var array = require( '@stdlib/ndarray/array' ); + +function isEven( v ) { + return v % 2.0 === 0.0; +} + +var x = array( [ 2.0, 1.0, 3.0, 4.0 ] ); + +var opts = { + 'dtype': 'generic' +}; + +var idx = findIndexBetween( x, 0, 4, opts, isEven ); +// returns [ 0 ] + +var dt = String( dtype( idx ) ); +// returns 'generic' +``` + +#### findIndexBetween.assign( x, fromIndex, toIndex, out\[, options], clbk\[, thisArg] ) + +Returns the index of the first element along an [ndarray][@stdlib/ndarray/ctor] dimension which passes a test implemented by a predicate function within a specified range and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor]. + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var zeros = require( '@stdlib/ndarray/zeros' ); + +function isEven( v ) { + return v % 2.0 === 0.0; +} + +var x = array( [ 2.0, 1.0, 3.0, 4.0 ] ); +var y = zeros( [], { + 'dtype': 'int32' +}); + +var out = findIndexBetween.assign( x, 0, 4, y, isEven ); +// returns [ 0 ] + +var bool = ( out === y ); +// returns true +``` + +The method has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have at least one dimension. +- **fromIndex**: index from which to begin searching. May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having an integer index or "generic" [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the non-reduced dimensions of the input [ndarray][@stdlib/ndarray/ctor]. For example, given the input shape `[2, 3, 4]` and `options.dim=0`, a provided [ndarray][@stdlib/ndarray/ctor] must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. If provided a negative integer, the index at which to begin searching along a dimension is determined by counting backward from the last element (where `-1` refers to the last element). +- **toIndex**: index at which to stop searching (exclusive). May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having an integer index or "generic" [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the non-reduced dimensions of the input [ndarray][@stdlib/ndarray/ctor]. For example, given the input shape `[2, 3, 4]` and `options.dim=0`, a provided [ndarray][@stdlib/ndarray/ctor] must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. If provided a negative integer, the index at which to stop searching along a dimension is determined by counting backward from the last element (where `-1` refers to the last element). +- **out**: output [ndarray][@stdlib/ndarray/ctor]. +- **options**: function options (_optional_). +- **clbk**: callback function. +- **thisArg**: callback execution context (_optional_). + +The method accepts the following options: + +- **dim**: dimension over which to perform operation. If provided a negative integer, the dimension along which to perform the operation is determined by counting backward from the last dimension (where `-1` refers to the last dimension). Default: `-1`. + +
+ + + +
+ +## Notes + +- A provided callback function should return a boolean. +- Setting the `keepdims` option to `true` can be useful when wanting to ensure that the output [ndarray][@stdlib/ndarray/ctor] is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with ndarrays having the same shape as the input [ndarray][@stdlib/ndarray/ctor]. +- The output data type [policy][@stdlib/ndarray/output-dtype-policies] only applies to the main function and specifies that, by default, the function must return an [ndarray][@stdlib/ndarray/ctor] having an integer index or "generic" [data type][@stdlib/ndarray/dtypes]. For the `assign` method, the output [ndarray][@stdlib/ndarray/ctor] is allowed to have any supported output [data type][@stdlib/ndarray/dtypes]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var findIndexBetween = require( '@stdlib/blas/ext/find-index-between' ); + +// Define a callback function: +function isEven( v ) { + return v % 2.0 === 0.0; +} + +// Generate an ndarray of random numbers: +var x = discreteUniform( [ 5, 2 ], 0, 20, { + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +var opts = { + 'dim': 0 +}; + +// Perform operation: +var idx = findIndexBetween( x, 0, 5, opts, isEven ); + +// Print the results: +console.log( ndarray2array( idx ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/find-index-between/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/blas/ext/find-index-between/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..e6876689e303 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index-between/benchmark/benchmark.assign.js @@ -0,0 +1,121 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR 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 uniform = require( '@stdlib/random/uniform' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var findIndexBetween = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @param {number} v - input value +* @returns {boolean} result +*/ +function clbk( v ) { + return v < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var out; + var x; + + x = uniform( [ len ], 0.0, 100.0, options ); + out = zeros( [], { + 'dtype': 'int32' + }); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var o; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = findIndexBetween.assign( x, 0, len, out, clbk ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( o.get() ) ) { + 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 f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:assign:dtype=%s,len=%d', pkg, options.dtype, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/find-index-between/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/find-index-between/benchmark/benchmark.js new file mode 100644 index 000000000000..6111bc2b82c9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index-between/benchmark/benchmark.js @@ -0,0 +1,114 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR 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 uniform = require( '@stdlib/random/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var findIndexBetween = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @param {number} v - input value +* @returns {boolean} result +*/ +function clbk( v ) { + return v < 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( [ len ], 0.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var o; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = findIndexBetween( x, 0, len, clbk ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( o.get() ) ) { + 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 f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:dtype=%s,len=%d', pkg, options.dtype, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/find-index-between/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/find-index-between/docs/repl.txt new file mode 100644 index 000000000000..d6eeabfd458d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index-between/docs/repl.txt @@ -0,0 +1,159 @@ + +{{alias}}( x, fromIndex, toIndex[, options], clbk[, thisArg] ) + Returns the index of the first element along an ndarray dimension which + passes a test implemented by a predicate function within a specified range. + + The callback function is provided the following arguments: + + - value: current array element. + - index: current array index. + - array: the input ndarray. + + The callback function should return a boolean. + + If no element along an ndarray dimension passes a test implemented by the + predicate function, the corresponding element in the returned ndarray is + `-1`. + + Parameters + ---------- + x: ndarray + Input array. Must have at least one dimension. + + fromIndex: ndarray|integer + Index from which to begin searching. May be either a scalar value or an + ndarray having an integer or "generic" data type. If provided an + ndarray, the value must have a shape which is broadcast compatible with + the non-reduced dimensions of the input ndarray. For example, given the + input shape `[2, 3, 4]` and `options.dim=0`, a provided ndarray must + have a shape which is broadcast-compatible with the shape `[3, 4]`. If + provided a negative integer, the index at which to begin searching along + a dimension is determined by counting backward from the last element + (where -1 refers to the last element). + + toIndex: ndarray|integer + Index at which to stop searching (exclusive). May be either a scalar + value or an ndarray having an integer or "generic" data type. If + provided an ndarray, the value must have a shape which is broadcast + compatible with the non-reduced dimensions of the input ndarray. For + example, given the input shape `[2, 3, 4]` and `options.dim=0`, a + provided ndarray must have a shape which is broadcast-compatible with + the shape `[3, 4]`. If provided a negative integer, the index at which + to stop searching along a dimension is determined by counting backward + from the last element (where -1 refers to the last element). + + options: Object (optional) + Function options. + + options.dtype: string|DataType (optional) + Output array data type. Must be an integer index or "generic" data type. + + options.dim: integer (optional) + Dimension over which to perform a reduction. If provided a negative + integer, the dimension along which to perform the operation is + determined by counting backward from the last dimension (where -1 refers + to the last dimension). Default: -1. + + options.keepdims: boolean (optional) + Boolean indicating whether the reduced dimensions should be included in + the returned ndarray as singleton dimensions. Default: false. + + clbk: Function + Callback function. + + thisArg: any (optional) + Callback execution context. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ -1.0, 2.0, -3.0, -4.0 ] ); + > function clbk( v ) { return v % 2.0 === 0.0; }; + > var y = {{alias}}( x, 0, 4, clbk ) + [ 1 ] + + +{{alias}}.assign( x, fromIndex, toIndex, out[, options], clbk[, thisArg] ) + Returns the index of the first element along an ndarray dimension which + passes a test implemented by a predicate function within a specified range + and assigns results to a provided output ndarray. + + The callback function is provided the following arguments: + + - value: current array element. + - index: current array index. + - array: the input ndarray. + + The callback function should return a boolean. + + If no element along an ndarray dimension passes a test implemented by the + predicate function, the corresponding element in the returned ndarray is + `-1`. + + Parameters + ---------- + x: ndarray + Input array. Must have at least one dimension. + + fromIndex: ndarray|integer + Index from which to begin searching. May be either a scalar value or an + ndarray having an integer or "generic" data type. If provided an + ndarray, the value must have a shape which is broadcast compatible with + the non-reduced dimensions of the input ndarray. For example, given the + input shape `[2, 3, 4]` and `options.dim=0`, a provided ndarray must + have a shape which is broadcast-compatible with the shape `[3, 4]`. If + provided a negative integer, the index at which to begin searching along + a dimension is determined by counting backward from the last element + (where -1 refers to the last element). + + toIndex: ndarray|integer + Index at which to stop searching (exclusive). May be either a scalar + value or an ndarray having an integer or "generic" data type. If + provided an ndarray, the value must have a shape which is broadcast + compatible with the non-reduced dimensions of the input ndarray. For + example, given the input shape `[2, 3, 4]` and `options.dim=0`, a + provided ndarray must have a shape which is broadcast-compatible with + the shape `[3, 4]`. If provided a negative integer, the index at which + to stop searching along a dimension is determined by counting backward + from the last element (where -1 refers to the last element). + + out: ndarray + Output array. + + options: Object (optional) + Function options. + + options.dim: integer (optional) + Dimension over which to perform a reduction. If provided a negative + integer, the dimension along which to perform the operation is + determined by counting backward from the last dimension (where -1 refers + to the last dimension). Default: -1. + + clbk: Function + Callback function. + + thisArg: any (optional) + Callback execution context. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ -1.0, 2.0, -3.0, -4.0 ] ); + > var out = {{alias:@stdlib/ndarray/zeros}}( [], { 'dtype': 'int32' } ); + > function clbk( v ) { return v % 2.0 === 0.0; }; + > var y = {{alias}}.assign( x, 0, 4, out, clbk ) + [ 1 ] + > var bool = ( out === y ) + true + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/find-index-between/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/find-index-between/docs/types/index.d.ts new file mode 100644 index 000000000000..a72e254d6d24 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index-between/docs/types/index.d.ts @@ -0,0 +1,293 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 { IntegerIndexAndGenericDataType as DataType, typedndarray } from '@stdlib/types/ndarray'; + +/** +* Input array. +*/ +type InputArray = typedndarray; + +/** +* Index argument. +*/ +type IndexArg = typedndarray | number; + +/** +* Output array. +*/ +type OutputArray = typedndarray; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @returns boolean indicating whether an element passes a test +*/ +type NullaryPredicate = ( this: ThisArg ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - current array element +* @returns boolean indicating whether an element passes a test +*/ +type UnaryPredicate = ( this: ThisArg, value: T ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - current array element +* @param index - current array element index +* @returns boolean indicating whether an element passes a test +*/ +type BinaryPredicate = ( this: ThisArg, value: T, index: number ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - current array element +* @param index - current array element index +* @param array - input ndarray +* @returns boolean indicating whether an element passes a test +*/ +type TernaryPredicate = ( this: ThisArg, value: T, index: number, array: U ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - current array element +* @param index - current array element index +* @param array - input ndarray +* @returns boolean indicating whether an element passes a test +*/ +type Predicate = NullaryPredicate | UnaryPredicate | BinaryPredicate | TernaryPredicate; + +/** +* Interface defining "base" options. +*/ +interface BaseOptions { + /** + * Dimension over which to perform operation. Default: `-1`. + * + * ## Notes + * + * - If provided a negative integer, the dimension along which to perform the operation is determined by counting backward from the last dimension (where `-1` refers to the last dimension). + */ + dim?: number; +} + +/** +* Interface defining options. +*/ +interface Options extends BaseOptions { + /** + * Output array data type. + */ + dtype?: DataType; + + /** + * Boolean indicating whether the reduced dimensions should be included in the returned array as singleton dimensions. Default: `false`. + */ + keepdims?: boolean; +} + +/** +* Interface describing `findIndexBetween`. +*/ +interface FindIndexBetween { + /** + * Returns the index of the first element along an ndarray dimension which passes a test implemented by a predicate function within a specified range. + * + * ## Notes + * + * - If no element along an ndarray dimension passes a test implemented by the predicate function, the corresponding element in the returned ndarray is `-1`. + * + * @param x - input ndarray + * @param fromIndex - index from which to begin searching + * @param toIndex - index at which to stop searching (exclusive) + * @param clbk - predicate function + * @param thisArg - predicate function execution context + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * + * function clbk( value ) { + * return value % 2.0 === 0.0; + * } + * + * var x = array( [ 2.0, 1.0, -3.0, 4.0 ] ); + * + * var y = findIndexBetween( x, 1, 4, clbk ); + * // returns [ 3 ] + */ + = InputArray, ThisArg = unknown>( x: U, fromIndex: IndexArg, toIndex: IndexArg, clbk: Predicate, thisArg?: ThisParameterType> ): OutputArray; + + /** + * Returns the index of the first element along an ndarray dimension which passes a test implemented by a predicate function within a specified range. + * + * ## Notes + * + * - If no element along an ndarray dimension passes a test implemented by the predicate function, the corresponding element in the returned ndarray is `-1`. + * + * @param x - input ndarray + * @param fromIndex - index from which to begin searching + * @param toIndex - index at which to stop searching (exclusive) + * @param options - function options + * @param clbk - predicate function + * @param thisArg - predicate function execution context + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * + * function clbk( value ) { + * return value % 2.0 === 0.0; + * } + * + * var x = array( [ 2.0, 1.0, -3.0, 4.0 ] ); + * + * var y = findIndexBetween( x, 1, 4, {}, clbk ); + * // returns [ 3 ] + */ + = InputArray, ThisArg = unknown>( x: U, fromIndex: IndexArg, toIndex: IndexArg, options: Options, clbk: Predicate, thisArg?: ThisParameterType> ): OutputArray; + + /** + * Returns the index of the first element along an ndarray dimension which passes a test implemented by a predicate function within a specified range and assigns results to a provided output ndarray. + * + * ## Notes + * + * - If no element along an ndarray dimension passes a test implemented by the predicate function, the corresponding element in the returned ndarray is `-1`. + * + * @param x - input ndarray + * @param fromIndex - index from which to begin searching + * @param toIndex - index at which to stop searching (exclusive) + * @param out - output ndarray + * @param clbk - predicate function + * @param thisArg - predicate function execution context + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * var zeros = require( '@stdlib/ndarray/zeros' ); + * + * function clbk( value ) { + * return value % 2.0 === 0.0; + * } + * + * var x = array( [ 2.0, 1.0, -3.0, 4.0 ] ); + * var y = zeros( [] ); + * + * var out = findIndexBetween.assign( x, 1, 4, y, clbk ); + * // returns [ 3 ] + * + * var bool = ( out === y ); + * // returns true + */ + assign = InputArray, V extends OutputArray = OutputArray, ThisArg = unknown>( x: U, fromIndex: IndexArg, toIndex: IndexArg, out: V, clbk: Predicate, thisArg?: ThisParameterType> ): V; + + /** + * Returns the index of the first element along an ndarray dimension which passes a test implemented by a predicate function within a specified range and assigns results to a provided output ndarray. + * + * ## Notes + * + * - If no element along an ndarray dimension passes a test implemented by the predicate function, the corresponding element in the returned ndarray is `-1`. + * + * @param x - input ndarray + * @param fromIndex - index from which to begin searching + * @param toIndex - index at which to stop searching (exclusive) + * @param out - output ndarray + * @param options - function options + * @param clbk - predicate function + * @param thisArg - predicate function execution context + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * var zeros = require( '@stdlib/ndarray/zeros' ); + * + * function clbk( value ) { + * return value % 2.0 === 0.0; + * } + * + * var x = array( [ 2.0, 1.0, -3.0, 4.0 ] ); + * var y = zeros( [] ); + * + * var out = findIndexBetween.assign( x, 1, 4, y, {}, clbk ); + * // returns [ 3 ] + * + * var bool = ( out === y ); + * // returns true + */ + assign = InputArray, V extends OutputArray = OutputArray, ThisArg = unknown>( x: U, fromIndex: IndexArg, toIndex: IndexArg, out: V, options: BaseOptions, clbk: Predicate, thisArg?: ThisParameterType> ): V; +} + +/** +* Returns the index of the first element along an ndarray dimension which passes a test implemented by a predicate function within a specified range. +* +* ## Notes +* +* - If no element along an ndarray dimension passes a test implemented by the predicate function, the corresponding element in the returned ndarray is `-1`. +* +* @param x - input ndarray +* @param fromIndex - index from which to begin searching +* @param toIndex - index at which to stop searching (exclusive) +* @param options - function options +* @param clbk - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* function clbk( value ) { +* return value % 2.0 === 0.0; +* } +* +* var x = array( [ 2.0, 1.0, -3.0, 4.0 ] ); +* +* var y = findIndexBetween( x, 1, 4, clbk ); +* // returns [ 3 ] +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* +* function clbk( value ) { +* return value % 2.0 === 0.0; +* } +* +* var x = array( [ 2.0, 1.0, -3.0, 4.0 ] ); +* var y = zeros( [] ); +* +* var out = findIndexBetween.assign( x, 1, 4, y, clbk ); +* // returns [ 3 ] +* +* var bool = ( out === y ); +* // returns true +*/ +declare const findIndexBetween: FindIndexBetween; + + +// EXPORTS // + +export = findIndexBetween; diff --git a/lib/node_modules/@stdlib/blas/ext/find-index-between/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/find-index-between/docs/types/test.ts new file mode 100644 index 000000000000..52106ee790ed --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index-between/docs/types/test.ts @@ -0,0 +1,470 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 @typescript-eslint/no-unused-expressions, space-in-parens */ + +/// + +import zeros = require( '@stdlib/ndarray/zeros' ); +import findIndexBetween = require( './index' ); + +/** +* Callback function. +* +* @param value - ndarray element +* @returns result +*/ +function clbk( value: any ): boolean { + return value % 2.0 === 0.0; +} + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + findIndexBetween( x, 0, 2, clbk ); // $ExpectType OutputArray + findIndexBetween( x, 0, 2, clbk, {} ); // $ExpectType OutputArray + + findIndexBetween( x, 0, 2, {}, clbk ); // $ExpectType OutputArray + findIndexBetween( x, 0, 2, {}, clbk, {} ); // $ExpectType OutputArray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + findIndexBetween( '5', 0, 2, clbk ); // $ExpectError + findIndexBetween( 5, 0, 2, clbk ); // $ExpectError + findIndexBetween( true, 0, 2, clbk ); // $ExpectError + findIndexBetween( false, 0, 2, clbk ); // $ExpectError + findIndexBetween( null, 0, 2, clbk ); // $ExpectError + findIndexBetween( void 0, 0, 2, clbk ); // $ExpectError + findIndexBetween( {}, 0, 2, clbk ); // $ExpectError + findIndexBetween( ( x: number ): number => x, 0, 2, clbk ); // $ExpectError + + findIndexBetween( '5', 0, 2, clbk, {} ); // $ExpectError + findIndexBetween( 5, 0, 2, clbk, {} ); // $ExpectError + findIndexBetween( true, 0, 2, clbk, {} ); // $ExpectError + findIndexBetween( false, 0, 2, clbk, {} ); // $ExpectError + findIndexBetween( null, 0, 2, clbk, {} ); // $ExpectError + findIndexBetween( void 0, 0, 2, clbk, {} ); // $ExpectError + findIndexBetween( {}, 0, 2, clbk, {} ); // $ExpectError + findIndexBetween( ( x: number ): number => x, 0, 2, clbk, {} ); // $ExpectError + + findIndexBetween( '5', 0, 2, {}, clbk ); // $ExpectError + findIndexBetween( 5, 0, 2, {}, clbk ); // $ExpectError + findIndexBetween( true, 0, 2, {}, clbk ); // $ExpectError + findIndexBetween( false, 0, 2, {}, clbk ); // $ExpectError + findIndexBetween( null, 0, 2, {}, clbk ); // $ExpectError + findIndexBetween( void 0, 0, 2, {}, clbk ); // $ExpectError + findIndexBetween( {}, 0, 2, {}, clbk ); // $ExpectError + findIndexBetween( ( x: number ): number => x, 0, 2, {}, clbk ); // $ExpectError + + findIndexBetween( '5', 0, 2, {}, clbk, {} ); // $ExpectError + findIndexBetween( 5, 0, 2, {}, clbk, {} ); // $ExpectError + findIndexBetween( true, 0, 2, {}, clbk, {} ); // $ExpectError + findIndexBetween( false, 0, 2, {}, clbk, {} ); // $ExpectError + findIndexBetween( null, 0, 2, {}, clbk, {} ); // $ExpectError + findIndexBetween( void 0, 0, 2, {}, clbk, {} ); // $ExpectError + findIndexBetween( {}, 0, 2, {}, clbk, {} ); // $ExpectError + findIndexBetween( ( x: number ): number => x, 0, 2, {}, clbk, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a `fromIndex` argument which is not an ndarray or an integer value... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + findIndexBetween( x, '5', 2, clbk ); // $ExpectError + findIndexBetween( x, true, 2, clbk ); // $ExpectError + findIndexBetween( x, false, 2, clbk ); // $ExpectError + findIndexBetween( x, null, 2, clbk ); // $ExpectError + findIndexBetween( x, [], 2, clbk ); // $ExpectError + + findIndexBetween( x, '5', 2, clbk, {} ); // $ExpectError + findIndexBetween( x, true, 2, clbk, {} ); // $ExpectError + findIndexBetween( x, false, 2, clbk, {} ); // $ExpectError + findIndexBetween( x, null, 2, clbk, {} ); // $ExpectError + findIndexBetween( x, [], 2, clbk, {} ); // $ExpectError + + findIndexBetween( x, '5', 2, {}, clbk ); // $ExpectError + findIndexBetween( x, true, 2, {}, clbk ); // $ExpectError + findIndexBetween( x, false, 2, {}, clbk ); // $ExpectError + findIndexBetween( x, null, 2, {}, clbk ); // $ExpectError + findIndexBetween( x, [], 2, {}, clbk ); // $ExpectError + + findIndexBetween( x, '5', 2, {}, clbk, {} ); // $ExpectError + findIndexBetween( x, true, 2, {}, clbk, {} ); // $ExpectError + findIndexBetween( x, false, 2, {}, clbk, {} ); // $ExpectError + findIndexBetween( x, null, 2, {}, clbk, {} ); // $ExpectError + findIndexBetween( x, [], 2, {}, clbk, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a `toIndex` argument which is not an ndarray or an integer value... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + findIndexBetween( x, 0, '5', clbk ); // $ExpectError + findIndexBetween( x, 0, true, clbk ); // $ExpectError + findIndexBetween( x, 0, false, clbk ); // $ExpectError + findIndexBetween( x, 0, null, clbk ); // $ExpectError + findIndexBetween( x, 0, [], clbk ); // $ExpectError + + findIndexBetween( x, 0, '5', clbk, {} ); // $ExpectError + findIndexBetween( x, 0, true, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, false, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, null, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, [], clbk, {} ); // $ExpectError + + findIndexBetween( x, 0, '5', {}, clbk ); // $ExpectError + findIndexBetween( x, 0, true, {}, clbk ); // $ExpectError + findIndexBetween( x, 0, false, {}, clbk ); // $ExpectError + findIndexBetween( x, 0, null, {}, clbk ); // $ExpectError + findIndexBetween( x, 0, [], {}, clbk ); // $ExpectError + + findIndexBetween( x, 0, '5', {}, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, true, {}, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, false, {}, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, null, {}, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, [], {}, clbk, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an options argument which is not an object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + findIndexBetween( x, 0, 2, '5', clbk ); // $ExpectError + findIndexBetween( x, 0, 2, true, clbk ); // $ExpectError + findIndexBetween( x, 0, 2, false, clbk ); // $ExpectError + findIndexBetween( x, 0, 2, null, clbk ); // $ExpectError + findIndexBetween( x, 0, 2, [], clbk ); // $ExpectError + + findIndexBetween( x, 0, 2, '5', clbk, {} ); // $ExpectError + findIndexBetween( x, 0, 2, true, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, 2, false, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, 2, null, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, 2, [], clbk, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a callback argument which is not a function... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + findIndexBetween( x, 0, 2, '5' ); // $ExpectError + findIndexBetween( x, 0, 2, true ); // $ExpectError + findIndexBetween( x, 0, 2, false ); // $ExpectError + findIndexBetween( x, 0, 2, null ); // $ExpectError + findIndexBetween( x, 0, 2, [] ); // $ExpectError + + findIndexBetween( x, 0, 2, '5', {} ); // $ExpectError + findIndexBetween( x, 0, 2, true, {} ); // $ExpectError + findIndexBetween( x, 0, 2, false, {} ); // $ExpectError + findIndexBetween( x, 0, 2, null, {} ); // $ExpectError + findIndexBetween( x, 0, 2, [], {} ); // $ExpectError + + findIndexBetween( x, 0, 2, {}, '5', {} ); // $ExpectError + findIndexBetween( x, 0, 2, {}, true, {} ); // $ExpectError + findIndexBetween( x, 0, 2, {}, false, {} ); // $ExpectError + findIndexBetween( x, 0, 2, {}, null, {} ); // $ExpectError + findIndexBetween( x, 0, 2, {}, [], {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dtype` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + findIndexBetween( x, 0, 2, { 'dtype': '5' }, clbk ); // $ExpectError + findIndexBetween( x, 0, 2, { 'dtype': 5 }, clbk ); // $ExpectError + findIndexBetween( x, 0, 2, { 'dtype': true }, clbk ); // $ExpectError + findIndexBetween( x, 0, 2, { 'dtype': false }, clbk ); // $ExpectError + findIndexBetween( x, 0, 2, { 'dtype': null }, clbk ); // $ExpectError + findIndexBetween( x, 0, 2, { 'dtype': [] }, clbk ); // $ExpectError + findIndexBetween( x, 0, 2, { 'dtype': {} }, clbk ); // $ExpectError + findIndexBetween( x, 0, 2, { 'dtype': ( x: number ): number => x }, clbk ); // $ExpectError + + findIndexBetween( x, 0, 2, { 'dtype': '5' }, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, 2, { 'dtype': 5 }, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, 2, { 'dtype': true }, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, 2, { 'dtype': false }, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, 2, { 'dtype': null }, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, 2, { 'dtype': [] }, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, 2, { 'dtype': {} }, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, 2, { 'dtype': ( x: number ): number => x }, clbk, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `keepdims` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + findIndexBetween( x, 0, 2, { 'keepdims': '5' }, clbk ); // $ExpectError + findIndexBetween( x, 0, 2, { 'keepdims': 5 }, clbk ); // $ExpectError + findIndexBetween( x, 0, 2, { 'keepdims': null }, clbk ); // $ExpectError + findIndexBetween( x, 0, 2, { 'keepdims': [] }, clbk ); // $ExpectError + findIndexBetween( x, 0, 2, { 'keepdims': {} }, clbk ); // $ExpectError + findIndexBetween( x, 0, 2, { 'keepdims': ( x: number ): number => x }, clbk ); // $ExpectError + + findIndexBetween( x, 0, 2, { 'keepdims': '5' }, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, 2, { 'keepdims': 5 }, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, 2, { 'keepdims': null }, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, 2, { 'keepdims': [] }, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, 2, { 'keepdims': {} }, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, 2, { 'keepdims': ( x: number ): number => x }, clbk, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dim` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + findIndexBetween( x, 0, 2, { 'dim': '5' }, clbk ); // $ExpectError + findIndexBetween( x, 0, 2, { 'dim': true }, clbk ); // $ExpectError + findIndexBetween( x, 0, 2, { 'dim': false }, clbk ); // $ExpectError + findIndexBetween( x, 0, 2, { 'dim': null }, clbk ); // $ExpectError + findIndexBetween( x, 0, 2, { 'dim': {} }, clbk ); // $ExpectError + findIndexBetween( x, 0, 2, { 'dim': ( x: number ): number => x }, clbk ); // $ExpectError + + findIndexBetween( x, 0, 2, { 'dim': '5' }, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, 2, { 'dim': true }, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, 2, { 'dim': false }, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, 2, { 'dim': null }, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, 2, { 'dim': {} }, clbk, {} ); // $ExpectError + findIndexBetween( x, 0, 2, { 'dim': ( x: number ): number => x }, clbk, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + findIndexBetween(); // $ExpectError + findIndexBetween( x ); + findIndexBetween( x, 0 ); + findIndexBetween( x, 0, 2 ); + findIndexBetween( x, 0, 2, {}, clbk, {}, {} ); // $ExpectError +} + +// Attached to the function is an `assign` method which returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + const y = zeros( [], { + 'dtype': 'int32' + }); + + findIndexBetween.assign( x, 0, 2, y, clbk ); // $ExpectType int32ndarray + findIndexBetween.assign( x, 0, 2, y, {}, clbk ); // $ExpectType int32ndarray + + findIndexBetween.assign( x, 0, 2, y, clbk, {} ); // $ExpectType int32ndarray + findIndexBetween.assign( x, 0, 2, y, {}, clbk, {} ); // $ExpectType int32ndarray +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not an ndarray... +{ + const y = zeros( [], { + 'dtype': 'int32' + }); + + findIndexBetween.assign( '5', 0, 2, y, clbk ); // $ExpectError + findIndexBetween.assign( 5, 0, 2, y, clbk ); // $ExpectError + findIndexBetween.assign( true, 0, 2, y, clbk ); // $ExpectError + findIndexBetween.assign( false, 0, 2, y, clbk ); // $ExpectError + findIndexBetween.assign( null, 0, 2, y, clbk ); // $ExpectError + findIndexBetween.assign( void 0, 0, 2, y, clbk ); // $ExpectError + findIndexBetween.assign( {}, 0, 2, y, clbk ); // $ExpectError + findIndexBetween.assign( ( x: number ): number => x, 0, 2, y, clbk ); // $ExpectError + + findIndexBetween.assign( '5', 0, 2, y, {}, clbk ); // $ExpectError + findIndexBetween.assign( 5, 0, 2, y, {}, clbk ); // $ExpectError + findIndexBetween.assign( true, 0, 2, y, {}, clbk ); // $ExpectError + findIndexBetween.assign( false, 0, 2, y, {}, clbk ); // $ExpectError + findIndexBetween.assign( null, 0, 2, y, {}, clbk ); // $ExpectError + findIndexBetween.assign( void 0, 0, 2, y, {}, clbk ); // $ExpectError + findIndexBetween.assign( {}, 0, 2, y, {}, clbk ); // $ExpectError + findIndexBetween.assign( ( x: number ): number => x, 0, 2, y, {}, clbk ); // $ExpectError + + findIndexBetween.assign( '5', 0, 2, y, clbk, {} ); // $ExpectError + findIndexBetween.assign( 5, 0, 2, y, clbk, {} ); // $ExpectError + findIndexBetween.assign( true, 0, 2, y, clbk, {} ); // $ExpectError + findIndexBetween.assign( false, 0, 2, y, clbk, {} ); // $ExpectError + findIndexBetween.assign( null, 0, 2, y, clbk, {} ); // $ExpectError + findIndexBetween.assign( void 0, 0, 2, y, clbk, {} ); // $ExpectError + findIndexBetween.assign( {}, 0, 2, y, clbk, {} ); // $ExpectError + findIndexBetween.assign( ( x: number ): number => x, 0, 2, y, clbk, {} ); // $ExpectError + + findIndexBetween.assign( '5', 0, 2, y, {}, clbk, {} ); // $ExpectError + findIndexBetween.assign( 5, 0, 2, y, {}, clbk, {} ); // $ExpectError + findIndexBetween.assign( true, 0, 2, y, {}, clbk, {} ); // $ExpectError + findIndexBetween.assign( false, 0, 2, y, {}, clbk, {} ); // $ExpectError + findIndexBetween.assign( null, 0, 2, y, {}, clbk, {} ); // $ExpectError + findIndexBetween.assign( void 0, 0, 2, y, {}, clbk, {} ); // $ExpectError + findIndexBetween.assign( {}, 0, 2, y, {}, clbk, {} ); // $ExpectError + findIndexBetween.assign( ( x: number ): number => x, 0, 2, y, {}, clbk, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fourth argument which is not an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + findIndexBetween.assign( x, 0, 2, '5', clbk ); // $ExpectError + findIndexBetween.assign( x, 0, 2, 5, clbk ); // $ExpectError + findIndexBetween.assign( x, 0, 2, true, clbk ); // $ExpectError + findIndexBetween.assign( x, 0, 2, false, clbk ); // $ExpectError + findIndexBetween.assign( x, 0, 2, null, clbk ); // $ExpectError + findIndexBetween.assign( x, 0, 2, void 0, clbk ); // $ExpectError + findIndexBetween.assign( x, 0, 2, ( x: number ): number => x, clbk ); // $ExpectError + + findIndexBetween.assign( x, 0, 2, '5', {}, clbk ); // $ExpectError + findIndexBetween.assign( x, 0, 2, 5, {}, clbk ); // $ExpectError + findIndexBetween.assign( x, 0, 2, true, {}, clbk ); // $ExpectError + findIndexBetween.assign( x, 0, 2, false, {}, clbk ); // $ExpectError + findIndexBetween.assign( x, 0, 2, null, {}, clbk ); // $ExpectError + findIndexBetween.assign( x, 0, 2, void 0, {}, clbk ); // $ExpectError + findIndexBetween.assign( x, 0, 2, ( x: number ): number => x, {}, clbk ); // $ExpectError + + findIndexBetween.assign( x, 0, 2, '5', clbk, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, 5, clbk, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, true, clbk, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, false, clbk, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, null, clbk, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, void 0, clbk, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, ( x: number ): number => x, clbk, {} ); // $ExpectError + + findIndexBetween.assign( x, 0, 2, '5', {}, clbk, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, 5, {}, clbk, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, true, {}, clbk, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, false, {}, clbk, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, null, {}, clbk, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, void 0, {}, clbk, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, ( x: number ): number => x, {}, clbk, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an options argument which is not an object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + const y = zeros( [], { + 'dtype': 'int32' + }); + + findIndexBetween.assign( x, 0, 2, y, '5', clbk ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, true, clbk ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, false, clbk ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, null, clbk ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, [], clbk ); // $ExpectError + + findIndexBetween.assign( x, 0, 2, y, '5', clbk, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, true, clbk, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, false, clbk, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, null, clbk, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, [], clbk, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a callback argument which is not a function... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + const y = zeros( [], { + 'dtype': 'int32' + }); + + findIndexBetween.assign( x, 0, 2, y, '5' ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, true ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, false ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, null ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, [] ); // $ExpectError + + findIndexBetween.assign( x, 0, 2, y, '5', {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, true, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, false, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, null, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, [], {} ); // $ExpectError + + findIndexBetween.assign( x, 0, 2, y, {}, '5' ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, {}, true ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, {}, false ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, {}, null ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, {}, [] ); // $ExpectError + + findIndexBetween.assign( x, 0, 2, y, {}, '5', {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, {}, true, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, {}, false, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, {}, null, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, {}, [], {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an invalid `dim` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + const y = zeros( [], { + 'dtype': 'int32' + }); + + findIndexBetween.assign( x, 0, 2, y, { 'dim': '5' }, clbk ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, { 'dim': true }, clbk ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, { 'dim': false }, clbk ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, { 'dim': null }, clbk ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, { 'dim': {} }, clbk ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, { 'dim': ( x: number ): number => x }, clbk ); // $ExpectError + + findIndexBetween.assign( x, 0, 2, y, { 'dim': '5' }, clbk, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, { 'dim': true }, clbk, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, { 'dim': false }, clbk, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, { 'dim': null }, clbk, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, { 'dim': {} }, clbk, {} ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, { 'dim': ( x: number ): number => x }, clbk, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + const y = zeros( [], { + 'dtype': 'int32' + }); + + findIndexBetween.assign(); // $ExpectError + findIndexBetween.assign( x ); // $ExpectError + findIndexBetween.assign( x, 0 ); // $ExpectError + findIndexBetween.assign( x, 0, 2 ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y ); // $ExpectError + findIndexBetween.assign( x, 0, 2, y, {}, clbk, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/find-index-between/examples/index.js b/lib/node_modules/@stdlib/blas/ext/find-index-between/examples/index.js new file mode 100644 index 000000000000..31752e948b87 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index-between/examples/index.js @@ -0,0 +1,44 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR 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/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var findIndexBetween = require( './../lib' ); + +// Define a callback function: +function isEven( v ) { + return v % 2.0 === 0.0; +} + +// Generate an ndarray of random numbers: +var x = discreteUniform( [ 5, 2 ], 0, 20, { + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +var opts = { + 'dim': 0 +}; + +// Perform operation: +var idx = findIndexBetween( x, 0, 5, opts, isEven ); + +// Print the results: +console.log( ndarray2array( idx ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/find-index-between/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/find-index-between/lib/assign.js new file mode 100644 index 000000000000..8e0f18956f3b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index-between/lib/assign.js @@ -0,0 +1,190 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var ndims = require( '@stdlib/ndarray/ndims' ); +var format = require( '@stdlib/string/format' ); +var broadcastIndex = require( './broadcast_index.js' ); +var base = require( './base.js' ).assign; + + +// MAIN // + +/** +* Returns the index of the first element along an ndarray dimension which passes a test implemented by a predicate function within a specified range and assigns the results to a provided output ndarray. +* +* @param {ndarrayLike} x - input ndarray +* @param {(ndarrayLike|integer)} fromIndex - index from which to begin searching +* @param {(ndarrayLike|integer)} toIndex - index at which to stop searching (exclusive) +* @param {ndarrayLike} out - output ndarray +* @param {Options} [options] - function options +* @param {integer} [options.dim=-1] - dimension over which to perform operation +* @param {Function} clbk - callback function +* @param {*} [thisArg] - callback execution context +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} `fromIndex` argument must be either an ndarray-like object or an integer +* @throws {TypeError} `toIndex` argument must be either an ndarray-like object or an integer +* @throws {TypeError} output argument must be an ndarray-like object +* @throws {TypeError} callback argument must be a function +* @throws {TypeError} options argument must be an object +* @throws {RangeError} dimension index must not exceed input ndarray bounds +* @throws {RangeError} first argument must have at least one dimension +* @throws {Error} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* function isEven( v ) { +* return v % 2.0 === 0.0; +* } +* +* // Create data buffers: +* var xbuf = [ 2.0, 1.0, 3.0, 4.0, 5.0, 6.0 ]; +* +* // Define the shape of the input array: +* var shape = [ 6 ]; +* +* // Define the array strides: +* var strides = [ 1 ]; +* +* // Define the index offset: +* var offset = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'generic', xbuf, shape, strides, offset, 'row-major' ); +* +* // Create an output ndarray: +* var y = zeros( [], { +* 'dtype': 'int32' +* }); +* +* // Perform operation: +* var out = assign( x, 1, 4, y, isEven ); +* // returns [ 3 ] +* +* var bool = ( out === y ); +* // returns true +*/ +function assign( x, fromIndex, toIndex, out ) { + var hasOptions; + var options; + var nargs; + var opts; + var ord; + var ctx; + var sh; + var cb; + var o; + + nargs = arguments.length; + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + } + if ( !isInteger( fromIndex ) && !isndarrayLike( fromIndex ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or an integer. Value: `%s`.', fromIndex ) ); + } + if ( !isInteger( toIndex ) && !isndarrayLike( toIndex ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be either an ndarray or an integer. Value: `%s`.', toIndex ) ); + } + // Resolve input ndarray meta data: + ord = getOrder( x ); + + // Initialize an options object: + opts = { + 'dims': [ -1 ] // default behavior is to perform a reduction over the last dimension + }; + + // Initialize a flag indicating whether an `options` argument was provided: + hasOptions = false; + + o = out; + if ( !isndarrayLike( o ) ) { + throw new TypeError( format( 'invalid argument. Fourth argument must be an ndarray. Value: `%s`.', o ) ); + } + + // Case: assign( x, fromIndex, toIndex, out, clbk ) + if ( nargs === 5 ) { + cb = arguments[ 4 ]; + if ( !isFunction( cb ) ) { + throw new TypeError( format( 'invalid argument. Fifth argument must be a function. Value: `%s`.', cb ) ); + } + } + // Case: assign( x, fromIndex, toIndex, out, ???, ??? ) + else if ( nargs === 6 ) { + // Case: assign( x, fromIndex, toIndex, out, clbk, thisArg ) + if ( isFunction( arguments[ 4 ] ) ) { + cb = arguments[ 4 ]; + ctx = arguments[ 5 ]; + } + // Case: assign( x, fromIndex, toIndex, out, options, clbk ) + else { + options = arguments[ 4 ]; + hasOptions = true; + cb = arguments[ 5 ]; + if ( !isFunction( cb ) ) { + throw new TypeError( format( 'invalid argument. Sixth argument must be a function. Value: `%s`.', cb ) ); + } + } + } + // Case: assign( x, fromIndex, toIndex, out, options, clbk, thisArg ) + else { + options = arguments[ 4 ]; + hasOptions = true; + cb = arguments[ 5 ]; + if ( !isFunction( cb ) ) { + throw new TypeError( format( 'invalid argument. Sixth argument must be a function. Value: `%s`.', cb ) ); + } + ctx = arguments[ 6 ]; + } + if ( hasOptions ) { + if ( !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + // Resolve provided options... + if ( hasOwnProp( options, 'dim' ) ) { + opts.dims[ 0 ] = options.dim; + } + } + if ( ndims( x ) < 1 ) { + throw new RangeError( 'invalid argument. First argument must have at least one dimension.' ); + } + // Resolve the list of non-reduced dimensions: + sh = getShape( x ); + sh = nonCoreShape( sh, opts.dims ); + + // Broadcast the indices to match the shape of the non-reduced dimensions... + return base( x, broadcastIndex( fromIndex, sh, ord ), broadcastIndex( toIndex, sh, ord ), o, opts, cb, ctx ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/blas/ext/find-index-between/lib/base.js b/lib/node_modules/@stdlib/blas/ext/find-index-between/lib/base.js new file mode 100644 index 000000000000..61fcabbab6b2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index-between/lib/base.js @@ -0,0 +1,110 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR 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 dtypes = require( '@stdlib/ndarray/dtypes' ); +var gfindIndexBetween = require( '@stdlib/blas/ext/base/ndarray/gfind-index-between' ); +var factory = require( '@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-by-factory' ); + + +// VARIABLES // + +var idtypes0 = dtypes( 'all' ); // input ndarray +var idtypes1 = dtypes( 'integer_index_and_generic' ); // from index ndarray +var idtypes2 = dtypes( 'integer_index_and_generic' ); // to index ndarray +var odtypes = dtypes( 'integer_index_and_generic' ); +var policies = { + 'output': 'integer_index_and_generic', + 'casting': 'none' +}; +var table = { + 'default': gfindIndexBetween +}; + + +// MAIN // + +/** +* Returns the index of the first element along an ndarray dimension which passes a test implemented by a predicate function within a specified range. +* +* @private +* @name findIndexBetween +* @type {Function} +* @param {ndarrayLike} x - input ndarray +* @param {ndarrayLike} fromIndex - indices from which to begin searching +* @param {ndarrayLike} toIndex - indices at which to stop searching (exclusive) +* @param {Options} [options] - function options +* @param {IntegerArray} [options.dims] - list of dimensions over which to perform operation +* @param {*} [options.dtype] - output ndarray data type +* @param {Function} clbk - callback function +* @param {*} [thisArg] - callback execution context +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} second argument must be an ndarray-like object +* @throws {TypeError} third argument must be an ndarray-like object +* @throws {TypeError} options argument must be an object +* @throws {RangeError} dimension indices must not exceed input ndarray bounds +* @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions +* @throws {Error} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* function isEven( v ) { +* return v % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = [ 2.0, 1.0, 3.0, 4.0, 5.0, 6.0 ]; +* +* // Define the shape of the input array: +* var sh = [ 6 ]; +* +* // Define the array strides: +* var sx = [ 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'generic', xbuf, sh, sx, ox, 'row-major' ); +* +* // Create from and to index ndarrays: +* var fromIndex = scalar2ndarray( 1, { +* 'dtype': 'int32' +* }); +* var toIndex = scalar2ndarray( 4, { +* 'dtype': 'int32' +* }); +* +* // Perform operation: +* var out = findIndexBetween( x, fromIndex, toIndex, isEven ); +* // returns [ 3 ] +*/ +var findIndexBetween = factory( table, [ idtypes0, idtypes1, idtypes2 ], odtypes, policies ); + + +// EXPORTS // + +module.exports = findIndexBetween; + +// exports: { "assign": "findIndexBetween.assign" } diff --git a/lib/node_modules/@stdlib/blas/ext/find-index-between/lib/broadcast_index.js b/lib/node_modules/@stdlib/blas/ext/find-index-between/lib/broadcast_index.js new file mode 100644 index 000000000000..bade251f2423 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index-between/lib/broadcast_index.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); +var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' ); +var getDefault = require( '@stdlib/ndarray/defaults' ).get; + + +// VARIABLES // + +var DEFAULT_DTYPE = getDefault( 'dtypes.integer_index' ); + + +// MAIN // + +/** +* Broadcasts an index argument to match the shape of the non-core dimensions. +* +* @private +* @param {(ndarray|NonNegativeInteger)} idx - index argument +* @param {NonNegativeIntegerArray} shape - shape of the non-core dimensions +* @param {string} order - memory layout order +* @returns {ndarray} ndarray containing index values +*/ +function broadcastIndex( idx, shape, order ) { + // FIXME: this breaks for large integer/array sizes (e.g., casting idx > 2^32 to int32). We also need to update in the future to accommodate 64-bit integer values. + if ( isInteger( idx ) ) { + return broadcastScalar( idx, DEFAULT_DTYPE, shape, order ); + } + return maybeBroadcastArray( idx, shape ); +} + + +// EXPORTS // + +module.exports = broadcastIndex; diff --git a/lib/node_modules/@stdlib/blas/ext/find-index-between/lib/index.js b/lib/node_modules/@stdlib/blas/ext/find-index-between/lib/index.js new file mode 100644 index 000000000000..47fcf0ccfc21 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index-between/lib/index.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR 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 index of the first element along an ndarray dimension which passes a test implemented by a predicate function within a specified range. +* +* @module @stdlib/blas/ext/find-index-between +* +* @example +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var findIndexBetween = require( '@stdlib/blas/ext/find-index-between' ); +* +* function isEven( v ) { +* return v % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = [ 2.0, 1.0, 3.0, 4.0, 5.0, 6.0 ]; +* +* // Define the shape of the input array: +* var sh = [ 6 ]; +* +* // Define the array strides: +* var sx = [ 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'generic', xbuf, sh, sx, ox, 'row-major' ); +* +* // Perform operation: +* var out = findIndexBetween( x, 1, 4, isEven ); +* // returns [ 3 ] +* +* @example +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var findIndexBetween = require( '@stdlib/blas/ext/find-index-between' ); +* +* function isEven( v ) { +* return v % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = [ 2.0, 1.0, 3.0, 4.0, 5.0, 6.0 ]; +* +* // Define the shape of the input array: +* var sh = [ 2, 3 ]; +* +* // Define the array strides: +* var sx = [ 3, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'generic', xbuf, sh, sx, ox, 'row-major' ); +* +* // Perform operation: +* var out = findIndexBetween( x, 0, 2, isEven ); +* // returns [ 0, 1 ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var assign = require( './assign.js' ); + + +// MAIN // + +setReadOnly( main, 'assign', assign ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "assign": "main.assign" } diff --git a/lib/node_modules/@stdlib/blas/ext/find-index-between/lib/main.js b/lib/node_modules/@stdlib/blas/ext/find-index-between/lib/main.js new file mode 100644 index 000000000000..f9748a46a399 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index-between/lib/main.js @@ -0,0 +1,182 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var ndims = require( '@stdlib/ndarray/ndims' ); +var format = require( '@stdlib/string/format' ); +var broadcastIndex = require( './broadcast_index.js' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Returns the index of the first element along an ndarray dimension which passes a test implemented by a predicate function within a specified range. +* +* @param {ndarrayLike} x - input ndarray +* @param {(ndarrayLike|integer)} fromIndex - index from which to begin searching +* @param {(ndarrayLike|integer)} toIndex - index at which to stop searching (exclusive) +* @param {Options} [options] - function options +* @param {integer} [options.dim=-1] - dimension over which to perform operation +* @param {boolean} [options.keepdims=false] - boolean indicating whether the reduced dimensions should be included in the returned ndarray as singleton dimensions +* @param {*} [options.dtype] - output ndarray data type +* @param {Function} clbk - callback function +* @param {*} [thisArg] - callback execution context +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} callback argument must be a function +* @throws {TypeError} options argument must be an object +* @throws {TypeError} `fromIndex` argument must be either an ndarray-like object or an integer +* @throws {TypeError} `toIndex` argument must be either an ndarray-like object or an integer +* @throws {RangeError} dimension index must not exceed input ndarray bounds +* @throws {RangeError} first argument must have at least one dimension +* @throws {Error} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* function isEven( v ) { +* return v % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = [ 2.0, 1.0, 3.0, 4.0, 5.0, 6.0 ]; +* +* // Define the shape of the input array: +* var sh = [ 6 ]; +* +* // Define the array strides: +* var sx = [ 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'generic', xbuf, sh, sx, ox, 'row-major' ); +* +* // Perform operation: +* var out = findIndexBetween( x, 1, 4, isEven ); +* // returns [ 3 ] +*/ +function findIndexBetween( x, fromIndex, toIndex ) { + var hasOptions; + var options; + var nargs; + var opts; + var ord; + var ctx; + var sh; + var cb; + + nargs = arguments.length; + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + } + if ( !isInteger( fromIndex ) && !isndarrayLike( fromIndex ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or an integer. Value: `%s`.', fromIndex ) ); + } + if ( !isInteger( toIndex ) && !isndarrayLike( toIndex ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be either an ndarray or an integer. Value: `%s`.', toIndex ) ); + } + // Resolve input ndarray meta data: + ord = getOrder( x ); + + // Initialize an options object: + opts = { + 'dims': [ -1 ], // default behavior is to perform a reduction over the last dimension + 'keepdims': false + }; + + // Initialize a flag indicating whether an `options` argument was provided: + hasOptions = false; + + // Case: findIndexBetween( x, fromIndex, toIndex, clbk ) + if ( nargs === 4 ) { + cb = arguments[ 3 ]; + if ( !isFunction( cb ) ) { + throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', cb ) ); + } + } + // Case: findIndexBetween( x, fromIndex, toIndex, ???, ??? ) + else if ( nargs === 5 ) { + // Case: findIndexBetween( x, fromIndex, toIndex, clbk, thisArg ) + if ( isFunction( arguments[ 3 ] ) ) { + cb = arguments[ 3 ]; + ctx = arguments[ 4 ]; + } + // Case: findIndexBetween( x, fromIndex, toIndex, options, clbk ) + else { + options = arguments[ 3 ]; + hasOptions = true; + cb = arguments[ 4 ]; + if ( !isFunction( cb ) ) { + throw new TypeError( format( 'invalid argument. Fifth argument must be a function. Value: `%s`.', cb ) ); + } + } + } + // Case: findIndexBetween( x, fromIndex, toIndex, options, clbk, thisArg ) + else { + options = arguments[ 3 ]; + hasOptions = true; + cb = arguments[ 4 ]; + if ( !isFunction( cb ) ) { + throw new TypeError( format( 'invalid argument. Fifth argument must be a function. Value: `%s`.', cb ) ); + } + ctx = arguments[ 5 ]; + } + if ( hasOptions ) { + if ( !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + // Resolve provided options... + if ( hasOwnProp( options, 'dim' ) ) { + opts.dims[ 0 ] = options.dim; + } + if ( hasOwnProp( options, 'keepdims' ) ) { + opts.keepdims = options.keepdims; + } + if ( hasOwnProp( options, 'dtype' ) ) { + opts.dtype = options.dtype; + } + } + if ( ndims( x ) < 1 ) { + throw new RangeError( 'invalid argument. First argument must have at least one dimension.' ); + } + // Resolve the list of non-reduced dimensions: + sh = getShape( x ); + sh = nonCoreShape( sh, opts.dims ); + + // Broadcast the indices to match the shape of the non-reduced dimensions... + return base( x, broadcastIndex( fromIndex, sh, ord ), broadcastIndex( toIndex, sh, ord ), opts, cb, ctx ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = findIndexBetween; diff --git a/lib/node_modules/@stdlib/blas/ext/find-index-between/package.json b/lib/node_modules/@stdlib/blas/ext/find-index-between/package.json new file mode 100644 index 000000000000..b923612da33f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index-between/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/blas/ext/find-index-between", + "version": "0.0.0", + "description": "Return the index of the first element along an ndarray dimension which passes a test implemented by a predicate function within a specified range.", + "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", + "stdmath", + "mathematics", + "math", + "blas", + "find", + "index", + "between", + "search", + "range", + "array", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/find-index-between/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/find-index-between/test/test.assign.js new file mode 100644 index 000000000000..0acebef51d6b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index-between/test/test.assign.js @@ -0,0 +1,1266 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var findIndexBetween = require( './../lib' ).assign; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @param {number} v - input value +* @returns {boolean} result +*/ +function clbk( v ) { + return v % 2.0 === 0.0; +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof findIndexBetween, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object', function test( t ) { + var values; + var i; + var y; + + y = zeros( [], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( value, 0, 2, y, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (thisArg)', function test( t ) { + var values; + var i; + var y; + + y = zeros( [], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( value, 0, 2, y, clbk, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var i; + var y; + + y = zeros( [], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( value, 0, 2, y, {}, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options, thisArg)', function test( t ) { + var values; + var i; + var y; + + y = zeros( [], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( value, 0, 2, y, {}, clbk, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a zero-dimensional input ndarray-like object', function test( t ) { + var values; + var i; + var y; + + y = zeros( [], { + 'dtype': 'int32' + }); + + values = [ + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( zeros( value ), 0, 1, y, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a fourth argument which is not an ndarray-like object', function test( t ) { + var values; + var i; + var x; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( x, 0, 2, value, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a fourth argument which is not an ndarray-like object (thisArg)', function test( t ) { + var values; + var i; + var x; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( x, 0, 2, value, clbk, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a fourth argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var i; + var x; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( x, 0, 2, value, {}, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a fourth argument which is not an ndarray-like object (options, thisArg)', function test( t ) { + var values; + var i; + var x; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( x, 0, 2, value, {}, clbk, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function', function test( t ) { + var values; + var i; + var x; + var y; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + y = zeros( [], { + 'dtype': 'int32' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( x, 0, 2, y, value ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function (thisArg)', function test( t ) { + var values; + var i; + var x; + var y; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + y = zeros( [], { + 'dtype': 'int32' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( x, 0, 2, y, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function (options)', function test( t ) { + var values; + var i; + var x; + var y; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + y = zeros( [], { + 'dtype': 'int32' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( x, 0, 2, y, {}, value ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function (options, thisArg)', function test( t ) { + var values; + var i; + var x; + var y; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + y = zeros( [], { + 'dtype': 'int32' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( x, 0, 2, y, {}, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + y = zeros( [], opts ); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( x, 0, 2, y, value, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (thisArg)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + y = zeros( [], opts ); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( x, 0, 2, y, value, clbk, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a `fromIndex` argument which is not an ndarray-like object or an integer', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + y = zeros( [ 2 ], { + 'dtype': 'generic' + }); + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( x, value, 2, y, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a `fromIndex` argument which is not an ndarray-like object or an integer (options)', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + y = zeros( [ 2 ], { + 'dtype': 'generic' + }); + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( x, value, 2, y, {}, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a `toIndex` argument which is not an ndarray-like object or an integer', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + y = zeros( [ 2 ], { + 'dtype': 'generic' + }); + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( x, 0, value, y, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a `toIndex` argument which is not an ndarray-like object or an integer (options)', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + y = zeros( [ 2 ], { + 'dtype': 'generic' + }); + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( x, 0, value, y, {}, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided insufficient number of arguments', function test( t ) { + var x; + var y; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + y = zeros( [], { + 'dtype': 'int32' + }); + + t.throws( badValue1, TypeError, 'throws an error when provided insufficient arguments' ); + t.throws( badValue2, TypeError, 'throws an error when provided insufficient arguments' ); + t.throws( badValue3, TypeError, 'throws an error when provided insufficient arguments' ); + t.throws( badValue4, TypeError, 'throws an error when provided insufficient arguments' ); + t.end(); + + function badValue1() { + findIndexBetween( x ); + } + + function badValue2() { + findIndexBetween( x, 0 ); + } + + function badValue3() { + findIndexBetween( x, 0, 2, y ); + } + + function badValue4() { + findIndexBetween(); + } +}); + +tape( 'the function throws an error if provided a `dim` option which is not an integer', function test( t ) { + var options; + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + y = zeros( [], opts ); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + options = { + 'dim': value + }; + findIndexBetween( x, 0, 2, y, options, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a `dim` option which is not an integer (thisArg)', function test( t ) { + var options; + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + y = zeros( [], opts ); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + options = { + 'dim': value + }; + findIndexBetween( x, 0, 2, y, options, clbk, {} ); + }; + } +}); + +tape( 'the function returns the index of the first element which passes a test (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = findIndexBetween( x, 0, 2, y, clbk ); + expected = [ 1, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element which passes a test (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = findIndexBetween( x, 0, 2, y, clbk ); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an operation dimension (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var opts; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + opts = { + 'dim': 0 + }; + + actual = findIndexBetween( x, 0, 2, y, opts, clbk ); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + opts = { + 'dim': 1 + }; + + actual = findIndexBetween( x, 0, 2, y, opts, clbk ); + expected = [ 1, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an operation dimension (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var opts; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + opts = { + 'dim': 0 + }; + + actual = findIndexBetween( x, 0, 2, y, opts, clbk ); + expected = [ 1, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + opts = { + 'dim': 1 + }; + + actual = findIndexBetween( x, 0, 2, y, opts, clbk ); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a starting and ending search index (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ 1.0, 2.0, 4.0, -3.0, 6.0, -5.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = findIndexBetween( x, 1, 3, y, clbk ); + expected = [ 1, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a starting and ending search index (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ 1.0, -3.0, 2.0, 6.0, 4.0, -5.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 3 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = findIndexBetween( x, 1, 3, y, clbk ); + expected = [ 1, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a starting and ending search index (scalar, options)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ 1.0, 2.0, 4.0, -3.0, 6.0, -5.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = findIndexBetween( x, 1, 3, y, {}, clbk ); + expected = [ 1, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a starting and ending search index (0d ndarray)', function test( t ) { + var expected; + var fromIdx; + var actual; + var toIdx; + var xbuf; + var x; + var y; + + xbuf = [ 1.0, 2.0, 4.0, -3.0, 6.0, -5.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + fromIdx = scalar2ndarray( 1, { + 'dtype': 'generic' + }); + toIdx = scalar2ndarray( 3, { + 'dtype': 'generic' + }); + actual = findIndexBetween( x, fromIdx, toIdx, y, clbk ); + expected = [ 1, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a starting and ending search index (0d ndarray, options)', function test( t ) { + var expected; + var fromIdx; + var actual; + var toIdx; + var xbuf; + var x; + var y; + + xbuf = [ 1.0, 2.0, 4.0, -3.0, 6.0, -5.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + fromIdx = scalar2ndarray( 1, { + 'dtype': 'int32' + }); + toIdx = scalar2ndarray( 3, { + 'dtype': 'int32' + }); + actual = findIndexBetween( x, fromIdx, toIdx, y, {}, clbk ); + expected = [ 1, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a starting and ending search index (scalar, broadcasted)', function test( t ) { + var expected; + var actual; + var opts; + var xbuf; + var x; + var y; + + xbuf = [ 1.0, 2.0, 4.0, -3.0, 6.0, -5.0 ]; + x = new ndarray( 'generic', xbuf, [ 3, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + opts = { + 'dim': 0 + }; + actual = findIndexBetween( x, 1, 3, y, opts, clbk ); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a starting and ending search index (0d ndarray, broadcasted)', function test( t ) { + var expected; + var fromIdx; + var actual; + var toIdx; + var opts; + var xbuf; + var x; + var y; + + xbuf = [ 1.0, 2.0, 4.0, -3.0, 6.0, -5.0 ]; + x = new ndarray( 'generic', xbuf, [ 3, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + fromIdx = scalar2ndarray( 1, { + 'dtype': 'int32' + }); + toIdx = scalar2ndarray( 3, { + 'dtype': 'int32' + }); + opts = { + 'dim': 0 + }; + actual = findIndexBetween( x, fromIdx, toIdx, y, opts, clbk ); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a starting and ending search index (1d ndarray)', function test( t ) { + var expected; + var fromIdx; + var actual; + var toIdx; + var opts; + var xbuf; + var x; + var y; + + xbuf = [ 1.0, 2.0, 4.0, -3.0, 6.0, -5.0 ]; + x = new ndarray( 'generic', xbuf, [ 3, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + fromIdx = new ndarray( 'generic', [ 1, 0 ], [ 2 ], [ 1 ], 0, 'row-major' ); + toIdx = new ndarray( 'generic', [ 3, 3 ], [ 2 ], [ 1 ], 0, 'row-major' ); + opts = { + 'dim': 0 + }; + actual = findIndexBetween( x, fromIdx, toIdx, y, opts, clbk ); + expected = [ 1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing an execution context', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var actual; + var xbuf; + var ctx; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + ctx = { + 'count': 0 + }; + + values = []; + indices = []; + arrays = []; + + actual = findIndexBetween( x, 0, 2, y, clbk1, ctx ); + expected = [ 1, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + expected = [ + -1.0, + 2.0, + -3.0, + 4.0 + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 0, 1 ], + [ 1, 0 ], + [ 1, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x, + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function clbk1( 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; + } +}); diff --git a/lib/node_modules/@stdlib/blas/ext/find-index-between/test/test.js b/lib/node_modules/@stdlib/blas/ext/find-index-between/test/test.js new file mode 100644 index 000000000000..0ec22b403f7e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index-between/test/test.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR 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 isMethod = require( '@stdlib/assert/is-method' ); +var findIndexBetween = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof findIndexBetween, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( findIndexBetween, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/find-index-between/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/find-index-between/test/test.main.js new file mode 100644 index 000000000000..c0dbd4713693 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index-between/test/test.main.js @@ -0,0 +1,1062 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var findIndexBetween = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @param {number} v - input value +* @returns {boolean} result +*/ +function clbk( v ) { + return v % 2.0 === 0.0; +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof findIndexBetween, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( value, 0, 2, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (thisArg)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( value, 0, 2, clbk, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( value, 0, 2, {}, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options, thisArg)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( value, 0, 2, {}, clbk, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a zero-dimensional input ndarray-like object', function test( t ) { + var values; + var i; + + values = [ + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( zeros( value ), 0, 1, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( x, 0, 2, value ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function (thisArg)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( x, 0, 2, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function (options)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( x, 0, 2, {}, value ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function (options, thisArg)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( x, 0, 2, {}, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( x, 0, 2, value, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (thisArg)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( x, 0, 2, value, clbk, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a `fromIndex` argument which is not an ndarray-like object or an integer', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( x, value, 2, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a `fromIndex` argument which is not an ndarray-like object or an integer (thisArg)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( x, value, 2, clbk, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a `toIndex` argument which is not an ndarray-like object or an integer', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( x, 0, value, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a `toIndex` argument which is not an ndarray-like object or an integer (thisArg)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + findIndexBetween( x, 0, value, clbk, {} ); + }; + } +}); + +tape( 'the function throws an error if provided insufficient number of arguments', function test( t ) { + var x; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + t.throws( badValue1, TypeError, 'throws an error when provided insufficient arguments' ); + t.throws( badValue2, TypeError, 'throws an error when provided insufficient arguments' ); + t.throws( badValue3, TypeError, 'throws an error when provided insufficient arguments' ); + t.end(); + + function badValue1() { + findIndexBetween( x ); + } + + function badValue2() { + findIndexBetween( x, 0 ); + } + + function badValue3() { + findIndexBetween(); + } +}); + +tape( 'the function throws an error if provided a `dtype` option which is not a supported data type', function test( t ) { + var values; + var opts; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + 'bool', + 'complex64', + 'complex128', + 'boop' + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dtype': value + }; + findIndexBetween( x, 0, 2, opts, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a `dtype` option which is not a supported data type (thisArg)', function test( t ) { + var values; + var opts; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + 'bool', + 'complex64', + 'complex128', + 'boop' + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dtype': value + }; + findIndexBetween( x, 0, 2, opts, clbk, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a `dim` option which is not an integer', function test( t ) { + var values; + var opts; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dim': value + }; + findIndexBetween( x, 0, 2, opts, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a `dim` option which is not an integer (thisArg)', function test( t ) { + var values; + var opts; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dim': value + }; + findIndexBetween( x, 0, 2, opts, clbk, {} ); + }; + } +}); + +tape( 'the function returns the index of the first element which passes a test (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = findIndexBetween( x, 0, 2, clbk ); + expected = [ 1, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element which passes a test (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = findIndexBetween( x, 0, 2, clbk ); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the operation dimension (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var opts; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + opts = { + 'dim': 0 + }; + + actual = findIndexBetween( x, 0, 2, opts, clbk ); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + opts = { + 'dim': 1 + }; + + actual = findIndexBetween( x, 0, 2, opts, clbk ); + expected = [ 1, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the operation dimension (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var opts; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + opts = { + 'dim': 0 + }; + + actual = findIndexBetween( x, 0, 2, opts, clbk ); + expected = [ 1, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + opts = { + 'dim': 1 + }; + + actual = findIndexBetween( x, 0, 2, opts, clbk ); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports whether to keep reduced dimensions as singleton dimensions', function test( t ) { + var expected; + var actual; + var xbuf; + var opts; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + opts = { + 'keepdims': true + }; + + actual = findIndexBetween( x, 0, 2, opts, clbk ); + expected = [ [ 1 ], [ 1 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 1 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the output array data type', function test( t ) { + var expected; + var actual; + var xbuf; + var opts; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + opts = { + 'dtype': 'int32' + }; + + actual = findIndexBetween( x, 0, 2, opts, clbk ); + expected = [ 1, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'int32', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a starting search index (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 4.0, -3.0, 6.0, -5.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + actual = findIndexBetween( x, 1, 3, clbk ); + expected = [ 1, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a starting search index (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, -3.0, 2.0, 6.0, 4.0, -5.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 3 ], [ 1, 2 ], 0, 'column-major' ); + + actual = findIndexBetween( x, 1, 3, clbk ); + expected = [ 1, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a starting search index (scalar, options)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 4.0, -3.0, 6.0, -5.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + actual = findIndexBetween( x, 1, 3, {}, clbk ); + expected = [ 1, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a starting and ending search index (0d ndarray)', function test( t ) { + var expected; + var fromIdx; + var actual; + var toIdx; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 4.0, -3.0, 6.0, -5.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + fromIdx = scalar2ndarray( 1, { + 'dtype': 'generic' + }); + toIdx = scalar2ndarray( 3, { + 'dtype': 'generic' + }); + actual = findIndexBetween( x, fromIdx, toIdx, clbk ); + expected = [ 1, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a starting and ending search index (0d ndarray, options)', function test( t ) { + var expected; + var fromIdx; + var actual; + var toIdx; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 4.0, -3.0, 6.0, -5.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + fromIdx = scalar2ndarray( 1, { + 'dtype': 'int32' + }); + toIdx = scalar2ndarray( 3, { + 'dtype': 'int32' + }); + actual = findIndexBetween( x, fromIdx, toIdx, {}, clbk ); + expected = [ 1, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a starting and ending search index (scalar, broadcasted)', function test( t ) { + var expected; + var actual; + var opts; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 4.0, -3.0, 6.0, -5.0 ]; + x = new ndarray( 'generic', xbuf, [ 3, 2 ], [ 2, 1 ], 0, 'row-major' ); + + opts = { + 'dim': 0 + }; + actual = findIndexBetween( x, 1, 3, opts, clbk ); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a starting and ending search index (0d ndarray, broadcasted)', function test( t ) { + var expected; + var fromIdx; + var actual; + var toIdx; + var opts; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 4.0, -3.0, 6.0, -5.0 ]; + x = new ndarray( 'generic', xbuf, [ 3, 2 ], [ 2, 1 ], 0, 'row-major' ); + + fromIdx = scalar2ndarray( 1, { + 'dtype': 'int32' + }); + toIdx = scalar2ndarray( 3, { + 'dtype': 'int32' + }); + opts = { + 'dim': 0 + }; + actual = findIndexBetween( x, fromIdx, toIdx, opts, clbk ); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a starting and ending search index (1d ndarray)', function test( t ) { + var expected; + var fromIdx; + var actual; + var toIdx; + var opts; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 4.0, -3.0, 6.0, -5.0 ]; + x = new ndarray( 'generic', xbuf, [ 3, 2 ], [ 2, 1 ], 0, 'row-major' ); + + fromIdx = new ndarray( 'generic', [ 1, 0 ], [ 2 ], [ 1 ], 0, 'row-major' ); + toIdx = new ndarray( 'generic', [ 3, 3 ], [ 2 ], [ 1 ], 0, 'row-major' ); + opts = { + 'dim': 0 + }; + actual = findIndexBetween( x, fromIdx, toIdx, opts, clbk ); + expected = [ 1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing an execution context', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var actual; + var xbuf; + var ctx; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + ctx = { + 'count': 0 + }; + + values = []; + indices = []; + arrays = []; + + actual = findIndexBetween( x, 0, 2, clbk1, ctx ); + expected = [ 1, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + expected = [ + -1.0, + 2.0, + -3.0, + 4.0 + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 0, 1 ], + [ 1, 0 ], + [ 1, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x, + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function clbk1( 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; + } +}); From 368ed6b063661f694b3d00b3631940b6d2f5ee2d Mon Sep 17 00:00:00 2001 From: headlessNode Date: Tue, 29 Sep 2026 13:47:09 +0500 Subject: [PATCH 2/3] fix: lint err --- .../@stdlib/blas/ext/find-index-between/README.md | 4 ++++ .../@stdlib/blas/ext/find-index-between/lib/index.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/find-index-between/README.md b/lib/node_modules/@stdlib/blas/ext/find-index-between/README.md index b325ba0f456d..420f7fc05754 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-index-between/README.md +++ b/lib/node_modules/@stdlib/blas/ext/find-index-between/README.md @@ -175,8 +175,12 @@ var dt = String( dtype( idx ) ); // returns 'generic' ``` + + #### findIndexBetween.assign( x, fromIndex, toIndex, out\[, options], clbk\[, thisArg] ) + + Returns the index of the first element along an [ndarray][@stdlib/ndarray/ctor] dimension which passes a test implemented by a predicate function within a specified range and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor]. ```javascript diff --git a/lib/node_modules/@stdlib/blas/ext/find-index-between/lib/index.js b/lib/node_modules/@stdlib/blas/ext/find-index-between/lib/index.js index 47fcf0ccfc21..aed6703f966e 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-index-between/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/find-index-between/lib/index.js @@ -75,7 +75,7 @@ * * // Perform operation: * var out = findIndexBetween( x, 0, 2, isEven ); -* // returns [ 0, 1 ] +* // returns [ 0, 0 ] */ // MODULES // From 80337f092056b948d45d47e685b8f902e80aee9c Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 29 Sep 2026 22:39:31 -0700 Subject: [PATCH 3/3] test: update assertions Signed-off-by: Athan --- .../find-index-between/test/test.assign.js | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/find-index-between/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/find-index-between/test/test.assign.js index 0acebef51d6b..9a338e78c83c 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-index-between/test/test.assign.js +++ b/lib/node_modules/@stdlib/blas/ext/find-index-between/test/test.assign.js @@ -830,7 +830,7 @@ tape( 'the function returns the index of the first element which passes a test ( t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( ( y === actual ), true, 'returns expected value' ); + t.strictEqual( y, actual, 'returns expected value' ); t.end(); }); @@ -857,7 +857,7 @@ tape( 'the function returns the index of the first element which passes a test ( t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( ( y === actual ), true, 'returns expected value' ); + t.strictEqual( y, actual, 'returns expected value' ); t.end(); }); @@ -888,7 +888,7 @@ tape( 'the function supports specifying an operation dimension (row-major)', fun t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( ( y === actual ), true, 'returns expected value' ); + t.strictEqual( y, actual, 'returns expected value' ); y = zeros( [ 2 ], { 'dtype': 'generic', @@ -906,7 +906,7 @@ tape( 'the function supports specifying an operation dimension (row-major)', fun t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( ( y === actual ), true, 'returns expected value' ); + t.strictEqual( y, actual, 'returns expected value' ); t.end(); }); @@ -937,7 +937,7 @@ tape( 'the function supports specifying an operation dimension (column-major)', t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( ( y === actual ), true, 'returns expected value' ); + t.strictEqual( y, actual, 'returns expected value' ); xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); @@ -957,7 +957,7 @@ tape( 'the function supports specifying an operation dimension (column-major)', t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( ( y === actual ), true, 'returns expected value' ); + t.strictEqual( y, actual, 'returns expected value' ); t.end(); }); @@ -981,7 +981,7 @@ tape( 'the function supports specifying a starting and ending search index (row- t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( ( y === actual ), true, 'returns expected value' ); + t.strictEqual( y, actual, 'returns expected value' ); t.end(); }); @@ -1005,7 +1005,7 @@ tape( 'the function supports specifying a starting and ending search index (colu t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( ( y === actual ), true, 'returns expected value' ); + t.strictEqual( y, actual, 'returns expected value' ); t.end(); }); @@ -1029,7 +1029,7 @@ tape( 'the function supports specifying a starting and ending search index (scal t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( ( y === actual ), true, 'returns expected value' ); + t.strictEqual( y, actual, 'returns expected value' ); t.end(); }); @@ -1061,7 +1061,7 @@ tape( 'the function supports specifying a starting and ending search index (0d n t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( ( y === actual ), true, 'returns expected value' ); + t.strictEqual( y, actual, 'returns expected value' ); t.end(); }); @@ -1093,7 +1093,7 @@ tape( 'the function supports specifying a starting and ending search index (0d n t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( ( y === actual ), true, 'returns expected value' ); + t.strictEqual( y, actual, 'returns expected value' ); t.end(); }); @@ -1121,7 +1121,7 @@ tape( 'the function supports specifying a starting and ending search index (scal t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( ( y === actual ), true, 'returns expected value' ); + t.strictEqual( y, actual, 'returns expected value' ); t.end(); }); @@ -1157,7 +1157,7 @@ tape( 'the function supports specifying a starting and ending search index (0d n t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( ( y === actual ), true, 'returns expected value' ); + t.strictEqual( y, actual, 'returns expected value' ); t.end(); }); @@ -1189,7 +1189,7 @@ tape( 'the function supports specifying a starting and ending search index (1d n t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( ( y === actual ), true, 'returns expected value' ); + t.strictEqual( y, actual, 'returns expected value' ); t.end(); }); @@ -1227,7 +1227,7 @@ tape( 'the function supports providing an execution context', function test( t ) t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( ( y === actual ), true, 'returns expected value' ); + t.strictEqual( y, actual, 'returns expected value' ); t.strictEqual( ctx.count, 4, 'returns expected value' ); expected = [