Skip to content

Commit b8fa53c

Browse files
headlessNodePlaneshifter
authored andcommitted
fix: update fromIndex handling in blas/ext/base/ndarray/glast-index-of
PR-URL: #8008 Closes: stdlib-js/metr-issue-tracker#72 Ref: #2656 Reviewed-by: Athan Reines <[email protected]>
1 parent 63a844c commit b8fa53c

File tree

7 files changed

+17
-28
lines changed

7 files changed

+17
-28
lines changed

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

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

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

@@ -80,7 +80,7 @@ var searchElement = scalar2ndarray( 10.0, {
8080
'dtype': 'generic'
8181
});
8282

83-
var fromIndex = scalar2ndarray( 0, {
83+
var fromIndex = scalar2ndarray( 3, {
8484
'dtype': 'generic'
8585
});
8686

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

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

lib/node_modules/@stdlib/blas/ext/base/ndarray/glast-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': options.dtype
6060
});
61-
fromIndex = scalar2ndarray( 0, {
61+
fromIndex = scalar2ndarray( -1, {
6262
'dtype': 'generic'
6363
});
6464

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

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

lib/node_modules/@stdlib/blas/ext/base/ndarray/glast-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/glast-index-of/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* 'dtype': 'generic'
3636
* });
3737
*
38-
* var fromIndex = scalar2ndarray( 0, {
38+
* var fromIndex = scalar2ndarray( 3, {
3939
* 'dtype': 'generic'
4040
* });
4141
*

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

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' );
4747
* 'dtype': 'generic'
4848
* });
4949
*
50-
* var fromIndex = scalar2ndarray( 0, {
50+
* var fromIndex = scalar2ndarray( 3, {
5151
* 'dtype': 'generic'
5252
* });
5353
*
@@ -57,9 +57,6 @@ var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' );
5757
function glastIndexOf( arrays ) {
5858
var searchElement;
5959
var fromIndex;
60-
var stride;
61-
var offset;
62-
var idx;
6360
var N;
6461
var x;
6562

@@ -71,20 +68,12 @@ function glastIndexOf( arrays ) {
7168
if ( fromIndex < 0 ) {
7269
fromIndex += N;
7370
if ( fromIndex < 0 ) {
74-
fromIndex = 0;
71+
return -1;
7572
}
7673
} else if ( fromIndex >= N ) {
77-
return -1;
74+
fromIndex = N - 1;
7875
}
79-
N -= fromIndex;
80-
stride = getStride( x, 0 );
81-
offset = getOffset( x ) + ( stride*fromIndex );
82-
83-
idx = strided( N, searchElement, getData( x ), stride, offset );
84-
if ( idx >= 0 ) {
85-
idx += fromIndex;
86-
}
87-
return idx;
76+
return strided( fromIndex+1, searchElement, getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len
8877
}
8978

9079

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ tape( 'the function returns the last index of an element which equals a provided
6363
searchElement = scalar2ndarray( 1.0, {
6464
'dtype': 'generic'
6565
});
66-
fromIndex = scalar2ndarray( 0, {
66+
fromIndex = scalar2ndarray( 5, {
6767
'dtype': 'generic'
6868
});
6969
actual = glastIndexOf( [ x, searchElement, fromIndex ] );
@@ -72,7 +72,7 @@ tape( 'the function returns the last index of an element which equals a provided
7272
searchElement = scalar2ndarray( 2.0, {
7373
'dtype': 'generic'
7474
});
75-
fromIndex = scalar2ndarray( 0, {
75+
fromIndex = scalar2ndarray( 5, {
7676
'dtype': 'generic'
7777
});
7878
actual = glastIndexOf( [ x, searchElement, fromIndex ] );
@@ -113,7 +113,7 @@ tape( 'the function returns the last index of an element which equals a provided
113113
'dtype': 'generic'
114114
});
115115
actual = glastIndexOf( [ x, searchElement, fromIndex ] );
116-
t.strictEqual( actual, 5, 'returns expected value' );
116+
t.strictEqual( actual, 4, 'returns expected value' );
117117

118118
searchElement = scalar2ndarray( 2.0, {
119119
'dtype': 'generic'
@@ -131,12 +131,12 @@ tape( 'the function returns the last index of an element which equals a provided
131131
'dtype': 'generic'
132132
});
133133
actual = glastIndexOf( [ x, searchElement, fromIndex ] );
134-
t.strictEqual( actual, 3, 'returns expected value' );
134+
t.strictEqual( actual, -1, 'returns expected value' );
135135

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

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

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

156156
t.end();
157157
});

0 commit comments

Comments
 (0)