Re: [eigen] Question about ColMajor vs. RowMajor

[ Thread Index | Date Index | More Archives ]

On Fri, Dec 16, 2011 at 6:27 PM, Michael Dixon <mdixon@xxxxxxxxxxxxxxxx> wrote:
>  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.

But the mapping from a one-dimensional array to a matrix is exactly
what ColMajor/RowMajor means.  Using a single index into a ColMajor
matrix is the equivalent of using a single index into the transpose of
the same matrix in RowMajor ordering.  For a 2 by 2 matrix the
ColMajor order is

0 2
1 3

whereas it is

0 1
2 3

for RowMajor

Mail converted by MHonArc 2.6.19+