[NumPy-Tickets] [NumPy] #1798: Type promotion rules regression
NumPy Trac
numpy-tickets@scipy....
Mon Apr 11 15:44:09 CDT 2011
#1798: Type promotion rules regression
------------------------+---------------------------------------------------
Reporter: mwiebe | Owner: somebody
Type: defect | Status: new
Priority: highest | Milestone: 1.6.0
Component: numpy.core | Version: devel
Keywords: |
------------------------+---------------------------------------------------
[scalar float64]*[array int8] should produce [array float64], but when the
value of the scalar float64 is small, it may produce [array float16] or
[array float32]. Here is the current behavior:
{{{
>>> 3.1*np.ones(2,dtype=np.int8)
array([ 3.09960938, 3.09960938], dtype=float16)
>>> 1e10*np.ones(2,dtype=np.int8)
array([ 1.00000000e+10, 1.00000000e+10], dtype=float32)
>>> 1e40*np.ones(2,dtype=np.int8)
array([ 1.00000000e+40, 1.00000000e+40])
}}}
I propose a fix in two parts.
1. Fix this in the PyArray_ResultType/numpy.result_type function of the
type promotion API. In particular, the algorithm should track the promoted
array and scalar types separately, then if the kind of the promoted scalar
type is greater than the kind of the promoted array type, continue the
promotion of the promoted array type with the scalars without using
minscalartype.
2. Change the ufunc to detect binary operators during creation, and set a
flag for it. Then, during evaluation, use PyArray_ResultType to do the
type promotion for binary operators instead of the existing slow linear
search. The ufunc doesn't have a flags field, but it does have a field
called 'check_return' which is unused, and could be repurposed as a flags
field without changing the size of the python type.
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1798>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list