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

numpy-svn at scipy.org numpy-svn at scipy.org
Thu Aug 24 23:00:00 CDT 2006


Author: oliphant
Date: 2006-08-24 22:59:57 -0500 (Thu, 24 Aug 2006)
New Revision: 3068

Modified:
   trunk/numpy/core/src/arrayobject.c
Log:
Fix coercion in multiarray to be like ufunc coercion.

Modified: trunk/numpy/core/src/arrayobject.c
===================================================================
--- trunk/numpy/core/src/arrayobject.c	2006-08-25 03:44:22 UTC (rev 3067)
+++ trunk/numpy/core/src/arrayobject.c	2006-08-25 03:59:57 UTC (rev 3068)
@@ -6751,11 +6751,24 @@
 _array_small_type(PyArray_Descr *chktype, PyArray_Descr* mintype)
 {
         PyArray_Descr *outtype;
-
-        if (chktype->type_num > mintype->type_num) outtype = chktype;
-        else outtype = mintype;
-
-        Py_INCREF(outtype);
+        int outtype_num, save_num;
+        
+        if (chktype->type_num > mintype->type_num) 
+                outtype_num = chktype->type_num;
+        else 
+                outtype_num = mintype->type_num;
+        
+        save_num = outtype_num;
+        while(outtype_num < PyArray_NTYPES && 
+              !(PyArray_CanCastSafely(chktype->type_num, outtype_num)
+                && PyArray_CanCastSafely(mintype->type_num, outtype_num)))
+                outtype_num++;
+        if (outtype_num == PyArray_NTYPES) {
+                outtype = PyArray_DescrFromType(save_num);
+        }
+        else {
+                outtype = PyArray_DescrFromType(outtype_num);
+        }
         if (PyTypeNum_ISEXTENDED(outtype->type_num) &&          \
             (PyTypeNum_ISEXTENDED(mintype->type_num) ||         \
              mintype->type_num==0)) {



More information about the Numpy-svn mailing list