Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52147 - in branches/release/libs/numeric/ublas: doc doc/samples test test/common
From: guwi17_at_[hidden]
Date: 2009-04-02 18:36:42


Author: guwi17
Date: 2009-04-02 18:36:39 EDT (Thu, 02 Apr 2009)
New Revision: 52147
URL: http://svn.boost.org/trac/boost/changeset/52147

Log:
ublas/doc/samples/ex_triangular.cpp: added new example
ublas/doc/samples/Jamfile.v2: added build section for ex_triangular
ublas/doc/container_concept.htm: fixed wrong description of array_type
ublas/doc/triangular.htm: fixed lower/upper confusion and added link to ex_triangular

ublas/test/test_lu.cpp: added unit test for LU decomposition
ublas/test/triangular_access.cpp: added unit test for accessing triangular/symmetric matrices
ublas/test/triangular_layout.cpp: added unit test for testing storage layout of triangular/symmetric matrices
ublas/test/common/testhelper.hpp: support routines for new unit tests

ublas/test/CMakeLists.txt: added new tests (still experimental) test_lu, triangular_access. triangular_layout

ublas/test/Jamfile.v2:
  added new tests (still experimental) test_lu, triangular_access. triangular_layout
  disabled broken test7 (maybe a fix of boost::interval is needed, see #2473)

ublas/test/test71.cpp, ublas/test/test73.cpp, ublas/test/test7.cpp:
  added first fixes to support boost::interval as scalar type

ublas/test/common/init.hpp:
  initialize all matrices/vectors with floats instead of (unsigned) ints
  this helps to fix broken test7 for boost::interval

Added:
   branches/release/libs/numeric/ublas/doc/samples/ex_triangular.cpp (contents, props changed)
   branches/release/libs/numeric/ublas/test/common/testhelper.hpp (contents, props changed)
   branches/release/libs/numeric/ublas/test/test_lu.cpp (contents, props changed)
   branches/release/libs/numeric/ublas/test/triangular_access.cpp (contents, props changed)
   branches/release/libs/numeric/ublas/test/triangular_layout.cpp (contents, props changed)
Text files modified:
   branches/release/libs/numeric/ublas/doc/container_concept.htm | 4 ++--
   branches/release/libs/numeric/ublas/doc/samples/Jamfile.v2 | 4 ++++
   branches/release/libs/numeric/ublas/doc/triangular.htm | 6 +++++-
   branches/release/libs/numeric/ublas/test/CMakeLists.txt | 11 ++++++++++-
   branches/release/libs/numeric/ublas/test/Jamfile.v2 | 10 +++++++++-
   branches/release/libs/numeric/ublas/test/common/init.hpp | 6 +++---
   branches/release/libs/numeric/ublas/test/test7.cpp | 2 ++
   branches/release/libs/numeric/ublas/test/test71.cpp | 2 +-
   branches/release/libs/numeric/ublas/test/test73.cpp | 2 +-
   9 files changed, 37 insertions(+), 10 deletions(-)

Modified: branches/release/libs/numeric/ublas/doc/container_concept.htm
==============================================================================
--- branches/release/libs/numeric/ublas/doc/container_concept.htm (original)
+++ branches/release/libs/numeric/ublas/doc/container_concept.htm 2009-04-02 18:36:39 EDT (Thu, 02 Apr 2009)
@@ -110,7 +110,7 @@
 <td>Storage</td>
 <td><code>v.data()</code></td>
 <td><code>v</code> is mutable and Dense.</td>
-<td><code>array_type&amp;</code> if a is mutable, <code>const array_type&amp;</code> otherwise</td>
+<td><code>array_type&amp;</code> if <code>v</code> is mutable, <code>const array_type&amp;</code> otherwise</td>
 </tr>
 </tbody>
 </table>
@@ -307,7 +307,7 @@
 <td>Storage</td>
 <td><code>m.data()</code></td>
 <td><code>m</code> is mutable and Dense.</td>
-<td><code>array_type&amp;</code> if a is mutable, <code>const array_type&amp;</code> otherwise</td>
+<td><code>array_type&amp;</code> if <code>m</code> is mutable, <code>const array_type&amp;</code> otherwise</td>
 </tr>
 </tbody>
 </table>

Modified: branches/release/libs/numeric/ublas/doc/samples/Jamfile.v2
==============================================================================
--- branches/release/libs/numeric/ublas/doc/samples/Jamfile.v2 (original)
+++ branches/release/libs/numeric/ublas/doc/samples/Jamfile.v2 2009-04-02 18:36:39 EDT (Thu, 02 Apr 2009)
@@ -222,3 +222,7 @@
 exe triangular_adaptor
     : triangular_adaptor.cpp
     ;
+
+exe ex_triangular
+ : ex_triangular.cpp
+ ;

Added: branches/release/libs/numeric/ublas/doc/samples/ex_triangular.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/numeric/ublas/doc/samples/ex_triangular.cpp 2009-04-02 18:36:39 EDT (Thu, 02 Apr 2009)
@@ -0,0 +1,58 @@
+// Copyright Gunter Winkler 2004 - 2009.
+// 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/matrix.hpp>
+#include <boost/numeric/ublas/triangular.hpp>
+
+#include <boost/numeric/ublas/io.hpp>
+
+using std::cout;
+using std::endl;
+
+
+
+namespace ublas = boost::numeric::ublas;
+
+
+int main(int argc, char * argv[] ) {
+
+ ublas::matrix<double> M (3, 3);
+ for (std::size_t i=0; i < M.data().size(); ++i) { M.data()[i] = 1+i ; }
+
+ std::cout << "full M = " << M << "\n" ;
+
+ ublas::triangular_matrix<double, ublas::lower> L;
+ ublas::triangular_matrix<double, ublas::unit_lower> UL;
+ ublas::triangular_matrix<double, ublas::strict_lower> SL;
+
+ L = ublas::triangular_adaptor<ublas::matrix<double>, ublas::lower> (M);
+ SL = ublas::triangular_adaptor<ublas::matrix<double>, ublas::strict_lower> (M);
+ UL = ublas::triangular_adaptor<ublas::matrix<double>, ublas::unit_lower> (M);
+
+ std::cout << "lower L = " << L << "\n"
+ << "strict lower SL = " << SL << "\n"
+ << "unit lower UL = " << UL << "\n" ;
+
+ ublas::triangular_matrix<double, ublas::upper> U;
+ ublas::triangular_matrix<double, ublas::unit_upper> UU;
+ ublas::triangular_matrix<double, ublas::strict_upper> SU;
+
+ U = ublas::triangular_adaptor<ublas::matrix<double>, ublas::upper> (M);
+ SU = ublas::triangular_adaptor<ublas::matrix<double>, ublas::strict_upper> (M);
+ UU = ublas::triangular_adaptor<ublas::matrix<double>, ublas::unit_upper> (M);
+
+ std::cout << "upper U = " << U << "\n"
+ << "strict upper SU = " << SU << "\n"
+ << "unit upper UU = " << UU << "\n" ;
+
+ std::cout << "M = L + SU ? " << ((norm_inf( M - (L + SU) ) == 0.0)?"ok":"failed") << "\n";
+ std::cout << "M = U + SL ? " << ((norm_inf( M - (U + SL) ) == 0.0)?"ok":"failed") << "\n";
+
+}
+
+

Modified: branches/release/libs/numeric/ublas/doc/triangular.htm
==============================================================================
--- branches/release/libs/numeric/ublas/doc/triangular.htm (original)
+++ branches/release/libs/numeric/ublas/doc/triangular.htm 2009-04-02 18:36:39 EDT (Thu, 02 Apr 2009)
@@ -21,7 +21,7 @@
 <em>t</em><sub><em>i, j</em></sub> <em>= 0</em> , if <em>i &gt;
 j</em>. If furthermore holds t<sub><em>i, i</em></sub><em>= 1</em>
 the matrix is called unit lower triangular. For a <em>(n x n</em>
-)-dimensional upper triangular matrix and <em>0 &lt;= i &lt;
+)-dimensional lower triangular matrix and <em>0 &lt;= i &lt;
 n</em>,<em>0 &lt;= j &lt; n</em> holds <em>t</em><sub><em>i,
 j</em></sub> <em>= 0</em> , if <em>i &lt; j</em>. If furthermore
 holds t<sub><em>i, i</em></sub><em>= 1</em> the matrix is called
