diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfind-index/README.md b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/README.md new file mode 100644 index 000000000000..d19d7efb767c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/README.md @@ -0,0 +1,229 @@ + + +# gfindIndex + +> Return the index of the first element which passes a test implemented by a predicate function. + +
+ +## Usage + +```javascript +var gfindIndex = require( '@stdlib/blas/ext/base/gfind-index' ); +``` + +#### gfindIndex( N, x, strideX, clbk\[, thisArg] ) + +Returns the index of the first element which passes a test implemented by a predicate function. + +```javascript +function isEven( v ) { + return v % 2.0 === 0.0; +} + +var x = [ 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; + +var idx = gfindIndex( x.length, x, 1, isEven ); +// returns 3 +``` + +If no element passes a test implemented by a predicate function, the function returns `-1`. + +```javascript +function isEven( v ) { + return v % 2.0 === 0.0; +} + +var x = [ 1.0, 3.0, 5.0, 7.0, 9.0 ]; + +var idx = gfindIndex( x.length, x, 1, isEven ); +// returns -1 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: input array. +- **strideX**: stride length. +- **clbk**: callback function. +- **thisArg**: execution context (_optional_). + +The callback function is provided the following arguments: + +- **value**: current array element. +- **aidx**: array index. +- **sidx**: strided index (`offset + aidx*stride`). +- **array**: the input array. + +To set the callback execution context, provide a `thisArg`. + +```javascript +function isEven( v ) { + this.count += 1; + return v % 2.0 === 0.0; +} + +var x = [ 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; + +var ctx = { + 'count': 0 +}; + +var idx = gfindIndex( x.length, x, 1, isEven, ctx ); +// returns 3 + +var count = ctx.count; +// returns 4 +``` + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to test every other element: + +```javascript +function isEven( v ) { + return v % 2.0 === 0.0; +} + +var x = [ 1.0, 3.0, -5.0, 0.0, 4.0, -1.0, -3.0 ]; + +var idx = gfindIndex( 4, x, 2, isEven ); +// returns 2 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +function isEven( v ) { + return v % 2.0 === 0.0; +} + +// Initial array: +var x0 = new Float64Array( [ 1.0, 3.0, 4.0, -5.0, 7.0, 6.0 ] ); + +// Create an offset view: +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var idx = gfindIndex( 3, x1, 2, isEven ); +// returns 2 +``` + +#### gfindIndex.ndarray( N, x, strideX, offsetX, clbk\[, thisArg] ) + +Returns the index of the first element which passes a test implemented by a predicate function using alternative indexing semantics. + +```javascript +function isEven( v ) { + return v % 2.0 === 0.0; +} + +var x = [ 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; + +var idx = gfindIndex.ndarray( x.length, x, 1, 0, isEven ); +// returns 3 +``` + +The function has the following additional parameters: + +- **offsetX**: starting index. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to access only the last three elements: + +```javascript +function isEven( v ) { + return v % 2.0 === 0.0; +} + +var x = [ 1.0, -2.0, -4.0, 5.0, -7.0, 6.0 ]; + +var idx = gfindIndex.ndarray( 3, x, 1, x.length-3, isEven ); +// returns 2 +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `-1`. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gfindIndex = require( '@stdlib/blas/ext/base/gfind-index' ); + +function isEven( v ) { + return v % 2.0 === 0.0; +} + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +console.log( x ); + +var idx = gfindIndex( x.length, x, 1, isEven ); +console.log( idx ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfind-index/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/benchmark/benchmark.js new file mode 100644 index 000000000000..637723bdbed5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/benchmark/benchmark.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 bench = require( '@stdlib/bench' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var gfindIndex = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} v - array element +* @returns {boolean} result +*/ +function clbk( v ) { + return v > 999.0; +} + +/** +* Create a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = discreteUniform( len, -100.0, 100.0, { + 'dtype': 'generic' + }); + return benchmark; + + function benchmark( b ) { + var idx; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + idx = gfindIndex( x.length, x, 1, clbk ); + if ( !isInteger( idx ) ) { + b.fail( 'should return an integer' ); + } + } + b.toc(); + if ( !isInteger( idx ) ) { + b.fail( 'should return an integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +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+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfind-index/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..f4c69cea8cf5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/benchmark/benchmark.ndarray.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 bench = require( '@stdlib/bench' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var gfindIndex = require( './../lib' ).ndarray; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {*} v - array element +* @returns {boolean} result +*/ +function clbk( v ) { + return v > 999.0; +} + +/** +* Create a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = discreteUniform( len, -100.0, 100.0, { + 'dtype': 'generic' + }); + return benchmark; + + function benchmark( b ) { + var idx; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + idx = gfindIndex( x.length, x, 1, 0, clbk ); + if ( !isInteger( idx ) ) { + b.fail( 'should return an integer' ); + } + } + b.toc(); + if ( !isInteger( idx ) ) { + b.fail( 'should return an integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +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+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfind-index/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/docs/repl.txt new file mode 100644 index 000000000000..938b9e7af123 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/docs/repl.txt @@ -0,0 +1,105 @@ + +{{alias}}( N, x, strideX, clbk[, thisArg] ) + Returns the index of the first element which passes a test implemented by a + predicate function. + + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + If `N <= 0` or no element passes a test implemented by a predicate function, + the function returns `-1`. + + The callback function is provided the following arguments: + + - value: current array element. + - aidx: array index. + - sidx: strided index (offset + aidx*stride). + - array: the input array. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: ArrayLikeObject + Input array. + + strideX: integer + Stride length. + + clbk: Function + Callback function. + + thisArg: any (optional) + Callback execution context. + + Returns + ------- + idx: integer + Index. + + Examples + -------- + // Standard Usage: + > function isEven( v ) { return v % 2.0 === 0.0; }; + > var x = [ 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ]; + > {{alias}}( x.length, x, 1, isEven ) + 3 + + // Using `N` and stride parameters: + > x = [ 1.0, 3.0, 4.0, -5.0, -1.0, -3.0 ]; + > {{alias}}( x.length, x, 2, isEven ) + 1 + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, 3.0, -4.0, 5.0, -6.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( 3, x1, 1, isEven ) + 1 + + +{{alias}}.ndarray( N, x, strideX, offsetX, clbk[, thisArg] ) + Returns the index of the first element which passes a test implemented by a + predicate function using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameter supports indexing semantics based on a starting + index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: ArrayLikeObject + Input array. + + strideX: integer + Stride length. + + offsetX: integer + Starting index. + + clbk: Function + Callback function. + + thisArg: any (optional) + Callback execution context. + + Returns + ------- + idx: integer + Index. + + Examples + -------- + > function isEven( v ) { return v % 2.0 === 0.0; }; + > var x = [ 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ]; + > {{alias}}.ndarray( x.length, x, 1, 2, isEven ) + 1 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfind-index/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/docs/types/index.d.ts new file mode 100644 index 000000000000..510d04d0e76a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/docs/types/index.d.ts @@ -0,0 +1,198 @@ +/* +* @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 { Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = Collection | AccessorArrayLike; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @returns boolean indicating whether an element passes a test +*/ +type Nullary = ( this: U ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - array element +* @returns boolean indicating whether an element passes a test +*/ +type Unary = ( this: U, value: T ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - array element +* @param aidx - array index +* @returns boolean indicating whether an element passes a test +*/ +type Binary = ( this: U, value: T, aidx: number ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - array element +* @param aidx - array index +* @param sidx - strided index (offset + aidx*stride) +* @returns boolean indicating whether an element passes a test +*/ +type Ternary = ( this: U, value: T, aidx: number, sidx: number ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - array element +* @param aidx - array index +* @param sidx - strided index (offset + aidx*stride) +* @param array - input array +* @returns boolean indicating whether an element passes a test +*/ +type Quaternary = ( this: U, value: T, aidx: number, sidx: number, array: InputArray ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - array element +* @param aidx - array index +* @param sidx - strided index (offset + aidx*stride) +* @param array - input array +* @returns boolean indicating whether an element passes a test +*/ +type Callback = Nullary | Unary | Binary | Ternary | Quaternary; + +/** +* Interface describing `gfindIndex`. +*/ +interface Routine { + /** + * Returns the index of the first element which passes a test implemented by a predicate function. + * + * ## Notes + * + * - The callback function is provided the following arguments: + * + * - `value`: array element + * - `aidx`: array index + * - `sidx`: strided index (offset + aidx*stride) + * - `array`: input array + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - stride length + * @param clbk - callback function + * @param thisArg - execution context + * @returns index + * + * @example + * function isEven( v ) { + * return v % 2.0 === 0.0; + * } + * + * var x = [ 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; + * + * var idx = gfindIndex( x.length, x, 1, isEven ); + * // returns 3 + */ + ( N: number, x: InputArray, strideX: number, clbk: Callback, thisArg?: ThisParameterType> ): number; + + /** + * Returns the index of the first element which passes a test implemented by a predicate function using alternative indexing semantics. + * + * ## Notes + * + * - The callback function is provided the following arguments: + * + * - `value`: array element + * - `aidx`: array index + * - `sidx`: strided index (offset + aidx*stride) + * - `array`: input array + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - stride length + * @param offsetX - starting index + * @param clbk - callback function + * @param thisArg - execution context + * @returns index + * + * @example + * function isEven( v ) { + * return v % 2.0 === 0.0; + * } + * + * var x = [ 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; + * + * var idx = gfindIndex.ndarray( x.length, x, 1, 0, isEven ); + * // returns 3 + */ + ndarray( N: number, x: InputArray, strideX: number, offsetX: number, clbk: Callback, thisArg?: ThisParameterType> ): number; +} + +/** +* Returns the index of the first element which passes a test implemented by a predicate function. +* +* ## Notes +* +* - The callback function is provided the following arguments: +* +* - `value`: array element +* - `aidx`: array index +* - `sidx`: strided index (offset + aidx*stride) +* - `array`: input array +* +* @param N - number of indexed elements +* @param x - input array +* @param strideX - stride length +* @param clbk - callback function +* @param thisArg - execution context +* @returns index +* +* @example +* function isEven( v ) { +* return v % 2.0 === 0.0; +* } +* +* var x = [ 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; +* +* var idx = gfindIndex( x.length, x, 1, isEven ); +* // returns 3 +* +* @example +* function isEven( v ) { +* return v % 2.0 === 0.0; +* } +* +* var x = [ 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; +* +* var idx = gfindIndex.ndarray( x.length, x, 1, 0, isEven ); +* // returns 3 +*/ +declare var gfindIndex: Routine; + + +// EXPORTS // + +export = gfindIndex; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfind-index/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/docs/types/test.ts new file mode 100644 index 000000000000..427e6bb2785b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/docs/types/test.ts @@ -0,0 +1,191 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import gfindIndex = require( './index' ); + +/** +* Predicate function. +* +* @param v - ndarray element +* @returns result +*/ +function isEven( v: any ): boolean { + return v % 2.0 === 0.0; +} + + +// TESTS // + +// The function returns a number... +{ + const x = new Float64Array( 10 ); + + gfindIndex( x.length, x, 1, isEven ); // $ExpectType number + gfindIndex( x.length, x, 1, isEven, {} ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gfindIndex( '10', x, 1, isEven ); // $ExpectError + gfindIndex( true, x, 1, isEven ); // $ExpectError + gfindIndex( false, x, 1, isEven ); // $ExpectError + gfindIndex( null, x, 1, isEven ); // $ExpectError + gfindIndex( undefined, x, 1, isEven ); // $ExpectError + gfindIndex( [], x, 1, isEven ); // $ExpectError + gfindIndex( {}, x, 1, isEven ); // $ExpectError + gfindIndex( ( x: number ): number => x, x, 1, isEven ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a collection... +{ + const x = new Float64Array( 10 ); + + gfindIndex( x.length, 10, 1, isEven ); // $ExpectError + gfindIndex( x.length, true, 1, isEven ); // $ExpectError + gfindIndex( x.length, false, 1, isEven ); // $ExpectError + gfindIndex( x.length, null, 1, isEven ); // $ExpectError + gfindIndex( x.length, undefined, 1, isEven ); // $ExpectError + gfindIndex( x.length, {}, 1, isEven ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gfindIndex( x.length, x, '10', isEven ); // $ExpectError + gfindIndex( x.length, x, true, isEven ); // $ExpectError + gfindIndex( x.length, x, false, isEven ); // $ExpectError + gfindIndex( x.length, x, null, isEven ); // $ExpectError + gfindIndex( x.length, x, undefined, isEven ); // $ExpectError + gfindIndex( x.length, x, [], isEven ); // $ExpectError + gfindIndex( x.length, x, {}, isEven ); // $ExpectError + gfindIndex( x.length, x, ( x: number ): number => x, isEven ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a function... +{ + const x = new Float64Array( 10 ); + + gfindIndex( x.length, x, 1, '10' ); // $ExpectError + gfindIndex( x.length, x, 1, true ); // $ExpectError + gfindIndex( x.length, x, 1, false ); // $ExpectError + gfindIndex( x.length, x, 1, null ); // $ExpectError + gfindIndex( x.length, x, 1, undefined ); // $ExpectError + gfindIndex( x.length, x, 1, [] ); // $ExpectError + gfindIndex( x.length, x, 1, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + gfindIndex(); // $ExpectError + gfindIndex( x.length ); // $ExpectError + gfindIndex( x.length, x ); // $ExpectError + gfindIndex( x.length, x, 1 ); // $ExpectError + gfindIndex( x.length, x, 1, isEven, {}, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const x = new Float64Array( 10 ); + + gfindIndex.ndarray( x.length, x, 1, 0, isEven ); // $ExpectType number + gfindIndex.ndarray( x.length, x, 1, 0, isEven, {} ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gfindIndex.ndarray( '10', x, 1, 0, isEven ); // $ExpectError + gfindIndex.ndarray( true, x, 1, 0, isEven ); // $ExpectError + gfindIndex.ndarray( false, x, 1, 0, isEven ); // $ExpectError + gfindIndex.ndarray( null, x, 1, 0, isEven ); // $ExpectError + gfindIndex.ndarray( undefined, x, 1, 0, isEven ); // $ExpectError + gfindIndex.ndarray( [], x, 1, 0, isEven ); // $ExpectError + gfindIndex.ndarray( {}, x, 1, 0, isEven ); // $ExpectError + gfindIndex.ndarray( ( x: number ): number => x, x, 1, 0, isEven ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a collection... +{ + const x = new Float64Array( 10 ); + + gfindIndex.ndarray( x.length, 10, 1, 0, isEven ); // $ExpectError + gfindIndex.ndarray( x.length, true, 1, 0, isEven ); // $ExpectError + gfindIndex.ndarray( x.length, false, 1, 0, isEven ); // $ExpectError + gfindIndex.ndarray( x.length, null, 1, 0, isEven ); // $ExpectError + gfindIndex.ndarray( x.length, undefined, 1, 0, isEven ); // $ExpectError + gfindIndex.ndarray( x.length, {}, 1, 0, isEven ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gfindIndex.ndarray( x.length, x, '10', 0, isEven ); // $ExpectError + gfindIndex.ndarray( x.length, x, true, 0, isEven ); // $ExpectError + gfindIndex.ndarray( x.length, x, false, 0, isEven ); // $ExpectError + gfindIndex.ndarray( x.length, x, null, 0, isEven ); // $ExpectError + gfindIndex.ndarray( x.length, x, undefined, 0, isEven ); // $ExpectError + gfindIndex.ndarray( x.length, x, [], 0, isEven ); // $ExpectError + gfindIndex.ndarray( x.length, x, {}, 0, isEven ); // $ExpectError + gfindIndex.ndarray( x.length, x, ( x: number ): number => x, 0, isEven ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gfindIndex.ndarray( x.length, x, 1, '10', isEven ); // $ExpectError + gfindIndex.ndarray( x.length, x, 1, true, isEven ); // $ExpectError + gfindIndex.ndarray( x.length, x, 1, false, isEven ); // $ExpectError + gfindIndex.ndarray( x.length, x, 1, null, isEven ); // $ExpectError + gfindIndex.ndarray( x.length, x, 1, undefined, isEven ); // $ExpectError + gfindIndex.ndarray( x.length, x, 1, [], isEven ); // $ExpectError + gfindIndex.ndarray( x.length, x, 1, {}, isEven ); // $ExpectError + gfindIndex.ndarray( x.length, x, 1, ( x: number ): number => x, isEven ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a function... +{ + const x = new Float64Array( 10 ); + + gfindIndex.ndarray( x.length, x, 1, 0, '10' ); // $ExpectError + gfindIndex.ndarray( x.length, x, 1, 0, true ); // $ExpectError + gfindIndex.ndarray( x.length, x, 1, 0, false ); // $ExpectError + gfindIndex.ndarray( x.length, x, 1, 0, null ); // $ExpectError + gfindIndex.ndarray( x.length, x, 1, 0, undefined ); // $ExpectError + gfindIndex.ndarray( x.length, x, 1, 0, [] ); // $ExpectError + gfindIndex.ndarray( x.length, x, 1, 0, {} ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + gfindIndex.ndarray(); // $ExpectError + gfindIndex.ndarray( x.length ); // $ExpectError + gfindIndex.ndarray( x.length, x ); // $ExpectError + gfindIndex.ndarray( x.length, x, 1 ); // $ExpectError + gfindIndex.ndarray( x.length, x, 1, 0 ); // $ExpectError + gfindIndex.ndarray( x.length, x, 1, 0, isEven, {}, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfind-index/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/examples/index.js new file mode 100644 index 000000000000..4c47d328a7f4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/examples/index.js @@ -0,0 +1,34 @@ +/** +* @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 gfindIndex = require( './../lib' ); + +function isEven( v ) { + return v % 2.0 === 0.0; +} + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +console.log( x ); + +var idx = gfindIndex( x.length, x, 1, isEven ); +console.log( idx ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfind-index/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/lib/accessors.js new file mode 100644 index 000000000000..f24bce7b73ba --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/lib/accessors.js @@ -0,0 +1,75 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MAIN // + +/** +* Returns the index of the first element which passes a test implemented by a predicate function. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {Object} x - input array object +* @param {Collection} x.data - input array data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @param {Callback} clbk - callback function +* @param {*} thisArg - execution context +* @returns {integer} index +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* function isEven( v ) { +* return v % 2.0 === 0.0; +* } +* +* var x = [ 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; +* +* var idx = gfindIndex( x.length, arraylike2object( toAccessorArray( x ) ), 1, 0, isEven ); +* // returns 3 +*/ +function gfindIndex( N, x, strideX, offsetX, clbk, thisArg ) { + var xbuf; + var get; + var ix; + var i; + + // Cache reference to array data: + xbuf = x.data; + + // Cache a reference to the element accessor: + get = x.accessors[ 0 ]; + + ix = offsetX; + for ( i = 0; i < N; i++ ) { + if ( clbk.call( thisArg, get( xbuf, ix ), i, ix, x ) ) { + return i; + } + ix += strideX; + } + return -1; +} + + +// EXPORTS // + +module.exports = gfindIndex; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfind-index/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/lib/index.js new file mode 100644 index 000000000000..05602320cbe5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/lib/index.js @@ -0,0 +1,65 @@ +/** +* @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 index of the first element which passes a test implemented by a predicate function. +* +* @module @stdlib/blas/ext/base/gfind-index +* +* @example +* var gfindIndex = require( '@stdlib/blas/ext/base/gfind-index' ); +* +* function isEven( v ) { +* return v % 2.0 === 0.0; +* } +* +* var x = [ 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; +* +* var idx = gfindIndex( x.length, x, 1, isEven ); +* // returns 3 +* +* @example +* var gfindIndex = require( '@stdlib/blas/ext/base/gfind-index' ); +* +* function isEven( x ) { +* return v % 2.0 === 0.0; +* } +* +* var x = [ 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; +* +* var idx = gfindIndex.ndarray( x.length, x, 1, 0, isEven ); +* // returns 3 +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfind-index/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/lib/main.js new file mode 100644 index 000000000000..30f2c7f3db78 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/lib/main.js @@ -0,0 +1,56 @@ +/** +* @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 stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Returns the index of the first element which passes a test implemented by a predicate function. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Collection} x - input array +* @param {integer} strideX - stride length +* @param {Callback} clbk - callback function +* @param {*} [thisArg] - execution context +* @returns {integer} index +* +* @example +* function isEven( v ) { +* return v % 2.0 === 0.0; +* } +* +* var x = [ 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; +* +* var idx = gfindIndex( x.length, x, 1, isEven ); +* // returns 3 +*/ +function gfindIndex( N, x, strideX, clbk, thisArg ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ), clbk, thisArg ); +} + + +// EXPORTS // + +module.exports = gfindIndex; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfind-index/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/lib/ndarray.js new file mode 100644 index 000000000000..e528e3d7201c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/lib/ndarray.js @@ -0,0 +1,75 @@ +/** +* @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 arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Returns the index of the first element which passes a test implemented by a predicate function. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Collection} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @param {Callback} clbk - callback function +* @param {*} [thisArg] - execution context +* @returns {integer} index +* +* @example +* function isEven( v ) { +* return v % 2.0 === 0.0; +* } +* +* var x = [ 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; +* +* var idx = gfindIndex( x.length, x, 1, 0, isEven ); +* // returns 3 +*/ +function gfindIndex( N, x, strideX, offsetX, clbk, thisArg ) { + var ix; + var o; + var i; + + if ( N <= 0 ) { + return -1; + } + o = arraylike2object( x ); + if ( o.accessorProtocol ) { + return accessors( N, o, strideX, offsetX, clbk, thisArg ); + } + ix = offsetX; + for ( i = 0; i < N; i++ ) { + if ( clbk.call( thisArg, x[ ix ], i, ix, x ) ) { + return i; + } + ix += strideX; + } + return -1; +} + + +// EXPORTS // + +module.exports = gfindIndex; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfind-index/package.json b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/package.json new file mode 100644 index 000000000000..9a39164037d5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/blas/ext/base/gfind-index", + "version": "0.0.0", + "description": "Return the index of the first element 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", + "stdmath", + "mathematics", + "math", + "blas", + "extended", + "find", + "index", + "get", + "search", + "strided", + "array", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfind-index/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/test/test.js new file mode 100644 index 000000000000..4b2ce7715e21 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/test/test.js @@ -0,0 +1,38 @@ +/** +* @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 gfindIndex = require( '@stdlib/blas/ext/base/gfind-index/lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gfindIndex, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof gfindIndex.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfind-index/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/test/test.main.js new file mode 100644 index 000000000000..9eb9e8d8bc27 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/test/test.main.js @@ -0,0 +1,145 @@ +/** +* @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var gfindIndex = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gfindIndex, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( gfindIndex.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function returns the index of the first element which passes a test implemented by a predicate function', function test( t ) { + var actual; + var x; + + x = [ 1.0, 1.0, 2.0, 3.0, 2.0, 3.0 ]; + + // Nonnegative stride... + actual = gfindIndex( x.length, x, 1, clbk ); + t.strictEqual( actual, 2, 'returns expected value' ); + + // Negative stride... + actual = gfindIndex( x.length, x, -1, clbk ); + t.strictEqual( actual, 1, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 === 0.0; + } +}); + +tape( 'the function returns the index of the first element which passes a test implemented by a predicate function (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 1.0, 1.0, 2.0, 3.0, 2.0, 3.0 ] ); + + // Nonnegative stride... + actual = gfindIndex( x.length, x, 1, clbk ); + t.strictEqual( actual, 2, 'returns expected value' ); + + // Negative stride... + actual = gfindIndex( x.length, x, -1, clbk ); + t.strictEqual( actual, 1, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 === 0.0; + } +}); + +tape( 'the function returns `-1` if the provided `N` parameter is less than or equal to zero', function test( t ) { + var actual; + + actual = gfindIndex( 0, [ 1.0, 2.0, 3.0 ], 1, clbk ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gfindIndex( -1, [ 1.0, 2.0, 3.0 ], 1, clbk ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 === 0.0; + } +}); + +tape( 'the function returns `-1` if the provided `N` parameter is less than or equal to zero (accessors)', function test( t ) { + var actual; + + actual = gfindIndex( 0, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1, clbk ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gfindIndex( -1, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1, clbk ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 === 0.0; + } +}); + +tape( 'the function returns `-1` if no element passes the test implemented by a predicate function', function test( t ) { + var actual; + var x; + + x = [ 1.0, 1.0, 3.0, 3.0, 5.0, 5.0 ]; + + actual = gfindIndex( x.length, x, 1, clbk ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 === 0.0; + } +}); + +tape( 'the function returns `-1` if no element passes the test implemented by a predicate function (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 1.0, 1.0, 3.0, 3.0, 5.0, 5.0 ] ); + + actual = gfindIndex( x.length, x, 1, clbk ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 === 0.0; + } +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfind-index/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/test/test.ndarray.js new file mode 100644 index 000000000000..fc88ed59e9fc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfind-index/test/test.ndarray.js @@ -0,0 +1,145 @@ +/** +* @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var gfindIndex = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gfindIndex, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 6', function test( t ) { + t.strictEqual( gfindIndex.length, 6, 'has expected arity' ); + t.end(); +}); + +tape( 'the function returns the index of the first element which passes a test implemented by a predicate function', function test( t ) { + var actual; + var x; + + x = [ 1.0, 1.0, 2.0, 3.0, 2.0, 3.0 ]; + + // Nonnegative stride... + actual = gfindIndex( 3, x, 1, 3, clbk ); + t.strictEqual( actual, 1, 'returns expected value' ); + + // Negative stride... + actual = gfindIndex( 3, x, -1, 3, clbk ); + t.strictEqual( actual, 1, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 === 0.0; + } +}); + +tape( 'the function returns the index of the first element which passes a test implemented by a predicate function (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 1.0, 1.0, 2.0, 3.0, 2.0, 3.0 ] ); + + // Nonnegative stride... + actual = gfindIndex( 3, x, 1, 3, clbk ); + t.strictEqual( actual, 1, 'returns expected value' ); + + // Negative stride... + actual = gfindIndex( 3, x, -1, 3, clbk ); + t.strictEqual( actual, 1, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 === 0.0; + } +}); + +tape( 'the function returns `-1` if the provided `N` parameter is less than or equal to zero', function test( t ) { + var actual; + + actual = gfindIndex( 0, [ 1.0, 2.0, 3.0 ], 1, 0, clbk ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gfindIndex( -1, [ 1.0, 2.0, 3.0 ], 1, 2, clbk ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 === 0.0; + } +}); + +tape( 'the function returns `-1` if the provided `N` parameter is less than or equal to zero (accessors)', function test( t ) { + var actual; + + actual = gfindIndex( 0, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1, 0, clbk ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gfindIndex( -1, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1, 2, clbk ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 === 0.0; + } +}); + +tape( 'the function returns `-1` if no element passes the test implemented by a predicate function', function test( t ) { + var actual; + var x; + + x = [ 1.0, 1.0, 3.0, 3.0, 5.0, 5.0 ]; + + actual = gfindIndex( x.length, x, 1, 0, clbk ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 === 0.0; + } +}); + +tape( 'the function returns `-1` if no element passes the test implemented by a predicate function (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 1.0, 1.0, 3.0, 3.0, 5.0, 5.0 ] ); + + actual = gfindIndex( x.length, x, 1, 0, clbk ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v % 2.0 === 0.0; + } +});