cleanup-2008 2645: Update make mat.

https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Update make mat. * tests/make/mat.cc: New. * tests/make/Makefile.am: Update. * mln/make/mat.hh: Overload. mln/make/mat.hh | 68 +++++++++++++++++++++++++++++++++++++++++-------- tests/make/Makefile.am | 4 ++ tests/make/mat.cc | 42 ++++++++++++------------------ 3 files changed, 79 insertions(+), 35 deletions(-) Index: tests/make/mat.cc --- tests/make/mat.cc (revision 2637) +++ tests/make/mat.cc (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -25,16 +25,12 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/*! \file tests/algebra/mat.cc +/*! \file tests/make/mat.cc * - * \brief Tests on mln::algebra::mat. + * \brief Tests on mln::make::mat. */ - -#include <iostream> -#include <mln/fun/i2v/all_to.hh> #include <mln/algebra/mat.hh> -#include <mln/algebra/h_mat.hh> @@ -42,26 +38,24 @@ { using namespace mln; - algebra::mat<1,3,float> m1(all_to(4.)); - algebra::mat<2,2,float> m2 = algebra::mat<2,2,float>::Id; + { + int vals[] = { 1, 0, + 0, 1 }; + algebra::mat<2,2,int> m = make::mat(vals); + } - algebra::h_mat<1,float> hm1(m2); - algebra::h_mat<2,float> hm2; - algebra::h_mat<3,float> hm3(all_to(1.5)); - - algebra::mat<4,4,float> m4 = hm3; - - std::cout << "m1 = " << m1 << ";" << std::endl; - std::cout << "m2 = " << m2 << ";" << std::endl; - std::cout << "m4 = " << m4 << ";" << std::endl; - std::cout << "hm1 = " << hm1 << ";" << std::endl; - std::cout << "hm2 = " << hm2 << ";" << std::endl; - std::cout << "hm3 = " << hm3 << ";" << std::endl; + { + int vals[] = { 1, 2, 3, + 4, 5, 6 }; + algebra::mat<2,3,int> m = make::mat<2,3>(vals); + std::cout << m << std::endl; + } { - algebra::h_mat<2,float> m, m2; - m = m2; - // FIXME: Test *many* => runs ok... + int vals[][3] = { { 1, 2, 3 }, + { 4, 5, 6 } }; + algebra::mat<2,3,int> m = make::mat(vals); + std::cout << m << std::endl; } } Index: tests/make/Makefile.am --- tests/make/Makefile.am (revision 2644) +++ tests/make/Makefile.am (working copy) @@ -3,8 +3,10 @@ include $(top_srcdir)/milena/tests/tests.mk check_PROGRAMS = \ - dual_neighb + dual_neighb \ + mat dual_neighb_SOURCES = dual_neighb.cc +mat_SOURCES = mat.cc TESTS = $(check_PROGRAMS) Index: mln/make/mat.hh --- mln/make/mat.hh (revision 2644) +++ mln/make/mat.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2006 EPITA Research and Development Laboratory +// Copyright (C) 2006, 2008 EPITA Research and Development Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -34,38 +34,86 @@ */ # include <mln/algebra/mat.hh> +# include <mln/metal/math/sqrt.hh> + namespace mln { namespace make { + /*! \brief Create an mln::algebra::mat<n,m,T>. * - * \param[in] tab Tab of value. + * \param[in] tab Array of values. * - * \pre The dimension table N is such as N = n * m - * with n and m, the dimensions oh the matrix. + * \pre The array dimension has to be n * m. */ - template <unsigned n, unsigned m, unsigned N, typename T> - algebra::mat<n,m,T> mat(const T tab[N]); + template <unsigned n, unsigned m, typename T> + algebra::mat<n,m,T> mat(const T (&tab)[n*m]); + + + /*! \brief Create an mln::algebra::mat<n,m,T>. + * + * \param[in] tab Array of values. + * + * \pre The array dimension has to be n * m. + */ + template <typename T, unsigned n, unsigned m> + algebra::mat<n,m,T> mat(const T (&tab)[n][m]); + + + /*! \brief Create 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::mat<mlc_sqrt_int(N), mlc_sqrt_int(N), T> + mat(const T (&tab)[N]); + template <unsigned n, unsigned m, typename T> algebra::mat<n,m,T> mat(algebra::vec<n,T> v); + + # ifndef MLN_INCLUDE_ONLY - template <unsigned n, unsigned m, unsigned N, typename T> + template <unsigned n, unsigned m, typename T> inline - algebra::mat<n,m,T> mat(const T tab[N]) + algebra::mat<n,m,T> mat(const T (&tab)[n*m]) { - mln_precondition(n * m == N); algebra::mat<n,m,T> tmp; - for (unsigned i = 0; i < N; ++i) + for (unsigned i = 0; i < n*m; ++i) tmp(i / m, i % m) = tab[i]; return tmp; } + template <typename T, unsigned n, unsigned m> + algebra::mat<n,m,T> mat(const T (&tab)[n][m]) + { + algebra::mat<n,m,T> tmp; + for (unsigned i = 0; i < n; ++i) + for (unsigned j = 0; j < m; ++j) + tmp(i, j) = tab[i][j]; + return tmp; + } + + template <typename T, unsigned N> + inline + algebra::mat<mlc_sqrt_int(N), mlc_sqrt_int(N), T> + mat(const T (&tab)[N]) + { + enum { n = mlc_sqrt_int(N) }; + mlc_bool(N == n * n)::check(); + algebra::mat<n,n,T> tmp; + for (unsigned i = 0; i < N; ++i) + tmp(i / n, i % n) = tab[i]; + return tmp; + } + template <unsigned n, typename T> algebra::mat<n,1,T> mat(algebra::vec<n,T> v) {
participants (1)
-
Thierry Geraud