code: def testCompositeTensorOrPytree(self):
      d = jdn.JointDistributionNamed(
          dict(
              e=independent.Independent(
                  exponential.Exponential(rate=[100, 120]), 1
              ),
              scale=lambda e: gamma.Gamma(  # pylint: disable=g-long-lambda
                  concentration=e[..., 0], rate=e[..., 1]
              ),
              loc=normal.Normal(loc=0, scale=2.0),
              m=normal.Normal,
              x=lambda m: sample_lib.Sample(
                  bernoulli.Bernoulli(logits=m), 12
              ),
          ),
          validate_args=True,
      )
  
      flat = tf.nest.flatten(d, expand_composites=True)
      unflat = tf.nest.pack_sequence_as(d, flat, expand_composites=True)
      self.assertIsInstance(unflat, jdn.JointDistributionNamed)
      self.assertIs(type(d.model), type(unflat.model))
  
      x = self.evaluate(d.sample(3, seed=test_util.test_seed()))
      actual = self.evaluate(d.log_prob(x))
  
      self.assertAllClose(self.evaluate(unflat.log_prob(x)), actual)
  
      @tf.function
      def call_log_prob(d):
          return d.log_prob(x)
  
      self.assertAllClose(actual, call_log_prob(d))
      self.assertAllClose(actual, call_log_prob(unflat))
  
imports: import collections
  from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import bijector_test_util
  from tensorflow_probability.python.bijectors import scale
  from tensorflow_probability.python.distributions import bernoulli
  from tensorflow_probability.python.distributions import beta
  from tensorflow_probability.python.distributions import exponential
  from tensorflow_probability.python.distributions import gamma
  from tensorflow_probability.python.distributions import half_normal
  from tensorflow_probability.python.distributions import independent
  from tensorflow_probability.python.distributions import joint_distribution_named
  from tensorflow_probability.python.distributions import joint_distribution_sequential
  from tensorflow_probability.python.distributions import kullback_leibler
  from tensorflow_probability.python.distributions import lognormal
  from tensorflow_probability.python.distributions import mvn_diag
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.distributions import sample
  from tensorflow_probability.python.distributions import student_t
  from tensorflow_probability.python.distributions import transformed_distribution
  from tensorflow_probability.python.internal import test_util
label_desc: Use image node_id 23 for calling the JointDistributionNamedTest obj's underlying member method code with example usage: obj.testCompositeTensorOrPytree() and returns: d