| 1 | /* Test program to test find functions of triagular matrices
|
|---|
| 2 | *
|
|---|
| 3 | * author: Gunter Winkler ( guwi17 at gmx dot de )
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 | #include <boost/numeric/ublas/triangular.hpp>
|
|---|
| 8 | #include <boost/numeric/ublas/io.hpp>
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 | void assertTrue(const char* message, bool condition) {
|
|---|
| 13 | #ifndef NOMESSAGES
|
|---|
| 14 | std::cout << message;
|
|---|
| 15 | #endif
|
|---|
| 16 | if ( condition ) {
|
|---|
| 17 | std::cout << "1\n"; // success
|
|---|
| 18 | } else {
|
|---|
| 19 | std::cout << "0\n"; // failed
|
|---|
| 20 | }
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | template < class MAT >
|
|---|
| 24 | void test_iterator( MAT & A ) {
|
|---|
| 25 |
|
|---|
| 26 | #ifndef NOMESSAGES
|
|---|
| 27 | std::cout << "=>";
|
|---|
| 28 | #endif
|
|---|
| 29 | // check mutable iterators
|
|---|
| 30 | typename MAT::iterator1 it1 = A.begin1();
|
|---|
| 31 | typename MAT::iterator1 it1_end = A.end1();
|
|---|
| 32 |
|
|---|
| 33 | for ( ; it1 != it1_end; ++it1 ) {
|
|---|
| 34 | typename MAT::iterator2 it2 = it1.begin();
|
|---|
| 35 | typename MAT::iterator2 it2_end = it1.end();
|
|---|
| 36 | for ( ; it2 != it2_end ; ++ it2 ) {
|
|---|
| 37 | #ifndef NOMESSAGES
|
|---|
| 38 | std::cout << "( " << it2.index1() << ", " << it2.index2() << ") " << std::flush;
|
|---|
| 39 | #endif
|
|---|
| 40 | * it2 = ( 10 * it2.index1() + it2.index2() );
|
|---|
| 41 | }
|
|---|
| 42 | #ifndef NOMESSAGES
|
|---|
| 43 | std::cout << std::endl;
|
|---|
| 44 | #endif
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | template < class MAT >
|
|---|
| 50 | void test_iterator2( MAT & A ) {
|
|---|
| 51 |
|
|---|
| 52 | #ifndef NOMESSAGES
|
|---|
| 53 | std::cout << "=>";
|
|---|
| 54 | #endif
|
|---|
| 55 | // check mutable iterators
|
|---|
| 56 | typename MAT::iterator2 it2 = A.begin2();
|
|---|
| 57 | typename MAT::iterator2 it2_end = A.end2();
|
|---|
| 58 |
|
|---|
| 59 | for ( ; it2 != it2_end; ++it2 ) {
|
|---|
| 60 | typename MAT::iterator1 it1 = it2.begin();
|
|---|
| 61 | typename MAT::iterator1 it1_end = it2.end();
|
|---|
| 62 | for ( ; it1 != it1_end ; ++ it1 ) {
|
|---|
| 63 | #ifndef NOMESSAGES
|
|---|
| 64 | std::cout << "( " << it1.index1() << ", " << it1.index2() << ") " << std::flush;
|
|---|
| 65 | #endif
|
|---|
| 66 | * it1 = ( 10 * it1.index1() + it1.index2() );
|
|---|
| 67 | }
|
|---|
| 68 | #ifndef NOMESSAGES
|
|---|
| 69 | std::cout << std::endl;
|
|---|
| 70 | #endif
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | template < class MAT >
|
|---|
| 76 | typename MAT::value_type
|
|---|
| 77 | test_iterator3( const MAT & A ) {
|
|---|
| 78 |
|
|---|
| 79 | #ifndef NOMESSAGES
|
|---|
| 80 | std::cout << "=>";
|
|---|
| 81 | #endif
|
|---|
| 82 | typename MAT::value_type result = 0;
|
|---|
| 83 |
|
|---|
| 84 | // check mutable iterators
|
|---|
| 85 | typename MAT::const_iterator1 it1 = A.begin1();
|
|---|
| 86 | typename MAT::const_iterator1 it1_end = A.end1();
|
|---|
| 87 |
|
|---|
| 88 | for ( ; it1 != it1_end; ++it1 ) {
|
|---|
| 89 | typename MAT::const_iterator2 it2 = it1.begin();
|
|---|
| 90 | typename MAT::const_iterator2 it2_end = it1.end();
|
|---|
| 91 | for ( ; it2 != it2_end ; ++ it2 ) {
|
|---|
| 92 | #ifndef NOMESSAGES
|
|---|
| 93 | std::cout << "( " << it2.index1() << ", " << it2.index2() << ") " << std::flush;
|
|---|
| 94 | #endif
|
|---|
| 95 | result += * it2;
|
|---|
| 96 | }
|
|---|
| 97 | #ifndef NOMESSAGES
|
|---|
| 98 | std::cout << std::endl;
|
|---|
| 99 | #endif
|
|---|
| 100 | }
|
|---|
| 101 | return result;
|
|---|
| 102 |
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 | int main (int argc, char * argv[]) {
|
|---|
| 107 | using namespace boost::numeric::ublas;
|
|---|
| 108 |
|
|---|
| 109 | typedef double VALUE_TYPE;
|
|---|
| 110 | typedef triangular_matrix<VALUE_TYPE, lower> LT;
|
|---|
| 111 | typedef triangular_matrix<VALUE_TYPE, unit_lower> ULT;
|
|---|
| 112 | typedef triangular_matrix<VALUE_TYPE, strict_lower> SLT;
|
|---|
| 113 | typedef triangular_matrix<VALUE_TYPE, upper> UT;
|
|---|
| 114 | typedef triangular_matrix<VALUE_TYPE, unit_upper> UUT;
|
|---|
| 115 | typedef triangular_matrix<VALUE_TYPE, strict_upper> SUT;
|
|---|
| 116 |
|
|---|
| 117 | LT A(5,5);
|
|---|
| 118 |
|
|---|
| 119 | test_iterator(A);
|
|---|
| 120 | test_iterator2(A);
|
|---|
| 121 |
|
|---|
| 122 | ULT B(5,5);
|
|---|
| 123 |
|
|---|
| 124 | test_iterator(B);
|
|---|
| 125 | test_iterator2(B);
|
|---|
| 126 |
|
|---|
| 127 | SLT C(5,5);
|
|---|
| 128 |
|
|---|
| 129 | test_iterator(C);
|
|---|
| 130 | test_iterator2(C);
|
|---|
| 131 |
|
|---|
| 132 | UT D(5,5);
|
|---|
| 133 |
|
|---|
| 134 | test_iterator(D);
|
|---|
| 135 | test_iterator2(D);
|
|---|
| 136 |
|
|---|
| 137 | UUT E(5,5);
|
|---|
| 138 |
|
|---|
| 139 | test_iterator(E);
|
|---|
| 140 | test_iterator2(E);
|
|---|
| 141 |
|
|---|
| 142 | SUT F(5,5);
|
|---|
| 143 |
|
|---|
| 144 | test_iterator(F);
|
|---|
| 145 | test_iterator2(F);
|
|---|
| 146 |
|
|---|
| 147 | assertTrue("Write access using iterators: ", true);
|
|---|
| 148 |
|
|---|
| 149 | test_iterator3(A);
|
|---|
| 150 | test_iterator3(B);
|
|---|
| 151 | test_iterator3(C);
|
|---|
| 152 | test_iterator3(D);
|
|---|
| 153 | test_iterator3(E);
|
|---|
| 154 | test_iterator3(F);
|
|---|
| 155 |
|
|---|
| 156 | assertTrue("Read access using iterators: ", true);
|
|---|
| 157 |
|
|---|
| 158 | #ifndef NOMESSAGES
|
|---|
| 159 | std::cout << A << B << C << D << E << F << std::endl;
|
|---|
| 160 | #endif
|
|---|
| 161 |
|
|---|
| 162 | typedef matrix<VALUE_TYPE> MATRIX;
|
|---|
| 163 | MATRIX mat(5,5);
|
|---|
| 164 | triangular_adaptor<MATRIX, lower> lta((mat));
|
|---|
| 165 | triangular_adaptor<MATRIX, unit_lower> ulta((mat));
|
|---|
| 166 | triangular_adaptor<MATRIX, strict_lower> slta((mat));
|
|---|
| 167 | triangular_adaptor<MATRIX, upper> uta((mat));
|
|---|
| 168 | triangular_adaptor<MATRIX, unit_upper> uuta((mat));
|
|---|
| 169 | triangular_adaptor<MATRIX, strict_upper> suta((mat));
|
|---|
| 170 |
|
|---|
| 171 | test_iterator ( lta );
|
|---|
| 172 | test_iterator2( lta );
|
|---|
| 173 |
|
|---|
| 174 | test_iterator ( ulta );
|
|---|
| 175 | test_iterator2( ulta );
|
|---|
| 176 |
|
|---|
| 177 | test_iterator ( slta );
|
|---|
| 178 | test_iterator2( slta );
|
|---|
| 179 |
|
|---|
| 180 | test_iterator ( uta );
|
|---|
| 181 | test_iterator2( uta );
|
|---|
| 182 |
|
|---|
| 183 | test_iterator ( uuta );
|
|---|
| 184 | test_iterator2( uuta );
|
|---|
| 185 |
|
|---|
| 186 | test_iterator ( suta );
|
|---|
| 187 | test_iterator2( suta );
|
|---|
| 188 |
|
|---|
| 189 | assertTrue("Write access using adaptors: ", true);
|
|---|
| 190 |
|
|---|
| 191 | test_iterator3( lta );
|
|---|
| 192 | test_iterator3( ulta );
|
|---|
| 193 | test_iterator3( slta );
|
|---|
| 194 |
|
|---|
| 195 | test_iterator3( uta );
|
|---|
| 196 | test_iterator3( uuta );
|
|---|
| 197 | test_iterator3( suta );
|
|---|
| 198 |
|
|---|
| 199 | assertTrue("Read access using adaptors: ", true);
|
|---|
| 200 |
|
|---|
| 201 | #ifndef NOMESSAGES
|
|---|
| 202 | std::cout << mat << std::endl;
|
|---|
| 203 | #endif
|
|---|
| 204 |
|
|---|
| 205 | return EXIT_SUCCESS;
|
|---|
| 206 | }
|
|---|