[Rcpp-devel] as<arma::cx_double>(x)

Dirk Eddelbuettel edd at debian.org
Wed Oct 26 15:22:56 CEST 2011


On 26 October 2011 at 15:05, baptiste auguie wrote:
| Dear list,
| 
| I'm probably missing something basic, but I expected the following to work,
| 
| library(RcppArmadillo)
| library(inline)
| 
| fx <- cxxfunction(signature(x = "Rcomplex") , '
|          arma::cx_double y = as<arma::cx_double>(x);
|          return wrap( y ) ;
|        ', plugin = "RcppArmadillo" )
| 
| 
| fx( 1+2i )
| 
| yet it fails to compile. I believe I need a conversion since arma does
| not know what to do with Rcomplex objects, e.g. multiplying x by i =
| arma::cx_double(0,1) yields
| 
| error: no match for 'operator*' in 'x * i'
| 
| I've successfully used cx_vec instead of cx_double,
| 
| fx <- cxxfunction(signature(x = "Rcomplex") , '
|          arma::cx_vec y = as<arma::cx_vec>(x);
|          const arma::cx_double i = arma::cx_double(0,1);
|          return wrap( y * i ) ;
|        ', plugin = "RcppArmadillo" )
| 
| fx( 1+2i )
| 
| Does this make sense?

At best sort of :)  

I am scratching my head a little as I don't even know where cx_double support
comes from. We don't define any of this:

  edd at max:~/svn/rcpp/pkg/Rcpp/inst/include$ grep -rin cx_double .
  edd at max:~/svn/rcpp/pkg/Rcpp/inst/include$ grep -rin cx_complex .
  edd at max:~/svn/rcpp/pkg/Rcpp/inst/include$ 

Dirk

-- 
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is too
dark to read." -- Groucho Marx


More information about the Rcpp-devel mailing list