(self)
| 1554 | |
| 1555 | @pytest.mark.skipif(IS_WASM, reason="fp errors don't work in wasm") |
| 1556 | def test_log_values(self): |
| 1557 | with np.errstate(all='ignore'): |
| 1558 | x = [np.nan, np.nan, np.inf, np.nan, -np.inf, np.nan] |
| 1559 | y = [np.nan, -np.nan, np.inf, -np.inf, 0.0, -1.0] |
| 1560 | y1p = [np.nan, -np.nan, np.inf, -np.inf, -1.0, -2.0] |
| 1561 | for dt in ['e', 'f', 'd', 'g']: |
| 1562 | xf = np.array(x, dtype=dt) |
| 1563 | yf = np.array(y, dtype=dt) |
| 1564 | yf1p = np.array(y1p, dtype=dt) |
| 1565 | assert_equal(np.log(yf), xf) |
| 1566 | assert_equal(np.log2(yf), xf) |
| 1567 | assert_equal(np.log10(yf), xf) |
| 1568 | assert_equal(np.log1p(yf1p), xf) |
| 1569 | |
| 1570 | with np.errstate(divide='raise'): |
| 1571 | for dt in ['e', 'f', 'd']: |
| 1572 | assert_raises(FloatingPointError, np.log, |
| 1573 | np.array(0.0, dtype=dt)) |
| 1574 | assert_raises(FloatingPointError, np.log2, |
| 1575 | np.array(0.0, dtype=dt)) |
| 1576 | assert_raises(FloatingPointError, np.log10, |
| 1577 | np.array(0.0, dtype=dt)) |
| 1578 | assert_raises(FloatingPointError, np.log1p, |
| 1579 | np.array(-1.0, dtype=dt)) |
| 1580 | |
| 1581 | with np.errstate(invalid='raise'): |
| 1582 | for dt in ['e', 'f', 'd']: |
| 1583 | assert_raises(FloatingPointError, np.log, |
| 1584 | np.array(-np.inf, dtype=dt)) |
| 1585 | assert_raises(FloatingPointError, np.log, |
| 1586 | np.array(-1.0, dtype=dt)) |
| 1587 | assert_raises(FloatingPointError, np.log2, |
| 1588 | np.array(-np.inf, dtype=dt)) |
| 1589 | assert_raises(FloatingPointError, np.log2, |
| 1590 | np.array(-1.0, dtype=dt)) |
| 1591 | assert_raises(FloatingPointError, np.log10, |
| 1592 | np.array(-np.inf, dtype=dt)) |
| 1593 | assert_raises(FloatingPointError, np.log10, |
| 1594 | np.array(-1.0, dtype=dt)) |
| 1595 | assert_raises(FloatingPointError, np.log1p, |
| 1596 | np.array(-np.inf, dtype=dt)) |
| 1597 | assert_raises(FloatingPointError, np.log1p, |
| 1598 | np.array(-2.0, dtype=dt)) |
| 1599 | |
| 1600 | # See https://github.com/numpy/numpy/issues/18005 |
| 1601 | with assert_no_warnings(): |
| 1602 | a = np.array(1e9, dtype='float32') |
| 1603 | np.log(a) |
| 1604 | |
| 1605 | @pytest.mark.skipif(IS_WASM, reason="fp errors don't work in wasm") |
| 1606 | @pytest.mark.parametrize('dtype', ['e', 'f', 'd', 'g']) |
nothing calls this directly
no test coverage detected