Skip to content
Prev 5437 / 10988 Next

[Rcpp-devel] Working with arma::cube

Try this:

library(RcppArmadillo)
library(inline)
if( require( RcppArmadillo ) ){
	fx <- cxxfunction( signature(x = "vector", n = "integer") , '
		Rcpp::NumericVector XX(x);
		Rcpp::IntegerVector dim(n);
		arma::cube AY(XX.begin(), dim[0], dim[1], dim[2]);
		return(wrap(AY));
	', plugin = "RcppArmadillo" )
}

set.seed(10)
x = array(rnorm(25*25*10), dim=c(25,25,10))
y = fx(x, c(25,25,10))
all.equal(x,y)

Regards,
Alexios
On 06/03/2013 01:15, Dirk Eddelbuettel wrote: