code: def _psd_mask(x):
      """Computes whether each square matrix in the input is positive semi-definite.
  
      Args:
        x: A floating-point `Tensor` of shape `[B1, ..., Bn, M, M]`.
  
      Returns:
        mask: A floating-point `Tensor` of shape `[B1, ... Bn]`.  Each
          scalar is 1 if the corresponding matrix was PSD, otherwise 0.
      """
      # Allegedly
      # https://scicomp.stackexchange.com/questions/12979/testing-if-a-matrix-is-positive-semi-definite
      # it is more efficient to test for positive semi-definiteness by
      # trying to compute the Cholesky decomposition -- the matrix is PSD
      # if you succeed and not PSD if you fail.  However, TensorFlow's
      # Cholesky raises an exception if _any_ of the input matrices are
      # not PSD, from which I don't know how to extract _which ones_, so I
      # proceed by explicitly computing all the eigenvalues and checking
      # whether they are all positive or not.
      #
      # Also, as was discussed in the answer, it is somewhat dangerous to
      # treat SPD-ness as binary in floating-point arithmetic. Cholesky
      # factorization can complete and 'look' like everything is fine
      # (e.g., O(1) entries and a diagonal of all ones) but the matrix can
      # have an exponential condition number.
      eigenvalues, _ = tf.linalg.eigh(x)
      return tf.cast(
          tf.reduce_min(eigenvalues, axis=-1) >= 0, dtype=x.dtype
      )
  
file_path: probability/tensorflow_probability/python/distributions/internal/correlation_matrix_volumes_lib.py
imports: import sys
  import numpy
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import uniform
  from tensorflow_probability.python.internal import empirical_statistical_testing
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.math.linalg import fill_triangular
label_desc: Use image node_id 1 for calling a global function with example usage: _psd_mask(x) and returns: tf