[Rcpp-devel] Regression in conversion from NumericVector to ComplexVector?

Christian Gunning xian at unm.edu
Fri Dec 17 16:53:49 CET 2010

I just tried to rebuild a package that built successfully as of
~August.  With new Rcpp, it fails on assigning a NumericVector to a
ComplexVector.  The gist seems to be as follows:

test1 = cxxfunction(, '
    ComplexVector tmpc(10);
    NumericVector tmpd(10, 2.0);
    tmpc = tmpc + tmpd;
 ', plugin='Rcpp')

file50eaa187.cpp:32: error: no match for ‘operator+’ in ‘tmpc + tmpd’
note: candidates are: Rcpp::sugar::Plus_Vector_Primitive<RTYPE, NA, T>
operator+(typename Rcpp::traits::storage_type<RTYPE>::type, const
Rcpp::VectorBase<RTYPE, NA, VECTOR>&) [with int RTYPE = 14, bool NA =
true, T = Rcpp::Vector<14>]

test2 = cxxfunction(, '
    NumericVector tmpd(10, 2.0);
    ComplexVector tmpc = tmpd;
 ', plugin='Rcpp')

file5b2fd8b.cpp:31: error: conversion from ‘Rcpp::NumericVector’ to
non-scalar type ‘Rcpp::ComplexVector’ requested

test3 = cxxfunction(, '
    ComplexVector tmpc(10, 0.0);
 ', plugin='Rcpp')

  Compilation ERROR, function(s)/method(s) not created!
In function ‘TO Rcpp::internal::caster(FROM) [with FROM = double, TO =


test2works = cxxfunction(, '
    NumericVector tmpd(10, 2.0);
    int nn = tmpd.size();
    ComplexVector tmpc(nn);
    Rcomplex rc;
    rc.r = rc.i = 0;
    for (int i = 0; i<nn; i++ ) {
      rc.r = tmpd[i];
      tmpc[i] = rc  ;
 ', plugin='Rcpp')

A bit of background - an excerpt of the code that orginaly worked was:

ComplexVector CwtScale(ComplexVector FreqSignal, double centralFreq,
int moments, double scale, int signalSize, pwavefun waveletFun,
ComplexVector *FreqWavelet )
  *FreqWavelet = waveletFun(centralFreq, moments, scale, signalSize);

waveletFun returns a NumericVector, but *FreqWavelet is multiplied by
the ComplexVector FreqSignal.  So, either test1 or test2 would work
here. Does a working double->R caster (test3) fix test2?  I can update
unit tests accordingly.


More information about the Rcpp-devel mailing list