0
votes

I am working with eigen library right now, and trying to find a way to extract the odd rows of a matrix into a new matrix. I am currently using

Map<MatrixXf,0,OuterStride<>>dst(eigen_src.data(), eigen_src.rows(), eigen_src.cols() / 2, OuterStride<>(eigen_src.outerStride() * 2))

to extract the even rows. But I do not think the upper way apply for odd number row as well. Or does it?

Does anyone knows how I could extract rows 1, 3, 5, ....(odd numbers) from a matrix and same them as a new matrix?

Thank you

1
Okay, I think I found an answer. The following code works:'Map<MatrixXf, 0, OuterStride<> > odd_col(src.data(), src.rows(), src.cols() / 2, OuterStride<>(src.outerStride() * 2)); Map<MatrixXf, 0, OuterStride<> > even_col(src.data() + src.rows(), src.rows(), src.cols() / 2, OuterStride<>(src.outerStride() * 2));'Chole Hou
the idea should be to use the same stride (doubled stride of input) but start with an offset of 1 row.Micka

1 Answers

0
votes

For the record, with the head of Eigen (aka devel branch) you can simply do:

using namespace Eigen::placeholders;
MatrixXf even = A(seq(0,last,fix<2>),all);
MatrixXf odd  = A(seq(1,last,fix<2>),all);