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

Method pad_test

tests/padders.py:58–92  ·  view source on GitHub ↗
(self, input_param, input_shape, expected_shape, modes=None)

Source from the content-addressed store, hash-verified

56 return np.random.randint(100, size=shape).astype(float)
57
58 def pad_test(self, input_param, input_shape, expected_shape, modes=None):
59 # loop over each mode
60 for mode in modes or MODES:
61 with self.subTest(mode=mode):
62 base_comparison = None
63 im = self.get_arr(input_shape)
64 padder = self.Padder(mode=mode, **input_param)
65 is_map = isinstance(padder, MapTransform)
66 # check result is the same regardless of input type
67 for im_type in TEST_NDARRAYS_ALL:
68 with self.subTest(im_type=im_type):
69 input_image = im_type(im)
70 input_data = {"img": im_type(im)} if is_map else im_type(im)
71 # our array transforms can also take `mode` as an argument to `__call__`
72 # Check this gives equivalent results
73 for call_extra_args in [{}] if is_map else [{}, {"mode": mode}]:
74 with self.subTest(call_extra_args=call_extra_args):
75 r_out = padder(input_data, **call_extra_args)
76 r_im = r_out["img"] if is_map else r_out
77 # check shape, type, etc.
78 np.testing.assert_allclose(r_im.shape, expected_shape)
79 self.assertIsInstance(r_im, MetaTensor)
80 self.assertEqual(len(r_im.applied_operations), 1)
81 # check results are same regardless of input type
82 if base_comparison is None:
83 base_comparison = r_im
84 else:
85 assert_allclose(r_im, base_comparison)
86 # test inverse
87 if isinstance(r_im, MetaTensor):
88 r_out = padder.inverse(r_out)
89 r_im = r_out["img"] if is_map else r_out
90 self.assertIsInstance(r_im, MetaTensor)
91 assert_allclose(r_im, input_image, type_test=False)
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:

Callers 6

test_padMethod · 0.80
test_padMethod · 0.80
test_padMethod · 0.80
test_padMethod · 0.80
test_padMethod · 0.80
test_padMethod · 0.80

Calls 3

get_arrMethod · 0.95
assert_allcloseFunction · 0.90
inverseMethod · 0.45

Tested by 6

test_padMethod · 0.64
test_padMethod · 0.64
test_padMethod · 0.64
test_padMethod · 0.64
test_padMethod · 0.64
test_padMethod · 0.64