📄 operation.hpp
字号:
for (size_type i = 0; i < size1; ++ i) column (m, j).plus_assign (e2 () (i, j) * column (e1 (), i));#if BOOST_UBLAS_TYPE_CHECK BOOST_UBLAS_CHECK (norm_1 (m - cm) <= 2 * std::numeric_limits<real_type>::epsilon () * merrorbound, internal_logic ());#endif return m; } template<class M, class E1, class E2, class F> BOOST_UBLAS_INLINE M & axpy_prod (const matrix_expression<E1> &e1, const matrix_expression<E2> &e2, M &m, F, sparse_proxy_tag, column_major_tag) { typedef M matrix_type; typedef const E1 expression1_type; typedef const E2 expression2_type; typedef typename M::size_type size_type; typedef typename M::value_type value_type; typedef F functor_type;#if BOOST_UBLAS_TYPE_CHECK matrix<value_type, column_major> cm (m); typedef typename type_traits<value_type>::real_type real_type; real_type merrorbound (norm_1 (m) + norm_1 (e1) * norm_1 (e2)); indexing_matrix_assign (scalar_plus_assign<typename matrix<value_type, column_major>::reference, value_type> (), cm, prod (e1, e2), column_major_tag ());#endif typename expression2_type::const_iterator2 it2 (e2 ().begin2 ()); typename expression2_type::const_iterator2 it2_end (e2 ().end2 ()); while (it2 != it2_end) {#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION typename expression2_type::const_iterator1 it1 (it2.begin ()); typename expression2_type::const_iterator1 it1_end (it2.end ());#else typename expression2_type::const_iterator1 it1 (boost::numeric::ublas::begin (it2, iterator2_tag ())); typename expression2_type::const_iterator1 it1_end (boost::numeric::ublas::end (it2, iterator2_tag ()));#endif while (it1 != it1_end) { // column (m, it2.index2 ()).plus_assign (*it1 * column (e1 (), it1.index1 ())); matrix_column<expression1_type> mc (e1 (), it1.index1 ()); typename matrix_column<expression1_type>::const_iterator itc (mc.begin ()); typename matrix_column<expression1_type>::const_iterator itc_end (mc.end ()); while (itc != itc_end) { if (functor_type ().other (itc.index (), it2.index2 ())) m (itc.index (), it2.index2 ()) += *it1 * *itc; ++ itc; } ++ it1; } ++ it2; }#if BOOST_UBLAS_TYPE_CHECK BOOST_UBLAS_CHECK (norm_1 (m - cm) <= 2 * std::numeric_limits<real_type>::epsilon () * merrorbound, internal_logic ());#endif return m; } // Dispatcher template<class M, class E1, class E2, class F> BOOST_UBLAS_INLINE M & axpy_prod (const matrix_expression<E1> &e1, const matrix_expression<E2> &e2, M &m, F, bool init = true) { typedef typename M::value_type value_type; typedef typename M::storage_category storage_category; typedef typename M::orientation_category orientation_category; typedef F functor_type; if (init) m.assign (zero_matrix<value_type> (e1 ().size1 (), e2 ().size2 ())); return axpy_prod (e1, e2, m, functor_type (), storage_category (), orientation_category ()); } template<class M, class E1, class E2, class F> BOOST_UBLAS_INLINE M axpy_prod (const matrix_expression<E1> &e1, const matrix_expression<E2> &e2, F) { typedef M matrix_type; typedef F functor_type; matrix_type m (e1 ().size1 (), e2 ().size2 ()); // FIXME: needed for c_matrix?! // return axpy_prod (e1, e2, m, functor_type (), false); return axpy_prod (e1, e2, m, functor_type (), true); } /** \brief computes <tt>M += A X</tt> or <tt>M = A X</tt> in an optimized fashion. \param e1 the matrix expression \c A \param e2 the matrix expression \c X \param m the result matrix \c M \param init a boolean parameter <tt>axpy_prod(A, X, M, init)</tt> implements the well known axpy-product. Setting \a init to \c true is equivalent to call <tt>M.clear()</tt> before <tt>axpy_prod</tt>. Currently \a init defaults to \c true, but this may change in the future. Up to now there are no specialisations. \ingroup blas3 \internal template parameters: \param M type of the result matrix \c M \param E1 type of a matrix expression \c A \param E2 type of a matrix expression \c X */ template<class M, class E1, class E2> BOOST_UBLAS_INLINE M & axpy_prod (const matrix_expression<E1> &e1, const matrix_expression<E2> &e2, M &m, bool init = true) { typedef typename M::value_type value_type; typedef typename M::storage_category storage_category; typedef typename M::orientation_category orientation_category; if (init) m.assign (zero_matrix<value_type> (e1 ().size1 (), e2 ().size2 ())); return axpy_prod (e1, e2, m, full (), storage_category (), orientation_category ()); } template<class M, class E1, class E2> BOOST_UBLAS_INLINE M axpy_prod (const matrix_expression<E1> &e1, const matrix_expression<E2> &e2) { typedef M matrix_type; matrix_type m (e1 ().size1 (), e2 ().size2 ()); // FIXME: needed for c_matrix?! // return axpy_prod (e1, e2, m, full (), false); return axpy_prod (e1, e2, m, full (), true); } template<class M, class E1, class E2, class F> BOOST_UBLAS_INLINE M & opb_prod (const matrix_expression<E1> &e1, const matrix_expression<E2> &e2, M &m, F, dense_proxy_tag, row_major_tag) { typedef M matrix_type; typedef const E1 expression1_type; typedef const E2 expression2_type; typedef typename M::size_type size_type; typedef typename M::value_type value_type;#if BOOST_UBLAS_TYPE_CHECK matrix<value_type, row_major> cm (m); typedef typename type_traits<value_type>::real_type real_type; real_type merrorbound (norm_1 (m) + norm_1 (e1) * norm_1 (e2)); indexing_matrix_assign (scalar_plus_assign<typename matrix<value_type, row_major>::reference, value_type> (), cm, prod (e1, e2), row_major_tag ());#endif size_type size (BOOST_UBLAS_SAME (e1 ().size2 (), e2 ().size1 ())); for (size_type k = 0; k < size; ++ k) { vector<value_type> ce1 (column (e1 (), k)); vector<value_type> re2 (row (e2 (), k)); m.plus_assign (outer_prod (ce1, re2)); }#if BOOST_UBLAS_TYPE_CHECK BOOST_UBLAS_CHECK (norm_1 (m - cm) <= 2 * std::numeric_limits<real_type>::epsilon () * merrorbound, internal_logic ());#endif return m; } template<class M, class E1, class E2, class F> BOOST_UBLAS_INLINE M & opb_prod (const matrix_expression<E1> &e1, const matrix_expression<E2> &e2, M &m, F, dense_proxy_tag, column_major_tag) { typedef M matrix_type; typedef const E1 expression1_type; typedef const E2 expression2_type; typedef typename M::size_type size_type; typedef typename M::value_type value_type;#if BOOST_UBLAS_TYPE_CHECK matrix<value_type, column_major> cm (m); typedef typename type_traits<value_type>::real_type real_type; real_type merrorbound (norm_1 (m) + norm_1 (e1) * norm_1 (e2)); indexing_matrix_assign (scalar_plus_assign<typename matrix<value_type, column_major>::reference, value_type> (), cm, prod (e1, e2), column_major_tag ());#endif size_type size (BOOST_UBLAS_SAME (e1 ().size2 (), e2 ().size1 ())); for (size_type k = 0; k < size; ++ k) { vector<value_type> ce1 (column (e1 (), k)); vector<value_type> re2 (row (e2 (), k)); m.plus_assign (outer_prod (ce1, re2)); }#if BOOST_UBLAS_TYPE_CHECK BOOST_UBLAS_CHECK (norm_1 (m - cm) <= 2 * std::numeric_limits<real_type>::epsilon () * merrorbound, internal_logic ());#endif return m; } // Dispatcher template<class M, class E1, class E2, class F> BOOST_UBLAS_INLINE M & opb_prod (const matrix_expression<E1> &e1, const matrix_expression<E2> &e2, M &m, F, bool init = true) { typedef typename M::value_type value_type; typedef typename M::storage_category storage_category; typedef typename M::orientation_category orientation_category; typedef F functor_type; if (init) m.assign (zero_matrix<value_type> (e1 ().size1 (), e2 ().size2 ())); return opb_prod (e1, e2, m, functor_type (), storage_category (), orientation_category ()); } template<class M, class E1, class E2, class F> BOOST_UBLAS_INLINE M opb_prod (const matrix_expression<E1> &e1, const matrix_expression<E2> &e2, F) { typedef M matrix_type; typedef F functor_type; matrix_type m (e1 ().size1 (), e2 ().size2 ()); // FIXME: needed for c_matrix?! // return opb_prod (e1, e2, m, functor_type (), false); return opb_prod (e1, e2, m, functor_type (), true); } /** \brief computes <tt>M += A X</tt> or <tt>M = A X</tt> in an optimized fashion. \param e1 the matrix expression \c A \param e2 the matrix expression \c X \param m the result matrix \c M \param init a boolean parameter <tt>opb_prod(A, X, M, init)</tt> implements the well known axpy-product. Setting \a init to \c true is equivalent to call <tt>M.clear()</tt> before <tt>opb_prod</tt>. Currently \a init defaults to \c true, but this may change in the future. This function may give a speedup if \c A has less columns than rows, because the product is computed as a sum of outer products. \ingroup blas3 \internal template parameters: \param M type of the result matrix \c M \param E1 type of a matrix expression \c A \param E2 type of a matrix expression \c X */ template<class M, class E1, class E2> BOOST_UBLAS_INLINE M & opb_prod (const matrix_expression<E1> &e1, const matrix_expression<E2> &e2, M &m, bool init = true) { typedef typename M::value_type value_type; typedef typename M::storage_category storage_category; typedef typename M::orientation_category orientation_category; if (init) m.assign (zero_matrix<value_type> (e1 ().size1 (), e2 ().size2 ())); return opb_prod (e1, e2, m, full (), storage_category (), orientation_category ()); } template<class M, class E1, class E2> BOOST_UBLAS_INLINE M opb_prod (const matrix_expression<E1> &e1, const matrix_expression<E2> &e2) { typedef M matrix_type; matrix_type m (e1 ().size1 (), e2 ().size2 ()); // FIXME: needed for c_matrix?! // return opb_prod (e1, e2, m, full (), false); return opb_prod (e1, e2, m, full (), true); }}}}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -