/* 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 ) { // 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 ) { // 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 } } 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); #ifndef NOMESSAGES std::cout << A << B << C << D << E << F << std::endl; #endif return EXIT_SUCCESS; }