def rescale_size(size, scale, return_scale=False):
    """
    Compute the new size to be rescaled to.

    Args:
        size (tuple[int]): The original size in the form of
            ``(width, height)``.
        scale (int | tuple[int]): The scaling factor or the maximum size. If
            it is a number, the image will be rescaled by this factor. When it
            is a tuple containing 2 numbers, the image will be rescaled as
            large as possible within the scale. In this case, ``-1`` means
            infinity.
        return_scale (bool, optional): Whether to return the scaling factor.
            Default: ``False``.

    Returns:
        :obj:`np.ndarray` | tuple: The new size (and scaling factor).
    """
    w, h = size

    if isinstance(scale, (float, int)):
        scale_factor = scale
    elif isinstance(scale, tuple):
        if -1 in scale:
            max_s_edge = max(scale)
            scale_factor = max_s_edge / min(h, w)
        else:
            max_l_edge = max(scale)
            max_s_edge = min(scale)
            scale_factor = min(max_l_edge / max(h, w), max_s_edge / min(h, w))
    else:
        raise TypeError(
            "'scale must be a number or tuple of int, but got '{}'".format(
                type(scale)))

    new_size = int(w * scale_factor + 0.5), int(h * scale_factor + 0.5)

    if return_scale:
        return new_size, scale_factor
    else:
        return new_size