Skip to content

Commit

Permalink
Merge pull request #226 from effigies/fix/chain_detection
Browse files Browse the repository at this point in the history
FIX: Do not treat iterable transforms as iterables of transforms when adding to a chain
  • Loading branch information
effigies committed Sep 21, 2024
2 parents e9b46cf + 7bc22c5 commit 40724fc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nitransforms/manip.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ def _as_chain(x):
"""Convert a value into a transform chain."""
if isinstance(x, TransformChain):
return x.transforms
if isinstance(x, TransformBase):
return [x]
if isinstance(x, Iterable):
return list(x)
return [x]
Expand Down
14 changes: 14 additions & 0 deletions nitransforms/tests/test_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ def test_loadsave_itk(tmp_path, data_path, testdata_path):
)


def test_mapping_chain(data_path):
xfm = nitl.load(data_path / "itktflist2.tfm", fmt="itk")
xfm = nitl.load(data_path / "itktflist2.tfm", fmt="itk")
assert len(xfm) == 9

# Addiition produces a chain
chain = xfm + xfm
# Length now means number of transforms, not number of affines in one transform
assert len(chain) == 2
# Just because a LinearTransformsMapping is iterable does not mean we decompose it
chain += xfm
assert len(chain) == 3


@pytest.mark.parametrize(
"image_orientation",
[
Expand Down

0 comments on commit 40724fc

Please sign in to comment.