matrix_proxy.hpp
来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 1,789 行 · 第 1/5 页
HPP
1,789 行
template<class AE> BOOST_UBLAS_INLINE matrix_vector_range &minus_assign (const vector_expression<AE> &ae) { vector_assign<scalar_minus_assign> (*this, ae); return *this; } template<class AT> BOOST_UBLAS_INLINE matrix_vector_range &operator *= (const AT &at) { vector_assign_scalar<scalar_multiplies_assign> (*this, at); return *this; } template<class AT> BOOST_UBLAS_INLINE matrix_vector_range &operator /= (const AT &at) { vector_assign_scalar<scalar_divides_assign> (*this, at); return *this; } // Closure comparison BOOST_UBLAS_INLINE bool same_closure (const matrix_vector_range &mvr) const { return (*this).data_.same_closure (mvr.data_); } // Comparison BOOST_UBLAS_INLINE bool operator == (const matrix_vector_range &mvr) const { return (*this).data_ == mvr.data_ && r1_ == mvr.r1_ && r2_ == mvr.r2_; } // Swapping BOOST_UBLAS_INLINE void swap (matrix_vector_range mvr) { if (this != &mvr) { BOOST_UBLAS_CHECK (size () == mvr.size (), bad_size ()); // Sparse ranges may be nonconformant now. // std::swap_ranges (begin (), end (), mvr.begin ()); vector_swap<scalar_swap> (*this, mvr); } } BOOST_UBLAS_INLINE friend void swap (matrix_vector_range mvr1, matrix_vector_range mvr2) { mvr1.swap (mvr2); } // Iterator types private: // Use range as an index - FIXME this fails for packed assignment typedef typename range_type::const_iterator const_subiterator1_type; typedef typename range_type::const_iterator subiterator1_type; typedef typename range_type::const_iterator const_subiterator2_type; typedef typename range_type::const_iterator subiterator2_type; public: class const_iterator; class iterator; // Element lookup BOOST_UBLAS_INLINE const_iterator find (size_type i) const { return const_iterator (*this, r1_.begin () + i, r2_.begin () + i); } BOOST_UBLAS_INLINE iterator find (size_type i) { return iterator (*this, r1_.begin () + i, r2_.begin () + i); } class const_iterator: public container_const_reference<matrix_vector_range>, public iterator_base_traits<typename M::const_iterator1::iterator_category>::template iterator_base<const_iterator, value_type>::type { public: // FIXME Iterator can never be different code was: // typename iterator_restrict_traits<typename M::const_iterator1::iterator_category, typename M::const_iterator2::iterator_category>::iterator_category> BOOST_STATIC_ASSERT ((boost::is_same<typename M::const_iterator1::iterator_category, typename M::const_iterator2::iterator_category>::value )); typedef typename matrix_vector_range::value_type value_type; typedef typename matrix_vector_range::difference_type difference_type; typedef typename matrix_vector_range::const_reference reference; typedef const typename matrix_vector_range::value_type *pointer; // Construction and destruction BOOST_UBLAS_INLINE const_iterator (): container_const_reference<self_type> (), it1_ (), it2_ () {} BOOST_UBLAS_INLINE const_iterator (const self_type &mvr, const const_subiterator1_type &it1, const const_subiterator2_type &it2): container_const_reference<self_type> (mvr), it1_ (it1), it2_ (it2) {} BOOST_UBLAS_INLINE const_iterator (const typename self_type::iterator &it): // ISSUE self_type:: stops VC8 using std::iterator here container_const_reference<self_type> (it ()), it1_ (it.it1_), it2_ (it.it2_) {} // Arithmetic BOOST_UBLAS_INLINE const_iterator &operator ++ () { ++ it1_; ++ it2_; return *this; } BOOST_UBLAS_INLINE const_iterator &operator -- () { -- it1_; -- it2_; return *this; } BOOST_UBLAS_INLINE const_iterator &operator += (difference_type n) { it1_ += n; it2_ += n; return *this; } BOOST_UBLAS_INLINE const_iterator &operator -= (difference_type n) { it1_ -= n; it2_ -= n; return *this; } BOOST_UBLAS_INLINE difference_type operator - (const const_iterator &it) const { BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ()); return BOOST_UBLAS_SAME (it1_ - it.it1_, it2_ - it.it2_); } // Dereference BOOST_UBLAS_INLINE const_reference operator * () const { // FIXME replace find with at_element return (*this) ().data_ (*it1_, *it2_); } BOOST_UBLAS_INLINE const_reference operator [] (difference_type n) const { return *(*this + n); } // Index BOOST_UBLAS_INLINE size_type index () const { return BOOST_UBLAS_SAME (it1_.index (), it2_.index ()); } // Assignment BOOST_UBLAS_INLINE const_iterator &operator = (const const_iterator &it) { container_const_reference<self_type>::assign (&it ()); it1_ = it.it1_; it2_ = it.it2_; return *this; } // Comparison BOOST_UBLAS_INLINE bool operator == (const const_iterator &it) const { BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ()); return it1_ == it.it1_ && it2_ == it.it2_; } BOOST_UBLAS_INLINE bool operator < (const const_iterator &it) const { BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ()); return it1_ < it.it1_ && it2_ < it.it2_; } private: const_subiterator1_type it1_; const_subiterator2_type it2_; }; BOOST_UBLAS_INLINE const_iterator begin () const { return find (0); } BOOST_UBLAS_INLINE const_iterator end () const { return find (size ()); } class iterator: public container_reference<matrix_vector_range>, public iterator_base_traits<typename M::iterator1::iterator_category>::template iterator_base<iterator, value_type>::type { public: // FIXME Iterator can never be different code was: // typename iterator_restrict_traits<typename M::const_iterator1::iterator_category, typename M::const_iterator2::iterator_category>::iterator_category> BOOST_STATIC_ASSERT ((boost::is_same<typename M::const_iterator1::iterator_category, typename M::const_iterator2::iterator_category>::value )); typedef typename matrix_vector_range::value_type value_type; typedef typename matrix_vector_range::difference_type difference_type; typedef typename matrix_vector_range::reference reference; typedef typename matrix_vector_range::value_type *pointer; // Construction and destruction BOOST_UBLAS_INLINE iterator (): container_reference<self_type> (), it1_ (), it2_ () {} BOOST_UBLAS_INLINE iterator (self_type &mvr, const subiterator1_type &it1, const subiterator2_type &it2): container_reference<self_type> (mvr), it1_ (it1), it2_ (it2) {} // Arithmetic BOOST_UBLAS_INLINE iterator &operator ++ () { ++ it1_; ++ it2_; return *this; } BOOST_UBLAS_INLINE iterator &operator -- () { -- it1_; -- it2_; return *this; } BOOST_UBLAS_INLINE iterator &operator += (difference_type n) { it1_ += n; it2_ += n; return *this; } BOOST_UBLAS_INLINE iterator &operator -= (difference_type n) { it1_ -= n; it2_ -= n; return *this; } BOOST_UBLAS_INLINE difference_type operator - (const iterator &it) const { BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ()); return BOOST_UBLAS_SAME (it1_ - it.it1_, it2_ - it.it2_); } // Dereference BOOST_UBLAS_INLINE reference operator * () const { // FIXME replace find with at_element return (*this) ().data_ (*it1_, *it2_); } BOOST_UBLAS_INLINE reference operator [] (difference_type n) const { return *(*this + n); } // Index BOOST_UBLAS_INLINE size_type index () const { return BOOST_UBLAS_SAME (it1_.index (), it2_.index ()); } // Assignment BOOST_UBLAS_INLINE iterator &operator = (const iterator &it) { container_reference<self_type>::assign (&it ()); it1_ = it.it1_; it2_ = it.it2_; return *this; } // Comparison BOOST_UBLAS_INLINE bool operator == (const iterator &it) const { BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ()); return it1_ == it.it1_ && it2_ == it.it2_; } BOOST_UBLAS_INLINE bool operator < (const iterator &it) const { BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ()); return it1_ < it.it1_ && it2_ < it.it2_; } private: subiterator1_type it1_; subiterator2_type it2_; friend class const_iterator; }; BOOST_UBLAS_INLINE iterator begin () { return find (0); } BOOST_UBLAS_INLINE iterator end () { return find (size ()); } // Reverse iterator typedef reverse_iterator_base<const_iterator> const_reverse_iterator; typedef reverse_iterator_base<iterator> reverse_iterator; BOOST_UBLAS_INLINE const_reverse_iterator rbegin () const { return const_reverse_iterator (end ()); } BOOST_UBLAS_INLINE const_reverse_iterator rend () const { return const_reverse_iterator (begin ()); } BOOST_UBLAS_INLINE reverse_iterator rbegin () { return reverse_iterator (end ()); } BOOST_UBLAS_INLINE reverse_iterator rend () { return reverse_iterator (begin ()); } private: matrix_closure_type data_; range_type r1_; range_type r2_; }; // Specialize temporary template <class M> struct vector_temporary_traits< matrix_vector_range<M> > : vector_temporary_traits< M > {} ; template <class M> struct vector_temporary_traits< const matrix_vector_range<M> > : vector_temporary_traits< M > {} ; // Matrix based vector slice class template<class M> class matrix_vector_slice: public vector_expression<matrix_vector_slice<M> > { typedef matrix_vector_slice<M> self_type; public:#ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS using vector_expression<self_type>::operator ();#endif 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; 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; typedef typename boost::mpl::if_<boost::is_const<M>, typename M::const_closure_type, typename M::closure_type>::type matrix_closure_type; typedef basic_range<size_type, difference_type> range_type; typedef basic_slice<size_type, difference_type> slice_type; typedef const self_type const_closure_type; typedef self_type closure_type; typedef typename storage_restrict_traits<typename M::storage_category, dense_proxy_tag>::storage_category storage_category; // Construction and destruction BOOST_UBLAS_INLINE matrix_vector_slice (matrix_type &data, const slice_type &s1, const slice_type &s2): data_ (data), s1_ (s1.preprocess (data.size1 ())), s2_ (s2.preprocess (data.size2 ())) { // Early checking of preconditions here. // BOOST_UBLAS_CHECK (s1_.start () <= data_.size1 () && // s1_.start () + s1_.stride () * (s1_.size () - (s1_.size () > 0)) <= data_.size1 (), bad_index ()); // BOOST_UBLAS_CHECK (s2_.start () <= data_.size2 () && // s2_.start () + s2_.stride () * (s2_.size () - (s2_.size () > 0)) <= data_.size2 (), bad_index ()); } // Accessors
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?