-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Implement np.intersect1d #3726
Implement np.intersect1d #3726
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks! One comment about a potential performance improvement.
|
||
if return_indices: | ||
indices = argsort(ar) | ||
aux = ar[indices] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible to use lax.sort
directly to get the sorted array and the indices in a single pass (if I recall correctly, argsort uses this and then discards the sorted array).
I think Jake and I were reviewing at the same time! His suggestion sounds good; maybe you can make another PR to incorporate it? |
* Implement np.intersect1d * Add jitable helper to function * Fix argsort failing tests * Fix linter errors
Sure, I'll add it and link to this PR |
* Implement np.intersect1d * Add jitable helper to function * Fix argsort failing tests * Fix linter errors
* Implement np.intersect1d * Add jitable helper to function * Fix argsort failing tests * Fix linter errors
* Implement np.intersect1d * Add jitable helper to function * Fix argsort failing tests * Fix linter errors
It seems that this function returns arrays of dynamic shapes, and is thus not compatible with jit? |
Correct, the semantics of numpy's #3614 tracks the effort to add size hints to functions that share this issue – many are done but Many of these kinds of features are implemented on an as-needed basis. If this is important to your use-case, you might chime-in on that issue with ideas of what kind of shape-hint behavior would be useful to you. |
This is an implementation of np.intersect1d from #70 (and #2078 )