MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / test_tensor_values

Method test_tensor_values

tests/transforms/test_copy_itemsd.py:51–62  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

49 self.assertTrue(name in result)
50
51 def test_tensor_values(self):
52 device = torch.device("cuda:0") if torch.cuda.is_available() else torch.device("cpu:0")
53 input_data = {
54 "img": torch.tensor([[0, 1], [1, 2]], device=device),
55 "seg": torch.tensor([[0, 1], [1, 2]], device=device),
56 }
57 # test default `times=1`
58 result = CopyItemsd(keys="img", names="img_1")(input_data)
59 self.assertTrue("img_1" in result)
60 result["img_1"] += 1
61 assert_allclose(result["img"], torch.tensor([[0, 1], [1, 2]], device=device))
62 assert_allclose(result["img_1"], torch.tensor([[1, 2], [2, 3]], device=device))
63
64 def test_array_values(self):
65 input_data = {"img": [[0, 1], [1, 2]], "seg": [[0, 1], [1, 2]]}

Callers

nothing calls this directly

Calls 2

CopyItemsdClass · 0.90
assert_allcloseFunction · 0.90

Tested by

no test coverage detected