Description
sort, sorthp, and circshift all take an optional ndarray arg that's supposed to apply across all dims (sortOrder for sort/sorthp, k for circshift). It's supposed to be 0-d when you don't pass dims, but the code never actually checks that; it just assumes it and passes it straight to base():
if ( isndarrayLike( o ) ) {
// As the operation is performed across all dimensions, `o` is assumed to be a zero-dimensional ndarray...
return base( x, o );
}
For sort at L180.
Same thing happens on the fn(x, arg, {}) path (options with no dims key). So if you pass a wrong-shaped array it just... doesn't throw, and gets passed into base unchecked.
Found this because the tests for it are already there and already failing ("...is not broadcast-compatible" in each package's test.js)
make test-javascript TESTS_FILTER=".*/blas/ext/sort/test/test\.js"
make test-javascript TESTS_FILTER=".*/blas/ext/sorthp/test/test\.js"
make test-javascript TESTS_FILTER=".*/blas/ext/circshift/test/test\.js"
Related Issues
None that I found.
Questions
No.
Demo
No response
Reproduction
var zeros = require( '@stdlib/ndarray/zeros' );
var sort = require( '@stdlib/blas/ext/sort' );
var x = zeros( [ 2, 2 ], { 'dtype': 'generic' } );
var sortOrder = zeros( [ 4 ], { 'dtype': 'generic' } );
sort( x, sortOrder ); // should throw, doesn't
Same deal with circshift:
var circshift = require( '@stdlib/blas/ext/circshift' );
var x = zeros( [ 2, 2 ], { 'dtype': 'int32' } );
var k = zeros( [ 4 ], { 'dtype': 'int32' } );
circshift( x, k ); // should throw, doesn't
Expected Results
Throws — this is already what the existing tests assert.
Actual Results
Returns normally, no error, wrong-shaped array just gets used.
Version
0.4.1
Environments
Node.js
Browser Version
No response
Node.js / npm Version
Node v22.22.2, npm 10.9.7
Platform
Linux
Checklist
Description
sort,sorthp, andcircshiftall take an optional ndarray arg that's supposed to apply across all dims (sortOrderfor sort/sorthp,kfor circshift). It's supposed to be 0-d when you don't passdims, but the code never actually checks that; it just assumes it and passes it straight tobase():For
sortat L180.Same thing happens on the
fn(x, arg, {})path (options with nodimskey). So if you pass a wrong-shaped array it just... doesn't throw, and gets passed intobaseunchecked.Found this because the tests for it are already there and already failing (
"...is not broadcast-compatible"in each package's test.js)Related Issues
None that I found.
Questions
No.
Demo
No response
Reproduction
Same deal with
circshift:Expected Results
Actual Results
Version
0.4.1
Environments
Node.js
Browser Version
No response
Node.js / npm Version
Node v22.22.2, npm 10.9.7
Platform
Linux
Checklist