Skip to content

BUG: Fix in-place aliasing and double transform in mni2tal - #968

Merged
ntustison merged 1 commit into
ANTsX:mainfrom
chenyangsu:fix/mni2tal-list-aliasing
Nov 29, 2026
Merged

ntustison merged 1 commit into
ANTsX:mainfrom
chenyangsu:fix/mni2tal-list-aliasing

Conversation

@chenyangsu

Copy link
Copy Markdown
Contributor

ants.mni2tal((10, 12, 14)) returns [-9.9, -10.9816, 13.3972076] instead of [-9.9, -10.9816, 13.4466], and ants.mni2tal((10, -100, 1)) returns [-9.801, 93.743064, -7.719646] instead of [-9.9, 96.926, -3.9311], compared against Brett's mni2tal matrices and ANTsX/ANTsR/R/mni2tal.R. Because xout = x aliases the list, writing xout[1] mutates x[1] before xout[2] reads it, and a negative xout[2] triggers the second if (x[2] < 0) branch.

Copy x into xout and use else for x[2] < 0, with unit tests in tests/test_utils.py. Happy to move them to tests/test_bugs.py if you prefer.

Testing: pytest -q tests/test_utils.py -k TestModule_mni2tal (3 passed; all 3 failed on main).

@ntustison

Copy link
Copy Markdown
Member

Thanks for this.

@ntustison
ntustison merged commit 03b7071 into ANTsX:main Nov 29, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants