Esempio n. 1
0
def test_log1mexp():
    vals = np.array([-1, 0, 1e-20, 1e-4, 10, 100, 1e20])
    # import mpmath
    # mpmath.mp.dps = 1000
    # [float(mpmath.log(1 - mpmath.exp(-x))) for x in vals]
    expected = np.array([
        np.nan,
        -np.inf,
        -46.051701859880914,
        -9.210390371559516,
        -4.540096037048921e-05,
        -3.720075976020836e-44,
        0.0,
    ])
    actual = log1mexp(vals).eval()
    npt.assert_allclose(actual, expected)
    actual_ = log1mexp_numpy(vals)
    npt.assert_allclose(actual_, expected)
Esempio n. 2
0
def test_log1mexp_numpy_no_warning():
    """Assert RuntimeWarning is not raised for very small numbers"""
    with pytest.warns(None) as record:
        log1mexp_numpy(1e-25)
    assert not record