[Rcpp-commits] r4007 - in pkg/Rcpp: . inst/include/Rcpp/sugar/functions/mapply inst/include/Rcpp/vector

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Nov 21 14:04:15 CET 2012


Author: romain
Date: 2012-11-21 14:04:14 +0100 (Wed, 21 Nov 2012)
New Revision: 4007

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/sugar/functions/mapply/mapply_3.h
   pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
Log:
improvements in mapply

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2012-11-21 12:46:44 UTC (rev 4006)
+++ pkg/Rcpp/ChangeLog	2012-11-21 13:04:14 UTC (rev 4007)
@@ -7,6 +7,9 @@
 2012-11-21  Romain Francois <romain at r-enthusiasts.com>
 
         * include/Rcpp/iostream/Rostream.h: Fix warning given by -Wreorder
+        * include/Rcpp/sugar/functions/mapply/mapply_3.h: more flexible
+        * include/Rcpp/vector/Vector.h: More efficient assign_object, which is 
+        used in the assignment operator
 
 2012-11-20  JJ Allaire <jj at rstudio.org>
 

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/functions/mapply/mapply_3.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/functions/mapply/mapply_3.h	2012-11-21 12:46:44 UTC (rev 4006)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/functions/mapply/mapply_3.h	2012-11-21 13:04:14 UTC (rev 4007)
@@ -25,10 +25,10 @@
 namespace Rcpp{
 namespace sugar{
 
-template <int RTYPE, 
-    bool NA_1, typename T_1, 
-    bool NA_2, typename T_2, 
-    bool NA_3, typename T_3, 
+template <
+    int RTYPE_1, bool NA_1, typename T_1, 
+    int RTYPE_2, bool NA_2, typename T_2, 
+    int RTYPE_3, bool NA_3, typename T_3, 
     typename Function
 >
 class Mapply_3 : public VectorBase< 
@@ -36,18 +36,18 @@
 		typename ::Rcpp::traits::result_of<Function>::type
 	>::rtype , 
 	true ,
-	Mapply_3<RTYPE,NA_1,T_1,NA_2,T_2,NA_3,T_3,Function>
+	Mapply_3<RTYPE_1,NA_1,T_1,RTYPE_2,NA_2,T_2,RTYPE_3,NA_3,T_3,Function>
 > {
 public:         
 	typedef typename ::Rcpp::traits::result_of<Function>::type result_type ;
 	
-    typedef Rcpp::VectorBase<RTYPE,NA_1,T_1> VEC_1 ;
-	typedef Rcpp::VectorBase<RTYPE,NA_2,T_2> VEC_2 ;
-	typedef Rcpp::VectorBase<RTYPE,NA_3,T_3> VEC_3 ;
+    typedef Rcpp::VectorBase<RTYPE_1,NA_1,T_1> VEC_1 ;
+	typedef Rcpp::VectorBase<RTYPE_2,NA_2,T_2> VEC_2 ;
+	typedef Rcpp::VectorBase<RTYPE_3,NA_3,T_3> VEC_3 ;
 	
-	typedef typename Rcpp::traits::Extractor<RTYPE,NA_1,T_1>::type EXT_1 ;
-	typedef typename Rcpp::traits::Extractor<RTYPE,NA_2,T_2>::type EXT_2 ;
-	typedef typename Rcpp::traits::Extractor<RTYPE,NA_3,T_3>::type EXT_3 ;
+	typedef typename Rcpp::traits::Extractor<RTYPE_1,NA_1,T_1>::type EXT_1 ;
+	typedef typename Rcpp::traits::Extractor<RTYPE_2,NA_2,T_2>::type EXT_2 ;
+	typedef typename Rcpp::traits::Extractor<RTYPE_3,NA_3,T_3>::type EXT_3 ;
 	
 	Mapply_3( const VEC_1& vec_1_, const VEC_2& vec_2_, const VEC_3& vec_3_, Function fun_ ) : 
 		vec_1(vec_1_.get_ref()), vec_2(vec_2_.get_ref()), vec_3(vec_3_.get_ref()), fun(fun_){}
@@ -66,15 +66,20 @@
 	
 } // sugar
 
-template <int RTYPE, bool NA_1, typename T_1, bool NA_2, typename T_2, bool NA_3, typename T_3, typename Function >
-inline sugar::Mapply_3<RTYPE,NA_1,T_1,NA_2,T_2,NA_3,T_3,Function> 
+template <
+    int RTYPE_1, bool NA_1, typename T_1, 
+    int RTYPE_2, bool NA_2, typename T_2, 
+    int RTYPE_3, bool NA_3, typename T_3, 
+    typename Function
+    >
+inline sugar::Mapply_3<RTYPE_1,NA_1,T_1,RTYPE_2,NA_2,T_2,RTYPE_3, NA_3,T_3,Function> 
 mapply( 
-    const Rcpp::VectorBase<RTYPE,NA_1,T_1>& t1, 
-    const Rcpp::VectorBase<RTYPE,NA_2,T_2>& t2, 
-    const Rcpp::VectorBase<RTYPE,NA_3,T_3>& t3, 
+    const Rcpp::VectorBase<RTYPE_1,NA_1,T_1>& t1, 
+    const Rcpp::VectorBase<RTYPE_2,NA_2,T_2>& t2, 
+    const Rcpp::VectorBase<RTYPE_3,NA_3,T_3>& t3, 
     Function fun
 ){
-	return sugar::Mapply_3<RTYPE,NA_1,T_1,NA_2,T_2,NA_3,T_3,Function>( t1, t2, t3, fun ) ;
+	return sugar::Mapply_3<RTYPE_1,NA_1,T_1,RTYPE_2,NA_2,T_2,RTYPE_3,NA_3,T_3,Function>( t1, t2, t3, fun ) ;
 }
 
 } // Rcpp

Modified: pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/Vector.h	2012-11-21 12:46:44 UTC (rev 4006)
+++ pkg/Rcpp/inst/include/Rcpp/vector/Vector.h	2012-11-21 13:04:14 UTC (rev 4007)
@@ -88,30 +88,28 @@
     
 private:
     
-    // sugar
     template <typename T>
-    inline void assign_object( const T& x, traits::true_type ){
+    inline void assign_sugar_expression( const T& x ){
         int n = size() ;
         if( n == x.size() ){
-           
             // just copy the data 
             iterator start = begin() ;
             
             int __trip_count = n >> 2 ;
             int i = 0 ;
             for ( ; __trip_count > 0 ; --__trip_count) { 
-            	start[i] = x[i] ; i++ ;            
-            	start[i] = x[i] ; i++ ;            
-            	start[i] = x[i] ; i++ ;            
-            	start[i] = x[i] ; i++ ;            
+            	*start++ = x[i++] ;            
+            	*start++ = x[i++] ;            
+            	*start++ = x[i++] ;            
+            	*start++ = x[i++] ;            
             }                                            
             switch (n - i){                          
             case 3:                                    
-                start[i] = x[i] ; i++ ;             
+                *start++ = x[i++] ;             
             case 2:                                    
-                start[i] = x[i] ; i++ ;             
+                *start++ = x[i++] ;             
             case 1:                                    
-                start[i] = x[i] ; i++ ;             
+                *start++ = x[i++] ;             
             case 0:                                    
             default:                                   
                 {}                         
@@ -122,6 +120,12 @@
         }
     }
     
+    // sugar
+    template <typename T>
+    inline void assign_object( const T& x, traits::true_type ){
+        assign_sugar_expression( x.get_ref() ) ;
+    }
+    
     // anything else
     template <typename T>
     inline void assign_object( const T& x, traits::false_type ){



More information about the Rcpp-commits mailing list