$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r80267 - in trunk: boost/numeric/ublas libs/numeric/ublas/test
From: guwi17_at_[hidden]
Date: 2012-08-27 18:13:26
Author: guwi17
Date: 2012-08-27 18:13:26 EDT (Mon, 27 Aug 2012)
New Revision: 80267
URL: http://svn.boost.org/trac/boost/changeset/80267
Log:
boost/numeric/ublas/triangular.hpp - applied patch, see #4024
libs/numeric/ublas/test/test_inplace_solve.cpp - fixed includes
libs/numeric/ublas/test/utils.hpp - applied patch (after s/BOOST_UBLA_TEST/BOOST_UBLAS_TEST/g), see #7296
Text files modified: 
   trunk/boost/numeric/ublas/triangular.hpp             |   377 ++++++++++++++++++++------------------- 
   trunk/libs/numeric/ublas/test/test_inplace_solve.cpp |     2                                         
   trunk/libs/numeric/ublas/test/utils.hpp              |   225 +++++++++++++++++++++--                 
   3 files changed, 401 insertions(+), 203 deletions(-)
Modified: trunk/boost/numeric/ublas/triangular.hpp
==============================================================================
--- trunk/boost/numeric/ublas/triangular.hpp	(original)
+++ trunk/boost/numeric/ublas/triangular.hpp	2012-08-27 18:13:26 EDT (Mon, 27 Aug 2012)
@@ -1936,6 +1936,92 @@
             }
         }
     }
+
+    // Dense (proxy) case
+    template<class E1, class E2>
+    BOOST_UBLAS_INLINE
+    void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
+                        lower_tag, row_major_tag, dense_proxy_tag) {
+        typedef typename E2::size_type size_type;
+        typedef typename E2::difference_type difference_type;
+        typedef typename E2::value_type value_type;
+
+        BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
+        BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
+        size_type size = e2 ().size ();
+        for (size_type n = 0; n < size; ++ n) {
+#ifndef BOOST_UBLAS_SINGULAR_CHECK
+            BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
+#else
+            if (e1 () (n, n) == value_type/*zero*/())
+                singular ().raise ();
+#endif
+            value_type t = e2 () (n) /= e1 () (n, n);
+            if (t != value_type/*zero*/()) {
+                for (size_type m = n + 1; m < size; ++ m)
+                    e2 () (m) -= e1 () (m, n) * t;
+            }
+        }
+    }
+    // Packed (proxy) case
+    template<class E1, class E2>
+    BOOST_UBLAS_INLINE
+    void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
+                        lower_tag, row_major_tag, packed_proxy_tag) {
+        typedef typename E2::size_type size_type;
+        typedef typename E2::difference_type difference_type;
+        typedef typename E2::value_type value_type;
+
+        BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
+        BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
+        size_type size = e2 ().size ();
+        for (size_type n = 0; n < size; ++ n) {
+#ifndef BOOST_UBLAS_SINGULAR_CHECK
+            BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
+#else
+            if (e1 () (n, n) == value_type/*zero*/())
+                singular ().raise ();
+#endif
+            value_type t = e2 () (n);
+            typename E1::const_iterator2 it2e1 (e1 ().find2 (1, n, 0));
+            typename E1::const_iterator2 it2e1_end (e1 ().find2 (1, n, n));
+            while (it2e1 != it2e1_end) {
+              t -= *it2e1 * e2 () (it2e1.index2());
+              ++ it2e1;
+            }
+            e2() (n) = t / e1 () (n, n);
+        }
+    }
+    // Sparse (proxy) case
+    template<class E1, class E2>
+    BOOST_UBLAS_INLINE
+    void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
+                        lower_tag, row_major_tag, unknown_storage_tag) {
+        typedef typename E2::size_type size_type;
+        typedef typename E2::difference_type difference_type;
+        typedef typename E2::value_type value_type;
+
+        BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
+        BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
+        size_type size = e2 ().size ();
+        for (size_type n = 0; n < size; ++ n) {
+#ifndef BOOST_UBLAS_SINGULAR_CHECK
+            BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
+#else
+            if (e1 () (n, n) == value_type/*zero*/())
+                singular ().raise ();
+#endif
+            value_type t = e2 () (n);
+            typename E1::const_iterator2 it2e1 (e1 ().find2 (1, n, 0));
+            typename E1::const_iterator2 it2e1_end (e1 ().find2 (1, n, n));
+            while (it2e1 != it2e1_end) {
+              t -= *it2e1 * e2 () (it2e1.index2());
+              ++ it2e1;
+            }
+            e2() (n) = t / e1 () (n, n);
+        }
+    }
+
     // Redirectors :-)
     template<class E1, class E2>
     BOOST_UBLAS_INLINE
@@ -1950,8 +2036,8 @@
     void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
                         lower_tag, row_major_tag) {
         typedef typename E1::storage_category storage_category;
-        inplace_solve (e2, trans (e1),
-                       upper_tag (), row_major_tag (), storage_category ());
+        inplace_solve (e1, e2,
+                       lower_tag (), row_major_tag (), storage_category ());
     }
     // Dispatcher
     template<class E1, class E2>
