说我有以下代码:
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可以实现这一目标吗?
答案 0 :(得分:1)
带有临时选项的“其他方法”将做,您要做的就是使用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);