Hi James, On 16 August 2013 at 11:59, James Li wrote: | Dear Dirk and Rcpp-devel members, | | I am currently passing a multidimensional (N > 2) array (i.e. | array(NA, dim = rep(3,5)) ) from R via Rcpp using
How big is 'N' going to be? | "in C++:" | | //[[Rcpp::export]] | Rcpp::List check_arrayC (Rcpp::NumericVector x, Rcpp::IntegerVector modes){ | //do stuff to x | return Rcpp::List::create(Rcpp::_["data"] = x, Rcpp::_["modes"] = modes); | } | | | "in R:" | | a <- array(1:32, dim=rep(2,5)) | b <- check_arrayC(a, dim(a)) | | While I know that a multidimensional array is stored as a contiguous | array internally, is there currently a more natural/efficient way to | pass it back and forth within Rcpp? | | Also from Dirk's book, it seems that an instance of | Rcpp::NumericVector can be instantiated into a multidimensional array | via | | Rcpp::NumericVector vec3 =Rcpp::NumericVector( Rcpp::Dimension(4, 5, 6)); | | In this case, how do we access element vec3[1,2,3]? | | Some background about what I am trying to do: I would like to create a | multidimensional array wrapper class around the base R multi-way array | class. I would also like to be able to pass this multidimensional | array via Rcpp to do all the heavy-lifting in c++. Ideally, I could | also convert the mda into a Boost::multi_array. For a moderately-sized project (at work, not open source) I had a very good experience using Armadillo 'cubes' (3-d matrices) which I occassionally stored in 'fields' (which I though of as lists of such cubes). I think in most (all?) cases I reduces data to 2-d matrices before returning that R. That worked great. Beyond that ... you are on your own as there is very little C++ support already useable by Rcpp. You'd have to write custom as<>() and wrap() methods (which is not hard and may well be worth it). Cheers, Dirk | Thanks in advance for any help. | | -James | | -- | James Li | Ph.D. Candidate | http://jamesyili.com/ | Dept. of Statistical Science | Cornell University | _______________________________________________ | Rcpp-devel mailing list | Rcpp-devel@lists.r-forge.r-project.org | https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel -- Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com _______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel