[Numpy-svn] r3204 - in trunk/numpy/core: code_generators src

numpy-svn at scipy.org numpy-svn at scipy.org
Thu Sep 21 11:58:27 CDT 2006


Author: oliphant
Date: 2006-09-21 11:58:07 -0500 (Thu, 21 Sep 2006)
New Revision: 3204

Modified:
   trunk/numpy/core/code_generators/generate_umath.py
   trunk/numpy/core/src/umathmodule.c.src
Log:
Add Object-type to maximum and minimum ufuncs.

Modified: trunk/numpy/core/code_generators/generate_umath.py
===================================================================
--- trunk/numpy/core/code_generators/generate_umath.py	2006-09-21 15:51:00 UTC (rev 3203)
+++ trunk/numpy/core/code_generators/generate_umath.py	2006-09-21 16:58:07 UTC (rev 3204)
@@ -261,11 +261,13 @@
     Ufunc(2, 1, None,
           'returns maximum (if x1 > x2: x1;  else: x2) elementwise.',
           TD(noobj),
+          TD(O, f='_npy_ObjectMax')
           ),
 'minimum' :
     Ufunc(2, 1, None,
           'returns minimum (if x1 < x2: x1;  else: x2) elementwise',
           TD(noobj),
+          TD(O, f='_npy_ObjectMin')          
           ),
 'bitwise_and' :
     Ufunc(2, 1, One,

Modified: trunk/numpy/core/src/umathmodule.c.src
===================================================================
--- trunk/numpy/core/src/umathmodule.c.src	2006-09-21 15:51:00 UTC (rev 3203)
+++ trunk/numpy/core/src/umathmodule.c.src	2006-09-21 16:58:07 UTC (rev 3204)
@@ -1207,7 +1207,6 @@
 /**end repeat**/
 
 
-
 static PyObject *
 Py_reciprocal(PyObject *o)
 {
@@ -1219,6 +1218,40 @@
     return result;
 }
 
+static PyObject *
+_npy_ObjectMax(PyObject *i1, PyObject *i2)
+{
+        int cmp;
+        PyObject *res;
+        if (PyObject_Cmp(i1, i2, &cmp) < 0) return NULL;
+        
+        if (cmp >= 0) {
+                res = i1;
+        }
+        else {
+                res = i2;
+        }
+        Py_INCREF(res);
+        return res;
+}
+
+static PyObject *
+_npy_ObjectMin(PyObject *i1, PyObject *i2)
+{
+        int cmp;
+        PyObject *res;
+        if (PyObject_Cmp(i1, i2, &cmp) < 0) return NULL;
+        
+        if (cmp <= 0) {
+                res = i1;
+        }
+        else {
+                res = i2;
+        }
+        Py_INCREF(res);
+        return res;
+}
+
 /* ones_like is defined here because it's used for x**0 */
 
 /**begin repeat



More information about the Numpy-svn mailing list