more tests for lowerTriangular transofrms
@@ -219,6 +219,28 @@ class TestMatrixTransforms(GPflowTestCase):
assert_allclose(M_free, M_free_tf)
assert_allclose(M, session.run(t.forward_tensor(tf.identity(M_free_tf))))
+ def test_LowerTriangular_squeezes(self):
+ t1 = gpflow.transforms.LowerTriangular(N=3, num_matrices=1)
+ t2 = gpflow.transforms.LowerTriangular(N=3, num_matrices=1, squeeze=True)
+ X = np.random.randn(1, 6)
+
+ self.assertTrue(np.all(t1.forward(X).squeeze() == t2.forward(X)))
+
+ with self.test_context() as session:
+ self.assertTrue(np.all(session.run(tf.squeeze(t1.forward_tensor(X))) ==
+ session.run(t2.forward_tensor(X))))
+
+ Y = np.random.randn(1, 3, 3)
+ self.assertTrue(np.all(session.run(t1.backward_tensor(Y)) ==
+ session.run(t2.backward_tensor(Y.squeeze()))))
+
+ # make sure we don't try to squeeze when there are more than 1 matrices.
+ with self.assertRaises(ValueError):
+ gpflow.transforms.LowerTriangular(N=3, num_matrices=2, squeeze=True)
+
+
+
+
def test_DiagMatrix(self):
t = gpflow.transforms.DiagMatrix(3)
t.backward(np.eye(3))
