[Rcpp-commits] r747 - in pkg: Rcpp Rcpp/src/Rcpp/internal Rcpp/src/Rcpp/traits RcppArmadillo RcppArmadillo/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Feb 19 17:05:21 CET 2010


Author: romain
Date: 2010-02-19 17:05:20 +0100 (Fri, 19 Feb 2010)
New Revision: 747

Modified:
   pkg/Rcpp/DESCRIPTION
   pkg/Rcpp/src/Rcpp/internal/export.h
   pkg/Rcpp/src/Rcpp/traits/Exporter.h
   pkg/RcppArmadillo/DESCRIPTION
   pkg/RcppArmadillo/src/RcppArmadillo.h
Log:
some more refinements

Modified: pkg/Rcpp/DESCRIPTION
===================================================================
--- pkg/Rcpp/DESCRIPTION	2010-02-19 15:43:33 UTC (rev 746)
+++ pkg/Rcpp/DESCRIPTION	2010-02-19 16:05:20 UTC (rev 747)
@@ -1,6 +1,6 @@
 Package: Rcpp
 Title: Rcpp R/C++ interface package
-Version: 0.7.7.8
+Version: 0.7.7.9
 Date: $Date$
 Author: Dirk Eddelbuettel and Romain Francois, with contributions 
  by Simon Urbanek and David Reiss; based on code written during 

Modified: pkg/Rcpp/src/Rcpp/internal/export.h
===================================================================
--- pkg/Rcpp/src/Rcpp/internal/export.h	2010-02-19 15:43:33 UTC (rev 746)
+++ pkg/Rcpp/src/Rcpp/internal/export.h	2010-02-19 16:05:20 UTC (rev 747)
@@ -56,7 +56,7 @@
 		STORAGE* start = ::Rcpp::internal::r_vector_start<RTYPE,STORAGE>(y) ;
 		R_len_t size = ::Rf_length(y)  ;
 		for( R_len_t i=0; i<size; i++){
-			res.set( i, start[i] ) ;
+			res[i] =  start[i] ;
 		}
 		UNPROTECT(1) ;
 	}
@@ -69,7 +69,7 @@
 		STORAGE* start = ::Rcpp::internal::r_vector_start<RTYPE,STORAGE>(y) ;
 		R_len_t size = ::Rf_length(y)  ;
 		for( R_len_t i=0; i<size; i++){
-			res.set( i, caster<STORAGE,value_type>(start[i]) ) ;
+			res[i] =  caster<STORAGE,value_type>(start[i]) ;
 		}
 		UNPROTECT(1) ;
 	}
@@ -83,12 +83,12 @@
 			typename ::Rcpp::traits::r_sexptype_needscast< typename std::iterator_traits<InputIterator>::value_type >() );
 	}
 	
-	template <typename T>
+	template <typename T, typename value_type>
 	void export_indexing( SEXP x, T& res ){
-		export_indexing__impl<T,typename T::value_type>( 
+		export_indexing__impl<T,value_type>( 
 			x, 
 			res, 
-			typename ::Rcpp::traits::r_sexptype_needscast< typename T::r_export_type >() ) ;
+			typename ::Rcpp::traits::r_sexptype_needscast<value_type>() ) ;
 	}
 	
 }

Modified: pkg/Rcpp/src/Rcpp/traits/Exporter.h
===================================================================
--- pkg/Rcpp/src/Rcpp/traits/Exporter.h	2010-02-19 15:43:33 UTC (rev 746)
+++ pkg/Rcpp/src/Rcpp/traits/Exporter.h	2010-02-19 16:05:20 UTC (rev 747)
@@ -65,7 +65,7 @@
 	
 	T get(){
 		T result( ::Rf_length(object) ) ;
-		::Rcpp::internal::export_indexing( object, result ) ;
+		::Rcpp::internal::export_indexing<T,value_type>( object, result ) ;
 		return result ;
 	}
 	
@@ -83,11 +83,11 @@
 	T get(){
 		SEXP dims = PROTECT( ::Rf_getAttrib( object, Rf_install("dim") ) ) ;
 		if( dims == R_NilValue || ::Rf_length(dims) != 2 ){
-			throw std::exception( "not a matrix" ) ;
+			throw std::range_error( "not a matrix" ) ;
 		}
 		int* dims_ = INTEGER(dims) ;
-		T result( dims[0], dims[1] ) ;
-		::Rcpp::internal::export_indexing( object, result ) ;
+		T result( dims_[0], dims_[1] ) ;
+		::Rcpp::internal::export_indexing<T,value_type>( object, result ) ;
 		UNPROTECT(1) ;
 		return result ;
 	}

