[Rcpp-devel] matrix indexing

Whit Armstrong armstrong.whit at gmail.com
Sun Jan 24 00:42:11 CET 2010


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

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?

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


More information about the Rcpp-devel mailing list