@numba.jit(nopython=True, cache=True)<EOL>def __match_intervals(intervals_from, intervals_to, strict=True):  
<EOL>start_index = np.argsort(intervals_to[:, <NUM_LIT:0>])<EOL>end_index = np.argsort(intervals_to[:, <NUM_LIT:1>])<EOL>start_sorted = intervals_to[start_index, <NUM_LIT:0>]<EOL>end_sorted = intervals_to[end_index, <NUM_LIT:1>]<EOL>search_ends = np.searchsorted(start_sorted, intervals_from[:, <NUM_LIT:1>], side='<STR_LIT:right>')<EOL>search_starts = np.searchsorted(end_sorted, intervals_from[:, <NUM_LIT:0>], side='<STR_LIT:left>')<EOL>output = np.empty(len(intervals_from), dtype=numba.uint32)<EOL>for i in range(len(intervals_from)):<EOL><INDENT>query = intervals_from[i]<EOL>after_query = search_ends[i]<EOL>before_query = search_starts[i]<EOL>candidates = set(start_index[:after_query]) & set(end_index[before_query:])<EOL>if len(candidates) > <NUM_LIT:0>:<EOL><INDENT>output[i] = __match_interval_overlaps(query, intervals_to, candidates)<EOL><DEDENT>elif strict:<EOL><INDENT>raise ParameterError<EOL><DEDENT>else:<EOL><INDENT>dist_before = np.inf<EOL>dist_after = np.inf<EOL>if search_starts[i] > <NUM_LIT:0>:<EOL><INDENT>dist_before = query[<NUM_LIT:0>] - end_sorted[search_starts[i]-<NUM_LIT:1>]<EOL><DEDENT>if search_ends[i] + <NUM_LIT:1> < len(intervals_to):<EOL><INDENT>dist_after = start_sorted[search_ends[i]+<NUM_LIT:1>] - query[<NUM_LIT:1>]<EOL><DEDENT>if dist_before < dist_after:<EOL><INDENT>output[i] = end_index[search_starts[i]-<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>output[i] = start_index[search_ends[i]+<NUM_LIT:1>]<EOL><DEDENT><DEDENT><DEDENT>return output<EOL>
Numba-accelerated interval matching algorithm.