我想创建一个模板,将特征矩阵作为输入,并在其主体中包含 Cholesky 分解(特征中的 LLT
;请参阅 doc)。
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;
}
问题是我需要矩阵类型 m
申报LLT
.替换 m_type
与 MatrixBase<Derived>
不工作。我可以将 Eigen 的动态矩阵类之一(例如 MatrixXd)用于 LLT,但我更愿意在以后的计算中使用具有固定维度的分解矩阵。有没有typedef
或其他可以解决此问题的技巧?
最佳答案
我会将矩阵类型作为模板参数:
template <typename MatrixType>
double function_with_llt(const MatrixType& m) {
LLT<MatrixType> llt_of_input(m);
return 0;
}
关于C++/Eigen : Get type of matrix argument to a template written for MatrixBase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49762646/