def testCorrectlyMakesNoBatchLowerTril(self):
   with self.test_session():
     x = tf.convert_to_tensor(self._rng.randn(10))
     expected = self._fill_lower_triangular(tensor_util.constant_value(x))
     actual = distribution_util.fill_lower_triangular(x, validate_args=True)
     self.assertAllEqual(expected.shape, actual.get_shape())
     self.assertAllEqual(expected, actual.eval())
     g = tf.gradients(distribution_util.fill_lower_triangular(x), x)
     self.assertAllEqual(np.tri(4).reshape(-1), g[0].values.eval())
 def testCorrectlyMakesNoBatchLowerTril(self):
   with self.test_session():
     x = tf.convert_to_tensor(self._rng.randn(10))
     expected = self._fill_lower_triangular(tensor_util.constant_value(x))
     actual = distribution_util.fill_lower_triangular(x, validate_args=True)
     self.assertAllEqual(expected.shape, actual.get_shape())
     self.assertAllEqual(expected, actual.eval())
     g = tf.gradients(distribution_util.fill_lower_triangular(x), x)
     self.assertAllEqual(np.tri(4).reshape(-1), g[0].values.eval())
 def testCorrectlyMakesBatchLowerTril(self):
   with self.test_session():
     x = ops.convert_to_tensor(self._rng.randn(2, 2, 6))
     expected = self._fill_lower_triangular(tensor_util.constant_value(x))
     actual = distribution_util.fill_lower_triangular(x, validate_args=True)
     self.assertAllEqual(expected.shape, actual.get_shape())
     self.assertAllEqual(expected, actual.eval())
     self.assertAllEqual(
         np.ones((2, 2, 6)),
         gradients_impl.gradients(
             distribution_util.fill_lower_triangular(x), x)[0].eval())
 def testCorrectlyMakesBatchLowerTril(self):
     with self.test_session():
         x = ops.convert_to_tensor(self._rng.randn(2, 2, 6))
         expected = self._fill_lower_triangular(
             tensor_util.constant_value(x))
         actual = distribution_util.fill_lower_triangular(
             x, validate_args=True)
         self.assertAllEqual(expected.shape, actual.get_shape())
         self.assertAllEqual(expected, actual.eval())
         self.assertAllEqual(
             np.ones((2, 2, 6)),
             gradients_impl.gradients(
                 distribution_util.fill_lower_triangular(x), x)[0].eval())
Example #5
0
 def testCorrectlyMakesNoBatchLowerTril(self):
     with self.test_session():
         x = tf.convert_to_tensor(np.arange(9, dtype=np.float32))
         expected = np.array([[0., 0., 0.], [1., 2., 0.], [3., 4., 5.]])
         actual = distribution_util.fill_lower_triangular(x)
         self.assertAllEqual(expected.shape, actual.get_shape())
         self.assertAllEqual(expected, actual.eval())
         self.assertAllEqual(
             np.concatenate([
                 np.ones(6, dtype=np.float32),
                 np.zeros(3, dtype=np.float32)
             ]),
             tf.gradients(distribution_util.fill_lower_triangular(x),
                          x)[0].eval())
Example #6
0
 def testCorrectlyMakesNoBatchLowerTril(self):
   with self.test_session():
     x = tf.convert_to_tensor(np.arange(9, dtype=np.float32))
     expected = np.array(
         [[0., 0., 0.],
          [1., 2., 0.],
          [3., 4., 5.]])
     actual = distribution_util.fill_lower_triangular(x)
     self.assertAllEqual(expected.shape, actual.get_shape())
     self.assertAllEqual(expected, actual.eval())
     self.assertAllEqual(
         np.concatenate([np.ones(6, dtype=np.float32),
                         np.zeros(3, dtype=np.float32)]),
         tf.gradients(distribution_util.fill_lower_triangular(x), x)[0].eval())
 def testCorrectlyMakes1x1LowerTril(self):
   with self.test_session():
     x = ops.convert_to_tensor(self._rng.randn(3, 1))
     expected = self._fill_lower_triangular(tensor_util.constant_value(x))
     actual = distribution_util.fill_lower_triangular(x, validate_args=True)
     self.assertAllEqual(expected.shape, actual.get_shape())
     self.assertAllEqual(expected, actual.eval())
