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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Nov 26 19:24:17 CET 2010


Author: romain
Date: 2010-11-26 19:24:17 +0100 (Fri, 26 Nov 2010)
New Revision: 2541

Modified:
   pkg/Rcpp/DESCRIPTION
   pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
Log:
Vector::operator+=( sugar expression) 

Modified: pkg/Rcpp/DESCRIPTION
===================================================================
--- pkg/Rcpp/DESCRIPTION	2010-11-26 15:11:12 UTC (rev 2540)
+++ pkg/Rcpp/DESCRIPTION	2010-11-26 18:24:17 UTC (rev 2541)
@@ -1,6 +1,6 @@
 Package: Rcpp
 Title: Seamless R and C++ Integration
-Version: 0.8.8.4
+Version: 0.8.8.5
 Date: $Date$
 Author: Dirk Eddelbuettel and Romain Francois, with contributions 
  by Douglas Bates, John Chambers, Simon Urbanek, and David Reiss; 

Modified: pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/Vector.h	2010-11-26 15:11:12 UTC (rev 2540)
+++ pkg/Rcpp/inst/include/Rcpp/vector/Vector.h	2010-11-26 18:24:17 UTC (rev 2541)
@@ -799,7 +799,44 @@
 		if( !::Rf_isMatrix(RObject::m_sexp) ) throw not_a_matrix() ;
 		return INTEGER( ::Rf_getAttrib( RObject::m_sexp, R_DimSymbol ) ) ;
 	}
+
 	
+public:
+    
+    template <bool EXPR_NA, typename EXPR_VEC>
+    Vector& operator+=( const VectorBase<RTYPE,EXPR_NA,EXPR_VEC>& rhs ){
+        const EXPR_VEC& ref = rhs.get_ref() ;
+        iterator start = begin() ;
+        int n = size() ;
+        // TODO: maybe unroll this
+        stored_type tmp ;
+        for( int i=0; i<n; i++){
+            Proxy left = start[i] ;
+            if( ! traits::is_na<RTYPE>( left ) ){
+                tmp = ref[i] ;
+                left = traits::is_na<RTYPE>( tmp ) ? tmp : ( left + tmp ) ;
+            }
+        }
+        return *this ;
+    }
+    
+    template <typename EXPR_VEC>
+    Vector& operator+=( const VectorBase<RTYPE,false,EXPR_VEC>& rhs ){
+        const EXPR_VEC& ref = rhs.get_ref() ;
+        iterator start = begin() ;
+        int n = size() ;
+        // TODO: maybe unroll this
+        stored_type tmp ;
+        for( int i=0; i<n; i++){
+            Proxy left = start[i] ;
+            if( ! traits::is_na<RTYPE>( left ) ){
+                left = left + ref[i] ;
+            }
+        }
+        return *this ;
+    }
+    
 } ; /* Vector */
 
+
 #endif



More information about the Rcpp-commits mailing list