-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pass 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.
The text was updated successfully, but these errors were encountered: