[NumPy-Tickets] [NumPy] #1949: Upcasting a float32 array to complex64 instead of complex128 when adding a complex128 scalar
NumPy Trac
numpy-tickets@scipy....
Tue Sep 6 12:59:25 CDT 2011
#1949: Upcasting a float32 array to complex64 instead of complex128 when adding a
complex128 scalar
---------------------+------------------------------------------------------
Reporter: tihocan | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: Unscheduled
Component: Other | Version: 1.6.0
Keywords: |
---------------------+------------------------------------------------------
This is with numpy 1.6.0 and 1.6.1 under Linux x86_64, testing the upcast
mechanism of "scalar + array":
{{{
>>> import numpy; print (numpy.array(2, dtype=numpy.complex128) +
numpy.ones(3, dtype=numpy.float32)).dtype
complex64
}}}
Since it has to upcast my array (float32 is not "compatible enough" with
complex128), why does it upcast it to complex64 instead of complex128?
As far as I can tell 1.4.x and 1.5.x versions of numpy are indeed
upcasting to complex128.
Also note that:
* When replacing "numpy.ones" with "numpy.array" it yields complex128
(expected upcast of scalar addition of complex128 with float32)
* The behavior is similar if instead of "2" I use a number which cannot
be represented exactly with a complex64 (so it's not a rule about picking
the smallest data type able to exactly represent the result)
This issue was reported on the mailing list in:
http://mail.scipy.org/pipermail/numpy-discussion/2011-August/057981.html
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1949>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list