[Numpy-discussion] Allowing broadcasting of code dimensions in generalized ufuncs

Matthew Harrigan harrigan.matthew at gmail.com
Wed May 30 20:00:22 EDT 2018


"short-cut to automatically return False if m != n", that seems like a
silent bug

AFAICT there are 3 possibilities:
1) current behavior
2) a scalar or size 1 array may be substituted, ie a constant
3) a scalar or array with shape[-1] == 1 may be substituted and broadcasted

I am fond of using "n^" to signify #3 since I think of broadcasting as
increasing the size of the array.  Although a stretch, "n#" might work for
#2, as it reminds me of #define'ing constants in C.

To generalize a bit, most elementwise operations have obvious broadcasting
cases and reduce operations have a core dimension.  Fusing any two, ie
sumproduct, would result in a gufunc which would benefit from this ability.

On Wed, May 30, 2018 at 7:22 PM, Stephan Hoyer <shoyer at gmail.com> wrote:

> On Wed, May 30, 2018 at 11:15 AM Marten van Kerkwijk <
> m.h.vankerkwijk at gmail.com> wrote:
>
>> My PR provides the ability to indicate in the signature that a core
>> dimension can be broadcast, by using a suffix of "|1". Thus, the
>> signature of `all_equal` would become:
>>
>> ```
>> (n|1),(n|1)->()
>> ```
>>
>
> I read this as "dimensions may have size n or 1", which would exclude the
> possibility of scalars.
>
> For all_equal, I think you could also use a signature like
> "(m?),(n?)->()", with a short-cut to automatically return False if m != n.
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20180530/2192cbfa/attachment.html>


More information about the NumPy-Discussion mailing list