提交 8b7aeb6e authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Add test demonstrating problem with current version of subtensor(alloc) opt.

上级 ad02dfbe
...@@ -276,3 +276,29 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -276,3 +276,29 @@ class TestComputeTestValue(unittest.TestCase):
finally: finally:
theano.config.compute_test_value = orig_compute_test_value theano.config.compute_test_value = orig_compute_test_value
def test_no_perform(self):
pass
def test_no_c_code(self):
orig_compute_test_value = theano.config.compute_test_value
try:
theano.config.compute_test_value = 'raise'
# int_div has no C code for the moment
# If that changes, use another op with no C code here
i = T.iscalar('i')
j = T.iscalar('j')
i.tag.test_value = 3
j.tag.test_value = 2
o = i // j
# Check that the c_code function is not implemented
self.assertRaises(NotImplementedError, o.owner.op.c_code,
o.owner, 'o', ('x', 'y'), 'z', {'fail': ''})
assert hasattr(o.tag, 'test_value')
assert o.tag.test_value == 1
finally:
theano.config.compute_test_value = orig_compute_test_value
...@@ -1581,8 +1581,9 @@ class test_local_subtensor_merge(unittest.TestCase): ...@@ -1581,8 +1581,9 @@ class test_local_subtensor_merge(unittest.TestCase):
for s2 in s2r: for s2 in s2r:
f(x_val, b1,e1,s1,b2,e2,s2) f(x_val, b1,e1,s1,b2,e2,s2)
class Test_alloc_zero(unittest.TestCase):
def test_setsubtensor_allocs0(): def test_setsubtensor_allocs0(self):
x = tensor.matrix() x = tensor.matrix()
y = tensor.matrix() y = tensor.matrix()
x0 = tensor.zeros_like(x) x0 = tensor.zeros_like(x)
...@@ -1592,7 +1593,7 @@ def test_setsubtensor_allocs0(): ...@@ -1592,7 +1593,7 @@ def test_setsubtensor_allocs0():
assert numpy.all( [ not isinstance(x.op, tensor.IncSubtensor) for x in assert numpy.all( [ not isinstance(x.op, tensor.IncSubtensor) for x in
f.maker.env.toposort() ]) f.maker.env.toposort() ])
def test_setsubtensor_allocs1(): def test_setsubtensor_allocs1(self):
y = tensor.matrix() y = tensor.matrix()
x0 = tensor.constant(numpy.asarray(numpy.zeros_like((4,4)), dtype=config.floatX)) x0 = tensor.constant(numpy.asarray(numpy.zeros_like((4,4)), dtype=config.floatX))
y0 = tensor.zeros_like(y) y0 = tensor.zeros_like(y)
...@@ -1601,7 +1602,7 @@ def test_setsubtensor_allocs1(): ...@@ -1601,7 +1602,7 @@ def test_setsubtensor_allocs1():
assert numpy.all( [ not isinstance(x.op, tensor.IncSubtensor) for x in assert numpy.all( [ not isinstance(x.op, tensor.IncSubtensor) for x in
f.maker.env.toposort() ]) f.maker.env.toposort() ])
def test_setsubtensor_allocs2(): def test_setsubtensor_allocs2(self):
x = tensor.matrix() x = tensor.matrix()
y0 = tensor.constant(numpy.asarray(numpy.zeros_like((4,4)), dtype=config.floatX)) y0 = tensor.constant(numpy.asarray(numpy.zeros_like((4,4)), dtype=config.floatX))
x0 = tensor.zeros_like(x) x0 = tensor.zeros_like(x)
...@@ -1610,7 +1611,7 @@ def test_setsubtensor_allocs2(): ...@@ -1610,7 +1611,7 @@ def test_setsubtensor_allocs2():
assert numpy.all( [ not isinstance(x.op, tensor.IncSubtensor) for x in assert numpy.all( [ not isinstance(x.op, tensor.IncSubtensor) for x in
f.maker.env.toposort() ]) f.maker.env.toposort() ])
def test_incsubtensor_allocs0(): def test_incsubtensor_allocs0(self):
x = tensor.matrix() x = tensor.matrix()
y = tensor.matrix() y = tensor.matrix()
y0 = tensor.zeros_like(y) y0 = tensor.zeros_like(y)
...@@ -1619,7 +1620,7 @@ def test_incsubtensor_allocs0(): ...@@ -1619,7 +1620,7 @@ def test_incsubtensor_allocs0():
assert numpy.all( [ not isinstance(x.op, tensor.IncSubtensor) for x in assert numpy.all( [ not isinstance(x.op, tensor.IncSubtensor) for x in
f.maker.env.toposort() ]) f.maker.env.toposort() ])
def test_incsubtensor_allocs1(): def test_incsubtensor_allocs1(self):
x = tensor.matrix() x = tensor.matrix()
y0 = tensor.constant(numpy.asarray(numpy.zeros_like((4,4)), dtype=config.floatX)) y0 = tensor.constant(numpy.asarray(numpy.zeros_like((4,4)), dtype=config.floatX))
z = tensor.inc_subtensor(x[:4], y0) z = tensor.inc_subtensor(x[:4], y0)
...@@ -1628,7 +1629,7 @@ def test_incsubtensor_allocs1(): ...@@ -1628,7 +1629,7 @@ def test_incsubtensor_allocs1():
f.maker.env.toposort() ]) f.maker.env.toposort() ])
def test_dot_allocs_0(): def test_dot_allocs_0(self):
v1 = tensor.vector('v1') v1 = tensor.vector('v1')
v2 = tensor.vector('v2') v2 = tensor.vector('v2')
m1 = tensor.matrix('m1') m1 = tensor.matrix('m1')
...@@ -1652,6 +1653,27 @@ def test_dot_allocs_0(): ...@@ -1652,6 +1653,27 @@ def test_dot_allocs_0():
f.maker.env.toposort() ]) f.maker.env.toposort() ])
def test_local_subtensor_alloc0():
x = tensor.matrix('x')
y = tensor.vector('y')
# The rows of yx are copies of x
yx = tensor.alloc(y, x.shape[0], x.shape[1])
# Slice of each row
z_mat = yx[:,3:]
assert z_mat.ndim == 2
# Only one column
z_vec = yx[:,3]
assert z_vec.ndim == 1
f = theano.function([x, y], z_mat)
g = theano.function([x, y], z_vec)
# DebugMode should detect if something goes wrong.
f(numpy.zeros((3,5)), numpy.arange(5))
g(numpy.zeros((3,5)), numpy.arange(5))
def test_local_fill_useless(): def test_local_fill_useless():
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论