test12.cpp 11 KB

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