Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BUG:
array_api.argsort(descending=True)
respects relative sort order (
#20788) * BUG: `array_api.argsort(descending=True)` respects relative order * Regression test for stable descending `array_api.argsort()`
- Loading branch information
Showing
2 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import pytest | ||
|
||
from numpy import array_api as xp | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"obj, axis, expected", | ||
[ | ||
([0, 0], -1, [0, 1]), | ||
([0, 1, 0], -1, [1, 0, 2]), | ||
([[0, 1], [1, 1]], 0, [[1, 0], [0, 1]]), | ||
([[0, 1], [1, 1]], 1, [[1, 0], [0, 1]]), | ||
], | ||
) | ||
def test_stable_desc_argsort(obj, axis, expected): | ||
""" | ||
Indices respect relative order of a descending stable-sort | ||
See https://github.com/numpy/numpy/issues/20778 | ||
""" | ||
x = xp.asarray(obj) | ||
out = xp.argsort(x, axis=axis, stable=True, descending=True) | ||
assert xp.all(out == xp.asarray(expected)) |