test71.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // Copyright (c) 2000-2002
  2. // Joerg Walter, Mathias Koch
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // The authors gratefully acknowledge the support of
  9. // GeNeSys mbH & Co. KG in producing this work.
  10. //
  11. //
  12. // This file fails to compile - appears to be a known uBlas issue :-(
  13. //
  14. #if defined(__GNUC__) && (__GNUC__ >= 9)
  15. #pragma GCC diagnostic ignored "-Wdeprecated-copy"
  16. #endif
  17. #include "test7.hpp"
  18. // Test vector expression templates
  19. template <class V, int N>
  20. struct test_my_vector
  21. {
  22. typedef typename V::value_type value_type;
  23. typedef typename V::size_type size_type;
  24. typedef typename ublas::type_traits<value_type>::real_type real_type;
  25. template <class VP>
  26. void test_with(VP& v1, VP& v2, VP& v3) const
  27. {
  28. {
  29. value_type t;
  30. size_type i;
  31. real_type n;
  32. // Copy and swap
  33. initialize_vector(v1);
  34. initialize_vector(v2);
  35. v1 = v2;
  36. std::cout << "v1 = v2 = " << v1 << std::endl;
  37. v1.assign_temporary(v2);
  38. std::cout << "v1.assign_temporary (v2) = " << v1 << std::endl;
  39. v1.swap(v2);
  40. std::cout << "v1.swap (v2) = " << v1 << " " << v2 << std::endl;
  41. // Zero assignment
  42. v1 = ublas::zero_vector<value_type>(v1.size());
  43. std::cout << "v1.zero_vector = " << v1 << std::endl;
  44. v1 = v2;
  45. // Unary vector operations resulting in a vector
  46. initialize_vector(v1);
  47. v2 = -v1;
  48. std::cout << "- v1 = " << v2 << std::endl;
  49. v2 = ublas::conj(v1);
  50. std::cout << "conj (v1) = " << v2 << std::endl;
  51. // Binary vector operations resulting in a vector
  52. initialize_vector(v1);
  53. initialize_vector(v2);
  54. v3 = v1 + v2;
  55. std::cout << "v1 + v2 = " << v3 << std::endl;
  56. v3 = v1 - v2;
  57. std::cout << "v1 - v2 = " << v3 << std::endl;
  58. // Scaling a vector
  59. t = value_type(N);
  60. initialize_vector(v1);
  61. v2 = value_type(1.) * v1;
  62. std::cout << "1. * v1 = " << v2 << std::endl;
  63. // v2 = t * v1;
  64. std::cout << "N * v1 = " << v2 << std::endl;
  65. initialize_vector(v1);
  66. // v2 = v1 * value_type (1.);
  67. std::cout << "v1 * 1. = " << v2 << std::endl;
  68. // v2 = v1 * t;
  69. std::cout << "v1 * N = " << v2 << std::endl;
  70. // Some assignments
  71. initialize_vector(v1);
  72. initialize_vector(v2);
  73. v2 += v1;
  74. std::cout << "v2 += v1 = " << v2 << std::endl;
  75. v2 -= v1;
  76. std::cout << "v2 -= v1 = " << v2 << std::endl;
  77. v2 = v2 + v1;
  78. std::cout << "v2 = v2 + v1 = " << v2 << std::endl;
  79. v2 = v2 - v1;
  80. std::cout << "v2 = v2 - v1 = " << v2 << std::endl;
  81. v1 *= value_type(1.);
  82. std::cout << "v1 *= 1. = " << v1 << std::endl;
  83. v1 *= t;
  84. std::cout << "v1 *= N = " << v1 << std::endl;
  85. // Unary vector operations resulting in a scalar
  86. initialize_vector(v1);
  87. t = ublas::sum(v1);
  88. std::cout << "sum (v1) = " << t << std::endl;
  89. n = ublas::norm_1(v1);
  90. std::cout << "norm_1 (v1) = " << n << std::endl;
  91. n = ublas::norm_2(v1);
  92. std::cout << "norm_2 (v1) = " << n << std::endl;
  93. n = ublas::norm_inf(v1);
  94. std::cout << "norm_inf (v1) = " << n << std::endl;
  95. i = ublas::index_norm_inf(v1);
  96. std::cout << "index_norm_inf (v1) = " << i << std::endl;
  97. // Binary vector operations resulting in a scalar
  98. initialize_vector(v1);
  99. initialize_vector(v2);
  100. t = ublas::inner_prod(v1, v2);
  101. std::cout << "inner_prod (v1, v2) = " << t << std::endl;
  102. }
  103. }
  104. void operator()() const
  105. {
  106. {
  107. V v1(N), v2(N), v3(N);
  108. test_with(v1, v2, v3);
  109. #ifdef USE_RANGE
  110. ublas::vector_range<V> vr1(v1, ublas::range(0, N)),
  111. vr2(v2, ublas::range(0, N)),
  112. vr3(v3, ublas::range(0, N));
  113. test_with(vr1, vr2, vr3);
  114. #endif
  115. #ifdef USE_SLICE
  116. ublas::vector_slice<V> vs1(v1, ublas::slice(0, 1, N)),
  117. vs2(v2, ublas::slice(0, 1, N)),
  118. vs3(v3, ublas::slice(0, 1, N));
  119. test_with(vs1, vs2, vs3);
  120. #endif
  121. }
  122. }
  123. };
  124. // Test vector
  125. void test_vector()
  126. {
  127. std::cout << "test_vector" << std::endl;
  128. #ifdef USE_BOUNDED_ARRAY
  129. #ifdef USE_FLOAT
  130. std::cout << "boost::numeric::interval<mp_test_type>, bounded_array" << std::endl;
  131. test_my_vector<ublas::vector<boost::numeric::interval<mp_test_type>, ublas::bounded_array<boost::numeric::interval<mp_test_type>, 3> >, 3>()();
  132. #endif
  133. #ifdef USE_DOUBLE
  134. std::cout << "boost::numeric::interval<double>, bounded_array" << std::endl;
  135. test_my_vector<ublas::vector<boost::numeric::interval<double>, ublas::bounded_array<boost::numeric::interval<double>, 3> >, 3>()();
  136. #endif
  137. #endif
  138. #ifdef USE_UNBOUNDED_ARRAY
  139. #ifdef USE_FLOAT
  140. std::cout << "boost::numeric::interval<mp_test_type>, unbounded_array" << std::endl;
  141. test_my_vector<ublas::vector<boost::numeric::interval<mp_test_type>, ublas::unbounded_array<boost::numeric::interval<mp_test_type> > >, 3>()();
  142. #endif
  143. #ifdef USE_DOUBLE
  144. std::cout << "boost::numeric::interval<double>, unbounded_array" << std::endl;
  145. test_my_vector<ublas::vector<boost::numeric::interval<double>, ublas::unbounded_array<boost::numeric::interval<double> > >, 3>()();
  146. #endif
  147. #endif
  148. #ifdef USE_STD_VECTOR
  149. #ifdef USE_FLOAT
  150. std::cout << "boost::numeric::interval<mp_test_type>, std::vector" << std::endl;
  151. test_my_vector<ublas::vector<boost::numeric::interval<mp_test_type>, std::vector<boost::numeric::interval<mp_test_type> > >, 3>()();
  152. #endif
  153. #ifdef USE_DOUBLE
  154. std::cout << "boost::numeric::interval<double>, std::vector" << std::endl;
  155. test_my_vector<ublas::vector<boost::numeric::interval<double>, std::vector<boost::numeric::interval<double> > >, 3>()();
  156. #endif
  157. #endif
  158. }