-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
A protocol for numpy.ones_like #11074
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
Comments
Actually, I suspect that accepting a shape is not particularly important. My guess is that some of these immediate problems would be solved if functions like |
Have a look at |
I guess
I feel like @shoyer and I might have discussed this in March, but I don't see anything in our notes and my brain is fried from getting my PyCon talk together for tomorrow. Maybe he remembers more :-) |
@njsmith I think you can find it briefly mentioned at the end, under "A (very) rough sketch of future plans". Speaking of which -- we really should finish polishing those notes up into a NEP :). The one other big question in my mind that we didn't talk about is where these protocols should live:
Perhaps this would be a good topic of discussion for the NumPy sprint at BIDS in a few weeks (or maybe the next week when @mrocklin is in town). |
This seems related to the problem of making concatenate work for duck arrays. |
IIRC, the |
Indeed,
|
This seems to be a sensible solution for my immediate problem. Thank you all In [1]: import numpy as np
In [2]: import dask.array as da
In [3]: x = da.arange(10, chunks=(5,))
In [4]: np.core.umath._ones_like(x)
Out[4]: dask.array<_ones_like, shape=(10,), dtype=int64, chunksize=(5,)> I'm curious about the private functions in this namespace. Is this documented somewhere or is there a conversation I can read to get some context about why they exist? |
@mrocklin I assume you mean |
Conversation seems to have slowed down a bit here. To summarize what I'm hearing above it sounds like at one point this was considered but then an alternative was put in place. It's not clear what the reasoning was at the time, but presumably one could do some sleuthing to find out why. There is some mild concern from @shoyer that some code might be built expecting From my limited perspective the world would be a nicer place if Numpy would tend towards the default of making operations ufuncs. This would allow the ecosystem to evolve more quickly towards using generic code in gpu, sparse, and parallel situations. |
The |
There's a related discussion over on #8994 about making the three-argument version of Overall, I agree with @mrocklin fairly strongly here that Numpy should move towards a protocol-oriented and I would be willing to co-author an (or multiple) NEPs, perhaps in conjunction with @njsmith, @shoyer. Hopefully @mrocklin joins in too. |
If it's possible, would I be able to join in on the NEP? I've never written an enhancement proposal, and would like to observe the process, while also hopefully being able to contribute one end-user's perspective on it. |
One other advantage of a NEP is that it could provide a list of functions that would, in principle, be suitable, and separate them by what extra machinery is needed (e.g., |
This is solved by NEP-18 |
Woot. Thanks all! |
I recently sat down with @ericmjl to see if we could make autograd work with cupy by making them both understand protocols like
__array_ufunc__
The goal here being to improve all projects to produce and consume numpy protocols rather than explicitly import each other in pair-wise plugin mechanisms.
One issue that we ran into is that autograd needs to produce new arrays, like
ones
(the gradient ofsum
) andrandom
(not sure why yet). It would be nice to be able to say "produce an array of ones with a particular shape and dtype, but using the module that created this particular array object". This would allow autograd to produce dask arrays of ones, cupy arrays of ones, etc..The
numpy.ones_like
function almost does this except for the following two issues:np.ones_like(my_duck_array, ...)
produces a numpy arrayAlso, to be clear,
ones
here is an example of a larger problem of how to improve dispatch for a wider set of numpy functions.The text was updated successfully, but these errors were encountered: