[Rcpp-commits] r2536 - in pkg/Rcpp: . inst/include inst/include/Rcpp inst/include/Rcpp/macros inst/include/Rcpp/vector

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Nov 26 15:30:51 CET 2010


Author: romain
Date: 2010-11-26 15:30:50 +0100 (Fri, 26 Nov 2010)
New Revision: 2536

Added:
   pkg/Rcpp/inst/include/Rcpp/macros/
   pkg/Rcpp/inst/include/Rcpp/macros/unroll.h
Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/vector/MatrixColumn.h
   pkg/Rcpp/inst/include/RcppCommon.h
Log:
added MatrixColumn::operator=( MatrixColumn& )

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2010-11-26 12:50:17 UTC (rev 2535)
+++ pkg/Rcpp/ChangeLog	2010-11-26 14:30:50 UTC (rev 2536)
@@ -4,6 +4,11 @@
     to R_MissingArg, usueful for formal arguments specifications, simpler form
     than List::create( _["foo"] = R_MissingArg )
     
+    * inst/include/Rcpp/macros/unroll.h: helper macro RCPP_UNROLL_LOOP
+    
+    * inst/include/Rcpp/vector/MatrixColumn.h: added MatrixColumn::operator=( MatrixColumn& )
+    otherwise it gets synthetized by the compiler
+    
 2010-11-25  Romain Francois <romain at r-enthusiasts.com>
 
     * inst/include/Rcpp/module/Module_generated_function.h: new .function with

Added: pkg/Rcpp/inst/include/Rcpp/macros/unroll.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/macros/unroll.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/macros/unroll.h	2010-11-26 14:30:50 UTC (rev 2536)
@@ -0,0 +1,47 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// unroll.h: Rcpp R/C++ interface class library -- loop unrolling macro 
+//
+// Copyright (C) 2010	Dirk Eddelbuettel and Romain Francois
+//
+// This file is part of Rcpp.
+//
+// Rcpp is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// Rcpp is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef Rcpp__macros_unroll_h
+#define Rcpp__macros_unroll_h
+   
+#define RCPP_LOOP_UNROLL(TARGET,SOURCE)           \
+int __trip_count = n >> 2 ;                       \
+int i = 0 ;                                       \
+for ( ; __trip_count > 0 ; --__trip_count) {      \
+	TARGET[i] = SOURCE[i] ; i++ ;                 \
+	TARGET[i] = SOURCE[i] ; i++ ;                 \
+	TARGET[i] = SOURCE[i] ; i++ ;                 \
+	TARGET[i] = SOURCE[i] ; i++ ;                 \
+}                                                 \
+switch (n - i){                                   \
+  case 3:                                         \
+      TARGET[i] = SOURCE[i] ; i++ ;               \
+  case 2:                                         \
+      TARGET[i] = SOURCE[i] ; i++ ;               \
+  case 1:                                         \
+      TARGET[i] = SOURCE[i] ; i++ ;               \
+  case 0:                                         \
+  default:                                        \
+      {}                                          \
+}
+
+
+#endif

Modified: pkg/Rcpp/inst/include/Rcpp/vector/MatrixColumn.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/MatrixColumn.h	2010-11-26 12:50:17 UTC (rev 2535)
+++ pkg/Rcpp/inst/include/Rcpp/vector/MatrixColumn.h	2010-11-26 14:30:50 UTC (rev 2536)
@@ -43,35 +43,23 @@
 	MatrixColumn& operator=( const Rcpp::VectorBase<RT,NA,T>& rhs ){
 	    int n = size() ;
 	    const T& ref = rhs.get_ref() ;
-	    
-	        int __trip_count = n >> 2 ;
-            int i = 0 ;
-            for ( ; __trip_count > 0 ; --__trip_count) { 
-            	start[i] = ref[i] ; i++ ;            
-            	start[i] = ref[i] ; i++ ;            
-            	start[i] = ref[i] ; i++ ;            
-            	start[i] = ref[i] ; i++ ;            
-            }                                            
-            switch (n - i){                          
-              case 3:                                    
-                  start[i] = ref[i] ; i++ ;             
-              case 2:                                    
-                  start[i] = ref[i] ; i++ ;             
-              case 1:                                    
-                  start[i] = ref[i] ; i++ ;             
-              case 0:                                    
-              default:                                   
-                  {}                         
-            }
-       return *this ;
+	    RCPP_LOOP_UNROLL(start,ref)
+	    return *this ;
 	}
+	
+	MatrixColumn& operator=( const MatrixColumn& rhs ){
+	    int n = size() ;
+	    iterator rhs_start = rhs.start ; 
+	    RCPP_LOOP_UNROLL(start,rhs_start)
+	    return *this ;
+	}
 
-	Proxy operator[]( int i ){
+	inline Proxy operator[]( int i ){
 		/* TODO: should we cache nrow and ncol */
 		return start[i] ;
 	}
 	
-	Proxy operator[]( int i ) const {
+	inline Proxy operator[]( int i ) const {
 		/* TODO: should we cache nrow and ncol */
 		return start[i] ;
 	}

Modified: pkg/Rcpp/inst/include/RcppCommon.h
===================================================================
--- pkg/Rcpp/inst/include/RcppCommon.h	2010-11-26 12:50:17 UTC (rev 2535)
+++ pkg/Rcpp/inst/include/RcppCommon.h	2010-11-26 14:30:50 UTC (rev 2536)
@@ -25,6 +25,7 @@
 #define RcppCommon_h
 
 #include <Rcpp/config.h>
+#include <Rcpp/macros/unroll.h>
 
 void logTxtFunction(const char* file, const int line, const char* expression ) ;
 



More information about the Rcpp-commits mailing list