docstr: Sampling from a 2-D Multivariate Normal distribution.
docstr_tok: ["Sampling","from","a","2-D","Multivariate","Normal","distribution","."]
code: def testTwoDimNormal(self, static_shape, static_rank):
      """Sampling from a 2-D Multivariate Normal distribution."""
  
      # Disabling this test in eager mode as it is very slow.
      # Other tests check eager behavior, so we can safely disable this test.
      if tf.executing_eagerly() and not JAX_MODE:
          return
  
      dtype = np.float32
      true_mean = dtype([0, 0])
      true_cov = dtype([[1, 0.5], [0.5, 1]])
      num_results, tolerance = _get_mode_dependent_settings()
      num_chains = 16
      # Target distribution is defined through the Cholesky decomposition.
      chol = tf.linalg.cholesky(true_cov)
      target = mvn_tril.MultivariateNormalTriL(
          loc=true_mean, scale_tril=chol
      )
  
      # Initial state of the chain
      if static_shape and static_rank:
          shape = [num_chains, 2]
      elif static_rank:
          shape = [None, 2]
      else:
          shape = None
  
      init_state = tf1.placeholder_with_default(
          np.ones([num_chains, 2], dtype=dtype), shape=shape
      )
  
      # Run Slice Samper for `num_results` iterations for `num_chains`
      # independent chains:
      states = sample.sample_chain(
          num_results=num_results,
          current_state=init_state,
          kernel=slice_sampler_kernel.SliceSampler(
              target_log_prob_fn=tf.function(
                  target.log_prob, autograph=False
              ),
              step_size=1.0,
              max_doublings=5,
          ),
          num_burnin_steps=1000,
          trace_fn=None,
          seed=test_util.test_seed_stream(),
      )
  
      states = tf.reshape(states, [-1, 2])
      sample_mean = tf.reduce_mean(states, axis=0)
      sample_cov = sample_stats.covariance(states)
  
      self.assertAllClose(
          true_mean, sample_mean, atol=tolerance, rtol=tolerance
      )
      self.assertAllClose(
          true_cov, sample_cov, atol=tolerance, rtol=tolerance
      )
  
imports: from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import joint_distribution_sequential
  from tensorflow_probability.python.distributions import mvn_tril
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.internal import distribute_lib
  from tensorflow_probability.python.internal import distribute_test_lib
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.mcmc import random_walk_metropolis
  from tensorflow_probability.python.mcmc import sample
  from tensorflow_probability.python.mcmc import slice_sampler_kernel
  from tensorflow_probability.python.stats import sample_stats
label_desc: Use image node_id 2 for calling the SliceSamplerTest obj's underlying member method code with example usage: obj.testTwoDimNormal(static_shape, static_rank) without return types