@@ -46,6 +46,8 @@
     std::cout &lt;&lt; mu &lt;&lt; std::endl;
 }
 </pre>
+<p>Please read the full triangular example for more details.</p>
+
 <h4>Definition</h4>
 <p>Defined in the header triangular.hpp.</p>
 <h4>Template parameters</h4>
@@ -348,6 +350,8 @@
     std::cout &lt;&lt; tau &lt;&lt; std::endl;
 }
 </pre>
+<p>Please read the full triangular example for more details.</p>
+
 <h4>Definition</h4>
 <p>Defined in the header triangular.hpp.</p>
 <h4>Template parameters</h4>

Modified: branches/release/libs/numeric/ublas/test/CMakeLists.txt
==============================================================================
--- branches/release/libs/numeric/ublas/test/CMakeLists.txt (original)
+++ branches/release/libs/numeric/ublas/test/CMakeLists.txt 2009-04-02 18:36:39 EDT (Thu, 02 Apr 2009)
@@ -50,13 +50,22 @@
   test6.cpp test62.cpp test63.cpp
   COMPILE_FLAGS "${UBLAS_TESTSET_DEFINES}")
 
-# Test commented out, just like in V1 and V2 Jamfiles
+# Test commented out because boost::interval does not behave like a scalar
 # boost_test_run(test7
 # test7.cpp test71.cpp test72.cpp test73.cpp
 # COMPILE_FLAGS "-DBOOST_UBLAS_USE_INTERVAL ${UBLAS_TESTSET_DEFINES}")
 
 boost_test_run(placement_new)
 
