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

numpy-svn at scipy.org numpy-svn at scipy.org
Sat Sep 16 17:27:43 CDT 2006


Author: oliphant
Date: 2006-09-16 17:27:38 -0500 (Sat, 16 Sep 2006)
New Revision: 3172

Modified:
   trunk/numpy/core/src/arrayobject.c
Log:
Fix type-coercion for void-type arrays.

Modified: trunk/numpy/core/src/arrayobject.c
===================================================================
--- trunk/numpy/core/src/arrayobject.c	2006-09-16 06:03:58 UTC (rev 3171)
+++ trunk/numpy/core/src/arrayobject.c	2006-09-16 22:27:38 UTC (rev 3172)
@@ -6785,6 +6785,11 @@
         PyArray_Descr *outtype;
         int outtype_num, save_num;
 
+        if (PyArray_EquivTypes(chktype, mintype)) {
+                Py_INCREF(mintype);
+                return mintype;
+        }
+
         if (chktype->type_num > mintype->type_num)
                 outtype_num = chktype->type_num;
         else
@@ -6872,23 +6877,33 @@
         PyArray_Descr *chktype=NULL;
         PyArray_Descr *outtype;
 
-        if (minitype == NULL)
-                minitype = PyArray_DescrFromType(PyArray_BOOL);
-        else Py_INCREF(minitype);
+        /* These need to come first because if op already carries
+           a descr structure, then we want it to be the result if minitype
+           is NULL.
+        */
 
-        if (max < 0) goto deflt;
-
         if (PyArray_Check(op)) {
                 chktype = PyArray_DESCR(op);
                 Py_INCREF(chktype);
+                if (minitype == NULL) return chktype;
+                Py_INCREF(minitype);
                 goto finish;
         }
 
         if (PyArray_IsScalar(op, Generic)) {
                 chktype = PyArray_DescrFromScalar(op);
+                if (minitype == NULL) return chktype;
+                Py_INCREF(minitype);
                 goto finish;
         }
 
+        if (minitype == NULL) {
+                minitype = PyArray_DescrFromType(PyArray_BOOL);
+        }
+        else Py_INCREF(minitype);
+
+        if (max < 0) goto deflt;
+
         chktype = _array_find_python_scalar_type(op);
         if (chktype) {
             goto finish;
@@ -6999,8 +7014,10 @@
         outtype = _array_small_type(chktype, minitype);
         Py_DECREF(chktype);
         Py_DECREF(minitype);
-        /* VOID Arrays should not occur by "default" */
-        if (outtype->type_num == PyArray_VOID) {
+        /* VOID Arrays should not occur by "default" 
+           unless intput was already a VOID */
+        if (outtype->type_num == PyArray_VOID && \
+            minitype->type_num != PyArray_VOID) {
                 Py_DECREF(outtype);
                 return PyArray_DescrFromType(PyArray_OBJECT);
         }



More information about the Numpy-svn mailing list