test12.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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 "test1.hpp"
  16. // Test matrix & vector expression templates
  17. template <class V, class M, int N>
  18. struct test_my_matrix_vector
  19. {
  20. typedef typename V::value_type value_type;
  21. template <class VP, class MP>
  22. void test_with(VP& v1, VP& v2, MP& m1) const
  23. {
  24. {
  25. // Rows and columns
  26. initialize_matrix(m1);
  27. for (int i = 0; i < N; ++i)
  28. {
  29. v1 = ublas::row(m1, i);
  30. std::cout << "row (m, " << i << ") = " << v1 << std::endl;
  31. v1 = ublas::column(m1, i);
  32. std::cout << "column (m, " << i << ") = " << v1 << std::endl;
  33. }
  34. // Outer product
  35. initialize_vector(v1);
  36. initialize_vector(v2);
  37. m1 = ublas::outer_prod(v1, v2);
  38. std::cout << "outer_prod (v1, v2) = " << m1 << std::endl;
  39. // Matrix vector product
  40. initialize_matrix(m1);
  41. initialize_vector(v1);
  42. v2 = ublas::prod(m1, v1);
  43. std::cout << "prod (m1, v1) = " << v2 << std::endl;
  44. v2 = ublas::prod(v1, m1);
  45. std::cout << "prod (v1, m1) = " << v2 << std::endl;
  46. }
  47. }
  48. void operator()() const
  49. {
  50. {
  51. V v1(N), v2(N);
  52. M m1(N, N);
  53. test_with(v1, v2, m1);
  54. ublas::matrix_row<M> mr1(m1, 0), mr2(m1, 1);
  55. test_with(mr1, mr2, m1);
  56. ublas::matrix_column<M> mc1(m1, 0), mc2(m1, 1);
  57. test_with(mc1, mc2, m1);
  58. #ifdef USE_RANGE
  59. ublas::matrix_vector_range<M> mvr1(m1, ublas::range(0, N), ublas::range(0, N)),
  60. mvr2(m1, ublas::range(0, N), ublas::range(0, N));
  61. test_with(mvr1, mvr2, m1);
  62. #endif
  63. #ifdef USE_SLICE
  64. ublas::matrix_vector_slice<M> mvs1(m1, ublas::slice(0, 1, N), ublas::slice(0, 1, N)),
  65. mvs2(m1, ublas::slice(0, 1, N), ublas::slice(0, 1, N));
  66. test_with(mvs1, mvs2, m1);
  67. #endif
  68. }
  69. }
  70. };
  71. // Test matrix & vector
  72. void test_matrix_vector()
  73. {
  74. std::cout << "test_matrix_vector" << std::endl;
  75. #ifdef USE_MATRIX
  76. #ifdef USE_BOUNDED_ARRAY
  77. #ifdef USE_FLOAT
  78. std::cout << "mp_test_type, bounded_array" << std::endl;
  79. test_my_matrix_vector<ublas::vector<mp_test_type, ublas::bounded_array<mp_test_type, 3> >,
  80. ublas::matrix<mp_test_type, ublas::row_major, ublas::bounded_array<mp_test_type, 3 * 3> >, 3>()();
  81. #endif
  82. #ifdef USE_DOUBLE
  83. std::cout << "double, bounded_array" << std::endl;
  84. test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >,
  85. ublas::matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3>()();
  86. #endif
  87. #ifdef USE_STD_COMPLEX
  88. #ifdef USE_FLOAT
  89. std::cout << "std::complex<mp_test_type>, bounded_array" << std::endl;
  90. test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::bounded_array<std::complex<mp_test_type>, 3> >,
  91. ublas::matrix<std::complex<mp_test_type>, ublas::row_major, ublas::bounded_array<std::complex<mp_test_type>, 3 * 3> >, 3>()();
  92. #endif
  93. #ifdef USE_DOUBLE
  94. std::cout << "std::complex<double>, bounded_array" << std::endl;
  95. test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >,
  96. ublas::matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3>()();
  97. #endif
  98. #endif
  99. #endif
  100. #ifdef USE_UNBOUNDED_ARRAY
  101. #ifdef USE_FLOAT
  102. std::cout << "mp_test_type, unbounded_array" << std::endl;
  103. test_my_matrix_vector<ublas::vector<mp_test_type, ublas::unbounded_array<mp_test_type> >,
  104. ublas::matrix<mp_test_type, ublas::row_major, ublas::unbounded_array<mp_test_type> >, 3>()();
  105. #endif
  106. #ifdef USE_DOUBLE
  107. std::cout << "double, unbounded_array" << std::endl;
  108. test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >,
  109. ublas::matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3>()();
  110. #endif
  111. #ifdef USE_STD_COMPLEX
  112. #ifdef USE_FLOAT
  113. std::cout << "std::complex<mp_test_type>, unbounded_array" << std::endl;
  114. test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::unbounded_array<std::complex<mp_test_type> > >,
  115. ublas::matrix<std::complex<mp_test_type>, ublas::row_major, ublas::unbounded_array<std::complex<mp_test_type> > >, 3>()();
  116. #endif
  117. #ifdef USE_DOUBLE
  118. std::cout << "std::complex<double>, unbounded_array" << std::endl;
  119. test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >,
  120. ublas::matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3>()();
  121. #endif
  122. #endif
  123. #endif
  124. #ifdef USE_STD_VECTOR
  125. #ifdef USE_FLOAT
  126. std::cout << "mp_test_type, std::vector" << std::endl;
  127. test_my_matrix_vector<ublas::vector<mp_test_type, std::vector<mp_test_type> >,
  128. ublas::matrix<mp_test_type, ublas::row_major, std::vector<mp_test_type> >, 3>()();
  129. #endif
  130. #ifdef USE_DOUBLE
  131. std::cout << "double, std::vector" << std::endl;
  132. test_my_matrix_vector<ublas::vector<double, std::vector<double> >,
  133. ublas::matrix<double, ublas::row_major, std::vector<double> >, 3>()();
  134. #endif
  135. #ifdef USE_STD_COMPLEX
  136. #ifdef USE_FLOAT
  137. std::cout << "std::complex<mp_test_type>, std::vector" << std::endl;
  138. test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, std::vector<std::complex<mp_test_type> > >,
  139. ublas::matrix<std::complex<mp_test_type>, ublas::row_major, std::vector<std::complex<mp_test_type> > >, 3>()();
  140. #endif
  141. #ifdef USE_DOUBLE
  142. std::cout << "std::complex<double>, std::vector" << std::endl;
  143. test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >,
  144. ublas::matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3>()();
  145. #endif
  146. #endif
  147. #endif
  148. #endif
  149. #ifdef USE_BOUNDED_MATRIX
  150. #ifdef USE_FLOAT
  151. std::cout << "mp_test_type, bounded" << std::endl;
  152. test_my_matrix_vector<ublas::bounded_vector<mp_test_type, 3>,
  153. ublas::bounded_matrix<mp_test_type, 3, 3>, 3>()();
  154. #endif
  155. #ifdef USE_DOUBLE
  156. std::cout << "double, bounded" << std::endl;
  157. test_my_matrix_vector<ublas::bounded_vector<double, 3>,
  158. ublas::bounded_matrix<double, 3, 3>, 3>()();
  159. #endif
  160. #ifdef USE_STD_COMPLEX
  161. #ifdef USE_FLOAT
  162. std::cout << "std::complex<mp_test_type>, bounded" << std::endl;
  163. test_my_matrix_vector<ublas::bounded_vector<std::complex<mp_test_type>, 3>,
  164. ublas::bounded_matrix<std::complex<mp_test_type>, 3, 3>, 3>()();
  165. #endif
  166. #ifdef USE_DOUBLE
  167. std::cout << "std::complex<double>, bounded" << std::endl;
  168. test_my_matrix_vector<ublas::bounded_vector<std::complex<double>, 3>,
  169. ublas::bounded_matrix<std::complex<double>, 3, 3>, 3>()();
  170. #endif
  171. #endif
  172. #endif
  173. #ifdef USE_VECTOR_OF_VECTOR
  174. #ifdef USE_BOUNDED_ARRAY
  175. #ifdef USE_FLOAT
  176. std::cout << "mp_test_type, bounded_array" << std::endl;
  177. test_my_matrix_vector<ublas::vector<mp_test_type, ublas::bounded_array<mp_test_type, 3> >,
  178. ublas::vector_of_vector<mp_test_type, ublas::row_major, ublas::bounded_array<ublas::bounded_array<mp_test_type, 3>, 3 + 1> >, 3>()();
  179. #endif
  180. #ifdef USE_DOUBLE
  181. std::cout << "double, bounded_array" << std::endl;
  182. test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >,
  183. ublas::vector_of_vector<double, ublas::row_major, ublas::bounded_array<ublas::bounded_array<double, 3>, 3 + 1> >, 3>()();
  184. #endif
  185. #ifdef USE_STD_COMPLEX
  186. #ifdef USE_FLOAT
  187. std::cout << "std::complex<mp_test_type>, bounded_array" << std::endl;
  188. test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::bounded_array<std::complex<mp_test_type>, 3> >,
  189. ublas::vector_of_vector<std::complex<mp_test_type>, ublas::row_major, ublas::bounded_array<ublas::bounded_array<std::complex<mp_test_type>, 3>, 3 + 1> >, 3>()();
  190. #endif
  191. #ifdef USE_DOUBLE
  192. std::cout << "std::complex<double>, bounded_array" << std::endl;
  193. test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >,
  194. ublas::vector_of_vector<std::complex<double>, ublas::row_major, ublas::bounded_array<ublas::bounded_array<std::complex<double>, 3>, 3 + 1> >, 3>()();
  195. #endif
  196. #endif
  197. #endif
  198. #ifdef USE_UNBOUNDED_ARRAY
  199. #ifdef USE_FLOAT
  200. std::cout << "mp_test_type, unbounded_array" << std::endl;
  201. test_my_matrix_vector<ublas::vector<mp_test_type, ublas::unbounded_array<mp_test_type> >,
  202. ublas::vector_of_vector<mp_test_type, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<mp_test_type> > >, 3>()();
  203. #endif
  204. #ifdef USE_DOUBLE
  205. std::cout << "double, unbounded_array" << std::endl;
  206. test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >,
  207. ublas::vector_of_vector<double, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<double> > >, 3>()();
  208. #endif
  209. #ifdef USE_STD_COMPLEX
  210. #ifdef USE_FLOAT
  211. std::cout << "std::complex<mp_test_type>, unbounded_array" << std::endl;
  212. test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::unbounded_array<std::complex<mp_test_type> > >,
  213. ublas::vector_of_vector<std::complex<mp_test_type>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<std::complex<mp_test_type> > > >, 3>()();
  214. #endif
  215. #ifdef USE_DOUBLE
  216. std::cout << "std::complex<double>, unbounded_array" << std::endl;
  217. test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >,
  218. ublas::vector_of_vector<std::complex<double>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<std::complex<double> > > >, 3>()();
  219. #endif
  220. #endif
  221. #endif
  222. #ifdef USE_STD_VECTOR
  223. #ifdef USE_FLOAT
  224. std::cout << "mp_test_type, std::vector" << std::endl;
  225. test_my_matrix_vector<ublas::vector<mp_test_type, std::vector<mp_test_type> >,
  226. ublas::vector_of_vector<mp_test_type, ublas::row_major, std::vector<std::vector<mp_test_type> > >, 3>()();
  227. #endif
  228. #ifdef USE_DOUBLE
  229. std::cout << "double, std::vector" << std::endl;
  230. test_my_matrix_vector<ublas::vector<double, std::vector<double> >,
  231. ublas::vector_of_vector<double, ublas::row_major, std::vector<std::vector<double> > >, 3>()();
  232. #endif
  233. #ifdef USE_STD_COMPLEX
  234. #ifdef USE_FLOAT
  235. std::cout << "std::complex<mp_test_type>, std::vector" << std::endl;
  236. test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, std::vector<std::complex<mp_test_type> > >,
  237. ublas::vector_of_vector<std::complex<mp_test_type>, ublas::row_major, std::vector<std::vector<std::complex<mp_test_type> > > >, 3>()();
  238. #endif
  239. #ifdef USE_DOUBLE
  240. std::cout << "std::complex<double>, std::vector" << std::endl;
  241. test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >,
  242. ublas::vector_of_vector<std::complex<double>, ublas::row_major, std::vector<std::vector<std::complex<double> > > >, 3>()();
  243. #endif
  244. #endif
  245. #endif
  246. #endif
  247. }