提交 b15a7884 authored 作者: Frederic's avatar Frederic

Added test related to subtensor optimization

上级 3392778a
...@@ -1856,11 +1856,11 @@ class Test_alloc_zero(unittest.TestCase): ...@@ -1856,11 +1856,11 @@ class Test_alloc_zero(unittest.TestCase):
f.maker.env.toposort() ]) f.maker.env.toposort() ])
def test_local_subtensor_alloc0(): def test_local_subtensor_of_alloc():
x = tensor.matrix('x') x = tensor.matrix('x')
y = tensor.vector('y') y = tensor.vector('y')
# The rows of yx are copies of x # The rows of yx are copies of y
yx = tensor.alloc(y, x.shape[0], x.shape[1]) yx = tensor.alloc(y, x.shape[0], x.shape[1])
# Slice of each row # Slice of each row
...@@ -1897,33 +1897,53 @@ def test_local_subtensor_alloc0(): ...@@ -1897,33 +1897,53 @@ def test_local_subtensor_alloc0():
def test_local_fill_useless(): def test_local_fill_useless():
m = theano.config.mode #Test opt local_fill_cut
if m == 'FAST_COMPILE':
m = 'FAST_RUN'
x = dvector() x = dvector()
y = dvector() y = dvector()
z = lvector() z = lvector()
m = dmatrix()
x_ = numpy.random.rand(5,)
y_ = numpy.random.rand(5,)
z_ = (numpy.random.rand(5,) * 5).astype("int64")
m_ = numpy.random.rand(5, 5)
# basic case # basic case
f = function([x], T.fill(x,x)*2, mode=m) f = function([x], T.fill(x, x) * 2, mode=mode_opt)
assert [node.op for node in f.maker.env.toposort()] == [T.mul] assert [node.op for node in f.maker.env.toposort()] == [T.mul]
f(x_)
# basic case # basic case
f = function([x,y], T.second(y,x)*2, mode=m) f = function([x, y], T.second(y, x) * 2, mode=mode_opt)
assert [node.op for node in f.maker.env.toposort()] == [T.mul] assert [node.op for node in f.maker.env.toposort()] == [T.mul]
f(x_, y_)
# now with different type # basic case
f = function([x,z], T.fill(z,x)*2, mode=m) f = function([x, y], T.fill(x, y) * 2, mode=mode_opt)
assert [node.op for node in f.maker.env.toposort()] == [T.mul] assert [node.op for node in f.maker.env.toposort()] == [T.mul]
f(x_, y_)
# now cutting out the input ?? # now with different type(cast)
f = function([x,y], T.fill(x,y)*2, mode=m) f = function([x, z], T.fill(z, x) * 2, mode=mode_opt)
assert [node.op for node in f.maker.env.toposort()] == [T.mul] assert [node.op for node in f.maker.env.toposort()] == [T.mul]
f(x_, z_)
# now filll is serving as a cast # now with different type(cast)
f = function([x,y], T.fill(x,y)*2, mode=m) f = function([x, z], T.fill(x, z) * 2, mode=mode_opt)
assert [node.op for node in f.maker.env.toposort()] == [T.mul]
f(x_, z_)
# now cutting out the input ??
f = function([x, y], T.fill(x, y) * 2, mode=mode_opt)
assert [node.op for node in f.maker.env.toposort()] == [T.mul] assert [node.op for node in f.maker.env.toposort()] == [T.mul]
f(x_, y_)
# Test with different number of dimensions
# The fill is not useless, so it should stay
f = function([m, x], T.fill(m, x) * 2, mode=mode_opt)
ops = [node.op.__class__ for node in f.maker.env.toposort()]
assert T.Alloc in ops
f(m_, x_)
class test_shapeoptimizer(unittest.TestCase): class test_shapeoptimizer(unittest.TestCase):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论