Make LuFactorization a stateful class outside detail#815
Draft
tigercosmos wants to merge 1 commit into
Draft
Conversation
Pull the LU-with-partial-pivoting helper out of modmesh::detail and turn it from a namespace of static methods into a stateful class modmesh::LuFactorization<T>. The constructor runs the factorization once and caches the lu matrix and pivot vector; solve() and inv() are const methods that read those cached members. Free functions lu_factorization(), lu_solve(), and lu_inv() remain as thin wrappers that construct a temporary LuFactorization<T>, so the existing API keeps working. The class is exposed to Python as LuFactorizationFloat32/Float64/ Complex64/Complex128 via a new wrap_LuFactorization.cpp, modelled on wrap_EigenSystem.cpp. Related to solvcon#809.
Member
|
Determinant may be a side product of the LU decomposition. Consider to add it along with the refactor work, or leave room to extend to it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This refactors the LU-with-partial-pivoting helper from a namespace of static methods (modmesh::detail::Lu) into a stateful class modmesh::LuFactorization. The class computes the factorization once in its constructor and caches the resulting LU matrix and pivot vector as members; solve() and inv() are const methods that reuse those cached factors instead of re-running the O(n^3) algorithm. Owners of an LuFactorization instance decide how the cached data is used.
The existing free functions lu_factorization(), lu_solve(), and lu_inv() are preserved as thin wrappers that construct a temporary LuFactorization internally, so callers of the original API keep working unchanged. The class itself is exposed to Python as LuFactorizationFloat32/Float64/Complex64/Complex128 via a new wrap_LuFactorization.cpp, mirroring the EigenSystem binding pattern.
Tests in tests/test_linalg.py exercise the class through its lu, piv, n, solve, and inv members. Two of them mutate the cached lu between calls and assert the result changes, which would catch a hidden re-factorization in solve() or inv(). The same shape, rank, dimension, and singularity error paths that the free functions cover are re-covered through the class API.
Related to #809.