BUG: numpy.array_api.argsort(stable=True, descending=True)
does not respect relative order
#20778
Labels
8000
numpy.array_api.argsort(stable=True, descending=True)
does not respect relative order
#20778
Uh oh!
There was an error while loading. Please reload this page.
The implementations of
xp.sort()
andxp.argsort()
innumpy.array_api
currently flip the resulting array whendescending=True
.For
stable=True
scenarios, this leads to incorrect behaviour as a stable sort should be respecting an equivalent element's relative order of whatever comparison is being used (i.e.<
and>
operators). To be fair, the concept of respecting relative order of a descending sort is nonsensical for NumPy as there's no actual descending sort to use, but this is an area of non-compliance and might trip array consuming libraries.This only really affects
xp.argsort()
as there's no way to distinguish relative order of equivalent elements inxp.sort()
.cc @asmeurer @pmeier @lezcano
An example of NumPy acting erroneously:
PyTorch's
sort()
and the Pythonsorted()
builtin are examples of respecting relative order when descending:The text was updated successfully, but these errors were encountered: