提交 d4b8841d authored 作者: ChienliMa's avatar ChienliMa

Delete extra value;Modift test case to avoid uduplicate code;Expexted error not raised.

上级 3626d6d5
...@@ -2104,9 +2104,11 @@ class Test_getitem(unittest.TestCase): ...@@ -2104,9 +2104,11 @@ class Test_getitem(unittest.TestCase):
verify_grad_sparse(op_with_fixed_index, x_val) verify_grad_sparse(op_with_fixed_index, x_val)
def test_GetItem2D(self): def test_GetItem2D(self):
sparse_formats = ('csc', 'csr')
scipy_ver = [int(n) for n in scipy.__version__.split('.')[:2]] scipy_ver = [int(n) for n in scipy.__version__.split('.')[:2]]
assert scipy_ver >= [0, 11]
is_supported_version = bool(scipy_ver >= [0, 14]) is_supported_version = bool(scipy_ver >= [0, 14])
sparse_formats = ('csc', 'csr')
for format in sparse_formats: for format in sparse_formats:
x = theano.sparse.matrix(format, name='x') x = theano.sparse.matrix(format, name='x')
a = theano.tensor.iscalar('a') a = theano.tensor.iscalar('a')
...@@ -2121,13 +2123,16 @@ class Test_getitem(unittest.TestCase): ...@@ -2121,13 +2123,16 @@ class Test_getitem(unittest.TestCase):
n = 5 n = 5
p = 10 p = 10
q = 15 q = 15
if is_supported_version:
j = 2 j = 2
k = 3 k = 3
else:
j = None
k = None
vx = as_sparse_format(self.rng.binomial(1, 0.5, (100, 97)), vx = as_sparse_format(self.rng.binomial(1, 0.5, (100, 97)),
format).astype(theano.config.floatX) format).astype(theano.config.floatX)
if is_supported_version:
#mode_no_debug = theano.compile.mode.get_default_mode() #mode_no_debug = theano.compile.mode.get_default_mode()
#if isinstance(mode_no_debug, theano.compile.DebugMode): #if isinstance(mode_no_debug, theano.compile.DebugMode):
# mode_no_debug = 'FAST_RUN' # mode_no_debug = 'FAST_RUN'
...@@ -2174,12 +2179,12 @@ class Test_getitem(unittest.TestCase): ...@@ -2174,12 +2179,12 @@ class Test_getitem(unittest.TestCase):
t4 = vx[m:n:j] t4 = vx[m:n:j]
assert r4.shape == t4.shape assert r4.shape == t4.shape
assert numpy.all(t4.toarray() == r4.toarray()) assert numpy.all(t4.toarray() == r4.toarray())
#----------------------------------------------------------- #-----------------------------------------------------------
# test cases using int indexing instead of theano variable # test cases using int indexing instead of theano variable
f6 = theano.function([x], x[1:10:j, 10:20:k])
f6 = theano.function([x], x[1:10:1, 10:20:2])
r6 = f6(vx) r6 = f6(vx)
t6 = vx[1:10:1, 10:20:2] t6 = vx[1:10:j, 10:20:k]
assert r6.shape == t6.shape assert r6.shape == t6.shape
assert numpy.all(r6.toarray() == t6.toarray()) assert numpy.all(r6.toarray() == t6.toarray())
...@@ -2191,43 +2196,9 @@ class Test_getitem(unittest.TestCase): ...@@ -2191,43 +2196,9 @@ class Test_getitem(unittest.TestCase):
assert r8.shape == t8.shape assert r8.shape == t8.shape
assert numpy.all(r8.toarray() == t8.toarray()) assert numpy.all(r8.toarray() == t8.toarray())
f9 = theano.function([x, a, b], x[1:a:2, 1:b:2]) f9 = theano.function([x, a, b], x[1:a:j, 1:b:k])
r9 = f9(vx, p, q)
t9 = vx[1:p:2, 1:q:2]
assert r9.shape == t9.shape
assert numpy.all(r9.toarray() == t9.toarray())
else:
f1 = theano.function([x, a, b, c, d], x[a:b, c:d])
r1 = f1(vx, m, n, p, q)
t1 = vx[m:n, p:q]
assert r1.shape == t1.shape
assert numpy.all(t1.toarray() == r1.toarray())
f4 = theano.function([x, a, b], x[a:b])
r4 = f4(vx, m, n)
t4 = vx[m:n]
assert r4.shape == t4.shape
assert numpy.all(t4.toarray() == r4.toarray())
#-----------------------------------------------------------
# test cases using int indexing instead of theano variable
f6 = theano.function([x], x[1:10, 10:20])
r6 = f6(vx)
t6 = vx[1:10, 10:20]
assert r6.shape == t6.shape
assert numpy.all(r6.toarray() == t6.toarray())
#----------------------------------------------------------
# test cases with indexing both with theano variable and int
f8 = theano.function([x, a, b, e], x[a:b, 10:20])
r8 = f8(vx, m, n)
t8 = vx[m:n, 10:20]
assert r8.shape == t8.shape
assert numpy.all(r8.toarray() == t8.toarray())
f9 = theano.function([x, a, b], x[a:, b:])
r9 = f9(vx, p, q) r9 = f9(vx, p, q)
t9 = vx[p:, q:] t9 = vx[1:p:j, 1:q:k]
assert r9.shape == t9.shape assert r9.shape == t9.shape
assert numpy.all(r9.toarray() == t9.toarray()) assert numpy.all(r9.toarray() == t9.toarray())
...@@ -2269,7 +2240,7 @@ class Test_getitem(unittest.TestCase): ...@@ -2269,7 +2240,7 @@ class Test_getitem(unittest.TestCase):
self.assertRaises(ValueError, self.assertRaises(ValueError,
x.__getitem__, (slice(a, b), slice(c, d, 2))) x.__getitem__, (slice(a, b), slice(c, d, 2)))
else: else:
raise SkipTest("Slicing with step needs newer release of scipy") raise SkipTest("Slicing with step is supported.")
# Advanced indexing is not supported # Advanced indexing is not supported
self.assertRaises(ValueError, self.assertRaises(ValueError,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论