-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
ENH: initial implementation of core __array_function__
machinery
#12005
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
Conversation
I'd like to implement NEP-18 in a multi-step process: 1. (This PR) Pure Python implementation of `__array_function__` machinery, based on the prototype implementation from NEP-18. 2. Rewrite this machinery in C as needed to improve performance. 3. Implement overrides on NumPy functions. Steps 2 and 3 should be able to happen in parallel (and with other people contributing!). This PR still needs more tests, especially for `ndarray.__array_function__`
OK, I think this has decent test coverage now and is ready for review. |
This test is failing on Python 2.7 with Shippable:
It looks unrelated. |
Correct, the warnings tests are not thread-safe & we run the tests with more than 1 core on shippable CI; I can't remember how much extra time it takes to run the suite on a single core, but that one test will fail stochastically so we should maybe roll back to 1 core, which is a bit of a sin since we get 96 cores on those ARM nodes. |
Maybe we could for detecting master vs. "child" process with a fixture: pytest-dev/pytest-xdist#47 (comment) |
numpy/core/overrides.py
Outdated
if result is not NotImplemented: | ||
return True, result | ||
|
||
raise TypeError('no implementation found for {} on types that implement ' |
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.
Is it the case that at least one of the non-ndarray types with override must implement the function?
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.
Not necessarily. For example, a project like scipy.sparse
might define a starter __array_function__
that returns (almost) always returns NotImplemented
, just as a way to guarantee that scipy matrices don't get inadvertently coerced into numpy arrays.
(But it occurs to me that we don't have a test for this yet, which I should fix!)
Could you add a release note with a short explanation and a link to the NEP. |
I'm happy to draft a release note, but I think it's a little early for that
-- we haven't actually implemented it on any NumPy functions yet :)
…On Sat, Sep 22, 2018 at 5:19 PM Charles Harris ***@***.***> wrote:
Could you add a release note with a short explanation and a link to the
NEP.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#12005 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABKS1qrtsE5qGjV_uz8ekLJsk-ckrLA-ks5udtOfgaJpZM4WzVT->
.
|
I believe there is already some experimental support out there. Was it @mhvk? Might get together and pick a function. Is it intended that ndarray methods can be overridden? |
Eventually I'd like the release note to read "Every core NumPy function now supports |
No, this is only for functions. |
The "subclasses before superclasses" rule coupled with the "special handling for In particular, in which order should we try overrides for arguments with types [ndarray, duck_array, ndarray_subclass]? Per the text in the NEP, I suspect we should call |
@shoyer - One way of thinking about it is that |
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 very nice! Some small comments only.
Yes, this helps. |
@shoyer - most of the diff now seems to be against benchmarks - surely not the intent! |
I'll split removing the Benchmark baseclass into another PR. |
I removed the unrelated changes to the benchmark suite. |
This update has made the code quite a bit clearer; the different split between the actual override call is particularly helpful. |
+1 to merge this as-is as step 1, and to add a tracking issue to follow up with the other two goals in the first comment |
see #12028 for a tracking issue |
Let's get this started. @shoyer Might want to break the tracking issue down into smaller bits. It would also be good to have some idea of how to gather feedback, and maybe some small demo project (masked arrays, TNG?) or existing project as a test platform. Also might consider long term possibility of JIT for python code, that is, how much does a C implementation actually buy us. |
Thanks Stephan. |
__array_function__
machinery
I'd like to implement NEP-18 in a multi-step process:
__array_function__
machinery,based on the prototype implementation from NEP-18.
Steps 2 and 3 should be able to happen in parallel (and with other people
contributing!).
This PR still needs more tests, especially forndarray.__array_function__