Boost logo

Boost-Commit :

From: guwi17_at_[hidden]
Date: 2008-04-28 17:50:20


Author: guwi17
Date: 2008-04-28 17:50:19 EDT (Mon, 28 Apr 2008)
New Revision: 44864
URL: http://svn.boost.org/trac/boost/changeset/44864

Log:
- fix and close #1829
- You are right. The scaled norm wrongly assumed that the first element is not zero.

Text files modified:
   trunk/boost/numeric/ublas/functional.hpp | 49 +++++++++++++++++++++++----------------
   1 files changed, 29 insertions(+), 20 deletions(-)

Modified: trunk/boost/numeric/ublas/functional.hpp
==============================================================================
--- trunk/boost/numeric/ublas/functional.hpp (original)
+++ trunk/boost/numeric/ublas/functional.hpp 2008-04-28 17:50:19 EDT (Mon, 28 Apr 2008)
@@ -446,6 +446,7 @@
             size_type size (e ().size ());
             for (size_type i = 0; i < size; ++ i) {
                 real_type u (type_traits<value_type>::norm_2 (e () (i)));
+ if ( real_type () /* zero */ == u ) continue;
                 if (scale < u) {
                     real_type v (scale / u);
                     sum_squares = sum_squares * v * v + real_type (1);
@@ -1851,6 +1852,8 @@
             return (std::max) (i, j);
         }
     };
+
+ // the first row only contains a single 1. Thus it is not stored.
     template <class Z>
     struct basic_unit_lower : public basic_lower<Z> {
         typedef Z size_type;
@@ -1879,21 +1882,23 @@
         BOOST_UBLAS_INLINE
         size_type element (L, size_type i, size_type size_i, size_type j, size_type size_j) {
             // Zero size strict triangles are bad at this point
- BOOST_UBLAS_CHECK (size_i != 0 && size_j != 0, bad_index ());
- return L::lower_element (i, size_i - 1, j, size_j - 1);
+ BOOST_UBLAS_CHECK (size_i != 0 && size_j != 0 && i != 0, bad_index ());
+ return L::lower_element (i-1, size_i - 1, j, size_j - 1);
         }
 
         static
         BOOST_UBLAS_INLINE
         size_type mutable_restrict1 (size_type i, size_type j) {
- return (std::max) (i, j);
+ return (std::max) ( (std::max<size_type>)(1, i), j);
         }
         static
         BOOST_UBLAS_INLINE
         size_type mutable_restrict2 (size_type i, size_type j) {
- return (std::min) (i, j);
+ return (std::min) ( (std::max<size_type>)(1, i), j);
         }
     };
+
+ // the last row only contains a single 1. Thus it is not stored.
     template <class Z>
     struct basic_unit_upper : public basic_upper<Z> {
         typedef Z size_type;
@@ -1922,21 +1927,23 @@
         BOOST_UBLAS_INLINE
         size_type element (L, size_type i, size_type size_i, size_type j, size_type size_j) {
             // Zero size strict triangles are bad at this point
- BOOST_UBLAS_CHECK (size_i != 0 && size_j != 0, bad_index ());
- return L::upper_element (i, size_i - 1, j, size_j - 1);
+ BOOST_UBLAS_CHECK (size_i != 0 && size_j != 0 && j != 0, bad_index ());
+ return L::upper_element (i, size_i - 1, j-1, size_j - 1);
         }
 
         static
         BOOST_UBLAS_INLINE
         size_type mutable_restrict1 (size_type i, size_type j) {
- return (std::min) (i, j);
+ return (std::min) (i, (std::max<size_type>)(1, j));
         }
         static
         BOOST_UBLAS_INLINE
         size_type mutable_restrict2 (size_type i, size_type j) {
- return (std::max) (i, j);
+ return (std::max) (i, (std::max<size_type>)(1, j));
         }
     };
+
+ // the first row only contains a single 1. Thus it is not stored.
     template <class Z>
     struct basic_strict_lower : public basic_lower<Z> {
         typedef Z size_type;
@@ -1970,31 +1977,33 @@
         BOOST_UBLAS_INLINE
         size_type element (L, size_type i, size_type size_i, size_type j, size_type size_j) {
             // Zero size strict triangles are bad at this point
- BOOST_UBLAS_CHECK (size_i != 0 && size_j != 0, bad_index ());
- return L::lower_element (i, size_i - 1, j, size_j - 1);
+ BOOST_UBLAS_CHECK (size_i != 0 && size_j != 0 && i != 0, bad_index ());
+ return L::lower_element (i-1, size_i - 1, j, size_j - 1);
         }
 
         static
         BOOST_UBLAS_INLINE
         size_type restrict1 (size_type i, size_type j) {
- return (std::max) (i, j);
+ return (std::max) ( (std::max<size_type>)(1, i), j);
         }
         static
         BOOST_UBLAS_INLINE
         size_type restrict2 (size_type i, size_type j) {
- return (std::min) (i, j);
+ return (std::min) ( (std::max<size_type>)(1, i), j);
         }
         static
         BOOST_UBLAS_INLINE
         size_type mutable_restrict1 (size_type i, size_type j) {
- return (std::max) (i, j);
+ return (std::max) ( (std::max<size_type>)(1, i), j);
         }
         static
         BOOST_UBLAS_INLINE
         size_type mutable_restrict2 (size_type i, size_type j) {
- return (std::min) (i, j);
+ return (std::min) ( (std::max<size_type>)(1, i), j);
         }
     };
+
+ // the last row only contains a single 1. Thus it is not stored.
     template <class Z>
     struct basic_strict_upper : public basic_upper<Z> {
         typedef Z size_type;
@@ -2028,29 +2037,29 @@
         BOOST_UBLAS_INLINE
         size_type element (L, size_type i, size_type size_i, size_type j, size_type size_j) {
             // Zero size strict triangles are bad at this point
- BOOST_UBLAS_CHECK (size_i != 0 && size_j != 0, bad_index ());
- return L::upper_element (i, size_i - 1, j, size_j - 1);
+ BOOST_UBLAS_CHECK (size_i != 0 && size_j != 0 && j != 0, bad_index ());
+ return L::upper_element (i, size_i - 1, j-1, size_j - 1);
         }
 
         static
         BOOST_UBLAS_INLINE
         size_type restrict1 (size_type i, size_type j) {
- return (std::min) (i, j);
+ return (std::min) (i, (std::max<size_type>)(1, j));
         }
         static
         BOOST_UBLAS_INLINE
         size_type restrict2 (size_type i, size_type j) {
- return (std::max) (i, j);
+ return (std::max) (i, (std::max<size_type>)(1, j));
         }
         static
         BOOST_UBLAS_INLINE
         size_type mutable_restrict1 (size_type i, size_type j) {
- return (std::min) (i, j);
+ return (std::min) (i, (std::max<size_type>)(1, j));
         }
         static
         BOOST_UBLAS_INLINE
         size_type mutable_restrict2 (size_type i, size_type j) {
- return (std::max) (i, j);
+ return (std::max) (i, (std::max<size_type>)(1, j));
         }
     };
 


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