2323from monai .data .utils import to_affine_nd
2424from monai .transforms import SpatialResample
2525from monai .utils import optional_import
26- from tests .lazy_transforms_utils import test_resampler_lazy
26+ from tests .lazy_transforms_utils import test_resampler_lazy as check_resampler_lazy
2727from tests .test_utils import TEST_DEVICES , TEST_NDARRAYS_ALL , assert_allclose , dict_product
2828
2929TESTS = []
@@ -148,7 +148,7 @@ def test_flips(self, img, device, data_param, expected_output):
148148 assert_allclose (out , expected_output , rtol = 1e-2 , atol = 1e-2 )
149149 assert_allclose (to_affine_nd (len (out .shape ) - 1 , out .affine ), call_param ["dst_affine" ])
150150
151- test_resampler_lazy (resampler , out , init_param = None , call_param = call_param )
151+ check_resampler_lazy (resampler , out , init_param = None , call_param = call_param )
152152
153153 @parameterized .expand (TEST_4_5_D )
154154 def test_4d_5d (self , new_shape , tile , device , dtype , expected_data ):
@@ -165,7 +165,7 @@ def test_4d_5d(self, new_shape, tile, device, dtype, expected_data):
165165 assert_allclose (out , expected_data [None ], rtol = 1e-2 , atol = 1e-2 )
166166 assert_allclose (out .affine , dst .to (torch .float32 ), rtol = 1e-2 , atol = 1e-2 )
167167
168- test_resampler_lazy (resampler , out , init_param , call_param )
168+ check_resampler_lazy (resampler , out , init_param , call_param )
169169
170170 @parameterized .expand (TEST_DEVICES )
171171 def test_ill_affine (self , device ):
@@ -199,7 +199,7 @@ def test_input_torch(self, new_shape, tile, device, dtype, expected_data, track_
199199 out = resampler (** call_param )
200200 assert_allclose (out , expected_data [None ], rtol = 1e-2 , atol = 1e-2 )
201201
202- test_resampler_lazy (resampler , out , init_param , call_param )
202+ check_resampler_lazy (resampler , out , init_param , call_param )
203203
204204 if track_meta :
205205 self .assertIsInstance (out , MetaTensor )
@@ -230,6 +230,22 @@ def test_unchange(self):
230230 assert_allclose (result , img , type_test = False )
231231 set_track_meta (True )
232232
233+ def test_none_spatial_size_rank_one (self ):
234+ img = MetaTensor (torch .randn (1 , 8 ))
235+ result = SpatialResample ()(img , spatial_size = None )
236+
237+ self .assertEqual (result .shape , img .shape )
238+ self .assertIsInstance (result , MetaTensor )
239+ self .assertTrue (torch .isfinite (result ).all ())
240+
241+ def test_partial_none_spatial_size (self ):
242+ img = MetaTensor (torch .randn (1 , 3 , 6 , 7 ))
243+ result = SpatialResample ()(img , spatial_size = (None , 4 , 5 ))
244+
245+ self .assertEqual (result .shape , (1 , 3 , 4 , 5 ))
246+ self .assertIsInstance (result , MetaTensor )
247+ self .assertTrue (torch .isfinite (result ).all ())
248+
233249
234250if __name__ == "__main__" :
235251 unittest .main ()
0 commit comments