@@ -2020,9 +2106,9 @@
             if (t != value_type/*zero*/()) {
                 typename E1::const_reverse_iterator1 it1e1 (e1 ().find1 (1, n, n));
                 typename E1::const_reverse_iterator1 it1e1_rend (e1 ().find1 (1, 0, n));
-                difference_type m (it1e1_rend - it1e1);
-                while (-- m >= 0)
-                    e2 () (it1e1.index1 ()) -= *it1e1 * t, ++ it1e1;
+                while (it1e1 != it1e1_rend) {
+                  e2 () (it1e1.index1 ()) -= *it1e1 * t, ++ it1e1;
+                }
             }
         }
     }
@@ -2049,11 +2135,100 @@
             if (t != value_type/*zero*/()) {
                 typename E1::const_reverse_iterator1 it1e1 (e1 ().find1 (1, n, n));
                 typename E1::const_reverse_iterator1 it1e1_rend (e1 ().find1 (1, 0, n));
-                while (it1e1 != it1e1_rend)
-                    e2 () (it1e1.index1 ()) -= *it1e1 * t, ++ it1e1;
+                while (it1e1 != it1e1_rend) {
+                  e2 () (it1e1.index1 ()) -= *it1e1 * t, ++ it1e1;
+                }
+            }
+        }
+    }
+
+    // Dense (proxy) case
+    template<class E1, class E2>
+    BOOST_UBLAS_INLINE
+    void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
+                        upper_tag, row_major_tag, dense_proxy_tag) {
+        typedef typename E2::size_type size_type;
+        typedef typename E2::difference_type difference_type;
+        typedef typename E2::value_type value_type;
+
+        BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
+        BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
+        size_type size = e1 ().size1 ();
+        for (difference_type n = size-1; n >=0; -- n) {
+#ifndef BOOST_UBLAS_SINGULAR_CHECK
+            BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
+#else
+            if (e1 () (n, n) == value_type/*zero*/())
+                singular ().raise ();
+#endif
+            value_type t = e2 () (n);
+            for (difference_type m = n + 1; m < e1 ().size2(); ++ m) {
+              t -= e1 () (n, m)  * e2 () (m);
+            }
+            e2() (n) = t / e1 () (n, n);
+        }
+    }
+    // Packed (proxy) case
+    template<class E1, class E2>
+    BOOST_UBLAS_INLINE
+    void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
+                        upper_tag, row_major_tag, packed_proxy_tag) {
+        typedef typename E2::size_type size_type;
+        typedef typename E2::difference_type difference_type;
+        typedef typename E2::value_type value_type;
+
+        BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
+        BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
+        size_type size = e1 ().size1 ();
+        for (difference_type n = size-1; n >=0; -- n) {
+#ifndef BOOST_UBLAS_SINGULAR_CHECK
+            BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
+#else
+            if (e1 () (n, n) == value_type/*zero*/())
+                singular ().raise ();
+#endif
+            value_type t = e2 () (n);
+            typename E1::const_iterator2 it2e1 (e1 ().find2 (1, n, n+1));
+            typename E1::const_iterator2 it2e1_end (e1 ().find2 (1, n, e1 ().size2 ()));
+            while (it2e1 != it2e1_end) {
+              t -= *it2e1 * e2 () (it2e1.index2());
+              ++ it2e1;
+            }
+            e2() (n) = t / e1 () (n, n);
+
+        }
+    }
+    // Sparse (proxy) case
+    template<class E1, class E2>
+    BOOST_UBLAS_INLINE
+    void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
+                        upper_tag, row_major_tag, unknown_storage_tag) {
+        typedef typename E2::size_type size_type;
+        typedef typename E2::difference_type difference_type;
+        typedef typename E2::value_type value_type;
+
+        BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
+        BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
+        size_type size = e1 ().size1 ();
+        for (difference_type n = size-1; n >=0; -- n) {
+#ifndef BOOST_UBLAS_SINGULAR_CHECK
+            BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
+#else
+            if (e1 () (n, n) == value_type/*zero*/())
+                singular ().raise ();
+#endif
+            value_type t = e2 () (n);
+            typename E1::const_iterator2 it2e1 (e1 ().find2 (1, n, n+1));
+            typename E1::const_iterator2 it2e1_end (e1 ().find2 (1, n, e1 ().size2 ()));
+            while (it2e1 != it2e1_end) {
+              t -= *it2e1 * e2 () (it2e1.index2());
+              ++ it2e1;
             }
+            e2() (n) = t / e1 () (n, n);
+
         }
     }
+
     // Redirectors :-)
     template<class E1, class E2>
     BOOST_UBLAS_INLINE
@@ -2068,8 +2243,8 @@
     void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
                         upper_tag, row_major_tag) {
         typedef typename E1::storage_category storage_category;
-        inplace_solve (e2, trans (e1),
-                       lower_tag (), row_major_tag (), storage_category ());
+        inplace_solve (e1, e2,
+                       upper_tag (), row_major_tag (), storage_category ());
     }
     // Dispatcher
     template<class E1, class E2>
