📄 matrix_assign.hpp
字号:
if (!functor_type::computed) {
while (-- size2 >= 0) { // zeroing
#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
difference_type size1 (it1_end - it1);
while (-- size1 >= 0)
functor_type::apply (*it1, value_type/*zero*/()), ++ it1;
++ it2;
}
} else {
it2 += size2;
}
diff2 += size2;
}
}
difference_type size2 ((std::min) (it2_size, it2e_size));
it2_size -= size2;
it2e_size -= size2;
while (-- size2 >= 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
difference_type it1_size (it1_end - it1);
difference_type it1e_size (it1e_end - it1e);
difference_type diff1 (0);
if (it1_size > 0 && it1e_size > 0) {
diff1 = it1.index1 () - it1e.index1 ();
difference_type size1 = (std::min) (diff1, it1e_size);
if (size1 > 0) {
it1e += size1;
it1e_size -= size1;
diff1 -= size1;
}
size1 = (std::min) (- diff1, it1_size);
if (size1 > 0) {
it1_size -= size1;
if (!functor_type::computed) {
while (-- size1 >= 0) // zeroing
functor_type::apply (*it1, value_type/*zero*/()), ++ it1;
} else {
it1 += size1;
}
diff1 += size1;
}
}
difference_type size1 ((std::min) (it1_size, it1e_size));
it1_size -= size1;
it1e_size -= size1;
while (-- size1 >= 0)
functor_type::apply (*it1, *it1e), ++ it1, ++ it1e;
size1 = it1_size;
if (!functor_type::computed) {
while (-- size1 >= 0) // zeroing
functor_type::apply (*it1, value_type/*zero*/()), ++ it1;
} else {
it1 += size1;
}
++ it2, ++ it2e;
}
size2 = it2_size;
if (!functor_type::computed) {
while (-- size2 >= 0) { // zeroing
#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
difference_type size1 (it1_end - it1);
while (-- size1 >= 0)
functor_type::apply (*it1, value_type/*zero*/()), ++ it1;
++ it2;
}
} else {
it2 += size2;
}
#if BOOST_UBLAS_TYPE_CHECK
if (! disable_type_check<bool>::value)
BOOST_UBLAS_CHECK (detail::expression_type_check (m, cm), external_logic ());
#endif
}
// Sparse 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_assign (M &m, const matrix_expression<E> &e, sparse_tag, row_major_tag) {
typedef F<typename M::iterator2::reference, typename E::value_type> functor_type;
// R unnecessary, make_conformant not required
BOOST_STATIC_ASSERT ((!functor_type::computed));
BOOST_UBLAS_CHECK (m.size1 () == e ().size1 (), bad_size ());
BOOST_UBLAS_CHECK (m.size2 () == e ().size2 (), bad_size ());
typedef typename M::value_type value_type;
// Sparse type has no numeric constraints to check
m.clear ();
typename E::const_iterator1 it1e (e ().begin1 ());
typename E::const_iterator1 it1e_end (e ().end1 ());
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) {
value_type t (*it2e);
if (t != value_type/*zero*/())
m.insert_element (it2e.index1 (), it2e.index2 (), t);
++ it2e;
}
++ it1e;
}
}
// Sparse 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_assign (M &m, const matrix_expression<E> &e, sparse_tag, column_major_tag) {
typedef F<typename M::iterator1::reference, typename E::value_type> functor_type;
// R unnecessary, make_conformant not required
BOOST_STATIC_ASSERT ((!functor_type::computed));
BOOST_UBLAS_CHECK (m.size1 () == e ().size1 (), bad_size ());
BOOST_UBLAS_CHECK (m.size2 () == e ().size2 (), bad_size ());
typedef typename M::value_type value_type;
// Sparse type has no numeric constraints to check
m.clear ();
typename E::const_iterator2 it2e (e ().begin2 ());
typename E::const_iterator2 it2e_end (e ().end2 ());
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) {
value_type t (*it1e);
if (t != value_type/*zero*/())
m.insert_element (it1e.index1 (), it1e.index2 (), t);
++ it1e;
}
++ it2e;
}
}
// Sparse proxy or functional 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_assign (M &m, const matrix_expression<E> &e, sparse_proxy_tag, row_major_tag) {
typedef F<typename M::iterator2::reference, typename E::value_type> 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 ().size1 (), bad_size ());
BOOST_UBLAS_CHECK (m.size2 () == e ().size2 (), bad_size ());
#if BOOST_UBLAS_TYPE_CHECK
matrix<value_type, row_major> cm (m.size1 (), m.size2 ());
indexing_matrix_assign<scalar_assign> (cm, m, row_major_tag ());
indexing_matrix_assign<F> (cm, e, row_major_tag ());
#endif
detail::make_conformant (m, e, row_major_tag (), conformant_restrict_type ());
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) {
functor_type::apply (*it2, *it2e);
++ it2, ++ it2e;
if (it2 != it2_end && it2e != it2e_end) {
it2_index = it2.index2 ();
it2e_index = it2e.index2 ();
} else
break;
} else if (compare < 0) {
if (!functor_type::computed) {
functor_type::apply (*it2, value_type/*zero*/());
++ it2;
} else
increment (it2, it2_end, - compare);
if (it2 != it2_end)
it2_index = it2.index2 ();
else
break;
} else if (compare > 0) {
increment (it2e, it2e_end, compare);
if (it2e != it2e_end)
it2e_index = it2e.index2 ();
else
break;
}
}
}
if (!functor_type::computed) {
while (it2 != it2_end) { // zeroing
functor_type::apply (*it2, value_type/*zero*/());
++ it2;
}
} else {
it2 = it2_end;
}
++ it1, ++ it1e;
} else if (compare < 0) {
if (!functor_type::computed) {
#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
typename M::iterator2 it2 (it1.begin ());
typename M::iterator2 it2_end (it1.end ());
#else
typename M::iterator2 it2 (begin (it1, iterator1_tag ()));
typename M::iterator2 it2_end (end (it1, iterator1_tag ()));
#endif
while (it2 != it2_end) { // zeroing
functor_type::apply (*it2, value_type/*zero*/());
++ it2;
}
++ it1;
} else {
increment (it1, it1_end, - compare);
}
} else if (compare > 0) {
increment (it1e, it1e_end, compare);
}
}
if (!functor_type::computed) {
while (it1 != it1_end) {
#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
typename M::iterator2 it2 (it1.begin ());
typename M::iterator2 it2_end (it1.end ());
#else
typename M::iterator2 it2 (begin (it1, iterator1_tag ()));
typename M::iterator2 it2_end (end (it1, iterator1_tag ()));
#endif
while (it2 != it2_end) { // zeroing
functor_type::apply (*it2, value_type/*zero*/());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -