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

Method test

tests/python/tensor_field.py:39–69  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

37
38class TestTensorField(unittest.TestCase):
39 def test(self):
40 coords = torch.IntTensor(
41 [[0, 1], [0, 1], [0, 2], [0, 2], [1, 0], [1, 0], [1, 1]]
42 )
43 feats = torch.FloatTensor([[0, 1, 2, 3, 5, 6, 7]]).T
44 sfield = TensorField(feats, coords)
45
46 # Convert to a sparse tensor
47 stensor = sfield.sparse(
48 quantization_mode=SparseTensorQuantizationMode.UNWEIGHTED_AVERAGE
49 )
50 print(stensor)
51 self.assertTrue(
52 {0.5, 2.5, 5.5, 7} == {a for a in stensor.F.squeeze().detach().numpy()}
53 )
54
55 # device cuda
56 if not torch.cuda.is_available():
57 return
58
59 sfield = TensorField(feats, coords, device="cuda")
60
61 # Convert to a sparse tensor
62 stensor = sfield.sparse(
63 quantization_mode=SparseTensorQuantizationMode.UNWEIGHTED_AVERAGE
64 )
65 print(stensor)
66 self.assertTrue(
67 {0.5, 2.5, 5.5, 7}
68 == {a for a in stensor.F.squeeze().detach().cpu().numpy()}
69 )
70
71 def test_maxpool(self):
72 coords = torch.IntTensor(

Callers

nothing calls this directly

Calls 3

sparseMethod · 0.95
TensorFieldClass · 0.90
detachMethod · 0.80

Tested by

no test coverage detected