+boost_test_run(test_lu)
+
+boost_test_run(triangular_access
+ triangular_access.cpp
+ COMPILE_FLAGS "-DNOMESSAGES")
+
+boost_test_run(triangular_layout
+ triangular_layout.cpp)
+
 
 SET(test_compile_flags "-DEXTERNAL")
 #-- Intel Compiler flags

Modified: branches/release/libs/numeric/ublas/test/Jamfile.v2
==============================================================================
--- branches/release/libs/numeric/ublas/test/Jamfile.v2 (original)
+++ branches/release/libs/numeric/ublas/test/Jamfile.v2 2009-04-02 18:36:39 EDT (Thu, 02 Apr 2009)
@@ -88,7 +88,7 @@
         : : :
             <define>$(UBLAS_TESTSET)
       ]
-# Test commented out, just like in V1 Jamfile
+# Test commented out because boost::interval does not behave like a scalar type
 # [ run test7.cpp
 # test71.cpp
 # test72.cpp
@@ -106,4 +106,12 @@
             <toolset>intel-linux:<cxxflags>"-Xc"
                         <toolset>darwin:<cxxflags>"-fabi-version=0"
       ]
+ [ run test_lu.cpp
+ ]
+ [ run triangular_access.cpp
+ : : :
+ <define>NOMESSAGES
+ ]
+ [ run triangular_layout.cpp
+ ]
     ;

Modified: branches/release/libs/numeric/ublas/test/common/init.hpp
==============================================================================
--- branches/release/libs/numeric/ublas/test/common/init.hpp (original)
+++ branches/release/libs/numeric/ublas/test/common/init.hpp 2009-04-02 18:36:39 EDT (Thu, 02 Apr 2009)
@@ -43,7 +43,7 @@
 void initialize_vector (V &v) {
     typename V::size_type size = v.size ();
     for (typename V::size_type i = 0; i < size; ++ i)
- v [i] = typename V::value_type (i + 1);
+ v [i] = typename V::value_type ( i + 1.f );
 }
 
 template<class M>
