Eigen 3.3.4:创建Map的方法是什么 到2d座?

问题描述 投票:0回答:1

说我有以下代码:

MatrixXd v(10, 10);
auto block = v.block(5, 0, 5, 2);  // a block xpr to v
// view the block as vector
// in Eigen 3.4 it would be block.reshaped()
// but for Eigen 3.3, the following does not work:
Map<VectorXd>(block.data(), 10) = VectorXd::LinSpaced(10, 0, 1.);
// or the other way around, which errors on the constness
block = Map<MatrixXd>(VectorXd::LinSpaced(10, 0., 1.).eval().data(), 5, 2);

我的问题是,有没有一个很好的方法来实现这个与Eigen 3.3?

c++ eigen eigen3
1个回答
1
投票

使用临时的“另一种方式”会做,所有你需要做的就是使用Map<const MatrixXd>或静态方法MatrixXd::Map来尊重constness:

block = Map<const MatrixXd>(VectorXd::LinSpaced(10, 0., 1.).eval().data(), 5, 2);
block = MatrixXd::Map(VectorXd::LinSpaced(10, 0., 1.).eval().data(), 5, 2);
© www.soinside.com 2019 - 2024. All rights reserved.