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

stable reversed indirect sort? #6217

Open
rainwoodman opened this issue Aug 18, 2015 · 3 comments
Open

stable reversed indirect sort? #6217

rainwoodman opened this issue Aug 18, 2015 · 3 comments

Comments

@rainwoodman
Copy link
Contributor

Looks like there is no easy way to achieve a stable reversed indirect sort with the sorting functions in numpy:

argsort()[::-1] would give a reversed indirect sort.

argsort(kind='mergesort')[::-1] does not give a stable reversed indirect sort. ([::-1] makes it unstable.

Would you consider including a 'reversed' parameter to argsort?

@rainwoodman
Copy link
Contributor Author

The easiest API change is to allow

argsort(order=[('field0', 1), ('field1', -1), ('field2', -1)])

Then we can make use of the new NPY_AUX_DATA to pass in such flags for reversed comparison used by 'compare' function.

@jaimefrio
Copy link
Member

It would be much easier to implement a two-pass O(n) stable reversal of the indexing array as a postprocessing step. I'm not sure we can do what you suggest without significantly affecting performance: sorting moved away from using the dtype's compare function, to having specialized inlined functions with hardcoded < for native types. And I don't think we can pass a "pointer to an inline function" and get the same performance we have now...

@jaimefrio
Copy link
Member

So I guess I'm leaning towards a reverse kwarg solution. Before getting something like this going it would be a good idea to talk about it on the mailing list. Could you send an e-mail to get the discussion started?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants