[Rcpp-devel] RcppArmadillo: passing complex matrices

baptiste Auguié baptiste.auguie at googlemail.com
Fri Aug 6 15:56:24 CEST 2010


Dear list,

I finally succeeded in porting some code from R to c++, with great performance improvement, although I suspect there are many ugly things since I don't really know c++. One particular worry of mine is the construct I use to pass a complex matrix from R to the armadillo code. Typically, I do the following (a lot),

using namespace Rcpp ;
using namespace RcppArmadillo ;
using namespace std;

extern "C" {

 SEXP  foo(SEXP betar, SEXP betai){

      Rcpp::NumericMatrix Brc(betar), Bic(betai);
      arma::cx_mat B =  arma::cx_mat( arma::mat(Brc.begin(), 3, N, false),  arma::mat(Bic.begin(), 3, N, false)); 

// [...]
}
}

where betar and betai have been obtained at the R level as Re(beta) and Im(beta).

Is there a simpler, more efficient and sweeter way?

Best regards,

baptiste



More information about the Rcpp-devel mailing list