提交 2166de1a authored 作者: Saizheng Zhang's avatar Saizheng Zhang

tensor_inc_subtensor_test: added numerical tests, alloc test not finished

上级 9fe35a2d
...@@ -1946,6 +1946,11 @@ def test_subtensor_inc_subtensor(): ...@@ -1946,6 +1946,11 @@ def test_subtensor_inc_subtensor():
prog = f.maker.fgraph.toposort() prog = f.maker.fgraph.toposort()
assert len(prog) == 1 assert len(prog) == 1
assert isinstance(prog[0].op, DeepCopyOp) assert isinstance(prog[0].op, DeepCopyOp)
# basic test, numerical check
x_ = numpy.random.uniform(size=[3, 4])
v_ = numpy.random.uniform(size=[4,])
i_ = 1
assert f(x_, i_, v_) == v_
# complicated test # complicated test
x = tensor.tensor4('x') x = tensor.tensor4('x')
...@@ -1961,6 +1966,11 @@ def test_subtensor_inc_subtensor(): ...@@ -1961,6 +1966,11 @@ def test_subtensor_inc_subtensor():
prog = f.maker.fgraph.toposort() prog = f.maker.fgraph.toposort()
assert len(prog) == 1 assert len(prog) == 1
assert isinstance(prog[0].op, DeepCopyOp) assert isinstance(prog[0].op, DeepCopyOp)
# complicated test, numerical check
x_ = numpy.random.uniform(size=[3, 4, 5, 6])
v_ = numpy.random.uniform(size=[2, 3, 2])
i1_, i2_, i3_, i4_ = 1, 2, 3, 4
assert f(x_, i1_, i2_, i3_, i4_, v_) == v_
# case not use this optimization # case not use this optimization
z = y[i1, :i3, i2:, ::i4] z = y[i1, :i3, i2:, ::i4]
...@@ -1970,6 +1980,31 @@ def test_subtensor_inc_subtensor(): ...@@ -1970,6 +1980,31 @@ def test_subtensor_inc_subtensor():
assert len(prog) != 1 assert len(prog) != 1
assert any(isinstance(x.op, tensor.IncSubtensor) for x in prog) assert any(isinstance(x.op, tensor.IncSubtensor) for x in prog)
assert any(isinstance(x.op, tensor.Subtensor) for x in prog) assert any(isinstance(x.op, tensor.Subtensor) for x in prog)
# case not use this optimization, numerical check
x_ = numpy.random.uniform(size=[3, 4, 5, 6])
v_ = numpy.random.uniform(size=[2, 3, 2])
i1_, i2_, i3_, i4_ = 1, 2, 3, 4
x_[i1, :i2, i3:, ::i4] = v_
assert f(x_, i1_, i2_, i3_, i4_, v_) == x_[i1, :i3, i2:, ::i4]
# case when v is broadcastable
x = tensor.matrix('x')
i1 = tensor.iscalar('i')
i2 = tensor.iscalar('i')
v = tensor.vector('v')
y = tensor.set_subtensor(x[:i1, :i2], v)
z = y[:i1, :i2]
mode = theano.compile.mode.get_default_mode().including('local_subtensor_inc_subtensor')
f = theano.function([x, i1, i2, v], z, mode=mode)
prog = f.maker.fgraph.toposort()
import pdb
pdb.set_trace()
assert len(prog) == 1
# basic test, numerical check
x_ = numpy.random.uniform(size=[3, 4])
v_ = numpy.random.uniform(size=[2,])
i1_, i2_ = 1, 2
assert f(x_, i_, v_) == v_
class test_local_subtensor_make_vector(unittest.TestCase): class test_local_subtensor_make_vector(unittest.TestCase):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论