-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Feature request: signal broadcasting is OK over core dimension #8811
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
Rather than producing an increasingly complex syntax for signatures (#5015, and i've wanted |
@eric-wieser - again a good suggestion; I added it above. I think the hook is separate (and good for more complicated cases). |
I would be much happier with a multiple dispatch system for gufuncs, where a given function has a list of signatures that are tried in order, which we need for |
@shoyer - I now listed this as an option. I think this is hard to do without those different signatures corresponding to different C functions, while all that is required for my original suggestion is to re-allow broadcasting by the iterator. |
I feel like we've got the cart a bit before the horse -- maybe we should
put together a list of these use cases and the details of what exactly they
need first before jumping to possible solutions? There's all_equal (which
is a bit odd because it's just the composition of all+equal, but ok),
there's matmul, there's Eric's min case (can you give more details?), and a
review of np.linalg I think will turn up some more cases too.
This probably interacts with the design for axes=, too. (E.g. should there
be a way to specifically request broadcasting?)
|
@njsmith - fair enough; added a "wishlist" section. I think this does not necessarily influence |
This is desirable in |
I think think the ufuncs should be universal and general enough that (almost) all numpy functions COULD be performed by a ufunc. Note I'm not saying they SHOULD all be ufuncs. Here are few examples not from linalg with different challenges:
There are probably other examples that could be pulled from existing numpy functions. @shoyer would multiple dispatch require an excessive number of possible signatures? As an example, would all_equal need (i),(i)->(), (i),()->(), (),(i)->(), and (),()->()? As the number of inputs increase the number of functions could go exponential. |
I'm really late to the party, but disallowing broadcasting over core dimensions was a conscious decision, that took a long time, with lots of disagreements, see #5077. I very rarely have strong opinions on this kind of things, but since we are just past July 4th: "Prudence, indeed, will dictate that Governments long established should not be changed for light and transient causes." In any case, most of the fancy changes being proposed require adding additional stuff to the ufunc struct, which means breaking ABI compatibility. At some point in the past we were planning on breaking it once to hide all internal details, similarly to what was done with Unless I'm missing something, without that prior work none of these other plans can really fly, so it would be a good thing if we could figure out a plan to get it done... |
EDITS:
ufunc
API.Rationale
Before numpy 1.10, there was automatic broadcasting over core dimensions in
gufunc
. While this is not necessarily good for many things (e.g.,np.inner1d
in the example in the documentation), it is for others, such as theall_equal
implementation in #8528. It would be nice if the signature allowed one to make this distinction.Wishlist beyond broadcasting
(i,k),(k,j)->(i,j)
,(i,j),(i)=(i,j),(i,1)->(i,j)
,(i),(i,j)=(1,i),(i,j)->(i,j)
min(i,j)
)Possible implementations
Noting that
signature
has to be a singlechar
to remain compatible with the API:(i|1), (i|1)->()
or(i?), (i?)->()
(Add an axis argument to generalized ufuncs? #5197) might convey what is needed forall_equal
(easy to do with setting relevant strides to 0)(i),(i)->(); (i),()->(); (),(i)->(); (),()->()
. This would likely make the most sense for things likematmul
, but would seem to imply different functions for each signature.The text was updated successfully, but these errors were encountered: