Skip to content

Commit fb5b7f2

Browse files
docs(transforms): update spatial_resample docstrings for None spatial_size (#9068)
Signed-off-by: Luchang Jiang <auroral.sunflower@gmail.com>
1 parent 3b23fa1 commit fb5b7f2

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

monai/transforms/spatial/functional.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ def spatial_resample(
117117
Args:
118118
img: data to be resampled, assuming `img` is channel-first.
119119
dst_affine: target affine matrix, if None, use the input affine matrix, effectively no resampling.
120-
spatial_size: output spatial size, if the component is ``-1``, use the corresponding input spatial size.
120+
spatial_size: output spatial size. Components set to ``-1`` or ``None`` use the corresponding input
121+
spatial dimension. If the entire value is ``None``, the output size is computed automatically when
122+
possible, otherwise the input spatial shape is used.
121123
mode: {``"bilinear"``, ``"nearest"``} or spline interpolation order 0-5 (integers).
122124
Interpolation mode to calculate output values.
123125
See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html

tests/transforms/test_spatial_resample.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ def test_unchange(self):
231231
set_track_meta(True)
232232

233233
def test_none_spatial_size_rank_one(self):
234+
"""Verify that an unspecified rank-one size preserves the input shape and returns finite values."""
234235
img = MetaTensor(torch.randn(1, 8))
235236
result = SpatialResample()(img, spatial_size=None)
236237

@@ -239,6 +240,7 @@ def test_none_spatial_size_rank_one(self):
239240
self.assertTrue(torch.isfinite(result).all())
240241

241242
def test_partial_none_spatial_size(self):
243+
"""Verify that ``None`` dimensions fall back while specified dimensions produce the requested shape."""
242244
img = MetaTensor(torch.randn(1, 3, 6, 7))
243245
result = SpatialResample()(img, spatial_size=(None, 4, 5))
244246

0 commit comments

Comments
 (0)