-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Support for np.unique #2902
Support for np.unique #2902
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2902 +/- ##
==========================================
- Coverage 85.84% 85.84% -0.01%
==========================================
Files 326 326
Lines 68309 68329 +20
Branches 7720 7722 +2
==========================================
+ Hits 58640 58654 +14
- Misses 8428 8434 +6
Partials 1241 1241 |
Great to see support for more numpy functions in numba! |
Thanks for the feedback. I'm pretty sure we should be able to determine the size of the array and branch the implementation based on that, but I don't know how to check for an empty array. |
Turns out it's not possible to differentiate on emptiness. Current implementation might replace [x for x in b[:1]] by simply list(b[:1]) (else we add an array to a list), but a cast has to happen somewhere. |
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.
Thanks for your contribution. I have some minor suggestions.
numba/targets/arrayobj.py
Outdated
@overload(np.unique) | ||
def np_unique(a): | ||
def np_unique_impl(a): | ||
b = np.sort(a.flatten()) |
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.
Performance nitpick: use .ravel()
instead of .flatten()
so you can save one copying.
numba/targets/arrayobj.py
Outdated
def np_unique(a): | ||
def np_unique_impl(a): | ||
b = np.sort(a.flatten()) | ||
return np.array([x for x in b[:1]] + [x for i, x in enumerate(b[1:]) if b[i] != x]) |
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.
pep8 nitpick: line more than 79col
You can check the size of the array by |
closes #2884
Fairly minimal, just the single array argument is supported,, not any of the return options or the axis argument.