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