C++/Eigen : Get type of matrix argument to a template written for MatrixBase

标签 c++ templates types eigen

我想创建一个模板,将特征矩阵作为输入,并在其主体中包含 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_typeMatrixBase<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/

相关文章:

arrays - PostgreSQL 中是否有可用的多值字段类型?

c++ - 'std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique 需要

c++ - 在 Borland C++ 上使用#pragma pack 和#define

c++ - 为模板类重载运算符<<。即使使用 friend 关键字也无法获得私有(private)成员(member)

c++ - 二叉搜索树显示问题

C++ 编译错误枚举 "does not name a type"

c++ - 编译时"one or more multiply defined symbols found"错误

c++ - C 骰子游戏的退出函数

c++ - 为什么要在 C++ 标准容器中为模板参数起别名?

haskell - 如何在 Haskell 中使记录类型位可寻址?