| 1 | // |
|---|
| 2 | // Copyright (c) 2000-2002 |
|---|
| 3 | // Joerg Walter, Mathias Koch |
|---|
| 4 | // |
|---|
| 5 | // Permission to use, copy, modify, distribute and sell this software |
|---|
| 6 | // and its documentation for any purpose is hereby granted without fee, |
|---|
| 7 | // provided that the above copyright notice appear in all copies and |
|---|
| 8 | // that both that copyright notice and this permission notice appear |
|---|
| 9 | // in supporting documentation. The authors make no representations |
|---|
| 10 | // about the suitability of this software for any purpose. |
|---|
| 11 | // It is provided "as is" without express or implied warranty. |
|---|
| 12 | // |
|---|
| 13 | // The authors gratefully acknowledge the support of |
|---|
| 14 | // GeNeSys mbH & Co. KG in producing this work. |
|---|
| 15 | // |
|---|
| 16 | |
|---|
| 17 | #include "test7.hpp" |
|---|
| 18 | |
|---|
| 19 | // Test matrix & vector expression templates |
|---|
| 20 | template<class V, class M, int N> |
|---|
| 21 | struct test_my_matrix_vector { |
|---|
| 22 | typedef typename V::value_type value_type; |
|---|
| 23 | |
|---|
| 24 | template<class VP, class MP> |
|---|
| 25 | void test_with (VP &v1, VP &v2, MP &m1) const { |
|---|
| 26 | { |
|---|
| 27 | // Rows and columns |
|---|
| 28 | initialize_matrix (m1); |
|---|
| 29 | for (int i = 0; i < N; ++ i) { |
|---|
| 30 | v1 = ublas::row (m1, i); |
|---|
| 31 | std::cout << "row (m, " << i << ") = " << v1 << std::endl; |
|---|
| 32 | v1 = ublas::column (m1, i); |
|---|
| 33 | std::cout << "column (m, " << i << ") = " << v1 << std::endl; |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | // Outer product |
|---|
| 37 | initialize_vector (v1); |
|---|
| 38 | initialize_vector (v2); |
|---|
| 39 | m1 = ublas::outer_prod (v1, v2); |
|---|
| 40 | std::cout << "outer_prod (v1, v2) = " << m1 << std::endl; |
|---|
| 41 | |
|---|
| 42 | // Matrix vector product |
|---|
| 43 | initialize_matrix (m1); |
|---|
| 44 | initialize_vector (v1); |
|---|
| 45 | v2 = ublas::prod (m1, v1); |
|---|
| 46 | std::cout << "prod (m1, v1) = " << v2 << std::endl; |
|---|
| 47 | v2 = ublas::prod (v1, m1); |
|---|
| 48 | std::cout << "prod (v1, m1) = " << v2 << std::endl; |
|---|
| 49 | } |
|---|
| 50 | } |
|---|
| 51 | void operator () () const { |
|---|
| 52 | { |
|---|
| 53 | V v1 (N), v2 (N); |
|---|
| 54 | M m1 (N, N); |
|---|
| 55 | test_with (v1, v2, m1); |
|---|
| 56 | |
|---|
| 57 | ublas::matrix_row<M> mr1 (m1, 0), mr2 (m1, 1); |
|---|
| 58 | test_with (mr1, mr2, m1); |
|---|
| 59 | |
|---|
| 60 | ublas::matrix_column<M> mc1 (m1, 0), mc2 (m1, 1); |
|---|
| 61 | test_with (mc1, mc2, m1); |
|---|
| 62 | |
|---|
| 63 | #ifdef USE_RANGE |
|---|
| 64 | ublas::matrix_vector_range<M> mvr1 (m1, ublas::range (0, N), ublas::range (0, N)), |
|---|
| 65 | mvr2 (m1, ublas::range (0, N), ublas::range (0, N)); |
|---|
| 66 | test_with (mvr1, mvr2, m1); |
|---|
| 67 | #endif |
|---|
| 68 | |
|---|
| 69 | #ifdef USE_SLICE |
|---|
| 70 | ublas::matrix_vector_slice<M> mvs1 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), |
|---|
| 71 | mvs2 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); |
|---|
| 72 | test_with (mvs1, mvs2, m1); |
|---|
| 73 | #endif |
|---|
| 74 | } |
|---|
| 75 | } |
|---|
| 76 | }; |
|---|
| 77 | |
|---|
| 78 | // Test matrix & vector |
|---|
| 79 | void test_matrix_vector () { |
|---|
| 80 | std::cout << "test_matrix_vector" << std::endl; |
|---|
| 81 | |
|---|
| 82 | #ifdef USE_MATRIX |
|---|
| 83 | #ifdef USE_BOUNDED_ARRAY |
|---|
| 84 | #ifdef USE_FLOAT |
|---|
| 85 | std::cout << "boost::numeric::interval<float>, bounded_array" << std::endl; |
|---|
| 86 | test_my_matrix_vector<ublas::vector<boost::numeric::interval<float>, ublas::bounded_array<boost::numeric::interval<float>, 3> >, |
|---|
| 87 | ublas::matrix<boost::numeric::interval<float>, ublas::row_major, ublas::bounded_array<boost::numeric::interval<float>, 3 * 3> >, 3> () (); |
|---|
| 88 | #endif |
|---|
| 89 | |
|---|
| 90 | #ifdef USE_DOUBLE |
|---|
| 91 | std::cout << "boost::numeric::interval<double>, bounded_array" << std::endl; |
|---|
| 92 | test_my_matrix_vector<ublas::vector<boost::numeric::interval<double>, ublas::bounded_array<boost::numeric::interval<double>, 3> >, |
|---|
| 93 | ublas::matrix<boost::numeric::interval<double>, ublas::row_major, ublas::bounded_array<boost::numeric::interval<double>, 3 * 3> >, 3> () (); |
|---|
| 94 | #endif |
|---|
| 95 | #endif |
|---|
| 96 | |
|---|
| 97 | #ifdef USE_UNBOUNDED_ARRAY |
|---|
| 98 | #ifdef USE_FLOAT |
|---|
| 99 | std::cout << "boost::numeric::interval<float>, unbounded_array" << std::endl; |
|---|
| 100 | test_my_matrix_vector<ublas::vector<boost::numeric::interval<float>, ublas::unbounded_array<boost::numeric::interval<float> > >, |
|---|
| 101 | ublas::matrix<boost::numeric::interval<float>, ublas::row_major, ublas::unbounded_array<boost::numeric::interval<float> > >, 3> () (); |
|---|
| 102 | #endif |
|---|
| 103 | |
|---|
| 104 | #ifdef USE_DOUBLE |
|---|
| 105 | std::cout << "boost::numeric::interval<double>, unbounded_array" << std::endl; |
|---|
| 106 | test_my_matrix_vector<ublas::vector<boost::numeric::interval<double>, ublas::unbounded_array<boost::numeric::interval<double> > >, |
|---|
| 107 | ublas::matrix<boost::numeric::interval<double>, ublas::row_major, ublas::unbounded_array<boost::numeric::interval<double> > >, 3> () (); |
|---|
| 108 | #endif |
|---|
| 109 | #endif |
|---|
| 110 | |
|---|
| 111 | #ifdef USE_STD_VECTOR |
|---|
| 112 | #ifdef USE_FLOAT |
|---|
| 113 | std::cout << "boost::numeric::interval<float>, std::vector" << std::endl; |
|---|
| 114 | test_my_matrix_vector<ublas::vector<boost::numeric::interval<float>, std::vector<boost::numeric::interval<float> > >, |
|---|
| 115 | ublas::matrix<boost::numeric::interval<float>, ublas::row_major, std::vector<boost::numeric::interval<float> > >, 3> () (); |
|---|
| 116 | #endif |
|---|
| 117 | |
|---|
| 118 | #ifdef USE_DOUBLE |
|---|
| 119 | std::cout << "boost::numeric::interval<double>, std::vector" << std::endl; |
|---|
| 120 | test_my_matrix_vector<ublas::vector<boost::numeric::interval<double>, std::vector<boost::numeric::interval<double> > >, |
|---|
| 121 | ublas::matrix<boost::numeric::interval<double>, ublas::row_major, std::vector<boost::numeric::interval<double> > >, 3> () (); |
|---|
| 122 | #endif |
|---|
| 123 | #endif |
|---|
| 124 | #endif |
|---|
| 125 | |
|---|
| 126 | #ifdef USE_VECTOR_OF_VECTOR |
|---|
| 127 | #ifdef USE_BOUNDED_ARRAY |
|---|
| 128 | #ifdef USE_FLOAT |
|---|
| 129 | std::cout << "boost::numeric::interval<float>, bounded_array" << std::endl; |
|---|
| 130 | test_my_matrix_vector<ublas::vector<boost::numeric::interval<float>, ublas::bounded_array<boost::numeric::interval<float>, 3> >, |
|---|
| 131 | 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> () (); |
|---|
| 132 | #endif |
|---|
| 133 | |
|---|
| 134 | #ifdef USE_DOUBLE |
|---|
| 135 | std::cout << "boost::numeric::interval<double>, bounded_array" << std::endl; |
|---|
| 136 | test_my_matrix_vector<ublas::vector<boost::numeric::interval<double>, ublas::bounded_array<boost::numeric::interval<double>, 3> >, |
|---|
| 137 | 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> () (); |
|---|
| 138 | #endif |
|---|
| 139 | #endif |
|---|
| 140 | |
|---|
| 141 | #ifdef USE_UNBOUNDED_ARRAY |
|---|
| 142 | #ifdef USE_FLOAT |
|---|
| 143 | std::cout << "boost::numeric::interval<float>, unbounded_array" << std::endl; |
|---|
| 144 | test_my_matrix_vector<ublas::vector<boost::numeric::interval<float>, ublas::unbounded_array<boost::numeric::interval<float> > >, |
|---|
| 145 | ublas::vector_of_vector<boost::numeric::interval<float>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<boost::numeric::interval<float> > > >, 3> () (); |
|---|
| 146 | #endif |
|---|
| 147 | |
|---|
| 148 | #ifdef USE_DOUBLE |
|---|
| 149 | std::cout << "boost::numeric::interval<double>, unbounded_array" << std::endl; |
|---|
| 150 | test_my_matrix_vector<ublas::vector<boost::numeric::interval<double>, ublas::unbounded_array<boost::numeric::interval<double> > >, |
|---|
| 151 | ublas::vector_of_vector<boost::numeric::interval<double>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<boost::numeric::interval<double> > > >, 3> () (); |
|---|
| 152 | #endif |
|---|
| 153 | #endif |
|---|
| 154 | |
|---|
| 155 | #ifdef USE_STD_VECTOR |
|---|
| 156 | #ifdef USE_FLOAT |
|---|
| 157 | std::cout << "boost::numeric::interval<float>, std::vector" << std::endl; |
|---|
| 158 | test_my_matrix_vector<ublas::vector<boost::numeric::interval<float>, std::vector<boost::numeric::interval<float> > >, |
|---|
| 159 | ublas::vector_of_vector<boost::numeric::interval<float>, ublas::row_major, std::vector<std::vector<boost::numeric::interval<float> > > >, 3> () (); |
|---|
| 160 | #endif |
|---|
| 161 | |
|---|
| 162 | #ifdef USE_DOUBLE |
|---|
| 163 | std::cout << "boost::numeric::interval<double>, std::vector" << std::endl; |
|---|
| 164 | test_my_matrix_vector<ublas::vector<boost::numeric::interval<double>, std::vector<boost::numeric::interval<double> > >, |
|---|
| 165 | ublas::vector_of_vector<boost::numeric::interval<double>, ublas::row_major, std::vector<std::vector<boost::numeric::interval<double> > > >, 3> () (); |
|---|
| 166 | #endif |
|---|
| 167 | #endif |
|---|
| 168 | #endif |
|---|
| 169 | } |
|---|