def shift_ip(x, d=1):
    """
    Optimized inplace shift
    """
    assert x.flags.contiguous, 'x must be contiguous'
    if d >= 0:
        x[:d - 1:-1] = x[-d - 1::-1]
    else:
        x[d - 1::-1] = x[:-d - 1:-1]
    return x
