
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2009-06-16 Edwin Carlinet <carlinet@lrde.epita.fr> Move rank accus in stat directory. * mln/accu/rank.hh, * mln/accu/rank_bool.hh, * mln/accu/rank_high_quant.hh: Move to... * mln/accu/stat/rank.hh, * mln/accu/stat/rank_bool.hh, * mln/accu/stat/rank_high_quant.hh: Move rank accus to stat directory. * mln/accu/all.hh, * mln/accu/essential.hh, * mln/accu/stat/all.hh, * mln/accu/stat/essential.hh: Update all and essential respecting new locations. * tests/accu/rank.cc, * tests/accu/stat/rank.cc: Move tests in stat directory. * tests/accu/Makefile.am, * tests/accu/stat/Makefile.am: Update makefiles. * mln/morpho/includes.hh, * mln/morpho/rank_filter.hh, * mln/morpho/tree/compute_attribute_image.hh, * sandbox/theo/tufa_2008/filter_n.cc: Replace accu::accu_name by accu::stat::accu_name, accu::meta::accu_name by accu::meta::stat::accu_name, accu/accu_name by accu/stat/accu_name. --- mln/accu/all.hh | 1 mln/accu/essential.hh | 1 mln/accu/stat/all.hh | 4 mln/accu/stat/essential.hh | 1 mln/accu/stat/rank.hh | 358 +++++++++++++++++++++++++++++ mln/accu/stat/rank_bool.hh | 171 +++++++++++++ mln/accu/stat/rank_high_quant.hh | 224 ++++++++++++++++++ mln/morpho/includes.hh | 2 mln/morpho/rank_filter.hh | 6 mln/morpho/tree/compute_attribute_image.hh | 2 sandbox/theo/tufa_2008/filter_n.cc | 2 tests/accu/Makefile.am | 2 tests/accu/stat/Makefile.am | 5 tests/accu/stat/rank.cc | 108 ++++++++ 14 files changed, 876 insertions(+), 11 deletions(-) Index: trunk/milena/mln/accu/rank.hh (deleted) =================================================================== Index: trunk/milena/mln/accu/rank_high_quant.hh (deleted) =================================================================== Index: trunk/milena/mln/accu/rank_bool.hh (deleted) =================================================================== Index: trunk/milena/mln/accu/all.hh =================================================================== --- trunk/milena/mln/accu/all.hh (revision 4151) +++ trunk/milena/mln/accu/all.hh (revision 4152) @@ -61,7 +61,6 @@ # include <mln/accu/line.hh> # include <mln/accu/nil.hh> # include <mln/accu/pair.hh> -# include <mln/accu/rank.hh> # include <mln/accu/rms.hh> // << # include <mln/accu/tuple.hh> >> Index: trunk/milena/mln/accu/essential.hh =================================================================== --- trunk/milena/mln/accu/essential.hh (revision 4151) +++ trunk/milena/mln/accu/essential.hh (revision 4152) @@ -32,7 +32,6 @@ # include <mln/accu/center.hh> # include <mln/accu/histo.hh> -# include <mln/accu/rank.hh> # include <mln/accu/stat/essential.hh> # include <mln/accu/image/essential.hh> Index: trunk/milena/mln/accu/stat/essential.hh =================================================================== --- trunk/milena/mln/accu/stat/essential.hh (revision 4151) +++ trunk/milena/mln/accu/stat/essential.hh (revision 4152) @@ -37,5 +37,6 @@ # include <mln/accu/stat/min_max.hh> # include <mln/accu/stat/mean.hh> # include <mln/accu/stat/median_h.hh> +# include <mln/accu/stat/rank.hh> #endif // ! MLN_ACCU_STAT_ESSENTIAL_HH Index: trunk/milena/mln/accu/stat/rank.hh =================================================================== --- trunk/milena/mln/accu/stat/rank.hh (revision 0) +++ trunk/milena/mln/accu/stat/rank.hh (revision 4152) @@ -0,0 +1,358 @@ +// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project 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_STAT_RANK_HH +# define MLN_ACCU_STAT_RANK_HH + +/// \file +/// +/// Define an rank accumulator. +/// +/// \todo It should be renamed as rank_h since it relies on histogram +/// (thus low quantization). + +# include <vector> +# include <mln/accu/internal/base.hh> +# include <mln/accu/histo.hh> +# include <mln/core/concept/meta_accumulator.hh> +# include <mln/trait/value_.hh> +# include <mln/util/pix.hh> + + +namespace mln +{ + + namespace accu + { + + namespace stat + { + + + /// \brief Generic rank accumulator class. + /// + /// The parameter \c T is the type of values. + /// + /// \ingroup modaccuvalues + template <typename T> + struct rank : public mln::accu::internal::base< const T&, rank<T> > + { + typedef T argument; + typedef mln::value::set<T> S; + + rank(); + explicit rank(unsigned k); + + /// Manipulators. + /// \{ + void init(); + void take(const argument& t); + void take(const rank<T>& other); + void untake(const argument& t); + void untake(const rank<T>& other); + /// \} + + unsigned card() const { return h_.sum(); } + + /// Get the value of the accumulator. + const T& to_result() const; + + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; + + /// Give the rank. + unsigned k() const; + + protected: + + unsigned k_; // 0 <= k_ < n + + mutable accu::histo<T> h_; + const S& s_; // derived from h_ + + mutable unsigned sum_minus_, sum_plus_; + + mutable bool valid_; + mutable unsigned i_; // the median index + mutable argument t_; // the median value + + // Auxiliary methods + void update_() const; + void go_minus_() const; + void go_plus_() const; + }; + + + template <typename I> struct rank< util::pix<I> >; + + + } // end of mln::accu::stat + + + namespace meta + { + + namespace stat + { + + /// Meta accumulator for rank. + + struct rank : public Meta_Accumulator< rank > + { + rank(unsigned k_) : k(k_) {} + + template <typename T> + struct with + { + typedef accu::stat::rank<T> ret; + }; + + unsigned k; + }; + + } // end of namespace mln::accu::meta::stat + + } // end of namespace mln::accu::meta + + + template <typename T> + stat::rank<T> unmeta(const meta::stat::rank& m, T) + { + stat::rank<T> a(m.k); + return a; + } + + + + + namespace stat + { + +# ifndef MLN_INCLUDE_ONLY + + template <typename T> + inline + rank<T>::rank() + : h_(), + s_(h_.vset()) + { + init(); + } + + template <typename T> + inline + rank<T>::rank(unsigned k) + : k_(k), + h_(), + s_(h_.vset()) + { + init(); + } + + template <typename T> + inline + unsigned + rank<T>::k() const + { + return k_; + } + + template <typename T> + inline + void rank<T>::take(const argument& t) + { + h_.take(t); + + if (t < t_) + ++sum_minus_; + else if (t > t_) + ++sum_plus_; + + if (valid_) + valid_ = false; + } + + template <typename T> + inline + void + rank<T>::take(const rank<T>& other) + { + // h_ + h_.take(other.h_); + + // sum_minus_ + for (unsigned i = 0; i < i_; ++i) + sum_minus_ += other.h_[i]; + + // sum_plus_ + for (unsigned i = i_ + 1; i < h_.nvalues(); ++i) + sum_plus_ += other.h_[i]; + + if (valid_) + valid_ = false; + } + + + template <typename T> + inline + void + rank<T>::untake(const argument& t) + { + mln_precondition(h_(t) != 0); + h_.untake(t); + + if (t < t_) + --sum_minus_; + else if (t > t_) + --sum_plus_; + + if (valid_) + valid_ = false; + } + + template <typename T> + inline + void + rank<T>::untake(const rank<T>& other) + { + // h_ + h_.untake(other.h_); + + // sum_minus_ + for (unsigned i = 0; i < i_; ++i) + sum_minus_ -= other.h_[i]; + + // sum_plus_ + for (unsigned i = i_ + 1; i < h_.nvalues(); ++i) + sum_plus_ -= other.h_[i]; + + if (valid_) + valid_ = false; + } + + template <typename T> + inline + void + rank<T>::update_() const + { + valid_ = true; + + if (h_.sum() == 0) + return; + + if (sum_minus_ > k_) + go_minus_(); + else + if ((sum_minus_ + h_[i_]) < k_) + go_plus_(); + else + if (h_[i_] == 0) + { + // go to the heaviest side + if (sum_plus_ > sum_minus_) + go_plus_(); + else + go_minus_(); // default when both sides are balanced + } + } + + template <typename T> + inline + void + rank<T>::go_minus_() const + { + do + { + sum_plus_ += h_[i_]; + do + --i_; + while (h_[i_] == 0); + sum_minus_ -= h_[i_]; + } + while (sum_minus_ > k_); + t_ = s_[i_]; + } + + template <typename T> + inline + void + rank<T>::go_plus_() const + { + do + { + sum_minus_ += h_[i_]; + do + ++i_; + while (h_[i_] == 0); + sum_plus_ -= h_[i_]; + } + while ((sum_minus_ + h_[i_]) < k_); + t_ = s_[i_]; + } + + template <typename T> + inline + void + rank<T>::init() + { + h_.init(); + sum_minus_ = 0; + sum_plus_ = 0; + i_ = (s_.index_of(mln_max(argument)) + - s_.index_of(mln_min(argument))) / 2; + t_ = s_[i_]; + valid_ = true; + } + + template <typename T> + inline + const T& + rank<T>::to_result() const + { + if (! valid_) + update_(); + return t_; + } + + template <typename T> + inline + bool + rank<T>::is_valid() const + { + return valid_; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::accu::stat + + } // end of namespace mln::accu + +} // end of namespace mln + +#include <mln/accu/stat/rank_bool.hh> + +#endif // ! MLN_ACCU_STAT_RANK_HH Property changes on: trunk/milena/mln/accu/stat/rank.hh ___________________________________________________________________ Added: svn:mergeinfo Index: trunk/milena/mln/accu/stat/rank_high_quant.hh =================================================================== --- trunk/milena/mln/accu/stat/rank_high_quant.hh (revision 0) +++ trunk/milena/mln/accu/stat/rank_high_quant.hh (revision 4152) @@ -0,0 +1,224 @@ +// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project 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_STAT_RANK_HIGH_QUANT_HH +# define MLN_ACCU_STAT_RANK_HIGH_QUANT_HH + +/// \file +/// +/// Define an rank accumulator. + +# include <vector> +# include <mln/accu/internal/base.hh> +# include <mln/core/concept/meta_accumulator.hh> +# include <mln/trait/value_.hh> +# include <mln/util/pix.hh> + + +namespace mln +{ + + namespace accu + { + + namespace stat + { + + + /// \brief Generic rank accumulator class. + /*! + * The parameter \c T is the type of values. + * + * \ingroup modaccuvalues + */ + template <typename T> + struct rank_high_quant : public mln::accu::internal::base< const T&, rank_high_quant<T> > + { + typedef T argument; + + rank_high_quant(unsigned k, unsigned n); + + /// Manipulators. + /// \{ + void init(); + void take_as_init_(const argument& t); + void take(const argument& t); + void take(const rank_high_quant<T>& other); + void sort(); + /// \} + + /// Get the value of the accumulator. + const T& to_result() const; + + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; + + protected: + + std::vector<T> elts_; + bool is_sorted_; + unsigned k_; // 0 <= k_ < n + unsigned n_; + }; + + + template <typename I> struct rank_high_quant< util::pix<I> >; + + + } // end of mln::accu::stat + + + namespace meta + { + + namespace stat + { + + /// Meta accumulator for rank_high_quant. + + struct rank_high_quant : public Meta_Accumulator< rank_high_quant > + { + rank_high_quant(unsigned k_, unsigned n_) : k(k_), n(n_) {} + + template <typename T> + struct with + { + typedef accu::stat::rank_high_quant<T> ret; + }; + + unsigned k; + unsigned n; + }; + + } // end of namespace mln::accu::meta::stat + + } // end of namespace mln::accu::meta + + + template <typename T> + stat::rank_high_quant<T> unmeta(const meta::stat::rank_high_quant& m, T) + { + stat::rank_high_quant<T> a(m.k, m.n); + return a; + } + + + namespace stat + { + +# ifndef MLN_INCLUDE_ONLY + + template <typename T> + inline + rank_high_quant<T>::rank_high_quant(unsigned k, unsigned n) + : k_(k), + n_(n), + is_sorted_(false) + { + mln_assertion(k_ < n_); + init(); + } + + template <typename T> + inline + void + rank_high_quant<T>::init() + { + elts_.clear(); + } + + template <typename T> + inline + void rank_high_quant<T>::take_as_init_(const argument& t) + { + elts_.push_back(t); + is_sorted_ = false; + } + + template <typename T> + inline + void rank_high_quant<T>::take(const argument& t) + { + elts_.push_back(t); + is_sorted_ = false; + } + + template <typename T> + inline + void + rank_high_quant<T>::take(const rank_high_quant<T>& other) + { + elts_.insert(elts_.end(), + other.elts_.begin(), + other.elts_.end()); + is_sorted_ = false; + } + + template <typename T> + inline + const T& + rank_high_quant<T>::to_result() const + { + const_cast<rank_high_quant<T>&>(*this).sort(); + + if (n_ == elts_.size()) + return elts_[k_]; + else + // FIXME : This alternative is used to handle images edges. + return elts_[(elts_.size() * k_) / n_]; + } + + template <typename T> + inline + bool + rank_high_quant<T>::is_valid() const + { + return true; + } + + template <typename T> + inline + void + rank_high_quant<T>::sort() + { + if (! is_sorted_) + { + is_sorted_ = true; + std::sort(elts_.begin(), elts_.end()); + } + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::accu::stat + + } // end of namespace mln::accu + +} // end of namespace mln + +// #include <mln/accu/stat/rank_bool.hh> ?? + +#endif // ! MLN_ACCU_STAT_RANK_HIGH_QUANT_HH Property changes on: trunk/milena/mln/accu/stat/rank_high_quant.hh ___________________________________________________________________ Added: svn:mergeinfo Index: trunk/milena/mln/accu/stat/rank_bool.hh =================================================================== --- trunk/milena/mln/accu/stat/rank_bool.hh (revision 0) +++ trunk/milena/mln/accu/stat/rank_bool.hh (revision 4152) @@ -0,0 +1,171 @@ +// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project 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_STAT_RANK_BOOL_HH +# define MLN_ACCU_STAT_RANK_BOOL_HH + +/// \file +/// +/// Define an rank accumulator. +/// +/// \todo There is no-arg-ctor so this accumulator does not support +/// deferred initialization! +/// +/// \todo Add untake routines... + +# include <mln/accu/internal/base.hh> + + +namespace mln +{ + + namespace accu + { + + namespace stat + { + + // Forward declaration. + template <typename T> struct rank; + + /// \brief rank accumulator class for Boolean. + /// + /// \ingroup modaccuvalues + // + template <> + struct rank<bool> : public mln::accu::internal::base< bool, rank<bool> > + { + typedef bool argument; + + rank(); + rank(unsigned k); + + /// Manipulators. + /// \{ + void init(); + void take_as_init_(const argument& t); + void take(const argument& t); + void take(const rank<bool>& other); + void untake(const argument& t); + void untake(const rank<bool>& other); + /// \} + + /// Get the value of the accumulator. + bool to_result() const; + + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; + + protected: + unsigned nfalse_; + unsigned k_; // 0 <= k_ + }; + + +# ifndef MLN_INCLUDE_ONLY + + inline + rank<bool>::rank() + { + init(); + } + + inline + rank<bool>::rank(unsigned k) + : k_(k) + { + init(); + } + + inline + void + rank<bool>::init() + { + nfalse_ = 0; + } + + inline + void rank<bool>::take_as_init_(const argument& t) + { + nfalse_ = t ? 0 : 1; + } + + inline + void rank<bool>::take(const argument& t) + { + if (t == false) + ++nfalse_; + } + + inline + void rank<bool>::untake(const argument& t) + { + if (t == false) + { + mln_assertion(nfalse_ > 0); + --nfalse_; + } + } + + inline + void + rank<bool>::take(const rank<bool>& other) + { + nfalse_ += other.nfalse_; + } + + inline + void + rank<bool>::untake(const rank<bool>& other) + { + mln_precondition(other.nfalse_ <= nfalse_); + nfalse_ -= other.nfalse_; + } + + inline + bool + rank<bool>::to_result() const + { + return k_ >= nfalse_; + } + + inline + bool + rank<bool>::is_valid() const + { + return true; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::accu::stat + + } // end of namespace mln::accu + +} // end of namespace mln + + +#endif // ! MLN_ACCU_STAT_RANK_BOOL_HH Property changes on: trunk/milena/mln/accu/stat/rank_bool.hh ___________________________________________________________________ Added: svn:mergeinfo Index: trunk/milena/mln/accu/stat/all.hh =================================================================== --- trunk/milena/mln/accu/stat/all.hh (revision 4151) +++ trunk/milena/mln/accu/stat/all.hh (revision 4152) @@ -64,5 +64,9 @@ # include <mln/accu/stat/mean.hh> # include <mln/accu/stat/median_h.hh> # include <mln/accu/stat/median_alt.hh> +# include <mln/accu/stat/rank_bool.hh> +# include <mln/accu/stat/rank_high_quant.hh> +# include <mln/accu/stat/rank.hh> #endif // ! MLN_ACCU_STAT_ALL_HH + Index: trunk/milena/mln/morpho/rank_filter.hh =================================================================== --- trunk/milena/mln/morpho/rank_filter.hh (revision 4151) +++ trunk/milena/mln/morpho/rank_filter.hh (revision 4152) @@ -102,7 +102,7 @@ mln_concrete(I) output; initialize(output, input); - accu::rank<mln_value(I)> accu(k); + accu::stat::rank<mln_value(I)> accu(k); extension::adjust_fill(input, geom::delta(win) + 1, accu); mln_piter(I) p(input.domain()); mln_qiter(W) q(win, p); @@ -133,7 +133,7 @@ internal::rank_filter_tests(input, win, k); - accu::rank<mln_value(I)> accu(k); + accu::stat::rank<mln_value(I)> accu(k); extension::adjust_fill(input, geom::delta(win) + 1, accu); mln_concrete(I) output = accu::transform_line(accu, input, exact(win).length(), dir); @@ -151,7 +151,7 @@ internal::rank_filter_tests(input, win, k); - accu::rank<mln_value(I)> accu(k); + accu::stat::rank<mln_value(I)> accu(k); extension::adjust_fill(input, geom::delta(win) + 1, accu); mln_concrete(I) output = accu::transform_directional(accu, input, win, dir); Index: trunk/milena/mln/morpho/tree/compute_attribute_image.hh =================================================================== --- trunk/milena/mln/morpho/tree/compute_attribute_image.hh (revision 4151) +++ trunk/milena/mln/morpho/tree/compute_attribute_image.hh (revision 4152) @@ -144,7 +144,7 @@ { // Transmit "dynamic data" (state) of 'a' to every values of // 'acc'. It is usually a no-op (so useless) except for a - // few accumulators, e.g., for accu::rank which has the 'k' + // few accumulators, e.g., for accu::stat::rank which has the 'k' // attribute. A a = exact(a_); mln::data::fill(acc, a); Index: trunk/milena/mln/morpho/includes.hh =================================================================== --- trunk/milena/mln/morpho/includes.hh (revision 4151) +++ trunk/milena/mln/morpho/includes.hh (revision 4152) @@ -39,7 +39,7 @@ # include <mln/value/ops.hh> -# include <mln/accu/rank.hh> +# include <mln/accu/stat/rank.hh> # include <mln/accu/transform.hh> # include <mln/accu/transform_stop.hh> Index: trunk/milena/sandbox/theo/tufa_2008/filter_n.cc =================================================================== --- trunk/milena/sandbox/theo/tufa_2008/filter_n.cc (revision 4151) +++ trunk/milena/sandbox/theo/tufa_2008/filter_n.cc (revision 4152) @@ -147,7 +147,7 @@ { // Transmit "dynamic data" (state) of 'a' to every values of // 'acc'. It is usually a no-op (so useless) except for a - // few accumulators, e.g., for accu::rank which has the 'k' + // few accumulators, e.g., for accu::stat::rank which has the 'k' // attribute. data::fill(acc, a); } Index: trunk/milena/tests/accu/rank.cc (deleted) =================================================================== Index: trunk/milena/tests/accu/Makefile.am =================================================================== --- trunk/milena/tests/accu/Makefile.am (revision 4151) +++ trunk/milena/tests/accu/Makefile.am (revision 4152) @@ -34,7 +34,6 @@ max_site \ nil \ pair \ - rank \ transform \ transform_diagonal \ transform_directional \ @@ -49,7 +48,6 @@ max_site_SOURCES = max_site.cc nil_SOURCES = nil.cc pair_SOURCES = pair.cc -rank_SOURCES = rank.cc transform_SOURCES = transform.cc transform_diagonal_SOURCES = transform_diagonal.cc transform_directional_SOURCES = transform_directional.cc Index: trunk/milena/tests/accu/stat/rank.cc =================================================================== --- trunk/milena/tests/accu/stat/rank.cc (revision 0) +++ trunk/milena/tests/accu/stat/rank.cc (revision 4152) @@ -0,0 +1,108 @@ +// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project 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. + +#include <mln/accu/stat/rank.hh> +#include <mln/value/int_u8.hh> + + + +template <typename A> +void fill(mln::Accumulator<A>& accu_) +{ + A& accu = exact(accu_); + accu.take(2); + accu.take(3); + accu.take(1); + accu.take(4); + accu.take(5); + accu.take(5); + accu.take(2); + accu.take(5); +} + + +int main() +{ + using namespace mln; + using value::int_u8; + + { + accu::meta::stat::rank r(4); + accu::stat::rank<int_u8> a = accu::unmeta(r, int_u8()); + mln_assertion(a.k() == 4); +// Meta_Accumulator<accu::meta::stat::rank>& R = r; +// accu::unmeta(R, int_u8()); + } + + { + accu::stat::rank<int_u8> accu(0); + fill(accu); + mln_assertion(accu.to_result() == 1u); + } + { + accu::stat::rank<int_u8> accu(1); + fill(accu); + mln_assertion(accu.to_result() == 2u); + } + { + accu::stat::rank<int_u8> accu(2); + fill(accu); + mln_assertion(accu.to_result() == 2u); + } + { + accu::stat::rank<int_u8> accu(3); + fill(accu); + mln_assertion(accu.to_result() == 3u); + } + { + accu::stat::rank<int_u8> accu(4); + fill(accu); + mln_assertion(accu.to_result() == 4u); + } + { + accu::stat::rank<int_u8> accu(5); + fill(accu); + mln_assertion(accu.to_result() == 5u); + } + { + accu::stat::rank<int_u8> accu(6); + fill(accu); + mln_assertion(accu.to_result() == 5u); + } + { + accu::stat::rank<int_u8> accu(7); + fill(accu); + mln_assertion(accu.to_result() == 5u); + } + { + accu::stat::rank<bool> accu_bool(1); + accu_bool.take(true); + accu_bool.take(true); + accu_bool.take(true); + accu_bool.take(true); + accu_bool.take(false); + mln_assertion(accu_bool == true); + } +} Property changes on: trunk/milena/tests/accu/stat/rank.cc ___________________________________________________________________ Added: svn:mergeinfo Index: trunk/milena/tests/accu/stat/Makefile.am =================================================================== --- trunk/milena/tests/accu/stat/Makefile.am (revision 4151) +++ trunk/milena/tests/accu/stat/Makefile.am (revision 4152) @@ -27,7 +27,8 @@ max \ max_h \ median_h \ - mean + mean \ + rank var_SOURCES = var.cc mean_SOURCES = min.cc @@ -37,5 +38,7 @@ max_SOURCES = max.cc max_h_SOURCES = max_h.cc min_max_SOURCES = min_max.cc +rank_SOURCES = rank.cc TESTS = $(check_PROGRAMS) +