code: def testKLBlockwise(self):
      # d0 and d1 are two MVN's that are 6 dimensional. Construct the
      # corresponding MVNs, and ensure that the KL between the MVNs is close to
      # the Blockwise ones.
      # In both cases the scale matrix has a block diag structure, owing to
      # independence of the component distributions.
      d0 = blockwise.Blockwise(
          [
              independent.Independent(
                  normal.Normal(
                      loc=tf.zeros(4, dtype=tf.float64), scale=1.0
                  ),
                  reinterpreted_batch_ndims=1,
              ),
              mvn_tril.MultivariateNormalTriL(
                  scale_tril=tf1.placeholder_with_default(
                      tf.eye(2, dtype=tf.float64), shape=None
                  )
              ),
          ],
          validate_args=True,
      )
  
      d0_mvn = mvn_linear_operator.MultivariateNormalLinearOperator(
          loc=np.float64([0.0] * 6),
          scale=tf.linalg.LinearOperatorBlockDiag(
              [
                  tf.linalg.LinearOperatorIdentity(
                      num_rows=4, dtype=tf.float64
                  ),
                  tf.linalg.LinearOperatorLowerTriangular(
                      tf.eye(2, dtype=tf.float64)
                  ),
              ]
          ),
      )
  
      d1 = blockwise.Blockwise(
          [
              independent.Independent(
                  normal.Normal(
                      loc=tf.ones(4, dtype=tf.float64), scale=1
                  ),
                  reinterpreted_batch_ndims=1,
              ),
              mvn_tril.MultivariateNormalTriL(
                  loc=tf.ones(2, dtype=tf.float64),
                  scale_tril=tf1.placeholder_with_default(
                      np.float64([[1.0, 0.0], [2.0, 3.0]]), shape=None
                  ),
              ),
          ],
          validate_args=True,
      )
      d1_mvn = mvn_linear_operator.MultivariateNormalLinearOperator(
          loc=np.float64([1.0] * 6),
          scale=tf.linalg.LinearOperatorBlockDiag(
              [
                  tf.linalg.LinearOperatorIdentity(
                      num_rows=4, dtype=tf.float64
                  ),
                  tf.linalg.LinearOperatorLowerTriangular(
                      np.float64([[1.0, 0.0], [2.0, 3.0]])
                  ),
              ]
          ),
      )
  
      blockwise_kl = kullback_leibler.kl_divergence(d0, d1)
      mvn_kl = kullback_leibler.kl_divergence(d0_mvn, d1_mvn)
      blockwise_kl_, mvn_kl_ = self.evaluate([blockwise_kl, mvn_kl])
      self.assertAllClose(blockwise_kl_, mvn_kl_)
  
imports: from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import blockwise
  from tensorflow_probability.python.distributions import exponential
  from tensorflow_probability.python.distributions import gamma
  from tensorflow_probability.python.distributions import independent
  from tensorflow_probability.python.distributions import joint_distribution_coroutine
  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 mvn_linear_operator
  from tensorflow_probability.python.distributions import mvn_tril
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.internal import test_util
label_desc: Use image node_id 9 for calling the BlockwiseTest obj's underlying member method code with example usage: obj.testKLBlockwise() without return types