matrix_proxy.hpp
来自「CGAL is a collaborative effort of severa」· HPP 代码 · 共 1,718 行 · 第 1/5 页
HPP
1,718 行
//// Copyright (c) 2000-2002// Joerg Walter, Mathias Koch//// Permission to use, copy, modify, distribute and sell this software// and its documentation for any purpose is hereby granted without fee,// provided that the above copyright notice appear in all copies and// that both that copyright notice and this permission notice appear// in supporting documentation. The authors make no representations// about the suitability of this software for any purpose.// It is provided "as is" without express or implied warranty.//// The authors gratefully acknowledge the support of// GeNeSys mbH & Co. KG in producing this work.//#ifndef BOOST_UBLAS_MATRIX_PROXY_H#define BOOST_UBLAS_MATRIX_PROXY_H#include <boost/numeric/ublas/config.hpp>#include <boost/numeric/ublas/vector_expression.hpp>#include <boost/numeric/ublas/matrix_expression.hpp>// Iterators based on ideas of Jeremy Sieknamespace boost { namespace numeric { namespace ublas { // Matrix based row vector class template<class M> class matrix_row: public vector_expression<matrix_row<M> > { public:#ifndef BOOST_UBLAS_NO_PROXY_SHORTCUTS BOOST_UBLAS_USING vector_expression<matrix_row<M> >::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;#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 matrix_row<matrix_type> 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 storage_restrict_traits<typename M::storage_category, dense_proxy_tag>::storage_category storage_category; typedef abstract_tag simd_category; // Construction and destruction BOOST_UBLAS_INLINE matrix_row (): data_ (nil_), i_ () {} BOOST_UBLAS_INLINE matrix_row (matrix_type &data, size_type i): data_ (data), i_ (i) { // Early checking of preconditions here. // BOOST_UBLAS_CHECK (i_ < data_.size1 (), bad_index ()); } // Accessors BOOST_UBLAS_INLINE size_type size () const { return data_.size2 (); } BOOST_UBLAS_INLINE size_type index () const { return i_; } 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 j) const { return data_ (i_, j); } BOOST_UBLAS_INLINE reference operator () (size_type j) { return data_ (i_, j); } BOOST_UBLAS_INLINE const_reference operator [] (size_type j) const { return (*this) (j); } BOOST_UBLAS_INLINE reference operator [] (size_type j) { return (*this) (j); }#else BOOST_UBLAS_INLINE reference operator () (size_type j) const { return data_ (i_, j); } BOOST_UBLAS_INLINE reference operator [] (size_type j) const { return (*this) (j); }#endif // Assignment BOOST_UBLAS_INLINE matrix_row &operator = (const matrix_row &mr) { // FIXME: the rows could be differently sized. // std::copy (mr.begin (), mr.end (), begin ()); vector_assign (scalar_assign<BOOST_UBLAS_TYPENAME iterator::reference, BOOST_UBLAS_TYPENAME vector_temporary_type::value_type> (), *this, vector_temporary_type (mr)); return *this; } BOOST_UBLAS_INLINE matrix_row &assign_temporary (matrix_row &mr) { // FIXME: this is suboptimal. // return *this = mr; vector_assign (scalar_assign<BOOST_UBLAS_TYPENAME iterator::reference, value_type> (), *this, mr); return *this; } template<class AE> BOOST_UBLAS_INLINE matrix_row &operator = (const vector_expression<AE> &ae) { vector_assign (scalar_assign<BOOST_UBLAS_TYPENAME iterator::reference, BOOST_UBLAS_TYPENAME vector_temporary_type::value_type> (), *this, vector_temporary_type (ae)); return *this; } template<class AE> BOOST_UBLAS_INLINE matrix_row &assign (const vector_expression<AE> &ae) { vector_assign (scalar_assign<BOOST_UBLAS_TYPENAME iterator::reference, BOOST_UBLAS_TYPENAME AE::value_type> (), *this, ae); return *this; } template<class AE> BOOST_UBLAS_INLINE matrix_row &operator += (const vector_expression<AE> &ae) { vector_assign (scalar_assign<BOOST_UBLAS_TYPENAME iterator::reference, BOOST_UBLAS_TYPENAME vector_temporary_type::value_type> (), *this, vector_temporary_type (*this + ae)); return *this; } template<class AE> BOOST_UBLAS_INLINE matrix_row &plus_assign (const vector_expression<AE> &ae) { vector_assign (scalar_plus_assign<BOOST_UBLAS_TYPENAME iterator::reference, BOOST_UBLAS_TYPENAME AE::value_type> (), *this, ae); return *this; } template<class AE> BOOST_UBLAS_INLINE matrix_row &operator -= (const vector_expression<AE> &ae) { vector_assign (scalar_assign<BOOST_UBLAS_TYPENAME iterator::reference, BOOST_UBLAS_TYPENAME vector_temporary_type::value_type> (), *this, vector_temporary_type (*this - ae)); return *this; } template<class AE> BOOST_UBLAS_INLINE matrix_row &minus_assign (const vector_expression<AE> &ae) { vector_assign (scalar_minus_assign<BOOST_UBLAS_TYPENAME iterator::reference, BOOST_UBLAS_TYPENAME AE::value_type> (), *this, ae); return *this; } template<class AT> BOOST_UBLAS_INLINE matrix_row &operator *= (const AT &at) { vector_assign_scalar (scalar_multiplies_assign<BOOST_UBLAS_TYPENAME iterator::reference, AT> (), *this, at); return *this; } template<class AT> BOOST_UBLAS_INLINE matrix_row &operator /= (const AT &at) { vector_assign_scalar (scalar_divides_assign<BOOST_UBLAS_TYPENAME iterator::reference, AT> (), *this, at); return *this; } // Closure comparison BOOST_UBLAS_INLINE bool same_closure (const matrix_row &mr) const { return (*this).data_.same_closure (mr.data_); } // Comparison BOOST_UBLAS_INLINE bool operator == (const matrix_row &mr) const { return (*this).data_ == mr.data_ && index () == mr.index (); } // Swapping BOOST_UBLAS_INLINE void swap (matrix_row mr) { if (this != &mr) { BOOST_UBLAS_CHECK (size () == mr.size (), bad_size ()); // Sparse ranges may be nonconformant now. // std::swap_ranges (begin (), end (), mr.begin ()); vector_swap (scalar_swap<BOOST_UBLAS_TYPENAME iterator::reference, BOOST_UBLAS_TYPENAME iterator::reference> (), *this, mr); } }#ifndef BOOST_UBLAS_NO_MEMBER_FRIENDS BOOST_UBLAS_INLINE friend void swap (matrix_row mr1, matrix_row mr2) { mr1.swap (mr2); }#endif // Iterator types private:#ifndef BOOST_UBLAS_CT_PROXY_BASE_TYPEDEFS // Reuse the matrix iterator typedef typename M::const_iterator2 const_iterator_type; typedef typename M::iterator2 iterator_type;#else typedef typename M::const_iterator2 const_iterator_type; typedef typename boost::mpl::if_<boost::is_const<M>, typename M::const_iterator2, typename M::iterator2>::type iterator_type;#endif public:#ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR typedef indexed_iterator<matrix_row<matrix_type>, BOOST_UBLAS_TYPENAME iterator_type::iterator_category> iterator; typedef indexed_const_iterator<matrix_row<matrix_type>, BOOST_UBLAS_TYPENAME const_iterator_type::iterator_category> const_iterator;#else class const_iterator; class iterator;#endif // Element lookup BOOST_UBLAS_INLINE const_iterator find (size_type j) const { const_iterator_type it2 (data_.find2 (1, i_, j));#ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR return const_iterator (*this, it2.index2 ());#else return const_iterator (*this, it2);#endif } BOOST_UBLAS_INLINE iterator find (size_type j) { iterator_type it2 (data_.find2 (1, i_, j));#ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR return iterator (*this, it2.index2 ());#else return iterator (*this, it2);#endif }#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR class const_iterator: public container_const_reference<matrix_row>,#ifndef BOOST_UBLAS_NO_ITERATOR_BASE_TRAITS public iterator_base_traits<typename const_iterator_type::iterator_category>::template iterator_base<const_iterator, value_type>::type {#else public random_access_iterator_base<typename const_iterator_type::iterator_category, const_iterator, value_type> {#endif public: typedef typename const_iterator_type::iterator_category iterator_category; typedef typename const_iterator_type::value_type value_type; typedef typename const_iterator_type::difference_type difference_type; typedef typename const_iterator_type::reference reference; typedef typename const_iterator_type::pointer pointer; // Construction and destruction BOOST_UBLAS_INLINE const_iterator (): container_const_reference<self_type> (), it_ () {} BOOST_UBLAS_INLINE const_iterator (const self_type &mr, const const_iterator_type &it): container_const_reference<self_type> (mr), it_ (it) {}#ifndef BOOST_UBLAS_QUALIFIED_TYPENAME BOOST_UBLAS_INLINE const_iterator (const iterator &it): container_const_reference<self_type> (it ()), it_ (it.it_) {}#else BOOST_UBLAS_INLINE const_iterator (const typename self_type::iterator &it): container_const_reference<self_type> (it ()), it_ (it.it_) {}#endif // Arithmetic BOOST_UBLAS_INLINE const_iterator &operator ++ () { ++ it_; return *this; } BOOST_UBLAS_INLINE const_iterator &operator -- () { -- it_; return *this; } BOOST_UBLAS_INLINE const_iterator &operator += (difference_type n) { it_ += n; return *this; } BOOST_UBLAS_INLINE const_iterator &operator -= (difference_type n) { it_ -= n; return *this; } BOOST_UBLAS_INLINE difference_type operator - (const const_iterator &it) const { BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ()); return it_ - it.it_; } // Dereference BOOST_UBLAS_INLINE const_reference operator * () const { BOOST_UBLAS_CHECK (index () < (*this) ().size (), bad_index ()); return *it_; } // Index BOOST_UBLAS_INLINE size_type index () const { return it_.index2 (); } // Assignment BOOST_UBLAS_INLINE const_iterator &operator = (const const_iterator &it) { container_const_reference<self_type>::assign (&it ()); it_ = it.it_; return *this; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?