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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jul 5 13:45:11 CEST 2010


Author: romain
Date: 2010-07-05 13:45:11 +0200 (Mon, 05 Jul 2010)
New Revision: 1781

Modified:
   pkg/Rcpp/inst/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/vector/Matrix.h
   pkg/Rcpp/inst/include/Rcpp/vector/MatrixBase.h
   pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
Log:
resolve compiler ambiguities related to matrix sugar

Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog	2010-07-05 11:29:47 UTC (rev 1780)
+++ pkg/Rcpp/inst/ChangeLog	2010-07-05 11:45:11 UTC (rev 1781)
@@ -1,6 +1,9 @@
 2010-07-05  Romain Francois <romain at r-enthusiasts.com>
 
 	* inst/include/Rcpp/RcppCommon.h : no more using variadic macros in RCPP_DEBUG
+	
+	* inst/include/Rcpp/vector/Matrix.h: move ncol, nrow, rows and cols in 
+	Matrix (used to be in Vector)
 
 2010-07-02  Romain Francois <romain at r-enthusiasts.com>
 
@@ -20,7 +23,6 @@
 	* inst/include/Rcpp/sugar/functions/rep.h: new sugar function : rep_len
 	* inst/include/Rcpp/sugar/functions/rep.h: new sugar function : rep_each
 	
-	
 2010-07-02  Dirk Eddelbuettel  <edd at debian.org>
 
 	* src/RcppStringVector: Now uses std::vector<std::string>

Modified: pkg/Rcpp/inst/include/Rcpp/vector/Matrix.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/Matrix.h	2010-07-05 11:29:47 UTC (rev 1780)
+++ pkg/Rcpp/inst/include/Rcpp/vector/Matrix.h	2010-07-05 11:45:11 UTC (rev 1781)
@@ -124,7 +124,7 @@
 		SEXP elem = PROTECT( converter_type::get( u ) ) ;
 		int n = Matrix::ncol() ;
 		int offset = n +1 ;
-		iterator it( Matrix::begin()) ;
+		iterator it( VECTOR::begin()) ;
 		for( int i=0; i<n; i++){
     		*it = ::Rf_duplicate( elem );
     		it += offset; 
@@ -137,13 +137,28 @@
 		stored_type elem = converter_type::get( u ) ;
 		int n = Matrix::ncol() ;
 		int offset = n + 1 ;
-		iterator it( Matrix::begin()) ;
+		iterator it( VECTOR::begin()) ;
 		for( int i=0; i<n; i++){
     		*it = elem ;
     		it += offset; 
     	}
     }
+
+public:
+	inline int ncol() const throw(not_a_matrix) {
+    	return VECTOR::dims()[1]; 
+    }
+    inline int nrow() const throw(not_a_matrix){
+    	return VECTOR::dims()[0]; 
+    }
+    inline int cols() const throw(not_a_matrix){ 
+    	return VECTOR::dims()[1]; 
+    }
+    inline int rows() const throw(not_a_matrix){ 
+    	return VECTOR::dims()[0]; 
+    }
 	    
+    
 } ;
 
 #endif

Modified: pkg/Rcpp/inst/include/Rcpp/vector/MatrixBase.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/MatrixBase.h	2010-07-05 11:29:47 UTC (rev 1780)
+++ pkg/Rcpp/inst/include/Rcpp/vector/MatrixBase.h	2010-07-05 11:45:11 UTC (rev 1781)
@@ -40,13 +40,13 @@
 		return static_cast<const MATRIX*>(this)->operator[](i) ;
 	}
 	
-	inline stored_type operator()( int i, int j){
+	inline stored_type operator()( int i, int j) throw(not_a_matrix) {
 		return static_cast<const MATRIX*>(this)->operator()(i, j) ;
 	}
 	
 	inline int size() const { return static_cast<const MATRIX&>(*this).size() ; }
-	inline int nrow() const { return static_cast<const MATRIX&>(*this).nrow() ; }
-	inline int ncol() const { return static_cast<const MATRIX&>(*this).ncol() ; }
+	inline int nrow() const throw(not_a_matrix) { return static_cast<const MATRIX&>(*this).nrow() ; }
+	inline int ncol() const throw(not_a_matrix) { return static_cast<const MATRIX&>(*this).ncol() ; }
 	
 	class iterator {
 	public:

Modified: pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/Vector.h	2010-07-05 11:29:47 UTC (rev 1780)
+++ pkg/Rcpp/inst/include/Rcpp/vector/Vector.h	2010-07-05 11:45:11 UTC (rev 1781)
@@ -155,21 +155,6 @@
      */
     inline R_len_t size() const { return ::Rf_length( RObject::m_sexp ) ; }
     
-    inline int ncol() const throw(not_a_matrix) {
-    	return dims()[1]; 
-    }
-    
-    inline int nrow() const throw(not_a_matrix){
-    	return dims()[0]; 
-    }
-
-    inline int cols() const throw(not_a_matrix){ 
-	return dims()[1]; 
-    }
-    inline int rows() const throw(not_a_matrix){ 
-	return dims()[0]; 
-    }
-	
     /**
      * offset based on the dimensions of this vector
      */
@@ -647,12 +632,7 @@
 		set_sexp(target.asSexp() );
 		return result ;
 	}
-	
-	inline int* dims() const throw(not_a_matrix) {
-		if( !::Rf_isMatrix(RObject::m_sexp) ) throw not_a_matrix() ;
-		return INTEGER( ::Rf_getAttrib( RObject::m_sexp, ::Rf_install( "dim") ) ) ;
-	}
-	
+		
 	void init(){
 		internal::r_init_vector<RTYPE>(RObject::m_sexp) ;
 	}
@@ -671,6 +651,13 @@
 	inline Indexer operator[]( const Range& range ){
 		return Indexer( const_cast<Vector&>(*this), range );
 	}
+
+protected:
+	inline int* dims() const throw(not_a_matrix) {
+		if( !::Rf_isMatrix(RObject::m_sexp) ) throw not_a_matrix() ;
+		return INTEGER( ::Rf_getAttrib( RObject::m_sexp, ::Rf_install( "dim") ) ) ;
+	}
+
 	
 } ; /* Vector */
 



More information about the Rcpp-commits mailing list