[Rcpp-commits] r2043 - 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
Thu Aug 19 08:38:06 CEST 2010


Author: romain
Date: 2010-08-19 08:38:05 +0200 (Thu, 19 Aug 2010)
New Revision: 2043

Added:
   pkg/RcppArmadillo/inst/include/RcppArmadillo/Col_meat.h
   pkg/RcppArmadillo/inst/include/RcppArmadillo/Col_proto.h
   pkg/RcppArmadillo/inst/include/RcppArmadillo/Row_meat.h
   pkg/RcppArmadillo/inst/include/RcppArmadillo/Row_proto.h
Modified:
   pkg/RcppArmadillo/inst/include/RcppArmadilloForward.h
   pkg/RcppArmadillo/inst/include/armadillo_bits/Col_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/Col_proto.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/Row_meat.hpp
   pkg/RcppArmadillo/inst/include/armadillo_bits/Row_proto.hpp
   pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R
Log:
Row and Col also know sugar

Added: pkg/RcppArmadillo/inst/include/RcppArmadillo/Col_meat.h
===================================================================
--- pkg/RcppArmadillo/inst/include/RcppArmadillo/Col_meat.h	                        (rev 0)
+++ pkg/RcppArmadillo/inst/include/RcppArmadillo/Col_meat.h	2010-08-19 06:38:05 UTC (rev 2043)
@@ -0,0 +1,43 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// Col_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_COL_MEAT_H
+#define RCPPARMADILLO_COL_MEAT_H
+
+template <typename eT>
+template <int RTYPE, bool NA, typename VECTOR>
+inline Col<eT>::Col( const Rcpp::VectorBase<RTYPE,NA,VECTOR>& X )
+	: Mat<eT>( X )
+	{	
+	arma_extra_debug_sigprint(this);
+	}
+
+template <typename eT>
+template <int RTYPE, bool NA, typename MATRIX>
+inline Col<eT>::Col( const Rcpp::MatrixBase<RTYPE,NA,MATRIX>& X ) 
+	: Mat<eT>( X )
+	{	
+	arma_extra_debug_sigprint(this);
+	
+	arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" );
+	}
+
+#endif

Added: pkg/RcppArmadillo/inst/include/RcppArmadillo/Col_proto.h
===================================================================
--- pkg/RcppArmadillo/inst/include/RcppArmadillo/Col_proto.h	                        (rev 0)
+++ pkg/RcppArmadillo/inst/include/RcppArmadillo/Col_proto.h	2010-08-19 06:38:05 UTC (rev 2043)
@@ -0,0 +1,32 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// Col_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_COL_PROTO_H
+#define RCPPARMADILLO_COL_PROTO_H
+
+template <int RTYPE, bool NA, typename VECTOR>
+inline Col( const Rcpp::VectorBase<RTYPE,NA,VECTOR>& X ) ;
+
+template <int RTYPE, bool NA, typename VECTOR>
+inline Col( const Rcpp::MatrixBase<RTYPE,NA,VECTOR>& X ) ;
+
+#endif

Added: pkg/RcppArmadillo/inst/include/RcppArmadillo/Row_meat.h
===================================================================
--- pkg/RcppArmadillo/inst/include/RcppArmadillo/Row_meat.h	                        (rev 0)
+++ pkg/RcppArmadillo/inst/include/RcppArmadillo/Row_meat.h	2010-08-19 06:38:05 UTC (rev 2043)
@@ -0,0 +1,44 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// Row_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_ROW_MEAT_H
+#define RCPPARMADILLO_ROW_MEAT_H
+
+template <typename eT>
+template <int RTYPE, bool NA, typename VECTOR>
+inline Row<eT>::Row( const Rcpp::VectorBase<RTYPE,NA,VECTOR>& X )
+	: Mat<eT>( X )
+	{	
+	arma_extra_debug_sigprint(this);
+	std::swap( access::rw(Mat<eT>::n_rows), access::rw(Mat<eT>::n_cols) );
+	}
+
+template <typename eT>
+template <int RTYPE, bool NA, typename MATRIX>
+inline Row<eT>::Row( const Rcpp::MatrixBase<RTYPE,NA,MATRIX>& X ) 
+	: Mat<eT>( X )
+	{	
+	arma_extra_debug_sigprint(this);
+	
+	arma_debug_check( (Mat<eT>::n_rows > 1), "Col(): incompatible dimensions" );
+	}
+
+#endif

