[Rcpp-devel] matrix indexing

Romain Francois francoisromain at free.fr
Sun Jan 24 09:09:02 CET 2010


On 01/24/2010 12:42 AM, Whit Armstrong wrote:
> I think the Armadillo stuff is great.  MTL4 is also great, but lacking
> some of the features of Armadillo.
>
> http://www.osl.iu.edu/research/mtl/mtl4/
>
> All the good libraries that I've seen allow you to construct objects
> from a pointer to raw memory and dimensions which should be very easy
> to write for Rcpp objects.  Armadillo also allows you to tell it not
> to copy (which is essentially what tslib does when it wraps SEXP's).

I'll have to do some reading/googling before I can make sense of the above.

> You all are also touching indirectly on another topic.  We are all
> doing interesting things in with R/c++ wrappers to make our lives
> easier and make our code faster. What we really want is R++?  Should
> we all be working on it as a separate project?  Or join the existing
> one?

As Dirk, I am not sure to understand what you mean, so I'll second guess.

Do you mean :
- R/C++ wrappers ? In that case, I will be proprietary and pretend that 
Rcpp is the best available. I'd be happy for you to participate. I 
however will not start a new one. up to you.
- R written in C++ ? This is CXXR. The project is awesome and basically 
reimplement all of R on top of c++ rather than C. I still prefer Rcpp's 
approach because it can be used with regular R, which is what people 
use. Although if R core wants to follow Andrew's lead and rebase on C++, 
then I'll volunteer to help.

Romain

> -Whit
>
> On Sat, Jan 23, 2010 at 3:23 PM, Dirk Eddelbuettel<edd at debian.org>  wrote:
>>
>> On 23 January 2010 at 21:05, Romain Francois wrote:
>> | Hello,
>> |
>> | Motivated by Christophe's question on R-help (cc'ed), I'd like to add
>> | facilities for matrix (and maybe arrays) indexing into the new Rcpp api.
>> |
>> | The classic api already ships matrix indexing through RcppMatrix and
>> | RcppMatrixView classes. I'm not a big fan of using round brackets for
>> | 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.
>> |
>> |
>> | Anyway I was thinking we can maybe add NumericVector::operator()( int,
>> | int) (other vectors as well), so that we can do :
>> |
>> | NumericVector m(x) ;
>> | double x11 = m(0,0) ;
>> |
>> |
>> | 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 :
>> |
>> | NumericVector m(x) ;
>> | NumericVector::MatrixIndexer indexer(m) ;
>> | double x11 = m[ indexer(0,0) ] ;
>> |
>> | But this might be even more ugly than operator().
>> |
>> |
>> | Given than a REALSXP can change its mind about being a matrix, I'm not
>> | sure I want to subclass NumericVector into NumericMatrix, etc. ...
>> |
>> | Ideas ?
>>
>> It's a really important topic, and I really don't know yet what I want.
>>
>> Recall another r-help questions of not too long ago when the almost-always-
>> complaining-yet-never-contributing Ivo Welch went on about needing a
>> faster lm().
>>
>> I once wrote one using GNU gsl for the ordinary least squares part, but one
>> can do much_ better with proper C++ classes. As a grad student, I published a
>> review paper in the J of Applied Econometrics about Newmat (a C++ library I
>> used a lot at the time), and things have come a long way since.
>>
>> Whit (also CC'ed) and I independently landed at using the clever armadillo
>> (templated C++) project at (IIRC) http://arma.sf.net, and there is also the
>> Eigen2 project (also templated C++, initially used only inside KDE).
>>
>> Whit essentially answered Ivo with a fast.lm project on github [ the boy is
>> lost in the wilderness and has yet not found the goodness that R-Forge is ;-)
>> -- see http://github.com/armstrtw/fast.lm ]
>>
>> Long story short: given that we pass these objects down to C++, we should
>> figure out a fast / light / convenient / elegant / [your term here] / ... way
>> to make use of them with other libraries.
>>
>> Dirk
>>
>> --
>> Three out of two people have difficulties with fractions.
>>
>


-- 
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