Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51763 - in trunk/libs/numeric/ublas/test: . common
From: guwi17_at_[hidden]
Date: 2009-03-13 16:57:53


Author: guwi17
Date: 2009-03-13 16:57:52 EDT (Fri, 13 Mar 2009)
New Revision: 51763
URL: http://svn.boost.org/trac/boost/changeset/51763

Log:
test_lu.cpp: added copyright header
triangular_access.cpp: tests constant and mutable iterators over triangular matrices
triangular_layout.cpp: tests storage layout of symmetric and triangular matrices
common/testhelper.hpp: added more common helper functions for tests
Jamfile.v2: added new unit tests

Added:
   trunk/libs/numeric/ublas/test/triangular_access.cpp (contents, props changed)
   trunk/libs/numeric/ublas/test/triangular_layout.cpp (contents, props changed)
Text files modified:
   trunk/libs/numeric/ublas/test/Jamfile.v2 | 6 ++++++
   trunk/libs/numeric/ublas/test/common/testhelper.hpp | 17 +++++++++++++++++
   trunk/libs/numeric/ublas/test/test_lu.cpp | 5 +++++
   3 files changed, 28 insertions(+), 0 deletions(-)

Modified: trunk/libs/numeric/ublas/test/Jamfile.v2
==============================================================================
--- trunk/libs/numeric/ublas/test/Jamfile.v2 (original)
+++ trunk/libs/numeric/ublas/test/Jamfile.v2 2009-03-13 16:57:52 EDT (Fri, 13 Mar 2009)
@@ -108,4 +108,10 @@
       ]
       [ run test_lu.cpp
       ]
+ [ run triangular_access.cpp
+ : : :
+ <define>NOMESSAGES
+ ]
+ [ run triangular_layout.cpp
+ ]
     ;

Modified: trunk/libs/numeric/ublas/test/common/testhelper.hpp
==============================================================================
--- trunk/libs/numeric/ublas/test/common/testhelper.hpp (original)
+++ trunk/libs/numeric/ublas/test/common/testhelper.hpp 2009-03-13 16:57:52 EDT (Fri, 13 Mar 2009)
@@ -26,6 +26,23 @@
   }
 }
 
