[Rcpp-devel] No matching function for calls to Rmath.h

Dirk Eddelbuettel edd at debian.org
Thu Sep 16 01:30:21 CEST 2010


On 15 September 2010 at 15:27, Davor Cubranic wrote:
| For some reason, after upgrading Rcpp from 0.8.3 to 0.8.6 and RcppArmadillo
| from 0.2.3 to 0.2.6, my code cannot use functions in Rmath.h. This happens in
| R 2.10.1 and 2.11.1. Example: 
| 
| fx <- cxxfunction( signature( a = "numeric", b = "numeric" ), '
| Rcpp::NumericVector xa(a);
| Rcpp::NumericVector xb(b);
| int n = xa.size() ;
| Rcpp::NumericVector xdpois(n);
| for (int i = 0; i < n; i++) {
|   xdpois = dpois(xa(i), xb(i), 0);
| }
| return xdpois;
| 
| ', includes="#include <Rmath.h>", plugin = "Rcpp" )
| 
| file44c9b62d.cpp: In function 'SEXPREC* file44c9b62d(SEXPREC*, SEXPREC*)':
| file44c9b62d.cpp:35: error: no matching function for call to 'dpois(double&, double&, int)'
| make: *** [file44c9b62d.o] Error 1
| 
| ERROR(s) during compilation: source code errors or compiler configuration errors!


It's a feature :)   

First, the fix -- use ::Rf_dpois to access R's scalar variant directly:

> fx <- cxxfunction( signature( a = "numeric", b = "numeric" ), '
+ Rcpp::NumericVector xa(a);
+ Rcpp::NumericVector xb(b);
+ int n = xa.size() ;
+ Rcpp::NumericVector xdpois(n);
+ for (int i = 0; i < n; i++) {
+   xdpois = ::Rf_dpois(xa(i), xb(i), 0);
+ }
+ return xdpois;
+ ', plugin = "Rcpp" )
> fx(1:5, seq(0.1, 0.5, by=0.1))
[1] 0.00015795 0.00000000 0.00000000 0.00000000 0.00000000
>

That is needed because we have new 'sugar' functions that are vectorised and
directly accessible:

> fx2 <- cxxfunction( signature( a = "numeric", b = "numeric" ), '
+ Rcpp::NumericVector xa(a);
+ double xb = Rcpp::as<double>(b);
+ Rcpp::NumericVector xdpois = dpois(xa, xb);
+ return xdpois;
+ ', plugin = "Rcpp" )
> fx2(1:5, 0.5)
[1] 0.30326533 0.07581633 0.01263606 0.00157951 0.00015795
> 

See, no loops :)  

 But it is only vectorised in terms of the first argument so you don't
_exactly_ get a replacement to your code.

The NEWS file etc would have lead you there, but then we tend to change so
many things that it is easy to overlook items :)

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


More information about the Rcpp-devel mailing list