[Rcpp-commits] r4478 - in pkg/RcppArmadillo: . inst/include

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Sep 13 17:26:28 CEST 2013


Author: romain
Date: 2013-09-13 17:26:28 +0200 (Fri, 13 Sep 2013)
New Revision: 4478

Modified:
   pkg/RcppArmadillo/ChangeLog
   pkg/RcppArmadillo/DESCRIPTION
   pkg/RcppArmadillo/inst/include/RcppArmadilloAs.h
   pkg/RcppArmadillo/inst/include/RcppArmadilloForward.h
Log:
implementation of InputParameter for arma::Mat

Modified: pkg/RcppArmadillo/ChangeLog
===================================================================
--- pkg/RcppArmadillo/ChangeLog	2013-09-13 15:22:50 UTC (rev 4477)
+++ pkg/RcppArmadillo/ChangeLog	2013-09-13 15:26:28 UTC (rev 4478)
@@ -1,3 +1,10 @@
+2013-09-13 Romain Francois <romain at r-enthusiasts.com>
+
+        * DESCRIPTION : require Rcpp 0.10.4.4
+        * include/RcppArmadilloForward.h : declaration of specializations of InputParameter
+        for references and const reference to arma::Mat
+        * include/RcppArmadilloAs.h : definitions of the above 
+        
 2013-08-24 Romain Francois <romain at r-enthusiasts.com>
 
         * include/RcppArmadilloExtensions/sample.h: added include guard, made 

Modified: pkg/RcppArmadillo/DESCRIPTION
===================================================================
--- pkg/RcppArmadillo/DESCRIPTION	2013-09-13 15:22:50 UTC (rev 4477)
+++ pkg/RcppArmadillo/DESCRIPTION	2013-09-13 15:26:28 UTC (rev 4478)
@@ -32,7 +32,7 @@
  or later, as is the rest of Rcpp.
 License: GPL (>= 2)
 LazyLoad: yes
-Depends: R (>= 2.14.0), Rcpp (>= 0.10.2)
+Depends: R (>= 2.14.0), Rcpp (>= 0.10.4.4)
 LinkingTo: Rcpp
 Suggests: RUnit
 URL: http://arma.sourceforge.net/, http://dirk.eddelbuettel.com/code/rcpp.armadillo.html, http://romainfrancois.blog.free.fr/index.php?category/R-package/RcppArmadillo

Modified: pkg/RcppArmadillo/inst/include/RcppArmadilloAs.h
===================================================================
--- pkg/RcppArmadillo/inst/include/RcppArmadilloAs.h	2013-09-13 15:22:50 UTC (rev 4477)
+++ pkg/RcppArmadillo/inst/include/RcppArmadilloAs.h	2013-09-13 15:26:28 UTC (rev 4478)
@@ -43,7 +43,21 @@
 	public:
 	    Exporter(SEXP x) : MatrixExporter< arma::Mat<T>, T >(x){}
 	}; 
+	                  
+	template <typename T> 
+	class Exporter< const arma::Mat<T>& > {
+	public:  
+		typedef typename Rcpp::Matrix< Rcpp::traits::r_sexptype_traits<T>::rtype > MATRIX ;
 		
+		Exporter(SEXP x) : mat(x) {}
+		
+		inline arma::Mat<T>* get(){
+			return new arma::Mat<T>( mat.begin(), mat.nrow(), mat.ncol(), false ) ;
+		}
+		
+	private:
+		MATRIX mat ;
+	};
 	 
 	template <typename T>
 	class Exporter< arma::SpMat<T> > {
@@ -85,6 +99,49 @@
 		S4 mat ;
 	} ;
 }	
+	
+	template <typename T>
+    class InputParameter< const arma::Mat<T>& > {
+    		public:
+    			typedef const typename arma::Mat<T>& const_reference ;
+    			
+    			InputParameter( SEXP x_ ) : mat(x_) {
+    				ptr = new arma::Mat<T>( mat.begin(), mat.nrow(), mat.ncol(), false ) ;	
+    			}
+    			inline operator const_reference(){
+    				return const_cast<const_reference>( *ptr ) ; 	
+    			}
+    			
+    			~InputParameter(){
+    				delete ptr ;
+    			}
+    			
+    		private:
+    			Rcpp::Matrix< Rcpp::traits::r_sexptype_traits<T>::rtype > mat ;
+    			arma::Mat<T>* ptr ;
+    } ;
+    
+    template <typename T>
+    class InputParameter< arma::Mat<T>& > {
+    		public:
+    			typedef typename arma::Mat<T>& reference ;
+    			
+    			InputParameter( SEXP x_ ) : mat(x_) {
+    				ptr = new arma::Mat<T>( mat.begin(), mat.nrow(), mat.ncol(), false ) ;	
+    			}
+    			inline operator reference(){
+    				return *ptr ; 	
+    			}
+    			
+    			~InputParameter(){
+    				delete ptr ;
+    			}
+    			
+    		private:
+    			Rcpp::Matrix< Rcpp::traits::r_sexptype_traits<T>::rtype > mat ;
+    			arma::Mat<T>* ptr ;
+    } ;
+    
 }
 
 #endif

Modified: pkg/RcppArmadillo/inst/include/RcppArmadilloForward.h
===================================================================
--- pkg/RcppArmadillo/inst/include/RcppArmadilloForward.h	2013-09-13 15:22:50 UTC (rev 4477)
+++ pkg/RcppArmadillo/inst/include/RcppArmadilloForward.h	2013-09-13 15:26:28 UTC (rev 4478)
@@ -90,11 +90,18 @@
 	template <typename T> class Exporter< arma::Row<T> > ;
 	template <typename T> class Exporter< arma::Col<T> > ;
 	template <typename T> class Exporter< arma::SpMat<T> > ;
-        // template <typename T> class Exporter< arma::field<T> > ;
+    
+	// template <typename T> class Exporter< arma::field<T> > ;
         // template <typename T> class Exporter< arma::Cube<T> > ;
 
     } // namespace traits 
 
+    template <typename T>
+    class InputParameter< const arma::Mat<T>& > ;
+    
+    template <typename T>
+    class InputParameter< arma::Mat<T>& > ;
+    
 }
 
 #endif



More information about the Rcpp-commits mailing list