特征矩阵的静态整形
Static reshape of Eigen matrix
我正在尝试使用Eigen对一些网格数据进行双三次插值,但我不知道如何将系数的16x1列向量重塑为4x4矩阵。理想情况下,我想做一些类似于https://bitbucket.org/eigen/eigen/pull-request/41/reshape/diff没有任何复制,但我无法制作文档的头或尾。或者,地图也可以,但我不知道如何在现有的矩阵上使用地图。
更多信息:http://en.wikipedia.org/wiki/Bicubic_interpolation
/// The inverse of the A matrix for the bicubic interpolation
/// (http://en.wikipedia.org/wiki/Bicubic_interpolation)
static const double Ainv_data[16*16] = {
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-3, 3, 0, 0, -2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, -2, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, -3, 3, 0, 0, -2, -1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 2, -2, 0, 0, 1, 1, 0, 0,
-3, 0, 3, 0, 0, 0, 0, 0, -2, 0, -1, 0, 0, 0, 0, 0,
0, 0, 0, 0, -3, 0, 3, 0, 0, 0, 0, 0, -2, 0, -1, 0,
9, -9, -9, 9, 6, 3, -6, -3, 6, -6, 3, -3, 4, 2, 2, 1,
-6, 6, 6, -6, -3, -3, 3, 3, -4, 4, -2, 2, -2, -2, -1, -1,
2, 0, -2, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 2, 0, -2, 0, 0, 0, 0, 0, 1, 0, 1, 0,
-6, 6, 6, -6, -4, -2, 4, 2, -3, 3, -3, 3, -2, -1, -2, -1,
4, -4, -4, 4, 2, 2, -2, -2, 2, -2, 2, -2, 1, 1, 1, 1};
Eigen::Matrix<double, 16, 16> Ainv(Ainv_data);
Eigen::Matrix<double, 16, 1> f;
f.setRandom();
Eigen::Matrix<double, 16, 1> alpha = Ainv*f;
// This next line works, but it is making a copy, right?
Eigen::Matrix<double, 4, 4> a(alpha.data());
最后一行确实在进行复制,因此您可以使用如下Map:
Map<Matrix4d,Eigen::Aligned> a(alpha.data());
a
的行为类似于Matrix4d
,并且它是读写的。Eigen::Aligned
标志告诉Eigen传递给Map的指针已正确对齐以进行矢量化。与纯Matrix4d的唯一区别在于C++类型不同。
相关文章:
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- #为""定义宏;静态";针对不同的上下文
- cmake如何在fedora工作站中找到boost静态库包
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 将公共但非静态的成员函数与ALGLIB集成
- cmake在我的项目中所需的所有静态库都不成功
- 绕过特征静态断言
- 特征中静态成员的初始化
- 特征库:计算倒数时静态和动态大小矩阵之间的不同行为
- 枚举和静态const成员变量在模板特征类中的用法
- 如何初始化具有类型特征的类模板的静态数据成员
- 类型特征:检查引用成员变量是否是静态的
- 特征矩阵的静态整形
- 带有静态类和特征类的未解析外部
- 成员模板静态函数的类型特征
- 用于将静态字符串常量与类型相关联的类型特征模式
- 如何初始化类型特征的静态 std::unordered_map
- 类型特征相对于静态成员的优势
- 在特征模板中声明静态自动函数指针
- 使用 "comma initialization" 初始化静态特征矩阵