
* headers.mk: add new header to distribution. * mln/accu/all.hh: include new header. * mln/accu/rms.hh: Compute the root mean square. * tests/unit_test/Makefile.am, * tests/unit_test/mln_accu_rms.cc: add unit test. --- milena/ChangeLog | 15 +++- milena/headers.mk | 1 + milena/mln/accu/all.hh | 1 + milena/mln/accu/rms.hh | 165 ++++++++++++++++++++++++++++++++ milena/tests/unit_test/Makefile.am | 1 + milena/tests/unit_test/mln_accu_rms.cc | 11 ++ 6 files changed, 193 insertions(+), 1 deletions(-) create mode 100644 milena/mln/accu/rms.hh create mode 100644 milena/tests/unit_test/mln_accu_rms.cc diff --git a/milena/ChangeLog b/milena/ChangeLog index 58b16ad..f2defdd 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,18 @@ 2009-02-02 Guillaume Lazzara <z@lrde.epita.fr> + Add accu::rms. + + * headers.mk: add new header to distribution. + + * mln/accu/all.hh: include new header. + + * mln/accu/rms.hh: Compute the root mean square. + + * tests/unit_test/Makefile.am, + * tests/unit_test/mln_accu_rms.cc: add unit test. + +2009-02-02 Guillaume Lazzara <z@lrde.epita.fr> + Add make::h_mat. * headers.mk: add new header to distribution. @@ -49,7 +62,7 @@ 2009-02-02 Thierry Geraud <thierry.geraud@lrde.epita.fr> Activate fastest version of algebraic union-find. - + * mln/morpho/closing_attribute.hh (closing_attribute_dispatch): Activate for fastest images. * mln/canvas/morpho/algebraic_union_find.hh: Likewise. diff --git a/milena/headers.mk b/milena/headers.mk index 04bef51..6a937c5 100644 --- a/milena/headers.mk +++ b/milena/headers.mk @@ -366,6 +366,7 @@ mln/accu/transform_snake.hh \ mln/accu/rank_high_quant.hh \ mln/accu/count.hh \ mln/accu/median_h.hh \ +mln/accu/rms.hh \ mln/accu/all.hh \ mln/accu/land_basic.hh \ mln/accu/p.hh \ diff --git a/milena/mln/accu/all.hh b/milena/mln/accu/all.hh index 273d4d2..0181b9a 100644 --- a/milena/mln/accu/all.hh +++ b/milena/mln/accu/all.hh @@ -77,6 +77,7 @@ namespace mln # include <mln/accu/nil.hh> # include <mln/accu/pair.hh> # include <mln/accu/rank.hh> +# include <mln/accu/rms.hh> # include <mln/accu/sum.hh> # include <mln/accu/tuple.hh> # include <mln/accu/volume.hh> diff --git a/milena/mln/accu/rms.hh b/milena/mln/accu/rms.hh new file mode 100644 index 0000000..c873686 --- /dev/null +++ b/milena/mln/accu/rms.hh @@ -0,0 +1,165 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef MLN_ACCU_RMS_HH +# define MLN_ACCU_RMS_HH + +/// \file mln/accu/rms.hh +/// +/// Define an accumulator that computes the Root Mean Square. + +# include <mln/core/concept/meta_accumulator.hh> +# include <mln/accu/internal/base.hh> + + +namespace mln +{ + + namespace accu + { + + + /// Generic rms accumulator class. + /// + /// The parameter \c T is the type of the root mean square value. + /// + template <typename T, typename V> + struct rms : public mln::accu::internal::base<V, rms<T,V> > + { + typedef T argument; + + rms(); + + /// Manipulators. + /// \{ + void init(); + void take_as_init(const T& p); + void take(const T& p); + void take(const rms<T,V>& other); + /// \} + + /// Get the value of the accumulator. + V to_result() const; + + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; + + protected: + + V t_; + unsigned count_; + }; + + + namespace meta + { + + /// Meta accumulator for rms. + struct rms : public Meta_Accumulator< rms > + { + template <typename T, typename V> + struct with + { + typedef accu::rms<T,V> ret; + }; + }; + + } // end of namespace mln::accu::meta + + +# ifndef MLN_INCLUDE_ONLY + + template <typename T, typename V> + inline + rms<T,V>::rms() + { + init(); + } + + template <typename T, typename V> + inline + void + rms<T,V>::init() + { + t_ = literal::zero; + count_ = 0; + } + + template <typename T, typename V> + inline + void + rms<T,V>::take_as_init(const T& t) + { + t_ += t * t; + ++count_; + } + + template <typename T, typename V> + inline + void + rms<T,V>::take(const T& t) + { + t_ += t * t; + ++count_; + } + + template <typename T, typename V> + inline + void + rms<T,V>::take(const rms<T,V>& other) + { + t_ += other.t_; + count_ += other.count_; + } + + template <typename T, typename V> + inline + V + rms<T,V>::to_result() const + { + if (count_ == 0) + return literal::zero; + return math::sqrt<V>(t_ / count_); + } + + template <typename T, typename V> + inline + bool + rms<T,V>::is_valid() const + { + return true; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::accu + +} // end of namespace mln + + +#endif // ! MLN_ACCU_RMS_HH diff --git a/milena/tests/unit_test/Makefile.am b/milena/tests/unit_test/Makefile.am index a6b6b26..b31efec 100644 --- a/milena/tests/unit_test/Makefile.am +++ b/milena/tests/unit_test/Makefile.am @@ -362,6 +362,7 @@ mln_accu_transform_snake \ mln_accu_rank_high_quant \ mln_accu_count \ mln_accu_median_h \ +mln_accu_rms \ mln_accu_all \ mln_accu_land_basic \ mln_accu_p \ diff --git a/milena/tests/unit_test/mln_accu_rms.cc b/milena/tests/unit_test/mln_accu_rms.cc new file mode 100644 index 0000000..0dd83bd --- /dev/null +++ b/milena/tests/unit_test/mln_accu_rms.cc @@ -0,0 +1,11 @@ +// Unit test for mln/accu/rms.hh. +// Generated by ./build_unit_test.sh, do not modify. + +// Include the file twice, so we detect missing inclusion guards. +#include <mln/accu/rms.hh> +#include <mln/accu/rms.hh> + +int main() +{ + // Nothing. +} -- 1.5.6.5
participants (1)
-
Guillaume Lazzara