20#ifndef Rcpp__sugar__mean_h
21#define Rcpp__sugar__mean_h
26template <
int RTYPE,
bool NA,
typename T>
27class Mean :
public Lazy<double, Mean<RTYPE,NA,T> > {
36 R_xlen_t n = input.
size();
37 long double s = std::accumulate(input.
begin(), input.
end(), 0.0L);
39 if (R_FINITE((
double)s)) {
41 for (R_xlen_t i = 0; i < n; i++) {
52template <
bool NA,
typename T>
53class Mean<CPLXSXP,
NA,T> :
public Lazy<Rcomplex, Mean<CPLXSXP,NA,T> > {
59 Rcomplex
get()
const {
61 R_xlen_t n = input.
size();
62 long double s = 0.0, si = 0.0;
63 for (R_xlen_t i=0; i<n; i++) {
64 Rcomplex z = input[i];
70 if (R_FINITE((
double)s) && R_FINITE((
double)si)) {
71 long double t = 0.0, ti = 0.0;
72 for (R_xlen_t i = 0; i < n; i++) {
73 Rcomplex z = input[i];
81 z.r =
static_cast<double>(s);
82 z.i =
static_cast<double>(si);
89template <
bool NA,
typename T>
90class Mean<LGLSXP,
NA,T> :
public Lazy<double, Mean<LGLSXP,NA,T> > {
98 R_xlen_t n = input.
size();
100 for (R_xlen_t i=0; i<n; i++) {
101 if (input[i] == NA_INTEGER)
return NA_REAL;
111template <
bool NA,
typename T>
112class Mean<INTSXP,
NA,T> :
public Lazy<double, Mean<INTSXP,NA,T> > {
120 R_xlen_t n = input.
size();
121 long double s = std::accumulate(input.
begin(), input.
end(), 0.0L);
124 for (R_xlen_t i = 0; i < n; i++) {
125 if (input[i] == NA_INTEGER)
return NA_REAL;
137template <
bool NA,
typename T>
142template <
bool NA,
typename T>
147template <
bool NA,
typename T>
152template <
bool NA,
typename T>
Mean(const VEC_TYPE &object_)
Rcpp::VectorBase< CPLXSXP, NA, T > VEC_TYPE
Mean(const VEC_TYPE &object_)
Rcpp::VectorBase< INTSXP, NA, T > VEC_TYPE
Mean(const VEC_TYPE &object_)
Rcpp::VectorBase< LGLSXP, NA, T > VEC_TYPE
Rcpp::VectorBase< RTYPE, NA, T > VEC_TYPE
Rcpp::Vector< RTYPE > VECTOR
Mean(const VEC_TYPE &object_)
sugar::Mean< REALSXP, NA, T > mean(const VectorBase< REALSXP, NA, T > &t)
Vector< LGLSXP > LogicalVector
Vector< INTSXP > IntegerVector
Vector< CPLXSXP > ComplexVector