-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix spatial_resample TypeError on None spatial_size with rank 1 #9070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -222,6 +222,16 @@ def test_inverse(self, img, device, data_param, expected_output): | |
| expected_affine = to_affine_nd(len(out.affine) - 1, torch.eye(4)) | ||
| assert_allclose(out.affine, expected_affine) | ||
|
|
||
| def test_none_spatial_size_rank1(self): | ||
| # Regression for #9068: a 1D-spatial image with no ``spatial_size`` keeps | ||
| # ``spatial_size`` as None, and the fall_back_tuple predicate used to raise | ||
| # ``TypeError: '>=' not supported between 'NoneType' and 'int'`` instead of | ||
| # falling back to the input spatial size. | ||
| img = MetaTensor(torch.arange(4).reshape(1, 4).to(torch.float32), affine=torch.eye(2)) | ||
| dst_affine = torch.tensor([[2.0, 0.0], [0.0, 1.0]]) | ||
| out = SpatialResample()(img=img, dst_affine=dst_affine) | ||
| self.assertEqual(out.shape[0], 1) | ||
|
Comment on lines
+232
to
+233
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Assert the fallback spatial dimension. The test checks only the channel dimension, so it can pass with an incorrect output spatial size. Assert the complete expected shape, for example 🤖 Prompt for AI Agents |
||
|
|
||
| def test_unchange(self): | ||
| for i, p in enumerate(TEST_NDARRAYS_ALL): | ||
| set_track_meta(i % 2) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: Project-MONAI/MONAI
Length of output: 699
🏁 Script executed:
Repository: Project-MONAI/MONAI
Length of output: 3156
Add a Google-style docstring to
test_none_spatial_size_rank1.This new test method lacks a docstring. The applicable Python guideline requires docstrings for all definitions. This is a minor maintainability issue, not a major one.
Suggested fix
def test_none_spatial_size_rank1(self): + """Test 1D-spatial resampling without an explicit spatial size.""" # Regression for #9068: a 1D-spatial image with no ``spatial_size`` keeps📝 Committable suggestion
🤖 Prompt for AI Agents