Rcpp Version 1.0.14
Loading...
Searching...
No Matches
var.h
Go to the documentation of this file.
1// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2//
3// var.h: Rcpp R/C++ interface class library -- var
4//
5// Copyright (C) 2011 Dirk Eddelbuettel and Romain Francois
6// Copyright (C) 2015 Wush Wu
7//
8// This file is part of Rcpp.
9//
10// Rcpp is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 2 of the License, or
13// (at your option) any later version.
14//
15// Rcpp is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
22
23#ifndef Rcpp__sugar__var_h
24#define Rcpp__sugar__var_h
25
26namespace Rcpp{
27namespace sugar{
28
29template <int RTYPE, bool NA, typename T>
30class Var : public Lazy< double , Var<RTYPE,NA,T> > {
31public:
33
35
36 double get() const{
37 const double average = mean(object).get();
38 const R_xlen_t sample_size = object.size();
39 double sum_squared_deviations = 0.0;
40 for (R_xlen_t i = 0; i != sample_size; ++i)
41 sum_squared_deviations += std::pow(object[i] - average, 2.0);
43 }
44
45private:
47} ;
48
49template <bool NA, typename T>
50class Var<CPLXSXP,NA,T> : public Lazy< double , Var<CPLXSXP,NA,T> > {
51public:
53
55
56 double get() const{
57 const Rcomplex average = mean(object).get();
58 const R_xlen_t sample_size = object.size();
60 for (R_xlen_t i = 0; i != sample_size; ++i) {
61 const Rcomplex deviation = object[i] - average;
63 }
65 }
66
67private:
69} ;
70
71} // sugar
72
73template <bool NA, typename T>
77
78template <bool NA, typename T>
82
83template <bool NA, typename T>
87
88template <bool NA, typename T>
92
93} // Rcpp
94#endif
95
const VEC_TYPE & object
Definition var.h:68
Rcpp::VectorBase< CPLXSXP, NA, T > VEC_TYPE
Definition var.h:52
Var(const VEC_TYPE &object_)
Definition var.h:54
Var(const VEC_TYPE &object_)
Definition var.h:34
Rcpp::VectorBase< RTYPE, NA, T > VEC_TYPE
Definition var.h:32
const VEC_TYPE & object
Definition var.h:46
double get() const
Definition var.h:36
Rcpp API.
Definition algo.h:28
sugar::Mean< REALSXP, NA, T > mean(const VectorBase< REALSXP, NA, T > &t)
Definition mean.h:138
sugar::Var< REALSXP, NA, T > var(const VectorBase< REALSXP, NA, T > &t)
Definition var.h:74
T as(SEXP x)
Definition as.h:151
static Na_Proxy NA
Definition Na_Proxy.h:52