def set_to_bounds(i_s, i_e, j_s, j_e, low=0, high=1):
    """
    Makes sure the given index values stay with the
    bounds (low and high). This works only for 2 dimensional
    square matrices where low and high are same in both
    dimensions.

    Arguments:
        i_s : Starting value for row index
        i_e : Ending value for row index
        j_s : Starting value for column index
        j_e : Ending value for column index
        low : Minimum value for index possible
        high : Maximum value for index possible

    Returns:
        Values within bounds for given index positions
    """
    if i_s < low:
        i_s = low
    if i_e > high:
        i_e = high
    if j_s < low:
        j_s = low
    if j_e > high:
        j_e = high
    return i_s, i_e, j_s, j_e