Skip to content

Commit 40724fc

Browse files
authoredSep 21, 2024··
Merge pull request #226 from effigies/fix/chain_detection
FIX: Do not treat iterable transforms as iterables of transforms when adding to a chain
2 parents e9b46cf + 7bc22c5 commit 40724fc

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed
 

‎nitransforms/manip.py

+2
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ def _as_chain(x):
213213
"""Convert a value into a transform chain."""
214214
if isinstance(x, TransformChain):
215215
return x.transforms
216+
if isinstance(x, TransformBase):
217+
return [x]
216218
if isinstance(x, Iterable):
217219
return list(x)
218220
return [x]

‎nitransforms/tests/test_linear.py

+14
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ def test_loadsave_itk(tmp_path, data_path, testdata_path):
8282
)
8383

8484

85+
def test_mapping_chain(data_path):
86+
xfm = nitl.load(data_path / "itktflist2.tfm", fmt="itk")
87+
xfm = nitl.load(data_path / "itktflist2.tfm", fmt="itk")
88+
assert len(xfm) == 9
89+
90+
# Addiition produces a chain
91+
chain = xfm + xfm
92+
# Length now means number of transforms, not number of affines in one transform
93+
assert len(chain) == 2
94+
# Just because a LinearTransformsMapping is iterable does not mean we decompose it
95+
chain += xfm
96+
assert len(chain) == 3
97+
98+
8599
@pytest.mark.parametrize(
86100
"image_orientation",
87101
[

0 commit comments

Comments
 (0)
Please sign in to comment.