diff --git a/Eigen/src/CholmodSupport/CholmodSupport.h b/Eigen/src/CholmodSupport/CholmodSupport.h index 447a393a1..e5b46c4ca 100644 --- a/Eigen/src/CholmodSupport/CholmodSupport.h +++ b/Eigen/src/CholmodSupport/CholmodSupport.h @@ -329,8 +329,10 @@ class CholmodBase : public SparseSolverBase { cholmod_sparse A = viewAsCholmod(matrix.template selfadjointView()); internal::cm_factorize_p(&A, m_shiftOffset, 0, 0, m_cholmodFactor, m_cholmod); - // If the factorization failed, minor is the column at which it did. On success minor == n. - this->m_info = (m_cholmodFactor->minor == m_cholmodFactor->n ? Success : NumericalIssue); + // If the factorization failed, either the input matrix was zero (so m_cholmodFactor == nullptr), or minor is the + // column at which it failed. On success minor == n. + this->m_info = + (m_cholmodFactor != nullptr && m_cholmodFactor->minor == m_cholmodFactor->n ? Success : NumericalIssue); m_factorizationIsOk = true; } diff --git a/test/cholmod_support.cpp b/test/cholmod_support.cpp index 24126a079..066674950 100644 --- a/test/cholmod_support.cpp +++ b/test/cholmod_support.cpp @@ -54,6 +54,13 @@ void test_cholmod_ST() { check_sparse_spd_determinant(llt_colmajor_upper); check_sparse_spd_determinant(ldlt_colmajor_lower); check_sparse_spd_determinant(ldlt_colmajor_upper); + + check_sparse_zero_matrix(chol_colmajor_lower); + check_sparse_zero_matrix(chol_colmajor_upper); + check_sparse_zero_matrix(llt_colmajor_lower); + check_sparse_zero_matrix(llt_colmajor_upper); + check_sparse_zero_matrix(ldlt_colmajor_lower); + check_sparse_zero_matrix(ldlt_colmajor_upper); } template diff --git a/test/sparse_solver.h b/test/sparse_solver.h index e7518e4e5..033df835f 100644 --- a/test/sparse_solver.h +++ b/test/sparse_solver.h @@ -484,6 +484,15 @@ void check_sparse_spd_determinant(Solver& solver) { } } +template +void check_sparse_zero_matrix(Solver& solver) { + typedef typename Solver::MatrixType Mat; + + Mat A(1, 1); + solver.compute(A); + VERIFY_IS_EQUAL(solver.info(), NumericalIssue); +} + template Index generate_sparse_square_problem(Solver&, typename Solver::MatrixType& A, DenseMat& dA, int maxSize = 300, int options = ForceNonZeroDiag) {