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

@antoniopvgs antoniopvgs commented Apr 25, 2015

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

@eddelbuettel eddelbuettel commented Apr 25, 2015

Pull requests would be welcome.

@antoniopvgs
Copy link
Author

@antoniopvgs antoniopvgs commented Apr 25, 2015

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

@eddelbuettel eddelbuettel commented Dec 1, 2015

This has been added in #64.

@gvegayon
Copy link
Contributor

@gvegayon 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

@eddelbuettel eddelbuettel commented Dec 1, 2015

Our thanks to @nathan-russell 😃

@antoniopvgs
Copy link
Author

@antoniopvgs antoniopvgs commented Dec 1, 2015

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

@eddelbuettel eddelbuettel commented Dec 1, 2015

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

@nathan-russell nathan-russell commented Dec 1, 2015

@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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.