matrix_assign.hpp
来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 1,356 行 · 第 1/5 页
HPP
1,356 行
matrix<value_type, column_major> cm (m.size1 (), m.size2 ()); indexing_matrix_assign<scalar_assign> (cm, m, column_major_tag ()); indexing_matrix_assign<F> (cm, e, column_major_tag ());#endif detail::make_conformant (m, e, column_major_tag (), conformant_restrict_type ()); 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) { functor_type::apply (*it1, *it1e); ++ it1, ++ it1e; if (it1 != it1_end && it1e != it1e_end) { it1_index = it1.index1 (); it1e_index = it1e.index1 (); } else break; } else if (compare < 0) { if (!functor_type::computed) { functor_type::apply (*it1, value_type/*zero*/()); // zeroing ++ it1; } else increment (it1, it1_end, - compare); if (it1 != it1_end) it1_index = it1.index1 (); else break; } else if (compare > 0) { increment (it1e, it1e_end, compare); if (it1e != it1e_end) it1e_index = it1e.index1 (); else break; } } } if (!functor_type::computed) { while (it1 != it1_end) { // zeroing functor_type::apply (*it1, value_type/*zero*/()); ++ it1; } } else { it1 = it1_end; } ++ it2, ++ it2e; } else if (compare < 0) { if (!functor_type::computed) {#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION typename M::iterator1 it1 (it2.begin ()); typename M::iterator1 it1_end (it2.end ());#else typename M::iterator1 it1 (begin (it2, iterator2_tag ())); typename M::iterator1 it1_end (end (it2, iterator2_tag ()));#endif while (it1 != it1_end) { // zeroing functor_type::apply (*it1, value_type/*zero*/()); ++ it1; } ++ it2; } else { increment (it2, it2_end, - compare); } } else if (compare > 0) { increment (it2e, it2e_end, compare); } } if (!functor_type::computed) { while (it2 != it2_end) {#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION typename M::iterator1 it1 (it2.begin ()); typename M::iterator1 it1_end (it2.end ());#else typename M::iterator1 it1 (begin (it2, iterator2_tag ())); typename M::iterator1 it1_end (end (it2, iterator2_tag ()));#endif while (it1 != it1_end) { // zeroing functor_type::apply (*it1, value_type/*zero*/()); ++ it1; } ++ it2; } } else { it2 = it2_end; }#if BOOST_UBLAS_TYPE_CHECK if (! disable_type_check<bool>::value) BOOST_UBLAS_CHECK (detail::expression_type_check (m, cm), external_logic ());#endif } // Dispatcher template<template <class T1, class T2> class F, class M, class E> BOOST_UBLAS_INLINE void matrix_assign (M &m, const matrix_expression<E> &e) { typedef typename matrix_assign_traits<typename M::storage_category, F<typename M::reference, typename E::value_type>::computed, typename E::const_iterator1::iterator_category, typename E::const_iterator2::iterator_category>::storage_category storage_category; // give preference to matrix M's orientation if known typedef typename boost::mpl::if_<boost::is_same<typename M::orientation_category, unknown_orientation_tag>, typename E::orientation_category , typename M::orientation_category >::type orientation_category; typedef basic_full<typename M::size_type> unrestricted; matrix_assign<F, unrestricted> (m, e, storage_category (), orientation_category ()); } template<template <class T1, class T2> class F, class R, class M, class E> BOOST_UBLAS_INLINE void matrix_assign (M &m, const matrix_expression<E> &e) { typedef R conformant_restrict_type; typedef typename matrix_assign_traits<typename M::storage_category, F<typename M::reference, typename E::value_type>::computed, typename E::const_iterator1::iterator_category, typename E::const_iterator2::iterator_category>::storage_category storage_category; // give preference to matrix M's orientation if known typedef typename boost::mpl::if_<boost::is_same<typename M::orientation_category, unknown_orientation_tag>, typename E::orientation_category , typename M::orientation_category >::type orientation_category; matrix_assign<F, conformant_restrict_type> (m, e, storage_category (), orientation_category ()); } template<class SC, class RI1, class RI2> struct matrix_swap_traits { typedef SC storage_category; }; template<> struct matrix_swap_traits<dense_proxy_tag, sparse_bidirectional_iterator_tag, sparse_bidirectional_iterator_tag> { typedef sparse_proxy_tag storage_category; }; template<> struct matrix_swap_traits<packed_proxy_tag, sparse_bidirectional_iterator_tag, sparse_bidirectional_iterator_tag> { typedef sparse_proxy_tag storage_category; }; // Dense (proxy) row major case template<template <class T1, class T2> class F, class R, class M, class E> // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it. void matrix_swap (M &m, matrix_expression<E> &e, dense_proxy_tag, row_major_tag) { typedef F<typename M::iterator2::reference, typename E::reference> functor_type; // R unnecessary, make_conformant not required typedef typename M::size_type size_type; typedef typename M::difference_type difference_type; typename M::iterator1 it1 (m.begin1 ()); typename E::iterator1 it1e (e ().begin1 ()); difference_type size1 (BOOST_UBLAS_SAME (m.size1 (), size_type (e ().end1 () - it1e))); while (-- size1 >= 0) {#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION typename M::iterator2 it2 (it1.begin ()); typename E::iterator2 it2e (it1e.begin ()); difference_type size2 (BOOST_UBLAS_SAME (m.size2 (), size_type (it1e.end () - it2e)));#else typename M::iterator2 it2 (begin (it1, iterator1_tag ())); typename E::iterator2 it2e (begin (it1e, iterator1_tag ())); difference_type size2 (BOOST_UBLAS_SAME (m.size2 (), size_type (end (it1e, iterator1_tag ()) - it2e)));#endif while (-- size2 >= 0) functor_type::apply (*it2, *it2e), ++ it2, ++ it2e; ++ it1, ++ it1e; } } // Dense (proxy) column major case template<template <class T1, class T2> class F, class R, class M, class E> // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it. void matrix_swap (M &m, matrix_expression<E> &e, dense_proxy_tag, column_major_tag) { typedef F<typename M::iterator1::reference, typename E::reference> functor_type; // R unnecessary, make_conformant not required typedef typename M::size_type size_type; typedef typename M::difference_type difference_type; typename M::iterator2 it2 (m.begin2 ()); typename E::iterator2 it2e (e ().begin2 ()); difference_type size2 (BOOST_UBLAS_SAME (m.size2 (), size_type (e ().end2 () - it2e))); while (-- size2 >= 0) {#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION typename M::iterator1 it1 (it2.begin ()); typename E::iterator1 it1e (it2e.begin ()); difference_type size1 (BOOST_UBLAS_SAME (m.size1 (), size_type (it2e.end () - it1e)));#else typename M::iterator1 it1 (begin (it2, iterator2_tag ())); typename E::iterator1 it1e (begin (it2e, iterator2_tag ())); difference_type size1 (BOOST_UBLAS_SAME (m.size1 (), size_type (end (it2e, iterator2_tag ()) - it1e)));#endif while (-- size1 >= 0) functor_type::apply (*it1, *it1e), ++ it1, ++ it1e; ++ it2, ++ it2e; } } // Packed (proxy) row major case template<template <class T1, class T2> class F, class R, class M, class E> // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it. void matrix_swap (M &m, matrix_expression<E> &e, packed_proxy_tag, row_major_tag) { typedef F<typename M::iterator2::reference, typename E::reference> functor_type; // R unnecessary, make_conformant not required typedef typename M::size_type size_type; typedef typename M::difference_type difference_type; typename M::iterator1 it1 (m.begin1 ()); typename E::iterator1 it1e (e ().begin1 ()); difference_type size1 (BOOST_UBLAS_SAME (m.end1 () - it1, e ().end1 () - it1e)); while (-- size1 >= 0) {#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION typename M::iterator2 it2 (it1.begin ()); typename E::iterator2 it2e (it1e.begin ()); difference_type size2 (BOOST_UBLAS_SAME (it1.end () - it2, it1e.end () - it2e));#else typename M::iterator2 it2 (begin (it1, iterator1_tag ())); typename E::iterator2 it2e (begin (it1e, iterator1_tag ())); difference_type size2 (BOOST_UBLAS_SAME (end (it1, iterator1_tag ()) - it2, end (it1e, iterator1_tag ()) - it2e));#endif while (-- size2 >= 0) functor_type::apply (*it2, *it2e), ++ it2, ++ it2e; ++ it1, ++ it1e; } } // Packed (proxy) column major case template<template <class T1, class T2> class F, class R, class M, class E> // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it. void matrix_swap (M &m, matrix_expression<E> &e, packed_proxy_tag, column_major_tag) { typedef F<typename M::iterator1::reference, typename E::reference> functor_type; // R unnecessary, make_conformant not required typedef typename M::size_type size_type; typedef typename M::difference_type difference_type; typename M::iterator2 it2 (m.begin2 ()); typename E::iterator2 it2e (e ().begin2 ()); difference_type size2 (BOOST_UBLAS_SAME (m.end2 () - it2, e ().end2 () - it2e)); while (-- size2 >= 0) {#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION typename M::iterator1 it1 (it2.begin ()); typename E::iterator1 it1e (it2e.begin ()); difference_type size1 (BOOST_UBLAS_SAME (it2.end () - it1, it2e.end () - it1e));#else typename M::iterator1 it1 (begin (it2, iterator2_tag ())); typename E::iterator1 it1e (begin (it2e, iterator2_tag ())); difference_type size1 (BOOST_UBLAS_SAME (end (it2, iterator2_tag ()) - it1, end (it2e, iterator2_tag ()) - it1e));#endif while (-- size1 >= 0) functor_type::apply (*it1, *it1e), ++ it1, ++ it1e; ++ it2, ++ it2e; } } // Sparse (proxy) row major case template<template <class T1, class T2> class F, class R, class M, class E> // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it. void matrix_swap (M &m, matrix_expression<E> &e, sparse_proxy_tag, row_major_tag) { typedef F<typename M::iterator2::reference, typename E::reference> functor_type; typedef R conformant_restrict_type; typedef typename M::size_type size_type; typedef typename M::difference_type difference_type; typedef typename M::value_type value_type; BOOST_UBLAS_CHECK (m.size1 () == e
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?