Skip to content

BUG: Support std::complex in Matrix and VariableSizeMatrix GetInverse - #7060

Open
hjmjohnson wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:bug-7058-complex-getinverse
Open

hjmjohnson wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:bug-7058-complex-getinverse

Conversation

@hjmjohnson

@hjmjohnson hjmjohnson commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Make GetInverse of itk::Matrix and itk::VariableSizeMatrix compile for std::complex through a complex-aware itk::bridge::Math::PseudoInverse. Fixes #7058; see also #7061.

Root cause and change

Both GetInverse methods called itk::bridge::Math::SVD, which is real-only (it applies < to the element type). fc7ab6bb550 and a2c58cc9bc4 introduced that path on main only, in no release tag. SWIG instantiates every member, so wrapping IsotropicWavelets failed on three wrapper files.

PseudoInverse dispatches with if constexpr: real types keep the existing SVD path, complex types use an Eigen BDCSVD (thin) with the same rcond rule, explicitly instantiated for float and double in libITKCommon like the real engines. No public signature changes.

Verification
  • New GTests: five in itkBridgeMathSVDGTest.cxx (known matrix, Penrose conditions, 20x20 full rank on the BDCSVD path, 20x20 rank-1 with the analytic result, real parity), plus Matrix.GetInverseOfComplexMatrix and VariableSizeMatrix.GetInverseOfComplexMatrix. Expected values are analytic (inverse of [[1,i],[0,1]] is [[1,-i],[0,1]]).
  • ITKCommon GTests: 56 of 57 matrix, SVD, and bridge tests pass; the one not run is a legacy-driver test whose driver was not built.
  • The three formerly failing IsotropicWavelets wrapper objects compile with 0 errors.
  • A standalone complex GetInverse program fails against the old headers and builds against the new ones.
  • pre-commit run --all-files passes.
AI assistance
  • Tool: Claude Code
  • Role: root-cause analysis, implementation, tests
  • All changes were reviewed and tested locally before committing.

@github-actions github-actions Bot added type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Core Issues affecting the Core module labels Oct 31, 2026
@hjmjohnson
hjmjohnson marked this pull request as ready for review October 31, 2026 23:10
@greptile-apps

greptile-apps Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; both previous findings are addressed.

Summary

Adds complex support to Matrix::GetInverse() and VariableSizeMatrix::GetInverse() while keeping the existing real-valued path.

  • Fixed-size and runtime-sized matrices can now invert complex values.

Reviews (2) · Last reviewed commit: "BUG: Support std::complex in Matrix and ..." · Reviewed by Greptile

@hjmjohnson
hjmjohnson force-pushed the bug-7058-complex-getinverse branch 2 times, most recently from 183b7de to d296c4f Compare October 31, 2026 23:26
itk::Matrix and itk::VariableSizeMatrix GetInverse called
itk::bridge::Math::SVD, which applies operator< to the element type, so
instantiating either for std::complex failed to compile. Python wrapping
instantiates every member, which exposed it.

Add itk::bridge::Math::PseudoInverse. Real types keep the existing SVD
path. Complex types use Eigen's BDCSVD with the same rcond rule. No
public signature changes.

Add GoogleTests for both classes and the bridge function, with analytic
expected values.

Issue: InsightSoftwareConsortium#7058
@hjmjohnson
hjmjohnson force-pushed the bug-7058-complex-getinverse branch from d296c4f to 56dec0d Compare October 31, 2026 23:36
@hjmjohnson

Copy link
Copy Markdown
Member Author

@greptileai review

hjmjohnson added a commit to hjmjohnson/ITK that referenced this pull request Nov 1, 2026
@hjmjohnson
hjmjohnson requested a review from thewtex November 1, 2026 16:52
hjmjohnson added a commit to hjmjohnson/ITK that referenced this pull request Nov 1, 2026
hjmjohnson added a commit to hjmjohnson/ITK that referenced this pull request Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Core Issues affecting the Core module type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Matrix and VariableSizeMatrix GetInverse do not compile for std::complex (bridge SVD is real-only)

1 participant