summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/src/multiarray/multiarraymodule.c4
-rw-r--r--numpy/core/src/umath/ufunc_object.c29
2 files changed, 11 insertions, 22 deletions
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c
index a89e27595..240ee4233 100644
--- a/numpy/core/src/multiarray/multiarraymodule.c
+++ b/numpy/core/src/multiarray/multiarraymodule.c
@@ -1500,6 +1500,10 @@ PyArray_EquivTypenums(int typenum1, int typenum2)
PyArray_Descr *d1, *d2;
npy_bool ret;
+ if (typenum1 == typenum2) {
+ return NPY_SUCCEED;
+ }
+
d1 = PyArray_DescrFromType(typenum1);
d2 = PyArray_DescrFromType(typenum2);
ret = PyArray_EquivTypes(d1, d2);
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index a47d9a96c..9b4f90a0e 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -515,7 +515,6 @@ _extract_pyvals(PyObject *ref, char *name, int *bufsize,
NPY_NO_EXPORT int
PyUFunc_GetPyValues(char *name, int *bufsize, int *errmask, PyObject **errobj)
{
- PyObject *thedict;
PyObject *ref = _get_global_ext_obj(name);
return _extract_pyvals(ref, name, bufsize, errmask, errobj);
@@ -2652,7 +2651,7 @@ reduce_type_resolver(PyUFuncObject *ufunc, PyArrayObject *arr,
* resolution.
*/
if (odtype != NULL) {
- type_tup = Py_BuildValue("OOO", odtype, odtype, Py_None);
+ type_tup = PyTuple_Pack(3, odtype, odtype, Py_None);
if (type_tup == NULL) {
return -1;
}
@@ -2825,7 +2824,6 @@ PyUFunc_Reduce(PyUFuncObject *ufunc, PyArrayObject *arr, PyArrayObject *out,
char *ufunc_name = ufunc->name ? ufunc->name : "(unknown)";
/* These parameters come from a TLS global */
int buffersize = 0, errormask = 0;
- PyObject *errobj = NULL;
NPY_UF_DBG_PRINT1("\nEvaluating ufunc %s.reduce\n", ufunc_name);
@@ -2879,13 +2877,12 @@ PyUFunc_Reduce(PyUFuncObject *ufunc, PyArrayObject *arr, PyArrayObject *out,
return NULL;
}
- if (PyUFunc_GetPyValues("reduce", &buffersize, &errormask, &errobj) < 0) {
+ if (_get_bufsize_errmask(NULL, "reduce", &buffersize, &errormask) < 0) {
return NULL;
}
/* Get the reduction dtype */
if (reduce_type_resolver(ufunc, arr, odtype, &dtype) < 0) {
- Py_XDECREF(errobj);
return NULL;
}
@@ -2898,7 +2895,6 @@ PyUFunc_Reduce(PyUFuncObject *ufunc, PyArrayObject *arr, PyArrayObject *out,
ufunc, buffersize, ufunc_name);
Py_DECREF(dtype);
- Py_XDECREF(errobj);
return result;
}
@@ -2925,7 +2921,6 @@ PyUFunc_Accumulate(PyUFuncObject *ufunc, PyArrayObject *arr, PyArrayObject *out,
/* These parameters come from extobj= or from a TLS global */
int buffersize = 0, errormask = 0;
- PyObject *errobj = NULL;
NPY_BEGIN_THREADS_DEF;
@@ -2937,7 +2932,7 @@ PyUFunc_Accumulate(PyUFuncObject *ufunc, PyArrayObject *arr, PyArrayObject *out,
printf("\n");
#endif
- if (PyUFunc_GetPyValues("accumulate", &buffersize, &errormask, &errobj) < 0) {
+ if (_get_bufsize_errmask(NULL, "accumulate", &buffersize, &errormask) < 0) {
return NULL;
}
@@ -3228,8 +3223,6 @@ finish:
NpyIter_Deallocate(iter);
NpyIter_Deallocate(iter_inner);
- Py_XDECREF(errobj);
-
return (PyObject *)out;
fail:
@@ -3239,8 +3232,6 @@ fail:
NpyIter_Deallocate(iter);
NpyIter_Deallocate(iter_inner);
- Py_XDECREF(errobj);
-
return NULL;
}
@@ -3290,7 +3281,6 @@ PyUFunc_Reduceat(PyUFuncObject *ufunc, PyArrayObject *arr, PyArrayObject *ind,
/* These parameters come from extobj= or from a TLS global */
int buffersize = 0, errormask = 0;
- PyObject *errobj = NULL;
NPY_BEGIN_THREADS_DEF;
@@ -3317,7 +3307,7 @@ PyUFunc_Reduceat(PyUFuncObject *ufunc, PyArrayObject *arr, PyArrayObject *ind,
printf("Index size is %d\n", (int)ind_size);
#endif
- if (PyUFunc_GetPyValues(opname, &buffersize, &errormask, &errobj) < 0) {
+ if (_get_bufsize_errmask(NULL, opname, &buffersize, &errormask) < 0) {
return NULL;
}
@@ -3629,8 +3619,6 @@ finish:
Py_XDECREF(op_dtypes[0]);
NpyIter_Deallocate(iter);
- Py_XDECREF(errobj);
-
return (PyObject *)out;
fail:
@@ -3639,8 +3627,6 @@ fail:
NpyIter_Deallocate(iter);
- Py_XDECREF(errobj);
-
return NULL;
}
@@ -4974,7 +4960,6 @@ ufunc_at(PyUFuncObject *ufunc, PyObject *args)
npy_uint32 op_flags[NPY_MAXARGS];
int buffersize;
int errormask = 0;
- PyObject *errobj = NULL;
NPY_BEGIN_THREADS_DEF;
if (ufunc->nin > 2) {
@@ -5108,7 +5093,9 @@ ufunc_at(PyUFuncObject *ufunc, PyObject *args)
NPY_ITER_NO_SUBTYPE;
}
- PyUFunc_GetPyValues(ufunc->name, &buffersize, &errormask, &errobj);
+ if (_get_bufsize_errmask(NULL, ufunc->name, &buffersize, &errormask) < 0) {
+ goto fail;
+ }
/*
* Create NpyIter object to "iterate" over single element of each input
@@ -5207,7 +5194,6 @@ ufunc_at(PyUFuncObject *ufunc, PyObject *args)
Py_XDECREF(array_operands[0]);
Py_XDECREF(array_operands[1]);
Py_XDECREF(array_operands[2]);
- Py_XDECREF(errobj);
if (needs_api && PyErr_Occurred()) {
return NULL;
@@ -5224,7 +5210,6 @@ fail:
Py_XDECREF(array_operands[0]);
Py_XDECREF(array_operands[1]);
Py_XDECREF(array_operands[2]);
- Py_XDECREF(errobj);
return NULL;
}