Added: pkg/RcppArmadillo/inst/include/RcppArmadillo/Row_proto.h
===================================================================
--- pkg/RcppArmadillo/inst/include/RcppArmadillo/Row_proto.h	                        (rev 0)
+++ pkg/RcppArmadillo/inst/include/RcppArmadillo/Row_proto.h	2010-08-19 06:38:05 UTC (rev 2043)
@@ -0,0 +1,32 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// Row_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_ROW_PROTO_H
+#define RCPPARMADILLO_ROW_PROTO_H
+
+template <int RTYPE, bool NA, typename VECTOR>
+inline Row( const Rcpp::VectorBase<RTYPE,NA,VECTOR>& X ) ;
+
+template <int RTYPE, bool NA, typename VECTOR>
+inline Row( const Rcpp::MatrixBase<RTYPE,NA,VECTOR>& X ) ;
+
+#endif

Modified: pkg/RcppArmadillo/inst/include/RcppArmadilloForward.h
===================================================================
--- pkg/RcppArmadillo/inst/include/RcppArmadilloForward.h	2010-08-19 05:56:51 UTC (rev 2042)
+++ pkg/RcppArmadillo/inst/include/RcppArmadilloForward.h	2010-08-19 06:38:05 UTC (rev 2043)
@@ -28,6 +28,10 @@
 
 #define ARMA_EXTRA_MAT_PROTO "RcppArmadillo/Mat_proto.h"
 #define ARMA_EXTRA_MAT_MEAT  "RcppArmadillo/Mat_meat.h"
+#define ARMA_EXTRA_COL_PROTO "RcppArmadillo/Col_proto.h"
+#define ARMA_EXTRA_COL_MEAT  "RcppArmadillo/Col_meat.h"
+#define ARMA_EXTRA_ROW_PROTO "RcppArmadillo/Row_proto.h"
+#define ARMA_EXTRA_ROW_MEAT  "RcppArmadillo/Row_meat.h"
 
 #include <armadillo>
 

Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Col_meat.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/Col_meat.hpp	2010-08-19 05:56:51 UTC (rev 2042)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/Col_meat.hpp	2010-08-19 06:38:05 UTC (rev 2043)
@@ -996,5 +996,8 @@
   }
 
 
+#ifdef ARMA_EXTRA_COL_MEAT
+#include ARMA_EXTRA_COL_MEAT
+#endif
 
 //! @}

Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Col_proto.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/Col_proto.hpp	2010-08-19 05:56:51 UTC (rev 2042)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/Col_proto.hpp	2010-08-19 06:38:05 UTC (rev 2043)
@@ -98,6 +98,10 @@
   template<typename T1, typename T2, typename glue_type> inline const Col&  operator=(const mtGlue<eT, T1, T2, glue_type>& X);
   template<typename T1, typename T2, typename glue_type> inline const Col& operator*=(const mtGlue<eT, T1, T2, glue_type>& X);
   
+#ifdef ARMA_EXTRA_COL_PROTO
+#include ARMA_EXTRA_COL_PROTO
+#endif
+
   inline void  set_size(const u32 n_elem);
   inline void  set_size(const u32 n_rows, const u32 n_cols);
   inline void   reshape(const u32 n_rows, const u32 n_cols, const u32 dim = 0);

Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Row_meat.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/Row_meat.hpp	2010-08-19 05:56:51 UTC (rev 2042)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/Row_meat.hpp	2010-08-19 06:38:05 UTC (rev 2043)
@@ -967,6 +967,9 @@
   return Mat<eT>::memptr() + Mat<eT>::n_cols;
   }
 
