| 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 | // check mutable iterators
|
|---|
| 27 | typename MAT::iterator1 it1 = A.begin1();
|
|---|
| 28 | typename MAT::iterator1 it1_end = A.end1();
|
|---|
| 29 |
|
|---|
| 30 | for ( ; it1 != it1_end; ++it1 ) {
|
|---|
| 31 | typename MAT::iterator2 it2 = it1.begin();
|
|---|
| 32 | typename MAT::iterator2 it2_end = it1.end();
|
|---|
| 33 | for ( ; it2 != it2_end ; ++ it2 ) {
|
|---|
| 34 | #ifndef NOMESSAGES
|
|---|
| 35 | std::cout << "( " << it2.index1() << ", " << it2.index2() << ") " << std::flush;
|
|---|
| 36 | #endif
|
|---|
| 37 | * it2 = ( 10 * it2.index1() + it2.index2() );
|
|---|
| 38 | }
|
|---|
| 39 | #ifndef NOMESSAGES
|
|---|
| 40 | std::cout << std::endl;
|
|---|
| 41 | #endif
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | template < class MAT >
|
|---|
| 47 | void test_iterator2( MAT & A ) {
|
|---|
| 48 |
|
|---|
| 49 | // check mutable iterators
|
|---|
| 50 | typename MAT::iterator2 it2 = A.begin2();
|
|---|
| 51 | typename MAT::iterator2 it2_end = A.end2();
|
|---|
| 52 |
|
|---|
| 53 | for ( ; it2 != it2_end; ++it2 ) {
|
|---|
| 54 | typename MAT::iterator1 it1 = it2.begin();
|
|---|
| 55 | typename MAT::iterator1 it1_end = it2.end();
|
|---|
| 56 | for ( ; it1 != it1_end ; ++ it1 ) {
|
|---|
| 57 | #ifndef NOMESSAGES
|
|---|
| 58 | std::cout << "( " << it1.index1() << ", " << it1.index2() << ") " << std::flush;
|
|---|
| 59 | #endif
|
|---|
| 60 | * it1 = ( 10 * it1.index1() + it1.index2() );
|
|---|
| 61 | }
|
|---|
| 62 | #ifndef NOMESSAGES
|
|---|
| 63 | std::cout << std::endl;
|
|---|
| 64 | #endif
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | int main (int argc, char * argv[]) {
|
|---|
| 70 | using namespace boost::numeric::ublas;
|
|---|
| 71 |
|
|---|
| 72 | typedef double VALUE_TYPE;
|
|---|
| 73 | typedef triangular_matrix<VALUE_TYPE, lower> LT;
|
|---|
| 74 | typedef triangular_matrix<VALUE_TYPE, unit_lower> ULT;
|
|---|
| 75 | typedef triangular_matrix<VALUE_TYPE, strict_lower> SLT;
|
|---|
| 76 | typedef triangular_matrix<VALUE_TYPE, upper> UT;
|
|---|
| 77 | typedef triangular_matrix<VALUE_TYPE, unit_upper> UUT;
|
|---|
| 78 | typedef triangular_matrix<VALUE_TYPE, strict_upper> SUT;
|
|---|
| 79 |
|
|---|
| 80 | LT A(5,5);
|
|---|
| 81 |
|
|---|
| 82 | test_iterator(A);
|
|---|
| 83 | test_iterator2(A);
|
|---|
| 84 |
|
|---|
| 85 | ULT B(5,5);
|
|---|
| 86 |
|
|---|
| 87 | test_iterator(B);
|
|---|
| 88 | test_iterator2(B);
|
|---|
| 89 |
|
|---|
| 90 | SLT C(5,5);
|
|---|
| 91 |
|
|---|
| 92 | test_iterator(C);
|
|---|
| 93 | test_iterator2(C);
|
|---|
| 94 |
|
|---|
| 95 | UT D(5,5);
|
|---|
| 96 |
|
|---|
| 97 | test_iterator(D);
|
|---|
| 98 | test_iterator2(D);
|
|---|
| 99 |
|
|---|
| 100 | UUT E(5,5);
|
|---|
| 101 |
|
|---|
| 102 | test_iterator(E);
|
|---|
| 103 | test_iterator2(E);
|
|---|
| 104 |
|
|---|
| 105 | SUT F(5,5);
|
|---|
| 106 |
|
|---|
| 107 | test_iterator(F);
|
|---|
| 108 | test_iterator2(F);
|
|---|
| 109 |
|
|---|
| 110 | assertTrue("Write access using iterators: ", true);
|
|---|
| 111 |
|
|---|
| 112 | #ifndef NOMESSAGES
|
|---|
| 113 | std::cout << A << B << C << D << E << F << std::endl;
|
|---|
| 114 | #endif
|
|---|
| 115 |
|
|---|
| 116 | return EXIT_SUCCESS;
|
|---|
| 117 | }
|
|---|