Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var searchElement = scalar2ndarray( 2.0, {
'dtype': 'generic'
});

var fromIndex = scalar2ndarray( 0, {
var fromIndex = scalar2ndarray( 3, {
'dtype': 'generic'
});

Expand Down Expand Up @@ -80,7 +80,7 @@ var searchElement = scalar2ndarray( 10.0, {
'dtype': 'generic'
});

var fromIndex = scalar2ndarray( 0, {
var fromIndex = scalar2ndarray( 3, {
'dtype': 'generic'
});

Expand Down Expand Up @@ -127,7 +127,7 @@ var searchElement = scalar2ndarray( 80.0, {
});
console.log( 'Search Element:', ndarraylike2scalar( searchElement ) );

var fromIndex = scalar2ndarray( 0, {
var fromIndex = scalar2ndarray( -1, {
'dtype': 'generic'
});
console.log( 'From Index:', ndarraylike2scalar( fromIndex ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function createBenchmark( len ) {
searchElement = scalar2ndarray( -10.0, {
'dtype': options.dtype
});
fromIndex = scalar2ndarray( 0, {
fromIndex = scalar2ndarray( -1, {
'dtype': 'generic'
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { typedndarray } from '@stdlib/types/ndarray';
* 'dtype': 'generic'
* });
*
* var fromIndex = scalar2ndarray( 0, {
* var fromIndex = scalar2ndarray( 3, {
* 'dtype': 'generic'
* });
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var searchElement = scalar2ndarray( 80.0, {
});
console.log( 'Search Element:', ndarraylike2scalar( searchElement ) );

var fromIndex = scalar2ndarray( 0, {
var fromIndex = scalar2ndarray( -1, {
'dtype': 'generic'
});
console.log( 'From Index:', ndarraylike2scalar( fromIndex ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* 'dtype': 'generic'
* });
*
* var fromIndex = scalar2ndarray( 0, {
* var fromIndex = scalar2ndarray( 3, {
* 'dtype': 'generic'
* });
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' );
* 'dtype': 'generic'
* });
*
* var fromIndex = scalar2ndarray( 0, {
* var fromIndex = scalar2ndarray( 3, {
* 'dtype': 'generic'
* });
*
Expand All @@ -57,9 +57,6 @@ var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' );
function glastIndexOf( arrays ) {
var searchElement;
var fromIndex;
var stride;
var offset;
var idx;
var N;
var x;

Expand All @@ -71,20 +68,12 @@ function glastIndexOf( arrays ) {
if ( fromIndex < 0 ) {
fromIndex += N;
if ( fromIndex < 0 ) {
fromIndex = 0;
return -1;
}
} else if ( fromIndex >= N ) {
return -1;
fromIndex = N - 1;
}
N -= fromIndex;
stride = getStride( x, 0 );
offset = getOffset( x ) + ( stride*fromIndex );

idx = strided( N, searchElement, getData( x ), stride, offset );
if ( idx >= 0 ) {
idx += fromIndex;
}
return idx;
return strided( fromIndex+1, searchElement, getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ tape( 'the function returns the last index of an element which equals a provided
searchElement = scalar2ndarray( 1.0, {
'dtype': 'generic'
});
fromIndex = scalar2ndarray( 0, {
fromIndex = scalar2ndarray( 5, {
'dtype': 'generic'
});
actual = glastIndexOf( [ x, searchElement, fromIndex ] );
Expand All @@ -72,7 +72,7 @@ tape( 'the function returns the last index of an element which equals a provided
searchElement = scalar2ndarray( 2.0, {
'dtype': 'generic'
});
fromIndex = scalar2ndarray( 0, {
fromIndex = scalar2ndarray( 5, {
'dtype': 'generic'
});
actual = glastIndexOf( [ x, searchElement, fromIndex ] );
Expand Down Expand Up @@ -113,7 +113,7 @@ tape( 'the function returns the last index of an element which equals a provided
'dtype': 'generic'
});
actual = glastIndexOf( [ x, searchElement, fromIndex ] );
t.strictEqual( actual, 5, 'returns expected value' );
t.strictEqual( actual, 4, 'returns expected value' );

searchElement = scalar2ndarray( 2.0, {
'dtype': 'generic'
Expand All @@ -131,12 +131,12 @@ tape( 'the function returns the last index of an element which equals a provided
'dtype': 'generic'
});
actual = glastIndexOf( [ x, searchElement, fromIndex ] );
t.strictEqual( actual, 3, 'returns expected value' );
t.strictEqual( actual, -1, '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 ) {
tape( 'the function clamps the provided starting search index if it is greater than or equal to number of elements in the input ndarray', function test( t ) {
var searchElement;
var fromIndex;
var actual;
Expand All @@ -151,7 +151,7 @@ tape( 'the function returns `-1` if provided a starting search index which is gr
});

actual = glastIndexOf( [ x, searchElement, fromIndex ] );
t.strictEqual( actual, -1, 'returns expected value' );
t.strictEqual( actual, 3, 'returns expected value' );

t.end();
});