[Rcpp-commits] r3179 - in pkg/Rcpp: . inst/examples/OpenMP

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Aug 26 18:08:45 CEST 2011


Author: edd
Date: 2011-08-26 18:08:44 +0200 (Fri, 26 Aug 2011)
New Revision: 3179

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/examples/OpenMP/OpenMPandInline.r
Log:
added Davor's variants using std::transform()


Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2011-08-25 22:50:51 UTC (rev 3178)
+++ pkg/Rcpp/ChangeLog	2011-08-26 16:08:44 UTC (rev 3179)
@@ -1,3 +1,8 @@
+2011-08-26  Dirk Eddelbuettel  <edd at debian.org>
+
+	* inst/examples/OpenMP/OpenMPandInline.r: Added two std::transform()
+	variants as suggested in rcpp-devel email by Davor Cubranic
+
 2011-08-25  Dirk Eddelbuettel  <edd at debian.org>
 
 	* inst/examples/OpenMP/OpenMPandInline.r: Added new example for

Modified: pkg/Rcpp/inst/examples/OpenMP/OpenMPandInline.r
===================================================================
--- pkg/Rcpp/inst/examples/OpenMP/OpenMPandInline.r	2011-08-25 22:50:51 UTC (rev 3178)
+++ pkg/Rcpp/inst/examples/OpenMP/OpenMPandInline.r	2011-08-26 16:08:44 UTC (rev 3179)
@@ -14,6 +14,13 @@
 '
 funSerial <- cxxfunction(signature(xs="numeric"), body=serialCode, plugin="Rcpp")
 
+serialStdAlgCode <- '
+   std::vector<double> x = Rcpp::as<std::vector< double > >(xs);
+   std::transform(x.begin(), x.end(), x.begin(), ::log);
+   return Rcpp::wrap(x);
+'
+funSerialStdAlg <- cxxfunction(signature(xs="numeric"), body=serialStdAlgCode, plugin="Rcpp")
+
 ## same, but with Rcpp vector just to see if there is measurable difference
 serialRcppCode <- '
    // assign to C++ vector
@@ -26,6 +33,13 @@
 '
 funSerialRcpp <- cxxfunction(signature(xs="numeric"), body=serialRcppCode, plugin="Rcpp")
 
+serialStdAlgRcppCode <- '
+   Rcpp::NumericVector x = Rcpp::NumericVector(xs);
+   std::transform(x.begin(), x.end(), x.begin(), ::log);
+   return x;
+'
+funSerialStdAlgRcpp <- cxxfunction(signature(xs="numeric"), body=serialStdAlgRcppCode, plugin="Rcpp")
+
 ## now with a sugar expression with internalizes the loop
 sugarRcppCode <- '
    // assign to C++ vector
@@ -56,6 +70,7 @@
 
 z <- seq(1, 2e6)
 res <- benchmark(funSerial(z), funOpenMP(z),
+                 funSerialStdAlgRcpp(z), funSerialStdAlg(z),
                  funSerialRcpp(z), funSugarRcpp(z),
                  columns=c("test", "replications", "elapsed",
                            "relative", "user.self", "sys.self"),



More information about the Rcpp-commits mailing list