@@ -2100,103 +2275,21 @@
         return r;
     }
 
-    // Dense (proxy) case
-    template<class E1, class E2>
-    BOOST_UBLAS_INLINE
-    void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
-                        lower_tag, row_major_tag, dense_proxy_tag) {
-        typedef typename E1::size_type size_type;
-        typedef typename E1::difference_type difference_type;
-        typedef typename E1::value_type value_type;
-
-        BOOST_UBLAS_CHECK (e1 ().size () == e2 ().size1 (), bad_size ());
-        BOOST_UBLAS_CHECK (e2 ().size1 () == e2 ().size2 (), bad_size ());
-        size_type size = e1 ().size ();
-        for (difference_type n = size - 1; n >= 0; -- n) {
-#ifndef BOOST_UBLAS_SINGULAR_CHECK
-            BOOST_UBLAS_CHECK (e2 () (n, n) != value_type/*zero*/(), singular ());
-#else
-            if (e2 () (n, n) == value_type/*zero*/())
-                singular ().raise ();
-#endif
-            value_type t = e1 () (n) /= e2 () (n, n);
-            if (t != value_type/*zero*/()) {
-                for (difference_type m = n - 1; m >= 0; -- m)
-                    e1 () (m) -= t * e2 () (n, m);
-            }
-        }
-    }
-    // Packed (proxy) case
-    template<class E1, class E2>
-    BOOST_UBLAS_INLINE
-    void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
-                        lower_tag, row_major_tag, packed_proxy_tag) {
-        typedef typename E1::size_type size_type;
-        typedef typename E1::difference_type difference_type;
-        typedef typename E1::value_type value_type;
-
-        BOOST_UBLAS_CHECK (e1 ().size () == e2 ().size1 (), bad_size ());
-        BOOST_UBLAS_CHECK (e2 ().size1 () == e2 ().size2 (), bad_size ());
-        size_type size = e1 ().size ();
-        for (difference_type n = size - 1; n >= 0; -- n) {
-#ifndef BOOST_UBLAS_SINGULAR_CHECK
-            BOOST_UBLAS_CHECK (e2 () (n, n) != value_type/*zero*/(), singular ());
-#else
-            if (e2 () (n, n) == value_type/*zero*/())
-                singular ().raise ();
-#endif
-            value_type t = e1 () (n) /= e2 () (n, n);
-            if (t != value_type/*zero*/()) {
-                typename E2::const_reverse_iterator2 it2e2 (e2 ().find2 (1, n, n));
-                typename E2::const_reverse_iterator2 it2e2_rend (e2 ().find2 (1, n, 0));
-                difference_type m (it2e2_rend - it2e2);
-                while (-- m >= 0)
-                    e1 () (it2e2.index2 ()) -= *it2e2 * t, ++ it2e2;
-            }
-        }
-    }
-    // Sparse (proxy) case
-    template<class E1, class E2>
-    BOOST_UBLAS_INLINE
-    void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
-                        lower_tag, row_major_tag, unknown_storage_tag) {
-        typedef typename E1::size_type size_type;
-        typedef typename E1::difference_type difference_type;
-        typedef typename E1::value_type value_type;
-
-        BOOST_UBLAS_CHECK (e1 ().size () == e2 ().size1 (), bad_size ());
-        BOOST_UBLAS_CHECK (e2 ().size1 () == e2 ().size2 (), bad_size ());
-        size_type size = e1 ().size ();
-        for (difference_type n = size - 1; n >= 0; -- n) {
-#ifndef BOOST_UBLAS_SINGULAR_CHECK
-            BOOST_UBLAS_CHECK (e2 () (n, n) != value_type/*zero*/(), singular ());
-#else
-            if (e2 () (n, n) == value_type/*zero*/())
-                singular ().raise ();
-#endif
-            value_type t = e1 () (n) /= e2 () (n, n);
-            if (t != value_type/*zero*/()) {
-                typename E2::const_reverse_iterator2 it2e2 (e2 ().find2 (1, n, n));
-                typename E2::const_reverse_iterator2 it2e2_rend (e2 ().find2 (1, n, 0));
-                while (it2e2 != it2e2_rend)
-                    e1 () (it2e2.index2 ()) -= *it2e2 * t, ++ it2e2;
-            }
-        }
-    }
+
     // Redirectors :-)
     template<class E1, class E2>
     BOOST_UBLAS_INLINE
     void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
                         lower_tag, row_major_tag) {
-        typedef typename E1::storage_category storage_category;
-        inplace_solve (e1, e2,
-                       lower_tag (), row_major_tag (), storage_category ());
+        typedef typename E2::storage_category storage_category;
+        inplace_solve (trans(e2), e1,
+                       upper_tag (), column_major_tag (), storage_category ());
     }
     template<class E1, class E2>
     BOOST_UBLAS_INLINE
     void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
                         lower_tag, column_major_tag) {
-        typedef typename E1::storage_category storage_category;
+        typedef typename E2::storage_category storage_category;
         inplace_solve (trans (e2), e1,
                        upper_tag (), row_major_tag (), storage_category ());
     }
