-
-
Notifications
You must be signed in to change notification settings - Fork 153
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
Create an Op
for NumPy's generalized ufunc
s
#695
Comments
One way I see this Otherwise if we want the inner |
Yes, it would be similar to a narrower, streamlined |
Built a rudimentary implementation: https://gist.github.com/kc611/72732f4305fe273c2da1620d6fb4e90c We should discuss how/at which level are we going to check for input shapes, without the actual shape information as integer tuples, it'll be very hard to determine if inputs are valid or not until we hit Any way in which #711 can help us out here ? |
Yes, that's a good start, especially the use of the To parse the NumPy signatures, we can use the same code NumPy uses (e.g. Now, I think it's important that we leave the ufunc signatures out of the This interface is really the first step. From there, the work is in
There's nothing we can—or really need—to do about that. That's the nature of this type of work: we simply do what we can with the available static information and leave the run-time-level checking to the run-time.
Yes, but now we're talking about static analysis-based optimizations. Those are great, but they come later down the line. |
@kc611, I just created an outline for the kind of |
I'll give it a try. |
We need to extend our existing
ufunc
support—currently provided by theElemwise
Op
—with a newOp
that covers NumPy'sgufunc
s. Let's call this proposedOp
Blockwise
.This new
Blockwise
Op
would allow us to generalize at least a few existingOp
s, and it would provide a very direct bridge to Numba and JAX's equivalent functionality (e.g. Numba's direct support forgufunc
s and JAX'svmap
). It would also allow us to implement a very convenientnp.vectorize
-like helper function.The implementation details behind a
Blockwise
Op
will likely involve a lot of the same logic asElemwise
andRandomVariable
. At a high level, the gradient methods in the former could be extended to account for non-scalar elements, while the latter demonstrates some of the relevant shape logic.The
RandomVariable
Op
already works similarly togufunc
s, because it supports generic "base" random variable "op"s that map distinctly shaped inputs to potentially non-scalar outputs. A good example is theMultinomialRV
Op
; itsgufunc
-like signature would be(), (n) -> (n)
.Here's an illustration:
See the originating discussion here.
The text was updated successfully, but these errors were encountered: