class_docstr: Test GeneralSpace works on a Symmetric Matrix.
class_docstr_tok: ["Test","GeneralSpace","works","on","a","Symmetric","Matrix","."]
code: def testTransformGeneralTransformDiagonal(self):
      tangent_basis = np.array(
          [
              [[1.0, 0.0], [0.0, 0.0]],
              [[0.0, 1.0], [1.0, 0.0]],
              [[0.0, 0.0], [0.0, 1.0]],
          ]
      ).astype(np.float32)
      x = np.array(
          [
              [[3.0, 4.0], [4.0, 3.0]],
              [[1.0, 0.0], [0.0, 1.0]],
              [[4.0, 2.0], [2.0, 3.0]],
              [[-1.0, 2.0], [2.0, 1.0]],
          ]
      ).astype(np.float32)
  
      bijector = transform_diagonal.TransformDiagonal(exp.Exp())
      gs = spaces.GeneralSpace(spaces.DenseBasis(tangent_basis))
      correction, new_gs = gs.transform_general(x, bijector)
  
      # Test that we get a correction only from the diagonal elements.
      diag_x = np.diagonal(x, axis1=-2, axis2=-1)
      self.assertAllClose(
          self.evaluate(correction), np.sum(diag_x, axis=-1)
      )
      # Test that the new basis retains the middle element. This is because the
      # bijector only modifies the diagonal elements.
      new_basis = self.evaluate(new_gs.basis.to_dense())
      middle_element = np.array([[0.0, 1.0], [1.0, 0.0]]).astype(
          np.float32
      )
      middle_element = np.broadcast_to(middle_element, [4, 2, 2])
      self.assertAllClose(new_basis[1], middle_element)
      # Test the new basis is correct.
      expected_bases_elems = np.exp(np.eye(2) * x)
      expected_elem_0 = expected_bases_elems * np.array(
          [[1.0, 0.0], [0.0, 0]]
      ).astype(np.float32)
      expected_elem_2 = expected_bases_elems * np.array(
          [[0.0, 0.0], [0.0, 1]]
      ).astype(np.float32)
      self.assertAllClose(new_basis[0], expected_elem_0)
      self.assertAllClose(new_basis[2], expected_elem_2)
  
      # Finally check that the log_volume
      reshaped_new_basis = np.transpose(
          new_basis.reshape([3, 4, -1]), [1, 0, 2]
      )
      expected_log_volume = (
          0.5
          * np.linalg.slogdet(
              np.matmul(
                  reshaped_new_basis,
                  np.transpose(reshaped_new_basis, axes=[0, 2, 1]),
              )
          )[1]
      )
      self.assertAllClose(
          self.evaluate(new_gs.computed_log_volume), expected_log_volume
      )
  
imports: from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import exp
  from tensorflow_probability.python.bijectors import reshape
  from tensorflow_probability.python.bijectors import scale
  from tensorflow_probability.python.bijectors import scale_matvec_tril
  from tensorflow_probability.python.bijectors import transform_diagonal
  from tensorflow_probability.python.experimental.tangent_spaces import spaces
  from tensorflow_probability.python.experimental.tangent_spaces import spaces_test_util
  from tensorflow_probability.python.internal import test_util
label_desc: Use image node_id 8 for calling the GeneralSpaceSymmetricMatrixTest obj's underlying member method code with example usage: obj.testTransformGeneralTransformDiagonal() without return types