MCPcopy Index your code
hub / github.com/Project-MONAI/MONAI / test_numpy

Method test_numpy

tests/data/meta_tensor/test_meta_tensor.py:548–562  ·  view source on GitHub ↗

device, dtype

(self, device=None, dtype=None)

Source from the content-addressed store, hash-verified

546
547 @parameterized.expand(TESTS)
548 def test_numpy(self, device=None, dtype=None):
549 """device, dtype"""
550 t = MetaTensor([0 if dtype in (torch.int32, torch.int64) else 0.0], device=device, dtype=dtype)
551 self.assertIsInstance(t, MetaTensor)
552 assert_allclose(t.array, np.asarray([0.0]))
553 t.array = np.asarray([1.0])
554 self.check_meta(t, MetaTensor([1.0]))
555 assert_allclose(t.as_tensor(), torch.as_tensor([1.0]))
556 t.array = [2.0]
557 self.check_meta(t, MetaTensor([2.0]))
558 assert_allclose(t.as_tensor(), torch.as_tensor([2.0]))
559 if not t.is_cuda:
560 t.array[0] = torch.as_tensor(3 if dtype in (torch.int32, torch.int64) else 3.0, device=device, dtype=dtype)
561 self.check_meta(t, MetaTensor([3.0]))
562 assert_allclose(t.as_tensor(), torch.as_tensor([3.0]))
563
564
565if __name__ == "__main__":

Callers

nothing calls this directly

Calls 4

check_metaMethod · 0.95
as_tensorMethod · 0.95
MetaTensorClass · 0.90
assert_allcloseFunction · 0.90

Tested by

no test coverage detected