提交 a224f4b5 authored 作者: Saizheng Zhang's avatar Saizheng Zhang

tensor_inc_subtensor, test:add numerical test, add alloc test for broadcastable case

上级 2166de1a
...@@ -1948,9 +1948,9 @@ def test_subtensor_inc_subtensor(): ...@@ -1948,9 +1948,9 @@ def test_subtensor_inc_subtensor():
assert isinstance(prog[0].op, DeepCopyOp) assert isinstance(prog[0].op, DeepCopyOp)
# basic test, numerical check # basic test, numerical check
x_ = numpy.random.uniform(size=[3, 4]) x_ = numpy.random.uniform(size=[3, 4])
v_ = numpy.random.uniform(size=[4,]) v_ = numpy.random.uniform(size=[4, ])
i_ = 1 i_ = 1
assert f(x_, i_, v_) == v_ assert numpy.array_equal(f(x_, i_, v_), v_)
# complicated test # complicated test
x = tensor.tensor4('x') x = tensor.tensor4('x')
...@@ -1968,9 +1968,9 @@ def test_subtensor_inc_subtensor(): ...@@ -1968,9 +1968,9 @@ def test_subtensor_inc_subtensor():
assert isinstance(prog[0].op, DeepCopyOp) assert isinstance(prog[0].op, DeepCopyOp)
# complicated test, numerical check # complicated test, numerical check
x_ = numpy.random.uniform(size=[3, 4, 5, 6]) x_ = numpy.random.uniform(size=[3, 4, 5, 6])
v_ = numpy.random.uniform(size=[2, 3, 2]) v_ = numpy.random.uniform(size=[2, 2, 2])
i1_, i2_, i3_, i4_ = 1, 2, 3, 4 i1_, i2_, i3_, i4_ = 1, 2, 3, 4
assert f(x_, i1_, i2_, i3_, i4_, v_) == v_ assert numpy.array_equal(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]
...@@ -1982,10 +1982,10 @@ def test_subtensor_inc_subtensor(): ...@@ -1982,10 +1982,10 @@ def test_subtensor_inc_subtensor():
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 # case not use this optimization, numerical check
x_ = numpy.random.uniform(size=[3, 4, 5, 6]) x_ = numpy.random.uniform(size=[3, 4, 5, 6])
v_ = numpy.random.uniform(size=[2, 3, 2]) v_ = numpy.random.uniform(size=[2, 2, 2])
i1_, i2_, i3_, i4_ = 1, 2, 3, 4 i1_, i2_, i3_, i4_ = 1, 2, 3, 4
x_[i1, :i2, i3:, ::i4] = v_ x_[i1_, :i2_, i3_:, ::i4_] = v_
assert f(x_, i1_, i2_, i3_, i4_, v_) == x_[i1, :i3, i2:, ::i4] assert numpy.array_equal(f(x_, i1_, i2_, i3_, i4_, v_), x_[i1_, :i3_, i2_:, ::i4_])
# case when v is broadcastable # case when v is broadcastable
x = tensor.matrix('x') x = tensor.matrix('x')
...@@ -1997,14 +1997,13 @@ def test_subtensor_inc_subtensor(): ...@@ -1997,14 +1997,13 @@ def test_subtensor_inc_subtensor():
mode = theano.compile.mode.get_default_mode().including('local_subtensor_inc_subtensor') mode = theano.compile.mode.get_default_mode().including('local_subtensor_inc_subtensor')
f = theano.function([x, i1, i2, v], z, mode=mode) f = theano.function([x, i1, i2, v], z, mode=mode)
prog = f.maker.fgraph.toposort() prog = f.maker.fgraph.toposort()
import pdb assert any(isinstance(x.op, tensor.Alloc) for x in prog)
pdb.set_trace() # case when v is broadcastable, numerical check
assert len(prog) == 1
# basic test, numerical check
x_ = numpy.random.uniform(size=[3, 4]) x_ = numpy.random.uniform(size=[3, 4])
v_ = numpy.random.uniform(size=[2,]) v_ = numpy.random.uniform(size=[2, ])
i1_, i2_ = 1, 2 i1_, i2_ = 2, 2
assert f(x_, i_, v_) == v_ x_[:i1_, :i2_] = v_
assert numpy.array_equal(f(x_, i1_, i2_, v_), x_[:i1_, :i2_])
class test_local_subtensor_make_vector(unittest.TestCase): class test_local_subtensor_make_vector(unittest.TestCase):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论