code: def convert_indexed_to_array(expr, first_indices=None):
      r"""
      Parse indexed expression into a form useful for code generation.
  
      Examples
      ========
  
      >>> from sympy.tensor.array.expressions.from_indexed_to_array import convert_indexed_to_array
      >>> from sympy import MatrixSymbol, Sum, symbols
  
      >>> i, j, k, d = symbols("i j k d")
      >>> M = MatrixSymbol("M", d, d)
      >>> N = MatrixSymbol("N", d, d)
  
      Recognize the trace in summation form:
  
      >>> expr = Sum(M[i, i], (i, 0, d-1))
      >>> convert_indexed_to_array(expr)
      ArrayContraction(M, (0, 1))
  
      Recognize the extraction of the diagonal by using the same index `i` on
      both axes of the matrix:
  
      >>> expr = M[i, i]
      >>> convert_indexed_to_array(expr)
      ArrayDiagonal(M, (0, 1))
  
      This function can help perform the transformation expressed in two
      different mathematical notations as:
  
      `\sum_{j=0}^{N-1} A_{i,j} B_{j,k} \Longrightarrow \mathbf{A}\cdot \mathbf{B}`
  
      Recognize the matrix multiplication in summation form:
  
      >>> expr = Sum(M[i, j]*N[j, k], (j, 0, d-1))
      >>> convert_indexed_to_array(expr)
      ArrayContraction(ArrayTensorProduct(M, N), (1, 2))
  
      Specify that ``k`` has to be the starting index:
  
      >>> convert_indexed_to_array(expr, first_indices=[k])
      ArrayContraction(ArrayTensorProduct(N, M), (0, 3))
      """
  
      result, indices = _convert_indexed_to_array(expr)
  
      if any(isinstance(i, (int, Integer)) for i in indices):
          result = ArrayElement(result, indices)
          indices = []
  
      if not first_indices:
          return result
  
      def _check_is_in(elem, indices):
          if elem in indices:
              return True
          if any(
              elem in i for i in indices if isinstance(i, frozenset)
          ):
              return True
          return False
  
      repl = {
          j: i for i in indices if isinstance(i, frozenset) for j in i
      }
      first_indices = [repl.get(i, i) for i in first_indices]
      for i in first_indices:
          if not _check_is_in(i, indices):
              first_indices.remove(i)
      first_indices.extend(
          [i for i in indices if not _check_is_in(i, first_indices)]
      )
  
      def _get_pos(elem, indices):
          if elem in indices:
              return indices.index(elem)
          for i, e in enumerate(indices):
              if not isinstance(e, frozenset):
                  continue
              if elem in e:
                  return i
          raise ValueError("not found")
  
      permutation = _af_invert(
          [_get_pos(i, first_indices) for i in indices]
      )
      if isinstance(result, ArrayAdd):
          return _array_add(
              *[_permute_dims(arg, permutation) for arg in result.args]
          )
      else:
          return _permute_dims(result, permutation)
  
file_path: sympy/sympy/tensor/array/expressions/from_indexed_to_array.py
imports: from collections import defaultdict
  from sympy import Function
  from sympy.combinatorics.permutations import _af_invert
  from sympy.concrete.summations import Sum
  from sympy.core.add import Add
  from sympy.core.mul import Mul
  from sympy.core.numbers import Integer
  from sympy.core.power import Pow
  from sympy.core.sorting import default_sort_key
  from sympy.functions.special.tensor_functions import KroneckerDelta
  from sympy.tensor.array.expressions import ArrayElementwiseApplyFunc
  from sympy.tensor.indexed import Indexed, IndexedBase
  from sympy.combinatorics import Permutation
  from sympy.matrices.expressions.matexpr import MatrixElement
  from sympy.tensor.array.expressions.array_expressions import ArrayDiagonal, get_shape, ArrayElement, _array_tensor_product, _array_diagonal, _array_contraction, _array_add, _permute_dims, OneArray, ArrayAdd
  from sympy.tensor.array.expressions.utils import _get_argindex, _get_diagonal_indices
label_desc: Use image node_id 1 for calling a global function with example usage: convert_indexed_to_array(expr, first_indices) and returns: result, False, _array_add, _permute_dims, True, True, indices, i