def _norm_index(dim, index, start, stop):
    """Return an index normalized to an farray start index."""
    length = stop - start
    if -length <= index < 0:
        normindex = index + length
    elif start <= index < stop:
        normindex = index - start
    else:
        fstr = 'expected dim {} index in range [{}, {})'
        raise IndexError(fstr.format(dim, start, stop))
    return normindex