Example #8
0
 def testCorrectlyMakes1x1LowerTril(self):
     with self.test_session():
         x = np.array([[1.], [2], [3]])
         expected = np.array([[[1.]], [[2]], [[3]]])
         actual = distribution_util.fill_lower_triangular(x)
         self.assertAllEqual(expected.shape, actual.get_shape())
         self.assertAllEqual(expected, actual.eval())
Example #9
0
 def testCorrectlyMakes1x1LowerTril(self):
   with self.test_session():
     x = np.array([[1.], [2], [3]])
     expected = np.array([[[1.]], [[2]], [[3]]])
     actual = distribution_util.fill_lower_triangular(x)
     self.assertAllEqual(expected.shape, actual.get_shape())
     self.assertAllEqual(expected, actual.eval())
 def testCorrectlyMakesNoBatchLowerTril(self):
     with self.test_session():
         x = np.arange(9)
         expected = np.array([[0., 0., 0.], [1., 2., 0.], [3., 4., 5.]])
         actual = distribution_util.fill_lower_triangular(x)
         self.assertAllEqual(expected.shape, actual.get_shape())
         self.assertAllEqual(expected, actual.eval())
 def testCorrectlyMakes1x1LowerTril(self):
   with self.test_session():
     x = tf.convert_to_tensor(self._rng.randn(3, 1))
     expected = self._fill_lower_triangular(tensor_util.constant_value(x))
     actual = distribution_util.fill_lower_triangular(x, validate_args=True)
     self.assertAllEqual(expected.shape, actual.get_shape())
     self.assertAllEqual(expected, actual.eval())
 def testCorrectlyMakesNoBatchLowerTril(self):
   with self.test_session():
     x = np.arange(9)
     expected = np.array(
         [[0., 0., 0.],
          [1., 2., 0.],
          [3., 4., 5.]])
     actual = distribution_util.fill_lower_triangular(x)
     self.assertAllEqual(expected.shape, actual.get_shape())
     self.assertAllEqual(expected, actual.eval())
Example #13
0
 def testCorrectlyMakesBatchLowerTril(self):
     with self.test_session():
         x = np.reshape(np.arange(24), (2, 2, 6))
         expected = np.array([[[[0., 0., 0.], [1., 2., 0.], [3., 4., 5.]],
                               [[6., 0., 0.], [7., 8., 0.], [9., 10.,
                                                             11.]]],
                              [[[12., 0., 0.], [13., 14., 0.],
                                [15., 16., 17.]],
                               [[18., 0., 0.], [19., 20., 0.],
                                [21., 22., 23.]]]])
         actual = distribution_util.fill_lower_triangular(x)
         self.assertAllEqual(expected.shape, actual.get_shape())
         self.assertAllEqual(expected, actual.eval())
Example #14
0
 def testCorrectlyMakesBatchLowerTril(self):
   with self.test_session():
     x = np.reshape(np.arange(24), (2, 2, 6))
     expected = np.array(
         [[[[0., 0., 0.],
            [1., 2., 0.],
            [3., 4., 5.]],
           [[6., 0., 0.],
            [7., 8., 0.],
            [9., 10., 11.]]],
          [[[12., 0., 0.],
            [13., 14., 0.],
            [15., 16., 17.]],
           [[18., 0., 0.],
            [19., 20., 0.],
            [21., 22., 23.]]]])
     actual = distribution_util.fill_lower_triangular(x)
     self.assertAllEqual(expected.shape, actual.get_shape())
     self.assertAllEqual(expected, actual.eval())