olena-2.0-103-gd61b69f Add functions.

* mln/fun/vv2v/span.hh, * mln/fun/vvvv2v/max.hh, * mln/fun/vvvv2v/min.hh, * mln/fun/vvvv2v/span.hh: New. * mln/math/max.hh, * mln/math/min.hh: New overloads. --- milena/ChangeLog | 12 ++++++++++ milena/mln/fun/vv2v/{mean.hh => span.hh} | 33 ++++++++++++++------------- milena/mln/fun/vvvv2v/{mean.hh => max.hh} | 20 ++++++++-------- milena/mln/fun/vvvv2v/mean.hh | 2 +- milena/mln/fun/vvvv2v/{mean.hh => min.hh} | 20 ++++++++-------- milena/mln/fun/vvvv2v/{mean.hh => span.hh} | 34 ++++++++++++++++----------- milena/mln/math/max.hh | 17 ++++++++++++++ milena/mln/math/min.hh | 17 ++++++++++++++ 8 files changed, 104 insertions(+), 51 deletions(-) copy milena/mln/fun/vv2v/{mean.hh => span.hh} (70%) copy milena/mln/fun/vvvv2v/{mean.hh => max.hh} (79%) copy milena/mln/fun/vvvv2v/{mean.hh => min.hh} (79%) copy milena/mln/fun/vvvv2v/{mean.hh => span.hh} (67%) diff --git a/milena/ChangeLog b/milena/ChangeLog index 04fb5c5..fb22a83 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,15 @@ +2012-10-18 Guillaume Lazzara <z@lrde.epita.fr> + + Add functions. + + * mln/fun/vv2v/span.hh, + * mln/fun/vvvv2v/max.hh, + * mln/fun/vvvv2v/min.hh, + * mln/fun/vvvv2v/span.hh: New. + + * mln/math/max.hh, + * mln/math/min.hh: New overloads. + 2012-10-05 Guillaume Lazzara <z@lrde.epita.fr> Improve accu::median_interval. diff --git a/milena/mln/fun/vv2v/mean.hh b/milena/mln/fun/vv2v/span.hh similarity index 70% copy from milena/mln/fun/vv2v/mean.hh copy to milena/mln/fun/vv2v/span.hh index 510b9a6..e9cd002 100644 --- a/milena/mln/fun/vv2v/mean.hh +++ b/milena/mln/fun/vv2v/span.hh @@ -23,15 +23,15 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef MLN_FUN_VV2V_MEAN_HH -# define MLN_FUN_VV2V_MEAN_HH +#ifndef MLN_FUN_VV2V_SPAN_HH +# define MLN_FUN_VV2V_SPAN_HH /// \file /// -/// Functor that computes the mean of two values. +/// Functor that computes the spanimum of two values. # include <mln/core/concept/function.hh> -# include <mln/math/mean.hh> +# include <mln/value/interval.hh> namespace mln @@ -45,24 +45,25 @@ namespace mln // FIXME: Doc. - /// \brief A functor computing the mean of two values. - template <typename L, typename R = L> - struct mean : public Function_vv2v< mean<L,R> >, - private mlc_converts_to(R,L)::check_t + /// \brief A functor computing the span of two interval values. + template <typename T> + struct span : public Function_vv2v< span<T> > { - typedef R result; - R operator()(const L& v1, const L& v2) const; + typedef value::interval<T> result; + + value::interval<T> operator()(const value::interval<T>& v1, + const value::interval<T>& v2) const; }; # ifndef MLN_INCLUDE_ONLY - template <typename L, typename R> - inline - R - mean<L,R>::operator()(const L& v1, const L& v2) const + template <typename T> + value::interval<T> + span<T>::operator()(const value::interval<T>& v1, + const value::interval<T>& v2) const { - return R(mln::math::mean(v1, v2); + return value::span(v1, v2); } # endif // ! MLN_INCLUDE_ONLY @@ -74,4 +75,4 @@ namespace mln } // end of namespace mln -#endif // ! MLN_FUN_VV2V_MEAN_HH +#endif // ! MLN_FUN_VV2V_SPAN_HH diff --git a/milena/mln/fun/vvvv2v/mean.hh b/milena/mln/fun/vvvv2v/max.hh similarity index 79% copy from milena/mln/fun/vvvv2v/mean.hh copy to milena/mln/fun/vvvv2v/max.hh index 0dba050..311bcfe 100644 --- a/milena/mln/fun/vvvv2v/mean.hh +++ b/milena/mln/fun/vvvv2v/max.hh @@ -23,15 +23,15 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef MLN_FUN_VVVV2V_MEAN_HH -# define MLN_FUN_VVVV2V_MEAN_HH +#ifndef MLN_FUN_VVVV2V_MAX_HH +# define MLN_FUN_VVVV2V_MAX_HH /// \file /// -/// Functor that computes the mean of two values. +/// Functor that computes the max of two values. # include <mln/core/concept/function.hh> -# include <mln/math/mean.hh> +# include <mln/math/max.hh> namespace mln @@ -45,9 +45,9 @@ namespace mln // FIXME: Doc. - /// \brief A functor computing the mean of two values. + /// \brief A functor computing the max of two values. template <typename T, typename R=T> - struct mean : public Function_vvvv2v< mean<T> > + struct max : public Function_vvvv2v< max<T> > { typedef R result; R operator()(const T& v1, const T& v2, const T& v3, const T& v4) const; @@ -56,12 +56,12 @@ namespace mln # ifndef MLN_INCLUDE_ONLY - template <typename T> + template <typename T, typename R> inline R - mean<T,R>::operator()(const T& v1, const T& v2, const T& v3, const T& v4) const + max<T,R>::operator()(const T& v1, const T& v2, const T& v3, const T& v4) const { - return R(mln::math::mean(v1, v2, v3, v4)); + return R(mln::math::max(v1, v2, v3, v4)); } # endif // ! MLN_INCLUDE_ONLY @@ -73,4 +73,4 @@ namespace mln } // end of namespace mln -#endif // ! MLN_FUN_VVVV2V_MEAN_HH +#endif // ! MLN_FUN_VVVV2V_MAX_HH diff --git a/milena/mln/fun/vvvv2v/mean.hh b/milena/mln/fun/vvvv2v/mean.hh index 0dba050..d9810ab 100644 --- a/milena/mln/fun/vvvv2v/mean.hh +++ b/milena/mln/fun/vvvv2v/mean.hh @@ -56,7 +56,7 @@ namespace mln # ifndef MLN_INCLUDE_ONLY - template <typename T> + template <typename T, typename R> inline R mean<T,R>::operator()(const T& v1, const T& v2, const T& v3, const T& v4) const diff --git a/milena/mln/fun/vvvv2v/mean.hh b/milena/mln/fun/vvvv2v/min.hh similarity index 79% copy from milena/mln/fun/vvvv2v/mean.hh copy to milena/mln/fun/vvvv2v/min.hh index 0dba050..f0c4b63 100644 --- a/milena/mln/fun/vvvv2v/mean.hh +++ b/milena/mln/fun/vvvv2v/min.hh @@ -23,15 +23,15 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef MLN_FUN_VVVV2V_MEAN_HH -# define MLN_FUN_VVVV2V_MEAN_HH +#ifndef MLN_FUN_VVVV2V_MIN_HH +# define MLN_FUN_VVVV2V_MIN_HH /// \file /// -/// Functor that computes the mean of two values. +/// Functor that computes the min of two values. # include <mln/core/concept/function.hh> -# include <mln/math/mean.hh> +# include <mln/math/min.hh> namespace mln @@ -45,9 +45,9 @@ namespace mln // FIXME: Doc. - /// \brief A functor computing the mean of two values. + /// \brief A functor computing the min of two values. template <typename T, typename R=T> - struct mean : public Function_vvvv2v< mean<T> > + struct min : public Function_vvvv2v< min<T> > { typedef R result; R operator()(const T& v1, const T& v2, const T& v3, const T& v4) const; @@ -56,12 +56,12 @@ namespace mln # ifndef MLN_INCLUDE_ONLY - template <typename T> + template <typename T, typename R> inline R - mean<T,R>::operator()(const T& v1, const T& v2, const T& v3, const T& v4) const + min<T,R>::operator()(const T& v1, const T& v2, const T& v3, const T& v4) const { - return R(mln::math::mean(v1, v2, v3, v4)); + return R(mln::math::min(v1, v2, v3, v4)); } # endif // ! MLN_INCLUDE_ONLY @@ -73,4 +73,4 @@ namespace mln } // end of namespace mln -#endif // ! MLN_FUN_VVVV2V_MEAN_HH +#endif // ! MLN_FUN_VVVV2V_MIN_HH diff --git a/milena/mln/fun/vvvv2v/mean.hh b/milena/mln/fun/vvvv2v/span.hh similarity index 67% copy from milena/mln/fun/vvvv2v/mean.hh copy to milena/mln/fun/vvvv2v/span.hh index 0dba050..8c99bd1 100644 --- a/milena/mln/fun/vvvv2v/mean.hh +++ b/milena/mln/fun/vvvv2v/span.hh @@ -23,15 +23,15 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef MLN_FUN_VVVV2V_MEAN_HH -# define MLN_FUN_VVVV2V_MEAN_HH +#ifndef MLN_FUN_VVVV2V_SPAN_HH +# define MLN_FUN_VVVV2V_SPAN_HH /// \file /// -/// Functor that computes the mean of two values. +/// Functor that computes the spanimum of two values. # include <mln/core/concept/function.hh> -# include <mln/math/mean.hh> +# include <mln/value/interval.hh> namespace mln @@ -45,23 +45,29 @@ namespace mln // FIXME: Doc. - /// \brief A functor computing the mean of two values. - template <typename T, typename R=T> - struct mean : public Function_vvvv2v< mean<T> > + /// \brief A functor computing the span of two interval values. + template <typename T> + struct span : public Function_vvvv2v< span<T> > { - typedef R result; - R operator()(const T& v1, const T& v2, const T& v3, const T& v4) const; + typedef value::interval<T> result; + + value::interval<T> operator()(const value::interval<T>& v1, + const value::interval<T>& v2, + const value::interval<T>& v3, + const value::interval<T>& v4) const; }; # ifndef MLN_INCLUDE_ONLY template <typename T> - inline - R - mean<T,R>::operator()(const T& v1, const T& v2, const T& v3, const T& v4) const + value::interval<T> + span<T>::operator()(const value::interval<T>& v1, + const value::interval<T>& v2, + const value::interval<T>& v3, + const value::interval<T>& v4) const { - return R(mln::math::mean(v1, v2, v3, v4)); + return value::span(v1, v2, v3, v4); } # endif // ! MLN_INCLUDE_ONLY @@ -73,4 +79,4 @@ namespace mln } // end of namespace mln -#endif // ! MLN_FUN_VVVV2V_MEAN_HH +#endif // ! MLN_FUN_VVVV2V_SPAN_HH diff --git a/milena/mln/math/max.hh b/milena/mln/math/max.hh index 0fe8ea4..786aa2e 100644 --- a/milena/mln/math/max.hh +++ b/milena/mln/math/max.hh @@ -43,6 +43,9 @@ namespace mln template <typename T> T max(const T& v1, const T& v2); + /// Return the maximum of four values. + template <typename T> + T max(const T& v1, const T& v2, const T& v3, const T& v4); } // end of namespace mln::math @@ -55,6 +58,14 @@ namespace mln return v1 > v2 ? v1 : v2; } + /// \internal Generic implementation of the maximum function. + template <typename T> + T max_(const T& v1, const T& v2, const T& v3, const T& v4) + { + return max_(max_(exact(v1), exact(v2)), max_(exact(v3), exact(v4))); + } + + namespace math { @@ -64,6 +75,12 @@ namespace mln return max_(exact(v1), exact(v2)); } + template <typename T> + T max(const T& v1, const T& v2, const T& v3, const T& v4) + { + return max_(exact(v1), exact(v2), exact(v3), exact(v4)); + } + } // end of namespace mln::math # endif // ! MLN_INCLUDE_ONLY diff --git a/milena/mln/math/min.hh b/milena/mln/math/min.hh index d2a5503..706c103 100644 --- a/milena/mln/math/min.hh +++ b/milena/mln/math/min.hh @@ -43,6 +43,9 @@ namespace mln template <typename T> T min(const T& v1, const T& v2); + /// Return the minimum of four values. + template <typename T> + T min(const T& v1, const T& v2, const T& v3, const T& v4); } // end of namespace mln::math @@ -55,6 +58,14 @@ namespace mln return v1 < v2 ? v1 : v2; } + /// \internal Generic implementation of the minimum function. + template <typename T> + T min_(const T& v1, const T& v2, const T& v3, const T& v4) + { + return min_(min_(v1, v2), min_(v3, v4)); + } + + namespace math { @@ -64,6 +75,12 @@ namespace mln return min_(exact(v1), exact(v2)); } + template <typename T> + T min(const T& v1, const T& v2, const T& v3, const T& v4) + { + return min_(exact(v1), exact(v2), exact(v3), exact(v4)); + } + } // end of namespace mln::math # endif // ! MLN_INCLUDE_ONLY -- 1.7.2.5
participants (1)
-
Guillaume Lazzara