Skip to content

Commit e1c69fa

Browse files
committed
Fix SplitDim spatial_ndim regression and stale duplicate test
b0397db passed no_channel=True to _normalize_spatial_ndim, which made the limit ndim instead of ndim-1 and broke test_spatial_ndim_channel_dim_no_decrement (expected 1, got 2). Revert to channel-first clamping in array.py (the c6a32b9 behavior) and update the duplicate assertion in tests/data/meta_tensor/test_spatial_ndim.py, which c6a32b9 missed, so both tests agree that SplitDim(dim=0, keepdim=False) on a (3,8,7) MetaTensor yields spatial_ndim=1. Signed-off-by: Soumya Snigdha Kundu <soumya_snigdha.kundu@kcl.ac.uk>
1 parent b0397db commit e1c69fa

2 files changed

Lines changed: 2 additions & 3 deletions

File tree

monai/transforms/utility/array.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,7 @@ def __call__(self, img: torch.Tensor) -> list[torch.Tensor]:
330330
outputs[idx] = out
331331
if dim == 0: # don't update affine if channel dim
332332
if not self.keepdim:
333-
# channel dim was squeezed out; remaining dims are all spatial
334-
out.spatial_ndim = _normalize_spatial_ndim(out.spatial_ndim, out.ndim, no_channel=True)
333+
out.spatial_ndim = _normalize_spatial_ndim(out.spatial_ndim, out.ndim)
335334
continue
336335
ndim = len(out.affine)
337336
shift = torch.eye(ndim, device=out.affine.device, dtype=out.affine.dtype)

tests/data/meta_tensor/test_spatial_ndim.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def test_splitdim_channel_dim_no_decrement(self):
100100
t = MetaTensor(torch.randn(3, 8, 7))
101101
for item in SplitDim(dim=0, keepdim=False)(t):
102102
if isinstance(item, MetaTensor):
103-
self.assertEqual(item.spatial_ndim, 2)
103+
self.assertEqual(item.spatial_ndim, 1)
104104

105105
def test_lazy_apply_pending_2d(self):
106106
"""apply_pending uses spatial_ndim for 2D data instead of hardcoded 3."""

0 commit comments

Comments
 (0)