* mln/inner_border/extend.hh,
* mln/inner_border/extend_and_fill.hh,
* mln/inner_border/extend_and_fill_with_inner_border.hh,
* mln/inner_border/fill.hh,
* mln/inner_border/internal/on_frontiere.hh: New.
---
milena/ChangeLog | 10 ++
.../mln/{make/pixel.hh => inner_border/extend.hh} | 55 ++++++----
.../extend_and_fill.hh} | 68 ++++++------
.../extend_and_fill_with_inner_border.hh | 99 +++++++++++++++++
milena/mln/{debug/iota.hh => inner_border/fill.hh} | 86 ++++++---------
milena/mln/inner_border/internal/on_frontiere.hh | 113 ++++++++++++++++++++
6 files changed, 323 insertions(+), 108 deletions(-)
copy milena/mln/{make/pixel.hh => inner_border/extend.hh} (55%)
copy milena/mln/{subsampling/gaussian_subsampling.hh => inner_border/extend_and_fill.hh} (52%)
create mode 100644 milena/mln/inner_border/extend_and_fill_with_inner_border.hh
copy milena/mln/{debug/iota.hh => inner_border/fill.hh} (56%)
create mode 100644 milena/mln/inner_border/internal/on_frontiere.hh
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 2413cb2..1bfdd14 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,13 @@
+2012-10-24 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Add inner_border routines.
+
+ * mln/inner_border/extend.hh,
+ * mln/inner_border/extend_and_fill.hh,
+ * mln/inner_border/extend_and_fill_with_inner_border.hh,
+ * mln/inner_border/fill.hh,
+ * mln/inner_border/internal/on_frontiere.hh: New.
+
2012-10-23 Guillaume Lazzara <z(a)lrde.epita.fr>
Add data::compute_in_inner_border.
diff --git a/milena/mln/make/pixel.hh b/milena/mln/inner_border/extend.hh
similarity index 55%
copy from milena/mln/make/pixel.hh
copy to milena/mln/inner_border/extend.hh
index 9f9f776..d5172a2 100644
--- a/milena/mln/make/pixel.hh
+++ b/milena/mln/inner_border/extend.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,54 +23,65 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_MAKE_PIXEL_HH
-# define MLN_MAKE_PIXEL_HH
+#ifndef MLN_INNER_BORDER_EXTEND_HH
+# define MLN_INNER_BORDER_EXTEND_HH
/// \file
-/// \brief Routine to construct an mln::pixel.
+///
+/// \brief Extend the inner border of an image.
-# include <mln/core/concept/image.hh>
-# include <mln/core/pixel.hh>
+# include <mln/core/image/image2d.hh>
+# include <mln/data/paste.hh>
namespace mln
{
- namespace make
+ namespace inner_border
{
- /// Create a mln::pixel from a constant image \p ima and a point \p p.
+ /// \brief Extend the inner border of an image.
template <typename I>
- mln::pixel<const I> pixel(const Image<I>& ima, const mln_psite(I)& p);
+ mln_concrete(I)
+ extend(const Image<I>& input, unsigned inner_border_size);
- /// Create a mln::pixel from a mutable image \p ima and a point \p p.
+ /// \overload
+ /// inner_border_size is set to 1.
template <typename I>
- mln::pixel<I> pixel(Image<I>& ima, const mln_psite(I)& p);
+ mln_concrete(I)
+ extend(const Image<I>& input);
# ifndef MLN_INCLUDE_ONLY
template <typename I>
- inline
- mln::pixel<const I> pixel(const Image<I>& ima, const mln_psite(I)& p)
+ mln_concrete(I)
+ extend(const Image<I>& input_, unsigned inner_border_size)
{
- mln::pixel<const I> tmp(exact(ima), p);
- return tmp;
+ trace::entering("mln::inner_border::extend");
+ mln_precondition(exact(input).is_valid());
+ const I& input = exact(input_);
+
+ box2d b = input.domain(), bb = b;
+ bb.enlarge(inner_border_size);
+ mln_concrete(I) output(bb);
+ data::paste(input, output);
+
+ trace::exiting("mln::inner_border::extend");
+ return output;
}
template <typename I>
- inline
- mln::pixel<I> pixel(Image<I>& ima, const mln_psite(I)& p)
+ mln_concrete(I)
+ extend(const Image<I>& input)
{
- mln::pixel<I> tmp(exact(ima), p);
- return tmp;
+ return extend(input, 1);
}
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace mln::make
+ } // end of namespace mln::inner_border
} // end of namespace mln
-
-#endif // ! MLN_MAKE_PIXEL_HH
+#endif // ! MLN_INNER_BORDER_EXTEND_HH
diff --git a/milena/mln/subsampling/gaussian_subsampling.hh b/milena/mln/inner_border/extend_and_fill.hh
similarity index 52%
copy from milena/mln/subsampling/gaussian_subsampling.hh
copy to milena/mln/inner_border/extend_and_fill.hh
index 8855b9c..b2804fc 100644
--- a/milena/mln/subsampling/gaussian_subsampling.hh
+++ b/milena/mln/inner_border/extend_and_fill.hh
@@ -1,5 +1,4 @@
-// Copyright (C) 2008, 2009, 2011 EPITA Research and Development
-// Laboratory (LRDE)
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -24,67 +23,64 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_SUBSAMPLING_GAUSSIAN_SUBSAMPLING_HH
-# define MLN_SUBSAMPLING_GAUSSIAN_SUBSAMPLING_HH
+#ifndef MLN_INNER_BORDER_EXTEND_AND_FILL_HH
+# define MLN_INNER_BORDER_EXTEND_AND_FILL_HH
/// \file
///
-/// Produce a subsampled image
-
-# include <mln/geom/ncols.hh>
-# include <mln/geom/nrows.hh>
-
-
-# include <mln/linear/gaussian.hh>
-# include <mln/subsampling/subsampling.hh>
+/// \brief Extend the inner border of an image.
+# include <mln/inner_border/extend.hh>
+# include <mln/inner_border/fill.hh>
namespace mln
{
- namespace subsampling
+ namespace inner_border
{
- /// Gaussian subsampling FIXME : doxy
+ /// \brief Extend the inner border of an image and fill it with a
+ /// value.
template <typename I>
- inline
mln_concrete(I)
- gaussian_subsampling(const Image<I>& input, float sigma,
- const mln_dpsite(I)& first_p,
- const mln_deduce(I, site, coord)& gap);
+ extend_and_fill(const Image<I>& input, unsigned inner_border_size,
+ const mln_value(I)& value);
-# ifndef MLN_INCLUDE_ONLY
+ /// \overload
+ /// inner_border_size is set to 1.
+ template <typename I>
+ mln_concrete(I)
+ extend_and_fill(const Image<I>& input, const mln_value(I)& value);
+# ifndef MLN_INCLUDE_ONLY
template <typename I>
- inline
mln_concrete(I)
- gaussian_subsampling(const Image<I>& input, float sigma,
- const mln_dpsite(I)& first_p,
- const mln_deduce(I, site, coord)& gap)
+ extend_and_fill(const Image<I>& input, unsigned inner_border_size,
+ const mln_value(I)& value)
{
- trace::entering("subsampling::gaussian_subsampling");
+ trace::entering("mln::inner_border::extend_and_fill");
mln_precondition(exact(input).is_valid());
- (void) sigma;
-
- mln_concrete(I) temp(exact(input).domain());
- mln_concrete(I) output(geom::nrows(input) / gap,
- geom::ncols(input) / gap); //FIXME : image2d only
+ mln_concrete(I) output = inner_border::extend(input, inner_border_size);
+ inner_border::fill(output, inner_border_size, value);
- linear::gaussian(input, 0.1, temp);
- output = impl::subsampling_(exact(temp), first_p, gap);
-
- trace::exiting("subsampling::gaussian_subsampling");
+ trace::exiting("mln::inner_border::extend_and_fill");
return output;
}
+ template <typename I>
+ mln_concrete(I)
+ extend_and_fill(const Image<I>& input, const mln_value(I)& value)
+ {
+ return extend_and_fill(input, 1, value);
+ }
+
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace mln::subsampling
+ } // end of namespace mln::inner_border
} // end of namespace mln
-
-#endif // ! MLN_SUBSAMPLING_GAUSSIAN_SUBSAMPLING_HH
+#endif // ! MLN_INNER_BORDER_EXTEND_AND_FILL_HH
diff --git a/milena/mln/inner_border/extend_and_fill_with_inner_border.hh b/milena/mln/inner_border/extend_and_fill_with_inner_border.hh
new file mode 100644
index 0000000..8c4db27
--- /dev/null
+++ b/milena/mln/inner_border/extend_and_fill_with_inner_border.hh
@@ -0,0 +1,99 @@
+// Copyright (C) 2012 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_INNER_BORDER_EXTEND_AND_FILL_WITH_INNER_BORDER_HH
+# define MLN_INNER_BORDER_EXTEND_AND_FILL_WITH_INNER_BORDER_HH
+
+/// \file
+///
+/// \brief Extend the inner border of an image.
+
+# include <mln/data/compute_in_inner_border.hh>
+# include <mln/inner_border/extend.hh>
+# include <mln/inner_border/fill.hh>
+
+
+namespace mln
+{
+
+ namespace inner_border
+ {
+
+ /// \brief Extend the inner border of an image and fill it with a
+ /// value.
+ template <typename I, typename A>
+ mln_concrete(I)
+ extend_and_fill_with_inner_border(const Image<I>& input,
+ unsigned old_inner_border_size,
+ const Accumulator<A>& accu,
+ unsigned inner_border_size_for_accu);
+
+ /// \overload
+ /// old_inner_border_size and inner_border_size_for_accu are set to 1.
+ template <typename I, typename A>
+ mln_concrete(I)
+ extend_and_fill_with_inner_border(const Image<I>& input,
+ const Accumulator<A>& accu);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename A>
+ mln_concrete(I)
+ extend_and_fill_with_inner_border(const Image<I>& input,
+ unsigned inner_border_size,
+ const Accumulator<A>& accu,
+ unsigned inner_border_size_for_accu)
+ {
+ trace::entering("mln::inner_border::extend_and_fill_with_inner_border");
+// mlc_converts_to(mln_result(A),mln_value(I))::check();
+ mln_precondition(exact(input).is_valid());
+
+ mln_result(A)
+ v = data::compute_in_inner_border(accu,
+ input, inner_border_size_for_accu);
+ mln_concrete(I) output = inner_border::extend(input, inner_border_size);
+ inner_border::fill(output, inner_border_size, static_cast<mln_value(I)>(v));
+
+ trace::exiting("mln::inner_border::extend_and_fill_with_inner_border");
+ return output;
+ }
+
+
+ template <typename I, typename A>
+ mln_concrete(I)
+ extend_and_fill_with_inner_border(const Image<I>& input,
+ const Accumulator<A>& accu)
+ {
+ return extend_and_fill_with_inner_border(input, 1, accu, 1);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::inner_border
+
+} // end of namespace mln
+
+#endif // ! MLN_INNER_BORDER_EXTEND_AND_FILL_WITH_INNER_BORDER_HH
diff --git a/milena/mln/debug/iota.hh b/milena/mln/inner_border/fill.hh
similarity index 56%
copy from milena/mln/debug/iota.hh
copy to milena/mln/inner_border/fill.hh
index 3e569b9..ccee289 100644
--- a/milena/mln/debug/iota.hh
+++ b/milena/mln/inner_border/fill.hh
@@ -1,5 +1,4 @@
-// Copyright (C) 2007, 2008, 2009, 2011 EPITA Research and Development
-// Laboratory (LRDE)
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -24,81 +23,68 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_DEBUG_IOTA_HH
-# define MLN_DEBUG_IOTA_HH
+#ifndef MLN_INNER_BORDER_FILL_HH
+# define MLN_INNER_BORDER_FILL_HH
-/*! \file
- *
- * \brief Fill an image with successive values.
- */
-
-# include <mln/core/concept/image.hh>
-
-// Specializations are in:
-# include <mln/debug/iota.spe.hh>
+/// \file
+///
+/// \brief Fill the inner border of an image.
+# include <mln/core/image/image2d.hh>
+# include <mln/data/paste.hh>
+# include <mln/inner_border/internal/on_frontiere.hh>
namespace mln
{
- namespace debug
+ namespace inner_border
{
- /*! Fill the image \p input with successive values.
- *
- * \param[in,out] input The image in which values are
- * assigned.
- */
+ /// \brief Fill the inner border of an image.
template <typename I>
- void iota(Image<I>& input, unsigned base_index);
-
-
-# ifndef MLN_INCLUDE_ONLY
-
- namespace impl
- {
+ void
+ fill(Image<I>& input, unsigned border_size,
+ const mln_value(I)& value);
- template <typename I>
- inline
- void
- iota(trait::image::speed::any, I& input, unsigned base_index)
- {
- unsigned i = base_index;
- mln_piter(I) p(input.domain());
- for_all(p)
- input(p) = ++i % mln_max(mln_value(I));
- }
+ /// \overload
+ /// The border_size is set to 1.
+ template <typename I>
+ void
+ fill(Image<I>& input, const mln_value(I)& value);
- } // end of namespace mln::debug::impl
+# ifndef MLN_INCLUDE_ONLY
template <typename I>
- inline
void
- iota(Image<I>& input)
+ fill(Image<I>& input_, unsigned border_size,
+ const mln_value(I)& value)
{
- iota(input, 0);
- }
+ trace::entering("mln::inner_border::fill");
+ mln_precondition(exact(input).is_valid());
+ I& input = exact(input_);
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ if (internal::on_frontiere(p, input.domain(), border_size))
+ input(p) = value;
+
+ trace::exiting("mln::inner_border::fill");
+ }
template <typename I>
- inline
void
- iota(Image<I>& input, unsigned base_index)
+ fill(Image<I>& input, const mln_value(I)& value)
{
- trace::entering("debug::iota");
- mln_precondition(exact(input).is_valid());
- impl::iota(mln_trait_image_speed(I)(), exact(input), base_index);
- trace::exiting("debug::iota");
+ fill(input, 1, value);
}
-
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace mln::debug
+ } // end of namespace mln::inner_border
} // end of namespace mln
+#endif // ! MLN_INNER_BORDER_FILL_HH
-#endif // ! MLN_DEBUG_IOTA_HH
diff --git a/milena/mln/inner_border/internal/on_frontiere.hh b/milena/mln/inner_border/internal/on_frontiere.hh
new file mode 100644
index 0000000..49430a8
--- /dev/null
+++ b/milena/mln/inner_border/internal/on_frontiere.hh
@@ -0,0 +1,113 @@
+// Copyright (C) 2012 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_INNER_BORDER_ON_FRONTIERE_HH
+# define MLN_INNER_BORDER_ON_FRONTIERE_HH
+
+/// \file
+///
+/// \brief Returns true if a site is included in the inner border of
+/// the image.
+
+# include <mln/core/image/image2d.hh>
+# include <mln/data/paste.hh>
+
+
+namespace mln
+{
+
+ namespace inner_border
+ {
+
+ namespace internal
+ {
+
+ /// \brief Returns true if a site is included in the inner
+ /// border of the image.
+ template <typename P>
+ bool
+ on_frontiere(const mln_site(box<P>)& p, const box<P>& b,
+ def::coord inner_border_size);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // Implementation
+
+ inline
+ bool
+ on_frontiere_2d(const point2d& p, const box2d& b,
+ def::coord inner_border_size)
+ {
+ for (int d = 0; d < 2; ++d)
+ if ((p[d] >= b.pmin()[d]
+ && p[d] < (b.pmin()[d] + inner_border_size))
+ ||
+ (p[d] <= b.pmax()[d]
+ && p[d] > b.pmax()[d] - inner_border_size))
+ return true;
+ return false;
+ }
+
+ // Dispatch
+
+ inline
+ bool
+ on_frontiere_dispatch(const point2d& p, const box2d& b,
+ def::coord inner_border_size)
+ {
+ return on_frontiere_2d(p, b, inner_border_size);
+ }
+
+ template <typename P>
+ bool
+ on_frontiere_dispatch(const mln_site(box<P>)& p, const box<P>& b,
+ def::coord inner_border_size)
+ {
+ mlc_abort(P)::check(); // Not implemented.
+ return false;
+ }
+
+
+ // Facade
+
+ template <typename P>
+ bool
+ on_frontiere(const mln_site(box<P>)& p, const box<P>& b,
+ def::coord inner_border_size)
+ {
+ return on_frontiere_dispatch(p, b, inner_border_size);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::inner_border::internal
+
+ } // end of namespace mln::inner_border
+
+} // end of namespace mln
+
+#endif // ! MLN_INNER_BORDER_ON_FRONTIERE_HH
+
--
1.7.2.5
#257: Overhaul and supplement Milena's hierarchy of namespaces and directories
----------------------+-----------------------------------------------------
Reporter: levill_r | Owner: Olena Team
Type: proposal | Status: new
Priority: major | Milestone:
Component: Milena | Version: 2.0
Keywords: indexing |
----------------------+-----------------------------------------------------
Following a discussion started by Jonathan on the organization of Milena's
contents (resp. files) in a tree of namespaces (resp. directories), I
suggest we try to rethink and improve this classification.
But more importantly, we should think about the concepts behind Milena
that can may come in handy for users of the library. We shall then reify
these concepts as keywords or tags, and use them to annotate the
documentation (e.g., produce one index or more, possibly organized in one
or several hierarchies), in order to provide users with an efficient tool
to search the library.
--
Ticket URL: <https://trac.lrde.epita.fr/olena/ticket/257>
Olena <http://olena.lrde.epita.fr>
Olena, a software platform dedicated to image processing.
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Olena, a generic and efficient image processing platform".
The branch exp/khalimsky has been updated
via fd94360102b88b25a7f6bbed8046fc329871c6b3 (commit)
from e4e04ba3c3fb549d9ad8778ac897c823e29b38d3 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
fd94360 Add data::compute_in_inner_border.
-----------------------------------------------------------------------
Summary of changes:
milena/ChangeLog | 9 +
milena/mln/data/compute_in_inner_border.hh | 184 ++++++++++++++++++++
milena/tests/data/Makefile.am | 2 +
.../compute_in_inner_border.cc} | 28 ++--
4 files changed, 211 insertions(+), 12 deletions(-)
create mode 100644 milena/mln/data/compute_in_inner_border.hh
copy milena/tests/{core/image/vmorph/fun_image.cc => data/compute_in_inner_border.cc} (75%)
hooks/post-receive
--
Olena, a generic and efficient image processing platform
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Olena, a generic and efficient image processing platform".
The branch exp/khalimsky has been updated
via dab9373645b13d4b42381d31ff11cbf8538f1810 (commit)
from c10b09b7b512f4ee639d353b79e23bbfacb05f98 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
dab9373 Improve support for mean and median functions.
-----------------------------------------------------------------------
Summary of changes:
milena/ChangeLog | 24 +++++
milena/mln/fun/vv2v/mean.hh | 3 +-
milena/mln/fun/vv2v/median.hh | 77 ++++++++++++++++
milena/mln/fun/vvvv2v/mean.hh | 3 +-
milena/mln/fun/vvvv2v/median.hh | 78 ++++++++++++++++
milena/mln/math/mean.hh | 24 +++---
milena/mln/math/median.hh | 172 ++++++++++++++++++++++++++++++++++++
milena/mln/trait/routine/mean.hh | 16 +++-
milena/mln/trait/routine/median.hh | 79 ++++++++++++++++
milena/mln/value/intsub.hh | 66 +++++---------
milena/tests/fun/vv2v/Makefile.am | 7 ++-
milena/tests/fun/vv2v/mean.cc | 71 +++++++++++++++
milena/tests/fun/vv2v/median.cc | 71 +++++++++++++++
milena/tests/math/Makefile.am | 13 +++-
milena/tests/math/mean.cc | 47 ++++++++++
milena/tests/math/median.cc | 90 +++++++++++++++++++
16 files changed, 779 insertions(+), 62 deletions(-)
create mode 100644 milena/mln/fun/vv2v/median.hh
create mode 100644 milena/mln/fun/vvvv2v/median.hh
create mode 100644 milena/mln/math/median.hh
create mode 100644 milena/mln/trait/routine/median.hh
create mode 100644 milena/tests/fun/vv2v/mean.cc
create mode 100644 milena/tests/fun/vv2v/median.cc
create mode 100644 milena/tests/math/mean.cc
create mode 100644 milena/tests/math/median.cc
hooks/post-receive
--
Olena, a generic and efficient image processing platform
* mln/fun/vv2v/median.hh,
* mln/fun/vvvv2v/median.hh,
* mln/math/median.hh,
* mln/trait/routine/median.hh,
* tests/fun/vv2v/mean.cc,
* tests/fun/vv2v/median.cc,
* tests/math/mean.cc,
* tests/math/median.cc: New.
* mln/fun/vv2v/mean.hh,
* mln/fun/vvvv2v/mean.hh,
* mln/math/mean.hh,
* mln/value/intsub.hh: Use a dedicated trait to deduce the return
type of mean() function.
* mln/trait/routine/mean.hh: Add more specializations.
* tests/fun/vv2v/Makefile.am,
* tests/math/Makefile.am: Update targets.
---
milena/ChangeLog | 24 +++++
milena/mln/fun/vv2v/mean.hh | 3 +-
milena/mln/fun/vv2v/median.hh | 77 ++++++++++++++++
milena/mln/fun/vvvv2v/mean.hh | 3 +-
milena/mln/fun/vvvv2v/median.hh | 78 ++++++++++++++++
milena/mln/math/mean.hh | 24 +++---
milena/mln/math/median.hh | 172 ++++++++++++++++++++++++++++++++++++
milena/mln/trait/routine/mean.hh | 16 +++-
milena/mln/trait/routine/median.hh | 79 ++++++++++++++++
milena/mln/value/intsub.hh | 66 +++++---------
milena/tests/fun/vv2v/Makefile.am | 7 ++-
milena/tests/fun/vv2v/mean.cc | 71 +++++++++++++++
milena/tests/fun/vv2v/median.cc | 71 +++++++++++++++
milena/tests/math/Makefile.am | 13 +++-
milena/tests/math/mean.cc | 47 ++++++++++
milena/tests/math/median.cc | 90 +++++++++++++++++++
16 files changed, 779 insertions(+), 62 deletions(-)
create mode 100644 milena/mln/fun/vv2v/median.hh
create mode 100644 milena/mln/fun/vvvv2v/median.hh
create mode 100644 milena/mln/math/median.hh
create mode 100644 milena/mln/trait/routine/median.hh
create mode 100644 milena/tests/fun/vv2v/mean.cc
create mode 100644 milena/tests/fun/vv2v/median.cc
create mode 100644 milena/tests/math/mean.cc
create mode 100644 milena/tests/math/median.cc
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 704143a..a02e163 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,29 @@
2012-10-23 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Improve support for mean and median functions.
+
+ * mln/fun/vv2v/median.hh,
+ * mln/fun/vvvv2v/median.hh,
+ * mln/math/median.hh,
+ * mln/trait/routine/median.hh,
+ * tests/fun/vv2v/mean.cc,
+ * tests/fun/vv2v/median.cc,
+ * tests/math/mean.cc,
+ * tests/math/median.cc: New.
+
+ * mln/fun/vv2v/mean.hh,
+ * mln/fun/vvvv2v/mean.hh,
+ * mln/math/mean.hh,
+ * mln/value/intsub.hh: Use a dedicated trait to deduce the return
+ type of mean() function.
+
+ * mln/trait/routine/mean.hh: Add more specializations.
+
+ * tests/fun/vv2v/Makefile.am,
+ * tests/math/Makefile.am: Update targets.
+
+2012-10-23 Guillaume Lazzara <z(a)lrde.epita.fr>
+
* mln/accu/stat/median_h_interval.hh: Make it inherit from
accumulator base.
diff --git a/milena/mln/fun/vv2v/mean.hh b/milena/mln/fun/vv2v/mean.hh
index 65e9f63..809d394 100644
--- a/milena/mln/fun/vv2v/mean.hh
+++ b/milena/mln/fun/vv2v/mean.hh
@@ -31,6 +31,7 @@
/// Functor that computes the mean of two values.
# include <mln/core/concept/function.hh>
+# include <mln/trait/routine/mean.hh>
# include <mln/math/mean.hh>
@@ -44,7 +45,7 @@ namespace mln
{
/// \brief A functor computing the mean of two values.
- template <typename V, typename R = V>
+ template <typename V, typename R = mln_trait_routine_mean(2,V) >
struct mean : public Function_vv2v< mean<V,R> >,
private mlc_converts_to(R,V)::check_t
{
diff --git a/milena/mln/fun/vv2v/median.hh b/milena/mln/fun/vv2v/median.hh
new file mode 100644
index 0000000..a5a451a
--- /dev/null
+++ b/milena/mln/fun/vv2v/median.hh
@@ -0,0 +1,77 @@
+// Copyright (C) 2012 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_FUN_VV2V_MEDIAN_HH
+# define MLN_FUN_VV2V_MEDIAN_HH
+
+/// \file
+///
+/// Functor that computes the median of two values.
+
+# include <mln/core/concept/function.hh>
+# include <mln/trait/routine/median.hh>
+# include <mln/math/median.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace vv2v
+ {
+
+ /// \brief A functor computing the median of two values.
+ template <typename V, typename R = mln_trait_routine_median(V) >
+ struct median : public Function_vv2v< median<V,R> >,
+ private mlc_converts_to(R,V)::check_t
+ {
+ typedef R result;
+ typedef V argument;
+ R operator()(const V& v1, const V& v2) const;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V, typename R>
+ inline
+ R
+ median<V,R>::operator()(const V& v1, const V& v2) const
+ {
+ return R(mln::math::mean(v1, v2));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun::vv2v
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_VV2V_MEDIAN_HH
diff --git a/milena/mln/fun/vvvv2v/mean.hh b/milena/mln/fun/vvvv2v/mean.hh
index d9810ab..7cc14e9 100644
--- a/milena/mln/fun/vvvv2v/mean.hh
+++ b/milena/mln/fun/vvvv2v/mean.hh
@@ -31,6 +31,7 @@
/// Functor that computes the mean of two values.
# include <mln/core/concept/function.hh>
+# include <mln/trait/routine/mean.hh>
# include <mln/math/mean.hh>
@@ -46,7 +47,7 @@ namespace mln
// FIXME: Doc.
/// \brief A functor computing the mean of two values.
- template <typename T, typename R=T>
+ template <typename T, typename R = mln_trait_routine_mean(4,T) >
struct mean : public Function_vvvv2v< mean<T> >
{
typedef R result;
diff --git a/milena/mln/fun/vvvv2v/median.hh b/milena/mln/fun/vvvv2v/median.hh
new file mode 100644
index 0000000..e08dabd
--- /dev/null
+++ b/milena/mln/fun/vvvv2v/median.hh
@@ -0,0 +1,78 @@
+// Copyright (C) 2012 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_FUN_VVVV2V_MEDIAN_HH
+# define MLN_FUN_VVVV2V_MEDIAN_HH
+
+/// \file
+///
+/// Functor that computes the median of two values.
+
+# include <mln/core/concept/function.hh>
+# include <mln/trait/routine/median.hh>
+# include <mln/math/median.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace vvvv2v
+ {
+
+ // FIXME: Doc.
+
+ /// \brief A functor computing the median of two values.
+ template <typename T, typename R = mln_trait_routine_median(T) >
+ struct median : public Function_vvvv2v< median<T> >
+ {
+ typedef T argument;
+ typedef R result;
+ R operator()(const T& v1, const T& v2, const T& v3, const T& v4) const;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, typename R>
+ inline
+ R
+ median<T,R>::operator()(const T& v1, const T& v2, const T& v3, const T& v4) const
+ {
+ return R(mln::math::median(v1, v2, v3, v4));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun::vvvv2v
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_VVVV2V_MEDIAN_HH
diff --git a/milena/mln/math/mean.hh b/milena/mln/math/mean.hh
index d9c95fc..86a5efc 100644
--- a/milena/mln/math/mean.hh
+++ b/milena/mln/math/mean.hh
@@ -26,7 +26,7 @@
#ifndef MLN_MATH_MEAN_HH
# define MLN_MATH_MEAN_HH
-# include <mln/trait/op/div.hh>
+# include <mln/trait/routine/mean.hh>
# include <mln/metal/converts_to.hh>
/*! \file
@@ -43,23 +43,23 @@ namespace mln
/// Return the mean of two values.
template <typename T>
- mln_trait_op_div(T,double)
+ mln_trait_routine_mean(2,T)
mean(const T& v1, const T& v2);
/// \overload \pre Type U must be convertible towards type T.
template <typename T, typename U>
- mln_trait_op_div(T,double)
+ mln_trait_routine_mean(2,T)
mean(const T& v1, const U& v2);
/// Return the mean of four values.
template <typename T>
- mln_trait_op_div(T,double)
+ mln_trait_routine_mean(4,T)
mean(const T& v1, const T& v2, const T& v3, const T& v4);
/// \overload \pre Type T2, T3 and T4 must be convertible towards
/// type T.
template <typename T, typename T2, typename T3, typename T4>
- mln_trait_op_div(T,double)
+ mln_trait_routine_mean(4,T)
mean(const T& v1, const T2& v2, const T3& v3, const T4& v4);
@@ -69,7 +69,7 @@ namespace mln
/// \internal Generic implementation of the mean of two values.
template <typename T>
- mln_trait_op_div(T,double)
+ mln_trait_routine_mean(2,T)
mean_(const T& v1, const T& v2)
{
return (v1 + v2) / 2.;
@@ -77,24 +77,24 @@ namespace mln
/// \internal Generic implementation of the mean of four values.
template <typename T>
- mln_trait_op_div(T,double)
+ mln_trait_routine_mean(4,T)
mean_(const T& v1, const T& v2, const T& v3, const T& v4)
{
- return (v1 + v2 + v3 + v4) / 4;
+ return (v1 + v2 + v3 + v4) / 4.;
}
namespace math
{
template <typename T>
- mln_trait_op_div(T,double)
+ mln_trait_routine_mean(2,T)
mean(const T& v1, const T& v2)
{
return mean_(exact(v1), exact(v2));
}
template <typename T, typename U>
- mln_trait_op_div(T,double)
+ mln_trait_routine_mean(2,T)
mean(const T& v1, const U& v2)
{
mlc_converts_to(U,T)::check();
@@ -102,14 +102,14 @@ namespace mln
}
template <typename T>
- mln_trait_op_div(T,double)
+ mln_trait_routine_mean(4,T)
mean(const T& v1, const T& v2, const T& v3, const T& v4)
{
return mean_(v1, T(v2), T(v3), T(v4));
}
template <typename T, typename T2, typename T3, typename T4>
- mln_trait_op_div(T,double)
+ mln_trait_routine_mean(4,T)
mean(const T& v1, const T2& v2, const T3& v3, const T4& v4)
{
mlc_converts_to(T2,T)::check();
diff --git a/milena/mln/math/median.hh b/milena/mln/math/median.hh
new file mode 100644
index 0000000..9338b90
--- /dev/null
+++ b/milena/mln/math/median.hh
@@ -0,0 +1,172 @@
+// Copyright (C) 2012 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_MATH_MEDIAN_HH
+# define MLN_MATH_MEDIAN_HH
+
+# include <mln/trait/routine/median.hh>
+# include <mln/math/mean.hh>
+# include <mln/metal/converts_to.hh>
+
+/*! \file
+ *
+ * \brief Define median routine.
+ */
+
+
+namespace mln
+{
+
+ namespace math
+ {
+
+ /// Return the median of two values.
+ template <typename T>
+ mln_trait_routine_median(T)
+ median(const T& v1, const T& v2);
+
+ /// \overload \pre Type U must be convertible towards type T.
+ template <typename T, typename U>
+ mln_trait_routine_median(T)
+ median(const T& v1, const U& v2);
+
+ /// Return the median of four values.
+ template <typename T>
+ mln_trait_routine_median(T)
+ median(const T& v1, const T& v2, const T& v3, const T& v4);
+
+ /// \overload \pre Type T2, T3 and T4 must be convertible towards
+ /// type T.
+ template <typename T, typename T2, typename T3, typename T4>
+ mln_trait_routine_median(T)
+ median(const T& v1, const T2& v2, const T3& v3, const T4& v4);
+
+
+ } // end of namespace mln::math
+
+# ifndef MLN_INCLUDE_ONLY
+
+ /// \internal Generic implementation of the median of four values.
+ template <typename T>
+ mln_trait_routine_median(T)
+ median_(const T& v1, const T& v2, const T& v3, const T& v4)
+ {
+ if (v1 <= v2)
+ if (v2 <= v3)
+ if (v3 <= v4)
+ return mean_(v2, v3);
+ else // v3 > v4
+ if (v4 <= v1)
+ return mean_(v1,v2);
+ else // v4 > v1
+ return mean_(v4,v2);
+ else // v2 > v3
+ if (v1 <= v3)
+ if (v2 <= v4)
+ return mean_(v3, v2);
+ else // v2 > v4
+ if (v4 <= v1)
+ return mean_(v1, v3);
+ else // v4 > v1
+ return mean_(v4, v3);
+ else // v1 > v3
+ if (v2 <= v4)
+ return mean_(v1,v2);
+ else // v2 > v4
+ if (v4 <= v3)
+ return mean_(v3,v1);
+ else // v4 > v3
+ return mean_(v4,v1);
+ else // v1 > v2
+ if (v1 <= v3)
+ if (v4 <= v3)
+ if (v4 <= v2)
+ return mean_(v2, v1);
+ else // v4 > v2
+ return mean_(v1, v4);
+ else // v4 > v2
+ return mean_(v1, v3);
+ else // v1 > v3
+ if (v2 <= v3)
+ if (v4 <= v1)
+ if (v4 <= v2)
+ return mean_(v2, v3);
+ else // v4 > v2
+ return mean_(v4, v3);
+ else // v4 > v1
+ return mean_(v3, v1);
+ else // v2 > v3
+ if (v4 <= v1)
+ if (v3 <= v4)
+ return mean_(v4, v2);
+ else // v3 > v4
+ return mean_(v3, v2);
+ else // v4 > v1
+ return mean_(v2, v1);
+ }
+
+ namespace math
+ {
+
+ template <typename T>
+ mln_trait_routine_median(T)
+ median(const T& v1, const T& v2)
+ {
+ return mean_(exact(v1), exact(v2));
+ }
+
+ template <typename T, typename U>
+ mln_trait_routine_median(T)
+ median(const T& v1, const U& v2)
+ {
+ mlc_converts_to(U,T)::check();
+ return mean_(v1, T(v2));
+ }
+
+ template <typename T>
+ mln_trait_routine_median(T)
+ median(const T& v1, const T& v2, const T& v3, const T& v4)
+ {
+ return median_(v1, T(v2), T(v3), T(v4));
+ }
+
+ template <typename T, typename T2, typename T3, typename T4>
+ mln_trait_routine_median(T)
+ median(const T& v1, const T2& v2, const T3& v3, const T4& v4)
+ {
+ mlc_converts_to(T2,T)::check();
+ mlc_converts_to(T3,T)::check();
+ mlc_converts_to(T4,T)::check();
+ return median_(v1, T(v2), T(v3), T(v4));
+ }
+
+ } // end of namespace mln::math
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MATH_MEDIAN_HH
diff --git a/milena/mln/trait/routine/mean.hh b/milena/mln/trait/routine/mean.hh
index 6d96344..8cdbcc2 100644
--- a/milena/mln/trait/routine/mean.hh
+++ b/milena/mln/trait/routine/mean.hh
@@ -26,8 +26,8 @@
#ifndef MLN_TRAIT_ROUTINE_MEAN_HH
# define MLN_TRAIT_ROUTINE_MEAN_HH
-# define mln_trait_routine_mean(n,T) typename mln::trait::routine::mean<n,T>::ret
-# define mln_trait_routine_mean_(n,T) mln::trait::routine::mean<n,T>::ret
+# define mln_trait_routine_mean(n,T) typename mln::trait::routine::mean< n,T >::ret
+# define mln_trait_routine_mean_(n,T) mln::trait::routine::mean< n,T >::ret
namespace mln
{
@@ -58,6 +58,18 @@ namespace mln
typedef mln::value::intsub<nvalues> ret;
};
+ template <unsigned nvalues>
+ struct mean< nvalues, float >
+ {
+ typedef float ret;
+ };
+
+ template <unsigned nvalues>
+ struct mean< nvalues, double >
+ {
+ typedef double ret;
+ };
+
} // end of namespace mln::trait::routine
} // end of namespace mln::routine
diff --git a/milena/mln/trait/routine/median.hh b/milena/mln/trait/routine/median.hh
new file mode 100644
index 0000000..40ea41e
--- /dev/null
+++ b/milena/mln/trait/routine/median.hh
@@ -0,0 +1,79 @@
+// Copyright (C) 2012 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_TRAIT_ROUTINE_MEDIAN_HH
+# define MLN_TRAIT_ROUTINE_MEDIAN_HH
+
+# define mln_trait_routine_median(T) typename mln::trait::routine::median< T >::ret
+# define mln_trait_routine_median_(T) mln::trait::routine::median< T >::ret
+
+namespace mln
+{
+
+ // Forward Declaration
+ namespace value { template <unsigned n> class intsub; }
+
+ namespace trait
+ {
+
+ namespace routine
+ {
+
+ // median
+
+ template <typename T>
+ struct median
+ {
+ // undef
+ };
+
+
+ // specializations
+
+ template <>
+ struct median< int >
+ {
+ typedef mln::value::intsub<2> ret;
+ };
+
+ template <>
+ struct median< float >
+ {
+ typedef float ret;
+ };
+
+ template <>
+ struct median< double >
+ {
+ typedef double ret;
+ };
+
+ } // end of namespace mln::trait::routine
+
+ } // end of namespace mln::routine
+
+} // end of namespace mln
+
+#endif // ! MLN_TRAIT_ROUTINE_MEDIAN_HH
diff --git a/milena/mln/value/intsub.hh b/milena/mln/value/intsub.hh
index eaff527..5cf6ca5 100644
--- a/milena/mln/value/intsub.hh
+++ b/milena/mln/value/intsub.hh
@@ -37,6 +37,7 @@
# include <algorithm>
# include <mln/core/routine/ops.hh>
# include <mln/trait/routine/mean.hh>
+# include <mln/trait/routine/median.hh>
# include <mln/value/ops.hh>
# include <mln/value/builtin/ops.hh>
# include <mln/value/internal/value_like.hh>
@@ -109,6 +110,12 @@ namespace mln
typedef mln::value::intsub<nvalues * n> ret;
};
+ template <unsigned n>
+ struct median< mln::value::intsub<n> >
+ {
+ typedef mln::value::intsub<2*n> ret;
+ };
+
} // end of namespace mln::trait::routine
} // end of namespace mln::trait
@@ -205,21 +212,19 @@ namespace mln
/// Specific implementation of the mean function.
template <unsigned n>
- intsub<2*n> mean(const intsub<n>& v1, const intsub<n>& v2);
+ mln_trait_routine_mean(2,intsub<n>)
+ mean_(const intsub<n>& v1, const intsub<n>& v2);
/// Specific implementation of the mean function.
template <unsigned n>
- intsub<4*n> mean(const intsub<n>& v1, const intsub<n>& v2,
- const intsub<n>& v3, const intsub<n>& v4);
+ mln_trait_routine_mean(4,intsub<n>)
+ mean_(const intsub<n>& v1, const intsub<n>& v2,
+ const intsub<n>& v3, const intsub<n>& v4);
/// Specific implementation of the median function.
template <unsigned n>
- intsub<2*n> median(const intsub<n>& v1, const intsub<n>& v2);
-
- /// Specific implementation of the median function.
- template <unsigned n>
- intsub<4*n> median(const intsub<n>& v1, const intsub<n>& v2,
- const intsub<n>& v3, const intsub<n>& v4);
+ mln_trait_routine_median(intsub<n>)
+ median_(const intsub<n>& v1, const intsub<n>& v2);
// Iota
@@ -484,55 +489,28 @@ namespace mln
return intsub<n>::make_from_enc_(v1.to_enc() > v2.to_enc() ? v1.to_enc() : v2.to_enc());
}
- // FIXME: Make use of mean_() overloads with math::mean. Require
- // to fix an issue with the return type which differs according to
- // the overload : with 2 (intsub<2*n>) or 4 (intsub<4*n>)
- // arguments.
template <unsigned n>
- intsub<2*n> mean(const intsub<n>& v1, const intsub<n>& v2)
+ mln_trait_routine_mean(2,intsub<n>)
+ mean_(const intsub<n>& v1, const intsub<n>& v2)
{
return intsub<2*n>::make_from_enc_((v1.to_enc() + v2.to_enc()));
}
- // FIXME: Make use of mean_() overloads with math::mean. Require
- // to fix an issue with the return type which differs according to
- // the overload : with 2 (intsub<2*n>) or 4 (intsub<4*n>)
- // arguments.
template <unsigned n>
- intsub<4*n> mean(const intsub<n>& v1, const intsub<n>& v2,
- const intsub<n>& v3, const intsub<n>& v4)
+ mln_trait_routine_mean(4,intsub<n>)
+ mean_(const intsub<n>& v1, const intsub<n>& v2,
+ const intsub<n>& v3, const intsub<n>& v4)
{
return mean_(mean_(v1, v2), mean_(v3, v4));
}
- // FIXME: Make use of median_() overloads with
- // math::median. Require to fix an issue with the return type
- // which differs according to the overload : with 2 (intsub<2*n>)
- // or 4 (intsub<4*n>) arguments.
template <unsigned n>
- intsub<2*n> median(const intsub<n>& v1, const intsub<n>& v2)
+ mln_trait_routine_median(intsub<n>)
+ median_(const intsub<n>& v1, const intsub<n>& v2)
{
- return mean(v1, v2);
- }
-
- // FIXME: Make use of median_() overloads with
- // math::median. Require to fix an issue with the return type
- // which differs according to the overload : with 2 (intsub<2*n>)
- // or 4 (intsub<4*n>) arguments.
- template <unsigned n>
- intsub<4*n> median(const intsub<n>& v1, const intsub<n>& v2,
- const intsub<n>& v3, const intsub<n>& v4)
- {
- std::vector<intsub<n> > vec(4);
- vec.push_back(v1);
- vec.push_back(v2);
- vec.push_back(v3);
- vec.push_back(v4);
- std::sort(vec.begin(), vec.end());
- return mean(vec[1], vec[2]);
+ return mean_(v1, v2);
}
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::value
diff --git a/milena/tests/fun/vv2v/Makefile.am b/milena/tests/fun/vv2v/Makefile.am
index d180e3d..47ae244 100644
--- a/milena/tests/fun/vv2v/Makefile.am
+++ b/milena/tests/fun/vv2v/Makefile.am
@@ -1,4 +1,5 @@
-# Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE).
+# Copyright (C) 2008, 2009, 2012 EPITA Research and Development
+# Laboratory (LRDE).
#
# This file is part of Olena.
#
@@ -18,8 +19,12 @@ include $(top_srcdir)/milena/tests/tests.mk
check_PROGRAMS = \
max \
+ mean \
+ median \
min
+mean_SOURCES = mean.cc
+median_SOURCES = median.cc
max_SOURCES = max.cc
min_SOURCES = min.cc
diff --git a/milena/tests/fun/vv2v/mean.cc b/milena/tests/fun/vv2v/mean.cc
new file mode 100644
index 0000000..fc11025
--- /dev/null
+++ b/milena/tests/fun/vv2v/mean.cc
@@ -0,0 +1,71 @@
+// Copyright (C) 2012 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/fun/vv2v/mean.hh>
+#include <mln/value/intsub.hh>
+
+using namespace mln;
+
+void do_it(float v1, float v2, float res)
+{
+
+ {
+ fun::vv2v::mean<value::intsub<2> > f;
+ mln_assertion(f(v1, v2) == res);
+ }
+
+ {
+ fun::vv2v::mean<int> f;
+ mln_assertion(f(v1, v2) == res);
+ }
+
+ {
+ fun::vv2v::mean<float> f;
+ mln_assertion(f(v1, v2) == res);
+ }
+}
+
+
+void do_it2(float v1, float v2, float res)
+{
+ {
+ fun::vv2v::mean<value::intsub<2> > f;
+ mln_assertion(f(v1, v2) == res);
+ }
+
+ {
+ fun::vv2v::mean<float> f;
+ mln_assertion(f(v1, v2) == res);
+ }
+}
+
+
+int main()
+{
+ do_it(3, 4, 3.5);
+ do_it(0, 4, 2);
+
+ do_it2(0, 4.5, 2.25);
+}
diff --git a/milena/tests/fun/vv2v/median.cc b/milena/tests/fun/vv2v/median.cc
new file mode 100644
index 0000000..1bf83d6
--- /dev/null
+++ b/milena/tests/fun/vv2v/median.cc
@@ -0,0 +1,71 @@
+// Copyright (C) 2012 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/fun/vv2v/median.hh>
+#include <mln/value/intsub.hh>
+
+using namespace mln;
+
+void do_it(float v1, float v2, float res)
+{
+
+ {
+ fun::vv2v::median<value::intsub<2> > f;
+ mln_assertion(f(v1, v2) == res);
+ }
+
+ {
+ fun::vv2v::median<int> f;
+ mln_assertion(f(v1, v2) == res);
+ }
+
+ {
+ fun::vv2v::median<float> f;
+ mln_assertion(f(v1, v2) == res);
+ }
+}
+
+
+void do_it2(float v1, float v2, float res)
+{
+ {
+ fun::vv2v::median<value::intsub<2> > f;
+ mln_assertion(f(v1, v2) == res);
+ }
+
+ {
+ fun::vv2v::median<float> f;
+ mln_assertion(f(v1, v2) == res);
+ }
+}
+
+
+int main()
+{
+ do_it(3, 4, 3.5);
+ do_it(0, 4, 2);
+
+ do_it2(0, 4.5, 2.25);
+}
diff --git a/milena/tests/math/Makefile.am b/milena/tests/math/Makefile.am
index 4c3ccb4..864e21c 100644
--- a/milena/tests/math/Makefile.am
+++ b/milena/tests/math/Makefile.am
@@ -1,4 +1,5 @@
-# Copyright (C) 2007, 2009 EPITA Research and Development Laboratory (LRDE).
+# Copyright (C) 2007, 2009, 2012 EPITA Research and Development
+# Laboratory (LRDE).
#
# This file is part of Olena.
#
@@ -15,3 +16,13 @@
# along with Olena. If not, see <http://www.gnu.org/licenses/>.
include $(top_srcdir)/milena/tests/tests.mk
+
+check_PROGRAMS = \
+ mean \
+ median
+
+mean_SOURCES = mean.cc
+median_SOURCES = median.cc
+
+
+TESTS = $(check_PROGRAMS)
diff --git a/milena/tests/math/mean.cc b/milena/tests/math/mean.cc
new file mode 100644
index 0000000..a62cab6
--- /dev/null
+++ b/milena/tests/math/mean.cc
@@ -0,0 +1,47 @@
+// Copyright (C) 2012 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/math/mean.hh>
+#include <mln/value/intsub.hh>
+
+int main()
+{
+ using namespace mln;
+
+ mln_assertion(math::mean(2,3) == 2.5);
+
+ {
+ value::intsub<2> v1(1.5);
+ value::intsub<2> v2(2);
+ mln_assertion(math::mean(v1, v2) == 1.75);
+ }
+
+ mln_assertion(math::mean(1,2,3,4) == 2.5);
+
+ {
+ value::intsub<2> v1(1), v2(2), v3(3), v4(5);
+ mln_assertion(math::mean(v1, v2, v3, v4) == 2.75);
+ }
+}
diff --git a/milena/tests/math/median.cc b/milena/tests/math/median.cc
new file mode 100644
index 0000000..5c0a58d
--- /dev/null
+++ b/milena/tests/math/median.cc
@@ -0,0 +1,90 @@
+// Copyright (C) 2012 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/math/median.hh>
+#include <mln/value/intsub.hh>
+
+template <typename T>
+void do_it(std::vector<T>& vec, float res)
+{
+ for (int i = 0; i < 3; ++i)
+ {
+ for (int j = 0; j < 3; ++j)
+ {
+ for (int k = 0; k < 3; ++k)
+ {
+ mln_assertion(mln::math::median(vec[0], vec[1], vec[2], vec[3]) == res);
+ std::swap(vec[k], vec[k + 1]);
+ }
+ }
+ }
+}
+
+int main()
+{
+ using namespace mln;
+
+ {
+ mln_assertion(math::median(2,3) == 2.5);
+ }
+
+ {
+ value::intsub<2> v1(1.5);
+ value::intsub<2> v2(2);
+ mln_assertion(math::median(v1, v2) == 1.75);
+ }
+
+ {
+ std::vector<int> vec(4);
+ vec[0] = 1;
+ vec[1] = 2;
+ vec[2] = 3;
+ vec[3] = 4;
+
+ do_it(vec, 2.5);
+ }
+
+ {
+ std::vector<int> vec(4);
+ vec[0] = 0;
+ vec[1] = 0;
+ vec[2] = 6;
+ vec[3] = 24;
+
+ do_it(vec, 3);
+ }
+
+
+ {
+ std::vector<value::intsub<2> > vec(4);
+ vec[0] = 2;
+ vec[1] = 1.5;
+ vec[2] = 3;
+ vec[3] = 5;
+
+ do_it(vec, 2.5);
+ }
+
+}
--
1.7.2.5