code: def apply_to_array_api(self, arr: T, ind: Union[T, List[T]]):
      known_axes_sizes: dict[str, int] = {}
      xp = arr.__array_namespace__()
  
      if not isinstance(ind, list):
          ind = [ind[i, ...] for i in range(ind.shape[0])]
  
      for indexer in ind:
          assert len(indexer.shape) == len(
              self.indexer_other_axes_names
          )
  
      # step 1. transpose, reshapes of arr; learn its dimensions
      arr_2d = self.array_composition.compose(arr, known_axes_sizes)
  
      # step 2. compute shifts and create an actual indexing array
      shift = 1
      full_index = xp.zeros(
          [1] * len(ind[0].shape), dtype=xp.int64, device=arr.device
      )
  
      # original order: [*batch-like axes, *indexing_axes,]
      # now we need to traverse them in the opposite direction
  
      for axis_name, indexer in list(
          zip(self.indexing_axes_names, ind)
      )[::-1]:
          full_index = full_index + shift * (
              indexer % known_axes_sizes[axis_name]
          )
          shift *= known_axes_sizes[axis_name]
  
      for axis_name in self.batch_axes[::-1]:
          axis_id = self.indexer_other_axes_names.index(axis_name)
          full_index = (
              full_index
              + arange_at_position(
                  xp,
                  len(self.indexer_other_axes_names),
                  axis=axis_id,
                  axis_len=known_axes_sizes[axis_name],
                  device=arr.device,
              )
              * shift
          )
          shift *= known_axes_sizes[axis_name]
  
      assert shift == arr_2d.shape[0]
  
      # step 3. Flatten index
      full_index = self.index_composition.compose(
          full_index, known_axes_sizes
      )
  
      # step 4. indexing
      # python array api lacks any integer indexing, so... I use loops.
      # did you know that there is conceptual programming ... just like art?
      # result_2d = arr_2d[full_index]
      result_2d = xp.stack(
          [arr_2d[full_index[i], :] for i in range(full_index.shape[0])]
      )
  
      # step 5. doing resulting
      result = self.result_composition.decompose(
          result_2d, known_axes_sizes
      )
      return result
  
file_path: einops/einops/experimental/indexing.py
imports: from typing import List, Union, TypeVar, Tuple
  from einops import EinopsError
label_desc: Use image node_id 2 for calling the IndexingFormula obj's underlying member method code with example usage: obj.apply_to_array_api(arr, ind) and returns: result