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 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
50 // Project range and slice
51 initialize_matrix(m1
);
52 initialize_matrix(m2
);
53 project(m1
, ublas::range(0, 1), ublas::range(0, 1)) = project(m2
, ublas::range(0, 1), ublas::range(0, 1));
54 project(m1
, ublas::range(0, 1), ublas::range(0, 1)) = project(m2
, ublas::slice(0, 1, 1), ublas::slice(0, 1, 1));
55 project(m1
, ublas::slice(2, -1, 2), ublas::slice(2, -1, 2)) = project(m2
, ublas::slice(0, 1, 2), ublas::slice(0, 1, 2));
56 project(m1
, ublas::slice(2, -1, 2), ublas::slice(2, -1, 2)) = project(m2
, ublas::range(0, 2), ublas::range(0, 2));
57 std::cout
<< "m1 = range/slice " << m1
<< std::endl
;
60 // Unary matrix operations resulting in a matrix
61 initialize_matrix(m1
);
63 std::cout
<< "- m1 = " << m2
<< std::endl
;
65 std::cout
<< "conj (m1) = " << m2
<< std::endl
;
67 // Binary matrix operations resulting in a matrix
68 initialize_matrix(m1
);
69 initialize_matrix(m2
);
70 initialize_matrix(m3
);
72 std::cout
<< "m1 + m2 = " << m3
<< std::endl
;
74 std::cout
<< "m1 - m2 = " << m3
<< std::endl
;
78 initialize_matrix(m1
);
79 m2
= value_type(1.) * m1
;
80 std::cout
<< "1. * m1 = " << m2
<< std::endl
;
82 std::cout
<< "N * m1 = " << m2
<< std::endl
;
83 initialize_matrix(m1
);
84 m2
= m1
* value_type(1.);
85 std::cout
<< "m1 * 1. = " << m2
<< std::endl
;
87 std::cout
<< "m1 * N = " << m2
<< std::endl
;
90 initialize_matrix(m1
);
91 initialize_matrix(m2
);
93 std::cout
<< "m2 += m1 = " << m2
<< std::endl
;
95 std::cout
<< "m2 -= m1 = " << m2
<< std::endl
;
97 std::cout
<< "m2 = m2 + m1 = " << m2
<< std::endl
;
99 std::cout
<< "m2 = m2 - m1 = " << m2
<< std::endl
;
100 m1
*= value_type(1.);
101 std::cout
<< "m1 *= 1. = " << m1
<< std::endl
;
103 std::cout
<< "m1 *= N = " << m1
<< std::endl
;
106 initialize_matrix(m1
);
107 m2
= ublas::trans(m1
);
108 std::cout
<< "trans (m1) = " << m2
<< std::endl
;
111 initialize_matrix(m1
);
112 m2
= ublas::herm(m1
);
113 std::cout
<< "herm (m1) = " << m2
<< std::endl
;
115 // Matrix multiplication
116 initialize_matrix(m1
);
117 initialize_matrix(m2
);
118 m3
= ublas::prod(m1
, m2
);
119 std::cout
<< "prod (m1, m2) = " << m3
<< std::endl
;
122 void operator()() const
125 M
m1(N
, N
, N
* N
), m2(N
, N
, N
* N
), m3(N
, N
, N
* N
);
126 test_with(m1
, m2
, m3
);
129 ublas::matrix_range
<M
> mr1(m1
, ublas::range(0, N
), ublas::range(0, N
)),
130 mr2(m2
, ublas::range(0, N
), ublas::range(0, N
)),
131 mr3(m3
, ublas::range(0, N
), ublas::range(0, N
));
132 test_with(mr1
, mr2
, mr3
);
136 ublas::matrix_slice
<M
> ms1(m1
, ublas::slice(0, 1, N
), ublas::slice(0, 1, N
)),
137 ms2(m2
, ublas::slice(0, 1, N
), ublas::slice(0, 1, N
)),
138 ms3(m3
, ublas::slice(0, 1, N
), ublas::slice(0, 1, N
));
139 test_with(ms1
, ms2
, ms3
);
148 std::cout
<< "test_matrix" << std::endl
;
150 #ifdef USE_SPARSE_MATRIX
153 std::cout
<< "mp_test_type, mapped_matrix map_array" << std::endl
;
154 test_my_matrix
<ublas::mapped_matrix
<mp_test_type
, ublas::row_major
, ublas::map_array
<std::size_t, mp_test_type
> >, 3>()();
158 std::cout
<< "double, mapped_matrix map_array" << std::endl
;
159 test_my_matrix
<ublas::mapped_matrix
<double, ublas::row_major
, ublas::map_array
<std::size_t, double> >, 3>()();
162 #ifdef USE_STD_COMPLEX
164 std::cout
<< "std::complex<mp_test_type>, mapped_matrix map_array" << std::endl
;
165 test_my_matrix
<ublas::mapped_matrix
<std::complex<mp_test_type
>, ublas::row_major
, ublas::map_array
<std::size_t, std::complex<mp_test_type
> > >, 3>()();
169 std::cout
<< "std::complex<double>, mapped_matrix map_array" << std::endl
;
170 test_my_matrix
<ublas::mapped_matrix
<std::complex<double>, ublas::row_major
, ublas::map_array
<std::size_t, std::complex<double> > >, 3>()();
177 std::cout
<< "mp_test_type, mapped_matrix std::map" << std::endl
;
178 test_my_matrix
<ublas::mapped_matrix
<mp_test_type
, ublas::row_major
, std::map
<std::size_t, mp_test_type
> >, 3>()();
182 std::cout
<< "double, mapped_matrix std::map" << std::endl
;
183 test_my_matrix
<ublas::mapped_matrix
<double, ublas::row_major
, std::map
<std::size_t, double> >, 3>()();
186 #ifdef USE_STD_COMPLEX
188 std::cout
<< "std::complex<mp_test_type>, mapped_matrix std::map" << std::endl
;
189 test_my_matrix
<ublas::mapped_matrix
<std::complex<mp_test_type
>, ublas::row_major
, std::map
<std::size_t, std::complex<mp_test_type
> > >, 3>()();
193 std::cout
<< "std::complex<double>, mapped_matrix std::map" << std::endl
;
194 test_my_matrix
<ublas::mapped_matrix
<std::complex<double>, ublas::row_major
, std::map
<std::size_t, std::complex<double> > >, 3>()();
200 #ifdef USE_SPARSE_VECTOR_OF_SPARSE_VECTOR
203 std::cout
<< "mp_test_type, mapped_vector_of_mapped_vector map_array" << std::endl
;
204 test_my_matrix
<ublas::mapped_vector_of_mapped_vector
<mp_test_type
, ublas::row_major
, ublas::map_array
<std::size_t, ublas::map_array
<std::size_t, mp_test_type
> > >, 3>()();
208 std::cout
<< "double, mapped_vector_of_mapped_vector map_array" << std::endl
;
209 test_my_matrix
<ublas::mapped_vector_of_mapped_vector
<double, ublas::row_major
, ublas::map_array
<std::size_t, ublas::map_array
<std::size_t, double> > >, 3>()();
212 #ifdef USE_STD_COMPLEX
214 std::cout
<< "std::complex<mp_test_type>, mapped_vector_of_mapped_vector map_array" << std::endl
;
215 test_my_matrix
<ublas::mapped_vector_of_mapped_vector
<std::complex<mp_test_type
>, ublas::row_major
, ublas::map_array
<std::size_t, ublas::map_array
<std::size_t, std::complex<mp_test_type
> > > >, 3>()();
219 std::cout
<< "std::complex<double>, mapped_vector_of_mapped_vectormap_array" << std::endl
;
220 test_my_matrix
<ublas::mapped_vector_of_mapped_vector
<std::complex<double>, ublas::row_major
, ublas::map_array
<std::size_t, ublas::map_array
<std::size_t, std::complex<double> > > >, 3>()();
227 std::cout
<< "mp_test_type, mapped_vector_of_mapped_vector std::map" << std::endl
;
228 test_my_matrix
<ublas::mapped_vector_of_mapped_vector
<mp_test_type
, ublas::row_major
, std::map
<std::size_t, std::map
<std::size_t, mp_test_type
> > >, 3>()();
232 std::cout
<< "double, mapped_vector_of_mapped_vector std::map" << std::endl
;
233 test_my_matrix
<ublas::mapped_vector_of_mapped_vector
<double, ublas::row_major
, std::map
<std::size_t, std::map
<std::size_t, double> > >, 3>()();
236 #ifdef USE_STD_COMPLEX
238 std::cout
<< "std::complex<mp_test_type>, mapped_vector_of_mapped_vector std::map" << std::endl
;
239 test_my_matrix
<ublas::mapped_vector_of_mapped_vector
<std::complex<mp_test_type
>, ublas::row_major
, std::map
<std::size_t, std::map
<std::size_t, std::complex<mp_test_type
> > > >, 3>()();
243 std::cout
<< "std::complex<double>, mapped_vector_of_mapped_vector std::map" << std::endl
;
244 test_my_matrix
<ublas::mapped_vector_of_mapped_vector
<std::complex<double>, ublas::row_major
, std::map
<std::size_t, std::map
<std::size_t, std::complex<double> > > >, 3>()();
250 #ifdef USE_GENERALIZED_VECTOR_OF_VECTOR
253 std::cout
<< "mp_test_type,generalized_vector_of_vector map_array" << std::endl
;
254 test_my_matrix
<ublas::generalized_vector_of_vector
<mp_test_type
, ublas::row_major
, ublas::vector
<ublas::mapped_vector
<mp_test_type
, ublas::map_array
<std::size_t, mp_test_type
> > > >, 3>()();
255 test_my_matrix
<ublas::generalized_vector_of_vector
<mp_test_type
, ublas::row_major
, ublas::mapped_vector
<ublas::mapped_vector
<mp_test_type
, ublas::map_array
<std::size_t, mp_test_type
> >, ublas::map_array
<std::size_t, ublas::mapped_vector
<mp_test_type
, ublas::map_array
<std::size_t, mp_test_type
> > > > >, 3>()();
259 std::cout
<< "double, generalized_vector_of_vector map_array" << std::endl
;
260 test_my_matrix
<ublas::generalized_vector_of_vector
<double, ublas::row_major
, ublas::vector
<ublas::mapped_vector
<double, ublas::map_array
<std::size_t, double> > > >, 3>()();
261 test_my_matrix
<ublas::generalized_vector_of_vector
<double, ublas::row_major
, ublas::mapped_vector
<ublas::mapped_vector
<double, ublas::map_array
<std::size_t, double> >, ublas::map_array
<std::size_t, ublas::mapped_vector
<double, ublas::map_array
<std::size_t, double> > > > >, 3>()();
264 #ifdef USE_STD_COMPLEX
266 std::cout
<< "std::complex<mp_test_type>, generalized_vector_of_vector map_array" << std::endl
;
267 test_my_matrix
<ublas::generalized_vector_of_vector
<std::complex<mp_test_type
>, ublas::row_major
, ublas::vector
<ublas::mapped_vector
<std::complex<mp_test_type
>, ublas::map_array
<std::size_t, std::complex<mp_test_type
> > > > >, 3>()();
268 test_my_matrix
<ublas::generalized_vector_of_vector
<std::complex<mp_test_type
>, ublas::row_major
, ublas::mapped_vector
<ublas::mapped_vector
<std::complex<mp_test_type
>, ublas::map_array
<std::size_t, std::complex<mp_test_type
> > >, ublas::map_array
<std::size_t, ublas::mapped_vector
<std::complex<mp_test_type
>, ublas::map_array
<std::size_t, std::complex<mp_test_type
> > > > > >, 3>()();
272 std::cout
<< "std::complex<double>, generalized_vector_of_vector map_array" << std::endl
;
273 test_my_matrix
<ublas::generalized_vector_of_vector
<std::complex<double>, ublas::row_major
, ublas::vector
<ublas::mapped_vector
<std::complex<double>, ublas::map_array
<std::size_t, std::complex<double> > > > >, 3>()();
274 test_my_matrix
<ublas::generalized_vector_of_vector
<std::complex<double>, ublas::row_major
, ublas::mapped_vector
<ublas::mapped_vector
<std::complex<double>, ublas::map_array
<std::size_t, std::complex<double> > >, ublas::map_array
<std::size_t, ublas::mapped_vector
<std::complex<double>, ublas::map_array
<std::size_t, std::complex<double> > > > > >, 3>()();
281 std::cout
<< "mp_test_type, generalized_vector_of_vector std::map" << std::endl
;
282 test_my_matrix
<ublas::generalized_vector_of_vector
<mp_test_type
, ublas::row_major
, ublas::vector
<ublas::mapped_vector
<mp_test_type
, std::map
<std::size_t, mp_test_type
> > > >, 3>()();
283 test_my_matrix
<ublas::generalized_vector_of_vector
<mp_test_type
, ublas::row_major
, ublas::mapped_vector
<ublas::mapped_vector
<mp_test_type
, std::map
<std::size_t, mp_test_type
> >, std::map
<std::size_t, ublas::mapped_vector
<mp_test_type
, std::map
<std::size_t, mp_test_type
> > > > >, 3>()();
287 std::cout
<< "double, generalized_vector_of_vector std::map" << std::endl
;
288 test_my_matrix
<ublas::generalized_vector_of_vector
<double, ublas::row_major
, ublas::vector
<ublas::mapped_vector
<double, std::map
<std::size_t, double> > > >, 3>()();
289 test_my_matrix
<ublas::generalized_vector_of_vector
<double, ublas::row_major
, ublas::mapped_vector
<ublas::mapped_vector
<double, std::map
<std::size_t, double> >, std::map
<std::size_t, ublas::mapped_vector
<double, std::map
<std::size_t, double> > > > >, 3>()();
292 #ifdef USE_STD_COMPLEX
294 std::cout
<< "std::complex<mp_test_type>, generalized_vector_of_vector std::map" << std::endl
;
295 test_my_matrix
<ublas::generalized_vector_of_vector
<std::complex<mp_test_type
>, ublas::row_major
, ublas::vector
<ublas::mapped_vector
<std::complex<mp_test_type
>, std::map
<std::size_t, std::complex<mp_test_type
> > > > >, 3>()();
296 test_my_matrix
<ublas::generalized_vector_of_vector
<std::complex<mp_test_type
>, ublas::row_major
, ublas::mapped_vector
<ublas::mapped_vector
<std::complex<mp_test_type
>, std::map
<std::size_t, std::complex<mp_test_type
> > >, std::map
<std::size_t, ublas::mapped_vector
<std::complex<mp_test_type
>, std::map
<std::size_t, std::complex<mp_test_type
> > > > > >, 3>()();
300 std::cout
<< "std::complex<double>, generalized_vector_of_vector std::map" << std::endl
;
301 test_my_matrix
<ublas::generalized_vector_of_vector
<std::complex<double>, ublas::row_major
, ublas::vector
<ublas::mapped_vector
<std::complex<double>, std::map
<std::size_t, std::complex<double> > > > >, 3>()();
302 test_my_matrix
<ublas::generalized_vector_of_vector
<std::complex<double>, ublas::row_major
, ublas::mapped_vector
<ublas::mapped_vector
<std::complex<double>, std::map
<std::size_t, std::complex<double> > >, std::map
<std::size_t, ublas::mapped_vector
<std::complex<double>, std::map
<std::size_t, std::complex<double> > > > > >, 3>()();
308 #ifdef USE_COMPRESSED_MATRIX
310 std::cout
<< "mp_test_type compressed_matrix" << std::endl
;
311 test_my_matrix
<ublas::compressed_matrix
<mp_test_type
>, 3>()();
315 std::cout
<< "double compressed_matrix" << std::endl
;
316 test_my_matrix
<ublas::compressed_matrix
<double>, 3>()();
319 #ifdef USE_STD_COMPLEX
321 std::cout
<< "std::complex<mp_test_type> compressed_matrix" << std::endl
;
322 test_my_matrix
<ublas::compressed_matrix
<std::complex<mp_test_type
> >, 3>()();
326 std::cout
<< "std::complex<double> compressed_matrix" << std::endl
;
327 test_my_matrix
<ublas::compressed_matrix
<std::complex<double> >, 3>()();
332 #ifdef USE_COORDINATE_MATRIX
334 std::cout
<< "mp_test_type coordinate_matrix" << std::endl
;
335 test_my_matrix
<ublas::coordinate_matrix
<mp_test_type
>, 3>()();
339 std::cout
<< "double coordinate_matrix" << std::endl
;
340 test_my_matrix
<ublas::coordinate_matrix
<double>, 3>()();
343 #ifdef USE_STD_COMPLEX
345 std::cout
<< "std::complex<mp_test_type> coordinate_matrix" << std::endl
;
346 test_my_matrix
<ublas::coordinate_matrix
<std::complex<mp_test_type
> >, 3>()();
350 std::cout
<< "std::complex<double> coordinate_matrix" << std::endl
;
351 test_my_matrix
<ublas::coordinate_matrix
<std::complex<double> >, 3>()();