[Numpy-discussion] Broadcasting rules (Ticket 76).
oliphant.travis at ieee.org
Mon Apr 24 22:27:02 CDT 2006
Travis Oliphant wrote:
> Sasha wrote:
>> On 4/24/06, Travis Oliphant <oliphant.travis at ieee.org> wrote:
>> I've attached a patch to the ticket:
> I don't think the patch will do your definition of "the right thing"
> (i.e. mirror broadcasting behavior) in all cases. For example if "a"
> is 2x3x4x5 and "b" is 2x1x1x5, then a[...] = b will not fill the
> right sub-space of "a" with the contents of "b".
> The PyArray_CopyInto gets called in a lot of places. Have you checked
> all of them to be sure that altering the semantics of copying (which
> are currently different than broadcasting) will work correctly? I
> agree that one can demonstrate a slight in-consistency. But, I'd
> rather have the inconsistency and tell people that copying and
> assignment is not a broadcasting ufunc, then feign consistency and
> have it not quite right.
Of course, as I've said I'm not opposed to the consistency.
To do it "right", one should use PyArray_MultiIterNew which abstracts
the concept of broadcasting into iterators (and uses the broadcastable
checking code that's already written --- so you guarantee
consistency). I'm not sure what overhead it would bring.
But, special cases could be checked-for (scalar, and same-size arrays
I'm also thinking that copyswapn should grow stride arguments so that it
can be used more generally.
More information about the Numpy-discussion