annotate DEPENDENCIES/generic/include/boost/numeric/ublas/triangular.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 //
Chris@16 2 // Copyright (c) 2000-2002
Chris@16 3 // Joerg Walter, Mathias Koch
Chris@16 4 //
Chris@16 5 // Distributed under the Boost Software License, Version 1.0. (See
Chris@16 6 // accompanying file LICENSE_1_0.txt or copy at
Chris@16 7 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 8 //
Chris@16 9 // The authors gratefully acknowledge the support of
Chris@16 10 // GeNeSys mbH & Co. KG in producing this work.
Chris@16 11 //
Chris@16 12
Chris@16 13 #ifndef _BOOST_UBLAS_TRIANGULAR_
Chris@16 14 #define _BOOST_UBLAS_TRIANGULAR_
Chris@16 15
Chris@16 16 #include <boost/numeric/ublas/matrix.hpp>
Chris@16 17 #include <boost/numeric/ublas/detail/temporary.hpp>
Chris@16 18 #include <boost/type_traits/remove_const.hpp>
Chris@16 19
Chris@16 20 // Iterators based on ideas of Jeremy Siek
Chris@16 21
Chris@16 22 namespace boost { namespace numeric { namespace ublas {
Chris@16 23
Chris@16 24 namespace detail {
Chris@16 25 using namespace boost::numeric::ublas;
Chris@16 26
Chris@16 27 // Matrix resizing algorithm
Chris@16 28 template <class L, class T, class M>
Chris@16 29 BOOST_UBLAS_INLINE
Chris@16 30 void matrix_resize_preserve (M& m, M& temporary) {
Chris@16 31 typedef L layout_type;
Chris@16 32 typedef T triangular_type;
Chris@16 33 typedef typename M::size_type size_type;
Chris@16 34 const size_type msize1 (m.size1 ()); // original size
Chris@16 35 const size_type msize2 (m.size2 ());
Chris@16 36 const size_type size1 (temporary.size1 ()); // new size is specified by temporary
Chris@16 37 const size_type size2 (temporary.size2 ());
Chris@16 38 // Common elements to preserve
Chris@16 39 const size_type size1_min = (std::min) (size1, msize1);
Chris@16 40 const size_type size2_min = (std::min) (size2, msize2);
Chris@16 41 // Order for major and minor sizes
Chris@16 42 const size_type major_size = layout_type::size_M (size1_min, size2_min);
Chris@16 43 const size_type minor_size = layout_type::size_m (size1_min, size2_min);
Chris@16 44 // Indexing copy over major
Chris@16 45 for (size_type major = 0; major != major_size; ++major) {
Chris@16 46 for (size_type minor = 0; minor != minor_size; ++minor) {
Chris@16 47 // find indexes - use invertability of element_ functions
Chris@16 48 const size_type i1 = layout_type::index_M(major, minor);
Chris@16 49 const size_type i2 = layout_type::index_m(major, minor);
Chris@16 50 if ( triangular_type::other(i1,i2) ) {
Chris@16 51 temporary.data () [triangular_type::element (layout_type (), i1, size1, i2, size2)] =
Chris@16 52 m.data() [triangular_type::element (layout_type (), i1, msize1, i2, msize2)];
Chris@16 53 }
Chris@16 54 }
Chris@16 55 }
Chris@16 56 m.assign_temporary (temporary);
Chris@16 57 }
Chris@16 58 }
Chris@16 59
Chris@16 60 /** \brief A triangular matrix of values of type \c T.
Chris@16 61 *
Chris@16 62 * For a \f$(n \times n )\f$-dimensional lower triangular matrix and if \f$0 \leq i < n\f$, \f$0 \leq j < n\f$ and \f$i>j\f$ holds,
Chris@16 63 * \f$m_{i,j}=0\f$. Furthermore if \f$m_{i,i}=1\f$, the matrix is called unit lower triangular.
Chris@16 64 *
Chris@16 65 * For a \f$(n \times n )\f$-dimensional upper triangular matrix and if \f$0 \leq i < n\f$, \f$0 \leq j < n\f$ and \f$i<j\f$ holds,
Chris@16 66 * \f$m_{i,j}=0\f$. Furthermore if \f$m_{i,i}=1\f$, the matrix is called unit upper triangular.
Chris@16 67 *
Chris@16 68 * The default storage for triangular matrices is packed. Orientation and storage can also be specified.
Chris@16 69 * Default is \c row_major and and unbounded_array. It is \b not required by the storage to initialize
Chris@16 70 * elements of the matrix.
Chris@16 71 *
Chris@16 72 * \tparam T the type of object stored in the matrix (like double, float, complex, etc...)
Chris@16 73 * \tparam TRI the type of the triangular matrix. It can either be \c lower or \c upper. Default is \c lower
Chris@16 74 * \tparam L the storage organization. It can be either \c row_major or \c column_major. Default is \c row_major
Chris@16 75 * \tparam A the type of Storage array. Default is \c unbounded_array
Chris@16 76 */
Chris@16 77 template<class T, class TRI, class L, class A>
Chris@16 78 class triangular_matrix:
Chris@16 79 public matrix_container<triangular_matrix<T, TRI, L, A> > {
Chris@16 80
Chris@16 81 typedef T *pointer;
Chris@16 82 typedef TRI triangular_type;
Chris@16 83 typedef L layout_type;
Chris@16 84 typedef triangular_matrix<T, TRI, L, A> self_type;
Chris@16 85 public:
Chris@16 86 #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
Chris@16 87 using matrix_container<self_type>::operator ();
Chris@16 88 #endif
Chris@16 89 typedef typename A::size_type size_type;
Chris@16 90 typedef typename A::difference_type difference_type;
Chris@16 91 typedef T value_type;
Chris@16 92 typedef const T &const_reference;
Chris@16 93 typedef T &reference;
Chris@16 94 typedef A array_type;
Chris@16 95
Chris@16 96 typedef const matrix_reference<const self_type> const_closure_type;
Chris@16 97 typedef matrix_reference<self_type> closure_type;
Chris@16 98 typedef vector<T, A> vector_temporary_type;
Chris@16 99 typedef matrix<T, L, A> matrix_temporary_type; // general sub-matrix
Chris@16 100 typedef packed_tag storage_category;
Chris@16 101 typedef typename L::orientation_category orientation_category;
Chris@16 102
Chris@16 103 // Construction and destruction
Chris@16 104 BOOST_UBLAS_INLINE
Chris@16 105 triangular_matrix ():
Chris@16 106 matrix_container<self_type> (),
Chris@16 107 size1_ (0), size2_ (0), data_ (0) {}
Chris@16 108 BOOST_UBLAS_INLINE
Chris@16 109 triangular_matrix (size_type size1, size_type size2):
Chris@16 110 matrix_container<self_type> (),
Chris@16 111 size1_ (size1), size2_ (size2), data_ (triangular_type::packed_size (layout_type (), size1, size2)) {
Chris@16 112 }
Chris@16 113 BOOST_UBLAS_INLINE
Chris@16 114 triangular_matrix (size_type size1, size_type size2, const array_type &data):
Chris@16 115 matrix_container<self_type> (),
Chris@16 116 size1_ (size1), size2_ (size2), data_ (data) {}
Chris@16 117 BOOST_UBLAS_INLINE
Chris@16 118 triangular_matrix (const triangular_matrix &m):
Chris@16 119 matrix_container<self_type> (),
Chris@16 120 size1_ (m.size1_), size2_ (m.size2_), data_ (m.data_) {}
Chris@16 121 template<class AE>
Chris@16 122 BOOST_UBLAS_INLINE
Chris@16 123 triangular_matrix (const matrix_expression<AE> &ae):
Chris@16 124 matrix_container<self_type> (),
Chris@16 125 size1_ (ae ().size1 ()), size2_ (ae ().size2 ()),
Chris@16 126 data_ (triangular_type::packed_size (layout_type (), size1_, size2_)) {
Chris@16 127 matrix_assign<scalar_assign> (*this, ae);
Chris@16 128 }
Chris@16 129
Chris@16 130 // Accessors
Chris@16 131 BOOST_UBLAS_INLINE
Chris@16 132 size_type size1 () const {
Chris@16 133 return size1_;
Chris@16 134 }
Chris@16 135 BOOST_UBLAS_INLINE
Chris@16 136 size_type size2 () const {
Chris@16 137 return size2_;
Chris@16 138 }
Chris@16 139
Chris@16 140 // Storage accessors
Chris@16 141 BOOST_UBLAS_INLINE
Chris@16 142 const array_type &data () const {
Chris@16 143 return data_;
Chris@16 144 }
Chris@16 145 BOOST_UBLAS_INLINE
Chris@16 146 array_type &data () {
Chris@16 147 return data_;
Chris@16 148 }
Chris@16 149
Chris@16 150 // Resizing
Chris@16 151 BOOST_UBLAS_INLINE
Chris@16 152 void resize (size_type size1, size_type size2, bool preserve = true) {
Chris@16 153 if (preserve) {
Chris@16 154 self_type temporary (size1, size2);
Chris@16 155 detail::matrix_resize_preserve<layout_type, triangular_type> (*this, temporary);
Chris@16 156 }
Chris@16 157 else {
Chris@16 158 data ().resize (triangular_type::packed_size (layout_type (), size1, size2));
Chris@16 159 size1_ = size1;
Chris@16 160 size2_ = size2;
Chris@16 161 }
Chris@16 162 }
Chris@16 163 BOOST_UBLAS_INLINE
Chris@16 164 void resize_packed_preserve (size_type size1, size_type size2) {
Chris@16 165 size1_ = size1;
Chris@16 166 size2_ = size2;
Chris@16 167 data ().resize (triangular_type::packed_size (layout_type (), size1_, size2_), value_type ());
Chris@16 168 }
Chris@16 169
Chris@16 170 // Element access
Chris@16 171 BOOST_UBLAS_INLINE
Chris@16 172 const_reference operator () (size_type i, size_type j) const {
Chris@16 173 BOOST_UBLAS_CHECK (i < size1_, bad_index ());
Chris@16 174 BOOST_UBLAS_CHECK (j < size2_, bad_index ());
Chris@16 175 if (triangular_type::other (i, j))
Chris@16 176 return data () [triangular_type::element (layout_type (), i, size1_, j, size2_)];
Chris@16 177 else if (triangular_type::one (i, j))
Chris@16 178 return one_;
Chris@16 179 else
Chris@16 180 return zero_;
Chris@16 181 }
Chris@16 182 BOOST_UBLAS_INLINE
Chris@16 183 reference at_element (size_type i, size_type j) {
Chris@16 184 BOOST_UBLAS_CHECK (i < size1_, bad_index ());
Chris@16 185 BOOST_UBLAS_CHECK (j < size2_, bad_index ());
Chris@16 186 return data () [triangular_type::element (layout_type (), i, size1_, j, size2_)];
Chris@16 187 }
Chris@16 188 BOOST_UBLAS_INLINE
Chris@16 189 reference operator () (size_type i, size_type j) {
Chris@16 190 BOOST_UBLAS_CHECK (i < size1_, bad_index ());
Chris@16 191 BOOST_UBLAS_CHECK (j < size2_, bad_index ());
Chris@16 192 if (!triangular_type::other (i, j)) {
Chris@16 193 bad_index ().raise ();
Chris@16 194 // NEVER reached
Chris@16 195 }
Chris@16 196 return data () [triangular_type::element (layout_type (), i, size1_, j, size2_)];
Chris@16 197 }
Chris@16 198
Chris@16 199 // Element assignment
Chris@16 200 BOOST_UBLAS_INLINE
Chris@16 201 reference insert_element (size_type i, size_type j, const_reference t) {
Chris@16 202 return (operator () (i, j) = t);
Chris@16 203 }
Chris@16 204 BOOST_UBLAS_INLINE
Chris@16 205 void erase_element (size_type i, size_type j) {
Chris@16 206 operator () (i, j) = value_type/*zero*/();
Chris@16 207 }
Chris@16 208
Chris@16 209 // Zeroing
Chris@16 210 BOOST_UBLAS_INLINE
Chris@16 211 void clear () {
Chris@16 212 // data ().clear ();
Chris@16 213 std::fill (data ().begin (), data ().end (), value_type/*zero*/());
Chris@16 214 }
Chris@16 215
Chris@16 216 // Assignment
Chris@16 217 BOOST_UBLAS_INLINE
Chris@16 218 triangular_matrix &operator = (const triangular_matrix &m) {
Chris@16 219 size1_ = m.size1_;
Chris@16 220 size2_ = m.size2_;
Chris@16 221 data () = m.data ();
Chris@16 222 return *this;
Chris@16 223 }
Chris@16 224 BOOST_UBLAS_INLINE
Chris@16 225 triangular_matrix &assign_temporary (triangular_matrix &m) {
Chris@16 226 swap (m);
Chris@16 227 return *this;
Chris@16 228 }
Chris@16 229 template<class AE>
Chris@16 230 BOOST_UBLAS_INLINE
Chris@16 231 triangular_matrix &operator = (const matrix_expression<AE> &ae) {
Chris@16 232 self_type temporary (ae);
Chris@16 233 return assign_temporary (temporary);
Chris@16 234 }
Chris@16 235 template<class AE>
Chris@16 236 BOOST_UBLAS_INLINE
Chris@16 237 triangular_matrix &assign (const matrix_expression<AE> &ae) {
Chris@16 238 matrix_assign<scalar_assign> (*this, ae);
Chris@16 239 return *this;
Chris@16 240 }
Chris@16 241 template<class AE>
Chris@16 242 BOOST_UBLAS_INLINE
Chris@16 243 triangular_matrix& operator += (const matrix_expression<AE> &ae) {
Chris@16 244 self_type temporary (*this + ae);
Chris@16 245 return assign_temporary (temporary);
Chris@16 246 }
Chris@16 247 template<class AE>
Chris@16 248 BOOST_UBLAS_INLINE
Chris@16 249 triangular_matrix &plus_assign (const matrix_expression<AE> &ae) {
Chris@16 250 matrix_assign<scalar_plus_assign> (*this, ae);
Chris@16 251 return *this;
Chris@16 252 }
Chris@16 253 template<class AE>
Chris@16 254 BOOST_UBLAS_INLINE
Chris@16 255 triangular_matrix& operator -= (const matrix_expression<AE> &ae) {
Chris@16 256 self_type temporary (*this - ae);
Chris@16 257 return assign_temporary (temporary);
Chris@16 258 }
Chris@16 259 template<class AE>
Chris@16 260 BOOST_UBLAS_INLINE
Chris@16 261 triangular_matrix &minus_assign (const matrix_expression<AE> &ae) {
Chris@16 262 matrix_assign<scalar_minus_assign> (*this, ae);
Chris@16 263 return *this;
Chris@16 264 }
Chris@16 265 template<class AT>
Chris@16 266 BOOST_UBLAS_INLINE
Chris@16 267 triangular_matrix& operator *= (const AT &at) {
Chris@16 268 matrix_assign_scalar<scalar_multiplies_assign> (*this, at);
Chris@16 269 return *this;
Chris@16 270 }
Chris@16 271 template<class AT>
Chris@16 272 BOOST_UBLAS_INLINE
Chris@16 273 triangular_matrix& operator /= (const AT &at) {
Chris@16 274 matrix_assign_scalar<scalar_divides_assign> (*this, at);
Chris@16 275 return *this;
Chris@16 276 }
Chris@16 277
Chris@16 278 // Swapping
Chris@16 279 BOOST_UBLAS_INLINE
Chris@16 280 void swap (triangular_matrix &m) {
Chris@16 281 if (this != &m) {
Chris@16 282 // BOOST_UBLAS_CHECK (size2_ == m.size2_, bad_size ());
Chris@16 283 std::swap (size1_, m.size1_);
Chris@16 284 std::swap (size2_, m.size2_);
Chris@16 285 data ().swap (m.data ());
Chris@16 286 }
Chris@16 287 }
Chris@16 288 BOOST_UBLAS_INLINE
Chris@16 289 friend void swap (triangular_matrix &m1, triangular_matrix &m2) {
Chris@16 290 m1.swap (m2);
Chris@16 291 }
Chris@16 292
Chris@16 293 // Iterator types
Chris@16 294 #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
Chris@16 295 typedef indexed_iterator1<self_type, packed_random_access_iterator_tag> iterator1;
Chris@16 296 typedef indexed_iterator2<self_type, packed_random_access_iterator_tag> iterator2;
Chris@16 297 typedef indexed_const_iterator1<self_type, packed_random_access_iterator_tag> const_iterator1;
Chris@16 298 typedef indexed_const_iterator2<self_type, packed_random_access_iterator_tag> const_iterator2;
Chris@16 299 #else
Chris@16 300 class const_iterator1;
Chris@16 301 class iterator1;
Chris@16 302 class const_iterator2;
Chris@16 303 class iterator2;
Chris@16 304 #endif
Chris@16 305 typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
Chris@16 306 typedef reverse_iterator_base1<iterator1> reverse_iterator1;
Chris@16 307 typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
Chris@16 308 typedef reverse_iterator_base2<iterator2> reverse_iterator2;
Chris@16 309
Chris@16 310 // Element lookup
Chris@16 311 BOOST_UBLAS_INLINE
Chris@16 312 const_iterator1 find1 (int rank, size_type i, size_type j) const {
Chris@16 313 if (rank == 1)
Chris@16 314 i = triangular_type::restrict1 (i, j, size1_, size2_);
Chris@16 315 if (rank == 0)
Chris@16 316 i = triangular_type::global_restrict1 (i, size1_, j, size2_);
Chris@16 317 return const_iterator1 (*this, i, j);
Chris@16 318 }
Chris@16 319 BOOST_UBLAS_INLINE
Chris@16 320 iterator1 find1 (int rank, size_type i, size_type j) {
Chris@16 321 if (rank == 1)
Chris@16 322 i = triangular_type::mutable_restrict1 (i, j, size1_, size2_);
Chris@16 323 if (rank == 0)
Chris@16 324 i = triangular_type::global_mutable_restrict1 (i, size1_, j, size2_);
Chris@16 325 return iterator1 (*this, i, j);
Chris@16 326 }
Chris@16 327 BOOST_UBLAS_INLINE
Chris@16 328 const_iterator2 find2 (int rank, size_type i, size_type j) const {
Chris@16 329 if (rank == 1)
Chris@16 330 j = triangular_type::restrict2 (i, j, size1_, size2_);
Chris@16 331 if (rank == 0)
Chris@16 332 j = triangular_type::global_restrict2 (i, size1_, j, size2_);
Chris@16 333 return const_iterator2 (*this, i, j);
Chris@16 334 }
Chris@16 335 BOOST_UBLAS_INLINE
Chris@16 336 iterator2 find2 (int rank, size_type i, size_type j) {
Chris@16 337 if (rank == 1)
Chris@16 338 j = triangular_type::mutable_restrict2 (i, j, size1_, size2_);
Chris@16 339 if (rank == 0)
Chris@16 340 j = triangular_type::global_mutable_restrict2 (i, size1_, j, size2_);
Chris@16 341 return iterator2 (*this, i, j);
Chris@16 342 }
Chris@16 343
Chris@16 344 // Iterators simply are indices.
Chris@16 345
Chris@16 346 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
Chris@16 347 class const_iterator1:
Chris@16 348 public container_const_reference<triangular_matrix>,
Chris@16 349 public random_access_iterator_base<packed_random_access_iterator_tag,
Chris@16 350 const_iterator1, value_type> {
Chris@16 351 public:
Chris@16 352 typedef typename triangular_matrix::value_type value_type;
Chris@16 353 typedef typename triangular_matrix::difference_type difference_type;
Chris@16 354 typedef typename triangular_matrix::const_reference reference;
Chris@16 355 typedef const typename triangular_matrix::pointer pointer;
Chris@16 356
Chris@16 357 typedef const_iterator2 dual_iterator_type;
Chris@16 358 typedef const_reverse_iterator2 dual_reverse_iterator_type;
Chris@16 359
Chris@16 360 // Construction and destruction
Chris@16 361 BOOST_UBLAS_INLINE
Chris@16 362 const_iterator1 ():
Chris@16 363 container_const_reference<self_type> (), it1_ (), it2_ () {}
Chris@16 364 BOOST_UBLAS_INLINE
Chris@16 365 const_iterator1 (const self_type &m, size_type it1, size_type it2):
Chris@16 366 container_const_reference<self_type> (m), it1_ (it1), it2_ (it2) {}
Chris@16 367 BOOST_UBLAS_INLINE
Chris@16 368 const_iterator1 (const iterator1 &it):
Chris@16 369 container_const_reference<self_type> (it ()), it1_ (it.it1_), it2_ (it.it2_) {}
Chris@16 370
Chris@16 371 // Arithmetic
Chris@16 372 BOOST_UBLAS_INLINE
Chris@16 373 const_iterator1 &operator ++ () {
Chris@16 374 ++ it1_;
Chris@16 375 return *this;
Chris@16 376 }
Chris@16 377 BOOST_UBLAS_INLINE
Chris@16 378 const_iterator1 &operator -- () {
Chris@16 379 -- it1_;
Chris@16 380 return *this;
Chris@16 381 }
Chris@16 382 BOOST_UBLAS_INLINE
Chris@16 383 const_iterator1 &operator += (difference_type n) {
Chris@16 384 it1_ += n;
Chris@16 385 return *this;
Chris@16 386 }
Chris@16 387 BOOST_UBLAS_INLINE
Chris@16 388 const_iterator1 &operator -= (difference_type n) {
Chris@16 389 it1_ -= n;
Chris@16 390 return *this;
Chris@16 391 }
Chris@16 392 BOOST_UBLAS_INLINE
Chris@16 393 difference_type operator - (const const_iterator1 &it) const {
Chris@16 394 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 395 BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
Chris@16 396 return it1_ - it.it1_;
Chris@16 397 }
Chris@16 398
Chris@16 399 // Dereference
Chris@16 400 BOOST_UBLAS_INLINE
Chris@16 401 const_reference operator * () const {
Chris@16 402 return (*this) () (it1_, it2_);
Chris@16 403 }
Chris@16 404 BOOST_UBLAS_INLINE
Chris@16 405 const_reference operator [] (difference_type n) const {
Chris@16 406 return *(*this + n);
Chris@16 407 }
Chris@16 408
Chris@16 409 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
Chris@16 410 BOOST_UBLAS_INLINE
Chris@16 411 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 412 typename self_type::
Chris@16 413 #endif
Chris@16 414 const_iterator2 begin () const {
Chris@16 415 return (*this) ().find2 (1, it1_, 0);
Chris@16 416 }
Chris@16 417 BOOST_UBLAS_INLINE
Chris@16 418 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 419 typename self_type::
Chris@16 420 #endif
Chris@101 421 const_iterator2 cbegin () const {
Chris@101 422 return begin ();
Chris@101 423 }
Chris@101 424 BOOST_UBLAS_INLINE
Chris@101 425 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@101 426 typename self_type::
Chris@101 427 #endif
Chris@16 428 const_iterator2 end () const {
Chris@16 429 return (*this) ().find2 (1, it1_, (*this) ().size2 ());
Chris@16 430 }
Chris@16 431 BOOST_UBLAS_INLINE
Chris@16 432 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 433 typename self_type::
Chris@16 434 #endif
Chris@101 435 const_iterator2 cend () const {
Chris@101 436 return end ();
Chris@101 437 }
Chris@101 438 BOOST_UBLAS_INLINE
Chris@101 439 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@101 440 typename self_type::
Chris@101 441 #endif
Chris@16 442 const_reverse_iterator2 rbegin () const {
Chris@16 443 return const_reverse_iterator2 (end ());
Chris@16 444 }
Chris@16 445 BOOST_UBLAS_INLINE
Chris@16 446 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 447 typename self_type::
Chris@16 448 #endif
Chris@101 449 const_reverse_iterator2 crbegin () const {
Chris@101 450 return rbegin ();
Chris@101 451 }
Chris@101 452 BOOST_UBLAS_INLINE
Chris@101 453 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@101 454 typename self_type::
Chris@101 455 #endif
Chris@16 456 const_reverse_iterator2 rend () const {
Chris@16 457 return const_reverse_iterator2 (begin ());
Chris@16 458 }
Chris@101 459 BOOST_UBLAS_INLINE
Chris@101 460 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@101 461 typename self_type::
Chris@101 462 #endif
Chris@101 463 const_reverse_iterator2 crend () const {
Chris@101 464 return rend ();
Chris@101 465 }
Chris@16 466 #endif
Chris@16 467
Chris@16 468 // Indices
Chris@16 469 BOOST_UBLAS_INLINE
Chris@16 470 size_type index1 () const {
Chris@16 471 return it1_;
Chris@16 472 }
Chris@16 473 BOOST_UBLAS_INLINE
Chris@16 474 size_type index2 () const {
Chris@16 475 return it2_;
Chris@16 476 }
Chris@16 477
Chris@16 478 // Assignment
Chris@16 479 BOOST_UBLAS_INLINE
Chris@16 480 const_iterator1 &operator = (const const_iterator1 &it) {
Chris@16 481 container_const_reference<self_type>::assign (&it ());
Chris@16 482 it1_ = it.it1_;
Chris@16 483 it2_ = it.it2_;
Chris@16 484 return *this;
Chris@16 485 }
Chris@16 486
Chris@16 487 // Comparison
Chris@16 488 BOOST_UBLAS_INLINE
Chris@16 489 bool operator == (const const_iterator1 &it) const {
Chris@16 490 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 491 BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
Chris@16 492 return it1_ == it.it1_;
Chris@16 493 }
Chris@16 494 BOOST_UBLAS_INLINE
Chris@16 495 bool operator < (const const_iterator1 &it) const {
Chris@16 496 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 497 BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
Chris@16 498 return it1_ < it.it1_;
Chris@16 499 }
Chris@16 500
Chris@16 501 private:
Chris@16 502 size_type it1_;
Chris@16 503 size_type it2_;
Chris@16 504 };
Chris@16 505 #endif
Chris@16 506
Chris@16 507 BOOST_UBLAS_INLINE
Chris@16 508 const_iterator1 begin1 () const {
Chris@16 509 return find1 (0, 0, 0);
Chris@16 510 }
Chris@16 511 BOOST_UBLAS_INLINE
Chris@101 512 const_iterator1 cbegin1 () const {
Chris@101 513 return begin1 ();
Chris@101 514 }
Chris@101 515 BOOST_UBLAS_INLINE
Chris@16 516 const_iterator1 end1 () const {
Chris@16 517 return find1 (0, size1_, 0);
Chris@16 518 }
Chris@101 519 BOOST_UBLAS_INLINE
Chris@101 520 const_iterator1 cend1 () const {
Chris@101 521 return end1 ();
Chris@101 522 }
Chris@16 523
Chris@16 524 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
Chris@16 525 class iterator1:
Chris@16 526 public container_reference<triangular_matrix>,
Chris@16 527 public random_access_iterator_base<packed_random_access_iterator_tag,
Chris@16 528 iterator1, value_type> {
Chris@16 529 public:
Chris@16 530 typedef typename triangular_matrix::value_type value_type;
Chris@16 531 typedef typename triangular_matrix::difference_type difference_type;
Chris@16 532 typedef typename triangular_matrix::reference reference;
Chris@16 533 typedef typename triangular_matrix::pointer pointer;
Chris@16 534
Chris@16 535 typedef iterator2 dual_iterator_type;
Chris@16 536 typedef reverse_iterator2 dual_reverse_iterator_type;
Chris@16 537
Chris@16 538 // Construction and destruction
Chris@16 539 BOOST_UBLAS_INLINE
Chris@16 540 iterator1 ():
Chris@16 541 container_reference<self_type> (), it1_ (), it2_ () {}
Chris@16 542 BOOST_UBLAS_INLINE
Chris@16 543 iterator1 (self_type &m, size_type it1, size_type it2):
Chris@16 544 container_reference<self_type> (m), it1_ (it1), it2_ (it2) {}
Chris@16 545
Chris@16 546 // Arithmetic
Chris@16 547 BOOST_UBLAS_INLINE
Chris@16 548 iterator1 &operator ++ () {
Chris@16 549 ++ it1_;
Chris@16 550 return *this;
Chris@16 551 }
Chris@16 552 BOOST_UBLAS_INLINE
Chris@16 553 iterator1 &operator -- () {
Chris@16 554 -- it1_;
Chris@16 555 return *this;
Chris@16 556 }
Chris@16 557 BOOST_UBLAS_INLINE
Chris@16 558 iterator1 &operator += (difference_type n) {
Chris@16 559 it1_ += n;
Chris@16 560 return *this;
Chris@16 561 }
Chris@16 562 BOOST_UBLAS_INLINE
Chris@16 563 iterator1 &operator -= (difference_type n) {
Chris@16 564 it1_ -= n;
Chris@16 565 return *this;
Chris@16 566 }
Chris@16 567 BOOST_UBLAS_INLINE
Chris@16 568 difference_type operator - (const iterator1 &it) const {
Chris@16 569 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 570 BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
Chris@16 571 return it1_ - it.it1_;
Chris@16 572 }
Chris@16 573
Chris@16 574 // Dereference
Chris@16 575 BOOST_UBLAS_INLINE
Chris@16 576 reference operator * () const {
Chris@16 577 return (*this) () (it1_, it2_);
Chris@16 578 }
Chris@16 579 BOOST_UBLAS_INLINE
Chris@16 580 reference operator [] (difference_type n) const {
Chris@16 581 return *(*this + n);
Chris@16 582 }
Chris@16 583
Chris@16 584 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
Chris@16 585 BOOST_UBLAS_INLINE
Chris@16 586 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 587 typename self_type::
Chris@16 588 #endif
Chris@16 589 iterator2 begin () const {
Chris@16 590 return (*this) ().find2 (1, it1_, 0);
Chris@16 591 }
Chris@16 592 BOOST_UBLAS_INLINE
Chris@16 593 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 594 typename self_type::
Chris@16 595 #endif
Chris@16 596 iterator2 end () const {
Chris@16 597 return (*this) ().find2 (1, it1_, (*this) ().size2 ());
Chris@16 598 }
Chris@16 599 BOOST_UBLAS_INLINE
Chris@16 600 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 601 typename self_type::
Chris@16 602 #endif
Chris@16 603 reverse_iterator2 rbegin () const {
Chris@16 604 return reverse_iterator2 (end ());
Chris@16 605 }
Chris@16 606 BOOST_UBLAS_INLINE
Chris@16 607 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 608 typename self_type::
Chris@16 609 #endif
Chris@16 610 reverse_iterator2 rend () const {
Chris@16 611 return reverse_iterator2 (begin ());
Chris@16 612 }
Chris@16 613 #endif
Chris@16 614
Chris@16 615 // Indices
Chris@16 616 BOOST_UBLAS_INLINE
Chris@16 617 size_type index1 () const {
Chris@16 618 return it1_;
Chris@16 619 }
Chris@16 620 BOOST_UBLAS_INLINE
Chris@16 621 size_type index2 () const {
Chris@16 622 return it2_;
Chris@16 623 }
Chris@16 624
Chris@16 625 // Assignment
Chris@16 626 BOOST_UBLAS_INLINE
Chris@16 627 iterator1 &operator = (const iterator1 &it) {
Chris@16 628 container_reference<self_type>::assign (&it ());
Chris@16 629 it1_ = it.it1_;
Chris@16 630 it2_ = it.it2_;
Chris@16 631 return *this;
Chris@16 632 }
Chris@16 633
Chris@16 634 // Comparison
Chris@16 635 BOOST_UBLAS_INLINE
Chris@16 636 bool operator == (const iterator1 &it) const {
Chris@16 637 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 638 BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
Chris@16 639 return it1_ == it.it1_;
Chris@16 640 }
Chris@16 641 BOOST_UBLAS_INLINE
Chris@16 642 bool operator < (const iterator1 &it) const {
Chris@16 643 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 644 BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
Chris@16 645 return it1_ < it.it1_;
Chris@16 646 }
Chris@16 647
Chris@16 648 private:
Chris@16 649 size_type it1_;
Chris@16 650 size_type it2_;
Chris@16 651
Chris@16 652 friend class const_iterator1;
Chris@16 653 };
Chris@16 654 #endif
Chris@16 655
Chris@16 656 BOOST_UBLAS_INLINE
Chris@16 657 iterator1 begin1 () {
Chris@16 658 return find1 (0, 0, 0);
Chris@16 659 }
Chris@16 660 BOOST_UBLAS_INLINE
Chris@16 661 iterator1 end1 () {
Chris@16 662 return find1 (0, size1_, 0);
Chris@16 663 }
Chris@16 664
Chris@16 665 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
Chris@16 666 class const_iterator2:
Chris@16 667 public container_const_reference<triangular_matrix>,
Chris@16 668 public random_access_iterator_base<packed_random_access_iterator_tag,
Chris@16 669 const_iterator2, value_type> {
Chris@16 670 public:
Chris@16 671 typedef typename triangular_matrix::value_type value_type;
Chris@16 672 typedef typename triangular_matrix::difference_type difference_type;
Chris@16 673 typedef typename triangular_matrix::const_reference reference;
Chris@16 674 typedef const typename triangular_matrix::pointer pointer;
Chris@16 675
Chris@16 676 typedef const_iterator1 dual_iterator_type;
Chris@16 677 typedef const_reverse_iterator1 dual_reverse_iterator_type;
Chris@16 678
Chris@16 679 // Construction and destruction
Chris@16 680 BOOST_UBLAS_INLINE
Chris@16 681 const_iterator2 ():
Chris@16 682 container_const_reference<self_type> (), it1_ (), it2_ () {}
Chris@16 683 BOOST_UBLAS_INLINE
Chris@16 684 const_iterator2 (const self_type &m, size_type it1, size_type it2):
Chris@16 685 container_const_reference<self_type> (m), it1_ (it1), it2_ (it2) {}
Chris@16 686 BOOST_UBLAS_INLINE
Chris@16 687 const_iterator2 (const iterator2 &it):
Chris@16 688 container_const_reference<self_type> (it ()), it1_ (it.it1_), it2_ (it.it2_) {}
Chris@16 689
Chris@16 690 // Arithmetic
Chris@16 691 BOOST_UBLAS_INLINE
Chris@16 692 const_iterator2 &operator ++ () {
Chris@16 693 ++ it2_;
Chris@16 694 return *this;
Chris@16 695 }
Chris@16 696 BOOST_UBLAS_INLINE
Chris@16 697 const_iterator2 &operator -- () {
Chris@16 698 -- it2_;
Chris@16 699 return *this;
Chris@16 700 }
Chris@16 701 BOOST_UBLAS_INLINE
Chris@16 702 const_iterator2 &operator += (difference_type n) {
Chris@16 703 it2_ += n;
Chris@16 704 return *this;
Chris@16 705 }
Chris@16 706 BOOST_UBLAS_INLINE
Chris@16 707 const_iterator2 &operator -= (difference_type n) {
Chris@16 708 it2_ -= n;
Chris@16 709 return *this;
Chris@16 710 }
Chris@16 711 BOOST_UBLAS_INLINE
Chris@16 712 difference_type operator - (const const_iterator2 &it) const {
Chris@16 713 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 714 BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
Chris@16 715 return it2_ - it.it2_;
Chris@16 716 }
Chris@16 717
Chris@16 718 // Dereference
Chris@16 719 BOOST_UBLAS_INLINE
Chris@16 720 const_reference operator * () const {
Chris@16 721 return (*this) () (it1_, it2_);
Chris@16 722 }
Chris@16 723 BOOST_UBLAS_INLINE
Chris@16 724 const_reference operator [] (difference_type n) const {
Chris@16 725 return *(*this + n);
Chris@16 726 }
Chris@16 727
Chris@16 728 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
Chris@16 729 BOOST_UBLAS_INLINE
Chris@16 730 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 731 typename self_type::
Chris@16 732 #endif
Chris@16 733 const_iterator1 begin () const {
Chris@16 734 return (*this) ().find1 (1, 0, it2_);
Chris@16 735 }
Chris@16 736 BOOST_UBLAS_INLINE
Chris@16 737 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 738 typename self_type::
Chris@16 739 #endif
Chris@101 740 const_iterator1 cbegin () const {
Chris@101 741 return begin ();
Chris@101 742 }
Chris@101 743 BOOST_UBLAS_INLINE
Chris@101 744 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@101 745 typename self_type::
Chris@101 746 #endif
Chris@16 747 const_iterator1 end () const {
Chris@16 748 return (*this) ().find1 (1, (*this) ().size1 (), it2_);
Chris@16 749 }
Chris@16 750 BOOST_UBLAS_INLINE
Chris@16 751 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 752 typename self_type::
Chris@16 753 #endif
Chris@101 754 const_iterator1 cend () const {
Chris@101 755 return end ();
Chris@101 756 }
Chris@101 757 BOOST_UBLAS_INLINE
Chris@101 758 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@101 759 typename self_type::
Chris@101 760 #endif
Chris@16 761 const_reverse_iterator1 rbegin () const {
Chris@16 762 return const_reverse_iterator1 (end ());
Chris@16 763 }
Chris@16 764 BOOST_UBLAS_INLINE
Chris@16 765 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 766 typename self_type::
Chris@16 767 #endif
Chris@101 768 const_reverse_iterator1 crbegin () const {
Chris@101 769 return rbegin ();
Chris@101 770 }
Chris@101 771
Chris@101 772 BOOST_UBLAS_INLINE
Chris@101 773 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@101 774 typename self_type::
Chris@101 775 #endif
Chris@16 776 const_reverse_iterator1 rend () const {
Chris@16 777 return const_reverse_iterator1 (begin ());
Chris@16 778 }
Chris@101 779 BOOST_UBLAS_INLINE
Chris@101 780 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@101 781 typename self_type::
Chris@101 782 #endif
Chris@101 783 const_reverse_iterator1 crend () const {
Chris@101 784 return rend ();
Chris@101 785 }
Chris@16 786 #endif
Chris@16 787
Chris@16 788 // Indices
Chris@16 789 BOOST_UBLAS_INLINE
Chris@16 790 size_type index1 () const {
Chris@16 791 return it1_;
Chris@16 792 }
Chris@16 793 BOOST_UBLAS_INLINE
Chris@16 794 size_type index2 () const {
Chris@16 795 return it2_;
Chris@16 796 }
Chris@16 797
Chris@16 798 // Assignment
Chris@16 799 BOOST_UBLAS_INLINE
Chris@16 800 const_iterator2 &operator = (const const_iterator2 &it) {
Chris@16 801 container_const_reference<self_type>::assign (&it ());
Chris@16 802 it1_ = it.it1_;
Chris@16 803 it2_ = it.it2_;
Chris@16 804 return *this;
Chris@16 805 }
Chris@16 806
Chris@16 807 // Comparison
Chris@16 808 BOOST_UBLAS_INLINE
Chris@16 809 bool operator == (const const_iterator2 &it) const {
Chris@16 810 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 811 BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
Chris@16 812 return it2_ == it.it2_;
Chris@16 813 }
Chris@16 814 BOOST_UBLAS_INLINE
Chris@16 815 bool operator < (const const_iterator2 &it) const {
Chris@16 816 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 817 BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
Chris@16 818 return it2_ < it.it2_;
Chris@16 819 }
Chris@16 820
Chris@16 821 private:
Chris@16 822 size_type it1_;
Chris@16 823 size_type it2_;
Chris@16 824 };
Chris@16 825 #endif
Chris@16 826
Chris@16 827 BOOST_UBLAS_INLINE
Chris@16 828 const_iterator2 begin2 () const {
Chris@16 829 return find2 (0, 0, 0);
Chris@16 830 }
Chris@16 831 BOOST_UBLAS_INLINE
Chris@101 832 const_iterator2 cbegin2 () const {
Chris@101 833 return begin2 ();
Chris@101 834 }
Chris@101 835 BOOST_UBLAS_INLINE
Chris@16 836 const_iterator2 end2 () const {
Chris@16 837 return find2 (0, 0, size2_);
Chris@16 838 }
Chris@101 839 BOOST_UBLAS_INLINE
Chris@101 840 const_iterator2 cend2 () const {
Chris@101 841 return end2 ();
Chris@101 842 }
Chris@16 843
Chris@16 844 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
Chris@16 845 class iterator2:
Chris@16 846 public container_reference<triangular_matrix>,
Chris@16 847 public random_access_iterator_base<packed_random_access_iterator_tag,
Chris@16 848 iterator2, value_type> {
Chris@16 849 public:
Chris@16 850 typedef typename triangular_matrix::value_type value_type;
Chris@16 851 typedef typename triangular_matrix::difference_type difference_type;
Chris@16 852 typedef typename triangular_matrix::reference reference;
Chris@16 853 typedef typename triangular_matrix::pointer pointer;
Chris@16 854
Chris@16 855 typedef iterator1 dual_iterator_type;
Chris@16 856 typedef reverse_iterator1 dual_reverse_iterator_type;
Chris@16 857
Chris@16 858 // Construction and destruction
Chris@16 859 BOOST_UBLAS_INLINE
Chris@16 860 iterator2 ():
Chris@16 861 container_reference<self_type> (), it1_ (), it2_ () {}
Chris@16 862 BOOST_UBLAS_INLINE
Chris@16 863 iterator2 (self_type &m, size_type it1, size_type it2):
Chris@16 864 container_reference<self_type> (m), it1_ (it1), it2_ (it2) {}
Chris@16 865
Chris@16 866 // Arithmetic
Chris@16 867 BOOST_UBLAS_INLINE
Chris@16 868 iterator2 &operator ++ () {
Chris@16 869 ++ it2_;
Chris@16 870 return *this;
Chris@16 871 }
Chris@16 872 BOOST_UBLAS_INLINE
Chris@16 873 iterator2 &operator -- () {
Chris@16 874 -- it2_;
Chris@16 875 return *this;
Chris@16 876 }
Chris@16 877 BOOST_UBLAS_INLINE
Chris@16 878 iterator2 &operator += (difference_type n) {
Chris@16 879 it2_ += n;
Chris@16 880 return *this;
Chris@16 881 }
Chris@16 882 BOOST_UBLAS_INLINE
Chris@16 883 iterator2 &operator -= (difference_type n) {
Chris@16 884 it2_ -= n;
Chris@16 885 return *this;
Chris@16 886 }
Chris@16 887 BOOST_UBLAS_INLINE
Chris@16 888 difference_type operator - (const iterator2 &it) const {
Chris@16 889 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 890 BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
Chris@16 891 return it2_ - it.it2_;
Chris@16 892 }
Chris@16 893
Chris@16 894 // Dereference
Chris@16 895 BOOST_UBLAS_INLINE
Chris@16 896 reference operator * () const {
Chris@16 897 return (*this) () (it1_, it2_);
Chris@16 898 }
Chris@16 899 BOOST_UBLAS_INLINE
Chris@16 900 reference operator [] (difference_type n) const {
Chris@16 901 return *(*this + n);
Chris@16 902 }
Chris@16 903
Chris@16 904 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
Chris@16 905 BOOST_UBLAS_INLINE
Chris@16 906 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 907 typename self_type::
Chris@16 908 #endif
Chris@16 909 iterator1 begin () const {
Chris@16 910 return (*this) ().find1 (1, 0, it2_);
Chris@16 911 }
Chris@16 912 BOOST_UBLAS_INLINE
Chris@16 913 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 914 typename self_type::
Chris@16 915 #endif
Chris@16 916 iterator1 end () const {
Chris@16 917 return (*this) ().find1 (1, (*this) ().size1 (), it2_);
Chris@16 918 }
Chris@16 919 BOOST_UBLAS_INLINE
Chris@16 920 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 921 typename self_type::
Chris@16 922 #endif
Chris@16 923 reverse_iterator1 rbegin () const {
Chris@16 924 return reverse_iterator1 (end ());
Chris@16 925 }
Chris@16 926 BOOST_UBLAS_INLINE
Chris@16 927 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 928 typename self_type::
Chris@16 929 #endif
Chris@16 930 reverse_iterator1 rend () const {
Chris@16 931 return reverse_iterator1 (begin ());
Chris@16 932 }
Chris@16 933 #endif
Chris@16 934
Chris@16 935 // Indices
Chris@16 936 BOOST_UBLAS_INLINE
Chris@16 937 size_type index1 () const {
Chris@16 938 return it1_;
Chris@16 939 }
Chris@16 940 BOOST_UBLAS_INLINE
Chris@16 941 size_type index2 () const {
Chris@16 942 return it2_;
Chris@16 943 }
Chris@16 944
Chris@16 945 // Assignment
Chris@16 946 BOOST_UBLAS_INLINE
Chris@16 947 iterator2 &operator = (const iterator2 &it) {
Chris@16 948 container_reference<self_type>::assign (&it ());
Chris@16 949 it1_ = it.it1_;
Chris@16 950 it2_ = it.it2_;
Chris@16 951 return *this;
Chris@16 952 }
Chris@16 953
Chris@16 954 // Comparison
Chris@16 955 BOOST_UBLAS_INLINE
Chris@16 956 bool operator == (const iterator2 &it) const {
Chris@16 957 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 958 BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
Chris@16 959 return it2_ == it.it2_;
Chris@16 960 }
Chris@16 961 BOOST_UBLAS_INLINE
Chris@16 962 bool operator < (const iterator2 &it) const {
Chris@16 963 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 964 BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
Chris@16 965 return it2_ < it.it2_;
Chris@16 966 }
Chris@16 967
Chris@16 968 private:
Chris@16 969 size_type it1_;
Chris@16 970 size_type it2_;
Chris@16 971
Chris@16 972 friend class const_iterator2;
Chris@16 973 };
Chris@16 974 #endif
Chris@16 975
Chris@16 976 BOOST_UBLAS_INLINE
Chris@16 977 iterator2 begin2 () {
Chris@16 978 return find2 (0, 0, 0);
Chris@16 979 }
Chris@16 980 BOOST_UBLAS_INLINE
Chris@16 981 iterator2 end2 () {
Chris@16 982 return find2 (0, 0, size2_);
Chris@16 983 }
Chris@16 984
Chris@16 985 // Reverse iterators
Chris@16 986
Chris@16 987 BOOST_UBLAS_INLINE
Chris@16 988 const_reverse_iterator1 rbegin1 () const {
Chris@16 989 return const_reverse_iterator1 (end1 ());
Chris@16 990 }
Chris@16 991 BOOST_UBLAS_INLINE
Chris@101 992 const_reverse_iterator1 crbegin1 () const {
Chris@101 993 return rbegin1 ();
Chris@101 994 }
Chris@101 995 BOOST_UBLAS_INLINE
Chris@16 996 const_reverse_iterator1 rend1 () const {
Chris@16 997 return const_reverse_iterator1 (begin1 ());
Chris@16 998 }
Chris@101 999 BOOST_UBLAS_INLINE
Chris@101 1000 const_reverse_iterator1 crend1 () const {
Chris@101 1001 return rend1 ();
Chris@101 1002 }
Chris@16 1003
Chris@16 1004 BOOST_UBLAS_INLINE
Chris@16 1005 reverse_iterator1 rbegin1 () {
Chris@16 1006 return reverse_iterator1 (end1 ());
Chris@16 1007 }
Chris@16 1008 BOOST_UBLAS_INLINE
Chris@16 1009 reverse_iterator1 rend1 () {
Chris@16 1010 return reverse_iterator1 (begin1 ());
Chris@16 1011 }
Chris@16 1012
Chris@16 1013 BOOST_UBLAS_INLINE
Chris@16 1014 const_reverse_iterator2 rbegin2 () const {
Chris@16 1015 return const_reverse_iterator2 (end2 ());
Chris@16 1016 }
Chris@16 1017 BOOST_UBLAS_INLINE
Chris@101 1018 const_reverse_iterator2 crbegin2 () const {
Chris@101 1019 return rbegin2 ();
Chris@101 1020 }
Chris@101 1021 BOOST_UBLAS_INLINE
Chris@16 1022 const_reverse_iterator2 rend2 () const {
Chris@16 1023 return const_reverse_iterator2 (begin2 ());
Chris@16 1024 }
Chris@101 1025 BOOST_UBLAS_INLINE
Chris@101 1026 const_reverse_iterator2 crend2 () const {
Chris@101 1027 return rend2 ();
Chris@101 1028 }
Chris@16 1029
Chris@16 1030 BOOST_UBLAS_INLINE
Chris@16 1031 reverse_iterator2 rbegin2 () {
Chris@16 1032 return reverse_iterator2 (end2 ());
Chris@16 1033 }
Chris@16 1034 BOOST_UBLAS_INLINE
Chris@16 1035 reverse_iterator2 rend2 () {
Chris@16 1036 return reverse_iterator2 (begin2 ());
Chris@16 1037 }
Chris@16 1038
Chris@16 1039 private:
Chris@16 1040 size_type size1_;
Chris@16 1041 size_type size2_;
Chris@16 1042 array_type data_;
Chris@16 1043 static const value_type zero_;
Chris@16 1044 static const value_type one_;
Chris@16 1045 };
Chris@16 1046
Chris@16 1047 template<class T, class TRI, class L, class A>
Chris@16 1048 const typename triangular_matrix<T, TRI, L, A>::value_type triangular_matrix<T, TRI, L, A>::zero_ = value_type/*zero*/();
Chris@16 1049 template<class T, class TRI, class L, class A>
Chris@16 1050 const typename triangular_matrix<T, TRI, L, A>::value_type triangular_matrix<T, TRI, L, A>::one_ (1);
Chris@16 1051
Chris@16 1052
Chris@16 1053 // Triangular matrix adaptor class
Chris@16 1054 template<class M, class TRI>
Chris@16 1055 class triangular_adaptor:
Chris@16 1056 public matrix_expression<triangular_adaptor<M, TRI> > {
Chris@16 1057
Chris@16 1058 typedef triangular_adaptor<M, TRI> self_type;
Chris@16 1059
Chris@16 1060 public:
Chris@16 1061 #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
Chris@16 1062 using matrix_expression<self_type>::operator ();
Chris@16 1063 #endif
Chris@16 1064 typedef const M const_matrix_type;
Chris@16 1065 typedef M matrix_type;
Chris@16 1066 typedef TRI triangular_type;
Chris@16 1067 typedef typename M::size_type size_type;
Chris@16 1068 typedef typename M::difference_type difference_type;
Chris@16 1069 typedef typename M::value_type value_type;
Chris@16 1070 typedef typename M::const_reference const_reference;
Chris@16 1071 typedef typename boost::mpl::if_<boost::is_const<M>,
Chris@16 1072 typename M::const_reference,
Chris@16 1073 typename M::reference>::type reference;
Chris@16 1074 typedef typename boost::mpl::if_<boost::is_const<M>,
Chris@16 1075 typename M::const_closure_type,
Chris@16 1076 typename M::closure_type>::type matrix_closure_type;
Chris@16 1077 typedef const self_type const_closure_type;
Chris@16 1078 typedef self_type closure_type;
Chris@16 1079 // Replaced by _temporary_traits to avoid type requirements on M
Chris@16 1080 //typedef typename M::vector_temporary_type vector_temporary_type;
Chris@16 1081 //typedef typename M::matrix_temporary_type matrix_temporary_type;
Chris@16 1082 typedef typename storage_restrict_traits<typename M::storage_category,
Chris@16 1083 packed_proxy_tag>::storage_category storage_category;
Chris@16 1084 typedef typename M::orientation_category orientation_category;
Chris@16 1085
Chris@16 1086 // Construction and destruction
Chris@16 1087 BOOST_UBLAS_INLINE
Chris@16 1088 triangular_adaptor (matrix_type &data):
Chris@16 1089 matrix_expression<self_type> (),
Chris@16 1090 data_ (data) {}
Chris@16 1091 BOOST_UBLAS_INLINE
Chris@16 1092 triangular_adaptor (const triangular_adaptor &m):
Chris@16 1093 matrix_expression<self_type> (),
Chris@16 1094 data_ (m.data_) {}
Chris@16 1095
Chris@16 1096 // Accessors
Chris@16 1097 BOOST_UBLAS_INLINE
Chris@16 1098 size_type size1 () const {
Chris@16 1099 return data_.size1 ();
Chris@16 1100 }
Chris@16 1101 BOOST_UBLAS_INLINE
Chris@16 1102 size_type size2 () const {
Chris@16 1103 return data_.size2 ();
Chris@16 1104 }
Chris@16 1105
Chris@16 1106 // Storage accessors
Chris@16 1107 BOOST_UBLAS_INLINE
Chris@16 1108 const matrix_closure_type &data () const {
Chris@16 1109 return data_;
Chris@16 1110 }
Chris@16 1111 BOOST_UBLAS_INLINE
Chris@16 1112 matrix_closure_type &data () {
Chris@16 1113 return data_;
Chris@16 1114 }
Chris@16 1115
Chris@16 1116 // Element access
Chris@16 1117 #ifndef BOOST_UBLAS_PROXY_CONST_MEMBER
Chris@16 1118 BOOST_UBLAS_INLINE
Chris@16 1119 const_reference operator () (size_type i, size_type j) const {
Chris@16 1120 BOOST_UBLAS_CHECK (i < size1 (), bad_index ());
Chris@16 1121 BOOST_UBLAS_CHECK (j < size2 (), bad_index ());
Chris@16 1122 if (triangular_type::other (i, j))
Chris@16 1123 return data () (i, j);
Chris@16 1124 else if (triangular_type::one (i, j))
Chris@16 1125 return one_;
Chris@16 1126 else
Chris@16 1127 return zero_;
Chris@16 1128 }
Chris@16 1129 BOOST_UBLAS_INLINE
Chris@16 1130 reference operator () (size_type i, size_type j) {
Chris@16 1131 BOOST_UBLAS_CHECK (i < size1 (), bad_index ());
Chris@16 1132 BOOST_UBLAS_CHECK (j < size2 (), bad_index ());
Chris@16 1133 if (!triangular_type::other (i, j)) {
Chris@16 1134 bad_index ().raise ();
Chris@16 1135 // NEVER reached
Chris@16 1136 }
Chris@16 1137 return data () (i, j);
Chris@16 1138 }
Chris@16 1139 #else
Chris@16 1140 BOOST_UBLAS_INLINE
Chris@16 1141 reference operator () (size_type i, size_type j) const {
Chris@16 1142 BOOST_UBLAS_CHECK (i < size1 (), bad_index ());
Chris@16 1143 BOOST_UBLAS_CHECK (j < size2 (), bad_index ());
Chris@16 1144 if (!triangular_type::other (i, j)) {
Chris@16 1145 bad_index ().raise ();
Chris@16 1146 // NEVER reached
Chris@16 1147 }
Chris@16 1148 return data () (i, j);
Chris@16 1149 }
Chris@16 1150 #endif
Chris@16 1151
Chris@16 1152 // Assignment
Chris@16 1153 BOOST_UBLAS_INLINE
Chris@16 1154 triangular_adaptor &operator = (const triangular_adaptor &m) {
Chris@16 1155 matrix_assign<scalar_assign> (*this, m);
Chris@16 1156 return *this;
Chris@16 1157 }
Chris@16 1158 BOOST_UBLAS_INLINE
Chris@16 1159 triangular_adaptor &assign_temporary (triangular_adaptor &m) {
Chris@16 1160 *this = m;
Chris@16 1161 return *this;
Chris@16 1162 }
Chris@16 1163 template<class AE>
Chris@16 1164 BOOST_UBLAS_INLINE
Chris@16 1165 triangular_adaptor &operator = (const matrix_expression<AE> &ae) {
Chris@16 1166 matrix_assign<scalar_assign> (*this, matrix<value_type> (ae));
Chris@16 1167 return *this;
Chris@16 1168 }
Chris@16 1169 template<class AE>
Chris@16 1170 BOOST_UBLAS_INLINE
Chris@16 1171 triangular_adaptor &assign (const matrix_expression<AE> &ae) {
Chris@16 1172 matrix_assign<scalar_assign> (*this, ae);
Chris@16 1173 return *this;
Chris@16 1174 }
Chris@16 1175 template<class AE>
Chris@16 1176 BOOST_UBLAS_INLINE
Chris@16 1177 triangular_adaptor& operator += (const matrix_expression<AE> &ae) {
Chris@16 1178 matrix_assign<scalar_assign> (*this, matrix<value_type> (*this + ae));
Chris@16 1179 return *this;
Chris@16 1180 }
Chris@16 1181 template<class AE>
Chris@16 1182 BOOST_UBLAS_INLINE
Chris@16 1183 triangular_adaptor &plus_assign (const matrix_expression<AE> &ae) {
Chris@16 1184 matrix_assign<scalar_plus_assign> (*this, ae);
Chris@16 1185 return *this;
Chris@16 1186 }
Chris@16 1187 template<class AE>
Chris@16 1188 BOOST_UBLAS_INLINE
Chris@16 1189 triangular_adaptor& operator -= (const matrix_expression<AE> &ae) {
Chris@16 1190 matrix_assign<scalar_assign> (*this, matrix<value_type> (*this - ae));
Chris@16 1191 return *this;
Chris@16 1192 }
Chris@16 1193 template<class AE>
Chris@16 1194 BOOST_UBLAS_INLINE
Chris@16 1195 triangular_adaptor &minus_assign (const matrix_expression<AE> &ae) {
Chris@16 1196 matrix_assign<scalar_minus_assign> (*this, ae);
Chris@16 1197 return *this;
Chris@16 1198 }
Chris@16 1199 template<class AT>
Chris@16 1200 BOOST_UBLAS_INLINE
Chris@16 1201 triangular_adaptor& operator *= (const AT &at) {
Chris@16 1202 matrix_assign_scalar<scalar_multiplies_assign> (*this, at);
Chris@16 1203 return *this;
Chris@16 1204 }
Chris@16 1205 template<class AT>
Chris@16 1206 BOOST_UBLAS_INLINE
Chris@16 1207 triangular_adaptor& operator /= (const AT &at) {
Chris@16 1208 matrix_assign_scalar<scalar_divides_assign> (*this, at);
Chris@16 1209 return *this;
Chris@16 1210 }
Chris@16 1211
Chris@16 1212 // Closure comparison
Chris@16 1213 BOOST_UBLAS_INLINE
Chris@16 1214 bool same_closure (const triangular_adaptor &ta) const {
Chris@16 1215 return (*this).data ().same_closure (ta.data ());
Chris@16 1216 }
Chris@16 1217
Chris@16 1218 // Swapping
Chris@16 1219 BOOST_UBLAS_INLINE
Chris@16 1220 void swap (triangular_adaptor &m) {
Chris@16 1221 if (this != &m)
Chris@16 1222 matrix_swap<scalar_swap> (*this, m);
Chris@16 1223 }
Chris@16 1224 BOOST_UBLAS_INLINE
Chris@16 1225 friend void swap (triangular_adaptor &m1, triangular_adaptor &m2) {
Chris@16 1226 m1.swap (m2);
Chris@16 1227 }
Chris@16 1228
Chris@16 1229 // Iterator types
Chris@16 1230 private:
Chris@16 1231 typedef typename M::const_iterator1 const_subiterator1_type;
Chris@16 1232 typedef typename boost::mpl::if_<boost::is_const<M>,
Chris@16 1233 typename M::const_iterator1,
Chris@16 1234 typename M::iterator1>::type subiterator1_type;
Chris@16 1235 typedef typename M::const_iterator2 const_subiterator2_type;
Chris@16 1236 typedef typename boost::mpl::if_<boost::is_const<M>,
Chris@16 1237 typename M::const_iterator2,
Chris@16 1238 typename M::iterator2>::type subiterator2_type;
Chris@16 1239
Chris@16 1240 public:
Chris@16 1241 #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
Chris@16 1242 typedef indexed_iterator1<self_type, packed_random_access_iterator_tag> iterator1;
Chris@16 1243 typedef indexed_iterator2<self_type, packed_random_access_iterator_tag> iterator2;
Chris@16 1244 typedef indexed_const_iterator1<self_type, packed_random_access_iterator_tag> const_iterator1;
Chris@16 1245 typedef indexed_const_iterator2<self_type, packed_random_access_iterator_tag> const_iterator2;
Chris@16 1246 #else
Chris@16 1247 class const_iterator1;
Chris@16 1248 class iterator1;
Chris@16 1249 class const_iterator2;
Chris@16 1250 class iterator2;
Chris@16 1251 #endif
Chris@16 1252 typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
Chris@16 1253 typedef reverse_iterator_base1<iterator1> reverse_iterator1;
Chris@16 1254 typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
Chris@16 1255 typedef reverse_iterator_base2<iterator2> reverse_iterator2;
Chris@16 1256
Chris@16 1257 // Element lookup
Chris@16 1258 BOOST_UBLAS_INLINE
Chris@16 1259 const_iterator1 find1 (int rank, size_type i, size_type j) const {
Chris@16 1260 if (rank == 1)
Chris@16 1261 i = triangular_type::restrict1 (i, j, size1(), size2());
Chris@16 1262 if (rank == 0)
Chris@16 1263 i = triangular_type::global_restrict1 (i, size1(), j, size2());
Chris@16 1264 return const_iterator1 (*this, data ().find1 (rank, i, j));
Chris@16 1265 }
Chris@16 1266 BOOST_UBLAS_INLINE
Chris@16 1267 iterator1 find1 (int rank, size_type i, size_type j) {
Chris@16 1268 if (rank == 1)
Chris@16 1269 i = triangular_type::mutable_restrict1 (i, j, size1(), size2());
Chris@16 1270 if (rank == 0)
Chris@16 1271 i = triangular_type::global_mutable_restrict1 (i, size1(), j, size2());
Chris@16 1272 return iterator1 (*this, data ().find1 (rank, i, j));
Chris@16 1273 }
Chris@16 1274 BOOST_UBLAS_INLINE
Chris@16 1275 const_iterator2 find2 (int rank, size_type i, size_type j) const {
Chris@16 1276 if (rank == 1)
Chris@16 1277 j = triangular_type::restrict2 (i, j, size1(), size2());
Chris@16 1278 if (rank == 0)
Chris@16 1279 j = triangular_type::global_restrict2 (i, size1(), j, size2());
Chris@16 1280 return const_iterator2 (*this, data ().find2 (rank, i, j));
Chris@16 1281 }
Chris@16 1282 BOOST_UBLAS_INLINE
Chris@16 1283 iterator2 find2 (int rank, size_type i, size_type j) {
Chris@16 1284 if (rank == 1)
Chris@16 1285 j = triangular_type::mutable_restrict2 (i, j, size1(), size2());
Chris@16 1286 if (rank == 0)
Chris@16 1287 j = triangular_type::global_mutable_restrict2 (i, size1(), j, size2());
Chris@16 1288 return iterator2 (*this, data ().find2 (rank, i, j));
Chris@16 1289 }
Chris@16 1290
Chris@16 1291 // Iterators simply are indices.
Chris@16 1292
Chris@16 1293 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
Chris@16 1294 class const_iterator1:
Chris@16 1295 public container_const_reference<triangular_adaptor>,
Chris@16 1296 public random_access_iterator_base<typename iterator_restrict_traits<
Chris@16 1297 typename const_subiterator1_type::iterator_category, packed_random_access_iterator_tag>::iterator_category,
Chris@16 1298 const_iterator1, value_type> {
Chris@16 1299 public:
Chris@16 1300 typedef typename const_subiterator1_type::value_type value_type;
Chris@16 1301 typedef typename const_subiterator1_type::difference_type difference_type;
Chris@16 1302 typedef typename const_subiterator1_type::reference reference;
Chris@16 1303 typedef typename const_subiterator1_type::pointer pointer;
Chris@16 1304
Chris@16 1305 typedef const_iterator2 dual_iterator_type;
Chris@16 1306 typedef const_reverse_iterator2 dual_reverse_iterator_type;
Chris@16 1307
Chris@16 1308 // Construction and destruction
Chris@16 1309 BOOST_UBLAS_INLINE
Chris@16 1310 const_iterator1 ():
Chris@16 1311 container_const_reference<self_type> (), it1_ () {}
Chris@16 1312 BOOST_UBLAS_INLINE
Chris@16 1313 const_iterator1 (const self_type &m, const const_subiterator1_type &it1):
Chris@16 1314 container_const_reference<self_type> (m), it1_ (it1) {}
Chris@16 1315 BOOST_UBLAS_INLINE
Chris@16 1316 const_iterator1 (const iterator1 &it):
Chris@16 1317 container_const_reference<self_type> (it ()), it1_ (it.it1_) {}
Chris@16 1318
Chris@16 1319 // Arithmetic
Chris@16 1320 BOOST_UBLAS_INLINE
Chris@16 1321 const_iterator1 &operator ++ () {
Chris@16 1322 ++ it1_;
Chris@16 1323 return *this;
Chris@16 1324 }
Chris@16 1325 BOOST_UBLAS_INLINE
Chris@16 1326 const_iterator1 &operator -- () {
Chris@16 1327 -- it1_;
Chris@16 1328 return *this;
Chris@16 1329 }
Chris@16 1330 BOOST_UBLAS_INLINE
Chris@16 1331 const_iterator1 &operator += (difference_type n) {
Chris@16 1332 it1_ += n;
Chris@16 1333 return *this;
Chris@16 1334 }
Chris@16 1335 BOOST_UBLAS_INLINE
Chris@16 1336 const_iterator1 &operator -= (difference_type n) {
Chris@16 1337 it1_ -= n;
Chris@16 1338 return *this;
Chris@16 1339 }
Chris@16 1340 BOOST_UBLAS_INLINE
Chris@16 1341 difference_type operator - (const const_iterator1 &it) const {
Chris@16 1342 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 1343 return it1_ - it.it1_;
Chris@16 1344 }
Chris@16 1345
Chris@16 1346 // Dereference
Chris@16 1347 BOOST_UBLAS_INLINE
Chris@16 1348 const_reference operator * () const {
Chris@16 1349 size_type i = index1 ();
Chris@16 1350 size_type j = index2 ();
Chris@16 1351 BOOST_UBLAS_CHECK (i < (*this) ().size1 (), bad_index ());
Chris@16 1352 BOOST_UBLAS_CHECK (j < (*this) ().size2 (), bad_index ());
Chris@16 1353 if (triangular_type::other (i, j))
Chris@16 1354 return *it1_;
Chris@16 1355 else
Chris@16 1356 return (*this) () (i, j);
Chris@16 1357 }
Chris@16 1358 BOOST_UBLAS_INLINE
Chris@16 1359 const_reference operator [] (difference_type n) const {
Chris@16 1360 return *(*this + n);
Chris@16 1361 }
Chris@16 1362
Chris@16 1363 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
Chris@16 1364 BOOST_UBLAS_INLINE
Chris@16 1365 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1366 typename self_type::
Chris@16 1367 #endif
Chris@16 1368 const_iterator2 begin () const {
Chris@16 1369 return (*this) ().find2 (1, index1 (), 0);
Chris@16 1370 }
Chris@16 1371 BOOST_UBLAS_INLINE
Chris@16 1372 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1373 typename self_type::
Chris@16 1374 #endif
Chris@101 1375 const_iterator2 cbegin () const {
Chris@101 1376 return begin ();
Chris@101 1377 }
Chris@101 1378 BOOST_UBLAS_INLINE
Chris@101 1379 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@101 1380 typename self_type::
Chris@101 1381 #endif
Chris@16 1382 const_iterator2 end () const {
Chris@16 1383 return (*this) ().find2 (1, index1 (), (*this) ().size2 ());
Chris@16 1384 }
Chris@16 1385 BOOST_UBLAS_INLINE
Chris@16 1386 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1387 typename self_type::
Chris@16 1388 #endif
Chris@101 1389 const_iterator2 cend () const {
Chris@101 1390 return end ();
Chris@101 1391 }
Chris@101 1392
Chris@101 1393 BOOST_UBLAS_INLINE
Chris@101 1394 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@101 1395 typename self_type::
Chris@101 1396 #endif
Chris@16 1397 const_reverse_iterator2 rbegin () const {
Chris@16 1398 return const_reverse_iterator2 (end ());
Chris@16 1399 }
Chris@16 1400 BOOST_UBLAS_INLINE
Chris@16 1401 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1402 typename self_type::
Chris@16 1403 #endif
Chris@101 1404 const_reverse_iterator2 crbegin () const {
Chris@101 1405 return rbegin ();
Chris@101 1406 }
Chris@101 1407 BOOST_UBLAS_INLINE
Chris@101 1408 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@101 1409 typename self_type::
Chris@101 1410 #endif
Chris@16 1411 const_reverse_iterator2 rend () const {
Chris@16 1412 return const_reverse_iterator2 (begin ());
Chris@16 1413 }
Chris@101 1414 BOOST_UBLAS_INLINE
Chris@101 1415 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@101 1416 typename self_type::
Chris@101 1417 #endif
Chris@101 1418 const_reverse_iterator2 crend () const {
Chris@101 1419 return rend ();
Chris@101 1420 }
Chris@16 1421 #endif
Chris@16 1422
Chris@16 1423 // Indices
Chris@16 1424 BOOST_UBLAS_INLINE
Chris@16 1425 size_type index1 () const {
Chris@16 1426 return it1_.index1 ();
Chris@16 1427 }
Chris@16 1428 BOOST_UBLAS_INLINE
Chris@16 1429 size_type index2 () const {
Chris@16 1430 return it1_.index2 ();
Chris@16 1431 }
Chris@16 1432
Chris@16 1433 // Assignment
Chris@16 1434 BOOST_UBLAS_INLINE
Chris@16 1435 const_iterator1 &operator = (const const_iterator1 &it) {
Chris@16 1436 container_const_reference<self_type>::assign (&it ());
Chris@16 1437 it1_ = it.it1_;
Chris@16 1438 return *this;
Chris@16 1439 }
Chris@16 1440
Chris@16 1441 // Comparison
Chris@16 1442 BOOST_UBLAS_INLINE
Chris@16 1443 bool operator == (const const_iterator1 &it) const {
Chris@16 1444 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 1445 return it1_ == it.it1_;
Chris@16 1446 }
Chris@16 1447 BOOST_UBLAS_INLINE
Chris@16 1448 bool operator < (const const_iterator1 &it) const {
Chris@16 1449 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 1450 return it1_ < it.it1_;
Chris@16 1451 }
Chris@16 1452
Chris@16 1453 private:
Chris@16 1454 const_subiterator1_type it1_;
Chris@16 1455 };
Chris@16 1456 #endif
Chris@16 1457
Chris@16 1458 BOOST_UBLAS_INLINE
Chris@16 1459 const_iterator1 begin1 () const {
Chris@16 1460 return find1 (0, 0, 0);
Chris@16 1461 }
Chris@16 1462 BOOST_UBLAS_INLINE
Chris@101 1463 const_iterator1 cbegin1 () const {
Chris@101 1464 return begin1 ();
Chris@101 1465 }
Chris@101 1466 BOOST_UBLAS_INLINE
Chris@16 1467 const_iterator1 end1 () const {
Chris@16 1468 return find1 (0, size1 (), 0);
Chris@16 1469 }
Chris@101 1470 BOOST_UBLAS_INLINE
Chris@101 1471 const_iterator1 cend1 () const {
Chris@101 1472 return end1 ();
Chris@101 1473 }
Chris@16 1474
Chris@16 1475 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
Chris@16 1476 class iterator1:
Chris@16 1477 public container_reference<triangular_adaptor>,
Chris@16 1478 public random_access_iterator_base<typename iterator_restrict_traits<
Chris@16 1479 typename subiterator1_type::iterator_category, packed_random_access_iterator_tag>::iterator_category,
Chris@16 1480 iterator1, value_type> {
Chris@16 1481 public:
Chris@16 1482 typedef typename subiterator1_type::value_type value_type;
Chris@16 1483 typedef typename subiterator1_type::difference_type difference_type;
Chris@16 1484 typedef typename subiterator1_type::reference reference;
Chris@16 1485 typedef typename subiterator1_type::pointer pointer;
Chris@16 1486
Chris@16 1487 typedef iterator2 dual_iterator_type;
Chris@16 1488 typedef reverse_iterator2 dual_reverse_iterator_type;
Chris@16 1489
Chris@16 1490 // Construction and destruction
Chris@16 1491 BOOST_UBLAS_INLINE
Chris@16 1492 iterator1 ():
Chris@16 1493 container_reference<self_type> (), it1_ () {}
Chris@16 1494 BOOST_UBLAS_INLINE
Chris@16 1495 iterator1 (self_type &m, const subiterator1_type &it1):
Chris@16 1496 container_reference<self_type> (m), it1_ (it1) {}
Chris@16 1497
Chris@16 1498 // Arithmetic
Chris@16 1499 BOOST_UBLAS_INLINE
Chris@16 1500 iterator1 &operator ++ () {
Chris@16 1501 ++ it1_;
Chris@16 1502 return *this;
Chris@16 1503 }
Chris@16 1504 BOOST_UBLAS_INLINE
Chris@16 1505 iterator1 &operator -- () {
Chris@16 1506 -- it1_;
Chris@16 1507 return *this;
Chris@16 1508 }
Chris@16 1509 BOOST_UBLAS_INLINE
Chris@16 1510 iterator1 &operator += (difference_type n) {
Chris@16 1511 it1_ += n;
Chris@16 1512 return *this;
Chris@16 1513 }
Chris@16 1514 BOOST_UBLAS_INLINE
Chris@16 1515 iterator1 &operator -= (difference_type n) {
Chris@16 1516 it1_ -= n;
Chris@16 1517 return *this;
Chris@16 1518 }
Chris@16 1519 BOOST_UBLAS_INLINE
Chris@16 1520 difference_type operator - (const iterator1 &it) const {
Chris@16 1521 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 1522 return it1_ - it.it1_;
Chris@16 1523 }
Chris@16 1524
Chris@16 1525 // Dereference
Chris@16 1526 BOOST_UBLAS_INLINE
Chris@16 1527 reference operator * () const {
Chris@16 1528 size_type i = index1 ();
Chris@16 1529 size_type j = index2 ();
Chris@16 1530 BOOST_UBLAS_CHECK (i < (*this) ().size1 (), bad_index ());
Chris@16 1531 BOOST_UBLAS_CHECK (j < (*this) ().size2 (), bad_index ());
Chris@16 1532 if (triangular_type::other (i, j))
Chris@16 1533 return *it1_;
Chris@16 1534 else
Chris@16 1535 return (*this) () (i, j);
Chris@16 1536 }
Chris@16 1537 BOOST_UBLAS_INLINE
Chris@16 1538 reference operator [] (difference_type n) const {
Chris@16 1539 return *(*this + n);
Chris@16 1540 }
Chris@16 1541
Chris@16 1542 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
Chris@16 1543 BOOST_UBLAS_INLINE
Chris@16 1544 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1545 typename self_type::
Chris@16 1546 #endif
Chris@16 1547 iterator2 begin () const {
Chris@16 1548 return (*this) ().find2 (1, index1 (), 0);
Chris@16 1549 }
Chris@16 1550 BOOST_UBLAS_INLINE
Chris@16 1551 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1552 typename self_type::
Chris@16 1553 #endif
Chris@16 1554 iterator2 end () const {
Chris@16 1555 return (*this) ().find2 (1, index1 (), (*this) ().size2 ());
Chris@16 1556 }
Chris@16 1557 BOOST_UBLAS_INLINE
Chris@16 1558 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1559 typename self_type::
Chris@16 1560 #endif
Chris@16 1561 reverse_iterator2 rbegin () const {
Chris@16 1562 return reverse_iterator2 (end ());
Chris@16 1563 }
Chris@16 1564 BOOST_UBLAS_INLINE
Chris@16 1565 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1566 typename self_type::
Chris@16 1567 #endif
Chris@16 1568 reverse_iterator2 rend () const {
Chris@16 1569 return reverse_iterator2 (begin ());
Chris@16 1570 }
Chris@16 1571 #endif
Chris@16 1572
Chris@16 1573 // Indices
Chris@16 1574 BOOST_UBLAS_INLINE
Chris@16 1575 size_type index1 () const {
Chris@16 1576 return it1_.index1 ();
Chris@16 1577 }
Chris@16 1578 BOOST_UBLAS_INLINE
Chris@16 1579 size_type index2 () const {
Chris@16 1580 return it1_.index2 ();
Chris@16 1581 }
Chris@16 1582
Chris@16 1583 // Assignment
Chris@16 1584 BOOST_UBLAS_INLINE
Chris@16 1585 iterator1 &operator = (const iterator1 &it) {
Chris@16 1586 container_reference<self_type>::assign (&it ());
Chris@16 1587 it1_ = it.it1_;
Chris@16 1588 return *this;
Chris@16 1589 }
Chris@16 1590
Chris@16 1591 // Comparison
Chris@16 1592 BOOST_UBLAS_INLINE
Chris@16 1593 bool operator == (const iterator1 &it) const {
Chris@16 1594 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 1595 return it1_ == it.it1_;
Chris@16 1596 }
Chris@16 1597 BOOST_UBLAS_INLINE
Chris@16 1598 bool operator < (const iterator1 &it) const {
Chris@16 1599 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 1600 return it1_ < it.it1_;
Chris@16 1601 }
Chris@16 1602
Chris@16 1603 private:
Chris@16 1604 subiterator1_type it1_;
Chris@16 1605
Chris@16 1606 friend class const_iterator1;
Chris@16 1607 };
Chris@16 1608 #endif
Chris@16 1609
Chris@16 1610 BOOST_UBLAS_INLINE
Chris@16 1611 iterator1 begin1 () {
Chris@16 1612 return find1 (0, 0, 0);
Chris@16 1613 }
Chris@16 1614 BOOST_UBLAS_INLINE
Chris@16 1615 iterator1 end1 () {
Chris@16 1616 return find1 (0, size1 (), 0);
Chris@16 1617 }
Chris@16 1618
Chris@16 1619 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
Chris@16 1620 class const_iterator2:
Chris@16 1621 public container_const_reference<triangular_adaptor>,
Chris@16 1622 public random_access_iterator_base<typename iterator_restrict_traits<
Chris@16 1623 typename const_subiterator1_type::iterator_category, packed_random_access_iterator_tag>::iterator_category,
Chris@16 1624 const_iterator2, value_type> {
Chris@16 1625 public:
Chris@16 1626 typedef typename const_subiterator2_type::value_type value_type;
Chris@16 1627 typedef typename const_subiterator2_type::difference_type difference_type;
Chris@16 1628 typedef typename const_subiterator2_type::reference reference;
Chris@16 1629 typedef typename const_subiterator2_type::pointer pointer;
Chris@16 1630
Chris@16 1631 typedef const_iterator1 dual_iterator_type;
Chris@16 1632 typedef const_reverse_iterator1 dual_reverse_iterator_type;
Chris@16 1633
Chris@16 1634 // Construction and destruction
Chris@16 1635 BOOST_UBLAS_INLINE
Chris@16 1636 const_iterator2 ():
Chris@16 1637 container_const_reference<self_type> (), it2_ () {}
Chris@16 1638 BOOST_UBLAS_INLINE
Chris@16 1639 const_iterator2 (const self_type &m, const const_subiterator2_type &it2):
Chris@16 1640 container_const_reference<self_type> (m), it2_ (it2) {}
Chris@16 1641 BOOST_UBLAS_INLINE
Chris@16 1642 const_iterator2 (const iterator2 &it):
Chris@16 1643 container_const_reference<self_type> (it ()), it2_ (it.it2_) {}
Chris@16 1644
Chris@16 1645 // Arithmetic
Chris@16 1646 BOOST_UBLAS_INLINE
Chris@16 1647 const_iterator2 &operator ++ () {
Chris@16 1648 ++ it2_;
Chris@16 1649 return *this;
Chris@16 1650 }
Chris@16 1651 BOOST_UBLAS_INLINE
Chris@16 1652 const_iterator2 &operator -- () {
Chris@16 1653 -- it2_;
Chris@16 1654 return *this;
Chris@16 1655 }
Chris@16 1656 BOOST_UBLAS_INLINE
Chris@16 1657 const_iterator2 &operator += (difference_type n) {
Chris@16 1658 it2_ += n;
Chris@16 1659 return *this;
Chris@16 1660 }
Chris@16 1661 BOOST_UBLAS_INLINE
Chris@16 1662 const_iterator2 &operator -= (difference_type n) {
Chris@16 1663 it2_ -= n;
Chris@16 1664 return *this;
Chris@16 1665 }
Chris@16 1666 BOOST_UBLAS_INLINE
Chris@16 1667 difference_type operator - (const const_iterator2 &it) const {
Chris@16 1668 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 1669 return it2_ - it.it2_;
Chris@16 1670 }
Chris@16 1671
Chris@16 1672 // Dereference
Chris@16 1673 BOOST_UBLAS_INLINE
Chris@16 1674 const_reference operator * () const {
Chris@16 1675 size_type i = index1 ();
Chris@16 1676 size_type j = index2 ();
Chris@16 1677 BOOST_UBLAS_CHECK (i < (*this) ().size1 (), bad_index ());
Chris@16 1678 BOOST_UBLAS_CHECK (j < (*this) ().size2 (), bad_index ());
Chris@16 1679 if (triangular_type::other (i, j))
Chris@16 1680 return *it2_;
Chris@16 1681 else
Chris@16 1682 return (*this) () (i, j);
Chris@16 1683 }
Chris@16 1684 BOOST_UBLAS_INLINE
Chris@16 1685 const_reference operator [] (difference_type n) const {
Chris@16 1686 return *(*this + n);
Chris@16 1687 }
Chris@16 1688
Chris@16 1689 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
Chris@16 1690 BOOST_UBLAS_INLINE
Chris@16 1691 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1692 typename self_type::
Chris@16 1693 #endif
Chris@16 1694 const_iterator1 begin () const {
Chris@16 1695 return (*this) ().find1 (1, 0, index2 ());
Chris@16 1696 }
Chris@16 1697 BOOST_UBLAS_INLINE
Chris@16 1698 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1699 typename self_type::
Chris@16 1700 #endif
Chris@101 1701 const_iterator1 cbegin () const {
Chris@101 1702 return begin ();
Chris@101 1703 }
Chris@101 1704 BOOST_UBLAS_INLINE
Chris@101 1705 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@101 1706 typename self_type::
Chris@101 1707 #endif
Chris@16 1708 const_iterator1 end () const {
Chris@16 1709 return (*this) ().find1 (1, (*this) ().size1 (), index2 ());
Chris@16 1710 }
Chris@16 1711 BOOST_UBLAS_INLINE
Chris@16 1712 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1713 typename self_type::
Chris@16 1714 #endif
Chris@101 1715 const_iterator1 cend () const {
Chris@101 1716 return end ();
Chris@101 1717 }
Chris@101 1718 BOOST_UBLAS_INLINE
Chris@101 1719 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@101 1720 typename self_type::
Chris@101 1721 #endif
Chris@16 1722 const_reverse_iterator1 rbegin () const {
Chris@16 1723 return const_reverse_iterator1 (end ());
Chris@16 1724 }
Chris@16 1725 BOOST_UBLAS_INLINE
Chris@16 1726 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1727 typename self_type::
Chris@16 1728 #endif
Chris@101 1729 const_reverse_iterator1 crbegin () const {
Chris@101 1730 return rbegin ();
Chris@101 1731 }
Chris@101 1732 BOOST_UBLAS_INLINE
Chris@101 1733 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@101 1734 typename self_type::
Chris@101 1735 #endif
Chris@16 1736 const_reverse_iterator1 rend () const {
Chris@16 1737 return const_reverse_iterator1 (begin ());
Chris@16 1738 }
Chris@101 1739 BOOST_UBLAS_INLINE
Chris@101 1740 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@101 1741 typename self_type::
Chris@101 1742 #endif
Chris@101 1743 const_reverse_iterator1 crend () const {
Chris@101 1744 return rend ();
Chris@101 1745 }
Chris@16 1746 #endif
Chris@16 1747
Chris@16 1748 // Indices
Chris@16 1749 BOOST_UBLAS_INLINE
Chris@16 1750 size_type index1 () const {
Chris@16 1751 return it2_.index1 ();
Chris@16 1752 }
Chris@16 1753 BOOST_UBLAS_INLINE
Chris@16 1754 size_type index2 () const {
Chris@16 1755 return it2_.index2 ();
Chris@16 1756 }
Chris@16 1757
Chris@16 1758 // Assignment
Chris@16 1759 BOOST_UBLAS_INLINE
Chris@16 1760 const_iterator2 &operator = (const const_iterator2 &it) {
Chris@16 1761 container_const_reference<self_type>::assign (&it ());
Chris@16 1762 it2_ = it.it2_;
Chris@16 1763 return *this;
Chris@16 1764 }
Chris@16 1765
Chris@16 1766 // Comparison
Chris@16 1767 BOOST_UBLAS_INLINE
Chris@16 1768 bool operator == (const const_iterator2 &it) const {
Chris@16 1769 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 1770 return it2_ == it.it2_;
Chris@16 1771 }
Chris@16 1772 BOOST_UBLAS_INLINE
Chris@16 1773 bool operator < (const const_iterator2 &it) const {
Chris@16 1774 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 1775 return it2_ < it.it2_;
Chris@16 1776 }
Chris@16 1777
Chris@16 1778 private:
Chris@16 1779 const_subiterator2_type it2_;
Chris@16 1780 };
Chris@16 1781 #endif
Chris@16 1782
Chris@16 1783 BOOST_UBLAS_INLINE
Chris@16 1784 const_iterator2 begin2 () const {
Chris@16 1785 return find2 (0, 0, 0);
Chris@16 1786 }
Chris@16 1787 BOOST_UBLAS_INLINE
Chris@101 1788 const_iterator2 cbegin2 () const {
Chris@101 1789 return begin2 ();
Chris@101 1790 }
Chris@101 1791 BOOST_UBLAS_INLINE
Chris@16 1792 const_iterator2 end2 () const {
Chris@16 1793 return find2 (0, 0, size2 ());
Chris@16 1794 }
Chris@101 1795 BOOST_UBLAS_INLINE
Chris@101 1796 const_iterator2 cend2 () const {
Chris@101 1797 return end2 ();
Chris@101 1798 }
Chris@16 1799
Chris@16 1800 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
Chris@16 1801 class iterator2:
Chris@16 1802 public container_reference<triangular_adaptor>,
Chris@16 1803 public random_access_iterator_base<typename iterator_restrict_traits<
Chris@16 1804 typename subiterator1_type::iterator_category, packed_random_access_iterator_tag>::iterator_category,
Chris@16 1805 iterator2, value_type> {
Chris@16 1806 public:
Chris@16 1807 typedef typename subiterator2_type::value_type value_type;
Chris@16 1808 typedef typename subiterator2_type::difference_type difference_type;
Chris@16 1809 typedef typename subiterator2_type::reference reference;
Chris@16 1810 typedef typename subiterator2_type::pointer pointer;
Chris@16 1811
Chris@16 1812 typedef iterator1 dual_iterator_type;
Chris@16 1813 typedef reverse_iterator1 dual_reverse_iterator_type;
Chris@16 1814
Chris@16 1815 // Construction and destruction
Chris@16 1816 BOOST_UBLAS_INLINE
Chris@16 1817 iterator2 ():
Chris@16 1818 container_reference<self_type> (), it2_ () {}
Chris@16 1819 BOOST_UBLAS_INLINE
Chris@16 1820 iterator2 (self_type &m, const subiterator2_type &it2):
Chris@16 1821 container_reference<self_type> (m), it2_ (it2) {}
Chris@16 1822
Chris@16 1823 // Arithmetic
Chris@16 1824 BOOST_UBLAS_INLINE
Chris@16 1825 iterator2 &operator ++ () {
Chris@16 1826 ++ it2_;
Chris@16 1827 return *this;
Chris@16 1828 }
Chris@16 1829 BOOST_UBLAS_INLINE
Chris@16 1830 iterator2 &operator -- () {
Chris@16 1831 -- it2_;
Chris@16 1832 return *this;
Chris@16 1833 }
Chris@16 1834 BOOST_UBLAS_INLINE
Chris@16 1835 iterator2 &operator += (difference_type n) {
Chris@16 1836 it2_ += n;
Chris@16 1837 return *this;
Chris@16 1838 }
Chris@16 1839 BOOST_UBLAS_INLINE
Chris@16 1840 iterator2 &operator -= (difference_type n) {
Chris@16 1841 it2_ -= n;
Chris@16 1842 return *this;
Chris@16 1843 }
Chris@16 1844 BOOST_UBLAS_INLINE
Chris@16 1845 difference_type operator - (const iterator2 &it) const {
Chris@16 1846 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 1847 return it2_ - it.it2_;
Chris@16 1848 }
Chris@16 1849
Chris@16 1850 // Dereference
Chris@16 1851 BOOST_UBLAS_INLINE
Chris@16 1852 reference operator * () const {
Chris@16 1853 size_type i = index1 ();
Chris@16 1854 size_type j = index2 ();
Chris@16 1855 BOOST_UBLAS_CHECK (i < (*this) ().size1 (), bad_index ());
Chris@16 1856 BOOST_UBLAS_CHECK (j < (*this) ().size2 (), bad_index ());
Chris@16 1857 if (triangular_type::other (i, j))
Chris@16 1858 return *it2_;
Chris@16 1859 else
Chris@16 1860 return (*this) () (i, j);
Chris@16 1861 }
Chris@16 1862 BOOST_UBLAS_INLINE
Chris@16 1863 reference operator [] (difference_type n) const {
Chris@16 1864 return *(*this + n);
Chris@16 1865 }
Chris@16 1866
Chris@16 1867 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
Chris@16 1868 BOOST_UBLAS_INLINE
Chris@16 1869 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1870 typename self_type::
Chris@16 1871 #endif
Chris@16 1872 iterator1 begin () const {
Chris@16 1873 return (*this) ().find1 (1, 0, index2 ());
Chris@16 1874 }
Chris@16 1875 BOOST_UBLAS_INLINE
Chris@16 1876 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1877 typename self_type::
Chris@16 1878 #endif
Chris@16 1879 iterator1 end () const {
Chris@16 1880 return (*this) ().find1 (1, (*this) ().size1 (), index2 ());
Chris@16 1881 }
Chris@16 1882 BOOST_UBLAS_INLINE
Chris@16 1883 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1884 typename self_type::
Chris@16 1885 #endif
Chris@16 1886 reverse_iterator1 rbegin () const {
Chris@16 1887 return reverse_iterator1 (end ());
Chris@16 1888 }
Chris@16 1889 BOOST_UBLAS_INLINE
Chris@16 1890 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1891 typename self_type::
Chris@16 1892 #endif
Chris@16 1893 reverse_iterator1 rend () const {
Chris@16 1894 return reverse_iterator1 (begin ());
Chris@16 1895 }
Chris@16 1896 #endif
Chris@16 1897
Chris@16 1898 // Indices
Chris@16 1899 BOOST_UBLAS_INLINE
Chris@16 1900 size_type index1 () const {
Chris@16 1901 return it2_.index1 ();
Chris@16 1902 }
Chris@16 1903 BOOST_UBLAS_INLINE
Chris@16 1904 size_type index2 () const {
Chris@16 1905 return it2_.index2 ();
Chris@16 1906 }
Chris@16 1907
Chris@16 1908 // Assignment
Chris@16 1909 BOOST_UBLAS_INLINE
Chris@16 1910 iterator2 &operator = (const iterator2 &it) {
Chris@16 1911 container_reference<self_type>::assign (&it ());
Chris@16 1912 it2_ = it.it2_;
Chris@16 1913 return *this;
Chris@16 1914 }
Chris@16 1915
Chris@16 1916 // Comparison
Chris@16 1917 BOOST_UBLAS_INLINE
Chris@16 1918 bool operator == (const iterator2 &it) const {
Chris@16 1919 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 1920 return it2_ == it.it2_;
Chris@16 1921 }
Chris@16 1922 BOOST_UBLAS_INLINE
Chris@16 1923 bool operator < (const iterator2 &it) const {
Chris@16 1924 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 1925 return it2_ < it.it2_;
Chris@16 1926 }
Chris@16 1927
Chris@16 1928 private:
Chris@16 1929 subiterator2_type it2_;
Chris@16 1930
Chris@16 1931 friend class const_iterator2;
Chris@16 1932 };
Chris@16 1933 #endif
Chris@16 1934
Chris@16 1935 BOOST_UBLAS_INLINE
Chris@16 1936 iterator2 begin2 () {
Chris@16 1937 return find2 (0, 0, 0);
Chris@16 1938 }
Chris@16 1939 BOOST_UBLAS_INLINE
Chris@16 1940 iterator2 end2 () {
Chris@16 1941 return find2 (0, 0, size2 ());
Chris@16 1942 }
Chris@16 1943
Chris@16 1944 // Reverse iterators
Chris@16 1945
Chris@16 1946 BOOST_UBLAS_INLINE
Chris@16 1947 const_reverse_iterator1 rbegin1 () const {
Chris@16 1948 return const_reverse_iterator1 (end1 ());
Chris@16 1949 }
Chris@16 1950 BOOST_UBLAS_INLINE
Chris@101 1951 const_reverse_iterator1 crbegin1 () const {
Chris@101 1952 return rbegin1 ();
Chris@101 1953 }
Chris@101 1954 BOOST_UBLAS_INLINE
Chris@16 1955 const_reverse_iterator1 rend1 () const {
Chris@16 1956 return const_reverse_iterator1 (begin1 ());
Chris@16 1957 }
Chris@101 1958 BOOST_UBLAS_INLINE
Chris@101 1959 const_reverse_iterator1 crend1 () const {
Chris@101 1960 return rend1 ();
Chris@101 1961 }
Chris@16 1962
Chris@16 1963 BOOST_UBLAS_INLINE
Chris@16 1964 reverse_iterator1 rbegin1 () {
Chris@16 1965 return reverse_iterator1 (end1 ());
Chris@16 1966 }
Chris@16 1967 BOOST_UBLAS_INLINE
Chris@16 1968 reverse_iterator1 rend1 () {
Chris@16 1969 return reverse_iterator1 (begin1 ());
Chris@16 1970 }
Chris@16 1971
Chris@16 1972 BOOST_UBLAS_INLINE
Chris@16 1973 const_reverse_iterator2 rbegin2 () const {
Chris@16 1974 return const_reverse_iterator2 (end2 ());
Chris@16 1975 }
Chris@16 1976 BOOST_UBLAS_INLINE
Chris@101 1977 const_reverse_iterator2 crbegin2 () const {
Chris@101 1978 return rbegin2 ();
Chris@101 1979 }
Chris@101 1980 BOOST_UBLAS_INLINE
Chris@16 1981 const_reverse_iterator2 rend2 () const {
Chris@16 1982 return const_reverse_iterator2 (begin2 ());
Chris@16 1983 }
Chris@101 1984 BOOST_UBLAS_INLINE
Chris@101 1985 const_reverse_iterator2 crend2 () const {
Chris@101 1986 return rend2 ();
Chris@101 1987 }
Chris@16 1988
Chris@16 1989 BOOST_UBLAS_INLINE
Chris@16 1990 reverse_iterator2 rbegin2 () {
Chris@16 1991 return reverse_iterator2 (end2 ());
Chris@16 1992 }
Chris@16 1993 BOOST_UBLAS_INLINE
Chris@16 1994 reverse_iterator2 rend2 () {
Chris@16 1995 return reverse_iterator2 (begin2 ());
Chris@16 1996 }
Chris@16 1997
Chris@16 1998 private:
Chris@16 1999 matrix_closure_type data_;
Chris@16 2000 static const value_type zero_;
Chris@16 2001 static const value_type one_;
Chris@16 2002 };
Chris@16 2003
Chris@16 2004 template<class M, class TRI>
Chris@16 2005 const typename triangular_adaptor<M, TRI>::value_type triangular_adaptor<M, TRI>::zero_ = value_type/*zero*/();
Chris@16 2006 template<class M, class TRI>
Chris@16 2007 const typename triangular_adaptor<M, TRI>::value_type triangular_adaptor<M, TRI>::one_ (1);
Chris@16 2008
Chris@16 2009 template <class M, class TRI>
Chris@16 2010 struct vector_temporary_traits< triangular_adaptor<M, TRI> >
Chris@16 2011 : vector_temporary_traits< typename boost::remove_const<M>::type > {} ;
Chris@16 2012 template <class M, class TRI>
Chris@16 2013 struct vector_temporary_traits< const triangular_adaptor<M, TRI> >
Chris@16 2014 : vector_temporary_traits< typename boost::remove_const<M>::type > {} ;
Chris@16 2015
Chris@16 2016 template <class M, class TRI>
Chris@16 2017 struct matrix_temporary_traits< triangular_adaptor<M, TRI> >
Chris@16 2018 : matrix_temporary_traits< typename boost::remove_const<M>::type > {};
Chris@16 2019 template <class M, class TRI>
Chris@16 2020 struct matrix_temporary_traits< const triangular_adaptor<M, TRI> >
Chris@16 2021 : matrix_temporary_traits< typename boost::remove_const<M>::type > {};
Chris@16 2022
Chris@16 2023
Chris@16 2024 template<class E1, class E2>
Chris@16 2025 struct matrix_vector_solve_traits {
Chris@16 2026 typedef typename promote_traits<typename E1::value_type, typename E2::value_type>::promote_type promote_type;
Chris@16 2027 typedef vector<promote_type> result_type;
Chris@16 2028 };
Chris@16 2029
Chris@16 2030 // Operations:
Chris@16 2031 // n * (n - 1) / 2 + n = n * (n + 1) / 2 multiplications,
Chris@16 2032 // n * (n - 1) / 2 additions
Chris@16 2033
Chris@16 2034 // Dense (proxy) case
Chris@16 2035 template<class E1, class E2>
Chris@16 2036 BOOST_UBLAS_INLINE
Chris@16 2037 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2038 lower_tag, column_major_tag, dense_proxy_tag) {
Chris@16 2039 typedef typename E2::size_type size_type;
Chris@16 2040 typedef typename E2::value_type value_type;
Chris@16 2041
Chris@16 2042 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2043 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
Chris@16 2044 size_type size = e2 ().size ();
Chris@16 2045 for (size_type n = 0; n < size; ++ n) {
Chris@16 2046 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2047 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2048 #else
Chris@16 2049 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2050 singular ().raise ();
Chris@16 2051 #endif
Chris@16 2052 value_type t = e2 () (n) /= e1 () (n, n);
Chris@16 2053 if (t != value_type/*zero*/()) {
Chris@16 2054 for (size_type m = n + 1; m < size; ++ m)
Chris@16 2055 e2 () (m) -= e1 () (m, n) * t;
Chris@16 2056 }
Chris@16 2057 }
Chris@16 2058 }
Chris@16 2059 // Packed (proxy) case
Chris@16 2060 template<class E1, class E2>
Chris@16 2061 BOOST_UBLAS_INLINE
Chris@16 2062 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2063 lower_tag, column_major_tag, packed_proxy_tag) {
Chris@16 2064 typedef typename E2::size_type size_type;
Chris@16 2065 typedef typename E2::difference_type difference_type;
Chris@16 2066 typedef typename E2::value_type value_type;
Chris@16 2067
Chris@16 2068 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2069 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
Chris@16 2070 size_type size = e2 ().size ();
Chris@16 2071 for (size_type n = 0; n < size; ++ n) {
Chris@16 2072 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2073 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2074 #else
Chris@16 2075 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2076 singular ().raise ();
Chris@16 2077 #endif
Chris@16 2078 value_type t = e2 () (n) /= e1 () (n, n);
Chris@16 2079 if (t != value_type/*zero*/()) {
Chris@16 2080 typename E1::const_iterator1 it1e1 (e1 ().find1 (1, n + 1, n));
Chris@16 2081 typename E1::const_iterator1 it1e1_end (e1 ().find1 (1, e1 ().size1 (), n));
Chris@16 2082 difference_type m (it1e1_end - it1e1);
Chris@16 2083 while (-- m >= 0)
Chris@16 2084 e2 () (it1e1.index1 ()) -= *it1e1 * t, ++ it1e1;
Chris@16 2085 }
Chris@16 2086 }
Chris@16 2087 }
Chris@16 2088 // Sparse (proxy) case
Chris@16 2089 template<class E1, class E2>
Chris@16 2090 BOOST_UBLAS_INLINE
Chris@16 2091 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2092 lower_tag, column_major_tag, unknown_storage_tag) {
Chris@16 2093 typedef typename E2::size_type size_type;
Chris@16 2094 typedef typename E2::value_type value_type;
Chris@16 2095
Chris@16 2096 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2097 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
Chris@16 2098 size_type size = e2 ().size ();
Chris@16 2099 for (size_type n = 0; n < size; ++ n) {
Chris@16 2100 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2101 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2102 #else
Chris@16 2103 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2104 singular ().raise ();
Chris@16 2105 #endif
Chris@16 2106 value_type t = e2 () (n) /= e1 () (n, n);
Chris@16 2107 if (t != value_type/*zero*/()) {
Chris@16 2108 typename E1::const_iterator1 it1e1 (e1 ().find1 (1, n + 1, n));
Chris@16 2109 typename E1::const_iterator1 it1e1_end (e1 ().find1 (1, e1 ().size1 (), n));
Chris@16 2110 while (it1e1 != it1e1_end)
Chris@16 2111 e2 () (it1e1.index1 ()) -= *it1e1 * t, ++ it1e1;
Chris@16 2112 }
Chris@16 2113 }
Chris@16 2114 }
Chris@16 2115
Chris@16 2116 // Dense (proxy) case
Chris@16 2117 template<class E1, class E2>
Chris@16 2118 BOOST_UBLAS_INLINE
Chris@16 2119 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2120 lower_tag, row_major_tag, dense_proxy_tag) {
Chris@16 2121 typedef typename E2::size_type size_type;
Chris@16 2122 typedef typename E2::value_type value_type;
Chris@16 2123
Chris@16 2124 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2125 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
Chris@16 2126 size_type size = e2 ().size ();
Chris@16 2127 for (size_type n = 0; n < size; ++ n) {
Chris@16 2128 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2129 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2130 #else
Chris@16 2131 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2132 singular ().raise ();
Chris@16 2133 #endif
Chris@16 2134 value_type t = e2 () (n) /= e1 () (n, n);
Chris@16 2135 if (t != value_type/*zero*/()) {
Chris@16 2136 for (size_type m = n + 1; m < size; ++ m)
Chris@16 2137 e2 () (m) -= e1 () (m, n) * t;
Chris@16 2138 }
Chris@16 2139 }
Chris@16 2140 }
Chris@16 2141 // Packed (proxy) case
Chris@16 2142 template<class E1, class E2>
Chris@16 2143 BOOST_UBLAS_INLINE
Chris@16 2144 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2145 lower_tag, row_major_tag, packed_proxy_tag) {
Chris@16 2146 typedef typename E2::size_type size_type;
Chris@16 2147 typedef typename E2::value_type value_type;
Chris@16 2148
Chris@16 2149 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2150 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
Chris@16 2151 size_type size = e2 ().size ();
Chris@16 2152 for (size_type n = 0; n < size; ++ n) {
Chris@16 2153 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2154 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2155 #else
Chris@16 2156 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2157 singular ().raise ();
Chris@16 2158 #endif
Chris@16 2159 value_type t = e2 () (n);
Chris@16 2160 typename E1::const_iterator2 it2e1 (e1 ().find2 (1, n, 0));
Chris@16 2161 typename E1::const_iterator2 it2e1_end (e1 ().find2 (1, n, n));
Chris@16 2162 while (it2e1 != it2e1_end) {
Chris@16 2163 t -= *it2e1 * e2 () (it2e1.index2());
Chris@16 2164 ++ it2e1;
Chris@16 2165 }
Chris@16 2166 e2() (n) = t / e1 () (n, n);
Chris@16 2167 }
Chris@16 2168 }
Chris@16 2169 // Sparse (proxy) case
Chris@16 2170 template<class E1, class E2>
Chris@16 2171 BOOST_UBLAS_INLINE
Chris@16 2172 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2173 lower_tag, row_major_tag, unknown_storage_tag) {
Chris@16 2174 typedef typename E2::size_type size_type;
Chris@16 2175 typedef typename E2::value_type value_type;
Chris@16 2176
Chris@16 2177 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2178 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
Chris@16 2179 size_type size = e2 ().size ();
Chris@16 2180 for (size_type n = 0; n < size; ++ n) {
Chris@16 2181 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2182 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2183 #else
Chris@16 2184 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2185 singular ().raise ();
Chris@16 2186 #endif
Chris@16 2187 value_type t = e2 () (n);
Chris@16 2188 typename E1::const_iterator2 it2e1 (e1 ().find2 (1, n, 0));
Chris@16 2189 typename E1::const_iterator2 it2e1_end (e1 ().find2 (1, n, n));
Chris@16 2190 while (it2e1 != it2e1_end) {
Chris@16 2191 t -= *it2e1 * e2 () (it2e1.index2());
Chris@16 2192 ++ it2e1;
Chris@16 2193 }
Chris@16 2194 e2() (n) = t / e1 () (n, n);
Chris@16 2195 }
Chris@16 2196 }
Chris@16 2197
Chris@16 2198 // Redirectors :-)
Chris@16 2199 template<class E1, class E2>
Chris@16 2200 BOOST_UBLAS_INLINE
Chris@16 2201 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2202 lower_tag, column_major_tag) {
Chris@16 2203 typedef typename E1::storage_category storage_category;
Chris@16 2204 inplace_solve (e1, e2,
Chris@16 2205 lower_tag (), column_major_tag (), storage_category ());
Chris@16 2206 }
Chris@16 2207 template<class E1, class E2>
Chris@16 2208 BOOST_UBLAS_INLINE
Chris@16 2209 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2210 lower_tag, row_major_tag) {
Chris@16 2211 typedef typename E1::storage_category storage_category;
Chris@16 2212 inplace_solve (e1, e2,
Chris@16 2213 lower_tag (), row_major_tag (), storage_category ());
Chris@16 2214 }
Chris@16 2215 // Dispatcher
Chris@16 2216 template<class E1, class E2>
Chris@16 2217 BOOST_UBLAS_INLINE
Chris@16 2218 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2219 lower_tag) {
Chris@16 2220 typedef typename E1::orientation_category orientation_category;
Chris@16 2221 inplace_solve (e1, e2,
Chris@16 2222 lower_tag (), orientation_category ());
Chris@16 2223 }
Chris@16 2224 template<class E1, class E2>
Chris@16 2225 BOOST_UBLAS_INLINE
Chris@16 2226 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2227 unit_lower_tag) {
Chris@16 2228 typedef typename E1::orientation_category orientation_category;
Chris@16 2229 inplace_solve (triangular_adaptor<const E1, unit_lower> (e1 ()), e2,
Chris@16 2230 unit_lower_tag (), orientation_category ());
Chris@16 2231 }
Chris@16 2232
Chris@16 2233 // Dense (proxy) case
Chris@16 2234 template<class E1, class E2>
Chris@16 2235 BOOST_UBLAS_INLINE
Chris@16 2236 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2237 upper_tag, column_major_tag, dense_proxy_tag) {
Chris@16 2238 typedef typename E2::size_type size_type;
Chris@16 2239 typedef typename E2::difference_type difference_type;
Chris@16 2240 typedef typename E2::value_type value_type;
Chris@16 2241
Chris@16 2242 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2243 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
Chris@16 2244 size_type size = e2 ().size ();
Chris@16 2245 for (difference_type n = size - 1; n >= 0; -- n) {
Chris@16 2246 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2247 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2248 #else
Chris@16 2249 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2250 singular ().raise ();
Chris@16 2251 #endif
Chris@16 2252 value_type t = e2 () (n) /= e1 () (n, n);
Chris@16 2253 if (t != value_type/*zero*/()) {
Chris@16 2254 for (difference_type m = n - 1; m >= 0; -- m)
Chris@16 2255 e2 () (m) -= e1 () (m, n) * t;
Chris@16 2256 }
Chris@16 2257 }
Chris@16 2258 }
Chris@16 2259 // Packed (proxy) case
Chris@16 2260 template<class E1, class E2>
Chris@16 2261 BOOST_UBLAS_INLINE
Chris@16 2262 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2263 upper_tag, column_major_tag, packed_proxy_tag) {
Chris@16 2264 typedef typename E2::size_type size_type;
Chris@16 2265 typedef typename E2::difference_type difference_type;
Chris@16 2266 typedef typename E2::value_type value_type;
Chris@16 2267
Chris@16 2268 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2269 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
Chris@16 2270 size_type size = e2 ().size ();
Chris@16 2271 for (difference_type n = size - 1; n >= 0; -- n) {
Chris@16 2272 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2273 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2274 #else
Chris@16 2275 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2276 singular ().raise ();
Chris@16 2277 #endif
Chris@16 2278 value_type t = e2 () (n) /= e1 () (n, n);
Chris@16 2279 if (t != value_type/*zero*/()) {
Chris@16 2280 typename E1::const_reverse_iterator1 it1e1 (e1 ().find1 (1, n, n));
Chris@16 2281 typename E1::const_reverse_iterator1 it1e1_rend (e1 ().find1 (1, 0, n));
Chris@16 2282 while (it1e1 != it1e1_rend) {
Chris@16 2283 e2 () (it1e1.index1 ()) -= *it1e1 * t, ++ it1e1;
Chris@16 2284 }
Chris@16 2285 }
Chris@16 2286 }
Chris@16 2287 }
Chris@16 2288 // Sparse (proxy) case
Chris@16 2289 template<class E1, class E2>
Chris@16 2290 BOOST_UBLAS_INLINE
Chris@16 2291 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2292 upper_tag, column_major_tag, unknown_storage_tag) {
Chris@16 2293 typedef typename E2::size_type size_type;
Chris@16 2294 typedef typename E2::difference_type difference_type;
Chris@16 2295 typedef typename E2::value_type value_type;
Chris@16 2296
Chris@16 2297 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2298 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
Chris@16 2299 size_type size = e2 ().size ();
Chris@16 2300 for (difference_type n = size - 1; n >= 0; -- n) {
Chris@16 2301 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2302 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2303 #else
Chris@16 2304 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2305 singular ().raise ();
Chris@16 2306 #endif
Chris@16 2307 value_type t = e2 () (n) /= e1 () (n, n);
Chris@16 2308 if (t != value_type/*zero*/()) {
Chris@16 2309 typename E1::const_reverse_iterator1 it1e1 (e1 ().find1 (1, n, n));
Chris@16 2310 typename E1::const_reverse_iterator1 it1e1_rend (e1 ().find1 (1, 0, n));
Chris@16 2311 while (it1e1 != it1e1_rend) {
Chris@16 2312 e2 () (it1e1.index1 ()) -= *it1e1 * t, ++ it1e1;
Chris@16 2313 }
Chris@16 2314 }
Chris@16 2315 }
Chris@16 2316 }
Chris@16 2317
Chris@16 2318 // Dense (proxy) case
Chris@16 2319 template<class E1, class E2>
Chris@16 2320 BOOST_UBLAS_INLINE
Chris@16 2321 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2322 upper_tag, row_major_tag, dense_proxy_tag) {
Chris@16 2323 typedef typename E2::size_type size_type;
Chris@16 2324 typedef typename E2::difference_type difference_type;
Chris@16 2325 typedef typename E2::value_type value_type;
Chris@16 2326
Chris@16 2327 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2328 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
Chris@16 2329 size_type size = e1 ().size1 ();
Chris@16 2330 for (difference_type n = size-1; n >=0; -- n) {
Chris@16 2331 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2332 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2333 #else
Chris@16 2334 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2335 singular ().raise ();
Chris@16 2336 #endif
Chris@16 2337 value_type t = e2 () (n);
Chris@101 2338 for (difference_type m = n + 1; m < static_cast<difference_type>(e1 ().size2()); ++ m) {
Chris@16 2339 t -= e1 () (n, m) * e2 () (m);
Chris@16 2340 }
Chris@16 2341 e2() (n) = t / e1 () (n, n);
Chris@16 2342 }
Chris@16 2343 }
Chris@16 2344 // Packed (proxy) case
Chris@16 2345 template<class E1, class E2>
Chris@16 2346 BOOST_UBLAS_INLINE
Chris@16 2347 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2348 upper_tag, row_major_tag, packed_proxy_tag) {
Chris@16 2349 typedef typename E2::size_type size_type;
Chris@16 2350 typedef typename E2::difference_type difference_type;
Chris@16 2351 typedef typename E2::value_type value_type;
Chris@16 2352
Chris@16 2353 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2354 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
Chris@16 2355 size_type size = e1 ().size1 ();
Chris@16 2356 for (difference_type n = size-1; n >=0; -- n) {
Chris@16 2357 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2358 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2359 #else
Chris@16 2360 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2361 singular ().raise ();
Chris@16 2362 #endif
Chris@16 2363 value_type t = e2 () (n);
Chris@16 2364 typename E1::const_iterator2 it2e1 (e1 ().find2 (1, n, n+1));
Chris@16 2365 typename E1::const_iterator2 it2e1_end (e1 ().find2 (1, n, e1 ().size2 ()));
Chris@16 2366 while (it2e1 != it2e1_end) {
Chris@16 2367 t -= *it2e1 * e2 () (it2e1.index2());
Chris@16 2368 ++ it2e1;
Chris@16 2369 }
Chris@16 2370 e2() (n) = t / e1 () (n, n);
Chris@16 2371
Chris@16 2372 }
Chris@16 2373 }
Chris@16 2374 // Sparse (proxy) case
Chris@16 2375 template<class E1, class E2>
Chris@16 2376 BOOST_UBLAS_INLINE
Chris@16 2377 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2378 upper_tag, row_major_tag, unknown_storage_tag) {
Chris@16 2379 typedef typename E2::size_type size_type;
Chris@16 2380 typedef typename E2::difference_type difference_type;
Chris@16 2381 typedef typename E2::value_type value_type;
Chris@16 2382
Chris@16 2383 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2384 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
Chris@16 2385 size_type size = e1 ().size1 ();
Chris@16 2386 for (difference_type n = size-1; n >=0; -- n) {
Chris@16 2387 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2388 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2389 #else
Chris@16 2390 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2391 singular ().raise ();
Chris@16 2392 #endif
Chris@16 2393 value_type t = e2 () (n);
Chris@16 2394 typename E1::const_iterator2 it2e1 (e1 ().find2 (1, n, n+1));
Chris@16 2395 typename E1::const_iterator2 it2e1_end (e1 ().find2 (1, n, e1 ().size2 ()));
Chris@16 2396 while (it2e1 != it2e1_end) {
Chris@16 2397 t -= *it2e1 * e2 () (it2e1.index2());
Chris@16 2398 ++ it2e1;
Chris@16 2399 }
Chris@16 2400 e2() (n) = t / e1 () (n, n);
Chris@16 2401
Chris@16 2402 }
Chris@16 2403 }
Chris@16 2404
Chris@16 2405 // Redirectors :-)
Chris@16 2406 template<class E1, class E2>
Chris@16 2407 BOOST_UBLAS_INLINE
Chris@16 2408 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2409 upper_tag, column_major_tag) {
Chris@16 2410 typedef typename E1::storage_category storage_category;
Chris@16 2411 inplace_solve (e1, e2,
Chris@16 2412 upper_tag (), column_major_tag (), storage_category ());
Chris@16 2413 }
Chris@16 2414 template<class E1, class E2>
Chris@16 2415 BOOST_UBLAS_INLINE
Chris@16 2416 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2417 upper_tag, row_major_tag) {
Chris@16 2418 typedef typename E1::storage_category storage_category;
Chris@16 2419 inplace_solve (e1, e2,
Chris@16 2420 upper_tag (), row_major_tag (), storage_category ());
Chris@16 2421 }
Chris@16 2422 // Dispatcher
Chris@16 2423 template<class E1, class E2>
Chris@16 2424 BOOST_UBLAS_INLINE
Chris@16 2425 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2426 upper_tag) {
Chris@16 2427 typedef typename E1::orientation_category orientation_category;
Chris@16 2428 inplace_solve (e1, e2,
Chris@16 2429 upper_tag (), orientation_category ());
Chris@16 2430 }
Chris@16 2431 template<class E1, class E2>
Chris@16 2432 BOOST_UBLAS_INLINE
Chris@16 2433 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2434 unit_upper_tag) {
Chris@16 2435 typedef typename E1::orientation_category orientation_category;
Chris@16 2436 inplace_solve (triangular_adaptor<const E1, unit_upper> (e1 ()), e2,
Chris@16 2437 unit_upper_tag (), orientation_category ());
Chris@16 2438 }
Chris@16 2439
Chris@16 2440 template<class E1, class E2, class C>
Chris@16 2441 BOOST_UBLAS_INLINE
Chris@16 2442 typename matrix_vector_solve_traits<E1, E2>::result_type
Chris@16 2443 solve (const matrix_expression<E1> &e1,
Chris@16 2444 const vector_expression<E2> &e2,
Chris@16 2445 C) {
Chris@16 2446 typename matrix_vector_solve_traits<E1, E2>::result_type r (e2);
Chris@16 2447 inplace_solve (e1, r, C ());
Chris@16 2448 return r;
Chris@16 2449 }
Chris@16 2450
Chris@16 2451
Chris@16 2452 // Redirectors :-)
Chris@16 2453 template<class E1, class E2>
Chris@16 2454 BOOST_UBLAS_INLINE
Chris@16 2455 void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
Chris@16 2456 lower_tag, row_major_tag) {
Chris@16 2457 typedef typename E2::storage_category storage_category;
Chris@16 2458 inplace_solve (trans(e2), e1,
Chris@16 2459 upper_tag (), column_major_tag (), storage_category ());
Chris@16 2460 }
Chris@16 2461 template<class E1, class E2>
Chris@16 2462 BOOST_UBLAS_INLINE
Chris@16 2463 void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
Chris@16 2464 lower_tag, column_major_tag) {
Chris@16 2465 typedef typename E2::storage_category storage_category;
Chris@16 2466 inplace_solve (trans (e2), e1,
Chris@16 2467 upper_tag (), row_major_tag (), storage_category ());
Chris@16 2468 }
Chris@16 2469 // Dispatcher
Chris@16 2470 template<class E1, class E2>
Chris@16 2471 BOOST_UBLAS_INLINE
Chris@16 2472 void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
Chris@16 2473 lower_tag) {
Chris@16 2474 typedef typename E2::orientation_category orientation_category;
Chris@16 2475 inplace_solve (e1, e2,
Chris@16 2476 lower_tag (), orientation_category ());
Chris@16 2477 }
Chris@16 2478 template<class E1, class E2>
Chris@16 2479 BOOST_UBLAS_INLINE
Chris@16 2480 void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
Chris@16 2481 unit_lower_tag) {
Chris@16 2482 typedef typename E2::orientation_category orientation_category;
Chris@16 2483 inplace_solve (e1, triangular_adaptor<const E2, unit_lower> (e2 ()),
Chris@16 2484 unit_lower_tag (), orientation_category ());
Chris@16 2485 }
Chris@16 2486
Chris@16 2487
Chris@16 2488 // Redirectors :-)
Chris@16 2489 template<class E1, class E2>
Chris@16 2490 BOOST_UBLAS_INLINE
Chris@16 2491 void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
Chris@16 2492 upper_tag, row_major_tag) {
Chris@16 2493 typedef typename E2::storage_category storage_category;
Chris@16 2494 inplace_solve (trans(e2), e1,
Chris@16 2495 lower_tag (), column_major_tag (), storage_category ());
Chris@16 2496 }
Chris@16 2497 template<class E1, class E2>
Chris@16 2498 BOOST_UBLAS_INLINE
Chris@16 2499 void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
Chris@16 2500 upper_tag, column_major_tag) {
Chris@16 2501 typedef typename E2::storage_category storage_category;
Chris@16 2502 inplace_solve (trans (e2), e1,
Chris@16 2503 lower_tag (), row_major_tag (), storage_category ());
Chris@16 2504 }
Chris@16 2505 // Dispatcher
Chris@16 2506 template<class E1, class E2>
Chris@16 2507 BOOST_UBLAS_INLINE
Chris@16 2508 void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
Chris@16 2509 upper_tag) {
Chris@16 2510 typedef typename E2::orientation_category orientation_category;
Chris@16 2511 inplace_solve (e1, e2,
Chris@16 2512 upper_tag (), orientation_category ());
Chris@16 2513 }
Chris@16 2514 template<class E1, class E2>
Chris@16 2515 BOOST_UBLAS_INLINE
Chris@16 2516 void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
Chris@16 2517 unit_upper_tag) {
Chris@16 2518 typedef typename E2::orientation_category orientation_category;
Chris@16 2519 inplace_solve (e1, triangular_adaptor<const E2, unit_upper> (e2 ()),
Chris@16 2520 unit_upper_tag (), orientation_category ());
Chris@16 2521 }
Chris@16 2522
Chris@16 2523 template<class E1, class E2, class C>
Chris@16 2524 BOOST_UBLAS_INLINE
Chris@16 2525 typename matrix_vector_solve_traits<E1, E2>::result_type
Chris@16 2526 solve (const vector_expression<E1> &e1,
Chris@16 2527 const matrix_expression<E2> &e2,
Chris@16 2528 C) {
Chris@16 2529 typename matrix_vector_solve_traits<E1, E2>::result_type r (e1);
Chris@16 2530 inplace_solve (r, e2, C ());
Chris@16 2531 return r;
Chris@16 2532 }
Chris@16 2533
Chris@16 2534 template<class E1, class E2>
Chris@16 2535 struct matrix_matrix_solve_traits {
Chris@16 2536 typedef typename promote_traits<typename E1::value_type, typename E2::value_type>::promote_type promote_type;
Chris@16 2537 typedef matrix<promote_type> result_type;
Chris@16 2538 };
Chris@16 2539
Chris@16 2540 // Operations:
Chris@16 2541 // k * n * (n - 1) / 2 + k * n = k * n * (n + 1) / 2 multiplications,
Chris@16 2542 // k * n * (n - 1) / 2 additions
Chris@16 2543
Chris@16 2544 // Dense (proxy) case
Chris@16 2545 template<class E1, class E2>
Chris@16 2546 BOOST_UBLAS_INLINE
Chris@16 2547 void inplace_solve (const matrix_expression<E1> &e1, matrix_expression<E2> &e2,
Chris@16 2548 lower_tag, dense_proxy_tag) {
Chris@16 2549 typedef typename E2::size_type size_type;
Chris@16 2550 typedef typename E2::value_type value_type;
Chris@16 2551
Chris@16 2552 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2553 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size1 (), bad_size ());
Chris@16 2554 size_type size1 = e2 ().size1 ();
Chris@16 2555 size_type size2 = e2 ().size2 ();
Chris@16 2556 for (size_type n = 0; n < size1; ++ n) {
Chris@16 2557 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2558 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2559 #else
Chris@16 2560 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2561 singular ().raise ();
Chris@16 2562 #endif
Chris@16 2563 for (size_type l = 0; l < size2; ++ l) {
Chris@16 2564 value_type t = e2 () (n, l) /= e1 () (n, n);
Chris@16 2565 if (t != value_type/*zero*/()) {
Chris@16 2566 for (size_type m = n + 1; m < size1; ++ m)
Chris@16 2567 e2 () (m, l) -= e1 () (m, n) * t;
Chris@16 2568 }
Chris@16 2569 }
Chris@16 2570 }
Chris@16 2571 }
Chris@16 2572 // Packed (proxy) case
Chris@16 2573 template<class E1, class E2>
Chris@16 2574 BOOST_UBLAS_INLINE
Chris@16 2575 void inplace_solve (const matrix_expression<E1> &e1, matrix_expression<E2> &e2,
Chris@16 2576 lower_tag, packed_proxy_tag) {
Chris@16 2577 typedef typename E2::size_type size_type;
Chris@16 2578 typedef typename E2::difference_type difference_type;
Chris@16 2579 typedef typename E2::value_type value_type;
Chris@16 2580
Chris@16 2581 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2582 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size1 (), bad_size ());
Chris@16 2583 size_type size1 = e2 ().size1 ();
Chris@16 2584 size_type size2 = e2 ().size2 ();
Chris@16 2585 for (size_type n = 0; n < size1; ++ n) {
Chris@16 2586 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2587 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2588 #else
Chris@16 2589 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2590 singular ().raise ();
Chris@16 2591 #endif
Chris@16 2592 for (size_type l = 0; l < size2; ++ l) {
Chris@16 2593 value_type t = e2 () (n, l) /= e1 () (n, n);
Chris@16 2594 if (t != value_type/*zero*/()) {
Chris@16 2595 typename E1::const_iterator1 it1e1 (e1 ().find1 (1, n + 1, n));
Chris@16 2596 typename E1::const_iterator1 it1e1_end (e1 ().find1 (1, e1 ().size1 (), n));
Chris@16 2597 difference_type m (it1e1_end - it1e1);
Chris@16 2598 while (-- m >= 0)
Chris@16 2599 e2 () (it1e1.index1 (), l) -= *it1e1 * t, ++ it1e1;
Chris@16 2600 }
Chris@16 2601 }
Chris@16 2602 }
Chris@16 2603 }
Chris@16 2604 // Sparse (proxy) case
Chris@16 2605 template<class E1, class E2>
Chris@16 2606 BOOST_UBLAS_INLINE
Chris@16 2607 void inplace_solve (const matrix_expression<E1> &e1, matrix_expression<E2> &e2,
Chris@16 2608 lower_tag, unknown_storage_tag) {
Chris@16 2609 typedef typename E2::size_type size_type;
Chris@16 2610 typedef typename E2::value_type value_type;
Chris@16 2611
Chris@16 2612 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2613 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size1 (), bad_size ());
Chris@16 2614 size_type size1 = e2 ().size1 ();
Chris@16 2615 size_type size2 = e2 ().size2 ();
Chris@16 2616 for (size_type n = 0; n < size1; ++ n) {
Chris@16 2617 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2618 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2619 #else
Chris@16 2620 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2621 singular ().raise ();
Chris@16 2622 #endif
Chris@16 2623 for (size_type l = 0; l < size2; ++ l) {
Chris@16 2624 value_type t = e2 () (n, l) /= e1 () (n, n);
Chris@16 2625 if (t != value_type/*zero*/()) {
Chris@16 2626 typename E1::const_iterator1 it1e1 (e1 ().find1 (1, n + 1, n));
Chris@16 2627 typename E1::const_iterator1 it1e1_end (e1 ().find1 (1, e1 ().size1 (), n));
Chris@16 2628 while (it1e1 != it1e1_end)
Chris@16 2629 e2 () (it1e1.index1 (), l) -= *it1e1 * t, ++ it1e1;
Chris@16 2630 }
Chris@16 2631 }
Chris@16 2632 }
Chris@16 2633 }
Chris@16 2634 // Dispatcher
Chris@16 2635 template<class E1, class E2>
Chris@16 2636 BOOST_UBLAS_INLINE
Chris@16 2637 void inplace_solve (const matrix_expression<E1> &e1, matrix_expression<E2> &e2,
Chris@16 2638 lower_tag) {
Chris@16 2639 typedef typename E1::storage_category dispatch_category;
Chris@16 2640 inplace_solve (e1, e2,
Chris@16 2641 lower_tag (), dispatch_category ());
Chris@16 2642 }
Chris@16 2643 template<class E1, class E2>
Chris@16 2644 BOOST_UBLAS_INLINE
Chris@16 2645 void inplace_solve (const matrix_expression<E1> &e1, matrix_expression<E2> &e2,
Chris@16 2646 unit_lower_tag) {
Chris@16 2647 typedef typename E1::storage_category dispatch_category;
Chris@16 2648 inplace_solve (triangular_adaptor<const E1, unit_lower> (e1 ()), e2,
Chris@16 2649 unit_lower_tag (), dispatch_category ());
Chris@16 2650 }
Chris@16 2651
Chris@16 2652 // Dense (proxy) case
Chris@16 2653 template<class E1, class E2>
Chris@16 2654 BOOST_UBLAS_INLINE
Chris@16 2655 void inplace_solve (const matrix_expression<E1> &e1, matrix_expression<E2> &e2,
Chris@16 2656 upper_tag, dense_proxy_tag) {
Chris@16 2657 typedef typename E2::size_type size_type;
Chris@16 2658 typedef typename E2::difference_type difference_type;
Chris@16 2659 typedef typename E2::value_type value_type;
Chris@16 2660
Chris@16 2661 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2662 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size1 (), bad_size ());
Chris@16 2663 size_type size1 = e2 ().size1 ();
Chris@16 2664 size_type size2 = e2 ().size2 ();
Chris@16 2665 for (difference_type n = size1 - 1; n >= 0; -- n) {
Chris@16 2666 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2667 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2668 #else
Chris@16 2669 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2670 singular ().raise ();
Chris@16 2671 #endif
Chris@16 2672 for (difference_type l = size2 - 1; l >= 0; -- l) {
Chris@16 2673 value_type t = e2 () (n, l) /= e1 () (n, n);
Chris@16 2674 if (t != value_type/*zero*/()) {
Chris@16 2675 for (difference_type m = n - 1; m >= 0; -- m)
Chris@16 2676 e2 () (m, l) -= e1 () (m, n) * t;
Chris@16 2677 }
Chris@16 2678 }
Chris@16 2679 }
Chris@16 2680 }
Chris@16 2681 // Packed (proxy) case
Chris@16 2682 template<class E1, class E2>
Chris@16 2683 BOOST_UBLAS_INLINE
Chris@16 2684 void inplace_solve (const matrix_expression<E1> &e1, matrix_expression<E2> &e2,
Chris@16 2685 upper_tag, packed_proxy_tag) {
Chris@16 2686 typedef typename E2::size_type size_type;
Chris@16 2687 typedef typename E2::difference_type difference_type;
Chris@16 2688 typedef typename E2::value_type value_type;
Chris@16 2689
Chris@16 2690 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2691 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size1 (), bad_size ());
Chris@16 2692 size_type size1 = e2 ().size1 ();
Chris@16 2693 size_type size2 = e2 ().size2 ();
Chris@16 2694 for (difference_type n = size1 - 1; n >= 0; -- n) {
Chris@16 2695 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2696 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2697 #else
Chris@16 2698 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2699 singular ().raise ();
Chris@16 2700 #endif
Chris@16 2701 for (difference_type l = size2 - 1; l >= 0; -- l) {
Chris@16 2702 value_type t = e2 () (n, l) /= e1 () (n, n);
Chris@16 2703 if (t != value_type/*zero*/()) {
Chris@16 2704 typename E1::const_reverse_iterator1 it1e1 (e1 ().find1 (1, n, n));
Chris@16 2705 typename E1::const_reverse_iterator1 it1e1_rend (e1 ().find1 (1, 0, n));
Chris@16 2706 difference_type m (it1e1_rend - it1e1);
Chris@16 2707 while (-- m >= 0)
Chris@16 2708 e2 () (it1e1.index1 (), l) -= *it1e1 * t, ++ it1e1;
Chris@16 2709 }
Chris@16 2710 }
Chris@16 2711 }
Chris@16 2712 }
Chris@16 2713 // Sparse (proxy) case
Chris@16 2714 template<class E1, class E2>
Chris@16 2715 BOOST_UBLAS_INLINE
Chris@16 2716 void inplace_solve (const matrix_expression<E1> &e1, matrix_expression<E2> &e2,
Chris@16 2717 upper_tag, unknown_storage_tag) {
Chris@16 2718 typedef typename E2::size_type size_type;
Chris@16 2719 typedef typename E2::difference_type difference_type;
Chris@16 2720 typedef typename E2::value_type value_type;
Chris@16 2721
Chris@16 2722 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2723 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size1 (), bad_size ());
Chris@16 2724 size_type size1 = e2 ().size1 ();
Chris@16 2725 size_type size2 = e2 ().size2 ();
Chris@16 2726 for (difference_type n = size1 - 1; n >= 0; -- n) {
Chris@16 2727 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2728 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2729 #else
Chris@16 2730 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2731 singular ().raise ();
Chris@16 2732 #endif
Chris@16 2733 for (difference_type l = size2 - 1; l >= 0; -- l) {
Chris@16 2734 value_type t = e2 () (n, l) /= e1 () (n, n);
Chris@16 2735 if (t != value_type/*zero*/()) {
Chris@16 2736 typename E1::const_reverse_iterator1 it1e1 (e1 ().find1 (1, n, n));
Chris@16 2737 typename E1::const_reverse_iterator1 it1e1_rend (e1 ().find1 (1, 0, n));
Chris@16 2738 while (it1e1 != it1e1_rend)
Chris@16 2739 e2 () (it1e1.index1 (), l) -= *it1e1 * t, ++ it1e1;
Chris@16 2740 }
Chris@16 2741 }
Chris@16 2742 }
Chris@16 2743 }
Chris@16 2744 // Dispatcher
Chris@16 2745 template<class E1, class E2>
Chris@16 2746 BOOST_UBLAS_INLINE
Chris@16 2747 void inplace_solve (const matrix_expression<E1> &e1, matrix_expression<E2> &e2,
Chris@16 2748 upper_tag) {
Chris@16 2749 typedef typename E1::storage_category dispatch_category;
Chris@16 2750 inplace_solve (e1, e2,
Chris@16 2751 upper_tag (), dispatch_category ());
Chris@16 2752 }
Chris@16 2753 template<class E1, class E2>
Chris@16 2754 BOOST_UBLAS_INLINE
Chris@16 2755 void inplace_solve (const matrix_expression<E1> &e1, matrix_expression<E2> &e2,
Chris@16 2756 unit_upper_tag) {
Chris@16 2757 typedef typename E1::storage_category dispatch_category;
Chris@16 2758 inplace_solve (triangular_adaptor<const E1, unit_upper> (e1 ()), e2,
Chris@16 2759 unit_upper_tag (), dispatch_category ());
Chris@16 2760 }
Chris@16 2761
Chris@16 2762 template<class E1, class E2, class C>
Chris@16 2763 BOOST_UBLAS_INLINE
Chris@16 2764 typename matrix_matrix_solve_traits<E1, E2>::result_type
Chris@16 2765 solve (const matrix_expression<E1> &e1,
Chris@16 2766 const matrix_expression<E2> &e2,
Chris@16 2767 C) {
Chris@16 2768 typename matrix_matrix_solve_traits<E1, E2>::result_type r (e2);
Chris@16 2769 inplace_solve (e1, r, C ());
Chris@16 2770 return r;
Chris@16 2771 }
Chris@16 2772
Chris@16 2773 }}}
Chris@16 2774
Chris@16 2775 #endif