+template < class T >
+void assertEquals(const char* message, T expected, T actual) {
+#ifndef NOMESSAGES
+ std::cout << message;
+#endif
+ if ( expected == actual ) {
+ ++ _success_counter;
+ std::cout << "1\n"; // success
+ } else {
+ #ifndef NOMESSAGES
+ std::cout << " expected " << expected << " actual " << actual << " ";
+ #endif
+ ++ _fail_counter;
+ std::cout << "0\n"; // failed
+ }
+}
+
 static
 std::pair<unsigned, unsigned> getResults() {
   return std::make_pair(_success_counter, _fail_counter);

Modified: trunk/libs/numeric/ublas/test/test_lu.cpp
==============================================================================
--- trunk/libs/numeric/ublas/test/test_lu.cpp (original)
+++ trunk/libs/numeric/ublas/test/test_lu.cpp 2009-03-13 16:57:52 EDT (Fri, 13 Mar 2009)
@@ -1,3 +1,8 @@
+// Copyright 2008 Gunter Winkler <guwi17_at_[hidden]>
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
 // switch automatic singular check off
 #define BOOST_UBLAS_TYPE_CHECK 0
 

Added: trunk/libs/numeric/ublas/test/triangular_access.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/numeric/ublas/test/triangular_access.cpp 2009-03-13 16:57:52 EDT (Fri, 13 Mar 2009)
@@ -0,0 +1,201 @@
+/* Test program to test find functions of triagular matrices
+ *
+ * author: Gunter Winkler ( guwi17 at gmx dot de )
+ */
+// Copyright 2008 Gunter Winkler <guwi17_at_[hidden]>
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+
+#include <boost/numeric/ublas/triangular.hpp>
+#include <boost/numeric/ublas/io.hpp>
+#include <boost/cstdlib.hpp>
+
+#include "common/testhelper.hpp"
+
+
+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<VALUE_TYPE, lower> LT;
+ typedef triangular_matrix<VALUE_TYPE, unit_lower> ULT;
+ typedef triangular_matrix<VALUE_TYPE, strict_lower> SLT;
+ typedef triangular_matrix<VALUE_TYPE, upper> UT;
+ typedef triangular_matrix<VALUE_TYPE, unit_upper> UUT;
+ typedef triangular_matrix<VALUE_TYPE, strict_upper> 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);
+
+ assertEquals(" LT: ",420.0,test_iterator3(A));
+ assertEquals("ULT: ",315.0,test_iterator3(B));
+ assertEquals("SLT: ",310.0,test_iterator3(C));
+ assertEquals(" UT: ",240.0,test_iterator3(D));
+ assertEquals("UUT: ",135.0,test_iterator3(E));
+ assertEquals("SUT: ",130.0,test_iterator3(F));
+
+ assertTrue("Read access using iterators: ", true);
+
+#ifndef NOMESSAGES
+ std::cout << A << B << C << D << E << F << std::endl;
+#endif
+
+ typedef matrix<VALUE_TYPE> MATRIX;
+ MATRIX mat(5,5);
+ triangular_adaptor<MATRIX, lower> lta((mat));
+ triangular_adaptor<MATRIX, unit_lower> ulta((mat));
+ triangular_adaptor<MATRIX, strict_lower> slta((mat));
+ triangular_adaptor<MATRIX, upper> uta((mat));
+ triangular_adaptor<MATRIX, unit_upper> uuta((mat));
+ triangular_adaptor<MATRIX, strict_upper> 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);
+
+ assertEquals(" LTA: ",420.0,test_iterator3( lta ));
+ assertEquals("ULTA: ",315.0,test_iterator3( ulta ));
+ assertEquals("SLTA: ",310.0,test_iterator3( slta ));
+
+ assertEquals(" UTA: ",240.0,test_iterator3( uta ));
+ assertEquals("UUTA: ",135.0,test_iterator3( uuta ));
+ assertEquals("SUTA: ",130.0,test_iterator3( suta ));
+
+ assertTrue("Read access using adaptors: ", true);
+
+#ifndef NOMESSAGES
+ std::cout << mat << std::endl;
+#endif
+
+ return (getResults().second > 0) ? boost::exit_failure : boost::exit_success;
+}

