提交 a6c2d45f authored 作者: Frédéric Bastien's avatar Frédéric Bastien

Merge pull request #2324 from nouiz/tests

Tests
...@@ -203,9 +203,9 @@ if __name__ == "__main__": ...@@ -203,9 +203,9 @@ if __name__ == "__main__":
cuda version 6.5 6.0 5.5 5.0 4.2 4.1 4.0 3.2 3.0 # note cuda version 6.5 6.0 5.5 5.0 4.2 4.1 4.0 3.2 3.0 # note
gpu gpu
K6000/NOECC 0.06s K6000/NOECC 0.06s 0.06s
K40 0.07s K40 0.07s
K20m/ECC 0.07s K20m/ECC 0.08s 0.07s
K20/NOECC 0.07s K20/NOECC 0.07s
M2090 0.19s M2090 0.19s
C2075 0.25s C2075 0.25s
......
...@@ -174,8 +174,8 @@ class TestPushOutScanOutputDot(object): ...@@ -174,8 +174,8 @@ class TestPushOutScanOutputDot(object):
# Ensure that the function compiled with the optimization produces # Ensure that the function compiled with the optimization produces
# the same results as the function compiled without # the same results as the function compiled without
v_value = numpy.random.random((4)) v_value = numpy.random.random((4)).astype(config.floatX)
m_value = numpy.random.random((4, 5)) m_value = numpy.random.random((4, 5)).astype(config.floatX)
output_opt = f_opt(v_value, m_value) output_opt = f_opt(v_value, m_value)
output_no_opt = f_no_opt(v_value, m_value) output_no_opt = f_no_opt(v_value, m_value)
...@@ -218,8 +218,8 @@ class TestPushOutScanOutputDot(object): ...@@ -218,8 +218,8 @@ class TestPushOutScanOutputDot(object):
# Ensure that the function compiled with the optimization produces # Ensure that the function compiled with the optimization produces
# the same results as the function compiled without # the same results as the function compiled without
a_value = numpy.random.random((3, 4)) a_value = numpy.random.random((3, 4)).astype(config.floatX)
b_value = numpy.random.random((4, 5)) b_value = numpy.random.random((4, 5)).astype(config.floatX)
output_opt = f_opt(a_value, b_value) output_opt = f_opt(a_value, b_value)
output_no_opt = f_no_opt(a_value, b_value) output_no_opt = f_no_opt(a_value, b_value)
...@@ -264,8 +264,8 @@ class TestPushOutScanOutputDot(object): ...@@ -264,8 +264,8 @@ class TestPushOutScanOutputDot(object):
# Ensure that the function compiled with the optimization produces # Ensure that the function compiled with the optimization produces
# the same results as the function compiled without # the same results as the function compiled without
a_value = numpy.random.random((3, 4)) a_value = numpy.random.random((3, 4)).astype(config.floatX)
b_value = numpy.random.random((4, 5)) b_value = numpy.random.random((4, 5)).astype(config.floatX)
output_opt = f_opt(a_value, b_value) output_opt = f_opt(a_value, b_value)
output_no_opt = f_no_opt(a_value, b_value) output_no_opt = f_no_opt(a_value, b_value)
......
...@@ -2490,9 +2490,11 @@ class test_local_adv_sub1_adv_inc_sub1(unittest.TestCase): ...@@ -2490,9 +2490,11 @@ class test_local_adv_sub1_adv_inc_sub1(unittest.TestCase):
f = theano.function([x, y, idx], o, self.mode) f = theano.function([x, y, idx], o, self.mode)
# test wrong index # test wrong index
for i in [dx.shape[0], -dx.shape[0] - 1]: for i in [dx.shape[0], -dx.shape[0] - 1]:
self.assertRaises(AssertionError, f, dx, dy, [i, i]) self.assertRaises((AssertionError, IndexError),
f, dx, dy, [i, i])
# test wrong shape # test wrong shape
self.assertRaises(AssertionError, f, dx, dy, [1]) self.assertRaises((AssertionError, ValueError),
f, dx, dy, [1])
class Test_alloc_zero(unittest.TestCase): class Test_alloc_zero(unittest.TestCase):
...@@ -2509,7 +2511,7 @@ class Test_alloc_zero(unittest.TestCase): ...@@ -2509,7 +2511,7 @@ class Test_alloc_zero(unittest.TestCase):
y0 = tensor.zeros_like(y) y0 = tensor.zeros_like(y)
z = tensor.set_subtensor(x0[:4], y0) z = tensor.set_subtensor(x0[:4], y0)
f = theano.function([x, y], z, mode=self.mode) f = theano.function([x, y], z, mode=self.mode)
assert numpy.all([not isinstance(x.op, tensor.IncSubtensor) for x in assert numpy.all([not isinstance(n.op, tensor.IncSubtensor) for n in
f.maker.fgraph.toposort()]) f.maker.fgraph.toposort()])
def test_setsubtensor_allocs1(self): def test_setsubtensor_allocs1(self):
...@@ -2519,7 +2521,7 @@ class Test_alloc_zero(unittest.TestCase): ...@@ -2519,7 +2521,7 @@ class Test_alloc_zero(unittest.TestCase):
y0 = tensor.zeros_like(y) y0 = tensor.zeros_like(y)
z = tensor.set_subtensor(x0[:4], y0) z = tensor.set_subtensor(x0[:4], y0)
f = theano.function([y], z, mode=self.mode) f = theano.function([y], z, mode=self.mode)
assert numpy.all([not isinstance(x.op, tensor.IncSubtensor) for x in assert numpy.all([not isinstance(n.op, tensor.IncSubtensor) for n in
f.maker.fgraph.toposort()]) f.maker.fgraph.toposort()])
def test_setsubtensor_allocs1t(self): def test_setsubtensor_allocs1t(self):
...@@ -2529,7 +2531,7 @@ class Test_alloc_zero(unittest.TestCase): ...@@ -2529,7 +2531,7 @@ class Test_alloc_zero(unittest.TestCase):
y0 = tensor.zeros_like(y) y0 = tensor.zeros_like(y)
z = tensor.set_subtensor(x0[:4], y0.T) z = tensor.set_subtensor(x0[:4], y0.T)
f = theano.function([y], z, mode=mode_opt) f = theano.function([y], z, mode=mode_opt)
assert numpy.all([not isinstance(x.op, tensor.IncSubtensor) for x in assert numpy.all([not isinstance(n.op, tensor.IncSubtensor) for n in
f.maker.fgraph.toposort()]) f.maker.fgraph.toposort()])
def test_setsubtensor_allocs2(self): def test_setsubtensor_allocs2(self):
...@@ -2548,7 +2550,7 @@ class Test_alloc_zero(unittest.TestCase): ...@@ -2548,7 +2550,7 @@ class Test_alloc_zero(unittest.TestCase):
y0 = tensor.zeros_like(y) y0 = tensor.zeros_like(y)
z = tensor.inc_subtensor(x[:4], y0) z = tensor.inc_subtensor(x[:4], y0)
f = theano.function([x, y], z, mode=self.mode) f = theano.function([x, y], z, mode=self.mode)
assert numpy.all([not isinstance(x.op, tensor.IncSubtensor) for x in assert numpy.all([not isinstance(n.op, tensor.IncSubtensor) for n in
f.maker.fgraph.toposort()]) f.maker.fgraph.toposort()])
def test_incsubtensor_allocs0t(self): def test_incsubtensor_allocs0t(self):
...@@ -2557,7 +2559,7 @@ class Test_alloc_zero(unittest.TestCase): ...@@ -2557,7 +2559,7 @@ class Test_alloc_zero(unittest.TestCase):
y0 = tensor.zeros_like(y) y0 = tensor.zeros_like(y)
z = tensor.inc_subtensor(x[:4], y0.T) z = tensor.inc_subtensor(x[:4], y0.T)
f = theano.function([x, y], z, mode=mode_opt) f = theano.function([x, y], z, mode=mode_opt)
assert numpy.all([not isinstance(x.op, tensor.IncSubtensor) for x in assert numpy.all([not isinstance(n.op, tensor.IncSubtensor) for n in
f.maker.fgraph.toposort()]) f.maker.fgraph.toposort()])
def test_incsubtensor_allocs1(self): def test_incsubtensor_allocs1(self):
...@@ -2575,8 +2577,8 @@ class Test_alloc_zero(unittest.TestCase): ...@@ -2575,8 +2577,8 @@ class Test_alloc_zero(unittest.TestCase):
y0 = tensor.zeros_like(y) y0 = tensor.zeros_like(y)
z = tensor.inc_subtensor(x[[0, 1, 2, 3]], y0) z = tensor.inc_subtensor(x[[0, 1, 2, 3]], y0)
f = theano.function([x, y], z, mode=self.mode) f = theano.function([x, y], z, mode=self.mode)
assert numpy.all([not isinstance(x.op, tensor.AdvancedIncSubtensor1) assert numpy.all([not isinstance(n.op, tensor.AdvancedIncSubtensor1)
for x in f.maker.fgraph.toposort()]) for n in f.maker.fgraph.toposort()])
def test_advancedincsubtensor1_allocs0t(self): def test_advancedincsubtensor1_allocs0t(self):
x = tensor.matrix() x = tensor.matrix()
...@@ -2584,8 +2586,8 @@ class Test_alloc_zero(unittest.TestCase): ...@@ -2584,8 +2586,8 @@ class Test_alloc_zero(unittest.TestCase):
y0 = tensor.zeros_like(y) y0 = tensor.zeros_like(y)
z = tensor.inc_subtensor(x[[0, 1, 2, 3]], y0.T) z = tensor.inc_subtensor(x[[0, 1, 2, 3]], y0.T)
f = theano.function([x, y], z, mode=mode_opt) f = theano.function([x, y], z, mode=mode_opt)
assert numpy.all([not isinstance(x.op, tensor.AdvancedIncSubtensor1) assert numpy.all([not isinstance(n.op, tensor.AdvancedIncSubtensor1)
for x in f.maker.fgraph.toposort()]) for n in f.maker.fgraph.toposort()])
def test_advancedincsubtensor1_allocs1(self): def test_advancedincsubtensor1_allocs1(self):
x = tensor.matrix() x = tensor.matrix()
...@@ -2593,8 +2595,8 @@ class Test_alloc_zero(unittest.TestCase): ...@@ -2593,8 +2595,8 @@ class Test_alloc_zero(unittest.TestCase):
dtype=config.floatX)) dtype=config.floatX))
z = tensor.inc_subtensor(x[[0, 1, 2, 3]], y0) z = tensor.inc_subtensor(x[[0, 1, 2, 3]], y0)
f = theano.function([x], z, mode=self.mode) f = theano.function([x], z, mode=self.mode)
assert numpy.all([not isinstance(x.op, tensor.AdvancedIncSubtensor1) assert numpy.all([not isinstance(n.op, tensor.AdvancedIncSubtensor1)
for x in f.maker.fgraph.toposort()]) for n in f.maker.fgraph.toposort()])
def test_advancedincsubtensor_allocs0(self): def test_advancedincsubtensor_allocs0(self):
if tensor.inplace_increment is None: if tensor.inplace_increment is None:
...@@ -2605,8 +2607,8 @@ class Test_alloc_zero(unittest.TestCase): ...@@ -2605,8 +2607,8 @@ class Test_alloc_zero(unittest.TestCase):
y0 = tensor.zeros_like(y) y0 = tensor.zeros_like(y)
z = tensor.inc_subtensor(x[[[0, 0], [1, 1]], [[0, 1], [0, 1]]], y0) z = tensor.inc_subtensor(x[[[0, 0], [1, 1]], [[0, 1], [0, 1]]], y0)
f = theano.function([x, y], z, mode=self.mode) f = theano.function([x, y], z, mode=self.mode)
assert numpy.all([not isinstance(x.op, tensor.AdvancedIncSubtensor) assert numpy.all([not isinstance(n.op, tensor.AdvancedIncSubtensor)
for x in f.maker.fgraph.toposort()]) for n in f.maker.fgraph.toposort()])
def test_advancedincsubtensor_allocs0t(self): def test_advancedincsubtensor_allocs0t(self):
if tensor.inplace_increment is None: if tensor.inplace_increment is None:
...@@ -2617,8 +2619,8 @@ class Test_alloc_zero(unittest.TestCase): ...@@ -2617,8 +2619,8 @@ class Test_alloc_zero(unittest.TestCase):
y0 = tensor.zeros_like(y) y0 = tensor.zeros_like(y)
z = tensor.inc_subtensor(x[[[0, 0], [1, 1]], [[0, 1], [0, 1]]], y0.T) z = tensor.inc_subtensor(x[[[0, 0], [1, 1]], [[0, 1], [0, 1]]], y0.T)
f = theano.function([x, y], z, mode=mode_opt) f = theano.function([x, y], z, mode=mode_opt)
assert numpy.all([not isinstance(x.op, tensor.AdvancedIncSubtensor) assert numpy.all([not isinstance(n.op, tensor.AdvancedIncSubtensor)
for x in f.maker.fgraph.toposort()]) for n in f.maker.fgraph.toposort()])
def test_advancedincsubtensor_allocs1(self): def test_advancedincsubtensor_allocs1(self):
if tensor.inplace_increment is None: if tensor.inplace_increment is None:
...@@ -2629,8 +2631,8 @@ class Test_alloc_zero(unittest.TestCase): ...@@ -2629,8 +2631,8 @@ class Test_alloc_zero(unittest.TestCase):
dtype=config.floatX)) dtype=config.floatX))
z = tensor.inc_subtensor(x[[[0, 0], [1, 1]], [[0, 1], [0, 1]]], y0) z = tensor.inc_subtensor(x[[[0, 0], [1, 1]], [[0, 1], [0, 1]]], y0)
f = theano.function([x], z, mode=self.mode) f = theano.function([x], z, mode=self.mode)
assert numpy.all([not isinstance(x.op, tensor.AdvancedIncSubtensor) assert numpy.all([not isinstance(n.op, tensor.AdvancedIncSubtensor)
for x in f.maker.fgraph.toposort()]) for n in f.maker.fgraph.toposort()])
def test_dot_allocs_0(self): def test_dot_allocs_0(self):
v1 = tensor.vector('v1') v1 = tensor.vector('v1')
...@@ -2656,7 +2658,7 @@ class Test_alloc_zero(unittest.TestCase): ...@@ -2656,7 +2658,7 @@ class Test_alloc_zero(unittest.TestCase):
f = theano.function([_e1[0], _e2[0]], o, mode=self.mode) f = theano.function([_e1[0], _e2[0]], o, mode=self.mode)
f(_e1[1], _e2[1]) f(_e1[1], _e2[1])
f(_e1[2], _e2[2]) f(_e1[2], _e2[2])
assert numpy.all([not isinstance(x.op, tensor.Dot) for x in assert numpy.all([not isinstance(n.op, tensor.Dot) for n in
f.maker.fgraph.toposort()]) f.maker.fgraph.toposort()])
#test that we don't remove shape errors #test that we don't remove shape errors
...@@ -3305,6 +3307,10 @@ class test_assert(utt.InferShapeTester): ...@@ -3305,6 +3307,10 @@ class test_assert(utt.InferShapeTester):
y = T.scalar() y = T.scalar()
f = theano.function([x, y], theano.tensor.opt.assert_op(x, y), f = theano.function([x, y], theano.tensor.opt.assert_op(x, y),
mode=mode) mode=mode)
if isinstance(mode, theano.compile.debugmode.DebugMode):
# DebugMode will run the original version with the Assert
self.assertRaises(AssertionError, f, 1, 0)
else:
f(1, 0) # Without opt, it should fail. f(1, 0) # Without opt, it should fail.
topo = f.maker.fgraph.toposort() topo = f.maker.fgraph.toposort()
assert len(topo) == 1, topo assert len(topo) == 1, topo
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论