def test_local_merge_abs():
x, y, z = T.matrices('xyz')
x_val = numpy.random.rand(5, 5).astype(config.floatX)
y_val = numpy.random.rand(5, 5).astype(config.floatX)
z_val = numpy.random.rand(5, 5).astype(config.floatX)
mode = theano.config.mode
if mode == "FAST_COMPILE":
mode = "FAST_RUN"
mode = theano.compile.mode.get_mode(mode).excluding(
"local_elemwise_fusion")
f = theano.function([y, z], (abs(y * z * -2)), mode=mode)
f(y_val, z_val)
assert isinstance(f.maker.fgraph.toposort()[1].op.scalar_op, scal.Abs)
assert len(f.maker.fgraph.toposort()) == 2
f = theano.function([x, y], abs(x / y), mode=mode)
f(x_val, y_val)
assert isinstance(f.maker.fgraph.toposort()[1].op.scalar_op, scal.Abs)
assert len(f.maker.fgraph.toposort()) == 2
评论列表
文章目录