[Numpy-discussion] Changes to generalized ufunc core dimension checking
travis at continuum.io
Thu Mar 17 04:04:11 EDT 2016
On Wed, Mar 16, 2016 at 3:07 PM, Charles R Harris <charlesr.harris at gmail.com
> On Wed, Mar 16, 2016 at 1:48 PM, Travis Oliphant <travis at continuum.io>
>> On Wed, Mar 16, 2016 at 12:55 PM, Nathaniel Smith <njs at pobox.com> wrote:
>>> Hi Travis,
>>> On Mar 16, 2016 9:52 AM, "Travis Oliphant" <travis at continuum.io> wrote:
>>> > Hi everyone,
>>> > Can you help me understand why the stricter changes to generalized
>>> ufunc argument checking no now longer allows scalars to be interpreted as
>>> 1-d arrays in the core-dimensions?
>>> > Is there a way to specify in the core-signature that scalars should be
>>> allowed and interpreted in those cases as an array with all the elements
>>> the same? This seems like an important feature.
>>> Can you share some example of when this is useful?
>> Being able to implicitly broadcast scalars to arrays is the core-function
>> of broadcasting. This is still very useful when you have a core-kernel
>> an want to pass in a scalar for many of the arguments. It seems that at
>> least in that case, automatic broadcasting should be allowed --- as it
>> seems clear what is meant.
>> While you can use the broadcast* features to get the same effect with the
>> current code-base, this is not intuitive to a user who is used to having
>> scalars interpreted as arrays in other NumPy operations.
> The `@` operator doesn't allow that.
>> It used to automatically happen and a few people depended on it in
>> several companies and so the 1.10 release broke their code.
>> I can appreciate that in the general case, allowing arbitrary
>> broadcasting on the internal core dimensions can create confusion. But,
>> scalar broadcasting still makes sense.
> Mixing array multiplications with scalar broadcasting is looking for
> trouble. Array multiplication needs strict dimensions and having stacked
> arrays and vectors was one of the prime objectives of gufuncs. Perhaps what
> we need is a more precise notation for broadcasting, maybe `*` or some such
> addition to the signaturs to indicate that scalar broadcasting is
I think that is a good idea. Let the user decide if scalar broadcasting
is acceptable for their function.
Here is a simple concrete example where scalar broadcasting makes sense:
A 1-d dot product (the core of np.inner) (k), (k) -> ()
A user would assume they could call this function with a scalar in either
argument and have it broadcast to a 1-d array. Of course, if both
arguments are scalars, then it doesn't make sense.
Having a way for the user to allow scalar broadcasting seems sensible and a
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
*Travis Oliphant, PhD*
*Co-founder and CEO*
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion