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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Apr 26 17:31:14 CEST 2011


Author: romain
Date: 2011-04-26 17:31:13 +0200 (Tue, 26 Apr 2011)
New Revision: 3016

Added:
   pkg/Rcpp/inst/include/Rcpp/sugar/functions/impl/
   pkg/Rcpp/inst/include/Rcpp/sugar/functions/impl/var.h
   pkg/Rcpp/inst/include/Rcpp/sugar/functions/var.h
   pkg/Rcpp/inst/include/Rcpp/sugar/sugar_impl.h
Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/NEWS
   pkg/Rcpp/inst/include/Rcpp.h
   pkg/Rcpp/inst/include/Rcpp/sugar/functions/functions.h
Log:
+ var

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2011-04-26 14:51:30 UTC (rev 3015)
+++ pkg/Rcpp/ChangeLog	2011-04-26 15:31:13 UTC (rev 3016)
@@ -1,7 +1,9 @@
 2011-04-26  Romain Francois  <romain at r-enthusiasts.com>
 
     * inst/include/Rcpp/sugar/functions/mean.h: new sugar function: mean
-
+    
+    * inst/include/Rcpp/sugar/functions/var.h: new sugar function: var
+    
 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-26 14:51:30 UTC (rev 3015)
+++ pkg/Rcpp/inst/NEWS	2011-04-26 15:31:13 UTC (rev 3016)
@@ -3,7 +3,7 @@
     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
+    o   New sugar functions: mean, var
 
 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-26 14:51:30 UTC (rev 3015)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/functions/functions.h	2011-04-26 15:31:13 UTC (rev 3016)
@@ -52,6 +52,7 @@
 
 #include <Rcpp/sugar/functions/sum.h>
 #include <Rcpp/sugar/functions/mean.h>
+#include <Rcpp/sugar/functions/var.h>
 #include <Rcpp/sugar/functions/cumsum.h>
 
 #endif

Added: pkg/Rcpp/inst/include/Rcpp/sugar/functions/impl/var.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/functions/impl/var.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/functions/impl/var.h	2011-04-26 15:31:13 UTC (rev 3016)
@@ -0,0 +1,39 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// var.h: Rcpp R/C++ interface class library -- var
+//
+// 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__impl_var_h
+#define Rcpp__sugar__impl_var_h
+
+namespace Rcpp{
+namespace sugar{
+
+    template <int RTYPE, bool NA, typename T>
+    typename Rcpp::traits::storage_type<RTYPE>::type Var<RTYPE,NA,T>::get() const {
+		STORAGE m = mean(object).get() ;
+		Minus_Vector_Primitive<RTYPE,NA,T> mm( object, m) ;
+		STORAGE ssq  = sum( pow(mm,2.0) ).get() ;
+	    return ssq / (object.size() - 1 ) ;
+	}         
+	
+}
+}
+
+#endif

Added: pkg/Rcpp/inst/include/Rcpp/sugar/functions/var.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/functions/var.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/functions/var.h	2011-04-26 15:31:13 UTC (rev 3016)
@@ -0,0 +1,52 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// var.h: Rcpp R/C++ interface class library -- var
+//
+// 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__var_h
+#define Rcpp__sugar__var_h
+
+namespace Rcpp{
+namespace sugar{
+
+template <int RTYPE, bool NA, typename T>
+class Var : public Lazy< typename Rcpp::traits::storage_type<RTYPE>::type , Var<RTYPE,NA,T> > {
+public:
+	typedef typename Rcpp::VectorBase<RTYPE,NA,T> VEC_TYPE ;
+	typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE ;
+		                                             
+	Var( const VEC_TYPE& object_ ) : object(object_){}
+	
+	STORAGE get() const ; 
+	
+private:
+	const VEC_TYPE& object ;
+} ;
+
+} // sugar
+
+template <bool NA, typename T>
+inline sugar::Var<REALSXP,NA,T> var( const VectorBase<REALSXP,NA,T>& t){
+	return sugar::Var<REALSXP,NA,T>( t ) ;
+}
+
+
+} // Rcpp
+#endif
+

Added: pkg/Rcpp/inst/include/Rcpp/sugar/sugar_impl.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/sugar_impl.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/sugar_impl.h	2011-04-26 15:31:13 UTC (rev 3016)
@@ -0,0 +1,27 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// sugar_impl.h: Rcpp R/C++ interface class library -- 
+//
+// 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_IMPL_H
+#define RCPP_SUGAR_IMPL_H
+
+#include <Rcpp/sugar/functions/impl/var.h>
+
+#endif

Modified: pkg/Rcpp/inst/include/Rcpp.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp.h	2011-04-26 14:51:30 UTC (rev 3015)
+++ pkg/Rcpp/inst/include/Rcpp.h	2011-04-26 15:31:13 UTC (rev 3016)
@@ -67,5 +67,6 @@
 
 #include <Rcpp/sugar/sugar.h>
 #include <Rcpp/stats/stats.h>
+#include <Rcpp/sugar/sugar_impl.h>
 
 #endif



More information about the Rcpp-commits mailing list