diff options
-rw-r--r-- | numpy/core/src/ufuncobject.c | 22 | ||||
-rw-r--r-- | numpy/core/src/umathmodule.c.src | 24 |
2 files changed, 25 insertions, 21 deletions
diff --git a/numpy/core/src/ufuncobject.c b/numpy/core/src/ufuncobject.c index 078dd1295..22df5e86a 100644 --- a/numpy/core/src/ufuncobject.c +++ b/numpy/core/src/ufuncobject.c @@ -268,12 +268,7 @@ PyUFunc_O_O(char **args, intp *dimensions, intp *steps, void *func) UNARY_LOOP { PyObject *in1 = *(PyObject **)ip1; PyObject **out = (PyObject **)op1; - PyObject *ret; - - if (in1 == NULL) { - return; - } - ret = f(in1); + PyObject *ret = f(in1); if ((ret == NULL) || PyErr_Occurred()) { return; } @@ -291,7 +286,6 @@ PyUFunc_O_O_method(char **args, intp *dimensions, intp *steps, void *func) PyObject *in1 = *(PyObject **)ip1; PyObject **out = (PyObject **)op1; PyObject *ret = PyObject_CallMethod(in1, meth, NULL); - if (ret == NULL) { return; } @@ -304,21 +298,12 @@ PyUFunc_O_O_method(char **args, intp *dimensions, intp *steps, void *func) static void PyUFunc_OO_O(char **args, intp *dimensions, intp *steps, void *func) { + binaryfunc f = (binaryfunc)func; BINARY_LOOP { PyObject *in1 = *(PyObject **)ip1; PyObject *in2 = *(PyObject **)ip2; PyObject **out = (PyObject **)op1; - PyObject *ret; - - if ((in1 == NULL) || (in2 == NULL)) { - return; - } - if ( (void *) func == (void *) PyNumber_Power) { - ret = ((ternaryfunc)func)(in1, in2, Py_None); - } - else { - ret = ((binaryfunc)func)(in1, in2); - } + PyObject *ret = f(in1, in2); if (PyErr_Occurred()) { return; } @@ -337,7 +322,6 @@ PyUFunc_OO_O_method(char **args, intp *dimensions, intp *steps, void *func) PyObject *in2 = *(PyObject **)ip2; PyObject **out = (PyObject **)op1; PyObject *ret = PyObject_CallMethod(in1, meth, "(O)", in2); - if (ret == NULL) { return; } diff --git a/numpy/core/src/umathmodule.c.src b/numpy/core/src/umathmodule.c.src index 14e7e5ba5..1e3202932 100644 --- a/numpy/core/src/umathmodule.c.src +++ b/numpy/core/src/umathmodule.c.src @@ -139,6 +139,16 @@ Py_reciprocal(PyObject *o) return result; } +/* + * Define numpy version of PyNumber_Power as binary function. + */ +static PyObject * +npy_PyNumber_Power(PyObject *x, PyObject *y) +{ + PyNumber_Power(x, y, Py_None); +} +#define PyNumber_Power npy_PyNumber_Power + /**begin repeat * #Kind = Max, Min# * #OP = >=, <=# @@ -1520,7 +1530,11 @@ OBJECT_@kind@(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func) BINARY_LOOP { PyObject *in1 = *(PyObject **)ip1; PyObject *in2 = *(PyObject **)ip2; - *((Bool *)op1) = (Bool) PyObject_RichCompareBool(in1, in2, Py_@OP@); + int ret = PyObject_RichCompareBool(in1, in2, Py_@OP@); + if (ret == -1) { + return; + } + *((Bool *)op1) = (Bool)ret; } } /**end repeat**/ @@ -1531,7 +1545,13 @@ OBJECT_sign(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func)) PyObject *zero = PyInt_FromLong(0); UNARY_LOOP { PyObject *in1 = *(PyObject **)ip1; - *((PyObject **)op1) = PyInt_FromLong(PyObject_Compare(in1, zero)); + PyObject **out = (PyObject **)op1; + PyObject *ret = PyInt_FromLong(PyObject_Compare(in1, zero)); + if (PyErr_Occurred()) { + return; + } + Py_XDECREF(*out); + *out = ret; } Py_DECREF(zero); } |