diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/README.md
index 73a627cff26d..bbf7310c1bdf 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/README.md
+++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/README.md
@@ -42,11 +42,16 @@ Returns the index of the first element in a one-dimensional double-precision flo
```javascript
var Float64Vector = require( '@stdlib/ndarray/vector/float64' );
+var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var x = new Float64Vector( [ 1.0, 2.0, 3.0, 4.0 ] );
var y = new Float64Vector( [ 0.0, 0.0, 3.0, 0.0 ] );
-var idx = dfirstIndexEqual( [ x, y ] );
+var fromIndex = scalar2ndarray( 0, {
+ 'dtype': 'generic'
+});
+
+var idx = dfirstIndexEqual( [ x, y, fromIndex ] );
// returns 2
```
@@ -56,16 +61,22 @@ The function has the following parameters:
- first one-dimensional input ndarray.
- second one-dimensional input ndarray.
+ - a zero-dimensional ndarray containing the index from which to begin searching.
If the function is unable to find an element in the first one-dimensional input ndarray equal to a corresponding element in the second one-dimensional input ndarray, the function returns `-1`.
```javascript
var Float64Vector = require( '@stdlib/ndarray/vector/float64' );
+var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var x = new Float64Vector( [ 1.0, 2.0, 3.0, 4.0 ] );
var y = new Float64Vector( [ 5.0, 6.0, 7.0, 8.0 ] );
-var idx = dfirstIndexEqual( [ x, y ] );
+var fromIndex = scalar2ndarray( 0, {
+ 'dtype': 'generic'
+});
+
+var idx = dfirstIndexEqual( [ x, y, fromIndex ] );
// returns -1
```
@@ -77,6 +88,7 @@ var idx = dfirstIndexEqual( [ x, y ] );
## Notes
+- If a specified starting search index is negative, the function resolves the starting search index by counting backward from the last element (where `-1` refers to the last element).
- When comparing elements, the function checks for equality using the strict equality operator `===`. As a consequence, `NaN` values are considered distinct, and `-0` and `+0` are considered the same.
@@ -91,7 +103,9 @@ var idx = dfirstIndexEqual( [ x, y ] );
```javascript
var discreteUniform = require( '@stdlib/random/discrete-uniform' );
+var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
+var ndarraylike2scalar = require( '@stdlib/ndarray/ndarraylike2scalar' );
var dfirstIndexEqual = require( '@stdlib/blas/ext/base/ndarray/dfirst-index-equal' );
var opts = {
@@ -103,7 +117,12 @@ console.log( ndarray2array( x ) );
var y = discreteUniform( [ 10 ], 0, 10, opts );
console.log( ndarray2array( y ) );
-var idx = dfirstIndexEqual( [ x, y ] );
+var fromIndex = scalar2ndarray( 0, {
+ 'dtype': 'generic'
+});
+console.log( 'From Index:', ndarraylike2scalar( fromIndex ) );
+
+var idx = dfirstIndexEqual( [ x, y, fromIndex ] );
console.log( idx );
```
diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/benchmark/benchmark.js
index 964d16deb117..5c949d4d82ca 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/benchmark/benchmark.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/benchmark/benchmark.js
@@ -23,6 +23,7 @@
var bench = require( '@stdlib/bench' );
var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
var pow = require( '@stdlib/math/base/special/pow' );
+var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var oneTo = require( '@stdlib/blas/ext/one-to' );
var zeros = require( '@stdlib/ndarray/zeros' );
var format = require( '@stdlib/string/format' );
@@ -47,8 +48,15 @@ var options = {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
- var x = oneTo( [ len ], options );
- var y = zeros( [ len ], options );
+ var fromIndex;
+ var x;
+ var y;
+
+ x = oneTo( [ len ], options );
+ y = zeros( [ len ], options );
+ fromIndex = scalar2ndarray( 0, {
+ 'dtype': 'generic'
+ });
return benchmark;
/**
@@ -63,7 +71,7 @@ function createBenchmark( len ) {
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
- out = dfirstIndexEqual( [ x, y ] );
+ out = dfirstIndexEqual( [ x, y, fromIndex ] );
if ( out !== out ) {
b.fail( 'should return an integer' );
}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/docs/repl.txt
index 3cc1eab8f657..bdedc7781ed0 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/docs/repl.txt
+++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/docs/repl.txt
@@ -4,6 +4,10 @@
precision floating-point ndarray equal to a corresponding element in
another one-dimensional double-precision floating-point ndarray.
+ If a specified starting search index is negative, the function resolves the
+ starting search index by counting backward from the last element (where `-1`
+ refers to the last element).
+
When comparing elements, the function checks for equality using the strict
equality operator `===`. As a consequence, `NaN` values are considered
distinct, and `-0` and `+0` are considered the same.
@@ -15,6 +19,8 @@
- first one-dimensional input ndarray.
- second one-dimensional input ndarray.
+ - a zero-dimensional ndarray containing the index from which to begin
+ searching.
Returns
-------
@@ -25,7 +31,8 @@
--------
> var x = new {{alias:@stdlib/ndarray/vector/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] );
> var y = new {{alias:@stdlib/ndarray/vector/float64}}( [ 0.0, 0.0, 3.0, 0.0 ] );
- > {{alias}}( [ x, y ] )
+ > var i = {{alias:@stdlib/ndarray/from-scalar}}( 0, { 'dtype': 'generic' } );
+ > {{alias}}( [ x, y, i ] )
2
See Also
diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/docs/types/index.d.ts
index d4c3062d4c11..0e1ed94c7ef0 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/docs/types/index.d.ts
+++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/docs/types/index.d.ts
@@ -20,7 +20,7 @@
///
-import { float64ndarray } from '@stdlib/types/ndarray';
+import { float64ndarray, typedndarray } from '@stdlib/types/ndarray';
/**
* Returns the index of the first element in a one-dimensional double-precision floating-point ndarray equal to a corresponding element in another one-dimensional double-precision floating-point ndarray.
@@ -31,6 +31,7 @@ import { float64ndarray } from '@stdlib/types/ndarray';
*
* - first one-dimensional input ndarray.
* - second one-dimensional input ndarray.
+* - a zero-dimensional ndarray containing the index from which to begin searching.
*
* - When comparing elements, the function checks for equality using the strict equality operator `===`. As a consequence, `NaN` values are considered distinct, and `-0` and `+0` are considered the same.
*
@@ -39,14 +40,19 @@ import { float64ndarray } from '@stdlib/types/ndarray';
*
* @example
* var Float64Vector = require( '@stdlib/ndarray/vector/float64' );
+* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
*
* var x = new Float64Vector( [ 1.0, 2.0, 3.0, 4.0 ] );
* var y = new Float64Vector( [ 0.0, 0.0, 3.0, 0.0 ] );
*
-* var idx = dfirstIndexEqual( [ x, y ] );
+* var fromIndex = scalar2ndarray( 0, {
+* 'dtype': 'generic'
+* });
+*
+* var idx = dfirstIndexEqual( [ x, y, fromIndex ] );
* // returns 2
*/
-declare function dfirstIndexEqual( arrays: [ float64ndarray, float64ndarray ] ): number;
+declare function dfirstIndexEqual( arrays: [ float64ndarray, float64ndarray, typedndarray ] ): number;
// EXPORTS //
diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/docs/types/test.ts
index 343032028dda..3ddec919973d 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/docs/types/test.ts
+++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/docs/types/test.ts
@@ -19,6 +19,7 @@
/* eslint-disable space-in-parens */
import zeros = require( '@stdlib/ndarray/zeros' );
+import scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
import dfirstIndexEqual = require( './index' );
@@ -32,8 +33,11 @@ import dfirstIndexEqual = require( './index' );
const y = zeros( [ 10 ], {
'dtype': 'float64'
});
+ const fromIndex = scalar2ndarray( 0, {
+ 'dtype': 'generic'
+ });
- dfirstIndexEqual( [ x, y ] ); // $ExpectType number
+ dfirstIndexEqual( [ x, y, fromIndex ] ); // $ExpectType number
}
// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays...
@@ -57,7 +61,10 @@ import dfirstIndexEqual = require( './index' );
const y = zeros( [ 10 ], {
'dtype': 'float64'
});
+ const fromIndex = scalar2ndarray( 0, {
+ 'dtype': 'generic'
+ });
dfirstIndexEqual(); // $ExpectError
- dfirstIndexEqual( [ x, y ], {} ); // $ExpectError
+ dfirstIndexEqual( [ x, y, fromIndex ], {} ); // $ExpectError
}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/examples/index.js
index 076e4cc382cf..a5f56f1d3d3e 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/examples/index.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/examples/index.js
@@ -19,7 +19,9 @@
'use strict';
var discreteUniform = require( '@stdlib/random/discrete-uniform' );
+var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
+var ndarraylike2scalar = require( '@stdlib/ndarray/ndarraylike2scalar' );
var dfirstIndexEqual = require( './../lib' );
var opts = {
@@ -31,5 +33,10 @@ console.log( ndarray2array( x ) );
var y = discreteUniform( [ 10 ], 0, 10, opts );
console.log( ndarray2array( y ) );
-var idx = dfirstIndexEqual( [ x, y ] );
+var fromIndex = scalar2ndarray( 0, {
+ 'dtype': 'generic'
+});
+console.log( 'From Index:', ndarraylike2scalar( fromIndex ) );
+
+var idx = dfirstIndexEqual( [ x, y, fromIndex ] );
console.log( idx );
diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/lib/index.js
index 63f15b2d86c1..0f81deaee1a4 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/lib/index.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/lib/index.js
@@ -25,12 +25,17 @@
*
* @example
* var Float64Vector = require( '@stdlib/ndarray/vector/float64' );
+* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
* var dfirstIndexEqual = require( '@stdlib/blas/ext/base/ndarray/dfirst-index-equal' );
*
* var x = new Float64Vector( [ 1.0, 2.0, 3.0, 4.0 ] );
* var y = new Float64Vector( [ 0.0, 0.0, 3.0, 0.0 ] );
*
-* var idx = dfirstIndexEqual( [ x, y ] );
+* var fromIndex = scalar2ndarray( 0, {
+* 'dtype': 'generic'
+* });
+*
+* var idx = dfirstIndexEqual( [ x, y, fromIndex ] );
* // returns 2
*/
diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/lib/main.js
index ce1ac296992b..62e5daaded69 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/lib/main.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/lib/main.js
@@ -25,6 +25,7 @@ var getStride = require( '@stdlib/ndarray/base/stride' );
var getOffset = require( '@stdlib/ndarray/base/offset' );
var getData = require( '@stdlib/ndarray/base/data-buffer' );
var strided = require( '@stdlib/blas/ext/base/dfirst-index-equal' ).ndarray;
+var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' );
// MAIN //
@@ -38,6 +39,7 @@ var strided = require( '@stdlib/blas/ext/base/dfirst-index-equal' ).ndarray;
*
* - first one-dimensional input ndarray.
* - second one-dimensional input ndarray.
+* - a zero-dimensional ndarray containing the index from which to begin searching.
*
* - When comparing elements, the function checks for equality using the strict equality operator `===`. As a consequence, `NaN` values are considered distinct, and `-0` and `+0` are considered the same.
*
@@ -46,17 +48,49 @@ var strided = require( '@stdlib/blas/ext/base/dfirst-index-equal' ).ndarray;
*
* @example
* var Float64Vector = require( '@stdlib/ndarray/vector/float64' );
+* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
*
* var x = new Float64Vector( [ 1.0, 2.0, 3.0, 4.0 ] );
* var y = new Float64Vector( [ 0.0, 0.0, 3.0, 0.0 ] );
*
-* var idx = dfirstIndexEqual( [ x, y ] );
+* var fromIndex = scalar2ndarray( 0, {
+* 'dtype': 'generic'
+* });
+*
+* var idx = dfirstIndexEqual( [ x, y, fromIndex ] );
* // returns 2
*/
function dfirstIndexEqual( arrays ) {
- var x = arrays[ 0 ];
- var y = arrays[ 1 ];
- return strided( numelDimension( x, 0 ), getData( x ), getStride( x, 0 ), getOffset( x ), getData( y ), getStride( y, 0 ), getOffset( y ) ); // eslint-disable-line max-len
+ var fromIndex;
+ var strideX;
+ var strideY;
+ var idx;
+ var N;
+ var x;
+ var y;
+
+ x = arrays[ 0 ];
+ y = arrays[ 1 ];
+ N = numelDimension( x, 0 );
+ fromIndex = ndarraylike2scalar( arrays[ 2 ] );
+
+ if ( fromIndex < 0 ) {
+ fromIndex += N;
+ if ( fromIndex < 0 ) {
+ fromIndex = 0;
+ }
+ } else if ( fromIndex >= N ) {
+ return -1;
+ }
+ N -= fromIndex;
+ strideX = getStride( x, 0 );
+ strideY = getStride( y, 0 );
+
+ idx = strided( N, getData( x ), strideX, getOffset( x ) + ( strideX*fromIndex ), getData( y ), strideY, getOffset( y ) + ( strideY*fromIndex ) ); // eslint-disable-line max-len
+ if ( idx >= 0 ) {
+ idx += fromIndex;
+ }
+ return idx;
}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/test/test.js
index 190b7ef714b4..0588099df6d2 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/test/test.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dfirst-index-equal/test/test.js
@@ -23,6 +23,7 @@
var tape = require( 'tape' );
var ndarray = require( '@stdlib/ndarray/base/ctor' );
var Float64Array = require( '@stdlib/array/float64' );
+var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var dfirstIndexEqual = require( './../lib' );
@@ -52,56 +53,71 @@ tape( 'main export is a function', function test( t ) {
});
tape( 'the function returns the index of the first element in a one-dimensional ndarray equal to a corresponding element in another one-dimensional ndarray', function test( t ) {
+ var fromIndex;
var actual;
var x;
var y;
+ fromIndex = scalar2ndarray( 0, {
+ 'dtype': 'generic'
+ });
+
x = vector( new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), 6, 1, 0 );
y = vector( new Float64Array( [ 1.0, 0.0, 3.0, 0.0, 5.0, 0.0 ] ), 6, 1, 0 );
- actual = dfirstIndexEqual( [ x, y ] );
+ actual = dfirstIndexEqual( [ x, y, fromIndex ] );
t.strictEqual( actual, 0, 'returns expected value' );
x = vector( new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), 6, 1, 0 );
y = vector( new Float64Array( [ 0.0, 2.0, 3.0, 0.0, 0.0, 0.0 ] ), 6, 1, 0 );
- actual = dfirstIndexEqual( [ x, y ] );
+ actual = dfirstIndexEqual( [ x, y, fromIndex ] );
t.strictEqual( actual, 1, 'returns expected value' );
x = vector( new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), 6, 1, 0 );
y = vector( new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 6.0 ] ), 6, 1, 0 );
- actual = dfirstIndexEqual( [ x, y ] );
+ actual = dfirstIndexEqual( [ x, y, fromIndex ] );
t.strictEqual( actual, 5, 'returns expected value' );
x = vector( new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), 6, 1, 0 );
y = vector( new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ), 6, 1, 0 );
- actual = dfirstIndexEqual( [ x, y ] );
+ actual = dfirstIndexEqual( [ x, y, fromIndex ] );
t.strictEqual( actual, -1, 'returns expected value' );
t.end();
});
tape( 'the function returns `-1` if unable to find an element in the first one-dimensional input ndarray equal to a corresponding element in the second one-dimensional input ndarray', function test( t ) {
+ var fromIndex;
var actual;
var x;
var y;
+ fromIndex = scalar2ndarray( 0, {
+ 'dtype': 'generic'
+ });
+
x = vector( new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), 6, 1, 0 );
y = vector( new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ), 6, 1, 0 );
- actual = dfirstIndexEqual( [ x, y ] );
+ actual = dfirstIndexEqual( [ x, y, fromIndex ] );
t.strictEqual( actual, -1, 'returns expected value' );
t.end();
});
tape( 'the function supports one-dimensional ndarrays having non-unit strides', function test( t ) {
+ var fromIndex;
var actual;
var x;
var y;
+ fromIndex = scalar2ndarray( 0, {
+ 'dtype': 'generic'
+ });
+
x = new Float64Array([
1.0, // 0
2.0,
@@ -123,17 +139,22 @@ tape( 'the function supports one-dimensional ndarrays having non-unit strides',
8.0
]);
- actual = dfirstIndexEqual( [ vector( x, 4, 2, 0 ), vector( y, 4, 2, 0 ) ] );
+ actual = dfirstIndexEqual( [ vector( x, 4, 2, 0 ), vector( y, 4, 2, 0 ), fromIndex ] );
t.strictEqual( actual, 2, 'returns expected value' );
t.end();
});
tape( 'the function supports one-dimensional ndarrays having negative strides', function test( t ) {
+ var fromIndex;
var actual;
var x;
var y;
+ fromIndex = scalar2ndarray( 0, {
+ 'dtype': 'generic'
+ });
+
x = new Float64Array([
1.0, // 3
2.0,
@@ -155,17 +176,22 @@ tape( 'the function supports one-dimensional ndarrays having negative strides',
8.0
]);
- actual = dfirstIndexEqual( [ vector( x, 4, -2, 6 ), vector( y, 4, -2, 6 ) ] );
+ actual = dfirstIndexEqual( [ vector( x, 4, -2, 6 ), vector( y, 4, -2, 6 ), fromIndex ] );
t.strictEqual( actual, 2, 'returns expected value' );
t.end();
});
tape( 'the function supports one-dimensional ndarrays having non-zero offsets', function test( t ) {
+ var fromIndex;
var actual;
var x;
var y;
+ fromIndex = scalar2ndarray( 0, {
+ 'dtype': 'generic'
+ });
+
x = new Float64Array([
0.0,
1.0, // 0
@@ -187,36 +213,144 @@ tape( 'the function supports one-dimensional ndarrays having non-zero offsets',
4.0 // 3
]);
- actual = dfirstIndexEqual( [ vector( x, 4, 2, 1 ), vector( y, 4, 2, 1 ) ] );
+ actual = dfirstIndexEqual( [ vector( x, 4, 2, 1 ), vector( y, 4, 2, 1 ), fromIndex ] );
t.strictEqual( actual, 1, 'returns expected value' );
t.end();
});
tape( 'the function considers NaN values as distinct', function test( t ) {
+ var fromIndex;
var actual;
var x;
var y;
+ fromIndex = scalar2ndarray( 0, {
+ 'dtype': 'generic'
+ });
+
x = vector( new Float64Array( [ NaN, NaN, NaN ] ), 3, 1, 0 );
y = vector( new Float64Array( [ NaN, NaN, NaN ] ), 3, 1, 0 );
- actual = dfirstIndexEqual( [ x, y ] );
+ actual = dfirstIndexEqual( [ x, y, fromIndex ] );
t.strictEqual( actual, -1, 'returns expected value' );
t.end();
});
tape( 'the function considers -0 and +0 as the same', function test( t ) {
+ var fromIndex;
var actual;
var x;
var y;
+ fromIndex = scalar2ndarray( 0, {
+ 'dtype': 'generic'
+ });
+
x = vector( new Float64Array( [ 1.0, -0.0, 3.0 ] ), 3, 1, 0 );
y = vector( new Float64Array( [ 0.0, 0.0, 0.0 ] ), 3, 1, 0 );
- actual = dfirstIndexEqual( [ x, y ] );
+ actual = dfirstIndexEqual( [ x, y, fromIndex ] );
t.strictEqual( actual, 1, 'returns expected value' );
t.end();
});
+
+tape( 'the function supports a nonnegative starting search index', function test( t ) {
+ var fromIndex;
+ var actual;
+ var x;
+ var y;
+
+ x = vector( new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), 6, 1, 0 );
+ y = vector( new Float64Array( [ 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 ] ), 6, 1, 0 );
+
+ fromIndex = scalar2ndarray( 0, {
+ 'dtype': 'generic'
+ });
+ actual = dfirstIndexEqual( [ x, y, fromIndex ] );
+ t.strictEqual( actual, 0, 'returns expected value' );
+
+ fromIndex = scalar2ndarray( 1, {
+ 'dtype': 'generic'
+ });
+ actual = dfirstIndexEqual( [ x, y, fromIndex ] );
+ t.strictEqual( actual, 1, 'returns expected value' );
+
+ fromIndex = scalar2ndarray( 2, {
+ 'dtype': 'generic'
+ });
+ actual = dfirstIndexEqual( [ x, y, fromIndex ] );
+ t.strictEqual( actual, 3, 'returns expected value' );
+
+ fromIndex = scalar2ndarray( 4, {
+ 'dtype': 'generic'
+ });
+ actual = dfirstIndexEqual( [ x, y, fromIndex ] );
+ t.strictEqual( actual, 5, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'the function supports a negative starting search index', function test( t ) {
+ var fromIndex;
+ var actual;
+ var x;
+ var y;
+
+ x = vector( new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), 6, 1, 0 );
+ y = vector( new Float64Array( [ 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 ] ), 6, 1, 0 );
+
+ fromIndex = scalar2ndarray( -1, {
+ 'dtype': 'generic'
+ });
+ actual = dfirstIndexEqual( [ x, y, fromIndex ] );
+ t.strictEqual( actual, 5, 'returns expected value' );
+
+ fromIndex = scalar2ndarray( -2, {
+ 'dtype': 'generic'
+ });
+ actual = dfirstIndexEqual( [ x, y, fromIndex ] );
+ t.strictEqual( actual, 5, 'returns expected value' );
+
+ fromIndex = scalar2ndarray( -3, {
+ 'dtype': 'generic'
+ });
+ actual = dfirstIndexEqual( [ x, y, fromIndex ] );
+ t.strictEqual( actual, 3, 'returns expected value' );
+
+ fromIndex = scalar2ndarray( -7, {
+ 'dtype': 'generic'
+ });
+ actual = dfirstIndexEqual( [ x, y, fromIndex ] );
+ t.strictEqual( actual, 0, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'the function returns `-1` if provided a starting search index which is greater than or equal to number of elements in the input ndarray', function test( t ) {
+ var fromIndex;
+ var actual;
+ var x;
+ var y;
+
+ x = vector( new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), 6, 1, 0 );
+ y = vector( new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), 6, 1, 0 );
+
+ fromIndex = scalar2ndarray( 6, {
+ 'dtype': 'generic'
+ });
+
+ actual = dfirstIndexEqual( [ x, y, fromIndex ] );
+ t.strictEqual( actual, -1, 'returns expected value' );
+
+ fromIndex = scalar2ndarray( 7, {
+ 'dtype': 'generic'
+ });
+
+ actual = dfirstIndexEqual( [ x, y, fromIndex ] );
+ t.strictEqual( actual, -1, 'returns expected value' );
+
+ t.end();
+});