def test_fusion_inplace(self):
mode = copy.copy(compile.mode.get_default_mode())
# we need the optimisation enabled and the canonicalize.
# the canonicalize is needed to merge multiplication/addition by constant.
mode._optimizer = mode._optimizer.including(
'local_elemwise_fusion', 'composite_elemwise_fusion',
'canonicalize', 'inplace')
x, y, z = dmatrices('xyz')
f = theano.function([x, y, z], tensor.dot(x, y) + x + y + z, mode=mode)
topo = f.maker.fgraph.toposort()
assert len(topo) == 2
assert f.maker.fgraph.toposort()[-1].op.inplace_pattern
f(numpy.random.random((5, 5)), numpy.random.random((5, 5)),
numpy.random.random((5, 5)))
评论列表
文章目录