1//
2// Copyright (c) 2000-2002
3// Joerg Walter, Mathias Koch
4//
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)
8//
9// The authors gratefully acknowledge the support of
10// GeNeSys mbH & Co. KG in producing this work.
11//
12
13#include "test5.hpp"
14
15// Test matrix expression templates
16template<class M, int N>
17struct test_my_matrix {
18 typedef typename M::value_type value_type;
19
20 template<class MP>
21 void test_with (MP &m1, MP &m2, MP &m3) const {
22 {
23 value_type t;
24
25 // Default Construct
26 default_construct<MP>::test ();
27
28 // Copy and swap
29 initialize_matrix (m1);
30 initialize_matrix (m2);
31 m1 = m2;
32 std::cout << "m1 = m2 = " << m1 << std::endl;
33 m1.assign_temporary (m2);
34 std::cout << "m1.assign_temporary (m2) = " << m1 << std::endl;
35 m1.swap (m2);
36 std::cout << "m1.swap (m2) = " << m1 << " " << m2 << std::endl;
37
38 // Zero assignment
39 m1 = ublas::zero_matrix<> (m1.size1 (), m1.size2 ());
40 std::cout << "m1.zero_matrix = " << m1 << std::endl;
41 m1 = m2;
42
43 // Unary matrix operations resulting in a matrix
44 initialize_matrix (m1);
45 m2 = - m1;
46 std::cout << "- m1 = " << m2 << std::endl;
47 m2 = ublas::conj (m1);
48 std::cout << "conj (m1) = " << m2 << std::endl;
49
50 // Binary matrix operations resulting in a matrix
51 initialize_matrix (m1);
52 initialize_matrix (m2);
53 m3 = m1 + m2;
54 std::cout << "m1 + m2 = " << m3 << std::endl;
55 m3 = m1 - m2;
56 std::cout << "m1 - m2 = " << m3 << std::endl;
57
58 // Scaling a matrix
59 t = N;
60 initialize_matrix (m1);
61 m2 = value_type (1.) * m1;
62 std::cout << "1. * m1 = " << m2 << std::endl;
63 m2 = t * m1;
64 std::cout << "N * m1 = " << m2 << std::endl;
65 initialize_matrix (m1);
66 m2 = m1 * value_type (1.);
67 std::cout << "m1 * 1. = " << m2 << std::endl;
68 m2 = m1 * t;
69 std::cout << "m1 * N = " << m2 << std::endl;
70
71 // Some assignments
72 initialize_matrix (m1);
73 initialize_matrix (m2);
74 m2 += m1;
75 std::cout << "m2 += m1 = " << m2 << std::endl;
76 m2 -= m1;
77 std::cout << "m2 -= m1 = " << m2 << std::endl;
78 m2 = m2 + m1;
79 std::cout << "m2 = m2 + m1 = " << m2 << std::endl;
80 m2 = m2 - m1;
81 std::cout << "m2 = m2 - m1 = " << m2 << std::endl;
82 m1 *= value_type (1.);
83 std::cout << "m1 *= 1. = " << m1 << std::endl;
84 m1 *= t;
85 std::cout << "m1 *= N = " << m1 << std::endl;
86
87 // Transpose
88 initialize_matrix (m1);
89 // Transpose of a triangular isn't triangular of the same kind
90 std::cout << "trans (m1) = " << ublas::trans (m1) << std::endl;
91
92 // Hermitian
93 initialize_matrix (m1);
94 // Hermitian of a triangular isn't hermitian of the same kind
95 std::cout << "herm (m1) = " << ublas::herm (m1) << std::endl;
96
97 // Matrix multiplication
98 initialize_matrix (m1);
99 initialize_matrix (m2);
100 m3 = ublas::prod (m1, m2);
101 std::cout << "prod (m1, m2) = " << m3 << std::endl;
102 }
103 }
104 void operator () () const {
105 {
106 M m1 (N, N), m2 (N, N), m3 (N, N);
107 test_with (m1, m2, m3);
108
109#ifdef USE_RANGE
110 ublas::matrix_range<M> mr1 (m1, ublas::range (0, N), ublas::range (0, N)),
111 mr2 (m2, ublas::range (0, N), ublas::range (0, N)),
112 mr3 (m3, ublas::range (0, N), ublas::range (0, N));
113 test_with (mr1, mr2, mr3);
114#endif
115
116#ifdef USE_SLICE
117 ublas::matrix_slice<M> ms1 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)),
118 ms2 (m2, ublas::slice (0, 1, N), ublas::slice (0, 1, N)),
119 ms3 (m3, ublas::slice (0, 1, N), ublas::slice (0, 1, N));
120 test_with (ms1, ms2, ms3);
121#endif
122 }
123
124#ifdef USE_ADAPTOR
125 {
126 M m1 (N, N), m2 (N, N), m3 (N, N);
127 ublas::triangular_adaptor<M> tam1 (m1), tam2 (m2), tam3 (m3);
128 test_with (tam1, tam2, tam3);
129
130#ifdef USE_RANGE
131 ublas::matrix_range<ublas::triangular_adaptor<M> > mr1 (tam1, ublas::range (0, N), ublas::range (0, N)),
132 mr2 (tam2, ublas::range (0, N), ublas::range (0, N)),
133 mr3 (tam3, ublas::range (0, N), ublas::range (0, N));
134 test_with (mr1, mr2, mr3);
135#endif
136
137#ifdef USE_SLICE
138 ublas::matrix_slice<ublas::triangular_adaptor<M> > ms1 (tam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)),
139 ms2 (tam2, ublas::slice (0, 1, N), ublas::slice (0, 1, N)),
140 ms3 (tam3, ublas::slice (0, 1, N), ublas::slice (0, 1, N));
141 test_with (ms1, ms2, ms3);
142#endif
143 }
144#endif
145 }
146};
147
148// Test matrix
149void test_matrix () {
150 std::cout << "test_matrix" << std::endl;
151
152#ifdef USE_BOUNDED_ARRAY
153#ifdef USE_FLOAT
154 std::cout << "float, bounded_array" << std::endl;
155 test_my_matrix<ublas::triangular_matrix<float, ublas::lower, ublas::row_major, ublas::bounded_array<float, 3 * 3> >, 3 > () ();
156#endif
157
158#ifdef USE_DOUBLE
159 std::cout << "double, bounded_array" << std::endl;
160 test_my_matrix<ublas::triangular_matrix<double, ublas::lower, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3 > () ();
161#endif
162
163#ifdef USE_STD_COMPLEX
164#ifdef USE_FLOAT
165 std::cout << "std::complex<float>, bounded_array" << std::endl;
166 test_my_matrix<ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<float>, 3 * 3> >, 3 > () ();
167#endif
168
169#ifdef USE_DOUBLE
170 std::cout << "std::complex<double>, bounded_array" << std::endl;
171 test_my_matrix<ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3 > () ();
172#endif
173#endif
174#endif
175
176#ifdef USE_UNBOUNDED_ARRAY
177#ifdef USE_FLOAT
178 std::cout << "float, unbounded_array" << std::endl;
179 test_my_matrix<ublas::triangular_matrix<float, ublas::lower, ublas::row_major, ublas::unbounded_array<float> >, 3 > () ();
180#endif
181
182#ifdef USE_DOUBLE
183 std::cout << "double, unbounded_array" << std::endl;
184 test_my_matrix<ublas::triangular_matrix<double, ublas::lower, ublas::row_major, ublas::unbounded_array<double> >, 3 > () ();
185#endif
186
187#ifdef USE_STD_COMPLEX
188#ifdef USE_FLOAT
189 std::cout << "std::complex<float>, unbounded_array" << std::endl;
190 test_my_matrix<ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<float> > >, 3 > () ();
191#endif
192
193#ifdef USE_DOUBLE
194 std::cout << "std::complex<double>, unbounded_array" << std::endl;
195 test_my_matrix<ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3 > () ();
196#endif
197#endif
198#endif
199
200#ifdef USE_STD_VECTOR
201#ifdef USE_FLOAT
202 std::cout << "float, std::vector" << std::endl;
203 test_my_matrix<ublas::triangular_matrix<float, ublas::lower, ublas::row_major, std::vector<float> >, 3 > () ();
204#endif
205
206#ifdef USE_DOUBLE
207 std::cout << "double, std::vector" << std::endl;
208 test_my_matrix<ublas::triangular_matrix<double, ublas::lower, ublas::row_major, std::vector<double> >, 3 > () ();
209#endif
210
211#ifdef USE_STD_COMPLEX
212#ifdef USE_FLOAT
213 std::cout << "std::complex<float>, std::vector" << std::endl;
214 test_my_matrix<ublas::triangular_matrix<std::complex<float>, ublas::lower, ublas::row_major, std::vector<std::complex<float> > >, 3 > () ();
215#endif
216
217#ifdef USE_DOUBLE
218std::cout << "std::complex<double>, std::vector" << std::endl;
219 test_my_matrix<ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, std::vector<std::complex<double> > >, 3 > () ();
220#endif
221#endif
222#endif
223}
224

source code of boost/libs/numeric/ublas/test/test53.cpp