Skip to content

Commit ac9b186

Browse files
authored
Always convert input to C-order in distance_transform_edt (#7675)
Fixes #7660 `indices_` may not always be a shallow copy for F-order input as it constantly converts to C-order https://github.com/Project-MONAI/MONAI/blob/ffd4454b576abd4eaae30b364f41c213e30dca4c/monai/transforms/utils.py#L2209 https://github.com/Project-MONAI/MONAI/blob/ffd4454b576abd4eaae30b364f41c213e30dca4c/monai/utils/type_conversion.py#L262 ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
1 parent 178ebc8 commit ac9b186

2 files changed

Lines changed: 2 additions & 3 deletions

File tree

monai/transforms/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2190,7 +2190,7 @@ def distance_transform_edt(
21902190
if return_distances:
21912191
dtype = torch.float64 if float64_distances else torch.float32
21922192
if distances is None:
2193-
distances = torch.zeros_like(img, dtype=dtype) # type: ignore
2193+
distances = torch.zeros_like(img, memory_format=torch.contiguous_format, dtype=dtype) # type: ignore
21942194
else:
21952195
if not isinstance(distances, torch.Tensor) and distances.device != img.device:
21962196
raise TypeError("distances must be a torch.Tensor on the same device as img")

tests/test_clip_intensity_percentiles.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from monai.transforms import ClipIntensityPercentiles
1919
from monai.transforms.utils import soft_clip
2020
from monai.transforms.utils_pytorch_numpy_unification import clip, percentile
21-
from monai.utils.type_conversion import convert_to_tensor
2221
from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, NumpyImageTestCase3D, assert_allclose
2322

2423

@@ -30,7 +29,7 @@ def test_hard_clipping_two_sided(self, p):
3029
im = p(self.imt)
3130
result = hard_clipper(im)
3231
lower, upper = percentile(im, (5, 95))
33-
expected = clip(convert_to_tensor(im), lower, upper)
32+
expected = clip(im, lower, upper)
3433
assert_allclose(result, p(expected), type_test="tensor", rtol=1e-4, atol=0)
3534

3635
@parameterized.expand([[p] for p in TEST_NDARRAYS])

0 commit comments

Comments
 (0)