// // Copyright (c) 2000-2002 // Joerg Walter, Mathias Koch // // 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) // // The authors gratefully acknowledge the support of // GeNeSys mbH & Co. KG in producing this work. // #ifndef _BOOST_UBLAS_VECTOR_ASSIGN_ #define _BOOST_UBLAS_VECTOR_ASSIGN_ #include // scalar_assign // Required for make_conformant storage #include // Iterators based on ideas of Jeremy Siek namespace boost { namespace numeric { namespace ublas { namespace detail { // Weak equality check - useful to compare equality two arbitary vector expression results. // Since the actual expressions are unknown, we check for and arbitary error bound // on the relative error. // For a linear expression the infinity norm makes sense as we do not know how the elements will be // combined in the expression. False positive results are inevitable for arbirary expressions! template BOOST_UBLAS_INLINE bool equals (const vector_expression &e1, const vector_expression &e2, S epsilon, S min_norm) { return norm_inf (e1 - e2) < epsilon * std::max (std::max (norm_inf (e1), norm_inf (e2)), min_norm); } template BOOST_UBLAS_INLINE bool expression_type_check (const vector_expression &e1, const vector_expression &e2) { typedef typename type_traits::promote_type>::real_type real_type; return equals (e1, e2, BOOST_UBLAS_TYPE_CHECK_EPSILON, BOOST_UBLAS_TYPE_CHECK_MIN); } // Make sparse proxies conformant template // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it. void make_conformant (V &v, const vector_expression &e) { BOOST_UBLAS_CHECK (v.size () == e ().size (), bad_size ()); typedef typename V::size_type size_type; typedef typename V::difference_type difference_type; typedef typename V::value_type value_type; // FIXME unbounded_array with push_back maybe better std::vector index; typename V::iterator it (v.begin ()); typename V::iterator it_end (v.end ()); typename E::const_iterator ite (e ().begin ()); typename E::const_iterator ite_end (e ().end ()); if (it != it_end && ite != ite_end) { size_type it_index = it.index (), ite_index = ite.index (); while (true) { difference_type compare = it_index - ite_index; if (compare == 0) { ++ it, ++ ite; if (it != it_end && ite != ite_end) { it_index = it.index (); ite_index = ite.index (); } else break; } else if (compare < 0) { increment (it, it_end, - compare); if (it != it_end) it_index = it.index (); else break; } else if (compare > 0) { if (*ite != value_type/*zero*/()) index.push_back (ite.index ()); ++ ite; if (ite != ite_end) ite_index = ite.index (); else break; } } } while (ite != ite_end) { if (*ite != value_type/*zero*/()) index.push_back (ite.index ()); ++ ite; } for (size_type k = 0; k < index.size (); ++ k) v (index [k]) = value_type/*zero*/(); } }//namespace detail // Explicitly iterating template