Skip to content

Commit a916c38

Browse files
committed
ENH: Adding special float32 handling tests for exp and log
1 parent 3e6579f commit a916c38

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

numpy/core/tests/test_umath.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
_gen_alignment_data
1818
)
1919

20-
2120
def on_powerpc():
2221
""" True if we are running on a Power PC platform."""
2322
return platform.processor() == 'powerpc' or \
@@ -650,6 +649,34 @@ def test_exp_values(self):
650649
yf = np.array(y, dtype=dt)*log2_
651650
assert_almost_equal(np.exp(yf), xf)
652651

652+
class TestSpecialFloats(object):
653+
def test_exp_values(self):
654+
x = [np.nan, np.nan, np.inf, 0.]
655+
y = [np.nan, -np.nan, np.inf, -np.inf]
656+
for dt in ['f', 'd', 'g']:
657+
xf = np.array(x, dtype=dt)
658+
yf = np.array(y, dtype=dt)
659+
assert_equal(np.exp(yf), xf)
660+
661+
with np.errstate(over='raise'):
662+
assert_raises(FloatingPointError, np.exp, np.float32(100.))
663+
assert_raises(FloatingPointError, np.exp, np.float32(1E19))
664+
665+
def test_log_values(self):
666+
with np.errstate(all='ignore'):
667+
x = [np.nan, np.nan, np.inf, np.nan, -np.inf, np.nan]
668+
y = [np.nan, -np.nan, np.inf, -np.inf, 0., -1.0]
669+
for dt in ['f', 'd', 'g']:
670+
xf = np.array(x, dtype=dt)
671+
yf = np.array(y, dtype=dt)
672+
assert_equal(np.log(yf), xf)
673+
674+
with np.errstate(divide='raise'):
675+
assert_raises(FloatingPointError, np.log, np.float32(0.))
676+
677+
with np.errstate(invalid='raise'):
678+
assert_raises(FloatingPointError, np.log, np.float32(-np.inf))
679+
assert_raises(FloatingPointError, np.log, np.float32(-1.0))
653680

654681
class TestLogAddExp(_FilterInvalids):
655682
def test_logaddexp_values(self):

0 commit comments

Comments
 (0)