Fix RandGridPatch whole-dimension patch sizes - #9048
Conversation
Signed-off-by: Rajioba1 <raji.lukmon@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
💤 Files with no reviewable changes (2)
📝 WalkthroughWalkthrough
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
monai/transforms/spatial/array.py (1)
3570-3570: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winMake the dimension contract explicit.
zipsilently truncates whenarray.shape[1:]andself.patch_sizehave different lengths. This can create an incompletemax_offsetand an invalidself.offset. Passstrict=True.Proposed fix
- max_offset = tuple(s % p if p else 0 for s, p in zip(array.shape[1:], self.patch_size)) + max_offset = tuple( + s % p if p else 0 + for s, p in zip(array.shape[1:], self.patch_size, strict=True) + )Ruff B905 identifies this call because it omits
strict=.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@monai/transforms/spatial/array.py` at line 3570, Update the max_offset computation in the relevant transform method to call zip with strict=True, ensuring array.shape[1:] and self.patch_size must have matching dimensions instead of being silently truncated.Source: Linters/SAST tools
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@monai/transforms/spatial/array.py`:
- Line 3570: Update the max_offset computation in the relevant transform method
to call zip with strict=True, ensuring array.shape[1:] and self.patch_size must
have matching dimensions instead of being silently truncated.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 1087d4fe-91b6-4634-bbc4-e4bffa33fc5a
📒 Files selected for processing (3)
monai/transforms/spatial/array.pytests/transforms/spatial/test_rand_grid_patch.pytests/transforms/spatial/test_rand_grid_patchd.py
Signed-off-by: Rajioba1 <raji.lukmon@gmail.com>
Fixes #9046.
Description
RandGridPatchdocuments thatpatch_sizeentries of0orNoneselect the whole dimension. Whenmax_offsetis omitted, the transform currently computes the default offset range withs % p, which raises for0andNonepatch dimensions.This PR treats whole-dimension patch entries as having zero random offset for that dimension, matching the documented behavior and
GridPatchbehavior. It adds regression coverage for bothRandGridPatchandRandGridPatchdwithpatch_size=(0, 2)andpatch_size=(None, 2).Types of changes
./runtests.sh -f -u --net --coverage../runtests.sh --quick --unittests --disttests.make htmlcommand in thedocs/folder.Local validation:
python -m tests.transforms.spatial.test_rand_grid_patchpython -m tests.transforms.spatial.test_rand_grid_patchdgit diff --checkNotes:
blackandisortwere not installed in my local Python environment, so I could not run those checks directly.python -m ruff check monai/transforms/spatial/array.py tests/transforms/spatial/test_rand_grid_patch.py tests/transforms/spatial/test_rand_grid_patchd.pyreports an unrelated pre-existingUP038warning inarray.pyoutside this PR's changed lines.