diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-09-20 10:53:30 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-09-20 10:53:30 +0000 |
commit | 289b1c6c44704de514659452ddb66c3d2e1656ce (patch) | |
tree | 6c1bb9b679cdcd947be4588df8d1ac485648cfba | |
parent | 1f4b85881b127b879241f2dafb88483c3c20bdd4 (diff) | |
download | numpy-289b1c6c44704de514659452ddb66c3d2e1656ce.tar.gz |
Only alter data-type of integer and bool types on reduce-like functions for 'add' and 'multiply'
-rw-r--r-- | numpy/core/src/ufuncobject.c | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/numpy/core/src/ufuncobject.c b/numpy/core/src/ufuncobject.c index 9a10a84a6..35825c490 100644 --- a/numpy/core/src/ufuncobject.c +++ b/numpy/core/src/ufuncobject.c @@ -2578,23 +2578,25 @@ PyUFunc_GenericReduction(PyUFuncObject *self, PyObject *args, } if (otype == NULL) { - /* For integer types --- makes sure at - least a long is used */ + /* For integer types --- make sure at + least a long is used for add and multiply + reduction --- to avoid overflow */ int typenum = PyArray_TYPE(mp); - if (PyTypeNum_ISINTEGER(typenum) && \ - (mp->descr->elsize < sizeof(long))) { - if (PyTypeNum_ISUNSIGNED(typenum)) - typenum = PyArray_ULONG; - else - typenum = PyArray_LONG; - } - else if (PyTypeNum_ISBOOL(typenum) && \ - ((strcmp(self->name,"add")==0) || \ - (strcmp(self->name,"multiply")==0))) { - typenum = PyArray_LONG; - } - otype = PyArray_DescrFromType(typenum); - } + if ((typenum < NPY_FLOAT) && \ + ((strcmp(self->name,"add")==0) || \ + (strcmp(self->name,"multiply")==0))) { + if (PyTypeNum_ISBOOL(typenum)) + typenum = PyArray_LONG; + else if (mp->descr->elsize < sizeof(long)) { + if (PyTypeNum_ISUNSIGNED(typenum)) + typenum = PyArray_ULONG; + else + typenum = PyArray_LONG; + } + } + otype = PyArray_DescrFromType(typenum); + } + switch(operation) { case UFUNC_REDUCE: |