Skip to content

Commit 69832d0

Browse files
headlessNodekgryte
andauthored
fix: update fromIndex handling in blas/ext/base/ndarray/dlast-index-of
PR-URL: #7894 Ref: #2656 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]>
1 parent 57b828d commit 69832d0

File tree

7 files changed

+18
-29
lines changed

7 files changed

+18
-29
lines changed

lib/node_modules/@stdlib/blas/ext/base/ndarray/dlast-index-of/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var searchElement = scalar2ndarray( 2.0, {
5252
'dtype': 'float64'
5353
});
5454

55-
var fromIndex = scalar2ndarray( 0, {
55+
var fromIndex = scalar2ndarray( 3, {
5656
'dtype': 'generic'
5757
});
5858

@@ -82,7 +82,7 @@ var searchElement = scalar2ndarray( 10.0, {
8282
'dtype': 'float64'
8383
});
8484

85-
var fromIndex = scalar2ndarray( 0, {
85+
var fromIndex = scalar2ndarray( 3, {
8686
'dtype': 'generic'
8787
});
8888

@@ -129,7 +129,7 @@ var searchElement = scalar2ndarray( 80.0, {
129129
});
130130
console.log( 'Search Element:', ndarraylike2scalar( searchElement ) );
131131

132-
var fromIndex = scalar2ndarray( 0, {
132+
var fromIndex = scalar2ndarray( -1, {
133133
'dtype': 'generic'
134134
});
135135
console.log( 'From Index:', ndarraylike2scalar( fromIndex ) );

lib/node_modules/@stdlib/blas/ext/base/ndarray/dlast-index-of/benchmark/benchmark.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function createBenchmark( len ) {
5858
searchElement = scalar2ndarray( -10.0, {
5959
'dtype': 'float64'
6060
});
61-
fromIndex = scalar2ndarray( 0, {
61+
fromIndex = scalar2ndarray( -1, {
6262
'dtype': 'generic'
6363
});
6464

lib/node_modules/@stdlib/blas/ext/base/ndarray/dlast-index-of/docs/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import { float64ndarray, typedndarray } from '@stdlib/types/ndarray';
4141
* 'dtype': 'float64'
4242
* });
4343
*
44-
* var fromIndex = scalar2ndarray( 0, {
44+
* var fromIndex = scalar2ndarray( 3, {
4545
* 'dtype': 'generic'
4646
* });
4747
*

lib/node_modules/@stdlib/blas/ext/base/ndarray/dlast-index-of/examples/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var searchElement = scalar2ndarray( 80.0, {
3636
});
3737
console.log( 'Search Element:', ndarraylike2scalar( searchElement ) );
3838

39-
var fromIndex = scalar2ndarray( 0, {
39+
var fromIndex = scalar2ndarray( -1, {
4040
'dtype': 'generic'
4141
});
4242
console.log( 'From Index:', ndarraylike2scalar( fromIndex ) );

lib/node_modules/@stdlib/blas/ext/base/ndarray/dlast-index-of/lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
3030
* var dlastIndexOf = require( '@stdlib/blas/ext/base/ndarray/dlast-index-of' );
3131
*
32-
* var xbuf = new Float64Array( [ 1.0, 3.0, 4.0, 2.0 ] );
32+
* var xbuf = new Float64Array( [ 1.0, 2.0, 4.0, 2.0 ] );
3333
* var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );
3434
*
3535
* var searchElement = scalar2ndarray( 2.0, {
3636
* 'dtype': 'float64'
3737
* });
3838
*
39-
* var fromIndex = scalar2ndarray( 0, {
39+
* var fromIndex = scalar2ndarray( 3, {
4040
* 'dtype': 'generic'
4141
* });
4242
*

lib/node_modules/@stdlib/blas/ext/base/ndarray/dlast-index-of/lib/main.js

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' );
4949
* 'dtype': 'float64'
5050
* });
5151
*
52-
* var fromIndex = scalar2ndarray( 0, {
52+
* var fromIndex = scalar2ndarray( 3, {
5353
* 'dtype': 'generic'
5454
* });
5555
*
@@ -59,9 +59,6 @@ var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' );
5959
function dlastIndexOf( arrays ) {
6060
var searchElement;
6161
var fromIndex;
62-
var stride;
63-
var offset;
64-
var idx;
6562
var N;
6663
var x;
6764

@@ -73,20 +70,12 @@ function dlastIndexOf( arrays ) {
7370
if ( fromIndex < 0 ) {
7471
fromIndex += N;
7572
if ( fromIndex < 0 ) {
76-
fromIndex = 0;
73+
return -1;
7774
}
7875
} else if ( fromIndex >= N ) {
79-
return -1;
76+
fromIndex = N - 1;
8077
}
81-
N -= fromIndex;
82-
stride = getStride( x, 0 );
83-
offset = getOffset( x ) + ( stride*fromIndex );
84-
85-
idx = strided( N, searchElement, getData( x ), stride, offset );
86-
if ( idx >= 0 ) {
87-
idx += fromIndex;
88-
}
89-
return idx;
78+
return strided( fromIndex+1, searchElement, getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len
9079
}
9180

9281

lib/node_modules/@stdlib/blas/ext/base/ndarray/dlast-index-of/test/test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ tape( 'the function returns the last index of an element which equals a provided
6464
searchElement = scalar2ndarray( 1.0, {
6565
'dtype': 'float64'
6666
});
67-
fromIndex = scalar2ndarray( 0, {
67+
fromIndex = scalar2ndarray( 5, {
6868
'dtype': 'generic'
6969
});
7070
actual = dlastIndexOf( [ x, searchElement, fromIndex ] );
@@ -73,7 +73,7 @@ tape( 'the function returns the last index of an element which equals a provided
7373
searchElement = scalar2ndarray( 2.0, {
7474
'dtype': 'float64'
7575
});
76-
fromIndex = scalar2ndarray( 0, {
76+
fromIndex = scalar2ndarray( 5, {
7777
'dtype': 'generic'
7878
});
7979
actual = dlastIndexOf( [ x, searchElement, fromIndex ] );
@@ -114,7 +114,7 @@ tape( 'the function returns the last index of an element which equals a provided
114114
'dtype': 'generic'
115115
});
116116
actual = dlastIndexOf( [ x, searchElement, fromIndex ] );
117-
t.strictEqual( actual, 5, 'returns expected value' );
117+
t.strictEqual( actual, 4, 'returns expected value' );
118118

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

137137
t.end();
138138
});
139139

140-
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 ) {
140+
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 ) {
141141
var searchElement;
142142
var fromIndex;
143143
var actual;
@@ -152,7 +152,7 @@ tape( 'the function returns `-1` if provided a starting search index which is gr
152152
});
153153

154154
actual = dlastIndexOf( [ x, searchElement, fromIndex ] );
155-
t.strictEqual( actual, -1, 'returns expected value' );
155+
t.strictEqual( actual, 3, 'returns expected value' );
156156

157157
t.end();
158158
});

0 commit comments

Comments
 (0)