Modified: pkg/RcppArmadillo/DESCRIPTION
===================================================================
--- pkg/RcppArmadillo/DESCRIPTION	2010-02-19 15:43:33 UTC (rev 746)
+++ pkg/RcppArmadillo/DESCRIPTION	2010-02-19 16:05:20 UTC (rev 747)
@@ -8,7 +8,7 @@
 Description: The package eases integration of armadillo types with Rcpp
 License: GPL-2
 LazyLoad: yes
-Depends: Rcpp (>= 0.7.7.7)
+Depends: Rcpp (>= 0.7.7.8)
 SystemRequirements: armadillo
 OS_type: unix
 Packaged: 2010-02-16 14:17:09 UTC; romain

Modified: pkg/RcppArmadillo/src/RcppArmadillo.h
===================================================================
--- pkg/RcppArmadillo/src/RcppArmadillo.h	2010-02-19 15:43:33 UTC (rev 746)
+++ pkg/RcppArmadillo/src/RcppArmadillo.h	2010-02-19 16:05:20 UTC (rev 747)
@@ -25,11 +25,6 @@
 #include <RcppCommon.h>
 #include <armadillo>
 
-#define RCPPARMA_FORWARD(TYPE) \
-	template <> arma::Mat<TYPE> as< arma::Mat<TYPE> >( SEXP ) ; \
-	template <> arma::Col<TYPE> as< arma::Col<TYPE> >( SEXP ) ; \
-	template <> arma::Row<TYPE> as< arma::Row<TYPE> >( SEXP ) ; 
-
 /* forward declarations */
 namespace Rcpp{
 	template <typename T> SEXP wrap ( const arma::Mat<T>& ) ;
@@ -40,10 +35,20 @@
 	template <typename T> SEXP wrap ( const arma::Cube<T>& ) ;
 #endif
 
-	RCPPARMA_FORWARD(int)
-	RCPPARMA_FORWARD(double)
-	RCPPARMA_FORWARD(float)
-	RCPPARMA_FORWARD(arma::s32)
+	// template <typename T> arma::Mat<TYPE> as< arma::Mat<TYPE> >( SEXP ) ;
+	// template <typename T> arma::Col<TYPE> as< arma::Col<TYPE> >( SEXP ) ;
+	// template <typename T> arma::Row<TYPE> as< arma::Row<TYPE> >( SEXP ) ;
+
+namespace traits{
+	template <typename T> class Exporter< arma::Mat<T> > ;
+	template <typename T> class Exporter< arma::Row<T> > ;
+	template <typename T> class Exporter< arma::Col<T> > ;
+// template <typename T> class Exporter< arma::field<T> > ;
+// #ifdef HAS_CUBE
+// 	template <typename T> class Exporter< arma::Cube<T> > ;
+// #endif
+} // namemspace traits 
+
 }
 
 #include <Rcpp.h>
@@ -112,96 +117,29 @@
 
 
 
