[Rcpp-commits] r743 - in pkg/RcppArmadillo: . inst src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Feb 19 13:21:14 CET 2010


Author: romain
Date: 2010-02-19 13:21:14 +0100 (Fri, 19 Feb 2010)
New Revision: 743

Modified:
   pkg/RcppArmadillo/DESCRIPTION
   pkg/RcppArmadillo/inst/ChangeLog
   pkg/RcppArmadillo/src/RcppArmadillo.cpp
   pkg/RcppArmadillo/src/RcppArmadillo.h
Log:
support for wrap( field<T> )

Modified: pkg/RcppArmadillo/DESCRIPTION
===================================================================
--- pkg/RcppArmadillo/DESCRIPTION	2010-02-19 12:20:17 UTC (rev 742)
+++ pkg/RcppArmadillo/DESCRIPTION	2010-02-19 12:21:14 UTC (rev 743)
@@ -8,6 +8,6 @@
 Description: The package eases integration of armadillo types with Rcpp
 License: GPL-2
 LazyLoad: yes
-Depends: Rcpp (>= 0.7.7.6)
+Depends: Rcpp (>= 0.7.7.7)
 SystemRequirements: armadillo
 Packaged: 2010-02-16 14:17:09 UTC; romain

Modified: pkg/RcppArmadillo/inst/ChangeLog
===================================================================
--- pkg/RcppArmadillo/inst/ChangeLog	2010-02-19 12:20:17 UTC (rev 742)
+++ pkg/RcppArmadillo/inst/ChangeLog	2010-02-19 12:21:14 UTC (rev 743)
@@ -1,3 +1,7 @@
+2010-02-19  Romain Francois <romain at r-enthusiasts.com>
+
+	* added support for field<T> where T is wrappable
+
 2010-02-17  Romain Francois <romain at r-enthusiasts.com>
 
 	* added support for as<Mat<T>> as<Row<T>> and as<Col<T>> 

Modified: pkg/RcppArmadillo/src/RcppArmadillo.cpp
===================================================================
--- pkg/RcppArmadillo/src/RcppArmadillo.cpp	2010-02-19 12:20:17 UTC (rev 742)
+++ pkg/RcppArmadillo/src/RcppArmadillo.cpp	2010-02-19 12:21:14 UTC (rev 743)
@@ -25,7 +25,7 @@
 	using namespace Rcpp ;
 	using namespace arma ;
 	
-	List output(3); 
+	List output(4); 
 	List matrices(4) ;
 	List rows(2) ;
 	List cols(2) ;
@@ -74,13 +74,36 @@
 	names[1] = "Col<float>" ;
 	cols.names() = names ;
 	
+	
+	List fields ;
+	field<int> f1( 2, 2 ) ;
+	f1( 0, 0 ) = 0 ; 
+	f1( 1, 0 ) = 1 ; 
+	f1( 0, 1 ) = 2 ; 
+	f1( 1, 1 ) = 3 ; 
+	fields["field<int>"] = f1 ;
+	field<std::string> f2(2,2) ;
+	f2( 0, 0 ) = "a" ; 
+	f2( 1, 0 ) = "b" ; 
+	f2( 0, 1 ) = "c" ; 
+	f2( 1, 1 ) = "d" ; 
+	fields["field<std::string>"] = f2 ;
+	field<colvec> f3(2,2) ;
+	f3(0,0) = zeros<mat>(5,1) ;
+	f3(1,0) = zeros<mat>(4,1) ;
+	f3(0,1) = zeros<mat>(3,1) ;
+	f3(1,1) = zeros<mat>(2,1) ;
+	fields["field<colvec>"] = f3 ;
+	
 	output[0] = matrices;
 	output[1] = rows ;
 	output[2] = cols ;
+	output[3] = fields ;
 	
 	names[0] = "matrices : Mat<T>" ; 
 	names[1] = "rows : Row<T>" ;
 	names.push_back( "columns : Col<T>" );
+	names.push_back( "fields  : field<T>" );
 	output.names() = names ;
 	
 	return output ;

Modified: pkg/RcppArmadillo/src/RcppArmadillo.h
===================================================================
--- pkg/RcppArmadillo/src/RcppArmadillo.h	2010-02-19 12:20:17 UTC (rev 742)
+++ pkg/RcppArmadillo/src/RcppArmadillo.h	2010-02-19 12:21:14 UTC (rev 743)
@@ -35,6 +35,7 @@
 	template <typename T> SEXP wrap ( const arma::Mat<T>& ) ;
 	template <typename T> SEXP wrap ( const arma::Row<T>& ) ;
 	template <typename T> SEXP wrap ( const arma::Col<T>& ) ;
+	template <typename T> SEXP wrap ( const arma::field<T>& ) ;
 #ifdef HAS_CUBE
 	template <typename T> SEXP wrap ( const arma::Cube<T>& ) ;
 #endif
@@ -87,11 +88,31 @@
 }
 #endif
 
-} // namespace Rcpp
+namespace RcppArmadillo {
+	
+/* Importer class for field<T> */
+template <typename T> class FieldImporter {
+public:
+	typedef T r_import_type ;
+	FieldImporter( const arma::field<T>& data_ ) : data(data_){}
+	inline int size() const { return data.n_elem ; }
+	inline T get(int i) const { return data[i] ; }
+	SEXP wrap( int i) const { return ::Rcpp::wrap( data[i] ) ; } 
+private:
+	const arma::field<T>& data ;
+} ;
 
+} // namespace RcppArmadillo
 
-namespace Rcpp{
-	
+template <typename T> SEXP wrap( const arma::field<T>& data){
+	RObject x = wrap( RcppArmadillo::FieldImporter<T>( data ) ) ;
+	x.attr("dim" ) = Dimension( data.n_rows, data.n_cols ) ;
+	return x ;
+}
+
+
+
+
 namespace RcppArmadillo{
 
 /* when a cast is needed */



More information about the Rcpp-commits mailing list