[Numpy-discussion] Silent Broadcasting considered harmful

Nathaniel Smith njs at pobox.com
Sun Feb 8 17:52:53 EST 2015


On 8 Feb 2015 13:04, "Stefan Reiterer" <domors at gmx.net> wrote:
>
> So I suggest that the best would be to throw warnings when arrays get
Broadcasted like
> Octave do. Python warnings can be catched and handled, that would be a
great benefit.
>
> Another idea would to provide warning levels for braodcasting, e.g
> 0 = Never, 1=Warn once, 2=Warn always, 3 = Forbid aka throw exception,
> with 0 as default.
> This would avoid breaking other code, and give the user some control over
braodcasting.

Unfortunately adding warnings is a non-starter for technical reasons, even
before we get into the more subjective debate about ideal API design:
issuing a warning is extremely slow (relative to typical array operations),
EVEN IF the warning is disabled. (By the time you can figure out it's
disabled, it's too late.) So this would cause massive slowdowns in existing
code.

Note also that in numpy, even simple expressions like '2 * arr' rely on
broadcasting. Do you really want warnings for all these cases?

-n
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150208/da384d34/attachment.html>


More information about the NumPy-Discussion mailing list