提交 2de5415d authored 作者: Brandon T. Willard's avatar Brandon T. Willard

Add missing return for Ops without c_code in local_elemwise_fusion_op

上级 002b7cdd
...@@ -2080,6 +2080,34 @@ class TestFusion: ...@@ -2080,6 +2080,34 @@ class TestFusion:
), ),
) )
@pytest.mark.skipif(not theano.config.cxx, reason="No cxx compiler")
def test_no_c_code(self):
"""Make sure we avoid fusions for `Op`s without C code implementations."""
# This custom `Op` has no `c_code` method
class NoCCodeOp(scal.basic.UnaryScalarOp):
def impl(self, x):
return x * 2
no_c_code_op = Elemwise(NoCCodeOp(scal.basic.upgrade_to_float))
mode = theano.Mode(linker="cvm")
mode._optimizer = mode._optimizer.including(
"local_elemwise_fusion",
"composite_elemwise_fusion",
"canonicalize",
"inplace",
)
x = tt.vector()
out = x * no_c_code_op(x + 1)
f = function([x], out, mode=mode)
assert not any(
isinstance(getattr(n.op, "scalar_op"), scal.basic.Composite)
for n in f.maker.fgraph.toposort()
)
class TimesN(scal.basic.UnaryScalarOp): class TimesN(scal.basic.UnaryScalarOp):
""" """
......
...@@ -7697,6 +7697,7 @@ your code will run correctly, but may be slower.""" ...@@ -7697,6 +7697,7 @@ your code will run correctly, but may be slower."""
"loop fusion." "loop fusion."
) )
) )
return False
# create the composite op. # create the composite op.
composite_op = ts.Composite(s_inputs, s_new_out) composite_op = ts.Composite(s_inputs, s_new_out)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论