class_docstr: Tangent space of M the space of `n x n` symmetric matrices.
class_docstr_tok: ["Tangent","space","of","M","the","space","of","`","n","x","n","`","symmetric","matrices","."]
docstr: Compute basis of symmetric matrices.
docstr_tok: ["Compute","basis","of","symmetric","matrices","."]
code: def compute_basis(self, x):
      """Compute basis of symmetric matrices."""
      # For each diagonal element, we have a basis element with one in that
      # position, while for off-diagonal elements we have 1 / sqrt(2) and the
      # corresponding symmetric element.
      # For example, in the case of 2x2 matrices:
      # [[1., 0.]     [[0, 1/sqrt(2)]     [[0., 0.]
      #  [0., 0.]]     [1/sqrt(2), 0.]]    [0., 1.]]
      dim = ps.shape(x)[-1]
      n = tf.cast(dim * (dim + 1) / 2, dtype=np.int32)
      basis_tensor = tf.eye(n, dtype=x.dtype)
      basis_tensor = linalg.fill_triangular(basis_tensor)
      sqrt_2 = dtype_util.as_numpy_dtype(x.dtype)(np.sqrt(2.0))
      basis_tensor = (
          basis_tensor + tf.linalg.matrix_transpose(basis_tensor)
      ) / sqrt_2
      basis_tensor = tf.linalg.set_diag(
          basis_tensor, tf.linalg.diag_part(basis_tensor) / sqrt_2
      )
      return spaces.DenseBasis(basis_tensor)
  
file_path: probability/tensorflow_probability/python/experimental/tangent_spaces/symmetric_matrix.py
imports: import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.experimental.tangent_spaces import spaces
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.math import linalg
label_desc: Use image node_id 1 for calling the SymmetricMatrixSpace obj's underlying member method code with example usage: obj.compute_basis(x) and returns: spaces