def index_restrict(i, arr):
    """
    Quick Internal Function - ensure that index i is appropriately bounded for the given arr;
    i.e. 0 <= i < len(arr)
    :param i:
    :param arr:
    :return:
    """
    if i < 0:
        i = 0
    elif i > len(arr) - 1:
        i = len(arr) - 1
    return i