/* Test program to test find functions of triagular matrices * * author: Gunter Winkler ( guwi17 at gmx dot de ) */ #include #include void assertTrue(const char* message, bool condition) { #ifndef NOMESSAGES std::cout << message; #endif if ( condition ) { std::cout << "1\n"; // success } else { std::cout << "0\n"; // failed } } template < class MAT > void test_iterator( MAT & A ) { #ifndef NOMESSAGES std::cout << "=>"; #endif // check mutable iterators typename MAT::iterator1 it1 = A.begin1(); typename MAT::iterator1 it1_end = A.end1(); for ( ; it1 != it1_end; ++it1 ) { typename MAT::iterator2 it2 = it1.begin(); typename MAT::iterator2 it2_end = it1.end(); for ( ; it2 != it2_end ; ++ it2 ) { #ifndef NOMESSAGES std::cout << "( " << it2.index1() << ", " << it2.index2() << ") " << std::flush; #endif * it2 = ( 10 * it2.index1() + it2.index2() ); } #ifndef NOMESSAGES std::cout << std::endl; #endif } } template < class MAT > void test_iterator2( MAT & A ) { #ifndef NOMESSAGES std::cout << "=>"; #endif // check mutable iterators typename MAT::iterator2 it2 = A.begin2(); typename MAT::iterator2 it2_end = A.end2(); for ( ; it2 != it2_end; ++it2 ) { typename MAT::iterator1 it1 = it2.begin(); typename MAT::iterator1 it1_end = it2.end(); for ( ; it1 != it1_end ; ++ it1 ) { #ifndef NOMESSAGES std::cout << "( " << it1.index1() << ", " << it1.index2() << ") " << std::flush; #endif * it1 = ( 10 * it1.index1() + it1.index2() ); } #ifndef NOMESSAGES std::cout << std::endl; #endif } } template < class MAT > typename MAT::value_type test_iterator3( const MAT & A ) { #ifndef NOMESSAGES std::cout << "=>"; #endif typename MAT::value_type result = 0; // check mutable iterators typename MAT::const_iterator1 it1 = A.begin1(); typename MAT::const_iterator1 it1_end = A.end1(); for ( ; it1 != it1_end; ++it1 ) { typename MAT::const_iterator2 it2 = it1.begin(); typename MAT::const_iterator2 it2_end = it1.end(); for ( ; it2 != it2_end ; ++ it2 ) { #ifndef NOMESSAGES std::cout << "( " << it2.index1() << ", " << it2.index2() << ") " << std::flush; #endif result += * it2; } #ifndef NOMESSAGES std::cout << std::endl; #endif } return result; } int main (int argc, char * argv[]) { using namespace boost::numeric::ublas; typedef double VALUE_TYPE; typedef triangular_matrix LT; typedef triangular_matrix ULT; typedef triangular_matrix SLT; typedef triangular_matrix UT; typedef triangular_matrix UUT; typedef triangular_matrix SUT; LT A(5,5); test_iterator(A); test_iterator2(A); ULT B(5,5); test_iterator(B); test_iterator2(B); SLT C(5,5); test_iterator(C); test_iterator2(C); UT D(5,5); test_iterator(D); test_iterator2(D); UUT E(5,5); test_iterator(E); test_iterator2(E); SUT F(5,5); test_iterator(F); test_iterator2(F); assertTrue("Write access using iterators: ", true); test_iterator3(A); test_iterator3(B); test_iterator3(C); test_iterator3(D); test_iterator3(E); test_iterator3(F); assertTrue("Read access using iterators: ", true); #ifndef NOMESSAGES std::cout << A << B << C << D << E << F << std::endl; #endif typedef matrix MATRIX; MATRIX mat(5,5); triangular_adaptor lta((mat)); triangular_adaptor ulta((mat)); triangular_adaptor slta((mat)); triangular_adaptor uta((mat)); triangular_adaptor uuta((mat)); triangular_adaptor suta((mat)); test_iterator ( lta ); test_iterator2( lta ); test_iterator ( ulta ); test_iterator2( ulta ); test_iterator ( slta ); test_iterator2( slta ); test_iterator ( uta ); test_iterator2( uta ); test_iterator ( uuta ); test_iterator2( uuta ); test_iterator ( suta ); test_iterator2( suta ); assertTrue("Write access using adaptors: ", true); test_iterator3( lta ); test_iterator3( ulta ); test_iterator3( slta ); test_iterator3( uta ); test_iterator3( uuta ); test_iterator3( suta ); assertTrue("Read access using adaptors: ", true); #ifndef NOMESSAGES std::cout << mat << std::endl; #endif return EXIT_SUCCESS; }