diff options
author | Warren Weckesser <warren.weckesser@gmail.com> | 2020-01-06 11:17:44 -0500 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2020-01-06 10:17:44 -0600 |
commit | b66864cfcaf0875f80bf68ccbd0cbbaaabc94f85 (patch) | |
tree | 0991d7a5969417a824c8c8b8a86d40d4f1017b44 | |
parent | b91dec15343ecbf72271b4ad40573a5415028b96 (diff) | |
download | numpy-b66864cfcaf0875f80bf68ccbd0cbbaaabc94f85.tar.gz |
BUG: do not emit warnings for np.sign, np.equal when using nan (gh-15230)
* BUG: do not emit warnings for np.sign, np.equal when using nan
* BUG: core: Fix test to handle big-endian platforms.
Co-authored-by: Matti Picus <matti.picus@gmail.com>
-rw-r--r-- | numpy/core/src/umath/loops.c.src | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_ufunc.py | 18 |
2 files changed, 20 insertions, 0 deletions
diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src index 8a2e5bc40..33d10da49 100644 --- a/numpy/core/src/umath/loops.c.src +++ b/numpy/core/src/umath/loops.c.src @@ -1824,6 +1824,7 @@ NPY_NO_EXPORT void *((npy_bool *)op1) = in1 @OP@ in2; } } + npy_clear_floatstatus_barrier((char*)dimensions); } /**end repeat1**/ @@ -2068,6 +2069,7 @@ NPY_NO_EXPORT void const @type@ in1 = *(@type@ *)ip1; *((@type@ *)op1) = in1 > 0 ? 1 : (in1 < 0 ? -1 : (in1 == 0 ? 0 : in1)); } + npy_clear_floatstatus_barrier((char*)dimensions); } NPY_NO_EXPORT void diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py index 507ac87b9..679bea96a 100644 --- a/numpy/core/tests/test_ufunc.py +++ b/numpy/core/tests/test_ufunc.py @@ -1982,3 +1982,21 @@ def test_ufunc_noncontiguous(ufunc): assert_allclose(res_c, res_n, atol=tol, rtol=tol) else: assert_equal(c_ar, n_ar) + + +@pytest.mark.parametrize('ufunc', [np.sign, np.equal]) +def test_ufunc_warn_with_nan(ufunc): + # issue gh-15127 + # test that calling certain ufuncs with a non-standard `nan` value does not + # emit a warning + # `b` holds a 64 bit signaling nan: the most significant bit of the + # significand is zero. + b = np.array([0x7ff0000000000001], 'i8').view('f8') + assert np.isnan(b) + if ufunc.nin == 1: + ufunc(b) + elif ufunc.nin == 2: + ufunc(b, b.copy()) + else: + raise ValueError('ufunc with more than 2 inputs') + |