Beispiel #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)
Beispiel #2
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)
Beispiel #3
0
def test_log1mexp():
    vals = np.array([-1, 0, 1e-20, 1e-4, 10, 100, 1e20])
    vals_ = vals.copy()
    # 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)
    # Check that input was not changed in place
    npt.assert_allclose(vals, vals_)