-
Notifications
You must be signed in to change notification settings - Fork 48
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
ENH: Provisional support for NEP 18 (__array_function__ protocol) #200
Conversation
5045c28
to
67129b0
Compare
dd41e16
to
a54ad1a
Compare
84562d9
to
3a51a41
Compare
I've gone the long way and started implemented a bunch of functions with obvious requirements. inverse-like functions
product-like functions
histogram functions (as requested for #130)
Pifalls I found along the way
|
1da1198
to
092f9b3
Compare
05bb1c7
to
3dc0af1
Compare
3dc0af1
to
6df56a1
Compare
pre-commit.ci autofix |
@jzuhone do you think you'd be able to review this ? Is there someone else I could ask ? |
@neutrinoceros I can try to look at it next week |
56b6650
to
ab2c70a
Compare
@jzuhone I would like to propose we bundle this PR in the next release alongside the dask layer. IMO, each of these would justify a release on their own, so it's up to you :) |
@chrishavlin or @matthewturk could you look at this one? |
I rebased the branch but didn't write the history. I added two commit, the first of which corresponds to #288, and the second one adds deprecation warnings as requested. |
1599f1d
to
91381f4
Compare
pre-commit.ci autofix |
…nstead of inverting them (specialize the function via NEP 18)
FIX: add support for numpy.histogram, numpy.histogram2d and numpy.histogramdd
for more information, see https://pre-commit.ci
0af15ea
to
d717381
Compare
(rebased again now that #288 went in) |
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.
Just a couple minor nits from the changes you made today. Will merge once they're resolved.
d717381
to
66c8187
Compare
My initial motivation here was to add some unit representation to error messages when comparing two unyt_array instance via functions from
numpy.testing
, like so:which yields, on master:
and on this branch
previous version
edit:
Incidentally, it turns out that fixing this necessitated a kick-off implementation of NEP 18, so this work laid the foundation to solve:
More broadly, implementing NEP 18 for any was the topic of #139.
Granted I need to take more time to check that I'm not going against the original intentions here. My current approach is that, since covering the whole numpy public API in one go seems like an gigantic task, I'm implementing
unyt_array.__array_function__
with a fallthrough condition: if a special case isn't implemented yet, just fallback to the raw numpy implem (which is currently the behaviour for all functions subject to NEP 18). This way we can add support for more and more functions in a progressive way.I'm going to set the bar low(ish) for now, and try and fix the already reported cases, as reported above, as a first step.
An important question to address is: what should be done in the general case where we don't have a custom implementation for an array function ?
Option 1 this is the current implementation of this PR because I think it is the less disruptive or noisy one. My personal opinion is that it's probably okay to have incomplete support for NEP 18 for a couple release, as long as it is clearly stated in the release notes.