Eigen 3.3.4: Map<VectorXd> to 2d Block的创建方法是什么?
Eigen 3.3.4: What is the way to create Map<VectorXd> to 2d Block?
假设我有以下代码:
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 实现此目的的好方法?
临时的 "other way around" 就可以了,你所要做的就是使用 Map<const MatrixXd>
或静态方法 MatrixXd::Map
:
尊重常量
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);
假设我有以下代码:
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 实现此目的的好方法?
临时的 "other way around" 就可以了,你所要做的就是使用 Map<const MatrixXd>
或静态方法 MatrixXd::Map
:
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);