def test_retrieve_all(): tree = RBush(4) tree.load(data_array) bbox = { 'xmin': -Infinity, 'ymin': -Infinity, 'xmax': Infinity, 'ymax': Infinity } items, _ = tree.search(**bbox) assert sorted_equal(items, data_array)
def test_find_matching_bbox(): # 'search' finds items intersecting and inside the given bbox tree = RBush(4) tree.load(data_array) items, _ = tree.search(xmin=40, ymin=20, xmax=80, ymax=70) compare_data = [[70, 20, 70, 20], [75, 25, 75, 25], [45, 45, 45, 45], [50, 50, 50, 50], [60, 60, 60, 60], [70, 70, 70, 70], [45, 20, 45, 20], [45, 70, 45, 70], [75, 50, 75, 50], [50, 25, 50, 25], [60, 35, 60, 35], [70, 45, 70, 45]] compare_data = np.asarray(compare_data) assert sorted_equal(items, compare_data)
def test_against_brute_force_numba(): b = RBush() data = generate_data_array(100000, 10) b.load(data) search_box = (-1, -1, 1, 1) c = search_brute_force(b.data, b.boxes, *search_box) t1 = time() c = search_brute_force(b.data, b.boxes, *search_box) c = search_brute_force(b.data, b.boxes, *search_box) c = search_brute_force(b.data, b.boxes, *search_box) t2 = time() print('BRUTE FORCE;', len(c), 'time: {:.5f}'.format(t2 - t1)) c, d = b.search(*search_box) rbush_t1 = time() c, d = b.search(*search_box) c, d = b.search(*search_box) c, d = b.search(*search_box) rbush_t2 = time() print('RBUSH;', len(c), 'time: {:.5f}'.format(rbush_t2 - rbush_t1)) assert rbush_t2 - rbush_t1 < t2 - t1, 'Sorry not fast enough yet'