def test_device2(self): print(f"{self.__class__.__name__}: test_device2 SparseTensor") if not is_cuda_available(): return coordinates = np.random.rand(8192,3) * 200 quant_coordinates, quant_features = sparse_quantize(coordinates, coordinates) bcoords, bfeats = sparse_collate([quant_coordinates], [quant_features]) bcoords, bfeats = bcoords.cuda(), bfeats.cuda() print(bcoords, bfeats) SparseTensor(bfeats, bcoords)
def test_device(self): if not is_cuda_available(): return coords = torch.IntTensor([[0, 1], [0, 1], [0, 2], [0, 2], [1, 0], [1, 0], [1, 1]]) feats = torch.FloatTensor([[0, 1, 2, 3, 5, 6, 7]]).T SparseTensor(feats, coords) SparseTensor(feats.to(0), coords.to(0)) feats = torch.FloatTensor([[0, 1, 2, 3, 5, 6, 7]]).T.to(0) st = SparseTensor(feats, coords, device=feats.device) print(st)
def test_device_unique(self): print(f"{self.__class__.__name__}: test_device_unique SparseTensor") if not is_cuda_available(): return coords = torch.IntTensor( [[0, 1], [0, 2], [0, 3], [0, 4], [1, 0], [1, 1], [1, 2]] ) feats = torch.FloatTensor([[0, 1, 2, 3, 5, 6, 7]]).T SparseTensor(feats.to(0), coords.to(0)) feats = torch.FloatTensor([[0, 1, 2, 3, 5, 6, 7]]).T.to(0) st = SparseTensor(feats, coords, device=feats.device) print(st)
def test_extraction(self): print(f"{self.__class__.__name__}: test_extraction") coords = torch.IntTensor([[0, 0], [0, 1], [0, 2], [2, 0], [2, 2]]) feats = torch.FloatTensor([[1.1, 2.1, 3.1, 4.1, 5.1]]).t() X = SparseTensor(feats, coords) C0 = X.coordinates_at(0) F0 = X.features_at(0) self.assertTrue(0 in C0) self.assertTrue(1 in C0) self.assertTrue(2 in C0) self.assertTrue(1.1 in F0) self.assertTrue(2.1 in F0) self.assertTrue(3.1 in F0) CC0, FC0 = X.coordinates_and_features_at(0) self.assertTrue((C0 == CC0).all()) self.assertTrue((F0 == FC0).all()) coords, feats = X.decomposed_coordinates_and_features for c, f in zip(coords, feats): self.assertEqual(c.numel(), f.numel()) print(c, f) self.assertEqual(len(coords[0]), 3) self.assertEqual(len(coords[1]), 0) self.assertEqual(len(coords[2]), 2) if not is_cuda_available(): return coords = torch.IntTensor([[0, 0], [0, 1], [0, 2], [2, 0], [2, 2]]) feats = torch.FloatTensor([[1.1, 2.1, 3.1, 4.1, 5.1]]).t() X = SparseTensor(feats, coords, device=0) coords, feats = X.decomposed_coordinates_and_features for c, f in zip(coords, feats): self.assertEqual(c.numel(), f.numel()) print(c, f) self.assertEqual(len(coords[0]), 3) self.assertEqual(len(coords[1]), 0) self.assertEqual(len(coords[2]), 2)