Skip to content

Commit 08a1cce

Browse files
committed
Merge remote-tracking branch 'upstream/dev' into 8587-test-erros-on-pytorch-release-2508-on-series-50
2 parents d30be44 + cc92126 commit 08a1cce

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

.github/workflows/pythonapp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ jobs:
8282
find /opt/hostedtoolcache/* -maxdepth 0 ! -name 'Python' -exec rm -rf {} \;
8383
- name: Install the dependencies
8484
run: |
85-
python -m pip install --user --upgrade pip wheel
85+
python -m pip install --user --upgrade pip wheel pybind11
8686
python -m pip install torch==2.5.1 torchvision==0.20.1
8787
cat "requirements-dev.txt"
8888
python -m pip install --no-build-isolation -r requirements-dev.txt

monai/data/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ def compute_shape_offset(
881881
Default is False, using option 1 to compute the shape and offset.
882882
883883
"""
884-
shape = np.array(spatial_shape, copy=True, dtype=float)
884+
shape = np.array(tuple(spatial_shape), copy=True, dtype=float)
885885
sr = len(shape)
886886
in_affine_ = convert_data_type(to_affine_nd(sr, in_affine), np.ndarray)[0]
887887
out_affine_ = convert_data_type(to_affine_nd(sr, out_affine), np.ndarray)[0]

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ black==25.1.0
1818
isort>=5.1, <6, !=6.0.0
1919
ruff>=0.14.11,<0.15
2020
pytype>=2020.6.1, <=2024.4.11; platform_system != "Windows"
21+
pybind11
2122
types-setuptools
2223
mypy>=1.5.0, <1.12.0
2324
ninja
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright (c) MONAI Consortium
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
# Unless required by applicable law or agreed to in writing, software
7+
# distributed under the License is distributed on an "AS IS" BASIS,
8+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
# See the License for the specific language governing permissions and
10+
# limitations under the License.
11+
12+
from __future__ import annotations
13+
14+
import unittest
15+
16+
import numpy as np
17+
import torch
18+
19+
from monai.data.utils import compute_shape_offset
20+
21+
22+
class TestComputeShapeOffsetRegression(unittest.TestCase):
23+
"""Regression tests for `compute_shape_offset` input-shape handling."""
24+
25+
def test_pytorch_size_input(self):
26+
"""Validate `torch.Size` input produces expected shape and offset.
27+
28+
Returns:
29+
None.
30+
31+
Raises:
32+
AssertionError: If computed shape/offset are not as expected.
33+
"""
34+
# 1. Create a PyTorch Size object (which triggered the original bug)
35+
spatial_shape = torch.Size([10, 10, 10])
36+
in_affine = np.eye(4)
37+
out_affine = np.eye(4)
38+
39+
# 2. Feed it into the function
40+
shape, offset = compute_shape_offset(spatial_shape, in_affine, out_affine)
41+
42+
# 3. Prove it successfully processed the shape by checking its length
43+
self.assertEqual(len(shape), 3)
44+
45+
46+
if __name__ == "__main__":
47+
unittest.main()

0 commit comments

Comments
 (0)