特征矩阵的静态整形

Static reshape of Eigen matrix

本文关键字:静态 特征      更新时间:2023-10-16

我正在尝试使用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++类型不同。