sl@0: // sl@0: // Copyright (c) 2000-2002 sl@0: // Joerg Walter, Mathias Koch sl@0: // sl@0: // Permission to use, copy, modify, distribute and sell this software sl@0: // and its documentation for any purpose is hereby granted without fee, sl@0: // provided that the above copyright notice appear in all copies and sl@0: // that both that copyright notice and this permission notice appear sl@0: // in supporting documentation. The authors make no representations sl@0: // about the suitability of this software for any purpose. sl@0: // It is provided "as is" without express or implied warranty. sl@0: // sl@0: // The authors gratefully acknowledge the support of sl@0: // GeNeSys mbH & Co. KG in producing this work. sl@0: // sl@0: sl@0: #ifndef _BOOST_UBLAS_BANDED_ sl@0: #define _BOOST_UBLAS_BANDED_ sl@0: sl@0: #include sl@0: #include sl@0: sl@0: // Iterators based on ideas of Jeremy Siek sl@0: sl@0: namespace boost { namespace numeric { namespace ublas { sl@0: sl@0: // Array based banded matrix class sl@0: template sl@0: class banded_matrix: sl@0: public matrix_container > { sl@0: sl@0: typedef T *pointer; sl@0: typedef L layout_type; sl@0: typedef banded_matrix self_type; sl@0: public: sl@0: #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS sl@0: using matrix_container::operator (); sl@0: #endif sl@0: typedef typename A::size_type size_type; sl@0: typedef typename A::difference_type difference_type; sl@0: typedef T value_type; sl@0: typedef const T &const_reference; sl@0: typedef T &reference; sl@0: typedef A array_type; sl@0: typedef const matrix_reference const_closure_type; sl@0: typedef matrix_reference closure_type; sl@0: typedef vector vector_temporary_type; sl@0: typedef matrix matrix_temporary_type; // general sub-matrix sl@0: typedef packed_tag storage_category; sl@0: typedef typename L::orientation_category orientation_category; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: banded_matrix (): sl@0: matrix_container (), sl@0: size1_ (0), size2_ (0), sl@0: lower_ (0), upper_ (0), data_ (0) {} sl@0: BOOST_UBLAS_INLINE sl@0: banded_matrix (size_type size1, size_type size2, size_type lower = 0, size_type upper = 0): sl@0: matrix_container (), sl@0: size1_ (size1), size2_ (size2), sl@0: lower_ (lower), upper_ (upper), data_ ((std::max) (size1, size2) * (lower + 1 + upper)) { sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: banded_matrix (size_type size1, size_type size2, size_type lower, size_type upper, const array_type &data): sl@0: matrix_container (), sl@0: size1_ (size1), size2_ (size2), sl@0: lower_ (lower), upper_ (upper), data_ (data) {} sl@0: BOOST_UBLAS_INLINE sl@0: banded_matrix (const banded_matrix &m): sl@0: matrix_container (), sl@0: size1_ (m.size1_), size2_ (m.size2_), sl@0: lower_ (m.lower_), upper_ (m.upper_), data_ (m.data_) {} sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: banded_matrix (const matrix_expression &ae, size_type lower = 0, size_type upper = 0): sl@0: matrix_container (), sl@0: size1_ (ae ().size1 ()), size2_ (ae ().size2 ()), sl@0: lower_ (lower), upper_ (upper), sl@0: data_ ((std::max) (size1_, size2_) * (lower_ + 1 + upper_)) { sl@0: matrix_assign (*this, ae); sl@0: } sl@0: sl@0: // Accessors sl@0: BOOST_UBLAS_INLINE sl@0: size_type size1 () const { sl@0: return size1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type size2 () const { sl@0: return size2_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type lower () const { sl@0: return lower_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type upper () const { sl@0: return upper_; sl@0: } sl@0: sl@0: // Storage accessors sl@0: BOOST_UBLAS_INLINE sl@0: const array_type &data () const { sl@0: return data_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: array_type &data () { sl@0: return data_; sl@0: } sl@0: sl@0: // Resizing sl@0: BOOST_UBLAS_INLINE sl@0: void resize (size_type size1, size_type size2, size_type lower = 0, size_type upper = 0, bool preserve = true) { sl@0: if (preserve) { sl@0: self_type temporary (size1, size2, lower, upper); sl@0: detail::matrix_resize_preserve (*this, temporary); sl@0: } sl@0: else { sl@0: data ().resize ((std::max) (size1, size2) * (lower + 1 + upper)); sl@0: size1_ = size1; sl@0: size2_ = size2; sl@0: lower_ = lower; sl@0: upper_ = upper; sl@0: } sl@0: } sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: void resize_packed_preserve (size_type size1, size_type size2, size_type lower = 0, size_type upper = 0) { sl@0: size1_ = size1; sl@0: size2_ = size2; sl@0: lower_ = lower; sl@0: upper_ = upper; sl@0: data ().resize ((std::max) (size1, size2) * (lower + 1 + upper), value_type ()); sl@0: } sl@0: sl@0: // Element access sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator () (size_type i, size_type j) const { sl@0: BOOST_UBLAS_CHECK (i < size1_, bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < size2_, bad_index ()); sl@0: #ifdef BOOST_UBLAS_OWN_BANDED sl@0: const size_type k = (std::max) (i, j); sl@0: const size_type l = lower_ + j - i; sl@0: if (k < (std::max) (size1_, size2_) && sl@0: l < lower_ + 1 + upper_) sl@0: return data () [layout_type::element (k, (std::max) (size1_, size2_), sl@0: l, lower_ + 1 + upper_)]; sl@0: #else sl@0: const size_type k = j; sl@0: const size_type l = upper_ + i - j; sl@0: if (k < size2_ && sl@0: l < lower_ + 1 + upper_) sl@0: return data () [layout_type::element (k, size2_, sl@0: l, lower_ + 1 + upper_)]; sl@0: #endif sl@0: return zero_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reference at_element (size_type i, size_type j) { sl@0: BOOST_UBLAS_CHECK (i < size1_, bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < size2_, bad_index ()); sl@0: #ifdef BOOST_UBLAS_OWN_BANDED sl@0: const size_type k = (std::max) (i, j); sl@0: const size_type l = lower_ + j - i; sl@0: return data () [layout_type::element (k, (std::max) (size1_, size2_), sl@0: l, lower_ + 1 + upper_)]; sl@0: #else sl@0: const size_type k = j; sl@0: const size_type l = upper_ + i - j; sl@0: return data () [layout_type::element (k, size2_, sl@0: l, lower_ + 1 + upper_)]; sl@0: #endif sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reference operator () (size_type i, size_type j) { sl@0: BOOST_UBLAS_CHECK (i < size1_, bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < size2_, bad_index ()); sl@0: #ifdef BOOST_UBLAS_OWN_BANDED sl@0: const size_type k = (std::max) (i, j); sl@0: const size_type l = lower_ + j - i; sl@0: if (k < (std::max) (size1_, size2_) && sl@0: l < lower_ + 1 + upper_) sl@0: return data () [layout_type::element (k, (std::max) (size1_, size2_), sl@0: l, lower_ + 1 + upper_)]; sl@0: #else sl@0: const size_type k = j; sl@0: const size_type l = upper_ + i - j; sl@0: if (k < size2_ && sl@0: l < lower_ + 1 + upper_) sl@0: return data () [layout_type::element (k, size2_, sl@0: l, lower_ + 1 + upper_)]; sl@0: #endif sl@0: bad_index ().raise (); sl@0: // arbitary return value sl@0: return const_cast(zero_); sl@0: } sl@0: sl@0: // Element assignment sl@0: BOOST_UBLAS_INLINE sl@0: reference insert_element (size_type i, size_type j, const_reference t) { sl@0: return (operator () (i, j) = t); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: void erase_element (size_type i, size_type j) { sl@0: operator () (i, j) = value_type/*zero*/(); sl@0: } sl@0: sl@0: // Zeroing sl@0: BOOST_UBLAS_INLINE sl@0: void clear () { sl@0: std::fill (data ().begin (), data ().end (), value_type/*zero*/()); sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: banded_matrix &operator = (const banded_matrix &m) { sl@0: size1_ = m.size1_; sl@0: size2_ = m.size2_; sl@0: lower_ = m.lower_; sl@0: upper_ = m.upper_; sl@0: data () = m.data (); sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: banded_matrix &assign_temporary (banded_matrix &m) { sl@0: swap (m); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: banded_matrix &operator = (const matrix_expression &ae) { sl@0: self_type temporary (ae, lower_, upper_); sl@0: return assign_temporary (temporary); sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: banded_matrix &assign (const matrix_expression &ae) { sl@0: matrix_assign (*this, ae); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: banded_matrix& operator += (const matrix_expression &ae) { sl@0: self_type temporary (*this + ae, lower_, upper_); sl@0: return assign_temporary (temporary); sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: banded_matrix &plus_assign (const matrix_expression &ae) { sl@0: matrix_assign (*this, ae); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: banded_matrix& operator -= (const matrix_expression &ae) { sl@0: self_type temporary (*this - ae, lower_, upper_); sl@0: return assign_temporary (temporary); sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: banded_matrix &minus_assign (const matrix_expression &ae) { sl@0: matrix_assign (*this, ae); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: banded_matrix& operator *= (const AT &at) { sl@0: matrix_assign_scalar (*this, at); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: banded_matrix& operator /= (const AT &at) { sl@0: matrix_assign_scalar (*this, at); sl@0: return *this; sl@0: } sl@0: sl@0: // Swapping sl@0: BOOST_UBLAS_INLINE sl@0: void swap (banded_matrix &m) { sl@0: if (this != &m) { sl@0: std::swap (size1_, m.size1_); sl@0: std::swap (size2_, m.size2_); sl@0: std::swap (lower_, m.lower_); sl@0: std::swap (upper_, m.upper_); sl@0: data ().swap (m.data ()); sl@0: } sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: friend void swap (banded_matrix &m1, banded_matrix &m2) { sl@0: m1.swap (m2); sl@0: } sl@0: sl@0: // Iterator types sl@0: #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: typedef indexed_iterator1 iterator1; sl@0: typedef indexed_iterator2 iterator2; sl@0: typedef indexed_const_iterator1 const_iterator1; sl@0: typedef indexed_const_iterator2 const_iterator2; sl@0: #else sl@0: class const_iterator1; sl@0: class iterator1; sl@0: class const_iterator2; sl@0: class iterator2; sl@0: #endif sl@0: typedef reverse_iterator_base1 const_reverse_iterator1; sl@0: typedef reverse_iterator_base1 reverse_iterator1; sl@0: typedef reverse_iterator_base2 const_reverse_iterator2; sl@0: typedef reverse_iterator_base2 reverse_iterator2; sl@0: sl@0: // Element lookup sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 find1 (int rank, size_type i, size_type j) const { sl@0: if (rank == 1) { sl@0: size_type lower_i = (std::max) (difference_type (j - upper_), difference_type (0)); sl@0: i = (std::max) (i, lower_i); sl@0: size_type upper_i = (std::min) (j + 1 + lower_, size1_); sl@0: i = (std::min) (i, upper_i); sl@0: } sl@0: return const_iterator1 (*this, i, j); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 find1 (int rank, size_type i, size_type j) { sl@0: if (rank == 1) { sl@0: size_type lower_i = (std::max) (difference_type (j - upper_), difference_type (0)); sl@0: i = (std::max) (i, lower_i); sl@0: size_type upper_i = (std::min) (j + 1 + lower_, size1_); sl@0: i = (std::min) (i, upper_i); sl@0: } sl@0: return iterator1 (*this, i, j); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 find2 (int rank, size_type i, size_type j) const { sl@0: if (rank == 1) { sl@0: size_type lower_j = (std::max) (difference_type (i - lower_), difference_type (0)); sl@0: j = (std::max) (j, lower_j); sl@0: size_type upper_j = (std::min) (i + 1 + upper_, size2_); sl@0: j = (std::min) (j, upper_j); sl@0: } sl@0: return const_iterator2 (*this, i, j); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 find2 (int rank, size_type i, size_type j) { sl@0: if (rank == 1) { sl@0: size_type lower_j = (std::max) (difference_type (i - lower_), difference_type (0)); sl@0: j = (std::max) (j, lower_j); sl@0: size_type upper_j = (std::min) (i + 1 + upper_, size2_); sl@0: j = (std::min) (j, upper_j); sl@0: } sl@0: return iterator2 (*this, i, j); sl@0: } sl@0: sl@0: // Iterators simply are indices. sl@0: sl@0: #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: class const_iterator1: sl@0: public container_const_reference, sl@0: public random_access_iterator_base { sl@0: public: sl@0: typedef typename banded_matrix::value_type value_type; sl@0: typedef typename banded_matrix::difference_type difference_type; sl@0: typedef typename banded_matrix::const_reference reference; sl@0: typedef const typename banded_matrix::pointer pointer; sl@0: sl@0: typedef const_iterator2 dual_iterator_type; sl@0: typedef const_reverse_iterator2 dual_reverse_iterator_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 (): sl@0: container_const_reference (), it1_ (), it2_ () {} sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 (const self_type &m, size_type it1, size_type it2): sl@0: container_const_reference (m), it1_ (it1), it2_ (it2) {} sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 (const iterator1 &it): sl@0: container_const_reference (it ()), it1_ (it.it1_), it2_ (it.it2_) {} sl@0: sl@0: // Arithmetic sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator ++ () { sl@0: ++ it1_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator -- () { sl@0: -- it1_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator += (difference_type n) { sl@0: it1_ += n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator -= (difference_type n) { sl@0: it1_ -= n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: difference_type operator - (const const_iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ()); sl@0: return it1_ - it.it1_; sl@0: } sl@0: sl@0: // Dereference sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator * () const { sl@0: return (*this) () (it1_, it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator [] (difference_type n) const { sl@0: return *(*this + n); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_iterator2 begin () const { sl@0: return (*this) ().find2 (1, it1_, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_iterator2 end () const { sl@0: return (*this) ().find2 (1, it1_, (*this) ().size2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_reverse_iterator2 rbegin () const { sl@0: return const_reverse_iterator2 (end ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_reverse_iterator2 rend () const { sl@0: return const_reverse_iterator2 (begin ()); sl@0: } sl@0: #endif sl@0: sl@0: // Indices sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 () const { sl@0: return it1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 () const { sl@0: return it2_; sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator = (const const_iterator1 &it) { sl@0: container_const_reference::assign (&it ()); sl@0: it1_ = it.it1_; sl@0: it2_ = it.it2_; sl@0: return *this; sl@0: } sl@0: sl@0: // Comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool operator == (const const_iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ()); sl@0: return it1_ == it.it1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: bool operator < (const const_iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ()); sl@0: return it1_ < it.it1_; sl@0: } sl@0: sl@0: private: sl@0: size_type it1_; sl@0: size_type it2_; sl@0: }; sl@0: #endif sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 begin1 () const { sl@0: return find1 (0, 0, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 end1 () const { sl@0: return find1 (0, size1_, 0); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: class iterator1: sl@0: public container_reference, sl@0: public random_access_iterator_base { sl@0: public: sl@0: typedef typename banded_matrix::value_type value_type; sl@0: typedef typename banded_matrix::difference_type difference_type; sl@0: typedef typename banded_matrix::reference reference; sl@0: typedef typename banded_matrix::pointer pointer; sl@0: sl@0: typedef iterator2 dual_iterator_type; sl@0: typedef reverse_iterator2 dual_reverse_iterator_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 (): sl@0: container_reference (), it1_ (), it2_ () {} sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 (self_type &m, size_type it1, size_type it2): sl@0: container_reference (m), it1_ (it1), it2_ (it2) {} sl@0: sl@0: // Arithmetic sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator ++ () { sl@0: ++ it1_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator -- () { sl@0: -- it1_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator += (difference_type n) { sl@0: it1_ += n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator -= (difference_type n) { sl@0: it1_ -= n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: difference_type operator - (const iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ()); sl@0: return it1_ - it.it1_; sl@0: } sl@0: sl@0: // Dereference sl@0: BOOST_UBLAS_INLINE sl@0: reference operator * () const { sl@0: return (*this) ().at_element (it1_, it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reference operator [] (difference_type n) const { sl@0: return *(*this + n); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: iterator2 begin () const { sl@0: return (*this) ().find2 (1, it1_, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: iterator2 end () const { sl@0: return (*this) ().find2 (1, it1_, (*this) ().size2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: reverse_iterator2 rbegin () const { sl@0: return reverse_iterator2 (end ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: reverse_iterator2 rend () const { sl@0: return reverse_iterator2 (begin ()); sl@0: } sl@0: #endif sl@0: sl@0: // Indices sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 () const { sl@0: return it1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 () const { sl@0: return it2_; sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator = (const iterator1 &it) { sl@0: container_reference::assign (&it ()); sl@0: it1_ = it.it1_; sl@0: it2_ = it.it2_; sl@0: return *this; sl@0: } sl@0: sl@0: // Comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool operator == (const iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ()); sl@0: return it1_ == it.it1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: bool operator < (const iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ()); sl@0: return it1_ < it.it1_; sl@0: } sl@0: sl@0: private: sl@0: size_type it1_; sl@0: size_type it2_; sl@0: sl@0: friend class const_iterator1; sl@0: }; sl@0: #endif sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 begin1 () { sl@0: return find1 (0, 0, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 end1 () { sl@0: return find1 (0, size1_, 0); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: class const_iterator2: sl@0: public container_const_reference, sl@0: public random_access_iterator_base { sl@0: public: sl@0: typedef typename banded_matrix::value_type value_type; sl@0: typedef typename banded_matrix::difference_type difference_type; sl@0: typedef typename banded_matrix::const_reference reference; sl@0: typedef const typename banded_matrix::pointer pointer; sl@0: sl@0: typedef const_iterator1 dual_iterator_type; sl@0: typedef const_reverse_iterator1 dual_reverse_iterator_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 (): sl@0: container_const_reference (), it1_ (), it2_ () {} sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 (const self_type &m, size_type it1, size_type it2): sl@0: container_const_reference (m), it1_ (it1), it2_ (it2) {} sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 (const iterator2 &it): sl@0: container_const_reference (it ()), it1_ (it.it1_), it2_ (it.it2_) {} sl@0: sl@0: // Arithmetic sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator ++ () { sl@0: ++ it2_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator -- () { sl@0: -- it2_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator += (difference_type n) { sl@0: it2_ += n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator -= (difference_type n) { sl@0: it2_ -= n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: difference_type operator - (const const_iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ()); sl@0: return it2_ - it.it2_; sl@0: } sl@0: sl@0: // Dereference sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator * () const { sl@0: return (*this) () (it1_, it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator [] (difference_type n) const { sl@0: return *(*this + n); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_iterator1 begin () const { sl@0: return (*this) ().find1 (1, 0, it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_iterator1 end () const { sl@0: return (*this) ().find1 (1, (*this) ().size1 (), it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_reverse_iterator1 rbegin () const { sl@0: return const_reverse_iterator1 (end ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_reverse_iterator1 rend () const { sl@0: return const_reverse_iterator1 (begin ()); sl@0: } sl@0: #endif sl@0: sl@0: // Indices sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 () const { sl@0: return it1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 () const { sl@0: return it2_; sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator = (const const_iterator2 &it) { sl@0: container_const_reference::assign (&it ()); sl@0: it1_ = it.it1_; sl@0: it2_ = it.it2_; sl@0: return *this; sl@0: } sl@0: sl@0: // Comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool operator == (const const_iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ()); sl@0: return it2_ == it.it2_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: bool operator < (const const_iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ()); sl@0: return it2_ < it.it2_; sl@0: } sl@0: sl@0: private: sl@0: size_type it1_; sl@0: size_type it2_; sl@0: }; sl@0: #endif sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 begin2 () const { sl@0: return find2 (0, 0, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 end2 () const { sl@0: return find2 (0, 0, size2_); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: class iterator2: sl@0: public container_reference, sl@0: public random_access_iterator_base { sl@0: public: sl@0: typedef typename banded_matrix::value_type value_type; sl@0: typedef typename banded_matrix::difference_type difference_type; sl@0: typedef typename banded_matrix::reference reference; sl@0: typedef typename banded_matrix::pointer pointer; sl@0: sl@0: typedef iterator1 dual_iterator_type; sl@0: typedef reverse_iterator1 dual_reverse_iterator_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 (): sl@0: container_reference (), it1_ (), it2_ () {} sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 (self_type &m, size_type it1, size_type it2): sl@0: container_reference (m), it1_ (it1), it2_ (it2) {} sl@0: sl@0: // Arithmetic sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator ++ () { sl@0: ++ it2_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator -- () { sl@0: -- it2_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator += (difference_type n) { sl@0: it2_ += n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator -= (difference_type n) { sl@0: it2_ -= n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: difference_type operator - (const iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ()); sl@0: return it2_ - it.it2_; sl@0: } sl@0: sl@0: // Dereference sl@0: BOOST_UBLAS_INLINE sl@0: reference operator * () const { sl@0: return (*this) ().at_element (it1_, it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reference operator [] (difference_type n) const { sl@0: return *(*this + n); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: iterator1 begin () const { sl@0: return (*this) ().find1 (1, 0, it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: iterator1 end () const { sl@0: return (*this) ().find1 (1, (*this) ().size1 (), it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: reverse_iterator1 rbegin () const { sl@0: return reverse_iterator1 (end ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: reverse_iterator1 rend () const { sl@0: return reverse_iterator1 (begin ()); sl@0: } sl@0: #endif sl@0: sl@0: // Indices sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 () const { sl@0: return it1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 () const { sl@0: return it2_; sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator = (const iterator2 &it) { sl@0: container_reference::assign (&it ()); sl@0: it1_ = it.it1_; sl@0: it2_ = it.it2_; sl@0: return *this; sl@0: } sl@0: sl@0: // Comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool operator == (const iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ()); sl@0: return it2_ == it.it2_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: bool operator < (const iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ()); sl@0: return it2_ < it.it2_; sl@0: } sl@0: sl@0: private: sl@0: size_type it1_; sl@0: size_type it2_; sl@0: sl@0: friend class const_iterator2; sl@0: }; sl@0: #endif sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 begin2 () { sl@0: return find2 (0, 0, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 end2 () { sl@0: return find2 (0, 0, size2_); sl@0: } sl@0: sl@0: // Reverse iterators sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: const_reverse_iterator1 rbegin1 () const { sl@0: return const_reverse_iterator1 (end1 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_reverse_iterator1 rend1 () const { sl@0: return const_reverse_iterator1 (begin1 ()); sl@0: } sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: reverse_iterator1 rbegin1 () { sl@0: return reverse_iterator1 (end1 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reverse_iterator1 rend1 () { sl@0: return reverse_iterator1 (begin1 ()); sl@0: } sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: const_reverse_iterator2 rbegin2 () const { sl@0: return const_reverse_iterator2 (end2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_reverse_iterator2 rend2 () const { sl@0: return const_reverse_iterator2 (begin2 ()); sl@0: } sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: reverse_iterator2 rbegin2 () { sl@0: return reverse_iterator2 (end2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reverse_iterator2 rend2 () { sl@0: return reverse_iterator2 (begin2 ()); sl@0: } sl@0: sl@0: private: sl@0: size_type size1_; sl@0: size_type size2_; sl@0: size_type lower_; sl@0: size_type upper_; sl@0: array_type data_; sl@0: typedef const value_type const_value_type; sl@0: static const_value_type zero_; sl@0: }; sl@0: sl@0: template sl@0: typename banded_matrix::const_value_type banded_matrix::zero_ = value_type/*zero*/(); sl@0: sl@0: sl@0: // Diagonal matrix class sl@0: template sl@0: class diagonal_matrix: sl@0: public banded_matrix { sl@0: public: sl@0: typedef typename A::size_type size_type; sl@0: typedef banded_matrix matrix_type; sl@0: typedef A array_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: diagonal_matrix (): sl@0: matrix_type () {} sl@0: BOOST_UBLAS_INLINE sl@0: diagonal_matrix (size_type size): sl@0: matrix_type (size, size) {} sl@0: BOOST_UBLAS_INLINE sl@0: diagonal_matrix (size_type size, const array_type& data): sl@0: matrix_type (size, size, 0, 0, data) {} sl@0: BOOST_UBLAS_INLINE sl@0: diagonal_matrix (size_type size1, size_type size2): sl@0: matrix_type (size1, size2) {} sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: diagonal_matrix (const matrix_expression &ae): sl@0: matrix_type (ae) {} sl@0: BOOST_UBLAS_INLINE sl@0: ~diagonal_matrix () {} sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: diagonal_matrix &operator = (const diagonal_matrix &m) { sl@0: matrix_type::operator = (m); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: diagonal_matrix &operator = (const matrix_expression &ae) { sl@0: matrix_type::operator = (ae); sl@0: return *this; sl@0: } sl@0: }; sl@0: sl@0: // Banded matrix adaptor class sl@0: template sl@0: class banded_adaptor: sl@0: public matrix_expression > { sl@0: sl@0: typedef banded_adaptor self_type; sl@0: public: sl@0: #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS sl@0: using matrix_expression::operator (); sl@0: #endif sl@0: typedef const M const_matrix_type; sl@0: typedef M matrix_type; sl@0: typedef typename M::size_type size_type; sl@0: typedef typename M::difference_type difference_type; sl@0: typedef typename M::value_type value_type; sl@0: typedef typename M::const_reference const_reference; sl@0: typedef typename boost::mpl::if_, sl@0: typename M::const_reference, sl@0: typename M::reference>::type reference; sl@0: typedef typename boost::mpl::if_, sl@0: typename M::const_closure_type, sl@0: typename M::closure_type>::type matrix_closure_type; sl@0: typedef const self_type const_closure_type; sl@0: typedef self_type closure_type; sl@0: // Replaced by _temporary_traits to avoid type requirements on M sl@0: //typedef typename M::vector_temporary_type vector_temporary_type; sl@0: //typedef typename M::matrix_temporary_type matrix_temporary_type; sl@0: typedef typename storage_restrict_traits::storage_category storage_category; sl@0: typedef typename M::orientation_category orientation_category; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: banded_adaptor (matrix_type &data, size_type lower = 0, size_type upper = 0): sl@0: matrix_expression (), sl@0: data_ (data), lower_ (lower), upper_ (upper) {} sl@0: BOOST_UBLAS_INLINE sl@0: banded_adaptor (const banded_adaptor &m): sl@0: matrix_expression (), sl@0: data_ (m.data_), lower_ (m.lower_), upper_ (m.upper_) {} sl@0: sl@0: // Accessors sl@0: BOOST_UBLAS_INLINE sl@0: size_type size1 () const { sl@0: return data_.size1 (); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type size2 () const { sl@0: return data_.size2 (); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type lower () const { sl@0: return lower_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type upper () const { sl@0: return upper_; sl@0: } sl@0: sl@0: // Storage accessors sl@0: BOOST_UBLAS_INLINE sl@0: const matrix_closure_type &data () const { sl@0: return data_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: matrix_closure_type &data () { sl@0: return data_; sl@0: } sl@0: sl@0: // Element access sl@0: #ifndef BOOST_UBLAS_PROXY_CONST_MEMBER sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator () (size_type i, size_type j) const { sl@0: BOOST_UBLAS_CHECK (i < size1 (), bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < size2 (), bad_index ()); sl@0: #ifdef BOOST_UBLAS_OWN_BANDED sl@0: size_type k = (std::max) (i, j); sl@0: size_type l = lower_ + j - i; sl@0: if (k < (std::max) (size1 (), size2 ()) && sl@0: l < lower_ + 1 + upper_) sl@0: return data () (i, j); sl@0: #else sl@0: size_type k = j; sl@0: size_type l = upper_ + i - j; sl@0: if (k < size2 () && sl@0: l < lower_ + 1 + upper_) sl@0: return data () (i, j); sl@0: #endif sl@0: return zero_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reference operator () (size_type i, size_type j) { sl@0: BOOST_UBLAS_CHECK (i < size1 (), bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < size2 (), bad_index ()); sl@0: #ifdef BOOST_UBLAS_OWN_BANDED sl@0: size_type k = (std::max) (i, j); sl@0: size_type l = lower_ + j - i; sl@0: if (k < (std::max) (size1 (), size2 ()) && sl@0: l < lower_ + 1 + upper_) sl@0: return data () (i, j); sl@0: #else sl@0: size_type k = j; sl@0: size_type l = upper_ + i - j; sl@0: if (k < size2 () && sl@0: l < lower_ + 1 + upper_) sl@0: return data () (i, j); sl@0: #endif sl@0: #ifndef BOOST_UBLAS_REFERENCE_CONST_MEMBER sl@0: bad_index ().raise (); sl@0: #endif sl@0: return const_cast(zero_); sl@0: } sl@0: #else sl@0: BOOST_UBLAS_INLINE sl@0: reference operator () (size_type i, size_type j) const { sl@0: BOOST_UBLAS_CHECK (i < size1 (), bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < size2 (), bad_index ()); sl@0: #ifdef BOOST_UBLAS_OWN_BANDED sl@0: size_type k = (std::max) (i, j); sl@0: size_type l = lower_ + j - i; sl@0: if (k < (std::max) (size1 (), size2 ()) && sl@0: l < lower_ + 1 + upper_) sl@0: return data () (i, j); sl@0: #else sl@0: size_type k = j; sl@0: size_type l = upper_ + i - j; sl@0: if (k < size2 () && sl@0: l < lower_ + 1 + upper_) sl@0: return data () (i, j); sl@0: #endif sl@0: #ifndef BOOST_UBLAS_REFERENCE_CONST_MEMBER sl@0: bad_index ().raise (); sl@0: #endif sl@0: return const_cast(zero_); sl@0: } sl@0: #endif sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: banded_adaptor &operator = (const banded_adaptor &m) { sl@0: matrix_assign (*this, m); sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: banded_adaptor &assign_temporary (banded_adaptor &m) { sl@0: *this = m; sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: banded_adaptor &operator = (const matrix_expression &ae) { sl@0: matrix_assign (*this, matrix (ae)); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: banded_adaptor &assign (const matrix_expression &ae) { sl@0: matrix_assign (*this, ae); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: banded_adaptor& operator += (const matrix_expression &ae) { sl@0: matrix_assign (*this, matrix (*this + ae)); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: banded_adaptor &plus_assign (const matrix_expression &ae) { sl@0: matrix_assign (*this, ae); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: banded_adaptor& operator -= (const matrix_expression &ae) { sl@0: matrix_assign (*this, matrix (*this - ae)); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: banded_adaptor &minus_assign (const matrix_expression &ae) { sl@0: matrix_assign (*this, ae); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: banded_adaptor& operator *= (const AT &at) { sl@0: matrix_assign_scalar (*this, at); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: banded_adaptor& operator /= (const AT &at) { sl@0: matrix_assign_scalar (*this, at); sl@0: return *this; sl@0: } sl@0: sl@0: // Closure comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool same_closure (const banded_adaptor &ba) const { sl@0: return (*this).data ().same_closure (ba.data ()); sl@0: } sl@0: sl@0: // Swapping sl@0: BOOST_UBLAS_INLINE sl@0: void swap (banded_adaptor &m) { sl@0: if (this != &m) { sl@0: BOOST_UBLAS_CHECK (lower_ == m.lower_, bad_size ()); sl@0: BOOST_UBLAS_CHECK (upper_ == m.upper_, bad_size ()); sl@0: matrix_swap (*this, m); sl@0: } sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: friend void swap (banded_adaptor &m1, banded_adaptor &m2) { sl@0: m1.swap (m2); sl@0: } sl@0: sl@0: // Iterator types sl@0: private: sl@0: // Use the matrix iterator sl@0: typedef typename M::const_iterator1 const_subiterator1_type; sl@0: typedef typename boost::mpl::if_, sl@0: typename M::const_iterator1, sl@0: typename M::iterator1>::type subiterator1_type; sl@0: typedef typename M::const_iterator2 const_subiterator2_type; sl@0: typedef typename boost::mpl::if_, sl@0: typename M::const_iterator2, sl@0: typename M::iterator2>::type subiterator2_type; sl@0: sl@0: public: sl@0: #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: typedef indexed_iterator1 iterator1; sl@0: typedef indexed_iterator2 iterator2; sl@0: typedef indexed_const_iterator1 const_iterator1; sl@0: typedef indexed_const_iterator2 const_iterator2; sl@0: #else sl@0: class const_iterator1; sl@0: class iterator1; sl@0: class const_iterator2; sl@0: class iterator2; sl@0: #endif sl@0: typedef reverse_iterator_base1 const_reverse_iterator1; sl@0: typedef reverse_iterator_base1 reverse_iterator1; sl@0: typedef reverse_iterator_base2 const_reverse_iterator2; sl@0: typedef reverse_iterator_base2 reverse_iterator2; sl@0: sl@0: // Element lookup sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 find1 (int rank, size_type i, size_type j) const { sl@0: if (rank == 1) { sl@0: size_type lower_i = (std::max) (difference_type (j - upper_), difference_type (0)); sl@0: i = (std::max) (i, lower_i); sl@0: size_type upper_i = (std::min) (j + 1 + lower_, size1 ()); sl@0: i = (std::min) (i, upper_i); sl@0: } sl@0: return const_iterator1 (*this, data ().find1 (rank, i, j)); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 find1 (int rank, size_type i, size_type j) { sl@0: if (rank == 1) { sl@0: size_type lower_i = (std::max) (difference_type (j - upper_), difference_type (0)); sl@0: i = (std::max) (i, lower_i); sl@0: size_type upper_i = (std::min) (j + 1 + lower_, size1 ()); sl@0: i = (std::min) (i, upper_i); sl@0: } sl@0: return iterator1 (*this, data ().find1 (rank, i, j)); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 find2 (int rank, size_type i, size_type j) const { sl@0: if (rank == 1) { sl@0: size_type lower_j = (std::max) (difference_type (i - lower_), difference_type (0)); sl@0: j = (std::max) (j, lower_j); sl@0: size_type upper_j = (std::min) (i + 1 + upper_, size2 ()); sl@0: j = (std::min) (j, upper_j); sl@0: } sl@0: return const_iterator2 (*this, data ().find2 (rank, i, j)); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 find2 (int rank, size_type i, size_type j) { sl@0: if (rank == 1) { sl@0: size_type lower_j = (std::max) (difference_type (i - lower_), difference_type (0)); sl@0: j = (std::max) (j, lower_j); sl@0: size_type upper_j = (std::min) (i + 1 + upper_, size2 ()); sl@0: j = (std::min) (j, upper_j); sl@0: } sl@0: return iterator2 (*this, data ().find2 (rank, i, j)); sl@0: } sl@0: sl@0: // Iterators simply are indices. sl@0: sl@0: #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: class const_iterator1: sl@0: public container_const_reference, sl@0: public random_access_iterator_base::iterator_category, sl@0: const_iterator1, value_type> { sl@0: public: sl@0: typedef typename const_subiterator1_type::value_type value_type; sl@0: typedef typename const_subiterator1_type::difference_type difference_type; sl@0: typedef typename const_subiterator1_type::reference reference; sl@0: typedef typename const_subiterator1_type::pointer pointer; sl@0: sl@0: typedef const_iterator2 dual_iterator_type; sl@0: typedef const_reverse_iterator2 dual_reverse_iterator_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 (): sl@0: container_const_reference (), it1_ () {} sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 (const self_type &m, const const_subiterator1_type &it1): sl@0: container_const_reference (m), it1_ (it1) {} sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 (const iterator1 &it): sl@0: container_const_reference (it ()), it1_ (it.it1_) {} sl@0: sl@0: // Arithmetic sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator ++ () { sl@0: ++ it1_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator -- () { sl@0: -- it1_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator += (difference_type n) { sl@0: it1_ += n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator -= (difference_type n) { sl@0: it1_ -= n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: difference_type operator - (const const_iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it1_ - it.it1_; sl@0: } sl@0: sl@0: // Dereference sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator * () const { sl@0: size_type i = index1 (); sl@0: size_type j = index2 (); sl@0: BOOST_UBLAS_CHECK (i < (*this) ().size1 (), bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < (*this) ().size2 (), bad_index ()); sl@0: #ifdef BOOST_UBLAS_OWN_BANDED sl@0: size_type k = (std::max) (i, j); sl@0: size_type l = (*this) ().lower () + j - i; sl@0: if (k < (std::max) ((*this) ().size1 (), (*this) ().size2 ()) && sl@0: l < (*this) ().lower () + 1 + (*this) ().upper ()) sl@0: return *it1_; sl@0: #else sl@0: size_type k = j; sl@0: size_type l = (*this) ().upper () + i - j; sl@0: if (k < (*this) ().size2 () && sl@0: l < (*this) ().lower () + 1 + (*this) ().upper ()) sl@0: return *it1_; sl@0: #endif sl@0: return (*this) () (i, j); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator [] (difference_type n) const { sl@0: return *(*this + n); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_iterator2 begin () const { sl@0: return (*this) ().find2 (1, index1 (), 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_iterator2 end () const { sl@0: return (*this) ().find2 (1, index1 (), (*this) ().size2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_reverse_iterator2 rbegin () const { sl@0: return const_reverse_iterator2 (end ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_reverse_iterator2 rend () const { sl@0: return const_reverse_iterator2 (begin ()); sl@0: } sl@0: #endif sl@0: sl@0: // Indices sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 () const { sl@0: return it1_.index1 (); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 () const { sl@0: return it1_.index2 (); sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator = (const const_iterator1 &it) { sl@0: container_const_reference::assign (&it ()); sl@0: it1_ = it.it1_; sl@0: return *this; sl@0: } sl@0: sl@0: // Comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool operator == (const const_iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it1_ == it.it1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: bool operator < (const const_iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it1_ < it.it1_; sl@0: } sl@0: sl@0: private: sl@0: const_subiterator1_type it1_; sl@0: }; sl@0: #endif sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 begin1 () const { sl@0: return find1 (0, 0, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 end1 () const { sl@0: return find1 (0, size1 (), 0); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: class iterator1: sl@0: public container_reference, sl@0: public random_access_iterator_base::iterator_category, sl@0: iterator1, value_type> { sl@0: public: sl@0: typedef typename subiterator1_type::value_type value_type; sl@0: typedef typename subiterator1_type::difference_type difference_type; sl@0: typedef typename subiterator1_type::reference reference; sl@0: typedef typename subiterator1_type::pointer pointer; sl@0: sl@0: typedef iterator2 dual_iterator_type; sl@0: typedef reverse_iterator2 dual_reverse_iterator_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 (): sl@0: container_reference (), it1_ () {} sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 (self_type &m, const subiterator1_type &it1): sl@0: container_reference (m), it1_ (it1) {} sl@0: sl@0: // Arithmetic sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator ++ () { sl@0: ++ it1_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator -- () { sl@0: -- it1_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator += (difference_type n) { sl@0: it1_ += n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator -= (difference_type n) { sl@0: it1_ -= n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: difference_type operator - (const iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it1_ - it.it1_; sl@0: } sl@0: sl@0: // Dereference sl@0: BOOST_UBLAS_INLINE sl@0: reference operator * () const { sl@0: size_type i = index1 (); sl@0: size_type j = index2 (); sl@0: BOOST_UBLAS_CHECK (i < (*this) ().size1 (), bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < (*this) ().size2 (), bad_index ()); sl@0: #ifdef BOOST_UBLAS_OWN_BANDED sl@0: size_type k = (std::max) (i, j); sl@0: size_type l = (*this) ().lower () + j - i; sl@0: if (k < (std::max) ((*this) ().size1 (), (*this) ().size2 ()) && sl@0: l < (*this) ().lower () + 1 + (*this) ().upper ()) sl@0: return *it1_; sl@0: #else sl@0: size_type k = j; sl@0: size_type l = (*this) ().upper () + i - j; sl@0: if (k < (*this) ().size2 () && sl@0: l < (*this) ().lower () + 1 + (*this) ().upper ()) sl@0: return *it1_; sl@0: #endif sl@0: return (*this) () (i, j); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reference operator [] (difference_type n) const { sl@0: return *(*this + n); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: iterator2 begin () const { sl@0: return (*this) ().find2 (1, index1 (), 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: iterator2 end () const { sl@0: return (*this) ().find2 (1, index1 (), (*this) ().size2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: reverse_iterator2 rbegin () const { sl@0: return reverse_iterator2 (end ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: reverse_iterator2 rend () const { sl@0: return reverse_iterator2 (begin ()); sl@0: } sl@0: #endif sl@0: sl@0: // Indices sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 () const { sl@0: return it1_.index1 (); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 () const { sl@0: return it1_.index2 (); sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator = (const iterator1 &it) { sl@0: container_reference::assign (&it ()); sl@0: it1_ = it.it1_; sl@0: return *this; sl@0: } sl@0: sl@0: // Comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool operator == (const iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it1_ == it.it1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: bool operator < (const iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it1_ < it.it1_; sl@0: } sl@0: sl@0: private: sl@0: subiterator1_type it1_; sl@0: sl@0: friend class const_iterator1; sl@0: }; sl@0: #endif sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 begin1 () { sl@0: return find1 (0, 0, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 end1 () { sl@0: return find1 (0, size1 (), 0); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: class const_iterator2: sl@0: public container_const_reference, sl@0: public random_access_iterator_base { sl@0: public: sl@0: typedef typename iterator_restrict_traits::iterator_category iterator_category; sl@0: typedef typename const_subiterator2_type::value_type value_type; sl@0: typedef typename const_subiterator2_type::difference_type difference_type; sl@0: typedef typename const_subiterator2_type::reference reference; sl@0: typedef typename const_subiterator2_type::pointer pointer; sl@0: sl@0: typedef const_iterator1 dual_iterator_type; sl@0: typedef const_reverse_iterator1 dual_reverse_iterator_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 (): sl@0: container_const_reference (), it2_ () {} sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 (const self_type &m, const const_subiterator2_type &it2): sl@0: container_const_reference (m), it2_ (it2) {} sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 (const iterator2 &it): sl@0: container_const_reference (it ()), it2_ (it.it2_) {} sl@0: sl@0: // Arithmetic sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator ++ () { sl@0: ++ it2_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator -- () { sl@0: -- it2_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator += (difference_type n) { sl@0: it2_ += n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator -= (difference_type n) { sl@0: it2_ -= n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: difference_type operator - (const const_iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it2_ - it.it2_; sl@0: } sl@0: sl@0: // Dereference sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator * () const { sl@0: size_type i = index1 (); sl@0: size_type j = index2 (); sl@0: BOOST_UBLAS_CHECK (i < (*this) ().size1 (), bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < (*this) ().size2 (), bad_index ()); sl@0: #ifdef BOOST_UBLAS_OWN_BANDED sl@0: size_type k = (std::max) (i, j); sl@0: size_type l = (*this) ().lower () + j - i; sl@0: if (k < (std::max) ((*this) ().size1 (), (*this) ().size2 ()) && sl@0: l < (*this) ().lower () + 1 + (*this) ().upper ()) sl@0: return *it2_; sl@0: #else sl@0: size_type k = j; sl@0: size_type l = (*this) ().upper () + i - j; sl@0: if (k < (*this) ().size2 () && sl@0: l < (*this) ().lower () + 1 + (*this) ().upper ()) sl@0: return *it2_; sl@0: #endif sl@0: return (*this) () (i, j); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator [] (difference_type n) const { sl@0: return *(*this + n); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_iterator1 begin () const { sl@0: return (*this) ().find1 (1, 0, index2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_iterator1 end () const { sl@0: return (*this) ().find1 (1, (*this) ().size1 (), index2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_reverse_iterator1 rbegin () const { sl@0: return const_reverse_iterator1 (end ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_reverse_iterator1 rend () const { sl@0: return const_reverse_iterator1 (begin ()); sl@0: } sl@0: #endif sl@0: sl@0: // Indices sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 () const { sl@0: return it2_.index1 (); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 () const { sl@0: return it2_.index2 (); sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator = (const const_iterator2 &it) { sl@0: container_const_reference::assign (&it ()); sl@0: it2_ = it.it2_; sl@0: return *this; sl@0: } sl@0: sl@0: // Comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool operator == (const const_iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it2_ == it.it2_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: bool operator < (const const_iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it2_ < it.it2_; sl@0: } sl@0: sl@0: private: sl@0: const_subiterator2_type it2_; sl@0: }; sl@0: #endif sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 begin2 () const { sl@0: return find2 (0, 0, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 end2 () const { sl@0: return find2 (0, 0, size2 ()); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: class iterator2: sl@0: public container_reference, sl@0: public random_access_iterator_base::iterator_category, sl@0: iterator2, value_type> { sl@0: public: sl@0: typedef typename subiterator2_type::value_type value_type; sl@0: typedef typename subiterator2_type::difference_type difference_type; sl@0: typedef typename subiterator2_type::reference reference; sl@0: typedef typename subiterator2_type::pointer pointer; sl@0: sl@0: typedef iterator1 dual_iterator_type; sl@0: typedef reverse_iterator1 dual_reverse_iterator_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 (): sl@0: container_reference (), it2_ () {} sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 (self_type &m, const subiterator2_type &it2): sl@0: container_reference (m), it2_ (it2) {} sl@0: sl@0: // Arithmetic sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator ++ () { sl@0: ++ it2_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator -- () { sl@0: -- it2_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator += (difference_type n) { sl@0: it2_ += n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator -= (difference_type n) { sl@0: it2_ -= n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: difference_type operator - (const iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it2_ - it.it2_; sl@0: } sl@0: sl@0: // Dereference sl@0: BOOST_UBLAS_INLINE sl@0: reference operator * () const { sl@0: size_type i = index1 (); sl@0: size_type j = index2 (); sl@0: BOOST_UBLAS_CHECK (i < (*this) ().size1 (), bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < (*this) ().size2 (), bad_index ()); sl@0: #ifdef BOOST_UBLAS_OWN_BANDED sl@0: size_type k = (std::max) (i, j); sl@0: size_type l = (*this) ().lower () + j - i; sl@0: if (k < (std::max) ((*this) ().size1 (), (*this) ().size2 ()) && sl@0: l < (*this) ().lower () + 1 + (*this) ().upper ()) sl@0: return *it2_; sl@0: #else sl@0: size_type k = j; sl@0: size_type l = (*this) ().upper () + i - j; sl@0: if (k < (*this) ().size2 () && sl@0: l < (*this) ().lower () + 1 + (*this) ().upper ()) sl@0: return *it2_; sl@0: #endif sl@0: return (*this) () (i, j); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reference operator [] (difference_type n) const { sl@0: return *(*this + n); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: iterator1 begin () const { sl@0: return (*this) ().find1 (1, 0, index2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: iterator1 end () const { sl@0: return (*this) ().find1 (1, (*this) ().size1 (), index2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: reverse_iterator1 rbegin () const { sl@0: return reverse_iterator1 (end ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: reverse_iterator1 rend () const { sl@0: return reverse_iterator1 (begin ()); sl@0: } sl@0: #endif sl@0: sl@0: // Indices sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 () const { sl@0: return it2_.index1 (); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 () const { sl@0: return it2_.index2 (); sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator = (const iterator2 &it) { sl@0: container_reference::assign (&it ()); sl@0: it2_ = it.it2_; sl@0: return *this; sl@0: } sl@0: sl@0: // Comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool operator == (const iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it2_ == it.it2_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: bool operator < (const iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it2_ < it.it2_; sl@0: } sl@0: sl@0: private: sl@0: subiterator2_type it2_; sl@0: sl@0: friend class const_iterator2; sl@0: }; sl@0: #endif sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 begin2 () { sl@0: return find2 (0, 0, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 end2 () { sl@0: return find2 (0, 0, size2 ()); sl@0: } sl@0: sl@0: // Reverse iterators sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: const_reverse_iterator1 rbegin1 () const { sl@0: return const_reverse_iterator1 (end1 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_reverse_iterator1 rend1 () const { sl@0: return const_reverse_iterator1 (begin1 ()); sl@0: } sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: reverse_iterator1 rbegin1 () { sl@0: return reverse_iterator1 (end1 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reverse_iterator1 rend1 () { sl@0: return reverse_iterator1 (begin1 ()); sl@0: } sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: const_reverse_iterator2 rbegin2 () const { sl@0: return const_reverse_iterator2 (end2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_reverse_iterator2 rend2 () const { sl@0: return const_reverse_iterator2 (begin2 ()); sl@0: } sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: reverse_iterator2 rbegin2 () { sl@0: return reverse_iterator2 (end2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reverse_iterator2 rend2 () { sl@0: return reverse_iterator2 (begin2 ()); sl@0: } sl@0: sl@0: private: sl@0: matrix_closure_type data_; sl@0: size_type lower_; sl@0: size_type upper_; sl@0: typedef const value_type const_value_type; sl@0: static const_value_type zero_; sl@0: }; sl@0: sl@0: // Specialization for temporary_traits sl@0: template sl@0: struct vector_temporary_traits< banded_adaptor > sl@0: : vector_temporary_traits< M > {} ; sl@0: template sl@0: struct vector_temporary_traits< const banded_adaptor > sl@0: : vector_temporary_traits< M > {} ; sl@0: sl@0: template sl@0: struct matrix_temporary_traits< banded_adaptor > sl@0: : matrix_temporary_traits< M > {} ; sl@0: template sl@0: struct matrix_temporary_traits< const banded_adaptor > sl@0: : matrix_temporary_traits< M > {} ; sl@0: sl@0: sl@0: template sl@0: typename banded_adaptor::const_value_type banded_adaptor::zero_ = value_type/*zero*/(); sl@0: sl@0: // Diagonal matrix adaptor class sl@0: template sl@0: class diagonal_adaptor: sl@0: public banded_adaptor { sl@0: public: sl@0: typedef M matrix_type; sl@0: typedef banded_adaptor adaptor_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: diagonal_adaptor (): sl@0: adaptor_type () {} sl@0: BOOST_UBLAS_INLINE sl@0: diagonal_adaptor (matrix_type &data): sl@0: adaptor_type (data) {} sl@0: BOOST_UBLAS_INLINE sl@0: ~diagonal_adaptor () {} sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: diagonal_adaptor &operator = (const diagonal_adaptor &m) { sl@0: adaptor_type::operator = (m); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: diagonal_adaptor &operator = (const matrix_expression &ae) { sl@0: adaptor_type::operator = (ae); sl@0: return *this; sl@0: } sl@0: }; sl@0: sl@0: }}} sl@0: sl@0: #endif