diff options
-rw-r--r-- | numpy/core/src/multiarray/arraytypes.c.src | 12 | ||||
-rw-r--r-- | numpy/core/src/umath/scalarmath.c.src | 47 | ||||
-rw-r--r-- | numpy/lib/tests/test_arraypad.py | 3 |
3 files changed, 16 insertions, 46 deletions
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src index 2539fdb57..7cd80ba9a 100644 --- a/numpy/core/src/multiarray/arraytypes.c.src +++ b/numpy/core/src/multiarray/arraytypes.c.src @@ -394,19 +394,9 @@ static int /* Overflow could have occured converting double to float */ if (NPY_UNLIKELY((npy_isinf(temp.real) && !npy_isinf(oop.real)) || (npy_isinf(temp.imag) && !npy_isinf(oop.imag)))) { - int bufsize, errmask; - PyObject *errobj; - - if (PyUFunc_GetPyValues("assignment", &bufsize, &errmask, - &errobj) < 0) { - return -1; - } - int first = 1; - if (PyUFunc_handlefperr(errmask, errobj, NPY_FPE_OVERFLOW, &first)) { - Py_XDECREF(errobj); + if (PyUFunc_GiveFloatingpointErrors("cast", NPY_FPE_OVERFLOW) < 0) { return -1; } - Py_XDECREF(errobj); } #endif } diff --git a/numpy/core/src/umath/scalarmath.c.src b/numpy/core/src/umath/scalarmath.c.src index ef608378a..c322ca33d 100644 --- a/numpy/core/src/umath/scalarmath.c.src +++ b/numpy/core/src/umath/scalarmath.c.src @@ -29,6 +29,8 @@ #include "array_coercion.h" #include "common.h" #include "can_cast_table.h" +#include "umathmodule.h" + /* TODO: Used for some functions, should possibly move these to npy_math.h */ #include "loops.h" @@ -1162,6 +1164,14 @@ convert_to_@name@(PyObject *value, @type@ *result, npy_bool *may_need_deferring) * (Half, Float, Double, LongDouble)*3# */ #define IS_@name@ +/* drop the "true_" from "true_divide" for floating point warnings: */ +#define IS_@oper@ +#ifdef IS_true_divide + #define OP_NAME "divide" +#else + #define OP_NAME "@oper@" +#endif +#undef IS_@oper@ static PyObject * @name@_@oper@(PyObject *a, PyObject *b) @@ -1281,19 +1291,9 @@ static PyObject * retstatus |= npy_get_floatstatus_barrier((char*)&out); #endif if (retstatus) { - int bufsize, errmask; - PyObject *errobj; - - if (PyUFunc_GetPyValues("@name@_scalars", &bufsize, &errmask, - &errobj) < 0) { - return NULL; - } - int first = 1; - if (PyUFunc_handlefperr(errmask, errobj, retstatus, &first)) { - Py_XDECREF(errobj); + if (PyUFunc_GiveFloatingpointErrors("scalar " OP_NAME, retstatus) < 0) { return NULL; } - Py_XDECREF(errobj); } @@ -1327,6 +1327,7 @@ static PyObject * } +#undef OP_NAME #undef IS_@name@ /**end repeat**/ @@ -1449,19 +1450,9 @@ static PyObject * retstatus |= npy_get_floatstatus_barrier((char*)&out); #endif if (retstatus) { - int bufsize, errmask; - PyObject *errobj; - - if (PyUFunc_GetPyValues("@name@_scalars", &bufsize, &errmask, - &errobj) < 0) { - return NULL; - } - int first = 1; - if (PyUFunc_handlefperr(errmask, errobj, retstatus, &first)) { - Py_XDECREF(errobj); + if (PyUFunc_GiveFloatingpointErrors("scalar power", retstatus) < 0) { return NULL; } - Py_XDECREF(errobj); } ret = PyArrayScalar_New(@Name@); @@ -1581,19 +1572,9 @@ static PyObject * int retstatus = @name@_ctype_@oper@(val, &out); if (retstatus) { - int bufsize, errmask; - PyObject *errobj; - - if (PyUFunc_GetPyValues("@name@_scalars", &bufsize, &errmask, - &errobj) < 0) { - return NULL; - } - int first = 1; - if (PyUFunc_handlefperr(errmask, errobj, retstatus, &first)) { - Py_XDECREF(errobj); + if (PyUFunc_GiveFloatingpointErrors("scalar @oper@", retstatus) < 0) { return NULL; } - Py_XDECREF(errobj); } /* diff --git a/numpy/lib/tests/test_arraypad.py b/numpy/lib/tests/test_arraypad.py index ca3c35335..64b6a2e18 100644 --- a/numpy/lib/tests/test_arraypad.py +++ b/numpy/lib/tests/test_arraypad.py @@ -474,8 +474,7 @@ class TestStatistic: @pytest.mark.filterwarnings("ignore:Mean of empty slice:RuntimeWarning") @pytest.mark.filterwarnings( - "ignore:invalid value encountered in (divide|double_scalars):" - "RuntimeWarning" + "ignore:invalid value encountered in( scalar)? divide:RuntimeWarning" ) @pytest.mark.parametrize("mode", ["mean", "median"]) def test_zero_stat_length_valid(self, mode): |