test72.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 & 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 << "boost::numeric::interval<mp_test_type>, bounded_array" << std::endl;
  79. test_my_matrix_vector<ublas::vector<boost::numeric::interval<mp_test_type>, ublas::bounded_array<boost::numeric::interval<mp_test_type>, 3> >,
  80. ublas::matrix<boost::numeric::interval<mp_test_type>, ublas::row_major, ublas::bounded_array<boost::numeric::interval<mp_test_type>, 3 * 3> >, 3>()();
  81. #endif
  82. #ifdef USE_DOUBLE
  83. std::cout << "boost::numeric::interval<double>, bounded_array" << std::endl;
  84. test_my_matrix_vector<ublas::vector<boost::numeric::interval<double>, ublas::bounded_array<boost::numeric::interval<double>, 3> >,
  85. ublas::matrix<boost::numeric::interval<double>, ublas::row_major, ublas::bounded_array<boost::numeric::interval<double>, 3 * 3> >, 3>()();
  86. #endif
  87. #endif
  88. #ifdef USE_UNBOUNDED_ARRAY
  89. #ifdef USE_FLOAT
  90. std::cout << "boost::numeric::interval<mp_test_type>, unbounded_array" << std::endl;
  91. test_my_matrix_vector<ublas::vector<boost::numeric::interval<mp_test_type>, ublas::unbounded_array<boost::numeric::interval<mp_test_type> > >,
  92. ublas::matrix<boost::numeric::interval<mp_test_type>, ublas::row_major, ublas::unbounded_array<boost::numeric::interval<mp_test_type> > >, 3>()();
  93. #endif
  94. #ifdef USE_DOUBLE
  95. std::cout << "boost::numeric::interval<double>, unbounded_array" << std::endl;
  96. test_my_matrix_vector<ublas::vector<boost::numeric::interval<double>, ublas::unbounded_array<boost::numeric::interval<double> > >,
  97. ublas::matrix<boost::numeric::interval<double>, ublas::row_major, ublas::unbounded_array<boost::numeric::interval<double> > >, 3>()();
  98. #endif
  99. #endif
  100. #ifdef USE_STD_VECTOR
  101. #ifdef USE_FLOAT
  102. std::cout << "boost::numeric::interval<mp_test_type>, std::vector" << std::endl;
  103. test_my_matrix_vector<ublas::vector<boost::numeric::interval<mp_test_type>, std::vector<boost::numeric::interval<mp_test_type> > >,
  104. ublas::matrix<boost::numeric::interval<mp_test_type>, ublas::row_major, std::vector<boost::numeric::interval<mp_test_type> > >, 3>()();
  105. #endif
  106. #ifdef USE_DOUBLE
  107. std::cout << "boost::numeric::interval<double>, std::vector" << std::endl;
  108. test_my_matrix_vector<ublas::vector<boost::numeric::interval<double>, std::vector<boost::numeric::interval<double> > >,
  109. ublas::matrix<boost::numeric::interval<double>, ublas::row_major, std::vector<boost::numeric::interval<double> > >, 3>()();
  110. #endif
  111. #endif
  112. #endif
  113. #ifdef USE_VECTOR_OF_VECTOR
  114. #ifdef USE_BOUNDED_ARRAY
  115. #ifdef USE_FLOAT
  116. std::cout << "boost::numeric::interval<mp_test_type>, bounded_array" << std::endl;
  117. test_my_matrix_vector<ublas::vector<boost::numeric::interval<mp_test_type>, ublas::bounded_array<boost::numeric::interval<mp_test_type>, 3> >,
  118. 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>()();
  119. #endif
  120. #ifdef USE_DOUBLE
  121. std::cout << "boost::numeric::interval<double>, bounded_array" << std::endl;
  122. test_my_matrix_vector<ublas::vector<boost::numeric::interval<double>, ublas::bounded_array<boost::numeric::interval<double>, 3> >,
  123. 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>()();
  124. #endif
  125. #endif
  126. #ifdef USE_UNBOUNDED_ARRAY
  127. #ifdef USE_FLOAT
  128. std::cout << "boost::numeric::interval<mp_test_type>, unbounded_array" << std::endl;
  129. test_my_matrix_vector<ublas::vector<boost::numeric::interval<mp_test_type>, ublas::unbounded_array<boost::numeric::interval<mp_test_type> > >,
  130. 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>()();
  131. #endif
  132. #ifdef USE_DOUBLE
  133. std::cout << "boost::numeric::interval<double>, unbounded_array" << std::endl;
  134. test_my_matrix_vector<ublas::vector<boost::numeric::interval<double>, ublas::unbounded_array<boost::numeric::interval<double> > >,
  135. ublas::vector_of_vector<boost::numeric::interval<double>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<boost::numeric::interval<double> > > >, 3>()();
  136. #endif
  137. #endif
  138. #ifdef USE_STD_VECTOR
  139. #ifdef USE_FLOAT
  140. std::cout << "boost::numeric::interval<mp_test_type>, std::vector" << std::endl;
  141. test_my_matrix_vector<ublas::vector<boost::numeric::interval<mp_test_type>, std::vector<boost::numeric::interval<mp_test_type> > >,
  142. ublas::vector_of_vector<boost::numeric::interval<mp_test_type>, ublas::row_major, std::vector<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_vector<ublas::vector<boost::numeric::interval<double>, std::vector<boost::numeric::interval<double> > >,
  147. ublas::vector_of_vector<boost::numeric::interval<double>, ublas::row_major, std::vector<std::vector<boost::numeric::interval<double> > > >, 3>()();
  148. #endif
  149. #endif
  150. #endif
  151. }