code: def index_add(input, dim, index, source, *, alpha=1, out=None):
      input = ivy.swapaxes(input, dim, 0)
      source = ivy.swapaxes(source, dim, 0)
      _to_adds = []
      index = sorted(
          zip(ivy.to_list(index), range(len(index))),
          key=(lambda x: x[0]),
      )
      while index:
          _curr_idx = index[0][0]
          while len(_to_adds) < _curr_idx:
              _to_adds.append(ivy.zeros_like(source[0]))
          _to_add_cum = ivy.get_item(source, index[0][1])
          while (len(index) > 1) and (index[0][0] == index[1][0]):
              _to_add_cum = _to_add_cum + ivy.get_item(
                  source, index.pop(1)[1]
              )
          index.pop(0)
          _to_adds.append(_to_add_cum)
      while len(_to_adds) < input.shape[0]:
          _to_adds.append(ivy.zeros_like(source[0]))
      _to_adds = ivy.stack(_to_adds)
      if len(input.shape) < 2:
          # Added this line due to the paddle backend treating scalars as 1-d arrays
          _to_adds = ivy.flatten(_to_adds)
  
      ret = ivy.add(input, _to_adds, alpha=alpha)
      ret = ivy.swapaxes(ret, 0, dim, out=out)
      return ret
  
imports: import ivy
  from ivy.func_wrapper import with_unsupported_dtypes
  from ivy.functional.frontends.torch.func_wrapper import to_ivy_arrays_and_back, numpy_to_torch_style_args, to_ivy_shape
  import ivy.functional.frontends.torch
label_desc: Use image node_id 14 for calling a global function with example usage: index_add(input, dim, index, source) and returns: ret