+#ifdef ARMA_EXTRA_ROW_MEAT
+#include ARMA_EXTRA_ROW_MEAT
+#endif
 
 
 //! @}

Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Row_proto.hpp
===================================================================
--- pkg/RcppArmadillo/inst/include/armadillo_bits/Row_proto.hpp	2010-08-19 05:56:51 UTC (rev 2042)
+++ pkg/RcppArmadillo/inst/include/armadillo_bits/Row_proto.hpp	2010-08-19 06:38:05 UTC (rev 2043)
@@ -99,6 +99,10 @@
   template<typename T1, typename T2, typename glue_type> inline const Row&  operator=(const mtGlue<eT, T1, T2, glue_type>& X);
   template<typename T1, typename T2, typename glue_type> inline const Row& operator*=(const mtGlue<eT, T1, T2, glue_type>& X);
   
+#ifdef ARMA_EXTRA_ROW_PROTO
+#include ARMA_EXTRA_ROW_PROTO
+#endif
+
   inline void  set_size(const u32 N);
   inline void  set_size(const u32 n_rows, const u32 n_cols);
   inline void   reshape(const u32 n_rows, const u32 n_cols, const u32 dim = 0);

Modified: pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R
===================================================================
--- pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R	2010-08-19 05:56:51 UTC (rev 2042)
+++ pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R	2010-08-19 06:38:05 UTC (rev 2043)
@@ -273,12 +273,22 @@
 
 	fx <- cxxfunction( signature(x= "numeric") , '
 	NumericVector xx(x) ;
-	arma::mat m = xx + xx ; 
-    return wrap( m + m ) ;
-    
-	', plugin = "RcppArmadillo" )
+	arma::mat m = xx + xx ;
+	arma::colvec co = xx ;
+	arma::rowvec ro = xx ;
+    return List::create( 
+    	_["mat"] = m + m, 
+    	_["rowvec"] = ro, 
+    	_["colvec"] = co 
+    ); 
+    ', plugin = "RcppArmadillo" )
 	checkEquals( fx(1:10), 
-		matrix( 4*(1:10), nrow = 10 ) , 
+		list( 
+			mat = matrix( 4*(1:10), nrow = 10 ), 
+			rowvec = matrix( 1:10, nrow = 1 ), 
+			colvec = matrix( 1:10, ncol = 1 )
+			)
+		, 
 		msg = "Mat( sugar expression )" )
 	
 }
@@ -286,14 +296,31 @@
 
 test.armadillo.sugar.matrix.ctor <- function(){
 
+	inc <- '
+	double norm( double x, double y){
+		return ::sqrt( x*x + y*y );
+	}
+	'
 	fx <- cxxfunction( signature(x= "numeric") , '
 	NumericVector xx(x) ;
+	NumericVector yy = NumericVector::create( 1 ) ;
 	arma::mat m = diag( xx ) ; 
-    return wrap( m ) ;
-    
-	', plugin = "RcppArmadillo" )
-	checkEquals( fx(1:10), 
-		diag( 1:10 ) , 
+	arma::colvec co = outer( xx, yy, ::norm ) ;
+	arma::rowvec ro = outer( yy, xx, ::norm ) ;
+    return List::create( 
+    	_["mat"] = m + m, 
+    	_["rowvec"] = ro, 
+    	_["colvec"] = co 
+    ); 
+    ', plugin = "RcppArmadillo", includes = inc )
+	res <- fx(1:10)    
+	norm <- function(x, y) sqrt( x*x + y*y )
+	checkEquals( res, 
+		list( 
+			mat = diag(2*(1:10)), 
+			rowvec = outer( 1, 1:10, norm ), 
+			colvec = outer( 1:10, 1, norm )
+		), 
 		msg = "Mat( sugar expression )" )
 	
 }



More information about the Rcpp-commits mailing list