提交 b1332b27 authored 作者: Ricardo Vieira's avatar Ricardo Vieira 提交者: Ricardo Vieira

Reintroduce test_log1mexp_stabilization accidentally removed in…

Reintroduce test_log1mexp_stabilization accidentally removed in ff1a3a9d
上级 b8e939e9
...@@ -4115,3 +4115,24 @@ def test_local_add_neg_to_sub_const(): ...@@ -4115,3 +4115,24 @@ def test_local_add_neg_to_sub_const():
x_test = np.array([3, 4], dtype=config.floatX) x_test = np.array([3, 4], dtype=config.floatX)
assert np.allclose(f(x_test), x_test + (-const)) assert np.allclose(f(x_test), x_test + (-const))
def test_log1mexp_stabilization():
mode = Mode("py").including("stabilize")
x = vector()
f = function([x], log(1 - exp(x)), mode=mode)
nodes = [node.op for node in f.maker.fgraph.toposort()]
assert nodes == [at.log1mexp]
# Check values that would under or overflow without rewriting
assert f([-(2.0**-55)]) != -np.inf
overflow_value = -500.0 if config.floatX == "float64" else -100.0
assert f([overflow_value]) < 0
# Check values around the switch point np.log(0.5)
assert np.allclose(
f(np.array([-0.8, -0.6], dtype=config.floatX)),
np.log(1 - np.exp([-0.8, -0.6])),
)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论