[Rcpp-commits] r3015 - in pkg/Rcpp: . inst inst/include/Rcpp/sugar/functions

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Apr 26 16:51:30 CEST 2011


Author: romain
Date: 2011-04-26 16:51:30 +0200 (Tue, 26 Apr 2011)
New Revision: 3015

Added:
   pkg/Rcpp/inst/include/Rcpp/sugar/functions/mean.h
Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/NEWS
   pkg/Rcpp/inst/include/Rcpp/sugar/functions/functions.h
Log:
new sugar function : mean

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2011-04-25 19:37:25 UTC (rev 3014)
+++ pkg/Rcpp/ChangeLog	2011-04-26 14:51:30 UTC (rev 3015)
@@ -1,3 +1,7 @@
+2011-04-26  Romain Francois  <romain at r-enthusiasts.com>
+
+    * inst/include/Rcpp/sugar/functions/mean.h: new sugar function: mean
+
 2011-04-19  Dirk Eddelbuettel  <edd at debian.org>
 
 	* inst/doc/Rcpp-FAQ/Rcpp-FAQ.Rnw: New example setting row and column

Modified: pkg/Rcpp/inst/NEWS
===================================================================
--- pkg/Rcpp/inst/NEWS	2011-04-25 19:37:25 UTC (rev 3014)
+++ pkg/Rcpp/inst/NEWS	2011-04-26 14:51:30 UTC (rev 3015)
@@ -2,6 +2,8 @@
 
     o   New Rcpp-FAQ examples on using the plugin maker for inline's
         cxxfunction(), and on setting row and column names for matrices
+        
+    o   New sugar function: mean
 
 0.9.4   2011-04-12
 

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/functions/functions.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/functions/functions.h	2011-04-25 19:37:25 UTC (rev 3014)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/functions/functions.h	2011-04-26 14:51:30 UTC (rev 3015)
@@ -51,6 +51,7 @@
 #include <Rcpp/sugar/functions/tail.h>
 
 #include <Rcpp/sugar/functions/sum.h>
+#include <Rcpp/sugar/functions/mean.h>
 #include <Rcpp/sugar/functions/cumsum.h>
 
 #endif

Added: pkg/Rcpp/inst/include/Rcpp/sugar/functions/mean.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/functions/mean.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/functions/mean.h	2011-04-26 14:51:30 UTC (rev 3015)
@@ -0,0 +1,53 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// mean.h: Rcpp R/C++ interface class library -- mean
+//
+// Copyright (C) 2011 Dirk Eddelbuettel and Romain Francois
+//
+// This file is part of Rcpp.
+//
+// Rcpp 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.
+//
+// Rcpp 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 Rcpp.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef Rcpp__sugar__mean_h
+#define Rcpp__sugar__mean_h
+
+namespace Rcpp{
+namespace sugar{
+
+template <int RTYPE, bool NA, typename T>
+class Mean : public Lazy< typename Rcpp::traits::storage_type<RTYPE>::type , Mean<RTYPE,NA,T> > {
+public:
+	typedef typename Rcpp::VectorBase<RTYPE,NA,T> VEC_TYPE ;
+	typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE ;
+		                                             
+	Mean( const VEC_TYPE& object_ ) : object(object_){}
+	
+	STORAGE get() const {
+		return sum(object).get() / object.size() ;
+	}         
+private:
+	const VEC_TYPE& object ;
+} ;
+
+} // sugar
+
+template <bool NA, typename T>
+inline sugar::Mean<REALSXP,NA,T> mean( const VectorBase<REALSXP,NA,T>& t){
+	return sugar::Mean<REALSXP,NA,T>( t ) ;
+}
+
+
+} // Rcpp
+#endif
+



More information about the Rcpp-commits mailing list