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 "test7.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 // Copy and swap
26 initialize_matrix (m1);
27 initialize_matrix (m2);
28 m1 = m2;
29 std::cout << "m1 = m2 = " << m1 << std::endl;
30 m1.assign_temporary (m2);
31 std::cout << "m1.assign_temporary (m2) = " << m1 << std::endl;
32 m1.swap (m2);
33 std::cout << "m1.swap (m2) = " << m1 << " " << m2 << std::endl;
34
35 // Zero assignment
36 m1 = ublas::zero_matrix<value_type> (m1.size1 (), m1.size2 ());
37 std::cout << "m1.zero_matrix = " << m1 << std::endl;
38 m1 = m2;
39
40 // Unary matrix operations resulting in a matrix
41 initialize_matrix (m1);
42 m2 = - m1;
43 std::cout << "- m1 = " << m2 << std::endl;
44 m2 = ublas::conj (m1);
45 std::cout << "conj (m1) = " << m2 << std::endl;
46
47 // Binary matrix operations resulting in a matrix
48 initialize_matrix (m1);
49 initialize_matrix (m2);
50 m3 = m1 + m2;
51 std::cout << "m1 + m2 = " << m3 << std::endl;
52 m3 = m1 - m2;
53 std::cout << "m1 - m2 = " << m3 << std::endl;
54
55 // Scaling a matrix
56 t = N;
57 initialize_matrix (m1);
58 m2 = value_type (1.) * m1;
59 std::cout << "1. * m1 = " << m2 << std::endl;
60 m2 = t * m1;
61 std::cout << "N * m1 = " << m2 << std::endl;
62 initialize_matrix (m1);
63 m2 = m1 * value_type (1.);
64 std::cout << "m1 * 1. = " << m2 << std::endl;
65 m2 = m1 * t;
66 std::cout << "m1 * N = " << m2 << std::endl;
67
68 // Some assignments
69 initialize_matrix (m1);
70 initialize_matrix (m2);
71 m2 += m1;
72 std::cout << "m2 += m1 = " << m2 << std::endl;
73 m2 -= m1;
74 std::cout << "m2 -= m1 = " << m2 << std::endl;
75 m2 = m2 + m1;
76 std::cout << "m2 = m2 + m1 = " << m2 << std::endl;
77 m2 = m2 - m1;
78 std::cout << "m2 = m1 - m1 = " << m2 << std::endl;
79 m1 *= value_type (1.);
80 std::cout << "m1 *= 1. = " << m1 << std::endl;
81 m1 *= t;
82 std::cout << "m1 *= N = " << m1 << std::endl;
83
84 // Transpose
85 initialize_matrix (m1);
86 m2 = ublas::trans (m1);
87 std::cout << "trans (m1) = " << m2 << std::endl;
88
89 // Hermitean
90 initialize_matrix (m1);
91 m2 = ublas::herm (m1);
92 std::cout << "herm (m1) = " << m2 << std::endl;
93
94 // Matrix multiplication
95 initialize_matrix (m1);
96 initialize_matrix (m2);
97 m3 = ublas::prod (m1, m2);
98 std::cout << "prod (m1, m2) = " << m3 << std::endl;
99 }
100 }
101 void operator () () const {
102 {
103 M m1 (N, N), m2 (N, N), m3 (N, N);
104 test_with (m1, m2, m3);
105
106#ifdef USE_RANGE
107 ublas::matrix_range<M> mr1 (m1, ublas::range (0, N), ublas::range (0, N)),
108 mr2 (m2, ublas::range (0, N), ublas::range (0, N)),
109 mr3 (m3, ublas::range (0, N), ublas::range (0, N));
110 test_with (mr1, mr2, mr3);
111#endif
112
113#ifdef USE_SLICE
114 ublas::matrix_slice<M> ms1 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)),
115 ms2 (m2, ublas::slice (0, 1, N), ublas::slice (0, 1, N)),
116 ms3 (m3, ublas::slice (0, 1, N), ublas::slice (0, 1, N));
117 test_with (ms1, ms2, ms3);
118#endif
119 }
120 }
121};
122
123// Test matrix
124void test_matrix () {
125 std::cout << "test_matrix" << std::endl;
126
127#ifdef USE_MATRIX
128#ifdef USE_BOUNDED_ARRAY
129#ifdef USE_FLOAT
130 std::cout << "boost::numeric::interval<float>, bounded_array" << std::endl;
131 test_my_matrix<ublas::matrix<boost::numeric::interval<float>, ublas::row_major, ublas::bounded_array<boost::numeric::interval<float>, 3 * 3> >, 3 > () ();
132#endif
133
134#ifdef USE_DOUBLE
135 std::cout << "boost::numeric::interval<double>, bounded_array" << std::endl;
136 test_my_matrix<ublas::matrix<boost::numeric::interval<double>, ublas::row_major, ublas::bounded_array<boost::numeric::interval<double>, 3 * 3> >, 3 > () ();
137#endif
138#endif
139
140#ifdef USE_UNBOUNDED_ARRAY
141#ifdef USE_FLOAT
142 std::cout << "boost::numeric::interval<float>, unbounded_array" << std::endl;
143 test_my_matrix<ublas::matrix<boost::numeric::interval<float>, ublas::row_major, ublas::unbounded_array<boost::numeric::interval<float> > >, 3 > () ();
144#endif
145
146#ifdef USE_DOUBLE
147 std::cout << "boost::numeric::interval<double>, unbounded_array" << std::endl;
148 test_my_matrix<ublas::matrix<boost::numeric::interval<double>, ublas::row_major, ublas::unbounded_array<boost::numeric::interval<double> > >, 3 > () ();
149#endif
150#endif
151
152#ifdef USE_STD_VECTOR
153#ifdef USE_FLOAT
154 std::cout << "boost::numeric::interval<float>, std::vector" << std::endl;
155 test_my_matrix<ublas::matrix<boost::numeric::interval<float>, ublas::row_major, std::vector<boost::numeric::interval<float> > >, 3 > () ();
156#endif
157
158#ifdef USE_DOUBLE
159 std::cout << "boost::numeric::interval<double>, std::vector" << std::endl;
160 test_my_matrix<ublas::matrix<boost::numeric::interval<double>, ublas::row_major, std::vector<boost::numeric::interval<double> > >, 3 > () ();
161#endif
162#endif
163#endif
164
165#ifdef USE_VECTOR_OF_VECTOR
166#ifdef USE_BOUNDED_ARRAY
167#ifdef USE_FLOAT
168 std::cout << "boost::numeric::interval<float>, bounded_array" << std::endl;
169 test_my_matrix<ublas::vector_of_vector<boost::numeric::interval<float>, ublas::row_major, ublas::bounded_array<ublas::bounded_array<boost::numeric::interval<float>, 3>, 3 + 1> >, 3 > () ();
170#endif
171
172#ifdef USE_DOUBLE
173 std::cout << "boost::numeric::interval<double>, bounded_array" << std::endl;
174 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 > () ();
175#endif
176#endif
177
178#ifdef USE_UNBOUNDED_ARRAY
179#ifdef USE_FLOAT
180 std::cout << "boost::numeric::interval<float>, unbounded_array" << std::endl;
181 test_my_matrix<ublas::vector_of_vector<boost::numeric::interval<float>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<boost::numeric::interval<float> > > >, 3 > () ();
182#endif
183
184#ifdef USE_DOUBLE
185 std::cout << "boost::numeric::interval<double>, unbounded_array" << std::endl;
186 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 > () ();
187#endif
188#endif
189
190#ifdef USE_STD_VECTOR
191#ifdef USE_FLOAT
192 std::cout << "boost::numeric::interval<float>, std::vector" << std::endl;
193 test_my_matrix<ublas::vector_of_vector<boost::numeric::interval<float>, ublas::row_major, std::vector<std::vector<boost::numeric::interval<float> > > >, 3 > () ();
194#endif
195
196#ifdef USE_DOUBLE
197 std::cout << "boost::numeric::interval<double>, std::vector" << std::endl;
198 test_my_matrix<ublas::vector_of_vector<boost::numeric::interval<double>, ublas::row_major, std::vector<std::vector<boost::numeric::interval<double> > > >, 3 > () ();
199#endif
200#endif
201#endif
202}
203

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