I'd like to replicate each row of a matrix M without any copy occurring (i.e. by creating a view):
0 1 0 1
2 3 -> 0 1
2 3
2 3
M.rowwise().replicate(n)is a shorcut forM.replicate(1,n)which seems kind of useless.The following snippet does a copy, and cannot work if
Mis an expression.
Eigen::Index rowFactor = 2;
Eigen::MatrixXi M2 = Eigen::Map(M.data(), 1, M.size()).replicate(rowFactor, 1);
M2.resize(M.rows()*rowFactor, M.cols()) ;
- In some situation, I may use the intermediate view
Eigen::Map<Eigen::MatrixXi>(M.data(), 1, M.size()).replicate(rowFactor, 1)by reshaping the other operands, but that's not very satisfying.
Is there a proper way to achieve this broadcast view?