(
self,
init_param: dict,
img: torch.Tensor,
affine: torch.Tensor,
data_param: dict,
expected_output: torch.Tensor,
device: torch.device,
)
| 228 | class TestSpacingCase(unittest.TestCase): |
| 229 | @parameterized.expand(TESTS) |
| 230 | def test_spacing( |
| 231 | self, |
| 232 | init_param: dict, |
| 233 | img: torch.Tensor, |
| 234 | affine: torch.Tensor, |
| 235 | data_param: dict, |
| 236 | expected_output: torch.Tensor, |
| 237 | device: torch.device, |
| 238 | ): |
| 239 | img = MetaTensor(img, affine=affine).to(device) |
| 240 | tr = Spacing(**init_param) |
| 241 | call_param = data_param.copy() |
| 242 | call_param["data_array"] = img |
| 243 | res: MetaTensor = tr(**call_param) # type: ignore |
| 244 | self.assertEqual(img.device, res.device) |
| 245 | |
| 246 | test_resampler_lazy(tr, res, init_param=init_param, call_param=call_param) |
| 247 | |
| 248 | if callable(expected_output): |
| 249 | expected_output = expected_output(device) |
| 250 | assert_allclose(res, expected_output, atol=1e-1, rtol=1e-1) |
| 251 | sr = min(len(res.shape) - 1, 3) |
| 252 | if isinstance(init_param["pixdim"], float): |
| 253 | init_param["pixdim"] = [init_param["pixdim"]] * sr |
| 254 | init_pixdim = init_param["pixdim"][:sr] |
| 255 | norm = affine_to_spacing(res.affine, sr).cpu().numpy() |
| 256 | assert_allclose(fall_back_tuple(init_pixdim, norm), norm, type_test=False) # type: ignore |
| 257 | |
| 258 | @parameterized.expand(TESTS_TORCH) |
| 259 | def test_spacing_torch(self, pixdim, img, track_meta: bool): |
nothing calls this directly
no test coverage detected