📄 banded.hpp
字号:
BOOST_UBLAS_INLINE diagonal_matrix (): matrix_type () {} BOOST_UBLAS_INLINE diagonal_matrix (size_type size): matrix_type (size, size) {} BOOST_UBLAS_INLINE diagonal_matrix (size_type size1, size_type size2): matrix_type (size1, size2) {} template<class AE> BOOST_UBLAS_INLINE diagonal_matrix (const matrix_expression<AE> &ae): matrix_type (ae) {} BOOST_UBLAS_INLINE ~diagonal_matrix () {} // Assignment BOOST_UBLAS_INLINE diagonal_matrix &operator = (const diagonal_matrix &m) { matrix_type::operator = (m); return *this; } template<class AE> BOOST_UBLAS_INLINE diagonal_matrix &operator = (const matrix_expression<AE> &ae) { matrix_type::operator = (ae); return *this; } }; // Banded matrix adaptor class template<class M> class banded_adaptor: public matrix_expression<banded_adaptor<M> > { public:#ifndef BOOST_UBLAS_NO_PROXY_SHORTCUTS BOOST_UBLAS_USING matrix_expression<banded_adaptor<M> >::operator ();#endif typedef const M const_matrix_type; typedef M matrix_type; typedef typename M::size_type size_type; typedef typename M::difference_type difference_type; typedef typename M::value_type value_type;#ifndef BOOST_UBLAS_CT_PROXY_BASE_TYPEDEFS typedef typename M::const_reference const_reference; typedef typename M::reference reference;#else typedef typename M::const_reference const_reference; typedef typename boost::mpl::if_<boost::is_const<M>, typename M::const_reference, typename M::reference>::type reference;#endif#ifndef BOOST_UBLAS_CT_PROXY_CLOSURE_TYPEDEFS typedef typename M::closure_type matrix_closure_type;#else typedef typename boost::mpl::if_<boost::is_const<M>, typename M::const_closure_type, typename M::closure_type>::type matrix_closure_type;#endif private: typedef banded_adaptor<M> self_type; public: typedef const self_type const_closure_type; typedef self_type closure_type; typedef typename M::vector_temporary_type vector_temporary_type; typedef typename M::matrix_temporary_type matrix_temporary_type; typedef typename storage_restrict_traits<typename M::storage_category, packed_proxy_tag>::storage_category storage_category; typedef typename M::orientation_category orientation_category; // Construction and destruction BOOST_UBLAS_INLINE banded_adaptor (): matrix_expression<self_type> (), data_ (nil_), lower_ (0), upper_ (0) {} BOOST_UBLAS_INLINE banded_adaptor (matrix_type &data, size_type lower = 0, size_type upper = 0): matrix_expression<self_type> (), data_ (data), lower_ (lower), upper_ (upper) {} BOOST_UBLAS_INLINE banded_adaptor (const banded_adaptor &m): matrix_expression<self_type> (), data_ (m.data_), lower_ (m.lower_), upper_ (m.upper_) {} // Accessors BOOST_UBLAS_INLINE size_type size1 () const { return data_.size1 (); } BOOST_UBLAS_INLINE size_type size2 () const { return data_.size2 (); } BOOST_UBLAS_INLINE size_type lower () const { return lower_; } BOOST_UBLAS_INLINE size_type upper () const { return upper_; } BOOST_UBLAS_INLINE const matrix_closure_type &data () const { return data_; } BOOST_UBLAS_INLINE matrix_closure_type &data () { return data_; } // Element access#ifndef BOOST_UBLAS_PROXY_CONST_MEMBER BOOST_UBLAS_INLINE const_reference operator () (size_type i, size_type j) const { BOOST_UBLAS_CHECK (i < size1 (), bad_index ()); BOOST_UBLAS_CHECK (j < size2 (), bad_index ());#ifdef BOOST_UBLAS_OWN_BANDED size_type k = (std::max) (i, j); size_type l = lower_ + j - i; if (k < (std::max) (size1 (), size2 ()) && l < lower_ + 1 + upper_) return data () (i, j);#else size_type k = j; size_type l = upper_ + i - j; if (k < size2 () && l < lower_ + 1 + upper_) return data () (i, j);#endif return zero_; } BOOST_UBLAS_INLINE reference operator () (size_type i, size_type j) { BOOST_UBLAS_CHECK (i < size1 (), bad_index ()); BOOST_UBLAS_CHECK (j < size2 (), bad_index ());#ifdef BOOST_UBLAS_OWN_BANDED size_type k = (std::max) (i, j); size_type l = lower_ + j - i; if (k < (std::max) (size1 (), size2 ()) && l < lower_ + 1 + upper_) return data () (i, j);#else size_type k = j; size_type l = upper_ + i - j; if (k < size2 () && l < lower_ + 1 + upper_) return data () (i, j);#endif#ifndef BOOST_UBLAS_REFERENCE_CONST_MEMBER bad_index ().raise ();#endif return const_cast<reference>(zero_); }#else BOOST_UBLAS_INLINE reference operator () (size_type i, size_type j) const { BOOST_UBLAS_CHECK (i < size1 (), bad_index ()); BOOST_UBLAS_CHECK (j < size2 (), bad_index ());#ifdef BOOST_UBLAS_OWN_BANDED size_type k = (std::max) (i, j); size_type l = lower_ + j - i; if (k < (std::max) (size1 (), size2 ()) && l < lower_ + 1 + upper_) return data () (i, j);#else size_type k = j; size_type l = upper_ + i - j; if (k < size2 () && l < lower_ + 1 + upper_) return data () (i, j);#endif#ifndef BOOST_UBLAS_REFERENCE_CONST_MEMBER bad_index ().raise ();#endif return const_cast<reference>(zero_); }#endif // Assignment BOOST_UBLAS_INLINE banded_adaptor &operator = (const banded_adaptor &m) { matrix_assign (scalar_assign<BOOST_UBLAS_TYPENAME iterator1_type::reference, value_type> (), *this, m); return *this; } BOOST_UBLAS_INLINE banded_adaptor &assign_temporary (banded_adaptor &m) { *this = m; return *this; } template<class AE> BOOST_UBLAS_INLINE banded_adaptor &operator = (const matrix_expression<AE> &ae) { matrix_assign (scalar_assign<BOOST_UBLAS_TYPENAME iterator1_type::reference, value_type> (), *this, matrix<value_type> (ae)); return *this; } template<class AE> BOOST_UBLAS_INLINE banded_adaptor &assign (const matrix_expression<AE> &ae) { matrix_assign (scalar_assign<BOOST_UBLAS_TYPENAME iterator1_type::reference, BOOST_UBLAS_TYPENAME AE::value_type> (), *this, ae); return *this; } template<class AE> BOOST_UBLAS_INLINE banded_adaptor& operator += (const matrix_expression<AE> &ae) { matrix_assign (scalar_assign<BOOST_UBLAS_TYPENAME iterator1_type::reference, value_type> (), *this, matrix<value_type> (*this + ae)); return *this; } template<class AE> BOOST_UBLAS_INLINE banded_adaptor &plus_assign (const matrix_expression<AE> &ae) { matrix_assign (scalar_plus_assign<BOOST_UBLAS_TYPENAME iterator1_type::reference, BOOST_UBLAS_TYPENAME AE::value_type> (), *this, ae); return *this; } template<class AE> BOOST_UBLAS_INLINE banded_adaptor& operator -= (const matrix_expression<AE> &ae) { matrix_assign (scalar_assign<BOOST_UBLAS_TYPENAME iterator1_type::reference, value_type> (), *this, matrix<value_type> (*this - ae)); return *this; } template<class AE> BOOST_UBLAS_INLINE banded_adaptor &minus_assign (const matrix_expression<AE> &ae) { matrix_assign (scalar_minus_assign<BOOST_UBLAS_TYPENAME iterator1_type::reference, BOOST_UBLAS_TYPENAME AE::value_type> (), *this, ae); return *this; } template<class AT> BOOST_UBLAS_INLINE banded_adaptor& operator *= (const AT &at) { matrix_assign_scalar (scalar_multiplies_assign<BOOST_UBLAS_TYPENAME iterator1_type::reference, AT> (), *this, at); return *this; } template<class AT> BOOST_UBLAS_INLINE banded_adaptor& operator /= (const AT &at) { matrix_assign_scalar (scalar_divides_assign<BOOST_UBLAS_TYPENAME iterator1_type::reference, AT> (), *this, at); return *this; } // Closure comparison BOOST_UBLAS_INLINE bool same_closure (const banded_adaptor &ba) const { return (*this).data ().same_closure (ba.data ()); } // Swapping BOOST_UBLAS_INLINE void swap (banded_adaptor &m) { if (this != &m) { BOOST_UBLAS_CHECK (lower_ == m.lower_, bad_size ()); BOOST_UBLAS_CHECK (upper_ == m.upper_, bad_size ()); matrix_swap (scalar_swap<BOOST_UBLAS_TYPENAME iterator1_type::reference, BOOST_UBLAS_TYPENAME iterator1_type::reference> (), *this, m); } }#ifndef BOOST_UBLAS_NO_MEMBER_FRIENDS BOOST_UBLAS_INLINE friend void swap (banded_adaptor &m1, banded_adaptor &m2) { m1.swap (m2); }#endif // Iterator types private: // Use the matrix iterator#ifndef BOOST_UBLAS_CT_PROXY_BASE_TYPEDEFS typedef typename M::const_iterator1 const_iterator1_type; typedef typename M::iterator1 iterator1_type; typedef typename M::const_iterator2 const_iterator2_type; typedef typename M::iterator2 iterator2_type;#else typedef typename M::const_iterator1 const_iterator1_type; typedef typename boost::mpl::if_<boost::is_const<M>, typename M::const_iterator1, typename M::iterator1>::type iterator1_type; typedef typename M::const_iterator2 const_iterator2_type; typedef typename boost::mpl::if_<boost::is_const<M>, typename M::const_iterator2, typename M::iterator2>::type iterator2_type;#endif public:#ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR typedef indexed_iterator1<self_type, packed_random_access_iterator_tag> iterator1; typedef indexed_iterator2<self_type, packed_random_access_iterator_tag> iterator2; typedef indexed_const_iterator1<self_type, packed_random_access_iterator_tag> const_iterator1; typedef indexed_const_iterator2<self_type, packed_random_access_iterator_tag> const_iterator2;#else class const_iterator1; class iterator1; class const_iterator2; class iterator2;#endif#ifdef BOOST_MSVC_STD_ITERATOR typedef reverse_iterator_base1<const_iterator1, value_type, const_reference> const_reverse_iterator1; typedef reverse_iterator_base1<iterator1, value_type, reference> reverse_iterator1; typedef reverse_iterator_base2<const_iterator2, value_type, const_reference> const_reverse_iterator2; typedef reverse_iterator_base2<iterator2, value_type, reference> reverse_iterator2;#else typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1; typedef reverse_iterator_base1<iterator1> reverse_iterator1; typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2; typedef reverse_iterator_base2<iterator2> reverse_iterator2;#endif // Element lookup BOOST_UBLAS_INLINE const_iterator1 find1 (int rank, size_type i, size_type j) const { if (rank == 1) { size_type lower_i = (std::max) (difference_type (j - upper_), difference_type (0)); i = (std::max) (i, lower_i); size_type upper_i = (std::min) (j + 1 + lower_, size1 ()); i = (std::min) (i, upper_i); } return const_iterator1 (*this, data ().find1 (rank, i, j)); } BOOST_UBLAS_INLINE iterator1 find1 (int rank, size_type i, size_type j) { if (rank == 1) { size_type lower_i = (std::max) (difference_type (j - upper_), difference_type (0)); i = (std::max) (i, lower_i); size_type upper_i = (std::min) (j + 1 + lower_, size1 ()); i = (std::min) (i, upper_i); } return iterator1 (*this, data ().find1 (rank, i, j)); } BOOST_UBLAS_INLINE const_iterator2 find2 (int rank, size_type i, size_type j) const { if (rank == 1) { size_type lower_j = (std::max) (difference_type (i - lower_), difference_type (0)); j = (std::max) (j, lower_j); size_type upper_j = (std::min) (i + 1 + upper_, size2 ()); j = (std::min) (j, upper_j); } return const_iterator2 (*this, data ().find2 (rank, i, j)); } BOOST_UBLAS_INLINE iterator2 find2 (int rank, size_type i, size_type j) { if (rank == 1) { size_type lower_j = (std::max) (difference_type (i - lower_), difference_type (0)); j = (std::max) (j, lower_j); size_type upper_j = (std::min) (i + 1 + upper_, size2 ());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -