[Rcpp-commits] r2212 - pkg/Rcpp/inst/include/Rcpp/sugar/operators

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Sep 27 15:30:38 CEST 2010


Author: romain
Date: 2010-09-27 15:30:38 +0200 (Mon, 27 Sep 2010)
New Revision: 2212

Modified:
   pkg/Rcpp/inst/include/Rcpp/sugar/operators/times.h
Log:
simplified times.h thanks to Extractor trait

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/operators/times.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/operators/times.h	2010-09-27 13:19:34 UTC (rev 2211)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/operators/times.h	2010-09-27 13:30:38 UTC (rev 2212)
@@ -140,6 +140,8 @@
 		typedef typename Rcpp::VectorBase<RTYPE,NA,T> VEC_TYPE ;
 		typedef typename traits::storage_type<RTYPE>::type STORAGE ;
 		
+		typedef typename Rcpp::traits::Extractor< RTYPE, NA, T>::type EXT ;
+		
 		Times_Vector_Primitive( const VEC_TYPE& lhs_, STORAGE rhs_ ) : 
 			lhs(lhs_.get_ref()), rhs(rhs_), rhs_na( Rcpp::traits::is_na<RTYPE>(rhs_) )
 			{}
@@ -153,56 +155,21 @@
 		inline int size() const { return lhs.size() ; }
 		
 	private:
-		const T& lhs ;
+		const EXT& lhs ;
 		STORAGE rhs ;
 		bool rhs_na ;
 		
 	} ;
 	
 	
-	// very special version that is used when the vector expression is 
-	// actually a vector. In that case we use its iterator (usually pointer)
-	// directly instead of adding the overhead of operator[]
-	template <int RTYPE>
-	class Times_Vector_Primitive<RTYPE,true,Rcpp::Vector<RTYPE> > : 
-	    public Rcpp::VectorBase<RTYPE,true, Times_Vector_Primitive<RTYPE,true,Rcpp::Vector<RTYPE> > > {
-	public:
-	    
-	    typedef typename Rcpp::Vector<RTYPE>::iterator iterator ;
-		typedef typename Rcpp::VectorBase<RTYPE,true,Rcpp::Vector<RTYPE> > VEC_TYPE ;
-		typedef typename traits::storage_type<RTYPE>::type STORAGE ;
-		
-		Times_Vector_Primitive( const VEC_TYPE& lhs_, STORAGE rhs_ ) : 
-			lhs(lhs_.get_ref().begin())
-			, rhs(rhs_)
-			, rhs_na( Rcpp::traits::is_na<RTYPE>(rhs_) )
-			, n( lhs_.size() )
-			{}
-		
-		inline STORAGE operator[]( int i ) const {
-			if( rhs_na ) return rhs ;
-			STORAGE x = lhs[i] ;
-			return Rcpp::traits::is_na<RTYPE>(x) ? x : (x * rhs) ;
-		}
-		
-		inline int size() const { return n ; }
-		
-	private:
-		iterator lhs ;
-	    STORAGE rhs ;
-		bool rhs_na ;
-		int n ;
-		
-	} ;
-	
-	
-	
 	template <int RTYPE, typename T>
 	class Times_Vector_Primitive<RTYPE,false,T> : public Rcpp::VectorBase<RTYPE,false, Times_Vector_Primitive<RTYPE,false,T> > {
 	public:
 		typedef typename Rcpp::VectorBase<RTYPE,false,T> VEC_TYPE ;
 		typedef typename traits::storage_type<RTYPE>::type STORAGE ;
 		
+		typedef typename Rcpp::traits::Extractor< RTYPE, false, T>::type EXT ;
+		
 		Times_Vector_Primitive( const VEC_TYPE& lhs_, STORAGE rhs_ ) : 
 			lhs(lhs_.get_ref()), rhs(rhs_), rhs_na( Rcpp::traits::is_na<RTYPE>(rhs_) ) {}
 		
@@ -213,7 +180,7 @@
 		inline int size() const { return lhs.size() ; }
 		
 	private:
-		const T& lhs ;
+		const EXT& lhs ;
 		STORAGE rhs ;
 		bool rhs_na ;
 		
@@ -231,7 +198,8 @@
 	public:
 		typedef typename Rcpp::VectorBase<RTYPE,NA,T> VEC_TYPE ;
 		typedef typename traits::storage_type<RTYPE>::type STORAGE ;
-		
+		typedef typename Rcpp::traits::Extractor< RTYPE, NA, T>::type EXT ;
+		   
 		Times_Vector_Primitive_nona( const VEC_TYPE& lhs_, STORAGE rhs_ ) : 
 			lhs(lhs_.get_ref()), rhs(rhs_)
 			{}
@@ -244,51 +212,20 @@
 		inline int size() const { return lhs.size() ; }
 		
 	private:
-		const T& lhs ;
+		const EXT& lhs ;
 		STORAGE rhs ;
 		
 	} ;
 
 	
-	// very special version that is used when the vector expression is 
-	// actually a vector. In that case we use its iterator (usually pointer)
-	// directly instead of adding the overhead of operator[]
-	template <int RTYPE>
-	class Times_Vector_Primitive_nona<RTYPE,true,Rcpp::Vector<RTYPE> > : 
-	    public Rcpp::VectorBase<RTYPE,true, Times_Vector_Primitive_nona<RTYPE,true,Rcpp::Vector<RTYPE> > > {
-	public:
-	    
-	    typedef typename Rcpp::Vector<RTYPE>::iterator iterator ;
-		typedef typename Rcpp::VectorBase<RTYPE,true,Rcpp::Vector<RTYPE> > VEC_TYPE ;
-		typedef typename traits::storage_type<RTYPE>::type STORAGE ;
-		
-		Times_Vector_Primitive_nona( const VEC_TYPE& lhs_, STORAGE rhs_ ) : 
-			lhs(lhs_.get_ref().begin())
-			, rhs(rhs_)
-			, n( lhs_.size() )
-			{}
-		
-		inline STORAGE operator[]( int i ) const {
-			STORAGE x = lhs[i] ;
-			return Rcpp::traits::is_na<RTYPE>(x) ? x : (x * rhs) ;
-		}
-		
-		inline int size() const { return n ; }
-		
-	private:
-		iterator lhs ;
-	    STORAGE rhs ;
-		int n ;
-		
-	} ;
-	
-	
 	template <int RTYPE, typename T>
 	class Times_Vector_Primitive_nona<RTYPE,false,T> : public Rcpp::VectorBase<RTYPE,false, Times_Vector_Primitive_nona<RTYPE,false,T> > {
 	public:
 		typedef typename Rcpp::VectorBase<RTYPE,false,T> VEC_TYPE ;
 		typedef typename traits::storage_type<RTYPE>::type STORAGE ;
 		
+		typedef typename Rcpp::traits::Extractor< RTYPE, false, T>::type EXT ;
+		
 		Times_Vector_Primitive_nona( const VEC_TYPE& lhs_, STORAGE rhs_ ) : 
 			lhs(lhs_.get_ref()), rhs(rhs_) {}
 		
@@ -299,7 +236,7 @@
 		inline int size() const { return lhs.size() ; }
 		
 	private:
-		const T& lhs ;
+		const EXT& lhs ;
 		STORAGE rhs ;
 		
 	} ;



More information about the Rcpp-commits mailing list