test73.cpp 7.7 KB

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