
* headers.mk: add new header to distribution. * mln/make/h_mat.hh: create a h_mat from a C-style array. * tests/unit_test/Makefile.am, * tests/unit_test/mln_make_h_mat.cc: add unit test. --- milena/ChangeLog | 38 +++++++++ milena/headers.mk | 1 + milena/mln/make/h_mat.hh | 121 ++++++++++++++++++++++++++++++ milena/tests/unit_test/Makefile.am | 1 + milena/tests/unit_test/mln_make_h_mat.cc | 11 +++ 5 files changed, 172 insertions(+), 0 deletions(-) create mode 100644 milena/mln/make/h_mat.hh create mode 100644 milena/tests/unit_test/mln_make_h_mat.cc diff --git a/milena/ChangeLog b/milena/ChangeLog index eb424b1..58b16ad 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,43 @@ 2009-02-02 Guillaume Lazzara <z@lrde.epita.fr> + Add make::h_mat. + + * headers.mk: add new header to distribution. + + * mln/make/h_mat.hh: create a h_mat from a C-style array. + + * tests/unit_test/Makefile.am, + * tests/unit_test/mln_make_h_mat.cc: add unit test. + +2009-02-02 Guillaume Lazzara <z@lrde.epita.fr> + + Add core/alias/all.hh and alias/vec3d.hh. + + * doc/tutorial/examples/examples.mk + * doc/tutorial/figures/figures.mk + * doc/tutorial/outputs/outputs.mk + * doc/tutorial/samples/samples.mk: Update generated files. + + * headers.mk: add new header to distribution. + + * mln/core/alias/all.hh: new header. + + * mln/core/alias/vec3d.hh: new aliases for 3d algebra::vec. + + * mln/core/alias/box2d.hh, + * mln/core/alias/box3d.hh: update comments. + + * mln/core/all.hh: include alias/all.hh. + + * mln/essential/3d.hh: add image3d.hh and vec3d.hh. + + * tests/unit_test/Makefile.am, + * tests/unit_test/mln_core_alias_all.cc, + * tests/unit_test/mln_core_alias_vec3d.cc, + * tests/unit_test/mln_make_image3d.cc: add new unit test files. + +2009-02-02 Guillaume Lazzara <z@lrde.epita.fr> + Fix tutorial generation. * doc/tutorial/generate_dist_files.sh: dot not include current diff --git a/milena/headers.mk b/milena/headers.mk index 037b5cc..04bef51 100644 --- a/milena/headers.mk +++ b/milena/headers.mk @@ -148,6 +148,7 @@ mln/make/w_window2d_int.hh \ mln/make/box1d.hh \ mln/make/voronoi.hh \ mln/make/box2d.hh \ +mln/make/h_mat.hh \ mln/make/w_window2d.hh \ mln/make/box3d.hh \ mln/make/relabelfun.hh \ diff --git a/milena/mln/make/h_mat.hh b/milena/mln/make/h_mat.hh new file mode 100644 index 0000000..930c133 --- /dev/null +++ b/milena/mln/make/h_mat.hh @@ -0,0 +1,121 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library 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 this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library 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_MAKE_H_MAT_HH +# define MLN_MAKE_H_MAT_HH + +/// \file mln/make/h_mat.hh +/// +/// Routine to construct an mln::algebra::h_mat. + +# include <mln/algebra/h_mat.hh> +# include <mln/metal/math/sqrt.hh> + + +namespace mln +{ + + namespace make + { + + /// Create an mln::algebra::h_mat<d,T>. + /* + * \param[in] tab Array of values. + * + * \pre The array dimension has to be d * d. + */ + template <typename T, unsigned d> + algebra::h_mat<d,T> h_mat(const T (&tab)[(d+1)*(d+1)]); + + + /// Create an mln::algebra::h_mat<d,T>. + /* + * \param[in] tab Array of values. + * + * \pre The array dimension has to be d * d. + */ + template <typename T, unsigned d> + algebra::h_mat<d,T> h_mat(const T (&tab)[d+1][d+1]); + + + /// reate an mln::algebra::mat<n,n,T>. + /* + * \param[in] tab C-array of values. + * + * \pre The array dimension N has to be square (N = n * n). + */ + template <typename T, unsigned N> + algebra::h_mat<mlc_sqrt_int(N), T> h_mat(const T (&tab)[N]); + + + +# ifndef MLN_INCLUDE_ONLY + + template <typename T, unsigned d> + inline + algebra::h_mat<d,T> + h_mat(const T (&tab)[(d+1)*(d+1)]) + { + algebra::h_mat<d,T> tmp; + for (unsigned i = 0; i <= d; ++i) + tmp(i / (d+1), i % (d+1)) = tab[i]; + return tmp; + } + + + template <typename T, unsigned d> + algebra::h_mat<d,T> + h_mat(const T (&tab)[d+1][d+1]) + { + algebra::h_mat<d,T> tmp; + for (unsigned i = 0; i <= d; ++i) + for (unsigned j = 0; j <= d; ++j) + tmp(i, j) = tab[i][j]; + return tmp; + } + + + template <typename T, unsigned N> + inline + algebra::h_mat<mlc_sqrt_int(N), T> + h_mat(const T (&tab)[N]) + { + enum { n = mlc_sqrt_int(N) }; + mlc_bool(N == n * n)::check(); + algebra::h_mat<n,T> tmp; + for (unsigned i = 0; i < N; ++i) + tmp(i / n, i % n) = tab[i]; + return tmp; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::make + +} // end of namespace mln + +#endif // ! MLN_MAKE_H_MAT_HH diff --git a/milena/tests/unit_test/Makefile.am b/milena/tests/unit_test/Makefile.am index 2653f23..a6b6b26 100644 --- a/milena/tests/unit_test/Makefile.am +++ b/milena/tests/unit_test/Makefile.am @@ -145,6 +145,7 @@ mln_make_w_window2d_int \ mln_make_box1d \ mln_make_voronoi \ mln_make_box2d \ +mln_make_h_mat \ mln_make_w_window2d \ mln_make_box3d \ mln_make_relabelfun \ diff --git a/milena/tests/unit_test/mln_make_h_mat.cc b/milena/tests/unit_test/mln_make_h_mat.cc new file mode 100644 index 0000000..b572cb4 --- /dev/null +++ b/milena/tests/unit_test/mln_make_h_mat.cc @@ -0,0 +1,11 @@ +// Unit test for mln/make/h_mat.hh. +// Generated by ./build_unit_test.sh, do not modify. + +// Include the file twice, so we detect missing inclusion guards. +#include <mln/make/h_mat.hh> +#include <mln/make/h_mat.hh> + +int main() +{ + // Nothing. +} -- 1.5.6.5
participants (1)
-
Guillaume Lazzara