def furthest_point_sample(xyz, npoint): # type: (Any, torch.Tensor, int) -> torch.Tensor r""" Uses iterative furthest point sampling to select a set of npoint features that have the largest minimum distance Parameters ---------- xyz : torch.Tensor (B, N, 3) tensor where N > npoint npoint : int32 number of features in the sampled set Returns ------- torch.Tensor (B, npoint) tensor containing the set """ if npoint > xyz.shape[1]: raise ValueError( "caanot sample %i points from an input set of %i points" % (npoint, xyz.shape[1])) if xyz.is_cuda: return tpcuda.furthest_point_sampling(xyz, npoint) else: return tpcpu.fps(xyz, npoint, True)
def test_random(self): points = torch.randn(10, 100, 3) idx = fps(points, 2, True) self.assertNotEqual(idx[0][0], 0)
def test_simplecpu(self): points = torch.tensor([[[0, 0, 0], [1, 0, 0], [2, 0, 0]], [[-1, 1, 0], [0, 0, 10], [0, 0, 2]]]).float() idx = fps(points, 2, False) torch.testing.assert_allclose(idx, torch.tensor([[0, 2], [0, 1]]))