STK++ 0.9.13
STK::Stat::SumSafeOp< Derived > Struct Template Reference

Compute safely the sum of the variable V. More...

#include <STK_Stat_Functors.h>

Public Types

typedef Derived::Type Type
 

Public Member Functions

 SumSafeOp (ExprBase< Derived > const &V)
 constructor
 
Type const operator() () const
 
template<class Weights >
Type const operator() (ExprBase< Weights > const &w) const
 

Protected Attributes

Derived constV_
 

Detailed Description

template<class Derived>
struct STK::Stat::SumSafeOp< Derived >

Compute safely the sum of the variable V.

Definition at line 255 of file STK_Stat_Functors.h.

Member Typedef Documentation

◆ Type

template<class Derived >
typedef Derived::Type STK::Stat::SumSafeOp< Derived >::Type

Definition at line 257 of file STK_Stat_Functors.h.

Constructor & Destructor Documentation

◆ SumSafeOp()

template<class Derived >
STK::Stat::SumSafeOp< Derived >::SumSafeOp ( ExprBase< Derived > const V)
inline

constructor

Definition at line 259 of file STK_Stat_Functors.h.

259 : V_(V.asDerived())
#define STK_STATIC_ASSERT_ONE_DIMENSION_ONLY(EXPR)

References STK_STATIC_ASSERT_ONE_DIMENSION_ONLY.

Member Function Documentation

◆ operator()() [1/2]

template<class Derived >
Type const STK::Stat::SumSafeOp< Derived >::operator() ( ) const
inline
Returns
the safely computed sum of the variable V discarding all missing values.

Definition at line 262 of file STK_Stat_Functors.h.

263 {
264 // sum the samples
265 Type sum = 0.0;
266 for (int i=V_.begin(); i<V_.end(); i++)
267 { if (!Arithmetic<Type>::isNA(V_[i])) sum += V_[i];}
268 return sum;
269 }
hidden::FunctorTraits< Derived, SumOp >::Row sum(Derived const &A)
Compute the sum of A.
static bool isNA(Type const &x)

References STK::Stat::sum(), and STK::Stat::SumSafeOp< Derived >::V_.

◆ operator()() [2/2]

template<class Derived >
template<class Weights >
Type const STK::Stat::SumSafeOp< Derived >::operator() ( ExprBase< Weights > const w) const
inline
Returns
the safely computed weighted sum of the variable V
Parameters
wthe weights

Definition at line 274 of file STK_Stat_Functors.h.

275 {
277#ifdef STK_BOUNDS_CHECK
278 if (V_.range() != w.range())
279 STKRUNTIME_ERROR_NO_ARG(wmeanSafe,V.range()!=w.range());
280#endif
281 // sum the weighted samples
282 Type sum = 0.0;
283 for (int i=V_.begin(); i<V_.end(); i++)
284 { if ( (!Arithmetic<Type>::isNA(V_[i])) && (!Arithmetic<Type>::isNA(w[i])))
285 { sum += std::abs(w[i]) * V_[i];}
286 }
287 return sum;
288 }
#define STKRUNTIME_ERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:138

References STK::Arithmetic< Type >::isNA(), STK_STATIC_ASSERT_ONE_DIMENSION_ONLY, STKRUNTIME_ERROR_NO_ARG, STK::Stat::sum(), and STK::Stat::SumSafeOp< Derived >::V_.

Member Data Documentation

◆ V_

template<class Derived >
Derived const& STK::Stat::SumSafeOp< Derived >::V_
protected

The documentation for this struct was generated from the following file: