模板类型铸造的特征矩阵库
Template type casting of Eigen Matrix library
我正在尝试使用Eigen库类型转换模板矩阵。
function( const Eigen::MatrixBase < Derived1 > &mat1,
Eigen::MatrixBase < Derived2 > &mat2 )
{
mat2 = coefficient * mat1.derived().cast < Derived2::Scalar >();
}
它不工作。谁能帮我纠正一下语法?
您的函数签名不完整,但我猜您缺少的主要内容是使用模板关键字进行函数调用:
mat2 = coefficient * mat1.template cast <typename Derived2::Scalar> ();
一个完整的工作示例:
#include <eigen3/Eigen/Core>
#include <iostream>
template<typename Derived1, typename Derived2>
void mul(const typename Derived1::Scalar& coefficient,
const Eigen::MatrixBase<Derived1>& mat1,
Eigen::MatrixBase<Derived2>& mat2)
{
mat2 = coefficient * mat1.template cast <typename Derived2::Scalar> ();
}
int main() {
Eigen::Matrix3f a;
a << 1.0, 0.0, 0.0,
0.0, 2.0, 0.0,
0.0, 0.0, 3.0;
Eigen::Matrix3i b;
b << 1, 0, 0,
0, 1, 0,
0, 0, 1;
mul(3.5, a, b);
std::cout << b << "n";
return 0;
}
在编译和运行时,输出
3 0 0
0 6 0
0 0 9
相关文章:
- 如何将高维数据映射到特征类型?
- 将平面阵列重塑为复杂的特征类型
- 以特征类型作为参数的泛型函数回调
- 如何通过opencv中的程序参数定义特征类型?
- 在编译时检查特征类型保存的数据在内存中是否连续
- 专门针对特征类型的功能
- 具有特征类型输出的特征二进制 Expr
- 使用具有STL容器和STD :: vector的特征类型
- 从指针进行特征3类型的强制转换/复制(溢出uint8_t)
- 使用 python 扩展在 gdb 中打印特征类型时出现问题
- 将特征类型与 boost::bind 一起使用是否会自动违反 Eigen 的"only pass by reference"规则?
- NVIDIA NVCC 在使用模板特征类型时更改编译时间常量
- 固定大小的特征类型作为参数
- 特征类型类型定义失败,并显示 C4430
- 检查类型是否为特征 3 类型
- 传递std::迭代器,指向具有特征类型的向量
- visual studio 2012中对特征类型向量的自动矢量化表现不佳
- 子类特征类型
- 使用一个特征类型内提升图
- 特征c++类型转换