[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;
    return(tmpc);
 ', plugin='Rcpp')

file50eaa187.cpp:32: error: no match for ‘operator+’ in ‘tmpc + tmpd’
/home/xian/R/x86_64-pc-linux-gnu-library/2.8/Rcpp/include/Rcpp/sugar/operators/plus.h:262:
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;
    return(tmpc);
 ', plugin='Rcpp')


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

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

  Compilation ERROR, function(s)/method(s) not created!
/home/xian/R/x86_64-pc-linux-gnu-library/2.8/Rcpp/include/Rcpp/internal/caster.h:
In function ‘TO Rcpp::internal::caster(FROM) [with FROM = double, TO =
Rcomplex]’:

Workaround:

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  ;
    }
    return(tmpc);
 ', 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.

thanks,
Christian


More information about the Rcpp-devel mailing list