📄 matrix_assign.hpp
字号:
++ it1;
}
}
// Sparse (proxy) column 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 matrix_assign_scalar (F, M &m, const T &t, sparse_proxy_tag, column_major_tag) {
typedef F functor_type;
typename M::iterator2 it2 (m.begin2 ());
typename M::iterator2 it2_end (m.end2 ());
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)
functor_type () (*it1, t), ++ it1;
++ it2;
}
}
// Dispatcher
template<class F, class M, class T>
BOOST_UBLAS_INLINE
void matrix_assign_scalar (F, M &m, const T &t) {
typedef F functor_type;
typedef typename M::storage_category storage_category;
typedef typename M::orientation_category orientation_category;
matrix_assign_scalar (functor_type (), m, t, storage_category (), orientation_category ());
}
template<class LS, class A, class RI1, class RI2>
struct matrix_assign_traits {
typedef LS storage_category;
};
template<>
struct matrix_assign_traits<dense_tag, assign_tag, packed_random_access_iterator_tag, packed_random_access_iterator_tag> {
typedef packed_tag storage_category;
};
template<>
struct matrix_assign_traits<dense_tag, computed_assign_tag, packed_random_access_iterator_tag, packed_random_access_iterator_tag> {
typedef packed_tag storage_category;
};
template<>
struct matrix_assign_traits<dense_tag, assign_tag, sparse_bidirectional_iterator_tag, sparse_bidirectional_iterator_tag> {
typedef sparse_tag storage_category;
};
template<>
struct matrix_assign_traits<dense_tag, computed_assign_tag, sparse_bidirectional_iterator_tag, sparse_bidirectional_iterator_tag> {
typedef sparse_proxy_tag storage_category;
};
template<>
struct matrix_assign_traits<dense_proxy_tag, assign_tag, packed_random_access_iterator_tag, packed_random_access_iterator_tag> {
typedef packed_proxy_tag storage_category;
};
template<>
struct matrix_assign_traits<dense_proxy_tag, computed_assign_tag, packed_random_access_iterator_tag, packed_random_access_iterator_tag> {
typedef packed_proxy_tag storage_category;
};
template<>
struct matrix_assign_traits<dense_proxy_tag, assign_tag, sparse_bidirectional_iterator_tag, sparse_bidirectional_iterator_tag> {
typedef sparse_proxy_tag storage_category;
};
template<>
struct matrix_assign_traits<dense_proxy_tag, computed_assign_tag, sparse_bidirectional_iterator_tag, sparse_bidirectional_iterator_tag> {
typedef sparse_proxy_tag storage_category;
};
template<>
struct matrix_assign_traits<packed_tag, assign_tag, sparse_bidirectional_iterator_tag, sparse_bidirectional_iterator_tag> {
typedef sparse_tag storage_category;
};
template<>
struct matrix_assign_traits<packed_tag, computed_assign_tag, sparse_bidirectional_iterator_tag, sparse_bidirectional_iterator_tag> {
typedef sparse_proxy_tag storage_category;
};
template<>
struct matrix_assign_traits<packed_proxy_tag, assign_tag, sparse_bidirectional_iterator_tag, sparse_bidirectional_iterator_tag> {
typedef sparse_proxy_tag storage_category;
};
template<>
struct matrix_assign_traits<packed_proxy_tag, computed_assign_tag, sparse_bidirectional_iterator_tag, sparse_bidirectional_iterator_tag> {
typedef sparse_proxy_tag storage_category;
};
template<>
struct matrix_assign_traits<sparse_tag, computed_assign_tag, dense_random_access_iterator_tag, dense_random_access_iterator_tag> {
typedef sparse_proxy_tag storage_category;
};
template<>
struct matrix_assign_traits<sparse_tag, computed_assign_tag, packed_random_access_iterator_tag, packed_random_access_iterator_tag> {
typedef sparse_proxy_tag storage_category;
};
template<>
struct matrix_assign_traits<sparse_tag, computed_assign_tag, sparse_bidirectional_iterator_tag, sparse_bidirectional_iterator_tag> {
typedef sparse_proxy_tag storage_category;
};
// Iterating row major case
template<class F, class M, class E>
// This function seems to be big. So we do not let the compiler inline it.
// BOOST_UBLAS_INLINE
void iterating_matrix_assign (F, M &m, const matrix_expression<E> &e, row_major_tag) {
typedef F functor_type;
typedef typename M::difference_type difference_type;
difference_type size1 (BOOST_UBLAS_SAME (m.size1 (), e ().size1 ()));
difference_type size2 (BOOST_UBLAS_SAME (m.size2 (), e ().size2 ()));
typename M::iterator1 it1 (m.begin1 ());
BOOST_UBLAS_CHECK (size2 == 0 || m.end1 () - it1 == size1, bad_size ());
typename E::const_iterator1 it1e (e ().begin1 ());
BOOST_UBLAS_CHECK (size2 == 0 || e ().end1 () - it1e == size1, bad_size ());
while (-- size1 >= 0) {
#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
typename M::iterator2 it2 (it1.begin ());
typename E::const_iterator2 it2e (it1e.begin ());
#else
typename M::iterator2 it2 (begin (it1, iterator1_tag ()));
typename E::const_iterator2 it2e (begin (it1e, iterator1_tag ()));
#endif
BOOST_UBLAS_CHECK (it1.end () - it2 == size2, bad_size ());
BOOST_UBLAS_CHECK (it1e.end () - it2e == size2, bad_size ());
difference_type temp_size2 (size2);
#ifndef BOOST_UBLAS_USE_DUFF_DEVICE
while (-- temp_size2 >= 0)
functor_type () (*it2, *it2e), ++ it2, ++ it2e;
#else
DD (temp_size2, 2, r, (functor_type () (*it2, *it2e), ++ it2, ++ it2e));
#endif
++ it1, ++ it1e;
}
}
// Iterating column major case
template<class F, class M, class E>
// This function seems to be big. So we do not let the compiler inline it.
// BOOST_UBLAS_INLINE
void iterating_matrix_assign (F, M &m, const matrix_expression<E> &e, column_major_tag) {
typedef F functor_type;
typedef typename M::difference_type difference_type;
difference_type size2 (BOOST_UBLAS_SAME (m.size2 (), e ().size2 ()));
difference_type size1 (BOOST_UBLAS_SAME (m.size1 (), e ().size1 ()));
typename M::iterator2 it2 (m.begin2 ());
BOOST_UBLAS_CHECK (size1 == 0 || m.end2 () - it2 == size2, bad_size ());
typename E::const_iterator2 it2e (e ().begin2 ());
BOOST_UBLAS_CHECK (size1 == 0 || e ().end2 () - it2e == size2, bad_size ());
while (-- size2 >= 0) {
#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
typename M::iterator1 it1 (it2.begin ());
typename E::const_iterator1 it1e (it2e.begin ());
#else
typename M::iterator1 it1 (begin (it2, iterator2_tag ()));
typename E::const_iterator1 it1e (begin (it2e, iterator2_tag ()));
#endif
BOOST_UBLAS_CHECK (it2.end () - it1 == size1, bad_size ());
BOOST_UBLAS_CHECK (it2e.end () - it1e == size1, bad_size ());
difference_type temp_size1 (size1);
#ifndef BOOST_UBLAS_USE_DUFF_DEVICE
while (-- temp_size1 >= 0)
functor_type () (*it1, *it1e), ++ it1, ++ it1e;
#else
DD (temp_size1, 2, r, (functor_type () (*it1, *it1e), ++ it1, ++ it1e));
#endif
++ it2, ++ it2e;
}
}
// Indexing row major case
template<class F, class M, class E>
// This function seems to be big. So we do not let the compiler inline it.
// BOOST_UBLAS_INLINE
void indexing_matrix_assign (F, M &m, const matrix_expression<E> &e, row_major_tag) {
typedef F functor_type;
typedef typename M::difference_type difference_type;
difference_type size1 (BOOST_UBLAS_SAME (m.size1 (), e ().size1 ()));
difference_type size2 (BOOST_UBLAS_SAME (m.size2 (), e ().size2 ()));
for (difference_type i = 0; i < size1; ++ i) {
#ifndef BOOST_UBLAS_USE_DUFF_DEVICE
for (difference_type j = 0; j < size2; ++ j)
functor_type () (m (i, j), e () (i, j));
#else
difference_type j (0);
DD (size2, 2, r, (functor_type () (m (i, j), e () (i, j)), ++ j));
#endif
}
}
// Indexing column major case
template<class F, class M, class E>
// This function seems to be big. So we do not let the compiler inline it.
// BOOST_UBLAS_INLINE
void indexing_matrix_assign (F, M &m, const matrix_expression<E> &e, column_major_tag) {
typedef F functor_type;
typedef typename M::difference_type difference_type;
difference_type size2 (BOOST_UBLAS_SAME (m.size2 (), e ().size2 ()));
difference_type size1 (BOOST_UBLAS_SAME (m.size1 (), e ().size1 ()));
for (difference_type j = 0; j < size2; ++ j)
#ifndef BOOST_UBLAS_USE_DUFF_DEVICE
for (difference_type i = 0; i < size1; ++ i) {
functor_type () (m (i, j), e () (i, j));
#else
difference_type i (0);
DD (size1, 2, r, (functor_type () (m (i, j), e () (i, j)), ++ i));
#endif
}
}
// Dense (proxy) case
template<class F, class M, class E, class C>
// This function seems to be big. So we do not let the compiler inline it.
// BOOST_UBLAS_INLINE
void matrix_assign (F, M &m, const matrix_expression<E> &e, full, dense_proxy_tag, C) {
typedef F functor_type;
typedef C orientation_category;
#ifdef BOOST_UBLAS_USE_INDEXING
indexing_matrix_assign (functor_type (), m, e, orientation_category ());
#elif BOOST_UBLAS_USE_ITERATING
iterating_matrix_assign (functor_type (), m, e, orientation_category ());
#else
typedef typename M::difference_type difference_type;
difference_type size1 (BOOST_UBLAS_SAME (m.size1 (), e ().size1 ()));
difference_type size2 (BOOST_UBLAS_SAME (m.size2 (), e ().size2 ()));
if (size1 >= BOOST_UBLAS_ITERATOR_THRESHOLD &&
size2 >= BOOST_UBLAS_ITERATOR_THRESHOLD)
iterating_matrix_assign (functor_type (), m, e, orientation_category ());
else
indexing_matrix_assign (functor_type (), m, e, orientation_category ());
#endif
}
// Packed (proxy) row major case
template<class F1, class M, class E, class F2>
// This function seems to be big. So we do not let the compiler inline it.
// BOOST_UBLAS_INLINE
void matrix_assign (F1, M &m, const matrix_expression<E> &e, F2, packed_proxy_tag, row_major_tag) {
BOOST_UBLAS_CHECK (m.size1 () == e ().size1 (), bad_size ());
BOOST_UBLAS_CHECK (m.size2 () == e ().size2 (), bad_size ());
typedef F1 functor1_type;
typedef F2 functor2_type;
typedef typename M::difference_type difference_type;
typedef typename M::value_type value_type;
#ifdef BOOST_UBLAS_TYPE_CHECK
matrix<value_type, row_major> cm (m.size1 (), m.size2 ());
#ifndef BOOST_UBLAS_NO_ELEMENT_PROXIES
indexing_matrix_assign (scalar_assign<typename matrix<value_type, row_major>::reference, value_type> (), cm, m, row_major_tag ());
indexing_matrix_assign (functor1_type::template make_debug_functor<typename matrix<value_type, row_major>::reference, value_type> (), cm, e, row_major_tag ());
#else
indexing_matrix_assign (scalar_assign<value_type, value_type> (), cm, m, row_major_tag ());
indexing_matrix_assign (functor1_type (), cm, e, row_major_tag ());
#endif
#endif
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 ());
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 ();
if (diff1 != 0) {
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 (boost::is_same<BOOST_UBLAS_TYPENAME functor1_type::assign_category, assign_tag>::value) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -