Skip to content
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

Closed
antoniopvgs opened this issue Apr 25, 2015 · 8 comments
Closed

pass arma::cube object as function argument gives error #42

antoniopvgs opened this issue Apr 25, 2015 · 8 comments

Comments

@antoniopvgs
Copy link

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.

@eddelbuettel
Copy link
Member

Pull requests would be welcome.

@antoniopvgs
Copy link
Author

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.

@eddelbuettel
Copy link
Member

This has been added in #64.

@gvegayon
Copy link
Contributor

gvegayon commented Dec 1, 2015

Great!

George G. Vega Yon (from mobile)
+1 626 381 8171
http://www.its.caltech.edu/~gvegayon
On Dec 1, 2015 4:10 AM, "Dirk Eddelbuettel" notifications@github.com
wrote:

This has been added in #64
#64.


Reply to this email directly or view it on GitHub
#42 (comment)
.

@eddelbuettel
Copy link
Member

Our thanks to @nathan-russell 😃

@antoniopvgs
Copy link
Author

Thanks a lot.
El 1 dic. 2015 1:10 p. m., "Dirk Eddelbuettel" notifications@github.com
escribió:

This has been added in #64
#64.


Reply to this email directly or view it on GitHub
#42 (comment)
.

@eddelbuettel
Copy link
Member

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 !

@nathan-russell
Copy link
Contributor

@eddelbuettel More than happy to help where I'm able to 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants