Skip to content
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

feat: support negative strides for idamax and isamax #2793

Merged
merged 3 commits into from
Aug 15, 2024
Merged
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
4 changes: 2 additions & 2 deletions lib/node_modules/@stdlib/blas/base/idamax/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ var idx = idamax.ndarray( 5, x, 1, 1 );

## Notes

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

</section>
Expand Down Expand Up @@ -157,7 +157,7 @@ console.log( idx );

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

[idamax]: http://www.netlib.org/lapack/explore-html/de/da4/group__double__blas__level1.html
[idamax]: https://netlib.org/lapack/explore-html/dd/de0/idamax_8f_source.html
kgryte marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down
2 changes: 1 addition & 1 deletion lib/node_modules/@stdlib/blas/base/idamax/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Indexing is relative to the first index. To introduce an offset, use typed
array views.

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

Parameters
----------
Expand Down
2 changes: 1 addition & 1 deletion lib/node_modules/@stdlib/blas/base/idamax/lib/ndarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function idamax( N, x, strideX, offsetX ) {
var v;
var i;

if ( N < 1 || strideX <= 0 ) {
if ( N < 1 ) {
return -1;
}
idx = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ function idamax( N, x, strideX, offsetX ) {
var viewX;
offsetX = minViewBufferIndex( N, strideX, offsetX );
viewX = offsetView( x, offsetX );
if ( strideX < 0 ) {
return N - 1 - addon( N, viewX, -strideX );
}
return addon( N, viewX, strideX );
}

Expand Down
16 changes: 9 additions & 7 deletions lib/node_modules/@stdlib/blas/base/idamax/test/test.ndarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,21 @@
t.end();
});

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

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

idx = idamax( x.length, x, 0, 0 );
t.strictEqual( idx, expected, 'returns expected value' );
idx = idamax( x.length, x, -1, x.length-1 );
t.strictEqual( idx, 2, 'returns expected value' );

idx = idamax( x.length, x, -1, 0 );
t.strictEqual( idx, expected, 'returns expected value' );
idx = idamax( 3, x, -1, x.length-4 );
t.strictEqual( idx, 1, 'returns expected value' );

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 ] );

Check warning on line 123 in lib/node_modules/@stdlib/blas/base/idamax/test/test.ndarray.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

This line has a length of 133. Maximum allowed is 80
idx = idamax( 6, x, -3, x.length-1 );
t.strictEqual( idx, 2, 'returns expected value' );

t.end();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,21 @@
t.end();
});

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

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

idx = idamax( x.length, x, 0, 0 );
t.strictEqual( idx, expected, 'returns expected value' );
idx = idamax( x.length, x, -1, x.length-1 );
t.strictEqual( idx, 2, 'returns expected value' );

idx = idamax( x.length, x, -1, 5 );
t.strictEqual( idx, expected, 'returns expected value' );
idx = idamax( 3, x, -1, x.length-4 );
t.strictEqual( idx, 1, 'returns expected value' );

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 ] );

Check warning on line 132 in lib/node_modules/@stdlib/blas/base/idamax/test/test.ndarray.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

This line has a length of 133. Maximum allowed is 80
idx = idamax( 6, x, -3, x.length-1 );
t.strictEqual( idx, 2, 'returns expected value' );

t.end();
});
Expand Down
2 changes: 1 addition & 1 deletion lib/node_modules/@stdlib/blas/base/isamax/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ var idx = isamax.ndarray( 5, x, 1, 1 );

## Notes

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

</section>
Expand Down
2 changes: 1 addition & 1 deletion lib/node_modules/@stdlib/blas/base/isamax/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Indexing is relative to the first index. To introduce an offset, use typed
array views.

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

Parameters
----------
Expand Down
2 changes: 1 addition & 1 deletion lib/node_modules/@stdlib/blas/base/isamax/lib/ndarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function isamax( N, x, strideX, offsetX ) {
var v;
var i;

if ( N < 1 || strideX <= 0 ) {
if ( N < 1 ) {
return -1;
}
idx = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ function isamax( N, x, strideX, offsetX ) {
var viewX;
offsetX = minViewBufferIndex( N, strideX, offsetX );
viewX = offsetView( x, offsetX );
if ( strideX < 0 ) {
return N - 1 - addon( N, viewX, -strideX );
}
return addon( N, viewX, strideX );
}

Expand Down
16 changes: 9 additions & 7 deletions lib/node_modules/@stdlib/blas/base/isamax/test/test.ndarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,21 @@
t.end();
});

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

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

idx = isamax( x.length, x, 0, 0 );
t.strictEqual( idx, expected, 'returns expected value' );
idx = isamax( x.length, x, -1, x.length-1 );
t.strictEqual( idx, 2, 'returns expected value' );

idx = isamax( x.length, x, -1, 0 );
t.strictEqual( idx, expected, 'returns expected value' );
idx = isamax( 3, x, -1, x.length-4 );
t.strictEqual( idx, 1, 'returns expected value' );

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 ] );

Check warning on line 123 in lib/node_modules/@stdlib/blas/base/isamax/test/test.ndarray.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

This line has a length of 133. Maximum allowed is 80
idx = isamax( 6, x, -3, x.length-1 );
t.strictEqual( idx, 2, 'returns expected value' );

t.end();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,21 @@
t.end();
});

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

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

idx = isamax( x.length, x, 0, 0 );
t.strictEqual( idx, expected, 'returns expected value' );
idx = isamax( x.length, x, -1, x.length-1 );
t.strictEqual( idx, 2, 'returns expected value' );

idx = isamax( x.length, x, -1, 5 );
t.strictEqual( idx, expected, 'returns expected value' );
idx = isamax( 3, x, -1, x.length-4 );
t.strictEqual( idx, 1, 'returns expected value' );

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 ] );

Check warning on line 132 in lib/node_modules/@stdlib/blas/base/isamax/test/test.ndarray.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

This line has a length of 133. Maximum allowed is 80
idx = isamax( 6, x, -3, x.length-1 );
t.strictEqual( idx, 2, 'returns expected value' );

t.end();
});
Expand Down
Loading