[Rcpp-commits] r2204 - in pkg/Rcpp: . inst/examples inst/examples/performance inst/include/Rcpp/sugar/nona inst/include/Rcpp/sugar/operators

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Sep 27 08:14:59 CEST 2010


Author: romain
Date: 2010-09-27 08:14:56 +0200 (Mon, 27 Sep 2010)
New Revision: 2204

Added:
   pkg/Rcpp/inst/examples/performance/
   pkg/Rcpp/inst/examples/performance/performance.R
Modified:
   pkg/Rcpp/TODO
   pkg/Rcpp/inst/include/Rcpp/sugar/nona/nona.h
   pkg/Rcpp/inst/include/Rcpp/sugar/operators/minus.h
Log:
typos

Modified: pkg/Rcpp/TODO
===================================================================
--- pkg/Rcpp/TODO	2010-09-26 19:45:20 UTC (rev 2203)
+++ pkg/Rcpp/TODO	2010-09-27 06:14:56 UTC (rev 2204)
@@ -104,4 +104,4 @@
     o	many dpq functions have not been tested yet
 	
     o	new autogenerated sugar functions: cos, acosh, atan, cos, cosh, log, 
-	log10, sqrt, sin, sinh, tan, tanh
+	log10, sqrt, sin, sinh, tan, tanh    

Added: pkg/Rcpp/inst/examples/performance/performance.R
===================================================================
--- pkg/Rcpp/inst/examples/performance/performance.R	                        (rev 0)
+++ pkg/Rcpp/inst/examples/performance/performance.R	2010-09-27 06:14:56 UTC (rev 2204)
@@ -0,0 +1,36 @@
+
+require( inline )
+require( Rcpp )
+
+expressions <- list( 
+    times = "nona(x) * y", 
+    plus = "x + y", 
+    minus = "x - y", 
+    divides = "x / y", 
+    exp_ = "exp( x )"
+)
+
+signatures <- lapply( expressions, function(.) signature( x_ = "numeric", y_ = "numeric", n_ = "integer" ) )
+bodies <- lapply( expressions, function(.){
+   sprintf( '
+    int n = as<int>( n_ ) ;
+    NumericVector x(x_), y(y_), z(x.size()) ;
+    for( int i=0; i<n; i++){
+        z = %s ;
+    }
+    return z ;
+', . ) 
+} )
+
+fx <- cxxfunction( signatures, bodies, plugin = "Rcpp" )
+
+set.seed( 43231 )
+x <- runif( 100000, min = 1, max = 100)
+y <- runif( 100000, min = 1, max = 100)
+# resolving the dyn lib once
+invisible( lapply( fx, function(f){ f( x, y, 1L) } ) )
+
+sapply( fx, function(f){
+    system.time( f( x, y, 1000 ) )
+} )
+

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/nona/nona.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/nona/nona.h	2010-09-26 19:45:20 UTC (rev 2203)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/nona/nona.h	2010-09-27 06:14:56 UTC (rev 2204)
@@ -48,13 +48,14 @@
         typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE ;
         typedef typename Rcpp::Vector<RTYPE>::iterator iterator ;
 	
-        Nona( const SUGAR_TYPE& expr) : data(expr.get_ref().begin()){} 
+        Nona( const SUGAR_TYPE& expr) : data(expr.get_ref().begin()), n(expr.size()){} 
         
-        inline int size() const { return data.size() ; }
+        inline int size() const { return n ; }
         inline STORAGE operator[](int i) const { return data[i] ; }
         
     private:
-        iterator data ;    
+        iterator data ;
+        int n ;
     } ;
     
     template <typename T>

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/operators/minus.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/operators/minus.h	2010-09-26 19:45:20 UTC (rev 2203)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/operators/minus.h	2010-09-27 06:14:56 UTC (rev 2204)
@@ -221,7 +221,7 @@
 	private:
 		STORAGE lhs ;
 		const T& rhs ;
-		bool rhs_na ;
+		bool lhs_na ;
 		
 	} ;
 



More information about the Rcpp-commits mailing list