[Rcpp-devel] Multiplication of ComplexVector?
Christian Gunning
xian at unm.edu
Wed Aug 18 07:44:19 CEST 2010
Thanks to all for the helpful suggestions. I was excited to learn
about Armadillo's plans for fft/ifft -- my original interest in Rcpp
was to facilitate the R fft call from C...
For conceptual simplicity, I'm opting for manually adding an operator*
for now. Benchmarks show a ~10% speedup over sending large vectors (2
million) to R for multiplication.
One question that I ran into that I don't quite understand -- there
are several permutations of an Rcomplex-returning operator*, depending
upon the type of lhs and rhs (e.g Rcomplex and Rcomplex; Rcomplex and
double; etc.). I admit, the template system is over my head for now,
and this has a low priority for me, but perhaps there's a simple
explanation asides from using separate operator symbols?
Here are 2 definitions that vary in input type:
Rcomplex operator*( const Rcomplex& lhs, const Rcomplex& rhs){
Rcomplex y ;
y.r = lhs.r * rhs.r - lhs.i * rhs.i ;
y.i = lhs.r * rhs.i + rhs.r * lhs.i ;
return y ;
}
Rcomplex operator*( const Rcomplex& lhs, const double& rhs){
Rcomplex y ;
y.r = lhs.r * rhs ;
y.i = lhs.i * rhs ;
return y ;
}
yielding the following compiler error:
rcpp_operators.h:7: error: declaration of C function ‘Rcomplex
operator*(const Rcomplex&, const double&)’ conflicts with
rcpp_operators.h:6: error: previous declaration ‘Rcomplex
operator*(const Rcomplex&, const Rcomplex&)’ here
best,
Christian
--
A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama!
More information about the Rcpp-devel
mailing list