Olena-patches
Threads by month
- ----- 2025 -----
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
October 2012
- 9 participants
- 221 discussions
* mln/value/intsub.hh: Improve class.
* tests/value/intsub.cc: Add more tests.
---
milena/ChangeLog | 8 +
milena/mln/value/intsub.hh | 399 +++++++++++++++++-------------------------
milena/tests/value/intsub.cc | 31 ++++
3 files changed, 204 insertions(+), 234 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 1a5f831..3d191ab 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,13 @@
2012-10-04 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Improve value::intsub class.
+
+ * mln/value/intsub.hh: Improve class.
+
+ * tests/value/intsub.cc: Add more tests.
+
+2012-10-04 Guillaume Lazzara <z(a)lrde.epita.fr>
+
* mln/value/builtin/ops.hh: Handle all the comparison operators.
2012-10-04 Guillaume Lazzara <z(a)lrde.epita.fr>
diff --git a/milena/mln/value/intsub.hh b/milena/mln/value/intsub.hh
index fc269a8..897215c 100644
--- a/milena/mln/value/intsub.hh
+++ b/milena/mln/value/intsub.hh
@@ -33,10 +33,12 @@
# include <cstdlib>
# include <iostream>
# include <sstream>
+# include <algorithm>
+# include <mln/core/routine/ops.hh>
+# include <mln/value/ops.hh>
+# include <mln/value/builtin/ops.hh>
# include <mln/value/internal/value_like.hh>
-# include <mln/value/internal/encoding.hh>
-# include <mln/value/internal/limits.hh>
-# include <mln/value/concept/integer.hh>
+# include <mln/value/concept/floating.hh>
# include <mln/value/iota.hh>
# include <mln/value/prev.hh>
# include <mln/value/succ.hh>
@@ -65,13 +67,13 @@ namespace mln
{
private:
typedef mln::value::intsub<n> self_;
- typedef typename mln::value::internal::encoding_signed_<32>::ret enc_;
+ typedef int enc_;
public:
enum constants_ {
dim = 1,
nbits = 32,
- card = mln_value_card_from_(32/n) // FIXME: Really?
+ card = mln_value_card_from_(32) / n
};
typedef trait::value::nature::integer nature;
@@ -103,12 +105,12 @@ namespace mln
{
template <unsigned n>
- class intsub
- : public Integer< intsub<n> >,
- public internal::value_like_< int, // Equivalent.
- typename internal::encoding_signed_<32>::ret, // Enc.
- int, // Interoperation.
- intsub<n> > // Exact.
+ class intsub :
+ public value::Floating< intsub<n> >,
+ public value::internal::value_like_< float, // Equivalent.
+ int, // Enc.
+ float, // Interoperation.
+ intsub<n> > // Exact.
{
public:
intsub();
@@ -116,9 +118,13 @@ namespace mln
/// Construct an intsub with value : \p int_part + 1 / \p denominator.
intsub(int int_part, unsigned denominator);
intsub(int i);
+ intsub(float i);
+ intsub(double i);
intsub<n>& operator=(const intsub<n>& rhs);
intsub<n>& operator=(int i);
+ intsub<n>& operator=(float i);
+ intsub<n>& operator=(double i);
/// Is an integer value.
bool is_integer() const;
@@ -143,92 +149,61 @@ namespace mln
/*!\internal Construct a intsub using an encoding value. */
static intsub<n> make_from_enc_(int enc);
+ /// Conversion to a float.
+ operator float() const;
+
/// Unary operator minus.
intsub<n> operator-() const;
+ /// Explicit conversion towards equivalent type.
+ float to_equiv() const;
+
+ /// Explicit conversion towards interoperation type.
+ float to_interop() const;
};
// Safety
template <> struct intsub<0>;
-// rounding
+ // rounding
+ /// Re-implementation of the floor function. \sa math::floor
template <unsigned n>
- intsub<n> floor(const intsub<n>& i);
+ intsub<n> floor_(const intsub<n>& i);
+ /// Re-implementation of the ceil function. \sa math::ceil
template <unsigned n>
- intsub<n> ceil(const intsub<n>& i);
-
+ intsub<n> ceil_(const intsub<n>& i);
-// comparison
+ // Other ops (overloads of generic ones)
+ /// Re-implementation of the min function. \sa math::min
template <unsigned n>
- bool operator==(const intsub<n>& l, const intsub<n>& r);
- template <unsigned n, typename V>
- bool operator==(const intsub<n>& l, const V& r);
- template <unsigned n>
- bool operator<=(const intsub<n>& l, const intsub<n>& r);
- template <unsigned n>
- bool operator!=(const intsub<n>& l, const intsub<n>& r);
+ intsub<n> min_(const intsub<n>& u1, const intsub<n>& u2);
+ /// Re-implementation of the max function. \sa math::max
template <unsigned n>
- bool operator>=(const intsub<n>& l, const intsub<n>& r);
- template <unsigned n>
- bool operator>(const intsub<n>& l, const intsub<n>& r);
- template <unsigned n>
- bool operator<(const intsub<n>& l, const intsub<n>& r);
-
-// arithmetics
+ intsub<n> max_(const intsub<n>& u1, const intsub<n>& u2);
+ /// Specific implementation of the mean function.
template <unsigned n>
- intsub<n> operator+(const intsub<n>& l, const intsub<n>& r);
- template <unsigned n, typename O>
- intsub<n> operator+(const intsub<n>& l, const O& r);
- template <typename O, unsigned n>
- intsub<n> operator+(const O& r, const intsub<n>& l);
- template <unsigned n>
- void operator+=(intsub<n>& l, const intsub<n>& r);
- template <unsigned n, typename O>
- void operator+=(intsub<n>& l, const O& r);
+ intsub<2*n> mean(const intsub<n>& v1, const intsub<n>& v2);
+ /// Specific implementation of the mean function.
template <unsigned n>
- intsub<n> operator-(const intsub<n>& l, const intsub<n>& r);
- template <unsigned n, typename O>
- intsub<n> operator-(const intsub<n>& l, const O& r);
- template <typename O, unsigned n>
- intsub<n> operator-(const O& r, const intsub<n>& l);
- template <unsigned n>
- void operator-=(intsub<n>& l, const intsub<n>& r);
- template <unsigned n, typename O>
- void operator-=(intsub<n>& l, const O& r);
+ intsub<4*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<n> operator*(const intsub<n>& l, const intsub<n>& r);
- template <unsigned n, typename O>
- intsub<n> operator*(const intsub<n>& l, const O& r);
- template <typename O, unsigned n>
- intsub<n> operator*(const O& r, const intsub<n>& l);
- template <unsigned n>
- void operator*=(intsub<n>& l, const intsub<n>& r);
- template <unsigned n, typename O>
- void operator*=(intsub<n>& l, const O& r);
-
-// other ops
+ intsub<2*n> median(const intsub<n>& v1, const intsub<n>& v2);
+ /// Specific implementation of the median function.
template <unsigned n>
- intsub<n> min(const intsub<n>& u1, const intsub<n>& u2);
- template <unsigned n>
- intsub<n> max(const intsub<n>& u1, const intsub<n>& u2);
- template <unsigned n>
- intsub<n> mean(const intsub<n>& v1, const intsub<n>& v2);
- template <unsigned n>
- intsub<n> mean(const intsub<n>& v1, const intsub<n>& v2,
- const intsub<n>& v3, const intsub<n>& v4);
+ intsub<4*n> median(const intsub<n>& v1, const intsub<n>& v2,
+ const intsub<n>& v3, const intsub<n>& v4);
-// <<
- template <unsigned n>
- std::ostream&
- operator<<(std::ostream& ostr, const intsub<n>& i);
+ // Iota
template <unsigned n>
struct iota<intsub<n> >
@@ -236,6 +211,11 @@ namespace mln
static intsub<n> value();
};
+ typedef intsub<1> intsub1;
+ typedef intsub<2> intsub2;
+ typedef intsub<4> intsub4;
+
+
} // end of namespace mln::value
extern const value::intsub<2> half;
@@ -243,7 +223,6 @@ namespace mln
# ifndef MLN_INCLUDE_ONLY
-
// half
# ifndef MLN_WO_GLOBAL_VARS
@@ -258,6 +237,27 @@ namespace mln
namespace value
{
+ namespace internal
+ {
+
+ /// \internal Test if (f * v) is an integer; an error less than
+ /// epsilon is ok
+ bool
+ mult_is_integer(float f, int v)
+ {
+ float a = f * v;
+ float b = float(unsigned(a));
+ const float epsilon = 0.00001f;
+
+ if (a > b)
+ return a - b < epsilon;
+ else
+ return b - a < epsilon;
+ }
+
+ } // end of namespace mln::value::internal
+
+
template <unsigned n>
intsub<n>::intsub()
{
@@ -276,12 +276,24 @@ namespace mln
}
template <unsigned n>
- intsub<n>::intsub(int int_part, unsigned denominator)
+ intsub<n>::intsub(float i)
{
- // FIXME: better error handling ?
- if (denominator > n)
- std::abort();
+ mln_precondition(internal::mult_is_integer(i, n));
+ this->v_ = n * i;
+ }
+ template <unsigned n>
+ intsub<n>::intsub(double i)
+ {
+ mln_precondition(internal::mult_is_integer(i, n));
+ this->v_ = n * i;
+ }
+
+
+ template <unsigned n>
+ intsub<n>::intsub(int int_part, unsigned denominator)
+ {
+ mln_precondition(denominator <= n);
this->v_ = int_part * n + denominator / n;
}
@@ -303,6 +315,25 @@ namespace mln
}
template <unsigned n>
+ intsub<n>&
+ intsub<n>::operator=(float i)
+ {
+ mln_precondition(internal::mult_is_integer(i, n));
+ this->v_ = n * i;
+ return *this;
+ }
+
+ template <unsigned n>
+ intsub<n>&
+ intsub<n>::operator=(double i)
+ {
+ mln_precondition(internal::mult_is_integer(i, n));
+ this->v_ = n * i;
+ return *this;
+ }
+
+
+ template <unsigned n>
intsub<n> intsub<n>::make_from_enc_(int enc)
{
intsub<n> i;
@@ -321,10 +352,8 @@ namespace mln
template <unsigned m>
intsub<n>::operator intsub<m>()
{
- // FIXME: better error handling ?
- if (n > m)
- std::abort();
- return intsub<m>::make_from_enc_(this->v_ * (m / n));
+ mln_precondition(n <= m);
+ return intsub<m>::make_from_enc_(this->v_ * m / n);
}
template <unsigned n>
@@ -349,215 +378,117 @@ namespace mln
}
template <unsigned n>
- intsub<n>
- intsub<n>::operator-() const
+ intsub<n>::operator float() const
{
- return intsub<n>::make_from_enc_(this->v_ * -1);
+ return to_equiv();
}
- // Iota
template <unsigned n>
intsub<n>
- iota<intsub<n> >::value()
- {
- return intsub<n>(0,n);
- }
-
-
-// rounding
-
-
- template <unsigned n>
- intsub<n> floor(const intsub<n>& i)
- {
- return i.is_integer() ? i : value::prev(i);
- }
-
- template <unsigned n>
- intsub<n> ceil(const intsub<n>& i)
- {
- return i.is_integer() ? i : value::succ(i);
- }
-
-
-
-// comparison
-
- template <unsigned n>
- bool operator==(const intsub<n>& l, const intsub<n>& r)
- {
- return l.to_enc() == r.to_enc();
- }
-
- template <unsigned n>
- bool operator==(const intsub<n>& l, const int& r)
- {
- return l == intsub<n>(r);
- }
-
- template <unsigned n>
- bool operator<=(const intsub<n>& l, const intsub<n>& r)
- {
- return l.to_enc() <= r.to_enc();
- }
-
- template <unsigned n>
- bool operator!=(const intsub<n>& l, const intsub<n>& r)
- {
- return ! (l == r);
- }
-
- template <unsigned n>
- bool operator>=(const intsub<n>& l, const intsub<n>& r)
- {
- return r <= l;
- }
-
- template <unsigned n>
- bool operator>(const intsub<n>& l, const intsub<n>& r)
- {
- return ! (l <= r);
- }
-
- template <unsigned n>
- bool operator<(const intsub<n>& l, const intsub<n>& r)
- {
- return r > l;
- }
-
-
-// arithmetics
-
- template <unsigned n>
- intsub<n> operator+(const intsub<n>& l, const intsub<n>& r)
- {
- return intsub<n>::make_from_enc_(l.to_enc() + r.to_enc());
- }
-
- template <unsigned n>
- intsub<n> operator+(const intsub<n>& l, int r)
- {
- return l + intsub<n>(r);
- }
-
- template <unsigned n>
- intsub<n> operator+(int l, const intsub<n>& r)
- {
- return r + l;
- }
-
- template <unsigned n>
- void operator+=(intsub<n>& l, const intsub<n>& r)
+ intsub<n>::operator-() const
{
- l = l + r;
+ return intsub<n>::make_from_enc_(this->v_ * -1);
}
template <unsigned n>
- void operator+=(intsub<n>& l, int r)
+ float
+ intsub<n>::to_equiv() const
{
- l = l + intsub<n>(r);
+ return float(this->v_) / float(n);
}
template <unsigned n>
- intsub<n> operator-(const intsub<n>& l, const intsub<n>& r)
+ float
+ intsub<n>::to_interop() const
{
- return intsub<n>::make_from_enc_(l.to_enc() - r.to_enc());
+ return float(this->v_) / float(n);
}
- template <unsigned n>
- intsub<n> operator-(const intsub<n>& l, int r)
- {
- return l - intsub<n>(r);
- }
+ // Iota
template <unsigned n>
- intsub<n> operator-(int l, const intsub<n>& r)
+ intsub<n>
+ iota<intsub<n> >::value()
{
- return - r + l;
+ return intsub<n>(0,n);
}
- template <unsigned n>
- void operator-=(intsub<n>& l, const intsub<n>& r)
- {
- l = l - r;
- }
- template <unsigned n>
- void operator-=(intsub<n>& l, int r)
- {
- l = l - intsub<n>(r);
- }
+ // rounding
template <unsigned n>
- intsub<n> operator*(const intsub<n>& l, const intsub<n>& r)
+ intsub<n> floor_(const intsub<n>& i)
{
- return intsub<n>::make_from_enc_(l.to_enc() * r.to_enc() / n);
+ return i.is_integer() ? i : value::prev(i);
}
template <unsigned n>
- intsub<n> operator*(const intsub<n>& l, int r)
+ intsub<n> ceil_(const intsub<n>& i)
{
- return l * intsub<n>(r);
+ return i.is_integer() ? i : value::succ(i);
}
- template <unsigned n>
- intsub<n> operator*(int l, const intsub<n>& r)
- {
- return r * l;
- }
- template <unsigned n>
- void operator*=(intsub<n>& l, const intsub<n>& r)
- {
- l = l * r;
- }
+ // Other operators (overloads of generic ones)
template <unsigned n>
- void operator*=(intsub<n>& l, int r)
+ intsub<n> min_(const intsub<n>& v1, const intsub<n>& v2)
{
- l = l * intsub<n>(r);
+ return intsub<n>::make_from_enc_(v1.to_enc() < v2.to_enc() ? v1.to_enc() : v2.to_enc());
}
-
-// other ops
-
template <unsigned n>
- intsub<n> min(const intsub<n>& v1, const intsub<n>& v2)
+ intsub<n> max_(const intsub<n>& v1, const intsub<n>& v2)
{
- return intsub<n>::make_from_enc_(v1.to_enc() < v2.to_enc() ? v1.to_enc() : v2.to_enc());
+ 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<n> max(const intsub<n>& v1, const intsub<n>& v2)
+ intsub<2*n> mean(const intsub<n>& v1, const intsub<n>& v2)
{
- return intsub<n>::make_from_enc_(v1.to_enc() > v2.to_enc() ? v1.to_enc() : v2.to_enc());
+ 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<n> mean(const intsub<n>& v1, const intsub<n>& v2)
+ intsub<4*n> mean(const intsub<n>& v1, const intsub<n>& v2,
+ const intsub<n>& v3, const intsub<n>& v4)
{
- return intsub<n>::make_from_enc_((v1.to_enc() + v2.to_enc()) / 2);
+ 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<n> mean(const intsub<n>& v1, const intsub<n>& v2,
- const intsub<n>& v3, const intsub<n>& v4)
+ intsub<2*n> median(const intsub<n>& v1, const intsub<n>& v2)
{
- return intsub<n>::make_from_enc_((v1.to_enc() + v2.to_enc()
- + v3.to_enc() + v4.to_enc()) / 4);
+ 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>
- std::ostream&
- operator<<(std::ostream& ostr, const intsub<n>& i)
+ intsub<4*n> median(const intsub<n>& v1, const intsub<n>& v2,
+ const intsub<n>& v3, const intsub<n>& v4)
{
- if (i.is_integer())
- return ostr << i.to_int();
- else
- return ostr << floor(i).to_int() << ".5";
+ 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]);
}
# endif // ! MLN_INCLUDE_ONLY
diff --git a/milena/tests/value/intsub.cc b/milena/tests/value/intsub.cc
index e324fe3..82a87fb 100644
--- a/milena/tests/value/intsub.cc
+++ b/milena/tests/value/intsub.cc
@@ -26,12 +26,16 @@
/// \file
#include <cassert>
+#include <mln/math/mean.hh>
#include <mln/value/intsub.hh>
#include <mln/value/inc.hh>
#include <mln/value/dec.hh>
#include <mln/value/succ.hh>
#include <mln/value/prev.hh>
#include <mln/math/mean.hh>
+#include <mln/math/min.hh>
+#include <mln/math/ceil.hh>
+#include <mln/math/floor.hh>
int main()
{
@@ -48,6 +52,10 @@ int main()
// (2.5 + 0.5) / 2 == 1.5
mln_assertion(mean(i, half) == 1 + half);
+ // (2.5 + 2) / 2 = 2.25
+ intsub<4> res = mean(i, intsub<2>(2));
+ mln_assertion(res == 2.25);
+
// i == 3
inc(i);
mln_assertion(i == intsub<2>(3));
@@ -75,4 +83,27 @@ int main()
inc(j);
mln_assertion(j == 6 + quarter);
+ // k = 10.25
+ intsub<8> k(10.25);
+ mln_assertion(k == 10 + quarter);
+
+ // sum(j,k,2) == 18.5
+ mln_assertion(j + k + 2 == 18.5);
+
+ // min(i,l) == 2.5
+ intsub<2> l(2.5);
+ mln_assertion(mln::math::min(i, l) == 2.5);
+
+ // mean(6,2,2.5,3) = 3.375
+ mln_assertion(mean(i, intsub<2>(2), l, intsub<2>(3)) == 3.375);
+
+ // ceil(2.5)
+ mln_assertion(math::ceil(l) == 3);
+ mln_assertion(math::floor(l) == 2);
+
+ // median(6,2,2.5,3) = 2.75
+ mln_assertion(median(i, intsub<2>(2), l, intsub<2>(3)) == 2.75);
+
+ // median(6,2) = 4
+ mln_assertion(median(i, intsub<2>(2)) == 4);
}
--
1.7.2.5
1
0
* mln/value/intsub.hh: Improve class.
* tests/value/intsub.cc: Add more tests.
---
milena/ChangeLog | 8 +
milena/mln/value/intsub.hh | 399 +++++++++++++++++-------------------------
milena/tests/value/intsub.cc | 31 ++++
3 files changed, 204 insertions(+), 234 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index b7e9506..c9a02a4 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,13 @@
2012-10-04 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Improve value::intsub class.
+
+ * mln/value/intsub.hh: Improve class.
+
+ * tests/value/intsub.cc: Add more tests.
+
+2012-10-04 Guillaume Lazzara <z(a)lrde.epita.fr>
+
* mln/value/builtin/ops.hh: Handle all the comparison operators.
2012-10-04 Guillaume Lazzara <z(a)lrde.epita.fr>
diff --git a/milena/mln/value/intsub.hh b/milena/mln/value/intsub.hh
index fc269a8..897215c 100644
--- a/milena/mln/value/intsub.hh
+++ b/milena/mln/value/intsub.hh
@@ -33,10 +33,12 @@
# include <cstdlib>
# include <iostream>
# include <sstream>
+# include <algorithm>
+# include <mln/core/routine/ops.hh>
+# include <mln/value/ops.hh>
+# include <mln/value/builtin/ops.hh>
# include <mln/value/internal/value_like.hh>
-# include <mln/value/internal/encoding.hh>
-# include <mln/value/internal/limits.hh>
-# include <mln/value/concept/integer.hh>
+# include <mln/value/concept/floating.hh>
# include <mln/value/iota.hh>
# include <mln/value/prev.hh>
# include <mln/value/succ.hh>
@@ -65,13 +67,13 @@ namespace mln
{
private:
typedef mln::value::intsub<n> self_;
- typedef typename mln::value::internal::encoding_signed_<32>::ret enc_;
+ typedef int enc_;
public:
enum constants_ {
dim = 1,
nbits = 32,
- card = mln_value_card_from_(32/n) // FIXME: Really?
+ card = mln_value_card_from_(32) / n
};
typedef trait::value::nature::integer nature;
@@ -103,12 +105,12 @@ namespace mln
{
template <unsigned n>
- class intsub
- : public Integer< intsub<n> >,
- public internal::value_like_< int, // Equivalent.
- typename internal::encoding_signed_<32>::ret, // Enc.
- int, // Interoperation.
- intsub<n> > // Exact.
+ class intsub :
+ public value::Floating< intsub<n> >,
+ public value::internal::value_like_< float, // Equivalent.
+ int, // Enc.
+ float, // Interoperation.
+ intsub<n> > // Exact.
{
public:
intsub();
@@ -116,9 +118,13 @@ namespace mln
/// Construct an intsub with value : \p int_part + 1 / \p denominator.
intsub(int int_part, unsigned denominator);
intsub(int i);
+ intsub(float i);
+ intsub(double i);
intsub<n>& operator=(const intsub<n>& rhs);
intsub<n>& operator=(int i);
+ intsub<n>& operator=(float i);
+ intsub<n>& operator=(double i);
/// Is an integer value.
bool is_integer() const;
@@ -143,92 +149,61 @@ namespace mln
/*!\internal Construct a intsub using an encoding value. */
static intsub<n> make_from_enc_(int enc);
+ /// Conversion to a float.
+ operator float() const;
+
/// Unary operator minus.
intsub<n> operator-() const;
+ /// Explicit conversion towards equivalent type.
+ float to_equiv() const;
+
+ /// Explicit conversion towards interoperation type.
+ float to_interop() const;
};
// Safety
template <> struct intsub<0>;
-// rounding
+ // rounding
+ /// Re-implementation of the floor function. \sa math::floor
template <unsigned n>
- intsub<n> floor(const intsub<n>& i);
+ intsub<n> floor_(const intsub<n>& i);
+ /// Re-implementation of the ceil function. \sa math::ceil
template <unsigned n>
- intsub<n> ceil(const intsub<n>& i);
-
+ intsub<n> ceil_(const intsub<n>& i);
-// comparison
+ // Other ops (overloads of generic ones)
+ /// Re-implementation of the min function. \sa math::min
template <unsigned n>
- bool operator==(const intsub<n>& l, const intsub<n>& r);
- template <unsigned n, typename V>
- bool operator==(const intsub<n>& l, const V& r);
- template <unsigned n>
- bool operator<=(const intsub<n>& l, const intsub<n>& r);
- template <unsigned n>
- bool operator!=(const intsub<n>& l, const intsub<n>& r);
+ intsub<n> min_(const intsub<n>& u1, const intsub<n>& u2);
+ /// Re-implementation of the max function. \sa math::max
template <unsigned n>
- bool operator>=(const intsub<n>& l, const intsub<n>& r);
- template <unsigned n>
- bool operator>(const intsub<n>& l, const intsub<n>& r);
- template <unsigned n>
- bool operator<(const intsub<n>& l, const intsub<n>& r);
-
-// arithmetics
+ intsub<n> max_(const intsub<n>& u1, const intsub<n>& u2);
+ /// Specific implementation of the mean function.
template <unsigned n>
- intsub<n> operator+(const intsub<n>& l, const intsub<n>& r);
- template <unsigned n, typename O>
- intsub<n> operator+(const intsub<n>& l, const O& r);
- template <typename O, unsigned n>
- intsub<n> operator+(const O& r, const intsub<n>& l);
- template <unsigned n>
- void operator+=(intsub<n>& l, const intsub<n>& r);
- template <unsigned n, typename O>
- void operator+=(intsub<n>& l, const O& r);
+ intsub<2*n> mean(const intsub<n>& v1, const intsub<n>& v2);
+ /// Specific implementation of the mean function.
template <unsigned n>
- intsub<n> operator-(const intsub<n>& l, const intsub<n>& r);
- template <unsigned n, typename O>
- intsub<n> operator-(const intsub<n>& l, const O& r);
- template <typename O, unsigned n>
- intsub<n> operator-(const O& r, const intsub<n>& l);
- template <unsigned n>
- void operator-=(intsub<n>& l, const intsub<n>& r);
- template <unsigned n, typename O>
- void operator-=(intsub<n>& l, const O& r);
+ intsub<4*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<n> operator*(const intsub<n>& l, const intsub<n>& r);
- template <unsigned n, typename O>
- intsub<n> operator*(const intsub<n>& l, const O& r);
- template <typename O, unsigned n>
- intsub<n> operator*(const O& r, const intsub<n>& l);
- template <unsigned n>
- void operator*=(intsub<n>& l, const intsub<n>& r);
- template <unsigned n, typename O>
- void operator*=(intsub<n>& l, const O& r);
-
-// other ops
+ intsub<2*n> median(const intsub<n>& v1, const intsub<n>& v2);
+ /// Specific implementation of the median function.
template <unsigned n>
- intsub<n> min(const intsub<n>& u1, const intsub<n>& u2);
- template <unsigned n>
- intsub<n> max(const intsub<n>& u1, const intsub<n>& u2);
- template <unsigned n>
- intsub<n> mean(const intsub<n>& v1, const intsub<n>& v2);
- template <unsigned n>
- intsub<n> mean(const intsub<n>& v1, const intsub<n>& v2,
- const intsub<n>& v3, const intsub<n>& v4);
+ intsub<4*n> median(const intsub<n>& v1, const intsub<n>& v2,
+ const intsub<n>& v3, const intsub<n>& v4);
-// <<
- template <unsigned n>
- std::ostream&
- operator<<(std::ostream& ostr, const intsub<n>& i);
+ // Iota
template <unsigned n>
struct iota<intsub<n> >
@@ -236,6 +211,11 @@ namespace mln
static intsub<n> value();
};
+ typedef intsub<1> intsub1;
+ typedef intsub<2> intsub2;
+ typedef intsub<4> intsub4;
+
+
} // end of namespace mln::value
extern const value::intsub<2> half;
@@ -243,7 +223,6 @@ namespace mln
# ifndef MLN_INCLUDE_ONLY
-
// half
# ifndef MLN_WO_GLOBAL_VARS
@@ -258,6 +237,27 @@ namespace mln
namespace value
{
+ namespace internal
+ {
+
+ /// \internal Test if (f * v) is an integer; an error less than
+ /// epsilon is ok
+ bool
+ mult_is_integer(float f, int v)
+ {
+ float a = f * v;
+ float b = float(unsigned(a));
+ const float epsilon = 0.00001f;
+
+ if (a > b)
+ return a - b < epsilon;
+ else
+ return b - a < epsilon;
+ }
+
+ } // end of namespace mln::value::internal
+
+
template <unsigned n>
intsub<n>::intsub()
{
@@ -276,12 +276,24 @@ namespace mln
}
template <unsigned n>
- intsub<n>::intsub(int int_part, unsigned denominator)
+ intsub<n>::intsub(float i)
{
- // FIXME: better error handling ?
- if (denominator > n)
- std::abort();
+ mln_precondition(internal::mult_is_integer(i, n));
+ this->v_ = n * i;
+ }
+ template <unsigned n>
+ intsub<n>::intsub(double i)
+ {
+ mln_precondition(internal::mult_is_integer(i, n));
+ this->v_ = n * i;
+ }
+
+
+ template <unsigned n>
+ intsub<n>::intsub(int int_part, unsigned denominator)
+ {
+ mln_precondition(denominator <= n);
this->v_ = int_part * n + denominator / n;
}
@@ -303,6 +315,25 @@ namespace mln
}
template <unsigned n>
+ intsub<n>&
+ intsub<n>::operator=(float i)
+ {
+ mln_precondition(internal::mult_is_integer(i, n));
+ this->v_ = n * i;
+ return *this;
+ }
+
+ template <unsigned n>
+ intsub<n>&
+ intsub<n>::operator=(double i)
+ {
+ mln_precondition(internal::mult_is_integer(i, n));
+ this->v_ = n * i;
+ return *this;
+ }
+
+
+ template <unsigned n>
intsub<n> intsub<n>::make_from_enc_(int enc)
{
intsub<n> i;
@@ -321,10 +352,8 @@ namespace mln
template <unsigned m>
intsub<n>::operator intsub<m>()
{
- // FIXME: better error handling ?
- if (n > m)
- std::abort();
- return intsub<m>::make_from_enc_(this->v_ * (m / n));
+ mln_precondition(n <= m);
+ return intsub<m>::make_from_enc_(this->v_ * m / n);
}
template <unsigned n>
@@ -349,215 +378,117 @@ namespace mln
}
template <unsigned n>
- intsub<n>
- intsub<n>::operator-() const
+ intsub<n>::operator float() const
{
- return intsub<n>::make_from_enc_(this->v_ * -1);
+ return to_equiv();
}
- // Iota
template <unsigned n>
intsub<n>
- iota<intsub<n> >::value()
- {
- return intsub<n>(0,n);
- }
-
-
-// rounding
-
-
- template <unsigned n>
- intsub<n> floor(const intsub<n>& i)
- {
- return i.is_integer() ? i : value::prev(i);
- }
-
- template <unsigned n>
- intsub<n> ceil(const intsub<n>& i)
- {
- return i.is_integer() ? i : value::succ(i);
- }
-
-
-
-// comparison
-
- template <unsigned n>
- bool operator==(const intsub<n>& l, const intsub<n>& r)
- {
- return l.to_enc() == r.to_enc();
- }
-
- template <unsigned n>
- bool operator==(const intsub<n>& l, const int& r)
- {
- return l == intsub<n>(r);
- }
-
- template <unsigned n>
- bool operator<=(const intsub<n>& l, const intsub<n>& r)
- {
- return l.to_enc() <= r.to_enc();
- }
-
- template <unsigned n>
- bool operator!=(const intsub<n>& l, const intsub<n>& r)
- {
- return ! (l == r);
- }
-
- template <unsigned n>
- bool operator>=(const intsub<n>& l, const intsub<n>& r)
- {
- return r <= l;
- }
-
- template <unsigned n>
- bool operator>(const intsub<n>& l, const intsub<n>& r)
- {
- return ! (l <= r);
- }
-
- template <unsigned n>
- bool operator<(const intsub<n>& l, const intsub<n>& r)
- {
- return r > l;
- }
-
-
-// arithmetics
-
- template <unsigned n>
- intsub<n> operator+(const intsub<n>& l, const intsub<n>& r)
- {
- return intsub<n>::make_from_enc_(l.to_enc() + r.to_enc());
- }
-
- template <unsigned n>
- intsub<n> operator+(const intsub<n>& l, int r)
- {
- return l + intsub<n>(r);
- }
-
- template <unsigned n>
- intsub<n> operator+(int l, const intsub<n>& r)
- {
- return r + l;
- }
-
- template <unsigned n>
- void operator+=(intsub<n>& l, const intsub<n>& r)
+ intsub<n>::operator-() const
{
- l = l + r;
+ return intsub<n>::make_from_enc_(this->v_ * -1);
}
template <unsigned n>
- void operator+=(intsub<n>& l, int r)
+ float
+ intsub<n>::to_equiv() const
{
- l = l + intsub<n>(r);
+ return float(this->v_) / float(n);
}
template <unsigned n>
- intsub<n> operator-(const intsub<n>& l, const intsub<n>& r)
+ float
+ intsub<n>::to_interop() const
{
- return intsub<n>::make_from_enc_(l.to_enc() - r.to_enc());
+ return float(this->v_) / float(n);
}
- template <unsigned n>
- intsub<n> operator-(const intsub<n>& l, int r)
- {
- return l - intsub<n>(r);
- }
+ // Iota
template <unsigned n>
- intsub<n> operator-(int l, const intsub<n>& r)
+ intsub<n>
+ iota<intsub<n> >::value()
{
- return - r + l;
+ return intsub<n>(0,n);
}
- template <unsigned n>
- void operator-=(intsub<n>& l, const intsub<n>& r)
- {
- l = l - r;
- }
- template <unsigned n>
- void operator-=(intsub<n>& l, int r)
- {
- l = l - intsub<n>(r);
- }
+ // rounding
template <unsigned n>
- intsub<n> operator*(const intsub<n>& l, const intsub<n>& r)
+ intsub<n> floor_(const intsub<n>& i)
{
- return intsub<n>::make_from_enc_(l.to_enc() * r.to_enc() / n);
+ return i.is_integer() ? i : value::prev(i);
}
template <unsigned n>
- intsub<n> operator*(const intsub<n>& l, int r)
+ intsub<n> ceil_(const intsub<n>& i)
{
- return l * intsub<n>(r);
+ return i.is_integer() ? i : value::succ(i);
}
- template <unsigned n>
- intsub<n> operator*(int l, const intsub<n>& r)
- {
- return r * l;
- }
- template <unsigned n>
- void operator*=(intsub<n>& l, const intsub<n>& r)
- {
- l = l * r;
- }
+ // Other operators (overloads of generic ones)
template <unsigned n>
- void operator*=(intsub<n>& l, int r)
+ intsub<n> min_(const intsub<n>& v1, const intsub<n>& v2)
{
- l = l * intsub<n>(r);
+ return intsub<n>::make_from_enc_(v1.to_enc() < v2.to_enc() ? v1.to_enc() : v2.to_enc());
}
-
-// other ops
-
template <unsigned n>
- intsub<n> min(const intsub<n>& v1, const intsub<n>& v2)
+ intsub<n> max_(const intsub<n>& v1, const intsub<n>& v2)
{
- return intsub<n>::make_from_enc_(v1.to_enc() < v2.to_enc() ? v1.to_enc() : v2.to_enc());
+ 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<n> max(const intsub<n>& v1, const intsub<n>& v2)
+ intsub<2*n> mean(const intsub<n>& v1, const intsub<n>& v2)
{
- return intsub<n>::make_from_enc_(v1.to_enc() > v2.to_enc() ? v1.to_enc() : v2.to_enc());
+ 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<n> mean(const intsub<n>& v1, const intsub<n>& v2)
+ intsub<4*n> mean(const intsub<n>& v1, const intsub<n>& v2,
+ const intsub<n>& v3, const intsub<n>& v4)
{
- return intsub<n>::make_from_enc_((v1.to_enc() + v2.to_enc()) / 2);
+ 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<n> mean(const intsub<n>& v1, const intsub<n>& v2,
- const intsub<n>& v3, const intsub<n>& v4)
+ intsub<2*n> median(const intsub<n>& v1, const intsub<n>& v2)
{
- return intsub<n>::make_from_enc_((v1.to_enc() + v2.to_enc()
- + v3.to_enc() + v4.to_enc()) / 4);
+ 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>
- std::ostream&
- operator<<(std::ostream& ostr, const intsub<n>& i)
+ intsub<4*n> median(const intsub<n>& v1, const intsub<n>& v2,
+ const intsub<n>& v3, const intsub<n>& v4)
{
- if (i.is_integer())
- return ostr << i.to_int();
- else
- return ostr << floor(i).to_int() << ".5";
+ 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]);
}
# endif // ! MLN_INCLUDE_ONLY
diff --git a/milena/tests/value/intsub.cc b/milena/tests/value/intsub.cc
index e324fe3..82a87fb 100644
--- a/milena/tests/value/intsub.cc
+++ b/milena/tests/value/intsub.cc
@@ -26,12 +26,16 @@
/// \file
#include <cassert>
+#include <mln/math/mean.hh>
#include <mln/value/intsub.hh>
#include <mln/value/inc.hh>
#include <mln/value/dec.hh>
#include <mln/value/succ.hh>
#include <mln/value/prev.hh>
#include <mln/math/mean.hh>
+#include <mln/math/min.hh>
+#include <mln/math/ceil.hh>
+#include <mln/math/floor.hh>
int main()
{
@@ -48,6 +52,10 @@ int main()
// (2.5 + 0.5) / 2 == 1.5
mln_assertion(mean(i, half) == 1 + half);
+ // (2.5 + 2) / 2 = 2.25
+ intsub<4> res = mean(i, intsub<2>(2));
+ mln_assertion(res == 2.25);
+
// i == 3
inc(i);
mln_assertion(i == intsub<2>(3));
@@ -75,4 +83,27 @@ int main()
inc(j);
mln_assertion(j == 6 + quarter);
+ // k = 10.25
+ intsub<8> k(10.25);
+ mln_assertion(k == 10 + quarter);
+
+ // sum(j,k,2) == 18.5
+ mln_assertion(j + k + 2 == 18.5);
+
+ // min(i,l) == 2.5
+ intsub<2> l(2.5);
+ mln_assertion(mln::math::min(i, l) == 2.5);
+
+ // mean(6,2,2.5,3) = 3.375
+ mln_assertion(mean(i, intsub<2>(2), l, intsub<2>(3)) == 3.375);
+
+ // ceil(2.5)
+ mln_assertion(math::ceil(l) == 3);
+ mln_assertion(math::floor(l) == 2);
+
+ // median(6,2,2.5,3) = 2.75
+ mln_assertion(median(i, intsub<2>(2), l, intsub<2>(3)) == 2.75);
+
+ // median(6,2) = 4
+ mln_assertion(median(i, intsub<2>(2)) == 4);
}
--
1.7.2.5
1
0

olena-2.0-95-g12b51e7 mln/value/builtin/ops.hh: Handle all the comparison operators.
by Guillaume Lazzara 04 Oct '12
by Guillaume Lazzara 04 Oct '12
04 Oct '12
---
milena/ChangeLog | 4 ++++
milena/mln/value/builtin/ops.hh | 14 ++++++++++----
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 2f69568..1a5f831 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,9 @@
2012-10-04 Guillaume Lazzara <z(a)lrde.epita.fr>
+ * mln/value/builtin/ops.hh: Handle all the comparison operators.
+
+2012-10-04 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Add mathematical tools.
* mln/fun/vv2v/mean.hh,
diff --git a/milena/mln/value/builtin/ops.hh b/milena/mln/value/builtin/ops.hh
index 1a89052..42ee53a 100644
--- a/milena/mln/value/builtin/ops.hh
+++ b/milena/mln/value/builtin/ops.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009, 2012 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -43,7 +44,7 @@
// into a value::scalar_ (which is a value::Scalar); as a consequence,
// the definition of an object should only handle the single case
// "Object (op) Scalar".
-//
+//
// For instance:
// an expression such as " int * Image<I> "
// is transformed into " I * scalar_<int> "
@@ -297,7 +298,7 @@
} \
\
struct m_a_c_r_o__e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n
-
+
# define mln_internal_builtins_opeq_obj_(De, Symb) \
\
mln_internal_##De##_bi_opeq_obj_(Symb, signed char); \
@@ -603,7 +604,9 @@ namespace mln
// Ops "bi < obj" and "obj < bi"
mln_internal_builtins_op_less_(decl, <, less);
-
+ mln_internal_builtins_op_less_(decl, <=, leq);
+ mln_internal_builtins_op_less_(decl, >, greater);
+ mln_internal_builtins_op_less_(decl, >=, geq);
# ifndef MLN_INCLUDE_ONLY
@@ -642,6 +645,9 @@ namespace mln
// Ops "bi < obj" and "obj < bi"
mln_internal_builtins_op_less_(def, <, less);
+ mln_internal_builtins_op_less_(def, <=, leq);
+ mln_internal_builtins_op_less_(def, >, greater);
+ mln_internal_builtins_op_less_(def, >=, geq);
# endif // ! MLN_INCLUDE_ONLY
--
1.7.2.5
1
0

olena-2.0-36-g0c9847e mln/value/builtin/ops.hh: Handle all the comparison operators.
by Guillaume Lazzara 04 Oct '12
by Guillaume Lazzara 04 Oct '12
04 Oct '12
---
milena/ChangeLog | 4 ++++
milena/mln/value/builtin/ops.hh | 14 ++++++++++----
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 46d712d..b7e9506 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,9 @@
2012-10-04 Guillaume Lazzara <z(a)lrde.epita.fr>
+ * mln/value/builtin/ops.hh: Handle all the comparison operators.
+
+2012-10-04 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Add mathematical tools.
* mln/fun/vv2v/mean.hh,
diff --git a/milena/mln/value/builtin/ops.hh b/milena/mln/value/builtin/ops.hh
index 1a89052..42ee53a 100644
--- a/milena/mln/value/builtin/ops.hh
+++ b/milena/mln/value/builtin/ops.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009, 2012 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -43,7 +44,7 @@
// into a value::scalar_ (which is a value::Scalar); as a consequence,
// the definition of an object should only handle the single case
// "Object (op) Scalar".
-//
+//
// For instance:
// an expression such as " int * Image<I> "
// is transformed into " I * scalar_<int> "
@@ -297,7 +298,7 @@
} \
\
struct m_a_c_r_o__e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n
-
+
# define mln_internal_builtins_opeq_obj_(De, Symb) \
\
mln_internal_##De##_bi_opeq_obj_(Symb, signed char); \
@@ -603,7 +604,9 @@ namespace mln
// Ops "bi < obj" and "obj < bi"
mln_internal_builtins_op_less_(decl, <, less);
-
+ mln_internal_builtins_op_less_(decl, <=, leq);
+ mln_internal_builtins_op_less_(decl, >, greater);
+ mln_internal_builtins_op_less_(decl, >=, geq);
# ifndef MLN_INCLUDE_ONLY
@@ -642,6 +645,9 @@ namespace mln
// Ops "bi < obj" and "obj < bi"
mln_internal_builtins_op_less_(def, <, less);
+ mln_internal_builtins_op_less_(def, <=, leq);
+ mln_internal_builtins_op_less_(def, >, greater);
+ mln_internal_builtins_op_less_(def, >=, geq);
# endif // ! MLN_INCLUDE_ONLY
--
1.7.2.5
1
0
* mln/fun/vv2v/mean.hh,
* mln/fun/vvvv2v/mean.hh,
* mln/math/ceil.hh,
* mln/math/floor.hh,
* mln/math/max.hh,
* mln/math/mean.hh,
* mln/math/min.hh: New.
---
milena/ChangeLog | 12 ++
milena/mln/fun/vv2v/{min.hh => mean.hh} | 26 +++---
milena/mln/fun/{vv2v/min.hh => vvvv2v/mean.hh} | 35 +++----
milena/{sandbox/green => }/mln/math/ceil.hh | 32 ++++--
milena/{sandbox/green => }/mln/math/floor.hh | 30 ++++--
milena/mln/math/max.hh | 23 ++++-
milena/mln/math/mean.hh | 128 ++++++++++++++++++++++++
milena/mln/math/min.hh | 23 ++++-
8 files changed, 247 insertions(+), 62 deletions(-)
copy milena/mln/fun/vv2v/{min.hh => mean.hh} (75%)
copy milena/mln/fun/{vv2v/min.hh => vvvv2v/mean.hh} (66%)
copy milena/{sandbox/green => }/mln/math/ceil.hh (76%)
copy milena/{sandbox/green => }/mln/math/floor.hh (77%)
create mode 100644 milena/mln/math/mean.hh
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 0b2e2cf..2f69568 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,15 @@
+2012-10-04 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Add mathematical tools.
+
+ * mln/fun/vv2v/mean.hh,
+ * mln/fun/vvvv2v/mean.hh,
+ * mln/math/ceil.hh,
+ * mln/math/floor.hh,
+ * mln/math/max.hh,
+ * mln/math/mean.hh,
+ * mln/math/min.hh: New.
+
2012-10-03 Guillaume Lazzara <z(a)lrde.epita.fr>
* tests/world/k1/Makefile.am: Fix target names.
diff --git a/milena/mln/fun/vv2v/min.hh b/milena/mln/fun/vv2v/mean.hh
similarity index 75%
copy from milena/mln/fun/vv2v/min.hh
copy to milena/mln/fun/vv2v/mean.hh
index 0f885fc..510b9a6 100644
--- a/milena/mln/fun/vv2v/min.hh
+++ b/milena/mln/fun/vv2v/mean.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -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_MIN_HH
-# define MLN_FUN_VV2V_MIN_HH
+#ifndef MLN_FUN_VV2V_MEAN_HH
+# define MLN_FUN_VV2V_MEAN_HH
/// \file
///
-/// Functor that computes the minimum of two values.
+/// Functor that computes the mean of two values.
# include <mln/core/concept/function.hh>
-# include <mln/math/min.hh>
+# include <mln/math/mean.hh>
namespace mln
@@ -45,13 +45,13 @@ namespace mln
// FIXME: Doc.
- /// \brief A functor computing the minimum of two values.
+ /// \brief A functor computing the mean of two values.
template <typename L, typename R = L>
- struct min : public Function_vv2v< min<L,R> >,
+ struct mean : public Function_vv2v< mean<L,R> >,
private mlc_converts_to(R,L)::check_t
{
- typedef L result;
- L operator()(const L& v1, const R& v2) const;
+ typedef R result;
+ R operator()(const L& v1, const L& v2) const;
};
@@ -59,10 +59,10 @@ namespace mln
template <typename L, typename R>
inline
- L
- min<L,R>::operator()(const L& v1, const R& v2) const
+ R
+ mean<L,R>::operator()(const L& v1, const L& v2) const
{
- return mln::math::min(v1, L(v2));
+ return R(mln::math::mean(v1, v2);
}
# endif // ! MLN_INCLUDE_ONLY
@@ -74,4 +74,4 @@ namespace mln
} // end of namespace mln
-#endif // ! MLN_FUN_VV2V_MIN_HH
+#endif // ! MLN_FUN_VV2V_MEAN_HH
diff --git a/milena/mln/fun/vv2v/min.hh b/milena/mln/fun/vvvv2v/mean.hh
similarity index 66%
copy from milena/mln/fun/vv2v/min.hh
copy to milena/mln/fun/vvvv2v/mean.hh
index 0f885fc..0dba050 100644
--- a/milena/mln/fun/vv2v/min.hh
+++ b/milena/mln/fun/vvvv2v/mean.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -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_MIN_HH
-# define MLN_FUN_VV2V_MIN_HH
+#ifndef MLN_FUN_VVVV2V_MEAN_HH
+# define MLN_FUN_VVVV2V_MEAN_HH
/// \file
///
-/// Functor that computes the minimum of two values.
+/// Functor that computes the mean of two values.
# include <mln/core/concept/function.hh>
-# include <mln/math/min.hh>
+# include <mln/math/mean.hh>
namespace mln
@@ -40,38 +40,37 @@ namespace mln
namespace fun
{
- namespace vv2v
+ namespace vvvv2v
{
// FIXME: Doc.
- /// \brief A functor computing the minimum of two values.
- template <typename L, typename R = L>
- struct min : public Function_vv2v< min<L,R> >,
- private mlc_converts_to(R,L)::check_t
+ /// \brief A functor computing the mean of two values.
+ template <typename T, typename R=T>
+ struct mean : public Function_vvvv2v< mean<T> >
{
- typedef L result;
- L operator()(const L& v1, const R& v2) const;
+ typedef R result;
+ R operator()(const T& v1, const T& v2, const T& v3, const T& v4) const;
};
# ifndef MLN_INCLUDE_ONLY
- template <typename L, typename R>
+ template <typename T>
inline
- L
- min<L,R>::operator()(const L& v1, const R& v2) const
+ R
+ mean<T,R>::operator()(const T& v1, const T& v2, const T& v3, const T& v4) const
{
- return mln::math::min(v1, L(v2));
+ return R(mln::math::mean(v1, v2, v3, v4));
}
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace mln::fun::vv2v
+ } // end of namespace mln::fun::vvvv2v
} // end of namespace mln::fun
} // end of namespace mln
-#endif // ! MLN_FUN_VV2V_MIN_HH
+#endif // ! MLN_FUN_VVVV2V_MEAN_HH
diff --git a/milena/sandbox/green/mln/math/ceil.hh b/milena/mln/math/ceil.hh
similarity index 76%
copy from milena/sandbox/green/mln/math/ceil.hh
copy to milena/mln/math/ceil.hh
index 6fc08c8..997c8b5 100644
--- a/milena/sandbox/green/mln/math/ceil.hh
+++ b/milena/mln/math/ceil.hh
@@ -1,5 +1,4 @@
-// Copyright (C) 2007, 2008, 2009, 2010
-// EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -29,36 +28,47 @@
/*! \file
*
- * \brief Define the ceil (ceil) routine.
+ * \brief Define ceil routine.
*/
# include <cmath>
-
namespace mln
{
namespace math
{
+ /// Return the nearest integer not less than \p v1.
template <typename T>
- T ceil(const T& v);
+ T ceil(const T& v1);
+
+ } // end of namespace mln::math
# ifndef MLN_INCLUDE_ONLY
+ /// \internal Generic implementation of the ceil function.
+ template <typename T>
+ T ceil_(const T& v1)
+ {
+ return std::ceil(v1);
+ }
+
+ namespace math
+ {
+
template <typename T>
- inline
- T ceil(const T& v)
+ T ceil(const T& v1)
{
- return std::ceil(v);
+ return ceil_(exact(v1));
}
-# endif // ! MLN_INCLUDE_ONLY
-
} // end of namespace mln::math
+# endif // ! MLN_INCLUDE_ONLY
+
} // end of namespace mln
-#endif // ! MLN_MATH_FLOOR_HH
+#endif // ! MLN_MATH_CEIL_HH
diff --git a/milena/sandbox/green/mln/math/floor.hh b/milena/mln/math/floor.hh
similarity index 77%
copy from milena/sandbox/green/mln/math/floor.hh
copy to milena/mln/math/floor.hh
index 97e63bd..defb112 100644
--- a/milena/sandbox/green/mln/math/floor.hh
+++ b/milena/mln/math/floor.hh
@@ -1,5 +1,4 @@
-// Copyright (C) 2007, 2008, 2009, 2010
-// EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -29,35 +28,46 @@
/*! \file
*
- * \brief Define the floor (floor) routine.
+ * \brief Define floor routine.
*/
# include <cmath>
-
namespace mln
{
namespace math
{
+ /// \brief Return the nearest integer not greater than \p v1.
template <typename T>
- T floor(const T& v);
+ T floor(const T& v1);
+
+ } // end of namespace mln::math
# ifndef MLN_INCLUDE_ONLY
+ /// \internal Generic implementation of the floor function.
+ template <typename T>
+ T floor_(const T& v1)
+ {
+ return std::floor(v1);
+ }
+
+ namespace math
+ {
+
template <typename T>
- inline
- T floor(const T& v)
+ T floor(const T& v1)
{
- return std::floor(v);
+ return floor_(exact(v1));
}
-# endif // ! MLN_INCLUDE_ONLY
-
} // end of namespace mln::math
+# endif // ! MLN_INCLUDE_ONLY
+
} // end of namespace mln
diff --git a/milena/mln/math/max.hh b/milena/mln/math/max.hh
index 24f124b..0fe8ea4 100644
--- a/milena/mln/math/max.hh
+++ b/milena/mln/math/max.hh
@@ -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.
//
@@ -38,23 +39,35 @@ namespace mln
namespace math
{
+ /// Return the maximum of two values.
template <typename T>
T max(const T& v1, const T& v2);
+ } // end of namespace mln::math
+
# ifndef MLN_INCLUDE_ONLY
+ /// \internal Generic implementation of the maximum function.
+ template <typename T>
+ T max_(const T& v1, const T& v2)
+ {
+ return v1 > v2 ? v1 : v2;
+ }
+
+ namespace math
+ {
+
template <typename T>
- inline
T max(const T& v1, const T& v2)
{
- return v1 > v2 ? v1 : v2;
+ return max_(exact(v1), exact(v2));
}
-# endif // ! MLN_INCLUDE_ONLY
-
} // end of namespace mln::math
+# endif // ! MLN_INCLUDE_ONLY
+
} // end of namespace mln
diff --git a/milena/mln/math/mean.hh b/milena/mln/math/mean.hh
new file mode 100644
index 0000000..d9c95fc
--- /dev/null
+++ b/milena/mln/math/mean.hh
@@ -0,0 +1,128 @@
+// 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_MEAN_HH
+# define MLN_MATH_MEAN_HH
+
+# include <mln/trait/op/div.hh>
+# include <mln/metal/converts_to.hh>
+
+/*! \file
+ *
+ * \brief Define mean routine.
+ */
+
+
+namespace mln
+{
+
+ namespace math
+ {
+
+ /// Return the mean of two values.
+ template <typename T>
+ mln_trait_op_div(T,double)
+ 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)
+ mean(const T& v1, const U& v2);
+
+ /// Return the mean of four values.
+ template <typename T>
+ mln_trait_op_div(T,double)
+ 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)
+ mean(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 mean of two values.
+ template <typename T>
+ mln_trait_op_div(T,double)
+ mean_(const T& v1, const T& v2)
+ {
+ return (v1 + v2) / 2.;
+ }
+
+ /// \internal Generic implementation of the mean of four values.
+ template <typename T>
+ mln_trait_op_div(T,double)
+ mean_(const T& v1, const T& v2, const T& v3, const T& v4)
+ {
+ return (v1 + v2 + v3 + v4) / 4;
+ }
+
+ namespace math
+ {
+
+ template <typename T>
+ mln_trait_op_div(T,double)
+ mean(const T& v1, const T& v2)
+ {
+ return mean_(exact(v1), exact(v2));
+ }
+
+ template <typename T, typename U>
+ mln_trait_op_div(T,double)
+ mean(const T& v1, const U& v2)
+ {
+ mlc_converts_to(U,T)::check();
+ return mean_(v1, T(v2));
+ }
+
+ template <typename T>
+ mln_trait_op_div(T,double)
+ 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)
+ mean(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 mean_(v1, T(v2), T(v3), T(v4));
+ }
+
+ } // end of namespace mln::math
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MATH_MEAN_HH
diff --git a/milena/mln/math/min.hh b/milena/mln/math/min.hh
index fd81d54..d2a5503 100644
--- a/milena/mln/math/min.hh
+++ b/milena/mln/math/min.hh
@@ -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.
//
@@ -38,23 +39,35 @@ namespace mln
namespace math
{
+ /// Return the minimum of two values.
template <typename T>
T min(const T& v1, const T& v2);
+ } // end of namespace mln::math
+
# ifndef MLN_INCLUDE_ONLY
+ /// \internal Generic implementation of the minimum function.
+ template <typename T>
+ T min_(const T& v1, const T& v2)
+ {
+ return v1 < v2 ? v1 : v2;
+ }
+
+ namespace math
+ {
+
template <typename T>
- inline
T min(const T& v1, const T& v2)
{
- return v1 < v2 ? v1 : v2;
+ return min_(exact(v1), exact(v2));
}
-# endif // ! MLN_INCLUDE_ONLY
-
} // end of namespace mln::math
+# endif // ! MLN_INCLUDE_ONLY
+
} // end of namespace mln
--
1.7.2.5
1
0
* mln/fun/vv2v/mean.hh,
* mln/fun/vvvv2v/mean.hh,
* mln/math/ceil.hh,
* mln/math/floor.hh,
* mln/math/max.hh,
* mln/math/mean.hh,
* mln/math/min.hh: New.
---
milena/ChangeLog | 12 ++
milena/mln/fun/vv2v/{min.hh => mean.hh} | 26 +++---
milena/mln/fun/{vv2v/min.hh => vvvv2v/mean.hh} | 35 +++----
milena/{sandbox/green => }/mln/math/ceil.hh | 32 ++++--
milena/{sandbox/green => }/mln/math/floor.hh | 30 ++++--
milena/mln/math/max.hh | 23 ++++-
milena/mln/math/mean.hh | 128 ++++++++++++++++++++++++
milena/mln/math/min.hh | 23 ++++-
8 files changed, 247 insertions(+), 62 deletions(-)
copy milena/mln/fun/vv2v/{min.hh => mean.hh} (75%)
copy milena/mln/fun/{vv2v/min.hh => vvvv2v/mean.hh} (66%)
copy milena/{sandbox/green => }/mln/math/ceil.hh (76%)
copy milena/{sandbox/green => }/mln/math/floor.hh (77%)
create mode 100644 milena/mln/math/mean.hh
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 08378ab..46d712d 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,15 @@
+2012-10-04 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Add mathematical tools.
+
+ * mln/fun/vv2v/mean.hh,
+ * mln/fun/vvvv2v/mean.hh,
+ * mln/math/ceil.hh,
+ * mln/math/floor.hh,
+ * mln/math/max.hh,
+ * mln/math/mean.hh,
+ * mln/math/min.hh: New.
+
2012-10-03 Guillaume Lazzara <z(a)lrde.epita.fr>
* tests/world/k1/Makefile.am: Fix target names.
diff --git a/milena/mln/fun/vv2v/min.hh b/milena/mln/fun/vv2v/mean.hh
similarity index 75%
copy from milena/mln/fun/vv2v/min.hh
copy to milena/mln/fun/vv2v/mean.hh
index 0f885fc..510b9a6 100644
--- a/milena/mln/fun/vv2v/min.hh
+++ b/milena/mln/fun/vv2v/mean.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -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_MIN_HH
-# define MLN_FUN_VV2V_MIN_HH
+#ifndef MLN_FUN_VV2V_MEAN_HH
+# define MLN_FUN_VV2V_MEAN_HH
/// \file
///
-/// Functor that computes the minimum of two values.
+/// Functor that computes the mean of two values.
# include <mln/core/concept/function.hh>
-# include <mln/math/min.hh>
+# include <mln/math/mean.hh>
namespace mln
@@ -45,13 +45,13 @@ namespace mln
// FIXME: Doc.
- /// \brief A functor computing the minimum of two values.
+ /// \brief A functor computing the mean of two values.
template <typename L, typename R = L>
- struct min : public Function_vv2v< min<L,R> >,
+ struct mean : public Function_vv2v< mean<L,R> >,
private mlc_converts_to(R,L)::check_t
{
- typedef L result;
- L operator()(const L& v1, const R& v2) const;
+ typedef R result;
+ R operator()(const L& v1, const L& v2) const;
};
@@ -59,10 +59,10 @@ namespace mln
template <typename L, typename R>
inline
- L
- min<L,R>::operator()(const L& v1, const R& v2) const
+ R
+ mean<L,R>::operator()(const L& v1, const L& v2) const
{
- return mln::math::min(v1, L(v2));
+ return R(mln::math::mean(v1, v2);
}
# endif // ! MLN_INCLUDE_ONLY
@@ -74,4 +74,4 @@ namespace mln
} // end of namespace mln
-#endif // ! MLN_FUN_VV2V_MIN_HH
+#endif // ! MLN_FUN_VV2V_MEAN_HH
diff --git a/milena/mln/fun/vv2v/min.hh b/milena/mln/fun/vvvv2v/mean.hh
similarity index 66%
copy from milena/mln/fun/vv2v/min.hh
copy to milena/mln/fun/vvvv2v/mean.hh
index 0f885fc..0dba050 100644
--- a/milena/mln/fun/vv2v/min.hh
+++ b/milena/mln/fun/vvvv2v/mean.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -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_MIN_HH
-# define MLN_FUN_VV2V_MIN_HH
+#ifndef MLN_FUN_VVVV2V_MEAN_HH
+# define MLN_FUN_VVVV2V_MEAN_HH
/// \file
///
-/// Functor that computes the minimum of two values.
+/// Functor that computes the mean of two values.
# include <mln/core/concept/function.hh>
-# include <mln/math/min.hh>
+# include <mln/math/mean.hh>
namespace mln
@@ -40,38 +40,37 @@ namespace mln
namespace fun
{
- namespace vv2v
+ namespace vvvv2v
{
// FIXME: Doc.
- /// \brief A functor computing the minimum of two values.
- template <typename L, typename R = L>
- struct min : public Function_vv2v< min<L,R> >,
- private mlc_converts_to(R,L)::check_t
+ /// \brief A functor computing the mean of two values.
+ template <typename T, typename R=T>
+ struct mean : public Function_vvvv2v< mean<T> >
{
- typedef L result;
- L operator()(const L& v1, const R& v2) const;
+ typedef R result;
+ R operator()(const T& v1, const T& v2, const T& v3, const T& v4) const;
};
# ifndef MLN_INCLUDE_ONLY
- template <typename L, typename R>
+ template <typename T>
inline
- L
- min<L,R>::operator()(const L& v1, const R& v2) const
+ R
+ mean<T,R>::operator()(const T& v1, const T& v2, const T& v3, const T& v4) const
{
- return mln::math::min(v1, L(v2));
+ return R(mln::math::mean(v1, v2, v3, v4));
}
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace mln::fun::vv2v
+ } // end of namespace mln::fun::vvvv2v
} // end of namespace mln::fun
} // end of namespace mln
-#endif // ! MLN_FUN_VV2V_MIN_HH
+#endif // ! MLN_FUN_VVVV2V_MEAN_HH
diff --git a/milena/sandbox/green/mln/math/ceil.hh b/milena/mln/math/ceil.hh
similarity index 76%
copy from milena/sandbox/green/mln/math/ceil.hh
copy to milena/mln/math/ceil.hh
index 6fc08c8..997c8b5 100644
--- a/milena/sandbox/green/mln/math/ceil.hh
+++ b/milena/mln/math/ceil.hh
@@ -1,5 +1,4 @@
-// Copyright (C) 2007, 2008, 2009, 2010
-// EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -29,36 +28,47 @@
/*! \file
*
- * \brief Define the ceil (ceil) routine.
+ * \brief Define ceil routine.
*/
# include <cmath>
-
namespace mln
{
namespace math
{
+ /// Return the nearest integer not less than \p v1.
template <typename T>
- T ceil(const T& v);
+ T ceil(const T& v1);
+
+ } // end of namespace mln::math
# ifndef MLN_INCLUDE_ONLY
+ /// \internal Generic implementation of the ceil function.
+ template <typename T>
+ T ceil_(const T& v1)
+ {
+ return std::ceil(v1);
+ }
+
+ namespace math
+ {
+
template <typename T>
- inline
- T ceil(const T& v)
+ T ceil(const T& v1)
{
- return std::ceil(v);
+ return ceil_(exact(v1));
}
-# endif // ! MLN_INCLUDE_ONLY
-
} // end of namespace mln::math
+# endif // ! MLN_INCLUDE_ONLY
+
} // end of namespace mln
-#endif // ! MLN_MATH_FLOOR_HH
+#endif // ! MLN_MATH_CEIL_HH
diff --git a/milena/sandbox/green/mln/math/floor.hh b/milena/mln/math/floor.hh
similarity index 77%
copy from milena/sandbox/green/mln/math/floor.hh
copy to milena/mln/math/floor.hh
index 97e63bd..defb112 100644
--- a/milena/sandbox/green/mln/math/floor.hh
+++ b/milena/mln/math/floor.hh
@@ -1,5 +1,4 @@
-// Copyright (C) 2007, 2008, 2009, 2010
-// EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -29,35 +28,46 @@
/*! \file
*
- * \brief Define the floor (floor) routine.
+ * \brief Define floor routine.
*/
# include <cmath>
-
namespace mln
{
namespace math
{
+ /// \brief Return the nearest integer not greater than \p v1.
template <typename T>
- T floor(const T& v);
+ T floor(const T& v1);
+
+ } // end of namespace mln::math
# ifndef MLN_INCLUDE_ONLY
+ /// \internal Generic implementation of the floor function.
+ template <typename T>
+ T floor_(const T& v1)
+ {
+ return std::floor(v1);
+ }
+
+ namespace math
+ {
+
template <typename T>
- inline
- T floor(const T& v)
+ T floor(const T& v1)
{
- return std::floor(v);
+ return floor_(exact(v1));
}
-# endif // ! MLN_INCLUDE_ONLY
-
} // end of namespace mln::math
+# endif // ! MLN_INCLUDE_ONLY
+
} // end of namespace mln
diff --git a/milena/mln/math/max.hh b/milena/mln/math/max.hh
index 24f124b..0fe8ea4 100644
--- a/milena/mln/math/max.hh
+++ b/milena/mln/math/max.hh
@@ -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.
//
@@ -38,23 +39,35 @@ namespace mln
namespace math
{
+ /// Return the maximum of two values.
template <typename T>
T max(const T& v1, const T& v2);
+ } // end of namespace mln::math
+
# ifndef MLN_INCLUDE_ONLY
+ /// \internal Generic implementation of the maximum function.
+ template <typename T>
+ T max_(const T& v1, const T& v2)
+ {
+ return v1 > v2 ? v1 : v2;
+ }
+
+ namespace math
+ {
+
template <typename T>
- inline
T max(const T& v1, const T& v2)
{
- return v1 > v2 ? v1 : v2;
+ return max_(exact(v1), exact(v2));
}
-# endif // ! MLN_INCLUDE_ONLY
-
} // end of namespace mln::math
+# endif // ! MLN_INCLUDE_ONLY
+
} // end of namespace mln
diff --git a/milena/mln/math/mean.hh b/milena/mln/math/mean.hh
new file mode 100644
index 0000000..d9c95fc
--- /dev/null
+++ b/milena/mln/math/mean.hh
@@ -0,0 +1,128 @@
+// 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_MEAN_HH
+# define MLN_MATH_MEAN_HH
+
+# include <mln/trait/op/div.hh>
+# include <mln/metal/converts_to.hh>
+
+/*! \file
+ *
+ * \brief Define mean routine.
+ */
+
+
+namespace mln
+{
+
+ namespace math
+ {
+
+ /// Return the mean of two values.
+ template <typename T>
+ mln_trait_op_div(T,double)
+ 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)
+ mean(const T& v1, const U& v2);
+
+ /// Return the mean of four values.
+ template <typename T>
+ mln_trait_op_div(T,double)
+ 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)
+ mean(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 mean of two values.
+ template <typename T>
+ mln_trait_op_div(T,double)
+ mean_(const T& v1, const T& v2)
+ {
+ return (v1 + v2) / 2.;
+ }
+
+ /// \internal Generic implementation of the mean of four values.
+ template <typename T>
+ mln_trait_op_div(T,double)
+ mean_(const T& v1, const T& v2, const T& v3, const T& v4)
+ {
+ return (v1 + v2 + v3 + v4) / 4;
+ }
+
+ namespace math
+ {
+
+ template <typename T>
+ mln_trait_op_div(T,double)
+ mean(const T& v1, const T& v2)
+ {
+ return mean_(exact(v1), exact(v2));
+ }
+
+ template <typename T, typename U>
+ mln_trait_op_div(T,double)
+ mean(const T& v1, const U& v2)
+ {
+ mlc_converts_to(U,T)::check();
+ return mean_(v1, T(v2));
+ }
+
+ template <typename T>
+ mln_trait_op_div(T,double)
+ 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)
+ mean(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 mean_(v1, T(v2), T(v3), T(v4));
+ }
+
+ } // end of namespace mln::math
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MATH_MEAN_HH
diff --git a/milena/mln/math/min.hh b/milena/mln/math/min.hh
index fd81d54..d2a5503 100644
--- a/milena/mln/math/min.hh
+++ b/milena/mln/math/min.hh
@@ -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.
//
@@ -38,23 +39,35 @@ namespace mln
namespace math
{
+ /// Return the minimum of two values.
template <typename T>
T min(const T& v1, const T& v2);
+ } // end of namespace mln::math
+
# ifndef MLN_INCLUDE_ONLY
+ /// \internal Generic implementation of the minimum function.
+ template <typename T>
+ T min_(const T& v1, const T& v2)
+ {
+ return v1 < v2 ? v1 : v2;
+ }
+
+ namespace math
+ {
+
template <typename T>
- inline
T min(const T& v1, const T& v2)
{
- return v1 < v2 ? v1 : v2;
+ return min_(exact(v1), exact(v2));
}
-# endif // ! MLN_INCLUDE_ONLY
-
} // end of namespace mln::math
+# endif // ! MLN_INCLUDE_ONLY
+
} // end of namespace mln
--
1.7.2.5
1
0

