Skip to content

Commit

Permalink
BUG: Fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
steff456 committed Jul 16, 2021
1 parent 18a2971 commit 8ad28c4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
4 changes: 2 additions & 2 deletions numpy/core/tests/test_numeric.py
Expand Up @@ -646,7 +646,7 @@ def test_floating_exceptions(self):
if np.dtype(ftype).kind == 'f':
# Get some extreme values for the type
fi = np.finfo(ftype)
ft_tiny = fi.tiny
ft_tiny = fi.machar.tiny
ft_max = fi.max
ft_eps = fi.eps
underflow = 'underflow'
Expand All @@ -655,7 +655,7 @@ def test_floating_exceptions(self):
# 'c', complex, corresponding real dtype
rtype = type(ftype(0).real)
fi = np.finfo(rtype)
ft_tiny = ftype(fi.tiny)
ft_tiny = ftype(fi.machar.tiny)
ft_max = ftype(fi.max)
ft_eps = ftype(fi.eps)
# The complex types raise different exceptions
Expand Down
6 changes: 4 additions & 2 deletions numpy/core/tests/test_scalarmath.py
Expand Up @@ -670,8 +670,10 @@ def _test_abs_func(self, absfunc, test_dtype):
x = test_dtype(np.finfo(test_dtype).max)
assert_equal(absfunc(x), x.real)

x = test_dtype(np.finfo(test_dtype).tiny)
assert_equal(absfunc(x), x.real)
with suppress_warnings() as sup:
sup.filter(UserWarning)
x = test_dtype(np.finfo(test_dtype).tiny)
assert_equal(absfunc(x), x.real)

x = test_dtype(np.finfo(test_dtype).min)
assert_equal(absfunc(x), -x.real)
Expand Down
22 changes: 13 additions & 9 deletions numpy/core/tests/test_ufunc.py
Expand Up @@ -12,7 +12,7 @@
from numpy.testing import (
assert_, assert_equal, assert_raises, assert_array_equal,
assert_almost_equal, assert_array_almost_equal, assert_no_warnings,
assert_allclose, HAS_REFCOUNT,
assert_allclose, HAS_REFCOUNT, suppress_warnings
)
from numpy.compat import pickle

Expand Down Expand Up @@ -584,10 +584,12 @@ def test_true_divide(self):
tgt = float(x)/float(y)
rtol = max(np.finfo(dtout).resolution, 1e-15)
# The value of tiny for double double is NaN
if not np.isnan(np.finfo(dtout).tiny):
atol = max(np.finfo(dtout).tiny, 3e-308)
else:
atol = 3e-308
with suppress_warnings() as sup:
sup.filter(UserWarning)
if not np.isnan(np.finfo(dtout).tiny):
atol = max(np.finfo(dtout).tiny, 3e-308)
else:
atol = 3e-308
# Some test values result in invalid for float16.
with np.errstate(invalid='ignore'):
res = np.true_divide(x, y, dtype=dtout)
Expand All @@ -601,10 +603,12 @@ def test_true_divide(self):
tgt = complex(x)/complex(y)
rtol = max(np.finfo(dtout).resolution, 1e-15)
# The value of tiny for double double is NaN
if not np.isnan(np.finfo(dtout).tiny):
atol = max(np.finfo(dtout).tiny, 3e-308)
else:
atol = 3e-308
with suppress_warnings() as sup:
sup.filter(UserWarning)
if not np.isnan(np.finfo(dtout).tiny):
atol = max(np.finfo(dtout).tiny, 3e-308)
else:
atol = 3e-308
res = np.true_divide(x, y, dtype=dtout)
if not np.isfinite(res):
continue
Expand Down
8 changes: 5 additions & 3 deletions numpy/core/tests/test_umath.py
Expand Up @@ -3448,9 +3448,11 @@ def test_nextafter_0():
for t, direction in itertools.product(np.sctypes['float'], (1, -1)):
# The value of tiny for double double is NaN, so we need to pass the
# assert
if not np.isnan(np.finfo(t).tiny):
tiny = np.finfo(t).tiny
assert_(0. < direction * np.nextafter(t(0), t(direction)) < tiny)
with suppress_warnings() as sup:
sup.filter(RuntimeWarning)
if not np.isnan(np.finfo(t).tiny):
tiny = np.finfo(t).tiny
assert_(0. < direction * np.nextafter(t(0), t(direction)) < tiny)
assert_equal(np.nextafter(t(0), t(direction)) / t(2.1), direction * 0.0)

def _test_spacing(t):
Expand Down

0 comments on commit 8ad28c4

Please sign in to comment.