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

Dirk Eddelbuettel edd at debian.org
Fri Dec 17 17:11:22 CET 2010


On 17 December 2010 at 08:53, Christian Gunning wrote:
| 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:

Aie. Thanks for catching that.
 
| 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')

Yes, but that should happen behind the scenes. We'll look into it, and will
try to fix it and add some unit tests to cover this.

| 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.

You could also express your code in terms of Armadillo matrices.

Dirk

 
| thanks,
| Christian
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list