@@ -52,11 +52,11 @@
 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
     for (typename M::iterator1 i = m.begin1(); i != m.end1(); ++ i)
         for (typename M::iterator2 j = i.begin(); j != i.end(); ++ j)
- *j = typename M::value_type (i.index1() * size1 + j.index2() + 1);
+ *j = typename M::value_type ( i.index1() * size1 + j.index2() + 1.f );
 #else
     for (typename M::iterator1 i = m.begin1(); i != m.end1(); ++ i)
         for (typename M::iterator2 j = ublas::begin (i, ublas::iterator1_tag ()); j != ublas::end (i, ublas::iterator1_tag ()); ++ j)
- *j = typename M::value_type (i.index1() * size1 + j.index2() + 1);
+ *j = typename M::value_type ( i.index1() * size1 + j.index2() + 1.f );
 #endif
 }
 

Added: branches/release/libs/numeric/ublas/test/common/testhelper.hpp
==============================================================================
--- (empty file)
+++ branches/release/libs/numeric/ublas/test/common/testhelper.hpp 2009-04-02 18:36:39 EDT (Thu, 02 Apr 2009)
@@ -0,0 +1,74 @@
+// 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)
+
+
+#ifndef _HPP_TESTHELPER_
+#define _HPP_TESTHELPER_
+
+#include <utility>
+
+static unsigned _success_counter = 0;
+static unsigned _fail_counter = 0;
+
+static inline
+void assertTrue(const char* message, bool condition) {
+#ifndef NOMESSAGES
+ std::cout << message;
+#endif
+ if ( condition ) {
+ ++ _success_counter;
+ std::cout << "1\n"; // success
+ } else {
+ ++ _fail_counter;
+ std::cout << "0\n"; // failed
+ }
+}
+
+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);
+}
+
+template < class M1, class M2 >
+bool compare( const boost::numeric::ublas::matrix_expression<M1> & m1,
+ const boost::numeric::ublas::matrix_expression<M2> & m2 ) {
+ size_t size1 = (std::min)(m1().size1(), m2().size1());
+ size_t size2 = (std::min)(m1().size2(), m2().size2());
+ for (size_t i=0; i < size1; ++i) {
+ for (size_t j=0; j < size2; ++j) {
+ if ( m1()(i,j) != m2()(i,j) ) return false;
+ }
+ }
+ return true;
+}
+
+template < class M1, class M2 >
+bool compare( const boost::numeric::ublas::vector_expression<M1> & m1,
+ const boost::numeric::ublas::vector_expression<M2> & m2 ) {
+ size_t size = (std::min)(m1().size(), m2().size());
+ for (size_t i=0; i < size; ++i) {
+ if ( m1()(i) != m2()(i) ) return false;
+ }
+ return true;
+}
+
+#endif

Modified: branches/release/libs/numeric/ublas/test/test7.cpp
==============================================================================
--- branches/release/libs/numeric/ublas/test/test7.cpp (original)
+++ branches/release/libs/numeric/ublas/test/test7.cpp 2009-04-02 18:36:39 EDT (Thu, 02 Apr 2009)
@@ -21,6 +21,8 @@
 
 #include "test7.hpp"
 
