* mln/debug/iota.hh (mln::trait::modulus<T>): New trait.
(mln::debug::impl::iota(trait::image::speed::any, I&, unsigned)):
* mln/debug/iota.spe.hh
(mln::debug::impl::iota(trait::image::speed::fastest, I&, unsigned)):
Here.
* tests/debug/iota.cc: Exercise mln::debug::iota with an image of
floats.
---
milena/ChangeLog | 12 ++++++++++++
milena/mln/debug/iota.hh | 35 +++++++++++++++++++++++++++++------
milena/mln/debug/iota.spe.hh | 11 ++++++-----
milena/tests/debug/iota.cc | 37 ++++++++++++++++++++++++++++++++-----
4 files changed, 79 insertions(+), 16 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index c63c9e6..6adf168 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,17 @@
2013-10-09 Roland Levillain <roland(a)lrde.epita.fr>
+ Milena: Have mln::debug::iota work with images of floats.
+
+ * mln/debug/iota.hh (mln::trait::modulus<T>): New trait.
+ (mln::debug::impl::iota(trait::image::speed::any, I&, unsigned)):
+ * mln/debug/iota.spe.hh
+ (mln::debug::impl::iota(trait::image::speed::fastest, I&, unsigned)):
+ Here.
+ * tests/debug/iota.cc: Exercise mln::debug::iota with an image of
+ floats.
+
+2013-10-09 Roland Levillain <roland(a)lrde.epita.fr>
+
Milena: Introduce point-wise function bindings.
* mln/pw/bind.hh: New.
diff --git a/milena/mln/debug/iota.hh b/milena/mln/debug/iota.hh
index 4bd92f7..6945a73 100644
--- a/milena/mln/debug/iota.hh
+++ b/milena/mln/debug/iota.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008, 2009, 2011, 2012 EPITA Research and
+// Copyright (C) 2007, 2008, 2009, 2011, 2012, 2013 EPITA Research and
// Development Laboratory (LRDE)
//
// This file is part of Olena.
@@ -27,13 +27,34 @@
#ifndef MLN_DEBUG_IOTA_HH
# define MLN_DEBUG_IOTA_HH
-/*! \file
- *
- * \brief Fill an image with successive values.
- */
+/// \file
+/// \brief Routine filling an image with successive values.
# include <mln/core/concept/image.hh>
+namespace mln
+{
+ namespace trait
+ {
+ // FIXME: Move this to mln/trait/ and generalize it?
+
+ /* Local trait: Modulus type compatible with `unsigned'.
+
+ The `mln::debug::iota' routine below performs an operation
+ `i % m', where `i' is an `unsigned' value and `m' is the
+ image's maximum value type. However, this operation is not
+ valid when `m' is a `float' or a `double'. Hence the following
+ trait, returning `unsigned' for these floating-point
+ value types and `T' for any other value type T. */
+ template <typename T> struct modulus_type { typedef T ret; };
+ template <> struct modulus_type<float> { typedef unsigned ret;
};
+ template <> struct modulus_type<double> { typedef unsigned ret;
};
+
+ } // end of namespace mln::debug
+
+} // end of namespace mln
+
+
// Specializations are in:
# include <mln/debug/iota.spe.hh>
@@ -68,8 +89,10 @@ namespace mln
{
unsigned i = base_index;
mln_piter(I) p(input.domain());
+ typedef mln_value(I) V;
for_all(p)
- input(p) = ++i % mln_max(mln_value(I));
+ input(p) =
+ static_cast<V>(++i % mln_max(typename
trait::modulus_type<V>::ret));
}
} // end of namespace mln::debug::impl
diff --git a/milena/mln/debug/iota.spe.hh b/milena/mln/debug/iota.spe.hh
index 37e17d9..f608696 100644
--- a/milena/mln/debug/iota.spe.hh
+++ b/milena/mln/debug/iota.spe.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2007, 2008, 2009, 2011 EPITA Research and Development
-// Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009, 2011, 2013 EPITA Research and
+// Development Laboratory (LRDE).
//
// This file is part of Olena.
//
@@ -28,8 +28,7 @@
# define MLN_DEBUG_IOTA_SPE_HH
/// \file
-///
-/// Specializations for mln::debug::iota.
+/// \brief Specializations of mln::debug::iota.
# ifndef MLN_DEBUG_IOTA_HH
# error "Forbidden inclusion of *.spe.hh"
@@ -60,8 +59,10 @@ namespace mln
{
unsigned i = base_index;
mln_pixter(I) p(input);
+ typedef mln_value(I) V;
for_all(p)
- p.val() = static_cast<mln_value(I)>(++i % mln_max(mln_value(I)));
+ p.val() =
+ static_cast<V>(++i % mln_max(typename
trait::modulus_type<V>::ret));;
}
# endif // ! MLN_INCLUDE_ONLY
diff --git a/milena/tests/debug/iota.cc b/milena/tests/debug/iota.cc
index 0873a0e..9d58607 100644
--- a/milena/tests/debug/iota.cc
+++ b/milena/tests/debug/iota.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009, 2013 EPITA Research and Development
+// Laboratory (LRDE).
//
// This file is part of Olena.
//
@@ -29,17 +30,23 @@
#include <mln/debug/iota.hh>
#include <mln/data/compare.hh>
+#include <mln/test/predicate.hh>
+
+#include <mln/pw/all.hh>
+#include <mln/fun/vv2v/diff_abs.hh>
+
int main()
{
using namespace mln;
using value::int_u8;
+ // Exercise mln::debug::iota with an image of ints.
{
- int vs[4][4] = { {1, 2, 3, 4},
- {5, 6, 7, 8},
- {9, 10,11,12},
- {13,14,15,16} };
+ int vs[4][4] = { { 1, 2, 3, 4},
+ { 5, 6, 7, 8},
+ { 9, 10, 11, 12},
+ {13, 14, 15, 16} };
image2d<int> ref = make::image(vs);
image2d<int> ima(4, 4);
@@ -47,4 +54,24 @@ int main()
debug::iota(ima);
mln_assertion(ima == ref);
}
+
+ // Exercise mln::debug::iota with an image of floats.
+ {
+ float vs[4][4] = { { 1.f, 2.f, 3.f, 4.f},
+ { 5.f, 6.f, 7.f, 8.f},
+ { 9.f, 10.f, 11.f, 12.f},
+ {13.f, 14.f, 15.f, 16.f} };
+
+ image2d<float> ref = make::image(vs);
+ image2d<float> ima(4, 4);
+
+ debug::iota(ima);
+ // Use a ``tolerant'' comparison.
+ float threshold = 0.0001f;
+ mln_assertion(test::predicate(ima.domain(),
+ pw::bind(fun::vv2v::diff_abs<float>(),
+ pw::value(ima),
+ pw::value(ref))
+ < pw::cst(threshold)));
+ }
}
--
1.7.10.4