[Rcpp-devel] matrix indexing

Romain Francois francoisromain at free.fr
Sun Jan 24 11:49:23 CET 2010


On 01/24/2010 12:33 AM, Whit Armstrong wrote:
>> indexing, but apparently one cannot pass more than one parameter to []
>> so ... I guess I'll have to sacrifice look and feel for a minute.
>
> yes, same issue for me in tslib.  but (i,j) is not so bad esp for
> matlab users.  tslib users have it even harder since x() is used as
> lag/lead. x[] is used as 1d accessor/setter, and x(i,j) is used as 2d
> accessor/setter.
>
> I think this is part of the reason people don't like c++. Overloading
> can confuse the hell out of people, but good documentation should take
> care of the negative sentiment.

Makes sense.

>> I was also thinking maybe making some sort of indexer class to take care
>> of conversion of 2 indices into 1d index; something like this pseudo code :
>> double x11 = m[ indexer(0,0) ] ;
>
> I think this is useful.  I called mine "offset(i,j)" in tslib.
>
>> Given than a REALSXP can change its mind about being a matrix, I'm not
>> sure I want to subclass NumericVector into NumericMatrix, etc. ...
>
> yes, but if you follow R's implicit class system, then you have to go
> this way.  One possibility is to thow if you don't find a dims
> attribute when calling a constructor on an SEXP, and what to do when
> length dims == 3?

yes. but you cannot lock your object so that you control how attributes 
(e.g. dim) are set, so you have to check for bounds each time, etc ... 
we'll have to document that this is convenience operators and that there 
is a performance penalty, etc ...

>> Ideas ?
>>
>> Romain


-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/KfKn : Rcpp 0.7.2
|- http://tr.im/JOlc : External pointers with Rcpp
`- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009



More information about the Rcpp-devel mailing list