code: def solve_diagonal_einsum(parsed_vectors, vars):
      def solve_diagonal_einsum_one_step(parsed_vector, x):
          for i in range(len(parsed_vector)):
              for j in range(i + 1, len(parsed_vector)):
                  if parsed_vector[i] != parsed_vector[j]:
                      continue
  
                  perm = list(range(len(parsed_vector)))
                  duplicated_indices = [
                      j
                      for j in range(len(parsed_vector))
                      if parsed_vector[j] == parsed_vector[i]
                  ]
                  for i, j in enumerate(duplicated_indices):
                      perm[i], perm[j] = perm[j], perm[i]
                      parsed_vector[i], parsed_vector[j] = (
                          parsed_vector[j],
                          parsed_vector[i],
                      )
  
                  dims = mb.shape(x=x)
                  dim_length = value_at(dims, duplicated_indices[0])
  
                  indices = mb.range_1d(end=dim_length, start=0, step=1)
                  indices = mb.stack(
                      values=[indices] * len(duplicated_indices), axis=1
                  )
                  x = mb.transpose(x=x, perm=perm)
                  x = mb.gather_nd(x=x, indices=indices)
                  ret_parsed_vector = [
                      parsed_vector[0]
                  ] + parsed_vector[len(duplicated_indices) :]
                  return ret_parsed_vector, x
  
      for i in range(len(vars)):
          while len(parsed_vectors[i]) != len(set(parsed_vectors[i])):
              parsed_vector, var = solve_diagonal_einsum_one_step(
                  parsed_vectors[i], vars[i]
              )
              parsed_vectors[i] = parsed_vector
              vars[i] = var
      return tuple(parsed_vectors), vars
  
file_path: coremltools/coremltools/converters/mil/frontend/_utils.py
imports: import itertools
  from typing import List, Optional
  from coremltools.converters.mil.input_types import InputType
  from coremltools.converters.mil.mil import Builder
  from coremltools.converters.mil.mil import Var, types
  from coremltools.converters.mil.mil.ops.defs._utils import parse_einsum_equation
  from coremltools.converters.mil.mil.types.symbolic import any_symbolic, is_symbolic
label_desc: Use image node_id 6 for calling a global function with example usage: solve_diagonal_einsum(parsed_vectors, vars) and returns: tuple,  vars, ret_parsed_vector,  x