[Rcpp-commits] r4262 - in pkg/Rcpp: . inst/include inst/include/Rcpp/api/meat inst/include/Rcpp/internal inst/include/Rcpp/vector src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Feb 19 16:36:59 CET 2013


Author: romain
Date: 2013-02-19 16:36:57 +0100 (Tue, 19 Feb 2013)
New Revision: 4262

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/api/meat/Vector.h
   pkg/Rcpp/inst/include/Rcpp/internal/wrap.h
   pkg/Rcpp/inst/include/Rcpp/vector/MatrixRow.h
   pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
   pkg/Rcpp/inst/include/Rcpp/vector/traits.h
   pkg/Rcpp/inst/include/RcppCommon.h
   pkg/Rcpp/src/api.cpp
Log:
correct wrap( MatrixRow)

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2013-02-18 16:59:48 UTC (rev 4261)
+++ pkg/Rcpp/ChangeLog	2013-02-19 15:36:57 UTC (rev 4262)
@@ -1,3 +1,11 @@
+2013-02-19 Romain Francois <romain at r-enthusiasts.com>
+
+        * src/api.cpp : more debugging
+        * include/RcppCommon.h : move sexp_to_name here. Used in some debugging
+        * include/Rcpp/vector/MatrixRow.h : fix const version of operator[]
+        * include/Rcpp/vector/Vector.h : more debugging
+        * include/Rcpp/internal/wrap.h : more debugging. more dispatch.  
+        
 2013-02-18 Romain Francois <romain at r-enthusiasts.com>
 
         * include/Rcpp/vector/string_proxy.h : only declare operator+=

Modified: pkg/Rcpp/inst/include/Rcpp/api/meat/Vector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/api/meat/Vector.h	2013-02-18 16:59:48 UTC (rev 4261)
+++ pkg/Rcpp/inst/include/Rcpp/api/meat/Vector.h	2013-02-19 15:36:57 UTC (rev 4262)
@@ -2,7 +2,7 @@
 //
 // Vector.h: Rcpp R/C++ interface class library -- Vector meat 
 //
-// Copyright (C) 2012    Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2012 - 2013    Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -57,12 +57,12 @@
     
     template <int RTYPE>
     Vector<RTYPE>::Vector( const Dimension& dims ) : RObject( Rf_allocVector( RTYPE, dims.prod() ) ){
-        RCPP_DEBUG_3( "Vector<%d>( const Dimension& (%d) )   m_sexp = <%p>", RTYPE, dims.size(), m_sexp )
+        RCPP_DEBUG_3( "Vector<%s>( const Dimension& (%d) )   m_sexp = <%p>", sexp_to_name(RTYPE), dims.size(), m_sexp )
         update_vector();
         init() ;
         if( dims.size() > 1 ){
             RObject::attr( "dim" ) = dims;
-        }    
+        }
     }
     
     template <int RTYPE>
@@ -720,7 +720,16 @@
         return false ;
     }
      
+    namespace internal {
     
+        template <typename T>
+        inline SEXP wrap_range_sugar_expression( const T& object, Rcpp::traits::true_type) {
+        	RCPP_DEBUG_1( "wrap_range_sugar_expression<%s>(., true  )", DEMANGLE(T) )
+        	const int RTYPE = T::r_type::value ;
+        	return Rcpp::Vector<RTYPE>(object) ;
+        }
+
+    }
     
 } // namespace Rcpp
 

