提交 e22a820e authored 作者: Frederic's avatar Frederic

test refactoring to remove duplicate code.

上级 d86ea664
...@@ -39,96 +39,57 @@ def test_neibs(): ...@@ -39,96 +39,57 @@ def test_neibs():
def test_neibs_bad_shape(): def test_neibs_bad_shape():
shape = (2, 3, 10, 10) shape = (2, 3, 10, 10)
images = shared(numpy.arange(numpy.prod(shape)).reshape(shape)) images = shared(numpy.arange(numpy.prod(shape)).reshape(shape))
neib_shape = T.as_tensor_variable((3, 2))
try: for neib_shape in [(3, 2), (2, 3)]:
f = function([], images2neibs(images, neib_shape), neib_shape = T.as_tensor_variable(neib_shape)
mode=mode_without_gpu)
neibs = f()
#print neibs
assert False, "An error was expected"
except TypeError:
pass
shape = (2, 3, 10, 10)
images = shared(numpy.arange(numpy.prod(shape)).reshape(shape))
neib_shape = T.as_tensor_variable((2, 3))
try: try:
f = function([], images2neibs(images, neib_shape), f = function([], images2neibs(images, neib_shape),
mode=mode_without_gpu) mode=mode_without_gpu)
neibs = f() f()
#print neibs assert False, "An error was expected"
assert False, "An error was expected" except TypeError:
except TypeError: pass
pass
def test_neibs_bad_shape_warp_centered(): def test_neibs_bad_shape_warp_centered():
shape = (2, 3, 10, 10) shape = (2, 3, 10, 10)
images = shared(numpy.arange(numpy.prod(shape)).reshape(shape)) images = shared(numpy.arange(numpy.prod(shape)).reshape(shape))
neib_shape = T.as_tensor_variable((3, 2))
try: for neib_shape in [(3, 2), (2, 3)]:
f = function([], images2neibs(images, neib_shape, neib_shape = T.as_tensor_variable(neib_shape)
mode="wrap_centered"),
mode=mode_without_gpu)
neibs = f()
#print neibs
assert False, "An error was expected"
except TypeError:
pass
shape = (2, 3, 10, 10)
images = shared(numpy.arange(numpy.prod(shape)).reshape(shape))
neib_shape = T.as_tensor_variable((2, 3))
try: try:
f = function([], images2neibs(images, neib_shape, f = function([], images2neibs(images, neib_shape,
mode="wrap_centered"), mode="wrap_centered"),
mode=mode_without_gpu) mode=mode_without_gpu)
neibs = f() f()
#print neibs assert False, "An error was expected"
assert False, "An error was expected" except TypeError:
except TypeError: pass
pass
shape = (2, 3, 2, 3) shape = (2, 3, 2, 3)
images = shared(numpy.arange(numpy.prod(shape)).reshape(shape)) images = shared(numpy.arange(numpy.prod(shape)).reshape(shape))
neib_shape = T.as_tensor_variable((3, 3)) neib_shape = T.as_tensor_variable((3, 3))
try: for shape in [(2, 3, 2, 3), (2, 3, 3, 2)]:
f = function([], images2neibs(images, neib_shape, try:
mode="wrap_centered"), f = function([], images2neibs(images, neib_shape,
mode=mode_without_gpu) mode="wrap_centered"),
neibs = f() mode=mode_without_gpu)
#print neibs f()
assert False, "An error was expected" assert False, "An error was expected"
except TypeError: except TypeError:
pass pass
shape = (2, 3, 3, 2)
images = shared(numpy.arange(numpy.prod(shape)).reshape(shape))
neib_shape = T.as_tensor_variable((3, 3))
try:
f = function([], images2neibs(images, neib_shape,
mode="wrap_centered"),
mode=mode_without_gpu)
neibs = f()
#print neibs
assert False, "An error was expected"
except TypeError, e:
pass
# Test a valid shapes
shape = (2, 3, 3, 3) shape = (2, 3, 3, 3)
images = shared(numpy.arange(numpy.prod(shape)).reshape(shape)) images = shared(numpy.arange(numpy.prod(shape)).reshape(shape))
neib_shape = T.as_tensor_variable((3, 3)) neib_shape = T.as_tensor_variable((3, 3))
f = function([], images2neibs(images, neib_shape, mode="wrap_centered"), f = function([], images2neibs(images, neib_shape, mode="wrap_centered"),
mode=mode_without_gpu) mode=mode_without_gpu)
neibs = f() f()
#print neibs
def test_neibs_manual(): def test_neibs_manual():
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论