1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/numeric/ublas/banded.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,2025 @@
1.4 +//
1.5 +// Copyright (c) 2000-2002
1.6 +// Joerg Walter, Mathias Koch
1.7 +//
1.8 +// Permission to use, copy, modify, distribute and sell this software
1.9 +// and its documentation for any purpose is hereby granted without fee,
1.10 +// provided that the above copyright notice appear in all copies and
1.11 +// that both that copyright notice and this permission notice appear
1.12 +// in supporting documentation. The authors make no representations
1.13 +// about the suitability of this software for any purpose.
1.14 +// It is provided "as is" without express or implied warranty.
1.15 +//
1.16 +// The authors gratefully acknowledge the support of
1.17 +// GeNeSys mbH & Co. KG in producing this work.
1.18 +//
1.19 +
1.20 +#ifndef _BOOST_UBLAS_BANDED_
1.21 +#define _BOOST_UBLAS_BANDED_
1.22 +
1.23 +#include <boost/numeric/ublas/matrix.hpp>
1.24 +#include <boost/numeric/ublas/detail/temporary.hpp>
1.25 +
1.26 +// Iterators based on ideas of Jeremy Siek
1.27 +
1.28 +namespace boost { namespace numeric { namespace ublas {
1.29 +
1.30 + // Array based banded matrix class
1.31 + template<class T, class L, class A>
1.32 + class banded_matrix:
1.33 + public matrix_container<banded_matrix<T, L, A> > {
1.34 +
1.35 + typedef T *pointer;
1.36 + typedef L layout_type;
1.37 + typedef banded_matrix<T, L, A> self_type;
1.38 + public:
1.39 +#ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
1.40 + using matrix_container<self_type>::operator ();
1.41 +#endif
1.42 + typedef typename A::size_type size_type;
1.43 + typedef typename A::difference_type difference_type;
1.44 + typedef T value_type;
1.45 + typedef const T &const_reference;
1.46 + typedef T &reference;
1.47 + typedef A array_type;
1.48 + typedef const matrix_reference<const self_type> const_closure_type;
1.49 + typedef matrix_reference<self_type> closure_type;
1.50 + typedef vector<T, A> vector_temporary_type;
1.51 + typedef matrix<T, L, A> matrix_temporary_type; // general sub-matrix
1.52 + typedef packed_tag storage_category;
1.53 + typedef typename L::orientation_category orientation_category;
1.54 +
1.55 + // Construction and destruction
1.56 + BOOST_UBLAS_INLINE
1.57 + banded_matrix ():
1.58 + matrix_container<self_type> (),
1.59 + size1_ (0), size2_ (0),
1.60 + lower_ (0), upper_ (0), data_ (0) {}
1.61 + BOOST_UBLAS_INLINE
1.62 + banded_matrix (size_type size1, size_type size2, size_type lower = 0, size_type upper = 0):
1.63 + matrix_container<self_type> (),
1.64 + size1_ (size1), size2_ (size2),
1.65 + lower_ (lower), upper_ (upper), data_ ((std::max) (size1, size2) * (lower + 1 + upper)) {
1.66 + }
1.67 + BOOST_UBLAS_INLINE
1.68 + banded_matrix (size_type size1, size_type size2, size_type lower, size_type upper, const array_type &data):
1.69 + matrix_container<self_type> (),
1.70 + size1_ (size1), size2_ (size2),
1.71 + lower_ (lower), upper_ (upper), data_ (data) {}
1.72 + BOOST_UBLAS_INLINE
1.73 + banded_matrix (const banded_matrix &m):
1.74 + matrix_container<self_type> (),
1.75 + size1_ (m.size1_), size2_ (m.size2_),
1.76 + lower_ (m.lower_), upper_ (m.upper_), data_ (m.data_) {}
1.77 + template<class AE>
1.78 + BOOST_UBLAS_INLINE
1.79 + banded_matrix (const matrix_expression<AE> &ae, size_type lower = 0, size_type upper = 0):
1.80 + matrix_container<self_type> (),
1.81 + size1_ (ae ().size1 ()), size2_ (ae ().size2 ()),
1.82 + lower_ (lower), upper_ (upper),
1.83 + data_ ((std::max) (size1_, size2_) * (lower_ + 1 + upper_)) {
1.84 + matrix_assign<scalar_assign> (*this, ae);
1.85 + }
1.86 +
1.87 + // Accessors
1.88 + BOOST_UBLAS_INLINE
1.89 + size_type size1 () const {
1.90 + return size1_;
1.91 + }
1.92 + BOOST_UBLAS_INLINE
1.93 + size_type size2 () const {
1.94 + return size2_;
1.95 + }
1.96 + BOOST_UBLAS_INLINE
1.97 + size_type lower () const {
1.98 + return lower_;
1.99 + }
1.100 + BOOST_UBLAS_INLINE
1.101 + size_type upper () const {
1.102 + return upper_;
1.103 + }
1.104 +
1.105 + // Storage accessors
1.106 + BOOST_UBLAS_INLINE
1.107 + const array_type &data () const {
1.108 + return data_;
1.109 + }
1.110 + BOOST_UBLAS_INLINE
1.111 + array_type &data () {
1.112 + return data_;
1.113 + }
1.114 +
1.115 + // Resizing
1.116 + BOOST_UBLAS_INLINE
1.117 + void resize (size_type size1, size_type size2, size_type lower = 0, size_type upper = 0, bool preserve = true) {
1.118 + if (preserve) {
1.119 + self_type temporary (size1, size2, lower, upper);
1.120 + detail::matrix_resize_preserve<layout_type> (*this, temporary);
1.121 + }
1.122 + else {
1.123 + data ().resize ((std::max) (size1, size2) * (lower + 1 + upper));
1.124 + size1_ = size1;
1.125 + size2_ = size2;
1.126 + lower_ = lower;
1.127 + upper_ = upper;
1.128 + }
1.129 + }
1.130 +
1.131 + BOOST_UBLAS_INLINE
1.132 + void resize_packed_preserve (size_type size1, size_type size2, size_type lower = 0, size_type upper = 0) {
1.133 + size1_ = size1;
1.134 + size2_ = size2;
1.135 + lower_ = lower;
1.136 + upper_ = upper;
1.137 + data ().resize ((std::max) (size1, size2) * (lower + 1 + upper), value_type ());
1.138 + }
1.139 +
1.140 + // Element access
1.141 + BOOST_UBLAS_INLINE
1.142 + const_reference operator () (size_type i, size_type j) const {
1.143 + BOOST_UBLAS_CHECK (i < size1_, bad_index ());
1.144 + BOOST_UBLAS_CHECK (j < size2_, bad_index ());
1.145 +#ifdef BOOST_UBLAS_OWN_BANDED
1.146 + const size_type k = (std::max) (i, j);
1.147 + const size_type l = lower_ + j - i;
1.148 + if (k < (std::max) (size1_, size2_) &&
1.149 + l < lower_ + 1 + upper_)
1.150 + return data () [layout_type::element (k, (std::max) (size1_, size2_),
1.151 + l, lower_ + 1 + upper_)];
1.152 +#else
1.153 + const size_type k = j;
1.154 + const size_type l = upper_ + i - j;
1.155 + if (k < size2_ &&
1.156 + l < lower_ + 1 + upper_)
1.157 + return data () [layout_type::element (k, size2_,
1.158 + l, lower_ + 1 + upper_)];
1.159 +#endif
1.160 + return zero_;
1.161 + }
1.162 + BOOST_UBLAS_INLINE
1.163 + reference at_element (size_type i, size_type j) {
1.164 + BOOST_UBLAS_CHECK (i < size1_, bad_index ());
1.165 + BOOST_UBLAS_CHECK (j < size2_, bad_index ());
1.166 +#ifdef BOOST_UBLAS_OWN_BANDED
1.167 + const size_type k = (std::max) (i, j);
1.168 + const size_type l = lower_ + j - i;
1.169 + return data () [layout_type::element (k, (std::max) (size1_, size2_),
1.170 + l, lower_ + 1 + upper_)];
1.171 +#else
1.172 + const size_type k = j;
1.173 + const size_type l = upper_ + i - j;
1.174 + return data () [layout_type::element (k, size2_,
1.175 + l, lower_ + 1 + upper_)];
1.176 +#endif
1.177 + }
1.178 + BOOST_UBLAS_INLINE
1.179 + reference operator () (size_type i, size_type j) {
1.180 + BOOST_UBLAS_CHECK (i < size1_, bad_index ());
1.181 + BOOST_UBLAS_CHECK (j < size2_, bad_index ());
1.182 +#ifdef BOOST_UBLAS_OWN_BANDED
1.183 + const size_type k = (std::max) (i, j);
1.184 + const size_type l = lower_ + j - i;
1.185 + if (k < (std::max) (size1_, size2_) &&
1.186 + l < lower_ + 1 + upper_)
1.187 + return data () [layout_type::element (k, (std::max) (size1_, size2_),
1.188 + l, lower_ + 1 + upper_)];
1.189 +#else
1.190 + const size_type k = j;
1.191 + const size_type l = upper_ + i - j;
1.192 + if (k < size2_ &&
1.193 + l < lower_ + 1 + upper_)
1.194 + return data () [layout_type::element (k, size2_,
1.195 + l, lower_ + 1 + upper_)];
1.196 +#endif
1.197 + bad_index ().raise ();
1.198 + // arbitary return value
1.199 + return const_cast<reference>(zero_);
1.200 + }
1.201 +
1.202 + // Element assignment
1.203 + BOOST_UBLAS_INLINE
1.204 + reference insert_element (size_type i, size_type j, const_reference t) {
1.205 + return (operator () (i, j) = t);
1.206 + }
1.207 + BOOST_UBLAS_INLINE
1.208 + void erase_element (size_type i, size_type j) {
1.209 + operator () (i, j) = value_type/*zero*/();
1.210 + }
1.211 +
1.212 + // Zeroing
1.213 + BOOST_UBLAS_INLINE
1.214 + void clear () {
1.215 + std::fill (data ().begin (), data ().end (), value_type/*zero*/());
1.216 + }
1.217 +
1.218 + // Assignment
1.219 + BOOST_UBLAS_INLINE
1.220 + banded_matrix &operator = (const banded_matrix &m) {
1.221 + size1_ = m.size1_;
1.222 + size2_ = m.size2_;
1.223 + lower_ = m.lower_;
1.224 + upper_ = m.upper_;
1.225 + data () = m.data ();
1.226 + return *this;
1.227 + }
1.228 + BOOST_UBLAS_INLINE
1.229 + banded_matrix &assign_temporary (banded_matrix &m) {
1.230 + swap (m);
1.231 + return *this;
1.232 + }
1.233 + template<class AE>
1.234 + BOOST_UBLAS_INLINE
1.235 + banded_matrix &operator = (const matrix_expression<AE> &ae) {
1.236 + self_type temporary (ae, lower_, upper_);
1.237 + return assign_temporary (temporary);
1.238 + }
1.239 + template<class AE>
1.240 + BOOST_UBLAS_INLINE
1.241 + banded_matrix &assign (const matrix_expression<AE> &ae) {
1.242 + matrix_assign<scalar_assign> (*this, ae);
1.243 + return *this;
1.244 + }
1.245 + template<class AE>
1.246 + BOOST_UBLAS_INLINE
1.247 + banded_matrix& operator += (const matrix_expression<AE> &ae) {
1.248 + self_type temporary (*this + ae, lower_, upper_);
1.249 + return assign_temporary (temporary);
1.250 + }
1.251 + template<class AE>
1.252 + BOOST_UBLAS_INLINE
1.253 + banded_matrix &plus_assign (const matrix_expression<AE> &ae) {
1.254 + matrix_assign<scalar_plus_assign> (*this, ae);
1.255 + return *this;
1.256 + }
1.257 + template<class AE>
1.258 + BOOST_UBLAS_INLINE
1.259 + banded_matrix& operator -= (const matrix_expression<AE> &ae) {
1.260 + self_type temporary (*this - ae, lower_, upper_);
1.261 + return assign_temporary (temporary);
1.262 + }
1.263 + template<class AE>
1.264 + BOOST_UBLAS_INLINE
1.265 + banded_matrix &minus_assign (const matrix_expression<AE> &ae) {
1.266 + matrix_assign<scalar_minus_assign> (*this, ae);
1.267 + return *this;
1.268 + }
1.269 + template<class AT>
1.270 + BOOST_UBLAS_INLINE
1.271 + banded_matrix& operator *= (const AT &at) {
1.272 + matrix_assign_scalar<scalar_multiplies_assign> (*this, at);
1.273 + return *this;
1.274 + }
1.275 + template<class AT>
1.276 + BOOST_UBLAS_INLINE
1.277 + banded_matrix& operator /= (const AT &at) {
1.278 + matrix_assign_scalar<scalar_divides_assign> (*this, at);
1.279 + return *this;
1.280 + }
1.281 +
1.282 + // Swapping
1.283 + BOOST_UBLAS_INLINE
1.284 + void swap (banded_matrix &m) {
1.285 + if (this != &m) {
1.286 + std::swap (size1_, m.size1_);
1.287 + std::swap (size2_, m.size2_);
1.288 + std::swap (lower_, m.lower_);
1.289 + std::swap (upper_, m.upper_);
1.290 + data ().swap (m.data ());
1.291 + }
1.292 + }
1.293 + BOOST_UBLAS_INLINE
1.294 + friend void swap (banded_matrix &m1, banded_matrix &m2) {
1.295 + m1.swap (m2);
1.296 + }
1.297 +
1.298 + // Iterator types
1.299 +#ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
1.300 + typedef indexed_iterator1<self_type, packed_random_access_iterator_tag> iterator1;
1.301 + typedef indexed_iterator2<self_type, packed_random_access_iterator_tag> iterator2;
1.302 + typedef indexed_const_iterator1<self_type, packed_random_access_iterator_tag> const_iterator1;
1.303 + typedef indexed_const_iterator2<self_type, packed_random_access_iterator_tag> const_iterator2;
1.304 +#else
1.305 + class const_iterator1;
1.306 + class iterator1;
1.307 + class const_iterator2;
1.308 + class iterator2;
1.309 +#endif
1.310 + typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
1.311 + typedef reverse_iterator_base1<iterator1> reverse_iterator1;
1.312 + typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
1.313 + typedef reverse_iterator_base2<iterator2> reverse_iterator2;
1.314 +
1.315 + // Element lookup
1.316 + BOOST_UBLAS_INLINE
1.317 + const_iterator1 find1 (int rank, size_type i, size_type j) const {
1.318 + if (rank == 1) {
1.319 + size_type lower_i = (std::max) (difference_type (j - upper_), difference_type (0));
1.320 + i = (std::max) (i, lower_i);
1.321 + size_type upper_i = (std::min) (j + 1 + lower_, size1_);
1.322 + i = (std::min) (i, upper_i);
1.323 + }
1.324 + return const_iterator1 (*this, i, j);
1.325 + }
1.326 + BOOST_UBLAS_INLINE
1.327 + iterator1 find1 (int rank, size_type i, size_type j) {
1.328 + if (rank == 1) {
1.329 + size_type lower_i = (std::max) (difference_type (j - upper_), difference_type (0));
1.330 + i = (std::max) (i, lower_i);
1.331 + size_type upper_i = (std::min) (j + 1 + lower_, size1_);
1.332 + i = (std::min) (i, upper_i);
1.333 + }
1.334 + return iterator1 (*this, i, j);
1.335 + }
1.336 + BOOST_UBLAS_INLINE
1.337 + const_iterator2 find2 (int rank, size_type i, size_type j) const {
1.338 + if (rank == 1) {
1.339 + size_type lower_j = (std::max) (difference_type (i - lower_), difference_type (0));
1.340 + j = (std::max) (j, lower_j);
1.341 + size_type upper_j = (std::min) (i + 1 + upper_, size2_);
1.342 + j = (std::min) (j, upper_j);
1.343 + }
1.344 + return const_iterator2 (*this, i, j);
1.345 + }
1.346 + BOOST_UBLAS_INLINE
1.347 + iterator2 find2 (int rank, size_type i, size_type j) {
1.348 + if (rank == 1) {
1.349 + size_type lower_j = (std::max) (difference_type (i - lower_), difference_type (0));
1.350 + j = (std::max) (j, lower_j);
1.351 + size_type upper_j = (std::min) (i + 1 + upper_, size2_);
1.352 + j = (std::min) (j, upper_j);
1.353 + }
1.354 + return iterator2 (*this, i, j);
1.355 + }
1.356 +
1.357 + // Iterators simply are indices.
1.358 +
1.359 +#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
1.360 + class const_iterator1:
1.361 + public container_const_reference<banded_matrix>,
1.362 + public random_access_iterator_base<packed_random_access_iterator_tag,
1.363 + const_iterator1, value_type> {
1.364 + public:
1.365 + typedef typename banded_matrix::value_type value_type;
1.366 + typedef typename banded_matrix::difference_type difference_type;
1.367 + typedef typename banded_matrix::const_reference reference;
1.368 + typedef const typename banded_matrix::pointer pointer;
1.369 +
1.370 + typedef const_iterator2 dual_iterator_type;
1.371 + typedef const_reverse_iterator2 dual_reverse_iterator_type;
1.372 +
1.373 + // Construction and destruction
1.374 + BOOST_UBLAS_INLINE
1.375 + const_iterator1 ():
1.376 + container_const_reference<self_type> (), it1_ (), it2_ () {}
1.377 + BOOST_UBLAS_INLINE
1.378 + const_iterator1 (const self_type &m, size_type it1, size_type it2):
1.379 + container_const_reference<self_type> (m), it1_ (it1), it2_ (it2) {}
1.380 + BOOST_UBLAS_INLINE
1.381 + const_iterator1 (const iterator1 &it):
1.382 + container_const_reference<self_type> (it ()), it1_ (it.it1_), it2_ (it.it2_) {}
1.383 +
1.384 + // Arithmetic
1.385 + BOOST_UBLAS_INLINE
1.386 + const_iterator1 &operator ++ () {
1.387 + ++ it1_;
1.388 + return *this;
1.389 + }
1.390 + BOOST_UBLAS_INLINE
1.391 + const_iterator1 &operator -- () {
1.392 + -- it1_;
1.393 + return *this;
1.394 + }
1.395 + BOOST_UBLAS_INLINE
1.396 + const_iterator1 &operator += (difference_type n) {
1.397 + it1_ += n;
1.398 + return *this;
1.399 + }
1.400 + BOOST_UBLAS_INLINE
1.401 + const_iterator1 &operator -= (difference_type n) {
1.402 + it1_ -= n;
1.403 + return *this;
1.404 + }
1.405 + BOOST_UBLAS_INLINE
1.406 + difference_type operator - (const const_iterator1 &it) const {
1.407 + BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1.408 + BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
1.409 + return it1_ - it.it1_;
1.410 + }
1.411 +
1.412 + // Dereference
1.413 + BOOST_UBLAS_INLINE
1.414 + const_reference operator * () const {
1.415 + return (*this) () (it1_, it2_);
1.416 + }
1.417 + BOOST_UBLAS_INLINE
1.418 + const_reference operator [] (difference_type n) const {
1.419 + return *(*this + n);
1.420 + }
1.421 +
1.422 +#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
1.423 + BOOST_UBLAS_INLINE
1.424 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.425 + typename self_type::
1.426 +#endif
1.427 + const_iterator2 begin () const {
1.428 + return (*this) ().find2 (1, it1_, 0);
1.429 + }
1.430 + BOOST_UBLAS_INLINE
1.431 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.432 + typename self_type::
1.433 +#endif
1.434 + const_iterator2 end () const {
1.435 + return (*this) ().find2 (1, it1_, (*this) ().size2 ());
1.436 + }
1.437 + BOOST_UBLAS_INLINE
1.438 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.439 + typename self_type::
1.440 +#endif
1.441 + const_reverse_iterator2 rbegin () const {
1.442 + return const_reverse_iterator2 (end ());
1.443 + }
1.444 + BOOST_UBLAS_INLINE
1.445 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.446 + typename self_type::
1.447 +#endif
1.448 + const_reverse_iterator2 rend () const {
1.449 + return const_reverse_iterator2 (begin ());
1.450 + }
1.451 +#endif
1.452 +
1.453 + // Indices
1.454 + BOOST_UBLAS_INLINE
1.455 + size_type index1 () const {
1.456 + return it1_;
1.457 + }
1.458 + BOOST_UBLAS_INLINE
1.459 + size_type index2 () const {
1.460 + return it2_;
1.461 + }
1.462 +
1.463 + // Assignment
1.464 + BOOST_UBLAS_INLINE
1.465 + const_iterator1 &operator = (const const_iterator1 &it) {
1.466 + container_const_reference<self_type>::assign (&it ());
1.467 + it1_ = it.it1_;
1.468 + it2_ = it.it2_;
1.469 + return *this;
1.470 + }
1.471 +
1.472 + // Comparison
1.473 + BOOST_UBLAS_INLINE
1.474 + bool operator == (const const_iterator1 &it) const {
1.475 + BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1.476 + BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
1.477 + return it1_ == it.it1_;
1.478 + }
1.479 + BOOST_UBLAS_INLINE
1.480 + bool operator < (const const_iterator1 &it) const {
1.481 + BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1.482 + BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
1.483 + return it1_ < it.it1_;
1.484 + }
1.485 +
1.486 + private:
1.487 + size_type it1_;
1.488 + size_type it2_;
1.489 + };
1.490 +#endif
1.491 +
1.492 + BOOST_UBLAS_INLINE
1.493 + const_iterator1 begin1 () const {
1.494 + return find1 (0, 0, 0);
1.495 + }
1.496 + BOOST_UBLAS_INLINE
1.497 + const_iterator1 end1 () const {
1.498 + return find1 (0, size1_, 0);
1.499 + }
1.500 +
1.501 +#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
1.502 + class iterator1:
1.503 + public container_reference<banded_matrix>,
1.504 + public random_access_iterator_base<packed_random_access_iterator_tag,
1.505 + iterator1, value_type> {
1.506 + public:
1.507 + typedef typename banded_matrix::value_type value_type;
1.508 + typedef typename banded_matrix::difference_type difference_type;
1.509 + typedef typename banded_matrix::reference reference;
1.510 + typedef typename banded_matrix::pointer pointer;
1.511 +
1.512 + typedef iterator2 dual_iterator_type;
1.513 + typedef reverse_iterator2 dual_reverse_iterator_type;
1.514 +
1.515 + // Construction and destruction
1.516 + BOOST_UBLAS_INLINE
1.517 + iterator1 ():
1.518 + container_reference<self_type> (), it1_ (), it2_ () {}
1.519 + BOOST_UBLAS_INLINE
1.520 + iterator1 (self_type &m, size_type it1, size_type it2):
1.521 + container_reference<self_type> (m), it1_ (it1), it2_ (it2) {}
1.522 +
1.523 + // Arithmetic
1.524 + BOOST_UBLAS_INLINE
1.525 + iterator1 &operator ++ () {
1.526 + ++ it1_;
1.527 + return *this;
1.528 + }
1.529 + BOOST_UBLAS_INLINE
1.530 + iterator1 &operator -- () {
1.531 + -- it1_;
1.532 + return *this;
1.533 + }
1.534 + BOOST_UBLAS_INLINE
1.535 + iterator1 &operator += (difference_type n) {
1.536 + it1_ += n;
1.537 + return *this;
1.538 + }
1.539 + BOOST_UBLAS_INLINE
1.540 + iterator1 &operator -= (difference_type n) {
1.541 + it1_ -= n;
1.542 + return *this;
1.543 + }
1.544 + BOOST_UBLAS_INLINE
1.545 + difference_type operator - (const iterator1 &it) const {
1.546 + BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1.547 + BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
1.548 + return it1_ - it.it1_;
1.549 + }
1.550 +
1.551 + // Dereference
1.552 + BOOST_UBLAS_INLINE
1.553 + reference operator * () const {
1.554 + return (*this) ().at_element (it1_, it2_);
1.555 + }
1.556 + BOOST_UBLAS_INLINE
1.557 + reference operator [] (difference_type n) const {
1.558 + return *(*this + n);
1.559 + }
1.560 +
1.561 +#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
1.562 + BOOST_UBLAS_INLINE
1.563 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.564 + typename self_type::
1.565 +#endif
1.566 + iterator2 begin () const {
1.567 + return (*this) ().find2 (1, it1_, 0);
1.568 + }
1.569 + BOOST_UBLAS_INLINE
1.570 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.571 + typename self_type::
1.572 +#endif
1.573 + iterator2 end () const {
1.574 + return (*this) ().find2 (1, it1_, (*this) ().size2 ());
1.575 + }
1.576 + BOOST_UBLAS_INLINE
1.577 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.578 + typename self_type::
1.579 +#endif
1.580 + reverse_iterator2 rbegin () const {
1.581 + return reverse_iterator2 (end ());
1.582 + }
1.583 + BOOST_UBLAS_INLINE
1.584 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.585 + typename self_type::
1.586 +#endif
1.587 + reverse_iterator2 rend () const {
1.588 + return reverse_iterator2 (begin ());
1.589 + }
1.590 +#endif
1.591 +
1.592 + // Indices
1.593 + BOOST_UBLAS_INLINE
1.594 + size_type index1 () const {
1.595 + return it1_;
1.596 + }
1.597 + BOOST_UBLAS_INLINE
1.598 + size_type index2 () const {
1.599 + return it2_;
1.600 + }
1.601 +
1.602 + // Assignment
1.603 + BOOST_UBLAS_INLINE
1.604 + iterator1 &operator = (const iterator1 &it) {
1.605 + container_reference<self_type>::assign (&it ());
1.606 + it1_ = it.it1_;
1.607 + it2_ = it.it2_;
1.608 + return *this;
1.609 + }
1.610 +
1.611 + // Comparison
1.612 + BOOST_UBLAS_INLINE
1.613 + bool operator == (const iterator1 &it) const {
1.614 + BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1.615 + BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
1.616 + return it1_ == it.it1_;
1.617 + }
1.618 + BOOST_UBLAS_INLINE
1.619 + bool operator < (const iterator1 &it) const {
1.620 + BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1.621 + BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
1.622 + return it1_ < it.it1_;
1.623 + }
1.624 +
1.625 + private:
1.626 + size_type it1_;
1.627 + size_type it2_;
1.628 +
1.629 + friend class const_iterator1;
1.630 + };
1.631 +#endif
1.632 +
1.633 + BOOST_UBLAS_INLINE
1.634 + iterator1 begin1 () {
1.635 + return find1 (0, 0, 0);
1.636 + }
1.637 + BOOST_UBLAS_INLINE
1.638 + iterator1 end1 () {
1.639 + return find1 (0, size1_, 0);
1.640 + }
1.641 +
1.642 +#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
1.643 + class const_iterator2:
1.644 + public container_const_reference<banded_matrix>,
1.645 + public random_access_iterator_base<packed_random_access_iterator_tag,
1.646 + const_iterator2, value_type> {
1.647 + public:
1.648 + typedef typename banded_matrix::value_type value_type;
1.649 + typedef typename banded_matrix::difference_type difference_type;
1.650 + typedef typename banded_matrix::const_reference reference;
1.651 + typedef const typename banded_matrix::pointer pointer;
1.652 +
1.653 + typedef const_iterator1 dual_iterator_type;
1.654 + typedef const_reverse_iterator1 dual_reverse_iterator_type;
1.655 +
1.656 + // Construction and destruction
1.657 + BOOST_UBLAS_INLINE
1.658 + const_iterator2 ():
1.659 + container_const_reference<self_type> (), it1_ (), it2_ () {}
1.660 + BOOST_UBLAS_INLINE
1.661 + const_iterator2 (const self_type &m, size_type it1, size_type it2):
1.662 + container_const_reference<self_type> (m), it1_ (it1), it2_ (it2) {}
1.663 + BOOST_UBLAS_INLINE
1.664 + const_iterator2 (const iterator2 &it):
1.665 + container_const_reference<self_type> (it ()), it1_ (it.it1_), it2_ (it.it2_) {}
1.666 +
1.667 + // Arithmetic
1.668 + BOOST_UBLAS_INLINE
1.669 + const_iterator2 &operator ++ () {
1.670 + ++ it2_;
1.671 + return *this;
1.672 + }
1.673 + BOOST_UBLAS_INLINE
1.674 + const_iterator2 &operator -- () {
1.675 + -- it2_;
1.676 + return *this;
1.677 + }
1.678 + BOOST_UBLAS_INLINE
1.679 + const_iterator2 &operator += (difference_type n) {
1.680 + it2_ += n;
1.681 + return *this;
1.682 + }
1.683 + BOOST_UBLAS_INLINE
1.684 + const_iterator2 &operator -= (difference_type n) {
1.685 + it2_ -= n;
1.686 + return *this;
1.687 + }
1.688 + BOOST_UBLAS_INLINE
1.689 + difference_type operator - (const const_iterator2 &it) const {
1.690 + BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1.691 + BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
1.692 + return it2_ - it.it2_;
1.693 + }
1.694 +
1.695 + // Dereference
1.696 + BOOST_UBLAS_INLINE
1.697 + const_reference operator * () const {
1.698 + return (*this) () (it1_, it2_);
1.699 + }
1.700 + BOOST_UBLAS_INLINE
1.701 + const_reference operator [] (difference_type n) const {
1.702 + return *(*this + n);
1.703 + }
1.704 +
1.705 +#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
1.706 + BOOST_UBLAS_INLINE
1.707 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.708 + typename self_type::
1.709 +#endif
1.710 + const_iterator1 begin () const {
1.711 + return (*this) ().find1 (1, 0, it2_);
1.712 + }
1.713 + BOOST_UBLAS_INLINE
1.714 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.715 + typename self_type::
1.716 +#endif
1.717 + const_iterator1 end () const {
1.718 + return (*this) ().find1 (1, (*this) ().size1 (), it2_);
1.719 + }
1.720 + BOOST_UBLAS_INLINE
1.721 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.722 + typename self_type::
1.723 +#endif
1.724 + const_reverse_iterator1 rbegin () const {
1.725 + return const_reverse_iterator1 (end ());
1.726 + }
1.727 + BOOST_UBLAS_INLINE
1.728 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.729 + typename self_type::
1.730 +#endif
1.731 + const_reverse_iterator1 rend () const {
1.732 + return const_reverse_iterator1 (begin ());
1.733 + }
1.734 +#endif
1.735 +
1.736 + // Indices
1.737 + BOOST_UBLAS_INLINE
1.738 + size_type index1 () const {
1.739 + return it1_;
1.740 + }
1.741 + BOOST_UBLAS_INLINE
1.742 + size_type index2 () const {
1.743 + return it2_;
1.744 + }
1.745 +
1.746 + // Assignment
1.747 + BOOST_UBLAS_INLINE
1.748 + const_iterator2 &operator = (const const_iterator2 &it) {
1.749 + container_const_reference<self_type>::assign (&it ());
1.750 + it1_ = it.it1_;
1.751 + it2_ = it.it2_;
1.752 + return *this;
1.753 + }
1.754 +
1.755 + // Comparison
1.756 + BOOST_UBLAS_INLINE
1.757 + bool operator == (const const_iterator2 &it) const {
1.758 + BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1.759 + BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
1.760 + return it2_ == it.it2_;
1.761 + }
1.762 + BOOST_UBLAS_INLINE
1.763 + bool operator < (const const_iterator2 &it) const {
1.764 + BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1.765 + BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
1.766 + return it2_ < it.it2_;
1.767 + }
1.768 +
1.769 + private:
1.770 + size_type it1_;
1.771 + size_type it2_;
1.772 + };
1.773 +#endif
1.774 +
1.775 + BOOST_UBLAS_INLINE
1.776 + const_iterator2 begin2 () const {
1.777 + return find2 (0, 0, 0);
1.778 + }
1.779 + BOOST_UBLAS_INLINE
1.780 + const_iterator2 end2 () const {
1.781 + return find2 (0, 0, size2_);
1.782 + }
1.783 +
1.784 +#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
1.785 + class iterator2:
1.786 + public container_reference<banded_matrix>,
1.787 + public random_access_iterator_base<packed_random_access_iterator_tag,
1.788 + iterator2, value_type> {
1.789 + public:
1.790 + typedef typename banded_matrix::value_type value_type;
1.791 + typedef typename banded_matrix::difference_type difference_type;
1.792 + typedef typename banded_matrix::reference reference;
1.793 + typedef typename banded_matrix::pointer pointer;
1.794 +
1.795 + typedef iterator1 dual_iterator_type;
1.796 + typedef reverse_iterator1 dual_reverse_iterator_type;
1.797 +
1.798 + // Construction and destruction
1.799 + BOOST_UBLAS_INLINE
1.800 + iterator2 ():
1.801 + container_reference<self_type> (), it1_ (), it2_ () {}
1.802 + BOOST_UBLAS_INLINE
1.803 + iterator2 (self_type &m, size_type it1, size_type it2):
1.804 + container_reference<self_type> (m), it1_ (it1), it2_ (it2) {}
1.805 +
1.806 + // Arithmetic
1.807 + BOOST_UBLAS_INLINE
1.808 + iterator2 &operator ++ () {
1.809 + ++ it2_;
1.810 + return *this;
1.811 + }
1.812 + BOOST_UBLAS_INLINE
1.813 + iterator2 &operator -- () {
1.814 + -- it2_;
1.815 + return *this;
1.816 + }
1.817 + BOOST_UBLAS_INLINE
1.818 + iterator2 &operator += (difference_type n) {
1.819 + it2_ += n;
1.820 + return *this;
1.821 + }
1.822 + BOOST_UBLAS_INLINE
1.823 + iterator2 &operator -= (difference_type n) {
1.824 + it2_ -= n;
1.825 + return *this;
1.826 + }
1.827 + BOOST_UBLAS_INLINE
1.828 + difference_type operator - (const iterator2 &it) const {
1.829 + BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1.830 + BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
1.831 + return it2_ - it.it2_;
1.832 + }
1.833 +
1.834 + // Dereference
1.835 + BOOST_UBLAS_INLINE
1.836 + reference operator * () const {
1.837 + return (*this) ().at_element (it1_, it2_);
1.838 + }
1.839 + BOOST_UBLAS_INLINE
1.840 + reference operator [] (difference_type n) const {
1.841 + return *(*this + n);
1.842 + }
1.843 +
1.844 +#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
1.845 + BOOST_UBLAS_INLINE
1.846 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.847 + typename self_type::
1.848 +#endif
1.849 + iterator1 begin () const {
1.850 + return (*this) ().find1 (1, 0, it2_);
1.851 + }
1.852 + BOOST_UBLAS_INLINE
1.853 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.854 + typename self_type::
1.855 +#endif
1.856 + iterator1 end () const {
1.857 + return (*this) ().find1 (1, (*this) ().size1 (), it2_);
1.858 + }
1.859 + BOOST_UBLAS_INLINE
1.860 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.861 + typename self_type::
1.862 +#endif
1.863 + reverse_iterator1 rbegin () const {
1.864 + return reverse_iterator1 (end ());
1.865 + }
1.866 + BOOST_UBLAS_INLINE
1.867 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.868 + typename self_type::
1.869 +#endif
1.870 + reverse_iterator1 rend () const {
1.871 + return reverse_iterator1 (begin ());
1.872 + }
1.873 +#endif
1.874 +
1.875 + // Indices
1.876 + BOOST_UBLAS_INLINE
1.877 + size_type index1 () const {
1.878 + return it1_;
1.879 + }
1.880 + BOOST_UBLAS_INLINE
1.881 + size_type index2 () const {
1.882 + return it2_;
1.883 + }
1.884 +
1.885 + // Assignment
1.886 + BOOST_UBLAS_INLINE
1.887 + iterator2 &operator = (const iterator2 &it) {
1.888 + container_reference<self_type>::assign (&it ());
1.889 + it1_ = it.it1_;
1.890 + it2_ = it.it2_;
1.891 + return *this;
1.892 + }
1.893 +
1.894 + // Comparison
1.895 + BOOST_UBLAS_INLINE
1.896 + bool operator == (const iterator2 &it) const {
1.897 + BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1.898 + BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
1.899 + return it2_ == it.it2_;
1.900 + }
1.901 + BOOST_UBLAS_INLINE
1.902 + bool operator < (const iterator2 &it) const {
1.903 + BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1.904 + BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
1.905 + return it2_ < it.it2_;
1.906 + }
1.907 +
1.908 + private:
1.909 + size_type it1_;
1.910 + size_type it2_;
1.911 +
1.912 + friend class const_iterator2;
1.913 + };
1.914 +#endif
1.915 +
1.916 + BOOST_UBLAS_INLINE
1.917 + iterator2 begin2 () {
1.918 + return find2 (0, 0, 0);
1.919 + }
1.920 + BOOST_UBLAS_INLINE
1.921 + iterator2 end2 () {
1.922 + return find2 (0, 0, size2_);
1.923 + }
1.924 +
1.925 + // Reverse iterators
1.926 +
1.927 + BOOST_UBLAS_INLINE
1.928 + const_reverse_iterator1 rbegin1 () const {
1.929 + return const_reverse_iterator1 (end1 ());
1.930 + }
1.931 + BOOST_UBLAS_INLINE
1.932 + const_reverse_iterator1 rend1 () const {
1.933 + return const_reverse_iterator1 (begin1 ());
1.934 + }
1.935 +
1.936 + BOOST_UBLAS_INLINE
1.937 + reverse_iterator1 rbegin1 () {
1.938 + return reverse_iterator1 (end1 ());
1.939 + }
1.940 + BOOST_UBLAS_INLINE
1.941 + reverse_iterator1 rend1 () {
1.942 + return reverse_iterator1 (begin1 ());
1.943 + }
1.944 +
1.945 + BOOST_UBLAS_INLINE
1.946 + const_reverse_iterator2 rbegin2 () const {
1.947 + return const_reverse_iterator2 (end2 ());
1.948 + }
1.949 + BOOST_UBLAS_INLINE
1.950 + const_reverse_iterator2 rend2 () const {
1.951 + return const_reverse_iterator2 (begin2 ());
1.952 + }
1.953 +
1.954 + BOOST_UBLAS_INLINE
1.955 + reverse_iterator2 rbegin2 () {
1.956 + return reverse_iterator2 (end2 ());
1.957 + }
1.958 + BOOST_UBLAS_INLINE
1.959 + reverse_iterator2 rend2 () {
1.960 + return reverse_iterator2 (begin2 ());
1.961 + }
1.962 +
1.963 + private:
1.964 + size_type size1_;
1.965 + size_type size2_;
1.966 + size_type lower_;
1.967 + size_type upper_;
1.968 + array_type data_;
1.969 + typedef const value_type const_value_type;
1.970 + static const_value_type zero_;
1.971 + };
1.972 +
1.973 + template<class T, class L, class A>
1.974 + typename banded_matrix<T, L, A>::const_value_type banded_matrix<T, L, A>::zero_ = value_type/*zero*/();
1.975 +
1.976 +
1.977 + // Diagonal matrix class
1.978 + template<class T, class L, class A>
1.979 + class diagonal_matrix:
1.980 + public banded_matrix<T, L, A> {
1.981 + public:
1.982 + typedef typename A::size_type size_type;
1.983 + typedef banded_matrix<T, L, A> matrix_type;
1.984 + typedef A array_type;
1.985 +
1.986 + // Construction and destruction
1.987 + BOOST_UBLAS_INLINE
1.988 + diagonal_matrix ():
1.989 + matrix_type () {}
1.990 + BOOST_UBLAS_INLINE
1.991 + diagonal_matrix (size_type size):
1.992 + matrix_type (size, size) {}
1.993 + BOOST_UBLAS_INLINE
1.994 + diagonal_matrix (size_type size, const array_type& data):
1.995 + matrix_type (size, size, 0, 0, data) {}
1.996 + BOOST_UBLAS_INLINE
1.997 + diagonal_matrix (size_type size1, size_type size2):
1.998 + matrix_type (size1, size2) {}
1.999 + template<class AE>
1.1000 + BOOST_UBLAS_INLINE
1.1001 + diagonal_matrix (const matrix_expression<AE> &ae):
1.1002 + matrix_type (ae) {}
1.1003 + BOOST_UBLAS_INLINE
1.1004 + ~diagonal_matrix () {}
1.1005 +
1.1006 + // Assignment
1.1007 + BOOST_UBLAS_INLINE
1.1008 + diagonal_matrix &operator = (const diagonal_matrix &m) {
1.1009 + matrix_type::operator = (m);
1.1010 + return *this;
1.1011 + }
1.1012 + template<class AE>
1.1013 + BOOST_UBLAS_INLINE
1.1014 + diagonal_matrix &operator = (const matrix_expression<AE> &ae) {
1.1015 + matrix_type::operator = (ae);
1.1016 + return *this;
1.1017 + }
1.1018 + };
1.1019 +
1.1020 + // Banded matrix adaptor class
1.1021 + template<class M>
1.1022 + class banded_adaptor:
1.1023 + public matrix_expression<banded_adaptor<M> > {
1.1024 +
1.1025 + typedef banded_adaptor<M> self_type;
1.1026 + public:
1.1027 +#ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
1.1028 + using matrix_expression<self_type>::operator ();
1.1029 +#endif
1.1030 + typedef const M const_matrix_type;
1.1031 + typedef M matrix_type;
1.1032 + typedef typename M::size_type size_type;
1.1033 + typedef typename M::difference_type difference_type;
1.1034 + typedef typename M::value_type value_type;
1.1035 + typedef typename M::const_reference const_reference;
1.1036 + typedef typename boost::mpl::if_<boost::is_const<M>,
1.1037 + typename M::const_reference,
1.1038 + typename M::reference>::type reference;
1.1039 + typedef typename boost::mpl::if_<boost::is_const<M>,
1.1040 + typename M::const_closure_type,
1.1041 + typename M::closure_type>::type matrix_closure_type;
1.1042 + typedef const self_type const_closure_type;
1.1043 + typedef self_type closure_type;
1.1044 + // Replaced by _temporary_traits to avoid type requirements on M
1.1045 + //typedef typename M::vector_temporary_type vector_temporary_type;
1.1046 + //typedef typename M::matrix_temporary_type matrix_temporary_type;
1.1047 + typedef typename storage_restrict_traits<typename M::storage_category,
1.1048 + packed_proxy_tag>::storage_category storage_category;
1.1049 + typedef typename M::orientation_category orientation_category;
1.1050 +
1.1051 + // Construction and destruction
1.1052 + BOOST_UBLAS_INLINE
1.1053 + banded_adaptor (matrix_type &data, size_type lower = 0, size_type upper = 0):
1.1054 + matrix_expression<self_type> (),
1.1055 + data_ (data), lower_ (lower), upper_ (upper) {}
1.1056 + BOOST_UBLAS_INLINE
1.1057 + banded_adaptor (const banded_adaptor &m):
1.1058 + matrix_expression<self_type> (),
1.1059 + data_ (m.data_), lower_ (m.lower_), upper_ (m.upper_) {}
1.1060 +
1.1061 + // Accessors
1.1062 + BOOST_UBLAS_INLINE
1.1063 + size_type size1 () const {
1.1064 + return data_.size1 ();
1.1065 + }
1.1066 + BOOST_UBLAS_INLINE
1.1067 + size_type size2 () const {
1.1068 + return data_.size2 ();
1.1069 + }
1.1070 + BOOST_UBLAS_INLINE
1.1071 + size_type lower () const {
1.1072 + return lower_;
1.1073 + }
1.1074 + BOOST_UBLAS_INLINE
1.1075 + size_type upper () const {
1.1076 + return upper_;
1.1077 + }
1.1078 +
1.1079 + // Storage accessors
1.1080 + BOOST_UBLAS_INLINE
1.1081 + const matrix_closure_type &data () const {
1.1082 + return data_;
1.1083 + }
1.1084 + BOOST_UBLAS_INLINE
1.1085 + matrix_closure_type &data () {
1.1086 + return data_;
1.1087 + }
1.1088 +
1.1089 + // Element access
1.1090 +#ifndef BOOST_UBLAS_PROXY_CONST_MEMBER
1.1091 + BOOST_UBLAS_INLINE
1.1092 + const_reference operator () (size_type i, size_type j) const {
1.1093 + BOOST_UBLAS_CHECK (i < size1 (), bad_index ());
1.1094 + BOOST_UBLAS_CHECK (j < size2 (), bad_index ());
1.1095 +#ifdef BOOST_UBLAS_OWN_BANDED
1.1096 + size_type k = (std::max) (i, j);
1.1097 + size_type l = lower_ + j - i;
1.1098 + if (k < (std::max) (size1 (), size2 ()) &&
1.1099 + l < lower_ + 1 + upper_)
1.1100 + return data () (i, j);
1.1101 +#else
1.1102 + size_type k = j;
1.1103 + size_type l = upper_ + i - j;
1.1104 + if (k < size2 () &&
1.1105 + l < lower_ + 1 + upper_)
1.1106 + return data () (i, j);
1.1107 +#endif
1.1108 + return zero_;
1.1109 + }
1.1110 + BOOST_UBLAS_INLINE
1.1111 + reference operator () (size_type i, size_type j) {
1.1112 + BOOST_UBLAS_CHECK (i < size1 (), bad_index ());
1.1113 + BOOST_UBLAS_CHECK (j < size2 (), bad_index ());
1.1114 +#ifdef BOOST_UBLAS_OWN_BANDED
1.1115 + size_type k = (std::max) (i, j);
1.1116 + size_type l = lower_ + j - i;
1.1117 + if (k < (std::max) (size1 (), size2 ()) &&
1.1118 + l < lower_ + 1 + upper_)
1.1119 + return data () (i, j);
1.1120 +#else
1.1121 + size_type k = j;
1.1122 + size_type l = upper_ + i - j;
1.1123 + if (k < size2 () &&
1.1124 + l < lower_ + 1 + upper_)
1.1125 + return data () (i, j);
1.1126 +#endif
1.1127 +#ifndef BOOST_UBLAS_REFERENCE_CONST_MEMBER
1.1128 + bad_index ().raise ();
1.1129 +#endif
1.1130 + return const_cast<reference>(zero_);
1.1131 + }
1.1132 +#else
1.1133 + BOOST_UBLAS_INLINE
1.1134 + reference operator () (size_type i, size_type j) const {
1.1135 + BOOST_UBLAS_CHECK (i < size1 (), bad_index ());
1.1136 + BOOST_UBLAS_CHECK (j < size2 (), bad_index ());
1.1137 +#ifdef BOOST_UBLAS_OWN_BANDED
1.1138 + size_type k = (std::max) (i, j);
1.1139 + size_type l = lower_ + j - i;
1.1140 + if (k < (std::max) (size1 (), size2 ()) &&
1.1141 + l < lower_ + 1 + upper_)
1.1142 + return data () (i, j);
1.1143 +#else
1.1144 + size_type k = j;
1.1145 + size_type l = upper_ + i - j;
1.1146 + if (k < size2 () &&
1.1147 + l < lower_ + 1 + upper_)
1.1148 + return data () (i, j);
1.1149 +#endif
1.1150 +#ifndef BOOST_UBLAS_REFERENCE_CONST_MEMBER
1.1151 + bad_index ().raise ();
1.1152 +#endif
1.1153 + return const_cast<reference>(zero_);
1.1154 + }
1.1155 +#endif
1.1156 +
1.1157 + // Assignment
1.1158 + BOOST_UBLAS_INLINE
1.1159 + banded_adaptor &operator = (const banded_adaptor &m) {
1.1160 + matrix_assign<scalar_assign> (*this, m);
1.1161 + return *this;
1.1162 + }
1.1163 + BOOST_UBLAS_INLINE
1.1164 + banded_adaptor &assign_temporary (banded_adaptor &m) {
1.1165 + *this = m;
1.1166 + return *this;
1.1167 + }
1.1168 + template<class AE>
1.1169 + BOOST_UBLAS_INLINE
1.1170 + banded_adaptor &operator = (const matrix_expression<AE> &ae) {
1.1171 + matrix_assign<scalar_assign> (*this, matrix<value_type> (ae));
1.1172 + return *this;
1.1173 + }
1.1174 + template<class AE>
1.1175 + BOOST_UBLAS_INLINE
1.1176 + banded_adaptor &assign (const matrix_expression<AE> &ae) {
1.1177 + matrix_assign<scalar_assign> (*this, ae);
1.1178 + return *this;
1.1179 + }
1.1180 + template<class AE>
1.1181 + BOOST_UBLAS_INLINE
1.1182 + banded_adaptor& operator += (const matrix_expression<AE> &ae) {
1.1183 + matrix_assign<scalar_assign> (*this, matrix<value_type> (*this + ae));
1.1184 + return *this;
1.1185 + }
1.1186 + template<class AE>
1.1187 + BOOST_UBLAS_INLINE
1.1188 + banded_adaptor &plus_assign (const matrix_expression<AE> &ae) {
1.1189 + matrix_assign<scalar_plus_assign> (*this, ae);
1.1190 + return *this;
1.1191 + }
1.1192 + template<class AE>
1.1193 + BOOST_UBLAS_INLINE
1.1194 + banded_adaptor& operator -= (const matrix_expression<AE> &ae) {
1.1195 + matrix_assign<scalar_assign> (*this, matrix<value_type> (*this - ae));
1.1196 + return *this;
1.1197 + }
1.1198 + template<class AE>
1.1199 + BOOST_UBLAS_INLINE
1.1200 + banded_adaptor &minus_assign (const matrix_expression<AE> &ae) {
1.1201 + matrix_assign<scalar_minus_assign> (*this, ae);
1.1202 + return *this;
1.1203 + }
1.1204 + template<class AT>
1.1205 + BOOST_UBLAS_INLINE
1.1206 + banded_adaptor& operator *= (const AT &at) {
1.1207 + matrix_assign_scalar<scalar_multiplies_assign> (*this, at);
1.1208 + return *this;
1.1209 + }
1.1210 + template<class AT>
1.1211 + BOOST_UBLAS_INLINE
1.1212 + banded_adaptor& operator /= (const AT &at) {
1.1213 + matrix_assign_scalar<scalar_divides_assign> (*this, at);
1.1214 + return *this;
1.1215 + }
1.1216 +
1.1217 + // Closure comparison
1.1218 + BOOST_UBLAS_INLINE
1.1219 + bool same_closure (const banded_adaptor &ba) const {
1.1220 + return (*this).data ().same_closure (ba.data ());
1.1221 + }
1.1222 +
1.1223 + // Swapping
1.1224 + BOOST_UBLAS_INLINE
1.1225 + void swap (banded_adaptor &m) {
1.1226 + if (this != &m) {
1.1227 + BOOST_UBLAS_CHECK (lower_ == m.lower_, bad_size ());
1.1228 + BOOST_UBLAS_CHECK (upper_ == m.upper_, bad_size ());
1.1229 + matrix_swap<scalar_swap> (*this, m);
1.1230 + }
1.1231 + }
1.1232 + BOOST_UBLAS_INLINE
1.1233 + friend void swap (banded_adaptor &m1, banded_adaptor &m2) {
1.1234 + m1.swap (m2);
1.1235 + }
1.1236 +
1.1237 + // Iterator types
1.1238 + private:
1.1239 + // Use the matrix iterator
1.1240 + typedef typename M::const_iterator1 const_subiterator1_type;
1.1241 + typedef typename boost::mpl::if_<boost::is_const<M>,
1.1242 + typename M::const_iterator1,
1.1243 + typename M::iterator1>::type subiterator1_type;
1.1244 + typedef typename M::const_iterator2 const_subiterator2_type;
1.1245 + typedef typename boost::mpl::if_<boost::is_const<M>,
1.1246 + typename M::const_iterator2,
1.1247 + typename M::iterator2>::type subiterator2_type;
1.1248 +
1.1249 + public:
1.1250 +#ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
1.1251 + typedef indexed_iterator1<self_type, packed_random_access_iterator_tag> iterator1;
1.1252 + typedef indexed_iterator2<self_type, packed_random_access_iterator_tag> iterator2;
1.1253 + typedef indexed_const_iterator1<self_type, packed_random_access_iterator_tag> const_iterator1;
1.1254 + typedef indexed_const_iterator2<self_type, packed_random_access_iterator_tag> const_iterator2;
1.1255 +#else
1.1256 + class const_iterator1;
1.1257 + class iterator1;
1.1258 + class const_iterator2;
1.1259 + class iterator2;
1.1260 +#endif
1.1261 + typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
1.1262 + typedef reverse_iterator_base1<iterator1> reverse_iterator1;
1.1263 + typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
1.1264 + typedef reverse_iterator_base2<iterator2> reverse_iterator2;
1.1265 +
1.1266 + // Element lookup
1.1267 + BOOST_UBLAS_INLINE
1.1268 + const_iterator1 find1 (int rank, size_type i, size_type j) const {
1.1269 + if (rank == 1) {
1.1270 + size_type lower_i = (std::max) (difference_type (j - upper_), difference_type (0));
1.1271 + i = (std::max) (i, lower_i);
1.1272 + size_type upper_i = (std::min) (j + 1 + lower_, size1 ());
1.1273 + i = (std::min) (i, upper_i);
1.1274 + }
1.1275 + return const_iterator1 (*this, data ().find1 (rank, i, j));
1.1276 + }
1.1277 + BOOST_UBLAS_INLINE
1.1278 + iterator1 find1 (int rank, size_type i, size_type j) {
1.1279 + if (rank == 1) {
1.1280 + size_type lower_i = (std::max) (difference_type (j - upper_), difference_type (0));
1.1281 + i = (std::max) (i, lower_i);
1.1282 + size_type upper_i = (std::min) (j + 1 + lower_, size1 ());
1.1283 + i = (std::min) (i, upper_i);
1.1284 + }
1.1285 + return iterator1 (*this, data ().find1 (rank, i, j));
1.1286 + }
1.1287 + BOOST_UBLAS_INLINE
1.1288 + const_iterator2 find2 (int rank, size_type i, size_type j) const {
1.1289 + if (rank == 1) {
1.1290 + size_type lower_j = (std::max) (difference_type (i - lower_), difference_type (0));
1.1291 + j = (std::max) (j, lower_j);
1.1292 + size_type upper_j = (std::min) (i + 1 + upper_, size2 ());
1.1293 + j = (std::min) (j, upper_j);
1.1294 + }
1.1295 + return const_iterator2 (*this, data ().find2 (rank, i, j));
1.1296 + }
1.1297 + BOOST_UBLAS_INLINE
1.1298 + iterator2 find2 (int rank, size_type i, size_type j) {
1.1299 + if (rank == 1) {
1.1300 + size_type lower_j = (std::max) (difference_type (i - lower_), difference_type (0));
1.1301 + j = (std::max) (j, lower_j);
1.1302 + size_type upper_j = (std::min) (i + 1 + upper_, size2 ());
1.1303 + j = (std::min) (j, upper_j);
1.1304 + }
1.1305 + return iterator2 (*this, data ().find2 (rank, i, j));
1.1306 + }
1.1307 +
1.1308 + // Iterators simply are indices.
1.1309 +
1.1310 +#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
1.1311 + class const_iterator1:
1.1312 + public container_const_reference<banded_adaptor>,
1.1313 + public random_access_iterator_base<typename iterator_restrict_traits<
1.1314 + typename const_subiterator1_type::iterator_category, packed_random_access_iterator_tag>::iterator_category,
1.1315 + const_iterator1, value_type> {
1.1316 + public:
1.1317 + typedef typename const_subiterator1_type::value_type value_type;
1.1318 + typedef typename const_subiterator1_type::difference_type difference_type;
1.1319 + typedef typename const_subiterator1_type::reference reference;
1.1320 + typedef typename const_subiterator1_type::pointer pointer;
1.1321 +
1.1322 + typedef const_iterator2 dual_iterator_type;
1.1323 + typedef const_reverse_iterator2 dual_reverse_iterator_type;
1.1324 +
1.1325 + // Construction and destruction
1.1326 + BOOST_UBLAS_INLINE
1.1327 + const_iterator1 ():
1.1328 + container_const_reference<self_type> (), it1_ () {}
1.1329 + BOOST_UBLAS_INLINE
1.1330 + const_iterator1 (const self_type &m, const const_subiterator1_type &it1):
1.1331 + container_const_reference<self_type> (m), it1_ (it1) {}
1.1332 + BOOST_UBLAS_INLINE
1.1333 + const_iterator1 (const iterator1 &it):
1.1334 + container_const_reference<self_type> (it ()), it1_ (it.it1_) {}
1.1335 +
1.1336 + // Arithmetic
1.1337 + BOOST_UBLAS_INLINE
1.1338 + const_iterator1 &operator ++ () {
1.1339 + ++ it1_;
1.1340 + return *this;
1.1341 + }
1.1342 + BOOST_UBLAS_INLINE
1.1343 + const_iterator1 &operator -- () {
1.1344 + -- it1_;
1.1345 + return *this;
1.1346 + }
1.1347 + BOOST_UBLAS_INLINE
1.1348 + const_iterator1 &operator += (difference_type n) {
1.1349 + it1_ += n;
1.1350 + return *this;
1.1351 + }
1.1352 + BOOST_UBLAS_INLINE
1.1353 + const_iterator1 &operator -= (difference_type n) {
1.1354 + it1_ -= n;
1.1355 + return *this;
1.1356 + }
1.1357 + BOOST_UBLAS_INLINE
1.1358 + difference_type operator - (const const_iterator1 &it) const {
1.1359 + BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1.1360 + return it1_ - it.it1_;
1.1361 + }
1.1362 +
1.1363 + // Dereference
1.1364 + BOOST_UBLAS_INLINE
1.1365 + const_reference operator * () const {
1.1366 + size_type i = index1 ();
1.1367 + size_type j = index2 ();
1.1368 + BOOST_UBLAS_CHECK (i < (*this) ().size1 (), bad_index ());
1.1369 + BOOST_UBLAS_CHECK (j < (*this) ().size2 (), bad_index ());
1.1370 +#ifdef BOOST_UBLAS_OWN_BANDED
1.1371 + size_type k = (std::max) (i, j);
1.1372 + size_type l = (*this) ().lower () + j - i;
1.1373 + if (k < (std::max) ((*this) ().size1 (), (*this) ().size2 ()) &&
1.1374 + l < (*this) ().lower () + 1 + (*this) ().upper ())
1.1375 + return *it1_;
1.1376 +#else
1.1377 + size_type k = j;
1.1378 + size_type l = (*this) ().upper () + i - j;
1.1379 + if (k < (*this) ().size2 () &&
1.1380 + l < (*this) ().lower () + 1 + (*this) ().upper ())
1.1381 + return *it1_;
1.1382 +#endif
1.1383 + return (*this) () (i, j);
1.1384 + }
1.1385 + BOOST_UBLAS_INLINE
1.1386 + const_reference operator [] (difference_type n) const {
1.1387 + return *(*this + n);
1.1388 + }
1.1389 +
1.1390 +#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
1.1391 + BOOST_UBLAS_INLINE
1.1392 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.1393 + typename self_type::
1.1394 +#endif
1.1395 + const_iterator2 begin () const {
1.1396 + return (*this) ().find2 (1, index1 (), 0);
1.1397 + }
1.1398 + BOOST_UBLAS_INLINE
1.1399 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.1400 + typename self_type::
1.1401 +#endif
1.1402 + const_iterator2 end () const {
1.1403 + return (*this) ().find2 (1, index1 (), (*this) ().size2 ());
1.1404 + }
1.1405 + BOOST_UBLAS_INLINE
1.1406 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.1407 + typename self_type::
1.1408 +#endif
1.1409 + const_reverse_iterator2 rbegin () const {
1.1410 + return const_reverse_iterator2 (end ());
1.1411 + }
1.1412 + BOOST_UBLAS_INLINE
1.1413 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.1414 + typename self_type::
1.1415 +#endif
1.1416 + const_reverse_iterator2 rend () const {
1.1417 + return const_reverse_iterator2 (begin ());
1.1418 + }
1.1419 +#endif
1.1420 +
1.1421 + // Indices
1.1422 + BOOST_UBLAS_INLINE
1.1423 + size_type index1 () const {
1.1424 + return it1_.index1 ();
1.1425 + }
1.1426 + BOOST_UBLAS_INLINE
1.1427 + size_type index2 () const {
1.1428 + return it1_.index2 ();
1.1429 + }
1.1430 +
1.1431 + // Assignment
1.1432 + BOOST_UBLAS_INLINE
1.1433 + const_iterator1 &operator = (const const_iterator1 &it) {
1.1434 + container_const_reference<self_type>::assign (&it ());
1.1435 + it1_ = it.it1_;
1.1436 + return *this;
1.1437 + }
1.1438 +
1.1439 + // Comparison
1.1440 + BOOST_UBLAS_INLINE
1.1441 + bool operator == (const const_iterator1 &it) const {
1.1442 + BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1.1443 + return it1_ == it.it1_;
1.1444 + }
1.1445 + BOOST_UBLAS_INLINE
1.1446 + bool operator < (const const_iterator1 &it) const {
1.1447 + BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1.1448 + return it1_ < it.it1_;
1.1449 + }
1.1450 +
1.1451 + private:
1.1452 + const_subiterator1_type it1_;
1.1453 + };
1.1454 +#endif
1.1455 +
1.1456 + BOOST_UBLAS_INLINE
1.1457 + const_iterator1 begin1 () const {
1.1458 + return find1 (0, 0, 0);
1.1459 + }
1.1460 + BOOST_UBLAS_INLINE
1.1461 + const_iterator1 end1 () const {
1.1462 + return find1 (0, size1 (), 0);
1.1463 + }
1.1464 +
1.1465 +#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
1.1466 + class iterator1:
1.1467 + public container_reference<banded_adaptor>,
1.1468 + public random_access_iterator_base<typename iterator_restrict_traits<
1.1469 + typename subiterator1_type::iterator_category, packed_random_access_iterator_tag>::iterator_category,
1.1470 + iterator1, value_type> {
1.1471 + public:
1.1472 + typedef typename subiterator1_type::value_type value_type;
1.1473 + typedef typename subiterator1_type::difference_type difference_type;
1.1474 + typedef typename subiterator1_type::reference reference;
1.1475 + typedef typename subiterator1_type::pointer pointer;
1.1476 +
1.1477 + typedef iterator2 dual_iterator_type;
1.1478 + typedef reverse_iterator2 dual_reverse_iterator_type;
1.1479 +
1.1480 + // Construction and destruction
1.1481 + BOOST_UBLAS_INLINE
1.1482 + iterator1 ():
1.1483 + container_reference<self_type> (), it1_ () {}
1.1484 + BOOST_UBLAS_INLINE
1.1485 + iterator1 (self_type &m, const subiterator1_type &it1):
1.1486 + container_reference<self_type> (m), it1_ (it1) {}
1.1487 +
1.1488 + // Arithmetic
1.1489 + BOOST_UBLAS_INLINE
1.1490 + iterator1 &operator ++ () {
1.1491 + ++ it1_;
1.1492 + return *this;
1.1493 + }
1.1494 + BOOST_UBLAS_INLINE
1.1495 + iterator1 &operator -- () {
1.1496 + -- it1_;
1.1497 + return *this;
1.1498 + }
1.1499 + BOOST_UBLAS_INLINE
1.1500 + iterator1 &operator += (difference_type n) {
1.1501 + it1_ += n;
1.1502 + return *this;
1.1503 + }
1.1504 + BOOST_UBLAS_INLINE
1.1505 + iterator1 &operator -= (difference_type n) {
1.1506 + it1_ -= n;
1.1507 + return *this;
1.1508 + }
1.1509 + BOOST_UBLAS_INLINE
1.1510 + difference_type operator - (const iterator1 &it) const {
1.1511 + BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1.1512 + return it1_ - it.it1_;
1.1513 + }
1.1514 +
1.1515 + // Dereference
1.1516 + BOOST_UBLAS_INLINE
1.1517 + reference operator * () const {
1.1518 + size_type i = index1 ();
1.1519 + size_type j = index2 ();
1.1520 + BOOST_UBLAS_CHECK (i < (*this) ().size1 (), bad_index ());
1.1521 + BOOST_UBLAS_CHECK (j < (*this) ().size2 (), bad_index ());
1.1522 +#ifdef BOOST_UBLAS_OWN_BANDED
1.1523 + size_type k = (std::max) (i, j);
1.1524 + size_type l = (*this) ().lower () + j - i;
1.1525 + if (k < (std::max) ((*this) ().size1 (), (*this) ().size2 ()) &&
1.1526 + l < (*this) ().lower () + 1 + (*this) ().upper ())
1.1527 + return *it1_;
1.1528 +#else
1.1529 + size_type k = j;
1.1530 + size_type l = (*this) ().upper () + i - j;
1.1531 + if (k < (*this) ().size2 () &&
1.1532 + l < (*this) ().lower () + 1 + (*this) ().upper ())
1.1533 + return *it1_;
1.1534 +#endif
1.1535 + return (*this) () (i, j);
1.1536 + }
1.1537 + BOOST_UBLAS_INLINE
1.1538 + reference operator [] (difference_type n) const {
1.1539 + return *(*this + n);
1.1540 + }
1.1541 +
1.1542 +#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
1.1543 + BOOST_UBLAS_INLINE
1.1544 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.1545 + typename self_type::
1.1546 +#endif
1.1547 + iterator2 begin () const {
1.1548 + return (*this) ().find2 (1, index1 (), 0);
1.1549 + }
1.1550 + BOOST_UBLAS_INLINE
1.1551 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.1552 + typename self_type::
1.1553 +#endif
1.1554 + iterator2 end () const {
1.1555 + return (*this) ().find2 (1, index1 (), (*this) ().size2 ());
1.1556 + }
1.1557 + BOOST_UBLAS_INLINE
1.1558 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.1559 + typename self_type::
1.1560 +#endif
1.1561 + reverse_iterator2 rbegin () const {
1.1562 + return reverse_iterator2 (end ());
1.1563 + }
1.1564 + BOOST_UBLAS_INLINE
1.1565 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.1566 + typename self_type::
1.1567 +#endif
1.1568 + reverse_iterator2 rend () const {
1.1569 + return reverse_iterator2 (begin ());
1.1570 + }
1.1571 +#endif
1.1572 +
1.1573 + // Indices
1.1574 + BOOST_UBLAS_INLINE
1.1575 + size_type index1 () const {
1.1576 + return it1_.index1 ();
1.1577 + }
1.1578 + BOOST_UBLAS_INLINE
1.1579 + size_type index2 () const {
1.1580 + return it1_.index2 ();
1.1581 + }
1.1582 +
1.1583 + // Assignment
1.1584 + BOOST_UBLAS_INLINE
1.1585 + iterator1 &operator = (const iterator1 &it) {
1.1586 + container_reference<self_type>::assign (&it ());
1.1587 + it1_ = it.it1_;
1.1588 + return *this;
1.1589 + }
1.1590 +
1.1591 + // Comparison
1.1592 + BOOST_UBLAS_INLINE
1.1593 + bool operator == (const iterator1 &it) const {
1.1594 + BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1.1595 + return it1_ == it.it1_;
1.1596 + }
1.1597 + BOOST_UBLAS_INLINE
1.1598 + bool operator < (const iterator1 &it) const {
1.1599 + BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1.1600 + return it1_ < it.it1_;
1.1601 + }
1.1602 +
1.1603 + private:
1.1604 + subiterator1_type it1_;
1.1605 +
1.1606 + friend class const_iterator1;
1.1607 + };
1.1608 +#endif
1.1609 +
1.1610 + BOOST_UBLAS_INLINE
1.1611 + iterator1 begin1 () {
1.1612 + return find1 (0, 0, 0);
1.1613 + }
1.1614 + BOOST_UBLAS_INLINE
1.1615 + iterator1 end1 () {
1.1616 + return find1 (0, size1 (), 0);
1.1617 + }
1.1618 +
1.1619 +#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
1.1620 + class const_iterator2:
1.1621 + public container_const_reference<banded_adaptor>,
1.1622 + public random_access_iterator_base<packed_random_access_iterator_tag,
1.1623 + const_iterator2, value_type> {
1.1624 + public:
1.1625 + typedef typename iterator_restrict_traits<typename const_subiterator2_type::iterator_category,
1.1626 + packed_random_access_iterator_tag>::iterator_category iterator_category;
1.1627 + typedef typename const_subiterator2_type::value_type value_type;
1.1628 + typedef typename const_subiterator2_type::difference_type difference_type;
1.1629 + typedef typename const_subiterator2_type::reference reference;
1.1630 + typedef typename const_subiterator2_type::pointer pointer;
1.1631 +
1.1632 + typedef const_iterator1 dual_iterator_type;
1.1633 + typedef const_reverse_iterator1 dual_reverse_iterator_type;
1.1634 +
1.1635 + // Construction and destruction
1.1636 + BOOST_UBLAS_INLINE
1.1637 + const_iterator2 ():
1.1638 + container_const_reference<self_type> (), it2_ () {}
1.1639 + BOOST_UBLAS_INLINE
1.1640 + const_iterator2 (const self_type &m, const const_subiterator2_type &it2):
1.1641 + container_const_reference<self_type> (m), it2_ (it2) {}
1.1642 + BOOST_UBLAS_INLINE
1.1643 + const_iterator2 (const iterator2 &it):
1.1644 + container_const_reference<self_type> (it ()), it2_ (it.it2_) {}
1.1645 +
1.1646 + // Arithmetic
1.1647 + BOOST_UBLAS_INLINE
1.1648 + const_iterator2 &operator ++ () {
1.1649 + ++ it2_;
1.1650 + return *this;
1.1651 + }
1.1652 + BOOST_UBLAS_INLINE
1.1653 + const_iterator2 &operator -- () {
1.1654 + -- it2_;
1.1655 + return *this;
1.1656 + }
1.1657 + BOOST_UBLAS_INLINE
1.1658 + const_iterator2 &operator += (difference_type n) {
1.1659 + it2_ += n;
1.1660 + return *this;
1.1661 + }
1.1662 + BOOST_UBLAS_INLINE
1.1663 + const_iterator2 &operator -= (difference_type n) {
1.1664 + it2_ -= n;
1.1665 + return *this;
1.1666 + }
1.1667 + BOOST_UBLAS_INLINE
1.1668 + difference_type operator - (const const_iterator2 &it) const {
1.1669 + BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1.1670 + return it2_ - it.it2_;
1.1671 + }
1.1672 +
1.1673 + // Dereference
1.1674 + BOOST_UBLAS_INLINE
1.1675 + const_reference operator * () const {
1.1676 + size_type i = index1 ();
1.1677 + size_type j = index2 ();
1.1678 + BOOST_UBLAS_CHECK (i < (*this) ().size1 (), bad_index ());
1.1679 + BOOST_UBLAS_CHECK (j < (*this) ().size2 (), bad_index ());
1.1680 +#ifdef BOOST_UBLAS_OWN_BANDED
1.1681 + size_type k = (std::max) (i, j);
1.1682 + size_type l = (*this) ().lower () + j - i;
1.1683 + if (k < (std::max) ((*this) ().size1 (), (*this) ().size2 ()) &&
1.1684 + l < (*this) ().lower () + 1 + (*this) ().upper ())
1.1685 + return *it2_;
1.1686 +#else
1.1687 + size_type k = j;
1.1688 + size_type l = (*this) ().upper () + i - j;
1.1689 + if (k < (*this) ().size2 () &&
1.1690 + l < (*this) ().lower () + 1 + (*this) ().upper ())
1.1691 + return *it2_;
1.1692 +#endif
1.1693 + return (*this) () (i, j);
1.1694 + }
1.1695 + BOOST_UBLAS_INLINE
1.1696 + const_reference operator [] (difference_type n) const {
1.1697 + return *(*this + n);
1.1698 + }
1.1699 +
1.1700 +#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
1.1701 + BOOST_UBLAS_INLINE
1.1702 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.1703 + typename self_type::
1.1704 +#endif
1.1705 + const_iterator1 begin () const {
1.1706 + return (*this) ().find1 (1, 0, index2 ());
1.1707 + }
1.1708 + BOOST_UBLAS_INLINE
1.1709 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.1710 + typename self_type::
1.1711 +#endif
1.1712 + const_iterator1 end () const {
1.1713 + return (*this) ().find1 (1, (*this) ().size1 (), index2 ());
1.1714 + }
1.1715 + BOOST_UBLAS_INLINE
1.1716 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.1717 + typename self_type::
1.1718 +#endif
1.1719 + const_reverse_iterator1 rbegin () const {
1.1720 + return const_reverse_iterator1 (end ());
1.1721 + }
1.1722 + BOOST_UBLAS_INLINE
1.1723 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.1724 + typename self_type::
1.1725 +#endif
1.1726 + const_reverse_iterator1 rend () const {
1.1727 + return const_reverse_iterator1 (begin ());
1.1728 + }
1.1729 +#endif
1.1730 +
1.1731 + // Indices
1.1732 + BOOST_UBLAS_INLINE
1.1733 + size_type index1 () const {
1.1734 + return it2_.index1 ();
1.1735 + }
1.1736 + BOOST_UBLAS_INLINE
1.1737 + size_type index2 () const {
1.1738 + return it2_.index2 ();
1.1739 + }
1.1740 +
1.1741 + // Assignment
1.1742 + BOOST_UBLAS_INLINE
1.1743 + const_iterator2 &operator = (const const_iterator2 &it) {
1.1744 + container_const_reference<self_type>::assign (&it ());
1.1745 + it2_ = it.it2_;
1.1746 + return *this;
1.1747 + }
1.1748 +
1.1749 + // Comparison
1.1750 + BOOST_UBLAS_INLINE
1.1751 + bool operator == (const const_iterator2 &it) const {
1.1752 + BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1.1753 + return it2_ == it.it2_;
1.1754 + }
1.1755 + BOOST_UBLAS_INLINE
1.1756 + bool operator < (const const_iterator2 &it) const {
1.1757 + BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1.1758 + return it2_ < it.it2_;
1.1759 + }
1.1760 +
1.1761 + private:
1.1762 + const_subiterator2_type it2_;
1.1763 + };
1.1764 +#endif
1.1765 +
1.1766 + BOOST_UBLAS_INLINE
1.1767 + const_iterator2 begin2 () const {
1.1768 + return find2 (0, 0, 0);
1.1769 + }
1.1770 + BOOST_UBLAS_INLINE
1.1771 + const_iterator2 end2 () const {
1.1772 + return find2 (0, 0, size2 ());
1.1773 + }
1.1774 +
1.1775 +#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
1.1776 + class iterator2:
1.1777 + public container_reference<banded_adaptor>,
1.1778 + public random_access_iterator_base<typename iterator_restrict_traits<
1.1779 + typename subiterator2_type::iterator_category, packed_random_access_iterator_tag>::iterator_category,
1.1780 + iterator2, value_type> {
1.1781 + public:
1.1782 + typedef typename subiterator2_type::value_type value_type;
1.1783 + typedef typename subiterator2_type::difference_type difference_type;
1.1784 + typedef typename subiterator2_type::reference reference;
1.1785 + typedef typename subiterator2_type::pointer pointer;
1.1786 +
1.1787 + typedef iterator1 dual_iterator_type;
1.1788 + typedef reverse_iterator1 dual_reverse_iterator_type;
1.1789 +
1.1790 + // Construction and destruction
1.1791 + BOOST_UBLAS_INLINE
1.1792 + iterator2 ():
1.1793 + container_reference<self_type> (), it2_ () {}
1.1794 + BOOST_UBLAS_INLINE
1.1795 + iterator2 (self_type &m, const subiterator2_type &it2):
1.1796 + container_reference<self_type> (m), it2_ (it2) {}
1.1797 +
1.1798 + // Arithmetic
1.1799 + BOOST_UBLAS_INLINE
1.1800 + iterator2 &operator ++ () {
1.1801 + ++ it2_;
1.1802 + return *this;
1.1803 + }
1.1804 + BOOST_UBLAS_INLINE
1.1805 + iterator2 &operator -- () {
1.1806 + -- it2_;
1.1807 + return *this;
1.1808 + }
1.1809 + BOOST_UBLAS_INLINE
1.1810 + iterator2 &operator += (difference_type n) {
1.1811 + it2_ += n;
1.1812 + return *this;
1.1813 + }
1.1814 + BOOST_UBLAS_INLINE
1.1815 + iterator2 &operator -= (difference_type n) {
1.1816 + it2_ -= n;
1.1817 + return *this;
1.1818 + }
1.1819 + BOOST_UBLAS_INLINE
1.1820 + difference_type operator - (const iterator2 &it) const {
1.1821 + BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1.1822 + return it2_ - it.it2_;
1.1823 + }
1.1824 +
1.1825 + // Dereference
1.1826 + BOOST_UBLAS_INLINE
1.1827 + reference operator * () const {
1.1828 + size_type i = index1 ();
1.1829 + size_type j = index2 ();
1.1830 + BOOST_UBLAS_CHECK (i < (*this) ().size1 (), bad_index ());
1.1831 + BOOST_UBLAS_CHECK (j < (*this) ().size2 (), bad_index ());
1.1832 +#ifdef BOOST_UBLAS_OWN_BANDED
1.1833 + size_type k = (std::max) (i, j);
1.1834 + size_type l = (*this) ().lower () + j - i;
1.1835 + if (k < (std::max) ((*this) ().size1 (), (*this) ().size2 ()) &&
1.1836 + l < (*this) ().lower () + 1 + (*this) ().upper ())
1.1837 + return *it2_;
1.1838 +#else
1.1839 + size_type k = j;
1.1840 + size_type l = (*this) ().upper () + i - j;
1.1841 + if (k < (*this) ().size2 () &&
1.1842 + l < (*this) ().lower () + 1 + (*this) ().upper ())
1.1843 + return *it2_;
1.1844 +#endif
1.1845 + return (*this) () (i, j);
1.1846 + }
1.1847 + BOOST_UBLAS_INLINE
1.1848 + reference operator [] (difference_type n) const {
1.1849 + return *(*this + n);
1.1850 + }
1.1851 +
1.1852 +#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
1.1853 + BOOST_UBLAS_INLINE
1.1854 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.1855 + typename self_type::
1.1856 +#endif
1.1857 + iterator1 begin () const {
1.1858 + return (*this) ().find1 (1, 0, index2 ());
1.1859 + }
1.1860 + BOOST_UBLAS_INLINE
1.1861 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.1862 + typename self_type::
1.1863 +#endif
1.1864 + iterator1 end () const {
1.1865 + return (*this) ().find1 (1, (*this) ().size1 (), index2 ());
1.1866 + }
1.1867 + BOOST_UBLAS_INLINE
1.1868 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.1869 + typename self_type::
1.1870 +#endif
1.1871 + reverse_iterator1 rbegin () const {
1.1872 + return reverse_iterator1 (end ());
1.1873 + }
1.1874 + BOOST_UBLAS_INLINE
1.1875 +#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
1.1876 + typename self_type::
1.1877 +#endif
1.1878 + reverse_iterator1 rend () const {
1.1879 + return reverse_iterator1 (begin ());
1.1880 + }
1.1881 +#endif
1.1882 +
1.1883 + // Indices
1.1884 + BOOST_UBLAS_INLINE
1.1885 + size_type index1 () const {
1.1886 + return it2_.index1 ();
1.1887 + }
1.1888 + BOOST_UBLAS_INLINE
1.1889 + size_type index2 () const {
1.1890 + return it2_.index2 ();
1.1891 + }
1.1892 +
1.1893 + // Assignment
1.1894 + BOOST_UBLAS_INLINE
1.1895 + iterator2 &operator = (const iterator2 &it) {
1.1896 + container_reference<self_type>::assign (&it ());
1.1897 + it2_ = it.it2_;
1.1898 + return *this;
1.1899 + }
1.1900 +
1.1901 + // Comparison
1.1902 + BOOST_UBLAS_INLINE
1.1903 + bool operator == (const iterator2 &it) const {
1.1904 + BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1.1905 + return it2_ == it.it2_;
1.1906 + }
1.1907 + BOOST_UBLAS_INLINE
1.1908 + bool operator < (const iterator2 &it) const {
1.1909 + BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
1.1910 + return it2_ < it.it2_;
1.1911 + }
1.1912 +
1.1913 + private:
1.1914 + subiterator2_type it2_;
1.1915 +
1.1916 + friend class const_iterator2;
1.1917 + };
1.1918 +#endif
1.1919 +
1.1920 + BOOST_UBLAS_INLINE
1.1921 + iterator2 begin2 () {
1.1922 + return find2 (0, 0, 0);
1.1923 + }
1.1924 + BOOST_UBLAS_INLINE
1.1925 + iterator2 end2 () {
1.1926 + return find2 (0, 0, size2 ());
1.1927 + }
1.1928 +
1.1929 + // Reverse iterators
1.1930 +
1.1931 + BOOST_UBLAS_INLINE
1.1932 + const_reverse_iterator1 rbegin1 () const {
1.1933 + return const_reverse_iterator1 (end1 ());
1.1934 + }
1.1935 + BOOST_UBLAS_INLINE
1.1936 + const_reverse_iterator1 rend1 () const {
1.1937 + return const_reverse_iterator1 (begin1 ());
1.1938 + }
1.1939 +
1.1940 + BOOST_UBLAS_INLINE
1.1941 + reverse_iterator1 rbegin1 () {
1.1942 + return reverse_iterator1 (end1 ());
1.1943 + }
1.1944 + BOOST_UBLAS_INLINE
1.1945 + reverse_iterator1 rend1 () {
1.1946 + return reverse_iterator1 (begin1 ());
1.1947 + }
1.1948 +
1.1949 + BOOST_UBLAS_INLINE
1.1950 + const_reverse_iterator2 rbegin2 () const {
1.1951 + return const_reverse_iterator2 (end2 ());
1.1952 + }
1.1953 + BOOST_UBLAS_INLINE
1.1954 + const_reverse_iterator2 rend2 () const {
1.1955 + return const_reverse_iterator2 (begin2 ());
1.1956 + }
1.1957 +
1.1958 + BOOST_UBLAS_INLINE
1.1959 + reverse_iterator2 rbegin2 () {
1.1960 + return reverse_iterator2 (end2 ());
1.1961 + }
1.1962 + BOOST_UBLAS_INLINE
1.1963 + reverse_iterator2 rend2 () {
1.1964 + return reverse_iterator2 (begin2 ());
1.1965 + }
1.1966 +
1.1967 + private:
1.1968 + matrix_closure_type data_;
1.1969 + size_type lower_;
1.1970 + size_type upper_;
1.1971 + typedef const value_type const_value_type;
1.1972 + static const_value_type zero_;
1.1973 + };
1.1974 +
1.1975 + // Specialization for temporary_traits
1.1976 + template <class M>
1.1977 + struct vector_temporary_traits< banded_adaptor<M> >
1.1978 + : vector_temporary_traits< M > {} ;
1.1979 + template <class M>
1.1980 + struct vector_temporary_traits< const banded_adaptor<M> >
1.1981 + : vector_temporary_traits< M > {} ;
1.1982 +
1.1983 + template <class M>
1.1984 + struct matrix_temporary_traits< banded_adaptor<M> >
1.1985 + : matrix_temporary_traits< M > {} ;
1.1986 + template <class M>
1.1987 + struct matrix_temporary_traits< const banded_adaptor<M> >
1.1988 + : matrix_temporary_traits< M > {} ;
1.1989 +
1.1990 +
1.1991 + template<class M>
1.1992 + typename banded_adaptor<M>::const_value_type banded_adaptor<M>::zero_ = value_type/*zero*/();
1.1993 +
1.1994 + // Diagonal matrix adaptor class
1.1995 + template<class M>
1.1996 + class diagonal_adaptor:
1.1997 + public banded_adaptor<M> {
1.1998 + public:
1.1999 + typedef M matrix_type;
1.2000 + typedef banded_adaptor<M> adaptor_type;
1.2001 +
1.2002 + // Construction and destruction
1.2003 + BOOST_UBLAS_INLINE
1.2004 + diagonal_adaptor ():
1.2005 + adaptor_type () {}
1.2006 + BOOST_UBLAS_INLINE
1.2007 + diagonal_adaptor (matrix_type &data):
1.2008 + adaptor_type (data) {}
1.2009 + BOOST_UBLAS_INLINE
1.2010 + ~diagonal_adaptor () {}
1.2011 +
1.2012 + // Assignment
1.2013 + BOOST_UBLAS_INLINE
1.2014 + diagonal_adaptor &operator = (const diagonal_adaptor &m) {
1.2015 + adaptor_type::operator = (m);
1.2016 + return *this;
1.2017 + }
1.2018 + template<class AE>
1.2019 + BOOST_UBLAS_INLINE
1.2020 + diagonal_adaptor &operator = (const matrix_expression<AE> &ae) {
1.2021 + adaptor_type::operator = (ae);
1.2022 + return *this;
1.2023 + }
1.2024 + };
1.2025 +
1.2026 +}}}
1.2027 +
1.2028 +#endif