]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/numeric/ublas/test/test73.cpp
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.
15 // Test matrix expression templates
16 template<class M
, int N
>
17 struct test_my_matrix
{
18 typedef typename
M::value_type value_type
;
21 void test_with (MP
&m1
, MP
&m2
, MP
&m3
) const {
26 initialize_matrix (m1
);
27 initialize_matrix (m2
);
29 std::cout
<< "m1 = m2 = " << m1
<< std::endl
;
30 m1
.assign_temporary (m2
);
31 std::cout
<< "m1.assign_temporary (m2) = " << m1
<< std::endl
;
33 std::cout
<< "m1.swap (m2) = " << m1
<< " " << m2
<< std::endl
;
36 m1
= ublas::zero_matrix
<value_type
> (m1
.size1 (), m1
.size2 ());
37 std::cout
<< "m1.zero_matrix = " << m1
<< std::endl
;
40 // Unary matrix operations resulting in a matrix
41 initialize_matrix (m1
);
43 std::cout
<< "- m1 = " << m2
<< std::endl
;
44 m2
= ublas::conj (m1
);
45 std::cout
<< "conj (m1) = " << m2
<< std::endl
;
47 // Binary matrix operations resulting in a matrix
48 initialize_matrix (m1
);
49 initialize_matrix (m2
);
51 std::cout
<< "m1 + m2 = " << m3
<< std::endl
;
53 std::cout
<< "m1 - m2 = " << m3
<< std::endl
;
57 initialize_matrix (m1
);
58 m2
= value_type (1.) * m1
;
59 std::cout
<< "1. * m1 = " << m2
<< std::endl
;
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
;
66 std::cout
<< "m1 * N = " << m2
<< std::endl
;
69 initialize_matrix (m1
);
70 initialize_matrix (m2
);
72 std::cout
<< "m2 += m1 = " << m2
<< std::endl
;
74 std::cout
<< "m2 -= m1 = " << m2
<< std::endl
;
76 std::cout
<< "m2 = m2 + m1 = " << m2
<< std::endl
;
78 std::cout
<< "m2 = m1 - m1 = " << m2
<< std::endl
;
79 m1
*= value_type (1.);
80 std::cout
<< "m1 *= 1. = " << m1
<< std::endl
;
82 std::cout
<< "m1 *= N = " << m1
<< std::endl
;
85 initialize_matrix (m1
);
86 m2
= ublas::trans (m1
);
87 std::cout
<< "trans (m1) = " << m2
<< std::endl
;
90 initialize_matrix (m1
);
91 m2
= ublas::herm (m1
);
92 std::cout
<< "herm (m1) = " << m2
<< std::endl
;
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
;
101 void operator () () const {
103 M
m1 (N
, N
), m2 (N
, N
), m3 (N
, N
);
104 test_with (m1
, m2
, m3
);
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
);
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
);
124 void test_matrix () {
125 std::cout
<< "test_matrix" << std::endl
;
128 #ifdef USE_BOUNDED_ARRAY
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 > () ();
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 > () ();
140 #ifdef USE_UNBOUNDED_ARRAY
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 > () ();
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 > () ();
152 #ifdef USE_STD_VECTOR
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 > () ();
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 > () ();
165 #ifdef USE_VECTOR_OF_VECTOR
166 #ifdef USE_BOUNDED_ARRAY
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 > () ();
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 > () ();
178 #ifdef USE_UNBOUNDED_ARRAY
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 > () ();
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 > () ();
190 #ifdef USE_STD_VECTOR
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 > () ();
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 > () ();