banded.hpp
来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 1,783 行 · 第 1/5 页
HPP
1,783 行
return upper_; } // Storage accessors 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> (*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> (*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> (*this, ae); return *this; } template<class AE> BOOST_UBLAS_INLINE banded_adaptor& operator += (const matrix_expression<AE> &ae) { matrix_assign<scalar_assign> (*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> (*this, ae); return *this; } template<class AE> BOOST_UBLAS_INLINE banded_adaptor& operator -= (const matrix_expression<AE> &ae) { matrix_assign<scalar_assign> (*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> (*this, ae); return *this; } template<class AT> BOOST_UBLAS_INLINE banded_adaptor& operator *= (const AT &at) { matrix_assign_scalar<scalar_multiplies_assign> (*this, at); return *this; } template<class AT> BOOST_UBLAS_INLINE banded_adaptor& operator /= (const AT &at) { matrix_assign_scalar<scalar_divides_assign> (*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> (*this, m); } } BOOST_UBLAS_INLINE friend void swap (banded_adaptor &m1, banded_adaptor &m2) { m1.swap (m2); } // Iterator types private: // Use the matrix iterator typedef typename M::const_iterator1 const_subiterator1_type; typedef typename boost::mpl::if_<boost::is_const<M>, typename M::const_iterator1, typename M::iterator1>::type subiterator1_type; typedef typename M::const_iterator2 const_subiterator2_type; typedef typename boost::mpl::if_<boost::is_const<M>, typename M::const_iterator2, typename M::iterator2>::type subiterator2_type; 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 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; // 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 ()); j = (std::min) (j, upper_j); } return iterator2 (*this, data ().find2 (rank, i, j)); } // Iterators simply are indices.#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR class const_iterator1: public container_const_reference<banded_adaptor>, public random_access_iterator_base<typename iterator_restrict_traits< typename const_subiterator1_type::iterator_category, packed_random_access_iterator_tag>::iterator_category, const_iterator1, value_type> { public: typedef typename const_subiterator1_type::value_type value_type; typedef typename const_subiterator1_type::difference_type difference_type; typedef typename const_subiterator1_type::reference reference; typedef typename const_subiterator1_type::pointer pointer; typedef const_iterator2 dual_iterator_type; typedef const_reverse_iterator2 dual_reverse_iterator_type; // Construction and destruction BOOST_UBLAS_INLINE const_iterator1 (): container_const_reference<self_type> (), it1_ () {} BOOST_UBLAS_INLINE const_iterator1 (const self_type &m, const const_subiterator1_type &it1): container_const_reference<self_type> (m), it1_ (it1) {} BOOST_UBLAS_INLINE const_iterator1 (const iterator1 &it): container_const_reference<self_type> (it ()), it1_ (it.it1_) {} // Arithmetic BOOST_UBLAS_INLINE const_iterator1 &operator ++ () { ++ it1_; return *this; } BOOST_UBLAS_INLINE const_iterator1 &operator -- () { -- it1_; return *this; } BOOST_UBLAS_INLINE const_iterator1 &operator += (difference_type n) { it1_ += n; return *this; } BOOST_UBLAS_INLINE const_iterator1 &operator -= (difference_type n) { it1_ -= n; return *this; } BOOST_UBLAS_INLINE difference_type operator - (const const_iterator1 &it) const { BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); return it1_ - it.it1_; } // Dereference BOOST_UBLAS_INLINE const_reference operator * () const { size_type i = index1 (); size_type j = index2 (); BOOST_UBLAS_CHECK (i < (*this) ().size1 (), bad_index ()); BOOST_UBLAS_CHECK (j < (*this) ().size2 (), bad_index ());#ifdef BOOST_UBLAS_OWN_BANDED size_type k = (std::max) (i, j); size_type l = (*this) ().lower () + j - i; if (k < (std::max) ((*this) ().size1 (), (*this) ().size2 ()) && l < (*this) ().lower () + 1 + (*this) ().upper ()) return *it1_;#else size_type k = j; size_type l = (*this) ().upper () + i - j; if (k < (*this) ().size2 () && l < (*this) ().lower () + 1 + (*this) ().upper ()) return *it1_;#endif return (*this) () (i, j); } BOOST_UBLAS_INLINE const_reference operator [] (difference_type n) const { return *(*this + n); }#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION BOOST_UBLAS_INLINE#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION typename self_type::#endif const_iterator2 begin () const { return (*this) ().find2 (1, index1 (), 0); } BOOST_UBLAS_INLINE#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION typename self_type::#endif const_iterator2 end () const { return (*this) ().find2 (1, index1 (), (*this) ().size2 ()); } BOOST_UBLAS_INLINE#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION typename self_type::#endif const_reverse_iterator2 rbegin () const { return const_reverse_iterator2 (end ()); } BOOST_UBLAS_INLINE#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION typename self_type::#endif const_reverse_iterator2 rend () const { return const_reverse_iterator2 (begin ()); }#endif // Indices BOOST_UBLAS_INLINE size_type index1 () const { return it1_.index1 (); } BOOST_UBLAS_INLINE size_type index2 () const { return it1_.index2 (); } // Assignment BOOST_UBLAS_INLINE
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?