code: def _batch_outer_product(target, event_ndims):
      """Calculates the batch outer product along `target`'s event dimensions.
  
      More precisely, A `tf.einsum` operation is used to calculate desired
      pairwise products as follows:
  
      For `event_ndims=0`, the return value is:
        `tf.einsum("...,...->...", target, target)`
      For `event_ndims=1`:
        `tf.einsum("...a,...b->...ab", target, target)`
      For `event_ndims=2`:
        `tf.einsum("...ab,...cd->...abcd", target, target)`
      ...
  
      Args:
        target: Target `Tensor` for the `tf.einsum` computation.
        event_ndims: Both the number of dimensions that specify the event
          shape and the desired number of dimensions for cross product
          terms.
  
      Returns:
        outer_product: A `Tensor` with shape B + E + E for all pairwise
          products of `target` in the event dimensions.
      """
      assign_indices = "".join(
          list(map(chr, range(ord("a"), ord("a") + event_ndims * 2)))
      )
      first_indices = assign_indices[:event_ndims]
      second_indices = assign_indices[event_ndims:]
      einsum_formula = "...{},...{}->...{}".format(
          first_indices, second_indices, assign_indices
      )
      return tf.einsum(einsum_formula, target, target)
  
imports: import functools
  import math
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import nest_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.mcmc import diagnostic
  from tensorflow.python.util import nest
label_desc: Use image node_id 2 for calling a global function with example usage: _batch_outer_product(target, event_ndims) and returns: tf