[eigen] Question about ColMajor vs. RowMajor

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


 Hi,

My colleagues and I were recently playing around with changing the
default for matrices from ColMajor to RowMajor, and we found that
doing so changed the behavior of the () operator.  Specifically, when
accessing a two-dimensional matrix with a single index (e.g., mat(i)
), the ColMajor/RowMajor flag affects which element of the matrix gets
indexed as the ith.  Our assumption had been that changing the
ColMajor/RowMajor flag would be completely transparent, which is to
say, it would affect the underlying storage (and thus the
performance/efficiency), but it wouldn't change the overall behavior
of the code.  I was just wondering whether the altered behavior of the
() operator was intended (in which case, our assumption of
transparency was incorrect), or whether this was an unintended bug.

Thanks,
Michael

P.S. In case my description of the problem was a little unclear, I'm
also attaching a small program that demonstrates the change in
behavior.
#include <Eigen/Core>
#include <iostream>

int main(int argc, char ** argv)
{
  Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor> col_major(2, 2);
  Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> row_major(2, 2);
  int i = 0;
  for (int c = 0; c < 2; ++c)
  {
    for (int r = 0; r < 2; ++r)
    {
      col_major(r,c) = i;
      row_major(r,c) = i;
      ++i;
    }
  }

  for (i = 0; i < 4; ++i)
  {
    std::cout << "col_major(" << i << ") = " << col_major(i) << std::endl;
    std::cout << "row_major(" << i << ") = " << row_major(i) << std::endl;
    std::cout << std::endl;
  }

  return (0);
}


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/