Restore statistical padding modes - #1499
Merged
Merged
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4c079ff0-a235-45de-b35d-154ca4812d34
Contributor
📖 Docs PreviewPreview of the documentation for this PR: 🔗 https://smokeshow.helpmanual.io/6v6d5j42573u4d5u6q4l/ Built from 79e565c |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4c079ff0-a235-45de-b35d-154ca4812d34
Contributor
There was a problem hiding this comment.
Pull request overview
This PR restores statistical padding modes (mean, median, minimum) for Pad and CropOrPad, ensuring consistent whole-volume/per-subject statistics across eager, batched, and lazy execution paths while preserving existing dtype/device/affine behavior.
Changes:
- Adds validation and implementation for statistical padding modes in
Pad, including integer-truncation warnings formean/median. - Reuses the same padding logic in
CropOrPad(eager + lazy paths) to keep behavior consistent. - Adds targeted test coverage for invalid modes, statistics correctness, batching, lazy backend behavior, and truncation warnings.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tests/test_pad.py | Adds tests for statistical modes, batching behavior, integer truncation warnings, and differentiability. |
| tests/test_crop_or_pad.py | Adds tests for statistical padding in tensor and lazy-backend paths. |
| src/torchio/transforms/spatial/pad.py | Introduces validated PaddingMode, statistical value computation, and a shared _pad_tensor implementation. |
| src/torchio/transforms/spatial/crop_or_pad.py | Switches eager/lazy padding to use the shared pad helper and validates padding mode. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fepegar
force-pushed
the
fepegar/restore-statistical-padding-modes
branch
from
July 20, 2026 16:17
b98068e to
20699a4
Compare
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4c079ff0-a235-45de-b35d-154ca4812d34
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4c079ff0-a235-45de-b35d-154ca4812d34
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4c079ff0-a235-45de-b35d-154ca4812d34
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4c079ff0-a235-45de-b35d-154ca4812d34
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4c079ff0-a235-45de-b35d-154ca4812d34
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4c079ff0-a235-45de-b35d-154ca4812d34
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4c079ff0-a235-45de-b35d-154ca4812d34
Comment on lines
+33
to
+38
| if not 0 <= q <= 1: | ||
| msg = f"Only values 0 <= q <= 1 are supported, but got {q!r}" | ||
| raise ValueError(msg) | ||
| index = q * (values.numel() - 1) | ||
| lower = math.floor(index) | ||
| lower_value = torch.kthvalue(values, lower + 1).values |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[Generated by a coding agent]
Summary
mean,median, andminimumpadding modes inPadandCropOrPadTesting
uv run --group test pytest tests/test_pad.py tests/test_crop_or_pad.py -qmise run quality