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 default_construct<MP>::test();
35 initialize_matrix(m1);
36 initialize_matrix(m2);
38 std::cout << "m1 = m2 = " << m1 << std::endl;
39 m1.assign_temporary(m2);
40 std::cout << "m1.assign_temporary (m2) = " << m1 << std::endl;
42 std::cout << "m1.swap (m2) = " << m1 << " " << m2 << std::endl;
45 m1 = ublas::zero_matrix<>(m1.size1(), m1.size2());
46 std::cout << "m1.zero_matrix = " << m1 << std::endl;
49 // Unary matrix operations resulting in a matrix
50 initialize_matrix(m1);
52 std::cout << "- m1 = " << m2 << std::endl;
54 std::cout << "conj (m1) = " << m2 << std::endl;
56 // Binary matrix operations resulting in a matrix
57 initialize_matrix(m1);
58 initialize_matrix(m2);
60 std::cout << "m1 + m2 = " << m3 << std::endl;
62 std::cout << "m1 - m2 = " << m3 << std::endl;
66 initialize_matrix(m1);
67 m2 = value_type(1.) * m1;
68 std::cout << "1. * m1 = " << m2 << std::endl;
70 std::cout << "N * m1 = " << m2 << std::endl;
71 initialize_matrix(m1);
72 m2 = m1 * value_type(1.);
73 std::cout << "m1 * 1. = " << m2 << std::endl;
75 std::cout << "m1 * N = " << m2 << std::endl;
78 initialize_matrix(m1);
79 initialize_matrix(m2);
81 std::cout << "m2 += m1 = " << m2 << std::endl;
83 std::cout << "m2 -= m1 = " << m2 << std::endl;
85 std::cout << "m2 = m2 + m1 = " << m2 << std::endl;
87 std::cout << "m2 = m1 - m1 = " << m2 << std::endl;
89 std::cout << "m1 *= 1. = " << m1 << std::endl;
91 std::cout << "m1 *= N = " << m1 << std::endl;
94 initialize_matrix(m1);
95 m2 = ublas::trans(m1);
96 std::cout << "trans (m1) = " << m2 << std::endl;
99 initialize_matrix(m1);
100 m2 = ublas::herm(m1);
101 std::cout << "herm (m1) = " << m2 << std::endl;
103 // Matrix multiplication
104 initialize_matrix(m1);
105 initialize_matrix(m2);
106 m3 = ublas::prod(m1, m2);
107 std::cout << "prod (m1, m2) = " << m3 << std::endl;
110 void operator()() const
113 M m1(N, N), m2(N, N), m3(N, N);
114 test_with(m1, m2, m3);
117 ublas::matrix_range<M> mr1(m1, ublas::range(0, N), ublas::range(0, N)),
118 mr2(m2, ublas::range(0, N), ublas::range(0, N)),
119 mr3(m3, ublas::range(0, N), ublas::range(0, N));
120 test_with(mr1, mr2, mr3);
124 ublas::matrix_slice<M> ms1(m1, ublas::slice(0, 1, N), ublas::slice(0, 1, N)),
125 ms2(m2, ublas::slice(0, 1, N), ublas::slice(0, 1, N)),
126 ms3(m3, ublas::slice(0, 1, N), ublas::slice(0, 1, N));
127 test_with(ms1, ms2, ms3);
133 M m1(N, N), m2(N, N), m3(N, N);
134 ublas::symmetric_adaptor<M> sam1(m1), sam2(m2), sam3(m3);
135 test_with(sam1, sam2, sam3);
138 ublas::matrix_range<ublas::symmetric_adaptor<M> > mr1(sam1, ublas::range(0, N), ublas::range(0, N)),
139 mr2(sam2, ublas::range(0, N), ublas::range(0, N)),
140 mr3(sam3, ublas::range(0, N), ublas::range(0, N));
141 test_with(mr1, mr2, mr3);
145 ublas::matrix_slice<ublas::symmetric_adaptor<M> > ms1(sam1, ublas::slice(0, 1, N), ublas::slice(0, 1, N)),
146 ms2(sam2, ublas::slice(0, 1, N), ublas::slice(0, 1, N)),
147 ms3(sam3, ublas::slice(0, 1, N), ublas::slice(0, 1, N));
148 test_with(ms1, ms2, ms3);
158 std::cout << "test_matrix" << std::endl;
160 #ifdef USE_BOUNDED_ARRAY
162 std::cout << "mp_test_type, bounded_array" << std::endl;
163 test_my_matrix<ublas::symmetric_matrix<mp_test_type, ublas::lower, ublas::row_major, ublas::bounded_array<mp_test_type, 3 * 3> >, 3>()();
167 std::cout << "double, bounded_array" << std::endl;
168 test_my_matrix<ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3>()();
171 #ifdef USE_STD_COMPLEX
173 std::cout << "std::complex<mp_test_type>, bounded_array" << std::endl;
174 test_my_matrix<ublas::symmetric_matrix<std::complex<mp_test_type>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<mp_test_type>, 3 * 3> >, 3>()();
178 std::cout << "std::complex<double>, bounded_array" << std::endl;
179 test_my_matrix<ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3>()();
184 #ifdef USE_UNBOUNDED_ARRAY
186 std::cout << "mp_test_type, unbounded_array" << std::endl;
187 test_my_matrix<ublas::symmetric_matrix<mp_test_type, ublas::lower, ublas::row_major, ublas::unbounded_array<mp_test_type> >, 3>()();
191 std::cout << "double, unbounded_array" << std::endl;
192 test_my_matrix<ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, ublas::unbounded_array<double> >, 3>()();
195 #ifdef USE_STD_COMPLEX
197 std::cout << "std::complex<mp_test_type>, unbounded_array" << std::endl;
198 test_my_matrix<ublas::symmetric_matrix<std::complex<mp_test_type>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<mp_test_type> > >, 3>()();
202 std::cout << "std::complex<double>, unbounded_array" << std::endl;
203 test_my_matrix<ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3>()();
208 #ifdef USE_STD_VECTOR
210 std::cout << "mp_test_type, std::vector" << std::endl;
211 test_my_matrix<ublas::symmetric_matrix<mp_test_type, ublas::lower, ublas::row_major, std::vector<mp_test_type> >, 3>()();
215 std::cout << "double, std::vector" << std::endl;
216 test_my_matrix<ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, std::vector<double> >, 3>()();
219 #ifdef USE_STD_COMPLEX
221 std::cout << "std::complex<mp_test_type>, std::vector" << std::endl;
222 test_my_matrix<ublas::symmetric_matrix<std::complex<mp_test_type>, ublas::lower, ublas::row_major, std::vector<std::complex<mp_test_type> > >, 3>()();
226 std::cout << "std::complex<double>, std::vector" << std::endl;
227 test_my_matrix<ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, std::vector<std::complex<double> > >, 3>()();