@@ -2218,103 +2311,21 @@
                        unit_lower_tag (), orientation_category ());
     }
 
-    // Dense (proxy) case
-    template<class E1, class E2>
-    BOOST_UBLAS_INLINE
-    void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
-                        upper_tag, row_major_tag, dense_proxy_tag) {
-        typedef typename E1::size_type size_type;
-        typedef typename E1::difference_type difference_type;
-        typedef typename E1::value_type value_type;
-
-        BOOST_UBLAS_CHECK (e1 ().size () == e2 ().size1 (), bad_size ());
-        BOOST_UBLAS_CHECK (e2 ().size1 () == e2 ().size2 (), bad_size ());
-        size_type size = e1 ().size ();
-        for (size_type n = 0; n < size; ++ n) {
-#ifndef BOOST_UBLAS_SINGULAR_CHECK
-            BOOST_UBLAS_CHECK (e2 () (n, n) != value_type/*zero*/(), singular ());
-#else
-            if (e2 () (n, n) == value_type/*zero*/())
-                singular ().raise ();
-#endif
-            value_type t = e1 () (n) /= e2 () (n, n);
-            if (t != value_type/*zero*/()) {
-                for (size_type m = n + 1; m < size; ++ m)
-                    e1 () (m) -= t * e2 () (n, m);
-            }
-        }
-    }
-    // Packed (proxy) case
-    template<class E1, class E2>
-    BOOST_UBLAS_INLINE
-    void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
-                        upper_tag, row_major_tag, packed_proxy_tag) {
-        typedef typename E1::size_type size_type;
-        typedef typename E1::difference_type difference_type;
-        typedef typename E1::value_type value_type;
-
-        BOOST_UBLAS_CHECK (e1 ().size () == e2 ().size1 (), bad_size ());
-        BOOST_UBLAS_CHECK (e2 ().size1 () == e2 ().size2 (), bad_size ());
-        size_type size = e1 ().size ();
-        for (size_type n = 0; n < size; ++ n) {
-#ifndef BOOST_UBLAS_SINGULAR_CHECK
-            BOOST_UBLAS_CHECK (e2 () (n, n) != value_type/*zero*/(), singular ());
-#else
-            if (e2 () (n, n) == value_type/*zero*/())
-                singular ().raise ();
-#endif
-            value_type t = e1 () (n) /= e2 () (n, n);
-            if (t != value_type/*zero*/()) {
-                typename E2::const_iterator2 it2e2 (e2 ().find2 (1, n, n + 1));
-                typename E2::const_iterator2 it2e2_end (e2 ().find2 (1, n, e2 ().size2 ()));
-                difference_type m (it2e2_end - it2e2);
-                while (-- m >= 0)
-                    e1 () (it2e2.index2 ()) -= *it2e2 * t, ++ it2e2;
-            }
-        }
-    }
-    // Sparse (proxy) case
-    template<class E1, class E2>
-    BOOST_UBLAS_INLINE
-    void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
-                        upper_tag, row_major_tag, unknown_storage_tag) {
-        typedef typename E1::size_type size_type;
-        typedef typename E1::difference_type difference_type;
-        typedef typename E1::value_type value_type;
-
-        BOOST_UBLAS_CHECK (e1 ().size () == e2 ().size1 (), bad_size ());
-        BOOST_UBLAS_CHECK (e2 ().size1 () == e2 ().size2 (), bad_size ());
-        size_type size = e1 ().size ();
-        for (size_type n = 0; n < size; ++ n) {
-#ifndef BOOST_UBLAS_SINGULAR_CHECK
-            BOOST_UBLAS_CHECK (e2 () (n, n) != value_type/*zero*/(), singular ());
-#else
-            if (e2 () (n, n) == value_type/*zero*/())
-                singular ().raise ();
-#endif
-            value_type t = e1 () (n) /= e2 () (n, n);
-            if (t != value_type/*zero*/()) {
-                typename E2::const_iterator2 it2e2 (e2 ().find2 (1, n, n + 1));
-                typename E2::const_iterator2 it2e2_end (e2 ().find2 (1, n, e2 ().size2 ()));
-                while (it2e2 != it2e2_end)
-                    e1 () (it2e2.index2 ()) -= *it2e2 * t, ++ it2e2;
-            }
-        }
-    }
+
     // Redirectors :-)
     template<class E1, class E2>
     BOOST_UBLAS_INLINE
     void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
                         upper_tag, row_major_tag) {
-        typedef typename E1::storage_category storage_category;
-        inplace_solve (e1, e2,
-                       upper_tag (), row_major_tag (), storage_category ());
+        typedef typename E2::storage_category storage_category;
+        inplace_solve (trans(e2), e1,
+                       lower_tag (), column_major_tag (), storage_category ());
     }
     template<class E1, class E2>
     BOOST_UBLAS_INLINE
     void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
                         upper_tag, column_major_tag) {
-        typedef typename E1::storage_category storage_category;
+        typedef typename E2::storage_category storage_category;
         inplace_solve (trans (e2), e1,
                        lower_tag (), row_major_tag (), storage_category ());
     }
