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 gufunc(pyfunc, ...)
similar to numpy.vectorize
but without the vectorize part
#10526
Comments
In step 3, I don't see any use or reference to |
It seems like there are at least two options here:
I think option (2) would be preferred, but it's not clear to me that it's possible to do with the current ufunc API (admittedly, I don't understand it well). |
As a concrete example consider Scikit-Learn's It would be useful for Scikit-Learn to have some mechanism to be able to say "this function can be broadcast in the following way" and defer to objects that can do that sort of broadcasting (using the Concretely, it would be nice for downstream projects to be able to say the following: class Estimator:
@numpy.broadcastable('(m)->()')
def predict(self, X):
...
return y Ideally then if a user provides something like a dask array estimator = Estimator(...)
estimator.fit(...)
estimator.predict(my_dask_array) Then ideally the decorated predict method would go through the normal checks for |
See a possible implementation in PR #11061, which was rejected for |
A signature of |
That's correct that it doesn't currently broadcast, but arguably it
should. This is another case where it'd be nice to say "This thing is
broadcastable in the following way, please apply gufunc semantics to it."
…On Tue, Jul 10, 2018 at 5:03 AM Eric Wieser ***@***.***> wrote:
but it generally just broadcasts along the first dimension
A signature of (m)->() broadcasts along all but the last dimension - in
einsum notation, it's ...j->.... It sounds like predict doesn't actually
broadcast, and is either ij->i or j-> but no higher dimensional versions.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#10526 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AASszER3rXPEd_l0o-mkVNFtGQmUb9rGks5uFG3kgaJpZM4R573a>
.
|
We do have |
If we design such a wrapper it should handle these better than the current gufunc mechanism:
|
This issue was suggested in dask/dask#3109
My current understanding is that
numpy.vectorize
provides a way to__array__ufunc__
, if present, and/orI would like to suggest to implement an additional wrapper, just like
numpy.vectorize
, which does all the steps above, except step 4). I.e. a Python function could be wrapped as gufunc and given a signature, and when binding input the same Step 3) is applied.The benefit is, that same data binding methodology and interface is used, if the user already provides a vectorized implementation of Python function. It becomes especially important for interoperability with other libraries, e.g.
dask
.The text was updated successfully, but these errors were encountered: