Olena
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
- February
- January
- ----- 2003 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2002 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
November 2003
- 4 participants
- 14 discussions
http://johnst.org/sw/exiftags/
Description
The exiftags utility parses a specified JPEG file or, by default, its
standard input, looking for a JPEG APP1 section containing Exif
(Exchangeable Image File) image metadata. The properties contained in
these data are then printed to the standard output. Digital cameras
typically add Exif data to the image files they produce, containing
information about the camera and digitized image.
The program supports a variety of cameras, and includes additional
support for a portion of the maker notes for Canon, Casio, Fuji,
Minolta, Nikon, Olympus, and Sanyo cameras. Currently this program
runs under Windows and Unix-like operating systems.
An included companion utility, exifcom, displays and writes the
UserComment Exif tag that some cameras include in the image metadata
they create. This program is useful for recording caption or location
information in the image file itself.
1
0

10.45: (intègre): Avoid useless dynamic checks in arithmetic operations.
by Nicolas Burrus 27 Nov '03
by Nicolas Burrus 27 Nov '03
27 Nov '03
int_u6 = int_u8 + int_u8
est safe au niveau de l'opération arithmétique, seul l'affectation à
besoin d'être checkée.
int_u6 = int_u32 + int_u8
n'est pas safe au niveau arithmétique, ie. il ne suffit pas de faire
l'opération puis de vérifier l'affectation. (int + int => int en C/C++).
Ce patch permet de déterminer avec plus de précision les cas où un
check dynamique est requis.
Index: integre/ChangeLog
from Nicolas Burrus <burrus_n(a)lrde.epita.fr>
* tests/types/tests/int_u8: New test.
* tests/types/runtests: Rename KEEP_RUN as KEEP_RUNS.
+2003-11-27 Nicolas Burrus <burrus_n(a)lrde.epita.fr>
+
+ * ntg/real/behavior.hh: Check arithmetic operators, not arithmetic
+ assignment operators.
+ (force): New behavior.
+ (ret_behavior_if): New helper struct.
+
+ * ntg/core/value.hh: Define unsafe_type.
+ * ntg/core/macros.hh (ntg_unsafe_type): New macro.
+ * ntg/utils/cast.hh: Use ntg_unsafe_type.
+
+ * ntg/real/typetraits_builtin_int.hh: Define abstract_behavior_type.
+ * ntg/real/builtin_float.hh: Likewise.
+ * ntg/real/range.hh: Likewise.
+ * ntg/real/cycle.hh: Likewise.
+
+ * ntg/real/int_s.hh: Remove useless arithmetic operations
+ checks. Define need_check for operation traits.
+ * ntg/real/int_u.hh: Likewise.
+
+ * ntg/real/optraits_real_defs.hh: Derive arithmetic assignment
+ operators from arithmetic operators. Use the behavior given by the
+ operator traits instead of the behavior of the return type.
+ * ntg/real/optraits_real.hh: Adjust consequently.
+
+2003-11-27 Nicolas Burrus <burrus_n(a)lrde.epita.fr>
+
Make typetraits and optraits reproduce more accurately the value
hierarchy.
Index: integre/ntg/real/behavior.hh
--- integre/ntg/real/behavior.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/g/31_behaviour. 1.13.1.16 640)
+++ integre/ntg/real/behavior.hh Thu, 27 Nov 2003 11:26:27 +0100 burrus_n (oln/g/31_behaviour. 1.13.1.15.1.1 640)
@@ -29,7 +29,7 @@
# define NTG_REAL_BEHAVIOUR_HH
/*
- Behaviors for data_types int_u, int_s, etc ...
+ Behaviors for real datatypes int_u, int_s, etc ...
<WARNING> Don't forget that behaviors are checked on assignements
and contruction of types, and use comparison, so create only vars
@@ -53,10 +53,10 @@
# include <string>
# include <sstream>
-
// FIXME: there is maybe simpler a way to write that, but we want it
// to be compatible with icc, so the behaviors must stay classes, not
// meta classes.
+// FIXME: are these considerations still accurate?
namespace ntg
{
@@ -86,28 +86,28 @@
template <class T1, class T2>
static T
- check_plus_equal (T1 lhs, T2 rhs)
+ check_plus (T1 lhs, T2 rhs)
{ return lhs + rhs; }
template <class T1, class T2>
static T
- check_minus_equal (T1 lhs, T2 rhs)
+ check_minus (T1 lhs, T2 rhs)
{ return lhs - rhs; }
template <class T1, class T2>
static T
- check_times_equal (T1 lhs, T2 rhs)
+ check_times (T1 lhs, T2 rhs)
{ return lhs * rhs; }
template <class T1, class T2>
static T
- check_div_equal (T1 lhs, T2 rhs)
+ check_div (T1 lhs, T2 rhs)
{ return lhs / rhs; }
template <class P>
static storage_type
check (const P& p)
- { return static_cast<storage_type>(p); }
+ { return p; }
};
static std::string
@@ -115,6 +115,63 @@
{ return "unsafe"; }
};
+ /*------.
+ | force |
+ `------*/
+ //! Force the value to be assigned without checks.
+ /*!
+ Quite similar to unsafe, but even if the destination type has a
+ strict behavior, by using cast::force we ensure that no check will
+ be performed.
+
+ Example:
+
+ int_u<8, strict> a;
+ a = force::get<int_u<8, strict> >::check_plus(5, 6);
+
+ => no check
+
+ This construction is useful when we want to use code from a
+ particular behavior to a type defined with another behavior.
+ */
+ struct force
+ {
+ template <class T>
+ struct get
+ {
+ typedef ntgi_storage_type(T) storage_type;
+
+ template <class T1, class T2>
+ static T
+ check_plus (T1 lhs, T2 rhs)
+ { return cast::force<T>(lhs + rhs); }
+
+ template <class T1, class T2>
+ static T
+ check_minus (T1 lhs, T2 rhs)
+ { return cast::force<T>(lhs - rhs); }
+
+ template <class T1, class T2>
+ static T
+ check_times (T1 lhs, T2 rhs)
+ { return cast::force<T>(lhs * rhs); }
+
+ template <class T1, class T2>
+ static T
+ check_div (T1 lhs, T2 rhs)
+ { return cast::force<T>(lhs / rhs); }
+
+ template <class P>
+ static storage_type
+ check (const P& p)
+ { return cast::force<T>(p); }
+ };
+
+ static std::string
+ name()
+ { return "force"; }
+ };
+
/*-------.
| strict |
`-------*/
@@ -136,7 +193,7 @@
template <class T1, class T2>
static T
- check_plus_equal (T1 lhs, T2 rhs)
+ check_plus (T1 lhs, T2 rhs)
{
T ret = lhs + rhs;
if (rhs > 0)
@@ -148,7 +205,7 @@
template <class T1, class T2>
static T
- check_minus_equal (T1 lhs, T2 rhs)
+ check_minus (T1 lhs, T2 rhs)
{
T ret = lhs - rhs;
if (rhs > 0)
@@ -161,7 +218,7 @@
// FIXME: this check is very slow! Find another solution.
template <class T1, class T2>
static T
- check_times_equal (T1 lhs, T2 rhs)
+ check_times (T1 lhs, T2 rhs)
{
T ret = lhs * rhs;
if (rhs != 0)
@@ -171,7 +228,7 @@
template <class T1, class T2>
static T
- check_div_equal (T1 lhs, T2 rhs)
+ check_div (T1 lhs, T2 rhs)
{ return lhs / rhs; }
template <class P>
@@ -203,7 +260,7 @@
template <class T1, class T2>
static T
- check_plus_equal (T1 lhs, T2 rhs)
+ check_plus (T1 lhs, T2 rhs)
{
T ret = lhs + rhs;
if (rhs > 0)
@@ -218,7 +275,7 @@
template <class T1, class T2>
static T
- check_minus_equal (T1 lhs, T2 rhs)
+ check_minus (T1 lhs, T2 rhs)
{
T ret = lhs - rhs;
if (rhs > 0)
@@ -234,7 +291,7 @@
// FIXME: this check is very slow ! find another solution ...
template <class T1, class T2>
static T
- check_times_equal (T1 lhs, T2 rhs)
+ check_times (T1 lhs, T2 rhs)
{
T ret = lhs * rhs;
if ((ret / rhs) != lhs)
@@ -250,7 +307,7 @@
template <class T1, class T2>
static T
- check_div_equal (T1 lhs, T2 rhs)
+ check_div (T1 lhs, T2 rhs)
{ return lhs / rhs; }
template <class P>
@@ -292,19 +349,19 @@
// FIXME: calculate real values!
template <class T1, class T2>
- static T check_plus_equal (T1 lhs, T2 rhs)
+ static T check_plus (T1 lhs, T2 rhs)
{ return lhs + rhs; }
template <class T1, class T2>
- static T check_minus_equal (T1 lhs, T2 rhs)
+ static T check_minus (T1 lhs, T2 rhs)
{ return lhs - rhs; }
template <class T1, class T2>
- static T check_times_equal (T1 lhs, T2 rhs)
+ static T check_times (T1 lhs, T2 rhs)
{ return lhs * rhs; }
template <class T1, class T2>
- static T check_div_equal (T1 lhs, T2 rhs)
+ static T check_div (T1 lhs, T2 rhs)
{ return lhs / rhs; }
// float modulus
@@ -372,6 +429,32 @@
struct deduce_op_behavior<B, B>
{ typedef B ret; };
+ /*----------------.
+ | ret_behavior_if |
+ `----------------*/
+
+ //! Determine the behavior to use depending on check requirements.
+ /*!
+ If need_check is true, the returned behavior will be the same as
+ the previously determined return type (generally safe).
+
+ In some cases, no check is required, thus type used to perform
+ the calculus does not need to be safe. The force behavior is
+ returned in such cases.
+ */
+
+ template <bool need_check, class Ret>
+ struct ret_behavior_if
+ {
+ typedef typename typetraits<Ret>::abstract_behavior_type ret;
+ };
+
+ template <class Ret>
+ struct ret_behavior_if<false, Ret>
+ {
+ typedef ntg::force ret;
+ };
+
} // end of internal.
} // end of ntg.
Index: integre/ntg/utils/cast.hh
--- integre/ntg/utils/cast.hh Fri, 07 Nov 2003 17:26:19 +0100 burrus_n (oln/i/26_cast.hh 1.3.1.10 640)
+++ integre/ntg/utils/cast.hh Thu, 27 Nov 2003 11:26:27 +0100 burrus_n (oln/i/26_cast.hh 1.3.1.11 640)
@@ -74,7 +74,7 @@
const Tdest
force(const Tsrc& val)
{
- Tdest tmp(static_cast<ntg_storage_type(Tdest)>(val));
+ ntg_unsafe_type(Tdest) tmp (val);
return tmp;
}
Index: integre/ntg/real/int_s.hh
--- integre/ntg/real/int_s.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/g/24_int_s.hh 1.16.1.18 640)
+++ integre/ntg/real/int_s.hh Thu, 27 Nov 2003 11:26:27 +0100 burrus_n (oln/g/24_int_s.hh 1.16.1.16.1.1 640)
@@ -46,17 +46,41 @@
// FIXME: add bits number comparison to avoid useless checks.
-# define INT_S_CTOR_FROM_BUILTIN(Builtin) \
+# define INT_S_CTOR_FROM_UNSIGNED_BUILTIN(Builtin) \
int_s (const Builtin rhs) \
{ \
+ if ((unsigned) internal::typetraits<ntg_type(Builtin)>::size < nbits) \
+ this->val_ = rhs; \
+ else \
this->val_ = optraits_type::check(rhs); \
} \
self& operator=(const Builtin rhs) \
{ \
+ if ((unsigned) internal::typetraits<ntg_type(Builtin)>::size < nbits) \
+ this->val_ = rhs; \
+ else \
this->val_ = optraits_type::check(rhs); \
return *this; \
}
+# define INT_S_CTOR_FROM_SIGNED_BUILTIN(Builtin) \
+int_s (const Builtin rhs) \
+{ \
+ if ((unsigned)internal::typetraits<ntg_type(Builtin)>::size <= nbits) \
+ this->val_ = rhs; \
+ else \
+ this->val_ = optraits_type::check(rhs); \
+} \
+self& operator=(const Builtin rhs) \
+{ \
+ if ((unsigned)internal::typetraits<ntg_type(Builtin)>::size <= nbits) \
+ this->val_ = rhs; \
+ else \
+ this->val_ = optraits_type::check(rhs); \
+ return *this; \
+}
+
+
namespace ntg {
namespace internal {
@@ -76,6 +100,7 @@
ntg_build_value_type(sint_value<E>);
typedef optraits<self> optraits_type;
+ typedef behavior abstract_behavior_type;
typedef typename behavior::template get<self> behavior_type;
typedef self base_type;
@@ -90,6 +115,9 @@
typedef int_u<32, behavior> unsigned_largest_type;
typedef int_u<32, behavior> unsigned_cumul_type;
typedef signed int integer_type;
+
+ // Particular properties
+ enum { size = nbits };
};
} // end of internal.
@@ -112,18 +140,18 @@
// We define ctor for each builtin to avoid implicit builtin
// promotion.
- INT_S_CTOR_FROM_BUILTIN(unsigned long);
- INT_S_CTOR_FROM_BUILTIN(signed long);
+ INT_S_CTOR_FROM_UNSIGNED_BUILTIN(unsigned long);
+ INT_S_CTOR_FROM_SIGNED_BUILTIN(signed long);
- INT_S_CTOR_FROM_BUILTIN(unsigned int);
- INT_S_CTOR_FROM_BUILTIN(signed int);
+ INT_S_CTOR_FROM_UNSIGNED_BUILTIN(unsigned int);
+ INT_S_CTOR_FROM_SIGNED_BUILTIN(signed int);
- INT_S_CTOR_FROM_BUILTIN(unsigned short);
- INT_S_CTOR_FROM_BUILTIN(signed short);
+ INT_S_CTOR_FROM_UNSIGNED_BUILTIN(unsigned short);
+ INT_S_CTOR_FROM_SIGNED_BUILTIN(signed short);
- INT_S_CTOR_FROM_BUILTIN(unsigned char);
- INT_S_CTOR_FROM_BUILTIN(signed char);
- INT_S_CTOR_FROM_BUILTIN(char);
+ INT_S_CTOR_FROM_UNSIGNED_BUILTIN(unsigned char);
+ INT_S_CTOR_FROM_SIGNED_BUILTIN(signed char);
+ INT_S_CTOR_FROM_SIGNED_BUILTIN(char);
template <unsigned mbits, class B2>
int_s (const int_s<mbits, B2>& rhs)
@@ -306,7 +334,8 @@
// debug
static std::string name() {
std::ostringstream out;
- out << "int_s<" << int(nbits) << ", " << behavior::name() << ">"<< std::ends;
+ out << "int_s<" << int(nbits) << ", " << behavior::name() << ">"
+ << std::ends;
return out.str();
}
};
@@ -325,10 +354,12 @@
template<unsigned nbits, class B1, unsigned mbits, class B2>
struct operator_traits<operator_plus, int_s<nbits, B1>, int_s<mbits, B2> >
{
- enum { commutative = true };
+ enum { commutative = true,
+ need_check = ((unsigned) mlc::max<nbits, mbits>::ret >= 32) };
typedef int_s<(unsigned)mlc::maxN<nbits + 1,mbits + 1, 32>::ret,
typename deduce_op_behavior<B1, B2>::ret> ret;
- typedef int_s<nbits, B1> impl;
+ typedef int_s<nbits,
+ typename ret_behavior_if<need_check, ret>::ret> impl;
};
@@ -337,10 +368,12 @@
template <unsigned nbits, class B1, unsigned mbits, class B2>
struct operator_traits<operator_plus, int_s<nbits, B1>, int_u<mbits, B2> >
{
- enum { commutative = true };
+ enum { commutative = true,
+ need_check = ((mbits >= 31) || (nbits >= 32)) };
typedef int_s<(unsigned)mlc::maxN<nbits + 1,mbits + 2, 32>::ret,
typename deduce_op_behavior<B1, B2>::ret> ret;
- typedef int_s<nbits, B1> impl;
+ typedef int_s<nbits,
+ typename ret_behavior_if<need_check, ret>::ret> impl;
};
@@ -353,10 +386,12 @@
template<unsigned nbits, class B1, unsigned mbits, class B2>
struct operator_traits<operator_minus, int_s<nbits, B1>, int_s<mbits, B2> >
{
- enum { commutative = true };
+ enum { commutative = true,
+ need_check = ((mbits >= 31) || (nbits >= 31)) };
typedef int_s<(unsigned)mlc::maxN<nbits + 1, mbits + 1, 32>::ret,
typename deduce_op_behavior<B1, B2>::ret> ret;
- typedef int_s<nbits, B1> impl;
+ typedef int_s<nbits,
+ typename ret_behavior_if<need_check, ret>::ret> impl;
};
// int_s - int_u ; int_u - int_s
@@ -364,10 +399,12 @@
template <unsigned nbits, class B1, unsigned mbits, class B2>
struct operator_traits<operator_minus, int_s<nbits, B1>, int_u<mbits, B2> >
{
- enum { commutative = true };
+ enum { commutative = true,
+ need_check = ((mbits >= 31) || (nbits >= 32)) };
typedef int_s<(unsigned)mlc::maxN<nbits + 1, mbits + 2, 32>::ret,
typename deduce_op_behavior<B1, B2>::ret> ret;
- typedef int_s<nbits, B1> impl;
+ typedef int_s<nbits,
+ typename ret_behavior_if<need_check, ret>::ret> impl;
};
@@ -380,10 +417,12 @@
template<unsigned nbits, class B1, unsigned mbits, class B2>
struct operator_traits<operator_times, int_s<nbits, B1>, int_s<mbits, B2> >
{
- enum { commutative = true };
+ enum { commutative = true,
+ need_check = (mbits + nbits > 32) };
typedef int_s<(unsigned)mlc::saturateN<nbits + mbits, 32>::ret,
typename deduce_op_behavior<B1, B2>::ret> ret;
- typedef int_s<nbits, B1> impl;
+ typedef int_s<nbits,
+ typename ret_behavior_if<need_check, ret>::ret> impl;
};
@@ -392,10 +431,12 @@
template <unsigned nbits, class B1, unsigned mbits, class B2>
struct operator_traits<operator_times, int_s<nbits, B1>, int_u<mbits, B2> >
{
- enum { commutative = true };
+ enum { commutative = true,
+ need_check = (nbits + mbits + 1 > 32)};
typedef int_s<(unsigned)mlc::saturateN<nbits + mbits+1, 32>::ret,
typename deduce_op_behavior<B1, B2>::ret> ret;
- typedef int_s<nbits, B1> impl;
+ typedef int_s<nbits,
+ typename ret_behavior_if<need_check, ret>::ret> impl;
};
//
@@ -409,7 +450,7 @@
{
enum { commutative = true };
typedef int_s<nbits, typename deduce_op_behavior<B1, B2>::ret> ret;
- typedef int_s<nbits, B1> impl;
+ typedef int_s<nbits, force> impl;
};
// int_s / int_u ; int_u / int_s
@@ -417,18 +458,22 @@
template <unsigned nbits, class B1, unsigned mbits, class B2>
struct operator_traits<operator_div, int_s<nbits, B1>, int_u<mbits, B2> >
{
- enum { commutative = false };
+ enum { commutative = false,
+ need_check = (mbits >= 32) };
typedef int_s<nbits, typename deduce_op_behavior<B1, B2>::ret> ret;
- typedef int_s<nbits, B1> impl;
+ typedef int_s<nbits,
+ typename ret_behavior_if<need_check, ret>::ret> impl;
};
template <unsigned nbits, class B1, unsigned mbits, class B2>
struct operator_traits<operator_div, int_u<mbits, B2>, int_s<nbits, B1> >
{
- enum { commutative = false };
+ enum { commutative = false,
+ need_check = (mbits >= 32) };
typedef int_s<mlc::saturateN<mbits + 1, 32>::ret,
typename deduce_op_behavior<B1, B2>::ret> ret;
- typedef int_s<nbits, B1> impl;
+ typedef int_s<nbits,
+ typename ret_behavior_if<need_check, ret>::ret> impl;
};
//
@@ -442,7 +487,7 @@
{
enum { commutative = false };
typedef int_s<mbits, typename deduce_op_behavior<B1, B2>::ret> ret;
- typedef int_s<nbits, B1> impl;
+ typedef int_s<nbits, force> impl;
};
// int_s % int_u ; int_u % int_s
@@ -450,12 +495,19 @@
template <unsigned nbits, class B1, unsigned mbits, class B2>
struct operator_traits<operator_mod, int_s<nbits, B1>, int_u<mbits, B2> >
{
- enum { commutative = false };
+ enum { commutative = false,
+ need_check = (mbits >= 32) };
typedef int_s<(unsigned)mlc::saturateN<mbits + 1, 32>::ret,
typename deduce_op_behavior<B1, B2>::ret> ret;
- typedef int_s<nbits, B1> impl;
+ typedef int_s<nbits,
+ typename ret_behavior_if<need_check, ret>::ret> impl;
};
+ // FIXME: don't know what to do with this operator, so the
+ // implementation is disabled. In classical C++, (a % b) with b < 0
+ // returns a whatever b is.
+
+#if 0
template <unsigned nbits, class B1, unsigned mbits, class B2>
struct operator_traits<operator_mod, int_u<nbits, B1>, int_s<mbits, B2> >
{
@@ -463,7 +515,7 @@
typedef int_u<mbits, typename deduce_op_behavior<B1, B2>::ret> ret;
typedef int_s<nbits, B1> impl;
};
-
+#endif
//
// Min
@@ -477,7 +529,7 @@
enum { commutative = true };
typedef int_s<(unsigned) mlc::min<nbits, mbits>::ret,
typename deduce_op_behavior<B1, B2>::ret> ret;
- typedef int_s<nbits, B1> impl;
+ typedef int_s<nbits, force> impl;
};
//
@@ -492,7 +544,7 @@
enum { commutative = true };
typedef int_s<(unsigned) mlc::max<nbits, mbits>::ret,
typename deduce_op_behavior<B1, B2>::ret> ret;
- typedef int_s<nbits, B1> impl;
+ typedef int_s<nbits, force> impl;
};
//
@@ -506,7 +558,7 @@
{
enum { commutative = true };
typedef int_s<(unsigned)mlc::maxN<nbits,mbits,32>::ret, unsafe> ret;
- typedef int_s<nbits, B1> impl;
+ typedef int_s<nbits, force> impl;
};
@@ -517,7 +569,7 @@
{
enum { commutative = true };
typedef int_s<(unsigned)mlc::maxN<nbits,mbits+1, 32>::ret, unsafe> ret;
- typedef int_s<nbits, B1> impl;
+ typedef int_s<nbits, force> impl;
};
} // end of internal.
Index: integre/ntg/real/int_u.hh
--- integre/ntg/real/int_u.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/g/23_int_u.hh 1.19.1.18 640)
+++ integre/ntg/real/int_u.hh Thu, 27 Nov 2003 11:26:27 +0100 burrus_n (oln/g/23_int_u.hh 1.19.1.16.1.1 640)
@@ -42,6 +42,23 @@
| macros |
`-------*/
+# define INT_U_CTOR_FROM_UNSIGNED_BUILTIN_INT(Builtin) \
+int_u (const Builtin rhs) \
+{ \
+ if ((unsigned) internal::typetraits<ntg_type(Builtin)>::size <= nbits) \
+ this->val_ = rhs; \
+ else \
+ this->val_ = optraits_type::check(rhs); \
+} \
+self& operator=(const Builtin rhs) \
+{ \
+ if ((unsigned) internal::typetraits<ntg_type(Builtin)>::size <= nbits) \
+ this->val_ = rhs; \
+ else \
+ this->val_ = optraits_type::check(rhs); \
+ return *this; \
+}
+
# define INT_U_CTOR_FROM_BUILTIN_INT(Builtin) \
int_u (const Builtin rhs) \
{ \
@@ -53,6 +70,7 @@
return *this; \
}
+
namespace ntg {
namespace internal {
@@ -72,9 +90,9 @@
ntg_build_value_type(uint_value<E>);
typedef optraits<self> optraits_type;
+ typedef behavior abstract_behavior_type;
typedef typename behavior::template get<self> behavior_type;
-
typedef self base_type;
typedef typename C_for_int_u<nbits>::type storage_type;
typedef int_s<mlc::saturateN<nbits+1, 32>::ret,
@@ -88,6 +106,10 @@
typedef int_u<32, behavior> unsigned_largest_type;
typedef int_u<32, behavior> unsigned_cumul_type;
typedef unsigned int integer_type;
+ typedef int_u<nbits, unsafe> unsafe_type;
+
+ // Particular properties
+ enum { size = nbits };
};
} // end of internal.
@@ -111,16 +133,18 @@
// We define ctor for each builtin to avoid implicit builtin
// promotion.
- INT_U_CTOR_FROM_BUILTIN_INT(unsigned long);
+ // FIXME: dynamic checks are not necessary for all builtin types!
+
+ INT_U_CTOR_FROM_UNSIGNED_BUILTIN_INT(unsigned long);
INT_U_CTOR_FROM_BUILTIN_INT(signed long);
- INT_U_CTOR_FROM_BUILTIN_INT(unsigned int);
+ INT_U_CTOR_FROM_UNSIGNED_BUILTIN_INT(unsigned int);
INT_U_CTOR_FROM_BUILTIN_INT(signed int);
- INT_U_CTOR_FROM_BUILTIN_INT(unsigned short);
+ INT_U_CTOR_FROM_UNSIGNED_BUILTIN_INT(unsigned short);
INT_U_CTOR_FROM_BUILTIN_INT(signed short);
- INT_U_CTOR_FROM_BUILTIN_INT(unsigned char);
+ INT_U_CTOR_FROM_UNSIGNED_BUILTIN_INT(unsigned char);
INT_U_CTOR_FROM_BUILTIN_INT(signed char);
INT_U_CTOR_FROM_BUILTIN_INT(char);
@@ -252,10 +276,12 @@
template<unsigned nbits, class B1, unsigned mbits, class B2>
struct operator_traits<operator_plus, int_u<nbits, B1>, int_u<mbits, B2> >
{
- enum { commutative = true };
+ enum { commutative = true,
+ need_check = ((unsigned) mlc::max<nbits, mbits>::ret >= 32) };
typedef int_u<(unsigned) mlc::maxN<nbits + 1, mbits + 1, 32>::ret,
typename deduce_op_behavior<B1, B2>::ret> ret;
- typedef int_u<nbits, B1> impl;
+ typedef int_u<nbits,
+ typename ret_behavior_if<need_check, ret>::ret> impl;
};
//
@@ -267,10 +293,12 @@
template<unsigned nbits, class B1, unsigned mbits, class B2>
struct operator_traits<operator_minus, int_u<nbits, B1>, int_u<mbits, B2> >
{
- enum { commutative = true };
+ enum { commutative = true,
+ need_check = ((unsigned) mlc::max<nbits, mbits>::ret >= 32) };
typedef int_s<(unsigned) mlc::maxN<nbits+1, mbits+1, 32>::ret,
typename deduce_op_behavior<B1, B2>::ret> ret;
- typedef int_u<nbits, B1> impl;
+ typedef int_u<nbits,
+ typename ret_behavior_if<need_check, ret>::ret> impl;
};
// int_u32 - int_u : we do not convert result to int_s because we
@@ -281,7 +309,7 @@
{
enum { commutative = true };
typedef int_u<32, typename deduce_op_behavior<B1, B2>::ret> ret;
- typedef int_u<32, B1> impl;
+ typedef int_u<32, force> impl;
};
//
@@ -293,10 +321,11 @@
template<unsigned nbits, class B1, unsigned mbits, class B2>
struct operator_traits<operator_times, int_u<nbits, B1>, int_u<mbits, B2> >
{
- enum { commutative = true };
+ enum { commutative = true, need_check = (nbits + mbits > 32) };
typedef int_u<(unsigned) mlc::saturateN<nbits + mbits, 32>::ret,
typename deduce_op_behavior<B1, B2>::ret> ret;
- typedef int_u<nbits, B1> impl;
+ typedef int_u<nbits,
+ typename ret_behavior_if<need_check, ret>::ret> impl;
};
//
@@ -310,7 +339,7 @@
{
enum { commutative = true };
typedef int_u<nbits, typename deduce_op_behavior<B1, B2>::ret> ret;
- typedef int_u<nbits, B1> impl;
+ typedef int_u<nbits, force> impl;
};
//
@@ -324,7 +353,7 @@
{
enum { commutative = false };
typedef int_u<mbits, typename deduce_op_behavior<B1, B2>::ret> ret;
- typedef int_u<nbits, B1> impl;
+ typedef int_u<nbits, force> impl;
};
//
@@ -339,7 +368,7 @@
enum { commutative = true };
typedef int_u<(unsigned) mlc::min<nbits, mbits>::ret,
typename deduce_op_behavior<B1, B2>::ret> ret;
- typedef int_u<nbits, B1> impl;
+ typedef int_u<nbits, force> impl;
};
@@ -355,7 +384,7 @@
enum { commutative = true };
typedef int_u<(unsigned) mlc::max<nbits, mbits>::ret,
typename deduce_op_behavior<B1, B2>::ret> ret;
- typedef int_u<nbits, B1> impl;
+ typedef int_u<nbits, force> impl;
};
@@ -369,8 +398,9 @@
struct operator_traits<operator_cmp, int_u<nbits, B1>, int_u<mbits, B2> >
{
enum { commutative = true };
+ // FIXME: why unsafe? I think there is a reason.
typedef int_u<(unsigned) mlc::maxN<nbits, mbits, 32>::ret, unsafe> ret;
- typedef int_u<nbits, B1> impl;
+ typedef int_u<nbits, force> impl;
};
} // end of internal.
Index: integre/ntg/real/optraits_real_defs.hh
--- integre/ntg/real/optraits_real_defs.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/g/11_optraits_s 1.15 640)
+++ integre/ntg/real/optraits_real_defs.hh Thu, 27 Nov 2003 11:26:27 +0100 burrus_n (oln/g/11_optraits_s 1.14.1.1 640)
@@ -29,23 +29,23 @@
# define NTG_OPTRAITS_REAL_DEFS_HH
//
-// macros used in optraits_scalar definition
+// macros used in optraits_real definition
//
/////////////////////////////////////////////
-# define ASSIGN_SCALAR_OPERATOR(Name, Op) \
+# define ASSIGN_SCALAR_OPERATOR(Name) \
template <class T1, class T2> inline \
- static T1& Name(T1& lhs, const T2& rhs) \
+ static T1& Name##_equal(T1& lhs, const T2& rhs) \
{ \
ntg_is_a(T1, ntg::real)::ensure(); \
ntg_is_a(T2, ntg::real)::ensure(); \
\
- return Name##_impl<T1,T2>(lhs, rhs); \
+ return Name##_equal_impl<T1,T2>(lhs, rhs); \
} \
\
template <class T1, class T2> inline \
static T1& \
- Name##_impl(ntg::real_value<T1>& lhs, \
+ Name##_equal_impl(ntg::real_value<T1>& lhs, \
const ntg::real_value<T2>& rhs) \
{ \
typedef typename typetraits<T1>::behavior_type behavior_type; \
@@ -56,7 +56,7 @@
\
template <class T1, class T2> inline \
static T1& \
- Name##_impl(ntg::real_value<T1>& lhs, \
+ Name##_equal_impl(ntg::real_value<T1>& lhs, \
const ntg::any_const_class<T2> rhs) \
{ \
typedef typename typetraits<T1>::behavior_type behavior_type; \
@@ -67,7 +67,7 @@
\
template <class T1, class T2> inline \
static T1& \
- Name##_impl(ntg::any_class<T1> lhs, \
+ Name##_equal_impl(ntg::any_class<T1> lhs, \
const ntg::real_value<T2>& rhs) \
{ \
typedef typename typetraits<T1>::behavior_type behavior_type; \
@@ -76,7 +76,7 @@
return lhs.exact(); \
}
-# define ARITH_SCALAR_OPERATOR(Name, Op) \
+# define ARITH_SCALAR_OPERATOR(Name) \
template <class T1, class T2> inline \
static ntg_return_type(Name, T1, T2) \
Name(const T1& lhs, const T2& rhs) \
@@ -84,13 +84,54 @@
ntg_is_a(T1, ntg::real)::ensure(); \
ntg_is_a(T2, ntg::real)::ensure(); \
\
+ return Name##_impl<T1,T2>(lhs, rhs); \
+ } \
+ \
+ template <class T1, class T2> inline \
+ static ntg_return_type(Name, T1, T2) \
+ Name##_impl(const ntg::real_value<T1>& lhs, \
+ const ntg::real_value<T2>& rhs) \
+ { \
typedef ntg_return_type(Name, T1, T2) return_type; \
- return_type result(lhs); \
- result Op rhs; \
- return result; \
+ typedef typename \
+ typetraits<E>::abstract_behavior_type::get<return_type> \
+ behavior_type; \
+ return_type tmp; \
+ tmp = behavior_type::check_##Name(lhs.exact().val(), \
+ rhs.exact().val()); \
+ return tmp; \
+ } \
+ \
+ template <class T1, class T2> inline \
+ static ntg_return_type(Name, T1, T2) \
+ Name##_impl(const ntg::real_value<T1>& lhs, \
+ const ntg::any_const_class<T2>& rhs) \
+ { \
+ typedef ntg_return_type(Name, T1, T2) return_type; \
+ typedef typename \
+ typetraits<E>::abstract_behavior_type::get<return_type> \
+ behavior_type; \
+ return_type tmp; \
+ tmp = behavior_type::check_##Name(lhs.exact().val(), \
+ rhs.exact()); \
+ return tmp; \
+ } \
+ \
+ template <class T1, class T2> inline \
+ static ntg_return_type(Name, T1, T2) \
+ Name##_impl(const ntg::any_const_class<T1>& lhs, \
+ const ntg::real_value<T2>& rhs) \
+ { \
+ typedef ntg_return_type(Name, T1, T2) return_type; \
+ typedef typename \
+ typetraits<E>::abstract_behavior_type::get<return_type> \
+ behavior_type; \
+ return_type tmp; \
+ tmp = behavior_type::check_##Name(lhs.exact(), \
+ rhs.exact().val()); \
+ return tmp; \
}
-
# define CMP_SCALAR_OPERATOR(Name, Op) \
template <class T1, class T2> inline \
static bool Name (const T1& lhs, const T2& rhs) \
@@ -105,7 +146,8 @@
} \
\
template <class T> inline \
- static bool Name##_impl(const ntg::real_value<T>& lhs, \
+ static bool \
+ Name##_impl(const ntg::real_value<T>& lhs, \
const ntg::real_value<T>& rhs) \
{ return lhs.exact().val() Op rhs.exact().val(); } \
\
@@ -121,7 +163,6 @@
//
////////////////////////////
-
# define ASSIGN_INT_OPERATOR(Name, Op) \
template <class T1, class T2> inline \
static T1& Name(T1& lhs, const T2& rhs) \
Index: integre/ntg/real/optraits_real.hh
--- integre/ntg/real/optraits_real.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/g/12_optraits_s 1.11.1.10 640)
+++ integre/ntg/real/optraits_real.hh Thu, 27 Nov 2003 11:26:27 +0100 burrus_n (oln/g/12_optraits_s 1.11.1.8.1.1 640)
@@ -65,27 +65,26 @@
static storage_type_ default_val() { return zero(); }
//
- // dev note : the goal in those default operators is to check the kind
+ // dev note : the aim of these default operators is to check the kind
// of operands (value or not), and then call the good function.
//
// ASSIGN_SCALAR_OPERATOR includes default check_xxx_equal functions
//
- ASSIGN_SCALAR_OPERATOR(plus_equal, +)
- ASSIGN_SCALAR_OPERATOR(minus_equal, -)
- ASSIGN_SCALAR_OPERATOR(times_equal, *)
- ASSIGN_SCALAR_OPERATOR(div_equal, /)
-
- ARITH_SCALAR_OPERATOR(plus, +=)
- ARITH_SCALAR_OPERATOR(minus, -=)
- ARITH_SCALAR_OPERATOR(times, *=)
- ARITH_SCALAR_OPERATOR(div, /=)
+ ASSIGN_SCALAR_OPERATOR(plus)
+ ASSIGN_SCALAR_OPERATOR(minus)
+ ASSIGN_SCALAR_OPERATOR(times)
+ ASSIGN_SCALAR_OPERATOR(div)
+
+ ARITH_SCALAR_OPERATOR(plus)
+ ARITH_SCALAR_OPERATOR(minus)
+ ARITH_SCALAR_OPERATOR(times)
+ ARITH_SCALAR_OPERATOR(div)
CMP_SCALAR_OPERATOR(cmp_eq, ==)
CMP_SCALAR_OPERATOR(cmp_lt, <)
};
-
/*----------------------.
| optraits<float_value> |
`----------------------*/
Index: integre/ntg/core/value.hh
--- integre/ntg/core/value.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/g/8_rec_value. 1.8.1.9 640)
+++ integre/ntg/core/value.hh Thu, 27 Nov 2003 11:26:27 +0100 burrus_n (oln/g/8_rec_value. 1.8.1.8.1.1 640)
@@ -107,7 +107,9 @@
template <class E>
struct typetraits<value<E> >
- {};
+ {
+ typedef E unsafe_type;
+ };
template <class E>
struct optraits<value<E> >
Index: integre/ntg/real/typetraits_builtin_int.hh
--- integre/ntg/real/typetraits_builtin_int.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/g/3_typetraits 1.7.1.13 640)
+++ integre/ntg/real/typetraits_builtin_int.hh Thu, 27 Nov 2003 11:26:27 +0100 burrus_n (oln/g/3_typetraits 1.7.1.11.1.1 640)
@@ -51,6 +51,7 @@
\
typedef optraits<self> optraits; \
typedef unsafe::get<self> behavior_type; \
+ typedef unsafe abstract_behavior_type; \
\
typedef self base_type; \
typedef self storage_type; \
Index: integre/tests/types/runtests
--- integre/tests/types/runtests Fri, 01 Aug 2003 11:42:33 +0200 burrus_n (oln/h/3_runtests 1.14.1.6 750)
+++ integre/tests/types/runtests Thu, 27 Nov 2003 11:26:27 +0100 burrus_n (oln/h/3_runtests 1.14.1.7 750)
@@ -93,7 +93,7 @@
msg="";
case $expected:$estatus in
ok:0 | compfail:50 | abort:134)
- if test ! x"$KEEP_RUN" = x"1"; then
+ if test ! x"$KEEP_RUNS" = x"1"; then
rm -rf "$dir";
fi
msg="(ok)" ;;
Index: integre/ntg/core/macros.hh
--- integre/ntg/core/macros.hh Sun, 27 Jul 2003 19:14:42 +0200 burrus_n (oln/s/19_macros.hh 1.7 640)
+++ integre/ntg/core/macros.hh Thu, 27 Nov 2003 11:26:27 +0100 burrus_n (oln/s/19_macros.hh 1.8 640)
@@ -92,6 +92,9 @@
# define ntg_comp_type_(T) \
ntg::type_traits<T>::comp_type
+# define ntg_unsafe_type(T) typename ntg::type_traits<T>::unsafe_type
+# define ntg_unsafe_type_(T) ntg::type_traits<T>::unsafe_type
+
/*-----------------.
| values accessors |
`-----------------*/
Index: integre/ntg/real/builtin_float.hh
--- integre/ntg/real/builtin_float.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/s/47_builtin_fl 1.4 640)
+++ integre/ntg/real/builtin_float.hh Thu, 27 Nov 2003 11:26:27 +0100 burrus_n (oln/s/47_builtin_fl 1.2.1.1 640)
@@ -57,6 +57,7 @@
typedef optraits<self> optraits_type;
typedef unsafe::get<self> behavior_type;
+ typedef unsafe abstract_behavior_type;
typedef self base_type;
typedef self storage_type;
@@ -86,6 +87,7 @@
typedef optraits<self> optraits_type;
typedef unsafe::get<self> behavior_type;
+ typedef unsafe abstract_behavior_type;
typedef self base_type;
typedef self storage_type;
Index: integre/ntg/real/range.hh
--- integre/ntg/real/range.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/t/16_range.hh 1.5 640)
+++ integre/ntg/real/range.hh Thu, 27 Nov 2003 11:26:27 +0100 burrus_n (oln/t/16_range.hh 1.3.1.1 640)
@@ -53,6 +53,7 @@
typedef self ntg_type;
typedef optraits<self> optraits_type;
typedef typename behavior::template get<self> behavior_type;
+ typedef behavior abstract_behavior_type;
typedef ntgi_base_type(T) base_type;
typedef T storage_type;
Index: integre/ntg/real/cycle.hh
--- integre/ntg/real/cycle.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/t/17_cycle.hh 1.3 640)
+++ integre/ntg/real/cycle.hh Thu, 27 Nov 2003 11:26:27 +0100 burrus_n (oln/t/17_cycle.hh 1.2.1.1 640)
@@ -53,6 +53,7 @@
typedef self ntg_type;
typedef optraits<self> optraits_type;
typedef cycle_behavior::get<self> behavior_type;
+ typedef cycle_behavior abstract_behavior_type;
typedef typename typetraits<T>::base_type base_type;
typedef T storage_type;
Index: integre/tests/types/tests/int_u8
--- integre/tests/types/tests/int_u8 Thu, 27 Nov 2003 11:45:11 +0100 burrus_n ()
+++ integre/tests/types/tests/int_u8 Thu, 27 Nov 2003 11:26:27 +0100 burrus_n (oln/w/6_int_u8 1.1 640)
@@ -0,0 +1,9 @@
+int_u8 u1 = (unsigned char) 56;
+int_u8 u2 = (unsigned char) 153;
+int_u32 u = 0U;
+
+for (unsigned i = 0; i < 5000000; ++i)
+ for (unsigned j = 0; j < 10; ++j)
+ u = u1 * u2 + int_u8u(i % 50);
+
+return u != 8617;
1
0

