提交 de10660e authored 作者: nouiz's avatar nouiz

Merge pull request #1104 from delallea/fix_1096

Fixed crash in constant folding optimization
...@@ -3659,3 +3659,18 @@ def test_compute_test_value(): ...@@ -3659,3 +3659,18 @@ def test_compute_test_value():
#print f(xv) #print f(xv)
finally: finally:
theano.config.compute_test_value = backup theano.config.compute_test_value = backup
def test_constant_folding_n_steps():
# The following code used to crash at revision 2060b8f, in the constant
# folding optimization step.
res, _ = theano.scan(lambda x: x * 2,
outputs_info=tensor.ones(()),
# The constant `n_steps` was causing the crash.
n_steps=10)
on_opt_error = theano.config.on_opt_error
theano.config.on_opt_error = 'raise'
try:
theano.function([], res)()
finally:
theano.config.on_opt_error = on_opt_error
...@@ -3370,6 +3370,10 @@ class Alloc(gof.Op): ...@@ -3370,6 +3370,10 @@ class Alloc(gof.Op):
return self.make_node(eval_points[0], *inputs[1:]).outputs return self.make_node(eval_points[0], *inputs[1:]).outputs
def do_constant_folding(self, node): def do_constant_folding(self, node):
if not getattr(node.outputs[0], 'clients', []):
# If there are no clients then there is no point doing constant
# folding.
return False
for client in node.outputs[0].clients: for client in node.outputs[0].clients:
if client[0] == 'output': if client[0] == 'output':
# If the output is a constant, it will have to be deepcopied # If the output is a constant, it will have to be deepcopied
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论