Skip to content

Fix Eigen iterative solver lifetime problem#91

Merged
iiiian merged 1 commit intopolyfem:mainfrom
iiiian:fix-eigen-iterative
Mar 12, 2026
Merged

Fix Eigen iterative solver lifetime problem#91
iiiian merged 1 commit intopolyfem:mainfrom
iiiian:fix-eigen-iterative

Conversation

@iiiian
Copy link
Contributor

@iiiian iiiian commented Dec 11, 2025

Description

Eigen iterative solver stores a reference to input matrix A and expect it to remain valid.

See https://libeigen.gitlab.io/eigen/docs-nightly/classEigen_1_1IterativeSolverBase.html#a3b0d9691964793bd55937666426fefbf.

Currently we do not make a copy and this results in segmentation fault when A is destroyed before the compute() call. This PR fix this by manually copying A.

An alternative solution is to have a API with clear lifetime expectancy.

Changes

  • Copy input matrix A in factorize().
  • Unify input matrix naming: Most of the code base uses const StiffnessMatrix &A but some methods in Eigen solver use const StiffnessMatrix &K instead. I change the parameter name to A for consistency.

@teseoch teseoch marked this pull request as draft February 18, 2026 15:51
@teseoch teseoch marked this pull request as ready for review February 18, 2026 15:51
@iiiian iiiian force-pushed the fix-eigen-iterative branch from 3e27910 to 662cacf Compare March 12, 2026 14:16
@codecov
Copy link

codecov bot commented Mar 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.67%. Comparing base (550f6a5) to head (662cacf).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #91   +/-   ##
=======================================
  Coverage   81.66%   81.67%           
=======================================
  Files          49       49           
  Lines        2024     2025    +1     
  Branches      269      269           
=======================================
+ Hits         1653     1654    +1     
  Misses        371      371           
Flag Coverage Δ
polysolve 81.67% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@iiiian iiiian merged commit 5d62b80 into polyfem:main Mar 12, 2026
9 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