def test_query_ball(): #tree = CoverTree(distance=lambda a, b: periodic_distance(np.array(a), np.array(b), np.array([10, 10, 10]))) tree = CoverTree(metric='periodic', metric_args={'cell_lengths': [10, 10, 10]}) np.random.seed(42) random.seed(42) positions = np.random.uniform(0, 5, (5000, 3)) np.set_printoptions(precision=2) for p in positions: # print 'inserting', p node = tree.insert(p) ref = (periodic_distance([1.0, 1.0, 1.0], positions, np.array([10, 10, 10])) < 3.0).nonzero()[0] res, dist = tree.query_ball([1, 1, 1], 3.0) #tree.check_invariant() #print ref, res eq_(len(ref), len(res))
def test_query_ball(): #tree = CoverTree(distance=lambda a, b: periodic_distance(np.array(a), np.array(b), np.array([10, 10, 10]))) tree = CoverTree(metric='periodic', metric_args={'cell_lengths': [10, 10, 10]}) np.random.seed(42) random.seed(42) positions = np.random.uniform(0, 5, (5000, 3)) np.set_printoptions(precision=2) for p in positions: # print 'inserting', p node = tree.insert(p) ref = (periodic_distance([1.0, 1.0, 1.0], positions, np.array( [10, 10, 10])) < 3.0).nonzero()[0] res, dist = tree.query_ball([1, 1, 1], 3.0) #tree.check_invariant() #print ref, res eq_(len(ref), len(res))
def test_speed(): tree = CoverTree(metric='periodic', metric_args={'cell_lengths': [10, 10, 10]}) positions = np.random.uniform(0, 10, (10000, 3)) for p in positions: tree.insert(p)