From 15f3d02ea9ecb104cf3ed5e48a2b1970246c0bba Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Tue, 5 Aug 2025 13:49:36 +0000 Subject: [PATCH 01/12] feat: add blas/ext/find-index --- .../@stdlib/blas/ext/find-index/README.md | 312 ++++++++ .../find-index/benchmark/benchmark.assign.js | 124 ++++ .../ext/find-index/benchmark/benchmark.js | 116 +++ .../@stdlib/blas/ext/find-index/docs/repl.txt | 116 +++ .../blas/ext/find-index/docs/types/index.d.ts | 276 +++++++ .../blas/ext/find-index/docs/types/test.ts | 405 ++++++++++ .../blas/ext/find-index/examples/index.js | 48 ++ .../@stdlib/blas/ext/find-index/lib/assign.js | 171 +++++ .../@stdlib/blas/ext/find-index/lib/base.js | 96 +++ .../@stdlib/blas/ext/find-index/lib/index.js | 74 ++ .../@stdlib/blas/ext/find-index/lib/main.js | 164 +++++ .../@stdlib/blas/ext/find-index/package.json | 62 ++ .../blas/ext/find-index/test/test.assign.js | 694 ++++++++++++++++++ .../@stdlib/blas/ext/find-index/test/test.js | 39 + .../blas/ext/find-index/test/test.main.js | 680 +++++++++++++++++ 15 files changed, 3377 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index/benchmark/benchmark.assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index/lib/assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index/lib/base.js create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index/test/test.assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/find-index/test/test.main.js diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/README.md b/lib/node_modules/@stdlib/blas/ext/find-index/README.md new file mode 100644 index 000000000000..4a5efbf2c953 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index/README.md @@ -0,0 +1,312 @@ + + +# findIndex + +> Return the first index of an element along an [ndarray][@stdlib/ndarray/ctor] dimension which passes a test implemented by a predicate function. + +
+ +## Usage + +```javascript +var findIndex = require( '@stdlib/blas/ext/find-index' ); +``` + +#### findIndex( x\[, options], clbk\[, thisArg] ) + +Returns the first index of an element along an [ndarray][@stdlib/ndarray/ctor] dimension which passes a test implemented by a predicate function. + +```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, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +// returns + +// Perform operation: +var out = findIndex( x, isEven ); +// returns + +var idx = out.get(); +// returns 1 +``` + +The function has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have at least one dimension. +- **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( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + +var ctx = { + 'count': 0 +}; +var out = findIndex( x, isEven, ctx ); +// returns + +var idx = out.get(); +// returns 1 + +var count = ctx.count; +// returns 2 +``` + +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] 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 = findIndex( x, isEven ); +// returns + +var idx = out.get(); +// 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 ndarray2array = require( '@stdlib/ndarray/to-array' ); +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 = findIndex( x, opts, isEven ); +// returns + +var idx = ndarray2array( out ); +// returns [ 1, -1 ] +``` + +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' ); +var ndarray2array = require( '@stdlib/ndarray/to-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 = findIndex( x, opts, isEven ); +// returns + +var idx = ndarray2array( out ); +// returns [ [ 1, -1 ] ] +``` + +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 ndarray2array = require( '@stdlib/ndarray/to-array' ); +var dtype = require( '@stdlib/ndarray/dtype' ); +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 = { + 'dtype': 'generic' +}; + +var idx = findIndex( x, opts, isEven ); +// returns + +var dt = dtype( idx ); +// returns 'generic' +``` + +#### findIndex.assign( x, out\[, options], clbk\[, thisArg] ) + +Returns the first index of an element along an [ndarray][@stdlib/ndarray/ctor] dimension which passes a test implemented by a predicate function 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( [ 1.0, 2.0, 3.0, 4.0 ] ); +var y = zeros( [], { + 'dtype': 'int32' +}); + +var out = findIndex.assign( x, y, isEven ); +// returns + +var idx = out.get(); +// returns 1 + +var bool = ( out === y ); +// returns true +``` + +The method has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have at least one dimension. +- **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/array/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var findIndex = require( '@stdlib/blas/ext/find-index' ); + +// Define a callback function: +function isEven( v ) { + return v % 2.0 === 0.0; +} + +// Generate an array of random numbers: +var xbuf = discreteUniform( 10, 0, 20, { + 'dtype': 'generic' +}); + +// Wrap in an ndarray: +var x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var opts = { + 'dim': 0 +}; + +// Perform operation: +var idx = findIndex( x, opts, isEven ); + +// Print the results: +console.log( ndarray2array( idx ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/blas/ext/find-index/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..6056ce16ec0a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index/benchmark/benchmark.assign.js @@ -0,0 +1,124 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var indexOf = 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 ); + x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' ); + + 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 = indexOf.assign( x, 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( pkg+':assign:dtype='+options.dtype+',len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/find-index/benchmark/benchmark.js new file mode 100644 index 000000000000..d922cf4abd75 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index/benchmark/benchmark.js @@ -0,0 +1,116 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'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/array/uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var findIndex = 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 ); + x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' ); + + 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 = findIndex( x, 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( pkg+':dtype='+options.dtype+',len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/find-index/docs/repl.txt new file mode 100644 index 000000000000..1180330b5cf1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index/docs/repl.txt @@ -0,0 +1,116 @@ + +{{alias}}( x[, options], clbk[, thisArg] ) + Returns the first index of an element along an ndarray dimension which + passes a test implemented by a predicate function. + + 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 passes a test implemented by the predicate + function, the corresponding element in the returned ndarray is `-1`. + + Parameters + ---------- + x: ndarray + Input array. Must at least have one dimension. + + options: Object (optional) + Function options. + + options.dtype: string (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, clbk ); + > var v = y.get() + 1 + + +{{alias}}.assign( x, out[, options], clbk[, thisArg] ) + Returns the first index of an element along an ndarray dimension which + passes a test implemented by a predicate function 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 passes a test implemented by the predicate + function, the corresponding element in the returned ndarray is `-1`. + + Parameters + ---------- + x: ndarray + Input array. Must at least have one dimension. + + 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}}( [] ); + > function clbk( v ) { return v % 2.0 === 0.0; }; + > var y = {{alias}}.assign( x, out, clbk ) + + > var bool = ( out === y ) + true + > var v = out.get() + 1 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/find-index/docs/types/index.d.ts new file mode 100644 index 000000000000..ff26f303a623 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index/docs/types/index.d.ts @@ -0,0 +1,276 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { IntegerIndexAndGenericDataType as DataType, typedndarray } from '@stdlib/types/ndarray'; + +/** +* Input array. +*/ +type InputArray = typedndarray; + +/** +* Output array. +*/ +type OutputArray = typedndarray; + +/** +* Returns the result of callback function. +* +* @returns result +*/ +type NullaryCallback = ( this: ThisArg ) => boolean; + +/** +* Returns the result of callback function. +* +* @param value - current array element +* @returns result +*/ +type UnaryCallback = ( this: ThisArg, value: T ) => boolean; + +/** +* Returns the result of callback function. +* +* @param value - current array element +* @param index - current array element index +* @returns result +*/ +type BinaryCallback = ( this: ThisArg, value: T, index: number ) => boolean; + +/** +* Returns the result of callback function. +* +* @param value - current array element +* @param index - current array element index +* @param array - input ndarray +* @returns result +*/ +type TernaryCallback = ( this: ThisArg, value: T, index: number, array: U ) => boolean; + +/** +* Returns the result of callback function. +* +* @param value - current array element +* @param index - current array element index +* @param array - input ndarray +* @returns result +*/ +type Callback = NullaryCallback | UnaryCallback | BinaryCallback | TernaryCallback; + +/** +* 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 `findIndex` +*/ +interface FindIndex { + /** + * Returns the first index of an element along an ndarray dimension which passes a test implemented by a predicate function. + * + * @param x - input ndarray + * @param clbk - callback function + * @param thisArg - callback 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( [ -1.0, 2.0, -3.0 ] ); + * + * var y = findIndex( x, clbk ); + * // returns + * + * var v = y.get(); + * // returns 1 + */ + = InputArray, ThisArg = unknown>( x: U, clbk: Callback, thisArg?: ThisParameterType> ): OutputArray; + + /** + * Returns the first index of an element along an ndarray dimension which passes a test implemented by a predicate function. + * + * @param x - input ndarray + * @param options - function options + * @param clbk - callback function + * @param thisArg - callback 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( [ -1.0, 2.0, -3.0 ] ); + * + * var y = findIndex( x, {}, clbk ); + * // returns + * + * var v = y.get(); + * // returns 1 + */ + = InputArray, ThisArg = unknown>( x: U, options: Options, clbk: Callback, thisArg?: ThisParameterType> ): OutputArray; + + /** + * Returns the first index of an element along an ndarray dimension which passes a test implemented by a predicate function and assigns results to a provided output ndarray. + * + * @param x - input ndarray + * @param out - output ndarray + * @param clbk - callback function + * @param thisArg - callback function execution context + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * var zeros = require( '@stdlib/ndarray/zeros' ); + * + * var x = array( [ -1.0, 2.0, -3.0 ] ); + * var y = zeros( [] ); + * + * function clbk( value ) { + * return value % 2.0 === 0.0; + * } + * + * var out = findIndex.assign( x, y, clbk ); + * // returns + * + * var v = out.get(); + * // returns 1 + * + * var bool = ( out === y ); + * // returns true + */ + assign = InputArray, V extends OutputArray = OutputArray, ThisArg = unknown>( x: U, out: V, clbk: Callback, thisArg?: ThisParameterType> ): V; + + /** + * Returns the first index of an element along an ndarray dimension which passes a test implemented by a predicate function and assigns results to a provided output ndarray. + * + * @param x - input ndarray + * @param out - output ndarray + * @param options - function options + * @param clbk - callback function + * @param thisArg - callback function execution context + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * var zeros = require( '@stdlib/ndarray/zeros' ); + * + * var x = array( [ -1.0, 2.0, -3.0 ] ); + * var y = zeros( [] ); + * + * function clbk( value ) { + * return value % 2.0 === 0.0; + * } + * + * var out = findIndex.assign( x, y, {}, clbk ); + * // returns + * + * var v = out.get(); + * // returns 1 + * + * var bool = ( out === y ); + * // returns true + */ + assign = InputArray, V extends OutputArray = OutputArray, ThisArg = unknown>( x: U, out: V, options: BaseOptions, clbk: Callback, thisArg?: ThisParameterType> ): V; +} + +/** +* Returns the first index of an element along an ndarray dimension which passes a test implemented by a predicate function and assigns results to a provided output ndarray. +* +* @param x - input ndarray +* @param options - function options +* @param clbk - callback function +* @param thisArg - callback execution context +* @returns output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ -1.0, 2.0, -3.0 ] ) +* +* function clbk( value ) { +* return value % 2.0 === 0.0; +* } +* +* var y = findIndex( x, clbk ); +* // returns +* +* var v = y.get(); +* // returns 1 +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* +* var x = array( [ -1.0, 2.0, -3.0 ] ) +* var y = zeros( [] ); +* +* function clbk( value ) { +* return value % 2.0 === 0.0; +* } +* +* var out = findIndex.assign( x, y, clbk ); +* // returns +* +* var v = out.get(); +* // returns 1 +* +* var bool = ( out === y ); +* // returns true +*/ +declare const findIndex: FindIndex; + + +// EXPORTS // + +export = findIndex; diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/find-index/docs/types/test.ts new file mode 100644 index 000000000000..0e7446ceaa9c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index/docs/types/test.ts @@ -0,0 +1,405 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable @typescript-eslint/no-unused-expressions, space-in-parens */ + +/// + +import zeros = require( '@stdlib/ndarray/zeros' ); +import findIndex = 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' + }); + + findIndex( x, clbk ); // $ExpectType OutputArray + findIndex( x, clbk, {} ); // $ExpectType OutputArray + + findIndex( x, {}, clbk ); // $ExpectType OutputArray + findIndex( x, {}, clbk, {} ); // $ExpectType OutputArray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + findIndex( '5', clbk ); // $ExpectError + findIndex( 5, clbk ); // $ExpectError + findIndex( true, clbk ); // $ExpectError + findIndex( false, clbk ); // $ExpectError + findIndex( null, clbk ); // $ExpectError + findIndex( void 0, clbk ); // $ExpectError + findIndex( {}, clbk ); // $ExpectError + findIndex( ( x: number ): number => x, clbk ); // $ExpectError + + findIndex( '5', clbk, {} ); // $ExpectError + findIndex( 5, clbk, {} ); // $ExpectError + findIndex( true, clbk, {} ); // $ExpectError + findIndex( false, clbk, {} ); // $ExpectError + findIndex( null, clbk, {} ); // $ExpectError + findIndex( void 0, clbk, {} ); // $ExpectError + findIndex( {}, clbk, {} ); // $ExpectError + findIndex( ( x: number ): number => x, clbk, {} ); // $ExpectError + + findIndex( '5', {}, clbk ); // $ExpectError + findIndex( 5, {}, clbk ); // $ExpectError + findIndex( true, {}, clbk ); // $ExpectError + findIndex( false, {}, clbk ); // $ExpectError + findIndex( null, {}, clbk ); // $ExpectError + findIndex( void 0, {}, clbk ); // $ExpectError + findIndex( {}, {}, clbk ); // $ExpectError + findIndex( ( x: number ): number => x, {}, clbk ); // $ExpectError + + findIndex( '5', {}, clbk, {} ); // $ExpectError + findIndex( 5, {}, clbk, {} ); // $ExpectError + findIndex( true, {}, clbk, {} ); // $ExpectError + findIndex( false, {}, clbk, {} ); // $ExpectError + findIndex( null, {}, clbk, {} ); // $ExpectError + findIndex( void 0, {}, clbk, {} ); // $ExpectError + findIndex( {}, {}, clbk, {} ); // $ExpectError + findIndex( ( x: number ): number => x, {}, 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' + }); + + findIndex( x, '5', clbk ); // $ExpectError + findIndex( x, true, clbk ); // $ExpectError + findIndex( x, false, clbk ); // $ExpectError + findIndex( x, null, clbk ); // $ExpectError + findIndex( x, [], clbk ); // $ExpectError + + findIndex( x, '5', clbk, {} ); // $ExpectError + findIndex( x, true, clbk, {} ); // $ExpectError + findIndex( x, false, clbk, {} ); // $ExpectError + findIndex( x, null, clbk, {} ); // $ExpectError + findIndex( x, [], 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' + }); + + findIndex( x, '5' ); // $ExpectError + findIndex( x, true ); // $ExpectError + findIndex( x, false ); // $ExpectError + findIndex( x, null ); // $ExpectError + findIndex( x, [] ); // $ExpectError + + findIndex( x, '5', {} ); // $ExpectError + findIndex( x, true, {} ); // $ExpectError + findIndex( x, false, {} ); // $ExpectError + findIndex( x, null, {} ); // $ExpectError + findIndex( x, [], {} ); // $ExpectError + + findIndex( x, {}, '5', {} ); // $ExpectError + findIndex( x, {}, true, {} ); // $ExpectError + findIndex( x, {}, false, {} ); // $ExpectError + findIndex( x, {}, null, {} ); // $ExpectError + findIndex( x, {}, [], {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dtype` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + findIndex( x, { 'dtype': '5' }, clbk ); // $ExpectError + findIndex( x, { 'dtype': 5 }, clbk ); // $ExpectError + findIndex( x, { 'dtype': true }, clbk ); // $ExpectError + findIndex( x, { 'dtype': false }, clbk ); // $ExpectError + findIndex( x, { 'dtype': null }, clbk ); // $ExpectError + findIndex( x, { 'dtype': [] }, clbk ); // $ExpectError + findIndex( x, { 'dtype': {} }, clbk ); // $ExpectError + findIndex( x, { 'dtype': ( x: number ): number => x }, clbk ); // $ExpectError + + findIndex( x, { 'dtype': '5' }, clbk, {} ); // $ExpectError + findIndex( x, { 'dtype': 5 }, clbk, {} ); // $ExpectError + findIndex( x, { 'dtype': true }, clbk, {} ); // $ExpectError + findIndex( x, { 'dtype': false }, clbk, {} ); // $ExpectError + findIndex( x, { 'dtype': null }, clbk, {} ); // $ExpectError + findIndex( x, { 'dtype': [] }, clbk, {} ); // $ExpectError + findIndex( x, { 'dtype': {} }, clbk, {} ); // $ExpectError + findIndex( x, { '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' + }); + + findIndex( x, { 'keepdims': '5' }, clbk ); // $ExpectError + findIndex( x, { 'keepdims': 5 }, clbk ); // $ExpectError + findIndex( x, { 'keepdims': null }, clbk ); // $ExpectError + findIndex( x, { 'keepdims': [] }, clbk ); // $ExpectError + findIndex( x, { 'keepdims': {} }, clbk ); // $ExpectError + findIndex( x, { 'keepdims': ( x: number ): number => x }, clbk ); // $ExpectError + + findIndex( x, { 'keepdims': '5' }, clbk, {} ); // $ExpectError + findIndex( x, { 'keepdims': 5 }, clbk, {} ); // $ExpectError + findIndex( x, { 'keepdims': null }, clbk, {} ); // $ExpectError + findIndex( x, { 'keepdims': [] }, clbk, {} ); // $ExpectError + findIndex( x, { 'keepdims': {} }, clbk, {} ); // $ExpectError + findIndex( x, { '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' + }); + + findIndex( x, { 'dim': '5' }, clbk ); // $ExpectError + findIndex( x, { 'dim': true }, clbk ); // $ExpectError + findIndex( x, { 'dim': false }, clbk ); // $ExpectError + findIndex( x, { 'dim': null }, clbk ); // $ExpectError + findIndex( x, { 'dim': {} }, clbk ); // $ExpectError + findIndex( x, { 'dim': ( x: number ): number => x }, clbk ); // $ExpectError + + findIndex( x, { 'dim': '5' }, clbk, {} ); // $ExpectError + findIndex( x, { 'dim': 5 }, clbk, {} ); // $ExpectError + findIndex( x, { 'dim': true }, clbk, {} ); // $ExpectError + findIndex( x, { 'dim': false }, clbk, {} ); // $ExpectError + findIndex( x, { 'dim': null }, clbk, {} ); // $ExpectError + findIndex( x, { 'dim': {} }, clbk, {} ); // $ExpectError + findIndex( x, { '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' + }); + + findIndex(); // $ExpectError + findIndex( x ); + findIndex( x, {}, 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' + }); + + findIndex.assign( x, y, clbk ); // $ExpectType int32ndarray + findIndex.assign( x, y, {}, clbk ); // $ExpectType int32ndarray + + findIndex.assign( x, y, clbk, {} ); // $ExpectType int32ndarray + findIndex.assign( x, 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' + }); + + findIndex.assign( '5', y, clbk ); // $ExpectError + findIndex.assign( 5, y, clbk ); // $ExpectError + findIndex.assign( true, y, clbk ); // $ExpectError + findIndex.assign( false, y, clbk ); // $ExpectError + findIndex.assign( null, y, clbk ); // $ExpectError + findIndex.assign( void 0, y, clbk ); // $ExpectError + findIndex.assign( {}, y, clbk ); // $ExpectError + findIndex.assign( ( x: number ): number => x, y, clbk ); // $ExpectError + + findIndex.assign( '5', y, {}, clbk ); // $ExpectError + findIndex.assign( 5, y, {}, clbk ); // $ExpectError + findIndex.assign( true, y, {}, clbk ); // $ExpectError + findIndex.assign( false, y, {}, clbk ); // $ExpectError + findIndex.assign( null, y, {}, clbk ); // $ExpectError + findIndex.assign( void 0, y, {}, clbk ); // $ExpectError + findIndex.assign( {}, y, {}, clbk ); // $ExpectError + findIndex.assign( ( x: number ): number => x, y, {}, clbk ); // $ExpectError + + findIndex.assign( '5', y, clbk, {} ); // $ExpectError + findIndex.assign( 5, y, clbk, {} ); // $ExpectError + findIndex.assign( true, y, clbk, {} ); // $ExpectError + findIndex.assign( false, y, clbk, {} ); // $ExpectError + findIndex.assign( null, y, clbk, {} ); // $ExpectError + findIndex.assign( void 0, y, clbk, {} ); // $ExpectError + findIndex.assign( {}, y, clbk, {} ); // $ExpectError + findIndex.assign( ( x: number ): number => x, y, clbk, {} ); // $ExpectError + + findIndex.assign( '5', y, {}, clbk, {} ); // $ExpectError + findIndex.assign( 5, y, {}, clbk, {} ); // $ExpectError + findIndex.assign( true, y, {}, clbk, {} ); // $ExpectError + findIndex.assign( false, y, {}, clbk, {} ); // $ExpectError + findIndex.assign( null, y, {}, clbk, {} ); // $ExpectError + findIndex.assign( void 0, y, {}, clbk, {} ); // $ExpectError + findIndex.assign( {}, y, {}, clbk, {} ); // $ExpectError + findIndex.assign( ( x: number ): number => x, y, {}, clbk, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + findIndex.assign( x, '5', clbk ); // $ExpectError + findIndex.assign( x, 5, clbk ); // $ExpectError + findIndex.assign( x, true, clbk ); // $ExpectError + findIndex.assign( x, false, clbk ); // $ExpectError + findIndex.assign( x, null, clbk ); // $ExpectError + findIndex.assign( x, void 0, clbk ); // $ExpectError + findIndex.assign( x, ( x: number ): number => x, clbk ); // $ExpectError + + findIndex.assign( x, '5', {}, clbk ); // $ExpectError + findIndex.assign( x, 5, {}, clbk ); // $ExpectError + findIndex.assign( x, true, {}, clbk ); // $ExpectError + findIndex.assign( x, false, {}, clbk ); // $ExpectError + findIndex.assign( x, null, {}, clbk ); // $ExpectError + findIndex.assign( x, void 0, {}, clbk ); // $ExpectError + findIndex.assign( x, ( x: number ): number => x, {}, clbk ); // $ExpectError + + findIndex.assign( x, '5', clbk, {} ); // $ExpectError + findIndex.assign( x, 5, clbk, {} ); // $ExpectError + findIndex.assign( x, true, clbk, {} ); // $ExpectError + findIndex.assign( x, false, clbk, {} ); // $ExpectError + findIndex.assign( x, null, clbk, {} ); // $ExpectError + findIndex.assign( x, void 0, clbk, {} ); // $ExpectError + findIndex.assign( x, ( x: number ): number => x, clbk, {} ); // $ExpectError + + findIndex.assign( x, '5', {}, clbk, {} ); // $ExpectError + findIndex.assign( x, 5, {}, clbk, {} ); // $ExpectError + findIndex.assign( x, true, {}, clbk, {} ); // $ExpectError + findIndex.assign( x, false, {}, clbk, {} ); // $ExpectError + findIndex.assign( x, null, {}, clbk, {} ); // $ExpectError + findIndex.assign( x, void 0, {}, clbk, {} ); // $ExpectError + findIndex.assign( x, ( 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' + }); + + findIndex.assign( x, y, '5', clbk ); // $ExpectError + findIndex.assign( x, y, true, clbk ); // $ExpectError + findIndex.assign( x, y, false, clbk ); // $ExpectError + findIndex.assign( x, y, null, clbk ); // $ExpectError + findIndex.assign( x, y, [], clbk ); // $ExpectError + + findIndex.assign( x, y, '5', clbk, {} ); // $ExpectError + findIndex.assign( x, y, true, clbk, {} ); // $ExpectError + findIndex.assign( x, y, false, clbk, {} ); // $ExpectError + findIndex.assign( x, y, null, clbk, {} ); // $ExpectError + findIndex.assign( x, 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' + }); + + findIndex.assign( x, y, '5' ); // $ExpectError + findIndex.assign( x, y, true ); // $ExpectError + findIndex.assign( x, y, false ); // $ExpectError + findIndex.assign( x, y, null ); // $ExpectError + findIndex.assign( x, y, [] ); // $ExpectError + + findIndex.assign( x, y, '5', {} ); // $ExpectError + findIndex.assign( x, y, true, {} ); // $ExpectError + findIndex.assign( x, y, false, {} ); // $ExpectError + findIndex.assign( x, y, null, {} ); // $ExpectError + findIndex.assign( x, y, [], {} ); // $ExpectError + + findIndex.assign( x, y, {}, '5' ); // $ExpectError + findIndex.assign( x, y, {}, true ); // $ExpectError + findIndex.assign( x, y, {}, false ); // $ExpectError + findIndex.assign( x, y, {}, null ); // $ExpectError + findIndex.assign( x, y, {}, [] ); // $ExpectError + + findIndex.assign( x, y, {}, '5', {} ); // $ExpectError + findIndex.assign( x, y, {}, true, {} ); // $ExpectError + findIndex.assign( x, y, {}, false, {} ); // $ExpectError + findIndex.assign( x, y, {}, null, {} ); // $ExpectError + findIndex.assign( x, 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' + }); + + findIndex.assign( x, y, { 'dim': '5' }, clbk ); // $ExpectError + findIndex.assign( x, y, { 'dim': true }, clbk ); // $ExpectError + findIndex.assign( x, y, { 'dim': false }, clbk ); // $ExpectError + findIndex.assign( x, y, { 'dim': null }, clbk ); // $ExpectError + findIndex.assign( x, y, { 'dim': {} }, clbk ); // $ExpectError + findIndex.assign( x, y, { 'dim': ( x: number ): number => x }, clbk ); // $ExpectError + + findIndex.assign( x, y, { 'dim': '5' }, clbk, {} ); // $ExpectError + findIndex.assign( x, y, { 'dim': true }, clbk, {} ); // $ExpectError + findIndex.assign( x, y, { 'dim': false }, clbk, {} ); // $ExpectError + findIndex.assign( x, y, { 'dim': null }, clbk, {} ); // $ExpectError + findIndex.assign( x, y, { 'dim': {} }, clbk, {} ); // $ExpectError + findIndex.assign( x, 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' + }); + + findIndex.assign(); // $ExpectError + findIndex.assign( x ); // $ExpectError + findIndex.assign( x, y ); // $ExpectError + findIndex.assign( x, y, {}, clbk, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/examples/index.js b/lib/node_modules/@stdlib/blas/ext/find-index/examples/index.js new file mode 100644 index 000000000000..3aa3921274af --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index/examples/index.js @@ -0,0 +1,48 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var findIndex = require( './../lib' ); + +// Define a callback function: +function isEven( v ) { + return v % 2.0 === 0.0; +} + +// Generate an array of random numbers: +var xbuf = discreteUniform( 10, 0, 20, { + 'dtype': 'generic' +}); + +// Wrap in an ndarray: +var x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var opts = { + 'dim': 0 +}; + +// Perform operation: +var idx = findIndex( x, opts, isEven ); + +// Print the results: +console.log( ndarray2array( idx ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/find-index/lib/assign.js new file mode 100644 index 000000000000..f635fa17b30a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index/lib/assign.js @@ -0,0 +1,171 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ).assign; + + +// MAIN // + +/** +* Returns the first index of an element along an ndarray dimension which passes a test implemented by a predicate function and assigns the results to a provided output ndarray. +* +* @param {ndarrayLike} x - input ndarray +* @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} function must be provided at least three arguments +* @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 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 ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* function isEven( v ) { +* return v % 2.0 === 0.0; +* } +* +* // Create data buffers: +* var xbuf = [ 1.0, 2.0, -3.0, 4.0, -5.0, 6.0 ]; +* +* // Define the shape of the input array: +* var shape = [ 2, 3 ]; +* +* // Define the array strides: +* var strides = [ 3, 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( [ 2 ], { +* 'dtype': 'int32' +* }); +* +* // Perform operation: +* var out = assign( x, y, isEven ); +* // returns +* +* var bool = ( out === y ); +* // returns true +* +* var arr = ndarray2array( out ); +* // returns [ -1, 1 ] +*/ +function assign( x, out ) { + var hasOptions; + var options; + var nargs; + var opts; + var ctx; + var cb; + var sh; + + nargs = arguments.length; + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. The first argument must be an ndarray. Value: `%s`.', x ) ); + } + if ( !isndarrayLike( out ) ) { + throw new TypeError( format( 'invalid argument. The second argument must be an ndarray. Value: `%s`.', out ) ); + } + if ( nargs < 3 ) { + throw new TypeError( format( 'invalid argument. Function must be provided a callback function. Value: `%s`.', arguments[ 2 ] ) ); + } + + // 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; + + // Case: assign( x, out, clbk ) + if ( nargs === 3 ) { + cb = arguments[ 1 ]; + if ( !isFunction( cb ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', cb ) ); + } + } + // Case: assign( x, out, options, clbk ) or Case: assign( x, out, clbk, thisArg ) + else if ( nargs < 5 ) { + options = arguments[ 2 ]; + cb = arguments[ 3 ]; + if ( isFunction( options ) ) { + cb = options; + ctx = cb; + } else { + if ( !isFunction( cb ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', cb ) ); + } + hasOptions = true; + } + } + // Case: assign( x, out, options, clbk, thisArg ) + else { + options = arguments[ 2 ]; + hasOptions = true; + cb = arguments[ 3 ]; + if ( !isFunction( cb ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', cb ) ); + } + ctx = arguments[ 4 ]; + } + 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; + } + } + // Resolve the list of non-reduced dimensions: + sh = getShape( x ); + if ( sh.length < 1 ) { + throw new RangeError( 'invalid argument. First argument must have at least one dimension.' ); + } + return base( x, out, opts, cb, ctx ); +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/lib/base.js b/lib/node_modules/@stdlib/blas/ext/find-index/lib/base.js new file mode 100644 index 000000000000..c076c9d8fb1d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index/lib/base.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var dtypes = require( '@stdlib/ndarray/dtypes' ); +var gfindIndex = require( '@stdlib/blas/ext/base/ndarray/gfind-index' ); +var factory = require( '@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-by-factory' ); + + +// VARIABLES // + +var idtypes = dtypes( 'all' ); +var odtypes = dtypes( 'integer_index_and_generic' ); +var policies = { + 'output': 'integer_index_and_generic', + 'casting': 'none' +}; +var table = { + 'default': gfindIndex +}; + + +// MAIN // + +/** +* Returns the first index of an element along an ndarray dimension which passes a test implemented by a predicate function. +* +* @private +* @name findIndex +* @type {Function} +* @param {ndarrayLike} x - input ndarray +* @param {Options} [options] - function options +* @param {IntegerArray} [options.dims] - list of dimensions over which to perform operation +* @param {string} [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} 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 ndarray = require( '@stdlib/ndarray/ctor' ); +* +* function isEven( v ) { +* return v % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = [ 1.0, 2.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 = findIndex( x, isEven ); +* // returns +* +* var idx = out.get(); +* // returns 1 +*/ +var findIndex = factory( table, [ idtypes ], odtypes, policies ); + + +// EXPORTS // + +module.exports = findIndex; diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/lib/index.js b/lib/node_modules/@stdlib/blas/ext/find-index/lib/index.js new file mode 100644 index 000000000000..fabbc972e68f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index/lib/index.js @@ -0,0 +1,74 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Return the first index of an along an ndarray dimension which passes a test implemented by a predicate function. +* +* @module @stdlib/blas/ext/find-index +* +* @example +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var findIndex = require( '@stdlib/blas/ext/find-index' ); +* +* function isEven( v ) { +* return v % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = [ 1.0, 2.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 = findIndex( x, isEven ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ -1, 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/lib/main.js b/lib/node_modules/@stdlib/blas/ext/find-index/lib/main.js new file mode 100644 index 000000000000..ea2e94a6af27 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index/lib/main.js @@ -0,0 +1,164 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Returns the first index of an element along an ndarray dimension which passes a test implemented by a predicate function. +* +* @param {ndarrayLike} x - input ndarray +* @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 {string} [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} 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 ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* function isEven( v ) { +* return v % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = [ 1.0, 2.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 = findIndex( x, isEven ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ -1, 1 ] +*/ +function findIndex( x ) { + var hasOptions; + var options; + var nargs; + var opts; + var ctx; + var cb; + var sh; + + nargs = arguments.length; + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + } + if ( nargs < 2 ) { + throw new TypeError( format( 'invalid argument. Function must be provided a callback function. Value: `%s`.', arguments[ 1 ] ) ); + } + + // 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: findIndex( x, clbk ) + if ( nargs === 2 ) { + cb = arguments[ 1 ]; + if ( !isFunction( cb ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', cb ) ); + } + } + // Case: findIndex( x, options, clbk ) or Case: findIndex( x, clbk, thisArg ) + else if ( nargs < 4 ) { + options = arguments[ 1 ]; + cb = arguments[ 2 ]; + if ( isFunction( options ) ) { + cb = options; + ctx = cb; + } else { + if ( !isFunction( cb ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', cb ) ); + } + hasOptions = true; + } + } + // Case: findIndex( x, options, clbk, thisArg ) + else { + options = arguments[ 1 ]; + hasOptions = true; + cb = arguments[ 2 ]; + if ( !isFunction( cb ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', cb ) ); + } + ctx = arguments[ 3 ]; + } + 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; + } + } + // Resolve the list of non-reduced dimensions: + sh = getShape( x ); + if ( sh.length < 1 ) { + throw new RangeError( 'invalid argument. First argument must have at least one dimension.' ); + } + return base( x, opts, cb, ctx ); +} + + +// EXPORTS // + +module.exports = findIndex; diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/package.json b/lib/node_modules/@stdlib/blas/ext/find-index/package.json new file mode 100644 index 000000000000..508bd43fd19a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index/package.json @@ -0,0 +1,62 @@ +{ + "name": "@stdlib/blas/ext/find-index", + "version": "0.0.0", + "description": "Return the first index of an element along an ndarray dimension which passes a test implemented by a predicate function.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "blas", + "find", + "index", + "callback", + "search", + "array", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/find-index/test/test.assign.js new file mode 100644 index 000000000000..2115ff329ee2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index/test/test.assign.js @@ -0,0 +1,694 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var isSameArray = require( '@stdlib/assert/is-same-array' ); +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 getOrder = require( '@stdlib/ndarray/order' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var findIndex = 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 findIndex, '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() { + findIndex( value, 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() { + findIndex( value, 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() { + findIndex( value, 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() { + findIndex( value, y, {}, clbk, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object', function test( t ) { + var values; + var i; + var x; + + x = 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() { + findIndex( x, value, 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 x; + + x = 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() { + findIndex( x, value, 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 x; + + x = 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() { + findIndex( x, value, {}, 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 x; + + x = 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() { + findIndex( x, value, {}, 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.end(); + + function badValue1() { + findIndex( x ); + } + + function badValue2() { + findIndex( x, y ); + } + + function badValue3() { + findIndex(); + } +}); + +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, + [], + 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() { + findIndex( x, 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, + [], + 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() { + findIndex( x, y, value, clbk, {} ); + }; + } +}); + +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 + }; + findIndex( x, 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 + }; + findIndex( x, y, options, clbk, {} ); + }; + } +}); + +tape( 'the function returns the first index of an 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 = findIndex( x, y, clbk ); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the first index of an 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 = findIndex( x, y, clbk ); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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 operation dimensions (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 = findIndex( x, y, opts, clbk ); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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 = findIndex( x, y, opts, clbk ); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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 = findIndex( x, y, opts, clbk ); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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 = { + 'dims': 1 + }; + + actual = findIndex( x, y, opts, clbk ); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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 providing an execution context', function test( t ) { + var expected; + 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 + }; + + actual = findIndex( x, y, clbk1, ctx ); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + t.strictEqual( ctx.count, 1, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return v % 2.0 === 0.0; + } +}); diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/test/test.js b/lib/node_modules/@stdlib/blas/ext/find-index/test/test.js new file mode 100644 index 000000000000..bd9754e4bc3c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index/test/test.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isMethod = require( '@stdlib/assert/is-method' ); +var findIndex = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof findIndex, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( findIndex, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/find-index/test/test.main.js new file mode 100644 index 000000000000..36c8cf5d088d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/find-index/test/test.main.js @@ -0,0 +1,680 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var 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 getOrder = require( '@stdlib/ndarray/order' ); +var findIndex = 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 findIndex, '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() { + findIndex( value, 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() { + findIndex( value, 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() { + findIndex( value, {}, 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() { + findIndex( value, {}, clbk, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second 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, + [], + 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() { + findIndex( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a second 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, + [], + 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() { + findIndex( x, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second 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, + [], + 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() { + findIndex( x, {}, value ); + }; + } +}); + +tape( 'the function throws an error if provided a second 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, + [], + 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() { + findIndex( x, {}, value, {} ); + }; + } +}); + +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.end(); + + function badValue1() { + findIndex( x ); + } + + function badValue2() { + findIndex(); + } +}); + +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, + [], + 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() { + findIndex( x, 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, + [], + 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() { + findIndex( x, value, clbk, {} ); + }; + } +}); + +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', + 'float64', + 'float32', + '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 + }; + findIndex( x, 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', + 'float64', + 'float32', + '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 + }; + findIndex( x, 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 + }; + findIndex( x, 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 + }; + findIndex( x, opts, clbk, {} ); + }; + } +}); + +tape( 'the function returns the first index of an 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 = findIndex( x, clbk ); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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 first index of an 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 = findIndex( x, clbk ); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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 = findIndex( x, opts, clbk ); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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 = findIndex( x, opts, clbk ); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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 = findIndex( x, opts, clbk ); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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 = findIndex( x, opts, clbk ); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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 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 = findIndex( x, opts, clbk ); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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 providing an execution context', function test( t ) { + var expected; + 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 + }; + + actual = findIndex( x, clbk1, ctx ); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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, 1, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return v % 2.0 === 0.0; + } +}); From 0e2cb50ad4ff9bde90cf34661ad442dcb3d381b0 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Thu, 7 Aug 2025 10:11:36 +0500 Subject: [PATCH 02/12] docs: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/blas/ext/find-index/lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/lib/index.js b/lib/node_modules/@stdlib/blas/ext/find-index/lib/index.js index fabbc972e68f..21e53d0e3c1a 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-index/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/find-index/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Return the first index of an along an ndarray dimension which passes a test implemented by a predicate function. +* Return the first index of an element along an ndarray dimension which passes a test implemented by a predicate function. * * @module @stdlib/blas/ext/find-index * From f4a0f9111ea3b633ce5fc6ff55d781542ef3f66e Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Thu, 7 Aug 2025 10:45:27 +0500 Subject: [PATCH 03/12] docs: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../blas/ext/find-index/docs/types/index.d.ts | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/find-index/docs/types/index.d.ts index ff26f303a623..92b7cfa5b4b4 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-index/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/find-index/docs/types/index.d.ts @@ -173,13 +173,13 @@ interface FindIndex { * var array = require( '@stdlib/ndarray/array' ); * var zeros = require( '@stdlib/ndarray/zeros' ); * - * var x = array( [ -1.0, 2.0, -3.0 ] ); - * var y = zeros( [] ); - * * function clbk( value ) { * return value % 2.0 === 0.0; * } * + * var x = array( [ -1.0, 2.0, -3.0 ] ); + * var y = zeros( [] ); + * * var out = findIndex.assign( x, y, clbk ); * // returns * @@ -205,13 +205,13 @@ interface FindIndex { * var array = require( '@stdlib/ndarray/array' ); * var zeros = require( '@stdlib/ndarray/zeros' ); * - * var x = array( [ -1.0, 2.0, -3.0 ] ); - * var y = zeros( [] ); - * * function clbk( value ) { * return value % 2.0 === 0.0; * } * + * var x = array( [ -1.0, 2.0, -3.0 ] ); + * var y = zeros( [] ); + * * var out = findIndex.assign( x, y, {}, clbk ); * // returns * @@ -236,12 +236,12 @@ interface FindIndex { * @example * var array = require( '@stdlib/ndarray/array' ); * -* var x = array( [ -1.0, 2.0, -3.0 ] ) -* * function clbk( value ) { * return value % 2.0 === 0.0; * } * +* var x = array( [ -1.0, 2.0, -3.0 ] ) +* * var y = findIndex( x, clbk ); * // returns * @@ -252,13 +252,13 @@ interface FindIndex { * var array = require( '@stdlib/ndarray/array' ); * var zeros = require( '@stdlib/ndarray/zeros' ); * -* var x = array( [ -1.0, 2.0, -3.0 ] ) -* var y = zeros( [] ); -* * function clbk( value ) { * return value % 2.0 === 0.0; * } * +* var x = array( [ -1.0, 2.0, -3.0 ] ) +* var y = zeros( [] ); +* * var out = findIndex.assign( x, y, clbk ); * // returns * From d0c4f6a85483219ce5d3366a017babc53151626a Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Thu, 7 Aug 2025 10:54:58 +0500 Subject: [PATCH 04/12] bench: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../@stdlib/blas/ext/find-index/benchmark/benchmark.assign.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/blas/ext/find-index/benchmark/benchmark.assign.js index 6056ce16ec0a..e3e183edcb42 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-index/benchmark/benchmark.assign.js +++ b/lib/node_modules/@stdlib/blas/ext/find-index/benchmark/benchmark.assign.js @@ -27,7 +27,7 @@ var uniform = require( '@stdlib/random/array/uniform' ); var zeros = require( '@stdlib/ndarray/zeros' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var pkg = require( './../package.json' ).name; -var indexOf = require( './../lib' ); +var findIndex = require( './../lib' ); // VARIABLES // @@ -82,7 +82,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - o = indexOf.assign( x, out, clbk ); + o = findIndex.assign( x, out, clbk ); if ( typeof o !== 'object' ) { b.fail( 'should return an ndarray' ); } From 3b8a281673512466970dff0fcae437e386d3b09d Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 11 Aug 2025 08:59:40 +0000 Subject: [PATCH 05/12] fix: argument juggling --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/blas/ext/find-index/lib/assign.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/find-index/lib/assign.js index f635fa17b30a..396543a60bab 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-index/lib/assign.js +++ b/lib/node_modules/@stdlib/blas/ext/find-index/lib/assign.js @@ -87,7 +87,7 @@ var base = require( './base.js' ).assign; * // returns true * * var arr = ndarray2array( out ); -* // returns [ -1, 1 ] +* // returns [ 1, 0 ] */ function assign( x, out ) { var hasOptions; @@ -119,7 +119,7 @@ function assign( x, out ) { // Case: assign( x, out, clbk ) if ( nargs === 3 ) { - cb = arguments[ 1 ]; + cb = arguments[ 2 ]; if ( !isFunction( cb ) ) { throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', cb ) ); } From 6de7b3fade8cf9d77d76aa191b9bf3e310d1fc6a Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 11 Aug 2025 09:37:58 +0000 Subject: [PATCH 06/12] fix: apply fixes --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/blas/ext/find-index/README.md | 4 ++-- lib/node_modules/@stdlib/blas/ext/find-index/lib/assign.js | 2 +- lib/node_modules/@stdlib/blas/ext/find-index/lib/main.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/README.md b/lib/node_modules/@stdlib/blas/ext/find-index/README.md index 4a5efbf2c953..fc9bca0f2d8d 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-index/README.md +++ b/lib/node_modules/@stdlib/blas/ext/find-index/README.md @@ -140,7 +140,7 @@ var out = findIndex( x, opts, isEven ); // returns var idx = ndarray2array( out ); -// returns [ 1, -1 ] +// 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`. @@ -164,7 +164,7 @@ var out = findIndex( x, opts, isEven ); // returns var idx = ndarray2array( out ); -// returns [ [ 1, -1 ] ] +// 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. diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/find-index/lib/assign.js index 396543a60bab..9c39c05be244 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-index/lib/assign.js +++ b/lib/node_modules/@stdlib/blas/ext/find-index/lib/assign.js @@ -129,8 +129,8 @@ function assign( x, out ) { options = arguments[ 2 ]; cb = arguments[ 3 ]; if ( isFunction( options ) ) { - cb = options; ctx = cb; + cb = options; } else { if ( !isFunction( cb ) ) { throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', cb ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/lib/main.js b/lib/node_modules/@stdlib/blas/ext/find-index/lib/main.js index ea2e94a6af27..092c5ba1e109 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-index/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/find-index/lib/main.js @@ -76,7 +76,7 @@ var base = require( './base.js' ); * // returns * * var arr = ndarray2array( out ); -* // returns [ -1, 1 ] +* // returns [ 1, 0 ] */ function findIndex( x ) { var hasOptions; @@ -116,8 +116,8 @@ function findIndex( x ) { options = arguments[ 1 ]; cb = arguments[ 2 ]; if ( isFunction( options ) ) { - cb = options; ctx = cb; + cb = options; } else { if ( !isFunction( cb ) ) { throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', cb ) ); From 3c48f508579867c0c19f306493afed5fbc089773 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 11 Aug 2025 09:57:22 +0000 Subject: [PATCH 07/12] fix: test cases --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../blas/ext/find-index/test/test.assign.js | 22 ++++++------- .../blas/ext/find-index/test/test.main.js | 31 +++++++------------ 2 files changed, 22 insertions(+), 31 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/find-index/test/test.assign.js index 2115ff329ee2..6c5a74eeffea 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-index/test/test.assign.js +++ b/lib/node_modules/@stdlib/blas/ext/find-index/test/test.assign.js @@ -220,7 +220,7 @@ tape( 'the function throws an error if provided a second argument which is not a } }); -tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (thisArg)', function test( t ) { +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (thisArg)', function test( t ) { var values; var i; var x; @@ -253,7 +253,7 @@ tape( 'the function throws an error if provided a first argument which is not an } }); -tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options)', function test( t ) { +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (options)', function test( t ) { var values; var i; var x; @@ -286,7 +286,7 @@ tape( 'the function throws an error if provided a first argument which is not an } }); -tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options, thisArg)', function test( t ) { +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (options, thisArg)', function test( t ) { var values; var i; var x; @@ -369,8 +369,7 @@ tape( 'the function throws an error if provided an options argument which is not 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 ] ); @@ -405,8 +404,7 @@ tape( 'the function throws an error if provided an options argument which is not 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 ] ); @@ -517,7 +515,7 @@ tape( 'the function returns the first index of an element which passes a test (r }); actual = findIndex( x, y, clbk ); - expected = [ 1, -1 ]; + expected = [ 1, 1 ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); @@ -593,7 +591,7 @@ tape( 'the function supports specifying operation dimensions (row-major)', funct }; actual = findIndex( x, y, opts, clbk ); - expected = [ 1, -1 ]; + expected = [ 1, 1 ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); @@ -624,7 +622,7 @@ tape( 'the function supports specifying an operation dimension (column-major)', }; actual = findIndex( x, y, opts, clbk ); - expected = [ 1, -1 ]; + expected = [ 1, 1 ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); @@ -675,7 +673,7 @@ tape( 'the function supports providing an execution context', function test( t ) }; actual = findIndex( x, y, clbk1, ctx ); - expected = [ 1, -1 ]; + expected = [ 1, 1 ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); @@ -683,7 +681,7 @@ tape( 'the function supports providing an execution context', function test( t ) t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); t.strictEqual( ( y === actual ), true, 'returns expected value' ); - t.strictEqual( ctx.count, 1, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/find-index/test/test.main.js index 36c8cf5d088d..d8d9145b2e1d 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-index/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/find-index/test/test.main.js @@ -180,8 +180,7 @@ tape( 'the function throws an error if provided a second argument which is not a 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 ] ); @@ -210,8 +209,7 @@ tape( 'the function throws an error if provided a second argument which is not a 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 ] ); @@ -240,8 +238,7 @@ tape( 'the function throws an error if provided a second argument which is not a 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 ] ); @@ -270,8 +267,7 @@ tape( 'the function throws an error if provided a second argument which is not a 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 ] ); @@ -321,8 +317,7 @@ tape( 'the function throws an error if provided an options argument which is not 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 ] ); @@ -352,8 +347,7 @@ tape( 'the function throws an error if provided an options argument which is not 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 ] ); @@ -511,7 +505,7 @@ tape( 'the function returns the first index of an element which passes a test (r x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); actual = findIndex( x, clbk ); - expected = [ 1, -1 ]; + expected = [ 1, 1 ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); @@ -572,7 +566,7 @@ tape( 'the function supports specifying the operation dimension (row-major)', fu }; actual = findIndex( x, opts, clbk ); - expected = [ 1, -1 ]; + expected = [ 1, 1 ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); @@ -597,7 +591,7 @@ tape( 'the function supports specifying the operation dimension (column-major)', }; actual = findIndex( x, opts, clbk ); - expected = [ 1, -1 ]; + expected = [ 1, 1 ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); @@ -637,7 +631,7 @@ tape( 'the function supports specifying the output array data type', function te }; actual = findIndex( x, opts, clbk ); - expected = [ 1, -1 ]; + expected = [ 1, 1 ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( getDType( actual ), 'int32', 'returns expected value' ); @@ -660,16 +654,15 @@ tape( 'the function supports providing an execution context', function test( t ) ctx = { 'count': 0 }; - actual = findIndex( x, clbk1, ctx ); - expected = [ 1, -1 ]; + expected = [ 1, 1 ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( 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, 1, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); t.end(); From d7f61cd4d587afd2cf1b7f3ac0776119ec93958f Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 11 Aug 2025 10:07:35 +0000 Subject: [PATCH 08/12] test: add missing test case --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/find-index/lib/main.js | 7 ------ .../blas/ext/find-index/test/test.main.js | 25 +++++++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/lib/main.js b/lib/node_modules/@stdlib/blas/ext/find-index/lib/main.js index 092c5ba1e109..ca5ea4180838 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-index/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/find-index/lib/main.js @@ -24,7 +24,6 @@ var hasOwnProp = require( '@stdlib/assert/has-own-property' ); var isFunction = require( '@stdlib/assert/is-function' ); var isPlainObject = require( '@stdlib/assert/is-plain-object' ); var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); -var getShape = require( '@stdlib/ndarray/shape' ); var format = require( '@stdlib/string/format' ); var base = require( './base.js' ); @@ -85,7 +84,6 @@ function findIndex( x ) { var opts; var ctx; var cb; - var sh; nargs = arguments.length; if ( !isndarrayLike( x ) ) { @@ -150,11 +148,6 @@ function findIndex( x ) { opts.dtype = options.dtype; } } - // Resolve the list of non-reduced dimensions: - sh = getShape( x ); - if ( sh.length < 1 ) { - throw new RangeError( 'invalid argument. First argument must have at least one dimension.' ); - } return base( x, opts, cb, ctx ); } diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/find-index/test/test.main.js index d8d9145b2e1d..765361230f04 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-index/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/find-index/test/test.main.js @@ -617,6 +617,31 @@ tape( 'the function supports specifying the operation dimension (column-major)', t.end(); }); +tape( 'the function supports specifying the `keepdims` options property', 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 = findIndex( x, opts, clbk ); + expected = [ [ 1 ], [ 1 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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; From fa99780287e1456b2fd6c28eba4bbd4ca62b28c9 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 11 Aug 2025 10:19:49 +0000 Subject: [PATCH 09/12] docs: fix inconsistencies --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../blas/ext/find-index/docs/types/index.d.ts | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/find-index/docs/types/index.d.ts index 92b7cfa5b4b4..c1fbb6d4198c 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-index/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/find-index/docs/types/index.d.ts @@ -33,48 +33,48 @@ type InputArray = typedndarray; type OutputArray = typedndarray; /** -* Returns the result of callback function. +* Returns a boolean indicating whether an element passes a test. * -* @returns result +* @returns a boolean indicating whether an element passes a test */ -type NullaryCallback = ( this: ThisArg ) => boolean; +type NullaryPredicate = ( this: ThisArg ) => boolean; /** -* Returns the result of callback function. +* Returns a boolean indicating whether an element passes a test. * * @param value - current array element -* @returns result +* @returns a boolean indicating whether an element passes a test */ -type UnaryCallback = ( this: ThisArg, value: T ) => boolean; +type UnaryPredicate = ( this: ThisArg, value: T ) => boolean; /** -* Returns the result of callback function. +* Returns a boolean indicating whether an element passes a test. * * @param value - current array element * @param index - current array element index -* @returns result +* @returns a boolean indicating whether an element passes a test */ -type BinaryCallback = ( this: ThisArg, value: T, index: number ) => boolean; +type BinaryPredicate = ( this: ThisArg, value: T, index: number ) => boolean; /** -* Returns the result of callback function. +* 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 result +* @returns a boolean indicating whether an element passes a test */ -type TernaryCallback = ( this: ThisArg, value: T, index: number, array: U ) => boolean; +type TernaryPredicate = ( this: ThisArg, value: T, index: number, array: U ) => boolean; /** -* Returns the result of callback function. +* 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 result +* @returns a boolean indicating whether an element passes a test */ -type Callback = NullaryCallback | UnaryCallback | BinaryCallback | TernaryCallback; +type Predicate = NullaryPredicate | UnaryPredicate | BinaryPredicate | TernaryPredicate; /** * Interface defining "base" options. @@ -113,8 +113,8 @@ interface FindIndex { * Returns the first index of an element along an ndarray dimension which passes a test implemented by a predicate function. * * @param x - input ndarray - * @param clbk - callback function - * @param thisArg - callback function execution context + * @param clbk - predicate function + * @param thisArg - predicate function execution context * @returns output ndarray * * @example @@ -132,15 +132,15 @@ interface FindIndex { * var v = y.get(); * // returns 1 */ - = InputArray, ThisArg = unknown>( x: U, clbk: Callback, thisArg?: ThisParameterType> ): OutputArray; + = InputArray, ThisArg = unknown>( x: U, clbk: Predicate, thisArg?: ThisParameterType> ): OutputArray; /** * Returns the first index of an element along an ndarray dimension which passes a test implemented by a predicate function. * * @param x - input ndarray * @param options - function options - * @param clbk - callback function - * @param thisArg - callback function execution context + * @param clbk - predicate function + * @param thisArg - predicate function execution context * @returns output ndarray * * @example @@ -158,15 +158,15 @@ interface FindIndex { * var v = y.get(); * // returns 1 */ - = InputArray, ThisArg = unknown>( x: U, options: Options, clbk: Callback, thisArg?: ThisParameterType> ): OutputArray; + = InputArray, ThisArg = unknown>( x: U, options: Options, clbk: Predicate, thisArg?: ThisParameterType> ): OutputArray; /** * Returns the first index of an element along an ndarray dimension which passes a test implemented by a predicate function and assigns results to a provided output ndarray. * * @param x - input ndarray * @param out - output ndarray - * @param clbk - callback function - * @param thisArg - callback function execution context + * @param clbk - predicate function + * @param thisArg - predicate function execution context * @returns output ndarray * * @example @@ -189,7 +189,7 @@ interface FindIndex { * var bool = ( out === y ); * // returns true */ - assign = InputArray, V extends OutputArray = OutputArray, ThisArg = unknown>( x: U, out: V, clbk: Callback, thisArg?: ThisParameterType> ): V; + assign = InputArray, V extends OutputArray = OutputArray, ThisArg = unknown>( x: U, out: V, clbk: Predicate, thisArg?: ThisParameterType> ): V; /** * Returns the first index of an element along an ndarray dimension which passes a test implemented by a predicate function and assigns results to a provided output ndarray. @@ -197,8 +197,8 @@ interface FindIndex { * @param x - input ndarray * @param out - output ndarray * @param options - function options - * @param clbk - callback function - * @param thisArg - callback function execution context + * @param clbk - predicate function + * @param thisArg - predicate function execution context * @returns output ndarray * * @example @@ -221,7 +221,7 @@ interface FindIndex { * var bool = ( out === y ); * // returns true */ - assign = InputArray, V extends OutputArray = OutputArray, ThisArg = unknown>( x: U, out: V, options: BaseOptions, clbk: Callback, thisArg?: ThisParameterType> ): V; + assign = InputArray, V extends OutputArray = OutputArray, ThisArg = unknown>( x: U, out: V, options: BaseOptions, clbk: Predicate, thisArg?: ThisParameterType> ): V; } /** @@ -229,8 +229,8 @@ interface FindIndex { * * @param x - input ndarray * @param options - function options -* @param clbk - callback function -* @param thisArg - callback execution context +* @param clbk - predicate function +* @param thisArg - predicate function execution context * @returns output ndarray * * @example From 771492b8ca8c28d913a22253a1475c5dbf1ab632 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 11 Aug 2025 17:12:23 +0000 Subject: [PATCH 10/12] test: add missing tests --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../blas/ext/find-index/test/test.assign.js | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/find-index/test/test.assign.js index 6c5a74eeffea..f52dd26c3488 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-index/test/test.assign.js +++ b/lib/node_modules/@stdlib/blas/ext/find-index/test/test.assign.js @@ -319,6 +319,150 @@ tape( 'the function throws an error if provided a second argument which is not a } }); +tape( 'the function throws an error if provided a callback which is not a function', function test( t ) { + var values; + var i; + var x; + var y; + + x = zeros( [], { + 'dtype': 'generic' + }); + x = 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() { + findIndex( x, y, value ); + }; + } +}); + +tape( 'the function throws an error if provided a callback which is not a function (thisArg)', function test( t ) { + var values; + var i; + var x; + var y; + + x = zeros( [], { + 'dtype': 'generic' + }); + x = 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() { + findIndex( x, y, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a callback which is not a function (options)', function test( t ) { + var values; + var i; + var x; + var y; + + x = zeros( [], { + '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() { + findIndex( x, y, value, {}, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a callback which is not a function (options, thisArg)', function test( t ) { + var values; + var i; + var x; + var y; + + x = zeros( [], { + 'dtype': 'generic' + }); + x = 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() { + findIndex( x, y, {}, value, {} ); + }; + } +}); + tape( 'the function throws an error if provided insufficient number of arguments', function test( t ) { var x; var y; From 69f6621d89bdf2e13bab71587c4848cec8f862a8 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 11 Aug 2025 17:21:25 +0000 Subject: [PATCH 11/12] test: add missing tests --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../blas/ext/find-index/test/test.assign.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/find-index/test/test.assign.js index f52dd26c3488..9ad0597c3640 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-index/test/test.assign.js +++ b/lib/node_modules/@stdlib/blas/ext/find-index/test/test.assign.js @@ -325,10 +325,10 @@ tape( 'the function throws an error if provided a callback which is not a functi var x; var y; - x = zeros( [], { + x = zeros( [ 2, 2 ], { 'dtype': 'generic' }); - x = zeros( [], { + y = zeros( [], { 'dtype': 'int32' }); @@ -361,10 +361,10 @@ tape( 'the function throws an error if provided a callback which is not a functi var x; var y; - x = zeros( [], { + x = zeros( [ 2, 2 ], { 'dtype': 'generic' }); - x = zeros( [], { + y = zeros( [], { 'dtype': 'int32' }); @@ -397,7 +397,7 @@ tape( 'the function throws an error if provided a callback which is not a functi var x; var y; - x = zeros( [], { + x = zeros( [ 2, 2 ], { 'dtype': 'generic' }); y = zeros( [], { @@ -433,10 +433,10 @@ tape( 'the function throws an error if provided a callback which is not a functi var x; var y; - x = zeros( [], { + x = zeros( [ 2, 2 ], { 'dtype': 'generic' }); - x = zeros( [], { + y = zeros( [], { 'dtype': 'int32' }); From 8c1a65dfee4714a757fca3673d2b21d1f59983cc Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 11 Aug 2025 17:31:42 +0000 Subject: [PATCH 12/12] refactor: add missing check & test case --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/find-index/lib/main.js | 7 ++++++ .../blas/ext/find-index/test/test.assign.js | 24 +++++++++++++++++++ .../blas/ext/find-index/test/test.main.js | 19 +++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/lib/main.js b/lib/node_modules/@stdlib/blas/ext/find-index/lib/main.js index ca5ea4180838..092c5ba1e109 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-index/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/find-index/lib/main.js @@ -24,6 +24,7 @@ var hasOwnProp = require( '@stdlib/assert/has-own-property' ); var isFunction = require( '@stdlib/assert/is-function' ); var isPlainObject = require( '@stdlib/assert/is-plain-object' ); var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var getShape = require( '@stdlib/ndarray/shape' ); var format = require( '@stdlib/string/format' ); var base = require( './base.js' ); @@ -84,6 +85,7 @@ function findIndex( x ) { var opts; var ctx; var cb; + var sh; nargs = arguments.length; if ( !isndarrayLike( x ) ) { @@ -148,6 +150,11 @@ function findIndex( x ) { opts.dtype = options.dtype; } } + // Resolve the list of non-reduced dimensions: + sh = getShape( x ); + if ( sh.length < 1 ) { + throw new RangeError( 'invalid argument. First argument must have at least one dimension.' ); + } return base( x, opts, cb, ctx ); } diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/find-index/test/test.assign.js index 9ad0597c3640..b0a3a33fe2cc 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-index/test/test.assign.js +++ b/lib/node_modules/@stdlib/blas/ext/find-index/test/test.assign.js @@ -187,6 +187,30 @@ tape( 'the function throws an error if provided a first argument which is not an } }); +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() { + findIndex( zeros( value ), y, clbk ); + }; + } +}); + tape( 'the function throws an error if provided a second argument which is not an ndarray-like object', function test( t ) { var values; var i; diff --git a/lib/node_modules/@stdlib/blas/ext/find-index/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/find-index/test/test.main.js index 765361230f04..8d9e1191c665 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-index/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/find-index/test/test.main.js @@ -165,6 +165,25 @@ tape( 'the function throws an error if provided a first argument which is not an } }); +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() { + findIndex( zeros( value ), clbk ); + }; + } +}); + tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { var values; var x;