如何在矩阵矩阵上使用eigen ::映射?
我需要编写一个包装器,以使用C/C ++ DLL中的现有第三方库。 该库在很大程度上依赖于 eigen 用于矩阵操作,我想在不修改的情况下重复使用该代码。
我想使用eigen ::映射在库的特征矩阵和我的DLL接口中的标准C风格阵列之间进行转换。对于输入,我有此功能,但是输出是3x4矩阵的4x1矩阵,我可以弄清楚如何以正确的方式映射该映射。
这个最小示例代码正在工作:
#include <Eigen/Dense>
using namespace Eigen;
void matrix_test(double* in, double* out)
{
// Map input array to 3x3 matrix (and match layout)
Map<Matrix<double, 3, 3>, 0, Stride<1, 3>> matrix_in(in, 3, 3);
// -- library would be called here --
// (taking matrix_in and filling matrix_out)
Matrix<Matrix<double, 3, 4>, 4, 1> matrix_out;
// Map 4x1 matrix of 3x3 matrices to output array
for (int i=0; i < 4; i++)
{
Map<Matrix<double, 3, 4, RowMajor>>((out + i * (3 * 4)), 3, 4) = matrix_out(i);
}
}
我想摆脱() -loop的。我认为特征有一种方法可以使用映射作为矩阵矩阵,但是看来我不知道如何 - 我只会得到一长串编译器错误列表对我来说是新的)
是否有人有提示或示例如何使用eigen ::地图实现这一目标?
谢谢你
Felix
I need to write a wrapper for using an existing third-party library within a C/C++ DLL.
The library is heavily relying on Eigen for matrix manipulations and I want to reuse that code without modifying it.
I'd like to use Eigen::Map to convert between the Eigen matrices of the library and the standard C-style arrays in my DLL interface. For the inputs I have this working, but the output is a 4x1 matrix of 3x4 matrices and I can' figure out how to map that the proper way.
This minimum example code is working:
#include <Eigen/Dense>
using namespace Eigen;
void matrix_test(double* in, double* out)
{
// Map input array to 3x3 matrix (and match layout)
Map<Matrix<double, 3, 3>, 0, Stride<1, 3>> matrix_in(in, 3, 3);
// -- library would be called here --
// (taking matrix_in and filling matrix_out)
Matrix<Matrix<double, 3, 4>, 4, 1> matrix_out;
// Map 4x1 matrix of 3x3 matrices to output array
for (int i=0; i < 4; i++)
{
Map<Matrix<double, 3, 4, RowMajor>>((out + i * (3 * 4)), 3, 4) = matrix_out(i);
}
}
I'd like to get rid of the for()
-loop. I would assume there is a way in Eigen to use Map for the matrix-of-matrices, but it seems I can't figure out how - I only get a long list of compiler errors (but then this C++ template-stuff is quite new to me)
Does anybody have a hint or an example how to achieve this with Eigen::Map?
Thank you
Felix
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论