+// this testcase requires fix of task #2473
+
 int main () {
     test_vector ();
     test_matrix_vector ();

Modified: branches/release/libs/numeric/ublas/test/test71.cpp
==============================================================================
--- branches/release/libs/numeric/ublas/test/test71.cpp (original)
+++ branches/release/libs/numeric/ublas/test/test71.cpp 2009-04-02 18:36:39 EDT (Thu, 02 Apr 2009)
@@ -36,7 +36,7 @@
             std::cout << "v1.swap (v2) = " << v1 << " " << v2 << std::endl;
 
             // Zero assignment
- v1 = ublas::zero_vector<> (v1.size ());
+ v1 = ublas::zero_vector<value_type> (v1.size ());
             std::cout << "v1.zero_vector = " << v1 << std::endl;
             v1 = v2;
 

Modified: branches/release/libs/numeric/ublas/test/test73.cpp
==============================================================================
--- branches/release/libs/numeric/ublas/test/test73.cpp (original)
+++ branches/release/libs/numeric/ublas/test/test73.cpp 2009-04-02 18:36:39 EDT (Thu, 02 Apr 2009)
@@ -33,7 +33,7 @@
             std::cout << "m1.swap (m2) = " << m1 << " " << m2 << std::endl;
 
             // Zero assignment
- m1 = ublas::zero_matrix<> (m1.size (), m1.size2 ());
+ m1 = ublas::zero_matrix<value_type> (m1.size1 (), m1.size2 ());
             std::cout << "m1.zero_matrix = " << m1 << std::endl;
             m1 = m2;
 

Added: branches/release/libs/numeric/ublas/test/test_lu.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/numeric/ublas/test/test_lu.cpp 2009-04-02 18:36:39 EDT (Thu, 02 Apr 2009)
@@ -0,0 +1,70 @@
+// 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
+
+#include <boost/numeric/ublas/io.hpp>
+#include <boost/numeric/ublas/lu.hpp>
+#include <boost/cstdlib.hpp>
+
+#include "common/testhelper.hpp"
+
+#include <iostream>
+#include <sstream>
+
+using namespace boost::numeric::ublas;
+using std::string;
+
+static const string matrix_IN = "[3,3]((1,2,2),(2,3,3),(3,4,6))\0";
+static const string matrix_LU = "[3,3]((3,4,6),(3.33333343e-01,6.66666627e-01,0),(6.66666687e-01,4.99999911e-01,-1))\0";
+static const string matrix_INV= "[3,3]((-3,2,-7.94728621e-08),(1.50000012,0,-5.00000060e-01),(4.99999911e-01,-1,5.00000060e-01))\0";
+static const string matrix_PM = "[3](2,2,2)";
+
+int main () {
+
+ typedef float TYPE;
+
+ typedef matrix<TYPE> MATRIX;
+
+ MATRIX A;
+ MATRIX LU;
+ MATRIX INV;
+
+ {
+ std::istringstream is(matrix_IN);
+ is >> A;
+ }
+ {
+ std::istringstream is(matrix_LU);
+ is >> LU;
+ }
+ {
+ std::istringstream is(matrix_INV);
+ is >> INV;
+ }
+ permutation_matrix<>::vector_type temp;
+ {
+ std::istringstream is(matrix_PM);
+ is >> temp;
+ }
+ permutation_matrix<> PM(temp);
+
+ permutation_matrix<> pm(3);
+
+ int result = lu_factorize<MATRIX, permutation_matrix<> >(A, pm);
+
+ assertTrue("factorization completed: ", 0 == result);
+ assertTrue("LU factors are correct: ", compare(A, LU));
+ assertTrue("permutation is correct: ", compare(pm, PM));
+
+ MATRIX B = identity_matrix<TYPE>(A.size2());
+
+ lu_substitute(A, pm, B);
+
+ assertTrue("inverse is correct: ", compare(B, INV));
+
+ return (getResults().second > 0) ? boost::exit_failure : boost::exit_success;
+}

Added: branches/release/libs/numeric/ublas/test/triangular_access.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/numeric/ublas/test/triangular_access.cpp 2009-04-02 18:36:39 EDT (Thu, 02 Apr 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: branches/release/libs/numeric/ublas/test/triangular_layout.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/numeric/ublas/test/triangular_layout.cpp 2009-04-02 18:36:39 EDT (Thu, 02 Apr 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