| 92 | self.assertEqual(r_im.applied_operations, []) |
| 93 | |
| 94 | def pad_test_kwargs(self, unchanged_slices, **input_param): |
| 95 | for im_type in TEST_NDARRAYS_ALL: |
| 96 | with self.subTest(im_type=im_type): |
| 97 | for kwargs in ({"value": 2}, {"constant_values": ((0, 0), (1, 1), (2, 2))}): |
| 98 | with self.subTest(kwargs=kwargs): |
| 99 | im = im_type(np.random.randint(-100, -10, size=(3, 8, 4))) |
| 100 | padder = self.Padder(**input_param, **kwargs) |
| 101 | result = padder(im) |
| 102 | if isinstance(result, torch.Tensor): |
| 103 | result = result.cpu() |
| 104 | assert_allclose(result[unchanged_slices], im, type_test=False) |
| 105 | # we should have the same as the input plus some 2s (if value) or 1s and 2s (if constant_values) |
| 106 | if isinstance(im, torch.Tensor): |
| 107 | im = im.detach().cpu().numpy() |
| 108 | expected_vals = np.unique(im).tolist() |
| 109 | expected_vals += [2] if "value" in kwargs else [1, 2] |
| 110 | assert_allclose(np.unique(result), expected_vals, type_test=False) |
| 111 | # check inverse |
| 112 | if isinstance(result, MetaTensor): |
| 113 | inv = padder.inverse(result) |
| 114 | assert_allclose(im, inv, type_test=False) |
| 115 | self.assertEqual(inv.applied_operations, []) |
| 116 | |
| 117 | def pad_test_pending_ops(self, input_param, input_shape): |
| 118 | for mode in TESTS_PENDING_MODE: |