C++/Eigen:获取为 MatrixBase 编写的模板的矩阵参数类型
C++/Eigen: Get type of matrix argument to a template written for MatrixBase
我想创建一个模板,它将特征矩阵作为输入,并在其主体中包含 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;
}
我想创建一个模板,它将特征矩阵作为输入,并在其主体中包含 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;
}