diff --git a/include/boost/numeric/ublas/config.hpp b/include/boost/numeric/ublas/config.hpp index 967512bd..cda142b1 100644 --- a/include/boost/numeric/ublas/config.hpp +++ b/include/boost/numeric/ublas/config.hpp @@ -123,8 +123,8 @@ // One of these workarounds is needed for MSVC 7.1 AFAIK // (thanks to John Maddock and Martin Lauer). // The second workaround looks like BOOST_UBLAS_QUALIFIED_TYPENAME. -// #define BOOST_UBLAS_NO_NESTED_CLASS_RELATION -#define BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION +#define BOOST_UBLAS_NO_NESTED_CLASS_RELATION +// #define BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION #endif diff --git a/include/boost/numeric/ublas/lu.hpp b/include/boost/numeric/ublas/lu.hpp index d22b0a16..3e26d7f2 100644 --- a/include/boost/numeric/ublas/lu.hpp +++ b/include/boost/numeric/ublas/lu.hpp @@ -52,7 +52,8 @@ namespace boost { namespace numeric { namespace ublas { size_type size = pm.size (); for (size_type i = 0; i < size; ++ i) { - std::swap (mv (i), mv (pm (i))); + if (i != pm (i)) + std::swap (mv (i), mv (pm (i))); } } template @@ -63,7 +64,8 @@ namespace boost { namespace numeric { namespace ublas { size_type size = pm.size (); for (size_type i = 0; i < size; ++ i) { - row (mv, i).swap (row (mv, pm (i))); + if (i != pm (i)) + row (mv, i).swap (row (mv, pm (i))); } } // Dispatcher @@ -95,6 +97,8 @@ namespace boost { namespace numeric { namespace ublas { if (i_norm_inf != i) { pm (i) = i_norm_inf; row (m, i_norm_inf).swap (mri); + } else { + BOOST_UBLAS_CHECK (pm (i) == i_norm_inf, external_logic ()); } project (mci, range (i + 1, size1)) *= value_type (1) / m (i, i); } else if (singular == 0) { @@ -145,6 +149,8 @@ namespace boost { namespace numeric { namespace ublas { pm (i) = i_norm_inf; std::swap (v (i_norm_inf), v (i)); project (row (m, i_norm_inf), range (i + 1, size2)).swap (project (row (m, i), range (i + 1, size2))); + } else { + BOOST_UBLAS_CHECK (pm (i) == i_norm_inf, external_logic ()); } project (column (mr, i), range (i + 1, size1)).assign ( project (v, range (i + 1, size1)) / v (i)); @@ -178,6 +184,8 @@ namespace boost { namespace numeric { namespace ublas { pm (i) = i_norm_inf; std::swap (v (i_norm_inf), v (i)); project (row (m, i_norm_inf), range (i + 1, size2)).swap (project (row (m, i), range (i + 1, size2))); + } else { + BOOST_UBLAS_CHECK (pm (i) == i_norm_inf, external_logic ()); } project (column (lr, i), range (i + 1, size1)).assign ( project (v, range (i + 1, size1)) / v (i)); @@ -204,7 +212,9 @@ namespace boost { namespace numeric { namespace ublas { template void lu_substitute (const M &m, const permutation_matrix &pm, MV &mv) { typedef const M const_matrix_type; - typedef MV matrix_vector_type; + typedef typename boost::mpl::if_c::value, + vector, + matrix >::type matrix_vector_type; swap_rows (pm, mv); #ifdef BOOST_UBLAS_TYPE_CHECK @@ -223,7 +233,9 @@ namespace boost { namespace numeric { namespace ublas { template void lu_substitute (MV &mv, const M &m, const permutation_matrix &pm) { typedef const M const_matrix_type; - typedef MV matrix_vector_type; + typedef typename boost::mpl::if_c::value, + vector, + matrix >::type matrix_vector_type; swap_rows (pm, mv); #ifdef BOOST_UBLAS_TYPE_CHECK diff --git a/include/boost/numeric/ublas/matrix_sparse.hpp b/include/boost/numeric/ublas/matrix_sparse.hpp index f6df6d9f..d6ac0169 100644 --- a/include/boost/numeric/ublas/matrix_sparse.hpp +++ b/include/boost/numeric/ublas/matrix_sparse.hpp @@ -53,31 +53,19 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE sparse_matrix_element (matrix_type &m, size_type i, size_type j): container_reference (m), it_ (), i_ (i), j_ (j), d_ (), dirty_ (false) { - // FIX: reduce fill in. - // pointer it = (*this) ().find_element (i_, j_); - // if (! it) - // (*this) ().insert (i_, j_, d_); - // else - // d_ = *it; - it_ = (*this) ().find_element (i_, j_); - if (it_) - d_ = *it_; + pointer it = (*this) ().find_element (i_, j_); + if (! it) + (*this) ().insert (i_, j_, d_); + else + d_ = *it; } BOOST_UBLAS_INLINE ~sparse_matrix_element () { - // FIX: reduce fill in. - // if (dirty_) { - // if (! it_) - // it_ = (*this) ().find_element (i_, j_); - // BOOST_UBLAS_CHECK (it_, internal_logic ()); - // *it_ = d_; - // } if (dirty_) { - if (! it_) { - if (d_ != value_type ()) - (*this) ().insert (i_, j_, d_); - } else - *it_ = d_; + if (! it_) + it_ = (*this) ().find_element (i_, j_); + BOOST_UBLAS_CHECK (it_, internal_logic ()); + *it_ = d_; } } diff --git a/include/boost/numeric/ublas/vector_sparse.hpp b/include/boost/numeric/ublas/vector_sparse.hpp index 54482313..a9b2b62a 100644 --- a/include/boost/numeric/ublas/vector_sparse.hpp +++ b/include/boost/numeric/ublas/vector_sparse.hpp @@ -52,31 +52,19 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE sparse_vector_element (vector_type &v, size_type i): container_reference (v), it_ (), i_ (i), d_ (), dirty_ (false) { - // FIX: reduce fill in. - // pointer it = (*this) ().find_element (i_); - // if (! it) - // (*this) ().insert (i_, d_); - // else - // d_ = *it; - it_ = (*this) ().find_element (i_); - if (it_) - d_ = *it_; + pointer it = (*this) ().find_element (i_); + if (! it) + (*this) ().insert (i_, d_); + else + d_ = *it; } BOOST_UBLAS_INLINE ~sparse_vector_element () { - // FIX: reduce fill in. - // if (dirty_) { - // if (! it_) - // it_ = (*this) ().find_element (i_); - // BOOST_UBLAS_CHECK (it_, internal_logic ()); - // *it_ = d_; - // } if (dirty_) { - if (! it_) { - if (d_ != value_type ()) - (*this) ().insert (i_, d_); - } else - *it_ = d_; + if (! it_) + it_ = (*this) ().find_element (i_); + BOOST_UBLAS_CHECK (it_, internal_logic ()); + *it_ = d_; } }