Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 63a844c

Browse files
headlessNodePlaneshifter
authored andcommitted
fix: update fromIndex handling in blas/ext/base/ndarray/slast-index-of
PR-URL: #8007 Closes: stdlib-js/metr-issue-tracker#71 Ref: #2656 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 0762d02 commit 63a844c

File tree

7 files changed

+20
-31
lines changed

7 files changed

+20
-31
lines changed

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ import { float32ndarray, typedndarray } from '@stdlib/types/ndarray';
3434
* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
3535
* var slastIndexOf = require( '@stdlib/blas/ext/base/ndarray/slast-index-of' );
3636
*
37-
* var xbuf = new Float32Array( [ 1.0, 3.0, 4.0, 2.0 ] );
37+
* var xbuf = new Float32Array( [ 1.0, 2.0, 4.0, 2.0 ] );
3838
* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );
3939
*
4040
* var searchElement = scalar2ndarray( 2.0, {
4141
* 'dtype': 'float32'
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/slast-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/slast-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 slastIndexOf = require( '@stdlib/blas/ext/base/ndarray/slast-index-of' );
3131
*
32-
* var xbuf = new Float32Array( [ 1.0, 3.0, 4.0, 2.0 ] );
32+
* var xbuf = new Float32Array( [ 1.0, 2.0, 4.0, 2.0 ] );
3333
* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );
3434
*
3535
* var searchElement = scalar2ndarray( 2.0, {
3636
* 'dtype': 'float32'
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/slast-index-of/lib/main.js‎

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' );
4141
* var ndarray = require( '@stdlib/ndarray/base/ctor' );
4242
* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
4343
*
44-
* var xbuf = new Float32Array( [ 1.0, 3.0, 4.0, 2.0 ] );
44+
* var xbuf = new Float32Array( [ 1.0, 2.0, 4.0, 2.0 ] );
4545
* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );
4646
*
4747
* var searchElement = scalar2ndarray( 2.0, {
4848
* 'dtype': 'float32'
4949
* });
5050
*
51-
* var fromIndex = scalar2ndarray( 0, {
51+
* var fromIndex = scalar2ndarray( 3, {
5252
* 'dtype': 'generic'
5353
* });
5454
*
@@ -58,9 +58,6 @@ var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' );
5858
function slastIndexOf( arrays ) {
5959
var searchElement;
6060
var fromIndex;
61-
var stride;
62-
var offset;
63-
var idx;
6461
var N;
6562
var x;
6663

@@ -72,20 +69,12 @@ function slastIndexOf( arrays ) {
7269
if ( fromIndex < 0 ) {
7370
fromIndex += N;
7471
if ( fromIndex < 0 ) {
75-
fromIndex=0;
72+
return-1;
7673
}
7774
} else if ( fromIndex >= N ) {
78-
return-1;
75+
fromIndex=N-1;
7976
}
80-
N -= fromIndex;
81-
stride = getStride( x, 0 );
82-
offset = getOffset( x ) + ( stride*fromIndex );
83-
84-
idx = strided( N, searchElement, getData( x ), stride, offset );
85-
if ( idx >= 0 ) {
86-
idx += fromIndex;
87-
}
88-
return idx;
77+
return strided( fromIndex+1, searchElement, getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len
8978
}
9079

9180

‎lib/node_modules/@stdlib/blas/ext/base/ndarray/slast-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': 'float32'
6666
});
67-
fromIndex = scalar2ndarray( 0, {
67+
fromIndex = scalar2ndarray( 5, {
6868
'dtype': 'generic'
6969
});
7070
actual = slastIndexOf( [ 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': 'float32'
7575
});
76-
fromIndex = scalar2ndarray( 0, {
76+
fromIndex = scalar2ndarray( 5, {
7777
'dtype': 'generic'
7878
});
7979
actual = slastIndexOf( [ 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 = slastIndexOf( [ 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': 'float32'
@@ -132,12 +132,12 @@ tape( 'the function returns the last index of an element which equals a provided
132132
'dtype': 'generic'
133133
});
134134
actual = slastIndexOf( [ 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 = slastIndexOf( [ 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)

AltStyle によって変換されたページ (->オリジナル) /