[Rcpp-devel] as cube

MISRA, SANJOG sanjog.misra at simon.rochester.edu
Mon Jun 6 19:15:33 CEST 2011


Richard,

I usually use a list for this (see below). If anybody has a simpler way,
I would love to learn about it...

Sanjog

 

src.cube = '

Rcpp::List aL(aL_);

int nr = Rcpp::as<int>(nr_);

int nc = Rcpp::as<int>(nc_);

int ns = Rcpp::as<int>(ns_);

 

arma::cube a(nr,nc,ns);

 

for(int i=0; i<ns; i++) {

a.slice(i) = Rcpp::as<arma::mat>(aL(i));

}

 

return Rcpp::wrap(a);

'

 

fx = cxxfunction(signature(aL_="list", nr_="integer", nc_="integer",
ns_="integer"),body = src.cube, plugin="RcppArmadillo")

 

aR = array(1:27,c(3,3,3))

aL = NULL;

for(i in 1:3)   aL[[i]] = aR[,,i] 

 

fx(aL,3,3,3)

 

 

Sanjog Misra

Associate Professor of Marketing and Applied Statistics

Area Coordinator, Applied Statistics

Simon School of Business

University of Rochester

Rochester, NY 14627

P: 585.275.8920

F: 585.273.1140

 

From: rcpp-devel-bounces at r-forge.wu-wien.ac.at
[mailto:rcpp-devel-bounces at r-forge.wu-wien.ac.at] On Behalf Of Richard
Chandler
Sent: Monday, June 06, 2011 11:13 AM
To: rcpp-devel
Subject: [Rcpp-devel] as cube

 

Hi, 

I would like to do something like this:

src.cube <- "
    arma::cube a = as<arma::cube>(aR);
    return wrap(a);
    "
fx <- cxxfunction(signature(aR="array"), src.cube,
plugin="RcppArmadillo")
fx(array(1:27, c(3,3,3)))


But it fails. Can someone suggest a good alternative? I tried to create
the cube on the C++ side and use .fill() to fill it with a
NumericVector, but this did not work either.

Thanks,
Richard

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110606/325d5634/attachment-0001.htm>


More information about the Rcpp-devel mailing list