def transform_Index(self, expr):
    arr = self.transform_expr(expr.value)
    idx = self.transform_expr(expr.index)
    idx = self.assign_name(idx, "idx")

    arr_t = arr.type
    if arr_t.__class__ is PtrT:
      assert isinstance(idx.type, IntT)
      return expr

    assert arr_t.__class__ is  ArrayT, "Unexpected array %s : %s" % (arr, arr.type)

    if self.is_tuple(idx):
      indices = self.tuple_elts(idx)
    else:
      indices = [idx]
    # right pad the index expression with None for each missing index
    n_given = len(indices)
    n_required = arr_t.rank
    if n_given < n_required:
      extra_indices = [syntax.helpers.slice_none] * (n_required - n_given)
      indices.extend(extra_indices)

    # fast-path for the common case when we're indexing
    # by all scalars to retrieve a scalar result
    if syntax.helpers.all_scalars(indices):
      data_ptr = self.attr(arr, "data")
      strides = self.attr(arr, "strides")
      offset_elts = self.attr(arr, "offset")
      for (i, idx_i) in enumerate(indices):
        stride_i = self.tuple_proj(strides, i)

        elts_i = self.mul(stride_i, idx_i, "offset_elts_%d" % i)
        offset_elts = self.add(offset_elts, elts_i, "total_offset")
      return self.index(data_ptr, offset_elts, temp = False)
    else:
      return self.array_slice(arr, indices)
dataset/ETHPy150Open iskandr/parakeet/parakeet/transforms/lower_indexing.py/LowerIndexing.transform_Index/original