Reputation: 579
I would like to create a template that takes an Eigen matrix as input and that includes a Cholesky decomposition (LLT
in Eigen; see doc) in its body.
template <typename Derived>
double function_with_llt(const MatrixBase<Derived>& m) {
LLT<m_type> llt_of_input(m); //how do I get m's type?
return 0;
}
The problem is that I need type of the matrix m
to declare LLT
. Substituting m_type
with MatrixBase<Derived>
did not work. I could use one of Eigen's dynamic matrix classes (e.g. MatrixXd) for LLT, but I would prefer to have decomposition matrices with fixed dimensions in later computations. Is there some typedef
or other trick that could fix this?
Upvotes: 0
Views: 490
Reputation: 5547
I would take the matrix type as a template parameter:
template <typename MatrixType>
double function_with_llt(const MatrixType& m) {
LLT<MatrixType> llt_of_input(m);
return 0;
}
Upvotes: 1