def _get_valid_indices(shape, ix0, ix1, iy0, iy1):
ymax, xmax = shape<EOL>if ix0 < <NUM_LIT:0>:<EOL><INDENT>ix0 = <NUM_LIT:0><EOL><DEDENT>if ix1 > xmax:<EOL><INDENT>ix1 = xmax<EOL><DEDENT>if iy0 < <NUM_LIT:0>:<EOL><INDENT>iy0 = <NUM_LIT:0><EOL><DEDENT>if iy1 > ymax:<EOL><INDENT>iy1 = ymax<EOL><DEDENT>if iy1 <= iy0 or ix1 <= ix0:<EOL><INDENT>raise IndexError(<EOL>'<STR_LIT>'.format(iy0, iy1, ix0, ix1))<EOL><DEDENT>return list(map(int, [ix0, ix1, iy0, iy1]))<EOL>
Give array shape and desired indices, return indices that are
    correctly bounded by the shape.