[Numpy-discussion] type coercion question
Rick White
rlw at stsci.edu
Wed Mar 31 09:55:36 CST 2004
On Wed, 31 Mar 2004, Perry Greenfield wrote:
> Just to summarize what I see as acceptable choices:
>
> 1) ints promote to Float32 (current behavior)
> 2) ints promote to Float64
> 3) Int32 promotes to Float64, lesser ints promote to Float32 (Numeric
> behavior)
I'm also +1 on option (2).
I believe that this will not cause problems with unwanted promotions. The
result of cos(1) is a scalar Python float, regardless of whether 1 is
converted to a Float32 or a Float64 before the cosine is evaluated. Then
if that scalar is used with a Float32 numarray, it gets converted to a
Float32 and the result is Float32. For example:
>>> from numarray import *
>>> cos(1)*ones(1,Float32)
array([ 0.54030228], type=Float32)
>>> cos(1.0)*ones(1,Float32)
array([ 0.54030228], type=Float32)
So it seems to me there is no downside to converting integers to Float64
when the ufunc requires a float. And I find it hard to believe that any
Numeric users are counting on behavior (3).
Rick
More information about the Numpy-discussion
mailing list