7 #ifndef SYMMETRIC_LDL_H
8 #define SYMMETRIC_LDL_H
12 #include "LapackWrapperExtra.h"
24 template <
typename Scalar =
double>
28 typedef arma::Mat<Scalar> Matrix;
29 typedef arma::Col<Scalar> Vector;
30 typedef arma::Col<int> IntVector;
45 dim_n(0), mat_uplo(
'L'), computed(false)
73 void compute(
const Matrix &mat,
const char uplo =
'L')
76 throw std::invalid_argument(
"SymmetricLDL: matrix must be square");
79 mat_uplo = (uplo ==
'L' ?
'L' :
'U');
81 vec_fac.set_size(dim_n);
85 arma::lapack::sytrf(&mat_uplo, &dim_n, mat_fac.memptr(), &dim_n,
86 vec_fac.memptr(), &lwork_query, &lwork, &info);
87 lwork = int(lwork_query);
89 Scalar *work =
new Scalar[lwork];
90 arma::lapack::sytrf(&mat_uplo, &dim_n, mat_fac.memptr(), &dim_n,
91 vec_fac.memptr(), work, &lwork, &info);
95 throw std::invalid_argument(
"Lapack sytrf: illegal value");
97 throw std::logic_error(
"SymmetricLDL: matrix is singular");
113 void solve(Vector &vec_in, Vector &vec_out)
122 arma::lapack::sytrs(&mat_uplo, &dim_n, &one, mat_fac.memptr(), &dim_n,
123 vec_fac.memptr(), vec_out.memptr(), &dim_n, &info);
125 throw std::invalid_argument(
"Lapack sytrs: illegal value");
131 #endif // SYMMETRIC_LDL_H
void compute(const Matrix &mat, const char uplo= 'L')
SymmetricLDL(const Matrix &mat, const char uplo= 'L')
void solve(Vector &vec_in, Vector &vec_out)