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

numpy-svn@scip... numpy-svn@scip...
Mon Mar 26 16:28:32 CDT 2007


Author: oliphant
Date: 2007-03-26 16:28:30 -0500 (Mon, 26 Mar 2007)
New Revision: 3602

Modified:
   trunk/numpy/core/src/ufuncobject.c
Log:
Fix scalar coercion rules so that mixed scalar array coercion with arrays of different types uses normal rules when the kind of the scalar is larger than the kind of the array.

Modified: trunk/numpy/core/src/ufuncobject.c
===================================================================
--- trunk/numpy/core/src/ufuncobject.c	2007-03-26 20:47:11 UTC (rev 3601)
+++ trunk/numpy/core/src/ufuncobject.c	2007-03-26 21:28:30 UTC (rev 3602)
@@ -1118,10 +1118,9 @@
         int nargs, i;
         int arg_types[NPY_MAXARGS];
 	PyArray_SCALARKIND scalars[NPY_MAXARGS];
-        PyArray_SCALARKIND kindof, new;
+        PyArray_SCALARKIND maxarrkind, maxsckind, new;
 	PyUFuncObject *self=loop->ufunc;
 	Bool allscalars=TRUE;
-        Bool samekind=TRUE;
 	PyTypeObject *subtype=&PyArray_Type;
         PyObject *context=NULL;
         PyObject *obj;
@@ -1137,6 +1136,8 @@
         }
 
         /* Get each input argument */
+        maxarrkind = PyArray_NOSCALAR;
+        maxsckind = PyArray_NOSCALAR;
         for (i=0; i<self->nin; i++) {
                 obj = PyTuple_GET_ITEM(args,i);
                 if (!PyArray_Check(obj) && !PyArray_IsScalar(obj, Generic)) {
@@ -1161,19 +1162,21 @@
 		/* Scalars are 0-dimensional arrays
 		   at this point
 		*/
+
+                /* We need to keep track of whether or not scalars
+                   are mixed with arrays of different kinds.
+                */
+
 		if (mps[i]->nd > 0) {
                         scalars[i] = PyArray_NOSCALAR;
 			allscalars=FALSE;
                         new = PyArray_ScalarKind(arg_types[i], NULL);
+                        maxarrkind = NPY_MAX(new, maxarrkind);
 		}
 		else {
                         scalars[i] = PyArray_ScalarKind(arg_types[i], &(mps[i]));
-                        new = scalars[i];
+                        maxsckind = NPY_MAX(scalars[i], maxsckind);
                 }
-                if (i==0) kindof=new;
-                else if (kindof != new) {
-                        samekind=FALSE;
-                }
         }
 
         if (flexible && !object) {
@@ -1181,15 +1184,14 @@
                 return nargs;
         }
 
-	/* If everything is a scalar, or scalars mixed with arrays of different kinds
-           then use normal coercion rules */
-	if (allscalars || !samekind) {
+	/* If everything is a scalar, or scalars mixed with arrays of 
+           different kinds of lesser types then use normal coercion rules */
+	if (allscalars || (maxsckind > maxarrkind)) {
 		for (i=0; i<self->nin; i++) {
 			scalars[i] = PyArray_NOSCALAR;
 		}
 	}
 
-
         /* Select an appropriate function for these argument types. */
         if (select_types(loop->ufunc, arg_types, &(loop->function),
                          &(loop->funcdata), scalars, typetup) == -1)



More information about the Numpy-svn mailing list