diff options
-rw-r--r-- | numpy/core/code_generators/generate_umath.py | 2 | ||||
-rw-r--r-- | numpy/core/src/umathmodule.c.src | 35 |
2 files changed, 36 insertions, 1 deletions
diff --git a/numpy/core/code_generators/generate_umath.py b/numpy/core/code_generators/generate_umath.py index 270ca50a4..96a681d3c 100644 --- a/numpy/core/code_generators/generate_umath.py +++ b/numpy/core/code_generators/generate_umath.py @@ -261,11 +261,13 @@ defdict = { 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, diff --git a/numpy/core/src/umathmodule.c.src b/numpy/core/src/umathmodule.c.src index ee3dca549..fa7cd678b 100644 --- a/numpy/core/src/umathmodule.c.src +++ b/numpy/core/src/umathmodule.c.src @@ -1207,7 +1207,6 @@ static void /**end repeat**/ - static PyObject * Py_reciprocal(PyObject *o) { @@ -1219,6 +1218,40 @@ Py_reciprocal(PyObject *o) 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 |