Added: trunk/libs/numeric/ublas/test/triangular_layout.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/numeric/ublas/test/triangular_layout.cpp 2009-03-13 16:57:52 EDT (Fri, 13 Mar 2009)
@@ -0,0 +1,139 @@
+// Copyright 2008 Gunter Winkler <guwi17_at_[hidden]>
+// Thanks to Tiago Requeijo for providing this test
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <iostream>
+#include <boost/numeric/ublas/symmetric.hpp>
+#include <boost/numeric/ublas/triangular.hpp>
+#include <boost/cstdlib.hpp>
+
+using namespace std;
+namespace ublas = boost::numeric::ublas;
+
+int main(int argc, char* argv[])
+{
+ int sz = 4;
+ ublas::symmetric_matrix<int, ublas::upper, ublas::column_major> UpCol (sz, sz);
+ ublas::symmetric_matrix<int, ublas::upper, ublas::row_major> UpRow (sz, sz);
+ ublas::symmetric_matrix<int, ublas::lower, ublas::column_major> LoCol (sz, sz);
+ ublas::symmetric_matrix<int, ublas::lower, ublas::row_major> LoRow (sz, sz);
+
+ ublas::triangular_matrix<int, ublas::upper, ublas::column_major> TrUpCol (sz, sz);
+ ublas::triangular_matrix<int, ublas::upper, ublas::row_major> TrUpRow (sz, sz);
+ ublas::triangular_matrix<int, ublas::lower, ublas::column_major> TrLoCol (sz, sz);
+ ublas::triangular_matrix<int, ublas::lower, ublas::row_major> TrLoRow (sz, sz);
+
+ for(int i=0; i<sz; ++i)
+ for(int j=i; j<sz; ++j)
+ {
+ // Symmetric
+ UpCol(i,j) = 10*i + j;
+ UpRow(i,j) = 10*i + j;
+ LoCol(i,j) = 10*i + j;
+ LoRow(i,j) = 10*i + j;
+ // Triangular
+ TrUpCol(i,j) = 10*i + j;
+ TrUpRow(i,j) = 10*i + j;
+ TrLoCol(j,i) = 10*i + j;
+ TrLoRow(j,i) = 10*i + j;
+ }
+
+ //get pointers to data
+ int* uc = &(UpCol.data()[0]);
+ int* ur = &(UpRow.data()[0]);
+ int* lc = &(LoCol.data()[0]);
+ int* lr = &(LoRow.data()[0]);
+ int* tuc = &(TrUpCol.data()[0]);
+ int* tur = &(TrUpRow.data()[0]);
+ int* tlc = &(TrLoCol.data()[0]);
+ int* tlr = &(TrLoRow.data()[0]);
+
+ // upper, column_major
+ // storage should be: 0 1 11 2 12 22 3 13 23 33
+ int uc_correct[] = {0, 1, 11, 2, 12, 22, 3, 13, 23, 33};
+
+ // upper, row_major
+ // storage should be: 0 1 2 3 11 12 13 22 23 33
+ int ur_correct[] = {0, 1, 2, 3, 11, 12, 13, 22, 23, 33};
+
+ // lower, column_major
+ // storage should be: 0 1 2 3 11 12 13 22 23 33
+ int lc_correct[] = {0, 1, 2, 3, 11, 12, 13, 22, 23, 33};
+
+ // lower, row_major
+ // storage should be: 0 1 11 2 12 22 3 13 23 33
+ int lr_correct[] = {0, 1, 11, 2, 12, 22, 3, 13, 23, 33};
+
+ bool success = true;
+
+ // Test Symmetric
+ for(int i=0; i<sz*(sz+1)/2; ++i)
+ if(uc[i] != uc_correct[i])
+ {
+ cout << "Storage error (Symmetric, Upper, Column major)" << endl;
+ success = false;
+ break;
+ }
+
+ for(int i=0; i<sz*(sz+1)/2; ++i)
+ if(ur[i] != ur_correct[i])
+ {
+ cout << "Storage error (Symmetric, Upper, Row major)" << endl;
+ success = false;
+ break;
+ }
+
+ for(int i=0; i<sz*(sz+1)/2; ++i)
+ if(lc[i] != lc_correct[i])
+ {
+ cout << "Storage error (Symmetric, Lower, Column major)" << endl;
+ success = false;
+ break;
+ }
+
+ for(int i=0; i<sz*(sz+1)/2; ++i)
+ if(lr[i] != lr_correct[i])
+ {
+ cout << "Storage error (Symmetric, Lower, Row major)" << endl;
+ success = false;
+ break;
+ }
+
+ // Test Triangular
+ for(int i=0; i<sz*(sz+1)/2; ++i)
+ if(tuc[i] != uc_correct[i])
+ {
+ cout << "Storage error (Triangular, Upper, Column major)" << endl;
+ success = false;
+ break;
+ }
+
+ for(int i=0; i<sz*(sz+1)/2; ++i)
+ if(tur[i] != ur_correct[i])
+ {
+ cout << "Storage error (Triangular, Upper, Row major)" << endl;
+ success = false;
+ break;
+ }
+
+ for(int i=0; i<sz*(sz+1)/2; ++i)
+ if(tlc[i] != lc_correct[i])
+ {
+ cout << "Storage error (Triangular, Lower, Column major)" << endl;
+ success = false;
+ break;
+ }
+
+ for(int i=0; i<sz*(sz+1)/2; ++i)
+ if(tlr[i] != lr_correct[i])
+ {
+ cout << "Storage error (Triangular, Lower, Row major)" << endl;
+ success = false;
+ break;
+ }
+
+
+ return (success)?boost::exit_success:boost::exit_failure;
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk