[Rcpp-commits] r2338 - in pkg/RcppDE: . src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Oct 19 02:56:31 CEST 2010


Author: edd
Date: 2010-10-19 02:56:30 +0200 (Tue, 19 Oct 2010)
New Revision: 2338

Modified:
   pkg/RcppDE/benchmark.r
   pkg/RcppDE/benchmark.txt
   pkg/RcppDE/src/evaluate.cpp
Log:
benchmark.r now defaults to 5,10,20
added benchmark and bigBenchmark numbers
evaluate made simpler by return to REAL() to get to SEXP pointer


Modified: pkg/RcppDE/benchmark.r
===================================================================
--- pkg/RcppDE/benchmark.r	2010-10-18 19:47:19 UTC (rev 2337)
+++ pkg/RcppDE/benchmark.r	2010-10-19 00:56:30 UTC (rev 2338)
@@ -45,7 +45,7 @@
 svnver <- system("svnversion", intern=TRUE)
 cat("# At ", format(Sys.time()), "\n# SVN ", svnver, "\n")
 
-reps <- c(2, 5, 20)
+reps <- c(5, 10, 20)
 
 res <- rbind(do.call(rbind, lapply(reps, runPair, maxIt, function(...) Rastrigin(...))),
              do.call(rbind, lapply(reps, runPair, maxIt, function(...) Wild(...))),

Modified: pkg/RcppDE/benchmark.txt
===================================================================
--- pkg/RcppDE/benchmark.txt	2010-10-18 19:47:19 UTC (rev 2337)
+++ pkg/RcppDE/benchmark.txt	2010-10-19 00:56:30 UTC (rev 2338)
@@ -416,3 +416,35 @@
 Genrose50   2.494250 2.568750           1.0299      -2.98687
 MEANS       0.559650 0.570625           1.0196      -1.96105
 # Done  2010-10-18 07:23:07.486604 
+
+
+# At  2010-10-18 19:42:43.859417
+# SVN  2337M
+            DEoptim  RcppDE ratioRcppToBasic pctGainOfRcpp
+Rastrigin5  0.10663 0.10713          1.00469      -0.46893
+Rastrigin10 0.23312 0.22825          0.97909       2.09115
+Rastrigin20 0.54738 0.53800          0.98287       1.71272
+Wild5       0.18075 0.18237          1.00899      -0.89903
+Wild10      0.40675 0.41000          1.00799      -0.79902
+Wild20      1.04412 1.03588          0.99210       0.79014
+Genrose5    0.18100 0.18388          1.01588      -1.58840
+Genrose10   0.38137 0.37850          0.99246       0.75385
+Genrose20   0.88325 0.87988          0.99618       0.38211
+MEANS       0.44049 0.43821          0.99483       0.51711
+# Done  2010-10-18 19:44:06.829564
+
+
+# At  2010-10-18 19:49:15.391802
+# SVN  2337M
+             DEoptim RcppDE ratioRcppToBasic pctGainOfRcpp
+Rastrigin50    1.770  1.672          0.94463       5.53672
+Rastrigin100   4.825  4.467          0.92580       7.41969
+Rastrigin200  15.141 13.220          0.87313      12.68741
+Wild50         3.763  3.771          1.00213      -0.21260
+Wild100       11.466 11.198          0.97663       2.33735
+Wild200       38.585 36.861          0.95532       4.46806
+Genrose50      2.543  2.523          0.99214       0.78647
+Genrose100     6.191  5.891          0.95154       4.84574
+Genrose200    16.934 15.448          0.91225       8.77525
+MEANS         11.246 10.561          0.93907       6.09279
+# Done  2010-10-18 19:52:32.353386 

Modified: pkg/RcppDE/src/evaluate.cpp
===================================================================
--- pkg/RcppDE/src/evaluate.cpp	2010-10-18 19:47:19 UTC (rev 2337)
+++ pkg/RcppDE/src/evaluate.cpp	2010-10-19 00:56:30 UTC (rev 2338)
@@ -7,13 +7,21 @@
 
 #include <RcppArmadillo.h>
 
-//RcppExport double evaluate(long &l_nfeval, const arma::rowvec & param, SEXP parS, SEXP fcall, SEXP env) {
-RcppExport double evaluate(long &l_nfeval, const double *param, SEXP parS, SEXP fcall, SEXP env) {
-    Rcpp::NumericVector par(parS); 			// access parS as numeric vector to fill it
-    //std::copy(param.begin(), param.end(), par.begin()); // STL way of copying
-    memcpy(par.begin(), param, par.size() * sizeof(double));
+// Slighly accelerated version of evaluate to evaluate function fcall with parameters param in environment env
+// Uses externally allocated par() vector into which param are copied
+//
+RcppExport double evaluate(long &l_nfeval, const double *param, SEXP par, SEXP fcall, SEXP env) {
+    // -- safer approach: cast to NumericVector, fill it and eval
+    //Rcpp::NumericVector parvec(par); 			// access parS as numeric vector to fill it
+    //memcpy(parvec.begin(), param, parvec.size() * sizeof(double));
+    //SEXP fn = ::Rf_lang2(fcall, parvec); 			// this could be done with Rcpp 
+
+    // -- faster: direct access _assuming_ numeric vector
+    memcpy(REAL(par), param, Rf_nrows(par) * sizeof(double));
+
     SEXP fn = ::Rf_lang2(fcall, par); 			// this could be done with Rcpp 
     SEXP sexp_fvec = ::Rf_eval(fn, env);		// but is still a lot slower right now
+
     double f_result = Rcpp::as<double>(sexp_fvec);
     if (ISNAN(f_result)) 
 	::Rf_error("NaN value of objective function! \nPerhaps adjust the bounds.");



More information about the Rcpp-commits mailing list