sl@0: // sl@0: // Copyright (c) 2000-2002 sl@0: // Joerg Walter, Mathias Koch sl@0: // sl@0: // Permission to use, copy, modify, distribute and sell this software sl@0: // and its documentation for any purpose is hereby granted without fee, sl@0: // provided that the above copyright notice appear in all copies and sl@0: // that both that copyright notice and this permission notice appear sl@0: // in supporting documentation. The authors make no representations sl@0: // about the suitability of this software for any purpose. sl@0: // It is provided "as is" without express or implied warranty. sl@0: // sl@0: // The authors gratefully acknowledge the support of sl@0: // GeNeSys mbH & Co. KG in producing this work. sl@0: // sl@0: sl@0: #ifndef _BOOST_UBLAS_TRIANGULAR_ sl@0: #define _BOOST_UBLAS_TRIANGULAR_ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: // Iterators based on ideas of Jeremy Siek sl@0: sl@0: namespace boost { namespace numeric { namespace ublas { sl@0: sl@0: // Array based triangular matrix class sl@0: template sl@0: class triangular_matrix: sl@0: public matrix_container > { sl@0: sl@0: typedef T *pointer; sl@0: typedef TRI triangular_type; sl@0: typedef L layout_type; sl@0: typedef triangular_matrix self_type; sl@0: public: sl@0: #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS sl@0: using matrix_container::operator (); sl@0: #endif sl@0: typedef typename A::size_type size_type; sl@0: typedef typename A::difference_type difference_type; sl@0: typedef T value_type; sl@0: typedef const T &const_reference; sl@0: typedef T &reference; sl@0: typedef A array_type; sl@0: sl@0: typedef const matrix_reference const_closure_type; sl@0: typedef matrix_reference closure_type; sl@0: typedef vector vector_temporary_type; sl@0: typedef matrix matrix_temporary_type; // general sub-matrix sl@0: typedef packed_tag storage_category; sl@0: typedef typename L::orientation_category orientation_category; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: triangular_matrix (): sl@0: matrix_container (), sl@0: size1_ (0), size2_ (0), data_ (0) {} sl@0: BOOST_UBLAS_INLINE sl@0: triangular_matrix (size_type size1, size_type size2): sl@0: matrix_container (), sl@0: size1_ (size1), size2_ (size2), data_ (triangular_type::packed_size (layout_type (), size1, size2)) { sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: triangular_matrix (size_type size1, size_type size2, const array_type &data): sl@0: matrix_container (), sl@0: size1_ (size1), size2_ (size2), data_ (data) {} sl@0: BOOST_UBLAS_INLINE sl@0: triangular_matrix (const triangular_matrix &m): sl@0: matrix_container (), sl@0: size1_ (m.size1_), size2_ (m.size2_), data_ (m.data_) {} sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: triangular_matrix (const matrix_expression &ae): sl@0: matrix_container (), sl@0: size1_ (ae ().size1 ()), size2_ (ae ().size2 ()), sl@0: data_ (triangular_type::packed_size (layout_type (), size1_, size2_)) { sl@0: matrix_assign (*this, ae); sl@0: } sl@0: sl@0: // Accessors sl@0: BOOST_UBLAS_INLINE sl@0: size_type size1 () const { sl@0: return size1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type size2 () const { sl@0: return size2_; sl@0: } sl@0: sl@0: // Storage accessors sl@0: BOOST_UBLAS_INLINE sl@0: const array_type &data () const { sl@0: return data_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: array_type &data () { sl@0: return data_; sl@0: } sl@0: sl@0: // Resizing sl@0: BOOST_UBLAS_INLINE sl@0: void resize (size_type size1, size_type size2, bool preserve = true) { sl@0: if (preserve) { sl@0: self_type temporary (size1, size2); sl@0: detail::matrix_resize_preserve (*this, temporary); sl@0: } sl@0: else { sl@0: data ().resize (triangular_type::packed_size (layout_type (), size1, size2)); sl@0: size1_ = size1; sl@0: size2_ = size2; sl@0: } sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: void resize_packed_preserve (size_type size1, size_type size2) { sl@0: size1_ = size1; sl@0: size2_ = size2; sl@0: data ().resize (triangular_type::packed_size (layout_type (), size1_, size2_), value_type ()); sl@0: } sl@0: sl@0: // Element access sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator () (size_type i, size_type j) const { sl@0: BOOST_UBLAS_CHECK (i < size1_, bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < size2_, bad_index ()); sl@0: if (triangular_type::other (i, j)) sl@0: return data () [triangular_type::element (layout_type (), i, size1_, j, size2_)]; sl@0: else if (triangular_type::one (i, j)) sl@0: return one_; sl@0: else sl@0: return zero_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reference at_element (size_type i, size_type j) { sl@0: BOOST_UBLAS_CHECK (i < size1_, bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < size2_, bad_index ()); sl@0: return data () [triangular_type::element (layout_type (), i, size1_, j, size2_)]; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reference operator () (size_type i, size_type j) { sl@0: BOOST_UBLAS_CHECK (i < size1_, bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < size2_, bad_index ()); sl@0: if (triangular_type::other (i, j)) sl@0: return data () [triangular_type::element (layout_type (), i, size1_, j, size2_)]; sl@0: else { sl@0: bad_index ().raise (); sl@0: // arbitary return value sl@0: return const_cast(zero_); sl@0: } sl@0: } sl@0: sl@0: // Element assignment sl@0: BOOST_UBLAS_INLINE sl@0: reference insert_element (size_type i, size_type j, const_reference t) { sl@0: return (operator () (i, j) = t); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: void erase_element (size_type i, size_type j) { sl@0: operator () (i, j) = value_type/*zero*/(); sl@0: } sl@0: sl@0: // Zeroing sl@0: BOOST_UBLAS_INLINE sl@0: void clear () { sl@0: // data ().clear (); sl@0: std::fill (data ().begin (), data ().end (), value_type/*zero*/()); sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: triangular_matrix &operator = (const triangular_matrix &m) { sl@0: size1_ = m.size1_; sl@0: size2_ = m.size2_; sl@0: data () = m.data (); sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: triangular_matrix &assign_temporary (triangular_matrix &m) { sl@0: swap (m); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: triangular_matrix &operator = (const matrix_expression &ae) { sl@0: self_type temporary (ae); sl@0: return assign_temporary (temporary); sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: triangular_matrix &assign (const matrix_expression &ae) { sl@0: matrix_assign (*this, ae); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: triangular_matrix& operator += (const matrix_expression &ae) { sl@0: self_type temporary (*this + ae); sl@0: return assign_temporary (temporary); sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: triangular_matrix &plus_assign (const matrix_expression &ae) { sl@0: matrix_assign (*this, ae); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: triangular_matrix& operator -= (const matrix_expression &ae) { sl@0: self_type temporary (*this - ae); sl@0: return assign_temporary (temporary); sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: triangular_matrix &minus_assign (const matrix_expression &ae) { sl@0: matrix_assign (*this, ae); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: triangular_matrix& operator *= (const AT &at) { sl@0: matrix_assign_scalar (*this, at); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: triangular_matrix& operator /= (const AT &at) { sl@0: matrix_assign_scalar (*this, at); sl@0: return *this; sl@0: } sl@0: sl@0: // Swapping sl@0: BOOST_UBLAS_INLINE sl@0: void swap (triangular_matrix &m) { sl@0: if (this != &m) { sl@0: // BOOST_UBLAS_CHECK (size2_ == m.size2_, bad_size ()); sl@0: std::swap (size1_, m.size1_); sl@0: std::swap (size2_, m.size2_); sl@0: data ().swap (m.data ()); sl@0: } sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: friend void swap (triangular_matrix &m1, triangular_matrix &m2) { sl@0: m1.swap (m2); sl@0: } sl@0: sl@0: // Iterator types sl@0: #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: typedef indexed_iterator1 iterator1; sl@0: typedef indexed_iterator2 iterator2; sl@0: typedef indexed_const_iterator1 const_iterator1; sl@0: typedef indexed_const_iterator2 const_iterator2; sl@0: #else sl@0: class const_iterator1; sl@0: class iterator1; sl@0: class const_iterator2; sl@0: class iterator2; sl@0: #endif sl@0: typedef reverse_iterator_base1 const_reverse_iterator1; sl@0: typedef reverse_iterator_base1 reverse_iterator1; sl@0: typedef reverse_iterator_base2 const_reverse_iterator2; sl@0: typedef reverse_iterator_base2 reverse_iterator2; sl@0: sl@0: // Element lookup sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 find1 (int rank, size_type i, size_type j) const { sl@0: if (rank == 1) sl@0: i = triangular_type::restrict1 (i, j); sl@0: return const_iterator1 (*this, i, j); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 find1 (int rank, size_type i, size_type j) { sl@0: if (rank == 1) sl@0: i = triangular_type::mutable_restrict1 (i, j); sl@0: return iterator1 (*this, i, j); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 find2 (int rank, size_type i, size_type j) const { sl@0: if (rank == 1) sl@0: j = triangular_type::restrict2 (i, j); sl@0: return const_iterator2 (*this, i, j); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 find2 (int rank, size_type i, size_type j) { sl@0: if (rank == 1) sl@0: j = triangular_type::mutable_restrict2 (i, j); sl@0: return iterator2 (*this, i, j); sl@0: } sl@0: sl@0: // Iterators simply are indices. sl@0: sl@0: #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: class const_iterator1: sl@0: public container_const_reference, sl@0: public random_access_iterator_base { sl@0: public: sl@0: typedef typename triangular_matrix::value_type value_type; sl@0: typedef typename triangular_matrix::difference_type difference_type; sl@0: typedef typename triangular_matrix::const_reference reference; sl@0: typedef const typename triangular_matrix::pointer pointer; sl@0: sl@0: typedef const_iterator2 dual_iterator_type; sl@0: typedef const_reverse_iterator2 dual_reverse_iterator_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 (): sl@0: container_const_reference (), it1_ (), it2_ () {} sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 (const self_type &m, size_type it1, size_type it2): sl@0: container_const_reference (m), it1_ (it1), it2_ (it2) {} sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 (const iterator1 &it): sl@0: container_const_reference (it ()), it1_ (it.it1_), it2_ (it.it2_) {} sl@0: sl@0: // Arithmetic sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator ++ () { sl@0: ++ it1_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator -- () { sl@0: -- it1_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator += (difference_type n) { sl@0: it1_ += n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator -= (difference_type n) { sl@0: it1_ -= n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: difference_type operator - (const const_iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ()); sl@0: return it1_ - it.it1_; sl@0: } sl@0: sl@0: // Dereference sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator * () const { sl@0: return (*this) () (it1_, it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator [] (difference_type n) const { sl@0: return *(*this + n); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_iterator2 begin () const { sl@0: return (*this) ().find2 (1, it1_, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_iterator2 end () const { sl@0: return (*this) ().find2 (1, it1_, (*this) ().size2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_reverse_iterator2 rbegin () const { sl@0: return const_reverse_iterator2 (end ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_reverse_iterator2 rend () const { sl@0: return const_reverse_iterator2 (begin ()); sl@0: } sl@0: #endif sl@0: sl@0: // Indices sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 () const { sl@0: return it1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 () const { sl@0: return it2_; sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator = (const const_iterator1 &it) { sl@0: container_const_reference::assign (&it ()); sl@0: it1_ = it.it1_; sl@0: it2_ = it.it2_; sl@0: return *this; sl@0: } sl@0: sl@0: // Comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool operator == (const const_iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ()); sl@0: return it1_ == it.it1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: bool operator < (const const_iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ()); sl@0: return it1_ < it.it1_; sl@0: } sl@0: sl@0: private: sl@0: size_type it1_; sl@0: size_type it2_; sl@0: }; sl@0: #endif sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 begin1 () const { sl@0: return find1 (0, 0, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 end1 () const { sl@0: return find1 (0, size1_, 0); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: class iterator1: sl@0: public container_reference, sl@0: public random_access_iterator_base { sl@0: public: sl@0: typedef typename triangular_matrix::value_type value_type; sl@0: typedef typename triangular_matrix::difference_type difference_type; sl@0: typedef typename triangular_matrix::reference reference; sl@0: typedef typename triangular_matrix::pointer pointer; sl@0: sl@0: typedef iterator2 dual_iterator_type; sl@0: typedef reverse_iterator2 dual_reverse_iterator_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 (): sl@0: container_reference (), it1_ (), it2_ () {} sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 (self_type &m, size_type it1, size_type it2): sl@0: container_reference (m), it1_ (it1), it2_ (it2) {} sl@0: sl@0: // Arithmetic sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator ++ () { sl@0: ++ it1_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator -- () { sl@0: -- it1_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator += (difference_type n) { sl@0: it1_ += n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator -= (difference_type n) { sl@0: it1_ -= n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: difference_type operator - (const iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ()); sl@0: return it1_ - it.it1_; sl@0: } sl@0: sl@0: // Dereference sl@0: BOOST_UBLAS_INLINE sl@0: reference operator * () const { sl@0: return (*this) () (it1_, it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reference operator [] (difference_type n) const { sl@0: return *(*this + n); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: iterator2 begin () const { sl@0: return (*this) ().find2 (1, it1_, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: iterator2 end () const { sl@0: return (*this) ().find2 (1, it1_, (*this) ().size2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: reverse_iterator2 rbegin () const { sl@0: return reverse_iterator2 (end ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: reverse_iterator2 rend () const { sl@0: return reverse_iterator2 (begin ()); sl@0: } sl@0: #endif sl@0: sl@0: // Indices sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 () const { sl@0: return it1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 () const { sl@0: return it2_; sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator = (const iterator1 &it) { sl@0: container_reference::assign (&it ()); sl@0: it1_ = it.it1_; sl@0: it2_ = it.it2_; sl@0: return *this; sl@0: } sl@0: sl@0: // Comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool operator == (const iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ()); sl@0: return it1_ == it.it1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: bool operator < (const iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ()); sl@0: return it1_ < it.it1_; sl@0: } sl@0: sl@0: private: sl@0: size_type it1_; sl@0: size_type it2_; sl@0: sl@0: friend class const_iterator1; sl@0: }; sl@0: #endif sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 begin1 () { sl@0: return find1 (0, 0, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 end1 () { sl@0: return find1 (0, size1_, 0); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: class const_iterator2: sl@0: public container_const_reference, sl@0: public random_access_iterator_base { sl@0: public: sl@0: typedef typename triangular_matrix::value_type value_type; sl@0: typedef typename triangular_matrix::difference_type difference_type; sl@0: typedef typename triangular_matrix::const_reference reference; sl@0: typedef const typename triangular_matrix::pointer pointer; sl@0: sl@0: typedef const_iterator1 dual_iterator_type; sl@0: typedef const_reverse_iterator1 dual_reverse_iterator_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 (): sl@0: container_const_reference (), it1_ (), it2_ () {} sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 (const self_type &m, size_type it1, size_type it2): sl@0: container_const_reference (m), it1_ (it1), it2_ (it2) {} sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 (const iterator2 &it): sl@0: container_const_reference (it ()), it1_ (it.it1_), it2_ (it.it2_) {} sl@0: sl@0: // Arithmetic sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator ++ () { sl@0: ++ it2_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator -- () { sl@0: -- it2_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator += (difference_type n) { sl@0: it2_ += n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator -= (difference_type n) { sl@0: it2_ -= n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: difference_type operator - (const const_iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ()); sl@0: return it2_ - it.it2_; sl@0: } sl@0: sl@0: // Dereference sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator * () const { sl@0: return (*this) () (it1_, it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator [] (difference_type n) const { sl@0: return *(*this + n); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_iterator1 begin () const { sl@0: return (*this) ().find1 (1, 0, it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_iterator1 end () const { sl@0: return (*this) ().find1 (1, (*this) ().size1 (), it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_reverse_iterator1 rbegin () const { sl@0: return const_reverse_iterator1 (end ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_reverse_iterator1 rend () const { sl@0: return const_reverse_iterator1 (begin ()); sl@0: } sl@0: #endif sl@0: sl@0: // Indices sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 () const { sl@0: return it1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 () const { sl@0: return it2_; sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator = (const const_iterator2 &it) { sl@0: container_const_reference::assign (&it ()); sl@0: it1_ = it.it1_; sl@0: it2_ = it.it2_; sl@0: return *this; sl@0: } sl@0: sl@0: // Comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool operator == (const const_iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ()); sl@0: return it2_ == it.it2_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: bool operator < (const const_iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ()); sl@0: return it2_ < it.it2_; sl@0: } sl@0: sl@0: private: sl@0: size_type it1_; sl@0: size_type it2_; sl@0: }; sl@0: #endif sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 begin2 () const { sl@0: return find2 (0, 0, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 end2 () const { sl@0: return find2 (0, 0, size2_); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: class iterator2: sl@0: public container_reference, sl@0: public random_access_iterator_base { sl@0: public: sl@0: typedef typename triangular_matrix::value_type value_type; sl@0: typedef typename triangular_matrix::difference_type difference_type; sl@0: typedef typename triangular_matrix::reference reference; sl@0: typedef typename triangular_matrix::pointer pointer; sl@0: sl@0: typedef iterator1 dual_iterator_type; sl@0: typedef reverse_iterator1 dual_reverse_iterator_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 (): sl@0: container_reference (), it1_ (), it2_ () {} sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 (self_type &m, size_type it1, size_type it2): sl@0: container_reference (m), it1_ (it1), it2_ (it2) {} sl@0: sl@0: // Arithmetic sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator ++ () { sl@0: ++ it2_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator -- () { sl@0: -- it2_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator += (difference_type n) { sl@0: it2_ += n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator -= (difference_type n) { sl@0: it2_ -= n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: difference_type operator - (const iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ()); sl@0: return it2_ - it.it2_; sl@0: } sl@0: sl@0: // Dereference sl@0: BOOST_UBLAS_INLINE sl@0: reference operator * () const { sl@0: return (*this) () (it1_, it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reference operator [] (difference_type n) const { sl@0: return *(*this + n); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: iterator1 begin () const { sl@0: return (*this) ().find1 (1, 0, it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: iterator1 end () const { sl@0: return (*this) ().find1 (1, (*this) ().size1 (), it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: reverse_iterator1 rbegin () const { sl@0: return reverse_iterator1 (end ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: reverse_iterator1 rend () const { sl@0: return reverse_iterator1 (begin ()); sl@0: } sl@0: #endif sl@0: sl@0: // Indices sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 () const { sl@0: return it1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 () const { sl@0: return it2_; sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator = (const iterator2 &it) { sl@0: container_reference::assign (&it ()); sl@0: it1_ = it.it1_; sl@0: it2_ = it.it2_; sl@0: return *this; sl@0: } sl@0: sl@0: // Comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool operator == (const iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ()); sl@0: return it2_ == it.it2_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: bool operator < (const iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ()); sl@0: return it2_ < it.it2_; sl@0: } sl@0: sl@0: private: sl@0: size_type it1_; sl@0: size_type it2_; sl@0: sl@0: friend class const_iterator2; sl@0: }; sl@0: #endif sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 begin2 () { sl@0: return find2 (0, 0, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 end2 () { sl@0: return find2 (0, 0, size2_); sl@0: } sl@0: sl@0: // Reverse iterators sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: const_reverse_iterator1 rbegin1 () const { sl@0: return const_reverse_iterator1 (end1 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_reverse_iterator1 rend1 () const { sl@0: return const_reverse_iterator1 (begin1 ()); sl@0: } sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: reverse_iterator1 rbegin1 () { sl@0: return reverse_iterator1 (end1 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reverse_iterator1 rend1 () { sl@0: return reverse_iterator1 (begin1 ()); sl@0: } sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: const_reverse_iterator2 rbegin2 () const { sl@0: return const_reverse_iterator2 (end2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_reverse_iterator2 rend2 () const { sl@0: return const_reverse_iterator2 (begin2 ()); sl@0: } sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: reverse_iterator2 rbegin2 () { sl@0: return reverse_iterator2 (end2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reverse_iterator2 rend2 () { sl@0: return reverse_iterator2 (begin2 ()); sl@0: } sl@0: sl@0: private: sl@0: size_type size1_; sl@0: size_type size2_; sl@0: array_type data_; sl@0: static const value_type zero_; sl@0: static const value_type one_; sl@0: }; sl@0: sl@0: template sl@0: const typename triangular_matrix::value_type triangular_matrix::zero_ = value_type/*zero*/(); sl@0: template sl@0: const typename triangular_matrix::value_type triangular_matrix::one_ (1); sl@0: sl@0: sl@0: // Triangular matrix adaptor class sl@0: template sl@0: class triangular_adaptor: sl@0: public matrix_expression > { sl@0: sl@0: typedef triangular_adaptor self_type; sl@0: sl@0: public: sl@0: #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS sl@0: using matrix_expression::operator (); sl@0: #endif sl@0: typedef const M const_matrix_type; sl@0: typedef M matrix_type; sl@0: typedef TRI triangular_type; sl@0: typedef typename M::size_type size_type; sl@0: typedef typename M::difference_type difference_type; sl@0: typedef typename M::value_type value_type; sl@0: typedef typename M::const_reference const_reference; sl@0: typedef typename boost::mpl::if_, sl@0: typename M::const_reference, sl@0: typename M::reference>::type reference; sl@0: typedef typename boost::mpl::if_, sl@0: typename M::const_closure_type, sl@0: typename M::closure_type>::type matrix_closure_type; sl@0: typedef const self_type const_closure_type; sl@0: typedef self_type closure_type; sl@0: // Replaced by _temporary_traits to avoid type requirements on M sl@0: //typedef typename M::vector_temporary_type vector_temporary_type; sl@0: //typedef typename M::matrix_temporary_type matrix_temporary_type; sl@0: typedef typename storage_restrict_traits::storage_category storage_category; sl@0: typedef typename M::orientation_category orientation_category; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: triangular_adaptor (matrix_type &data): sl@0: matrix_expression (), sl@0: data_ (data) {} sl@0: BOOST_UBLAS_INLINE sl@0: triangular_adaptor (const triangular_adaptor &m): sl@0: matrix_expression (), sl@0: data_ (m.data_) {} sl@0: sl@0: // Accessors sl@0: BOOST_UBLAS_INLINE sl@0: size_type size1 () const { sl@0: return data_.size1 (); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type size2 () const { sl@0: return data_.size2 (); sl@0: } sl@0: sl@0: // Storage accessors sl@0: BOOST_UBLAS_INLINE sl@0: const matrix_closure_type &data () const { sl@0: return data_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: matrix_closure_type &data () { sl@0: return data_; sl@0: } sl@0: sl@0: // Element access sl@0: #ifndef BOOST_UBLAS_PROXY_CONST_MEMBER sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator () (size_type i, size_type j) const { sl@0: BOOST_UBLAS_CHECK (i < size1 (), bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < size2 (), bad_index ()); sl@0: if (triangular_type::other (i, j)) sl@0: return data () (i, j); sl@0: else if (triangular_type::one (i, j)) sl@0: return one_; sl@0: else sl@0: return zero_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reference operator () (size_type i, size_type j) { sl@0: BOOST_UBLAS_CHECK (i < size1 (), bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < size2 (), bad_index ()); sl@0: if (triangular_type::other (i, j)) sl@0: return data () (i, j); sl@0: else if (triangular_type::one (i, j)) { sl@0: bad_index ().raise (); sl@0: // arbitary return value sl@0: return const_cast(one_); sl@0: } else { sl@0: bad_index ().raise (); sl@0: // arbitary return value sl@0: return const_cast(zero_); sl@0: } sl@0: } sl@0: #else sl@0: BOOST_UBLAS_INLINE sl@0: reference operator () (size_type i, size_type j) const { sl@0: BOOST_UBLAS_CHECK (i < size1 (), bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < size2 (), bad_index ()); sl@0: if (triangular_type::other (i, j)) sl@0: return data () (i, j); sl@0: else if (triangular_type::one (i, j)) { sl@0: bad_index ().raise (); sl@0: // arbitary return value sl@0: return const_cast(one_); sl@0: } else { sl@0: bad_index ().raise (); sl@0: // arbitary return value sl@0: return const_cast(zero_); sl@0: } sl@0: } sl@0: #endif sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: triangular_adaptor &operator = (const triangular_adaptor &m) { sl@0: matrix_assign (*this, m); sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: triangular_adaptor &assign_temporary (triangular_adaptor &m) { sl@0: *this = m; sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: triangular_adaptor &operator = (const matrix_expression &ae) { sl@0: matrix_assign (*this, matrix (ae)); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: triangular_adaptor &assign (const matrix_expression &ae) { sl@0: matrix_assign (*this, ae); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: triangular_adaptor& operator += (const matrix_expression &ae) { sl@0: matrix_assign (*this, matrix (*this + ae)); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: triangular_adaptor &plus_assign (const matrix_expression &ae) { sl@0: matrix_assign (*this, ae); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: triangular_adaptor& operator -= (const matrix_expression &ae) { sl@0: matrix_assign (*this, matrix (*this - ae)); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: triangular_adaptor &minus_assign (const matrix_expression &ae) { sl@0: matrix_assign (*this, ae); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: triangular_adaptor& operator *= (const AT &at) { sl@0: matrix_assign_scalar (*this, at); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: triangular_adaptor& operator /= (const AT &at) { sl@0: matrix_assign_scalar (*this, at); sl@0: return *this; sl@0: } sl@0: sl@0: // Closure comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool same_closure (const triangular_adaptor &ta) const { sl@0: return (*this).data ().same_closure (ta.data ()); sl@0: } sl@0: sl@0: // Swapping sl@0: BOOST_UBLAS_INLINE sl@0: void swap (triangular_adaptor &m) { sl@0: if (this != &m) sl@0: matrix_swap (*this, m); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: friend void swap (triangular_adaptor &m1, triangular_adaptor &m2) { sl@0: m1.swap (m2); sl@0: } sl@0: sl@0: // Iterator types sl@0: private: sl@0: typedef typename M::const_iterator1 const_subiterator1_type; sl@0: typedef typename boost::mpl::if_, sl@0: typename M::const_iterator1, sl@0: typename M::iterator1>::type subiterator1_type; sl@0: typedef typename M::const_iterator2 const_subiterator2_type; sl@0: typedef typename boost::mpl::if_, sl@0: typename M::const_iterator2, sl@0: typename M::iterator2>::type subiterator2_type; sl@0: sl@0: public: sl@0: #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: typedef indexed_iterator1 iterator1; sl@0: typedef indexed_iterator2 iterator2; sl@0: typedef indexed_const_iterator1 const_iterator1; sl@0: typedef indexed_const_iterator2 const_iterator2; sl@0: #else sl@0: class const_iterator1; sl@0: class iterator1; sl@0: class const_iterator2; sl@0: class iterator2; sl@0: #endif sl@0: typedef reverse_iterator_base1 const_reverse_iterator1; sl@0: typedef reverse_iterator_base1 reverse_iterator1; sl@0: typedef reverse_iterator_base2 const_reverse_iterator2; sl@0: typedef reverse_iterator_base2 reverse_iterator2; sl@0: sl@0: // Element lookup sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 find1 (int rank, size_type i, size_type j) const { sl@0: if (rank == 1) sl@0: i = triangular_type::restrict1 (i, j); sl@0: return const_iterator1 (*this, data ().find1 (rank, i, j)); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 find1 (int rank, size_type i, size_type j) { sl@0: if (rank == 1) sl@0: i = triangular_type::mutable_restrict1 (i, j); sl@0: return iterator1 (*this, data ().find1 (rank, i, j)); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 find2 (int rank, size_type i, size_type j) const { sl@0: if (rank == 1) sl@0: j = triangular_type::restrict2 (i, j); sl@0: return const_iterator2 (*this, data ().find2 (rank, i, j)); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 find2 (int rank, size_type i, size_type j) { sl@0: if (rank == 1) sl@0: j = triangular_type::mutable_restrict2 (i, j); sl@0: return iterator2 (*this, data ().find2 (rank, i, j)); sl@0: } sl@0: sl@0: // Iterators simply are indices. sl@0: sl@0: #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: class const_iterator1: sl@0: public container_const_reference, sl@0: public random_access_iterator_base::iterator_category, sl@0: const_iterator1, value_type> { sl@0: public: sl@0: typedef typename const_subiterator1_type::value_type value_type; sl@0: typedef typename const_subiterator1_type::difference_type difference_type; sl@0: typedef typename const_subiterator1_type::reference reference; sl@0: typedef typename const_subiterator1_type::pointer pointer; sl@0: sl@0: typedef const_iterator2 dual_iterator_type; sl@0: typedef const_reverse_iterator2 dual_reverse_iterator_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 (): sl@0: container_const_reference (), it1_ () {} sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 (const self_type &m, const const_subiterator1_type &it1): sl@0: container_const_reference (m), it1_ (it1) {} sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 (const iterator1 &it): sl@0: container_const_reference (it ()), it1_ (it.it1_) {} sl@0: sl@0: // Arithmetic sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator ++ () { sl@0: ++ it1_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator -- () { sl@0: -- it1_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator += (difference_type n) { sl@0: it1_ += n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator -= (difference_type n) { sl@0: it1_ -= n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: difference_type operator - (const const_iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it1_ - it.it1_; sl@0: } sl@0: sl@0: // Dereference sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator * () const { sl@0: size_type i = index1 (); sl@0: size_type j = index2 (); sl@0: BOOST_UBLAS_CHECK (i < (*this) ().size1 (), bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < (*this) ().size2 (), bad_index ()); sl@0: if (triangular_type::other (i, j)) sl@0: return *it1_; sl@0: else sl@0: return (*this) () (i, j); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator [] (difference_type n) const { sl@0: return *(*this + n); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_iterator2 begin () const { sl@0: return (*this) ().find2 (1, index1 (), 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_iterator2 end () const { sl@0: return (*this) ().find2 (1, index1 (), (*this) ().size2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_reverse_iterator2 rbegin () const { sl@0: return const_reverse_iterator2 (end ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_reverse_iterator2 rend () const { sl@0: return const_reverse_iterator2 (begin ()); sl@0: } sl@0: #endif sl@0: sl@0: // Indices sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 () const { sl@0: return it1_.index1 (); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 () const { sl@0: return it1_.index2 (); sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator = (const const_iterator1 &it) { sl@0: container_const_reference::assign (&it ()); sl@0: it1_ = it.it1_; sl@0: return *this; sl@0: } sl@0: sl@0: // Comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool operator == (const const_iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it1_ == it.it1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: bool operator < (const const_iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it1_ < it.it1_; sl@0: } sl@0: sl@0: private: sl@0: const_subiterator1_type it1_; sl@0: }; sl@0: #endif sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 begin1 () const { sl@0: return find1 (0, 0, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 end1 () const { sl@0: return find1 (0, size1 (), 0); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: class iterator1: sl@0: public container_reference, sl@0: public random_access_iterator_base::iterator_category, sl@0: iterator1, value_type> { sl@0: public: sl@0: typedef typename subiterator1_type::value_type value_type; sl@0: typedef typename subiterator1_type::difference_type difference_type; sl@0: typedef typename subiterator1_type::reference reference; sl@0: typedef typename subiterator1_type::pointer pointer; sl@0: sl@0: typedef iterator2 dual_iterator_type; sl@0: typedef reverse_iterator2 dual_reverse_iterator_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 (): sl@0: container_reference (), it1_ () {} sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 (self_type &m, const subiterator1_type &it1): sl@0: container_reference (m), it1_ (it1) {} sl@0: sl@0: // Arithmetic sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator ++ () { sl@0: ++ it1_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator -- () { sl@0: -- it1_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator += (difference_type n) { sl@0: it1_ += n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator -= (difference_type n) { sl@0: it1_ -= n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: difference_type operator - (const iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it1_ - it.it1_; sl@0: } sl@0: sl@0: // Dereference sl@0: BOOST_UBLAS_INLINE sl@0: reference operator * () const { sl@0: size_type i = index1 (); sl@0: size_type j = index2 (); sl@0: BOOST_UBLAS_CHECK (i < (*this) ().size1 (), bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < (*this) ().size2 (), bad_index ()); sl@0: if (triangular_type::other (i, j)) sl@0: return *it1_; sl@0: else sl@0: return (*this) () (i, j); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reference operator [] (difference_type n) const { sl@0: return *(*this + n); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: iterator2 begin () const { sl@0: return (*this) ().find2 (1, index1 (), 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: iterator2 end () const { sl@0: return (*this) ().find2 (1, index1 (), (*this) ().size2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: reverse_iterator2 rbegin () const { sl@0: return reverse_iterator2 (end ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: reverse_iterator2 rend () const { sl@0: return reverse_iterator2 (begin ()); sl@0: } sl@0: #endif sl@0: sl@0: // Indices sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 () const { sl@0: return it1_.index1 (); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 () const { sl@0: return it1_.index2 (); sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator = (const iterator1 &it) { sl@0: container_reference::assign (&it ()); sl@0: it1_ = it.it1_; sl@0: return *this; sl@0: } sl@0: sl@0: // Comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool operator == (const iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it1_ == it.it1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: bool operator < (const iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it1_ < it.it1_; sl@0: } sl@0: sl@0: private: sl@0: subiterator1_type it1_; sl@0: sl@0: friend class const_iterator1; sl@0: }; sl@0: #endif sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 begin1 () { sl@0: return find1 (0, 0, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 end1 () { sl@0: return find1 (0, size1 (), 0); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: class const_iterator2: sl@0: public container_const_reference, sl@0: public random_access_iterator_base::iterator_category, sl@0: const_iterator2, value_type> { sl@0: public: sl@0: typedef typename const_subiterator2_type::value_type value_type; sl@0: typedef typename const_subiterator2_type::difference_type difference_type; sl@0: typedef typename const_subiterator2_type::reference reference; sl@0: typedef typename const_subiterator2_type::pointer pointer; sl@0: sl@0: typedef const_iterator1 dual_iterator_type; sl@0: typedef const_reverse_iterator1 dual_reverse_iterator_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 (): sl@0: container_const_reference (), it2_ () {} sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 (const self_type &m, const const_subiterator2_type &it2): sl@0: container_const_reference (m), it2_ (it2) {} sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 (const iterator2 &it): sl@0: container_const_reference (it ()), it2_ (it.it2_) {} sl@0: sl@0: // Arithmetic sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator ++ () { sl@0: ++ it2_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator -- () { sl@0: -- it2_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator += (difference_type n) { sl@0: it2_ += n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator -= (difference_type n) { sl@0: it2_ -= n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: difference_type operator - (const const_iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it2_ - it.it2_; sl@0: } sl@0: sl@0: // Dereference sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator * () const { sl@0: size_type i = index1 (); sl@0: size_type j = index2 (); sl@0: BOOST_UBLAS_CHECK (i < (*this) ().size1 (), bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < (*this) ().size2 (), bad_index ()); sl@0: if (triangular_type::other (i, j)) sl@0: return *it2_; sl@0: else sl@0: return (*this) () (i, j); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator [] (difference_type n) const { sl@0: return *(*this + n); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_iterator1 begin () const { sl@0: return (*this) ().find1 (1, 0, index2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_iterator1 end () const { sl@0: return (*this) ().find1 (1, (*this) ().size1 (), index2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_reverse_iterator1 rbegin () const { sl@0: return const_reverse_iterator1 (end ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_reverse_iterator1 rend () const { sl@0: return const_reverse_iterator1 (begin ()); sl@0: } sl@0: #endif sl@0: sl@0: // Indices sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 () const { sl@0: return it2_.index1 (); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 () const { sl@0: return it2_.index2 (); sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator = (const const_iterator2 &it) { sl@0: container_const_reference::assign (&it ()); sl@0: it2_ = it.it2_; sl@0: return *this; sl@0: } sl@0: sl@0: // Comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool operator == (const const_iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it2_ == it.it2_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: bool operator < (const const_iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it2_ < it.it2_; sl@0: } sl@0: sl@0: private: sl@0: const_subiterator2_type it2_; sl@0: }; sl@0: #endif sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 begin2 () const { sl@0: return find2 (0, 0, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 end2 () const { sl@0: return find2 (0, 0, size2 ()); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: class iterator2: sl@0: public container_reference, sl@0: public random_access_iterator_base::iterator_category, sl@0: iterator2, value_type> { sl@0: public: sl@0: typedef typename subiterator2_type::value_type value_type; sl@0: typedef typename subiterator2_type::difference_type difference_type; sl@0: typedef typename subiterator2_type::reference reference; sl@0: typedef typename subiterator2_type::pointer pointer; sl@0: sl@0: typedef iterator1 dual_iterator_type; sl@0: typedef reverse_iterator1 dual_reverse_iterator_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 (): sl@0: container_reference (), it2_ () {} sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 (self_type &m, const subiterator2_type &it2): sl@0: container_reference (m), it2_ (it2) {} sl@0: sl@0: // Arithmetic sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator ++ () { sl@0: ++ it2_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator -- () { sl@0: -- it2_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator += (difference_type n) { sl@0: it2_ += n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator -= (difference_type n) { sl@0: it2_ -= n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: difference_type operator - (const iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it2_ - it.it2_; sl@0: } sl@0: sl@0: // Dereference sl@0: BOOST_UBLAS_INLINE sl@0: reference operator * () const { sl@0: size_type i = index1 (); sl@0: size_type j = index2 (); sl@0: BOOST_UBLAS_CHECK (i < (*this) ().size1 (), bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < (*this) ().size2 (), bad_index ()); sl@0: if (triangular_type::other (i, j)) sl@0: return *it2_; sl@0: else sl@0: return (*this) () (i, j); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reference operator [] (difference_type n) const { sl@0: return *(*this + n); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: iterator1 begin () const { sl@0: return (*this) ().find1 (1, 0, index2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: iterator1 end () const { sl@0: return (*this) ().find1 (1, (*this) ().size1 (), index2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: reverse_iterator1 rbegin () const { sl@0: return reverse_iterator1 (end ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: reverse_iterator1 rend () const { sl@0: return reverse_iterator1 (begin ()); sl@0: } sl@0: #endif sl@0: sl@0: // Indices sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 () const { sl@0: return it2_.index1 (); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 () const { sl@0: return it2_.index2 (); sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator = (const iterator2 &it) { sl@0: container_reference::assign (&it ()); sl@0: it2_ = it.it2_; sl@0: return *this; sl@0: } sl@0: sl@0: // Comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool operator == (const iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it2_ == it.it2_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: bool operator < (const iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it2_ < it.it2_; sl@0: } sl@0: sl@0: private: sl@0: subiterator2_type it2_; sl@0: sl@0: friend class const_iterator2; sl@0: }; sl@0: #endif sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 begin2 () { sl@0: return find2 (0, 0, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 end2 () { sl@0: return find2 (0, 0, size2 ()); sl@0: } sl@0: sl@0: // Reverse iterators sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: const_reverse_iterator1 rbegin1 () const { sl@0: return const_reverse_iterator1 (end1 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_reverse_iterator1 rend1 () const { sl@0: return const_reverse_iterator1 (begin1 ()); sl@0: } sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: reverse_iterator1 rbegin1 () { sl@0: return reverse_iterator1 (end1 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reverse_iterator1 rend1 () { sl@0: return reverse_iterator1 (begin1 ()); sl@0: } sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: const_reverse_iterator2 rbegin2 () const { sl@0: return const_reverse_iterator2 (end2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_reverse_iterator2 rend2 () const { sl@0: return const_reverse_iterator2 (begin2 ()); sl@0: } sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: reverse_iterator2 rbegin2 () { sl@0: return reverse_iterator2 (end2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reverse_iterator2 rend2 () { sl@0: return reverse_iterator2 (begin2 ()); sl@0: } sl@0: sl@0: private: sl@0: matrix_closure_type data_; sl@0: static const value_type zero_; sl@0: static const value_type one_; sl@0: }; sl@0: sl@0: template sl@0: const typename triangular_adaptor::value_type triangular_adaptor::zero_ = value_type/*zero*/(); sl@0: template sl@0: const typename triangular_adaptor::value_type triangular_adaptor::one_ (1); sl@0: sl@0: template sl@0: struct vector_temporary_traits< triangular_adaptor > sl@0: : vector_temporary_traits< typename boost::remove_const::type > {} ; sl@0: template sl@0: struct vector_temporary_traits< const triangular_adaptor > sl@0: : vector_temporary_traits< typename boost::remove_const::type > {} ; sl@0: sl@0: template sl@0: struct matrix_temporary_traits< triangular_adaptor > sl@0: : matrix_temporary_traits< typename boost::remove_const::type > {}; sl@0: template sl@0: struct matrix_temporary_traits< const triangular_adaptor > sl@0: : matrix_temporary_traits< typename boost::remove_const::type > {}; sl@0: sl@0: sl@0: template sl@0: struct matrix_vector_solve_traits { sl@0: typedef typename promote_traits::promote_type promote_type; sl@0: typedef vector result_type; sl@0: }; sl@0: sl@0: // Operations: sl@0: // n * (n - 1) / 2 + n = n * (n + 1) / 2 multiplications, sl@0: // n * (n - 1) / 2 additions sl@0: sl@0: // Dense (proxy) case sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (const matrix_expression &e1, vector_expression &e2, sl@0: lower_tag, column_major_tag, dense_proxy_tag) { sl@0: typedef typename E2::size_type size_type; sl@0: typedef typename E2::difference_type difference_type; sl@0: typedef typename E2::value_type value_type; sl@0: sl@0: BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ()); sl@0: BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ()); sl@0: size_type size = e2 ().size (); sl@0: for (size_type n = 0; n < size; ++ n) { sl@0: #ifndef BOOST_UBLAS_SINGULAR_CHECK sl@0: BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ()); sl@0: #else sl@0: if (e1 () (n, n) == value_type/*zero*/()) sl@0: singular ().raise (); sl@0: #endif sl@0: value_type t = e2 () (n) /= e1 () (n, n); sl@0: if (t != value_type/*zero*/()) { sl@0: for (size_type m = n + 1; m < size; ++ m) sl@0: e2 () (m) -= e1 () (m, n) * t; sl@0: } sl@0: } sl@0: } sl@0: // Packed (proxy) case sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (const matrix_expression &e1, vector_expression &e2, sl@0: lower_tag, column_major_tag, packed_proxy_tag) { sl@0: typedef typename E2::size_type size_type; sl@0: typedef typename E2::difference_type difference_type; sl@0: typedef typename E2::value_type value_type; sl@0: sl@0: BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ()); sl@0: BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ()); sl@0: size_type size = e2 ().size (); sl@0: for (size_type n = 0; n < size; ++ n) { sl@0: #ifndef BOOST_UBLAS_SINGULAR_CHECK sl@0: BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ()); sl@0: #else sl@0: if (e1 () (n, n) == value_type/*zero*/()) sl@0: singular ().raise (); sl@0: #endif sl@0: value_type t = e2 () (n) /= e1 () (n, n); sl@0: if (t != value_type/*zero*/()) { sl@0: typename E1::const_iterator1 it1e1 (e1 ().find1 (1, n + 1, n)); sl@0: typename E1::const_iterator1 it1e1_end (e1 ().find1 (1, e1 ().size1 (), n)); sl@0: difference_type m (it1e1_end - it1e1); sl@0: while (-- m >= 0) sl@0: e2 () (it1e1.index1 ()) -= *it1e1 * t, ++ it1e1; sl@0: } sl@0: } sl@0: } sl@0: // Sparse (proxy) case sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (const matrix_expression &e1, vector_expression &e2, sl@0: lower_tag, column_major_tag, unknown_storage_tag) { sl@0: typedef typename E2::size_type size_type; sl@0: typedef typename E2::difference_type difference_type; sl@0: typedef typename E2::value_type value_type; sl@0: sl@0: BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ()); sl@0: BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ()); sl@0: size_type size = e2 ().size (); sl@0: for (size_type n = 0; n < size; ++ n) { sl@0: #ifndef BOOST_UBLAS_SINGULAR_CHECK sl@0: BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ()); sl@0: #else sl@0: if (e1 () (n, n) == value_type/*zero*/()) sl@0: singular ().raise (); sl@0: #endif sl@0: value_type t = e2 () (n) /= e1 () (n, n); sl@0: if (t != value_type/*zero*/()) { sl@0: typename E1::const_iterator1 it1e1 (e1 ().find1 (1, n + 1, n)); sl@0: typename E1::const_iterator1 it1e1_end (e1 ().find1 (1, e1 ().size1 (), n)); sl@0: while (it1e1 != it1e1_end) sl@0: e2 () (it1e1.index1 ()) -= *it1e1 * t, ++ it1e1; sl@0: } sl@0: } sl@0: } sl@0: // Redirectors :-) sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (const matrix_expression &e1, vector_expression &e2, sl@0: lower_tag, column_major_tag) { sl@0: typedef typename E1::storage_category storage_category; sl@0: inplace_solve (e1, e2, sl@0: lower_tag (), column_major_tag (), storage_category ()); sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (const matrix_expression &e1, vector_expression &e2, sl@0: lower_tag, row_major_tag) { sl@0: typedef typename E1::storage_category storage_category; sl@0: inplace_solve (e2, trans (e1), sl@0: upper_tag (), row_major_tag (), storage_category ()); sl@0: } sl@0: // Dispatcher sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (const matrix_expression &e1, vector_expression &e2, sl@0: lower_tag) { sl@0: typedef typename E1::orientation_category orientation_category; sl@0: inplace_solve (e1, e2, sl@0: lower_tag (), orientation_category ()); sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (const matrix_expression &e1, vector_expression &e2, sl@0: unit_lower_tag) { sl@0: typedef typename E1::orientation_category orientation_category; sl@0: inplace_solve (triangular_adaptor (e1 ()), e2, sl@0: unit_lower_tag (), orientation_category ()); sl@0: } sl@0: sl@0: // Dense (proxy) case sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (const matrix_expression &e1, vector_expression &e2, sl@0: upper_tag, column_major_tag, dense_proxy_tag) { sl@0: typedef typename E2::size_type size_type; sl@0: typedef typename E2::difference_type difference_type; sl@0: typedef typename E2::value_type value_type; sl@0: sl@0: BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ()); sl@0: BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ()); sl@0: size_type size = e2 ().size (); sl@0: for (difference_type n = size - 1; n >= 0; -- n) { sl@0: #ifndef BOOST_UBLAS_SINGULAR_CHECK sl@0: BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ()); sl@0: #else sl@0: if (e1 () (n, n) == value_type/*zero*/()) sl@0: singular ().raise (); sl@0: #endif sl@0: value_type t = e2 () (n) /= e1 () (n, n); sl@0: if (t != value_type/*zero*/()) { sl@0: for (difference_type m = n - 1; m >= 0; -- m) sl@0: e2 () (m) -= e1 () (m, n) * t; sl@0: } sl@0: } sl@0: } sl@0: // Packed (proxy) case sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (const matrix_expression &e1, vector_expression &e2, sl@0: upper_tag, column_major_tag, packed_proxy_tag) { sl@0: typedef typename E2::size_type size_type; sl@0: typedef typename E2::difference_type difference_type; sl@0: typedef typename E2::value_type value_type; sl@0: sl@0: BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ()); sl@0: BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ()); sl@0: size_type size = e2 ().size (); sl@0: for (difference_type n = size - 1; n >= 0; -- n) { sl@0: #ifndef BOOST_UBLAS_SINGULAR_CHECK sl@0: BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ()); sl@0: #else sl@0: if (e1 () (n, n) == value_type/*zero*/()) sl@0: singular ().raise (); sl@0: #endif sl@0: value_type t = e2 () (n) /= e1 () (n, n); sl@0: if (t != value_type/*zero*/()) { sl@0: typename E1::const_reverse_iterator1 it1e1 (e1 ().find1 (1, n, n)); sl@0: typename E1::const_reverse_iterator1 it1e1_rend (e1 ().find1 (1, 0, n)); sl@0: difference_type m (it1e1_rend - it1e1); sl@0: while (-- m >= 0) sl@0: e2 () (it1e1.index1 ()) -= *it1e1 * t, ++ it1e1; sl@0: } sl@0: } sl@0: } sl@0: // Sparse (proxy) case sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (const matrix_expression &e1, vector_expression &e2, sl@0: upper_tag, column_major_tag, unknown_storage_tag) { sl@0: typedef typename E2::size_type size_type; sl@0: typedef typename E2::difference_type difference_type; sl@0: typedef typename E2::value_type value_type; sl@0: sl@0: BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ()); sl@0: BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ()); sl@0: size_type size = e2 ().size (); sl@0: for (difference_type n = size - 1; n >= 0; -- n) { sl@0: #ifndef BOOST_UBLAS_SINGULAR_CHECK sl@0: BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ()); sl@0: #else sl@0: if (e1 () (n, n) == value_type/*zero*/()) sl@0: singular ().raise (); sl@0: #endif sl@0: value_type t = e2 () (n) /= e1 () (n, n); sl@0: if (t != value_type/*zero*/()) { sl@0: typename E1::const_reverse_iterator1 it1e1 (e1 ().find1 (1, n, n)); sl@0: typename E1::const_reverse_iterator1 it1e1_rend (e1 ().find1 (1, 0, n)); sl@0: while (it1e1 != it1e1_rend) sl@0: e2 () (it1e1.index1 ()) -= *it1e1 * t, ++ it1e1; sl@0: } sl@0: } sl@0: } sl@0: // Redirectors :-) sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (const matrix_expression &e1, vector_expression &e2, sl@0: upper_tag, column_major_tag) { sl@0: typedef typename E1::storage_category storage_category; sl@0: inplace_solve (e1, e2, sl@0: upper_tag (), column_major_tag (), storage_category ()); sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (const matrix_expression &e1, vector_expression &e2, sl@0: upper_tag, row_major_tag) { sl@0: typedef typename E1::storage_category storage_category; sl@0: inplace_solve (e2, trans (e1), sl@0: lower_tag (), row_major_tag (), storage_category ()); sl@0: } sl@0: // Dispatcher sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (const matrix_expression &e1, vector_expression &e2, sl@0: upper_tag) { sl@0: typedef typename E1::orientation_category orientation_category; sl@0: inplace_solve (e1, e2, sl@0: upper_tag (), orientation_category ()); sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (const matrix_expression &e1, vector_expression &e2, sl@0: unit_upper_tag) { sl@0: typedef typename E1::orientation_category orientation_category; sl@0: inplace_solve (triangular_adaptor (e1 ()), e2, sl@0: unit_upper_tag (), orientation_category ()); sl@0: } sl@0: sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: typename matrix_vector_solve_traits::result_type sl@0: solve (const matrix_expression &e1, sl@0: const vector_expression &e2, sl@0: C) { sl@0: typename matrix_vector_solve_traits::result_type r (e2); sl@0: inplace_solve (e1, r, C ()); sl@0: return r; sl@0: } sl@0: sl@0: // Dense (proxy) case sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (vector_expression &e1, const matrix_expression &e2, sl@0: lower_tag, row_major_tag, dense_proxy_tag) { sl@0: typedef typename E1::size_type size_type; sl@0: typedef typename E1::difference_type difference_type; sl@0: typedef typename E1::value_type value_type; sl@0: sl@0: BOOST_UBLAS_CHECK (e1 ().size () == e2 ().size1 (), bad_size ()); sl@0: BOOST_UBLAS_CHECK (e2 ().size1 () == e2 ().size2 (), bad_size ()); sl@0: size_type size = e1 ().size (); sl@0: for (difference_type n = size - 1; n >= 0; -- n) { sl@0: #ifndef BOOST_UBLAS_SINGULAR_CHECK sl@0: BOOST_UBLAS_CHECK (e2 () (n, n) != value_type/*zero*/(), singular ()); sl@0: #else sl@0: if (e2 () (n, n) == value_type/*zero*/()) sl@0: singular ().raise (); sl@0: #endif sl@0: value_type t = e1 () (n) /= e2 () (n, n); sl@0: if (t != value_type/*zero*/()) { sl@0: for (difference_type m = n - 1; m >= 0; -- m) sl@0: e1 () (m) -= t * e2 () (n, m); sl@0: } sl@0: } sl@0: } sl@0: // Packed (proxy) case sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (vector_expression &e1, const matrix_expression &e2, sl@0: lower_tag, row_major_tag, packed_proxy_tag) { sl@0: typedef typename E1::size_type size_type; sl@0: typedef typename E1::difference_type difference_type; sl@0: typedef typename E1::value_type value_type; sl@0: sl@0: BOOST_UBLAS_CHECK (e1 ().size () == e2 ().size1 (), bad_size ()); sl@0: BOOST_UBLAS_CHECK (e2 ().size1 () == e2 ().size2 (), bad_size ()); sl@0: size_type size = e1 ().size (); sl@0: for (difference_type n = size - 1; n >= 0; -- n) { sl@0: #ifndef BOOST_UBLAS_SINGULAR_CHECK sl@0: BOOST_UBLAS_CHECK (e2 () (n, n) != value_type/*zero*/(), singular ()); sl@0: #else sl@0: if (e2 () (n, n) == value_type/*zero*/()) sl@0: singular ().raise (); sl@0: #endif sl@0: value_type t = e1 () (n) /= e2 () (n, n); sl@0: if (t != value_type/*zero*/()) { sl@0: typename E2::const_reverse_iterator2 it2e2 (e2 ().find2 (1, n, n)); sl@0: typename E2::const_reverse_iterator2 it2e2_rend (e2 ().find2 (1, n, 0)); sl@0: difference_type m (it2e2_rend - it2e2); sl@0: while (-- m >= 0) sl@0: e1 () (it2e2.index2 ()) -= *it2e2 * t, ++ it2e2; sl@0: } sl@0: } sl@0: } sl@0: // Sparse (proxy) case sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (vector_expression &e1, const matrix_expression &e2, sl@0: lower_tag, row_major_tag, unknown_storage_tag) { sl@0: typedef typename E1::size_type size_type; sl@0: typedef typename E1::difference_type difference_type; sl@0: typedef typename E1::value_type value_type; sl@0: sl@0: BOOST_UBLAS_CHECK (e1 ().size () == e2 ().size1 (), bad_size ()); sl@0: BOOST_UBLAS_CHECK (e2 ().size1 () == e2 ().size2 (), bad_size ()); sl@0: size_type size = e1 ().size (); sl@0: for (difference_type n = size - 1; n >= 0; -- n) { sl@0: #ifndef BOOST_UBLAS_SINGULAR_CHECK sl@0: BOOST_UBLAS_CHECK (e2 () (n, n) != value_type/*zero*/(), singular ()); sl@0: #else sl@0: if (e2 () (n, n) == value_type/*zero*/()) sl@0: singular ().raise (); sl@0: #endif sl@0: value_type t = e1 () (n) /= e2 () (n, n); sl@0: if (t != value_type/*zero*/()) { sl@0: typename E2::const_reverse_iterator2 it2e2 (e2 ().find2 (1, n, n)); sl@0: typename E2::const_reverse_iterator2 it2e2_rend (e2 ().find2 (1, n, 0)); sl@0: while (it2e2 != it2e2_rend) sl@0: e1 () (it2e2.index2 ()) -= *it2e2 * t, ++ it2e2; sl@0: } sl@0: } sl@0: } sl@0: // Redirectors :-) sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (vector_expression &e1, const matrix_expression &e2, sl@0: lower_tag, row_major_tag) { sl@0: typedef typename E1::storage_category storage_category; sl@0: inplace_solve (e1, e2, sl@0: lower_tag (), row_major_tag (), storage_category ()); sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (vector_expression &e1, const matrix_expression &e2, sl@0: lower_tag, column_major_tag) { sl@0: typedef typename E1::storage_category storage_category; sl@0: inplace_solve (trans (e2), e1, sl@0: upper_tag (), row_major_tag (), storage_category ()); sl@0: } sl@0: // Dispatcher sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (vector_expression &e1, const matrix_expression &e2, sl@0: lower_tag) { sl@0: typedef typename E2::orientation_category orientation_category; sl@0: inplace_solve (e1, e2, sl@0: lower_tag (), orientation_category ()); sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (vector_expression &e1, const matrix_expression &e2, sl@0: unit_lower_tag) { sl@0: typedef typename E2::orientation_category orientation_category; sl@0: inplace_solve (e1, triangular_adaptor (e2 ()), sl@0: unit_lower_tag (), orientation_category ()); sl@0: } sl@0: sl@0: // Dense (proxy) case sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (vector_expression &e1, const matrix_expression &e2, sl@0: upper_tag, row_major_tag, dense_proxy_tag) { sl@0: typedef typename E1::size_type size_type; sl@0: typedef typename E1::difference_type difference_type; sl@0: typedef typename E1::value_type value_type; sl@0: sl@0: BOOST_UBLAS_CHECK (e1 ().size () == e2 ().size1 (), bad_size ()); sl@0: BOOST_UBLAS_CHECK (e2 ().size1 () == e2 ().size2 (), bad_size ()); sl@0: size_type size = e1 ().size (); sl@0: for (size_type n = 0; n < size; ++ n) { sl@0: #ifndef BOOST_UBLAS_SINGULAR_CHECK sl@0: BOOST_UBLAS_CHECK (e2 () (n, n) != value_type/*zero*/(), singular ()); sl@0: #else sl@0: if (e2 () (n, n) == value_type/*zero*/()) sl@0: singular ().raise (); sl@0: #endif sl@0: value_type t = e1 () (n) /= e2 () (n, n); sl@0: if (t != value_type/*zero*/()) { sl@0: for (size_type m = n + 1; m < size; ++ m) sl@0: e1 () (m) -= t * e2 () (n, m); sl@0: } sl@0: } sl@0: } sl@0: // Packed (proxy) case sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (vector_expression &e1, const matrix_expression &e2, sl@0: upper_tag, row_major_tag, packed_proxy_tag) { sl@0: typedef typename E1::size_type size_type; sl@0: typedef typename E1::difference_type difference_type; sl@0: typedef typename E1::value_type value_type; sl@0: sl@0: BOOST_UBLAS_CHECK (e1 ().size () == e2 ().size1 (), bad_size ()); sl@0: BOOST_UBLAS_CHECK (e2 ().size1 () == e2 ().size2 (), bad_size ()); sl@0: size_type size = e1 ().size (); sl@0: for (size_type n = 0; n < size; ++ n) { sl@0: #ifndef BOOST_UBLAS_SINGULAR_CHECK sl@0: BOOST_UBLAS_CHECK (e2 () (n, n) != value_type/*zero*/(), singular ()); sl@0: #else sl@0: if (e2 () (n, n) == value_type/*zero*/()) sl@0: singular ().raise (); sl@0: #endif sl@0: value_type t = e1 () (n) /= e2 () (n, n); sl@0: if (t != value_type/*zero*/()) { sl@0: typename E2::const_iterator2 it2e2 (e2 ().find2 (1, n, n + 1)); sl@0: typename E2::const_iterator2 it2e2_end (e2 ().find2 (1, n, e2 ().size2 ())); sl@0: difference_type m (it2e2_end - it2e2); sl@0: while (-- m >= 0) sl@0: e1 () (it2e2.index2 ()) -= *it2e2 * t, ++ it2e2; sl@0: } sl@0: } sl@0: } sl@0: // Sparse (proxy) case sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (vector_expression &e1, const matrix_expression &e2, sl@0: upper_tag, row_major_tag, unknown_storage_tag) { sl@0: typedef typename E1::size_type size_type; sl@0: typedef typename E1::difference_type difference_type; sl@0: typedef typename E1::value_type value_type; sl@0: sl@0: BOOST_UBLAS_CHECK (e1 ().size () == e2 ().size1 (), bad_size ()); sl@0: BOOST_UBLAS_CHECK (e2 ().size1 () == e2 ().size2 (), bad_size ()); sl@0: size_type size = e1 ().size (); sl@0: for (size_type n = 0; n < size; ++ n) { sl@0: #ifndef BOOST_UBLAS_SINGULAR_CHECK sl@0: BOOST_UBLAS_CHECK (e2 () (n, n) != value_type/*zero*/(), singular ()); sl@0: #else sl@0: if (e2 () (n, n) == value_type/*zero*/()) sl@0: singular ().raise (); sl@0: #endif sl@0: value_type t = e1 () (n) /= e2 () (n, n); sl@0: if (t != value_type/*zero*/()) { sl@0: typename E2::const_iterator2 it2e2 (e2 ().find2 (1, n, n + 1)); sl@0: typename E2::const_iterator2 it2e2_end (e2 ().find2 (1, n, e2 ().size2 ())); sl@0: while (it2e2 != it2e2_end) sl@0: e1 () (it2e2.index2 ()) -= *it2e2 * t, ++ it2e2; sl@0: } sl@0: } sl@0: } sl@0: // Redirectors :-) sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (vector_expression &e1, const matrix_expression &e2, sl@0: upper_tag, row_major_tag) { sl@0: typedef typename E1::storage_category storage_category; sl@0: inplace_solve (e1, e2, sl@0: upper_tag (), row_major_tag (), storage_category ()); sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (vector_expression &e1, const matrix_expression &e2, sl@0: upper_tag, column_major_tag) { sl@0: typedef typename E1::storage_category storage_category; sl@0: inplace_solve (trans (e2), e1, sl@0: lower_tag (), row_major_tag (), storage_category ()); sl@0: } sl@0: // Dispatcher sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (vector_expression &e1, const matrix_expression &e2, sl@0: upper_tag) { sl@0: typedef typename E2::orientation_category orientation_category; sl@0: inplace_solve (e1, e2, sl@0: upper_tag (), orientation_category ()); sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (vector_expression &e1, const matrix_expression &e2, sl@0: unit_upper_tag) { sl@0: typedef typename E2::orientation_category orientation_category; sl@0: inplace_solve (e1, triangular_adaptor (e2 ()), sl@0: unit_upper_tag (), orientation_category ()); sl@0: } sl@0: sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: typename matrix_vector_solve_traits::result_type sl@0: solve (const vector_expression &e1, sl@0: const matrix_expression &e2, sl@0: C) { sl@0: typename matrix_vector_solve_traits::result_type r (e1); sl@0: inplace_solve (r, e2, C ()); sl@0: return r; sl@0: } sl@0: sl@0: template sl@0: struct matrix_matrix_solve_traits { sl@0: typedef typename promote_traits::promote_type promote_type; sl@0: typedef matrix result_type; sl@0: }; sl@0: sl@0: // Operations: sl@0: // k * n * (n - 1) / 2 + k * n = k * n * (n + 1) / 2 multiplications, sl@0: // k * n * (n - 1) / 2 additions sl@0: sl@0: // Dense (proxy) case sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (const matrix_expression &e1, matrix_expression &e2, sl@0: lower_tag, dense_proxy_tag) { sl@0: typedef typename E2::size_type size_type; sl@0: typedef typename E2::difference_type difference_type; sl@0: typedef typename E2::value_type value_type; sl@0: sl@0: BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ()); sl@0: BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size1 (), bad_size ()); sl@0: size_type size1 = e2 ().size1 (); sl@0: size_type size2 = e2 ().size2 (); sl@0: for (size_type n = 0; n < size1; ++ n) { sl@0: #ifndef BOOST_UBLAS_SINGULAR_CHECK sl@0: BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ()); sl@0: #else sl@0: if (e1 () (n, n) == value_type/*zero*/()) sl@0: singular ().raise (); sl@0: #endif sl@0: for (size_type l = 0; l < size2; ++ l) { sl@0: value_type t = e2 () (n, l) /= e1 () (n, n); sl@0: if (t != value_type/*zero*/()) { sl@0: for (size_type m = n + 1; m < size1; ++ m) sl@0: e2 () (m, l) -= e1 () (m, n) * t; sl@0: } sl@0: } sl@0: } sl@0: } sl@0: // Packed (proxy) case sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (const matrix_expression &e1, matrix_expression &e2, sl@0: lower_tag, packed_proxy_tag) { sl@0: typedef typename E2::size_type size_type; sl@0: typedef typename E2::difference_type difference_type; sl@0: typedef typename E2::value_type value_type; sl@0: sl@0: BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ()); sl@0: BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size1 (), bad_size ()); sl@0: size_type size1 = e2 ().size1 (); sl@0: size_type size2 = e2 ().size2 (); sl@0: for (size_type n = 0; n < size1; ++ n) { sl@0: #ifndef BOOST_UBLAS_SINGULAR_CHECK sl@0: BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ()); sl@0: #else sl@0: if (e1 () (n, n) == value_type/*zero*/()) sl@0: singular ().raise (); sl@0: #endif sl@0: for (size_type l = 0; l < size2; ++ l) { sl@0: value_type t = e2 () (n, l) /= e1 () (n, n); sl@0: if (t != value_type/*zero*/()) { sl@0: typename E1::const_iterator1 it1e1 (e1 ().find1 (1, n + 1, n)); sl@0: typename E1::const_iterator1 it1e1_end (e1 ().find1 (1, e1 ().size1 (), n)); sl@0: difference_type m (it1e1_end - it1e1); sl@0: while (-- m >= 0) sl@0: e2 () (it1e1.index1 (), l) -= *it1e1 * t, ++ it1e1; sl@0: } sl@0: } sl@0: } sl@0: } sl@0: // Sparse (proxy) case sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (const matrix_expression &e1, matrix_expression &e2, sl@0: lower_tag, unknown_storage_tag) { sl@0: typedef typename E2::size_type size_type; sl@0: typedef typename E2::difference_type difference_type; sl@0: typedef typename E2::value_type value_type; sl@0: sl@0: BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ()); sl@0: BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size1 (), bad_size ()); sl@0: size_type size1 = e2 ().size1 (); sl@0: size_type size2 = e2 ().size2 (); sl@0: for (size_type n = 0; n < size1; ++ n) { sl@0: #ifndef BOOST_UBLAS_SINGULAR_CHECK sl@0: BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ()); sl@0: #else sl@0: if (e1 () (n, n) == value_type/*zero*/()) sl@0: singular ().raise (); sl@0: #endif sl@0: for (size_type l = 0; l < size2; ++ l) { sl@0: value_type t = e2 () (n, l) /= e1 () (n, n); sl@0: if (t != value_type/*zero*/()) { sl@0: typename E1::const_iterator1 it1e1 (e1 ().find1 (1, n + 1, n)); sl@0: typename E1::const_iterator1 it1e1_end (e1 ().find1 (1, e1 ().size1 (), n)); sl@0: while (it1e1 != it1e1_end) sl@0: e2 () (it1e1.index1 (), l) -= *it1e1 * t, ++ it1e1; sl@0: } sl@0: } sl@0: } sl@0: } sl@0: // Dispatcher sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (const matrix_expression &e1, matrix_expression &e2, sl@0: lower_tag) { sl@0: typedef typename E1::storage_category dispatch_category; sl@0: inplace_solve (e1, e2, sl@0: lower_tag (), dispatch_category ()); sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (const matrix_expression &e1, matrix_expression &e2, sl@0: unit_lower_tag) { sl@0: typedef typename E1::storage_category dispatch_category; sl@0: inplace_solve (triangular_adaptor (e1 ()), e2, sl@0: unit_lower_tag (), dispatch_category ()); sl@0: } sl@0: sl@0: // Dense (proxy) case sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (const matrix_expression &e1, matrix_expression &e2, sl@0: upper_tag, dense_proxy_tag) { sl@0: typedef typename E2::size_type size_type; sl@0: typedef typename E2::difference_type difference_type; sl@0: typedef typename E2::value_type value_type; sl@0: sl@0: BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ()); sl@0: BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size1 (), bad_size ()); sl@0: size_type size1 = e2 ().size1 (); sl@0: size_type size2 = e2 ().size2 (); sl@0: for (difference_type n = size1 - 1; n >= 0; -- n) { sl@0: #ifndef BOOST_UBLAS_SINGULAR_CHECK sl@0: BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ()); sl@0: #else sl@0: if (e1 () (n, n) == value_type/*zero*/()) sl@0: singular ().raise (); sl@0: #endif sl@0: for (difference_type l = size2 - 1; l >= 0; -- l) { sl@0: value_type t = e2 () (n, l) /= e1 () (n, n); sl@0: if (t != value_type/*zero*/()) { sl@0: for (difference_type m = n - 1; m >= 0; -- m) sl@0: e2 () (m, l) -= e1 () (m, n) * t; sl@0: } sl@0: } sl@0: } sl@0: } sl@0: // Packed (proxy) case sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (const matrix_expression &e1, matrix_expression &e2, sl@0: upper_tag, packed_proxy_tag) { sl@0: typedef typename E2::size_type size_type; sl@0: typedef typename E2::difference_type difference_type; sl@0: typedef typename E2::value_type value_type; sl@0: sl@0: BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ()); sl@0: BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size1 (), bad_size ()); sl@0: size_type size1 = e2 ().size1 (); sl@0: size_type size2 = e2 ().size2 (); sl@0: for (difference_type n = size1 - 1; n >= 0; -- n) { sl@0: #ifndef BOOST_UBLAS_SINGULAR_CHECK sl@0: BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ()); sl@0: #else sl@0: if (e1 () (n, n) == value_type/*zero*/()) sl@0: singular ().raise (); sl@0: #endif sl@0: for (difference_type l = size2 - 1; l >= 0; -- l) { sl@0: value_type t = e2 () (n, l) /= e1 () (n, n); sl@0: if (t != value_type/*zero*/()) { sl@0: typename E1::const_reverse_iterator1 it1e1 (e1 ().find1 (1, n, n)); sl@0: typename E1::const_reverse_iterator1 it1e1_rend (e1 ().find1 (1, 0, n)); sl@0: difference_type m (it1e1_rend - it1e1); sl@0: while (-- m >= 0) sl@0: e2 () (it1e1.index1 (), l) -= *it1e1 * t, ++ it1e1; sl@0: } sl@0: } sl@0: } sl@0: } sl@0: // Sparse (proxy) case sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (const matrix_expression &e1, matrix_expression &e2, sl@0: upper_tag, unknown_storage_tag) { sl@0: typedef typename E2::size_type size_type; sl@0: typedef typename E2::difference_type difference_type; sl@0: typedef typename E2::value_type value_type; sl@0: sl@0: BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ()); sl@0: BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size1 (), bad_size ()); sl@0: size_type size1 = e2 ().size1 (); sl@0: size_type size2 = e2 ().size2 (); sl@0: for (difference_type n = size1 - 1; n >= 0; -- n) { sl@0: #ifndef BOOST_UBLAS_SINGULAR_CHECK sl@0: BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ()); sl@0: #else sl@0: if (e1 () (n, n) == value_type/*zero*/()) sl@0: singular ().raise (); sl@0: #endif sl@0: for (difference_type l = size2 - 1; l >= 0; -- l) { sl@0: value_type t = e2 () (n, l) /= e1 () (n, n); sl@0: if (t != value_type/*zero*/()) { sl@0: typename E1::const_reverse_iterator1 it1e1 (e1 ().find1 (1, n, n)); sl@0: typename E1::const_reverse_iterator1 it1e1_rend (e1 ().find1 (1, 0, n)); sl@0: while (it1e1 != it1e1_rend) sl@0: e2 () (it1e1.index1 (), l) -= *it1e1 * t, ++ it1e1; sl@0: } sl@0: } sl@0: } sl@0: } sl@0: // Dispatcher sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (const matrix_expression &e1, matrix_expression &e2, sl@0: upper_tag) { sl@0: typedef typename E1::storage_category dispatch_category; sl@0: inplace_solve (e1, e2, sl@0: upper_tag (), dispatch_category ()); sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: void inplace_solve (const matrix_expression &e1, matrix_expression &e2, sl@0: unit_upper_tag) { sl@0: typedef typename E1::storage_category dispatch_category; sl@0: inplace_solve (triangular_adaptor (e1 ()), e2, sl@0: unit_upper_tag (), dispatch_category ()); sl@0: } sl@0: sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: typename matrix_matrix_solve_traits::result_type sl@0: solve (const matrix_expression &e1, sl@0: const matrix_expression &e2, sl@0: C) { sl@0: typename matrix_matrix_solve_traits::result_type r (e2); sl@0: inplace_solve (e1, r, C ()); sl@0: return r; sl@0: } sl@0: sl@0: }}} sl@0: sl@0: #endif