MCPcopy Create free account
hub / github.com/NVIDIA/MinkowskiEngine / test_extraction

Method test_extraction

tests/python/sparse_tensor.py:189–230  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

187 self.assertTrue(len(sinput.slice(sinput)) == len(coords))
188
189 def test_extraction(self):
190 print(f"{self.__class__.__name__}: test_extraction")
191 coords = torch.IntTensor([[0, 0], [0, 1], [0, 2], [2, 0], [2, 2]])
192 feats = torch.FloatTensor([[1.1, 2.1, 3.1, 4.1, 5.1]]).t()
193 X = SparseTensor(feats, coords)
194 C0 = X.coordinates_at(0)
195 F0 = X.features_at(0)
196 self.assertTrue(0 in C0)
197 self.assertTrue(1 in C0)
198 self.assertTrue(2 in C0)
199
200 self.assertTrue(1.1 in F0)
201 self.assertTrue(2.1 in F0)
202 self.assertTrue(3.1 in F0)
203
204 CC0, FC0 = X.coordinates_and_features_at(0)
205 self.assertTrue((C0 == CC0).all())
206 self.assertTrue((F0 == FC0).all())
207
208 coords, feats = X.decomposed_coordinates_and_features
209 for c, f in zip(coords, feats):
210 self.assertEqual(c.numel(), f.numel())
211 print(c, f)
212 self.assertEqual(len(coords[0]), 3)
213 self.assertEqual(len(coords[1]), 0)
214 self.assertEqual(len(coords[2]), 2)
215
216 if not is_cuda_available():
217 return
218
219 coords = torch.IntTensor([[0, 0], [0, 1], [0, 2], [2, 0], [2, 2]])
220 feats = torch.FloatTensor([[1.1, 2.1, 3.1, 4.1, 5.1]]).t()
221
222 X = SparseTensor(feats, coords, device=0)
223 coords, feats = X.decomposed_coordinates_and_features
224 for c, f in zip(coords, feats):
225 self.assertEqual(c.numel(), f.numel())
226 print(c, f)
227
228 self.assertEqual(len(coords[0]), 3)
229 self.assertEqual(len(coords[1]), 0)
230 self.assertEqual(len(coords[2]), 2)
231
232 def test_features_at_coordinates(self):
233 print(f"{self.__class__.__name__}: test_features_at_coordinates")

Callers

nothing calls this directly

Calls 5

SparseTensorClass · 0.90
is_cuda_availableFunction · 0.85
coordinates_atMethod · 0.80
features_atMethod · 0.80

Tested by

no test coverage detected