0

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

sgarizvi
  • 16,623
  • 9
  • 64
  • 98
  • Okay, I think I found an answer. The following code works:'Map > odd_col(src.data(), src.rows(), src.cols() / 2, OuterStride<>(src.outerStride() * 2)); Map > even_col(src.data() + src.rows(), src.rows(), src.cols() / 2, OuterStride<>(src.outerStride() * 2));' – Chole Hou Sep 07 '18 at 06:25
  • 1
    the idea should be to use the same stride (doubled stride of input) but start with an offset of 1 row. – Micka Sep 07 '18 at 07:25

1 Answers1

0

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);
ggael
  • 28,425
  • 2
  • 65
  • 71