def widen_bounds(a_bounds, b_bounds):
    """Find the inclusive hyperrect that bounds both hyperrects.
    
    Arguments
    ---------
    a_bounds, b_bounds : ndim X 2 int32 arrays
        Index [dim, 0] gives the lower bounds along each dimension "dim".
        Index [dim, 1] gives the upper bounds along each dimension "dim".
        Each bounding value is inclusive.
    
    Note
    ----
    This function assumes that a_bounds can be overwritten. If this
    is not True you should copy a_bounds before passing it into
    this function.
    """
    assert a_bounds.ndim == b_bounds.ndim
    assert a_bounds.shape[0]  == b_bounds.shape[0]
    assert a_bounds.shape[1] == b_bounds.shape[1]
    
    for dim in range(a_bounds.shape[0]):
        a_bounds[dim, 0] = min(a_bounds[dim, 0], b_bounds[dim, 0])
        a_bounds[dim, 1] = max(a_bounds[dim, 1], b_bounds[dim, 1])
    return a_bounds