10.44: (intègre): reproduce more accurately the value hierarchy for traits
by Nicolas Burrus 27 Nov '03
by Nicolas Burrus 27 Nov '03
27 Nov '03
Index: integre/ChangeLog
from Nicolas Burrus <burrus_n(a)lrde.epita.fr>
Make typetraits and optraits reproduce more accurately the value
hierarchy.
* ntg/real/int_s.hh: Fix traits inheritance.
* ntg/real/int_u.hh: Likewise.
* ntg/real/optraits_builtin_int.hh: Likewise.
* ntg/real/typetraits_builtin_int.hh: Likewise.
* ntg/real/builtin_float.hh: Likewise.
* ntg/real/range.hh: Likewise.
* ntg/real/cycle.hh: Likewise.
* ntg/vect/vec.hh: Likewise.
* ntg/enum/bin.hh: Likewise.
* ntg/real/real_value.hh: Define typetraits.
* ntg/vect/vect_value.hh: Likewise.
* ntg/enum/enum_value.hh: Likewise.
* ntg/real/optraits_real.hh: Rename optraits_xxx as
optraits<xxx_value>.
* ntg/core/value.hh: Define typetraits<value> and optraits<value>.
* ntg/core/internal/traits.hh: Remove useless optraits_xxx definitions.
Index: integre/ntg/real/int_s.hh
--- integre/ntg/real/int_s.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/g/24_int_s.hh 1.16.1.17 640)
+++ integre/ntg/real/int_s.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/g/24_int_s.hh 1.16.1.18 640)
@@ -67,6 +67,7 @@
template <unsigned nbits, class behavior>
struct typetraits<int_s<nbits, behavior> >
+ : public typetraits<sint_value<int_s<nbits, behavior> > >
{
typedef int_s<nbits, behavior> self;
typedef signed_integer abstract_type;
@@ -213,10 +214,11 @@
template <unsigned nbits, class behavior>
struct optraits<int_s<nbits, behavior> > :
- public optraits_int_s<int_s<nbits, behavior> >
+ public optraits<sint_value<int_s<nbits, behavior> > >
{
public:
typedef int_s<nbits, behavior> self;
+ typedef optraits<sint_value<int_s<nbits, behavior> > > super;
private:
typedef typename typetraits<self>::base_type base_type_;
@@ -250,17 +252,17 @@
// int_sN == int_u32; int_u32 == int_sN
- template <class B2>
+ template <unsigned mbits, class B1, class B2>
static bool
- cmp_eq(const self& lhs, const int_u<32, B2>& rhs)
+ cmp_eq(const int_s<mbits, B1>& lhs, const int_u<32, B2>& rhs)
{
if (lhs.val() < 0)
return false;
return static_cast<int_u<32, B2> >(lhs).val() == rhs.val();
}
- template <class B1>
- static bool cmp_eq(const int_u<32, B1>& lhs, const self& rhs)
+ template <unsigned mbits, class B1, class B2>
+ static bool cmp_eq(const int_u<32, B1>& lhs, const int_s<mbits, B2>& rhs)
{ return cmp_eq(rhs, lhs); }
// <T1> == <T2>
@@ -268,7 +270,7 @@
template <class T1, class T2>
static bool
cmp_eq(const T1& lhs, const T2& rhs)
- { return optraits_scalar<self>::cmp_eq(lhs, rhs); }
+ { return super::cmp_eq(lhs, rhs); }
//
// cmp_lt
@@ -276,17 +278,17 @@
// int_sN < int_u32; int_u32 < int_sN
- template <class B2>
+ template <unsigned mbits, class B1, class B2>
static bool
- cmp_lt(const self& lhs, const int_u<32, B2>& rhs)
+ cmp_lt(const int_s<mbits, B1>& lhs, const int_u<32, B2>& rhs)
{
if (lhs.val() < 0)
return true;
return static_cast<int_u<32, B2> >(lhs).val() < rhs.val();
}
- template <class B1>
- static bool cmp_lt(const int_u<32, B1>& lhs, const self& rhs)
+ template <unsigned mbits, class B1, class B2>
+ static bool cmp_lt(const int_u<32, B1>& lhs, const int_s<mbits, B2>& rhs)
{
if (rhs.val() < 0)
return false;
@@ -299,7 +301,7 @@
template <class T1, class T2>
static bool
cmp_lt(const T1& lhs, const T2& rhs)
- { return optraits_scalar<self>::cmp_lt(lhs, rhs); }
+ { return super::cmp_lt(lhs, rhs); }
// debug
static std::string name() {
Index: integre/ntg/real/int_u.hh
--- integre/ntg/real/int_u.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/g/23_int_u.hh 1.19.1.17 640)
+++ integre/ntg/real/int_u.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/g/23_int_u.hh 1.19.1.18 640)
@@ -63,6 +63,7 @@
template <unsigned nbits, class behavior>
struct typetraits<int_u<nbits, behavior> >
+ : public typetraits<uint_value<int_u<nbits, behavior> > >
{
typedef int_u<nbits, behavior> self;
typedef unsigned_integer abstract_type;
@@ -213,7 +214,7 @@
template <unsigned nbits, class behavior>
struct optraits<int_u<nbits, behavior> > :
- public optraits_int_u<int_u<nbits, behavior> >
+ public optraits<uint_value<int_u<nbits, behavior> > >
{
private:
typedef int_u<nbits, behavior> self;
Index: integre/ntg/real/optraits_builtin_int.hh
--- integre/ntg/real/optraits_builtin_int.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/g/18_optraits_b 1.6.1.9 640)
+++ integre/ntg/real/optraits_builtin_int.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/g/18_optraits_b 1.6.1.10 640)
@@ -47,7 +47,7 @@
# define OPTRAITS_BUILTIN_INT_U(Name, Max) \
template <> \
- struct optraits<Name> : public optraits_int_u<Name> \
+ struct optraits<Name> : public optraits<uint_value<Name> > \
{ \
static Name max() { return Max; } \
static std::string name() { return std::string(#Name); } \
@@ -55,7 +55,7 @@
# define OPTRAITS_BUILTIN_INT_S(Name, Min, Max) \
template <> \
- struct optraits<Name> : public optraits_int_s<Name> \
+ struct optraits<Name> : public optraits<sint_value<Name> > \
{ \
static Name min() { return Min; } \
static Name max() { return Max; } \
Index: integre/ntg/real/optraits_real.hh
--- integre/ntg/real/optraits_real.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/g/12_optraits_s 1.11.1.9 640)
+++ integre/ntg/real/optraits_real.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/g/12_optraits_s 1.11.1.10 640)
@@ -39,7 +39,6 @@
// --
# include <ntg/core/internal/global_ops_traits.hh>
-# include <ntg/core/type_traits.hh>
# include <ntg/core/macros.hh>
// macros definitions
@@ -49,16 +48,16 @@
namespace internal {
- /*----------------.
- | optraits_scalar |
- `----------------*/
+ /*---------------------.
+ | optraits<real_value> |
+ `---------------------*/
//! Implement common operators for scalars
- template <class Self>
- class optraits_scalar : public optraits_top<Self>
+ template <class E>
+ class optraits<real_value<E> > : public optraits<value<E> >
{
private:
- typedef typename typetraits<Self>::storage_type storage_type_;
+ typedef typename typetraits<E>::storage_type storage_type_;
public:
static storage_type_ zero () { return 0; }
@@ -86,60 +85,61 @@
CMP_SCALAR_OPERATOR(cmp_lt, <)
};
- /*---------------.
- | optraits_float |
- `---------------*/
- template <class Self>
- class optraits_float : public optraits_scalar<Self>
+ /*----------------------.
+ | optraits<float_value> |
+ `----------------------*/
+
+ template <class E>
+ class optraits<float_value<E> > : public optraits<real_value<E> >
{
public:
// This is the standard size for float on std::ostream.
static unsigned max_print_width () { return 11U; }
};
- /*-------------.
- | optraits_int |
- `-------------*/
+ /*--------------------.
+ | optraits<int_value> |
+ `--------------------*/
- template <class Self>
- class optraits_int : public optraits_scalar<Self>
+ template <class E>
+ class optraits<int_value<E> > : public optraits<real_value<E> >
{
- typedef typename typetraits<Self>::storage_type storage_type_;
+ typedef typename typetraits<E>::storage_type storage_type_;
public:
- static storage_type_ inf () { return optraits<Self>::min(); }
- static storage_type_ sup () { return optraits<Self>::max(); }
+ static storage_type_ inf () { return optraits<E>::min(); }
+ static storage_type_ sup () { return optraits<E>::max(); }
static unsigned max_print_width ()
{
- return (unsigned) log10(double(optraits<Self>::max())) + 1;
+ return (unsigned) log10(double(optraits<E>::max())) + 1;
}
ASSIGN_INT_OPERATOR(mod_equal, %)
ARITH_INT_OPERATOR(mod, %=)
};
- /*---------------.
- | optraits_int_u |
- `---------------*/
+ /*---------------------.
+ | optraits<uint_value> |
+ `---------------------*/
- template <class Self>
- class optraits_int_u : public optraits_int<Self>
+ template <class E>
+ class optraits<uint_value<E> > : public optraits<int_value<E> >
{
private:
- typedef typename typetraits<Self>::storage_type storage_type_;
+ typedef typename typetraits<E>::storage_type storage_type_;
public:
static storage_type_ min () { return 0; }
};
- /*---------------.
- | optraits_int_s |
- `---------------*/
+ /*---------------------.
+ | optraits<sint_value> |
+ `---------------------*/
- template <class Self>
- class optraits_int_s : public optraits_int<Self>
+ template <class E>
+ class optraits<sint_value<E> > : public optraits<int_value<E> >
{};
} // end of internal
Index: integre/ntg/core/value.hh
--- integre/ntg/core/value.hh Tue, 13 May 2003 21:32:45 +0200 burrus_n (oln/g/8_rec_value. 1.8.1.8 640)
+++ integre/ntg/core/value.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/g/8_rec_value. 1.8.1.9 640)
@@ -103,6 +103,18 @@
storage_type val_;
};
+ namespace internal {
+
+ template <class E>
+ struct typetraits<value<E> >
+ {};
+
+ template <class E>
+ struct optraits<value<E> >
+ {};
+
+ }
+
} // end of ntg.
#endif // !NTG_CORE_VALUE_HH
Index: integre/ntg/real/typetraits_builtin_int.hh
--- integre/ntg/real/typetraits_builtin_int.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/g/3_typetraits 1.7.1.12 640)
+++ integre/ntg/real/typetraits_builtin_int.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/g/3_typetraits 1.7.1.13 640)
@@ -36,9 +36,9 @@
| macros |
`-------*/
-# define TYPETRAITS_BUILTIN_INT(Name) \
+# define TYPETRAITS_BUILTIN_INT(Name, Value) \
template<> \
- struct typetraits<Name> \
+ struct typetraits<Name> : public typetraits<Value<Name> > \
{ \
typedef Name self; \
typedef builtin::to_ntg<Name>::ret ntg_type; \
@@ -152,18 +152,18 @@
namespace internal {
- TYPETRAITS_BUILTIN_INT(unsigned long)
- TYPETRAITS_BUILTIN_INT( signed long)
+ TYPETRAITS_BUILTIN_INT(unsigned long, uint_value)
+ TYPETRAITS_BUILTIN_INT(signed long, sint_value)
- TYPETRAITS_BUILTIN_INT(unsigned int)
- TYPETRAITS_BUILTIN_INT( signed int)
+ TYPETRAITS_BUILTIN_INT(unsigned int, uint_value)
+ TYPETRAITS_BUILTIN_INT(signed int, sint_value)
- TYPETRAITS_BUILTIN_INT(unsigned short)
- TYPETRAITS_BUILTIN_INT( signed short)
+ TYPETRAITS_BUILTIN_INT(unsigned short, uint_value)
+ TYPETRAITS_BUILTIN_INT(signed short, sint_value)
- TYPETRAITS_BUILTIN_INT(unsigned char)
- TYPETRAITS_BUILTIN_INT( signed char)
- TYPETRAITS_BUILTIN_INT( char)
+ TYPETRAITS_BUILTIN_INT(unsigned char, uint_value)
+ TYPETRAITS_BUILTIN_INT(signed char, sint_value)
+ TYPETRAITS_BUILTIN_INT(char, sint_value)
} // end of internal.
Index: integre/ntg/real/real_value.hh
--- integre/ntg/real/real_value.hh Sun, 04 May 2003 21:38:39 +0200 burrus_n (oln/s/15_real_value 1.2 640)
+++ integre/ntg/real/real_value.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/s/15_real_value 1.3 640)
@@ -28,42 +28,30 @@
#ifndef NTG_REAL_REAL_VALUE_HH
# define NTG_REAL_REAL_VALUE_HH
+# include <ntg/core/type_traits.hh>
# include <ntg/core/value.hh>
+# define declare_real_value_type__(Type, Parent) \
+ template <class E> \
+ class Type : public Parent<E> \
+ {}; \
+ \
+ namespace internal { \
+ \
+ template <class E> \
+ struct typetraits<Type<E> > : public typetraits<Parent<E> > \
+ {}; \
+ \
+ }
+
namespace ntg
{
- /*-----------.
- | real_value |
- `-----------*/
-
- template <class E>
- class real_value : public value<E>
- {};
-
- /*----------.
- | int_value |
- `----------*/
-
- template <class E>
- class int_value : public real_value<E>
- {};
-
- template <class E>
- class uint_value : public int_value<E>
- {};
-
- template <class E>
- class sint_value : public int_value<E>
- {};
-
- /*------------.
- | float_value |
- `------------*/
-
- template <class E>
- class float_value : public real_value<E>
- {};
+ declare_real_value_type__(real_value, value)
+ declare_real_value_type__(float_value, real_value)
+ declare_real_value_type__(int_value, real_value)
+ declare_real_value_type__(uint_value, int_value)
+ declare_real_value_type__(sint_value, int_value)
} // end of ntg.
Index: integre/ntg/core/internal/traits.hh
--- integre/ntg/core/internal/traits.hh Sun, 03 Aug 2003 21:08:04 +0200 burrus_n (oln/s/16_traits.hh 1.4 640)
+++ integre/ntg/core/internal/traits.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/s/16_traits.hh 1.5 640)
@@ -62,21 +62,6 @@
| optraits |
`---------*/
- // top of hierarchy
- template <class T>
- struct optraits_top
- {};
-
- // enumerated types
- template <class T>
- class optraits_enum : public optraits_top<T>
- {};
-
- // vectorial types
- template <class T>
- class optraits_vector : public optraits_top<T>
- {};
-
//! Associates functions to types.
/*
It should be specialized for every types.
Index: integre/ntg/vect/vect_value.hh
--- integre/ntg/vect/vect_value.hh Sun, 27 Jul 2003 19:14:42 +0200 burrus_n (oln/s/22_vect_value 1.2 640)
+++ integre/ntg/vect/vect_value.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/s/22_vect_value 1.3 640)
@@ -51,6 +51,18 @@
static unsigned size() { return nb_comp; }
};
+ namespace internal {
+
+ template <class E>
+ class typetraits<vect_value<E> > : public typetraits<value<E> >
+ {};
+
+ template <class E>
+ class optraits<vect_value<E> > : public optraits<value<E> >
+ {};
+
+ }
+
}
#endif // !NTG_VECT_VECT_VALUE_HH
Index: integre/ntg/enum/enum_value.hh
--- integre/ntg/enum/enum_value.hh Sun, 04 May 2003 16:11:37 +0200 burrus_n (oln/s/23_enum_value 1.1 640)
+++ integre/ntg/enum/enum_value.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/s/23_enum_value 1.2 640)
@@ -29,6 +29,7 @@
# define NTG_ENUM_ENUM_VALUE_HH
# include <ntg/core/value.hh>
+# include <ntg/core/type_traits.hh>
namespace ntg
{
@@ -41,6 +42,18 @@
class enum_value : public value<E>
{};
+ namespace internal {
+
+ template <class E>
+ class typetraits<enum_value<E> > : public typetraits<value<E> >
+ {};
+
+ template <class E>
+ class optraits<enum_value<E> > : public optraits<value<E> >
+ {};
+
+ }
+
}
#endif // !NTG_ENUM_ENUM_VALUE_HH
Index: integre/ntg/real/builtin_float.hh
--- integre/ntg/real/builtin_float.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/s/47_builtin_fl 1.3 640)
+++ integre/ntg/real/builtin_float.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/s/47_builtin_fl 1.4 640)
@@ -47,7 +47,7 @@
`------------------*/
template <>
- struct typetraits<float>
+ struct typetraits<float> : public typetraits<float_value<float> >
{
typedef float self;
typedef decimal abstract_type;
@@ -76,7 +76,7 @@
`-------------------*/
template <>
- struct typetraits<double>
+ struct typetraits<double> : public typetraits<float_value<double> >
{
typedef double self;
typedef decimal abstract_type;
@@ -105,7 +105,7 @@
`----------------*/
template <>
- struct optraits<float> : public optraits_float<float>
+ struct optraits<float> : public optraits<float_value<float> >
{
private:
typedef float self;
@@ -251,7 +251,7 @@
`-----------------*/
template <>
- struct optraits<double> : public optraits_float<double>
+ struct optraits<double> : public optraits<float_value<double> >
{
private:
// shortcuts
Index: integre/ntg/real/range.hh
--- integre/ntg/real/range.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/t/16_range.hh 1.4 640)
+++ integre/ntg/real/range.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/t/16_range.hh 1.5 640)
@@ -46,7 +46,7 @@
`------------------*/
template <class T, class interval, class behavior>
- struct typetraits<range<T, interval, behavior> >
+ struct typetraits<range<T, interval, behavior> > : public typetraits<T>
{
typedef range<T, interval, behavior> self;
typedef ntgi_abstract_type(T) abstract_type;
Index: integre/ntg/real/cycle.hh
--- integre/ntg/real/cycle.hh Mon, 21 Jul 2003 17:51:12 +0200 burrus_n (oln/t/17_cycle.hh 1.2 640)
+++ integre/ntg/real/cycle.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/t/17_cycle.hh 1.3 640)
@@ -46,7 +46,7 @@
`------------------*/
template <class T, class interval>
- struct typetraits<cycle<T, interval> >
+ struct typetraits<cycle<T, interval> > : public typetraits<T>
{
typedef cycle<T, interval> self;
typedef typename typetraits<T>::abstract_type abstract_type;
Index: integre/ntg/vect/vec.hh
--- integre/ntg/vect/vec.hh Thu, 07 Aug 2003 02:37:23 +0200 burrus_n (oln/t/18_vec.hh 1.7 640)
+++ integre/ntg/vect/vec.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/t/18_vec.hh 1.8 640)
@@ -89,7 +89,7 @@
`----------------*/
template <unsigned N, class T, class Self>
- struct typetraits<vec<N, T, Self> >
+ struct typetraits<vec<N, T, Self> > : public typetraits<vect_value<vec<N, T, Self> > >
{
enum { nb_comp = N };
@@ -186,7 +186,7 @@
`--------------*/
template <unsigned N, class T, class E>
- class optraits<vec<N, T, E> > : public optraits_vector<vec<N, T, E> >
+ class optraits<vec<N, T, E> > : public optraits<vect_value<vec<N, T, E> > >
{
typedef vec<N, T, E> self;
typedef ntgi_storage_type(self) storage_type_;
Index: integre/ntg/enum/bin.hh
--- integre/ntg/enum/bin.hh Mon, 10 Nov 2003 11:19:49 +0100 burrus_n (oln/t/21_bin.hh 1.5 640)
+++ integre/ntg/enum/bin.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/t/21_bin.hh 1.6 640)
@@ -49,7 +49,7 @@
`----------------*/
template <>
- struct typetraits<bin>
+ struct typetraits<bin> : typetraits<enum_value<bin> >
{
typedef binary abstract_type;
typedef bin self;
@@ -133,7 +133,7 @@
`--------------*/
template <>
- struct optraits<bin> : public optraits_enum<bin>
+ struct optraits<bin> : public optraits<enum_value<bin> >
{
private:
typedef typetraits<bin>::storage_type storage_type_;
1
0
Un peu de cleanup de fait jamais de mal.
Index: integre/ChangeLog
from Nicolas Burrus <burrus_n(a)lrde.epita.fr>
* ntg/real/optraits_scalar_defs.hh: Rename as...
* ntg/real/optraits_real_defs.hh: ... this.
* ntg/real/optraits_scalar.hh: Rename as...
* ntg/real/optraits_real.hh: ... this.
* ntg/core/behavior.hh: Rename as...
* ntg/real/behavior.hh: ... this.
* ntg/real/int_s.hh,
* ntg/real/int_u.hh,
* ntg/real/optraits_builtin_int.hh,
* ntg/real/typetraits_builtin_int.hh,
* ntg/Makefile.am,
* ntg/basics.hh,
* ntg/real/builtin_float.hh,
* ntg/enum/builtin_bool.hh,
* ntg/real/range.hh: Adjust consequently.
Index: integre/ntg/real/behavior.hh
--- integre/ntg/core/behavior.hh Mon, 01 Sep 2003 19:55:03 +0200 burrus_n (oln/g/31_behaviour. 1.13.1.15 640)
+++ integre/ntg/real/behavior.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/g/31_behaviour. 1.13.1.16 640)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef NTG_CORE_BEHAVIOUR_HH
-# define NTG_CORE_BEHAVIOUR_HH
+#ifndef NTG_REAL_BEHAVIOUR_HH
+# define NTG_REAL_BEHAVIOUR_HH
/*
Behaviors for data_types int_u, int_s, etc ...
@@ -45,7 +45,7 @@
# include <ntg/core/type_traits.hh>
# include <ntg/core/value.hh>
# include <ntg/core/internal/macros.hh>
-# include <ntg/real/optraits_scalar.hh>
+# include <ntg/real/optraits_real.hh>
# include <ntg/real/real_value.hh>
# include <ntg/utils/debug.hh>
# include <ntg/utils/cast.hh>
@@ -376,4 +376,4 @@
} // end of ntg.
-#endif // !NTG_CORE_BEHAVIOUR_HH
+#endif // !NTG_REAL_BEHAVIOUR_HH
Index: integre/ntg/real/int_s.hh
--- integre/ntg/real/int_s.hh Sun, 27 Jul 2003 19:14:42 +0200 burrus_n (oln/g/24_int_s.hh 1.16.1.16 640)
+++ integre/ntg/real/int_s.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/g/24_int_s.hh 1.16.1.17 640)
@@ -29,7 +29,7 @@
# define NTG_CORE_INT_S_HH
# include <ntg/basics.hh>
-# include <ntg/real/optraits_scalar.hh>
+# include <ntg/real/optraits_real.hh>
# include <ntg/real/real_value.hh>
# include <ntg/bin.hh>
Index: integre/ntg/real/int_u.hh
--- integre/ntg/real/int_u.hh Sun, 27 Jul 2003 19:14:42 +0200 burrus_n (oln/g/23_int_u.hh 1.19.1.16 640)
+++ integre/ntg/real/int_u.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/g/23_int_u.hh 1.19.1.17 640)
@@ -29,7 +29,7 @@
# define NTG_REAL_INT_U_HH
# include <ntg/basics.hh>
-# include <ntg/real/optraits_scalar.hh>
+# include <ntg/real/optraits_real.hh>
# include <ntg/real/real_value.hh>
# include <ntg/bin.hh>
Index: integre/ntg/real/optraits_builtin_int.hh
--- integre/ntg/real/optraits_builtin_int.hh Wed, 30 Jul 2003 18:49:16 +0200 burrus_n (oln/g/18_optraits_b 1.6.1.8 640)
+++ integre/ntg/real/optraits_builtin_int.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/g/18_optraits_b 1.6.1.9 640)
@@ -33,7 +33,7 @@
*/
# include <ntg/config/system.hh>
-# include <ntg/real/optraits_scalar.hh>
+# include <ntg/real/optraits_real.hh>
# include <ntg/real/typetraits_builtin_int.hh>
// FIXME: this should be included by system.hh.
Index: integre/ntg/real/optraits_real_defs.hh
--- integre/ntg/real/optraits_scalar_defs.hh Mon, 01 Sep 2003 19:55:03 +0200 burrus_n (oln/g/11_optraits_s 1.14 640)
+++ integre/ntg/real/optraits_real_defs.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/g/11_optraits_s 1.15 640)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef NTG_OPTRAITS_SCALAR_DEFS_HH
-# define NTG_OPTRAITS_SCALAR_DEFS_HH
+#ifndef NTG_OPTRAITS_REAL_DEFS_HH
+# define NTG_OPTRAITS_REAL_DEFS_HH
//
// macros used in optraits_scalar definition
@@ -169,4 +169,4 @@
return result; \
}
-#endif // ndef NTG_OPTRAITS_SCALAR_DEFS_HH
+#endif // ndef NTG_OPTRAITS_REAL_DEFS_HH
Index: integre/ntg/real/optraits_real.hh
--- integre/ntg/real/optraits_scalar.hh Wed, 30 Jul 2003 18:49:16 +0200 burrus_n (oln/g/12_optraits_s 1.11.1.8 640)
+++ integre/ntg/real/optraits_real.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/g/12_optraits_s 1.11.1.9 640)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef NTG_OPTRAITS_SCALAR_HH_
-# define NTG_OPTRAITS_SCALAR_HH_
+#ifndef NTG_OPTRAITS_REAL_HH_
+# define NTG_OPTRAITS_REAL_HH_
# include <cmath>
@@ -43,7 +43,7 @@
# include <ntg/core/macros.hh>
// macros definitions
-# include <ntg/real/optraits_scalar_defs.hh>
+# include <ntg/real/optraits_real_defs.hh>
namespace ntg {
@@ -146,4 +146,4 @@
} // end of ntg
-#endif // ndef NTG_OPTRAITS_SCALAR_HH_
+#endif // ndef NTG_OPTRAITS_REAL_HH_
Index: integre/ntg/real/typetraits_builtin_int.hh
--- integre/ntg/real/typetraits_builtin_int.hh Wed, 30 Jul 2003 18:49:16 +0200 burrus_n (oln/g/3_typetraits 1.7.1.11 640)
+++ integre/ntg/real/typetraits_builtin_int.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/g/3_typetraits 1.7.1.12 640)
@@ -28,7 +28,7 @@
#ifndef NTG_REAL_TYPETRAITS_BUILTIN_INT_HH
# define NTG_REAL_TYPETRAITS_BUILTIN_INT_HH
-# include <ntg/core/behavior.hh>
+# include <ntg/real/behavior.hh>
# include <ntg/core/predecls.hh>
# include <ntg/core/type_traits.hh>
Index: integre/ntg/Makefile.am
--- integre/ntg/Makefile.am Tue, 13 May 2003 21:32:45 +0200 burrus_n (oln/q/36_Makefile.a 1.8 640)
+++ integre/ntg/Makefile.am Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/q/36_Makefile.a 1.9 640)
@@ -18,7 +18,7 @@
config/math.hh \
config/system.hh \
core/abstract_hierarchy.hh \
- core/behavior.hh \
+ real/behavior.hh \
core/contract.hh \
core/internal/global_ops.hh \
core/internal/global_ops_defs.hh \
@@ -46,8 +46,8 @@
real/int_s.hh \
real/int_u.hh \
real/optraits_builtin_int.hh \
- real/optraits_scalar.hh \
- real/optraits_scalar_defs.hh \
+ real/optraits_real.hh \
+ real/optraits_real_defs.hh \
real/range.hh \
real/real_value.hh \
real/typetraits_builtin_int.hh \
Index: integre/ntg/basics.hh
--- integre/ntg/basics.hh Tue, 13 May 2003 21:32:45 +0200 burrus_n (oln/s/21_basics.hh 1.3 640)
+++ integre/ntg/basics.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/s/21_basics.hh 1.4 640)
@@ -38,7 +38,7 @@
# include <ntg/core/predecls.hh>
# include <ntg/core/abstract_hierarchy.hh>
-# include <ntg/core/behavior.hh>
+# include <ntg/real/behavior.hh>
# include <ntg/core/contract.hh>
# include <ntg/core/interval.hh>
# include <ntg/real/builtin_properties.hh>
Index: integre/ntg/real/builtin_float.hh
--- integre/ntg/real/builtin_float.hh Mon, 21 Jul 2003 17:51:12 +0200 burrus_n (oln/s/47_builtin_fl 1.2 640)
+++ integre/ntg/real/builtin_float.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/s/47_builtin_fl 1.3 640)
@@ -29,11 +29,11 @@
# define NTG_REAL_BUILTIN_FLOAT_HH
# include <ntg/config/system.hh>
-# include <ntg/core/behavior.hh>
+# include <ntg/real/behavior.hh>
# include <ntg/core/internal/global_ops_traits.hh>
# include <ntg/core/internal/traits.hh>
# include <ntg/real/builtin_properties.hh>
-# include <ntg/real/optraits_scalar.hh>
+# include <ntg/real/optraits_real.hh>
# include <ntg/core/predecls.hh>
# include <mlc/cmp.hh>
Index: integre/ntg/enum/builtin_bool.hh
--- integre/ntg/enum/builtin_bool.hh Sun, 27 Jul 2003 19:14:42 +0200 burrus_n (oln/s/50_builtin_bo 1.4 640)
+++ integre/ntg/enum/builtin_bool.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/s/50_builtin_bo 1.5 640)
@@ -29,7 +29,7 @@
# define NTG_ENUM_BUILTIN_BOOL_HH
# include <ntg/core/abstract_hierarchy.hh>
-# include <ntg/core/behavior.hh>
+# include <ntg/real/behavior.hh>
# include <ntg/core/predecls.hh>
# include <ntg/core/type_traits.hh>
Index: integre/ntg/real/range.hh
--- integre/ntg/real/range.hh Sun, 27 Jul 2003 19:14:42 +0200 burrus_n (oln/t/16_range.hh 1.3 640)
+++ integre/ntg/real/range.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/t/16_range.hh 1.4 640)
@@ -32,7 +32,7 @@
# include <ntg/basics.hh>
# include <ntg/core/internal/macros.hh>
-# include <ntg/real/optraits_scalar.hh>
+# include <ntg/real/optraits_real.hh>
# include <string>
# include <sstream>
1
0
j'ai posé ici :
/mnt/doc/computer_vision/color/ecole_ete_99/
les documents (supports de présentation, articles, etc.)
liés à une école d'été sur la couleur qui a eu lieu en 1999.
je vous conseille à tous Lambert.pdf sur les pré-traitements
et BrunP.pdf sur la segmentation en général. Ensuite,
MacaireP.pdf, toujours sur la segmentation, est un bon
complément.
Les autres documents sont plus éloignés de nos préoccupations.
1
0
Index: olena/ChangeLog
from Nicolas Burrus <burrus_n(a)lrde.epita.fr>
* oln/utils/timer.hh: Improve. Can give the elapsed time since the
last resume.
* tests/utils/tests/timer: Adjust consequently.
* tests/morpho/tests/overall_benchs: New test.
* tests/core/tests/benchs: New test.
+2003-11-07 Nicolas Burrus <burrus_n(a)lrde.epita.fr>
+
* oln/arith/internal/opdecls.hh: Add missing default functors.
* oln/level/cc.hh: Use default arithmetic functor.
Index: olena/oln/utils/timer.hh
--- olena/oln/utils/timer.hh Thu, 07 Aug 2003 02:37:23 +0200 burrus_n (oln/8_timer.hh 1.7 640)
+++ olena/oln/utils/timer.hh Fri, 07 Nov 2003 17:34:52 +0100 burrus_n (oln/8_timer.hh 1.8 640)
@@ -50,6 +50,7 @@
{
assertion(status_ != e_running);
total_time_ = 0;
+ stop_time_ = 0;
status_ = e_running;
start_time_ = clock();
}
@@ -58,7 +59,7 @@
restart()
{
assertion(status_ != e_unknown);
- float val = value();
+ float val = total_time();
start();
return val;
}
@@ -75,13 +76,25 @@
stop()
{
assertion(status_ == e_running);
- total_time_ += (clock() - start_time_);
+ stop_time_ = clock();
+ total_time_ += (stop_time_ - start_time_);
status_ = e_stopped;
- return value();
+ return total_time();
}
+ // Time since the last resume() or start()
float
- value()
+ last_time() const
+ {
+ assertion(status_ != e_unknown);
+ return
+ status_ == e_stopped ?
+ float(stop_time_ - start_time_) / CLOCKS_PER_SEC :
+ float((clock() - start_time_)) / CLOCKS_PER_SEC;
+ }
+
+ float
+ total_time() const
{
assertion(status_ != e_unknown);
return
@@ -99,6 +112,7 @@
} status_;
clock_t total_time_;
clock_t start_time_;
+ clock_t stop_time_;
};
} // end of namespace utils
Index: olena/tests/morpho/tests/reconstruction
--- olena/tests/morpho/tests/reconstruction Wed, 08 Oct 2003 11:15:11 +0200 burrus_n (oln/e/34_reconstruc 1.11 640)
+++ olena/tests/morpho/tests/reconstruction Fri, 07 Nov 2003 17:34:52 +0100 burrus_n (oln/e/34_reconstruc 1.12 640)
@@ -24,6 +24,10 @@
fail = true; \
}
+// FIXME: reference images are several times computed twice, this
+// should be factorized! For example,
+// morpho::sure::regional_minima(lena, ...) is computed twice.
+
bool
check()
{
Index: olena/tests/utils/tests/timer
--- olena/tests/utils/tests/timer Thu, 07 Aug 2003 02:37:23 +0200 burrus_n (oln/u/29_timer.cc 1.3 600)
+++ olena/tests/utils/tests/timer Fri, 07 Nov 2003 17:34:52 +0100 burrus_n (oln/u/29_timer.cc 1.4 600)
@@ -30,14 +30,14 @@
t.stop();
- float b = t.value();
+ float b = t.total_time();
t.resume();
for (int i = 0; i < 1000000000; )
++i;
- b = t.value() - b;
+ b = t.total_time() - b;
if (b >= 0)
OK_OR_FAIL;
Index: olena/tests/morpho/tests/overall_benchs
--- olena/tests/morpho/tests/overall_benchs Fri, 07 Nov 2003 17:38:50 +0100 burrus_n ()
+++ olena/tests/morpho/tests/overall_benchs Fri, 07 Nov 2003 17:34:52 +0100 burrus_n (oln/v/36_overall_be 1.1 640)
@@ -0,0 +1,99 @@
+// -*- c++ -*-
+
+#include <oln/basics2d.hh>
+#include <oln/morpho/watershed.hh>
+#include <oln/morpho/extrema_killer.hh>
+#include <oln/morpho/opening.hh>
+#include <oln/morpho/geodesic_dilation.hh>
+#include <oln/morpho/geodesic_erosion.hh>
+#include <oln/morpho/reconstruction.hh>
+#include <oln/morpho/extrema.hh>
+#include <oln/utils/timer.hh>
+
+#include <ntg/all.hh>
+
+#include "check.hh"
+#include "data.hh"
+
+#include <iostream>
+
+using namespace oln;
+using namespace oln::morpho;
+using namespace ntg;
+
+void bench_extrema()
+{
+ image2d<int_u8> lena = load(rdata("lena128.pgm"));
+
+ unsigned size = 20;
+ sure_minima_killer(lena, size, neighb_c4());
+ fast_minima_killer(lena, size, neighb_c4());
+ sure_maxima_killer(lena, size, neighb_c4());
+ fast_maxima_killer(lena, size, neighb_c4());
+}
+
+void bench_reconstruction()
+{
+ image2d<int_u8> lena = load(rdata("lena128.pgm"));
+ image2d<int_u8> lena_open = morpho::opening(lena, win_c4p());
+ image2d<ntg::bin> minima_map(lena.size());
+ image2d<int_u8> max_map(lena.size());
+
+ level::fill (minima_map, false);
+ level::fill (max_map, 255);
+ minima_map(10,10) = true;
+ minima_map(100,100) = true;
+
+ morpho::sure::regional_minima(lena, neighb_c4());
+ morpho::sequential::regional_minima(lena, neighb_c4());
+ morpho::hybrid::regional_minima(lena, neighb_c4());
+
+ morpho::sure::minima_imposition(lena, minima_map, neighb_c4());
+ morpho::geodesic_erosion(lena, lena_open, neighb_c4());
+ morpho::sure::geodesic_dilation(lena_open, lena, neighb_c4());
+
+ morpho::sequential::geodesic_reconstruction_erosion
+ (max_map, lena_open, neighb_c4());
+ morpho::sure::geodesic_reconstruction_dilation
+ (lena_open, lena, neighb_c4());
+}
+
+void bench_watershed()
+{
+ image2d<int_u8> lena = load(rdata("lena128.pgm"));
+
+ for (int i = 0; i < 200; ++i)
+ watershed_seg<int_u16>(lena, neighb_c4());
+}
+
+void print_info(const oln::utils::timer& t, std::string name)
+{
+ std::cout << t.total_time() << "\t\t(" << name << ": "
+ << t.last_time() << ")" << std::endl;
+}
+
+bool check()
+{
+ bool fail = false;
+
+ oln::utils::timer t;
+
+ bench_extrema();
+
+ t.start();
+ bench_extrema();
+ print_info(t, "extrema killers");
+ t.stop();
+
+ t.resume();
+ bench_watershed();
+ print_info(t, "wastershed");
+ t.stop();
+
+ t.resume();
+ bench_reconstruction();
+ print_info(t, "reconstructions");
+ t.stop();
+
+ return fail;
+}
Index: olena/tests/core/tests/benchs
--- olena/tests/core/tests/benchs Fri, 07 Nov 2003 17:38:50 +0100 burrus_n ()
+++ olena/tests/core/tests/benchs Fri, 07 Nov 2003 17:34:52 +0100 burrus_n (oln/v/37_benchs 1.1 600)
@@ -0,0 +1,44 @@
+// -*- c++ -*-
+
+#include <iostream>
+
+#include <oln/basics1d.hh>
+#include <oln/basics2d.hh>
+#include <oln/basics3d.hh>
+
+#include <oln/utils/timer.hh>
+
+#include <ntg/all.hh>
+
+using namespace oln;
+using namespace ntg;
+
+template <class I>
+void abstract_fill_image(abstract::image<I>& ima)
+{
+ oln_iter_type(I) p (ima.exact());
+ for_all(p)
+ ima[p] = p.row() + p.col();
+}
+
+template <class I>
+void concrete_fill_image(I& ima)
+{
+ oln_iter_type(I) p (ima);
+ for_all(p)
+ ima[p] = p.row() + p.col();
+}
+
+int main()
+{
+ oln::image2d<int_u32> ima(10000, 10000);
+ oln::utils::timer t;
+ t.start();
+ abstract_fill_image(ima);
+ t.stop();
+ std::cout << "With abstract: " << t.total_time() << std::endl;
+ t.restart();
+ concrete_fill_image(ima);
+ t.stop();
+ std::cout << "With concrete: " << t.total_time() << std::endl;
+}
4
3
Voila, j'ai fini de flusher les patchs que j'avais en attente :)
Index: tools/swilena/ChangeLog
from Nicolas Burrus <burrus_n(a)lrde.epita.fr>
* python/swilena_all1d.py: New.
* python/swilena_all2d.py: New.
* python/swilena_all2d.py: New.
* python/Makefile.am: New.
Index: tools/swilena/python/Makefile.am
--- tools/swilena/python/Makefile.am Mon, 10 Nov 2003 14:16:30 +0100 burrus_n ()
+++ tools/swilena/python/Makefile.am Mon, 10 Nov 2003 14:12:17 +0100 burrus_n (oln/w/2_Makefile.a 1.1 640)
@@ -0,0 +1,10 @@
+## Process this file through Automake to produce Makefile.in -*- Makefile -*-
+##
+## Makefile.am for swilena/python
+##
+
+SUBDIRS = . tests
+
+python_PYTHON = swilena_display.py swilena_all1d.py swilena_all2d.py swilena_all3d.py
+
+include makefile.swig
Index: tools/swilena/python/swilena_all1d.py
--- tools/swilena/python/swilena_all1d.py Mon, 10 Nov 2003 14:16:30 +0100 burrus_n ()
+++ tools/swilena/python/swilena_all1d.py Mon, 10 Nov 2003 14:12:17 +0100 burrus_n (oln/w/3_swilena_al 1.1 640)
@@ -0,0 +1,14 @@
+# Utility module which includes everything available in swilena
+# FIXME: should be generated
+
+from swilena_image1d import *
+from swilena_imagesize1d import *
+from swilena_point1d import *
+from swilena_morpho1d import *
+from swilena_structelt1d import *
+from swilena_w_win1d import *
+from swilena_conversions1d import *
+from swilena_arith1d import *
+
+from swilena_ntg import *
+from swilena_display import *
Index: tools/swilena/python/swilena_all2d.py
--- tools/swilena/python/swilena_all2d.py Mon, 10 Nov 2003 14:16:30 +0100 burrus_n ()
+++ tools/swilena/python/swilena_all2d.py Mon, 10 Nov 2003 14:12:17 +0100 burrus_n (oln/w/4_swilena_al 1.1 640)
@@ -0,0 +1,14 @@
+# Utility module which includes everything available in swilena
+# FIXME: should be generated
+
+from swilena_image2d import *
+from swilena_imagesize2d import *
+from swilena_point2d import *
+from swilena_morpho2d import *
+from swilena_structelt2d import *
+from swilena_w_win2d import *
+from swilena_conversions2d import *
+from swilena_arith2d import *
+
+from swilena_ntg import *
+from swilena_display import *
Index: tools/swilena/python/swilena_all3d.py
--- tools/swilena/python/swilena_all3d.py Mon, 10 Nov 2003 14:16:30 +0100 burrus_n ()
+++ tools/swilena/python/swilena_all3d.py Mon, 10 Nov 2003 14:12:17 +0100 burrus_n (oln/w/5_swilena_al 1.1 640)
@@ -0,0 +1,14 @@
+# Utility module which includes everything available in swilena
+# FIXME: should be generated
+
+from swilena_image3d import *
+from swilena_imagesize3d import *
+from swilena_point3d import *
+from swilena_morpho3d import *
+from swilena_structelt3d import *
+from swilena_w_win3d import *
+from swilena_conversions3d import *
+from swilena_arith3d import *
+
+from swilena_ntg import *
+from swilena_display import *
1
0
Index: tools/swilena/ChangeLog
from Nicolas Burrus <burrus_n(a)lrde.epita.fr>
* meta/swilena_arith.i: New.
* generate_arith_instantiations.py: New.
* python/tests/arith.py: New test.
* meta/swilena_conversions.i: New.
* generate_conversions_instantiations.py: New.
* python/tests/conversions.py: New test.
* generate_morpho_instantiations.py: Update.
* python/tests/morpho.py: New test.
* expand.sh: Adjust consequently.
* meta/Makefile.am: Likewise.
* python/tests/Makefile.am: Likewise.
Index: tools/swilena/expand.sh
--- tools/swilena/expand.sh Thu, 09 Oct 2003 16:21:55 +0200 burrus_n (oln/s/25_expand.sh 1.11 750)
+++ tools/swilena/expand.sh Mon, 10 Nov 2003 14:09:27 +0100 burrus_n (oln/s/25_expand.sh 1.12 750)
@@ -9,7 +9,7 @@
mkdir -p "$SWILENA/python"
mkdir -p "$SWILENA/ruby"
-MODULES="$MODULES ntg morpho"
+MODULES="$MODULES ntg"
for dim in 1 2 3; do
## {1d,2d,3d} families
@@ -30,6 +30,7 @@
## Image instances
cat >>"$SWILENA/src/swilena_image${dim}d.i" <<EOF
+%include swilena_ntg_macros.i
%import swilena_ntg.i
EOF
# int_u8 int_u16 int_s8 int_s16 int_s8s int_s16s int_s32s
@@ -43,9 +44,18 @@
make_image(image${dim}d_s32, $dim, ntg_int_s32, ntg_int_s32_value)
make_image(image${dim}d_float, $dim, ntg_float, ntg_float_value)
EOF
+
## Morpho algorithms
MODULES="$MODULES morpho${dim}d"
- cd "$SWILENA/src" && ../generate_morpho_instantiations.py && cd ..
+ $SWILENA/generate_morpho_instantiations.py $SWILENA/src
+
+ ## Arith
+ MODULES="$MODULES arith${dim}d"
+ $SWILENA/generate_arith_instantiations.py $SWILENA/src
+
+ ## Conversions
+ MODULES="$MODULES conversions${dim}d"
+ $SWILENA/generate_conversions_instantiations.py $SWILENA/src
done # for dim ...
#################### Python stuff #######################
Index: tools/swilena/meta/Makefile.am
--- tools/swilena/meta/Makefile.am Sat, 27 Sep 2003 19:02:23 +0200 burrus_n (oln/s/26_Makefile.a 1.2 640)
+++ tools/swilena/meta/Makefile.am Mon, 10 Nov 2003 14:09:27 +0100 burrus_n (oln/s/26_Makefile.a 1.3 640)
@@ -2,6 +2,7 @@
EXTRA_DIST = swilena_core.i swilena_decl.i swilena_describe.i \
swilena_exception.i swilena_image.i swilena_imagesize.i \
- swilena_morpho.i swilena_ntg.i swilena_point.i \
+ swilena_morpho.i swilena_arith.i swilena_conversions.i \
+ swilena_ntg.i swilena_point.i \
swilena_structelt.i \
swilena_w_win.i
Index: tools/swilena/python/tests/Makefile.am
--- tools/swilena/python/tests/Makefile.am Sun, 21 Sep 2003 23:13:48 +0200 burrus_n (oln/v/15_Makefile.a 1.1 600)
+++ tools/swilena/python/tests/Makefile.am Mon, 10 Nov 2003 14:09:27 +0100 burrus_n (oln/v/15_Makefile.a 1.2 600)
@@ -4,7 +4,7 @@
##
TESTS_ENVIRONMENT = \
- PYTHONPATH="$(PYTHONPATH):.." \
+ PYTHONPATH="$(PYTHONPATH):..:$(srcdir)/.." \
IMGDIR="$(top_srcdir)/olena/img"
-TESTS = simple1.py
+TESTS = arith.py conversions.py simple1.py morpho.py
Index: tools/swilena/generate_morpho_instantiations.py
--- tools/swilena/generate_morpho_instantiations.py Sat, 08 Nov 2003 18:17:07 +0100 burrus_n (oln/v/24_generate_m 1.3 700)
+++ tools/swilena/generate_morpho_instantiations.py Mon, 10 Nov 2003 14:09:27 +0100 burrus_n (oln/v/24_generate_m 1.4 700)
@@ -123,13 +123,13 @@
instantiate(dim, "top_hat_contrast_op", img_type, img_type, win_type)
instantiate(dim, "fast_top_hat_contrast_op", img_type, img_type, win_type)
- # FIXME: watershed only works with ntg_int_u8
- if type == "ntg_int_u32":
+ # FIXME: fix this when available
+ #if type == "ntg_int_u8":
# Watershed
- img_ret_type = "::oln::image%(dim)sd< ntg_int_u32 >" % vars()
- instantiate(dim, "watershed_seg", img_ret_type, img_type, neighb_type)
- instantiate(dim, "watershed_con", img_ret_type, img_type, neighb_type)
- instantiate(dim, "watershed_seg_or", img_type, img_type, img_ret_type, neighb_type)
+ #img_ret_type = "::oln::image%(dim)sd< ntg_int_u32 >" % vars()
+ #instantiate(dim, "watershed_seg", img_ret_type, img_type, neighb_type)
+ #instantiate(dim, "watershed_con", img_ret_type, img_type, neighb_type)
+ #instantiate(dim, "watershed_seg_or", img_type, img_type, img_ret_type, neighb_type)
# FIXME: this is broken
# instantiate(dim, "laplacian", img_type, img_type, win_type)
Index: tools/swilena/python/tests/morpho.py
--- tools/swilena/python/tests/morpho.py Mon, 10 Nov 2003 14:15:38 +0100 burrus_n ()
+++ tools/swilena/python/tests/morpho.py Mon, 10 Nov 2003 14:09:27 +0100 burrus_n (oln/v/47_morpho.py 1.1 700)
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+
+import os
+import sys
+from swilena_all2d import *
+
+imgdir = os.environ['IMGDIR']
+
+lena = image2d_u8(load(imgdir + "/lena.pgm"))
+closing(lena, win_c4p())
+#watershed_seg(lena, neighb_c4())
Index: tools/swilena/meta/swilena_arith.i
--- tools/swilena/meta/swilena_arith.i Mon, 10 Nov 2003 14:15:38 +0100 burrus_n ()
+++ tools/swilena/meta/swilena_arith.i Mon, 10 Nov 2003 14:09:27 +0100 burrus_n (oln/v/48_swilena_ar 1.1 640)
@@ -0,0 +1,54 @@
+// -*- C++ -*-
+
+%include swilena_describe.i
+%include swilena_core.i
+
+%define decl_arith(Dim)
+
+#if Dim == 1
+%{
+#include <oln/basics1d.hh>
+%}
+#elif Dim == 2
+%{
+#include <oln/basics2d.hh>
+%}
+#elif Dim == 3
+%{
+#include <oln/basics3d.hh>
+%}
+#endif
+
+%{
+#include <oln/arith/ops.hh>
+%}
+
+%inline %{
+
+ template<class R, class I1, class I2>
+ static R my_plus(const I1& i1, const I2& i2)
+ { return ::oln::arith::plus<R>(i1, i2); }
+
+ template<class R, class I1, class I2>
+ static R my_minus(const I1& i1, const I2& i2)
+ { return ::oln::arith::minus<R>(i1, i2); }
+
+ template<class R, class I1, class I2>
+ static R my_times(const I1& i1, const I2& i2)
+ { return ::oln::arith::times<R>(i1, i2); }
+
+ template<class R, class I1, class I2>
+ static R my_div(const I1& i1, const I2& i2)
+ { return ::oln::arith::div<R>(i1, i2); }
+
+ template<class R, class I1, class I2>
+ static R my_min(const I1& i1, const I2& i2)
+ { return ::oln::arith::min<R>(i1, i2); }
+
+ template<class R, class I1, class I2>
+ static R my_max(const I1& i1, const I2& i2)
+ { return ::oln::arith::max<R>(i1, i2); }
+
+%}
+
+%enddef
Index: tools/swilena/meta/swilena_conversions.i
--- tools/swilena/meta/swilena_conversions.i Mon, 10 Nov 2003 14:15:38 +0100 burrus_n ()
+++ tools/swilena/meta/swilena_conversions.i Mon, 10 Nov 2003 14:09:27 +0100 burrus_n (oln/v/49_swilena_co 1.1 600)
@@ -0,0 +1,28 @@
+// -*- C++ -*-
+
+%include swilena_describe.i
+%include swilena_core.i
+
+%define decl_conversions(Dim)
+
+%{
+#include <oln/convert/basics.hh>
+%}
+
+// FIXME: not very elegant, but %{ %} blocks are not preprocessed.
+
+#if Dim == 1
+%{
+#include <oln/basics1d.hh>
+%}
+#elif Dim == 2
+%{
+#include <oln/basics2d.hh>
+%}
+#elif Dim == 3
+%{
+#include <oln/basics3d.hh>
+%}
+#endif
+
+%enddef
Index: tools/swilena/generate_conversions_instantiations.py
--- tools/swilena/generate_conversions_instantiations.py Mon, 10 Nov 2003 14:15:38 +0100 burrus_n ()
+++ tools/swilena/generate_conversions_instantiations.py Mon, 10 Nov 2003 14:09:27 +0100 burrus_n (oln/v/50_generate_c 1.1 700)
@@ -0,0 +1,121 @@
+#!/usr/bin/env python
+
+import sys
+
+files = []
+
+def close_files():
+ for file in files:
+ file.close()
+
+def open_files(path):
+ for dim in range(1, 4):
+ files.append(open(path + "/swilena_conversions%(dim)sd.i" % vars(), 'w'))
+
+def write_headers():
+ for dim in range(1, 4):
+ file = files[dim - 1]
+ file.write("""// Note: this file was generated by generate_conversions_instantiations.py.
+
+%%module swilena_conversions%(dim)sd
+
+%%include swilena_exception.i
+
+%%include swilena_ntg_macros.i
+%%import swilena_image%(dim)sd.i
+%%import swilena_ntg.i
+
+%%include swilena_conversions.i
+
+decl_conversions(%(dim)s)
+""" % vars())
+
+def instantiate(dim, algo, name, img_from, img_to):
+ file = files[dim - 1]
+ file.write("""
+//
+// %(img_from)s ==> %(img_to)s
+//
+
+%%newobject %(algo)s_to_%(name)s;
+
+%%inline %%{
+namespace oln {
+ namespace convert {
+
+ %(img_to)s &
+ %(algo)s_to_%(name)s(const %(img_from)s& i)
+ {
+ typedef %(img_to)s::value_type to_value_type;
+ return *new %(img_to)s(oln::apply(oln::convert::%(algo)s< to_value_type >(), i));
+ }
+ }
+}
+%%}
+""" % vars())
+
+def get_name(type):
+ # Remove the ntg_ prefix
+ return type[4:]
+
+def write_algorithms():
+ reduce_relations = [ ("ntg_int_u32", "ntg_int_u8"),
+ ("ntg_int_s32", "ntg_int_s8") ]
+
+ # FIXME: no conversions from float are available
+
+ # Note: no conversion to bin available, one should use a threshold
+ # instead.
+
+ integer_types = [ "ntg_int_u8", "ntg_int_u32",
+ "ntg_int_s8", "ntg_int_s32" ]
+
+ scalar_types = integer_types + [ "ntg_float" ]
+
+ # Algorithms with all types and all dims
+ for dim in range(1, 4):
+ # stretch, bound and force
+ for relation in reduce_relations:
+ for algo in ["stretch", "bound"]:
+ from_type = relation[0]
+ to_type = relation[1]
+ from_img = "::oln::image%(dim)sd< %(from_type)s >" % vars()
+ to_img = "::oln::image%(dim)sd< %(to_type)s >" % vars()
+ instantiate(dim, algo, get_name(to_type), from_img, to_img)
+
+ for from_type in scalar_types:
+ for to_type in scalar_types:
+ if from_type != to_type:
+ from_img = "::oln::image%(dim)sd< %(from_type)s >" % vars()
+ to_img = "::oln::image%(dim)sd< %(to_type)s >" % vars()
+ instantiate(dim, "cast", get_name(to_type),
+ from_img, to_img)
+
+ for to_type in scalar_types:
+ from_type = "ntg_bin"
+ from_img = "::oln::image%(dim)sd< %(from_type)s >" % vars()
+ to_img = "::oln::image%(dim)sd< %(to_type)s >" % vars()
+ instantiate(dim, "cast", get_name(to_type),
+ from_img, to_img)
+
+ for from_type in integer_types:
+ to_type = "ntg_bin"
+ from_img = "::oln::image%(dim)sd< %(from_type)s >" % vars()
+ to_img = "::oln::image%(dim)sd< %(to_type)s >" % vars()
+ instantiate(dim, "cast", get_name(to_type),
+ from_img, to_img)
+
+
+def main():
+ if len(sys.argv) != 2:
+ sys.stderr.write ("Usage: generate_conversions_instantiations.py path\n")
+ sys.exit (1)
+ else:
+ path = sys.argv[1]
+ open_files(path)
+ write_headers()
+ write_algorithms()
+ close_files()
+
+if __name__ == "__main__":
+ main()
Index: tools/swilena/generate_arith_instantiations.py
--- tools/swilena/generate_arith_instantiations.py Mon, 10 Nov 2003 14:15:38 +0100 burrus_n ()
+++ tools/swilena/generate_arith_instantiations.py Mon, 10 Nov 2003 14:09:27 +0100 burrus_n (oln/v/51_generate_a 1.1 700)
@@ -0,0 +1,84 @@
+#!/usr/bin/env python
+
+import sys
+
+files = []
+
+def close_files():
+ for file in files:
+ file.close()
+
+def open_files(path):
+ for dim in range(1, 4):
+ files.append(open(path + "/swilena_arith%(dim)sd.i" % vars(), 'w'))
+
+def write_headers():
+ for dim in range(1, 4):
+ file = files[dim - 1]
+ file.write("""// Note: this file was generated by generate_arith.py.
+
+%%module swilena_arith%(dim)sd
+
+%%include swilena_exception.i
+%%include swilena_ntg_macros.i
+%%import swilena_ntg.i
+
+%%include swilena_arith.i
+
+%%import swilena_image%(dim)sd.i
+
+decl_arith(%(dim)s)
+
+""" % vars())
+
+def instantiate(dim, algorithm, *args):
+ file = files[dim - 1]
+ swilena_algorithm = algorithm
+ params = args[0]
+ for param in args[1:]:
+ params += ", " + param
+ file.write(
+ "%%template(%(algorithm)s) my_%(swilena_algorithm)s< %(params)s >;\n"
+ % vars())
+
+def get_bigger_type(type):
+ traits = { "ntg_int_u8" : "ntg_int_u32",
+ "ntg_int_u32" : "ntg_int_u32",
+ "ntg_int_s8" : "ntg_int_s32",
+ "ntg_int_s32" : "ntg_int_s32" }
+ if traits.has_key(type):
+ return traits[type]
+ return type
+
+def write_algorithms():
+ # Algorithms with all types and all dims
+ for dim in range(1, 4):
+ for type in [ "ntg_bin",
+ "ntg_int_u8", "ntg_int_u32",
+ "ntg_int_s8", "ntg_int_s32",
+ "ntg_float" ]:
+ img_type = "::oln::image%(dim)sd< %(type)s >" % vars()
+ bigger_type = get_bigger_type(type)
+ return_img_type = "::oln::image%(dim)sd< %(bigger_type)s >" % vars()
+
+ # FIXME: these algorithms do not work with bin
+ if type != "ntg_bin":
+ for algo in [ "plus", "minus", "times", "div" ]:
+ instantiate(dim, algo, return_img_type, img_type, img_type)
+
+ instantiate(dim, "min", return_img_type, img_type, img_type)
+ instantiate(dim, "max", return_img_type, img_type, img_type)
+
+def main():
+ if len(sys.argv) != 2:
+ sys.stderr.write ("Usage: generate_arith_instantiations.py path\n")
+ sys.exit (1)
+ else:
+ path = sys.argv[1]
+ open_files(path)
+ write_headers()
+ write_algorithms()
+ close_files()
+
+if __name__ == "__main__":
+ main()
Index: tools/swilena/python/tests/arith.py
--- tools/swilena/python/tests/arith.py Mon, 10 Nov 2003 14:15:38 +0100 burrus_n ()
+++ tools/swilena/python/tests/arith.py Mon, 10 Nov 2003 14:09:27 +0100 burrus_n (oln/w/0_arith.py 1.1 750)
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+
+import os
+import sys
+from swilena_arith2d import *
+from swilena_image2d import *
+
+imgdir = os.environ['IMGDIR']
+
+ima1 = image2d_u8(5, 5)
+ima2 = image2d_u8(5, 5)
+
+ima1.set(1, 1, 51)
+ima1.set(2, 2, 42)
+
+ima2.set(0, 0, 12)
+ima2.set(2, 2, 9)
+
+ima = plus(ima1, ima2)
+
+assert(ima.at(0, 0) == 12)
+assert(ima.at(1, 1) == 51)
+assert(ima.at(2, 2) == 51)
Index: tools/swilena/python/tests/conversions.py
--- tools/swilena/python/tests/conversions.py Mon, 10 Nov 2003 14:15:38 +0100 burrus_n ()
+++ tools/swilena/python/tests/conversions.py Mon, 10 Nov 2003 14:09:27 +0100 burrus_n (oln/w/1_conversion 1.1 750)
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+
+import os
+import sys
+from swilena_all2d import *
+
+imgdir = os.environ['IMGDIR']
+
+lena = image2d_u8(load(imgdir + "/lena.pgm"))
+lena32 = cast_to_int_u32(lena)
+
+lena32.set(0, 0, 65536)
+assert(lena32.at(0, 0) == 65536)
+
+lena8 = bound_to_int_u8(lena32)
+assert(lena8.at(0, 0) == 255)
1
0
Index: integre/ChangeLog
from Nicolas Burrus <burrus_n(a)lrde.epita.fr>
* ntg/enum/bin.hh: Fix assignment from a real_value.
Index: tools/swilena/ChangeLog
from Nicolas Burrus <burrus_n(a)epita.fr>
* meta/swilena_ntg_macros.i: New.
* meta/swilena_ntg.i: Include it.
Index: tools/swilena/meta/swilena_ntg.i
--- tools/swilena/meta/swilena_ntg.i Thu, 09 Oct 2003 16:21:55 +0200 burrus_n (oln/s/33_swilena_nt 1.6 640)
+++ tools/swilena/meta/swilena_ntg.i Mon, 10 Nov 2003 11:19:49 +0100 burrus_n (oln/s/33_swilena_nt 1.7 640)
@@ -1,7 +1,6 @@
%module swilena_ntg
%include swilena_exception.i
-
/***** Generic class declaration for scalars ******/
/* Predecls */
@@ -225,32 +224,17 @@
everywhere. ntg_uint is just a convenient macro.
*/
-#define ntg_bin ntg::bin
-#define ntg_bin_value bool
+%include swilena_ntg_macros.i
%template(int_u32) ntg::int_u< 32, ntg::strict >;
-#define ntg_int_u32 ntg::int_u< 32, ntg::strict >
-#define ntg_int_u32_value unsigned long
%template(int_s32) ntg::int_s< 32, ntg::strict >;
-#define ntg_int_s32 ntg::int_s< 32, ntg::strict >
-#define ntg_int_s32_value long
%template(int_u8) ntg::int_u< 8, ntg::strict >;
-#define ntg_int_u8 ntg::int_u< 8, ntg::strict >
-#define ntg_int_u8_value unsigned long
%template(int_s8) ntg::int_s< 8, ntg::strict >;
-#define ntg_int_s8 ntg::int_s< 8, ntg::strict >
-#define ntg_int_s8_value long
-
-#define ntg_float ntg::float_d
-#define ntg_float_value ntg_float
%template(cplx_rect) ntg::cplx< ntg::rect, ntg_float >;
-#define ntg_cplx_rect ntg::cplx< ntg::rect, ntg_float >
-#define ntg_cplx_rect_value ntg_cplx_rect
%template(cplx_polar) ntg::cplx< ntg::polar, ntg_float >;
-#define ntg_cplx_polar ntg::cplx< ntg::polar, ntg_float >
-#define ntg_cplx_polar_value ntg_cplx_polar
+
Index: integre/ntg/enum/bin.hh
--- integre/ntg/enum/bin.hh Thu, 24 Jul 2003 17:46:03 +0200 burrus_n (oln/t/21_bin.hh 1.4 640)
+++ integre/ntg/enum/bin.hh Mon, 10 Nov 2003 11:19:49 +0100 burrus_n (oln/t/21_bin.hh 1.5 640)
@@ -105,14 +105,14 @@
bin (const real_value<T>& val)
{
ntg_assert(val < 2);
- this->val_ = val;
+ this->val_ = val.val();
}
template <class T>
bin&
operator=(const real_value<T>& val)
{
ntg_assert(val < 2);
- this->val_ = val;
+ this->val_ = val.val();
return *this;
}
Index: tools/swilena/meta/swilena_ntg_macros.i
--- tools/swilena/meta/swilena_ntg_macros.i Mon, 10 Nov 2003 14:13:46 +0100 burrus_n ()
+++ tools/swilena/meta/swilena_ntg_macros.i Mon, 10 Nov 2003 11:19:49 +0100 burrus_n (oln/v/39_swilena_nt 1.1 600)
@@ -0,0 +1,57 @@
+// FIXME: avoid code repetitions!
+
+#define ntg_bin ntg::bin
+#define ntg_bin_value bool
+%inline %{
+#define ntg_bin ntg::bin
+#define ntg_bin_value bool
+%}
+
+#define ntg_int_u32 ntg::int_u< 32, ntg::strict >
+#define ntg_int_u32_value unsigned long
+%inline %{
+#define ntg_int_u32 ntg::int_u< 32, ntg::strict >
+#define ntg_int_u32_value unsigned long
+%}
+
+#define ntg_int_s32 ntg::int_s< 32, ntg::strict >
+#define ntg_int_s32_value long
+%inline %{
+#define ntg_int_s32 ntg::int_s< 32, ntg::strict >
+#define ntg_int_s32_value long
+%}
+
+#define ntg_int_u8 ntg::int_u< 8, ntg::strict >
+#define ntg_int_u8_value unsigned long
+%inline %{
+#define ntg_int_u8 ntg::int_u< 8, ntg::strict >
+#define ntg_int_u8_value unsigned long
+%}
+
+#define ntg_int_s8 ntg::int_s< 8, ntg::strict >
+#define ntg_int_s8_value long
+%inline %{
+#define ntg_int_s8 ntg::int_s< 8, ntg::strict >
+#define ntg_int_s8_value long
+%}
+
+#define ntg_float ntg::float_d
+#define ntg_float_value ntg_float
+%inline %{
+#define ntg_float ntg::float_d
+#define ntg_float_value ntg_float
+%}
+
+#define ntg_cplx_rect ntg::cplx< ntg::rect, ntg_float >
+#define ntg_cplx_rect_value ntg_cplx_rect
+%inline %{
+#define ntg_cplx_rect ntg::cplx< ntg::rect, ntg_float >
+#define ntg_cplx_rect_value ntg_cplx_rect
+%}
+
+#define ntg_cplx_polar ntg::cplx< ntg::polar, ntg_float >
+#define ntg_cplx_polar_value ntg_cplx_polar
+%inline %{
+#define ntg_cplx_polar ntg::cplx< ntg::polar, ntg_float >
+#define ntg_cplx_polar_value ntg_cplx_polar
+%}
1
0
Index: tools/swilena/ChangeLog
from Nicolas Burrus <burrus_n(a)lrde.epita.fr>
* generate_morpho_instantiations.py: Minor update. Add opening and
closing algorithms.
Index: tools/swilena/generate_morpho_instantiations.py
--- tools/swilena/generate_morpho_instantiations.py Thu, 09 Oct 2003 16:21:55 +0200 burrus_n (oln/v/24_generate_m 1.2 700)
+++ tools/swilena/generate_morpho_instantiations.py Sat, 08 Nov 2003 18:17:07 +0100 burrus_n (oln/v/24_generate_m 1.3 700)
@@ -1,14 +1,16 @@
#!/usr/bin/env python
+import sys
+
files = []
def close_files():
for file in files:
file.close()
-def open_files():
+def open_files(path):
for dim in range(1, 4):
- files.append(open("swilena_morpho%(dim)sd.i" % vars(), 'w'))
+ files.append(open(path + "/swilena_morpho%(dim)sd.i" % vars(), 'w'))
def write_headers():
for dim in range(1, 4):
@@ -18,10 +20,13 @@
%%module swilena_morpho%(dim)sd
%%include swilena_exception.i
+
+%%include swilena_ntg_macros.i
+%%import swilena_ntg.i
+
%%include swilena_morpho.i
%%import swilena_image%(dim)sd.i
-%%import swilena_ntg.i
""" % vars())
@@ -54,6 +59,12 @@
instantiate(dim, "dilation", img_type, img_type, win_type)
instantiate(dim, "fast_dilation", img_type, img_type, win_type)
+ instantiate(dim, "opening", img_type, img_type, win_type)
+ instantiate(dim, "fast_opening", img_type, img_type, win_type)
+
+ instantiate(dim, "closing", img_type, img_type, win_type)
+ instantiate(dim, "fast_closing", img_type, img_type, win_type)
+
instantiate(dim, "thickening", img_type, img_type, win_type, win_type)
instantiate(dim, "fast_thickening", img_type, img_type, win_type, win_type)
@@ -143,7 +154,12 @@
# instantiate(dim, "fast_minima_killer", img_type, neighb_type)
def main():
- open_files()
+ if len(sys.argv) != 2:
+ sys.stderr.write ("Usage: generate_morpho_instanciations.py path\n")
+ sys.exit (1)
+ else:
+ path = sys.argv[1]
+ open_files(path)
write_headers()
write_algorithms()
close_files()
1
0