[Rcpp-commits] r3017 - 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 17:40:52 CEST 2011
Author: romain
Date: 2011-04-26 17:40:52 +0200 (Tue, 26 Apr 2011)
New Revision: 3017
Added:
pkg/Rcpp/inst/include/Rcpp/sugar/functions/sd.h
Modified:
pkg/Rcpp/ChangeLog
pkg/Rcpp/inst/NEWS
pkg/Rcpp/inst/include/Rcpp/sugar/functions/functions.h
Log:
+sd
Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog 2011-04-26 15:31:13 UTC (rev 3016)
+++ pkg/Rcpp/ChangeLog 2011-04-26 15:40:52 UTC (rev 3017)
@@ -4,6 +4,8 @@
* inst/include/Rcpp/sugar/functions/var.h: new sugar function: var
+ * inst/include/Rcpp/sugar/functions/sd.h: new sugar function: sd
+
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 15:31:13 UTC (rev 3016)
+++ pkg/Rcpp/inst/NEWS 2011-04-26 15:40:52 UTC (rev 3017)
@@ -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 functions: mean, var
+ o New sugar functions: mean, var, sd
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 15:31:13 UTC (rev 3016)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/functions/functions.h 2011-04-26 15:40:52 UTC (rev 3017)
@@ -53,6 +53,7 @@
#include <Rcpp/sugar/functions/sum.h>
#include <Rcpp/sugar/functions/mean.h>
#include <Rcpp/sugar/functions/var.h>
+#include <Rcpp/sugar/functions/sd.h>
#include <Rcpp/sugar/functions/cumsum.h>
#endif
Added: pkg/Rcpp/inst/include/Rcpp/sugar/functions/sd.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/functions/sd.h (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/functions/sd.h 2011-04-26 15:40:52 UTC (rev 3017)
@@ -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__sd_h
+#define Rcpp__sugar__sd_h
+
+namespace Rcpp{
+namespace sugar{
+
+template <int RTYPE, bool NA, typename T>
+class Sd : public Lazy< typename Rcpp::traits::storage_type<RTYPE>::type , Sd<RTYPE,NA,T> > {
+public:
+ typedef typename Rcpp::VectorBase<RTYPE,NA,T> VEC_TYPE ;
+ typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE ;
+
+ Sd( const VEC_TYPE& object_ ) : object(object_){}
+
+ STORAGE get() const {
+ return ::sqrt( var(object).get() ) ;
+ }
+private:
+ const VEC_TYPE& object ;
+} ;
+
+} // sugar
+
+template <bool NA, typename T>
+inline sugar::Sd<REALSXP,NA,T> sd( const VectorBase<REALSXP,NA,T>& t){
+ return sugar::Sd<REALSXP,NA,T>( t ) ;
+}
+
+
+} // Rcpp
+#endif
+
More information about the Rcpp-commits
mailing list