Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:20:21

0001 //
0002 //  Copyright (c) 2000-2002
0003 //  Joerg Walter, Mathias Koch
0004 //
0005 //  Distributed under the Boost Software License, Version 1.0. (See
0006 //  accompanying file LICENSE_1_0.txt or copy at
0007 //  http://www.boost.org/LICENSE_1_0.txt)
0008 //
0009 //  The authors gratefully acknowledge the support of
0010 //  GeNeSys mbH & Co. KG in producing this work.
0011 //
0012 
0013 #ifndef _BOOST_UBLAS_SYMMETRIC_
0014 #define _BOOST_UBLAS_SYMMETRIC_
0015 
0016 #include <boost/numeric/ublas/matrix.hpp>
0017 #include <boost/numeric/ublas/triangular.hpp>
0018 #include <boost/numeric/ublas/detail/temporary.hpp>
0019 
0020 // Iterators based on ideas of Jeremy Siek
0021 // Symmetric matrices are square. Thanks to Peter Schmitteckert for spotting this.
0022 
0023 namespace boost { namespace numeric { namespace ublas {
0024 
0025     template<class M>
0026     bool is_symmetric (const M &m) {
0027         typedef typename M::size_type size_type;
0028 
0029         if (m.size1 () != m.size2 ())
0030             return false;
0031         size_type size = BOOST_UBLAS_SAME (m.size1 (), m.size2 ());
0032         for (size_type i = 0; i < size; ++ i) {
0033             for (size_type j = i; j < size; ++ j) {
0034                 if (m (i, j) != m (j, i))
0035                     return false;
0036             }
0037         }
0038         return true;
0039     }
0040 
0041     // Array based symmetric matrix class
0042     template<class T, class TRI, class L, class A>
0043     class symmetric_matrix:
0044         public matrix_container<symmetric_matrix<T, TRI, L, A> > {
0045 
0046         typedef T *pointer;
0047         typedef TRI triangular_type;
0048         typedef L layout_type;
0049         typedef symmetric_matrix<T, TRI, L, A> self_type;
0050     public:
0051 #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
0052         using matrix_container<self_type>::operator ();
0053 #endif
0054         typedef typename A::size_type size_type;
0055         typedef typename A::difference_type difference_type;
0056         typedef T value_type;
0057         typedef const T &const_reference;
0058         typedef T &reference;
0059         typedef A array_type;
0060 
0061         typedef const matrix_reference<const self_type> const_closure_type;
0062         typedef matrix_reference<self_type> closure_type;
0063         typedef vector<T, A> vector_temporary_type;
0064         typedef matrix<T, L, A> matrix_temporary_type;  // general sub-matrix
0065         typedef packed_tag storage_category;
0066         typedef typename L::orientation_category orientation_category;
0067 
0068         // Construction and destruction
0069         BOOST_UBLAS_INLINE
0070         symmetric_matrix ():
0071             matrix_container<self_type> (),
0072             size_ (0), data_ (0) {}
0073         BOOST_UBLAS_INLINE
0074         symmetric_matrix (size_type size):
0075             matrix_container<self_type> (),
0076             size_ (BOOST_UBLAS_SAME (size, size)), data_ (triangular_type::packed_size (layout_type (), size, size)) {
0077         }
0078         BOOST_UBLAS_INLINE
0079         symmetric_matrix (size_type size1, size_type size2):
0080             matrix_container<self_type> (),
0081             size_ (BOOST_UBLAS_SAME (size1, size2)), data_ (triangular_type::packed_size (layout_type (), size1, size2)) {
0082         }
0083         BOOST_UBLAS_INLINE
0084         symmetric_matrix (size_type size, const array_type &data):
0085             matrix_container<self_type> (),
0086             size_ (size), data_ (data) {}
0087         BOOST_UBLAS_INLINE
0088         symmetric_matrix (const symmetric_matrix &m):
0089             matrix_container<self_type> (),
0090             size_ (m.size_), data_ (m.data_) {}
0091         template<class AE>
0092         BOOST_UBLAS_INLINE
0093         symmetric_matrix (const matrix_expression<AE> &ae):
0094             matrix_container<self_type> (),
0095             size_ (BOOST_UBLAS_SAME (ae ().size1 (), ae ().size2 ())),
0096             data_ (triangular_type::packed_size (layout_type (), size_, size_)) {
0097             matrix_assign<scalar_assign> (*this, ae);
0098         }
0099 
0100         // Accessors
0101         BOOST_UBLAS_INLINE
0102         size_type size1 () const {
0103             return size_;
0104         }
0105         BOOST_UBLAS_INLINE
0106         size_type size2 () const {
0107             return size_;
0108         }
0109 
0110         // Storage accessors
0111         BOOST_UBLAS_INLINE
0112         const array_type &data () const {
0113             return data_;
0114         }
0115         BOOST_UBLAS_INLINE
0116         array_type &data () {
0117             return data_;
0118         }
0119 
0120         // Resizing
0121         BOOST_UBLAS_INLINE
0122         void resize (size_type size, bool preserve = true) {
0123             if (preserve) {
0124                 self_type temporary (size, size);
0125                 detail::matrix_resize_preserve<layout_type, triangular_type> (*this, temporary);
0126             }
0127             else {
0128                 data ().resize (triangular_type::packed_size (layout_type (), size, size));
0129                 size_ = size;
0130             }
0131         }
0132         BOOST_UBLAS_INLINE
0133         void resize (size_type size1, size_type size2, bool preserve = true) {
0134             resize (BOOST_UBLAS_SAME (size1, size2), preserve);
0135         }
0136         BOOST_UBLAS_INLINE
0137         void resize_packed_preserve (size_type size) {
0138             size_ = BOOST_UBLAS_SAME (size, size);
0139             data ().resize (triangular_type::packed_size (layout_type (), size_, size_), value_type ());
0140         }
0141 
0142         // Element access
0143         BOOST_UBLAS_INLINE
0144         const_reference operator () (size_type i, size_type j) const {
0145             BOOST_UBLAS_CHECK (i < size_, bad_index ());
0146             BOOST_UBLAS_CHECK (j < size_, bad_index ());
0147             if (triangular_type::other (i, j))
0148                 return data () [triangular_type::element (layout_type (), i, size_, j, size_)];
0149             else
0150                 return data () [triangular_type::element (layout_type (), j, size_, i, size_)];
0151         }
0152         BOOST_UBLAS_INLINE
0153         reference at_element (size_type i, size_type j) {
0154             BOOST_UBLAS_CHECK (i < size_, bad_index ());
0155             BOOST_UBLAS_CHECK (j < size_, bad_index ());
0156             return data () [triangular_type::element (layout_type (), i, size_, j, size_)];
0157         }
0158         BOOST_UBLAS_INLINE
0159         reference operator () (size_type i, size_type j) {
0160             BOOST_UBLAS_CHECK (i < size_, bad_index ());
0161             BOOST_UBLAS_CHECK (j < size_, bad_index ());
0162             if (triangular_type::other (i, j))
0163                 return data () [triangular_type::element (layout_type (), i, size_, j, size_)];
0164             else
0165                 return data () [triangular_type::element (layout_type (), j, size_, i, size_)];
0166         }
0167 
0168         // Element assignment
0169         BOOST_UBLAS_INLINE
0170         reference insert_element (size_type i, size_type j, const_reference t) {
0171             return (operator () (i, j) = t);
0172         }
0173         BOOST_UBLAS_INLINE
0174         void erase_element (size_type i, size_type j) {
0175             operator () (i, j) = value_type/*zero*/();
0176         }
0177         
0178         // Zeroing
0179         BOOST_UBLAS_INLINE
0180         void clear () {
0181             // data ().clear ();
0182             std::fill (data ().begin (), data ().end (), value_type/*zero*/());
0183         }
0184 
0185         // Assignment
0186         BOOST_UBLAS_INLINE
0187         symmetric_matrix &operator = (const symmetric_matrix &m) {
0188             size_ = m.size_;
0189             data () = m.data ();
0190             return *this;
0191         }
0192         BOOST_UBLAS_INLINE
0193         symmetric_matrix &assign_temporary (symmetric_matrix &m) {
0194             swap (m);
0195             return *this;
0196         }
0197         template<class AE>
0198         BOOST_UBLAS_INLINE
0199         symmetric_matrix &operator = (const matrix_expression<AE> &ae) {
0200             self_type temporary (ae);
0201             return assign_temporary (temporary);
0202         }
0203         template<class AE>
0204         BOOST_UBLAS_INLINE
0205         symmetric_matrix &assign (const matrix_expression<AE> &ae) {
0206             matrix_assign<scalar_assign> (*this, ae);
0207             return *this;
0208         }
0209         template<class AE>
0210         BOOST_UBLAS_INLINE
0211         symmetric_matrix& operator += (const matrix_expression<AE> &ae) {
0212             self_type temporary (*this + ae);
0213             return assign_temporary (temporary);
0214         }
0215         template<class AE>
0216         BOOST_UBLAS_INLINE
0217         symmetric_matrix &plus_assign (const matrix_expression<AE> &ae) {
0218             matrix_assign<scalar_plus_assign> (*this, ae);
0219             return *this;
0220         }
0221         template<class AE>
0222         BOOST_UBLAS_INLINE
0223         symmetric_matrix& operator -= (const matrix_expression<AE> &ae) {
0224             self_type temporary (*this - ae);
0225             return assign_temporary (temporary);
0226         }
0227         template<class AE>
0228         BOOST_UBLAS_INLINE
0229         symmetric_matrix &minus_assign (const matrix_expression<AE> &ae) {
0230             matrix_assign<scalar_minus_assign> (*this, ae);
0231             return *this;
0232         }
0233         template<class AT>
0234         BOOST_UBLAS_INLINE
0235         symmetric_matrix& operator *= (const AT &at) {
0236             matrix_assign_scalar<scalar_multiplies_assign> (*this, at);
0237             return *this;
0238         }
0239         template<class AT>
0240         BOOST_UBLAS_INLINE
0241         symmetric_matrix& operator /= (const AT &at) {
0242             matrix_assign_scalar<scalar_divides_assign> (*this, at);
0243             return *this;
0244         }
0245 
0246         // Swapping
0247         BOOST_UBLAS_INLINE
0248         void swap (symmetric_matrix &m) {
0249             if (this != &m) {
0250                 std::swap (size_, m.size_);
0251                 data ().swap (m.data ());
0252             }
0253         }
0254         BOOST_UBLAS_INLINE
0255         friend void swap (symmetric_matrix &m1, symmetric_matrix &m2) {
0256             m1.swap (m2);
0257         }
0258 
0259         // Iterator types
0260 #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
0261         typedef indexed_iterator1<self_type, packed_random_access_iterator_tag> iterator1;
0262         typedef indexed_iterator2<self_type, packed_random_access_iterator_tag> iterator2;
0263         typedef indexed_const_iterator1<self_type, dense_random_access_iterator_tag> const_iterator1;
0264         typedef indexed_const_iterator2<self_type, dense_random_access_iterator_tag> const_iterator2;
0265 #else
0266         class const_iterator1;
0267         class iterator1;
0268         class const_iterator2;
0269         class iterator2;
0270 #endif
0271         typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
0272         typedef reverse_iterator_base1<iterator1> reverse_iterator1;
0273         typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
0274         typedef reverse_iterator_base2<iterator2> reverse_iterator2;
0275 
0276         // Element lookup
0277         BOOST_UBLAS_INLINE
0278         const_iterator1 find1 (int /* rank */, size_type i, size_type j) const {
0279             return const_iterator1 (*this, i, j);
0280         }
0281         BOOST_UBLAS_INLINE
0282         iterator1 find1 (int rank, size_type i, size_type j) {
0283             if (rank == 1)
0284                 i = triangular_type::mutable_restrict1 (i, j, size1(), size2());
0285             if (rank == 0)
0286                 i = triangular_type::global_mutable_restrict1 (i, size1(), j, size2());
0287             return iterator1 (*this, i, j);
0288         }
0289         BOOST_UBLAS_INLINE
0290         const_iterator2 find2 (int /* rank */, size_type i, size_type j) const {
0291             return const_iterator2 (*this, i, j);
0292         }
0293         BOOST_UBLAS_INLINE
0294         iterator2 find2 (int rank, size_type i, size_type j) {
0295             if (rank == 1)
0296                 j = triangular_type::mutable_restrict2 (i, j, size1(), size2());
0297             if (rank == 0)
0298                 j = triangular_type::global_mutable_restrict2 (i, size1(), j, size2());
0299             return iterator2 (*this, i, j);
0300         }
0301 
0302         // Iterators simply are indices.
0303 
0304 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
0305         class const_iterator1:
0306             public container_const_reference<symmetric_matrix>,
0307             public random_access_iterator_base<dense_random_access_iterator_tag,
0308                                                const_iterator1, value_type> {
0309         public:
0310             typedef typename symmetric_matrix::value_type value_type;
0311             typedef typename symmetric_matrix::difference_type difference_type;
0312             typedef typename symmetric_matrix::const_reference reference;
0313             typedef const typename symmetric_matrix::pointer pointer;
0314 
0315             typedef const_iterator2 dual_iterator_type;
0316             typedef const_reverse_iterator2 dual_reverse_iterator_type;
0317 
0318             // Construction and destruction
0319             BOOST_UBLAS_INLINE
0320             const_iterator1 ():
0321                 container_const_reference<self_type> (), it1_ (), it2_ () {}
0322             BOOST_UBLAS_INLINE
0323             const_iterator1 (const self_type &m, size_type it1, size_type it2):
0324                 container_const_reference<self_type> (m), it1_ (it1), it2_ (it2) {}
0325             BOOST_UBLAS_INLINE
0326             const_iterator1 (const iterator1 &it):
0327                 container_const_reference<self_type> (it ()), it1_ (it.it1_), it2_ (it.it2_) {}
0328 
0329             // Arithmetic
0330             BOOST_UBLAS_INLINE
0331             const_iterator1 &operator ++ () {
0332                 ++ it1_;
0333                 return *this;
0334             }
0335             BOOST_UBLAS_INLINE
0336             const_iterator1 &operator -- () {
0337                 -- it1_;
0338                 return *this;
0339             }
0340             BOOST_UBLAS_INLINE
0341             const_iterator1 &operator += (difference_type n) {
0342                 it1_ += n;
0343                 return *this;
0344             }
0345             BOOST_UBLAS_INLINE
0346             const_iterator1 &operator -= (difference_type n) {
0347                 it1_ -= n;
0348                 return *this;
0349             }
0350             BOOST_UBLAS_INLINE
0351             difference_type operator - (const const_iterator1 &it) const {
0352                 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
0353                 BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
0354                 return it1_ - it.it1_;
0355             }
0356 
0357             // Dereference
0358             BOOST_UBLAS_INLINE
0359             const_reference operator * () const {
0360                 return (*this) () (it1_, it2_);
0361             }
0362             BOOST_UBLAS_INLINE
0363             const_reference operator [] (difference_type n) const {
0364                 return *(*this + n);
0365             }
0366 
0367 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
0368             BOOST_UBLAS_INLINE
0369 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
0370             typename self_type::
0371 #endif
0372             const_iterator2 begin () const {
0373                 return (*this) ().find2 (1, it1_, 0);
0374             }
0375             BOOST_UBLAS_INLINE
0376 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
0377             typename self_type::
0378 #endif
0379             const_iterator2 cbegin () const {
0380                 return begin ();
0381             }
0382             BOOST_UBLAS_INLINE
0383 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
0384             typename self_type::
0385 #endif
0386             const_iterator2 end () const {
0387                 return (*this) ().find2 (1, it1_, (*this) ().size2 ());
0388             }
0389             BOOST_UBLAS_INLINE
0390 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
0391             typename self_type::
0392 #endif
0393             const_iterator2 cend () const {
0394                 return end ();
0395             }
0396             BOOST_UBLAS_INLINE
0397 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
0398             typename self_type::
0399 #endif
0400             const_reverse_iterator2 rbegin () const {
0401                 return const_reverse_iterator2 (end ());
0402             }
0403             BOOST_UBLAS_INLINE
0404 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
0405             typename self_type::
0406 #endif
0407             const_reverse_iterator2 crbegin () const {
0408                 return rbegin ();
0409             }
0410             BOOST_UBLAS_INLINE
0411 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
0412             typename self_type::
0413 #endif
0414             const_reverse_iterator2 rend () const {
0415                 return const_reverse_iterator2 (begin ());
0416             }
0417             BOOST_UBLAS_INLINE
0418 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
0419             typename self_type::
0420 #endif
0421             const_reverse_iterator2 crend () const {
0422                 return rend ();
0423             }
0424 #endif
0425 
0426             // Indices
0427             BOOST_UBLAS_INLINE
0428             size_type index1 () const {
0429                 return it1_;
0430             }
0431             BOOST_UBLAS_INLINE
0432             size_type index2 () const {
0433                 return it2_;
0434             }
0435 
0436             // Assignment
0437             BOOST_UBLAS_INLINE
0438             const_iterator1 &operator = (const const_iterator1 &it) {
0439                 container_const_reference<self_type>::assign (&it ());
0440                 it1_ = it.it1_;
0441                 it2_ = it.it2_;
0442                 return *this;
0443             }
0444 
0445             // Comparison
0446             BOOST_UBLAS_INLINE
0447             bool operator == (const const_iterator1 &it) const {
0448                 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
0449                 BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
0450                 return it1_ == it.it1_;
0451             }
0452             BOOST_UBLAS_INLINE
0453             bool operator < (const const_iterator1 &it) const {
0454                 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
0455                 BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
0456                 return it1_ < it.it1_;
0457             }
0458 
0459         private:
0460             size_type it1_;
0461             size_type it2_;
0462         };
0463 #endif
0464 
0465         BOOST_UBLAS_INLINE
0466         const_iterator1 begin1 () const {
0467             return find1 (0, 0, 0);
0468         }
0469         BOOST_UBLAS_INLINE
0470         const_iterator1 cbegin1 () const {
0471             return begin1 ();
0472         }
0473         BOOST_UBLAS_INLINE
0474         const_iterator1 end1 () const {
0475             return find1 (0, size_, 0);
0476         }
0477         BOOST_UBLAS_INLINE
0478         const_iterator1 cend1 () const {
0479             return end1 ();
0480         }
0481 
0482 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
0483         class iterator1:
0484             public container_reference<symmetric_matrix>,
0485             public random_access_iterator_base<packed_random_access_iterator_tag,
0486                                                iterator1, value_type> {
0487         public:
0488             typedef typename symmetric_matrix::value_type value_type;
0489             typedef typename symmetric_matrix::difference_type difference_type;
0490             typedef typename symmetric_matrix::reference reference;
0491             typedef typename symmetric_matrix::pointer pointer;
0492             typedef iterator2 dual_iterator_type;
0493             typedef reverse_iterator2 dual_reverse_iterator_type;
0494 
0495             // Construction and destruction
0496             BOOST_UBLAS_INLINE
0497             iterator1 ():
0498                 container_reference<self_type> (), it1_ (), it2_ () {}
0499             BOOST_UBLAS_INLINE
0500             iterator1 (self_type &m, size_type it1, size_type it2):
0501                 container_reference<self_type> (m), it1_ (it1), it2_ (it2) {}
0502 
0503             // Arithmetic
0504             BOOST_UBLAS_INLINE
0505             iterator1 &operator ++ () {
0506                 ++ it1_;
0507                 return *this;
0508             }
0509             BOOST_UBLAS_INLINE
0510             iterator1 &operator -- () {
0511                 -- it1_;
0512                 return *this;
0513             }
0514             BOOST_UBLAS_INLINE
0515             iterator1 &operator += (difference_type n) {
0516                 it1_ += n;
0517                 return *this;
0518             }
0519             BOOST_UBLAS_INLINE
0520             iterator1 &operator -= (difference_type n) {
0521                 it1_ -= n;
0522                 return *this;
0523             }
0524             BOOST_UBLAS_INLINE
0525             difference_type operator - (const iterator1 &it) const {
0526                 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
0527                 BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
0528                 return it1_ - it.it1_;
0529             }
0530 
0531             // Dereference
0532             BOOST_UBLAS_INLINE
0533             reference operator * () const {
0534                 return (*this) () (it1_, it2_);
0535             }
0536             BOOST_UBLAS_INLINE
0537             reference operator [] (difference_type n) const {
0538                 return *(*this + n);
0539             }
0540 
0541 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
0542             BOOST_UBLAS_INLINE
0543 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
0544             typename self_type::
0545 #endif
0546             iterator2 begin () const {
0547                 return (*this) ().find2 (1, it1_, 0);
0548             }
0549             BOOST_UBLAS_INLINE
0550 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
0551             typename self_type::
0552 #endif
0553             iterator2 end () const {
0554                 return (*this) ().find2 (1, it1_, (*this) ().size2 ());
0555             }
0556             BOOST_UBLAS_INLINE
0557 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
0558             typename self_type::
0559 #endif
0560             reverse_iterator2 rbegin () const {
0561                 return reverse_iterator2 (end ());
0562             }
0563             BOOST_UBLAS_INLINE
0564 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
0565             typename self_type::
0566 #endif
0567             reverse_iterator2 rend () const {
0568                 return reverse_iterator2 (begin ());
0569             }
0570 #endif
0571 
0572             // Indices
0573             BOOST_UBLAS_INLINE
0574             size_type index1 () const {
0575                 return it1_;
0576             }
0577             BOOST_UBLAS_INLINE
0578             size_type index2 () const {
0579                 return it2_;
0580             }
0581 
0582             // Assignment
0583             BOOST_UBLAS_INLINE
0584             iterator1 &operator = (const iterator1 &it) {
0585                 container_reference<self_type>::assign (&it ());
0586                 it1_ = it.it1_;
0587                 it2_ = it.it2_;
0588                 return *this;
0589             }
0590 
0591             // Comparison
0592             BOOST_UBLAS_INLINE
0593             bool operator == (const iterator1 &it) const {
0594                 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
0595                 BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
0596                 return it1_ == it.it1_;
0597             }
0598             BOOST_UBLAS_INLINE
0599             bool operator < (const iterator1 &it) const {
0600                 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
0601                 BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
0602                 return it1_ < it.it1_;
0603             }
0604 
0605         private:
0606             size_type it1_;
0607             size_type it2_;
0608 
0609             friend class const_iterator1;
0610         };
0611 #endif
0612 
0613         BOOST_UBLAS_INLINE
0614         iterator1 begin1 () {
0615             return find1 (0, 0, 0);
0616         }
0617         BOOST_UBLAS_INLINE
0618         iterator1 end1 () {
0619             return find1 (0, size_, 0);
0620         }
0621 
0622 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
0623         class const_iterator2:
0624             public container_const_reference<symmetric_matrix>,
0625             public random_access_iterator_base<dense_random_access_iterator_tag,
0626                                                const_iterator2, value_type> {
0627         public:
0628             typedef typename symmetric_matrix::value_type value_type;
0629             typedef typename symmetric_matrix::difference_type difference_type;
0630             typedef typename symmetric_matrix::const_reference reference;
0631             typedef const typename symmetric_matrix::pointer pointer;
0632 
0633             typedef const_iterator1 dual_iterator_type;
0634             typedef const_reverse_iterator1 dual_reverse_iterator_type;
0635 
0636             // Construction and destruction
0637             BOOST_UBLAS_INLINE
0638             const_iterator2 ():
0639                 container_const_reference<self_type> (), it1_ (), it2_ () {}
0640             BOOST_UBLAS_INLINE
0641             const_iterator2 (const self_type &m, size_type it1, size_type it2):
0642                 container_const_reference<self_type> (m), it1_ (it1), it2_ (it2) {}
0643             BOOST_UBLAS_INLINE
0644             const_iterator2 (const iterator2 &it):
0645                 container_const_reference<self_type> (it ()), it1_ (it.it1_), it2_ (it.it2_) {}
0646 
0647             // Arithmetic
0648             BOOST_UBLAS_INLINE
0649             const_iterator2 &operator ++ () {
0650                 ++ it2_;
0651                 return *this;
0652             }
0653             BOOST_UBLAS_INLINE
0654             const_iterator2 &operator -- () {
0655                 -- it2_;
0656                 return *this;
0657             }
0658             BOOST_UBLAS_INLINE
0659             const_iterator2 &operator += (difference_type n) {
0660                 it2_ += n;
0661                 return *this;
0662             }
0663             BOOST_UBLAS_INLINE
0664             const_iterator2 &operator -= (difference_type n) {
0665                 it2_ -= n;
0666                 return *this;
0667             }
0668             BOOST_UBLAS_INLINE
0669             difference_type operator - (const const_iterator2 &it) const {
0670                 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
0671                 BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
0672                 return it2_ - it.it2_;
0673             }
0674 
0675             // Dereference
0676             BOOST_UBLAS_INLINE
0677             const_reference operator * () const {
0678                 return (*this) () (it1_, it2_);
0679             }
0680             BOOST_UBLAS_INLINE
0681             const_reference operator [] (difference_type n) const {
0682                 return *(*this + n);
0683             }
0684 
0685 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
0686             BOOST_UBLAS_INLINE
0687 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
0688             typename self_type::
0689 #endif
0690             const_iterator1 begin () const {
0691                 return (*this) ().find1 (1, 0, it2_);
0692             }
0693             BOOST_UBLAS_INLINE
0694 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
0695             typename self_type::
0696 #endif
0697             const_iterator1 cbegin () const {
0698                 return begin ();
0699             }
0700             BOOST_UBLAS_INLINE
0701 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
0702             typename self_type::
0703 #endif
0704             const_iterator1 end () const {
0705                 return (*this) ().find1 (1, (*this) ().size1 (), it2_);
0706             }
0707             BOOST_UBLAS_INLINE
0708 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
0709             typename self_type::
0710 #endif
0711             const_iterator1 cend () const {
0712                 return end ();
0713             }
0714             BOOST_UBLAS_INLINE
0715 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
0716             typename self_type::
0717 #endif
0718             const_reverse_iterator1 rbegin () const {
0719                 return const_reverse_iterator1 (end ());
0720             }
0721             BOOST_UBLAS_INLINE
0722 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
0723             typename self_type::
0724 #endif
0725             const_reverse_iterator1 crbegin () const {
0726                 return rbegin ();
0727             }
0728             BOOST_UBLAS_INLINE
0729 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
0730             typename self_type::
0731 #endif
0732             const_reverse_iterator1 rend () const {
0733                 return const_reverse_iterator1 (begin ());
0734             }
0735             BOOST_UBLAS_INLINE
0736 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
0737             typename self_type::
0738 #endif
0739             const_reverse_iterator1 crend () const {
0740                 return rend ();
0741             }
0742 #endif
0743 
0744             // Indices
0745             BOOST_UBLAS_INLINE
0746             size_type index1 () const {
0747                 return it1_;
0748             }
0749             BOOST_UBLAS_INLINE
0750             size_type index2 () const {
0751                 return it2_;
0752             }
0753 
0754             // Assignment
0755             BOOST_UBLAS_INLINE
0756             const_iterator2 &operator = (const const_iterator2 &it) {
0757                 container_const_reference<self_type>::assign (&it ());
0758                 it1_ = it.it1_;
0759                 it2_ = it.it2_;
0760                 return *this;
0761             }
0762 
0763             // Comparison
0764             BOOST_UBLAS_INLINE
0765             bool operator == (const const_iterator2 &it) const {
0766                 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
0767                 BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
0768                 return it2_ == it.it2_;
0769             }
0770             BOOST_UBLAS_INLINE
0771             bool operator < (const const_iterator2 &it) const {
0772                 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
0773                 BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
0774                 return it2_ < it.it2_;
0775             }
0776 
0777         private:
0778             size_type it1_;
0779             size_type it2_;
0780         };
0781 #endif
0782 
0783         BOOST_UBLAS_INLINE
0784         const_iterator2 begin2 () const {
0785             return find2 (0, 0, 0);
0786         }
0787         BOOST_UBLAS_INLINE
0788         const_iterator2 cbegin2 () const {
0789             return begin2 ();
0790         }
0791         BOOST_UBLAS_INLINE
0792         const_iterator2 end2 () const {
0793             return find2 (0, 0, size_);
0794         }
0795         BOOST_UBLAS_INLINE
0796         const_iterator2 cend2 () const {
0797             return end2 ();
0798         }
0799 
0800 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
0801         class iterator2:
0802             public container_reference<symmetric_matrix>,
0803             public random_access_iterator_base<packed_random_access_iterator_tag,
0804                                                iterator2, value_type> {
0805         public:
0806             typedef typename symmetric_matrix::value_type value_type;
0807             typedef typename symmetric_matrix::difference_type difference_type;
0808             typedef typename symmetric_matrix::reference reference;
0809             typedef typename symmetric_matrix::pointer pointer;
0810 
0811             typedef iterator1 dual_iterator_type;
0812             typedef reverse_iterator1 dual_reverse_iterator_type;
0813 
0814             // Construction and destruction
0815             BOOST_UBLAS_INLINE
0816             iterator2 ():
0817                 container_reference<self_type> (), it1_ (), it2_ () {}
0818             BOOST_UBLAS_INLINE
0819             iterator2 (self_type &m, size_type it1, size_type it2):
0820                 container_reference<self_type> (m), it1_ (it1), it2_ (it2) {}
0821 
0822             // Arithmetic
0823             BOOST_UBLAS_INLINE
0824             iterator2 &operator ++ () {
0825                 ++ it2_;
0826                 return *this;
0827             }
0828             BOOST_UBLAS_INLINE
0829             iterator2 &operator -- () {
0830                 -- it2_;
0831                 return *this;
0832             }
0833             BOOST_UBLAS_INLINE
0834             iterator2 &operator += (difference_type n) {
0835                 it2_ += n;
0836                 return *this;
0837             }
0838             BOOST_UBLAS_INLINE
0839             iterator2 &operator -= (difference_type n) {
0840                 it2_ -= n;
0841                 return *this;
0842             }
0843             BOOST_UBLAS_INLINE
0844             difference_type operator - (const iterator2 &it) const {
0845                 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
0846                 BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
0847                 return it2_ - it.it2_;
0848             }
0849 
0850             // Dereference
0851             BOOST_UBLAS_INLINE
0852             reference operator * () const {
0853                 return (*this) () (it1_, it2_);
0854             }
0855             BOOST_UBLAS_INLINE
0856             reference operator [] (difference_type n) const {
0857                 return *(*this + n);
0858             }
0859 
0860 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
0861             BOOST_UBLAS_INLINE
0862 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
0863             typename self_type::
0864 #endif
0865             iterator1 begin () const {
0866                 return (*this) ().find1 (1, 0, it2_);
0867             }
0868             BOOST_UBLAS_INLINE
0869 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
0870             typename self_type::
0871 #endif
0872             iterator1 end () const {
0873                 return (*this) ().find1 (1, (*this) ().size1 (), it2_);
0874             }
0875             BOOST_UBLAS_INLINE
0876 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
0877             typename self_type::
0878 #endif
0879             reverse_iterator1 rbegin () const {
0880                 return reverse_iterator1 (end ());
0881             }
0882             BOOST_UBLAS_INLINE
0883 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
0884             typename self_type::
0885 #endif
0886             reverse_iterator1 rend () const {
0887                 return reverse_iterator1 (begin ());
0888             }
0889 #endif
0890 
0891             // Indices
0892             BOOST_UBLAS_INLINE
0893             size_type index1 () const {
0894                 return it1_;
0895             }
0896             BOOST_UBLAS_INLINE
0897             size_type index2 () const {
0898                 return it2_;
0899             }
0900 
0901             // Assignment
0902             BOOST_UBLAS_INLINE
0903             iterator2 &operator = (const iterator2 &it) {
0904                 container_reference<self_type>::assign (&it ());
0905                 it1_ = it.it1_;
0906                 it2_ = it.it2_;
0907                 return *this;
0908             }
0909 
0910             // Comparison
0911             BOOST_UBLAS_INLINE
0912             bool operator == (const iterator2 &it) const {
0913                 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
0914                 BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
0915                 return it2_ == it.it2_;
0916             }
0917             BOOST_UBLAS_INLINE
0918             bool operator < (const iterator2 &it) const {
0919                 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
0920                 BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
0921                 return it2_ < it.it2_;
0922             }
0923 
0924         private:
0925             size_type it1_;
0926             size_type it2_;
0927 
0928             friend class const_iterator2;
0929         };
0930 #endif
0931 
0932         BOOST_UBLAS_INLINE
0933         iterator2 begin2 () {
0934             return find2 (0, 0, 0);
0935         }
0936         BOOST_UBLAS_INLINE
0937         iterator2 end2 () {
0938             return find2 (0, 0, size_);
0939         }
0940 
0941         // Reverse iterators
0942 
0943         BOOST_UBLAS_INLINE
0944         const_reverse_iterator1 rbegin1 () const {
0945             return const_reverse_iterator1 (end1 ());
0946         }
0947         BOOST_UBLAS_INLINE
0948         const_reverse_iterator1 crbegin1 () const {
0949             return rbegin1 ();
0950         }
0951         BOOST_UBLAS_INLINE
0952         const_reverse_iterator1 rend1 () const {
0953             return const_reverse_iterator1 (begin1 ());
0954         }
0955         BOOST_UBLAS_INLINE
0956         const_reverse_iterator1 crend1 () const {
0957             return rend1 ();
0958         }
0959 
0960         BOOST_UBLAS_INLINE
0961         reverse_iterator1 rbegin1 () {
0962             return reverse_iterator1 (end1 ());
0963         }
0964         BOOST_UBLAS_INLINE
0965         reverse_iterator1 rend1 () {
0966             return reverse_iterator1 (begin1 ());
0967         }
0968 
0969         BOOST_UBLAS_INLINE
0970         const_reverse_iterator2 rbegin2 () const {
0971             return const_reverse_iterator2 (end2 ());
0972         }
0973         BOOST_UBLAS_INLINE
0974         const_reverse_iterator2 crbegin2 () const {
0975             return rbegin2 ();
0976         }
0977         BOOST_UBLAS_INLINE
0978         const_reverse_iterator2 rend2 () const {
0979             return const_reverse_iterator2 (begin2 ());
0980         }
0981         BOOST_UBLAS_INLINE
0982         const_reverse_iterator2 crend2 () const {
0983             return rend2 ();
0984         }
0985         BOOST_UBLAS_INLINE
0986         reverse_iterator2 rbegin2 () {
0987             return reverse_iterator2 (end2 ());
0988         }
0989         BOOST_UBLAS_INLINE
0990         reverse_iterator2 rend2 () {
0991             return reverse_iterator2 (begin2 ());
0992         }
0993 
0994     private:
0995         size_type size_;
0996         array_type data_;
0997     };
0998 
0999 
1000     // Symmetric matrix adaptor class
1001     template<class M, class TRI>
1002     class symmetric_adaptor:
1003         public matrix_expression<symmetric_adaptor<M, TRI> > {
1004 
1005         typedef symmetric_adaptor<M, TRI> self_type;
1006     public:
1007 #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
1008         using matrix_expression<self_type>::operator ();
1009 #endif
1010         typedef const M const_matrix_type;
1011         typedef M matrix_type;
1012         typedef TRI triangular_type;
1013         typedef typename M::size_type size_type;
1014         typedef typename M::difference_type difference_type;
1015         typedef typename M::value_type value_type;
1016         typedef typename M::const_reference const_reference;
1017         typedef typename boost::mpl::if_<boost::is_const<M>,
1018                                           typename M::const_reference,
1019                                           typename M::reference>::type reference;
1020         typedef typename boost::mpl::if_<boost::is_const<M>,
1021                                           typename M::const_closure_type,
1022                                           typename M::closure_type>::type matrix_closure_type;
1023         typedef const self_type const_closure_type;
1024         typedef self_type closure_type;
1025         // Replaced by _temporary_traits to avoid type requirements on M
1026         //typedef typename M::vector_temporary_type vector_temporary_type;
1027         //typedef typename M::matrix_temporary_type matrix_temporary_type;
1028         typedef typename storage_restrict_traits<typename M::storage_category,
1029                                                  packed_proxy_tag>::storage_category storage_category;
1030         typedef typename M::orientation_category orientation_category;
1031 
1032         // Construction and destruction
1033         BOOST_UBLAS_INLINE
1034         symmetric_adaptor (matrix_type &data):
1035             matrix_expression<self_type> (),
1036             data_ (data) {
1037             BOOST_UBLAS_CHECK (data_.size1 () == data_.size2 (), bad_size ());
1038         }
1039         BOOST_UBLAS_INLINE
1040         symmetric_adaptor (const symmetric_adaptor &m):
1041             matrix_expression<self_type> (),
1042             data_ (m.data_) {
1043             BOOST_UBLAS_CHECK (data_.size1 () == data_.size2 (), bad_size ());
1044         }
1045 
1046         // Accessors
1047         BOOST_UBLAS_INLINE
1048         size_type size1 () const {
1049             return data_.size1 ();
1050         }
1051         BOOST_UBLAS_INLINE
1052         size_type size2 () const {
1053             return data_.size2 ();
1054         }
1055 
1056         // Storage accessors
1057         BOOST_UBLAS_INLINE
1058         const matrix_closure_type &data () const {
1059             return data_;
1060         }
1061         BOOST_UBLAS_INLINE
1062         matrix_closure_type &data () {
1063             return data_;
1064         }
1065 
1066         // Element access
1067 #ifndef BOOST_UBLAS_PROXY_CONST_MEMBER
1068         BOOST_UBLAS_INLINE
1069         const_reference operator () (size_type i, size_type j) const {
1070             BOOST_UBLAS_CHECK (i < size1 (), bad_index ());
1071             BOOST_UBLAS_CHECK (j < size2 (), bad_index ());
1072             if (triangular_type::other (i, j))
1073                 return data () (i, j);
1074             else
1075                 return data () (j, i);
1076         }
1077         BOOST_UBLAS_INLINE
1078         reference operator () (size_type i, size_type j) {
1079             BOOST_UBLAS_CHECK (i < size1 (), bad_index ());
1080             BOOST_UBLAS_CHECK (j < size2 (), bad_index ());
1081             if (triangular_type::other (i, j))
1082                 return data () (i, j);
1083             else
1084                 return data () (j, i);
1085         }
1086 #else
1087         BOOST_UBLAS_INLINE
1088         reference operator () (size_type i, size_type j) const {
1089             BOOST_UBLAS_CHECK (i < size1 (), bad_index ());
1090             BOOST_UBLAS_CHECK (j < size2 (), bad_index ());
1091             if (triangular_type::other (i, j))
1092                 return data () (i, j);
1093             else
1094                 return data () (j, i);
1095         }
1096 #endif
1097 
1098         // Assignment
1099         BOOST_UBLAS_INLINE
1100         symmetric_adaptor &operator = (const symmetric_adaptor &m) {
1101             matrix_assign<scalar_assign, triangular_type> (*this, m);
1102             return *this;
1103         }
1104         BOOST_UBLAS_INLINE
1105         symmetric_adaptor &assign_temporary (symmetric_adaptor &m) {
1106             *this = m;
1107             return *this;
1108         }
1109         template<class AE>
1110         BOOST_UBLAS_INLINE
1111         symmetric_adaptor &operator = (const matrix_expression<AE> &ae) {
1112             matrix_assign<scalar_assign, triangular_type> (*this, matrix<value_type> (ae));
1113             return *this;
1114         }
1115         template<class AE>
1116         BOOST_UBLAS_INLINE
1117         symmetric_adaptor &assign (const matrix_expression<AE> &ae) {
1118             matrix_assign<scalar_assign, triangular_type> (*this, ae);
1119             return *this;
1120         }
1121         template<class AE>
1122         BOOST_UBLAS_INLINE
1123         symmetric_adaptor& operator += (const matrix_expression<AE> &ae) {
1124             matrix_assign<scalar_assign, triangular_type> (*this, matrix<value_type> (*this + ae));
1125             return *this;
1126         }
1127         template<class AE>
1128         BOOST_UBLAS_INLINE
1129         symmetric_adaptor &plus_assign (const matrix_expression<AE> &ae) {
1130             matrix_assign<scalar_plus_assign, triangular_type> (*this, ae);
1131             return *this;
1132         }
1133         template<class AE>
1134         BOOST_UBLAS_INLINE
1135         symmetric_adaptor& operator -= (const matrix_expression<AE> &ae) {
1136             matrix_assign<scalar_assign, triangular_type> (*this, matrix<value_type> (*this - ae));
1137             return *this;
1138         }
1139         template<class AE>
1140         BOOST_UBLAS_INLINE
1141         symmetric_adaptor &minus_assign (const matrix_expression<AE> &ae) {
1142             matrix_assign<scalar_minus_assign, triangular_type> (*this, ae);
1143             return *this;
1144         }
1145         template<class AT>
1146         BOOST_UBLAS_INLINE
1147         symmetric_adaptor& operator *= (const AT &at) {
1148             matrix_assign_scalar<scalar_multiplies_assign> (*this, at);
1149             return *this;
1150         }
1151         template<class AT>
1152         BOOST_UBLAS_INLINE
1153         symmetric_adaptor& operator /= (const AT &at) {
1154             matrix_assign_scalar<scalar_divides_assign> (*this, at);
1155             return *this;
1156         }
1157 
1158         // Closure comparison
1159         BOOST_UBLAS_INLINE
1160         bool same_closure (const symmetric_adaptor &sa) const {
1161             return (*this).data ().same_closure (sa.data ());
1162        }
1163 
1164         // Swapping
1165         BOOST_UBLAS_INLINE
1166         void swap (symmetric_adaptor &m) {
1167             if (this != &m)
1168                 matrix_swap<scalar_swap, triangular_type> (*this, m);
1169         }
1170         BOOST_UBLAS_INLINE
1171         friend void swap (symmetric_adaptor &m1, symmetric_adaptor &m2) {
1172             m1.swap (m2);
1173         }
1174 
1175         // Iterator types
1176     private:
1177         // Use matrix iterator
1178         typedef typename M::const_iterator1 const_subiterator1_type;
1179         typedef typename boost::mpl::if_<boost::is_const<M>,
1180                                           typename M::const_iterator1,
1181                                           typename M::iterator1>::type subiterator1_type;
1182         typedef typename M::const_iterator2 const_subiterator2_type;
1183         typedef typename boost::mpl::if_<boost::is_const<M>,
1184                                           typename M::const_iterator2,
1185                                           typename M::iterator2>::type subiterator2_type;
1186 
1187     public:
1188 #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
1189         typedef indexed_iterator1<self_type, packed_random_access_iterator_tag> iterator1;
1190         typedef indexed_iterator2<self_type, packed_random_access_iterator_tag> iterator2;
1191         typedef indexed_const_iterator1<self_type, dense_random_access_iterator_tag> const_iterator1;
1192         typedef indexed_const_iterator2<self_type, dense_random_access_iterator_tag> const_iterator2;
1193 #else
1194         class const_iterator1;
1195         class iterator1;
1196         class const_iterator2;
1197         class iterator2;
1198 #endif
1199         typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
1200         typedef reverse_iterator_base1<iterator1> reverse_iterator1;
1201         typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
1202         typedef reverse_iterator_base2<iterator2> reverse_iterator2;
1203 
1204         // Element lookup
1205         BOOST_UBLAS_INLINE
1206         const_iterator1 find1 (int rank, size_type i, size_type j) const {
1207             if (triangular_type::other (i, j)) {
1208                 if (triangular_type::other (size1 (), j)) {
1209                     return const_iterator1 (*this, 0, 0,
1210                                             data ().find1 (rank, i, j), data ().find1 (rank, size1 (), j),
1211                                             data ().find2 (rank, size2 (), size1 ()), data ().find2 (rank, size2 (), size1 ()));
1212                 } else {
1213                     return const_iterator1 (*this, 0, 1,
1214                                             data ().find1 (rank, i, j), data ().find1 (rank, j, j),
1215                                             data ().find2 (rank, j, j), data ().find2 (rank, j, size1 ()));
1216                 }
1217             } else {
1218                 if (triangular_type::other (size1 (), j)) {
1219                     return const_iterator1 (*this, 1, 0,
1220                                             data ().find1 (rank, j, j), data ().find1 (rank, size1 (), j),
1221                                             data ().find2 (rank, j, i), data ().find2 (rank, j, j));
1222                 } else {
1223                     return const_iterator1 (*this, 1, 1,
1224                                             data ().find1 (rank, size1 (), size2 ()), data ().find1 (rank, size1 (), size2 ()),
1225                                             data ().find2 (rank, j, i), data ().find2 (rank, j, size1 ()));
1226                 }
1227             }
1228         }
1229         BOOST_UBLAS_INLINE
1230         iterator1 find1 (int rank, size_type i, size_type j) {
1231             if (rank == 1)
1232                 i = triangular_type::mutable_restrict1 (i, j, size1(), size2());
1233             return iterator1 (*this, data ().find1 (rank, i, j));
1234         }
1235         BOOST_UBLAS_INLINE
1236         const_iterator2 find2 (int rank, size_type i, size_type j) const {
1237             if (triangular_type::other (i, j)) {
1238                 if (triangular_type::other (i, size2 ())) {
1239                     return const_iterator2 (*this, 1, 1,
1240                                             data ().find1 (rank, size2 (), size1 ()), data ().find1 (rank, size2 (), size1 ()),
1241                                             data ().find2 (rank, i, j), data ().find2 (rank, i, size2 ()));
1242                 } else {
1243                     return const_iterator2 (*this, 1, 0,
1244                                             data ().find1 (rank, i, i), data ().find1 (rank, size2 (), i),
1245                                             data ().find2 (rank, i, j), data ().find2 (rank, i, i));
1246                 }
1247             } else {
1248                 if (triangular_type::other (i, size2 ())) {
1249                     return const_iterator2 (*this, 0, 1,
1250                                             data ().find1 (rank, j, i), data ().find1 (rank, i, i),
1251                                             data ().find2 (rank, i, i), data ().find2 (rank, i, size2 ()));
1252                 } else {
1253                     return const_iterator2 (*this, 0, 0,
1254                                             data ().find1 (rank, j, i), data ().find1 (rank, size2 (), i),
1255                                             data ().find2 (rank, size1 (), size2 ()), data ().find2 (rank, size2 (), size2 ()));
1256                 }
1257             }
1258         }
1259         BOOST_UBLAS_INLINE
1260         iterator2 find2 (int rank, size_type i, size_type j) {
1261             if (rank == 1)
1262                 j = triangular_type::mutable_restrict2 (i, j, size1(), size2());
1263             return iterator2 (*this, data ().find2 (rank, i, j));
1264         }
1265 
1266         // Iterators simply are indices.
1267 
1268 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
1269         class const_iterator1:
1270             public container_const_reference<symmetric_adaptor>,
1271             public random_access_iterator_base<typename iterator_restrict_traits<
1272                                                    typename const_subiterator1_type::iterator_category, dense_random_access_iterator_tag>::iterator_category,
1273                                                const_iterator1, value_type> {
1274         public:
1275             typedef typename const_subiterator1_type::value_type value_type;
1276             typedef typename const_subiterator1_type::difference_type difference_type;
1277             typedef typename const_subiterator1_type::reference reference;
1278             typedef typename const_subiterator1_type::pointer pointer;
1279 
1280             typedef const_iterator2 dual_iterator_type;
1281             typedef const_reverse_iterator2 dual_reverse_iterator_type;
1282 
1283             // Construction and destruction
1284             BOOST_UBLAS_INLINE
1285             const_iterator1 ():
1286                 container_const_reference<self_type> (),
1287                 begin_ (-1), end_ (-1), current_ (-1),
1288                 it1_begin_ (), it1_end_ (), it1_ (),
1289                 it2_begin_ (), it2_end_ (), it2_ () {}
1290             BOOST_UBLAS_INLINE
1291             const_iterator1 (const self_type &m, int begin, int end,
1292                              const const_subiterator1_type &it1_begin, const const_subiterator1_type &it1_end,
1293                              const const_subiterator2_type &it2_begin, const const_subiterator2_type &it2_end):
1294                 container_const_reference<self_type> (m),
1295                 begin_ (begin), end_ (end), current_ (begin),
1296                 it1_begin_ (it1_begin), it1_end_ (it1_end), it1_ (it1_begin_),
1297                 it2_begin_ (it2_begin), it2_end_ (it2_end), it2_ (it2_begin_) {
1298                 if (current_ == 0 && it1_ == it1_end_)
1299                     current_ = 1;
1300                 if (current_ == 1 && it2_ == it2_end_)
1301                     current_ = 0;
1302                 if ((current_ == 0 && it1_ == it1_end_) ||
1303                     (current_ == 1 && it2_ == it2_end_))
1304                     current_ = end_;
1305                 BOOST_UBLAS_CHECK (current_ == end_ ||
1306                                    (current_ == 0 && it1_ != it1_end_) ||
1307                                    (current_ == 1 && it2_ != it2_end_), internal_logic ());
1308             }
1309             // FIXME cannot compile
1310             //  iterator1 does not have these members!
1311             BOOST_UBLAS_INLINE
1312             const_iterator1 (const iterator1 &it):
1313                 container_const_reference<self_type> (it ()),
1314                 begin_ (it.begin_), end_ (it.end_), current_ (it.current_),
1315                 it1_begin_ (it.it1_begin_), it1_end_ (it.it1_end_), it1_ (it.it1_),
1316                 it2_begin_ (it.it2_begin_), it2_end_ (it.it2_end_), it2_ (it.it2_) {
1317                 BOOST_UBLAS_CHECK (current_ == end_ ||
1318                                    (current_ == 0 && it1_ != it1_end_) ||
1319                                    (current_ == 1 && it2_ != it2_end_), internal_logic ());
1320             }
1321 
1322             // Arithmetic
1323             BOOST_UBLAS_INLINE
1324             const_iterator1 &operator ++ () {
1325                 BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
1326                 if (current_ == 0) {
1327                     BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ());
1328                     ++ it1_;
1329                     if (it1_ == it1_end_ && end_ == 1) {
1330                         it2_ = it2_begin_;
1331                         current_ = 1;
1332                     }
1333                 } else /* if (current_ == 1) */ {
1334                     BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ());
1335                     ++ it2_;
1336                     if (it2_ == it2_end_ && end_ == 0) {
1337                         it1_ = it1_begin_;
1338                         current_ = 0;
1339                     }
1340                 }
1341                 return *this;
1342             }
1343             BOOST_UBLAS_INLINE
1344             const_iterator1 &operator -- () {
1345                 BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
1346                 if (current_ == 0) {
1347                     if (it1_ == it1_begin_ && begin_ == 1) {
1348                         it2_ = it2_end_;
1349                         BOOST_UBLAS_CHECK (it2_ != it2_begin_, internal_logic ());
1350                         -- it2_;
1351                         current_ = 1;
1352                     } else {
1353                         -- it1_;
1354                     }
1355                 } else /* if (current_ == 1) */ {
1356                     if (it2_ == it2_begin_ && begin_ == 0) {
1357                         it1_ = it1_end_;
1358                         BOOST_UBLAS_CHECK (it1_ != it1_begin_, internal_logic ());
1359                         -- it1_;
1360                         current_ = 0;
1361                     } else {
1362                         -- it2_;
1363                     }
1364                 }
1365                 return *this;
1366             }
1367             BOOST_UBLAS_INLINE
1368             const_iterator1 &operator += (difference_type n) {
1369                 BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
1370                 if (current_ == 0) {
1371                     size_type d = (std::min) (n, it1_end_ - it1_);
1372                     it1_ += d;
1373                     n -= d;
1374                     if (n > 0 || (end_ == 1 && it1_ == it1_end_)) {
1375                         BOOST_UBLAS_CHECK (end_ == 1, external_logic ());
1376                         d = (std::min) (n, it2_end_ - it2_begin_);
1377                         it2_ = it2_begin_ + d;
1378                         n -= d;
1379                         current_ = 1;
1380                     }
1381                 } else /* if (current_ == 1) */ {
1382                     size_type d = (std::min) (n, it2_end_ - it2_);
1383                     it2_ += d;
1384                     n -= d;
1385                     if (n > 0 || (end_ == 0 && it2_ == it2_end_)) {
1386                         BOOST_UBLAS_CHECK (end_ == 0, external_logic ());
1387                         d = (std::min) (n, it1_end_ - it1_begin_);
1388                         it1_ = it1_begin_ + d;
1389                         n -= d;
1390                         current_ = 0;
1391                     }
1392                 }
1393                 BOOST_UBLAS_CHECK (n == 0, external_logic ());
1394                 return *this;
1395             }
1396             BOOST_UBLAS_INLINE
1397             const_iterator1 &operator -= (difference_type n) {
1398                 BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
1399                 if (current_ == 0) {
1400                     size_type d = (std::min) (n, it1_ - it1_begin_);
1401                     it1_ -= d;
1402                     n -= d;
1403                     if (n > 0) {
1404                         BOOST_UBLAS_CHECK (end_ == 1, external_logic ());
1405                         d = (std::min) (n, it2_end_ - it2_begin_);
1406                         it2_ = it2_end_ - d;
1407                         n -= d;
1408                         current_ = 1;
1409                     }
1410                 } else /* if (current_ == 1) */ {
1411                     size_type d = (std::min) (n, it2_ - it2_begin_);
1412                     it2_ -= d;
1413                     n -= d;
1414                     if (n > 0) {
1415                         BOOST_UBLAS_CHECK (end_ == 0, external_logic ());
1416                         d = (std::min) (n, it1_end_ - it1_begin_);
1417                         it1_ = it1_end_ - d;
1418                         n -= d;
1419                         current_ = 0;
1420                     }
1421                 }
1422                 BOOST_UBLAS_CHECK (n == 0, external_logic ());
1423                 return *this;
1424             }
1425             BOOST_UBLAS_INLINE
1426             difference_type operator - (const const_iterator1 &it) const {
1427                 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1428                 BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
1429                 BOOST_UBLAS_CHECK (it.current_ == 0 || it.current_ == 1, internal_logic ());
1430                 BOOST_UBLAS_CHECK (/* begin_ == it.begin_ && */ end_ == it.end_, internal_logic ());
1431                 if (current_ == 0 && it.current_ == 0) {
1432                     return it1_ - it.it1_;
1433                 } else if (current_ == 0 && it.current_ == 1) {
1434                     if (end_ == 1 && it.end_ == 1) {
1435                         return (it1_ - it.it1_end_) + (it.it2_begin_ - it.it2_);
1436                     } else /* if (end_ == 0 && it.end_ == 0) */ {
1437                         return (it1_ - it.it1_begin_) + (it.it2_end_ - it.it2_);
1438                     }
1439 
1440                 } else if (current_ == 1 && it.current_ == 0) {
1441                     if (end_ == 1 && it.end_ == 1) {
1442                         return (it2_ - it.it2_begin_) + (it.it1_end_ - it.it1_);
1443                     } else /* if (end_ == 0 && it.end_ == 0) */ {
1444                         return (it2_ - it.it2_end_) + (it.it1_begin_ - it.it1_);
1445                     }
1446                 }
1447                 /* current_ == 1 && it.current_ == 1 */ {
1448                     return it2_ - it.it2_;
1449                 }
1450             }
1451 
1452             // Dereference
1453             BOOST_UBLAS_INLINE
1454             const_reference operator * () const {
1455                 BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
1456                 if (current_ == 0) {
1457                     BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ());
1458                     return *it1_;
1459                 } else /* if (current_ == 1) */ {
1460                     BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ());
1461                     return *it2_;
1462                 }
1463             }
1464             BOOST_UBLAS_INLINE
1465             const_reference operator [] (difference_type n) const {
1466                 return *(*this + n);
1467             }
1468 
1469 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
1470             BOOST_UBLAS_INLINE
1471 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1472             typename self_type::
1473 #endif
1474             const_iterator2 begin () const {
1475                 return (*this) ().find2 (1, index1 (), 0);
1476             }
1477             BOOST_UBLAS_INLINE
1478 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1479             typename self_type::
1480 #endif
1481             const_iterator2 cbegin () const {
1482                 return begin ();
1483             }
1484             BOOST_UBLAS_INLINE
1485 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1486             typename self_type::
1487 #endif
1488             const_iterator2 end () const {
1489                 return (*this) ().find2 (1, index1 (), (*this) ().size2 ());
1490             }
1491             BOOST_UBLAS_INLINE
1492 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1493             typename self_type::
1494 #endif
1495             const_iterator2 cend () const {
1496                 return end ();
1497             }
1498             BOOST_UBLAS_INLINE
1499 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1500             typename self_type::
1501 #endif
1502             const_reverse_iterator2 rbegin () const {
1503                 return const_reverse_iterator2 (end ());
1504             }
1505             BOOST_UBLAS_INLINE
1506 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1507             typename self_type::
1508 #endif
1509             const_reverse_iterator2 crbegin () const {
1510                 return rbegin ();
1511             }
1512             BOOST_UBLAS_INLINE
1513 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1514             typename self_type::
1515 #endif
1516             const_reverse_iterator2 rend () const {
1517                 return const_reverse_iterator2 (begin ());
1518             }
1519             BOOST_UBLAS_INLINE
1520 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1521             typename self_type::
1522 #endif
1523             const_reverse_iterator2 crend () const {
1524                 return rend ();
1525             }
1526 #endif
1527 
1528             // Indices
1529             BOOST_UBLAS_INLINE
1530             size_type index1 () const {
1531                 BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
1532                 if (current_ == 0) {
1533                     BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ());
1534                     return it1_.index1 ();
1535                 } else /* if (current_ == 1) */ {
1536                     BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ());
1537                     return it2_.index2 ();
1538                 }
1539             }
1540             BOOST_UBLAS_INLINE
1541             size_type index2 () const {
1542                 BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
1543                 if (current_ == 0) {
1544                     BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ());
1545                     return it1_.index2 ();
1546                 } else /* if (current_ == 1) */ {
1547                     BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ());
1548                     return it2_.index1 ();
1549                 }
1550             }
1551 
1552             // Assignment
1553             BOOST_UBLAS_INLINE
1554             const_iterator1 &operator = (const const_iterator1 &it) {
1555                 container_const_reference<self_type>::assign (&it ());
1556                 begin_ = it.begin_;
1557                 end_ = it.end_;
1558                 current_ = it.current_;
1559                 it1_begin_ = it.it1_begin_;
1560                 it1_end_ = it.it1_end_;
1561                 it1_ = it.it1_;
1562                 it2_begin_ = it.it2_begin_;
1563                 it2_end_ = it.it2_end_;
1564                 it2_ = it.it2_;
1565                 return *this;
1566             }
1567 
1568             // Comparison
1569             BOOST_UBLAS_INLINE
1570             bool operator == (const const_iterator1 &it) const {
1571                 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1572                 BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
1573                 BOOST_UBLAS_CHECK (it.current_ == 0 || it.current_ == 1, internal_logic ());
1574                 BOOST_UBLAS_CHECK (/* begin_ == it.begin_ && */ end_ == it.end_, internal_logic ());
1575                 return (current_ == 0 && it.current_ == 0 && it1_ == it.it1_) ||
1576                        (current_ == 1 && it.current_ == 1 && it2_ == it.it2_);
1577             }
1578             BOOST_UBLAS_INLINE
1579             bool operator < (const const_iterator1 &it) const {
1580                 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1581                 return it - *this > 0;
1582             }
1583 
1584         private:
1585             int begin_;
1586             int end_;
1587             int current_;
1588             const_subiterator1_type it1_begin_;
1589             const_subiterator1_type it1_end_;
1590             const_subiterator1_type it1_;
1591             const_subiterator2_type it2_begin_;
1592             const_subiterator2_type it2_end_;
1593             const_subiterator2_type it2_;
1594         };
1595 #endif
1596 
1597         BOOST_UBLAS_INLINE
1598         const_iterator1 begin1 () const {
1599             return find1 (0, 0, 0);
1600         }
1601         BOOST_UBLAS_INLINE
1602         const_iterator1 cbegin1 () const {
1603             return begin1 ();
1604         }
1605         BOOST_UBLAS_INLINE
1606         const_iterator1 end1 () const {
1607             return find1 (0, size1 (), 0);
1608         }
1609         BOOST_UBLAS_INLINE
1610         const_iterator1 cend1 () const {
1611             return end1 ();
1612         }
1613 
1614 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
1615         class iterator1:
1616             public container_reference<symmetric_adaptor>,
1617             public random_access_iterator_base<typename iterator_restrict_traits<
1618                                                    typename subiterator1_type::iterator_category, packed_random_access_iterator_tag>::iterator_category,
1619                                                iterator1, value_type> {
1620         public:
1621             typedef typename subiterator1_type::value_type value_type;
1622             typedef typename subiterator1_type::difference_type difference_type;
1623             typedef typename subiterator1_type::reference reference;
1624             typedef typename subiterator1_type::pointer pointer;
1625 
1626             typedef iterator2 dual_iterator_type;
1627             typedef reverse_iterator2 dual_reverse_iterator_type;
1628 
1629             // Construction and destruction
1630             BOOST_UBLAS_INLINE
1631             iterator1 ():
1632                 container_reference<self_type> (), it1_ () {}
1633             BOOST_UBLAS_INLINE
1634             iterator1 (self_type &m, const subiterator1_type &it1):
1635                 container_reference<self_type> (m), it1_ (it1) {}
1636 
1637             // Arithmetic
1638             BOOST_UBLAS_INLINE
1639             iterator1 &operator ++ () {
1640                 ++ it1_;
1641                 return *this;
1642             }
1643             BOOST_UBLAS_INLINE
1644             iterator1 &operator -- () {
1645                 -- it1_;
1646                 return *this;
1647             }
1648             BOOST_UBLAS_INLINE
1649             iterator1 &operator += (difference_type n) {
1650                 it1_ += n;
1651                 return *this;
1652             }
1653             BOOST_UBLAS_INLINE
1654             iterator1 &operator -= (difference_type n) {
1655                 it1_ -= n;
1656                 return *this;
1657             }
1658             BOOST_UBLAS_INLINE
1659             difference_type operator - (const iterator1 &it) const {
1660                 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1661                 return it1_ - it.it1_;
1662             }
1663 
1664             // Dereference
1665             BOOST_UBLAS_INLINE
1666             reference operator * () const {
1667                 return *it1_;
1668             }
1669             BOOST_UBLAS_INLINE
1670             reference operator [] (difference_type n) const {
1671                 return *(*this + n);
1672             }
1673 
1674 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
1675             BOOST_UBLAS_INLINE
1676 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1677             typename self_type::
1678 #endif
1679             iterator2 begin () const {
1680                 return (*this) ().find2 (1, index1 (), 0);
1681             }
1682             BOOST_UBLAS_INLINE
1683 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1684             typename self_type::
1685 #endif
1686             iterator2 end () const {
1687                 return (*this) ().find2 (1, index1 (), (*this) ().size2 ());
1688             }
1689             BOOST_UBLAS_INLINE
1690 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1691             typename self_type::
1692 #endif
1693             reverse_iterator2 rbegin () const {
1694                 return reverse_iterator2 (end ());
1695             }
1696             BOOST_UBLAS_INLINE
1697 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1698             typename self_type::
1699 #endif
1700             reverse_iterator2 rend () const {
1701                 return reverse_iterator2 (begin ());
1702             }
1703 #endif
1704 
1705             // Indices
1706             BOOST_UBLAS_INLINE
1707             size_type index1 () const {
1708                 return it1_.index1 ();
1709             }
1710             BOOST_UBLAS_INLINE
1711             size_type index2 () const {
1712                 return it1_.index2 ();
1713             }
1714 
1715             // Assignment
1716             BOOST_UBLAS_INLINE
1717             iterator1 &operator = (const iterator1 &it) {
1718                 container_reference<self_type>::assign (&it ());
1719                 it1_ = it.it1_;
1720                 return *this;
1721             }
1722 
1723             // Comparison
1724             BOOST_UBLAS_INLINE
1725             bool operator == (const iterator1 &it) const {
1726                 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1727                 return it1_ == it.it1_;
1728             }
1729             BOOST_UBLAS_INLINE
1730             bool operator < (const iterator1 &it) const {
1731                 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1732                 return it1_ < it.it1_;
1733             }
1734 
1735         private:
1736             subiterator1_type it1_;
1737 
1738             friend class const_iterator1;
1739         };
1740 #endif
1741 
1742         BOOST_UBLAS_INLINE
1743         iterator1 begin1 () {
1744             return find1 (0, 0, 0);
1745         }
1746         BOOST_UBLAS_INLINE
1747         iterator1 end1 () {
1748             return find1 (0, size1 (), 0);
1749         }
1750 
1751 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
1752         class const_iterator2:
1753             public container_const_reference<symmetric_adaptor>,
1754             public random_access_iterator_base<typename iterator_restrict_traits<
1755                                                    typename const_subiterator2_type::iterator_category, dense_random_access_iterator_tag>::iterator_category,
1756                                                const_iterator2, value_type> {
1757         public:
1758             typedef typename const_subiterator2_type::value_type value_type;
1759             typedef typename const_subiterator2_type::difference_type difference_type;
1760             typedef typename const_subiterator2_type::reference reference;
1761             typedef typename const_subiterator2_type::pointer pointer;
1762 
1763             typedef const_iterator1 dual_iterator_type;
1764             typedef const_reverse_iterator1 dual_reverse_iterator_type;
1765 
1766             // Construction and destruction
1767             BOOST_UBLAS_INLINE
1768             const_iterator2 ():
1769                 container_const_reference<self_type> (),
1770                 begin_ (-1), end_ (-1), current_ (-1),
1771                 it1_begin_ (), it1_end_ (), it1_ (),
1772                 it2_begin_ (), it2_end_ (), it2_ () {}
1773             BOOST_UBLAS_INLINE
1774             const_iterator2 (const self_type &m, int begin, int end,
1775                              const const_subiterator1_type &it1_begin, const const_subiterator1_type &it1_end,
1776                              const const_subiterator2_type &it2_begin, const const_subiterator2_type &it2_end):
1777                 container_const_reference<self_type> (m),
1778                 begin_ (begin), end_ (end), current_ (begin),
1779                 it1_begin_ (it1_begin), it1_end_ (it1_end), it1_ (it1_begin_),
1780                 it2_begin_ (it2_begin), it2_end_ (it2_end), it2_ (it2_begin_) {
1781                 if (current_ == 0 && it1_ == it1_end_)
1782                     current_ = 1;
1783                 if (current_ == 1 && it2_ == it2_end_)
1784                     current_ = 0;
1785                 if ((current_ == 0 && it1_ == it1_end_) ||
1786                     (current_ == 1 && it2_ == it2_end_))
1787                     current_ = end_;
1788                 BOOST_UBLAS_CHECK (current_ == end_ ||
1789                                    (current_ == 0 && it1_ != it1_end_) ||
1790                                    (current_ == 1 && it2_ != it2_end_), internal_logic ());
1791             }
1792             // FIXME cannot compiler
1793             //  iterator2 does not have these members!
1794             BOOST_UBLAS_INLINE
1795             const_iterator2 (const iterator2 &it):
1796                 container_const_reference<self_type> (it ()),
1797                 begin_ (it.begin_), end_ (it.end_), current_ (it.current_),
1798                 it1_begin_ (it.it1_begin_), it1_end_ (it.it1_end_), it1_ (it.it1_),
1799                 it2_begin_ (it.it2_begin_), it2_end_ (it.it2_end_), it2_ (it.it2_) {
1800                 BOOST_UBLAS_CHECK (current_ == end_ ||
1801                                    (current_ == 0 && it1_ != it1_end_) ||
1802                                    (current_ == 1 && it2_ != it2_end_), internal_logic ());
1803             }
1804 
1805             // Arithmetic
1806             BOOST_UBLAS_INLINE
1807             const_iterator2 &operator ++ () {
1808                 BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
1809                 if (current_ == 0) {
1810                     BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ());
1811                     ++ it1_;
1812                     if (it1_ == it1_end_ && end_ == 1) {
1813                         it2_ = it2_begin_;
1814                         current_ = 1;
1815                     }
1816                 } else /* if (current_ == 1) */ {
1817                     BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ());
1818                     ++ it2_;
1819                     if (it2_ == it2_end_ && end_ == 0) {
1820                         it1_ = it1_begin_;
1821                         current_ = 0;
1822                     }
1823                 }
1824                 return *this;
1825             }
1826             BOOST_UBLAS_INLINE
1827             const_iterator2 &operator -- () {
1828                 BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
1829                 if (current_ == 0) {
1830                     if (it1_ == it1_begin_ && begin_ == 1) {
1831                         it2_ = it2_end_;
1832                         BOOST_UBLAS_CHECK (it2_ != it2_begin_, internal_logic ());
1833                         -- it2_;
1834                         current_ = 1;
1835                     } else {
1836                         -- it1_;
1837                     }
1838                 } else /* if (current_ == 1) */ {
1839                     if (it2_ == it2_begin_ && begin_ == 0) {
1840                         it1_ = it1_end_;
1841                         BOOST_UBLAS_CHECK (it1_ != it1_begin_, internal_logic ());
1842                         -- it1_;
1843                         current_ = 0;
1844                     } else {
1845                         -- it2_;
1846                     }
1847                 }
1848                 return *this;
1849             }
1850             BOOST_UBLAS_INLINE
1851             const_iterator2 &operator += (difference_type n) {
1852                 BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
1853                 if (current_ == 0) {
1854                     size_type d = (std::min) (n, it1_end_ - it1_);
1855                     it1_ += d;
1856                     n -= d;
1857                     if (n > 0 || (end_ == 1 && it1_ == it1_end_)) {
1858                         BOOST_UBLAS_CHECK (end_ == 1, external_logic ());
1859                         d = (std::min) (n, it2_end_ - it2_begin_);
1860                         it2_ = it2_begin_ + d;
1861                         n -= d;
1862                         current_ = 1;
1863                     }
1864                 } else /* if (current_ == 1) */ {
1865                     size_type d = (std::min) (n, it2_end_ - it2_);
1866                     it2_ += d;
1867                     n -= d;
1868                     if (n > 0 || (end_ == 0 && it2_ == it2_end_)) {
1869                         BOOST_UBLAS_CHECK (end_ == 0, external_logic ());
1870                         d = (std::min) (n, it1_end_ - it1_begin_);
1871                         it1_ = it1_begin_ + d;
1872                         n -= d;
1873                         current_ = 0;
1874                     }
1875                 }
1876                 BOOST_UBLAS_CHECK (n == 0, external_logic ());
1877                 return *this;
1878             }
1879             BOOST_UBLAS_INLINE
1880             const_iterator2 &operator -= (difference_type n) {
1881                 BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
1882                 if (current_ == 0) {
1883                     size_type d = (std::min) (n, it1_ - it1_begin_);
1884                     it1_ -= d;
1885                     n -= d;
1886                     if (n > 0) {
1887                         BOOST_UBLAS_CHECK (end_ == 1, external_logic ());
1888                         d = (std::min) (n, it2_end_ - it2_begin_);
1889                         it2_ = it2_end_ - d;
1890                         n -= d;
1891                         current_ = 1;
1892                     }
1893                 } else /* if (current_ == 1) */ {
1894                     size_type d = (std::min) (n, it2_ - it2_begin_);
1895                     it2_ -= d;
1896                     n -= d;
1897                     if (n > 0) {
1898                         BOOST_UBLAS_CHECK (end_ == 0, external_logic ());
1899                         d = (std::min) (n, it1_end_ - it1_begin_);
1900                         it1_ = it1_end_ - d;
1901                         n -= d;
1902                         current_ = 0;
1903                     }
1904                 }
1905                 BOOST_UBLAS_CHECK (n == 0, external_logic ());
1906                 return *this;
1907             }
1908             BOOST_UBLAS_INLINE
1909             difference_type operator - (const const_iterator2 &it) const {
1910                 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1911                 BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
1912                 BOOST_UBLAS_CHECK (it.current_ == 0 || it.current_ == 1, internal_logic ());
1913                 BOOST_UBLAS_CHECK (/* begin_ == it.begin_ && */ end_ == it.end_, internal_logic ());
1914                 if (current_ == 0 && it.current_ == 0) {
1915                     return it1_ - it.it1_;
1916                 } else if (current_ == 0 && it.current_ == 1) {
1917                     if (end_ == 1 && it.end_ == 1) {
1918                         return (it1_ - it.it1_end_) + (it.it2_begin_ - it.it2_);
1919                     } else /* if (end_ == 0 && it.end_ == 0) */ {
1920                         return (it1_ - it.it1_begin_) + (it.it2_end_ - it.it2_);
1921                     }
1922 
1923                 } else if (current_ == 1 && it.current_ == 0) {
1924                     if (end_ == 1 && it.end_ == 1) {
1925                         return (it2_ - it.it2_begin_) + (it.it1_end_ - it.it1_);
1926                     } else /* if (end_ == 0 && it.end_ == 0) */ {
1927                         return (it2_ - it.it2_end_) + (it.it1_begin_ - it.it1_);
1928                     }
1929                 }
1930                 /* current_ == 1 && it.current_ == 1 */ {
1931                     return it2_ - it.it2_;
1932                 }
1933             }
1934 
1935             // Dereference
1936             BOOST_UBLAS_INLINE
1937             const_reference operator * () const {
1938                 BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
1939                 if (current_ == 0) {
1940                     BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ());
1941                     return *it1_;
1942                 } else /* if (current_ == 1) */ {
1943                     BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ());
1944                     return *it2_;
1945                 }
1946             }
1947             BOOST_UBLAS_INLINE
1948             const_reference operator [] (difference_type n) const {
1949                 return *(*this + n);
1950             }
1951 
1952 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
1953             BOOST_UBLAS_INLINE
1954 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1955             typename self_type::
1956 #endif
1957             const_iterator1 begin () const {
1958                 return (*this) ().find1 (1, 0, index2 ());
1959             }
1960             BOOST_UBLAS_INLINE
1961 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1962             typename self_type::
1963 #endif
1964             const_iterator1 cbegin () const {
1965                 return begin ();
1966             }
1967             BOOST_UBLAS_INLINE
1968 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1969             typename self_type::
1970 #endif
1971             const_iterator1 end () const {
1972                 return (*this) ().find1 (1, (*this) ().size1 (), index2 ());
1973             }
1974             BOOST_UBLAS_INLINE
1975 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1976             typename self_type::
1977 #endif
1978             const_iterator1 cend () const {
1979                 return end ();
1980             }
1981             BOOST_UBLAS_INLINE
1982 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1983             typename self_type::
1984 #endif
1985             const_reverse_iterator1 rbegin () const {
1986                 return const_reverse_iterator1 (end ());
1987             }
1988             BOOST_UBLAS_INLINE
1989 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1990             typename self_type::
1991 #endif
1992             const_reverse_iterator1 crbegin () const {
1993                 return rbegin ();
1994             }
1995             BOOST_UBLAS_INLINE
1996 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1997             typename self_type::
1998 #endif
1999             const_reverse_iterator1 rend () const {
2000                 return const_reverse_iterator1 (begin ());
2001             }
2002             BOOST_UBLAS_INLINE
2003 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
2004             typename self_type::
2005 #endif
2006             const_reverse_iterator1 crend () const {
2007                 return rend ();
2008             }
2009 #endif
2010 
2011             // Indices
2012             BOOST_UBLAS_INLINE
2013             size_type index1 () const {
2014                 BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
2015                 if (current_ == 0) {
2016                     BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ());
2017                     return it1_.index2 ();
2018                 } else /* if (current_ == 1) */ {
2019                     BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ());
2020                     return it2_.index1 ();
2021                 }
2022             }
2023             BOOST_UBLAS_INLINE
2024             size_type index2 () const {
2025                 BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
2026                 if (current_ == 0) {
2027                     BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ());
2028                     return it1_.index1 ();
2029                 } else /* if (current_ == 1) */ {
2030                     BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ());
2031                     return it2_.index2 ();
2032                 }
2033             }
2034 
2035             // Assignment
2036             BOOST_UBLAS_INLINE
2037             const_iterator2 &operator = (const const_iterator2 &it) {
2038                 container_const_reference<self_type>::assign (&it ());
2039                 begin_ = it.begin_;
2040                 end_ = it.end_;
2041                 current_ = it.current_;
2042                 it1_begin_ = it.it1_begin_;
2043                 it1_end_ = it.it1_end_;
2044                 it1_ = it.it1_;
2045                 it2_begin_ = it.it2_begin_;
2046                 it2_end_ = it.it2_end_;
2047                 it2_ = it.it2_;
2048                 return *this;
2049             }
2050 
2051             // Comparison
2052             BOOST_UBLAS_INLINE
2053             bool operator == (const const_iterator2 &it) const {
2054                 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
2055                 BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
2056                 BOOST_UBLAS_CHECK (it.current_ == 0 || it.current_ == 1, internal_logic ());
2057                 BOOST_UBLAS_CHECK (/* begin_ == it.begin_ && */ end_ == it.end_, internal_logic ());
2058                 return (current_ == 0 && it.current_ == 0 && it1_ == it.it1_) ||
2059                        (current_ == 1 && it.current_ == 1 && it2_ == it.it2_);
2060             }
2061             BOOST_UBLAS_INLINE
2062             bool operator < (const const_iterator2 &it) const {
2063                 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
2064                 return it - *this > 0;
2065             }
2066 
2067         private:
2068             int begin_;
2069             int end_;
2070             int current_;
2071             const_subiterator1_type it1_begin_;
2072             const_subiterator1_type it1_end_;
2073             const_subiterator1_type it1_;
2074             const_subiterator2_type it2_begin_;
2075             const_subiterator2_type it2_end_;
2076             const_subiterator2_type it2_;
2077         };
2078 #endif
2079 
2080         BOOST_UBLAS_INLINE
2081         const_iterator2 begin2 () const {
2082             return find2 (0, 0, 0);
2083         }
2084         BOOST_UBLAS_INLINE
2085         const_iterator2 cbegin2 () const {
2086             return begin2 ();
2087         }
2088         BOOST_UBLAS_INLINE
2089         const_iterator2 end2 () const {
2090             return find2 (0, 0, size2 ());
2091         }
2092         BOOST_UBLAS_INLINE
2093         const_iterator2 cend2 () const {
2094             return end2 ();
2095         }
2096 
2097 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
2098         class iterator2:
2099             public container_reference<symmetric_adaptor>,
2100             public random_access_iterator_base<typename iterator_restrict_traits<
2101                                                    typename subiterator2_type::iterator_category, packed_random_access_iterator_tag>::iterator_category,
2102                                                iterator2, value_type> {
2103         public:
2104             typedef typename subiterator2_type::value_type value_type;
2105             typedef typename subiterator2_type::difference_type difference_type;
2106             typedef typename subiterator2_type::reference reference;
2107             typedef typename subiterator2_type::pointer pointer;
2108 
2109             typedef iterator1 dual_iterator_type;
2110             typedef reverse_iterator1 dual_reverse_iterator_type;
2111 
2112             // Construction and destruction
2113             BOOST_UBLAS_INLINE
2114             iterator2 ():
2115                 container_reference<self_type> (), it2_ () {}
2116             BOOST_UBLAS_INLINE
2117             iterator2 (self_type &m, const subiterator2_type &it2):
2118                 container_reference<self_type> (m), it2_ (it2) {}
2119 
2120             // Arithmetic
2121             BOOST_UBLAS_INLINE
2122             iterator2 &operator ++ () {
2123                 ++ it2_;
2124                 return *this;
2125             }
2126             BOOST_UBLAS_INLINE
2127             iterator2 &operator -- () {
2128                 -- it2_;
2129                 return *this;
2130             }
2131             BOOST_UBLAS_INLINE
2132             iterator2 &operator += (difference_type n) {
2133                 it2_ += n;
2134                 return *this;
2135             }
2136             BOOST_UBLAS_INLINE
2137             iterator2 &operator -= (difference_type n) {
2138                 it2_ -= n;
2139                 return *this;
2140             }
2141             BOOST_UBLAS_INLINE
2142             difference_type operator - (const iterator2 &it) const {
2143                 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
2144                 return it2_ - it.it2_;
2145             }
2146 
2147             // Dereference
2148             BOOST_UBLAS_INLINE
2149             reference operator * () const {
2150                 return *it2_;
2151             }
2152             BOOST_UBLAS_INLINE
2153             reference operator [] (difference_type n) const {
2154                 return *(*this + n);
2155             }
2156 
2157 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
2158             BOOST_UBLAS_INLINE
2159 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
2160             typename self_type::
2161 #endif
2162             iterator1 begin () const {
2163                 return (*this) ().find1 (1, 0, index2 ());
2164             }
2165             BOOST_UBLAS_INLINE
2166 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
2167             typename self_type::
2168 #endif
2169             iterator1 end () const {
2170                 return (*this) ().find1 (1, (*this) ().size1 (), index2 ());
2171             }
2172             BOOST_UBLAS_INLINE
2173 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
2174             typename self_type::
2175 #endif
2176             reverse_iterator1 rbegin () const {
2177                 return reverse_iterator1 (end ());
2178             }
2179             BOOST_UBLAS_INLINE
2180 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
2181             typename self_type::
2182 #endif
2183             reverse_iterator1 rend () const {
2184                 return reverse_iterator1 (begin ());
2185             }
2186 #endif
2187 
2188             // Indices
2189             BOOST_UBLAS_INLINE
2190             size_type index1 () const {
2191                 return it2_.index1 ();
2192             }
2193             BOOST_UBLAS_INLINE
2194             size_type index2 () const {
2195                 return it2_.index2 ();
2196             }
2197 
2198             // Assignment
2199             BOOST_UBLAS_INLINE
2200             iterator2 &operator = (const iterator2 &it) {
2201                 container_reference<self_type>::assign (&it ());
2202                 it2_ = it.it2_;
2203                 return *this;
2204             }
2205 
2206             // Comparison
2207             BOOST_UBLAS_INLINE
2208             bool operator == (const iterator2 &it) const {
2209                 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
2210                 return it2_ == it.it2_;
2211             }
2212             BOOST_UBLAS_INLINE
2213             bool operator < (const iterator2 &it) const {
2214                 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
2215                 return it2_ < it.it2_;
2216             }
2217 
2218         private:
2219             subiterator2_type it2_;
2220 
2221             friend class const_iterator2;
2222         };
2223 #endif
2224 
2225         BOOST_UBLAS_INLINE
2226         iterator2 begin2 () {
2227             return find2 (0, 0, 0);
2228         }
2229         BOOST_UBLAS_INLINE
2230         iterator2 end2 () {
2231             return find2 (0, 0, size2 ());
2232         }
2233 
2234         // Reverse iterators
2235 
2236         BOOST_UBLAS_INLINE
2237         const_reverse_iterator1 rbegin1 () const {
2238             return const_reverse_iterator1 (end1 ());
2239         }
2240         BOOST_UBLAS_INLINE
2241         const_reverse_iterator1 crbegin1 () const {
2242             return rbegin1 ();
2243         }
2244         BOOST_UBLAS_INLINE
2245         const_reverse_iterator1 rend1 () const {
2246             return const_reverse_iterator1 (begin1 ());
2247         }
2248         BOOST_UBLAS_INLINE
2249         const_reverse_iterator1 crend1 () const {
2250             return rend1 ();
2251         }
2252 
2253         BOOST_UBLAS_INLINE
2254         reverse_iterator1 rbegin1 () {
2255             return reverse_iterator1 (end1 ());
2256         }
2257         BOOST_UBLAS_INLINE
2258         reverse_iterator1 rend1 () {
2259             return reverse_iterator1 (begin1 ());
2260         }
2261 
2262         BOOST_UBLAS_INLINE
2263         const_reverse_iterator2 rbegin2 () const {
2264             return const_reverse_iterator2 (end2 ());
2265         }
2266         BOOST_UBLAS_INLINE
2267         const_reverse_iterator2 crbegin2 () const {
2268             return rbegin2 ();
2269         }
2270         BOOST_UBLAS_INLINE
2271         const_reverse_iterator2 rend2 () const {
2272             return const_reverse_iterator2 (begin2 ());
2273         }
2274         BOOST_UBLAS_INLINE
2275         const_reverse_iterator2 crend2 () const {
2276             return rend2 ();
2277         }
2278 
2279         BOOST_UBLAS_INLINE
2280         reverse_iterator2 rbegin2 () {
2281             return reverse_iterator2 (end2 ());
2282         }
2283         BOOST_UBLAS_INLINE
2284         reverse_iterator2 rend2 () {
2285             return reverse_iterator2 (begin2 ());
2286         }
2287 
2288     private:
2289         matrix_closure_type data_;
2290     };
2291 
2292     // Specialization for temporary_traits
2293     template <class M, class TRI>
2294     struct vector_temporary_traits< symmetric_adaptor<M, TRI> >
2295     : vector_temporary_traits< M > {} ;
2296     template <class M, class TRI>
2297     struct vector_temporary_traits< const symmetric_adaptor<M, TRI> >
2298     : vector_temporary_traits< M > {} ;
2299 
2300     template <class M, class TRI>
2301     struct matrix_temporary_traits< symmetric_adaptor<M, TRI> >
2302     : matrix_temporary_traits< M > {} ;
2303     template <class M, class TRI>
2304     struct matrix_temporary_traits< const symmetric_adaptor<M, TRI> >
2305     : matrix_temporary_traits< M > {} ;
2306 
2307 }}}
2308 
2309 #endif