[Rcpp-devel] matrix indexing
Whit Armstrong
armstrong.whit at gmail.com
Sun Jan 24 00:33:51 CET 2010
> 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.
> 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?
>
> 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
>
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>
More information about the Rcpp-devel
mailing list