Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign uppass arma::cube object as function argument gives error #42
Comments
|
Pull requests would be welcome. |
|
Hi Dirk, that's fair. I'm far from being an expert programmer but found the following code that solves the problem. However, I don't know how easy would be integrating it in your package: #include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
arma::cube array2cube( SEXP myArray ) {
Rcpp::NumericVector vecArray(myArray);
Rcpp::IntegerVector arrayDims = vecArray.attr("dim");
arma::cube cubeArray(vecArray.begin(), arrayDims[0], arrayDims[1], arrayDims[2], false);
return(cubeArray);
}Many thanks in any case for providing the Rcpp package. |
|
This has been added in #64. |
|
Great! George G. Vega Yon (from mobile)
|
|
Our thanks to @nathan-russell |
|
Thanks a lot.
|
|
For completeness: R> library(Rcpp)
R> cppFunction("arma::cube doubleCube(arma::cube cb) { return 2*cb; }",
+ depends="RcppArmadillo")
R> doubleCube(array(1:8, dim=c(2,2,2)))
, , 1
[,1] [,2]
[1,] 2 6
[2,] 4 8
, , 2
[,1] [,2]
[1,] 10 14
[2,] 12 16
R> Thanks again @nathan-russell ! |
|
@eddelbuettel More than happy to help where I'm able to |
I don not think this is a bug but if you pass and arma::mat object or arma::field as an argument to a function instead, the code runs smoothly. Therefore it seems that the package does not implement the same functionality for arma::cube.