Ejemplo n.º 1
0
def test_log1mexp_deprecation_warnings():
    with pytest.warns(
            FutureWarning,
            match="pymc.math.log1mexp_numpy will expect a negative input",
    ):
        res_pos = log1mexp_numpy(2)

    with pytest.warns(None) as record:
        res_neg = log1mexp_numpy(-2, negative_input=True)
    assert not record

    with pytest.warns(
            FutureWarning,
            match="pymc.math.log1mexp will expect a negative input",
    ):
        res_pos_at = log1mexp(2).eval()

    with pytest.warns(None):
        res_neg_at = log1mexp(-2, negative_input=True).eval()

    assert np.isclose(res_pos, res_neg)
    assert np.isclose(res_pos_at, res_neg)
    assert np.isclose(res_neg_at, res_neg)
Ejemplo n.º 2
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 = at.log1mexp(-vals).eval()
    npt.assert_allclose(actual, expected)
    actual_ = log1mexp_numpy(-vals, negative_input=True)
    npt.assert_allclose(actual_, expected)
    # Check that input was not changed in place
    npt.assert_allclose(vals, vals_)
Ejemplo n.º 3
0
def test_log1mexp_numpy_integer_input():
    assert np.isclose(log1mexp_numpy(-2, negative_input=True),
                      at.log1mexp(-2).eval())
Ejemplo n.º 4
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, negative_input=True)
    assert not record