Skip to content

Instantly share code, notes, and snippets.

@juliantaylor
Created September 11, 2013 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliantaylor/6521016 to your computer and use it in GitHub Desktop.
Save juliantaylor/6521016 to your computer and use it in GitHub Desktop.
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -207,12 +207,15 @@ PyUFunc_handlefperr(int errmask, PyObject *errobj, int retstatus, int *first)
/*UFUNC_API*/
NPY_NO_EXPORT int
-PyUFunc_checkfperr(int errmask, PyObject *errobj, int *first)
+PyUFunc_checkfperr(int errmask, PyObject *errobj, int *first, int * pre)
{
int retstatus;
/* 1. check hardware flag --- this is platform dependent code */
- retstatus = PyUFunc_getfperr();
+ if (pre)
+ retstatus = *pre;
+ else
+ retstatus = PyUFunc_getfperr();
return PyUFunc_handlefperr(errmask, errobj, retstatus, first);
}
@@ -2204,7 +2207,7 @@ PyUFunc_GeneralizedFunction(PyUFuncObject *ufunc,
/* Check whether any errors occurred during the loop */
if (PyErr_Occurred() || (errormask &&
- PyUFunc_checkfperr(errormask, errobj, &first_error))) {
+ PyUFunc_checkfperr(errormask, errobj, &first_error, NULL))) {
retval = -1;
goto fail;
}
@@ -2267,7 +2270,6 @@ PyUFunc_GenericFunction(PyUFuncObject *ufunc,
/* These parameters come from extobj= or from a TLS global */
int buffersize = 0, errormask = 0;
- PyObject *errobj = NULL;
int first_error = 1;
/* The mask provided in the 'where=' parameter */
@@ -2330,22 +2332,6 @@ PyUFunc_GenericFunction(PyUFuncObject *ufunc,
need_fancy = 1;
}
- /* Get the buffersize, errormask, and error object globals */
- if (extobj == NULL) {
- if (PyUFunc_GetPyValues(ufunc_name,
- &buffersize, &errormask, &errobj) < 0) {
- retval = -1;
- goto fail;
- }
- }
- else {
- if (_extract_pyvals(extobj, ufunc_name,
- &buffersize, &errormask, &errobj) < 0) {
- retval = -1;
- goto fail;
- }
- }
-
NPY_UF_DBG_PRINT("Finding inner loop\n");
retval = ufunc->type_resolver(ufunc, casting,
@@ -2452,11 +2438,37 @@ PyUFunc_GenericFunction(PyUFuncObject *ufunc,
goto fail;
}
- /* Check whether any errors occurred during the loop */
- if (PyErr_Occurred() || (errormask &&
- PyUFunc_checkfperr(errormask, errobj, &first_error))) {
- retval = -1;
- goto fail;
+ int pre = PyUFunc_getfperr();
+ if (pre) {
+ PyObject *errobj = NULL;
+
+ /* Get the buffersize, errormask, and error object globals */
+ if (extobj == NULL) {
+ if (PyUFunc_GetPyValues(ufunc_name,
+ &buffersize, &errormask, &errobj) < 0) {
+ retval = -1;
+ Py_XDECREF(errobj);
+ goto fail;
+ }
+ }
+ else {
+ if (_extract_pyvals(extobj, ufunc_name,
+ &buffersize, &errormask, &errobj) < 0) {
+ retval = -1;
+ Py_XDECREF(errobj);
+ goto fail;
+ }
+ }
+
+
+ /* Check whether any errors occurred during the loop */
+ if (PyErr_Occurred() || (errormask &&
+ PyUFunc_checkfperr(errormask, errobj, &first_error, &pre))) {
+ retval = -1;
+ Py_XDECREF(errobj);
+ goto fail;
+ }
+ Py_XDECREF(errobj);
}
/* The caller takes ownership of all the references in op */
@@ -2464,7 +2476,6 @@ PyUFunc_GenericFunction(PyUFuncObject *ufunc,
Py_XDECREF(dtypes[i]);
Py_XDECREF(arr_prep[i]);
}
- Py_XDECREF(errobj);
Py_XDECREF(type_tup);
Py_XDECREF(arr_prep_args);
Py_XDECREF(wheremask);
@@ -2481,7 +2492,6 @@ fail:
Py_XDECREF(dtypes[i]);
Py_XDECREF(arr_prep[i]);
}
- Py_XDECREF(errobj);
Py_XDECREF(type_tup);
Py_XDECREF(arr_prep_args);
Py_XDECREF(wheremask);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment