提交 6aedf054 authored 作者: Eric Larsen's avatar Eric Larsen 提交者: Frederic Bastien

testing infer_shape: op CAReduce

上级 d3705773
...@@ -202,9 +202,7 @@ class test_Broadcast(unittest.TestCase): ...@@ -202,9 +202,7 @@ class test_Broadcast(unittest.TestCase):
assert (f(xv) == zv).all() assert (f(xv) == zv).all()
class test_CAReduce(unittest.TestCase): class test_CAReduce(unittest_tools.InferShapeTester):
def setUp(self):
unittest_tools.seed_rng()
def with_linker(self, linker, scalar_op=scalar.add, dtype="floatX", def with_linker(self, linker, scalar_op=scalar.add, dtype="floatX",
test_nan=False, tensor_op=None): test_nan=False, tensor_op=None):
...@@ -411,6 +409,29 @@ class test_CAReduce(unittest.TestCase): ...@@ -411,6 +409,29 @@ class test_CAReduce(unittest.TestCase):
self.with_linker(gof.CLinker(), scalar.maximum, dtype=dtype, self.with_linker(gof.CLinker(), scalar.maximum, dtype=dtype,
test_nan=True) test_nan=True)
def test_infer_shape(self):
# Note: will fail upon submission of following (xsh, tosum) tuples:
# ((5, 6), ()), ((5, 0), ()), ((), None), ((), ())]:
for xsh, tosum in [((5, 6), None),
((5, 6), (0, 1)),
((5, 6), (0, )),
((5, 6), (1, )),
((5, 6), (-1, )),
((5, 6), (-2, )),
((2, 3, 4, 5), (0, 1, 3)),
((2, 3, 4, 5), (-2, -3)),
((5, 0), None),
((5, 0), (0, )),
((5, 0), (1, ))]:
dtype = theano.config.floatX
x = TensorType(dtype, [(entry == 1) for entry in xsh])('x')
if tosum is None:
tosum = range(len(xsh))
xv = numpy.asarray(numpy.random.rand(*xsh))
self._compile_and_check([x],
[CAReduce(add, axis=tosum)(x)],
[xv], CAReduce)
class test_Prod(unittest.TestCase): class test_Prod(unittest.TestCase):
def setUp(self): def setUp(self):
...@@ -776,7 +797,7 @@ if __name__ == '__main__': ...@@ -776,7 +797,7 @@ if __name__ == '__main__':
if __name__ == '__main__': if __name__ == '__main__':
t = test_DimShuffle('setUp') t = test_CAReduce('setUp')
t.setUp() t.setUp()
t.test_infer_shape() t.test_infer_shape()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论