def slice_to_range(slicer, r_max):
    """Convert a slice object to the corresponding index list"""
    step = 1 if slicer.step is None else slicer.step
    if slicer.start is None:
        start = r_max - 1 if step < 0 else 0
    else:
        start = slicer.start
    if slicer.stop is None:
        stop = -1 if step < 0 else r_max
    else:
        stop = slicer.stop
    # start = 0 if slicer.start is None else slicer.start
    # stop = r_max if slicer.stop is None else slicer.stop
    return range(start, stop, step)