Skip to content

Commit 35cbdfb

Browse files
authored
feat: add support for negative strides in idamax and isamax
PR-URL: #2793 Closes: #2792 Ref: #2464 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 2bd8dad commit 35cbdfb

File tree

12 files changed

+49
-35
lines changed

12 files changed

+49
-35
lines changed

lib/node_modules/@stdlib/blas/base/idamax/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ var idx = idamax.ndarray( 5, x, 1, 1 );
112112

113113
## Notes
114114

115-
- If `N < 1` or `strideX <= 0`, both functions return `-1`.
115+
- If `N < 1`, both functions return `-1`.
116116
- `idamax()` corresponds to the [BLAS][blas] level 1 function [`idamax`][idamax].
117117

118118
</section>
@@ -157,7 +157,7 @@ console.log( idx );
157157

158158
[blas]: http://www.netlib.org/blas
159159

160-
[idamax]: http://www.netlib.org/lapack/explore-html/de/da4/group__double__blas__level1.html
160+
[idamax]: https://netlib.org/lapack/explore-html/dd/de0/idamax_8f_source.html
161161

162162
[@stdlib/array/float64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/float64
163163

lib/node_modules/@stdlib/blas/base/idamax/docs/repl.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
Indexing is relative to the first index. To introduce an offset, use typed
99
array views.
1010

11-
If `N < 1` or `strideX <= 0`, the function returns `-1`.
11+
If `N < 1`, both functions return `-1`.
1212

1313
Parameters
1414
----------

lib/node_modules/@stdlib/blas/base/idamax/lib/ndarray.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function idamax( N, x, strideX, offsetX ) {
4949
var v;
5050
var i;
5151

52-
if ( N < 1 || strideX <= 0 ) {
52+
if ( N < 1 ) {
5353
return -1;
5454
}
5555
idx = 0;

lib/node_modules/@stdlib/blas/base/idamax/lib/ndarray.native.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ function idamax( N, x, strideX, offsetX ) {
4848
var viewX;
4949
offsetX = minViewBufferIndex( N, strideX, offsetX );
5050
viewX = offsetView( x, offsetX );
51+
if ( strideX < 0 ) {
52+
return N - 1 - addon( N, viewX, -strideX );
53+
}
5154
return addon( N, viewX, strideX );
5255
}
5356

lib/node_modules/@stdlib/blas/base/idamax/test/test.ndarray.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,21 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns `0`', fun
108108
t.end();
109109
});
110110

111-
tape( 'if provided a `strideX` parameter less than or equal to `0`, the function returns `-1`', function test( t ) {
112-
var expected;
111+
tape( 'the function supports accessing elements in reverse order', function test( t ) {
113112
var idx;
114113
var x;
115114

116115
x = new Float64Array( [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ] );
117-
expected = -1;
118116

119-
idx = idamax( x.length, x, 0, 0 );
120-
t.strictEqual( idx, expected, 'returns expected value' );
117+
idx = idamax( x.length, x, -1, x.length-1 );
118+
t.strictEqual( idx, 2, 'returns expected value' );
121119

122-
idx = idamax( x.length, x, -1, 0 );
123-
t.strictEqual( idx, expected, 'returns expected value' );
120+
idx = idamax( 3, x, -1, x.length-4 );
121+
t.strictEqual( idx, 1, 'returns expected value' );
122+
123+
x = new Float64Array( [ 3.0, 999.9, 999.9, -4.0, 999.9, 999.9, 1.0, 999.9, 999.9, 15.0, 999.9, 999.9, 4.0, 999.9, 999.9, 3.0 ] );
124+
idx = idamax( 6, x, -3, x.length-1 );
125+
t.strictEqual( idx, 2, 'returns expected value' );
124126

125127
t.end();
126128
});

lib/node_modules/@stdlib/blas/base/idamax/test/test.ndarray.native.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,21 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns `0`', opt
117117
t.end();
118118
});
119119

120-
tape( 'if provided a `strideX` parameter less than or equal to `0`, the function returns `-1`', opts, function test( t ) {
121-
var expected;
120+
tape( 'the function supports accessing elements in reverse order', function test( t ) {
122121
var idx;
123122
var x;
124123

125124
x = new Float64Array( [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ] );
126-
expected = -1;
127125

128-
idx = idamax( x.length, x, 0, 0 );
129-
t.strictEqual( idx, expected, 'returns expected value' );
126+
idx = idamax( x.length, x, -1, x.length-1 );
127+
t.strictEqual( idx, 2, 'returns expected value' );
130128

131-
idx = idamax( x.length, x, -1, 5 );
132-
t.strictEqual( idx, expected, 'returns expected value' );
129+
idx = idamax( 3, x, -1, x.length-4 );
130+
t.strictEqual( idx, 1, 'returns expected value' );
131+
132+
x = new Float64Array( [ 3.0, 999.9, 999.9, -4.0, 999.9, 999.9, 1.0, 999.9, 999.9, 15.0, 999.9, 999.9, 4.0, 999.9, 999.9, 3.0 ] );
133+
idx = idamax( 6, x, -3, x.length-1 );
134+
t.strictEqual( idx, 2, 'returns expected value' );
133135

134136
t.end();
135137
});

lib/node_modules/@stdlib/blas/base/isamax/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ var idx = isamax.ndarray( 5, x, 1, 1 );
112112

113113
## Notes
114114

115-
- If `N < 1` or `strideX <= 0`, both functions return `-1`.
115+
- If `N < 1`, both functions return `-1`.
116116
- `isamax()` corresponds to the [BLAS][blas] level 1 function [`isamax`][isamax].
117117

118118
</section>

lib/node_modules/@stdlib/blas/base/isamax/docs/repl.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
Indexing is relative to the first index. To introduce an offset, use typed
99
array views.
1010

11-
If `N < 1` or `strideX <= 0`, the function returns `-1`.
11+
If `N < 1`, both functions return `-1`.
1212

1313
Parameters
1414
----------

lib/node_modules/@stdlib/blas/base/isamax/lib/ndarray.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function isamax( N, x, strideX, offsetX ) {
4949
var v;
5050
var i;
5151

52-
if ( N < 1 || strideX <= 0 ) {
52+
if ( N < 1 ) {
5353
return -1;
5454
}
5555
idx = 0;

lib/node_modules/@stdlib/blas/base/isamax/lib/ndarray.native.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ function isamax( N, x, strideX, offsetX ) {
4848
var viewX;
4949
offsetX = minViewBufferIndex( N, strideX, offsetX );
5050
viewX = offsetView( x, offsetX );
51+
if ( strideX < 0 ) {
52+
return N - 1 - addon( N, viewX, -strideX );
53+
}
5154
return addon( N, viewX, strideX );
5255
}
5356

lib/node_modules/@stdlib/blas/base/isamax/test/test.ndarray.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,21 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns `0`', fun
108108
t.end();
109109
});
110110

111-
tape( 'if provided a `strideX` parameter less than or equal to `0`, the function returns `-1`', function test( t ) {
112-
var expected;
111+
tape( 'the function supports accessing elements in reverse order', function test( t ) {
113112
var idx;
114113
var x;
115114

116115
x = new Float32Array( [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ] );
117-
expected = -1;
118116

119-
idx = isamax( x.length, x, 0, 0 );
120-
t.strictEqual( idx, expected, 'returns expected value' );
117+
idx = isamax( x.length, x, -1, x.length-1 );
118+
t.strictEqual( idx, 2, 'returns expected value' );
121119

122-
idx = isamax( x.length, x, -1, 0 );
123-
t.strictEqual( idx, expected, 'returns expected value' );
120+
idx = isamax( 3, x, -1, x.length-4 );
121+
t.strictEqual( idx, 1, 'returns expected value' );
122+
123+
x = new Float32Array( [ 3.0, 999.9, 999.9, -4.0, 999.9, 999.9, 1.0, 999.9, 999.9, 15.0, 999.9, 999.9, 4.0, 999.9, 999.9, 3.0 ] );
124+
idx = isamax( 6, x, -3, x.length-1 );
125+
t.strictEqual( idx, 2, 'returns expected value' );
124126

125127
t.end();
126128
});

lib/node_modules/@stdlib/blas/base/isamax/test/test.ndarray.native.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,21 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns `0`', opt
117117
t.end();
118118
});
119119

120-
tape( 'if provided a `strideX` parameter less than or equal to `0`, the function returns `-1`', opts, function test( t ) {
121-
var expected;
120+
tape( 'the function supports accessing elements in reverse order', function test( t ) {
122121
var idx;
123122
var x;
124123

125124
x = new Float32Array( [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ] );
126-
expected = -1;
127125

128-
idx = isamax( x.length, x, 0, 0 );
129-
t.strictEqual( idx, expected, 'returns expected value' );
126+
idx = isamax( x.length, x, -1, x.length-1 );
127+
t.strictEqual( idx, 2, 'returns expected value' );
130128

131-
idx = isamax( x.length, x, -1, 5 );
132-
t.strictEqual( idx, expected, 'returns expected value' );
129+
idx = isamax( 3, x, -1, x.length-4 );
130+
t.strictEqual( idx, 1, 'returns expected value' );
131+
132+
x = new Float32Array( [ 3.0, 999.9, 999.9, -4.0, 999.9, 999.9, 1.0, 999.9, 999.9, 15.0, 999.9, 999.9, 4.0, 999.9, 999.9, 3.0 ] );
133+
idx = isamax( 6, x, -3, x.length-1 );
134+
t.strictEqual( idx, 2, 'returns expected value' );
133135

134136
t.end();
135137
});

0 commit comments

Comments
 (0)