device, dtype
(self, device=None, dtype=None)
| 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 | |
| 565 | if __name__ == "__main__": |
nothing calls this directly
no test coverage detected