test72.cpp 7.5 KB

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