[Numpy-svn] r3195 - trunk/numpy/core/src

numpy-svn at scipy.org numpy-svn at scipy.org
Wed Sep 20 05:53:32 CDT 2006


Author: oliphant
Date: 2006-09-20 05:53:30 -0500 (Wed, 20 Sep 2006)
New Revision: 3195

Modified:
   trunk/numpy/core/src/ufuncobject.c
Log:
Only alter data-type of integer and bool types on reduce-like functions for 'add' and 'multiply'

Modified: trunk/numpy/core/src/ufuncobject.c
===================================================================
--- trunk/numpy/core/src/ufuncobject.c	2006-09-20 00:12:21 UTC (rev 3194)
+++ trunk/numpy/core/src/ufuncobject.c	2006-09-20 10:53:30 UTC (rev 3195)
@@ -2578,24 +2578,26 @@
         }
 
         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:
                 ret = (PyArrayObject *)PyUFunc_Reduce(self, mp, out, axis,



More information about the Numpy-svn mailing list