from typing import Tuple


def custom_ravel(tup: Tuple[int, int], shape: Tuple[int, int]) -> int:
    """Ravel indexes for 2D array.

    This is a jitted function, equivalent to the `numpy` implementation of
    `ravel_multi_index`, but configured to accept only a single tuple as
    the index to ravel, and only works for two-dimensional array.

    Parameters
    ----------
    tup : :obj:`tuple` of :obj:`int`
        Two element `tuple` with the `x` and `y` index into an array of
        shape :obj:`shape` to ravel.

    shape : :obj:`tuple` of :obj:`int`
        Two element tuple of integers indicating the shape of the
        two-dimensional array from which :obj:`tup` will be ravelled.

    Returns
    -------
    i : :obj:`int`
        Ravelled integer index into array of shape :obj:`shape`.

    Examples
    --------
    .. testsetup::

        from pyDeltaRCM.shared_tools import custom_ravel

    .. doctest::

        >>> _shape = (100, 200)  # e.g., delta.eta.shape

        >>> np.ravel_multi_index((25, 124), _shape)
        5124

        >>> custom_ravel((25, 124), _shape)
        5124
    """
    if tup[0] > shape[0] or tup[1] > shape[1]:
        raise IndexError("Index is out of array bounds")
    x = tup[0] * shape[1]
    y = tup[1]
    return x + y