|
17 | 17 | _gen_alignment_data
|
18 | 18 | )
|
19 | 19 |
|
20 |
| - |
21 | 20 | def on_powerpc():
|
22 | 21 | """ True if we are running on a Power PC platform."""
|
23 | 22 | return platform.processor() == 'powerpc' or \
|
@@ -650,6 +649,34 @@ def test_exp_values(self):
|
650 | 649 | yf = np.array(y, dtype=dt)*log2_
|
651 | 650 | assert_almost_equal(np.exp(yf), xf)
|
652 | 651 |
|
| 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)) |
653 | 680 |
|
654 | 681 | class TestLogAddExp(_FilterInvalids):
|
655 | 682 | def test_logaddexp_values(self):
|
|
0 commit comments