提交 568ba109 authored 作者: Amjad Almahairi's avatar Amjad Almahairi

adding infer_shape test for MatrixInverse Op

上级 36a6ef33
......@@ -61,23 +61,39 @@ def test_pseudoinverse_correctness():
assert _allclose(ri, numpy.linalg.pinv(r))
def test_inverse_correctness():
rng = numpy.random.RandomState(utt.fetch_seed())
class test_MatrixInverse(utt.InferShapeTester):
def setUp(self):
super(test_MatrixInverse, self).setUp()
self.op_class = MatrixInverse
self.op = matrix_inverse
self.rng = numpy.random.RandomState(utt.fetch_seed())
r = rng.randn(4, 4).astype(theano.config.floatX)
def test_inverse_correctness(self):
x = tensor.matrix()
xi = matrix_inverse(x)
r = self.rng.randn(4, 4).astype(theano.config.floatX)
ri = function([x], xi)(r)
assert ri.shape == r.shape
assert ri.dtype == r.dtype
x = tensor.matrix()
xi = self.op(x)
ri = function([x], xi)(r)
assert ri.shape == r.shape
assert ri.dtype == r.dtype
rir = numpy.dot(ri, r)
rri = numpy.dot(r, ri)
assert _allclose(numpy.identity(4), rir), rir
assert _allclose(numpy.identity(4), rri), rri
def test_infer_shape(self):
r = self.rng.randn(4, 4).astype(theano.config.floatX)
rir = numpy.dot(ri, r)
rri = numpy.dot(r, ri)
x = tensor.matrix()
xi = self.op(x)
assert _allclose(numpy.identity(4), rir), rir
assert _allclose(numpy.identity(4), rri), rri
self._compile_and_check([x], [xi], [r],
self.op_class, warn=False)
def test_matrix_dot():
......@@ -490,4 +506,4 @@ class T_NormTests(unittest.TestCase):
f = function([A[1][i]], norm(A[1][i], A[0][i]))
t_n = f(A[2][i])
n_n = numpy.linalg.norm(A[2][i], A[3][i])
assert _allclose(n_n, t_n)
\ No newline at end of file
assert _allclose(n_n, t_n)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论