Re: [Rd] Matrix memory layout R vs. C

2013-12-06 Thread Prof Brian Ripley
On 06/12/2013 15:51, Luis Carvalho wrote: And to be safer on a 64-bit platform #define INDEX(i,j) ((i) + rows*(R_xlen_t)(j)) since rows*j might overflow there. Shouldn't 'rows' be also a parameter? This is a macro, not a function. 'rows' (I would have use nr or nrows) is going to be the s

Re: [Rd] Matrix memory layout R vs. C

2013-12-06 Thread Luis Carvalho
> And to be safer on a 64-bit platform > > #define INDEX(i,j) ((i) + rows*(R_xlen_t)(j)) > > since rows*j might overflow there. Shouldn't 'rows' be also a parameter? #define INDEX(rows,i,j) ((i) + (rows)*((R_xlen_t)(j))) Cheers, Luis -- Computers are useless. They can only give you answers.

Re: [Rd] Matrix memory layout R vs. C

2013-12-06 Thread Prof Brian Ripley
On 06/12/2013 15:49, Gábor Csárdi wrote: On Fri, Dec 6, 2013 at 10:42 AM, Prof Brian Ripley wrote: On 06/12/2013 14:42, Gábor Csárdi wrote: On Fri, Dec 6, 2013 at 9:38 AM, Duncan Murdoch wrote: On 06/12/2013 8:21 AM, Larissa Hauer wrote: [...] I would not assume that a 2D matrix in C

Re: [Rd] Matrix memory layout R vs. C

2013-12-06 Thread Luis Carvalho
Hi Larissa, > I'm trying to pass a matrix from R to C, where some computation is > done for performance reasons, and back to R for evaluation. But I've > run into the problem that R and C seem to have different ways of > representing the matrix in main memory. The C representation of a 2D > matrix

Re: [Rd] Matrix memory layout R vs. C

2013-12-06 Thread Gábor Csárdi
On Fri, Dec 6, 2013 at 10:42 AM, Prof Brian Ripley wrote: > On 06/12/2013 14:42, Gábor Csárdi wrote: >> >> On Fri, Dec 6, 2013 at 9:38 AM, Duncan Murdoch >> wrote: >>> >>> On 06/12/2013 8:21 AM, Larissa Hauer wrote: >> >> [...] >>> >>> >>> >>> I would not assume that a 2D matrix in C doesn't have

Re: [Rd] Matrix memory layout R vs. C

2013-12-06 Thread Prof Brian Ripley
On 06/12/2013 14:42, Gábor Csárdi wrote: On Fri, Dec 6, 2013 at 9:38 AM, Duncan Murdoch wrote: 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

Re: [Rd] Matrix memory layout R vs. C

2013-12-06 Thread Gábor Csárdi
On Fri, Dec 6, 2013 at 9:38 AM, Duncan Murdoch wrote: > 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, > > #de

Re: [Rd] Matrix memory layout R vs. C

2013-12-06 Thread Duncan Murdoch
On 06/12/2013 8:21 AM, Larissa Hauer wrote: Hi everybody, I'm trying to pass a matrix from R to C, where some computation is done for performance reasons, and back to R for evaluation. But I've run into the problem that R and C seem to have different ways of representing the matrix in main memor

Re: [Rd] Matrix memory layout R vs. C

2013-12-06 Thread Lorenz, David
Larissa, So is the problem "in the matrix reference is mat[col][row] whereas in R it is mar[row, col]?" The solution is just recognizing the difference in references. Dave On Fri, Dec 6, 2013 at 7:21 AM, Larissa Hauer wrote: > > Hi everybody, > > I'm trying to pass a matrix from R to C, wher