简体   繁体   English

本征矩阵的静态重塑

[英]Static reshape of Eigen matrix

I am experimenting with doing bicubic interpolation of some gridded data using Eigen, and I can't figure out how to reshape the 16x1 column vector of coefficients into a 4x4 matrix. 我正在尝试使用Eigen对某些栅格数据进行三次三次插值,但无法弄清楚如何将系数的16x1列向量整形为4x4矩阵。 Ideally I would like to do something along the lines of https://bitbucket.org/eigen/eigen/pull-request/41/reshape/diff without any copying, but I can't make heads or tails of the docs. 理想情况下,我希望按照https://bitbucket.org/eigen/eigen/pull-request/41/reshape/diff的方式进行操作,而不进行任何复制,但是我无法做出文档的正面或反面。 Alternatively, a map would be fine as well, but I can't figure out how to use a map on an already existing matrix. 另外,地图也可以,但是我不知道如何在已经存在的矩阵上使用地图。

More here: http://en.wikipedia.org/wiki/Bicubic_interpolation 此处更多信息: 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());

The last line is indeed doing a copy, so you can use a Map as follow: 最后一行的确在进行复制,因此您可以按以下方式使用地图:

Map<Matrix4d,Eigen::Aligned> a(alpha.data());

a behaves like a Matrix4d and it is read-write. a行为类似于Matrix4d ,并且是可读写的。 The Eigen::Aligned flag tells Eigen that the pointer you pass to Map is properly aligned for vectorization. Eigen::Aligned标志告诉Eigen您传递给Map的指针已正确对齐以进行矢量化。 The only difference with a pure Matrix4d is that the C++ type is not the same. 纯Matrix4d的唯一区别是C ++类型不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM