[Rcpp-devel] matrix indexing
Dirk Eddelbuettel
edd at debian.org
Sat Jan 23 21:23:06 CET 2010
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