test73.cpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. #if defined(__GNUC__) && (__GNUC__ >= 9)
  13. #pragma GCC diagnostic ignored "-Wdeprecated-copy"
  14. #endif
  15. #include "test7.hpp"
  16. // Test matrix expression templates
  17. template <class M, int N>
  18. struct test_my_matrix
  19. {
  20. typedef typename M::value_type value_type;
  21. template <class MP>
  22. void test_with(MP& m1, MP& m2, MP& m3) const
  23. {
  24. {
  25. value_type t;
  26. // Copy and swap
  27. initialize_matrix(m1);
  28. initialize_matrix(m2);
  29. m1 = m2;
  30. std::cout << "m1 = m2 = " << m1 << std::endl;
  31. m1.assign_temporary(m2);
  32. std::cout << "m1.assign_temporary (m2) = " << m1 << std::endl;
  33. m1.swap(m2);
  34. std::cout << "m1.swap (m2) = " << m1 << " " << m2 << std::endl;
  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. // Unary matrix operations resulting in a matrix
  40. initialize_matrix(m1);
  41. m2 = -m1;
  42. std::cout << "- m1 = " << m2 << std::endl;
  43. m2 = ublas::conj(m1);
  44. std::cout << "conj (m1) = " << m2 << std::endl;
  45. // Binary matrix operations resulting in a matrix
  46. initialize_matrix(m1);
  47. initialize_matrix(m2);
  48. m3 = m1 + m2;
  49. std::cout << "m1 + m2 = " << m3 << std::endl;
  50. m3 = m1 - m2;
  51. std::cout << "m1 - m2 = " << m3 << std::endl;
  52. // Scaling a matrix
  53. t = N;
  54. initialize_matrix(m1);
  55. m2 = value_type(1.) * m1;
  56. std::cout << "1. * m1 = " << m2 << std::endl;
  57. m2 = t * m1;
  58. std::cout << "N * m1 = " << m2 << std::endl;
  59. initialize_matrix(m1);
  60. m2 = m1 * value_type(1.);
  61. std::cout << "m1 * 1. = " << m2 << std::endl;
  62. m2 = m1 * t;
  63. std::cout << "m1 * N = " << m2 << std::endl;
  64. // Some assignments
  65. initialize_matrix(m1);
  66. initialize_matrix(m2);
  67. m2 += m1;
  68. std::cout << "m2 += m1 = " << m2 << std::endl;
  69. m2 -= m1;
  70. std::cout << "m2 -= m1 = " << m2 << std::endl;
  71. m2 = m2 + m1;
  72. std::cout << "m2 = m2 + m1 = " << m2 << std::endl;
  73. m2 = m2 - m1;
  74. std::cout << "m2 = m1 - m1 = " << m2 << std::endl;
  75. m1 *= value_type(1.);
  76. std::cout << "m1 *= 1. = " << m1 << std::endl;
  77. m1 *= t;
  78. std::cout << "m1 *= N = " << m1 << std::endl;
  79. // Transpose
  80. initialize_matrix(m1);
  81. m2 = ublas::trans(m1);
  82. std::cout << "trans (m1) = " << m2 << std::endl;
  83. // Hermitean
  84. initialize_matrix(m1);
  85. m2 = ublas::herm(m1);
  86. std::cout << "herm (m1) = " << m2 << std::endl;
  87. // Matrix multiplication
  88. initialize_matrix(m1);
  89. initialize_matrix(m2);
  90. m3 = ublas::prod(m1, m2);
  91. std::cout << "prod (m1, m2) = " << m3 << std::endl;
  92. }
  93. }
  94. void operator()() const
  95. {
  96. {
  97. M m1(N, N), m2(N, N), m3(N, N);
  98. test_with(m1, m2, m3);
  99. #ifdef USE_RANGE
  100. ublas::matrix_range<M> mr1(m1, ublas::range(0, N), ublas::range(0, N)),
  101. mr2(m2, ublas::range(0, N), ublas::range(0, N)),
  102. mr3(m3, ublas::range(0, N), ublas::range(0, N));
  103. test_with(mr1, mr2, mr3);
  104. #endif
  105. #ifdef USE_SLICE
  106. ublas::matrix_slice<M> ms1(m1, ublas::slice(0, 1, N), ublas::slice(0, 1, N)),
  107. ms2(m2, ublas::slice(0, 1, N), ublas::slice(0, 1, N)),
  108. ms3(m3, ublas::slice(0, 1, N), ublas::slice(0, 1, N));
  109. test_with(ms1, ms2, ms3);
  110. #endif
  111. }
  112. }
  113. };
  114. // Test matrix
  115. void test_matrix()
  116. {
  117. std::cout << "test_matrix" << std::endl;
  118. #ifdef USE_MATRIX
  119. #ifdef USE_BOUNDED_ARRAY
  120. #ifdef USE_FLOAT
  121. std::cout << "boost::numeric::interval<mp_test_type>, bounded_array" << std::endl;
  122. test_my_matrix<ublas::matrix<boost::numeric::interval<mp_test_type>, ublas::row_major, ublas::bounded_array<boost::numeric::interval<mp_test_type>, 3 * 3> >, 3>()();
  123. #endif
  124. #ifdef USE_DOUBLE
  125. std::cout << "boost::numeric::interval<double>, bounded_array" << std::endl;
  126. test_my_matrix<ublas::matrix<boost::numeric::interval<double>, ublas::row_major, ublas::bounded_array<boost::numeric::interval<double>, 3 * 3> >, 3>()();
  127. #endif
  128. #endif
  129. #ifdef USE_UNBOUNDED_ARRAY
  130. #ifdef USE_FLOAT
  131. std::cout << "boost::numeric::interval<mp_test_type>, unbounded_array" << std::endl;
  132. test_my_matrix<ublas::matrix<boost::numeric::interval<mp_test_type>, ublas::row_major, ublas::unbounded_array<boost::numeric::interval<mp_test_type> > >, 3>()();
  133. #endif
  134. #ifdef USE_DOUBLE
  135. std::cout << "boost::numeric::interval<double>, unbounded_array" << std::endl;
  136. test_my_matrix<ublas::matrix<boost::numeric::interval<double>, ublas::row_major, ublas::unbounded_array<boost::numeric::interval<double> > >, 3>()();
  137. #endif
  138. #endif
  139. #ifdef USE_STD_VECTOR
  140. #ifdef USE_FLOAT
  141. std::cout << "boost::numeric::interval<mp_test_type>, std::vector" << std::endl;
  142. test_my_matrix<ublas::matrix<boost::numeric::interval<mp_test_type>, ublas::row_major, std::vector<boost::numeric::interval<mp_test_type> > >, 3>()();
  143. #endif
  144. #ifdef USE_DOUBLE
  145. std::cout << "boost::numeric::interval<double>, std::vector" << std::endl;
  146. test_my_matrix<ublas::matrix<boost::numeric::interval<double>, ublas::row_major, std::vector<boost::numeric::interval<double> > >, 3>()();
  147. #endif
  148. #endif
  149. #endif
  150. #ifdef USE_VECTOR_OF_VECTOR
  151. #ifdef USE_BOUNDED_ARRAY
  152. #ifdef USE_FLOAT
  153. std::cout << "boost::numeric::interval<mp_test_type>, bounded_array" << std::endl;
  154. test_my_matrix<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>()();
  155. #endif
  156. #ifdef USE_DOUBLE
  157. std::cout << "boost::numeric::interval<double>, bounded_array" << std::endl;
  158. 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>()();
  159. #endif
  160. #endif
  161. #ifdef USE_UNBOUNDED_ARRAY
  162. #ifdef USE_FLOAT
  163. std::cout << "boost::numeric::interval<mp_test_type>, unbounded_array" << std::endl;
  164. test_my_matrix<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>()();
  165. #endif
  166. #ifdef USE_DOUBLE
  167. std::cout << "boost::numeric::interval<double>, unbounded_array" << std::endl;
  168. 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>()();
  169. #endif
  170. #endif
  171. #ifdef USE_STD_VECTOR
  172. #ifdef USE_FLOAT
  173. std::cout << "boost::numeric::interval<mp_test_type>, std::vector" << std::endl;
  174. test_my_matrix<ublas::vector_of_vector<boost::numeric::interval<mp_test_type>, ublas::row_major, std::vector<std::vector<boost::numeric::interval<mp_test_type> > > >, 3>()();
  175. #endif
  176. #ifdef USE_DOUBLE
  177. std::cout << "boost::numeric::interval<double>, std::vector" << std::endl;
  178. test_my_matrix<ublas::vector_of_vector<boost::numeric::interval<double>, ublas::row_major, std::vector<std::vector<boost::numeric::interval<double> > > >, 3>()();
  179. #endif
  180. #endif
  181. #endif
  182. }