

def transform_Index(self, expr):
    ndims = expr.value.type.rank
    if ((ndims == 1) and isinstance(expr.index.type, ScalarT)):
        return expr
    elif (isinstance(expr.index.type, TupleT) and (len(expr.index.type.elt_types) == ndims) and all((isinstance(t, ScalarT) for t in expr.index.type.elt_types))):
        return expr
    (scalar_indices, scalar_index_positions, slices, slice_positions) = self.dissect_index_expr(expr)
    assert (len(scalar_indices) == len(scalar_index_positions))
    assert (len(idx) == len(slice_positions))
    if (len(slices) == 0):
        return expr
    array = self.transform_expr(expr.value)
    data = self.attr(array, 'data')
    shape = self.shape(array)
    shape_elts = self.tuple_elts(shape)
    strides = self.strides(array)
    stride_elts = self.tuple_elts(strides)
    offset = self.attr(array, 'offset')
    new_shape = []
    new_strides = []
    n_indices = (len(scalar_indices) + len(slices))
    fixed_count = 0
    slice_count = 0
    for i in xrange(n_indices):
        if ((fixed_count < len(scalar_index_positions)) and (scalar_index_positions[fixed_count] == i)):
            idx = scalar_indices[fixed_count]
            fixed_count += 1
            offset = self.add(offset, self.mul(idx, stride_elts[i]), name='offset')
        else:
            assert (slice_positions[slice_count] == i)
            (start, stop, step) = slices[slice_count]
            slice_count += 1
            dim_offset = self.mul(start, stride_elts[i], name='dim_offset')
            offset = self.add(offset, dim_offset, 'offset')
            span = self.sub(stop, start, name='span')
            shape_elt = self.div_round_up(span, step, name='new_shape')
            new_shape.append(shape_elt)
            stride_elt = self.mul(stride_elts[i], step, name='new_stride')
            new_strides.append(stride_elt)
    size = self.prod(new_shape)
    new_rank = len(slices)
    assert (len(new_shape) == new_rank)
    assert (len(new_strides) == new_rank)
    new_array = self.array_view(data, self.tuple(new_shape), self.tuple(new_strides), offset, size)
    assert (new_array.type.rank == new_rank)
    return new_array

dataset/ETHPy150Open iskandr/parakeet/parakeet/transforms/lower_slices.py LowerSlices.transform_Index/VarMisuse@139/172 `slices`->`idx`