Olena-patches
Threads by month
- ----- 2025 -----
- October
- September
- 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
- 9625 discussions

last-svn-commit-544-g1dfe127 WIP: More comparisons on dilation (static windows and qixters).
by Roland Levillain 14 Oct '11
by Roland Levillain 14 Oct '11
14 Oct '11
---
milena/apps/bench/Makefile.am | 1 +
milena/apps/bench/dilation-lena.cc | 45 +++
milena/apps/bench/static_array.hh | 134 +++++++++
.../bench/static_dpoints_pixter.hh} | 196 +++++++-------
.../core/window.hh => apps/bench/static_window.hh} | 288 ++++++++++----------
5 files changed, 420 insertions(+), 244 deletions(-)
create mode 100644 milena/apps/bench/static_array.hh
copy milena/{mln/core/dpoints_pixter.hh => apps/bench/static_dpoints_pixter.hh} (66%)
copy milena/{mln/core/window.hh => apps/bench/static_window.hh} (51%)
diff --git a/milena/apps/bench/Makefile.am b/milena/apps/bench/Makefile.am
index 41b57f5..766f620 100644
--- a/milena/apps/bench/Makefile.am
+++ b/milena/apps/bench/Makefile.am
@@ -40,6 +40,7 @@ MOSTLYCLEANFILES = \
dilation-lena-out-gen.pgm \
dilation-lena-out-fast.pgm \
dilation-lena-out-faster.pgm \
+ dilation-lena-out-fast_static.pgm \
gradient-lena-out.pgm \
gradient-spe-lena-out-0.pgm \
gradient-spe-lena-out-1.pgm \
diff --git a/milena/apps/bench/dilation-lena.cc b/milena/apps/bench/dilation-lena.cc
index 1cb1198..ea37f19 100644
--- a/milena/apps/bench/dilation-lena.cc
+++ b/milena/apps/bench/dilation-lena.cc
@@ -37,6 +37,8 @@
#include <mln/util/timer.hh>
+#include "apps/bench/static_window.hh"
+#include "apps/bench/static_dpoints_pixter.hh"
#include "apps/data.hh"
@@ -134,6 +136,33 @@ namespace faster
}
}
+namespace fast_static
+{
+ using namespace mln;
+
+ template <typename I, typename W>
+ mln_concrete(I) dilation(const I& input, const W& win)
+ {
+ typedef mln_concrete(I) O;
+ O output; initialize(output, input); // Initialize output.
+
+ mln_pixter(const I) pi(input); // Iterator on the pixels of `input'.
+ mln_pixter(O) po(output); // Iterator on the pixels of `output'.
+
+ typedef mln::static_dpoints_fwd_pixter<const I, W::Size> mln_static_qixter;
+ mln_static_qixter q(pi, win);
+ for_all_2(pi, po)
+ {
+ // FIXME: Cheat: replace the accu::supremum by a maximum.
+ mln::accu::stat::max<mln_value(I)> sup; // Accumulator computing the supremum.
+ for_all(q)
+ sup.take(q.val());
+ po.val() = sup.to_result();
+ }
+ return output;
+ }
+}
+
int main()
{
@@ -170,4 +199,20 @@ int main()
t.stop();
std::cout << t.read() << std::endl;
io::pgm::save(d, "dilation-lena-out-faster.pgm");
+
+
+ const unsigned n = 5;
+ mln::dpoint2d dps[n] = { mln::dpoint2d( 0, -1),
+ mln::dpoint2d(-1, 0),
+ mln::dpoint2d( 0, 0),
+ mln::dpoint2d(+1, 0),
+ mln::dpoint2d( 0, +1) };
+ mln::util::static_array<mln::dpoint2d, n> sa(dps, dps + n);
+ mln::static_window<mln::dpoint2d, n> static_win_c4p (sa);
+
+ t.start();
+ d = fast_static::dilation(lena, static_win_c4p);
+ t.stop();
+ std::cout << t.read() << std::endl;
+ io::pgm::save(d, "dilation-lena-out-fast_static.pgm");
}
diff --git a/milena/apps/bench/static_array.hh b/milena/apps/bench/static_array.hh
new file mode 100644
index 0000000..ddf42bd
--- /dev/null
+++ b/milena/apps/bench/static_array.hh
@@ -0,0 +1,134 @@
+// Copyright (C) 2010 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_UTIL_STATIC_ARRAY_HH
+# define MLN_UTIL_STATIC_ARRAY_HH
+
+// FIXME: Add documentation.
+
+# include <cstddef>
+# include <algorithm>
+
+# include <mln/core/internal/window_base.hh>
+# include <mln/core/concept/gdpoint.hh>
+
+# include <mln/metal/is_a.hh>
+# include <mln/util/set.hh>
+# include <mln/fun/i2v/all_to.hh>
+# include <mln/norm/linfty.hh>
+# include <mln/literal/zero.hh>
+
+namespace mln
+{
+
+ namespace util
+ {
+
+ template <typename T, std::size_t n>
+ class static_array
+ {
+ public:
+ // FIXME: Careful, this ctor initializes nothing.
+ static_array();
+
+ // FIXME: Find a better way to build this static array.
+ template <typename InputIterator>
+ static_array(InputIterator first, InputIterator last);
+
+ T& operator[](std::size_t i);
+ const T& operator[](std::size_t i) const;
+
+ bool has(const T& value) const;
+
+ private:
+ T data_[n];
+ };
+
+
+ template <typename D, std::size_t n>
+ bool
+ operator==(const static_array<D, n>& lhs, const static_array<D, n>& rhs);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, std::size_t n>
+ inline
+ static_array<T, n>::static_array()
+ {
+ }
+
+ template <typename T, std::size_t n>
+ template <typename InputIterator>
+ inline
+ static_array<T, n>::static_array(InputIterator first, InputIterator last)
+ {
+ mln_precondition(std::distance(first, last) == n);
+ std::copy(first, last, data_);
+ }
+
+ template <typename T, std::size_t n>
+ inline
+ T&
+ static_array<T, n>::operator[](std::size_t i)
+ {
+ return data_[i];
+ }
+
+ template <typename T, std::size_t n>
+ inline
+ const T&
+ static_array<T, n>::operator[](std::size_t i) const
+ {
+ return data_[i];
+ }
+
+ template <typename T, std::size_t n>
+ inline
+ bool
+ static_array<T, n>::has(const T& value) const
+ {
+ return std::find(data_, data_ + n, value) != data_ + n;
+ }
+
+
+ template <typename D, std::size_t n>
+ inline
+ bool
+ operator==(const static_array<D, n>& lhs, const static_array<D, n>& rhs)
+ {
+ for(std::size_t i = 0; i < n; ++i)
+ if (lhs[i] != rhs[i])
+ return false;
+ return true;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::util
+
+} // end of namespace mln
+
+#endif // ! MLN_UTIL_STATIC_ARRAY_HH
diff --git a/milena/mln/core/dpoints_pixter.hh b/milena/apps/bench/static_dpoints_pixter.hh
similarity index 66%
copy from milena/mln/core/dpoints_pixter.hh
copy to milena/apps/bench/static_dpoints_pixter.hh
index 8020fcc..d7823ac 100644
--- a/milena/mln/core/dpoints_pixter.hh
+++ b/milena/apps/bench/static_dpoints_pixter.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009, 2010 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,8 +24,10 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_CORE_DPOINTS_PIXTER_HH
-# define MLN_CORE_DPOINTS_PIXTER_HH
+#ifndef MLN_CORE_STATIC_DPOINTS_PIXTER_HH
+# define MLN_CORE_STATIC_DPOINTS_PIXTER_HH
+
+// FIXME: Review and update the documentation.
/// \file
///
@@ -41,24 +44,25 @@
# include <mln/core/internal/pixel_impl.hh>
# include <mln/metal/converts_to.hh>
+# include "apps/bench/static_array.hh"
namespace mln
{
- /*------------------------.
- | dpoints_fwd_pixter<I>. |
- `------------------------*/
+ /*----------------------------------.
+ | static_dpoints_fwd_pixter<I, n>. |
+ `----------------------------------*/
/// \brief A generic forward iterator on the pixels of a
/// dpoint-based window or neighborhood.
///
/// Parameter \c I is the image type.
- template <typename I>
- class dpoints_fwd_pixter
- : public Pixel_Iterator< dpoints_fwd_pixter<I> >,
- public internal::pixel_impl_< I, dpoints_fwd_pixter<I> >
+ template <typename I, unsigned n>
+ class static_dpoints_fwd_pixter
+ : public Pixel_Iterator< static_dpoints_fwd_pixter<I, n> >,
+ public internal::pixel_impl_< I, static_dpoints_fwd_pixter<I, n> >
{
- typedef typename internal::pixel_impl_< I, dpoints_fwd_pixter<I> > super_;
+ typedef typename internal::pixel_impl_< I, static_dpoints_fwd_pixter<I, n> > super_;
public:
/// \brief Constructor (using an image).
@@ -69,9 +73,9 @@ namespace mln
/// \param[in] p_ref Center (resp. reference) point of the
/// neighborhood (resp. window).
template <typename Dps, typename Pref>
- dpoints_fwd_pixter(I& image,
- const Dps& dps,
- const Pref& p_ref);
+ static_dpoints_fwd_pixter(I& image,
+ const Dps& dps,
+ const Pref& p_ref);
/// \brief Constructor (using a generalized pixel).
///
@@ -79,8 +83,8 @@ namespace mln
/// \param[in] dps An object (neighborhood or window) that can
/// provide a set of delta-points.
template <typename Dps, typename Pref>
- dpoints_fwd_pixter(const Generalized_Pixel<Pref>& pxl_ref,
- const Dps& dps);
+ static_dpoints_fwd_pixter(const Generalized_Pixel<Pref>& pxl_ref,
+ const Dps& dps);
/// Manipulation.
/// \{
@@ -112,9 +116,9 @@ namespace mln
/// offset_[0] is absolute, while other offsets are relative
/// (i.e., offset_[i] is the memory difference to go from pixel
/// i-1 to pixel i.
- std::vector<int> offset_;
+ util::static_array<int, n> offset_;
/// Current offset.
- typename std::vector<int>::const_iterator i_;
+ std::size_t i_;
/// \brief Reference value or pixel.
///
@@ -128,20 +132,20 @@ namespace mln
};
- /*------------------------.
- | dpoints_bkd_pixter<I>. |
- `------------------------*/
+ /*----------------------------------.
+ | static_dpoints_bkd_pixter<I, n>. |
+ `----------------------------------*/
/// \brief A generic backward iterator on the pixels of a
/// dpoint-based window or neighborhood.
///
/// Parameter \c I is the image type.
- template <typename I>
- class dpoints_bkd_pixter
- : public Pixel_Iterator< dpoints_bkd_pixter<I> >,
- public internal::pixel_impl_< I, dpoints_bkd_pixter<I> >
+ template <typename I, unsigned n>
+ class static_dpoints_bkd_pixter
+ : public Pixel_Iterator< static_dpoints_bkd_pixter<I, n> >,
+ public internal::pixel_impl_< I, static_dpoints_bkd_pixter<I, n> >
{
- typedef typename internal::pixel_impl_< I, dpoints_bkd_pixter<I> > super_;
+ typedef typename internal::pixel_impl_< I, static_dpoints_bkd_pixter<I, n> > super_;
public:
/// \brief Constructor (using an image).
@@ -152,9 +156,9 @@ namespace mln
/// \param[in] p_ref Center (resp. reference) point of the
/// neighborhood (resp. window).
template <typename Dps, typename Pref>
- dpoints_bkd_pixter(I& image,
- const Dps& dps,
- const Pref& p_ref);
+ static_dpoints_bkd_pixter(I& image,
+ const Dps& dps,
+ const Pref& p_ref);
/// \brief Constructor (using a generalized pixel).
///
@@ -162,8 +166,8 @@ namespace mln
/// \param[in] dps An object (neighborhood or window) that can
/// provide a set of delta-points.
template <typename Dps, typename Pref>
- dpoints_bkd_pixter(const Generalized_Pixel<Pref>& pxl_ref,
- const Dps& dps);
+ static_dpoints_bkd_pixter(const Generalized_Pixel<Pref>& pxl_ref,
+ const Dps& dps);
/// Manipulation.
/// \{
@@ -195,9 +199,9 @@ namespace mln
/// offset_[dps.size() - 1] is absolute, while other offsets
/// are relative (i.e., offset_[i] is the memory difference to go
/// from pixel i+1 to pixel i.
- std::vector<int> offset_;
+ util::static_array<int, n> offset_;
/// Current offset.
- typename std::vector<int>::const_reverse_iterator i_;
+ std::size_t i_;
/// \brief Reference value or pixel.
///
@@ -214,16 +218,16 @@ namespace mln
#ifndef MLN_INCLUDE_ONLY
- /*------------------------.
- | dpoints_fwd_pixter<I>. |
- `------------------------*/
+ /*----------------------------------.
+ | static_dpoints_fwd_pixter<I, n>. |
+ `----------------------------------*/
- template <typename I>
+ template <typename I, unsigned n>
template <typename Dps, typename Pref>
inline
- dpoints_fwd_pixter<I>::dpoints_fwd_pixter(I& image,
- const Dps& dps,
- const Pref& p_ref)
+ static_dpoints_fwd_pixter<I, n>::static_dpoints_fwd_pixter(I& image,
+ const Dps& dps,
+ const Pref& p_ref)
: super_(image)
{
mln_precondition(image.is_valid());
@@ -235,11 +239,11 @@ namespace mln
init_(dps);
}
- template <typename I>
+ template <typename I, unsigned n>
template <typename Dps, typename Pref>
inline
- dpoints_fwd_pixter<I>::dpoints_fwd_pixter(const Generalized_Pixel<Pref>& pxl_ref_,
- const Dps& dps)
+ static_dpoints_fwd_pixter<I, n>::static_dpoints_fwd_pixter(const Generalized_Pixel<Pref>& pxl_ref_,
+ const Dps& dps)
: super_(internal::force_exact<Pref>(pxl_ref_).ima())
{
const Pref& pxl_ref = internal::force_exact<Pref>(pxl_ref_);
@@ -250,10 +254,10 @@ namespace mln
init_(dps);
}
- template <typename I>
+ template <typename I, unsigned n>
inline
const mln_value(I)&
- dpoints_fwd_pixter<I>::center_val() const
+ static_dpoints_fwd_pixter<I, n>::center_val() const
{
mln_invariant(value_ref_ != 0 || p_ref_ != 0);
if (p_ref_)
@@ -262,14 +266,14 @@ namespace mln
return **value_ref_;
}
- template <typename I>
+ template <typename I, unsigned n>
template <typename Dps>
inline
void
- dpoints_fwd_pixter<I>::init_(const Dps& dps)
+ static_dpoints_fwd_pixter<I, n>::init_(const Dps& dps)
{
for (unsigned i = 0; i < dps.size(); ++i)
- offset_.push_back(this->image_.delta_index(dps.dp(i)));
+ offset_[i] = this->image_.delta_index(dps.dp(i));
// offset_[0] is absolute
// other offsets are relative:
if (dps.size() > 1)
@@ -278,66 +282,66 @@ namespace mln
invalidate();
}
- template <typename I>
+ template <typename I, unsigned n>
inline
void
- dpoints_fwd_pixter<I>::update()
+ static_dpoints_fwd_pixter<I, n>::update()
{
if (is_valid())
{
if (p_ref_)
- this->value_ptr_ = & image_(*p_ref_) + *i_;
+ this->value_ptr_ = & image_(*p_ref_) + offset_[i_];
else
- this->value_ptr_ = * value_ref_ + *i_;
+ this->value_ptr_ = * value_ref_ + offset_[i_];
}
}
- template <typename I>
+ template <typename I, unsigned n>
inline
void
- dpoints_fwd_pixter<I>::start()
+ static_dpoints_fwd_pixter<I, n>::start()
{
- i_ = offset_.begin();
+ i_ = 0;
update();
}
- template <typename I>
+ template <typename I, unsigned n>
inline
void
- dpoints_fwd_pixter<I>::next_()
+ static_dpoints_fwd_pixter<I, n>::next_()
{
++i_;
if (is_valid())
- this->value_ptr_ += *i_;
+ this->value_ptr_ += offset_[i_];
}
- template <typename I>
+ template <typename I, unsigned n>
inline
bool
- dpoints_fwd_pixter<I>::is_valid() const
+ static_dpoints_fwd_pixter<I, n>::is_valid() const
{
- return i_ != offset_.end();
+ return i_ < n;
}
- template <typename I>
+ template <typename I, unsigned n>
inline
void
- dpoints_fwd_pixter<I>::invalidate()
+ static_dpoints_fwd_pixter<I, n>::invalidate()
{
- i_ = offset_.end();
+ i_ = n;
}
- /*------------------------.
- | dpoints_bkd_pixter<I>. |
- `------------------------*/
+ /*----------------------------------.
+ | static_dpoints_bkd_pixter<I, n>. |
+ `----------------------------------*/
- template <typename I>
+ template <typename I, unsigned n>
template <typename Dps, typename Pref>
inline
- dpoints_bkd_pixter<I>::dpoints_bkd_pixter(I& image,
- const Dps& dps,
- const Pref& p_ref)
+ static_dpoints_bkd_pixter<I, n>::static_dpoints_bkd_pixter(I& image,
+ const Dps& dps,
+ const Pref& p_ref)
: super_(image)
{
mln_precondition(image.is_valid());
@@ -346,11 +350,11 @@ namespace mln
init_(dps);
}
- template <typename I>
+ template <typename I, unsigned n>
template <typename Dps, typename Pref>
inline
- dpoints_bkd_pixter<I>::dpoints_bkd_pixter(const Generalized_Pixel<Pref>& pxl_ref_,
- const Dps& dps)
+ static_dpoints_bkd_pixter<I, n>::static_dpoints_bkd_pixter(const Generalized_Pixel<Pref>& pxl_ref_,
+ const Dps& dps)
: super_(internal::force_exact<Pref>(pxl_ref_).ima())
{
const Pref& pxl_ref = internal::force_exact<Pref>(pxl_ref_);
@@ -361,10 +365,10 @@ namespace mln
init_(dps);
}
- template <typename I>
+ template <typename I, unsigned n>
inline
const mln_value(I)&
- dpoints_bkd_pixter<I>::center_val() const
+ static_dpoints_bkd_pixter<I, n>::center_val() const
{
mln_invariant(value_ref_ != 0 || p_ref_ != 0);
if (p_ref_)
@@ -373,14 +377,14 @@ namespace mln
return **value_ref_;
}
- template <typename I>
+ template <typename I, unsigned n>
template <typename Dps>
inline
void
- dpoints_bkd_pixter<I>::init_(const Dps& dps)
+ static_dpoints_bkd_pixter<I, n>::init_(const Dps& dps)
{
for (unsigned i = 0; i < dps.size(); ++i)
- offset_.push_back(this->image_.delta_index(dps.dp(i)));
+ offset_[i] = this->image_.delta_index(dps.dp(i));
// offset_[size() - 1] is absolute
// other offsets are relative:
if (dps.size() > 1)
@@ -389,53 +393,53 @@ namespace mln
invalidate();
}
- template <typename I>
+ template <typename I, unsigned n>
inline
void
- dpoints_bkd_pixter<I>::update()
+ static_dpoints_bkd_pixter<I, n>::update()
{
if (is_valid())
{
if (p_ref_)
- this->value_ptr_ = & image_(*p_ref_) + *i_;
+ this->value_ptr_ = & image_(*p_ref_) + offset_[n - 1 - i_];
else
- this->value_ptr_ = * value_ref_ + *i_;
+ this->value_ptr_ = * value_ref_ + offset_[n - 1 - i_];
}
}
- template <typename I>
+ template <typename I, unsigned n>
inline
void
- dpoints_bkd_pixter<I>::start()
+ static_dpoints_bkd_pixter<I, n>::start()
{
- i_ = offset_.rbegin();
+ i_ = 0;
update();
}
- template <typename I>
+ template <typename I, unsigned n>
inline
void
- dpoints_bkd_pixter<I>::next_()
+ static_dpoints_bkd_pixter<I, n>::next_()
{
++i_;
if (is_valid())
- this->value_ptr_ += *i_;
+ this->value_ptr_ += offset_[n - 1 - i_];
}
- template <typename I>
+ template <typename I, unsigned n>
inline
bool
- dpoints_bkd_pixter<I>::is_valid() const
+ static_dpoints_bkd_pixter<I, n>::is_valid() const
{
- return i_ != offset_.rend();
+ return i_ < n;
}
- template <typename I>
+ template <typename I, unsigned n>
inline
void
- dpoints_bkd_pixter<I>::invalidate()
+ static_dpoints_bkd_pixter<I, n>::invalidate()
{
- i_ = offset_.rend();
+ i_ = n;
}
#endif // ! MLN_INCLUDE_ONLY
@@ -443,4 +447,4 @@ namespace mln
} // end of namespace mln
-#endif // ! MLN_CORE_DPOINTS_PIXTER_HH
+#endif // ! MLN_CORE_STATIC_DPOINTS_PIXTER_HH
diff --git a/milena/mln/core/window.hh b/milena/apps/bench/static_window.hh
similarity index 51%
copy from milena/mln/core/window.hh
copy to milena/apps/bench/static_window.hh
index 87f1940..fe8f791 100644
--- a/milena/mln/core/window.hh
+++ b/milena/apps/bench/static_window.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Copyright (C) 2007, 2008, 2009, 2010 EPITA Research and Development
// Laboratory (LRDE)
//
// This file is part of Olena.
@@ -24,8 +24,10 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_CORE_WINDOW_HH
-# define MLN_CORE_WINDOW_HH
+#ifndef MLN_CORE_STATIC_WINDOW_HH
+# define MLN_CORE_STATIC_WINDOW_HH
+
+// FIXME: Review and update the documentation.
/*! \file
*
@@ -50,12 +52,14 @@
# include <mln/norm/linfty.hh>
# include <mln/literal/zero.hh>
+# include "apps/bench/static_array.hh"
+
namespace mln
{
// Forward declarations.
- template <typename D> class window;
+ template <typename D, unsigned n> class static_window;
template <typename V> class dpsites_fwd_piter;
template <typename V> class dpsites_bkd_piter;
@@ -64,8 +68,8 @@ namespace mln
namespace trait
{
- template <typename D>
- struct window_< mln::window<D> >
+ template <typename D, unsigned n>
+ struct window_< mln::static_window<D, n> >
{
typedef trait::window::size::fixed size;
typedef trait::window::support::regular support;
@@ -81,20 +85,18 @@ namespace mln
* This type of window is just like a set of delta-points. The
* parameter is \c D, type of delta-point.
*/
- template <typename D>
- class window : public internal::window_base< D, window<D> >
+ template <typename D, unsigned n>
+ class static_window : public internal::window_base< D, static_window<D, n> >
{
public:
+ enum { Size = n };
+
/// Regular window associated type.
- typedef window<D> regular;
+ typedef static_window<D, n> regular;
- /*! \brief Constructor without argument.
- *
- * The constructed window is empty.
- */
- window();
+ static_window(const mln::util::static_array<D, n>& dps);
/*! \brief Test if the window is centered.
*
@@ -116,12 +118,12 @@ namespace mln
/*! \brief Site_Iterator type to browse the points of a basic window
* w.r.t. the ordering of delta-points.
*/
- typedef dpsites_fwd_piter< window<D> > fwd_qiter;
+ typedef dpsites_fwd_piter< static_window<D, n> > fwd_qiter;
/*! \brief Site_Iterator type to browse the points of a basic window
* w.r.t. the reverse ordering of delta-points.
*/
- typedef dpsites_bkd_piter< window<D> > bkd_qiter;
+ typedef dpsites_bkd_piter< static_window<D, n> > bkd_qiter;
/*! \brief Site_Iterator type to browse the points of a basic window
* whatever the ordering of delta-points.
@@ -136,8 +138,8 @@ namespace mln
*/
bool is_empty() const;
- /// Clear the window.
- void clear();
+ // /// Clear the window.
+ // void clear();
/*! \brief Give the maximum coordinate gap between the window
center and a window point.
@@ -150,38 +152,35 @@ namespace mln
/// Test if \p dp is in this window definition.
bool has(const D& dp) const;
- /// Insert a delta-point \p dp.
- window<D>& insert(const D& dp);
+ // /// Insert a delta-point \p dp.
+ // static_window<D, n>& insert(const D& dp);
- /// Insert another window \p win.
- template <typename W>
- window<D>& insert(const Window<W>& win);
+ // /// Insert another window \p win.
+ // template <typename W>
+ // static_window<D, n>& insert(const Window<W>& win);
- /// \{ Insertion of a delta-point with different numbers of
- /// arguments (coordinates) w.r.t. the dimension.
- window<D>& insert(const mln_coord(D)& dind); // For 1D or index access.
+ // /// \{ Insertion of a delta-point with different numbers of
+ // /// arguments (coordinates) w.r.t. the dimension.
+ // static_window<D, n>& insert(const mln_coord(D)& dind); // For 1D or index access.
- window<D>& insert(const mln_coord(D)& drow,
- const mln_coord(D)& dcol); // For 2D.
+ // static_window<D, n>& insert(const mln_coord(D)& drow,
+ // const mln_coord(D)& dcol); // For 2D.
- window<D>& insert(const mln_coord(D)& dsli,
- const mln_coord(D)& drow,
- const mln_coord(D)& dcol); // For 3D.
+ // static_window<D, n>& insert(const mln_coord(D)& dsli,
+ // const mln_coord(D)& drow,
+ // const mln_coord(D)& dcol); // For 3D.
/// \}
- /// Give the std vector of delta-points.
- const std::vector<D>& std_vector() const;
-
/// Hook to the set of D.
- const mln::util::set<D>& dps_hook_() const;
+ const mln::util::static_array<D, n>& dps_hook_() const;
/// Print the window definition into \p ostr.
void print(std::ostream& ostr) const;
private:
- util::set<D> dps_;
+ mln::util::static_array<D, n> dps_;
unsigned delta_(int i) const; // For indices.
unsigned delta_(const Gdpoint<D>& dp) const; // For grids delta-points.
@@ -193,76 +192,77 @@ namespace mln
*
* \relates mln::window
*/
- template <typename D>
- bool operator==(const window<D>& lhs, const window<D>& rhs);
+ template <typename D, unsigned n>
+ bool operator==(const static_window<D, n>& lhs, const static_window<D, n>& rhs);
# ifndef MLN_INCLUDE_ONLY
- // window<D>
+ // static_window<D, n>
- template <typename D>
+ template <typename D, unsigned n>
inline
- window<D>::window()
+ static_window<D, n>::static_window(const mln::util::static_array<D, n>& dps)
+ : dps_(dps)
{
// FIXME HERE: Was: mln::metal::is_a<D, Dpoint>::check();
// mln::metal::is_a<D, Delta_Point_Site>::check();
}
- template <typename D>
+ template <typename D, unsigned n>
inline
bool
- window<D>::is_symmetric() const
+ static_window<D, n>::is_symmetric() const
{
- window<D> cpy = *this;
+ static_window<D, n> cpy = *this;
cpy.sym();
return cpy == *this;
}
- template <typename D>
+ template <typename D, unsigned n>
inline
bool
- window<D>::is_centered() const
+ static_window<D, n>::is_centered() const
{
return this->dps_.has(literal::zero);
}
- template <typename D>
+ template <typename D, unsigned n>
inline
void
- window<D>::sym()
+ static_window<D, n>::sym()
{
- window<D> tmp;
- const unsigned n = size();
- for (unsigned i = 0; i < n; ++i)
- tmp.insert(- this->dp(i));
+ util::static_array<D, n> rev;
+ // FIXME: Can't we use std::copy and reverse_iterators here?
+ for (std::size_t i = 0; i < n; ++i)
+ rev[i] = dps_[n - 1 - i];
+ static_window<D, n> tmp(rev);
*this = tmp;
}
- template <typename D>
+ template <typename D, unsigned n>
inline
bool
- window<D>::is_empty() const
+ static_window<D, n>::is_empty() const
{
- return dps_.is_empty();
+ return n == 0;
}
- template <typename D>
- inline
- void
- window<D>::clear()
- {
- dps_.clear();
- }
+ // template <typename D, unsigned n>
+ // inline
+ // void
+ // static_window<D, n>::clear()
+ // {
+ // dps_.clear();
+ // }
- template <typename D>
+ template <typename D, unsigned n>
inline
unsigned
- window<D>::delta() const
+ static_window<D, n>::delta() const
{
unsigned d = 0;
- const unsigned n = size();
for (unsigned i = 0; i < n; ++i)
{
unsigned dd = delta_(dp(i));
@@ -272,122 +272,114 @@ namespace mln
return d;
}
- template <typename D>
+ template <typename D, unsigned n>
inline
unsigned
- window<D>::delta_(int i) const
+ static_window<D, n>::delta_(int i) const
{
return i;
}
- template <typename D>
+ template <typename D, unsigned n>
inline
unsigned
- window<D>::delta_(const Gdpoint<D>& dp) const
+ static_window<D, n>::delta_(const Gdpoint<D>& dp) const
{
return norm::linfty(exact(dp).to_vec());
}
- template <typename D>
+ template <typename D, unsigned n>
inline
unsigned
- window<D>::size() const
+ static_window<D, n>::size() const
{
- return dps_.nelements();
+ return n;
}
- template <typename D>
+ template <typename D, unsigned n>
inline
const D&
- window<D>::dp(unsigned i) const
+ static_window<D, n>::dp(unsigned i) const
{
- mln_precondition(i < size());
+ mln_precondition(i < n);
return dps_[i];
}
- template <typename D>
+ template <typename D, unsigned n>
inline
bool
- window<D>::has(const D& dp) const
+ static_window<D, n>::has(const D& dp) const
{
return dps_.has(dp);
}
- template <typename D>
- inline
- const std::vector<D>&
- window<D>::std_vector() const
- {
- return dps_.std_vector();
- }
-
- template <typename D>
- inline
- window<D>&
- window<D>::insert(const D& dp)
- {
- dps_.insert(dp);
- return *this;
- }
-
- template <typename D>
- template <typename W>
- inline
- window<D>&
- window<D>::insert(const Window<W>& win_)
- {
- const W& win = exact(win_);
- const unsigned n = win.size();
- for (unsigned i = 0; i < n; ++i)
- dps_.insert(win.dp(i));
- return *this;
- }
-
- template <typename D>
- inline
- window<D>&
- window<D>::insert(const mln_coord(D)& dind)
- {
- mlc_bool(D::dim == 1)::check();
- D dp(dind);
- return insert(dp);
- }
-
- template <typename D>
- inline
- window<D>&
- window<D>::insert(const mln_coord(D)& drow,
- const mln_coord(D)& dcol)
- {
- mlc_bool(D::dim == 2)::check();
- D dp(drow, dcol);
- return insert(dp);
- }
-
- template <typename D>
- inline
- window<D>&
- window<D>::insert(const mln_coord(D)& dsli,
- const mln_coord(D)& drow,
- const mln_coord(D)& dcol)
- {
- mlc_bool(D::dim == 3)::check();
- D dp(dsli, drow, dcol);
- return insert(dp);
- }
-
- template <typename D>
+ // template <typename D, unsigned n>
+ // inline
+ // static_window<D, n>&
+ // static_window<D, n>::insert(const D& dp)
+ // {
+ // dps_.insert(dp);
+ // return *this;
+ // }
+
+ // template <typename D, unsigned n>
+ // template <typename W>
+ // inline
+ // static_window<D, n>&
+ // static_window<D, n>::insert(const Window<W>& win_)
+ // {
+ // const W& win = exact(win_);
+ // const unsigned n = win.size();
+ // for (unsigned i = 0; i < n; ++i)
+ // dps_.insert(win.dp(i));
+ // return *this;
+ // }
+
+ // template <typename D, unsigned n>
+ // inline
+ // static_window<D, n>&
+ // static_window<D, n>::insert(const mln_coord(D)& dind)
+ // {
+ // mlc_bool(D::dim == 1)::check();
+ // D dp(dind);
+ // return insert(dp);
+ // }
+
+ // template <typename D, unsigned n>
+ // inline
+ // static_window<D, n>&
+ // static_window<D, n>::insert(const mln_coord(D)& drow,
+ // const mln_coord(D)& dcol)
+ // {
+ // mlc_bool(D::dim == 2)::check();
+ // D dp(drow, dcol);
+ // return insert(dp);
+ // }
+
+ // template <typename D, unsigned n>
+ // inline
+ // static_window<D, n>&
+ // static_window<D, n>::insert(const mln_coord(D)& dsli,
+ // const mln_coord(D)& drow,
+ // const mln_coord(D)& dcol)
+ // {
+ // mlc_bool(D::dim == 3)::check();
+ // D dp(dsli, drow, dcol);
+ // return insert(dp);
+ // }
+
+ template <typename D, unsigned n>
inline
- const util::set<D>&
- window<D>::dps_hook_() const
+ const mln::util::static_array<D, n>&
+ static_window<D, n>::dps_hook_() const
{
return dps_;
}
- template <typename D>
+ template <typename D, unsigned n>
inline
void
- window<D>::print(std::ostream& ostr) const
+ static_window<D, n>::print(std::ostream& ostr) const
{
ostr << dps_;
}
@@ -395,9 +387,9 @@ namespace mln
// Operators.
- template <typename D>
+ template <typename D, unsigned n>
bool
- operator==(const window<D>& lhs, const window<D>& rhs)
+ operator==(const static_window<D, n>& lhs, const static_window<D, n>& rhs)
{
return lhs.dps_hook_() == rhs.dps_hook_();
}
@@ -410,4 +402,4 @@ namespace mln
# include <mln/core/dpsites_piter.hh>
-#endif // ! MLN_CORE_WINDOW_HH
+#endif // ! MLN_CORE_STATIC_WINDOW_HH
--
1.7.2.5
1
0

last-svn-commit-545-ga8d13f2 WIP: More comparisons on dilation (variants without accu).
by Roland Levillain 14 Oct '11
by Roland Levillain 14 Oct '11
14 Oct '11
---
milena/apps/bench/Makefile.am | 2 +
milena/apps/bench/dilation-lena.cc | 64 ++++++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+), 0 deletions(-)
diff --git a/milena/apps/bench/Makefile.am b/milena/apps/bench/Makefile.am
index 766f620..f106b23 100644
--- a/milena/apps/bench/Makefile.am
+++ b/milena/apps/bench/Makefile.am
@@ -39,7 +39,9 @@ MOSTLYCLEANFILES = \
dilation-lena-out-spe.pgm \
dilation-lena-out-gen.pgm \
dilation-lena-out-fast.pgm \
+ dilation-lena-out-fast_noaccu.pgm \
dilation-lena-out-faster.pgm \
+ dilation-lena-out-faster_noaccu.pgm \
dilation-lena-out-fast_static.pgm \
gradient-lena-out.pgm \
gradient-spe-lena-out-0.pgm \
diff --git a/milena/apps/bench/dilation-lena.cc b/milena/apps/bench/dilation-lena.cc
index ea37f19..3557487 100644
--- a/milena/apps/bench/dilation-lena.cc
+++ b/milena/apps/bench/dilation-lena.cc
@@ -111,6 +111,33 @@ namespace fast
}
}
+namespace fast_noaccu
+{
+ using namespace mln;
+
+ template <typename I, typename W>
+ mln_concrete(I) dilation(const I& input, const W& win)
+ {
+ typedef mln_concrete(I) O;
+ O output; initialize(output, input); // Initialize output.
+
+ mln_pixter(const I) pi(input); // Iterator on the pixels of `input'.
+ mln_pixter(O) po(output); // Iterator on the pixels of `output'.
+
+ mln_qixter(const I, W) q(pi, win); // Iterator on the neighbors of `p' w.r.t. `win'.
+ for_all_2(pi, po)
+ {
+ // FIXME: Cheat: replace the accu::supremum by a maximum.
+ mln_value(I) sup = mln_min(mln_value(I));
+ for_all(q)
+ if (q.val() > sup)
+ sup = q.val();
+ po.val() = sup;
+ }
+ return output;
+ }
+}
+
namespace faster
{
using namespace mln;
@@ -136,6 +163,32 @@ namespace faster
}
}
+namespace faster_noaccu
+{
+ using namespace mln;
+
+ template <typename I, typename W>
+ mln_concrete(I) dilation(const I& input, const W& win)
+ {
+ typedef mln_concrete(I) O;
+ O output; initialize(output, input); // Initialize output.
+
+ mln_pixter(const I) p(input); // Iterator on the pixels of `input'.
+
+ mln_qixter(const I, W) q(p, win); // Iterator on the neighbors of `p' w.r.t. `win'.
+ for_all(p)
+ {
+ // FIXME: Cheat: replace the accu::supremum by a maximum.
+ mln_value(I) sup = mln_min(mln_value(I));
+ for_all(q)
+ if (q.val() > sup)
+ sup = q.val();
+ *(output.buffer() + p.offset()) = sup;
+ }
+ return output;
+ }
+}
+
namespace fast_static
{
using namespace mln;
@@ -195,11 +248,22 @@ int main()
io::pgm::save(d, "dilation-lena-out-fast.pgm");
t.start();
+ d = fast_noaccu::dilation(lena, win_c4p());
+ t.stop();
+ std::cout << t.read() << std::endl;
+ io::pgm::save(d, "dilation-lena-out-fast_noaccu.pgm");
+
+ t.start();
d = faster::dilation(lena, win_c4p());
t.stop();
std::cout << t.read() << std::endl;
io::pgm::save(d, "dilation-lena-out-faster.pgm");
+ t.start();
+ d = faster_noaccu::dilation(lena, win_c4p());
+ t.stop();
+ std::cout << t.read() << std::endl;
+ io::pgm::save(d, "dilation-lena-out-faster_noaccu.pgm");
const unsigned n = 5;
mln::dpoint2d dps[n] = { mln::dpoint2d( 0, -1),
--
1.7.2.5
1
0

last-svn-commit-546-ga7f8a8c WIP: More comparisons on dilation (static window + single pixter).
by Roland Levillain 14 Oct '11
by Roland Levillain 14 Oct '11
14 Oct '11
---
milena/apps/bench/Makefile.am | 1 +
milena/apps/bench/dilation-lena.cc | 32 ++++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/milena/apps/bench/Makefile.am b/milena/apps/bench/Makefile.am
index f106b23..1dcb18e 100644
--- a/milena/apps/bench/Makefile.am
+++ b/milena/apps/bench/Makefile.am
@@ -43,6 +43,7 @@ MOSTLYCLEANFILES = \
dilation-lena-out-faster.pgm \
dilation-lena-out-faster_noaccu.pgm \
dilation-lena-out-fast_static.pgm \
+ dilation-lena-out-faster_static.pgm \
gradient-lena-out.pgm \
gradient-spe-lena-out-0.pgm \
gradient-spe-lena-out-1.pgm \
diff --git a/milena/apps/bench/dilation-lena.cc b/milena/apps/bench/dilation-lena.cc
index 3557487..4372540 100644
--- a/milena/apps/bench/dilation-lena.cc
+++ b/milena/apps/bench/dilation-lena.cc
@@ -216,6 +216,32 @@ namespace fast_static
}
}
+namespace faster_static
+{
+ using namespace mln;
+
+ template <typename I, typename W>
+ mln_concrete(I) dilation(const I& input, const W& win)
+ {
+ typedef mln_concrete(I) O;
+ O output; initialize(output, input); // Initialize output.
+
+ mln_pixter(const I) p(input); // Iterator on the pixels of `input'.
+
+ typedef mln::static_dpoints_fwd_pixter<const I, W::Size> mln_static_qixter;
+ mln_static_qixter q(p, win);
+ for_all(p)
+ {
+ // FIXME: Cheat: replace the accu::supremum by a maximum.
+ mln::accu::stat::max<mln_value(I)> sup; // Accumulator computing the supremum.
+ for_all(q)
+ sup.take(q.val());
+ *(output.buffer() + p.offset()) = sup.to_result();
+ }
+ return output;
+ }
+}
+
int main()
{
@@ -279,4 +305,10 @@ int main()
t.stop();
std::cout << t.read() << std::endl;
io::pgm::save(d, "dilation-lena-out-fast_static.pgm");
+
+ t.start();
+ d = faster_static::dilation(lena, static_win_c4p);
+ t.stop();
+ std::cout << t.read() << std::endl;
+ io::pgm::save(d, "dilation-lena-out-faster_static.pgm");
}
--
1.7.2.5
1
0

last-svn-commit-548-g4762c47 WIP: More comparisons (2- and 1-pointer based non-gen impl.)
by Roland Levillain 14 Oct '11
by Roland Levillain 14 Oct '11
14 Oct '11
---
milena/apps/bench/Makefile.am | 15 +++-
milena/apps/bench/dilation-lena.cc | 119 +++++++++++++++++++++++++--
milena/apps/bench/static_dpoints_pixter.hh | 102 ++++++++++++-----------
milena/apps/bench/static_window.hh | 4 +-
milena/apps/bench/trait.hh | 99 +++++++++++++++++++++++
5 files changed, 277 insertions(+), 62 deletions(-)
create mode 100644 milena/apps/bench/trait.hh
diff --git a/milena/apps/bench/Makefile.am b/milena/apps/bench/Makefile.am
index adc0cdf..266b71b 100644
--- a/milena/apps/bench/Makefile.am
+++ b/milena/apps/bench/Makefile.am
@@ -1,4 +1,4 @@
-# Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE).
+# Copyright (C) 2010, 2011 EPITA Research and Development Laboratory (LRDE).
#
# This file is part of Olena.
#
@@ -29,7 +29,12 @@ noinst_PROGRAMS = \
EXTRA_DIST += \
and_not.hh \
- minus.hh
+ minus.hh \
+ \
+ static_array.hh \
+ static_dpoints_pixter.hh \
+ static_window.hh \
+ trait.hh
dilation_lena_SOURCES = dilation-lena.cc
gradient_lena_SOURCES = gradient-lena.cc
@@ -37,6 +42,8 @@ gradient_spe_lena_SOURCES = gradient-spe-lena.cc
MOSTLYCLEANFILES = \
dilation-lena-out-512-nongen.pgm \
+ dilation-lena-out-512-nongen_2ptr.pgm \
+ dilation-lena-out-512-nongen_1ptr.pgm \
dilation-lena-out-512-gen.pgm \
dilation-lena-out-512-fast.pgm \
dilation-lena-out-512-fast_noaccu.pgm \
@@ -46,6 +53,8 @@ MOSTLYCLEANFILES = \
dilation-lena-out-512-faster_static.pgm \
\
dilation-lena-out-1024-nongen.pgm \
+ dilation-lena-out-1024-nongen_2ptr.pgm \
+ dilation-lena-out-1024-nongen_1ptr.pgm \
dilation-lena-out-1024-gen.pgm \
dilation-lena-out-1024-fast.pgm \
dilation-lena-out-1024-fast_noaccu.pgm \
@@ -55,6 +64,8 @@ MOSTLYCLEANFILES = \
dilation-lena-out-1024-faster_static.pgm \
\
dilation-lena-out-2048-nongen.pgm \
+ dilation-lena-out-2048-nongen_2ptr.pgm \
+ dilation-lena-out-2048-nongen_1ptr.pgm \
dilation-lena-out-2048-gen.pgm \
dilation-lena-out-2048-fast.pgm \
dilation-lena-out-2048-fast_noaccu.pgm \
diff --git a/milena/apps/bench/dilation-lena.cc b/milena/apps/bench/dilation-lena.cc
index 69c82a7..e4996fb 100644
--- a/milena/apps/bench/dilation-lena.cc
+++ b/milena/apps/bench/dilation-lena.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,6 +23,8 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
+#include <cstddef>
+
#include <iostream>
#include <mln/core/image/image2d.hh>
@@ -39,9 +41,12 @@
#include "apps/bench/static_window.hh"
#include "apps/bench/static_dpoints_pixter.hh"
+#include "apps/bench/trait.hh"
+
#include "apps/data.hh"
+
namespace nongen
{
typedef mln::image2d<mln::value::int_u8> image;
@@ -63,6 +68,99 @@ namespace nongen
}
}
+namespace nongen_2ptr
+{
+ typedef mln::image2d<mln::value::int_u8> image;
+
+ image dilation(const image& input)
+ {
+ typedef mln::value::int_u8 val_t;
+ // Offsets corresponding to a 4-c window on INPUT.
+ ptrdiff_t win_offset[4] = { &input.at_(-1, 0) - &input.at_(0, 0),
+ &input.at_(+1, 0) - &input.at_(0, 0),
+ &input.at_( 0, -1) - &input.at_(0, 0),
+ &input.at_( 0, +1) - &input.at_(0, 0) };
+
+ image output (input.nrows(), input.ncols()); // Initialize an output image.
+ for (unsigned int r = 0; r < input.nrows(); ++r) // Iterate on rows.
+ {
+ const val_t* pi = &input.at_(r, 0);
+ val_t* po = &output.at_(r, 0);
+ for (; pi < &input.at_(r, 0) + input.ncols(); ++pi, ++po)
+ {
+ unsigned char sup = *pi;
+ // (-1, 0) neighbor.
+ if (r != 0
+ && *(pi + win_offset[0]) > sup)
+ sup = *(pi + win_offset[0]);
+ // (+1, 0) neighbor.
+ if (r != input.nrows() - 1
+ && *(pi + win_offset[1]) > sup)
+ sup = *(pi + win_offset[1]);
+ // (0, -1) neighbor.
+ if (pi != &input.at_(r, 0)
+ && *(pi + win_offset[2]) > sup)
+ sup = *(pi + win_offset[2]);
+ // (0, +1) neighbor.
+ if (pi != &input.at_(r, 0) + input.ncols() - 1
+ && *(pi + win_offset[3]) > sup)
+ sup = *(pi + win_offset[3]);
+ *po = sup;
+ }
+ }
+ return output;
+ }
+}
+
+namespace nongen_1ptr
+{
+ typedef mln::image2d<mln::value::int_u8> image;
+
+ image dilation(const image& input)
+ {
+ typedef mln::value::int_u8 val_t;
+ // Offsets corresponding to a 4-c window on INPUT.
+ ptrdiff_t win_offset[4] = { &input.at_(-1, 0) - &input.at_(0, 0),
+ &input.at_(+1, 0) - &input.at_(0, 0),
+ &input.at_( 0, -1) - &input.at_(0, 0),
+ &input.at_( 0, +1) - &input.at_(0, 0) };
+
+ image output;
+ initialize(output, input);
+ // Offset between a the pixel located at the same position in
+ // INPUT and OUTPUT.
+ ptrdiff_t output_offset = &output.at_(0, 0) - &input.at_(0, 0);
+
+ for (unsigned int r = 0; r < input.nrows(); ++r) // Iterate on rows.
+ {
+ for (const val_t* pi = &input.at_(r, 0);
+ pi < &input.at_(r, 0) + input.ncols();
+ ++pi)
+ {
+ unsigned char sup = *pi;
+ // (-1, 0) neighbor.
+ if (r != 0
+ && *(pi + win_offset[0]) > sup)
+ sup = *(pi + win_offset[0]);
+ // (+1, 0) neighbor.
+ if (r != input.nrows() - 1
+ && *(pi + win_offset[1]) > sup)
+ sup = *(pi + win_offset[1]);
+ // (0, -1) neighbor.
+ if (pi != &input.at_(r, 0)
+ && *(pi + win_offset[2]) > sup)
+ sup = *(pi + win_offset[2]);
+ // (0, +1) neighbor.
+ if (pi != &input.at_(r, 0) + input.ncols() - 1
+ && *(pi + win_offset[3]) > sup)
+ sup = *(pi + win_offset[3]);
+ const_cast<val_t&>(*(pi + output_offset)) = sup;
+ }
+ }
+ return output;
+ }
+}
+
namespace gen
{
using namespace mln;
@@ -201,9 +299,8 @@ namespace fast_static
mln_pixter(const I) pi(input); // Iterator on the pixels of `input'.
mln_pixter(O) po(output); // Iterator on the pixels of `output'.
+ mln_static_qixter(const I, W) q(pi, win); // Iterator on the neighbors of `p' w.r.t. `win'.
- typedef mln::static_dpoints_fwd_pixter<const I, W::Size> mln_static_qixter;
- mln_static_qixter q(pi, win);
for_all_2(pi, po)
{
// FIXME: Cheat: replace the accu::supremum by a maximum.
@@ -227,9 +324,8 @@ namespace faster_static
O output; initialize(output, input); // Initialize output.
mln_pixter(const I) p(input); // Iterator on the pixels of `input'.
+ mln_static_qixter(const I, W) q(p, win); // Iterator on the neighbors of `p' w.r.t. `win'.
- typedef mln::static_dpoints_fwd_pixter<const I, W::Size> mln_static_qixter;
- mln_static_qixter q(p, win);
for_all(p)
{
// FIXME: Cheat: replace the accu::supremum by a maximum.
@@ -288,9 +384,13 @@ run(const std::string& filename, const std::string& length, unsigned niters)
std::string prefix = "dilation-lena-out";
std::cout << "== " << filename << std::endl;
- DILATION_WITH_BUILTIN_WINDOW(nongen, "nongen", "nongen\t\t");
+ DILATION_WITH_BUILTIN_WINDOW(nongen, "nongen", "nongen\t\t");
+ DILATION_WITH_BUILTIN_WINDOW(nongen_2ptr, "nongen_2ptr", "nongen_2ptr\t");
+ DILATION_WITH_BUILTIN_WINDOW(nongen_1ptr, "nongen_1ptr", "nongen_1ptr\t");
DILATION(gen, win_c4p(), "gen", "gen\t\t");
+ // FIXME: Introduce a new test case, gen_static, using a static window
+ // and static_qiters.
DILATION(fast, win_c4p(), "fast", "fast\t\t");
DILATION(fast_noaccu, win_c4p(), "fast_noaccu", "fast_noaccu\t");
DILATION(faster, win_c4p(), "faster", "faster\t\t");
@@ -315,7 +415,8 @@ run(const std::string& filename, const std::string& length, unsigned niters)
int
main ()
{
- run(MLN_IMG_DIR "/lena.pgm", "512", 10);
- run(MLN_APPS_DIR "/bench/lena1024.pgm", "1024", 10);
- run(MLN_APPS_DIR "/bench/lena2048.pgm", "2048", 10);
+ unsigned niters = 10;
+ run(MLN_IMG_DIR "/lena.pgm", "512", niters);
+ run(MLN_APPS_DIR "/bench/lena1024.pgm", "1024", niters);
+ run(MLN_APPS_DIR "/bench/lena2048.pgm", "2048", niters);
}
diff --git a/milena/apps/bench/static_dpoints_pixter.hh b/milena/apps/bench/static_dpoints_pixter.hh
index d7823ac..ffa4a81 100644
--- a/milena/apps/bench/static_dpoints_pixter.hh
+++ b/milena/apps/bench/static_dpoints_pixter.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008, 2009, 2010 EPITA Research and Development
+// Copyright (C) 2007, 2008, 2009, 2010, 2011 EPITA Research and Development
// Laboratory (LRDE)
//
// This file is part of Olena.
@@ -50,19 +50,19 @@ namespace mln
{
/*----------------------------------.
- | static_dpoints_fwd_pixter<I, n>. |
+ | static_dpoints_fwd_pixter<I, W>. |
`----------------------------------*/
/// \brief A generic forward iterator on the pixels of a
/// dpoint-based window or neighborhood.
///
/// Parameter \c I is the image type.
- template <typename I, unsigned n>
+ template <typename I, typename W>
class static_dpoints_fwd_pixter
- : public Pixel_Iterator< static_dpoints_fwd_pixter<I, n> >,
- public internal::pixel_impl_< I, static_dpoints_fwd_pixter<I, n> >
+ : public Pixel_Iterator< static_dpoints_fwd_pixter<I, W> >,
+ public internal::pixel_impl_< I, static_dpoints_fwd_pixter<I, W> >
{
- typedef typename internal::pixel_impl_< I, static_dpoints_fwd_pixter<I, n> > super_;
+ typedef typename internal::pixel_impl_< I, static_dpoints_fwd_pixter<I, W> > super_;
public:
/// \brief Constructor (using an image).
@@ -111,6 +111,8 @@ namespace mln
void init_(const Dps& dps);
private:
+ enum { n = W::length };
+
/// \brief Offset of each delta-point.
///
/// offset_[0] is absolute, while other offsets are relative
@@ -133,19 +135,19 @@ namespace mln
/*----------------------------------.
- | static_dpoints_bkd_pixter<I, n>. |
+ | static_dpoints_bkd_pixter<I, W>. |
`----------------------------------*/
/// \brief A generic backward iterator on the pixels of a
/// dpoint-based window or neighborhood.
///
/// Parameter \c I is the image type.
- template <typename I, unsigned n>
+ template <typename I, typename W>
class static_dpoints_bkd_pixter
- : public Pixel_Iterator< static_dpoints_bkd_pixter<I, n> >,
- public internal::pixel_impl_< I, static_dpoints_bkd_pixter<I, n> >
+ : public Pixel_Iterator< static_dpoints_bkd_pixter<I, W> >,
+ public internal::pixel_impl_< I, static_dpoints_bkd_pixter<I, W> >
{
- typedef typename internal::pixel_impl_< I, static_dpoints_bkd_pixter<I, n> > super_;
+ typedef typename internal::pixel_impl_< I, static_dpoints_bkd_pixter<I, W> > super_;
public:
/// \brief Constructor (using an image).
@@ -194,6 +196,8 @@ namespace mln
void init_(const Dps& dps);
private:
+ enum { n = W::length };
+
/// \brief Offset of each delta-point.
///
/// offset_[dps.size() - 1] is absolute, while other offsets
@@ -219,13 +223,13 @@ namespace mln
#ifndef MLN_INCLUDE_ONLY
/*----------------------------------.
- | static_dpoints_fwd_pixter<I, n>. |
+ | static_dpoints_fwd_pixter<I, W>. |
`----------------------------------*/
- template <typename I, unsigned n>
+ template <typename I, typename W>
template <typename Dps, typename Pref>
inline
- static_dpoints_fwd_pixter<I, n>::static_dpoints_fwd_pixter(I& image,
+ static_dpoints_fwd_pixter<I, W>::static_dpoints_fwd_pixter(I& image,
const Dps& dps,
const Pref& p_ref)
: super_(image)
@@ -239,10 +243,10 @@ namespace mln
init_(dps);
}
- template <typename I, unsigned n>
+ template <typename I, typename W>
template <typename Dps, typename Pref>
inline
- static_dpoints_fwd_pixter<I, n>::static_dpoints_fwd_pixter(const Generalized_Pixel<Pref>& pxl_ref_,
+ static_dpoints_fwd_pixter<I, W>::static_dpoints_fwd_pixter(const Generalized_Pixel<Pref>& pxl_ref_,
const Dps& dps)
: super_(internal::force_exact<Pref>(pxl_ref_).ima())
{
@@ -254,10 +258,10 @@ namespace mln
init_(dps);
}
- template <typename I, unsigned n>
+ template <typename I, typename W>
inline
const mln_value(I)&
- static_dpoints_fwd_pixter<I, n>::center_val() const
+ static_dpoints_fwd_pixter<I, W>::center_val() const
{
mln_invariant(value_ref_ != 0 || p_ref_ != 0);
if (p_ref_)
@@ -266,11 +270,11 @@ namespace mln
return **value_ref_;
}
- template <typename I, unsigned n>
+ template <typename I, typename W>
template <typename Dps>
inline
void
- static_dpoints_fwd_pixter<I, n>::init_(const Dps& dps)
+ static_dpoints_fwd_pixter<I, W>::init_(const Dps& dps)
{
for (unsigned i = 0; i < dps.size(); ++i)
offset_[i] = this->image_.delta_index(dps.dp(i));
@@ -282,10 +286,10 @@ namespace mln
invalidate();
}
- template <typename I, unsigned n>
+ template <typename I, typename W>
inline
void
- static_dpoints_fwd_pixter<I, n>::update()
+ static_dpoints_fwd_pixter<I, W>::update()
{
if (is_valid())
{
@@ -296,50 +300,50 @@ namespace mln
}
}
- template <typename I, unsigned n>
+ template <typename I, typename W>
inline
void
- static_dpoints_fwd_pixter<I, n>::start()
+ static_dpoints_fwd_pixter<I, W>::start()
{
i_ = 0;
update();
}
- template <typename I, unsigned n>
+ template <typename I, typename W>
inline
void
- static_dpoints_fwd_pixter<I, n>::next_()
+ static_dpoints_fwd_pixter<I, W>::next_()
{
++i_;
if (is_valid())
this->value_ptr_ += offset_[i_];
}
- template <typename I, unsigned n>
+ template <typename I, typename W>
inline
bool
- static_dpoints_fwd_pixter<I, n>::is_valid() const
+ static_dpoints_fwd_pixter<I, W>::is_valid() const
{
return i_ < n;
}
- template <typename I, unsigned n>
+ template <typename I, typename W>
inline
void
- static_dpoints_fwd_pixter<I, n>::invalidate()
+ static_dpoints_fwd_pixter<I, W>::invalidate()
{
i_ = n;
}
/*----------------------------------.
- | static_dpoints_bkd_pixter<I, n>. |
+ | static_dpoints_bkd_pixter<I, W>. |
`----------------------------------*/
- template <typename I, unsigned n>
+ template <typename I, typename W>
template <typename Dps, typename Pref>
inline
- static_dpoints_bkd_pixter<I, n>::static_dpoints_bkd_pixter(I& image,
+ static_dpoints_bkd_pixter<I, W>::static_dpoints_bkd_pixter(I& image,
const Dps& dps,
const Pref& p_ref)
: super_(image)
@@ -350,10 +354,10 @@ namespace mln
init_(dps);
}
- template <typename I, unsigned n>
+ template <typename I, typename W>
template <typename Dps, typename Pref>
inline
- static_dpoints_bkd_pixter<I, n>::static_dpoints_bkd_pixter(const Generalized_Pixel<Pref>& pxl_ref_,
+ static_dpoints_bkd_pixter<I, W>::static_dpoints_bkd_pixter(const Generalized_Pixel<Pref>& pxl_ref_,
const Dps& dps)
: super_(internal::force_exact<Pref>(pxl_ref_).ima())
{
@@ -365,10 +369,10 @@ namespace mln
init_(dps);
}
- template <typename I, unsigned n>
+ template <typename I, typename W>
inline
const mln_value(I)&
- static_dpoints_bkd_pixter<I, n>::center_val() const
+ static_dpoints_bkd_pixter<I, W>::center_val() const
{
mln_invariant(value_ref_ != 0 || p_ref_ != 0);
if (p_ref_)
@@ -377,11 +381,11 @@ namespace mln
return **value_ref_;
}
- template <typename I, unsigned n>
+ template <typename I, typename W>
template <typename Dps>
inline
void
- static_dpoints_bkd_pixter<I, n>::init_(const Dps& dps)
+ static_dpoints_bkd_pixter<I, W>::init_(const Dps& dps)
{
for (unsigned i = 0; i < dps.size(); ++i)
offset_[i] = this->image_.delta_index(dps.dp(i));
@@ -393,10 +397,10 @@ namespace mln
invalidate();
}
- template <typename I, unsigned n>
+ template <typename I, typename W>
inline
void
- static_dpoints_bkd_pixter<I, n>::update()
+ static_dpoints_bkd_pixter<I, W>::update()
{
if (is_valid())
{
@@ -407,37 +411,37 @@ namespace mln
}
}
- template <typename I, unsigned n>
+ template <typename I, typename W>
inline
void
- static_dpoints_bkd_pixter<I, n>::start()
+ static_dpoints_bkd_pixter<I, W>::start()
{
i_ = 0;
update();
}
- template <typename I, unsigned n>
+ template <typename I, typename W>
inline
void
- static_dpoints_bkd_pixter<I, n>::next_()
+ static_dpoints_bkd_pixter<I, W>::next_()
{
++i_;
if (is_valid())
this->value_ptr_ += offset_[n - 1 - i_];
}
- template <typename I, unsigned n>
+ template <typename I, typename W>
inline
bool
- static_dpoints_bkd_pixter<I, n>::is_valid() const
+ static_dpoints_bkd_pixter<I, W>::is_valid() const
{
return i_ < n;
}
- template <typename I, unsigned n>
+ template <typename I, typename W>
inline
void
- static_dpoints_bkd_pixter<I, n>::invalidate()
+ static_dpoints_bkd_pixter<I, W>::invalidate()
{
i_ = n;
}
diff --git a/milena/apps/bench/static_window.hh b/milena/apps/bench/static_window.hh
index fe8f791..5a8ce21 100644
--- a/milena/apps/bench/static_window.hh
+++ b/milena/apps/bench/static_window.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008, 2009, 2010 EPITA Research and Development
+// Copyright (C) 2007, 2008, 2009, 2010, 2011 EPITA Research and Development
// Laboratory (LRDE)
//
// This file is part of Olena.
@@ -90,7 +90,7 @@ namespace mln
{
public:
- enum { Size = n };
+ enum { length = n };
/// Regular window associated type.
typedef static_window<D, n> regular;
diff --git a/milena/apps/bench/trait.hh b/milena/apps/bench/trait.hh
new file mode 100644
index 0000000..e3e5004
--- /dev/null
+++ b/milena/apps/bench/trait.hh
@@ -0,0 +1,99 @@
+// Copyright (C) 2011 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 APPS_BENCH_TRAITS_HH
+# define APPS_BENCH_TRAITS_HH
+
+# include <mln/core/image/image2d.hh>
+# include <mln/metal/none.hh>
+
+# include "apps/bench/static_dpoints_pixter.hh"
+
+
+// FIXME: Move this into mln/core/macro.hh.
+# define mln_static_fwd_qixter(I, W) typename mln::trait::static_fwd_qixter< I, W >::ret
+# define mln_static_fwd_qixter_(I, W) mln::trait::static_fwd_qixter< I, W >::ret
+
+# define mln_static_bkd_qixter(I, W) typename mln::trait::static_bkd_qixter< I, W >::ret
+# define mln_static_bkd_qixter_(I, W) mln::trait::static_bkd_qixter< I, W >::ret
+
+# define mln_static_qixter(I, W) mln_static_fwd_qixter(I, W)
+# define mln_static_qixter_(I, W) mln_static_fwd_qixter_(I, W)
+
+
+// FIXME: Move this into mln/trait/ (and mln/core/image/?)
+namespace mln
+{
+
+ namespace trait
+ {
+
+ // qixter
+
+ template <typename I, typename W>
+ struct static_fwd_qixter
+ {
+ typedef metal::none ret;
+ };
+
+ template <typename I, typename W>
+ struct static_bkd_qixter
+ {
+ typedef metal::none ret;
+ };
+
+
+ template <typename T, typename W>
+ struct static_fwd_qixter< image2d<T>, W >
+ {
+ typedef static_dpoints_fwd_pixter< image2d<T>, W > ret;
+ };
+
+ template <typename T, typename W>
+ struct static_fwd_qixter< const image2d<T>, W >
+ {
+ typedef static_dpoints_fwd_pixter< const image2d<T>, W > ret;
+ };
+
+ template <typename T, typename W>
+ struct static_bkd_qixter< image2d<T>, W >
+ {
+ typedef static_dpoints_bkd_pixter< image2d<T>, W > ret;
+ };
+
+ template <typename T, typename W>
+ struct static_bkd_qixter< const image2d<T>, W >
+ {
+ typedef static_dpoints_bkd_pixter< const image2d<T>, W > ret;
+ };
+
+ // FIXME: Also handle mln::image1d<T> and mln::image3d<T>.
+
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+#endif // ! APPS_BENCH_TRAITS_HH
--
1.7.2.5
1
0

14 Oct '11
* apps/bench/dilation-lena.cc
(nongen::dilation)
(nongen_2ptr::dilation)
(nongen_1ptr::dilation)
(gen::dilation)
(fast::dilation)
(fast_noaccu::dilation)
(faster::dilation)
(faster_noaccu::dilation)
(fast_static::dilation)
(faster_static::dilation):
Move functions...
* apps/bench/dilation-lena.hh: ...here (new file).
---
milena/apps/bench/Makefile.am | 2 +-
milena/apps/bench/dilation-lena.cc | 314 +-------------------
.../bench/{dilation-lena.cc => dilation-lena.hh} | 92 +------
3 files changed, 9 insertions(+), 399 deletions(-)
copy milena/apps/bench/{dilation-lena.cc => dilation-lena.hh} (79%)
diff --git a/milena/apps/bench/Makefile.am b/milena/apps/bench/Makefile.am
index 266b71b..40f0147 100644
--- a/milena/apps/bench/Makefile.am
+++ b/milena/apps/bench/Makefile.am
@@ -36,7 +36,7 @@ EXTRA_DIST += \
static_window.hh \
trait.hh
-dilation_lena_SOURCES = dilation-lena.cc
+dilation_lena_SOURCES = dilation-lena.cc dilation-lena.hh
gradient_lena_SOURCES = gradient-lena.cc
gradient_spe_lena_SOURCES = gradient-spe-lena.cc
diff --git a/milena/apps/bench/dilation-lena.cc b/milena/apps/bench/dilation-lena.cc
index e4996fb..82b4497 100644
--- a/milena/apps/bench/dilation-lena.cc
+++ b/milena/apps/bench/dilation-lena.cc
@@ -23,322 +23,10 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#include <cstddef>
-
-#include <iostream>
-
-#include <mln/core/image/image2d.hh>
-#include <mln/core/alias/window2d.hh>
-
-#include <mln/io/pgm/load.hh>
-#include <mln/io/pgm/save.hh>
-
-#include <mln/value/int_u8.hh>
-
-#include <mln/accu/stat/max.hh>
-
-#include <mln/util/timer.hh>
-
-#include "apps/bench/static_window.hh"
-#include "apps/bench/static_dpoints_pixter.hh"
-#include "apps/bench/trait.hh"
-
+#include "apps/bench/dilation-lena.hh"
#include "apps/data.hh"
-
-namespace nongen
-{
- typedef mln::image2d<mln::value::int_u8> image;
-
- image dilation(const image& input)
- {
- image output (input.nrows(), input.ncols()); // Initialize an output image.
- for (unsigned int r = 0; r < input.nrows(); ++r) // Iterate on rows.
- for (unsigned int c = 0; c < input.ncols(); ++c)
- { // Iterate on columns.
- unsigned char sup = input.at_(r, c);
- if (r != 0 && input.at_(r-1, c) > sup) sup = input.at_(r-1, c);
- if (r != input.nrows() - 1 && input.at_(r+1, c) > sup) sup = input.at_(r+1, c);
- if (c != 0 && input.at_(r, c-1) > sup) sup = input.at_(r, c-1);
- if (c != input.ncols() - 1 && input.at_(r, c+1) > sup) sup = input.at_(r, c+1);
- output.at_(r, c) = sup;
- }
- return output;
- }
-}
-
-namespace nongen_2ptr
-{
- typedef mln::image2d<mln::value::int_u8> image;
-
- image dilation(const image& input)
- {
- typedef mln::value::int_u8 val_t;
- // Offsets corresponding to a 4-c window on INPUT.
- ptrdiff_t win_offset[4] = { &input.at_(-1, 0) - &input.at_(0, 0),
- &input.at_(+1, 0) - &input.at_(0, 0),
- &input.at_( 0, -1) - &input.at_(0, 0),
- &input.at_( 0, +1) - &input.at_(0, 0) };
-
- image output (input.nrows(), input.ncols()); // Initialize an output image.
- for (unsigned int r = 0; r < input.nrows(); ++r) // Iterate on rows.
- {
- const val_t* pi = &input.at_(r, 0);
- val_t* po = &output.at_(r, 0);
- for (; pi < &input.at_(r, 0) + input.ncols(); ++pi, ++po)
- {
- unsigned char sup = *pi;
- // (-1, 0) neighbor.
- if (r != 0
- && *(pi + win_offset[0]) > sup)
- sup = *(pi + win_offset[0]);
- // (+1, 0) neighbor.
- if (r != input.nrows() - 1
- && *(pi + win_offset[1]) > sup)
- sup = *(pi + win_offset[1]);
- // (0, -1) neighbor.
- if (pi != &input.at_(r, 0)
- && *(pi + win_offset[2]) > sup)
- sup = *(pi + win_offset[2]);
- // (0, +1) neighbor.
- if (pi != &input.at_(r, 0) + input.ncols() - 1
- && *(pi + win_offset[3]) > sup)
- sup = *(pi + win_offset[3]);
- *po = sup;
- }
- }
- return output;
- }
-}
-
-namespace nongen_1ptr
-{
- typedef mln::image2d<mln::value::int_u8> image;
-
- image dilation(const image& input)
- {
- typedef mln::value::int_u8 val_t;
- // Offsets corresponding to a 4-c window on INPUT.
- ptrdiff_t win_offset[4] = { &input.at_(-1, 0) - &input.at_(0, 0),
- &input.at_(+1, 0) - &input.at_(0, 0),
- &input.at_( 0, -1) - &input.at_(0, 0),
- &input.at_( 0, +1) - &input.at_(0, 0) };
-
- image output;
- initialize(output, input);
- // Offset between a the pixel located at the same position in
- // INPUT and OUTPUT.
- ptrdiff_t output_offset = &output.at_(0, 0) - &input.at_(0, 0);
-
- for (unsigned int r = 0; r < input.nrows(); ++r) // Iterate on rows.
- {
- for (const val_t* pi = &input.at_(r, 0);
- pi < &input.at_(r, 0) + input.ncols();
- ++pi)
- {
- unsigned char sup = *pi;
- // (-1, 0) neighbor.
- if (r != 0
- && *(pi + win_offset[0]) > sup)
- sup = *(pi + win_offset[0]);
- // (+1, 0) neighbor.
- if (r != input.nrows() - 1
- && *(pi + win_offset[1]) > sup)
- sup = *(pi + win_offset[1]);
- // (0, -1) neighbor.
- if (pi != &input.at_(r, 0)
- && *(pi + win_offset[2]) > sup)
- sup = *(pi + win_offset[2]);
- // (0, +1) neighbor.
- if (pi != &input.at_(r, 0) + input.ncols() - 1
- && *(pi + win_offset[3]) > sup)
- sup = *(pi + win_offset[3]);
- const_cast<val_t&>(*(pi + output_offset)) = sup;
- }
- }
- return output;
- }
-}
-
-namespace gen
-{
- using namespace mln;
-
- template <typename I, typename W>
- mln_concrete(I) dilation(const I& input, const W& win)
- {
- mln_concrete(I) output; initialize(output, input); // Initialize output.
- mln_piter(I) p(input.domain()); // Iterator on sites of the domain of `input'.
- mln_qiter(W) q(win, p); // Iterator on the neighbors of `p' w.r.t. `win'.
- for_all(p)
- {
- // FIXME: Cheat: replace the accu::supremum by a maximum.
- mln::accu::stat::max<mln_value(I)> sup; // Accumulator computing the supremum.
- for_all(q) if (input.has(q))
- sup.take(input(q));
- output(p) = sup.to_result();
- }
- return output;
- }
-}
-
-namespace fast
-{
- using namespace mln;
-
- template <typename I, typename W>
- mln_concrete(I) dilation(const I& input, const W& win)
- {
- typedef mln_concrete(I) O;
- O output; initialize(output, input); // Initialize output.
-
- mln_pixter(const I) pi(input); // Iterator on the pixels of `input'.
- mln_pixter(O) po(output); // Iterator on the pixels of `output'.
-
- mln_qixter(const I, W) q(pi, win); // Iterator on the neighbors of `p' w.r.t. `win'.
- for_all_2(pi, po)
- {
- // FIXME: Cheat: replace the accu::supremum by a maximum.
- mln::accu::stat::max<mln_value(I)> sup; // Accumulator computing the supremum.
- for_all(q)
- sup.take(q.val());
- po.val() = sup.to_result();
- }
- return output;
- }
-}
-
-namespace fast_noaccu
-{
- using namespace mln;
-
- template <typename I, typename W>
- mln_concrete(I) dilation(const I& input, const W& win)
- {
- typedef mln_concrete(I) O;
- O output; initialize(output, input); // Initialize output.
-
- mln_pixter(const I) pi(input); // Iterator on the pixels of `input'.
- mln_pixter(O) po(output); // Iterator on the pixels of `output'.
-
- mln_qixter(const I, W) q(pi, win); // Iterator on the neighbors of `p' w.r.t. `win'.
- for_all_2(pi, po)
- {
- // FIXME: Cheat: replace the accu::supremum by a maximum.
- mln_value(I) sup = mln_min(mln_value(I));
- for_all(q)
- if (q.val() > sup)
- sup = q.val();
- po.val() = sup;
- }
- return output;
- }
-}
-
-namespace faster
-{
- using namespace mln;
-
- template <typename I, typename W>
- mln_concrete(I) dilation(const I& input, const W& win)
- {
- typedef mln_concrete(I) O;
- O output; initialize(output, input); // Initialize output.
-
- mln_pixter(const I) p(input); // Iterator on the pixels of `input'.
-
- mln_qixter(const I, W) q(p, win); // Iterator on the neighbors of `p' w.r.t. `win'.
- for_all(p)
- {
- // FIXME: Cheat: replace the accu::supremum by a maximum.
- mln::accu::stat::max<mln_value(I)> sup; // Accumulator computing the supremum.
- for_all(q)
- sup.take(q.val());
- *(output.buffer() + p.offset()) = sup.to_result();
- }
- return output;
- }
-}
-
-namespace faster_noaccu
-{
- using namespace mln;
-
- template <typename I, typename W>
- mln_concrete(I) dilation(const I& input, const W& win)
- {
- typedef mln_concrete(I) O;
- O output; initialize(output, input); // Initialize output.
-
- mln_pixter(const I) p(input); // Iterator on the pixels of `input'.
-
- mln_qixter(const I, W) q(p, win); // Iterator on the neighbors of `p' w.r.t. `win'.
- for_all(p)
- {
- // FIXME: Cheat: replace the accu::supremum by a maximum.
- mln_value(I) sup = mln_min(mln_value(I));
- for_all(q)
- if (q.val() > sup)
- sup = q.val();
- *(output.buffer() + p.offset()) = sup;
- }
- return output;
- }
-}
-
-namespace fast_static
-{
- using namespace mln;
-
- template <typename I, typename W>
- mln_concrete(I) dilation(const I& input, const W& win)
- {
- typedef mln_concrete(I) O;
- O output; initialize(output, input); // Initialize output.
-
- mln_pixter(const I) pi(input); // Iterator on the pixels of `input'.
- mln_pixter(O) po(output); // Iterator on the pixels of `output'.
- mln_static_qixter(const I, W) q(pi, win); // Iterator on the neighbors of `p' w.r.t. `win'.
-
- for_all_2(pi, po)
- {
- // FIXME: Cheat: replace the accu::supremum by a maximum.
- mln::accu::stat::max<mln_value(I)> sup; // Accumulator computing the supremum.
- for_all(q)
- sup.take(q.val());
- po.val() = sup.to_result();
- }
- return output;
- }
-}
-
-namespace faster_static
-{
- using namespace mln;
-
- template <typename I, typename W>
- mln_concrete(I) dilation(const I& input, const W& win)
- {
- typedef mln_concrete(I) O;
- O output; initialize(output, input); // Initialize output.
-
- mln_pixter(const I) p(input); // Iterator on the pixels of `input'.
- mln_static_qixter(const I, W) q(p, win); // Iterator on the neighbors of `p' w.r.t. `win'.
-
- for_all(p)
- {
- // FIXME: Cheat: replace the accu::supremum by a maximum.
- mln::accu::stat::max<mln_value(I)> sup; // Accumulator computing the supremum.
- for_all(q)
- sup.take(q.val());
- *(output.buffer() + p.offset()) = sup.to_result();
- }
- return output;
- }
-}
-
-
// Shortcut macros for run.
#define DILATION_WITH_BUILTIN_WINDOW(Namespace, Suffix, Headline) \
diff --git a/milena/apps/bench/dilation-lena.cc b/milena/apps/bench/dilation-lena.hh
similarity index 79%
copy from milena/apps/bench/dilation-lena.cc
copy to milena/apps/bench/dilation-lena.hh
index e4996fb..c89eb4e 100644
--- a/milena/apps/bench/dilation-lena.cc
+++ b/milena/apps/bench/dilation-lena.hh
@@ -23,6 +23,12 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
+#ifndef APPS_BENCH_DILATION_LENA_HH
+#define APPS_BENCH_DILATION_LENA_HH
+
+/// \file
+/// \brief Dilation benchmark cases.
+
#include <cstddef>
#include <iostream>
@@ -43,9 +49,6 @@
#include "apps/bench/static_dpoints_pixter.hh"
#include "apps/bench/trait.hh"
-#include "apps/data.hh"
-
-
namespace nongen
{
@@ -338,85 +341,4 @@ namespace faster_static
}
}
-
-// Shortcut macros for run.
-
-#define DILATION_WITH_BUILTIN_WINDOW(Namespace, Suffix, Headline) \
- do \
- { \
- d = lena; \
- t.start(); \
- for (unsigned i = 0; i < niters; ++i) \
- d = Namespace::dilation(d); \
- t.stop(); \
- std::cout << Headline << t.read() << " s" << std::endl; \
- io::pgm::save(d, prefix + '-' + length + '-' + Suffix + ".pgm"); \
- } \
- while (0)
-
-#define DILATION(Namespace, Win, Suffix, Headline) \
- do \
- { \
- d = lena; \
- t.start(); \
- for (unsigned i = 0; i < niters; ++i) \
- d = Namespace::dilation(d, Win); \
- t.stop(); \
- std::cout << Headline << t.read() << " s" << std::endl; \
- io::pgm::save(d, prefix + '-' + length + '-' + Suffix + ".pgm"); \
- } \
- while (0)
-
-
-void
-run(const std::string& filename, const std::string& length, unsigned niters)
-{
- using namespace mln;
- using value::int_u8;
-
- border::thickness = 1;
- image2d<int_u8> lena;
- io::pgm::load(lena, filename);
-
- image2d<int_u8> d;
- util::timer t;
-
- std::string prefix = "dilation-lena-out";
- std::cout << "== " << filename << std::endl;
-
- DILATION_WITH_BUILTIN_WINDOW(nongen, "nongen", "nongen\t\t");
- DILATION_WITH_BUILTIN_WINDOW(nongen_2ptr, "nongen_2ptr", "nongen_2ptr\t");
- DILATION_WITH_BUILTIN_WINDOW(nongen_1ptr, "nongen_1ptr", "nongen_1ptr\t");
-
- DILATION(gen, win_c4p(), "gen", "gen\t\t");
- // FIXME: Introduce a new test case, gen_static, using a static window
- // and static_qiters.
- DILATION(fast, win_c4p(), "fast", "fast\t\t");
- DILATION(fast_noaccu, win_c4p(), "fast_noaccu", "fast_noaccu\t");
- DILATION(faster, win_c4p(), "faster", "faster\t\t");
- DILATION(faster_noaccu, win_c4p(), "faster_noaccu", "faster_noaccu\t");
-
- // Static windows and qixters.
- const unsigned n = 5;
- mln::dpoint2d dps[n] = { mln::dpoint2d( 0, -1),
- mln::dpoint2d(-1, 0),
- mln::dpoint2d( 0, 0),
- mln::dpoint2d(+1, 0),
- mln::dpoint2d( 0, +1) };
- mln::util::static_array<mln::dpoint2d, n> sa(dps, dps + n);
- mln::static_window<mln::dpoint2d, n> static_win_c4p (sa);
-
- DILATION(fast_static, static_win_c4p, "fast_static", "fast_static\t");
- DILATION(faster_static, static_win_c4p, "faster_static", "faster_static\t");
-
- std::cout << std::endl;
-}
-
-int
-main ()
-{
- unsigned niters = 10;
- run(MLN_IMG_DIR "/lena.pgm", "512", niters);
- run(MLN_APPS_DIR "/bench/lena1024.pgm", "1024", niters);
- run(MLN_APPS_DIR "/bench/lena2048.pgm", "2048", niters);
-}
+#endif // ! APPS_BENCH_DILATION_LENA_HH
--
1.7.2.5
1
0

last-svn-commit-550-gfcea0a4 WIP: Generate a LaTeX table from some results of apps/bench/dilation-lena.
by Roland Levillain 14 Oct '11
by Roland Levillain 14 Oct '11
14 Oct '11
---
milena/apps/bench/Makefile.am | 2 +
.../{dilation-lena.cc => dilation-lena-table.cc} | 91 +++++++++++++++++---
2 files changed, 80 insertions(+), 13 deletions(-)
copy milena/apps/bench/{dilation-lena.cc => dilation-lena-table.cc} (56%)
diff --git a/milena/apps/bench/Makefile.am b/milena/apps/bench/Makefile.am
index 40f0147..e27be3c 100644
--- a/milena/apps/bench/Makefile.am
+++ b/milena/apps/bench/Makefile.am
@@ -24,6 +24,7 @@ EXTRA_DIST = lena1024.pgm lena2048.pgm
noinst_PROGRAMS = \
dilation-lena \
+ dilation-lena-table \
gradient-lena \
gradient-spe-lena
@@ -37,6 +38,7 @@ EXTRA_DIST += \
trait.hh
dilation_lena_SOURCES = dilation-lena.cc dilation-lena.hh
+dilation_lena_table_SOURCES = dilation-lena-table.cc dilation-lena.hh
gradient_lena_SOURCES = gradient-lena.cc
gradient_spe_lena_SOURCES = gradient-spe-lena.cc
diff --git a/milena/apps/bench/dilation-lena.cc b/milena/apps/bench/dilation-lena-table.cc
similarity index 56%
copy from milena/apps/bench/dilation-lena.cc
copy to milena/apps/bench/dilation-lena-table.cc
index 82b4497..3057ce3 100644
--- a/milena/apps/bench/dilation-lena.cc
+++ b/milena/apps/bench/dilation-lena-table.cc
@@ -37,8 +37,7 @@
for (unsigned i = 0; i < niters; ++i) \
d = Namespace::dilation(d); \
t.stop(); \
- std::cout << Headline << t.read() << " s" << std::endl; \
- io::pgm::save(d, prefix + '-' + length + '-' + Suffix + ".pgm"); \
+ times.push_back(t.read()); \
} \
while (0)
@@ -50,14 +49,13 @@
for (unsigned i = 0; i < niters; ++i) \
d = Namespace::dilation(d, Win); \
t.stop(); \
- std::cout << Headline << t.read() << " s" << std::endl; \
- io::pgm::save(d, prefix + '-' + length + '-' + Suffix + ".pgm"); \
+ times.push_back(t.read()); \
} \
while (0)
-void
-run(const std::string& filename, const std::string& length, unsigned niters)
+std::vector<float>
+run(const std::string& filename, unsigned niters)
{
using namespace mln;
using value::int_u8;
@@ -68,21 +66,25 @@ run(const std::string& filename, const std::string& length, unsigned niters)
image2d<int_u8> d;
util::timer t;
-
- std::string prefix = "dilation-lena-out";
- std::cout << "== " << filename << std::endl;
+ std::vector<float> times;
DILATION_WITH_BUILTIN_WINDOW(nongen, "nongen", "nongen\t\t");
DILATION_WITH_BUILTIN_WINDOW(nongen_2ptr, "nongen_2ptr", "nongen_2ptr\t");
+# if 0
+ // Disabled, not used in the paper's table.
DILATION_WITH_BUILTIN_WINDOW(nongen_1ptr, "nongen_1ptr", "nongen_1ptr\t");
+#endif
DILATION(gen, win_c4p(), "gen", "gen\t\t");
// FIXME: Introduce a new test case, gen_static, using a static window
// and static_qiters.
DILATION(fast, win_c4p(), "fast", "fast\t\t");
+# if 0
+ // Disabled, not used in the paper's table.
DILATION(fast_noaccu, win_c4p(), "fast_noaccu", "fast_noaccu\t");
DILATION(faster, win_c4p(), "faster", "faster\t\t");
DILATION(faster_noaccu, win_c4p(), "faster_noaccu", "faster_noaccu\t");
+#endif
// Static windows and qixters.
const unsigned n = 5;
@@ -95,16 +97,79 @@ run(const std::string& filename, const std::string& length, unsigned niters)
mln::static_window<mln::dpoint2d, n> static_win_c4p (sa);
DILATION(fast_static, static_win_c4p, "fast_static", "fast_static\t");
+# if 0
+ // Disabled, not used in the paper's table.
DILATION(faster_static, static_win_c4p, "faster_static", "faster_static\t");
+#endif
- std::cout << std::endl;
+ return times;
}
int
main ()
{
unsigned niters = 10;
- run(MLN_IMG_DIR "/lena.pgm", "512", niters);
- run(MLN_APPS_DIR "/bench/lena1024.pgm", "1024", niters);
- run(MLN_APPS_DIR "/bench/lena2048.pgm", "2048", niters);
+ typedef std::vector<float> times_t;
+
+ // Compute times.
+ times_t times_512 = run(MLN_IMG_DIR "/lena.pgm", niters);
+ times_t times_1024 = run(MLN_APPS_DIR "/bench/lena1024.pgm", niters);
+ times_t times_2048 = run(MLN_APPS_DIR "/bench/lena2048.pgm", niters);
+
+ // Display times.
+ times_t::const_iterator i_512 = times_512.begin();
+ times_t::const_iterator i_1024 = times_1024.begin();
+ times_t::const_iterator i_2048 = times_2048.begin();
+ std::cout <<
+ "\\begin{table}[tbp]\n"
+ " \\centering\n"
+ " \\begin{tabular}{lrrr}\n"
+ " \\hline\n"
+ " Implementation & \\multicolumn{3}{c}{Execution times (s)} \\\\\n"
+ " & $512^2$ & $1024^2$ & $2048^2$ \\\\\n"
+ " \\hline\n"
+ " \\hline\n";
+
+ /* Increment each iterator only once in each output statement to
+ avoid non-determinism due to the successive uses of operator++ on
+ a given iterator. */
+
+ // nongen.
+ std::cout <<
+ " Non generic (\\algref{lst:non-gen-dilation}) & " <<
+ *i_512++ << " & " << *i_1024++ << " & " << *i_2048++ << " \\\\\n"
+ " \\hline\n";
+
+ // nongen_2ptr.
+ std::cout <<
+ " Non generic, pointer-based\\footnotemark[1] & " <<
+ *i_512++ << " & " << *i_1024++ << " & " << *i_2048++ << " \\\\\n"
+ " \\hline\n";
+
+ // gen.
+ std::cout <<
+ " Generic (\\algref{lst:gen-dilation}) & " <<
+ *i_512++ << " & " << *i_1024++ << " & " << *i_2048++ << " \\\\\n"
+ " \\hline\n";
+
+ // fast.
+ std::cout <<
+ " Fast, partly generic (\\algref{lst:fast-dilation}) & " <<
+ *i_512++ << " & " << *i_1024++ << " & " << *i_2048++ << " \\\\\n"
+ " \\hline\n";
+
+ // fast_static.
+ std::cout <<
+ " Fast, partly generic with & " <<
+ *i_512++ << " & " << *i_1024++ << " & " << *i_2048++ << " \\\\\n"
+ " static window (\\algref{lst:fast-static-dilation}) & & & \\\\\n"
+ " \\hline\n";
+
+ std::cout <<
+ " \\end{tabular}\n"
+ " \\caption{Execution times of various dilation implementations.}\n"
+ " \\label{tab:results}\n"
+ "\\end{table}\n"
+ "\\footnotetext[1]{Implementation not shown in this paper for space\n"
+ " reasons.}\n" << std::flush;
}
--
1.7.2.5
1
0

last-svn-commit-551-gb2a8ff2 WIP: configure.ac (APPS_CXXFLAGS_NODEBUG): New precious variable.
by Roland Levillain 14 Oct '11
by Roland Levillain 14 Oct '11
14 Oct '11
---
configure.ac | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/configure.ac b/configure.ac
index a64f80d..9fd70ce 100644
--- a/configure.ac
+++ b/configure.ac
@@ -569,6 +569,13 @@ if test -z "$APPS_CXXFLAGS"; then
APPS_CXXFLAGS="-O3 -DNDEBUG -g $WARNINGS_CXXFLAGS"
fi
fi
+# Likewise, without debugging information.
+AC_ARG_VAR([APPS_CXXFLAGS_NODEBUG],
+ [C++ compiler flags for applications w/o debug symbols])
+if test -z "$APPS_CXXFLAGS_NODEBUG" && test "$GXX" = yes; then
+ APPS_CXXFLAGS_NODEBUG="-O3 -DNDEBUG $WARNINGS_CXXFLAGS"
+fi
+
## ------- ##
## Tools. ##
--
1.7.2.5
1
0

14 Oct '11
---
milena/apps/bench/Makefile.am | 3 +--
milena/apps/bench/dilation-lena-table.cc | 11 ++++++++++-
milena/apps/bench/dilation-lena.cc | 2 ++
milena/apps/bench/dilation-lena.hh | 4 ----
4 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/milena/apps/bench/Makefile.am b/milena/apps/bench/Makefile.am
index e27be3c..18e0a38 100644
--- a/milena/apps/bench/Makefile.am
+++ b/milena/apps/bench/Makefile.am
@@ -17,8 +17,7 @@
# Find Milena headers.
AM_CPPFLAGS = -I$(top_srcdir)/milena -I$(top_builddir)/milena
# Produce fast code.
-APPS_CXXFLAGS = @APPS_CXXFLAGS@
-AM_CXXFLAGS = $(APPS_CXXFLAGS)
+AM_CXXFLAGS = $(APPS_CXXFLAGS_NODEBUG)
EXTRA_DIST = lena1024.pgm lena2048.pgm
diff --git a/milena/apps/bench/dilation-lena-table.cc b/milena/apps/bench/dilation-lena-table.cc
index 3057ce3..cff1a2b 100644
--- a/milena/apps/bench/dilation-lena-table.cc
+++ b/milena/apps/bench/dilation-lena-table.cc
@@ -23,6 +23,9 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
+#include <iostream>
+#include <iomanip>
+
#include "apps/bench/dilation-lena.hh"
#include "apps/data.hh"
@@ -67,6 +70,7 @@ run(const std::string& filename, unsigned niters)
image2d<int_u8> d;
util::timer t;
std::vector<float> times;
+ times.reserve(5);
DILATION_WITH_BUILTIN_WINDOW(nongen, "nongen", "nongen\t\t");
DILATION_WITH_BUILTIN_WINDOW(nongen_2ptr, "nongen_2ptr", "nongen_2ptr\t");
@@ -106,7 +110,7 @@ run(const std::string& filename, unsigned niters)
}
int
-main ()
+main (int /* argc */, char* argv[])
{
unsigned niters = 10;
typedef std::vector<float> times_t;
@@ -121,6 +125,8 @@ main ()
times_t::const_iterator i_1024 = times_1024.begin();
times_t::const_iterator i_2048 = times_2048.begin();
std::cout <<
+ "% Generated by `" << argv[0] << "', do not modify.\n"
+ "\n"
"\\begin{table}[tbp]\n"
" \\centering\n"
" \\begin{tabular}{lrrr}\n"
@@ -130,6 +136,9 @@ main ()
" \\hline\n"
" \\hline\n";
+ // Fix the output format for floats.
+ std::cout << std::fixed << std::setprecision(4);
+
/* Increment each iterator only once in each output statement to
avoid non-determinism due to the successive uses of operator++ on
a given iterator. */
diff --git a/milena/apps/bench/dilation-lena.cc b/milena/apps/bench/dilation-lena.cc
index 82b4497..0754cab 100644
--- a/milena/apps/bench/dilation-lena.cc
+++ b/milena/apps/bench/dilation-lena.cc
@@ -23,6 +23,8 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
+#include <iostream>
+
#include "apps/bench/dilation-lena.hh"
#include "apps/data.hh"
diff --git a/milena/apps/bench/dilation-lena.hh b/milena/apps/bench/dilation-lena.hh
index c89eb4e..47e76dd 100644
--- a/milena/apps/bench/dilation-lena.hh
+++ b/milena/apps/bench/dilation-lena.hh
@@ -29,10 +29,6 @@
/// \file
/// \brief Dilation benchmark cases.
-#include <cstddef>
-
-#include <iostream>
-
#include <mln/core/image/image2d.hh>
#include <mln/core/alias/window2d.hh>
--
1.7.2.5
1
0

last-svn-commit-553-g7808a2d WIP: Have apps/bench/dilation-lena-table behave a bit more like apps/bench/dilation-lena.
by Roland Levillain 14 Oct '11
by Roland Levillain 14 Oct '11
14 Oct '11
---
milena/apps/bench/Makefile.am | 18 ++++++++++++++++--
milena/apps/bench/dilation-lena-table.cc | 18 ++++++++++++++----
2 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/milena/apps/bench/Makefile.am b/milena/apps/bench/Makefile.am
index 18e0a38..b5919ce 100644
--- a/milena/apps/bench/Makefile.am
+++ b/milena/apps/bench/Makefile.am
@@ -52,7 +52,6 @@ MOSTLYCLEANFILES = \
dilation-lena-out-512-faster_noaccu.pgm \
dilation-lena-out-512-fast_static.pgm \
dilation-lena-out-512-faster_static.pgm \
- \
dilation-lena-out-1024-nongen.pgm \
dilation-lena-out-1024-nongen_2ptr.pgm \
dilation-lena-out-1024-nongen_1ptr.pgm \
@@ -63,7 +62,6 @@ MOSTLYCLEANFILES = \
dilation-lena-out-1024-faster_noaccu.pgm \
dilation-lena-out-1024-fast_static.pgm \
dilation-lena-out-1024-faster_static.pgm \
- \
dilation-lena-out-2048-nongen.pgm \
dilation-lena-out-2048-nongen_2ptr.pgm \
dilation-lena-out-2048-nongen_1ptr.pgm \
@@ -75,6 +73,22 @@ MOSTLYCLEANFILES = \
dilation-lena-out-2048-fast_static.pgm \
dilation-lena-out-2048-faster_static.pgm \
\
+ dilation-lena-table-out-512-nongen.pgm \
+ dilation-lena-table-out-512-nongen_2ptr.pgm \
+ dilation-lena-table-out-512-gen.pgm \
+ dilation-lena-table-out-512-fast.pgm \
+ dilation-lena-table-out-512-fast_static.pgm \
+ dilation-lena-table-out-1024-nongen.pgm \
+ dilation-lena-table-out-1024-nongen_2ptr.pgm \
+ dilation-lena-table-out-1024-gen.pgm \
+ dilation-lena-table-out-1024-fast.pgm \
+ dilation-lena-table-out-1024-fast_static.pgm \
+ dilation-lena-table-out-2048-nongen.pgm \
+ dilation-lena-table-out-2048-nongen_2ptr.pgm \
+ dilation-lena-table-out-2048-gen.pgm \
+ dilation-lena-table-out-2048-fast.pgm \
+ dilation-lena-table-out-2048-fast_static.pgm \
+ \
gradient-lena-out.pgm \
gradient-spe-lena-out-0.pgm \
gradient-spe-lena-out-1.pgm \
diff --git a/milena/apps/bench/dilation-lena-table.cc b/milena/apps/bench/dilation-lena-table.cc
index cff1a2b..ca21758 100644
--- a/milena/apps/bench/dilation-lena-table.cc
+++ b/milena/apps/bench/dilation-lena-table.cc
@@ -40,6 +40,8 @@
for (unsigned i = 0; i < niters; ++i) \
d = Namespace::dilation(d); \
t.stop(); \
+ std::cerr << Headline << t.read() << " s" << std::endl; \
+ io::pgm::save(d, prefix + '-' + length + '-' + Suffix + ".pgm"); \
times.push_back(t.read()); \
} \
while (0)
@@ -52,13 +54,15 @@
for (unsigned i = 0; i < niters; ++i) \
d = Namespace::dilation(d, Win); \
t.stop(); \
+ std::cerr << Headline << t.read() << " s" << std::endl; \
+ io::pgm::save(d, prefix + '-' + length + '-' + Suffix + ".pgm"); \
times.push_back(t.read()); \
} \
while (0)
std::vector<float>
-run(const std::string& filename, unsigned niters)
+run(const std::string& filename, const std::string& length, unsigned niters)
{
using namespace mln;
using value::int_u8;
@@ -69,6 +73,10 @@ run(const std::string& filename, unsigned niters)
image2d<int_u8> d;
util::timer t;
+
+ std::string prefix = "dilation-lena-table-out";
+ std::cerr << "== " << filename << std::endl;
+
std::vector<float> times;
times.reserve(5);
@@ -106,6 +114,8 @@ run(const std::string& filename, unsigned niters)
DILATION(faster_static, static_win_c4p, "faster_static", "faster_static\t");
#endif
+ std::cerr << std::endl;
+
return times;
}
@@ -116,9 +126,9 @@ main (int /* argc */, char* argv[])
typedef std::vector<float> times_t;
// Compute times.
- times_t times_512 = run(MLN_IMG_DIR "/lena.pgm", niters);
- times_t times_1024 = run(MLN_APPS_DIR "/bench/lena1024.pgm", niters);
- times_t times_2048 = run(MLN_APPS_DIR "/bench/lena2048.pgm", niters);
+ times_t times_512 = run(MLN_IMG_DIR "/lena.pgm", "512", niters);
+ times_t times_1024 = run(MLN_APPS_DIR "/bench/lena1024.pgm", "1024", niters);
+ times_t times_2048 = run(MLN_APPS_DIR "/bench/lena2048.pgm", "2048", niters);
// Display times.
times_t::const_iterator i_512 = times_512.begin();
--
1.7.2.5
1
0

last-svn-commit-554-g51d7fe3 WIP: New experiment: apps/bench/dilation-lena-bench.
by Roland Levillain 14 Oct '11
by Roland Levillain 14 Oct '11
14 Oct '11
---
milena/apps/bench/Makefile.am | 8 ++-
milena/apps/bench/dilation-lena-bench.cc | 127 ++++++++++++++++++++++++++++++
2 files changed, 133 insertions(+), 2 deletions(-)
create mode 100644 milena/apps/bench/dilation-lena-bench.cc
diff --git a/milena/apps/bench/Makefile.am b/milena/apps/bench/Makefile.am
index b5919ce..64bfc18 100644
--- a/milena/apps/bench/Makefile.am
+++ b/milena/apps/bench/Makefile.am
@@ -23,6 +23,7 @@ EXTRA_DIST = lena1024.pgm lena2048.pgm
noinst_PROGRAMS = \
dilation-lena \
+ dilation-lena-bench \
dilation-lena-table \
gradient-lena \
gradient-spe-lena
@@ -36,8 +37,11 @@ EXTRA_DIST += \
static_window.hh \
trait.hh
-dilation_lena_SOURCES = dilation-lena.cc dilation-lena.hh
-dilation_lena_table_SOURCES = dilation-lena-table.cc dilation-lena.hh
+noinst_HEADERS = dilation-lena.hh
+
+dilation_lena_SOURCES = dilation-lena.cc
+dilation_lena_bench_SOURCES = dilation-lena-bench.cc
+dilation_lena_table_SOURCES = dilation-lena-table.cc
gradient_lena_SOURCES = gradient-lena.cc
gradient_spe_lena_SOURCES = gradient-spe-lena.cc
diff --git a/milena/apps/bench/dilation-lena-bench.cc b/milena/apps/bench/dilation-lena-bench.cc
new file mode 100644
index 0000000..ce4cee0
--- /dev/null
+++ b/milena/apps/bench/dilation-lena-bench.cc
@@ -0,0 +1,127 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#include <cstdlib>
+
+#include <iostream>
+#include <iomanip>
+#include <string>
+
+#include "apps/bench/dilation-lena.hh"
+
+
+namespace tag
+{
+ enum dilation
+ {
+ nongen = 1,
+ nongen_2ptr = 2,
+ gen = 3,
+ fast = 4,
+ fast_static = 5
+ };
+}
+
+void
+usage(const std::string& program)
+{
+ std::cerr << program << " implementation input.pgm\n\n" <<
+ " were implementation is\n"
+ " 1 : nongen\n"
+ " 2 : nongen_2ptr \n"
+ " 3 : gen\n"
+ " 4 : fast\n"
+ " 5 : fast_static\n";
+ std::exit(1);
+}
+
+
+#define DILATION_WITH_BUILTIN_WINDOW(Namespace) \
+ do \
+ { \
+ image2d<int_u8> d = lena; \
+ t.start(); \
+ for (unsigned i = 0; i < 10; ++i) \
+ d = Namespace::dilation(d); \
+ t.stop(); \
+ } \
+ while (0)
+
+#define DILATION(Namespace, Win) \
+ do \
+ { \
+ image2d<int_u8> d = lena; \
+ t.start(); \
+ for (unsigned i = 0; i < 10; ++i) \
+ d = Namespace::dilation(d, Win); \
+ t.stop(); \
+ } \
+ while (0)
+
+
+int
+main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+
+ if (argc != 3)
+ usage(argv[0]);
+
+ int method = atoi(argv[1]);
+ std::string filename = argv[2];
+
+ border::thickness = 1;
+ image2d<int_u8> lena;
+ io::pgm::load(lena, filename);
+ util::timer t;
+
+ // Static windows and qixters.
+ const unsigned n = 5;
+ mln::dpoint2d dps[n] = { mln::dpoint2d( 0, -1),
+ mln::dpoint2d(-1, 0),
+ mln::dpoint2d( 0, 0),
+ mln::dpoint2d(+1, 0),
+ mln::dpoint2d( 0, +1) };
+ mln::util::static_array<mln::dpoint2d, n> sa(dps, dps + n);
+ mln::static_window<mln::dpoint2d, n> static_win_c4p(sa);
+
+ switch (method)
+ {
+ case ::tag::nongen: DILATION_WITH_BUILTIN_WINDOW(nongen); break;
+ case ::tag::nongen_2ptr: DILATION_WITH_BUILTIN_WINDOW(nongen_2ptr); break;
+ case ::tag::gen: DILATION(gen, win_c4p()); break;
+ case ::tag::fast: DILATION(fast, win_c4p()); break;
+ case ::tag::fast_static: DILATION(fast_static, static_win_c4p); break;
+
+ default:
+ usage(argv[0]);
+ }
+
+ // Fix the output format for floats.
+ std::cout << std::fixed << std::setprecision(4);
+ // Display the elapsed time.
+ std::cout << t.read() << std::endl;
+}
--
1.7.2.5
1
0