03 Oct '12
---
milena/ChangeLog | 4 ++++
milena/tests/world/k1/Makefile.am | 2 +-
2 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 24bd25c..08378ab 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,9 @@
2012-10-03 Guillaume Lazzara <z(a)lrde.epita.fr>
+ * tests/world/k1/Makefile.am: Fix target names.
+
+2012-10-03 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Replace unsignedh type by intsub.
* mln/value/unsignedh.hh,
diff --git a/milena/tests/world/k1/Makefile.am b/milena/tests/world/k1/Makefile.am
index 0027267..598d8dd 100644
--- a/milena/tests/world/k1/Makefile.am
+++ b/milena/tests/world/k1/Makefile.am
@@ -38,7 +38,7 @@ check_PROGRAMS = \
un_immerse
display_enlarged_SOURCES = display_enlarged.cc
-fill_0_1_faces_border_SOURCES = fill_0_1_faces_border.cc
+fill_0_1_faces_internal_border_SOURCES = fill_0_1_faces_internal_border.cc
fill_0_from_1_faces_SOURCES = fill_0_from_1_faces.cc
fill_0_from_2_faces_SOURCES = fill_0_from_2_faces.cc
fill_0_from_primary_faces_SOURCES = fill_0_from_primary_faces.cc
--
1.7.2.5
1
0
* mln/value/unsignedh.hh,
* tests/value/unsignedh.cc: Remove.
* mln/value/intsub.hh,
* tests/value/intsub.cc: New.
* tests/value/Makefile.am: Change target name.
---
milena/ChangeLog | 12 +
milena/mln/value/intsub.hh | 569 ++++++++++++++++++++++++
milena/mln/value/unsignedh.hh | 415 -----------------
milena/tests/value/Makefile.am | 4 +-
milena/tests/value/{unsignedh.cc => intsub.cc} | 46 ++-
5 files changed, 623 insertions(+), 423 deletions(-)
create mode 100644 milena/mln/value/intsub.hh
delete mode 100644 milena/mln/value/unsignedh.hh
rename milena/tests/value/{unsignedh.cc => intsub.cc} (65%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index ea274e2..24bd25c 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,17 @@
2012-10-03 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Replace unsignedh type by intsub.
+
+ * mln/value/unsignedh.hh,
+ * tests/value/unsignedh.cc: Remove.
+
+ * mln/value/intsub.hh,
+ * tests/value/intsub.cc: New.
+
+ * tests/value/Makefile.am: Change target name.
+
+2012-10-03 Guillaume Lazzara <z(a)lrde.epita.fr>
+
New routines to browse values into a value set.
* mln/accu/label_used.hh,
diff --git a/milena/mln/value/intsub.hh b/milena/mln/value/intsub.hh
new file mode 100644
index 0000000..fc269a8
--- /dev/null
+++ b/milena/mln/value/intsub.hh
@@ -0,0 +1,569 @@
+// 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_VALUE_INTSUB_HH
+# define MLN_VALUE_INTSUB_HH
+
+/// \file
+///
+/// Define a subdivided integer value class.
+
+# include <cstdlib>
+# include <iostream>
+# include <sstream>
+# include <mln/value/internal/value_like.hh>
+# include <mln/value/internal/encoding.hh>
+# include <mln/value/internal/limits.hh>
+# include <mln/value/concept/integer.hh>
+# include <mln/value/iota.hh>
+# include <mln/value/prev.hh>
+# include <mln/value/succ.hh>
+
+
+namespace mln
+{
+
+ // Forward declaration
+ namespace value {
+ template <unsigned n> class intsub;
+ }
+
+ namespace trait
+ {
+
+ template <unsigned n>
+ struct set_precise_unary_< op::uminus, mln::value::intsub<n> >
+ {
+ typedef mln::value::intsub<n> ret;
+ };
+
+
+ template <unsigned n>
+ struct value_< mln::value::intsub<n> >
+ {
+ private:
+ typedef mln::value::intsub<n> self_;
+ typedef typename mln::value::internal::encoding_signed_<32>::ret enc_;
+ public:
+
+ enum constants_ {
+ dim = 1,
+ nbits = 32,
+ card = mln_value_card_from_(32/n) // FIXME: Really?
+ };
+
+ typedef trait::value::nature::integer nature;
+ typedef trait::value::kind::data kind;
+ typedef mln_value_quant_from_(card) quant;
+
+ static const self_ max() { return mln::value::internal::limits<int>::max() / n; }
+ static const self_ min() { return - max(); }
+ static const self_ epsilon() { return 0; }
+
+ typedef mln::value::intsub<n> comp;
+
+ typedef mln::value::intsub<n> sum;
+
+ static const char* name()
+ {
+ static std::string
+ s = mln::value::internal::make_generic_name("intsub", n);
+ return s.c_str();
+ }
+
+ };
+
+ } // end of namespace mln::trait
+
+
+
+ namespace value
+ {
+
+ template <unsigned n>
+ class intsub
+ : public Integer< intsub<n> >,
+ public internal::value_like_< int, // Equivalent.
+ typename internal::encoding_signed_<32>::ret, // Enc.
+ int, // Interoperation.
+ intsub<n> > // Exact.
+ {
+ public:
+ intsub();
+ intsub(const intsub<n>& rhs);
+ /// Construct an intsub with value : \p int_part + 1 / \p denominator.
+ intsub(int int_part, unsigned denominator);
+ intsub(int i);
+
+ intsub<n>& operator=(const intsub<n>& rhs);
+ intsub<n>& operator=(int i);
+
+ /// Is an integer value.
+ bool is_integer() const;
+
+ /// Convert this intsub to a larger intsub type.
+ template <unsigned m>
+ operator intsub<m>();
+
+ /*! \internal Increment by value::iota::value() the
+ value to the next one.
+ */
+ void inc_();
+ /*! \internal Decrement by value::iota::value() the
+ value to the next one.
+ */
+ void dec_();
+
+ /*!\internal Return the integer part of this value.
+ */
+ int to_int() const;
+
+ /*!\internal Construct a intsub using an encoding value. */
+ static intsub<n> make_from_enc_(int enc);
+
+ /// Unary operator minus.
+ intsub<n> operator-() const;
+
+ };
+
+
+ // Safety
+ template <> struct intsub<0>;
+
+// rounding
+
+ template <unsigned n>
+ intsub<n> floor(const intsub<n>& i);
+ template <unsigned n>
+ intsub<n> ceil(const intsub<n>& i);
+
+
+// comparison
+
+ template <unsigned n>
+ bool operator==(const intsub<n>& l, const intsub<n>& r);
+ template <unsigned n, typename V>
+ bool operator==(const intsub<n>& l, const V& r);
+ template <unsigned n>
+ bool operator<=(const intsub<n>& l, const intsub<n>& r);
+ template <unsigned n>
+ bool operator!=(const intsub<n>& l, const intsub<n>& r);
+ template <unsigned n>
+ bool operator>=(const intsub<n>& l, const intsub<n>& r);
+ template <unsigned n>
+ bool operator>(const intsub<n>& l, const intsub<n>& r);
+ template <unsigned n>
+ bool operator<(const intsub<n>& l, const intsub<n>& r);
+
+// arithmetics
+
+ template <unsigned n>
+ intsub<n> operator+(const intsub<n>& l, const intsub<n>& r);
+ template <unsigned n, typename O>
+ intsub<n> operator+(const intsub<n>& l, const O& r);
+ template <typename O, unsigned n>
+ intsub<n> operator+(const O& r, const intsub<n>& l);
+ template <unsigned n>
+ void operator+=(intsub<n>& l, const intsub<n>& r);
+ template <unsigned n, typename O>
+ void operator+=(intsub<n>& l, const O& r);
+
+ template <unsigned n>
+ intsub<n> operator-(const intsub<n>& l, const intsub<n>& r);
+ template <unsigned n, typename O>
+ intsub<n> operator-(const intsub<n>& l, const O& r);
+ template <typename O, unsigned n>
+ intsub<n> operator-(const O& r, const intsub<n>& l);
+ template <unsigned n>
+ void operator-=(intsub<n>& l, const intsub<n>& r);
+ template <unsigned n, typename O>
+ void operator-=(intsub<n>& l, const O& r);
+
+ template <unsigned n>
+ intsub<n> operator*(const intsub<n>& l, const intsub<n>& r);
+ template <unsigned n, typename O>
+ intsub<n> operator*(const intsub<n>& l, const O& r);
+ template <typename O, unsigned n>
+ intsub<n> operator*(const O& r, const intsub<n>& l);
+ template <unsigned n>
+ void operator*=(intsub<n>& l, const intsub<n>& r);
+ template <unsigned n, typename O>
+ void operator*=(intsub<n>& l, const O& r);
+
+// other ops
+
+ template <unsigned n>
+ intsub<n> min(const intsub<n>& u1, const intsub<n>& u2);
+ template <unsigned n>
+ intsub<n> max(const intsub<n>& u1, const intsub<n>& u2);
+ template <unsigned n>
+ intsub<n> mean(const intsub<n>& v1, const intsub<n>& v2);
+ template <unsigned n>
+ intsub<n> mean(const intsub<n>& v1, const intsub<n>& v2,
+ const intsub<n>& v3, const intsub<n>& v4);
+
+// <<
+
+ template <unsigned n>
+ std::ostream&
+ operator<<(std::ostream& ostr, const intsub<n>& i);
+
+ template <unsigned n>
+ struct iota<intsub<n> >
+ {
+ static intsub<n> value();
+ };
+
+ } // end of namespace mln::value
+
+ extern const value::intsub<2> half;
+ extern const value::intsub<4> quarter;
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // half
+
+# ifndef MLN_WO_GLOBAL_VARS
+
+ const value::intsub<2> half = value::intsub<2>(0, 2);
+ const value::intsub<4> quarter = value::intsub<4>(0, 4);
+
+# endif // ! MLN_WO_GLOBAL_VARS
+
+
+
+ namespace value
+ {
+
+ template <unsigned n>
+ intsub<n>::intsub()
+ {
+ }
+
+ template <unsigned n>
+ intsub<n>::intsub(const intsub<n>& rhs)
+ {
+ this->v_ = rhs.v_;
+ }
+
+ template <unsigned n>
+ intsub<n>::intsub(int i)
+ {
+ this->v_ = n * i;
+ }
+
+ template <unsigned n>
+ intsub<n>::intsub(int int_part, unsigned denominator)
+ {
+ // FIXME: better error handling ?
+ if (denominator > n)
+ std::abort();
+
+ this->v_ = int_part * n + denominator / n;
+ }
+
+
+ template <unsigned n>
+ intsub<n>&
+ intsub<n>::operator=(const intsub<n>& rhs)
+ {
+ this->v_ = rhs.v_;
+ return *this;
+ }
+
+ template <unsigned n>
+ intsub<n>&
+ intsub<n>::operator=(int i)
+ {
+ this->v_ = n * i;
+ return *this;
+ }
+
+ template <unsigned n>
+ intsub<n> intsub<n>::make_from_enc_(int enc)
+ {
+ intsub<n> i;
+ i.v_ = enc;
+ return i;
+ }
+
+ template <unsigned n>
+ bool
+ intsub<n>::is_integer() const
+ {
+ return this->v_ % n == 0;
+ }
+
+ template <unsigned n>
+ template <unsigned m>
+ intsub<n>::operator intsub<m>()
+ {
+ // FIXME: better error handling ?
+ if (n > m)
+ std::abort();
+ return intsub<m>::make_from_enc_(this->v_ * (m / n));
+ }
+
+ template <unsigned n>
+ void
+ intsub<n>::inc_()
+ {
+ this->v_ += iota<intsub<n> >::value().to_enc();
+ }
+
+ template <unsigned n>
+ void
+ intsub<n>::dec_()
+ {
+ this->v_ -= iota<intsub<n> >::value().to_enc();
+ }
+
+ template <unsigned n>
+ int
+ intsub<n>::to_int() const
+ {
+ return this->v_ / n;
+ }
+
+ template <unsigned n>
+ intsub<n>
+ intsub<n>::operator-() const
+ {
+ return intsub<n>::make_from_enc_(this->v_ * -1);
+ }
+
+ // Iota
+ template <unsigned n>
+ intsub<n>
+ iota<intsub<n> >::value()
+ {
+ return intsub<n>(0,n);
+ }
+
+
+// rounding
+
+
+ template <unsigned n>
+ intsub<n> floor(const intsub<n>& i)
+ {
+ return i.is_integer() ? i : value::prev(i);
+ }
+
+ template <unsigned n>
+ intsub<n> ceil(const intsub<n>& i)
+ {
+ return i.is_integer() ? i : value::succ(i);
+ }
+
+
+
+// comparison
+
+ template <unsigned n>
+ bool operator==(const intsub<n>& l, const intsub<n>& r)
+ {
+ return l.to_enc() == r.to_enc();
+ }
+
+ template <unsigned n>
+ bool operator==(const intsub<n>& l, const int& r)
+ {
+ return l == intsub<n>(r);
+ }
+
+ template <unsigned n>
+ bool operator<=(const intsub<n>& l, const intsub<n>& r)
+ {
+ return l.to_enc() <= r.to_enc();
+ }
+
+ template <unsigned n>
+ bool operator!=(const intsub<n>& l, const intsub<n>& r)
+ {
+ return ! (l == r);
+ }
+
+ template <unsigned n>
+ bool operator>=(const intsub<n>& l, const intsub<n>& r)
+ {
+ return r <= l;
+ }
+
+ template <unsigned n>
+ bool operator>(const intsub<n>& l, const intsub<n>& r)
+ {
+ return ! (l <= r);
+ }
+
+ template <unsigned n>
+ bool operator<(const intsub<n>& l, const intsub<n>& r)
+ {
+ return r > l;
+ }
+
+
+// arithmetics
+
+ template <unsigned n>
+ intsub<n> operator+(const intsub<n>& l, const intsub<n>& r)
+ {
+ return intsub<n>::make_from_enc_(l.to_enc() + r.to_enc());
+ }
+
+ template <unsigned n>
+ intsub<n> operator+(const intsub<n>& l, int r)
+ {
+ return l + intsub<n>(r);
+ }
+
+ template <unsigned n>
+ intsub<n> operator+(int l, const intsub<n>& r)
+ {
+ return r + l;
+ }
+
+ template <unsigned n>
+ void operator+=(intsub<n>& l, const intsub<n>& r)
+ {
+ l = l + r;
+ }
+
+ template <unsigned n>
+ void operator+=(intsub<n>& l, int r)
+ {
+ l = l + intsub<n>(r);
+ }
+
+ template <unsigned n>
+ intsub<n> operator-(const intsub<n>& l, const intsub<n>& r)
+ {
+ return intsub<n>::make_from_enc_(l.to_enc() - r.to_enc());
+ }
+
+ template <unsigned n>
+ intsub<n> operator-(const intsub<n>& l, int r)
+ {
+ return l - intsub<n>(r);
+ }
+
+ template <unsigned n>
+ intsub<n> operator-(int l, const intsub<n>& r)
+ {
+ return - r + l;
+ }
+
+ template <unsigned n>
+ void operator-=(intsub<n>& l, const intsub<n>& r)
+ {
+ l = l - r;
+ }
+
+ template <unsigned n>
+ void operator-=(intsub<n>& l, int r)
+ {
+ l = l - intsub<n>(r);
+ }
+
+ template <unsigned n>
+ intsub<n> operator*(const intsub<n>& l, const intsub<n>& r)
+ {
+ return intsub<n>::make_from_enc_(l.to_enc() * r.to_enc() / n);
+ }
+
+ template <unsigned n>
+ intsub<n> operator*(const intsub<n>& l, int r)
+ {
+ return l * intsub<n>(r);
+ }
+
+ template <unsigned n>
+ intsub<n> operator*(int l, const intsub<n>& r)
+ {
+ return r * l;
+ }
+
+ template <unsigned n>
+ void operator*=(intsub<n>& l, const intsub<n>& r)
+ {
+ l = l * r;
+ }
+
+ template <unsigned n>
+ void operator*=(intsub<n>& l, int r)
+ {
+ l = l * intsub<n>(r);
+ }
+
+
+// other ops
+
+ template <unsigned n>
+ intsub<n> min(const intsub<n>& v1, const intsub<n>& v2)
+ {
+ return intsub<n>::make_from_enc_(v1.to_enc() < v2.to_enc() ? v1.to_enc() : v2.to_enc());
+ }
+
+ template <unsigned n>
+ intsub<n> max(const intsub<n>& v1, const intsub<n>& v2)
+ {
+ return intsub<n>::make_from_enc_(v1.to_enc() > v2.to_enc() ? v1.to_enc() : v2.to_enc());
+ }
+
+ template <unsigned n>
+ intsub<n> mean(const intsub<n>& v1, const intsub<n>& v2)
+ {
+ return intsub<n>::make_from_enc_((v1.to_enc() + v2.to_enc()) / 2);
+ }
+
+ template <unsigned n>
+ intsub<n> mean(const intsub<n>& v1, const intsub<n>& v2,
+ const intsub<n>& v3, const intsub<n>& v4)
+ {
+ return intsub<n>::make_from_enc_((v1.to_enc() + v2.to_enc()
+ + v3.to_enc() + v4.to_enc()) / 4);
+ }
+
+
+// <<
+
+ template <unsigned n>
+ std::ostream&
+ operator<<(std::ostream& ostr, const intsub<n>& i)
+ {
+ if (i.is_integer())
+ return ostr << i.to_int();
+ else
+ return ostr << floor(i).to_int() << ".5";
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+#endif // ! MLN_VALUE_INTSUB_HH
diff --git a/milena/mln/value/unsignedh.hh b/milena/mln/value/unsignedh.hh
deleted file mode 100644
index 1f0281c..0000000
--- a/milena/mln/value/unsignedh.hh
+++ /dev/null
@@ -1,415 +0,0 @@
-// 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_VALUE_UNSIGNEDH_HH
-# define MLN_VALUE_UNSIGNEDH_HH
-
-/// \file
-///
-/// Define a semi-unsigned value class.
-
-# include <cstdlib>
-# include <iostream>
-# include <sstream>
-
-// FIXME: parameterize unsignedh so that we also can have
-// Z/4 and so on...
-
-namespace mln
-{
-
- namespace value
- {
-
-
- class unsignedh
- {
- public:
- unsignedh();
- unsignedh(const unsignedh& rhs);
- unsignedh(unsigned i);
- unsignedh(int i);
-
- unsignedh& operator=(const unsignedh& rhs);
- unsignedh& operator=(unsigned i);
- unsignedh& operator=(int i);
-
- unsigned enc() const;
-
- /// Construct an unsignedh with value v
- static unsignedh make(unsigned v);
- /// Construct an unsignedh with value v. The given value is
- /// rounded to the closest integer or half value.
-// static unsignedh make(float v);
-
- bool is_integer() const;
-
- unsigned to_unsigned() const;
-
- /// Set this unsignedh to its next value and return itself.
- unsignedh& goto_succ();
-
- /// Set this unsignedh to its previous value and return itself.
- unsignedh& goto_pred();
-
- operator std::string() const;
-
- private:
- unsigned enc_;
- };
-
-
- extern const unsignedh half;
-
-
-// next
-
- unsignedh succ(unsignedh i);
- unsignedh pred(unsignedh i);
-
-// rounding
-
- unsignedh floor(unsignedh i);
- unsignedh ceil(unsignedh i);
-
-
-// comparison
-
- bool operator==(unsignedh l, unsignedh r);
- bool operator<=(unsignedh l, unsignedh r);
- bool operator!=(unsignedh l, unsignedh r);
- bool operator>=(unsignedh l, unsignedh r);
- bool operator>(unsignedh l, unsignedh r);
- bool operator<(unsignedh l, unsignedh r);
-
-// arithmetics
-
- unsignedh operator+(unsignedh l, unsignedh r);
- void operator+=(unsignedh& l, unsignedh r);
- unsignedh operator-(unsignedh l, unsignedh r);
- void operator-=(unsignedh& l, unsignedh r);
- unsignedh operator/(unsignedh l, unsigned r);
-
-// other ops
-
- unsignedh min(unsignedh u1, unsignedh u2);
- unsignedh max(unsignedh u1, unsignedh u2);
- unsignedh mean(unsignedh u1, unsignedh u2);
-
-// for a transparent use of both unsigned and unsignedh
-// FIXME: is it useful?
-
- unsigned decode(unsigned u);
- void encode(unsigned u, unsigned& dst);
- unsigned decode(unsignedh u);
- void encode(unsigned u, unsignedh& dst);
-
-// <<
-
- std::ostream&
- operator<<(std::ostream& ostr, const unsignedh& i);
-
-
-# ifndef MLN_INCLUDE_ONLY
-
- inline
- unsignedh::unsignedh()
- {
- }
-
- inline
- unsignedh::unsignedh(const unsignedh& rhs)
- : enc_(rhs.enc_)
- {
- }
-
-
- inline
- unsignedh::unsignedh(unsigned i)
- {
- enc_ = 2 * i;
- }
-
- inline
- unsignedh::unsignedh(int i)
- {
- if (i < 0)
- std::abort();
- enc_ = 2 * i;
- }
-
- inline
- unsignedh&
- unsignedh::operator=(const unsignedh& rhs)
- {
- enc_ = rhs.enc_;
- return *this;
- }
-
- inline
- unsignedh&
- unsignedh::operator=(unsigned i)
- {
- enc_ = 2 * i;
- return *this;
- }
-
- inline
- unsignedh&
- unsignedh::operator=(int i)
- {
- if (i < 0)
- std::abort();
- enc_ = 2 * i;
- return *this;
- }
-
- inline
- unsigned
- unsignedh::enc() const
- {
- return enc_;
- }
-
- inline
- unsignedh unsignedh::make(unsigned enc)
- {
- unsignedh i;
- i.enc_ = enc;
- return i;
- }
-
- inline
- bool
- unsignedh::is_integer() const
- {
- return enc_ % 2 == 0;
- }
-
- inline
- unsigned
- unsignedh::to_unsigned() const
- {
- if (! this->is_integer())
- std::abort();
- return enc_ / 2;
- }
-
- inline
- unsignedh&
- unsignedh::goto_succ()
- {
- enc_ += 1;
- return *this;
- }
-
- inline
- unsignedh&
- unsignedh::goto_pred()
- {
- if (enc_ == 0)
- std::abort();
- enc_ -= 1;
- return *this;
- }
-
- inline
- unsignedh::operator std::string() const
- {
- std::stringstream s;
- s << *this;
- return s.str();
- }
-
-
-
-// half
-
-# ifndef MLN_WO_GLOBAL_VARS
-
- const unsignedh half = unsignedh::make(1u);
-
-# endif // ! MLN_WO_GLOBAL_VARS
-
-
-// next
-
- unsignedh succ(unsignedh i)
- {
- return unsignedh::make(i.enc() + 1);
- }
-
- unsignedh pred(unsignedh i)
- {
- if (i.enc() == 0)
- std::abort();
- return unsignedh::make(i.enc() - 1);
- }
-
-
-
-// rounding
-
- unsignedh floor(unsignedh i)
- {
- return i.is_integer() ? i : pred(i);
- }
-
- unsignedh ceil(unsignedh i)
- {
- return i.is_integer() ? i : succ(i);
- }
-
-
-
-// comparison
-
- bool operator==(unsignedh l, unsignedh r)
- {
- return l.enc() == r.enc();
- }
-
- bool operator<=(unsignedh l, unsignedh r)
- {
- return l.enc() <= r.enc();
- }
-
- bool operator!=(unsignedh l, unsignedh r)
- {
- return ! (l == r);
- }
-
- bool operator>=(unsignedh l, unsignedh r)
- {
- return r <= l;
- }
-
- bool operator>(unsignedh l, unsignedh r)
- {
- return ! (l <= r);
- }
-
- bool operator<(unsignedh l, unsignedh r)
- {
- return r > l;
- }
-
-
-
-// arithmetics
-
- unsignedh operator+(unsignedh l, unsignedh r)
- {
- return unsignedh::make(l.enc() + r.enc());
- }
-
- void operator+=(unsignedh& l, unsignedh r)
- {
- l = l + r;
- }
-
- unsignedh operator-(unsignedh l, unsignedh r)
- {
- if (r > l)
- std::abort();
- return unsignedh::make(l.enc() - r.enc());
- }
-
- void operator-=(unsignedh& l, unsignedh r)
- {
- if (r > l)
- std::abort();
- l = l - r;
- }
-
- unsignedh operator/(unsignedh l, unsigned r)
- {
- if (l.enc() % r != 0)
- std::abort();
- return unsignedh::make(l.enc() / r);
- }
-
-
-
-// other ops
-
- unsignedh min(unsignedh u1, unsignedh u2)
- {
- return unsignedh::make(u1.enc() < u2.enc() ? u1.enc() : u2.enc());
- }
-
- unsignedh max(unsignedh u1, unsignedh u2)
- {
- return unsignedh::make(u1.enc() > u2.enc() ? u1.enc() : u2.enc());
- }
-
- unsignedh mean(unsignedh u1, unsignedh u2)
- {
- return (u1 + u2) / 2;
- }
-
-
-// for a transparent use of both unsigned and unsignedh
-// FIXME: is it useful?
-
- unsigned decode(unsigned u)
- {
- return u;
- }
-
- void encode(unsigned u, unsigned& dst)
- {
- dst = u;
- }
-
- unsigned decode(unsignedh u)
- {
- return u.enc();
- }
-
- void encode(unsigned u, unsignedh& dst)
- {
- dst = unsignedh::make(u);
- }
-
-
-// <<
-
- std::ostream&
- operator<<(std::ostream& ostr, const unsignedh& i)
- {
- if (i.is_integer())
- return ostr << i.to_unsigned();
- else
- return ostr << floor(i).to_unsigned() << ".5";
- }
-
-# endif // ! MLN_INCLUDE_ONLY
-
- } // end of namespace mln::value
-
-} // end of namespace mln
-
-#endif // ndef UNSIGNEDH_HH
diff --git a/milena/tests/value/Makefile.am b/milena/tests/value/Makefile.am
index fb654fa..8d6718f 100644
--- a/milena/tests/value/Makefile.am
+++ b/milena/tests/value/Makefile.am
@@ -36,7 +36,7 @@ check_PROGRAMS = \
scalar \
set \
sign \
- unsignedh
+ intsub
# float01
# float01_bis
# float01_f
@@ -61,7 +61,7 @@ rgb8_SOURCES = rgb8.cc
scalar_SOURCES = scalar.cc
set_SOURCES = set.cc
sign_SOURCES = sign.cc
-unsignedh_SOURCES = unsignedh.cc
+intsub_SOURCES = intsub.cc
#<<lrde
# FIXME: Not distributed (yet).
diff --git a/milena/tests/value/unsignedh.cc b/milena/tests/value/intsub.cc
similarity index 65%
rename from milena/tests/value/unsignedh.cc
rename to milena/tests/value/intsub.cc
index ca98a59..e324fe3 100644
--- a/milena/tests/value/unsignedh.cc
+++ b/milena/tests/value/intsub.cc
@@ -26,19 +26,53 @@
/// \file
#include <cassert>
-#include <mln/value/unsignedh.hh>
-
+#include <mln/value/intsub.hh>
+#include <mln/value/inc.hh>
+#include <mln/value/dec.hh>
+#include <mln/value/succ.hh>
+#include <mln/value/prev.hh>
+#include <mln/math/mean.hh>
int main()
{
+ using namespace mln;
using namespace mln::value;
- unsignedh i = 2;
- i.goto_succ();
+ // i == 2
+ intsub<2> i = 2;
+ inc(i);
// i == 2.5
- assert(i == 2 + half);
+ mln_assertion(i == half + 2);
// (2.5 + 0.5) / 2 == 1.5
- assert(mean(i, half) == 1 + half);
+ mln_assertion(mean(i, half) == 1 + half);
+
+ // i == 3
+ inc(i);
+ mln_assertion(i == intsub<2>(3));
+
+ // i == 2.5
+ dec(i);
+ mln_assertion(i == intsub<2>(2,2));
+ dec(i);
+
+ // i == 2.5
+ mln_assertion(succ(i) == 2 + half);
+
+ // i == 1.5
+ mln_assertion(prev(i) == 2 - half);
+
+ // i == 6
+ i *= 3;
+ mln_assertion(i == 6);
+
+ // j = 6
+ intsub<4> j = i;
+ mln_assertion(j == 6);
+
+ // j = 6.25
+ inc(j);
+ mln_assertion(j == 6 + quarter);
+
}
--
1.7.2.5
1
0
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/moravec has been created
at 53b274c8427ab68df0439ec68ef3af9361d64f17 (commit)
- Log -----------------------------------------------------------------
53b274c Configure Makefiles under milena/tests/detection.
f7be478 Add test for Moravec corner detection.
63675c3 Add Moravec corner detection.
-----------------------------------------------------------------------
hooks/post-receive
--
Olena, a generic and efficient image processing platform
1
0

olena-2.0-32-ge5977cb New routines to browse values into a value set.
by Guillaume Lazzara 03 Oct '12
by Guillaume Lazzara 03 Oct '12
03 Oct '12
* mln/accu/label_used.hh,
* mln/core/internal/labeled_image_base.hh,
* mln/labeling/colorize.hh,
* mln/labeling/compute.hh,
* mln/labeling/superpose.hh,
* mln/make/relabelfun.hh,
* mln/set/compute_with_weights.hh,
* mln/value/label.hh,
* mln/value/range.hh: Rename value::next to value::succ.
* mln/value/dec.hh,
* mln/value/inc.hh,
* mln/value/iota.hh,
* mln/value/next.hh,
* mln/value/prev.hh,
* mln/value/succ.hh: New.
---
milena/ChangeLog | 21 ++++++
milena/mln/accu/label_used.hh | 2 +-
milena/mln/core/internal/labeled_image_base.hh | 2 +-
milena/mln/labeling/colorize.hh | 2 +-
milena/mln/labeling/compute.hh | 22 +++---
milena/mln/labeling/superpose.hh | 2 +-
milena/mln/make/relabelfun.hh | 4 +-
milena/mln/set/compute_with_weights.hh | 2 +-
milena/mln/value/{next.hh => dec.hh} | 66 +++++++-------------
milena/mln/value/{next.hh => inc.hh} | 66 +++++++-------------
.../{world/k1/is_0_or_1_face.hh => value/iota.hh} | 59 ++++++++++--------
milena/mln/value/label.hh | 8 +-
milena/mln/value/{next.hh => prev.hh} | 54 ++++++----------
milena/mln/value/range.hh | 4 +-
milena/mln/value/{next.hh => succ.hh} | 51 +++++----------
15 files changed, 162 insertions(+), 203 deletions(-)
copy milena/mln/value/{next.hh => dec.hh} (68%)
copy milena/mln/value/{next.hh => inc.hh} (68%)
copy milena/mln/{world/k1/is_0_or_1_face.hh => value/iota.hh} (64%)
copy milena/mln/value/{next.hh => prev.hh} (69%)
rename milena/mln/value/{next.hh => succ.hh} (72%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 4ff88af..ea274e2 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,24 @@
+2012-10-03 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ New routines to browse values into a value set.
+
+ * mln/accu/label_used.hh,
+ * mln/core/internal/labeled_image_base.hh,
+ * mln/labeling/colorize.hh,
+ * mln/labeling/compute.hh,
+ * mln/labeling/superpose.hh,
+ * mln/make/relabelfun.hh,
+ * mln/set/compute_with_weights.hh,
+ * mln/value/label.hh,
+ * mln/value/range.hh: Rename value::next to value::succ.
+
+ * mln/value/dec.hh,
+ * mln/value/inc.hh,
+ * mln/value/iota.hh,
+ * mln/value/next.hh,
+ * mln/value/prev.hh,
+ * mln/value/succ.hh: New.
+
2012-09-28 Guillaume Lazzara <z(a)lrde.epita.fr>
New value types.
diff --git a/milena/mln/accu/label_used.hh b/milena/mln/accu/label_used.hh
index 69121b1..37fb459 100644
--- a/milena/mln/accu/label_used.hh
+++ b/milena/mln/accu/label_used.hh
@@ -118,7 +118,7 @@ namespace mln
label_used<L>::take(const argument& l)
{
if (label_used_.size() <= l)
- label_used_.resize(value::next(l), false);
+ label_used_.resize(value::succ(l), false);
label_used_(l) = true;
}
diff --git a/milena/mln/core/internal/labeled_image_base.hh b/milena/mln/core/internal/labeled_image_base.hh
index 45f3ed2..a80e5b8 100644
--- a/milena/mln/core/internal/labeled_image_base.hh
+++ b/milena/mln/core/internal/labeled_image_base.hh
@@ -281,7 +281,7 @@ namespace mln
labeled_image_base<I,E>::update_data(const fun::i2v::array<mln_value(I)>& relabel_fun)
{
util::array<accu::shape::bbox<mln_psite(I)> >
- new_bboxes(mln::value::next(this->data_->nlabels_));
+ new_bboxes(mln::value::succ(this->data_->nlabels_));
exact(this)->init_update_data_();
diff --git a/milena/mln/labeling/colorize.hh b/milena/mln/labeling/colorize.hh
index ddfbb15..ba876a7 100644
--- a/milena/mln/labeling/colorize.hh
+++ b/milena/mln/labeling/colorize.hh
@@ -198,7 +198,7 @@ namespace mln
// mlc_is_a(mln_value(L), mln::value::Symbolic)::check();
(void) value;
- unsigned label_count = value::next(nlabels);
+ unsigned label_count = value::succ(nlabels);
static fun::i2v::array<V> f(0);
int diff_size = f.size() - label_count;
if (diff_size < 0)
diff --git a/milena/mln/labeling/compute.hh b/milena/mln/labeling/compute.hh
index a9dc791..4ad48b5 100644
--- a/milena/mln/labeling/compute.hh
+++ b/milena/mln/labeling/compute.hh
@@ -211,7 +211,7 @@ namespace mln
const A& a = exact(a_);
const L& label = exact(label_);
- util::array<A> accus(value::next(nlabels), a);
+ util::array<A> accus(value::succ(nlabels), a);
mln_piter(L) p(label.domain());
for_all(p)
@@ -245,12 +245,12 @@ namespace mln
trace::entering("labeling::impl::generic::compute");
internal::compute_tests(A(), label_, nlabels);
- if (value::next(nlabels) != accus.size())
+ if (value::succ(nlabels) != accus.size())
{
accus.resize(0); // Make sure all the accumulators are
// re-initialized when resizing on next
// line.
- accus.resize(value::next(nlabels));
+ accus.resize(value::succ(nlabels));
}
const L& label = exact(label_);
@@ -292,7 +292,7 @@ namespace mln
const I& input = exact(input_);
const L& label = exact(label_);
- util::array<A> accus(value::next(nlabels), a);
+ util::array<A> accus(value::succ(nlabels), a);
mln_piter(I) p(input.domain());
for_all(p)
@@ -331,12 +331,12 @@ namespace mln
const L& label = exact(label_);
(void) nlabels;
- if (value::next(nlabels) != accus.size())
+ if (value::succ(nlabels) != accus.size())
{
accus.resize(0); // Make sure all the accumulators are
// re-initialized when resizing on next
// line.
- accus.resize(value::next(nlabels));
+ accus.resize(value::succ(nlabels));
}
mln_piter(I) p(input.domain());
@@ -384,7 +384,7 @@ namespace mln
// FIXME: check image properties + add doc.
- util::array<A> accus(value::next(nlabels), a);
+ util::array<A> accus(value::succ(nlabels), a);
unsigned ncols = geom::ncols(label);
@@ -439,12 +439,12 @@ namespace mln
const L& label = exact(label_);
(void) nlabels;
- if (value::next(nlabels) != accus.size())
+ if (value::succ(nlabels) != accus.size())
{
accus.resize(0); // Make sure all the accumulators are
// re-initialized when resizing on next
// line.
- accus.resize(value::next(nlabels));
+ accus.resize(value::succ(nlabels));
}
unsigned ncols = geom::ncols(label);
@@ -757,7 +757,7 @@ namespace mln
typedef util::array<mln_result(A)> R;
R res = internal::compute_dispatch(accus, label, nlabels);
- mln_postcondition(res.nelements() == value::next(nlabels));
+ mln_postcondition(res.nelements() == value::succ(nlabels));
trace::exiting("labeling::compute");
return res;
@@ -779,7 +779,7 @@ namespace mln
typedef util::array<mln_result(A)> R;
R res = internal::compute_dispatch(a, label, nlabels);
- mln_postcondition(res.nelements() == value::next(nlabels));
+ mln_postcondition(res.nelements() == value::succ(nlabels));
trace::exiting("labeling::compute");
return res;
diff --git a/milena/mln/labeling/superpose.hh b/milena/mln/labeling/superpose.hh
index 1df647c..e063912 100644
--- a/milena/mln/labeling/superpose.hh
+++ b/milena/mln/labeling/superpose.hh
@@ -98,7 +98,7 @@ namespace mln
mln_concrete(I) output = duplicate(lhs);
util::array<mln_value(J)>
- rebase_lbl(value::next(rhs_nlabels));
+ rebase_lbl(value::succ(rhs_nlabels));
rebase_lbl(0) = 0;
for (unsigned i = 1; i <= rhs_nlabels; ++i)
diff --git a/milena/mln/make/relabelfun.hh b/milena/mln/make/relabelfun.hh
index bc423fb..3ec38cb 100644
--- a/milena/mln/make/relabelfun.hh
+++ b/milena/mln/make/relabelfun.hh
@@ -88,7 +88,7 @@ namespace mln
const F& fv2b = exact(fv2b_);
- unsigned nlabels_i = value::next(nlabels);
+ unsigned nlabels_i = value::succ(nlabels);
V tmp_nlabels = literal::zero;
fun::i2v::array<V> fi2v(nlabels_i, literal::zero);
for (V i = 1; i < nlabels_i; ++i)
@@ -111,7 +111,7 @@ namespace mln
const F& fv2v = exact(fv2v_);
- unsigned nlabels_i = value::next(nlabels);
+ unsigned nlabels_i = value::succ(nlabels);
util::array<V> new_labels(nlabels_i, mln_max(V));
new_labels(0) = literal::zero;
diff --git a/milena/mln/set/compute_with_weights.hh b/milena/mln/set/compute_with_weights.hh
index 24da256..2612498 100644
--- a/milena/mln/set/compute_with_weights.hh
+++ b/milena/mln/set/compute_with_weights.hh
@@ -189,7 +189,7 @@ namespace mln
internal::compute_with_weights_tests(a, w, label);
- util::array<A> accus(value::next(nlabels), a);
+ util::array<A> accus(value::succ(nlabels), a);
mln_piter(I) p(w.domain());
for_all(p)
diff --git a/milena/mln/value/next.hh b/milena/mln/value/dec.hh
similarity index 68%
copy from milena/mln/value/next.hh
copy to milena/mln/value/dec.hh
index b9bc06e..7b0e05b 100644
--- a/milena/mln/value/next.hh
+++ b/milena/mln/value/dec.hh
@@ -24,15 +24,15 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_VALUE_NEXT_HH
-# define MLN_VALUE_NEXT_HH
+#ifndef MLN_VALUE_DEC_HH
+# define MLN_VALUE_DEC_HH
/// \file
///
-/// Return the next value.
+/// Return the dec value.
+# include <mln/value/iota.hh>
# include <mln/value/label.hh>
-# include <mln/value/unsignedh.hh>
namespace mln
@@ -42,8 +42,8 @@ namespace mln
{
template <typename V>
- V
- next(const V&);
+ void
+ dec(V&);
# ifndef MLN_INCLUDE_ONLY
@@ -58,30 +58,20 @@ namespace mln
{
template <typename V>
- inline
- V
- next(const V& v)
+ void
+ dec(V& v)
{
- return v + 1;
+ v -= mln::value::iota<V>::value();
}
} // end of namespace mln::value::implementation::generic
- template <unsigned n>
- inline
- mln::value::label<n>
- next_label(const mln::value::label<n>& v)
- {
- return v.next();
- }
-
-
- inline
- mln::value::unsignedh
- next_unsignedh(const mln::value::unsignedh& v)
+ template <typename V>
+ void
+ dec_label(V& v)
{
- return mln::value::succ(v);
+ --v;
}
} // end of namespace mln::value::implementation
@@ -94,26 +84,17 @@ namespace mln
{
template <unsigned n>
- inline
- label<n>
- next_dispatch(const label<n>& v)
- {
- return implementation::next_label(v);
- }
-
- inline
- unsignedh
- next_dispatch(const unsignedh& v)
+ void
+ dec_dispatch(label<n>& v)
{
- return implementation::next_unsignedh(v);
+ implementation::dec_label(v);
}
template <typename V>
- inline
- V
- next_dispatch(const V& v)
+ void
+ dec_dispatch(V& v)
{
- return implementation::generic::next(v);
+ implementation::generic::dec(v);
}
} // end of namespace mln::value::internal
@@ -123,11 +104,10 @@ namespace mln
// Facade
template <typename V>
- inline
- V
- next(const V& v)
+ void
+ dec(V& v)
{
- return internal::next_dispatch(v);
+ internal::dec_dispatch(v);
}
@@ -138,4 +118,4 @@ namespace mln
} // end of namespace mln
-#endif // ! MLN_VALUE_NEXT_HH
+#endif // ! MLN_VALUE_DEC_HH
diff --git a/milena/mln/value/next.hh b/milena/mln/value/inc.hh
similarity index 68%
copy from milena/mln/value/next.hh
copy to milena/mln/value/inc.hh
index b9bc06e..80fc625 100644
--- a/milena/mln/value/next.hh
+++ b/milena/mln/value/inc.hh
@@ -24,15 +24,15 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_VALUE_NEXT_HH
-# define MLN_VALUE_NEXT_HH
+#ifndef MLN_VALUE_INC_HH
+# define MLN_VALUE_INC_HH
/// \file
///
-/// Return the next value.
+/// Return the inc value.
+# include <mln/value/iota.hh>
# include <mln/value/label.hh>
-# include <mln/value/unsignedh.hh>
namespace mln
@@ -42,8 +42,8 @@ namespace mln
{
template <typename V>
- V
- next(const V&);
+ void
+ inc(V&);
# ifndef MLN_INCLUDE_ONLY
@@ -58,30 +58,20 @@ namespace mln
{
template <typename V>
- inline
- V
- next(const V& v)
+ void
+ inc(V& v)
{
- return v + 1;
+ v += mln::value::iota<V>::value();
}
} // end of namespace mln::value::implementation::generic
- template <unsigned n>
- inline
- mln::value::label<n>
- next_label(const mln::value::label<n>& v)
- {
- return v.next();
- }
-
-
- inline
- mln::value::unsignedh
- next_unsignedh(const mln::value::unsignedh& v)
+ template <typename V>
+ void
+ inc_label(V& v)
{
- return mln::value::succ(v);
+ ++v;
}
} // end of namespace mln::value::implementation
@@ -94,26 +84,17 @@ namespace mln
{
template <unsigned n>
- inline
- label<n>
- next_dispatch(const label<n>& v)
- {
- return implementation::next_label(v);
- }
-
- inline
- unsignedh
- next_dispatch(const unsignedh& v)
+ void
+ inc_dispatch(label<n>& v)
{
- return implementation::next_unsignedh(v);
+ implementation::inc_label(v);
}
template <typename V>
- inline
- V
- next_dispatch(const V& v)
+ void
+ inc_dispatch(V& v)
{
- return implementation::generic::next(v);
+ implementation::generic::inc(v);
}
} // end of namespace mln::value::internal
@@ -123,11 +104,10 @@ namespace mln
// Facade
template <typename V>
- inline
- V
- next(const V& v)
+ void
+ inc(V& v)
{
- return internal::next_dispatch(v);
+ internal::inc_dispatch(v);
}
@@ -138,4 +118,4 @@ namespace mln
} // end of namespace mln
-#endif // ! MLN_VALUE_NEXT_HH
+#endif // ! MLN_VALUE_INC_HH
diff --git a/milena/mln/world/k1/is_0_or_1_face.hh b/milena/mln/value/iota.hh
similarity index 64%
copy from milena/mln/world/k1/is_0_or_1_face.hh
copy to milena/mln/value/iota.hh
index 6f3f47a..bdad60c 100644
--- a/milena/mln/world/k1/is_0_or_1_face.hh
+++ b/milena/mln/value/iota.hh
@@ -23,49 +23,58 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
+#ifndef MLN_VALUE_IOTA_HH
+# define MLN_VALUE_IOTA_HH
+
/// \file
///
-/// \brief Check if site is a 1 face.
-
-#ifndef MLN_WORLD_K1_IS_0_OR_1_FACE_HH
-# define MLN_WORLD_K1_IS_0_OR_1_FACE_HH
-
-# include <mln/core/alias/point2d.hh>
-# include <mln/world/k1/internal/face_dim.hh>
-
+/// Define a functor returning the smallest next value in a given
+/// type.
namespace mln
{
- namespace world
+ namespace value
{
- namespace k1
+ /// Define a functor returning the smallest next value in a
+ /// given type.
+ template <typename T>
+ struct iota;
+
+ /// Specialization of \ref mln::value::internal::iota for unsigned.
+ template <>
+ struct iota<unsigned>
{
+ static unsigned value();
+ };
- /// \brief Check if site is a 1 face
- bool is_0_or_1_face(const point2d& p);
+ /// Specialization of \ref mln::value::internal::iota for int.
+ template <>
+ struct iota<int>
+ {
+ static int value();
+ };
# ifndef MLN_INCLUDE_ONLY
+ unsigned
+ iota<unsigned>::value()
+ {
+ return 1u;
+ }
- // Facade
-
- inline
- bool is_0_or_1_face(const point2d& p)
- {
- unsigned dim = internal::face_dim(p);
- return dim == 0 || dim == 1;
- }
-
+ int
+ iota<int>::value()
+ {
+ return 1;
+ }
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace mln::world::k1
-
- } // end of namespace mln::world
+ } // end of namespace mln::value
} // end of namespace mln
-#endif // ! MLN_WORLD_K1_IS_0_OR_1_FACE_HH
+#endif // MLN_VALUE_IOTA_HH
diff --git a/milena/mln/value/label.hh b/milena/mln/value/label.hh
index 5c983e5..f74662f 100644
--- a/milena/mln/value/label.hh
+++ b/milena/mln/value/label.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008, 2009, 2010, 2011 EPITA Research and
+// Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 EPITA Research and
// Development Laboratory (LRDE)
//
// This file is part of Olena.
@@ -173,8 +173,8 @@ namespace mln
/// Self decrement.
label<n>& operator--();
- /// Return the next value.
- label<n> next() const;
+ /// Return the successive value.
+ label<n> succ() const;
/// Return the previous value.
label<n> prev() const;
@@ -335,7 +335,7 @@ namespace mln
template <unsigned n>
inline
label<n>
- label<n>::next() const
+ label<n>::succ() const
{
return label<n>(this->v_ + 1);
}
diff --git a/milena/mln/value/next.hh b/milena/mln/value/prev.hh
similarity index 69%
copy from milena/mln/value/next.hh
copy to milena/mln/value/prev.hh
index b9bc06e..93221c5 100644
--- a/milena/mln/value/next.hh
+++ b/milena/mln/value/prev.hh
@@ -1,5 +1,4 @@
-// Copyright (C) 2010, 2012 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -24,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_VALUE_NEXT_HH
-# define MLN_VALUE_NEXT_HH
+#ifndef MLN_VALUE_PREV_HH
+# define MLN_VALUE_PREV_HH
/// \file
///
-/// Return the next value.
+/// Return the prev value.
+# include <mln/value/iota.hh>
# include <mln/value/label.hh>
-# include <mln/value/unsignedh.hh>
namespace mln
@@ -43,7 +42,7 @@ namespace mln
template <typename V>
V
- next(const V&);
+ prev(const V&);
# ifndef MLN_INCLUDE_ONLY
@@ -60,28 +59,20 @@ namespace mln
template <typename V>
inline
V
- next(const V& v)
+ prev(const V& v)
{
- return v + 1;
+ return v - mln::value::iota<V>::value();
}
} // end of namespace mln::value::implementation::generic
- template <unsigned n>
- inline
- mln::value::label<n>
- next_label(const mln::value::label<n>& v)
- {
- return v.next();
- }
-
-
+ template <typename V>
inline
- mln::value::unsignedh
- next_unsignedh(const mln::value::unsignedh& v)
+ V
+ prev_method(const V& v)
{
- return mln::value::succ(v);
+ return v.prev();
}
} // end of namespace mln::value::implementation
@@ -96,24 +87,17 @@ namespace mln
template <unsigned n>
inline
label<n>
- next_dispatch(const label<n>& v)
- {
- return implementation::next_label(v);
- }
-
- inline
- unsignedh
- next_dispatch(const unsignedh& v)
+ prev_dispatch(const label<n>& v)
{
- return implementation::next_unsignedh(v);
+ return implementation::prev_method(v);
}
template <typename V>
inline
V
- next_dispatch(const V& v)
+ prev_dispatch(const V& v)
{
- return implementation::generic::next(v);
+ return implementation::generic::prev(v);
}
} // end of namespace mln::value::internal
@@ -125,9 +109,9 @@ namespace mln
template <typename V>
inline
V
- next(const V& v)
+ prev(const V& v)
{
- return internal::next_dispatch(v);
+ return internal::prev_dispatch(v);
}
@@ -138,4 +122,4 @@ namespace mln
} // end of namespace mln
-#endif // ! MLN_VALUE_NEXT_HH
+#endif // ! MLN_VALUE_PREV_HH
diff --git a/milena/mln/value/range.hh b/milena/mln/value/range.hh
index ca8f2f4..5c90de7 100644
--- a/milena/mln/value/range.hh
+++ b/milena/mln/value/range.hh
@@ -233,7 +233,7 @@ namespace mln
{
unsigned n = 1;
T v = lower_;
- for (; v != upper_; v = value::next(v))
+ for (; v != upper_; v = value::succ(v))
n += 1;
return n;
@@ -323,7 +323,7 @@ namespace mln
are_adjacent(const range<T>& r1, const range<T>& r2)
{
return span(r1, r2).length() == r1.length() + r2.length()
- + (value::next(r2.lower()) - r2.lower());
+ + (value::succ(r2.lower()) - r2.lower());
}
template <typename T>
diff --git a/milena/mln/value/next.hh b/milena/mln/value/succ.hh
similarity index 72%
rename from milena/mln/value/next.hh
rename to milena/mln/value/succ.hh
index b9bc06e..4877727 100644
--- a/milena/mln/value/next.hh
+++ b/milena/mln/value/succ.hh
@@ -24,15 +24,15 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_VALUE_NEXT_HH
-# define MLN_VALUE_NEXT_HH
+#ifndef MLN_VALUE_SUCC_HH
+# define MLN_VALUE_SUCC_HH
/// \file
///
-/// Return the next value.
+/// Return the succ value.
+# include <mln/value/iota.hh>
# include <mln/value/label.hh>
-# include <mln/value/unsignedh.hh>
namespace mln
@@ -43,7 +43,7 @@ namespace mln
template <typename V>
V
- next(const V&);
+ succ(const V&);
# ifndef MLN_INCLUDE_ONLY
@@ -60,28 +60,20 @@ namespace mln
template <typename V>
inline
V
- next(const V& v)
+ succ(const V& v)
{
- return v + 1;
+ return v + mln::value::iota<V>::value();
}
} // end of namespace mln::value::implementation::generic
- template <unsigned n>
- inline
- mln::value::label<n>
- next_label(const mln::value::label<n>& v)
- {
- return v.next();
- }
-
-
+ template <typename V>
inline
- mln::value::unsignedh
- next_unsignedh(const mln::value::unsignedh& v)
+ V
+ succ_method(const V& v)
{
- return mln::value::succ(v);
+ return v.succ();
}
} // end of namespace mln::value::implementation
@@ -96,24 +88,17 @@ namespace mln
template <unsigned n>
inline
label<n>
- next_dispatch(const label<n>& v)
- {
- return implementation::next_label(v);
- }
-
- inline
- unsignedh
- next_dispatch(const unsignedh& v)
+ succ_dispatch(const label<n>& v)
{
- return implementation::next_unsignedh(v);
+ return implementation::succ_method(v);
}
template <typename V>
inline
V
- next_dispatch(const V& v)
+ succ_dispatch(const V& v)
{
- return implementation::generic::next(v);
+ return implementation::generic::succ(v);
}
} // end of namespace mln::value::internal
@@ -125,9 +110,9 @@ namespace mln
template <typename V>
inline
V
- next(const V& v)
+ succ(const V& v)
{
- return internal::next_dispatch(v);
+ return internal::succ_dispatch(v);
}
@@ -138,4 +123,4 @@ namespace mln
} // end of namespace mln
-#endif // ! MLN_VALUE_NEXT_HH
+#endif // ! MLN_VALUE_SUCC_HH
--
1.7.2.5
1
0