Skip to content

RFC: Why stable=True is the default for xp.sort? #976

@cakedev0

Description

@cakedev0

In xp.sort and xp.argsort, the sort is stable by default.

I understand very well the interest for argsort: I've seen a lot of bugs because people expected np.argsort to be stable.

And I guess sort is stable by default to match argsort behavior. But:

  • stable sort is slower. Typically, 8x slower in numpy on my machine.
  • for totally ordered data types, stable sort output is indistinguable from unstable sort output
  • for complex numbers the doc says:

For backward compatibility, conforming implementations may support complex numbers; however, inequality comparison of complex numbers is unspecified and thus implementation-dependent

So: are we sure it's a good idea to default to stable sort?

Alternatively: shouldn't we call unstable sort under-the-hood for non-complex numbers, even when stable=True?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions