[Rcpp-devel] List of matrices mimicking 3d array?

Dirk Eddelbuettel edd at debian.org
Thu Nov 10 00:38:44 CET 2011


On 9 November 2011 at 18:19, Edward Wallace wrote:
| Dear All,
| I have just started using Rcpp and found it very useful. A step of my
| calculation would naturally be done in a 3D array, and am trying to
| work around this. May I gently make a feature request for Rcpp::array?
| 
| My workround idea involves trying to use lists of matrices. Since it
| is array-like, I would like to initialize a list with many matrices of
| the same size. Many for my problem means between 6 and ~100. I can do
| this like so:
| 
| listcreate <- cxxfunction( signature(),'
|     NumericMatrix m(3,5);
|     List mmm = List::create(m,m,m,m) ;
|     return wrap(mmm);
|     ', plugin= "Rcpp")
| But this requires the number of entries to be hard-coded. Really I
| would like to do something more like:
| 
| listcreatebetter <- cxxfunction( signature(),'
|     NumericMatrix m(3,5);
|     List mmm = List::createclones(4,m) ;
|     return wrap(mmm);
|     ', plugin= "Rcpp")
| which of course does not work.
| 
| Is there an easy way to do that? Or is there a native C++ class I
| could use to skirt the issue?
| 
| This is my first post on the list and so I approach with some trepidation.

Our arrays in Rcpp can be multidimensional just like they can in R. Here is a
line from one of the unit tests:

   return IntegerVector( Dimension( 2, 3, 4) ) ;

which sets the dim attribute of a given vector to c(2,3,4) just like you
would in R.  That should all work too but may have seen less exposure than
other parts of our code.

One easy alternative to get want you want is to go one step further from Rcpp
to RcppArmadillo and use the Armadillo 'Cube' classes with are in fact proper
three-dimensional arrays:

   http://arma.sourceforge.net/docs.html#Cube


Dirk



| 
| Thanks,
| Edward
| 
| -- 
| Edward Wallace, PhD
| Harvard FAS center for Systems Biology
| +1-773-517-4009
| _______________________________________________
| 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

-- 
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is too
dark to read." -- Groucho Marx


More information about the Rcpp-devel mailing list