+namespace traits{
+	
+template <typename T> 
+class Exporter< arma::Col<T> > : public IndexingExporter< arma::Col<T>, T > {
+public:
+	Exporter(SEXP x) : IndexingExporter< arma::Col<T>, T >(x){}
+}; 
 
-namespace RcppArmadillo{
+template <typename T> 
+class Exporter< arma::Row<T> > : public IndexingExporter< arma::Row<T>, T > {
+public:
+	Exporter(SEXP x) : IndexingExporter< arma::Row<T>, T >(x){}
+}; 
 
-/* when a cast is needed */
-template <typename T> ::arma::Mat<T> convert_Mat__dispatch( SEXP x, T, ::Rcpp::traits::true_type ){
-	::Rcpp::SimpleMatrix< ::Rcpp::traits::r_sexptype_traits<T>::rtype > input(x);
-	::Rcpp::IntegerVector dim = input.attr("dim") ;
-	::arma::Mat<T> out( dim[0], dim[1] ) ;
-	int n = dim[0] * dim[1] ;
-	RCPPARMA_COPY_CAST(input, out, n, T) ;
-	return out;
-}
+template <typename T> 
+class Exporter< arma::Mat<T> > : public MatrixExporter< arma::Mat<T>, T > {
+public:
+	Exporter(SEXP x) : MatrixExporter< arma::Mat<T>, T >(x){}
+}; 
+	
+} // namespace traits
 
-/* when no cast is needed */
-template <typename T> ::arma::Mat<T> convert_Mat__dispatch( SEXP x, T, ::Rcpp::traits::false_type ){
-	::Rcpp::SimpleMatrix< ::Rcpp::traits::r_sexptype_traits<T>::rtype > input(x);
-	::Rcpp::IntegerVector dim = input.attr("dim") ;
-	::arma::Mat<T> out( dim[0], dim[1] ) ;
-	int n = dim[0] * dim[1] ;
-	RCPPARMA_COPY(input, out, n) ;
-	return out;
 }
 
-/* when a cast is needed */
-template <typename T> ::arma::Col<T> convert_Col__dispatch( SEXP x, T, ::Rcpp::traits::true_type ){
-	::Rcpp::SimpleVector< ::Rcpp::traits::r_sexptype_traits<T>::rtype > input(x);
-	int n = input.size() ;
-	::arma::Col<T> out( n ) ;
-	RCPPARMA_COPY_CAST(input, out, n, T) ;
-	return out;
-}
-
-/* when no cast is needed */
-template <typename T> ::arma::Col<T> convert_Col__dispatch( SEXP x, T, ::Rcpp::traits::false_type ){
-	::Rcpp::SimpleVector< ::Rcpp::traits::r_sexptype_traits<T>::rtype > input(x);
-	int n = input.size() ;
-	::arma::Col<T> out( n ) ;
-	RCPPARMA_COPY(input, out, n) ;
-	return out;
-}
-
-/* when a cast is needed */
-template <typename T> ::arma::Row<T> convert_Row__dispatch( SEXP x, T, ::Rcpp::traits::true_type ){
-	::Rcpp::SimpleVector< ::Rcpp::traits::r_sexptype_traits<T>::rtype > input(x);
-	int n = input.size() ;
-	::arma::Row<T> out( n ) ;
-	RCPPARMA_COPY_CAST(input, out, n, T) ;
-	return out;
-}
-
-/* when no cast is needed */
-template <typename T> ::arma::Row<T> convert_Row__dispatch( SEXP x, T, ::Rcpp::traits::false_type ){
-	::Rcpp::SimpleVector< ::Rcpp::traits::r_sexptype_traits<T>::rtype > input(x);
-	int n = input.size() ;
-	::arma::Row<T> out( n ) ;
-	RCPPARMA_COPY(input, out, n) ;
-	return out;
-}
-
-/* dispatch depending on whether the type of data in the R vector is the same as T */
-template <typename T> ::arma::Mat<T> convert_Mat( SEXP x, T t){
-	return convert_Mat__dispatch( x, t, typename ::Rcpp::traits::r_sexptype_needscast<T>() ) ;
-}
-template <typename T> ::arma::Col<T> convert_Col( SEXP x, T t){
-	return convert_Col__dispatch( x, t, typename ::Rcpp::traits::r_sexptype_needscast<T>() ) ;
-}
-template <typename T> ::arma::Mat<T> convert_Row( SEXP x, T t){
-	return convert_Row__dispatch( x, t, typename ::Rcpp::traits::r_sexptype_needscast<T>() ) ;
-}
-
-} /* namespace RcppArmadillo */
-
-/* as */
-
-#define GENERATE_CONVERTERS(TYPE)  \
-	template<> arma::Mat<TYPE> as< arma::Mat<TYPE> >(SEXP x){ return RcppArmadillo::convert_Mat<TYPE>(x, TYPE()) ; } ; \
-	template<> arma::Col<TYPE> as< arma::Col<TYPE> >(SEXP x){ return RcppArmadillo::convert_Col<TYPE>(x, TYPE()) ; } ; \
-	template<> arma::Row<TYPE> as< arma::Row<TYPE> >(SEXP x){ return RcppArmadillo::convert_Row<TYPE>(x, TYPE()) ; } ;
-
-GENERATE_CONVERTERS(int)
-GENERATE_CONVERTERS(arma::u32)
-GENERATE_CONVERTERS(double)
-GENERATE_CONVERTERS(float)
-
-#undef GENERATE_CONVERTER
-#undef RCPPARMA_COPY
-#undef RCPPARMA_COPY_CAST
-#undef RCPPARMA_FORWARD
-
-}
-
 #endif
 



More information about the Rcpp-commits mailing list