Commit 48e0bb25 authored by Edwin Carlinet's avatar Edwin Carlinet
Browse files

Add untake methods to sum and mean accumulators.

	* accu/math/sum.hh: Add untake method.
	* accu/stat/mean.hh: Add untake, sum, count methods.

git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@4304 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 02d345c2
2009-07-16 Edwin Carlinet <carlinet@lrde.epita.fr>
Add untake methods to sum and mean accumulators.
* accu/math/sum.hh: Add untake method.
* accu/stat/mean.hh: Add untake, sum, count methods.
2009-07-13 Roland Levillain <roland@lrde.epita.fr>
 
* doc/examples/examples.mk, doc/outputs/outputs.mk: Regen.
......@@ -122,6 +122,7 @@ namespace mln
void take(const sum<T,S>& other);
void untake(const argument& t);
void untake(const sum<T,S>& other);
void set_value(const S& s);
/// \}
......@@ -190,6 +191,14 @@ namespace mln
s_ += other.s_;
}
template <typename T, typename S>
inline
void
sum<T,S>::untake(const sum<T,S>& other)
{
s_ -= other.s_;
}
template <typename T, typename S>
inline
const S&
......
......@@ -88,7 +88,7 @@ namespace mln
template <typename T, typename S, typename M>
struct accumulator_< accu::stat::mean<T, S, M> >
{
typedef accumulator::has_untake::no has_untake;
typedef accumulator::has_untake::yes has_untake;
typedef accumulator::has_set_value::no has_set_value;
typedef accumulator::has_stop::no has_stop;
typedef accumulator::when_pix::use_v when_pix;
......@@ -128,6 +128,8 @@ namespace mln
void init();
void take(const argument& t);
void take(const mean<T,S,M>& other);
void untake(const argument& t);
void untake(const mean<T,S,M>& other);
/// \}
/// Get the value of the accumulator.
......@@ -138,6 +140,12 @@ namespace mln
/// Always true here.
bool is_valid() const;
/// Get the cardinality.
mln_result(accu::math::count<T>) count() const;
/// Get the sum of values.
mln_result(accu::math::sum<T>) sum() const;
protected:
accu::math::count<T> count_;
......@@ -185,6 +193,23 @@ namespace mln
sum_.take(other.sum_);
}
template <typename T, typename S, typename M>
inline
void mean<T,S,M>::untake(const argument& t)
{
count_.untake(t);
sum_.untake(t);
}
template <typename T, typename S, typename M>
inline
void
mean<T,S,M>::untake(const mean<T,S,M>& other)
{
count_.untake(other.count_);
sum_.untake(other.sum_);
}
template <typename T, typename S, typename M>
inline
M
......@@ -211,6 +236,23 @@ namespace mln
return count_.to_result() != 0;
}
template <typename T, typename S, typename M>
inline
mln_result(accu::math::count<T>)
mean<T,S,M>::count() const
{
return count_.to_result();
}
template <typename T, typename S, typename M>
inline
mln_result(accu::math::sum<T>)
mean<T,S,M>::sum() const
{
return sum_.to_result();
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::accu::stat
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment