[Numpy-discussion] Do we want scalar casting to behave as it does at the moment?

Olivier Delalleau shish@keba...
Tue Jan 8 12:48:42 CST 2013


2013/1/8 Andrew Collette <andrew.collette@gmail.com>:
> Hi,
>
>> I think you are voting strongly for the current casting rules, because
>> they make it less obvious to the user that scalars are different from
>> arrays.
>
> Maybe this is the source of my confusion... why should scalars be
> different from arrays?  They should follow the same rules, as closely
> as possible.  If a scalar value would fit in an int16, why not add it
> using the rules for an int16 array?

As I mentioned in another post, I also agree that it would make things
simpler and safer to just yield the same result as if we were using a
one-element array.

My understanding of the motivation for the rule "scalars do not upcast
arrays unless they are of a fundamentally different type" is that it
avoids accidentally upcasting arrays in operations like "x + 1" (for
instance if x is a float32 array, the upcast would yield a float64
result, and if x is an int16, it would yield int64), which may waste
memory. I find it a useful feature, however I'm not sure it's worth
the headaches it can lead to.

However, my first reaction at the idea of dropping this rule
altogether is that it would lead to a long and painful deprecation
process. I may be wrong though, I really haven't thought about it
much.

-=- Olivier


More information about the NumPy-Discussion mailing list