-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathvar.h
More file actions
36 lines (26 loc) · 889 Bytes
/
var.h
File metadata and controls
36 lines (26 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef Rcpp__sugar__var_h
#define Rcpp__sugar__var_h
namespace Rcpp{
namespace sugar{
template <int RTYPE, bool NA, typename T>
class Var : public Lazy< typename Rcpp::traits::storage_type<RTYPE>::type , Var<RTYPE,NA,T> > {
public:
typedef typename Rcpp::VectorBase<RTYPE,NA,T> VEC_TYPE ;
typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE ;
Var( const VEC_TYPE& object_ ) : object(object_){}
STORAGE get() const{
STORAGE m = mean(object).get() ;
Minus_Vector_Primitive<RTYPE,NA,T> mm( object, m) ;
STORAGE ssq = sum( pow(mm,2.0) ).get() ;
return ssq / (object.size() - 1 ) ;
}
private:
const VEC_TYPE& object ;
} ;
} // sugar
template <bool NA, typename T>
inline sugar::Var<REALSXP,NA,T> var( const VectorBase<REALSXP,NA,T>& t){
return sugar::Var<REALSXP,NA,T>( t ) ;
}
} // Rcpp
#endif