milena r4304: Add untake methods to sum and mean accumulators

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 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. --- math/sum.hh | 9 +++++++++ stat/mean.hh | 44 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) Index: trunk/milena/mln/accu/math/sum.hh =================================================================== --- trunk/milena/mln/accu/math/sum.hh (revision 4303) +++ trunk/milena/mln/accu/math/sum.hh (revision 4304) @@ -122,6 +122,7 @@ 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); /// \} @@ -192,6 +193,14 @@ 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& sum<T,S>::to_result() const { Index: trunk/milena/mln/accu/stat/mean.hh =================================================================== --- trunk/milena/mln/accu/stat/mean.hh (revision 4303) +++ trunk/milena/mln/accu/stat/mean.hh (revision 4304) @@ -88,7 +88,7 @@ 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 @@ 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 @@ /// 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_; @@ -187,6 +195,23 @@ 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 mean<T,S,M>::to_result() const { @@ -211,6 +236,23 @@ 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
participants (1)
-
Edwin Carlinet