Modified: pkg/Rcpp/inst/include/Rcpp/internal/wrap.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/internal/wrap.h	2013-02-18 16:59:48 UTC (rev 4261)
+++ pkg/Rcpp/inst/include/Rcpp/internal/wrap.h	2013-02-19 15:36:57 UTC (rev 4262)
@@ -435,6 +435,7 @@
  */
 template <typename T>
 inline SEXP wrap_dispatch_unknown( const T& object, ::Rcpp::traits::true_type ){
+	RCPP_DEBUG_1( "wrap_dispatch_unknown<%s>(., false  )", DEMANGLE(T) )
 	// here we know (or assume) that T is convertible to SEXP
 	SEXP x = object ;
 	return x ;
@@ -453,7 +454,8 @@
  */
 template <typename T>
 inline SEXP wrap_dispatch_unknown_iterable(const T& object, ::Rcpp::traits::false_type){
-	// here we know that T is not convertible to SEXP
+RCPP_DEBUG_1( "wrap_dispatch_unknown_iterable<%s>(., false  )", DEMANGLE(T) )
+		// here we know that T is not convertible to SEXP
 #ifdef HAS_STATIC_ASSERT
 	static_assert( !sizeof(T), "cannot convert type to SEXP" ) ;
 #else
@@ -466,6 +468,7 @@
 
 template <typename T>
 inline SEXP wrap_dispatch_unknown_iterable__logical( const T& object, ::Rcpp::traits::true_type){
+	RCPP_DEBUG_1( "wrap_dispatch_unknown_iterable__logical<%s>(., true  )", DEMANGLE(T) )
 	size_t size = object.size() ;
 	SEXP x = PROTECT( Rf_allocVector( LGLSXP, size ) );
 	std::copy( object.begin(), object.end(), LOGICAL(x) ) ; 
@@ -474,13 +477,23 @@
 }
 
 template <typename T>
-inline SEXP wrap_dispatch_unknown_iterable__logical( const T& object, ::Rcpp::traits::false_type){
+inline SEXP wrap_range_sugar_expression( const T& object, Rcpp::traits::false_type){
+	RCPP_DEBUG_1( "wrap_range_sugar_expression<%s>(., false  )", DEMANGLE(T) )
 	return range_wrap( object.begin(), object.end() ) ;
 }
+template <typename T>
+inline SEXP wrap_range_sugar_expression( const T& object, Rcpp::traits::true_type) ; 
 
+template <typename T>
+inline SEXP wrap_dispatch_unknown_iterable__logical( const T& object, ::Rcpp::traits::false_type){
+	RCPP_DEBUG_1( "wrap_dispatch_unknown_iterable__logical<%s>(., false  )", DEMANGLE(T) )
+	return wrap_range_sugar_expression( object, typename Rcpp::traits::is_sugar_expression<T>::type() ) ;
+}
 
+
 template <typename T>
 inline SEXP wrap_dispatch_unknown_iterable__matrix_interface( const T& object, ::Rcpp::traits::false_type ){
+	RCPP_DEBUG_1( "wrap_dispatch_unknown_iterable__matrix_interface<%s>(., false  )", DEMANGLE(T) )
 	return wrap_dispatch_unknown_iterable__logical( object, 
 			typename ::Rcpp::traits::expands_to_logical<T>::type() );
 }
@@ -567,6 +580,7 @@
 
 template <typename T>
 inline SEXP wrap_dispatch_unknown_iterable__matrix_interface( const T& object, ::Rcpp::traits::true_type ){
+	RCPP_DEBUG_1( "wrap_dispatch_unknown_iterable__matrix_interface<%s>(., true  )", DEMANGLE(T) )
 	return wrap_dispatch_matrix_logical( object, typename ::Rcpp::traits::expands_to_logical<T>::type() ) ;
 }
 
@@ -585,6 +599,7 @@
  */
 template <typename T>
 inline SEXP wrap_dispatch_unknown_iterable(const T& object, ::Rcpp::traits::true_type){
+	RCPP_DEBUG_1( "wrap_dispatch_unknown_iterable<%s>(., true  )", DEMANGLE(T) )
 	return wrap_dispatch_unknown_iterable__matrix_interface( object, 
 		typename ::Rcpp::traits::matrix_interface<T>::type() ) ;
 }
@@ -661,6 +676,7 @@
  */
 template <typename T>
 inline SEXP wrap_dispatch_unknown( const T& object, ::Rcpp::traits::false_type){
+	RCPP_DEBUG_1( "wrap_dispatch_unknown<%s>(., false  )", DEMANGLE(T) )
 	return wrap_dispatch_unknown_iterable( object, typename ::Rcpp::traits::has_iterator<T>::type() ) ;
 }
 // }}}
@@ -692,11 +708,13 @@
 
 template <typename T>
 inline SEXP wrap_dispatch_eigen( const T& object, ::Rcpp::traits::false_type){
+	RCPP_DEBUG_1( "wrap_dispatch_eigen<%s>(., false  )", DEMANGLE(T) )
 	return wrap_dispatch_unknown( object, typename ::Rcpp::traits::is_convertible<T,SEXP>::type() ) ;
 }
 
 template <typename T>
 inline SEXP wrap_dispatch_eigen( const T& object, ::Rcpp::traits::true_type){
+	RCPP_DEBUG_1( "wrap_dispatch_eigen<%s>(., true  )", DEMANGLE(T) )
 	return ::Rcpp::RcppEigen::eigen_wrap( object ) ;
 }
 
@@ -707,6 +725,7 @@
  */
 template <typename T> 
 inline SEXP wrap_dispatch_unknown_importable( const T& object, ::Rcpp::traits::false_type){
+	RCPP_DEBUG_1( "wrap_dispatch_unknown_importable<%s>(., false  )", DEMANGLE(T) )
 	return wrap_dispatch_eigen( object, typename traits::is_eigen_base<T>::type() ) ;
 }
 
@@ -715,6 +734,7 @@
  */
 template <typename T> 
 inline SEXP wrap_dispatch_unknown_importable( const T& object, ::Rcpp::traits::true_type){
+	RCPP_DEBUG_1( "wrap_dispatch_unknown_importable<%s>(., true  )", DEMANGLE(T) )
 	return wrap_dispatch_importer<T,typename T::r_import_type>( object ) ;
 }
 
@@ -725,6 +745,7 @@
  */
 template <typename T> 
 inline SEXP wrap_dispatch( const T& object, ::Rcpp::traits::wrap_type_unknown_tag ){
+	RCPP_DEBUG_1( "wrap_dispatch<%s>(., wrap_type_unknown_tag )", DEMANGLE(T) )
 	return wrap_dispatch_unknown_importable( object, typename ::Rcpp::traits::is_importer<T>::type() ) ;
 }
 	// }}}

Modified: pkg/Rcpp/inst/include/Rcpp/vector/MatrixRow.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/MatrixRow.h	2013-02-18 16:59:48 UTC (rev 4261)
+++ pkg/Rcpp/inst/include/Rcpp/vector/MatrixRow.h	2013-02-19 15:36:57 UTC (rev 4262)
@@ -28,6 +28,7 @@
     typedef Matrix<RTYPE> MATRIX ;
     typedef typename MATRIX::Proxy Proxy ;
     typedef typename MATRIX::Proxy reference ;
+    typedef typename MATRIX::const_Proxy const_reference ;
     typedef typename MATRIX::value_type value_type ;
     
     class iterator {
@@ -101,7 +102,8 @@
     MatrixRow( MATRIX& object, int i ) : 
         parent(object), 
         start(parent.begin() + i), 
-        parent_nrow(parent.nrow()) 
+        parent_nrow(parent.nrow()), 
+        row(i)
     {
         if( i < 0 || i >= parent.nrow() ) throw index_out_of_bounds() ;
     }
@@ -109,7 +111,8 @@
     MatrixRow( const MatrixRow& other ) : 
         parent(other.parent), 
         start(other.start), 
-        parent_nrow(other.parent_nrow)
+        parent_nrow(other.parent_nrow), 
+        row(other.row)
     {} ;
         
     template <int RT, bool NA, typename T>
@@ -131,7 +134,7 @@
     }
         
     inline reference operator[]( int i ) const {
-        return start[ get_parent_index(i) ] ;
+        return parent[ row + i * parent_nrow ] ;
     }
         
     inline iterator begin(){
@@ -158,9 +161,11 @@
     MATRIX& parent; 
     typename MATRIX::iterator start ;
     int parent_nrow ;
+    int row ;
         
     inline int get_parent_index(int i) const { 
         RCPP_DEBUG_4( "MatrixRow<%d>[%p]::get_parent_index(%d) = %d", RTYPE, this, i, i*parent_nrow)
+        Rprintf( "MatrixRow::get_parent_index(int = %d), parent_nrow = %d >> %d\n", i, parent_nrow, i*parent_nrow ) ;
         return i * parent_nrow ;
     } 
 } ;

Modified: pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/Vector.h	2013-02-18 16:59:48 UTC (rev 4261)
+++ pkg/Rcpp/inst/include/Rcpp/vector/Vector.h	2013-02-19 15:36:57 UTC (rev 4262)
@@ -439,6 +439,7 @@
         return INTEGER( ::Rf_getAttrib( RObject::m_sexp, R_DimSymbol ) ) ;
     }
     void init(){
+        RCPP_DEBUG_2( "VECTOR<%d>::init( SEXP = <%p> )", RTYPE, RObject::m_sexp )
         internal::r_init_vector<RTYPE>(RObject::m_sexp) ;
     }
 

Modified: pkg/Rcpp/inst/include/Rcpp/vector/traits.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/traits.h	2013-02-18 16:59:48 UTC (rev 4261)
+++ pkg/Rcpp/inst/include/Rcpp/vector/traits.h	2013-02-19 15:36:57 UTC (rev 4262)
@@ -36,7 +36,7 @@
 		
 		r_vector_cache() : start(0){} ;
 		inline void update( const VECTOR& v ) {
-			start = ::Rcpp::internal::r_vector_start<RTYPE>(v.asSexp()) ;
+		    start = ::Rcpp::internal::r_vector_start<RTYPE>(v.asSexp()) ;
 			RCPP_DEBUG_3( " cache<%d>::update( <%p> ), start = <%p>", RTYPE, reinterpret_cast<void*>(v.asSexp()),  reinterpret_cast<void*>(start) )
 		}
 		inline iterator get() const { return start; }

Modified: pkg/Rcpp/inst/include/RcppCommon.h
===================================================================
--- pkg/Rcpp/inst/include/RcppCommon.h	2013-02-18 16:59:48 UTC (rev 4261)
+++ pkg/Rcpp/inst/include/RcppCommon.h	2013-02-19 15:36:57 UTC (rev 4262)
@@ -23,7 +23,7 @@
 #ifndef RcppCommon_h
 #define RcppCommon_h
 
-// #define RCPP_DEBUG_LEVEL 0
+// #define RCPP_DEBUG_LEVEL 1
 
 #include <Rcpp/platform/compiler.h>
 #include <Rcpp/config.h>
@@ -39,6 +39,11 @@
 #include <R_ext/Rdynload.h>
 #include <Rversion.h>
 
+#ifdef __cplusplus
+extern "C" 
+#endif 
+const char * sexp_to_name(int sexp_type);
+
 /**
  * \brief Rcpp API
  */

Modified: pkg/Rcpp/src/api.cpp
===================================================================
--- pkg/Rcpp/src/api.cpp	2013-02-18 16:59:48 UTC (rev 4261)
+++ pkg/Rcpp/src/api.cpp	2013-02-19 15:36:57 UTC (rev 4262)
@@ -1355,11 +1355,26 @@
 namespace Rcpp{
 namespace internal{
 
-	template<> int* r_vector_start<INTSXP>(SEXP x){ return INTEGER(x) ; }
-	template<> int* r_vector_start<LGLSXP>(SEXP x){ return LOGICAL(x) ; }
-	template<> double* r_vector_start<REALSXP>(SEXP x){ return REAL(x) ; }
-	template<> Rbyte* r_vector_start<RAWSXP>(SEXP x){ return RAW(x) ; }
-	template<> Rcomplex* r_vector_start<CPLXSXP>(SEXP x){ return COMPLEX(x) ; }
+	template<> int* r_vector_start<INTSXP>(SEXP x){ 
+	    RCPP_DEBUG_1( "r_vector_start<INTSXP>( SEXP = %p )", x )
+	    return INTEGER(x) ; 
+	}
+	template<> int* r_vector_start<LGLSXP>(SEXP x){ 
+	    RCPP_DEBUG_1( "r_vector_start<LGLSXP>( SEXP = %p )", x )
+	    return LOGICAL(x) ;
+	}
+	template<> double* r_vector_start<REALSXP>(SEXP x){ 
+	    RCPP_DEBUG_1( "r_vector_start<REALSXP>( SEXP = %p )", x )
+	    return REAL(x) ;
+	}
+	template<> Rbyte* r_vector_start<RAWSXP>(SEXP x){ 
+	    RCPP_DEBUG_1( "r_vector_start<RAWSXP>( SEXP = %p )", x )
+	    return RAW(x) ;
+	}
+	template<> Rcomplex* r_vector_start<CPLXSXP>(SEXP x){ 
+	    RCPP_DEBUG_1( "r_vector_start<CPLXSXP>( SEXP = %p )", x )
+	    return COMPLEX(x) ;
+	}
 	
 	template<> void r_init_vector<VECSXP>(SEXP x){}
 	template<> void r_init_vector<EXPRSXP>(SEXP x){}



More information about the Rcpp-commits mailing list