Modified: trunk/libs/numeric/ublas/test/test_inplace_solve.cpp
==============================================================================
--- trunk/libs/numeric/ublas/test/test_inplace_solve.cpp	(original)
+++ trunk/libs/numeric/ublas/test/test_inplace_solve.cpp	2012-08-27 18:13:26 EDT (Mon, 27 Aug 2012)
@@ -3,7 +3,7 @@
 #include <boost/numeric/ublas/vector.hpp>
 #include <boost/numeric/ublas/matrix.hpp>
 #include <boost/numeric/ublas/matrix_sparse.hpp>
-#include <boost/numeric/ublas/triangular.hpp.new>
+#include <boost/numeric/ublas/triangular.hpp>
 #include <boost/numeric/ublas/io.hpp>
 
 
Modified: trunk/libs/numeric/ublas/test/utils.hpp
==============================================================================
--- trunk/libs/numeric/ublas/test/utils.hpp	(original)
+++ trunk/libs/numeric/ublas/test/utils.hpp	2012-08-27 18:13:26 EDT (Mon, 27 Aug 2012)
@@ -1,38 +1,225 @@
-//  Copyright (c) 2011 David Bellot
-//
-//  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)
+/**
+ *  \file util.hpp
+ *
+ *  \brief Utility macros/functions for testing and debugging purpose.
+ *
+ *  Copyright (c) 2009-2012, Marco Guazzone
+ *
+ *  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)
+ *
+ * \author Marco Guazzone, marco.guazzone_at_[hidden]
+ */
 
-#ifndef TEST_UTILS_HPP
-#define TEST_UTILS_HPP
+#ifndef BOOST_NUMERIC_UBLAS_TEST_UTILS_HPP
+#define BOOST_NUMERIC_UBLAS_TEST_UTILS_HPP
 
 
+#include <cmath>
 #include <iostream>
+#include <limits>
+#include <stdexcept>
 
 
-#define EXPAND_(x) x
+namespace boost { namespace numeric { namespace ublas { namespace test { namespace detail { namespace /*<unnamed>*/ {
 
-#define STRINGIFY_(x) #x
+template <typename T1, typename T2, typename T3>
+inline
+bool close_to(T1 x, T2 y, T3 tol)
+{
+    if (::std::isnan(x) || ::std::isnan(y))
+    {
+        // According to IEEE, NaN are different event by itself
+        return false;
+    }
+    return ::std::abs(x-y) <= (::std::max(::std::abs(x), ::std::abs(y))*tol);
+}
 
-#define JOIN_(x,y) x ## y
+}}}}}} // Namespace boost::numeric::ublas::test::detail::<unnamed>
 
+
+/// Expand its argument.
+#define BOOST_UBLAS_TEST_EXPAND_(x) x
+
+
+/// Transform its argument into a string.
+#define BOOST_UBLAS_TEST_STRINGIFY_(x) #x
+
+
+/// Concatenate its two \e string arguments.
+#define BOOST_UBLAS_TEST_JOIN_(x,y) x ## y
+
+
+/// Output the message \a x if in debug-mode; otherwise output nothing.
 #ifndef NDEBUG
-#       define BOOST_UBLAS_DEBUG_TRACE(x) std::cerr << "[Debug>> " << EXPAND_(x) << std::endl
+# 	define BOOST_UBLAS_DEBUG_TRACE(x) ::std::cerr << "[Debug>> " << BOOST_UBLAS_TEST_EXPAND_(x) << ::std::endl
 #else
-#       define BOOST_UBLAS_DEBUG_TRACE(x) /**/
+# 	define BOOST_UBLAS_DEBUG_TRACE(x) /**/
 #endif // NDEBUG
 
-#define BOOST_UBLAS_TEST_BEGIN() unsigned int test_fails_(0)
 
-#define BOOST_UBLAS_TEST_DEF(x) void EXPAND_(x)(unsigned int& test_fails_)
+/// Define the name of the entire test suite.
+#define DCS_TEST_SUITE(m) ::std::cerr << "--- Test Suite: " << m << " ---" << ::std::endl;
 
-#define BOOST_UBLAS_TEST_DO(x) EXPAND_(x)(test_fails_)
 
