def _get_mask_pairs(starts_old, stops_old, c, idx):
    "\n    Gets the pairs for a following dimension given the pairs for\n    a dimension.\n\n    For each pair, it searches in the following dimension for\n    matching coords and returns those.\n\n    The total combined length of all pairs is returned to\n    help with the performance guesstimate.\n\n    Parameters\n    ----------\n    starts_old, stops_old : list[int]\n        The starts and stops from the previous index.\n    c : np.ndarray\n        The coords for this index's dimension.\n    idx : np.ndarray\n        The index in the form of a slice.\n        idx[0], idx[1], idx[2] = start, stop, step\n\n    Returns\n    -------\n    starts, stops: list\n        The starts and stops after applying the current index.\n    n_matches : int\n        The sum of elements in all ranges.\n\n    Examples\n    --------\n    >>> c = np.array([1, 2, 1, 2, 1, 1, 2, 2])\n    >>> starts_old = [4]\n    >>> stops_old = [8]\n    >>> idx = np.array([1, 2, 1])\n    >>> _get_mask_pairs(starts_old, stops_old, c, idx)\n    ([4], [6], 2)\n    "
    starts = []
    stops = []
    n_matches = 0
    for j in range(len(starts_old)):
        for p_match in range(idx[0], idx[1], idx[2]):
            start = (np.searchsorted(c[starts_old[j]:stops_old[j]], p_match) + starts_old[j])
            stop = (np.searchsorted(c[starts_old[j]:stops_old[j]], (p_match + 1)) + starts_old[j])
            if (start != stop):
                starts.append(start)
                stops.append(stop)
                n_matches += (stop - start)
    return (starts, stops, n_matches)
Gets the pairs for a following dimension given the pairs for
a dimension.

For each pair, it searches in the following dimension for
matching coords and returns those.

The total combined length of all pairs is returned to
help with the performance guesstimate.

Parameters
----------
starts_old, stops_old : list[int]
    The starts and stops from the previous index.
c : np.ndarray
    The coords for this index's dimension.
idx : np.ndarray
    The index in the form of a slice.
    idx[0], idx[1], idx[2] = start, stop, step

Returns
-------
starts, stops: list
    The starts and stops after applying the current index.
n_matches : int
    The sum of elements in all ranges.

Examples
--------
>>> c = np.array([1, 2, 1, 2, 1, 1, 2, 2])
>>> starts_old = [4]
>>> stops_old = [8]
>>> idx = np.array([1, 2, 1])
>>> _get_mask_pairs(starts_old, stops_old, c, idx)
([4], [6], 2)
def _get_mask_pairs(starts_old, stops_old, c, idx):
    "\n    Gets the pairs for a following dimension given the pairs for\n    a dimension.\n\n    For each pair, it searches in the following dimension for\n    matching coords and returns those.\n\n    The total combined length of all pairs is returned to\n    help with the performance guesstimate.\n\n    Parameters\n    ----------\n    starts_old, stops_old : list[int]\n        The starts and stops from the previous index.\n    c : np.ndarray\n        The coords for this index's dimension.\n    idx : np.ndarray\n        The index in the form of a slice.\n        idx[0], idx[1], idx[2] = start, stop, step\n\n    Returns\n    -------\n    starts, stops: list\n        The starts and stops after applying the current index.\n    n_matches : int\n        The sum of elements in all ranges.\n\n    Examples\n    --------\n    >>> c = np.array([1, 2, 1, 2, 1, 1, 2, 2])\n    >>> starts_old = [4]\n    >>> stops_old = [8]\n    >>> idx = np.array([1, 2, 1])\n    >>> _get_mask_pairs(starts_old, stops_old, c, idx)\n    ([4], [6], 2)\n    "
    starts = []
    stops = []
    n_matches = 0
    for j in range(len(starts_old)):
        for p_match in range(idx[0], idx[1], idx[2]):
            start = (np.searchsorted(c[starts_old[j]:stops_old[j]], p_match) + starts_old[j])
            stop = (np.searchsorted(c[starts_old[j]:stops_old[j]], (p_match + 1)) + starts_old[j])
            if (start != stop):
                starts.append(start)
                stops.append(stop)
                n_matches += (stop - start)
    return (starts, stops, n_matches)