2 // Copyright (c) 2000-2002
3 // Joerg Walter, Mathias Koch
5 // Distributed under the Boost Software License, Version 1.0. (See
6 // accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // The authors gratefully acknowledge the support of
10 // GeNeSys mbH & Co. KG in producing this work.
13 #if defined(__GNUC__) && (__GNUC__ >= 9)
14 #pragma GCC diagnostic ignored "-Wdeprecated-copy"
19 // Test matrix expression templates
20 template <class M, int N>
23 typedef typename M::value_type value_type;
26 void test_with(MP& m1, MP& m2, MP& m3) const
32 initialize_matrix(m1);
33 initialize_matrix(m2);
35 std::cout << "m1 = m2 = " << m1 << std::endl;
36 m1.assign_temporary(m2);
37 std::cout << "m1.assign_temporary (m2) = " << m1 << std::endl;
39 std::cout << "m1.swap (m2) = " << m1 << " " << m2 << std::endl;
42 m1 = ublas::zero_matrix<value_type>(m1.size1(), m1.size2());
43 std::cout << "m1.zero_matrix = " << m1 << std::endl;
46 // Unary matrix operations resulting in a matrix
47 initialize_matrix(m1);
49 std::cout << "- m1 = " << m2 << std::endl;
51 std::cout << "conj (m1) = " << m2 << std::endl;
53 // Binary matrix operations resulting in a matrix
54 initialize_matrix(m1);
55 initialize_matrix(m2);
57 std::cout << "m1 + m2 = " << m3 << std::endl;
59 std::cout << "m1 - m2 = " << m3 << std::endl;
63 initialize_matrix(m1);
64 m2 = value_type(1.) * m1;
65 std::cout << "1. * m1 = " << m2 << std::endl;
67 std::cout << "N * m1 = " << m2 << std::endl;
68 initialize_matrix(m1);
69 m2 = m1 * value_type(1.);
70 std::cout << "m1 * 1. = " << m2 << std::endl;
72 std::cout << "m1 * N = " << m2 << std::endl;
75 initialize_matrix(m1);
76 initialize_matrix(m2);
78 std::cout << "m2 += m1 = " << m2 << std::endl;
80 std::cout << "m2 -= m1 = " << m2 << std::endl;
82 std::cout << "m2 = m2 + m1 = " << m2 << std::endl;
84 std::cout << "m2 = m1 - m1 = " << m2 << std::endl;
86 std::cout << "m1 *= 1. = " << m1 << std::endl;
88 std::cout << "m1 *= N = " << m1 << std::endl;
91 initialize_matrix(m1);
92 m2 = ublas::trans(m1);
93 std::cout << "trans (m1) = " << m2 << std::endl;
96 initialize_matrix(m1);
98 std::cout << "herm (m1) = " << m2 << std::endl;
100 // Matrix multiplication
101 initialize_matrix(m1);
102 initialize_matrix(m2);
103 m3 = ublas::prod(m1, m2);
104 std::cout << "prod (m1, m2) = " << m3 << std::endl;
107 void operator()() const
110 M m1(N, N), m2(N, N), m3(N, N);
111 test_with(m1, m2, m3);
114 ublas::matrix_range<M> mr1(m1, ublas::range(0, N), ublas::range(0, N)),
115 mr2(m2, ublas::range(0, N), ublas::range(0, N)),
116 mr3(m3, ublas::range(0, N), ublas::range(0, N));
117 test_with(mr1, mr2, mr3);
121 ublas::matrix_slice<M> ms1(m1, ublas::slice(0, 1, N), ublas::slice(0, 1, N)),
122 ms2(m2, ublas::slice(0, 1, N), ublas::slice(0, 1, N)),
123 ms3(m3, ublas::slice(0, 1, N), ublas::slice(0, 1, N));
124 test_with(ms1, ms2, ms3);
133 std::cout << "test_matrix" << std::endl;
136 #ifdef USE_BOUNDED_ARRAY
138 std::cout << "boost::numeric::interval<mp_test_type>, bounded_array" << std::endl;
139 test_my_matrix<ublas::matrix<boost::numeric::interval<mp_test_type>, ublas::row_major, ublas::bounded_array<boost::numeric::interval<mp_test_type>, 3 * 3> >, 3>()();
143 std::cout << "boost::numeric::interval<double>, bounded_array" << std::endl;
144 test_my_matrix<ublas::matrix<boost::numeric::interval<double>, ublas::row_major, ublas::bounded_array<boost::numeric::interval<double>, 3 * 3> >, 3>()();
148 #ifdef USE_UNBOUNDED_ARRAY
150 std::cout << "boost::numeric::interval<mp_test_type>, unbounded_array" << std::endl;
151 test_my_matrix<ublas::matrix<boost::numeric::interval<mp_test_type>, ublas::row_major, ublas::unbounded_array<boost::numeric::interval<mp_test_type> > >, 3>()();
155 std::cout << "boost::numeric::interval<double>, unbounded_array" << std::endl;
156 test_my_matrix<ublas::matrix<boost::numeric::interval<double>, ublas::row_major, ublas::unbounded_array<boost::numeric::interval<double> > >, 3>()();
160 #ifdef USE_STD_VECTOR
162 std::cout << "boost::numeric::interval<mp_test_type>, std::vector" << std::endl;
163 test_my_matrix<ublas::matrix<boost::numeric::interval<mp_test_type>, ublas::row_major, std::vector<boost::numeric::interval<mp_test_type> > >, 3>()();
167 std::cout << "boost::numeric::interval<double>, std::vector" << std::endl;
168 test_my_matrix<ublas::matrix<boost::numeric::interval<double>, ublas::row_major, std::vector<boost::numeric::interval<double> > >, 3>()();
173 #ifdef USE_VECTOR_OF_VECTOR
174 #ifdef USE_BOUNDED_ARRAY
176 std::cout << "boost::numeric::interval<mp_test_type>, bounded_array" << std::endl;
177 test_my_matrix<ublas::vector_of_vector<boost::numeric::interval<mp_test_type>, ublas::row_major, ublas::bounded_array<ublas::bounded_array<boost::numeric::interval<mp_test_type>, 3>, 3 + 1> >, 3>()();
181 std::cout << "boost::numeric::interval<double>, bounded_array" << std::endl;
182 test_my_matrix<ublas::vector_of_vector<boost::numeric::interval<double>, ublas::row_major, ublas::bounded_array<ublas::bounded_array<boost::numeric::interval<double>, 3>, 3 + 1> >, 3>()();
186 #ifdef USE_UNBOUNDED_ARRAY
188 std::cout << "boost::numeric::interval<mp_test_type>, unbounded_array" << std::endl;
189 test_my_matrix<ublas::vector_of_vector<boost::numeric::interval<mp_test_type>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<boost::numeric::interval<mp_test_type> > > >, 3>()();
193 std::cout << "boost::numeric::interval<double>, unbounded_array" << std::endl;
194 test_my_matrix<ublas::vector_of_vector<boost::numeric::interval<double>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<boost::numeric::interval<double> > > >, 3>()();
198 #ifdef USE_STD_VECTOR
200 std::cout << "boost::numeric::interval<mp_test_type>, std::vector" << std::endl;
201 test_my_matrix<ublas::vector_of_vector<boost::numeric::interval<mp_test_type>, ublas::row_major, std::vector<std::vector<boost::numeric::interval<mp_test_type> > > >, 3>()();
205 std::cout << "boost::numeric::interval<double>, std::vector" << std::endl;
206 test_my_matrix<ublas::vector_of_vector<boost::numeric::interval<double>, ublas::row_major, std::vector<std::vector<boost::numeric::interval<double> > > >, 3>()();