这是一个非特征用户可以回答的问题......
我想使用Eigen API初始化头文件中的常量矩阵,但Eigen似乎没有提供构造函数来实现这一点,以下是我尝试的:
// tried the following first, but Eigen does not provide such a constructor
//const Eigen::Matrix3f M<<1,2,3,4,5,6,7,8,9;
// then I tried the following, but this is not allowed in header file
//const Eigen::Matrix3f M;
//M <<1,2,3,4,5,6,7,8,9; // not allowed in header file
Run Code Online (Sandbox Code Playgroud)
在头文件中实现此目的的替代方法是什么?
gga*_*ael 11
至少有两种可能性.第一个是使用Eigen的逗号初始化功能:
Eigen::Matrix3d A((Eigen::Matrix3d() << 1, 2, 3, 4, 5, 6, 7, 8, 9).finished());
Run Code Online (Sandbox Code Playgroud)
第二种是使用Matrix3d(const double*)从原始指针复制数据的构造函数.在这种情况下,必须以与目标的存储顺序相同的顺序提供值,因此在大多数情况下按列进行:
const double B_data[] = {1, 4, 7, 2, 5, 8, 3, 6, 9};
Eigen::Matrix3d B(B_data);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3833 次 |
| 最近记录: |