code: def testCovarianceNAlphaBroadcast(self):
      alpha_v = [1.0, 2, 3]
      alpha_0 = 6.0
  
      # Shape [4, 3]
      alpha = np.array(4 * [alpha_v], dtype=np.float32)
      # Shape [4, 1]
      ns = np.array([[2.0], [3.0], [4.0], [5.0]], dtype=np.float32)
  
      variance_entry = lambda a, a_sum: a / a_sum * (1 - a / a_sum)
      covariance_entry = lambda a, b, a_sum: -a * b / a_sum**2
      # Shape [4, 3, 3]
      shared_matrix = np.array(
          4
          * [
              [
                  [
                      variance_entry(alpha_v[0], alpha_0),
                      covariance_entry(alpha_v[0], alpha_v[1], alpha_0),
                      covariance_entry(alpha_v[0], alpha_v[2], alpha_0),
                  ],
                  [
                      covariance_entry(alpha_v[1], alpha_v[0], alpha_0),
                      variance_entry(alpha_v[1], alpha_0),
                      covariance_entry(alpha_v[1], alpha_v[2], alpha_0),
                  ],
                  [
                      covariance_entry(alpha_v[2], alpha_v[0], alpha_0),
                      covariance_entry(alpha_v[2], alpha_v[1], alpha_0),
                      variance_entry(alpha_v[2], alpha_0),
                  ],
              ]
          ],
          dtype=np.float32,
      )
  
      with self.cached_session():
          # ns is shape [4, 1], and alpha is shape [4, 3].
          dist = ds.DirichletMultinomial(ns, alpha)
          covariance = dist.covariance()
          expected_covariance = (
              shared_matrix
              * (ns * (ns + alpha_0) / (1 + alpha_0))[
                  ..., array_ops.newaxis
              ]
          )
  
          self.assertEqual([4, 3, 3], covariance.get_shape())
          self.assertAllClose(
              expected_covariance, self.evaluate(covariance)
          )
  
imports: import numpy
  from tensorflow.python.eager import backprop
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import tensor_shape
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops.distributions import dirichlet_multinomial
  from tensorflow.python.platform import test
label_desc: Use image node_id 19 for calling the DirichletMultinomialTest obj's underlying member method code with example usage: obj.testCovarianceNAlphaBroadcast() without return types