7 #ifndef SPECTRA_DENSE_CHOLESKY_H
8 #define SPECTRA_DENSE_CHOLESKY_H
11 #include <Eigen/Cholesky>
14 #include "../Util/CompInfo.h"
33 template <
typename Scalar_,
int Uplo = Eigen::Lower,
int Flags = Eigen::ColMajor>
43 using Index = Eigen::Index;
44 using Matrix = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Flags>;
45 using Vector = Eigen::Matrix<Scalar, Eigen::Dynamic, 1>;
46 using MapConstVec = Eigen::Map<const Vector>;
47 using MapVec = Eigen::Map<Vector>;
50 Eigen::LLT<Matrix, Uplo> m_decomp;
62 template <
typename Derived>
67 static_cast<int>(Derived::PlainObject::IsRowMajor) ==
static_cast<int>(Matrix::IsRowMajor),
68 "DenseCholesky: the \"Flags\" template parameter does not match the input matrix (Eigen::ColMajor/Eigen::RowMajor)");
70 if (m_n != mat.cols())
71 throw std::invalid_argument(
"DenseCholesky: matrix must be square");
73 m_decomp.compute(mat);
74 m_info = (m_decomp.info() == Eigen::Success) ?
82 Index
rows()
const {
return m_n; }
86 Index
cols()
const {
return m_n; }
103 MapConstVec x(x_in, m_n);
104 MapVec y(y_out, m_n);
105 y.noalias() = m_decomp.matrixL().solve(x);
117 MapConstVec x(x_in, m_n);
118 MapVec y(y_out, m_n);
119 y.noalias() = m_decomp.matrixU().solve(x);
void upper_triangular_solve(const Scalar *x_in, Scalar *y_out) const
DenseCholesky(const Eigen::MatrixBase< Derived > &mat)
void lower_triangular_solve(const Scalar *x_in, Scalar *y_out) const
@ Successful
Computation was successful.