code: def _internal_contract(formula_a, a, other):
      """Perform contractions contained completely within a single tensor.
  
      Args:
        formula_a: a string of indices compatible with the given tensor.
        a: a tensor compatible with the given indices.
        other: a string of indices.
  
      Returns:
        If an einsum formula contains indices that correspond solely to
        dimensions of one tensor and appear nowhere among the indices
        for the other input arguments or the output then these describe
        a summation or contraction within that tensor.
        For example an einsum formula like 'ij,kj,lk->...'
        we can completely eliminate all occurrences of 'i' from the
        formula by applying `_internal_contract` to the appropriate tensor.
        `_internal_contract` also updates the appropriate part of the formula
        reflect the eliminations.
        For example if `m` is a 10x3x3 tensor considered as an array
        of 10 3-vectors, `_internal_contract('ji', m)` will return
        a vector consisting of the sums of the 10 vectors along with the
        string 'j' indicating the index 'j' was not reduced or contracted over.
        Note that this function sums in log space so it in fact uses
        `reduce_logsumexp` to compute the sum.
        Note also that this function is written on the assumption that repeated
        indices have already been removed by `_extract_diagonals`.
      """
  
      reducing_a = ""
      keep_a = ""
      for i in formula_a:
          if i in other:
              # Keep an index if it's used elsewhere
              keep_a += i
          else:
              # Collect indices that appear only for this tensor
              reducing_a += i
      if formula_a != keep_a:
          axes_a = map(formula_a.index, reducing_a)
          # This reduction is only valid if there are no repeated indices
          # in `formula_a`.
          a = tf.reduce_logsumexp(a, axis=tuple(axes_a))
          formula_a = keep_a
  
      return formula_a, a
  
file_path: probability/tensorflow_probability/python/experimental/marginalize/logeinsumexp.py
imports: import opt_einsum
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import prefer_static
label_desc: Use image node_id 5 for calling a global function with example usage: _internal_contract(formula_a, a, other) and returns: formula_a,  a