22 #ifndef Rcpp__sugar__mean_h
23 #define Rcpp__sugar__mean_h
28 template <
int RTYPE,
bool NA,
typename T>
29 class Mean :
public Lazy<double, Mean<RTYPE,NA,T> > {
38 R_xlen_t n = input.
size();
39 long double s = std::accumulate(input.
begin(), input.
end(), 0.0L);
41 if (R_FINITE((
double)s)) {
43 for (R_xlen_t i = 0; i < n; i++) {
54 template <
bool NA,
typename T>
55 class Mean<CPLXSXP,
NA,T> :
public Lazy<Rcomplex, Mean<CPLXSXP,NA,T> > {
61 Rcomplex
get()
const {
63 R_xlen_t n = input.
size();
64 long double s = 0.0, si = 0.0;
65 for (R_xlen_t i=0; i<n; i++) {
66 Rcomplex z = input[i];
72 if (R_FINITE((
double)s) && R_FINITE((
double)si)) {
73 long double t = 0.0, ti = 0.0;
74 for (R_xlen_t i = 0; i < n; i++) {
75 Rcomplex z = input[i];
91 template <
bool NA,
typename T>
92 class Mean<LGLSXP,
NA,T> :
public Lazy<double, Mean<LGLSXP,NA,T> > {
100 R_xlen_t n = input.
size();
102 for (R_xlen_t i=0; i<n; i++) {
103 if (input[i] == NA_INTEGER)
return NA_REAL;
113 template <
bool NA,
typename T>
114 class Mean<INTSXP,
NA,T> :
public Lazy<double, Mean<INTSXP,NA,T> > {
122 R_xlen_t n = input.
size();
123 long double s = std::accumulate(input.
begin(), input.
end(), 0.0L);
126 for (R_xlen_t i = 0; i < n; i++) {
127 if (input[i] == NA_INTEGER)
return NA_REAL;
139 template <
bool NA,
typename T>
144 template <
bool NA,
typename T>
149 template <
bool NA,
typename T>
154 template <
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)