Skip to content

refactor: fix fromIndex handling in blas/ext/base/ndarray/dlast-index-of #7894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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 @@ -52,7 +52,7 @@ var searchElement = scalar2ndarray( 2.0, {
'dtype': 'float64'
});

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

Expand All @@ -78,7 +78,7 @@ var ndarray = require( '@stdlib/ndarray/base/ctor' );
var xbuf = new Float64Array( [ 1.0, 2.0, 4.0, 2.0 ] );
var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );

var searchElement = scalar2ndarray( 10.0, {
var searchElement = scalar2ndarray( 2.0, {
'dtype': 'float64'
});

Expand Down Expand Up @@ -129,7 +129,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': 'float64'
});
fromIndex = scalar2ndarray( 0, {
fromIndex = scalar2ndarray( -1, {
'dtype': 'generic'
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { float64ndarray, typedndarray } from '@stdlib/types/ndarray';
* 'dtype': 'float64'
* });
*
* 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 @@ -29,14 +29,14 @@
* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
* var dlastIndexOf = require( '@stdlib/blas/ext/base/ndarray/dlast-index-of' );
*
* var xbuf = new Float64Array( [ 1.0, 3.0, 4.0, 2.0 ] );
* var xbuf = new Float64Array( [ 1.0, 2.0, 4.0, 2.0 ] );
* var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );
*
* var searchElement = scalar2ndarray( 2.0, {
* 'dtype': 'float64'
* });
*
* var fromIndex = scalar2ndarray( 0, {
* var fromIndex = scalar2ndarray( 3, {
* 'dtype': 'generic'
* });
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' );
* 'dtype': 'float64'
* });
*
* var fromIndex = scalar2ndarray( 0, {
* var fromIndex = scalar2ndarray( 3, {
* 'dtype': 'generic'
* });
*
Expand Down Expand Up @@ -78,14 +78,11 @@ function dlastIndexOf( arrays ) {
} else if ( fromIndex >= N ) {
return -1;
}
N -= fromIndex;
N = fromIndex + 1;
stride = getStride( x, 0 );
offset = getOffset( x ) + ( stride*fromIndex );
offset = getOffset( x );

idx = strided( N, searchElement, getData( x ), stride, offset );
if ( idx >= 0 ) {
idx += fromIndex;
}
return idx;
}

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

searchElement = scalar2ndarray( 2.0, {
'dtype': 'float64'
Expand All @@ -132,7 +132,7 @@ tape( 'the function returns the last index of an element which equals a provided
'dtype': 'generic'
});
actual = dlastIndexOf( [ x, searchElement, fromIndex ] );
t.strictEqual( actual, 3, 'returns expected value' );
t.strictEqual( actual, -1, 'returns expected value' );

t.end();
});
Expand Down