-#define BOOST_UBLAS_TEST_END() if (test_fails_ > 0) { std::cerr << "Number of failed tests: " << test_fails_ << std::endl; return -1; \
-} else { std::cerr << "No failed test" << std::endl; return 0; }
+/// Define the beginning of a test suite.
+#define BOOST_UBLAS_TEST_BEGIN() 	/* [BOOST_UBLAS_TEST_BEGIN] */ \
+									{ \
+										/* Begin of Test Suite */ \
+										unsigned int test_fails__(0) \
+									/* [/BOOST_UBLAS_TEST_BEGIN] */
+
+
+/// Define a test case \a x inside the current test suite.
+#define BOOST_UBLAS_TEST_DEF(x) void BOOST_UBLAS_TEST_EXPAND_(x)(unsigned int& test_fails__)
+
+
+/// Call the test case \a x.
+#define BOOST_UBLAS_TEST_DO(x) 	/* [BOOST_UBLAS_TEST_DO] */ \
+								try \
+								{ \
+									BOOST_UBLAS_TEST_EXPAND_(x)(test_fails__); \
+								} \
+								catch (::std::exception& e) \
+								{ \
+									++test_fails__; \
+									BOOST_UBLAS_TEST_ERROR( e.what() ); \
+								} \
+								catch (...) \
+								{ \
+									++test_fails__; \
+								} \
+								/* [/BOOST_UBLAS_TEST_DO] */
+
+
+/// Define the end of a test suite.
+#define BOOST_UBLAS_TEST_END() 	/* [BOOST_UBLAS_TEST_END] */ \
+								if (test_fails__ > 0) \
+								{ \
+									::std::cerr << "Number of failed tests: " << test_fails__ << ::std::endl; \
+								} \
+								else \
+								{ \
+									::std::cerr << "No failed test" << ::std::endl; \
+								} \
+								} /* End of test suite */ \
+								/* [/BOOST_UBLAS_TEST_END] */
+
+
+/// Check the truth of assertion \a x.
+#define BOOST_UBLAS_TEST_CHECK(x)	/* [BOOST_UBLAS_TEST_CHECK] */ \
+									if (!(x)) \
+									{ \
+										BOOST_UBLAS_TEST_ERROR( "Failed assertion: " << BOOST_UBLAS_TEST_STRINGIFY_(x) ); \
+										++test_fails__; \
+									} \
+									/* [/BOOST_UBLAS_TEST_CHECK] */
+
+
+/// Check for the equality of \a x against \a y.
+#define BOOST_UBLAS_TEST_CHECK_EQ(x,y)	/* [BOOST_UBLAS_TEST_CHECK_EQUAL] */ \
+										if (!(BOOST_UBLAS_TEST_PARAM_EXPAND_(x) == BOOST_UBLAS_TEST_PARAM_EXPAND_(y))) \
+										{ \
+											BOOST_UBLAS_TEST_ERROR( "Failed assertion: (" << BOOST_UBLAS_TEST_STRINGIFY_(x) << " == " << BOOST_UBLAS_TEST_STRINGIFY_(y) << ")" ); \
+											++test_fails__; \
+										} \
+										/* [/BOOST_UBLAS_TEST_CHECK_EQUAL] */
+
+
+/// Alias for macro \c BOOST_UBLAS_TEST_CHECK_EQ (for backward compatibility).
+#define BOOST_UBLAS_TEST_CHECK_EQUAL(x,y) BOOST_UBLAS_TEST_CHECK_EQ(x,y)
+
+
+/// Check that \a x and \a y are close with respect to a given precision.
+#define BOOST_UBLAS_TEST_CHECK_CLOSE(x,y,e)	/* [BOOST_UBLAS_TEST_CHECK_PRECISION] */ \
+											if (!::boost::numeric::ublas::test::detail::close_to(BOOST_UBLAS_TEST_EXPAND_(x), BOOST_UBLAS_TEST_EXPAND_(y), BOOST_UBLAS_TEST_EXPAND_(e))) \
+											{ \
+												BOOST_UBLAS_TEST_ERROR( "Failed assertion: abs(" << BOOST_UBLAS_TEST_STRINGIFY_(x) << "-" << BOOST_UBLAS_TEST_STRINGIFY_(y) << ") <= " << BOOST_UBLAS_TEST_STRINGIFY_(e) << " [with " << BOOST_UBLAS_TEST_STRINGIFY_(x) << " == " << BOOST_UBLAS_TEST_EXPAND_(x) << ", " << BOOST_UBLAS_TEST_STRINGIFY_(y) << " == " << BOOST_UBLAS_TEST_EXPAND_(y) << " and " << BOOST_UBLAS_TEST_STRINGIFY_(e) << " == " << BOOST_UBLAS_TEST_EXPAND_(e) << "]" ); \
+												++test_fails__; \
+											} \
+											/* [/BOOST_UBLAS_TEST_CHECK_PRECISION] */
+
+
+/// Alias for macro \c BOOST_UBLAS_TEST_CHECK_CLOSE (for backward compatibility),
+#define BOOST_UBLAS_TEST_CHECK_PRECISION(x,y,e) BOOST_UBLAS_TEST_CHECK_CLOSE(x,y,e)
+
+
+/// Check that \a x is close to \a y with respect to a given relative precision.
+#define BOOST_UBLAS_TEST_CHECK_REL_PRECISION(x,y,e)	/* [BOOST_UBLAS_TEST_CHECK_REL_PRECISION] */ \
+													if (!::boost::numeric::ublas::test::detail::close_to(BOOST_UBLAS_TEST_EXPAND_(x)/BOOST_UBLAS_TEST_EXPAND_(y), 1.0, BOOST_UBLAS_TEST_EXPAND_(e))) \
+													{ \
+														BOOST_UBLAS_TEST_ERROR( "Failed assertion: abs((" << BOOST_UBLAS_TEST_STRINGIFY_(x) << "-" << BOOST_UBLAS_TEST_STRINGIFY_(y) << ")/" << BOOST_UBLAS_TEST_STRINGIFY_(y) << ") <= " << BOOST_UBLAS_TEST_STRINGIFY_(e)  << " [with " << BOOST_UBLAS_TEST_STRINGIFY_(x) << " == " << BOOST_UBLAS_TEST_EXPAND_(x) << ", " << BOOST_UBLAS_TEST_STRINGIFY_(y) << " == " << BOOST_UBLAS_TEST_EXPAND_(y) << " and " << BOOST_UBLAS_TEST_STRINGIFY_(e) << " == " << BOOST_UBLAS_TEST_EXPAND_(e) << "]" ); \
+														++test_fails__; \
+													} \
+													/* [/BOOST_UBLAS_TEST_CHECK_REL_PRECISION] */
+
+
+/// Check that elements of \a x and \a y are equal.
+#define BOOST_UBLAS_TEST_CHECK_VECTOR_EQ(x,y,n)	/* [BOOST_UBLAS_TEST_CHECK_VECTOR_EQ] */ \
+												if (BOOST_UBLAS_TEST_EXPAND_(n) > 0) \
+												{ \
+													unsigned long n__ = BOOST_UBLAS_TEST_EXPAND_(n); \
+													for (unsigned long i__ = n__; i__ > 0; --i__) \
+													{ \
+														if (!(BOOST_UBLAS_TEST_EXPAND_(x)[n__-i__]==BOOST_UBLAS_TEST_EXPAND_(y)[n__-i__])) \
+														{ \
+															BOOST_UBLAS_TEST_ERROR( "Failed assertion: (" << BOOST_UBLAS_TEST_STRINGIFY_(x[i__]) << "==" << BOOST_UBLAS_TEST_STRINGIFY_(y[i__]) << ")" << " [with " << BOOST_UBLAS_TEST_STRINGIFY_(x[i__]) << " == " << BOOST_UBLAS_TEST_EXPAND_(x)[n__-i__] << ", " << BOOST_UBLAS_TEST_STRINGIFY_(y[i__]) << " == " << BOOST_UBLAS_TEST_EXPAND_(y)[n__-i__] << ", " << BOOST_UBLAS_TEST_STRINGIFY_(i__) << " == " << i__ << " and " << BOOST_UBLAS_TEST_STRINGIFY_(n) << " == " << n__ << "]" ); \
+															++test_fails__; \
+														} \
+													} \
+												} \
+												/* [/BOOST_UBLAS_TEST_CHECK_VECTOR_EQ] */
+
+
+/// Check that elements of \a x and \a y are close with respect to a given precision.
+#define BOOST_UBLAS_TEST_CHECK_VECTOR_CLOSE(x,y,n,e)	/* [BOOST_UBLAS_TEST_CHECK_VECTOR_CLOSE] */ \
+														if (BOOST_UBLAS_TEST_EXPAND_(n) > 0) \
+														{ \
+															unsigned long n__ = BOOST_UBLAS_TEST_EXPAND_(n); \
+															for (unsigned long i__ = n__; i__ > 0; --i__) \
+															{ \
+																if (!::boost::numeric::ublas::test::detail::close_to(BOOST_UBLAS_TEST_EXPAND_(x)[n__-i__], BOOST_UBLAS_TEST_EXPAND_(y)[n__-i__], BOOST_UBLAS_TEST_EXPAND_(e))) \
+																{ \
+																	BOOST_UBLAS_TEST_ERROR( "Failed assertion: abs((" << BOOST_UBLAS_TEST_STRINGIFY_(x[i__]) << "-" << BOOST_UBLAS_TEST_STRINGIFY_(y[i__]) << ") <= " << BOOST_UBLAS_TEST_STRINGIFY_(e)  << " [with " << BOOST_UBLAS_TEST_STRINGIFY_(x[i__]) << " == " << BOOST_UBLAS_TEST_EXPAND_(x)[n__-i__] << ", " << BOOST_UBLAS_TEST_STRINGIFY_(y[i__]) << " == " << BOOST_UBLAS_TEST_EXPAND_(y)[n__-i__] << ", " << BOOST_UBLAS_TEST_STRINGIFY_(i__) << " == " << i__ << " and " << BOOST_UBLAS_TEST_STRINGIFY_(n) << " == " << n__ << "]" ); \
+																	++test_fails__; \
+																} \
+															} \
+														} \
+														/* [/BOOST_UBLAS_TEST_CHECK_VECTOR_CLOSE] */
+
+
+/// Check that elements of matrices \a x and \a y are equal.
+#define BOOST_UBLAS_TEST_CHECK_MATRIX_EQ(x,y,nr,nc)	/* [BOOST_UBLAS_TEST_CHECK_MATRIX_EQ] */ \
+													for (unsigned long i__ = 0; i__ < BOOST_UBLAS_TEST_EXPAND_(nr); ++i__) \
+													{ \
+														for (unsigned long j__ = 0; j__ < BOOST_UBLAS_TEST_EXPAND_(nc); ++j__) \
+														{ \
+															if (!(BOOST_UBLAS_TEST_EXPAND_(x)(i__,j__)==BOOST_UBLAS_TEST_EXPAND_(y)(i__,j__))) \
+															{ \
+																BOOST_UBLAS_TEST_ERROR( "Failed assertion: (" << BOOST_UBLAS_TEST_STRINGIFY_(x(i__,j__)) << " == " << BOOST_UBLAS_TEST_STRINGIFY_(y(i__,j__)) << ") [with " << BOOST_UBLAS_TEST_STRINGIFY_(x(i__,j__)) << " == " << BOOST_UBLAS_TEST_EXPAND_(x)(i__,j__) << ", " << BOOST_UBLAS_TEST_STRINGIFY_(y(i__,j__)) << " == " << BOOST_UBLAS_TEST_EXPAND_(y)(i__,j__) << ", " << BOOST_UBLAS_TEST_STRINGIFY_(i__) << " == " << i__ << ", " << BOOST_UBLAS_TEST_STRINGIFY_(j__) << " == " << BOOST_UBLAS_TEST_EXPAND_(j__) << ", " << BOOST_UBLAS_TEST_STRINGIFY_(nr) << " == " << BOOST_UBLAS_TEST_EXPAND_(nr) << " and " << BOOST_UBLAS_TEST_STRINGIFY_(nc) << " == " << BOOST_UBLAS_TEST_EXPAND_(nc) << "]" ); \
+															} \
+														} \
+													} \
+													/* [/BOOST_UBLAS_TEST_CHECK_MATRIX_EQ] */
+
+
+/// Check that elements of matrices \a x and \a y are close with respect to a given precision.
+#define BOOST_UBLAS_TEST_CHECK_MATRIX_CLOSE(x,y,nr,nc,e)	/* [BOOST_UBLAS_TEST_CHECK_MATRIX_CLOSE] */ \
+															for (unsigned long i__ = 0; i__ < BOOST_UBLAS_TEST_EXPAND_(nr); ++i__) \
+															{ \
+																for (unsigned long j__ = 0; j__ < BOOST_UBLAS_TEST_EXPAND_(nc); ++j__) \
+																{ \
+																	if (!::boost::numeric::ublas::test::detail::close_to(BOOST_UBLAS_TEST_EXPAND_(x)(i__,j__), BOOST_UBLAS_TEST_EXPAND_(y)(i__,j__), BOOST_UBLAS_TEST_EXPAND_(e))) \
+																	{ \
+																		BOOST_UBLAS_TEST_ERROR( "Failed assertion: abs((" << BOOST_UBLAS_TEST_STRINGIFY_(x(i__,j__)) << "-" << BOOST_UBLAS_TEST_STRINGIFY_(y(i__,j__)) << ") <= " << BOOST_UBLAS_TEST_STRINGIFY_(e)  << " [with " << BOOST_UBLAS_TEST_STRINGIFY_(x(i__,j__)) << " == " << BOOST_UBLAS_TEST_EXPAND_(x)(i__,j__) << ", " << BOOST_UBLAS_TEST_STRINGIFY_(y(i__,j__)) << " == " << BOOST_UBLAS_TEST_EXPAND_(y)(i__,j__) << ", " << BOOST_UBLAS_TEST_STRINGIFY_(i__) << " == " << i__ << ", " << BOOST_UBLAS_TEST_STRINGIFY_(j__) << " == " << BOOST_UBLAS_TEST_EXPAND_(j__) << ", " << BOOST_UBLAS_TEST_STRINGIFY_(nr) << " == " << BOOST_UBLAS_TEST_EXPAND_(nr) << " and " << BOOST_UBLAS_TEST_STRINGIFY_(nc) << " == " << BOOST_UBLAS_TEST_EXPAND_(nc) << "]" ); \
+																	} \
+																} \
+															} \
+															/* [/BOOST_UBLAS_TEST_CHECK_MATRIX_CLOSE] */
 
-#define BOOST_UBLAS_TEST_CHECK(x) if (!(x)) { std::cerr << "Failed assertion: " << STRINGIFY_(x) << std::endl; ++test_fails_; }
 
+///< Output the error message \a x.
+#define BOOST_UBLAS_TEST_ERROR(x) ::std::cerr << "[Error (" << __FILE__ << ":" << __func__ << ":" << __LINE__ << ")>> " << BOOST_UBLAS_TEST_EXPAND_(x) << ::std::endl
 
-#endif // TEST_UTILS_HPP
+#endif // BOOST_NUMERIC_UBLAS_TEST_UTILS_HPP