[Numpy-discussion] find_common_type broken?

Travis Oliphant oliphant@enthought....
Mon Jul 20 15:00:20 CDT 2009


On Jul 16, 2009, at 12:59 AM, Ralf Gommers wrote:

>
>
> This is not a problem with r_.  This is correct behavior.   A scalar  
> "float" will not cause an array "float32" to be upcast.
>
> This was at first counter-intuitive but I found the reason for it in  
> Guide to Numpy now:
>
> "Mixed scalar-array operations use a different set of casting rules  
> that ensure that
> a scalar cannot upcast an array unless the scalar is of a  
> fundamentally different kind
> of data (i.e. under a different hierarchy in the data type  
> hierarchy) then the array.
> This rule enables you to use scalar constants in your code (which as  
> Python types
> are interpreted accordingly in ufuncs) without worrying about  
> whether the precision
> of the scalar constant will cause upcasting on your large (small  
> precision) array."
>
> Makes sense.
>
> Nonetheless, the OP did point out a flaw in find_common_type that  
> has been fixed in r7133.
>
> Great, it works for me now.
>
> There is still one rule I do not understand the reason for. Out of  
> curiosity, what is the reason for this:
> In [16]: can_cast(int32, float32)
> Out[16]: False
> In [17]: can_cast(int64, float64)
> Out[17]: True

To prevent proliferation of float128 or float96 (i.e. longdouble's in  
a commonly used case).    Not a very pretty exceptional case, but  
definitely useful.

Thanks,

-Travis

--
Travis Oliphant
Enthought Inc.
1-512-536-1057
http://www.enthought.com
oliphant@enthought.com







More information about the NumPy-Discussion mailing list