matrix_proxy.hpp

来自「CGAL is a collaborative effort of severa」· HPP 代码 · 共 1,718 行 · 第 1/5 页

HPP
1,718
字号
            // Comparison            BOOST_UBLAS_INLINE            bool operator == (const const_iterator &it) const {                BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());                return it_ == it.it_;            }            BOOST_UBLAS_INLINE            bool operator < (const const_iterator &it) const {                BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());                return it_ < it.it_;            }        private:            const_iterator_type it_;        };#endif        BOOST_UBLAS_INLINE        const_iterator begin () const {            return find (0);        }        BOOST_UBLAS_INLINE        const_iterator end () const {            return find (size ());        }#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR        class iterator:            public container_reference<matrix_row>,#ifndef BOOST_UBLAS_NO_ITERATOR_BASE_TRAITS            public iterator_base_traits<typename iterator_type::iterator_category>::template                        iterator_base<iterator, value_type>::type {#else            public random_access_iterator_base<typename iterator_type::iterator_category,                                               iterator, value_type> {#endif        public:            typedef typename iterator_type::iterator_category iterator_category;            typedef typename iterator_type::value_type value_type;            typedef typename iterator_type::difference_type difference_type;            typedef typename iterator_type::reference reference;            typedef typename iterator_type::pointer pointer;            // Construction and destruction            BOOST_UBLAS_INLINE            iterator ():                container_reference<self_type> (), it_ () {}            BOOST_UBLAS_INLINE            iterator (self_type &mr, const iterator_type &it):                container_reference<self_type> (mr), it_ (it) {}            // Arithmetic            BOOST_UBLAS_INLINE            iterator &operator ++ () {                ++ it_;                return *this;            }            BOOST_UBLAS_INLINE            iterator &operator -- () {                -- it_;                return *this;            }            BOOST_UBLAS_INLINE            iterator &operator += (difference_type n) {                it_ += n;                return *this;            }            BOOST_UBLAS_INLINE            iterator &operator -= (difference_type n) {                it_ -= n;                return *this;            }            BOOST_UBLAS_INLINE            difference_type operator - (const iterator &it) const {                BOOST_UBLAS_CHECK ((*this) ().same_closure  (it ()), external_logic ());                return it_ - it.it_;            }            // Dereference            BOOST_UBLAS_INLINE            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            iterator &operator = (const iterator &it) {                container_reference<self_type>::assign (&it ());                it_ = it.it_;                return *this;            }            // Comparison            BOOST_UBLAS_INLINE            bool operator == (const iterator &it) const {                BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());                return it_ == it.it_;            }            BOOST_UBLAS_INLINE            bool operator < (const iterator &it) const {                BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());                return it_ < it.it_;            }        private:            iterator_type it_;            friend class const_iterator;        };#endif        BOOST_UBLAS_INLINE        iterator begin () {            return find (0);        }        BOOST_UBLAS_INLINE        iterator end () {            return find (size ());        }        // Reverse iterator#ifdef BOOST_MSVC_STD_ITERATOR        typedef reverse_iterator_base<const_iterator, value_type, const_reference> const_reverse_iterator;#else        typedef reverse_iterator_base<const_iterator> const_reverse_iterator;#endif        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 ());        }#ifdef BOOST_MSVC_STD_ITERATOR        typedef reverse_iterator_base<iterator, value_type, reference> reverse_iterator;#else        typedef reverse_iterator_base<iterator> reverse_iterator;#endif        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_;        size_type i_;        static matrix_type nil_;    };    template<class M>    typename matrix_row<M>::matrix_type matrix_row<M>::nil_#ifdef BOOST_UBLAS_STATIC_OLD_INIT        = BOOST_UBLAS_TYPENAME matrix_row<M>::matrix_type ()#endif    ;    // Projections    template<class M>    BOOST_UBLAS_INLINE    matrix_row<M> row (M &data, typename M::size_type i) {        return matrix_row<M> (data, i);    }    template<class M>    BOOST_UBLAS_INLINE    matrix_row<const M> row_const (const M &data, typename M::size_type i) {        return matrix_row<const M> (data, i);    }#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING    template<class M>    BOOST_UBLAS_INLINE    matrix_row<M> row (const M &data, typename M::size_type i) {        return matrix_row<M> (const_cast<M &> (data), i);    }#endif    // Matrix based column vector class    template<class M>    class matrix_column:        public vector_expression<matrix_column<M> > {    public:#ifndef BOOST_UBLAS_NO_PROXY_SHORTCUTS        BOOST_UBLAS_USING vector_expression<matrix_column<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_column<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_column ():            data_ (nil_), j_ () {}        BOOST_UBLAS_INLINE        matrix_column (matrix_type &data, size_type j):            data_ (data), j_ (j) {            // Early checking of preconditions here.            // BOOST_UBLAS_CHECK (j_ < data_.size2 (), bad_index ());        }        // Accessors        BOOST_UBLAS_INLINE        size_type size () const {            return data_.size1 ();        }        BOOST_UBLAS_INLINE        size_type index () const {            return j_;        }        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) const {            return data_ (i, j_);        }        BOOST_UBLAS_INLINE        reference operator () (size_type i) {            return data_ (i, j_);        }        BOOST_UBLAS_INLINE        const_reference operator [] (size_type i) const {            return (*this) (i);        }        BOOST_UBLAS_INLINE        reference operator [] (size_type i) {            return (*this) (i);        }#else        BOOST_UBLAS_INLINE        reference operator () (size_type i) const {            return data_ (i, j_);        }        BOOST_UBLAS_INLINE        reference operator [] (size_type i) const {            return (*this) (i);        }#endif        // Assignment        BOOST_UBLAS_INLINE        matrix_column &operator = (const matrix_column &mc) {            // FIXME: the columns could be differently sized.            // std::copy (mc.begin (), mc.end (), begin ());            vector_assign (scalar_assign<BOOST_UBLAS_TYPENAME iterator::reference, BOOST_UBLAS_TYPENAME vector_temporary_type::value_type> (), *this, vector_temporary_type (mc));            return *this;        }        BOOST_UBLAS_INLINE        matrix_column &assign_temporary (matrix_column &mc) {            // FIXME: this is suboptimal.            // return *this = mc;            vector_assign (scalar_assign<BOOST_UBLAS_TYPENAME iterator::reference, value_type> (), *this, mc);            return *this;        }        template<class AE>        BOOST_UBLAS_INLINE        matrix_column &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_column &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_column &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_column &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_column &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_column &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_column &operator *= (const AT &at) {            vector_assign_scalar (scalar_multiplies_assign<BOOST_UBLAS_TYPENAME iterator::reference, AT> (), *this, at);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?