예제 #1
0
파일: test_utils.py 프로젝트: molmod/hipart
def test_grid_distances():
    N = 10
    p = numpy.random.normal(0, 1, (N, 3))
    c = numpy.random.normal(0, 1, (3,))
    d1 = numpy.sqrt(((p - c) ** 2).sum(axis=1))
    d2 = numpy.zeros(d1.shape, float)
    grid_distances(c, p, d2)
    error = abs(d1 - d2).max()
    assert error < 1e-5
예제 #2
0
def test_grid_distances():
    N = 10
    p = numpy.random.normal(0, 1, (N, 3))
    c = numpy.random.normal(0, 1, (3, ))
    d1 = numpy.sqrt(((p - c)**2).sum(axis=1))
    d2 = numpy.zeros(d1.shape, float)
    grid_distances(c, p, d2)
    error = abs(d1 - d2).max()
    assert (error < 1e-5)
예제 #3
0
 def __getitem__(self, index):
     if self.save_mem:
         # in case we want to save memory, the grid distances are always
         # computed from scratch. For reasons of efficiency, the same result
         # array is used to avoid repetetive memory allocation
         grid_distances(self.centers[index], self.grid.points, self._result)
         return self._result
     else:
         result = self._cache.get(index)
         if result is None:
             result = numpy.zeros(self.grid.size, float)
             grid_distances(self.centers[index], self.grid.points, result)
             self._cache[index] = result
         return result