code: def _reshape_einsum_outputs(
      output_tensor: tf.Tensor,
      equation: str,
  ) -> tf.Tensor:
      """Converts an output tensor of arbitrary rank to a batched matrix tensor.
  
      The logic is almost the same as in `_reshape_einsum_inputs()` except
      in the case where the equation is left-elided by ellipses. For this case,
      we need to pass in a reversed kernel shape.
  
      Args:
        output_tensor: A `tf.Tensor` corresponding to the output of the einsum
          equation.
        equation: The einsum equation `string`.
  
      Returns:
        A rank-3 `tf.Tensor` whose first dimension is the batch dimension. The
        product of the non-trivial dimensions of the output should be equal to
        the product of the non-trivial dimensions of `output_tensor`.
  
      Raises:
        ValueError: If `equation` is not a valid einsum equation in the context of
          the `tf.keras.layers.EinsumDense` layer.
      """
      # Get the raw components of the reversed equation.
      equation_type, (ab_str, bc_str, ac_str) = _parse_einsum_equation(
          equation
      )
      prefix = (
          "..." if equation_type == EquationType.LEFT_ELLIPSES else ""
      )
      suffix = (
          "..." if equation_type == EquationType.RIGHT_ELLIPSES else ""
      )
      ellided_ab_str = prefix + ab_str + suffix
      ellided_ac_str = prefix + ac_str + suffix
      # Swap the `b` and `c` components.
      c_str = os.path.commonprefix([bc_str[::-1], ac_str[::-1]])[::-1]
      b_len = len(bc_str) - len(c_str)
      b_str = bc_str[:b_len]
      cb_str = c_str + b_str
      reversed_equation = (
          ellided_ac_str + "," + cb_str + "->" + ellided_ab_str
      )
      return _reshape_einsum_inputs(output_tensor, reversed_equation)
  
file_path: privacy/tensorflow_privacy/privacy/fast_gradient_clipping/registry_functions/einsum_utils.py
imports: import enum
  import itertools
  import os
  import re
  from typing import Optional
  import tensorflow
  from tensorflow_privacy.privacy.fast_gradient_clipping import common_manip_utils
label_desc: Use image node_id 5 for calling a global function with example usage: _reshape_einsum_outputs(output_tensor, equation) and returns: _reshape_einsum_inputs