diff --git a/Eigen/src/CholmodSupport/CholmodSupport.h b/Eigen/src/CholmodSupport/CholmodSupport.h index be2e737ba..447a393a1 100644 --- a/Eigen/src/CholmodSupport/CholmodSupport.h +++ b/Eigen/src/CholmodSupport/CholmodSupport.h @@ -149,11 +149,20 @@ cholmod_dense viewAsCholmod(MatrixBase& mat) { /** Returns a view of the Cholmod sparse matrix \a cm as an Eigen sparse matrix. * The data are not copied but shared. */ -template -Map > viewAsEigen(cholmod_sparse& cm) { - return Map >(cm.nrow, cm.ncol, static_cast(cm.p)[cm.ncol], - static_cast(cm.p), - static_cast(cm.i), static_cast(cm.x)); +template +Map > viewAsEigen(cholmod_sparse& cm) { + return Map >( + cm.nrow, cm.ncol, static_cast(cm.p)[cm.ncol], static_cast(cm.p), + static_cast(cm.i), static_cast(cm.x)); +} + +/** Returns a view of the Cholmod sparse matrix factor \a cm as an Eigen sparse matrix. + * The data are not copied but shared. */ +template +Map > viewAsEigen(cholmod_factor& cm) { + return Map >( + cm.n, cm.n, static_cast(cm.p)[cm.n], static_cast(cm.p), + static_cast(cm.i), static_cast(cm.x)); } namespace internal { @@ -188,6 +197,7 @@ EIGEN_CHOLMOD_SPECIALIZE1(int, free_dense, cholmod_dense*, X) EIGEN_CHOLMOD_SPECIALIZE1(int, free_sparse, cholmod_sparse*, A) EIGEN_CHOLMOD_SPECIALIZE1(cholmod_factor*, analyze, cholmod_sparse, A) +EIGEN_CHOLMOD_SPECIALIZE1(cholmod_sparse*, factor_to_sparse, cholmod_factor, L) template inline cholmod_dense* cm_solve(int sys, cholmod_factor& L, cholmod_dense& B, cholmod_common& Common) { @@ -377,7 +387,7 @@ class CholmodBase : public SparseSolverBase { // TODO optimize this copy by swapping when possible (be careful with alignment, etc.) // NOTE cholmod_spsolve in fact just calls the dense solver for blocks of 4 columns at a time (similar to Eigen's // sparse solver) - dest.derived() = viewAsEigen(*x_cs); + dest.derived() = viewAsEigen(*x_cs); internal::cm_free_sparse(x_cs, m_cholmod); } #endif // EIGEN_PARSED_BY_DOXYGEN @@ -483,6 +493,11 @@ class CholmodSimplicialLLT : public CholmodBase MatrixL; + typedef TriangularView MatrixU; CholmodSimplicialLLT() : Base() { init(); } @@ -493,6 +508,12 @@ class CholmodSimplicialLLT : public CholmodBase(*Base::m_cholmodFactor); } + + /** \returns an expression of the factor U (= L^*) */ + inline MatrixU matrixU() const { return matrixL().adjoint(); } + protected: void init() { m_cholmod.final_asis = 0; @@ -531,6 +552,12 @@ class CholmodSimplicialLDLT : public CholmodBase VectorType; + typedef TriangularView MatrixL; + typedef TriangularView MatrixU; CholmodSimplicialLDLT() : Base() { init(); } @@ -541,6 +568,26 @@ class CholmodSimplicialLDLT : public CholmodBase(*Base::m_cholmodFactor); + + VectorType D{cholmodL.rows()}; + + for (Index k = 0; k < cholmodL.outerSize(); ++k) { + typename decltype(cholmodL)::InnerIterator it{cholmodL, k}; + D(k) = it.value(); + } + + return D; + } + + /** \returns an expression of the factor L */ + inline MatrixL matrixL() const { return viewAsEigen(*Base::m_cholmodFactor); } + + /** \returns an expression of the factor U (= L^*) */ + inline MatrixU matrixU() const { return matrixL().adjoint(); } + protected: void init() { m_cholmod.final_asis = 1; @@ -578,6 +625,9 @@ class CholmodSupernodalLLT : public CholmodBase(*cholmodL); + internal::cm_free_sparse(cholmodL, m_cholmod); + + return L; + } + + /** \returns an expression of the factor U (= L^*) */ + inline MatrixType matrixU() const { return matrixL().adjoint(); } + protected: void init() { m_cholmod.final_asis = 1;