<jupyter_start><jupyter_text>Initialization<jupyter_code>ndim = 5
rad = .2
box = [(-rad, rad)] * ndim
X = np.random.rand(500, ndim)
X[:5]<jupyter_output><empty_output><jupyter_text>Compare results In order to compare the results of the range query, we create here corresponding metric for ball tree.We can note that we loose the radius property of it.<jupyter_code>def box_metric(box):
    def _box_metric(a, b):
        return any([not(box_d_min < b_d - a_d < box_d_max) for a_d, b_d, (box_d_min, box_d_max) in zip(a, b, box)])
    return _box_metric
bt = BallTree(X, metric=box_metric(box))
bt.query_radius(X[(2, 3), :], 0.)
search = rangesearch_box(X)
search(X[(2, 3), :], box)<jupyter_output><empty_output><jupyter_text>We find the same results for a given query.  Compare perf  Rangesearch init<jupyter_code>%timeit rangesearch_box(X)
%timeit BallTree(X, metric=box_metric(box))<jupyter_output>1000 loops, best of 3: 483 µs per loop
100 loops, best of 3: 9.95 ms per loop<jupyter_text>Query a few points<jupyter_code>%timeit search(X[(2, 6, 10), :], box)
%timeit bt.query_radius(X[(2, 6, 10), :], 0.)<jupyter_output>1000 loops, best of 3: 331 µs per loop
100 loops, best of 3: 7.91 ms per loop<jupyter_text>Query more points<jupyter_code>y = np.random.rand(500, ndim)

%timeit search(y, box)
%timeit bt.query_radius(y, 0.)<jupyter_output>10 loops, best of 3: 38.3 ms per loop
1 loop, best of 3: 1.3 s per loop
{'fraction_non_alphanumeric': 0.13083451202263083, 'fraction_numerical': 0.04526166902404526, 'mean_word_length': 5.5813953488372094, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '598526', 'license': 'MIT', 'n_tokens_mistral': 604, 'n_tokens_neox': 555, 'n_words': 161, 'path': 'demo.ipynb', 'repo_name': 'pelodelfuego/rangesearch-box', 'size': '1414'}