I enclose a rewrite of your function
R version 2.15.0 (2012-03-30)
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> require(inline)
Loading required package: inline
> code <- '
+ Function      fun(ff);
+ NumericVector par(pp);
+ NumericVector par1(par), par2(par);
+ const double a(2.), b(3.);
+ 
+ par1[0] *= a;
+ par2[0] *= b;
+ NumericVector f1(fun(par1)), f2(fun(par2));
+ return wrap(Rf_runif(0., 1.) <= (f1[0] - f2[0]));
+ '
> RcppGibbs <- cxxfunction(signature(pp = "numeric", ff="function"),
+                          code, plugin="Rcpp")
> ff <- function(par) dnorm(par[1]) * dnorm(par[2])
> 
> RcppGibbs(3., ff)
[1] FALSE
> 
> proc.time()
   user  system elapsed 
  4.888   0.388   5.390 

Attachment: foo.R
Description: Binary data

_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to