code: def test_log_prob_and_sample(
      self,
      use_loc,
      use_precision,
      event_size,
      batch_shape,
      dtype,
      n_samples,
  ):
      cov = self._random_constant_spd_linop(
          event_size, batch_shape=batch_shape, dtype=dtype
      )
      precision = cov.inverse()
      precision_factor = precision.cholesky()
  
      # Make sure to evaluate here, else you'll have a random loc vector!
      if use_loc:
          loc = self.evaluate(
              tf.random.normal(
                  batch_shape + (event_size,),
                  dtype=dtype,
                  seed=test_util.test_seed(),
              )
          )
      else:
          loc = None
  
      mvn_scale = mvn_tril.MultivariateNormalTriL(
          loc=loc, scale_tril=cov.cholesky().to_dense()
      )
  
      mvn_precision = (
          mvnpflo.MultivariateNormalPrecisionFactorLinearOperator(
              loc=loc,
              precision_factor=precision_factor,
              precision=precision if use_precision else None,
          )
      )
  
      point = tf.random.normal(
          batch_shape + (event_size,),
          dtype=dtype,
          seed=test_util.test_seed(),
      )
      mvn_scale_log_prob, mvn_precision_log_prob = self.evaluate(
          [mvn_scale.log_prob(point), mvn_precision.log_prob(point)]
      )
      self.assertAllClose(
          mvn_scale_log_prob,
          mvn_precision_log_prob,
          atol=5e-4,
          rtol=5e-4,
      )
  
      batch_point = tf.random.normal(
          (2,) + batch_shape + (event_size,),
          dtype=dtype,
          seed=test_util.test_seed(),
      )
      mvn_scale_log_prob, mvn_precision_log_prob = self.evaluate(
          [
              mvn_scale.log_prob(batch_point),
              mvn_precision.log_prob(batch_point),
          ]
      )
      self.assertAllClose(
          mvn_scale_log_prob,
          mvn_precision_log_prob,
          atol=5e-4,
          rtol=5e-4,
      )
  
      samples = mvn_precision.sample(
          n_samples, seed=test_util.test_seed()
      )
      arrs = self.evaluate(
          {
              "stddev": tf.sqrt(cov.diag_part()),
              "var": cov.diag_part(),
              "cov": cov.to_dense(),
              "samples": samples,
              "sample_var": sample_stats.variance(
                  samples, sample_axis=0
              ),
              "sample_cov": sample_stats.covariance(
                  samples, sample_axis=0
              ),
          }
      )
  
      self.assertAllMeansClose(
          arrs["samples"],
          loc
          if loc is not None
          else np.zeros_like(arrs["cov"][..., 0]),
          axis=0,
          atol=5 * np.max(arrs["stddev"]) / np.sqrt(n_samples),
      )
      self.assertAllClose(
          arrs["sample_var"],
          arrs["var"],
          atol=5
          * np.sqrt(2)
          * np.max(arrs["var"])
          / np.sqrt(n_samples),
      )
      self.assertAllClose(
          arrs["sample_cov"],
          arrs["cov"],
          atol=5
          * np.sqrt(2)
          * np.max(arrs["var"])
          / np.sqrt(n_samples),
      )
  
file_path: probability/tensorflow_probability/python/experimental/distributions/mvn_precision_factor_linop_test.py
imports: import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import mvn_tril
  from tensorflow_probability.python.distributions import wishart
  from tensorflow_probability.python.experimental.distributions import mvn_precision_factor_linop
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import test_combinations
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.stats import sample_stats
label_desc: Use image node_id 2 for calling the MVNPrecisionFactorLinOpTest obj's underlying member method code with example usage: obj.test_log_prob_and_sample(use_loc, use_precision, event_size, batch_shape, dtype, n_samples) without return types