[Numpy-discussion] Do we want scalar casting to behave as it does at the moment?
Fri Jan 4 10:34:34 CST 2013
(sorry, no time for full reply, so for now just answering what I
believe is the main point)
2013/1/4 Andrew Collette <email@example.com>:
>> The ValueError is here to warn you that the operation may not be doing
>> what you want. The rollover for smaller values would be the documented
>> (and thus hopefully expected) behavior.
> Right, but what confuses me is that the only thing this prevents is
> the current upcast behavior. Why is that so evil it should be
> replaced with an exception?
The evilness lies in the silent switch between the rollover and upcast
behavior, as in the example I gave previously:
In : np.array(, dtype='int8') + 127
Out: array([-127], dtype=int8)
In : np.array(, dtype='int8') + 128
Out: array(, dtype=int16)
If the scalar is the user-supplied value, it's likely you actually
want a fixed behavior (either rollover or upcast) regardless of the
numeric value being provided.
Looking at what other numeric libraries are doing is definitely a good
More information about the NumPy-Discussion