【发布时间】:2019-06-21 11:21:18
【问题描述】:
想法是将 std::vector 中的值分配给 Eigen::MatrixXd 中的块。
我的问题是,有什么好的方法吗?
1 1 1 1 1 1
1 1 1 to 1 102 123
1 1 1 1 1 1
我尝试将 std::vector 转换为 Eigen::Map,但没有成功。 我有一个工作代码 [跟随 sn-p],但它并没有多大吸引力。也许有更简单的方法?
void do_work(Eigen::MatrixXd &m, const std::vector<double> &v,
const Index i, const Index j,
const Index p, const Index q) {
auto stop = j + q;
for (Index start = j, idx = 0; start < stop; ++start, ++idx)
m.block(i, start, p, 1) << v[idx];
}
Eigen::MatrixXd m(3, 3);
m << 1, 1, 1, 1, 1, 1, 1, 1, 1;
std::vector<double> v = {102, 123};
Index change_row = 0;
Index change_column_from = 1, change_column_to = v.size();
do_work(m, v, change_row, change_column_from, 1, change_column_to);
预期的结果是以高效(也许更干净)的方式执行操作。
【问题讨论】: