[Rcpp-commits] r2039 - in pkg/RcppArmadillo/inst: . include include/RcppArmadillo include/armadillo_bits unitTests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Aug 18 21:52:46 CEST 2010


Author: romain
Date: 2010-08-18 21:52:45 +0200 (Wed, 18 Aug 2010)
New Revision: 2039

Added:
   pkg/RcppArmadillo/inst/include/RcppArmadillo/
   pkg/RcppArmadillo/inst/include/RcppArmadillo/Mat_meat.h
   pkg/RcppArmadillo/inst/include/RcppArmadillo/Mat_proto.h
Modified:
   pkg/RcppArmadillo/inst/ChangeLog
   pkg/RcppArmadillo/inst/include/RcppArmadilloForward.h
   pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_proto.hpp
   pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R
Log:
arma::Mat now can handle sugar expressions as input

Modified: pkg/RcppArmadillo/inst/ChangeLog
===================================================================
--- pkg/RcppArmadillo/inst/ChangeLog	2010-08-18 08:04:51 UTC (rev 2038)
+++ pkg/RcppArmadillo/inst/ChangeLog	2010-08-18 19:52:45 UTC (rev 2039)
@@ -1,3 +1,13 @@
+2010-08-18   Romain Francois <romain at r-enthusiasts.com>
+
+	* inst/include/armadillo_bits/Mat_meat.hpp : not so intrusive patch that allows
+	RcppArmadillo to add its own Mat constructors
+	* inst/include/armadillo_bits/Mat_proto.hpp : same
+	
+	* inst/include/RcppArmadillo/Mat_proto.h : Mat constructor that takes a sugar
+	expression 
+	* inst/include/RcppArmadillo/Mat_meat.h : implementation
+
 2010-08-17   Romain Francois <romain at r-enthusiasts.com>
 
 	* inst/include/RcppArmadilloWrap.h : extracted from RcppArmadillo.h

Added: pkg/RcppArmadillo/inst/include/RcppArmadillo/Mat_meat.h
===================================================================
--- pkg/RcppArmadillo/inst/include/RcppArmadillo/Mat_meat.h	                        (rev 0)
+++ pkg/RcppArmadillo/inst/include/RcppArmadillo/Mat_meat.h	2010-08-18 19:52:45 UTC (rev 2039)
@@ -0,0 +1,50 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// Mat_meat.h: Rcpp/Armadillo glue
+//
+// Copyright (C)  2010 Dirk Eddelbuettel, Romain Francois and Douglas Bates
+//
+// This file is part of RcppArmadillo.
+//
+// RcppArmadillo is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// RcppArmadillo is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with RcppArmadillo.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef RCPPARMADILLO_MAT_MEAT_H
+#define RCPPARMADILLO_MAT_MEAT_H
+
+template <typename eT>
+template <int RTYPE, bool NA, typename VECTOR>
+inline Mat<eT>::Mat( const Rcpp::VectorBase<RTYPE,NA,VECTOR>& X ) 
+	: n_rows( 0 )
+	, n_cols( 0 )
+	, n_elem( 0 )
+	, use_aux_mem(false)
+	, mem(mem)
+{
+	
+	arma_extra_debug_sigprint_this(this);
+	
+	// TODO : deal with complex expressions because 
+	// std::complex<double> != Rcomplex
+	isnt_same_type<eT, typename Rcpp::traits::storage_type<RTYPE>::type >::check();
+  	
+	u32 n = X.size() ;
+	set_size( n, 1 ) ;
+		
+	iterator first = begin(), last = end(); 
+	for( u32 i=0; first != last; ++i){
+		*first++ = X[i] ;
+	}
+}
+
+#endif

Added: pkg/RcppArmadillo/inst/include/RcppArmadillo/Mat_proto.h
===================================================================
--- pkg/RcppArmadillo/inst/include/RcppArmadillo/Mat_proto.h	                        (rev 0)
+++ pkg/RcppArmadillo/inst/include/RcppArmadillo/Mat_proto.h	2010-08-18 19:52:45 UTC (rev 2039)
@@ -0,0 +1,29 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// Mat_proto.h: Rcpp/Armadillo glue
+//
+// Copyright (C)  2010 Dirk Eddelbuettel, Romain Francois and Douglas Bates
+//
+// This file is part of RcppArmadillo.
+//
+// RcppArmadillo is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// RcppArmadillo is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with RcppArmadillo.  If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef RCPPARMADILLO_MAT_PROTO_H
+#define RCPPARMADILLO_MAT_PROTO_H
+
+template <int RTYPE, bool NA, typename VECTOR>
+inline Mat( const Rcpp::VectorBase<RTYPE,NA,VECTOR>& X ) ;
+
+#endif

Modified: pkg/RcppArmadillo/inst/include/RcppArmadilloForward.h
===================================================================
--- pkg/RcppArmadillo/inst/include/RcppArmadilloForward.h	2010-08-18 08:04:51 UTC (rev 2038)
+++ pkg/RcppArmadillo/inst/include/RcppArmadilloForward.h	2010-08-18 19:52:45 UTC (rev 2039)
@@ -26,6 +26,9 @@
 #include <Rconfig.h>
 #include <RcppArmadilloConfig.h>
 
+#define ARMADILLO_EXTRA_MAT_PROTO "RcppArmadillo/Mat_proto.h"
+#define ARMADILLO_EXTRA_MAT_MEAT  "RcppArmadillo/Mat_meat.h"
+
 #include <armadillo>
 
 /* forward declarations */

Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_meat.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_meat.hpp	2010-08-18 08:04:51 UTC (rev 2038)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_meat.hpp	2010-08-18 19:52:45 UTC (rev 2039)
@@ -3416,5 +3416,9 @@
   }
 
 
+#ifdef ARMADILLO_EXTRA_MAT_MEAT
+#include ARMADILLO_EXTRA_MAT_MEAT
+#endif
 
+
 //! @}

Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_proto.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_proto.hpp	2010-08-18 08:04:51 UTC (rev 2038)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_proto.hpp	2010-08-18 19:52:45 UTC (rev 2039)
@@ -174,6 +174,9 @@
   template<typename T1, typename T2, typename glue_type> inline const Mat& operator%=(const mtGlue<eT, T1, T2, glue_type>& X);
   template<typename T1, typename T2, typename glue_type> inline const Mat& operator/=(const mtGlue<eT, T1, T2, glue_type>& X);
   
+#ifdef ARMADILLO_EXTRA_MAT_PROTO
+#include ARMADILLO_EXTRA_MAT_PROTO
+#endif
   
   arma_inline eT& operator[] (const u32 i);
   arma_inline eT  operator[] (const u32 i) const;

Modified: pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R
===================================================================
--- pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R	2010-08-18 08:04:51 UTC (rev 2038)
+++ pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R	2010-08-18 19:52:45 UTC (rev 2039)
@@ -269,4 +269,17 @@
 	
 }
 
+test.armadillo.sugar.ctor <- function(){
 
+	fx <- cxxfunction( signature(x= "numeric") , '
+	NumericVector xx(x) ;
+	arma::mat m = xx + xx ; 
+    return wrap( m + m ) ;
+    
+	', plugin = "RcppArmadillo" )
+	checkEquals( fx(1:10), 
+		matrix( 4*(1:10), nrow = 10 ) , 
+		msg = "Mat( sugar expression )" )
+	
+}
+



More information about the Rcpp-commits mailing list