[NumPy-Tickets] [NumPy] #2109: mean() with axis=None causes promotion of floating point types
NumPy Trac
numpy-tickets@scipy....
Mon Apr 30 16:13:32 CDT 2012
#2109: mean() with axis=None causes promotion of floating point types
--------------------------------+-------------------------------------------
Reporter: david.warde-farley | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: Unscheduled
Component: numpy.core | Version: 1.6.1
Keywords: |
--------------------------------+-------------------------------------------
Comment(by david.warde-farley):
So the problem seems to come from the fact that in
`numpy/core/src/multiarray/calculation.c`, the divisor is cast to a Python
float:
{{{
obj2 = PyFloat_FromDouble((double)PyArray_DIM(arr,axis));
}}}
and then `PyNumber_{True}Divide` causes the promotion of the NumPy scalar
to float64:
{{{
#if defined(NPY_PY3K)
ret = PyNumber_TrueDivide(obj1, obj2);
#else
ret = PyNumber_Divide(obj1, obj2);
#endif
}}}
I've tried to fix this by creating a !NumPy scalar from `PyArray_DIM(arr,
axis)` but so far been unsuccessful in avoiding the promotion (it also
happens with complex64, by the way: the mean is promoted to complex128).
It seems to me that if `PyArray_ISFLOAT(arr)` is true then either the
divisor should be cast to the correct type before division or the result
of the division should be cast to the correct type: the latter may be more
stable.
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/2109#comment:1>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list