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

Modify test_fill_diagonal_offset.py to cover every possible case

上级 ba683cc7
...@@ -480,10 +480,9 @@ class TestFillDiagonalOffset(utt.InferShapeTester): ...@@ -480,10 +480,9 @@ class TestFillDiagonalOffset(utt.InferShapeTester):
y = tensor.scalar() y = tensor.scalar()
z = tensor.iscalar() z = tensor.iscalar()
test_offset = numpy.random.randint(-5,5)
f = function([x, y, z], fill_diagonal_offset(x, y, z)) f = function([x, y, z], fill_diagonal_offset(x, y, z))
for shp in [(8, 8), (5, 8), (8, 5)]: for test_offset in (-5, -4, -1, 0, 1, 4, 5):
for shp in [(8, 8), (5, 8), (8, 5), (5, 5)]:
a = numpy.random.rand(*shp).astype(config.floatX) a = numpy.random.rand(*shp).astype(config.floatX)
val = numpy.cast[config.floatX](numpy.random.rand()) val = numpy.cast[config.floatX](numpy.random.rand())
out = f(a, val, test_offset) out = f(a, val, test_offset)
...@@ -497,7 +496,7 @@ class TestFillDiagonalOffset(utt.InferShapeTester): ...@@ -497,7 +496,7 @@ class TestFillDiagonalOffset(utt.InferShapeTester):
a.shape[0]+test_offset ) a.shape[0]+test_offset )
def test_gradient(self): def test_gradient(self):
test_offset = numpy.random.randint(-5,5) for test_offset in (-5, -4, -1, 0, 1, 4, 5):
# input 'offset' will not be tested # input 'offset' will not be tested
def fill_diagonal_with_fix_offset( a, val): def fill_diagonal_with_fix_offset( a, val):
return fill_diagonal_offset( a, val, test_offset) return fill_diagonal_offset( a, val, test_offset)
...@@ -508,13 +507,23 @@ class TestFillDiagonalOffset(utt.InferShapeTester): ...@@ -508,13 +507,23 @@ class TestFillDiagonalOffset(utt.InferShapeTester):
utt.verify_grad(fill_diagonal_with_fix_offset, utt.verify_grad(fill_diagonal_with_fix_offset,
[numpy.random.rand(8, 5), numpy.random.rand()], [numpy.random.rand(8, 5), numpy.random.rand()],
n_tests=1, rng=TestFillDiagonalOffset.rng) n_tests=1, rng=TestFillDiagonalOffset.rng)
utt.verify_grad(fill_diagonal_with_fix_offset,
[numpy.random.rand(5, 5), numpy.random.rand()],
n_tests=1, rng=TestFillDiagonalOffset.rng)
def test_infer_shape(self): def test_infer_shape(self):
x = tensor.dmatrix() x = tensor.dmatrix()
y = tensor.dscalar() y = tensor.dscalar()
z = tensor.iscalar() z = tensor.iscalar()
for test_offset in (-5, -4, -1, 0, 1, 4, 5):
self._compile_and_check([x, y, z], [self.op(x, y, z)], self._compile_and_check([x, y, z], [self.op(x, y, z)],
[numpy.random.rand(8, 5), [numpy.random.rand(8, 5),
numpy.random.rand(), numpy.random.rand(),
numpy.random.randint(-5,5)], test_offset],
self.op_class ) self.op_class )
self._compile_and_check([x, y, z], [self.op(x, y, z)],
[numpy.random.rand(5, 8),
numpy.random.rand(),
test_offset],
self.op_class )
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论