URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-11 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Add tests for mat and vec and h_mat and h_vec.
* tests/fun_x2x_translation.cc: Fix.
* mln/make/vec.hh,
* mln/metal/mat.hh,
* mln/metal/vec.hh: Update.
* tests/mat.cc: New.
* tests/vec.cc: New.
---
mln/make/vec.hh | 20 -------------
mln/metal/mat.hh | 16 ++++++++++
mln/metal/vec.hh | 1
tests/fun_x2x_translation.cc | 2 -
tests/mat.cc | 60 ++++++++++++++++++++++++++++++++++++++++
tests/vec.cc | 64 +++++++++++++++++++++++++++++++++++++++++++
6 files changed, 142 insertions(+), 21 deletions(-)
Index: trunk/milena/tests/fun_x2x_translation.cc
===================================================================
--- trunk/milena/tests/fun_x2x_translation.cc (revision 1304)
+++ trunk/milena/tests/fun_x2x_translation.cc (revision 1305)
@@ -47,7 +47,7 @@
c = 2.9;
metal::vec<3,float> vec1 = make::vec(a, b, c);
- fun::x2x::translation<3,float> tr1(make::vec<3, float>(all(1.6)));
+ fun::x2x::translation<3,float> tr1(all(1.6));
std::cout << vec1 << std::endl;
std::cout << tr1(vec1) << std::endl;
Index: trunk/milena/tests/mat.cc
===================================================================
--- trunk/milena/tests/mat.cc (revision 0)
+++ trunk/milena/tests/mat.cc (revision 1305)
@@ -0,0 +1,60 @@
+// Copyright (C) 2007 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
+// 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.
+
+/*! \file tests/image2d.cc
+ *
+ * \brief Tests on mln::image2d.
+ */
+
+
+#include <iostream>
+#include <mln/fun/i2v/all.hh>
+#include <mln/metal/mat.hh>
+#include <mln/core/h_mat.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ metal::mat<1,3,float> m1(all(4.));
+ metal::mat<2,2,float> m2 = metal::mat<2,2,float>::Id;
+
+ h_mat<1,float> hm1(m2);
+ h_mat<2,float> hm2;
+ h_mat<3,float> hm3(all(1.5));
+
+ metal::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;
+}
Index: trunk/milena/tests/vec.cc
===================================================================
--- trunk/milena/tests/vec.cc (revision 0)
+++ trunk/milena/tests/vec.cc (revision 1305)
@@ -0,0 +1,64 @@
+// Copyright (C) 2007 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
+// 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.
+
+/*! \file tests/image2d.cc
+ *
+ * \brief Tests on mln::image2d.
+ */
+
+
+#include <iostream>
+#include <mln/fun/i2v/all.hh>
+#include <mln/metal/vec.hh>
+#include <mln/core/h_vec.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ metal::vec<1,float> v1(all(4.));
+ metal::vec<2,float> v2 = make::vec(6., 2.8);
+
+ h_vec<1,float> hv1;
+ h_vec<2,float> hv2(v2);
+ h_vec<3,float> hv3(all(1.5));
+
+ hv3 += make::vec(0., 0., 0., 0.5);
+
+ metal::vec<3,float> v3 = hv3;
+ metal::vec<4,float> v4 = hv3;
+
+ std::cout << "v1 = " << v1 << ";" <<
std::endl;
+ std::cout << "v2 = " << v2 << ";" <<
std::endl;
+ std::cout << "v3 = " << v3 << ";" <<
std::endl;
+ std::cout << "v4 = " << v4 << ";" <<
std::endl;
+ std::cout << "hv1 = " << hv1 << ";" <<
std::endl;
+ std::cout << "hv2 = " << hv2 << ";" <<
std::endl;
+ std::cout << "hv3 = " << hv3 << ";" <<
std::endl;
+}
Index: trunk/milena/mln/metal/mat.hh
===================================================================
--- trunk/milena/mln/metal/mat.hh (revision 1304)
+++ trunk/milena/mln/metal/mat.hh (revision 1305)
@@ -31,6 +31,7 @@
# include <iostream>
# include <mln/core/concept/object.hh>
+# include <mln/core/concept/function.hh>
# include <mln/core/contract.hh>
# include <mln/trait/all.hh>
# include <mln/value/props.hh>
@@ -66,6 +67,10 @@
template <typename U>
mat(const mat<n,m,U>& rhs);
+ /// Constructor; coordinates are set by function \p f.
+ template <typename F>
+ mat(const Function_i2v<F>& f);
+
template <typename U>
mat& operator=(const mat<n,m,U>& rhs);
@@ -281,6 +286,17 @@
}
template <unsigned n, unsigned m, typename T>
+ template <typename F>
+ mat<n,m,T>::mat(const Function_i2v<F>& f_)
+ {
+ mlc_converts_to(mln_result(F), T)::check();
+ const F& f = exact(f_);
+ for (unsigned i = 0; i < n; ++i)
+ for (unsigned j = 0; j < m; ++j)
+ data_[i][j] = f(i * n + j);
+ }
+
+ template <unsigned n, unsigned m, typename T>
template <typename U>
mat<n,m,T>&
mat<n,m,T>::operator=(const mat<n,m,U>& rhs)
Index: trunk/milena/mln/metal/vec.hh
===================================================================
--- trunk/milena/mln/metal/vec.hh (revision 1304)
+++ trunk/milena/mln/metal/vec.hh (revision 1305)
@@ -414,6 +414,7 @@
template <typename F>
vec<n, T>::vec(const Function_i2v<F>& f_)
{
+ mlc_converts_to(mln_result(F), T)::check();
const F& f = exact(f_);
for (unsigned i = 0; i < n; ++i)
data_[i] = f(i);
Index: trunk/milena/mln/make/vec.hh
===================================================================
--- trunk/milena/mln/make/vec.hh (revision 1304)
+++ trunk/milena/mln/make/vec.hh (revision 1305)
@@ -45,15 +45,6 @@
/*! \brief Create an mln::metal::vec<n,T>.
*
- * \param[in] f Function.
- *
- * \return A nD vector filled with the function \p f .
- */
- template <unsigned n, typename T, typename F>
- metal::vec<n, T> vec(const Function_i2v<F>& f_);
-
- /*! \brief Create an mln::metal::vec<n,T>.
- *
* \param[in] v_0 First coordinate.
*
* \return A 1D vector.
@@ -97,17 +88,6 @@
# ifndef MLN_INCLUDE_ONLY
- template <unsigned n, typename T, typename F>
- metal::vec<n, T> vec(const Function_i2v<F>& f_)
- {
- mlc_converts_to(mln_result(F), T)::check();
- F f = exact(f_);
- metal::vec<n, T> tmp;
- for (unsigned i; i < n; ++i)
- tmp[i] = f(i);
- return tmp;
- }
-
template <typename T>
metal::vec<1, T> vec(const T& v_0)
{