提交 06f7b0bc authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Add local_zero_div to specialize phase

Add a test that this is enough to solve the binary_crossentropy(reshape) case.
上级 0bfc64e2
......@@ -30,7 +30,8 @@ from theano.tensor.nnet import (categorical_crossentropy,
Prepend_scalar_to_each_row,
relu,
h_softmax,
elu)
elu,
binary_crossentropy)
from theano.tensor import matrix, vector, lvector, scalar
......@@ -1684,3 +1685,15 @@ def test_elu():
for alpha in 1.5, 2, -1, -1.5, -2:
y = elu(x, alpha).eval({x: X})
utt.assert_allclose(y, numpy.where(X > 0, X, alpha * (numpy.exp(X) - 1)))
def test_binary_crossentropy_reshape():
# Reported as https://github.com/Theano/Theano/issues/4086
a = tensor.tensor4('a')
c = binary_crossentropy(sigmoid(a.reshape((-1, 1))), 1).sum()
ga = theano.grad(c, a)
# This only works when "specialize" options are included
mode = theano.compile.get_default_mode().including('fast_run')
fga = theano.function([a], ga, mode=mode)
utt.assert_allclose(fga(numpy.array([[[[30.]]]], dtype=config.floatX)),
numpy.zeros((1, 1, 1, 1), dtype=config.floatX))
......@@ -5270,6 +5270,7 @@ def local_intdiv_by_one(node):
@register_canonicalize
@register_specialize
@gof.local_optimizer([T.int_div, T.true_div])
def local_zero_div(node):
"""0 / x -> 0
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论