⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matrix_assign.hpp

📁 CGAL is a collaborative effort of several sites in Europe and Israel. The goal is to make the most i
💻 HPP
📖 第 1 页 / 共 5 页
字号:
////  Copyright (c) 2000-2002//  Joerg Walter, Mathias Koch////  Permission to use, copy, modify, distribute and sell this software//  and its documentation for any purpose is hereby granted without fee,//  provided that the above copyright notice appear in all copies and//  that both that copyright notice and this permission notice appear//  in supporting documentation.  The authors make no representations//  about the suitability of this software for any purpose.//  It is provided "as is" without express or implied warranty.////  The authors gratefully acknowledge the support of//  GeNeSys mbH & Co. KG in producing this work.//#ifndef BOOST_UBLAS_MATRIX_ASSIGN_H#define BOOST_UBLAS_MATRIX_ASSIGN_H#include <boost/numeric/ublas/config.hpp>#include <boost/numeric/ublas/matrix_expression.hpp>// Iterators based on ideas of Jeremy Sieknamespace boost { namespace numeric { namespace ublas {    template<class E1, class E2>    BOOST_UBLAS_INLINE    bool equals (const matrix_expression<E1> &e1, const matrix_expression<E2> &e2) {        typedef BOOST_UBLAS_TYPENAME type_traits<BOOST_UBLAS_TYPENAME promote_traits<BOOST_UBLAS_TYPENAME E1::value_type,                                                                                     BOOST_UBLAS_TYPENAME E2::value_type>::promote_type>::real_type real_type;#ifndef __GNUC__        return norm_inf (e1 - e2) < BOOST_UBLAS_TYPE_CHECK_EPSILON *               std::max<real_type> (std::max<real_type> (norm_inf (e1),                                                         norm_inf (e2)),                                    BOOST_UBLAS_TYPE_CHECK_MIN);#else        // GCC 3.1, oops?!        return norm_inf (e1 - e2) < BOOST_UBLAS_TYPE_CHECK_EPSILON *               (std::max) (real_type ((std::max) (real_type (norm_inf (e1)), real_type (norm_inf (e2)))),                         real_type (BOOST_UBLAS_TYPE_CHECK_MIN));#endif    }    template<class M, class E, class F>    // This function seems to be big. So we do not let the compiler inline it.    // BOOST_UBLAS_INLINE    void make_conformant (M &m, const matrix_expression<E> &e, row_major_tag, F) {        BOOST_UBLAS_CHECK (m.size1 () == e ().size1 (), bad_size ());        BOOST_UBLAS_CHECK (m.size2 () == e ().size2 (), bad_size ());        typedef F functor_type;        typedef typename M::size_type size_type;        typedef typename M::difference_type difference_type;        typedef typename M::value_type value_type;        // FIXME unbounded_array with push_back maybe better        std::vector<std::pair<size_type, size_type> > index;        typename M::iterator1 it1 (m.begin1 ());        typename M::iterator1 it1_end (m.end1 ());        typename E::const_iterator1 it1e (e ().begin1 ());        typename E::const_iterator1 it1e_end (e ().end1 ());        while (it1 != it1_end && it1e != it1e_end) {            difference_type compare = it1.index1 () - it1e.index1 ();            if (compare == 0) {#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION                typename M::iterator2 it2 (it1.begin ());                typename M::iterator2 it2_end (it1.end ());                typename E::const_iterator2 it2e (it1e.begin ());                typename E::const_iterator2 it2e_end (it1e.end ());#else                typename M::iterator2 it2 (begin (it1, iterator1_tag ()));                typename M::iterator2 it2_end (end (it1, iterator1_tag ()));                typename E::const_iterator2 it2e (begin (it1e, iterator1_tag ()));                typename E::const_iterator2 it2e_end (end (it1e, iterator1_tag ()));#endif                if (it2 != it2_end && it2e != it2e_end) {                    size_type it2_index = it2.index2 (), it2e_index = it2e.index2 ();                    while (true) {                        difference_type compare = it2_index - it2e_index;                        if (compare == 0) {                            ++ it2, ++ it2e;                            if (it2 != it2_end && it2e != it2e_end) {                                it2_index = it2.index2 ();                                it2e_index = it2e.index2 ();                            } else                                break;                        } else if (compare < 0) {                            increment (it2, it2_end, - compare);                            if (it2 != it2_end)                                it2_index = it2.index2 ();                            else                                break;                        } else if (compare > 0) {                            if (functor_type::other (it2e.index1 (), it2e.index2 ()))                                if (*it2e != value_type (0))                                    index.push_back (std::pair<size_type, size_type> (it2e.index1 (), it2e.index2 ()));                            ++ it2e;                            if (it2e != it2e_end)                                it2e_index = it2e.index2 ();                            else                                break;                        }                    }                }                while (it2e != it2e_end) {                    if (functor_type::other (it2e.index1 (), it2e.index2 ()))                        if (*it2e != value_type (0))                            index.push_back (std::pair<size_type, size_type> (it2e.index1 (), it2e.index2 ()));                    ++ it2e;                }                ++ it1, ++ it1e;            } else if (compare < 0) {                increment (it1, it1_end, - compare);            } else if (compare > 0) {#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION                typename E::const_iterator2 it2e (it1e.begin ());                typename E::const_iterator2 it2e_end (it1e.end ());#else                typename E::const_iterator2 it2e (begin (it1e, iterator1_tag ()));                typename E::const_iterator2 it2e_end (end (it1e, iterator1_tag ()));#endif                while (it2e != it2e_end) {                    if (functor_type::other (it2e.index1 (), it2e.index2 ()))                        if (*it2e != value_type (0))                            index.push_back (std::pair<size_type, size_type> (it2e.index1 (), it2e.index2 ()));                    ++ it2e;                }                ++ it1e;            }        }        while (it1e != it1e_end) {#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION            typename E::const_iterator2 it2e (it1e.begin ());            typename E::const_iterator2 it2e_end (it1e.end ());#else            typename E::const_iterator2 it2e (begin (it1e, iterator1_tag ()));            typename E::const_iterator2 it2e_end (end (it1e, iterator1_tag ()));#endif            while (it2e != it2e_end) {                if (functor_type::other (it2e.index1 (), it2e.index2 ()))                    if (*it2e != value_type (0))                        index.push_back (std::pair<size_type, size_type> (it2e.index1 (), it2e.index2 ()));                ++ it2e;            }            ++ it1e;        }        for (size_type k = 0; k < index.size (); ++ k)            m (index [k].first, index [k].second) = value_type (0);    }    template<class M, class E, class F>    // This function seems to be big. So we do not let the compiler inline it.    // BOOST_UBLAS_INLINE    void make_conformant (M &m, const matrix_expression<E> &e, column_major_tag, F) {        BOOST_UBLAS_CHECK (m.size1 () == e ().size1 (), bad_size ());        BOOST_UBLAS_CHECK (m.size2 () == e ().size2 (), bad_size ());        typedef F functor_type;        typedef typename M::size_type size_type;        typedef typename M::difference_type difference_type;        typedef typename M::value_type value_type;        std::vector<std::pair<size_type, size_type> > index;        typename M::iterator2 it2 (m.begin2 ());        typename M::iterator2 it2_end (m.end2 ());        typename E::const_iterator2 it2e (e ().begin2 ());        typename E::const_iterator2 it2e_end (e ().end2 ());        while (it2 != it2_end && it2e != it2e_end) {            difference_type compare = it2.index2 () - it2e.index2 ();            if (compare == 0) {#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION                typename M::iterator1 it1 (it2.begin ());                typename M::iterator1 it1_end (it2.end ());                typename E::const_iterator1 it1e (it2e.begin ());                typename E::const_iterator1 it1e_end (it2e.end ());#else                typename M::iterator1 it1 (begin (it2, iterator2_tag ()));                typename M::iterator1 it1_end (end (it2, iterator2_tag ()));                typename E::const_iterator1 it1e (begin (it2e, iterator2_tag ()));                typename E::const_iterator1 it1e_end (end (it2e, iterator2_tag ()));#endif                if (it1 != it1_end && it1e != it1e_end) {                    size_type it1_index = it1.index1 (), it1e_index = it1e.index1 ();                    while (true) {                        difference_type compare = it1_index - it1e_index;                        if (compare == 0) {                            ++ it1, ++ it1e;                            if (it1 != it1_end && it1e != it1e_end) {                                it1_index = it1.index1 ();                                it1e_index = it1e.index1 ();                            } else                                break;                        } else if (compare < 0) {                            increment (it1, it1_end, - compare);                            if (it1 != it1_end)                                it1_index = it1.index1 ();                            else                                break;                        } else if (compare > 0) {                            if (functor_type::other (it1e.index1 (), it1e.index2 ()))                                if (*it1e != value_type (0))                                    index.push_back (std::pair<size_type, size_type> (it1e.index1 (), it1e.index2 ()));                            ++ it1e;                            if (it1e != it1e_end)                                it1e_index = it1e.index1 ();                            else                                break;                        }                    }                }                while (it1e != it1e_end) {                    if (functor_type::other (it1e.index1 (), it1e.index2 ()))                        if (*it1e != value_type (0))                            index.push_back (std::pair<size_type, size_type> (it1e.index1 (), it1e.index2 ()));                    ++ it1e;                }                ++ it2, ++ it2e;            } else if (compare < 0) {                increment (it2, it2_end, - compare);            } else if (compare > 0) {#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION                typename E::const_iterator1 it1e (it2e.begin ());                typename E::const_iterator1 it1e_end (it2e.end ());#else                typename E::const_iterator1 it1e (begin (it2e, iterator2_tag ()));                typename E::const_iterator1 it1e_end (end (it2e, iterator2_tag ()));#endif                while (it1e != it1e_end) {                    if (functor_type::other (it1e.index1 (), it1e.index2 ()))                        if (*it1e != value_type (0))                            index.push_back (std::pair<size_type, size_type> (it1e.index1 (), it1e.index2 ()));                    ++ it1e;                }                ++ it2e;            }        }        while (it2e != it2e_end) {#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION            typename E::const_iterator1 it1e (it2e.begin ());            typename E::const_iterator1 it1e_end (it2e.end ());#else            typename E::const_iterator1 it1e (begin (it2e, iterator2_tag ()));            typename E::const_iterator1 it1e_end (end (it2e, iterator2_tag ()));#endif            while (it1e != it1e_end) {                if (functor_type::other (it1e.index1 (), it1e.index2 ()))                    if (*it1e != value_type (0))                        index.push_back (std::pair<size_type, size_type> (it1e.index1 (), it1e.index2 ()));                ++ it1e;            }            ++ it2e;        }        for (size_type k = 0; k < index.size (); ++ k)            m (index [k].first, index [k].second) = value_type (0);    }    // Iterating row major case    template<class F, class M, class T>    // This function seems to be big. So we do not let the compiler inline it.    // BOOST_UBLAS_INLINE    void iterating_matrix_assign_scalar (F, M &m, const T &t, row_major_tag) {        typedef F functor_type;        typedef typename M::difference_type difference_type;        difference_type size1 (m.size1 ());        difference_type size2 (m.size2 ());        typename M::iterator1 it1 (m.begin1 ());        BOOST_UBLAS_CHECK (size2 == 0 || m.end1 () - it1 == size1, bad_size ());        while (-- size1 >= 0) {#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION            typename M::iterator2 it2 (it1.begin ());#else            typename M::iterator2 it2 (begin (it1, iterator1_tag ()));#endif            BOOST_UBLAS_CHECK (it1.end () - it2 == size2, bad_size ());            difference_type temp_size2 (size2);#ifndef BOOST_UBLAS_USE_DUFF_DEVICE            while (-- temp_size2 >= 0)                functor_type::apply (*it2, t), ++ it2;#else            DD (temp_size2, 4, r, (functor_type::apply (*it2, t), ++ it2));#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -