Skip to content
Prev 47268 / 63424 Next

Matrix memory layout R vs. C

On 06/12/2013 8:21 AM, Larissa Hauer wrote:
I would not assume that a 2D matrix in C doesn't have gaps in it between 
the rows.  Let C treat it as a vector, and write a little macro that 
does the indexing.  For example,

#define INDEX(i,j) (i) + rows*(j)

Then mPtr[INDEX(i,j)] will do R-style indexing (except it will be 
0-based, not 1-based.  You could fix that too if you wanted.)

Duncan Murdoch