[Rcpp-commits] r1567 - in pkg/Rcpp/inst/include/Rcpp: sugar vector

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jun 17 13:41:56 CEST 2010


Author: romain
Date: 2010-06-17 13:41:55 +0200 (Thu, 17 Jun 2010)
New Revision: 1567

Modified:
   pkg/Rcpp/inst/include/Rcpp/sugar/Comparator.h
   pkg/Rcpp/inst/include/Rcpp/sugar/LogicalResult.h
   pkg/Rcpp/inst/include/Rcpp/sugar/logical_operators.h
   pkg/Rcpp/inst/include/Rcpp/vector/VectorBase.h
Log:
more generic Vector to Vector binary operators

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/Comparator.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/Comparator.h	2010-06-17 11:16:16 UTC (rev 1566)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/Comparator.h	2010-06-17 11:41:55 UTC (rev 1567)
@@ -25,14 +25,13 @@
 namespace Rcpp{
 namespace sugar{
 
-template <int RTYPE, typename Operator>
-class Comparator : public LogicalResult< Comparator<RTYPE,Operator> > {
+template <int RTYPE, typename Operator, typename LHS_TYPE, typename RHS_TYPE>
+class Comparator : public LogicalResult< Comparator<RTYPE,Operator,LHS_TYPE,RHS_TYPE> > {
 public:
-	typedef Vector<RTYPE> VEC ;
 	typedef typename traits::storage_type<RTYPE>::type STORAGE ;
 	typedef r_binary_op<RTYPE,Operator> R_OPERATOR ;
 	
-	Comparator( const VEC& lhs_, const VEC& rhs_) : 
+	Comparator( const LHS_TYPE& lhs_, const RHS_TYPE& rhs_) : 
 		op(), lhs(lhs_), rhs(rhs_){}
 	
 	inline int operator[]( int i ) const {
@@ -43,8 +42,8 @@
 	
 private:
 	R_OPERATOR op ;
-	const VEC& lhs ;
-	const VEC& rhs ;
+	const LHS_TYPE& lhs ;
+	const RHS_TYPE& rhs ;
 	
 } ;
 

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/LogicalResult.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/LogicalResult.h	2010-06-17 11:16:16 UTC (rev 1566)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/LogicalResult.h	2010-06-17 11:41:55 UTC (rev 1567)
@@ -39,89 +39,89 @@
 		return static_cast<T&>(*this).size() ;
 	}
 	
-public:
-	
-	class iterator {
-	public:
-		typedef int difference_type ;
-		typedef int value_type ;
-		typedef const int* pointer ;
-		typedef int reference ;
-		typedef std::random_access_iterator_tag iterator_category ;
-		
-		iterator( const LogicalResult& comp_, int index_ = 0 ) : 
-			comp(comp_), index(index_) {}
-		                                                     
-		inline difference_type operator-( const iterator& other ){
-			return index - other.index ;
-		}
-		inline bool operator==( const iterator& other ){
-			return index == other.index ;
-		}
-		inline bool operator<( const iterator& other ){
-			return index < other.index ;
-		}
-		inline bool operator>( const iterator& other ){
-			return index > other.index ;
-		}
-		inline bool operator<=( const iterator& other ){
-			return index <= other.index ;
-		}
-		inline bool operator>=( const iterator& other ){
-			return index >= other.index ;
-		}
-		inline bool operator!=( const iterator& other ){
-			return index != other.index ;
-		}
-		
-		inline reference operator*(){
-			return comp[index] ;
-		}
-		inline pointer operator->(){
-			return &comp[index] ;
-		}
+// public:
+// 	
+// 	class iterator {
+// 	public:
+// 		typedef int difference_type ;
+// 		typedef int value_type ;
+// 		typedef const int* pointer ;
+// 		typedef int reference ;
+// 		typedef std::random_access_iterator_tag iterator_category ;
+// 		
+// 		iterator( const LogicalResult& comp_, int index_ = 0 ) : 
+// 			comp(comp_), index(index_) {}
+// 		                                                     
+// 		inline difference_type operator-( const iterator& other ){
+// 			return index - other.index ;
+// 		}
+// 		inline bool operator==( const iterator& other ){
+// 			return index == other.index ;
+// 		}
+// 		inline bool operator<( const iterator& other ){
+// 			return index < other.index ;
+// 		}
+// 		inline bool operator>( const iterator& other ){
+// 			return index > other.index ;
+// 		}
+// 		inline bool operator<=( const iterator& other ){
+// 			return index <= other.index ;
+// 		}
+// 		inline bool operator>=( const iterator& other ){
+// 			return index >= other.index ;
+// 		}
+// 		inline bool operator!=( const iterator& other ){
+// 			return index != other.index ;
+// 		}
+// 		
+// 		inline reference operator*(){
+// 			return comp[index] ;
+// 		}
+// 		inline pointer operator->(){
+// 			return &comp[index] ;
+// 		}
+// 
+// 		inline iterator& operator++(){
+// 			index++; 
+// 			return *this ;
+// 		}
+// 		inline iterator& operator++(int){
+// 			index++ ;
+// 			return *this ;
+// 		}
+// 		inline iterator& operator--(){
+// 			index-- ;
+// 			return *this ;
+// 		}
+// 		inline iterator& operator--(int){
+// 			index-- ;
+// 			return *this ;
+// 		}
+// 		inline iterator& operator+=(difference_type n) {
+// 			index += n ;
+// 			return *this ;
+// 		}
+// 		inline iterator& operator-=(difference_type n) {
+// 			index -= n ;
+// 			return *this ;
+// 		}
+// 		
+// 		inline iterator operator+(difference_type n) const {
+// 			return iterator( comp, index + n ) ;
+// 		}
+// 		inline iterator operator-(difference_type n) const {
+// 			return iterator( comp, index - n ) ;
+// 		}
+// 
+// 	private:
+// 		const LogicalResult& comp ;
+// 		int index ;
+// 	} ;
+// 	
+// 	inline iterator begin() const { return iterator(*this, 0 ) ; }
+// 	inline iterator end() const { return iterator(*this, size() ) ; }
 
-		inline iterator& operator++(){
-			index++; 
-			return *this ;
-		}
-		inline iterator& operator++(int){
-			index++ ;
-			return *this ;
-		}
-		inline iterator& operator--(){
-			index-- ;
-			return *this ;
-		}
-		inline iterator& operator--(int){
-			index-- ;
-			return *this ;
-		}
-		inline iterator& operator+=(difference_type n) {
-			index += n ;
-			return *this ;
-		}
-		inline iterator& operator-=(difference_type n) {
-			index -= n ;
-			return *this ;
-		}
-		
-		inline iterator operator+(difference_type n) const {
-			return iterator( comp, index + n ) ;
-		}
-		inline iterator operator-(difference_type n) const {
-			return iterator( comp, index - n ) ;
-		}
-
-	private:
-		const LogicalResult& comp ;
-		int index ;
-	} ;
 	
-	inline iterator begin() const { return iterator(*this, 0 ) ; }
-	inline iterator end() const { return iterator(*this, size() ) ; }
-
-	
 } ;
 
 } // namespace sugar

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/logical_operators.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/logical_operators.h	2010-06-17 11:16:16 UTC (rev 1566)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/logical_operators.h	2010-06-17 11:41:55 UTC (rev 1567)
@@ -22,58 +22,135 @@
 #ifndef Rcpp__sugar__logical_operators_h
 #define Rcpp__sugar__logical_operators_h
 
-/* Vector op Vector */
-template <int RTYPE>
-inline Rcpp::sugar::Comparator< RTYPE , Rcpp::sugar::less<RTYPE> > 
-operator<( const Rcpp::Vector<RTYPE>& lhs , const Rcpp::Vector<RTYPE>& rhs ){
-	return Rcpp::sugar::Comparator<RTYPE, Rcpp::sugar::less<RTYPE> >( 
+
+/* Vector < Vector */ 
+template <int RTYPE,bool LHS_NA,typename LHS_T,bool RHS_NA, typename RHS_T>
+inline Rcpp::sugar::Comparator<
+	RTYPE , 
+	Rcpp::sugar::less<RTYPE>, 
+	Rcpp::VectorBase<RTYPE,LHS_NA,LHS_T>, 
+	Rcpp::VectorBase<RTYPE,RHS_NA,RHS_T>
+	> 
+operator<( 
+	const Rcpp::VectorBase<RTYPE,LHS_NA,LHS_T>& lhs , 
+	const Rcpp::VectorBase<RTYPE,RHS_NA,RHS_T>& rhs
+	){
+	return Rcpp::sugar::Comparator<
+		RTYPE, 
+		Rcpp::sugar::less<RTYPE>, 
+		Rcpp::VectorBase<RTYPE,LHS_NA,LHS_T>, 
+		Rcpp::VectorBase<RTYPE,RHS_NA,RHS_T>
+		>( 
 		lhs, rhs
 		) ;
 }
-
-template <int RTYPE>
-inline Rcpp::sugar::Comparator< RTYPE , Rcpp::sugar::greater<RTYPE> > 
-operator>( const Rcpp::Vector<RTYPE>& lhs , const Rcpp::Vector<RTYPE>& rhs ){
-	return Rcpp::sugar::Comparator<RTYPE, Rcpp::sugar::greater<RTYPE> >( 
+/* Vector > Vector */
+template <int RTYPE,bool LHS_NA,typename LHS_T,bool RHS_NA, typename RHS_T>
+inline Rcpp::sugar::Comparator<
+	RTYPE , 
+	Rcpp::sugar::greater<RTYPE>, 
+	Rcpp::VectorBase<RTYPE,LHS_NA,LHS_T>, 
+	Rcpp::VectorBase<RTYPE,RHS_NA,RHS_T>
+	> 
+operator>( 
+	const Rcpp::VectorBase<RTYPE,LHS_NA,LHS_T>& lhs , 
+	const Rcpp::VectorBase<RTYPE,RHS_NA,RHS_T>& rhs
+	){
+	return Rcpp::sugar::Comparator<
+		RTYPE, 
+		Rcpp::sugar::greater<RTYPE>, 
+		Rcpp::VectorBase<RTYPE,LHS_NA,LHS_T>, 
+		Rcpp::VectorBase<RTYPE,RHS_NA,RHS_T>
+		>( 
 		lhs, rhs
 		) ;
 }
-
-template <int RTYPE>
-inline Rcpp::sugar::Comparator< RTYPE , Rcpp::sugar::less_or_equal<RTYPE> > 
-operator<=( const Rcpp::Vector<RTYPE>& lhs , const Rcpp::Vector<RTYPE>& rhs ){
-	return Rcpp::sugar::Comparator<RTYPE, Rcpp::sugar::less_or_equal<RTYPE> >( 
+/* Vector <= Vector */
+template <int RTYPE,bool LHS_NA,typename LHS_T,bool RHS_NA, typename RHS_T>
+inline Rcpp::sugar::Comparator<
+	RTYPE , 
+	Rcpp::sugar::less_or_equal<RTYPE>, 
+	Rcpp::VectorBase<RTYPE,LHS_NA,LHS_T>, 
+	Rcpp::VectorBase<RTYPE,RHS_NA,RHS_T>
+	> 
+operator<=( 
+	const Rcpp::VectorBase<RTYPE,LHS_NA,LHS_T>& lhs , 
+	const Rcpp::VectorBase<RTYPE,RHS_NA,RHS_T>& rhs
+	){
+	return Rcpp::sugar::Comparator<
+		RTYPE, 
+		Rcpp::sugar::less_or_equal<RTYPE>, 
+		Rcpp::VectorBase<RTYPE,LHS_NA,LHS_T>, 
+		Rcpp::VectorBase<RTYPE,RHS_NA,RHS_T>
+		>( 
 		lhs, rhs
 		) ;
 }
-
-template <int RTYPE>
-inline Rcpp::sugar::Comparator< RTYPE , Rcpp::sugar::greater_or_equal<RTYPE> > 
-operator>=( const Rcpp::Vector<RTYPE>& lhs , const Rcpp::Vector<RTYPE>& rhs ){
-	return Rcpp::sugar::Comparator<RTYPE, Rcpp::sugar::greater_or_equal<RTYPE> >( 
+/* Vector >= Vector */
+template <int RTYPE,bool LHS_NA,typename LHS_T,bool RHS_NA, typename RHS_T>
+inline Rcpp::sugar::Comparator<
+	RTYPE , 
+	Rcpp::sugar::greater_or_equal<RTYPE>, 
+	Rcpp::VectorBase<RTYPE,LHS_NA,LHS_T>, 
+	Rcpp::VectorBase<RTYPE,RHS_NA,RHS_T>
+	> 
+operator>=( 
+	const Rcpp::VectorBase<RTYPE,LHS_NA,LHS_T>& lhs , 
+	const Rcpp::VectorBase<RTYPE,RHS_NA,RHS_T>& rhs
+	){
+	return Rcpp::sugar::Comparator<
+		RTYPE, 
+		Rcpp::sugar::greater_or_equal<RTYPE>, 
+		Rcpp::VectorBase<RTYPE,LHS_NA,LHS_T>, 
+		Rcpp::VectorBase<RTYPE,RHS_NA,RHS_T>
+		>( 
 		lhs, rhs
 		) ;
 }
-
-template <int RTYPE>
-inline Rcpp::sugar::Comparator< RTYPE , Rcpp::sugar::equal<RTYPE> > 
-operator==( const Rcpp::Vector<RTYPE>& lhs , const Rcpp::Vector<RTYPE>& rhs ){
-	return Rcpp::sugar::Comparator<RTYPE, Rcpp::sugar::equal<RTYPE> >( 
+/* Vector == Vector */
+template <int RTYPE,bool LHS_NA,typename LHS_T,bool RHS_NA, typename RHS_T>
+inline Rcpp::sugar::Comparator<
+	RTYPE , 
+	Rcpp::sugar::equal<RTYPE>, 
+	Rcpp::VectorBase<RTYPE,LHS_NA,LHS_T>, 
+	Rcpp::VectorBase<RTYPE,RHS_NA,RHS_T>
+	> 
+operator==( 
+	const Rcpp::VectorBase<RTYPE,LHS_NA,LHS_T>& lhs , 
+	const Rcpp::VectorBase<RTYPE,RHS_NA,RHS_T>& rhs
+	){
+	return Rcpp::sugar::Comparator<
+		RTYPE, 
+		Rcpp::sugar::equal<RTYPE>, 
+		Rcpp::VectorBase<RTYPE,LHS_NA,LHS_T>, 
+		Rcpp::VectorBase<RTYPE,RHS_NA,RHS_T>
+		>( 
 		lhs, rhs
 		) ;
 }
-
-template <int RTYPE>
-inline Rcpp::sugar::Comparator< RTYPE , Rcpp::sugar::not_equal<RTYPE> > 
-operator!=( const Rcpp::Vector<RTYPE>& lhs , const Rcpp::Vector<RTYPE>& rhs ){
-	return Rcpp::sugar::Comparator<RTYPE, Rcpp::sugar::not_equal<RTYPE> >( 
+/* Vector != Vector */
+template <int RTYPE,bool LHS_NA,typename LHS_T,bool RHS_NA, typename RHS_T>
+inline Rcpp::sugar::Comparator<
+	RTYPE , 
+	Rcpp::sugar::not_equal<RTYPE>, 
+	Rcpp::VectorBase<RTYPE,LHS_NA,LHS_T>, 
+	Rcpp::VectorBase<RTYPE,RHS_NA,RHS_T>
+	> 
+operator!=( 
+	const Rcpp::VectorBase<RTYPE,LHS_NA,LHS_T>& lhs , 
+	const Rcpp::VectorBase<RTYPE,RHS_NA,RHS_T>& rhs
+	){
+	return Rcpp::sugar::Comparator<
+		RTYPE, 
+		Rcpp::sugar::not_equal<RTYPE>, 
+		Rcpp::VectorBase<RTYPE,LHS_NA,LHS_T>, 
+		Rcpp::VectorBase<RTYPE,RHS_NA,RHS_T>
+		>( 
 		lhs, rhs
 		) ;
 }
 
 
-
-
 /* Vector op primitive */
 template <int RTYPE>
 inline Rcpp::sugar::Comparator_With_One_Value< RTYPE , Rcpp::sugar::less<RTYPE> > 

Modified: pkg/Rcpp/inst/include/Rcpp/vector/VectorBase.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/VectorBase.h	2010-06-17 11:16:16 UTC (rev 1566)
+++ pkg/Rcpp/inst/include/Rcpp/vector/VectorBase.h	2010-06-17 11:41:55 UTC (rev 1567)
@@ -42,9 +42,9 @@
 	// inline iterator begin(){ return static_cast<VECTOR*>(this)->begin() ; }
 	// inline iterator end(){ return static_cast<VECTOR*>(this)->end() ; }
 
-	inline stored_type operator[]( int i) const { return static_cast<VECTOR*>(this)->operator[](i) ; }
+	inline stored_type operator[]( int i) const { return static_cast<const VECTOR*>(this)->operator[](i) ; }
 	
-	inline int size() const { return static_cast<VECTOR*>(this)->size() ; }
+	inline int size() const { return static_cast<const VECTOR*>(this)->size() ; }
 } ;
 
 } // namespace Rcpp



More information about the Rcpp-commits mailing list