Class sym::SparseCholeskySolver

template<typename _MatrixType, int _UpLo = Eigen::Lower>
class SparseCholeskySolver

Efficiently solves A * x = b, where A is a sparse matrix and b is a dense vector or matrix, using the LDLT cholesky factorization A = L * D * L^T, where L is a unit triangular matrix and D is a diagonal matrix.

When repeatedly solving systems where A changes but its sparsity pattern remains identical, this class can analyze the sparsity pattern once and use it to more efficiently factorize and solve on subsequent calls.

Public Types

enum [anonymous]

Values:

enumerator UpLo
using MatrixType = _MatrixType
using Scalar = typename MatrixType::Scalar
using StorageIndex = typename MatrixType::StorageIndex
using CholMatrixType = Eigen::SparseMatrix<Scalar, Eigen::ColMajor, StorageIndex>
using VectorType = Eigen::Matrix<Scalar, Eigen::Dynamic, 1>
using RhsType = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>
using PermutationMatrixType = Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic, StorageIndex>
using Ordering = std::function<void(const MatrixType&, PermutationMatrixType&)>

Public Functions

inline SparseCholeskySolver(const Ordering &ordering = Eigen::MetisOrdering<StorageIndex>())

Default constructor

Parameters:

ordering – Functor to compute the variable ordering to use. Can be any functor with signature void(const MatrixType&, PermutationMatrixType&) which takes in the sparsity pattern of the matrix A and fills out the permutation of variables to use in the second argument. The first argument is the full matrix A, not just the upper or lower triangle; the values may not be the same as in A, but will be nonzero for entries in A that are nonzero. Typically this will be an instance of one of the orderings provided by Eigen, such as Eigen::NaturalOrdering().

inline explicit SparseCholeskySolver(const MatrixType &A, const Ordering &ordering = Eigen::MetisOrdering<StorageIndex>())

Construct with a representative sparse matrix

Parameters:
  • A – The matrix to be factorized

  • ordering – Functor to compute the variable ordering to use. Can be any functor with signature void(const MatrixType&, PermutationMatrixType&) which takes in the sparsity pattern of the matrix A and fills out the permutation of variables to use in the second argument. The first argument is the full matrix A, not just the upper or lower triangle; the values may not be the same as in A, but will be nonzero for entries in A that are nonzero. Typically this will be an instance of one of the orderings provided by Eigen, such as Eigen::NaturalOrdering().

inline ~SparseCholeskySolver()
inline bool IsInitialized() const

Whether we have computed a symbolic sparsity and are ready to factorize/solve.

void ComputePermutationMatrix(const MatrixType &A)

Compute an efficient permutation matrix (ordering) for A and store internally.

void ComputeSymbolicSparsity(const MatrixType &A)

Compute symbolic sparsity pattern for A and store internally.

bool Factorize(const MatrixType &A)

Decompose A into A = L * D * L^T and store internally. A must have the same sparsity as the matrix used for construction. Returns true if factorization was successful, and false otherwise. NOTE(brad): Currently always returns true.

template<typename Rhs>
RhsType Solve(const Eigen::MatrixBase<Rhs> &b) const

Returns x for A x = b, where x and b are dense.

template<typename Rhs>
void SolveInPlace(Eigen::MatrixBase<Rhs> &b) const

Solves in place for x in A x = b, where x and b are dense.

inline const CholMatrixType &L() const
inline const VectorType &D() const
inline const PermutationMatrixType &Permutation() const
inline const PermutationMatrixType &InversePermutation() const
inline void AnalyzeSparsityPattern(const Eigen::SparseMatrix<Scalar> &matrix)