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 #if defined(__GNUC__) && (__GNUC__ >= 9)
14 #pragma GCC diagnostic ignored "-Wdeprecated-copy"
15 #endif
16
17 #include "test7.hpp"
18
19 // Test matrix & vector expression templates
20 template <class V, class M, int N>
21 struct test_my_matrix_vector
22 {
23 typedef typename V::value_type value_type;
24
25 template <class VP, class MP>
test_withtest_my_matrix_vector26 void test_with(VP& v1, VP& v2, MP& m1) const
27 {
28 {
29 // Rows and columns
30 initialize_matrix(m1);
31 for (int i = 0; i < N; ++i)
32 {
33 v1 = ublas::row(m1, i);
34 std::cout << "row (m, " << i << ") = " << v1 << std::endl;
35 v1 = ublas::column(m1, i);
36 std::cout << "column (m, " << i << ") = " << v1 << std::endl;
37 }
38
39 // Outer product
40 initialize_vector(v1);
41 initialize_vector(v2);
42 m1 = ublas::outer_prod(v1, v2);
43 std::cout << "outer_prod (v1, v2) = " << m1 << std::endl;
44
45 // Matrix vector product
46 initialize_matrix(m1);
47 initialize_vector(v1);
48 v2 = ublas::prod(m1, v1);
49 std::cout << "prod (m1, v1) = " << v2 << std::endl;
50 v2 = ublas::prod(v1, m1);
51 std::cout << "prod (v1, m1) = " << v2 << std::endl;
52 }
53 }
operator ()test_my_matrix_vector54 void operator()() const
55 {
56 {
57 V v1(N), v2(N);
58 M m1(N, N);
59 test_with(v1, v2, m1);
60
61 ublas::matrix_row<M> mr1(m1, 0), mr2(m1, 1);
62 test_with(mr1, mr2, m1);
63
64 ublas::matrix_column<M> mc1(m1, 0), mc2(m1, 1);
65 test_with(mc1, mc2, m1);
66
67 #ifdef USE_RANGE
68 ublas::matrix_vector_range<M> mvr1(m1, ublas::range(0, N), ublas::range(0, N)),
69 mvr2(m1, ublas::range(0, N), ublas::range(0, N));
70 test_with(mvr1, mvr2, m1);
71 #endif
72
73 #ifdef USE_SLICE
74 ublas::matrix_vector_slice<M> mvs1(m1, ublas::slice(0, 1, N), ublas::slice(0, 1, N)),
75 mvs2(m1, ublas::slice(0, 1, N), ublas::slice(0, 1, N));
76 test_with(mvs1, mvs2, m1);
77 #endif
78 }
79 }
80 };
81
82 // Test matrix & vector
test_matrix_vector()83 void test_matrix_vector()
84 {
85 std::cout << "test_matrix_vector" << std::endl;
86
87 #ifdef USE_MATRIX
88 #ifdef USE_BOUNDED_ARRAY
89 #ifdef USE_FLOAT
90 std::cout << "boost::numeric::interval<mp_test_type>, bounded_array" << std::endl;
91 test_my_matrix_vector<ublas::vector<boost::numeric::interval<mp_test_type>, ublas::bounded_array<boost::numeric::interval<mp_test_type>, 3> >,
92 ublas::matrix<boost::numeric::interval<mp_test_type>, ublas::row_major, ublas::bounded_array<boost::numeric::interval<mp_test_type>, 3 * 3> >, 3>()();
93 #endif
94
95 #ifdef USE_DOUBLE
96 std::cout << "boost::numeric::interval<double>, bounded_array" << std::endl;
97 test_my_matrix_vector<ublas::vector<boost::numeric::interval<double>, ublas::bounded_array<boost::numeric::interval<double>, 3> >,
98 ublas::matrix<boost::numeric::interval<double>, ublas::row_major, ublas::bounded_array<boost::numeric::interval<double>, 3 * 3> >, 3>()();
99 #endif
100 #endif
101
102 #ifdef USE_UNBOUNDED_ARRAY
103 #ifdef USE_FLOAT
104 std::cout << "boost::numeric::interval<mp_test_type>, unbounded_array" << std::endl;
105 test_my_matrix_vector<ublas::vector<boost::numeric::interval<mp_test_type>, ublas::unbounded_array<boost::numeric::interval<mp_test_type> > >,
106 ublas::matrix<boost::numeric::interval<mp_test_type>, ublas::row_major, ublas::unbounded_array<boost::numeric::interval<mp_test_type> > >, 3>()();
107 #endif
108
109 #ifdef USE_DOUBLE
110 std::cout << "boost::numeric::interval<double>, unbounded_array" << std::endl;
111 test_my_matrix_vector<ublas::vector<boost::numeric::interval<double>, ublas::unbounded_array<boost::numeric::interval<double> > >,
112 ublas::matrix<boost::numeric::interval<double>, ublas::row_major, ublas::unbounded_array<boost::numeric::interval<double> > >, 3>()();
113 #endif
114 #endif
115
116 #ifdef USE_STD_VECTOR
117 #ifdef USE_FLOAT
118 std::cout << "boost::numeric::interval<mp_test_type>, std::vector" << std::endl;
119 test_my_matrix_vector<ublas::vector<boost::numeric::interval<mp_test_type>, std::vector<boost::numeric::interval<mp_test_type> > >,
120 ublas::matrix<boost::numeric::interval<mp_test_type>, ublas::row_major, std::vector<boost::numeric::interval<mp_test_type> > >, 3>()();
121 #endif
122
123 #ifdef USE_DOUBLE
124 std::cout << "boost::numeric::interval<double>, std::vector" << std::endl;
125 test_my_matrix_vector<ublas::vector<boost::numeric::interval<double>, std::vector<boost::numeric::interval<double> > >,
126 ublas::matrix<boost::numeric::interval<double>, ublas::row_major, std::vector<boost::numeric::interval<double> > >, 3>()();
127 #endif
128 #endif
129 #endif
130
131 #ifdef USE_VECTOR_OF_VECTOR
132 #ifdef USE_BOUNDED_ARRAY
133 #ifdef USE_FLOAT
134 std::cout << "boost::numeric::interval<mp_test_type>, bounded_array" << std::endl;
135 test_my_matrix_vector<ublas::vector<boost::numeric::interval<mp_test_type>, ublas::bounded_array<boost::numeric::interval<mp_test_type>, 3> >,
136 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>()();
137 #endif
138
139 #ifdef USE_DOUBLE
140 std::cout << "boost::numeric::interval<double>, bounded_array" << std::endl;
141 test_my_matrix_vector<ublas::vector<boost::numeric::interval<double>, ublas::bounded_array<boost::numeric::interval<double>, 3> >,
142 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>()();
143 #endif
144 #endif
145
146 #ifdef USE_UNBOUNDED_ARRAY
147 #ifdef USE_FLOAT
148 std::cout << "boost::numeric::interval<mp_test_type>, unbounded_array" << std::endl;
149 test_my_matrix_vector<ublas::vector<boost::numeric::interval<mp_test_type>, ublas::unbounded_array<boost::numeric::interval<mp_test_type> > >,
150 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>()();
151 #endif
152
153 #ifdef USE_DOUBLE
154 std::cout << "boost::numeric::interval<double>, unbounded_array" << std::endl;
155 test_my_matrix_vector<ublas::vector<boost::numeric::interval<double>, ublas::unbounded_array<boost::numeric::interval<double> > >,
156 ublas::vector_of_vector<boost::numeric::interval<double>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<boost::numeric::interval<double> > > >, 3>()();
157 #endif
158 #endif
159
160 #ifdef USE_STD_VECTOR
161 #ifdef USE_FLOAT
162 std::cout << "boost::numeric::interval<mp_test_type>, std::vector" << std::endl;
163 test_my_matrix_vector<ublas::vector<boost::numeric::interval<mp_test_type>, std::vector<boost::numeric::interval<mp_test_type> > >,
164 ublas::vector_of_vector<boost::numeric::interval<mp_test_type>, ublas::row_major, std::vector<std::vector<boost::numeric::interval<mp_test_type> > > >, 3>()();
165 #endif
166
167 #ifdef USE_DOUBLE
168 std::cout << "boost::numeric::interval<double>, std::vector" << std::endl;
169 test_my_matrix_vector<ublas::vector<boost::numeric::interval<double>, std::vector<boost::numeric::interval<double> > >,
170 ublas::vector_of_vector<boost::numeric::interval<double>, ublas::row_major, std::vector<std::vector<boost::numeric::interval<double> > > >, 3>()();
171 #endif
172 #endif
173 #endif
174 }
175