Example #1
0
 def collision_prepare(self):
     # self.spatial_grid = self.spatial_grid.update(self.position)
     # bounds = np.array([[-10]*3, [10]*3]).astype(np.float32)
     self.spec = spatial.Spec3d(self.position, self.scale)
     self.offsets = self.spec.stencil(self.stencil).astype(np.int32)
     self.spatial_grid = spatial.Grid3d(self.spec, self.position,
                                        self.offsets)
Example #2
0
def test_performance():
    # warmup run for mem allocation
    lengthscale = 0.03
    n = 300000
    points = np.random.rand(n, 3).astype(np.float32)
    spec = spatial.Spec3d(points, lengthscale)

    start = time.clock()
    grid = spatial.Grid3d(spec, points)
    warmup = time.clock() - start

    # run on unsorted data
    points = np.random.rand(n, 3).astype(np.float32)
    start = time.clock()
    grid = spatial.Grid3d(spec, points)
    unsorted = time.clock() - start

    # update from existing
    start = time.clock()
    grid = grid.update(points)
    update = time.clock() - start

    # sort data
    points = points[grid.permutation]

    # run on sorted data
    start = time.clock()
    grid = spatial.Grid3d(spec, points)
    sorted = time.clock() - start

    print(warmup, unsorted, update, sorted)
Example #3
0
 def get_spatial_grid(self):
     stencil = np.zeros((1), np.int32)
     return spatial.Grid3d(
         spatial.Spec3d(self.position, self.length_scale * 2),
         self.position, stencil)