@@ -26,21 +26,20 @@ namespace Rcpp{
26
26
namespace sugar {
27
27
28
28
template <int RTYPE, bool NA, typename T>
29
- class Mean : public Lazy < typename Rcpp::traits::storage_type<RTYPE>::type , Mean<RTYPE,NA,T> > {
29
+ class Mean : public Lazy <typename Rcpp::traits::storage_type<RTYPE>::type, Mean<RTYPE,NA,T> > {
30
30
public:
31
- typedef typename Rcpp::VectorBase<RTYPE,NA,T> VEC_TYPE ;
32
- typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE ;
31
+ typedef typename Rcpp::VectorBase<RTYPE,NA,T> VEC_TYPE;
32
+ typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE;
33
+ typedef Rcpp::Vector<RTYPE> VECTOR;
33
34
34
- Mean ( const VEC_TYPE& object_ ) : object(object_){}
35
+ Mean (const VEC_TYPE& object_) : object(object_) {}
35
36
36
37
STORAGE get () const {
37
- // return sum(object).get() / object.size() ;
38
- NumericVector input = object;
39
-
38
+ VECTOR input = object;
40
39
int n = input.size (); // double pass (as in summary.c)
41
40
long double s = std::accumulate (input.begin (), input.end (), 0 .0L );
42
41
s /= n;
43
- if (R_FINITE ((double )s)) {
42
+ if (R_FINITE ((double )s)) {
44
43
long double t = 0.0 ;
45
44
for (int i = 0 ; i < n; i++) {
46
45
t += input[i] - s;
@@ -51,16 +50,21 @@ class Mean : public Lazy< typename Rcpp::traits::storage_type<RTYPE>::type , Mea
51
50
}
52
51
private:
53
52
const VEC_TYPE& object ;
54
- } ;
53
+ };
55
54
56
55
} // sugar
57
56
58
57
template <bool NA, typename T>
59
- inline sugar::Mean<REALSXP,NA,T> mean ( const VectorBase<REALSXP,NA,T>& t){
60
- return sugar::Mean<REALSXP,NA,T>( t ) ;
58
+ inline sugar::Mean<REALSXP,NA,T> mean (const VectorBase<REALSXP,NA,T>& t) {
59
+ return sugar::Mean<REALSXP,NA,T>(t) ;
61
60
}
62
61
62
+ template <bool NA, typename T>
63
+ inline sugar::Mean<INTSXP,NA,T> mean (const VectorBase<INTSXP,NA,T>& t) {
64
+ return sugar::Mean<INTSXP,NA,T>(t);
65
+ }
63
66
64
67
} // Rcpp
65
68
#endif
66
69
70
+
0 commit comments