Skip to content

Commit 2e08e4b

Browse files
committed
support INTSXP (cf #221)
1 parent e6882c0 commit 2e08e4b

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2014-12-31 Dirk Eddelbuettel <[email protected]>
2+
3+
* inst/include/Rcpp/sugar/functions/mean.h: Support INTSXP
4+
15
2014-12-30 Dirk Eddelbuettel <[email protected]>
26

37
* inst/include/Rcpp/sugar/functions/mean.h: Use two-pass method

inst/include/Rcpp/sugar/functions/mean.h

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,20 @@ namespace Rcpp{
2626
namespace sugar{
2727

2828
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> > {
3030
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;
3334

34-
Mean( const VEC_TYPE& object_ ) : object(object_){}
35+
Mean(const VEC_TYPE& object_) : object(object_) {}
3536

3637
STORAGE get() const {
37-
//return sum(object).get() / object.size() ;
38-
NumericVector input = object;
39-
38+
VECTOR input = object;
4039
int n = input.size(); // double pass (as in summary.c)
4140
long double s = std::accumulate(input.begin(), input.end(), 0.0L);
4241
s /= n;
43-
if (R_FINITE((double)s)) {
42+
if (R_FINITE((double)s)) {
4443
long double t = 0.0;
4544
for (int i = 0; i < n; i++) {
4645
t += input[i] - s;
@@ -51,16 +50,21 @@ class Mean : public Lazy< typename Rcpp::traits::storage_type<RTYPE>::type , Mea
5150
}
5251
private:
5352
const VEC_TYPE& object ;
54-
} ;
53+
};
5554

5655
} // sugar
5756

5857
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);
6160
}
6261

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+
}
6366

6467
} // Rcpp
6568
#endif
6669

70+

0 commit comments

Comments
 (0)