Пример #1
0
 def test_knn(self):
     """testing k-nearest neighbors.
     """
     sqd = np.sum(np.power((self.arr - self.point), 2), axis=1)
     sorted_idx = sqd.argsort()
     kdt = ckd3.KDTree(self.arr)
     points, dists = kdt.knn(self.point, 5)
     self.assertEqualItems(sorted_idx[:5], points)
Пример #2
0
 def test_instance(self):
     """check if KDTree instance behaves correctly."""
     kdt = ckd3.KDTree(self.arr)
     self.assertEqual(kdt.dims, 3)
     def assig():
         kdt.dims = 4
     self.assertRaises(AttributeError, assig)
     self.assertEqual(kdt.dims, 3)
     self.assertEqual(kdt.pnts, 1000)
Пример #3
0
 def test_rn(self):
     """testing neighbors within radius.
     """
     sqd = np.sum(np.power((self.arr - self.point), 2), axis=1)
     sqd = sqd[sqd <= 0.05]
     sqd.sort()
     kdt = ckd3.KDTree(self.arr)
     points, dists = kdt.rn(self.point, 0.05)
     dists.sort()
     self.assertFloatEqual(dists, sqd)