(self)
| 1436 | |
| 1437 | @pytest.mark.skipif(IS_WASM, reason="fp errors don't work in wasm") |
| 1438 | def test_log_values(self): |
| 1439 | with np.errstate(all='ignore'): |
| 1440 | x = [np.nan, np.nan, np.inf, np.nan, -np.inf, np.nan] |
| 1441 | y = [np.nan, -np.nan, np.inf, -np.inf, 0.0, -1.0] |
| 1442 | y1p = [np.nan, -np.nan, np.inf, -np.inf, -1.0, -2.0] |
| 1443 | for dt in ['e', 'f', 'd', 'g']: |
| 1444 | xf = np.array(x, dtype=dt) |
| 1445 | yf = np.array(y, dtype=dt) |
| 1446 | yf1p = np.array(y1p, dtype=dt) |
| 1447 | assert_equal(np.log(yf), xf) |
| 1448 | assert_equal(np.log2(yf), xf) |
| 1449 | assert_equal(np.log10(yf), xf) |
| 1450 | assert_equal(np.log1p(yf1p), xf) |
| 1451 | |
| 1452 | with np.errstate(divide='raise'): |
| 1453 | for dt in ['e', 'f', 'd']: |
| 1454 | assert_raises(FloatingPointError, np.log, |
| 1455 | np.array(0.0, dtype=dt)) |
| 1456 | assert_raises(FloatingPointError, np.log2, |
| 1457 | np.array(0.0, dtype=dt)) |
| 1458 | assert_raises(FloatingPointError, np.log10, |
| 1459 | np.array(0.0, dtype=dt)) |
| 1460 | assert_raises(FloatingPointError, np.log1p, |
| 1461 | np.array(-1.0, dtype=dt)) |
| 1462 | |
| 1463 | with np.errstate(invalid='raise'): |
| 1464 | for dt in ['e', 'f', 'd']: |
| 1465 | assert_raises(FloatingPointError, np.log, |
| 1466 | np.array(-np.inf, dtype=dt)) |
| 1467 | assert_raises(FloatingPointError, np.log, |
| 1468 | np.array(-1.0, dtype=dt)) |
| 1469 | assert_raises(FloatingPointError, np.log2, |
| 1470 | np.array(-np.inf, dtype=dt)) |
| 1471 | assert_raises(FloatingPointError, np.log2, |
| 1472 | np.array(-1.0, dtype=dt)) |
| 1473 | assert_raises(FloatingPointError, np.log10, |
| 1474 | np.array(-np.inf, dtype=dt)) |
| 1475 | assert_raises(FloatingPointError, np.log10, |
| 1476 | np.array(-1.0, dtype=dt)) |
| 1477 | assert_raises(FloatingPointError, np.log1p, |
| 1478 | np.array(-np.inf, dtype=dt)) |
| 1479 | assert_raises(FloatingPointError, np.log1p, |
| 1480 | np.array(-2.0, dtype=dt)) |
| 1481 | |
| 1482 | # See https://github.com/numpy/numpy/issues/18005 |
| 1483 | with assert_no_warnings(): |
| 1484 | a = np.array(1e9, dtype='float32') |
| 1485 | np.log(a) |
| 1486 | |
| 1487 | @pytest.mark.skipif(IS_WASM, reason="fp errors don't work in wasm") |
| 1488 | @pytest.mark.parametrize('dtype', ['e', 'f', 'd', 'g']) |
nothing calls this directly
no test coverage detected