def test_all_search(nr_points, dim, bucket_size, query_radius): """Test fixed neighbor search. Search all point pairs that are within radius. Arguments: - nr_points: number of points used in test - dim: dimension of coords - bucket_size: nr of points per tree node - query_radius: radius of search Returns true if the test passes. """ kdt = KDTree(dim, bucket_size) coords = random.random((nr_points, dim)) kdt.set_coords(coords) kdt.all_search(query_radius) indices = kdt.all_get_indices() if indices is None: l1 = 0 else: l1 = len(indices) radii = kdt.all_get_radii() if radii is None: l2 = 0 else: l2 = len(radii) if l1 == l2: return True else: return False
def test_search(nr_points, dim, bucket_size, radius): """Test search all points within radius of center. Search all point pairs that are within radius. Arguments: - nr_points: number of points used in test - dim: dimension of coords - bucket_size: nr of points per tree node - radius: radius of search Returns true if the test passes. """ kdt = KDTree(dim, bucket_size) coords = random.random((nr_points, dim)) kdt.set_coords(coords) kdt.search(coords[0], radius * 100) radii = kdt.get_radii() l1 = 0 for i in range(0, nr_points): p = coords[i] if _dist(p, coords[0]) <= radius * 100: l1 = l1 + 1 if l1 == len(radii): return True else: return False
def test_KDTree_exceptions(self): kdt = KDTree(dim, bucket_size) with self.assertRaises(Exception) as context: kdt.set_coords(random.random((nr_points, dim)) * 100000000000000) self.assertTrue("Points should lie between -1e6 and 1e6" in str(context.exception)) with self.assertRaises(Exception) as context: kdt.set_coords(random.random((nr_points, dim - 2))) self.assertTrue("Expected a Nx%i NumPy array" % dim in str(context.exception)) with self.assertRaises(Exception) as context: kdt.search(array([0, 0, 0]), radius) self.assertTrue("No point set specified" in str(context.exception))