annotate DEPENDENCIES/generic/include/boost/numeric/ublas/triangular.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
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@16 421 const_iterator2 end () const {
Chris@16 422 return (*this) ().find2 (1, it1_, (*this) ().size2 ());
Chris@16 423 }
Chris@16 424 BOOST_UBLAS_INLINE
Chris@16 425 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 426 typename self_type::
Chris@16 427 #endif
Chris@16 428 const_reverse_iterator2 rbegin () const {
Chris@16 429 return const_reverse_iterator2 (end ());
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@16 435 const_reverse_iterator2 rend () const {
Chris@16 436 return const_reverse_iterator2 (begin ());
Chris@16 437 }
Chris@16 438 #endif
Chris@16 439
Chris@16 440 // Indices
Chris@16 441 BOOST_UBLAS_INLINE
Chris@16 442 size_type index1 () const {
Chris@16 443 return it1_;
Chris@16 444 }
Chris@16 445 BOOST_UBLAS_INLINE
Chris@16 446 size_type index2 () const {
Chris@16 447 return it2_;
Chris@16 448 }
Chris@16 449
Chris@16 450 // Assignment
Chris@16 451 BOOST_UBLAS_INLINE
Chris@16 452 const_iterator1 &operator = (const const_iterator1 &it) {
Chris@16 453 container_const_reference<self_type>::assign (&it ());
Chris@16 454 it1_ = it.it1_;
Chris@16 455 it2_ = it.it2_;
Chris@16 456 return *this;
Chris@16 457 }
Chris@16 458
Chris@16 459 // Comparison
Chris@16 460 BOOST_UBLAS_INLINE
Chris@16 461 bool operator == (const const_iterator1 &it) const {
Chris@16 462 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 463 BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
Chris@16 464 return it1_ == it.it1_;
Chris@16 465 }
Chris@16 466 BOOST_UBLAS_INLINE
Chris@16 467 bool operator < (const const_iterator1 &it) const {
Chris@16 468 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 469 BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
Chris@16 470 return it1_ < it.it1_;
Chris@16 471 }
Chris@16 472
Chris@16 473 private:
Chris@16 474 size_type it1_;
Chris@16 475 size_type it2_;
Chris@16 476 };
Chris@16 477 #endif
Chris@16 478
Chris@16 479 BOOST_UBLAS_INLINE
Chris@16 480 const_iterator1 begin1 () const {
Chris@16 481 return find1 (0, 0, 0);
Chris@16 482 }
Chris@16 483 BOOST_UBLAS_INLINE
Chris@16 484 const_iterator1 end1 () const {
Chris@16 485 return find1 (0, size1_, 0);
Chris@16 486 }
Chris@16 487
Chris@16 488 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
Chris@16 489 class iterator1:
Chris@16 490 public container_reference<triangular_matrix>,
Chris@16 491 public random_access_iterator_base<packed_random_access_iterator_tag,
Chris@16 492 iterator1, value_type> {
Chris@16 493 public:
Chris@16 494 typedef typename triangular_matrix::value_type value_type;
Chris@16 495 typedef typename triangular_matrix::difference_type difference_type;
Chris@16 496 typedef typename triangular_matrix::reference reference;
Chris@16 497 typedef typename triangular_matrix::pointer pointer;
Chris@16 498
Chris@16 499 typedef iterator2 dual_iterator_type;
Chris@16 500 typedef reverse_iterator2 dual_reverse_iterator_type;
Chris@16 501
Chris@16 502 // Construction and destruction
Chris@16 503 BOOST_UBLAS_INLINE
Chris@16 504 iterator1 ():
Chris@16 505 container_reference<self_type> (), it1_ (), it2_ () {}
Chris@16 506 BOOST_UBLAS_INLINE
Chris@16 507 iterator1 (self_type &m, size_type it1, size_type it2):
Chris@16 508 container_reference<self_type> (m), it1_ (it1), it2_ (it2) {}
Chris@16 509
Chris@16 510 // Arithmetic
Chris@16 511 BOOST_UBLAS_INLINE
Chris@16 512 iterator1 &operator ++ () {
Chris@16 513 ++ it1_;
Chris@16 514 return *this;
Chris@16 515 }
Chris@16 516 BOOST_UBLAS_INLINE
Chris@16 517 iterator1 &operator -- () {
Chris@16 518 -- it1_;
Chris@16 519 return *this;
Chris@16 520 }
Chris@16 521 BOOST_UBLAS_INLINE
Chris@16 522 iterator1 &operator += (difference_type n) {
Chris@16 523 it1_ += n;
Chris@16 524 return *this;
Chris@16 525 }
Chris@16 526 BOOST_UBLAS_INLINE
Chris@16 527 iterator1 &operator -= (difference_type n) {
Chris@16 528 it1_ -= n;
Chris@16 529 return *this;
Chris@16 530 }
Chris@16 531 BOOST_UBLAS_INLINE
Chris@16 532 difference_type operator - (const iterator1 &it) const {
Chris@16 533 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 534 BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
Chris@16 535 return it1_ - it.it1_;
Chris@16 536 }
Chris@16 537
Chris@16 538 // Dereference
Chris@16 539 BOOST_UBLAS_INLINE
Chris@16 540 reference operator * () const {
Chris@16 541 return (*this) () (it1_, it2_);
Chris@16 542 }
Chris@16 543 BOOST_UBLAS_INLINE
Chris@16 544 reference operator [] (difference_type n) const {
Chris@16 545 return *(*this + n);
Chris@16 546 }
Chris@16 547
Chris@16 548 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
Chris@16 549 BOOST_UBLAS_INLINE
Chris@16 550 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 551 typename self_type::
Chris@16 552 #endif
Chris@16 553 iterator2 begin () const {
Chris@16 554 return (*this) ().find2 (1, it1_, 0);
Chris@16 555 }
Chris@16 556 BOOST_UBLAS_INLINE
Chris@16 557 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 558 typename self_type::
Chris@16 559 #endif
Chris@16 560 iterator2 end () const {
Chris@16 561 return (*this) ().find2 (1, it1_, (*this) ().size2 ());
Chris@16 562 }
Chris@16 563 BOOST_UBLAS_INLINE
Chris@16 564 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 565 typename self_type::
Chris@16 566 #endif
Chris@16 567 reverse_iterator2 rbegin () const {
Chris@16 568 return reverse_iterator2 (end ());
Chris@16 569 }
Chris@16 570 BOOST_UBLAS_INLINE
Chris@16 571 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 572 typename self_type::
Chris@16 573 #endif
Chris@16 574 reverse_iterator2 rend () const {
Chris@16 575 return reverse_iterator2 (begin ());
Chris@16 576 }
Chris@16 577 #endif
Chris@16 578
Chris@16 579 // Indices
Chris@16 580 BOOST_UBLAS_INLINE
Chris@16 581 size_type index1 () const {
Chris@16 582 return it1_;
Chris@16 583 }
Chris@16 584 BOOST_UBLAS_INLINE
Chris@16 585 size_type index2 () const {
Chris@16 586 return it2_;
Chris@16 587 }
Chris@16 588
Chris@16 589 // Assignment
Chris@16 590 BOOST_UBLAS_INLINE
Chris@16 591 iterator1 &operator = (const iterator1 &it) {
Chris@16 592 container_reference<self_type>::assign (&it ());
Chris@16 593 it1_ = it.it1_;
Chris@16 594 it2_ = it.it2_;
Chris@16 595 return *this;
Chris@16 596 }
Chris@16 597
Chris@16 598 // Comparison
Chris@16 599 BOOST_UBLAS_INLINE
Chris@16 600 bool operator == (const iterator1 &it) const {
Chris@16 601 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 602 BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
Chris@16 603 return it1_ == it.it1_;
Chris@16 604 }
Chris@16 605 BOOST_UBLAS_INLINE
Chris@16 606 bool operator < (const iterator1 &it) const {
Chris@16 607 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 608 BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
Chris@16 609 return it1_ < it.it1_;
Chris@16 610 }
Chris@16 611
Chris@16 612 private:
Chris@16 613 size_type it1_;
Chris@16 614 size_type it2_;
Chris@16 615
Chris@16 616 friend class const_iterator1;
Chris@16 617 };
Chris@16 618 #endif
Chris@16 619
Chris@16 620 BOOST_UBLAS_INLINE
Chris@16 621 iterator1 begin1 () {
Chris@16 622 return find1 (0, 0, 0);
Chris@16 623 }
Chris@16 624 BOOST_UBLAS_INLINE
Chris@16 625 iterator1 end1 () {
Chris@16 626 return find1 (0, size1_, 0);
Chris@16 627 }
Chris@16 628
Chris@16 629 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
Chris@16 630 class const_iterator2:
Chris@16 631 public container_const_reference<triangular_matrix>,
Chris@16 632 public random_access_iterator_base<packed_random_access_iterator_tag,
Chris@16 633 const_iterator2, value_type> {
Chris@16 634 public:
Chris@16 635 typedef typename triangular_matrix::value_type value_type;
Chris@16 636 typedef typename triangular_matrix::difference_type difference_type;
Chris@16 637 typedef typename triangular_matrix::const_reference reference;
Chris@16 638 typedef const typename triangular_matrix::pointer pointer;
Chris@16 639
Chris@16 640 typedef const_iterator1 dual_iterator_type;
Chris@16 641 typedef const_reverse_iterator1 dual_reverse_iterator_type;
Chris@16 642
Chris@16 643 // Construction and destruction
Chris@16 644 BOOST_UBLAS_INLINE
Chris@16 645 const_iterator2 ():
Chris@16 646 container_const_reference<self_type> (), it1_ (), it2_ () {}
Chris@16 647 BOOST_UBLAS_INLINE
Chris@16 648 const_iterator2 (const self_type &m, size_type it1, size_type it2):
Chris@16 649 container_const_reference<self_type> (m), it1_ (it1), it2_ (it2) {}
Chris@16 650 BOOST_UBLAS_INLINE
Chris@16 651 const_iterator2 (const iterator2 &it):
Chris@16 652 container_const_reference<self_type> (it ()), it1_ (it.it1_), it2_ (it.it2_) {}
Chris@16 653
Chris@16 654 // Arithmetic
Chris@16 655 BOOST_UBLAS_INLINE
Chris@16 656 const_iterator2 &operator ++ () {
Chris@16 657 ++ it2_;
Chris@16 658 return *this;
Chris@16 659 }
Chris@16 660 BOOST_UBLAS_INLINE
Chris@16 661 const_iterator2 &operator -- () {
Chris@16 662 -- it2_;
Chris@16 663 return *this;
Chris@16 664 }
Chris@16 665 BOOST_UBLAS_INLINE
Chris@16 666 const_iterator2 &operator += (difference_type n) {
Chris@16 667 it2_ += n;
Chris@16 668 return *this;
Chris@16 669 }
Chris@16 670 BOOST_UBLAS_INLINE
Chris@16 671 const_iterator2 &operator -= (difference_type n) {
Chris@16 672 it2_ -= n;
Chris@16 673 return *this;
Chris@16 674 }
Chris@16 675 BOOST_UBLAS_INLINE
Chris@16 676 difference_type operator - (const const_iterator2 &it) const {
Chris@16 677 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 678 BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
Chris@16 679 return it2_ - it.it2_;
Chris@16 680 }
Chris@16 681
Chris@16 682 // Dereference
Chris@16 683 BOOST_UBLAS_INLINE
Chris@16 684 const_reference operator * () const {
Chris@16 685 return (*this) () (it1_, it2_);
Chris@16 686 }
Chris@16 687 BOOST_UBLAS_INLINE
Chris@16 688 const_reference operator [] (difference_type n) const {
Chris@16 689 return *(*this + n);
Chris@16 690 }
Chris@16 691
Chris@16 692 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
Chris@16 693 BOOST_UBLAS_INLINE
Chris@16 694 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 695 typename self_type::
Chris@16 696 #endif
Chris@16 697 const_iterator1 begin () const {
Chris@16 698 return (*this) ().find1 (1, 0, it2_);
Chris@16 699 }
Chris@16 700 BOOST_UBLAS_INLINE
Chris@16 701 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 702 typename self_type::
Chris@16 703 #endif
Chris@16 704 const_iterator1 end () const {
Chris@16 705 return (*this) ().find1 (1, (*this) ().size1 (), it2_);
Chris@16 706 }
Chris@16 707 BOOST_UBLAS_INLINE
Chris@16 708 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 709 typename self_type::
Chris@16 710 #endif
Chris@16 711 const_reverse_iterator1 rbegin () const {
Chris@16 712 return const_reverse_iterator1 (end ());
Chris@16 713 }
Chris@16 714 BOOST_UBLAS_INLINE
Chris@16 715 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 716 typename self_type::
Chris@16 717 #endif
Chris@16 718 const_reverse_iterator1 rend () const {
Chris@16 719 return const_reverse_iterator1 (begin ());
Chris@16 720 }
Chris@16 721 #endif
Chris@16 722
Chris@16 723 // Indices
Chris@16 724 BOOST_UBLAS_INLINE
Chris@16 725 size_type index1 () const {
Chris@16 726 return it1_;
Chris@16 727 }
Chris@16 728 BOOST_UBLAS_INLINE
Chris@16 729 size_type index2 () const {
Chris@16 730 return it2_;
Chris@16 731 }
Chris@16 732
Chris@16 733 // Assignment
Chris@16 734 BOOST_UBLAS_INLINE
Chris@16 735 const_iterator2 &operator = (const const_iterator2 &it) {
Chris@16 736 container_const_reference<self_type>::assign (&it ());
Chris@16 737 it1_ = it.it1_;
Chris@16 738 it2_ = it.it2_;
Chris@16 739 return *this;
Chris@16 740 }
Chris@16 741
Chris@16 742 // Comparison
Chris@16 743 BOOST_UBLAS_INLINE
Chris@16 744 bool operator == (const const_iterator2 &it) const {
Chris@16 745 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 746 BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
Chris@16 747 return it2_ == it.it2_;
Chris@16 748 }
Chris@16 749 BOOST_UBLAS_INLINE
Chris@16 750 bool operator < (const const_iterator2 &it) const {
Chris@16 751 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 752 BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
Chris@16 753 return it2_ < it.it2_;
Chris@16 754 }
Chris@16 755
Chris@16 756 private:
Chris@16 757 size_type it1_;
Chris@16 758 size_type it2_;
Chris@16 759 };
Chris@16 760 #endif
Chris@16 761
Chris@16 762 BOOST_UBLAS_INLINE
Chris@16 763 const_iterator2 begin2 () const {
Chris@16 764 return find2 (0, 0, 0);
Chris@16 765 }
Chris@16 766 BOOST_UBLAS_INLINE
Chris@16 767 const_iterator2 end2 () const {
Chris@16 768 return find2 (0, 0, size2_);
Chris@16 769 }
Chris@16 770
Chris@16 771 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
Chris@16 772 class iterator2:
Chris@16 773 public container_reference<triangular_matrix>,
Chris@16 774 public random_access_iterator_base<packed_random_access_iterator_tag,
Chris@16 775 iterator2, value_type> {
Chris@16 776 public:
Chris@16 777 typedef typename triangular_matrix::value_type value_type;
Chris@16 778 typedef typename triangular_matrix::difference_type difference_type;
Chris@16 779 typedef typename triangular_matrix::reference reference;
Chris@16 780 typedef typename triangular_matrix::pointer pointer;
Chris@16 781
Chris@16 782 typedef iterator1 dual_iterator_type;
Chris@16 783 typedef reverse_iterator1 dual_reverse_iterator_type;
Chris@16 784
Chris@16 785 // Construction and destruction
Chris@16 786 BOOST_UBLAS_INLINE
Chris@16 787 iterator2 ():
Chris@16 788 container_reference<self_type> (), it1_ (), it2_ () {}
Chris@16 789 BOOST_UBLAS_INLINE
Chris@16 790 iterator2 (self_type &m, size_type it1, size_type it2):
Chris@16 791 container_reference<self_type> (m), it1_ (it1), it2_ (it2) {}
Chris@16 792
Chris@16 793 // Arithmetic
Chris@16 794 BOOST_UBLAS_INLINE
Chris@16 795 iterator2 &operator ++ () {
Chris@16 796 ++ it2_;
Chris@16 797 return *this;
Chris@16 798 }
Chris@16 799 BOOST_UBLAS_INLINE
Chris@16 800 iterator2 &operator -- () {
Chris@16 801 -- it2_;
Chris@16 802 return *this;
Chris@16 803 }
Chris@16 804 BOOST_UBLAS_INLINE
Chris@16 805 iterator2 &operator += (difference_type n) {
Chris@16 806 it2_ += n;
Chris@16 807 return *this;
Chris@16 808 }
Chris@16 809 BOOST_UBLAS_INLINE
Chris@16 810 iterator2 &operator -= (difference_type n) {
Chris@16 811 it2_ -= n;
Chris@16 812 return *this;
Chris@16 813 }
Chris@16 814 BOOST_UBLAS_INLINE
Chris@16 815 difference_type operator - (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 // Dereference
Chris@16 822 BOOST_UBLAS_INLINE
Chris@16 823 reference operator * () const {
Chris@16 824 return (*this) () (it1_, it2_);
Chris@16 825 }
Chris@16 826 BOOST_UBLAS_INLINE
Chris@16 827 reference operator [] (difference_type n) const {
Chris@16 828 return *(*this + n);
Chris@16 829 }
Chris@16 830
Chris@16 831 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
Chris@16 832 BOOST_UBLAS_INLINE
Chris@16 833 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 834 typename self_type::
Chris@16 835 #endif
Chris@16 836 iterator1 begin () const {
Chris@16 837 return (*this) ().find1 (1, 0, it2_);
Chris@16 838 }
Chris@16 839 BOOST_UBLAS_INLINE
Chris@16 840 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 841 typename self_type::
Chris@16 842 #endif
Chris@16 843 iterator1 end () const {
Chris@16 844 return (*this) ().find1 (1, (*this) ().size1 (), it2_);
Chris@16 845 }
Chris@16 846 BOOST_UBLAS_INLINE
Chris@16 847 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 848 typename self_type::
Chris@16 849 #endif
Chris@16 850 reverse_iterator1 rbegin () const {
Chris@16 851 return reverse_iterator1 (end ());
Chris@16 852 }
Chris@16 853 BOOST_UBLAS_INLINE
Chris@16 854 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 855 typename self_type::
Chris@16 856 #endif
Chris@16 857 reverse_iterator1 rend () const {
Chris@16 858 return reverse_iterator1 (begin ());
Chris@16 859 }
Chris@16 860 #endif
Chris@16 861
Chris@16 862 // Indices
Chris@16 863 BOOST_UBLAS_INLINE
Chris@16 864 size_type index1 () const {
Chris@16 865 return it1_;
Chris@16 866 }
Chris@16 867 BOOST_UBLAS_INLINE
Chris@16 868 size_type index2 () const {
Chris@16 869 return it2_;
Chris@16 870 }
Chris@16 871
Chris@16 872 // Assignment
Chris@16 873 BOOST_UBLAS_INLINE
Chris@16 874 iterator2 &operator = (const iterator2 &it) {
Chris@16 875 container_reference<self_type>::assign (&it ());
Chris@16 876 it1_ = it.it1_;
Chris@16 877 it2_ = it.it2_;
Chris@16 878 return *this;
Chris@16 879 }
Chris@16 880
Chris@16 881 // Comparison
Chris@16 882 BOOST_UBLAS_INLINE
Chris@16 883 bool operator == (const iterator2 &it) const {
Chris@16 884 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 885 BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
Chris@16 886 return it2_ == it.it2_;
Chris@16 887 }
Chris@16 888 BOOST_UBLAS_INLINE
Chris@16 889 bool operator < (const iterator2 &it) const {
Chris@16 890 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 891 BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
Chris@16 892 return it2_ < it.it2_;
Chris@16 893 }
Chris@16 894
Chris@16 895 private:
Chris@16 896 size_type it1_;
Chris@16 897 size_type it2_;
Chris@16 898
Chris@16 899 friend class const_iterator2;
Chris@16 900 };
Chris@16 901 #endif
Chris@16 902
Chris@16 903 BOOST_UBLAS_INLINE
Chris@16 904 iterator2 begin2 () {
Chris@16 905 return find2 (0, 0, 0);
Chris@16 906 }
Chris@16 907 BOOST_UBLAS_INLINE
Chris@16 908 iterator2 end2 () {
Chris@16 909 return find2 (0, 0, size2_);
Chris@16 910 }
Chris@16 911
Chris@16 912 // Reverse iterators
Chris@16 913
Chris@16 914 BOOST_UBLAS_INLINE
Chris@16 915 const_reverse_iterator1 rbegin1 () const {
Chris@16 916 return const_reverse_iterator1 (end1 ());
Chris@16 917 }
Chris@16 918 BOOST_UBLAS_INLINE
Chris@16 919 const_reverse_iterator1 rend1 () const {
Chris@16 920 return const_reverse_iterator1 (begin1 ());
Chris@16 921 }
Chris@16 922
Chris@16 923 BOOST_UBLAS_INLINE
Chris@16 924 reverse_iterator1 rbegin1 () {
Chris@16 925 return reverse_iterator1 (end1 ());
Chris@16 926 }
Chris@16 927 BOOST_UBLAS_INLINE
Chris@16 928 reverse_iterator1 rend1 () {
Chris@16 929 return reverse_iterator1 (begin1 ());
Chris@16 930 }
Chris@16 931
Chris@16 932 BOOST_UBLAS_INLINE
Chris@16 933 const_reverse_iterator2 rbegin2 () const {
Chris@16 934 return const_reverse_iterator2 (end2 ());
Chris@16 935 }
Chris@16 936 BOOST_UBLAS_INLINE
Chris@16 937 const_reverse_iterator2 rend2 () const {
Chris@16 938 return const_reverse_iterator2 (begin2 ());
Chris@16 939 }
Chris@16 940
Chris@16 941 BOOST_UBLAS_INLINE
Chris@16 942 reverse_iterator2 rbegin2 () {
Chris@16 943 return reverse_iterator2 (end2 ());
Chris@16 944 }
Chris@16 945 BOOST_UBLAS_INLINE
Chris@16 946 reverse_iterator2 rend2 () {
Chris@16 947 return reverse_iterator2 (begin2 ());
Chris@16 948 }
Chris@16 949
Chris@16 950 private:
Chris@16 951 size_type size1_;
Chris@16 952 size_type size2_;
Chris@16 953 array_type data_;
Chris@16 954 static const value_type zero_;
Chris@16 955 static const value_type one_;
Chris@16 956 };
Chris@16 957
Chris@16 958 template<class T, class TRI, class L, class A>
Chris@16 959 const typename triangular_matrix<T, TRI, L, A>::value_type triangular_matrix<T, TRI, L, A>::zero_ = value_type/*zero*/();
Chris@16 960 template<class T, class TRI, class L, class A>
Chris@16 961 const typename triangular_matrix<T, TRI, L, A>::value_type triangular_matrix<T, TRI, L, A>::one_ (1);
Chris@16 962
Chris@16 963
Chris@16 964 // Triangular matrix adaptor class
Chris@16 965 template<class M, class TRI>
Chris@16 966 class triangular_adaptor:
Chris@16 967 public matrix_expression<triangular_adaptor<M, TRI> > {
Chris@16 968
Chris@16 969 typedef triangular_adaptor<M, TRI> self_type;
Chris@16 970
Chris@16 971 public:
Chris@16 972 #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
Chris@16 973 using matrix_expression<self_type>::operator ();
Chris@16 974 #endif
Chris@16 975 typedef const M const_matrix_type;
Chris@16 976 typedef M matrix_type;
Chris@16 977 typedef TRI triangular_type;
Chris@16 978 typedef typename M::size_type size_type;
Chris@16 979 typedef typename M::difference_type difference_type;
Chris@16 980 typedef typename M::value_type value_type;
Chris@16 981 typedef typename M::const_reference const_reference;
Chris@16 982 typedef typename boost::mpl::if_<boost::is_const<M>,
Chris@16 983 typename M::const_reference,
Chris@16 984 typename M::reference>::type reference;
Chris@16 985 typedef typename boost::mpl::if_<boost::is_const<M>,
Chris@16 986 typename M::const_closure_type,
Chris@16 987 typename M::closure_type>::type matrix_closure_type;
Chris@16 988 typedef const self_type const_closure_type;
Chris@16 989 typedef self_type closure_type;
Chris@16 990 // Replaced by _temporary_traits to avoid type requirements on M
Chris@16 991 //typedef typename M::vector_temporary_type vector_temporary_type;
Chris@16 992 //typedef typename M::matrix_temporary_type matrix_temporary_type;
Chris@16 993 typedef typename storage_restrict_traits<typename M::storage_category,
Chris@16 994 packed_proxy_tag>::storage_category storage_category;
Chris@16 995 typedef typename M::orientation_category orientation_category;
Chris@16 996
Chris@16 997 // Construction and destruction
Chris@16 998 BOOST_UBLAS_INLINE
Chris@16 999 triangular_adaptor (matrix_type &data):
Chris@16 1000 matrix_expression<self_type> (),
Chris@16 1001 data_ (data) {}
Chris@16 1002 BOOST_UBLAS_INLINE
Chris@16 1003 triangular_adaptor (const triangular_adaptor &m):
Chris@16 1004 matrix_expression<self_type> (),
Chris@16 1005 data_ (m.data_) {}
Chris@16 1006
Chris@16 1007 // Accessors
Chris@16 1008 BOOST_UBLAS_INLINE
Chris@16 1009 size_type size1 () const {
Chris@16 1010 return data_.size1 ();
Chris@16 1011 }
Chris@16 1012 BOOST_UBLAS_INLINE
Chris@16 1013 size_type size2 () const {
Chris@16 1014 return data_.size2 ();
Chris@16 1015 }
Chris@16 1016
Chris@16 1017 // Storage accessors
Chris@16 1018 BOOST_UBLAS_INLINE
Chris@16 1019 const matrix_closure_type &data () const {
Chris@16 1020 return data_;
Chris@16 1021 }
Chris@16 1022 BOOST_UBLAS_INLINE
Chris@16 1023 matrix_closure_type &data () {
Chris@16 1024 return data_;
Chris@16 1025 }
Chris@16 1026
Chris@16 1027 // Element access
Chris@16 1028 #ifndef BOOST_UBLAS_PROXY_CONST_MEMBER
Chris@16 1029 BOOST_UBLAS_INLINE
Chris@16 1030 const_reference operator () (size_type i, size_type j) const {
Chris@16 1031 BOOST_UBLAS_CHECK (i < size1 (), bad_index ());
Chris@16 1032 BOOST_UBLAS_CHECK (j < size2 (), bad_index ());
Chris@16 1033 if (triangular_type::other (i, j))
Chris@16 1034 return data () (i, j);
Chris@16 1035 else if (triangular_type::one (i, j))
Chris@16 1036 return one_;
Chris@16 1037 else
Chris@16 1038 return zero_;
Chris@16 1039 }
Chris@16 1040 BOOST_UBLAS_INLINE
Chris@16 1041 reference operator () (size_type i, size_type j) {
Chris@16 1042 BOOST_UBLAS_CHECK (i < size1 (), bad_index ());
Chris@16 1043 BOOST_UBLAS_CHECK (j < size2 (), bad_index ());
Chris@16 1044 if (!triangular_type::other (i, j)) {
Chris@16 1045 bad_index ().raise ();
Chris@16 1046 // NEVER reached
Chris@16 1047 }
Chris@16 1048 return data () (i, j);
Chris@16 1049 }
Chris@16 1050 #else
Chris@16 1051 BOOST_UBLAS_INLINE
Chris@16 1052 reference operator () (size_type i, size_type j) const {
Chris@16 1053 BOOST_UBLAS_CHECK (i < size1 (), bad_index ());
Chris@16 1054 BOOST_UBLAS_CHECK (j < size2 (), bad_index ());
Chris@16 1055 if (!triangular_type::other (i, j)) {
Chris@16 1056 bad_index ().raise ();
Chris@16 1057 // NEVER reached
Chris@16 1058 }
Chris@16 1059 return data () (i, j);
Chris@16 1060 }
Chris@16 1061 #endif
Chris@16 1062
Chris@16 1063 // Assignment
Chris@16 1064 BOOST_UBLAS_INLINE
Chris@16 1065 triangular_adaptor &operator = (const triangular_adaptor &m) {
Chris@16 1066 matrix_assign<scalar_assign> (*this, m);
Chris@16 1067 return *this;
Chris@16 1068 }
Chris@16 1069 BOOST_UBLAS_INLINE
Chris@16 1070 triangular_adaptor &assign_temporary (triangular_adaptor &m) {
Chris@16 1071 *this = m;
Chris@16 1072 return *this;
Chris@16 1073 }
Chris@16 1074 template<class AE>
Chris@16 1075 BOOST_UBLAS_INLINE
Chris@16 1076 triangular_adaptor &operator = (const matrix_expression<AE> &ae) {
Chris@16 1077 matrix_assign<scalar_assign> (*this, matrix<value_type> (ae));
Chris@16 1078 return *this;
Chris@16 1079 }
Chris@16 1080 template<class AE>
Chris@16 1081 BOOST_UBLAS_INLINE
Chris@16 1082 triangular_adaptor &assign (const matrix_expression<AE> &ae) {
Chris@16 1083 matrix_assign<scalar_assign> (*this, ae);
Chris@16 1084 return *this;
Chris@16 1085 }
Chris@16 1086 template<class AE>
Chris@16 1087 BOOST_UBLAS_INLINE
Chris@16 1088 triangular_adaptor& operator += (const matrix_expression<AE> &ae) {
Chris@16 1089 matrix_assign<scalar_assign> (*this, matrix<value_type> (*this + ae));
Chris@16 1090 return *this;
Chris@16 1091 }
Chris@16 1092 template<class AE>
Chris@16 1093 BOOST_UBLAS_INLINE
Chris@16 1094 triangular_adaptor &plus_assign (const matrix_expression<AE> &ae) {
Chris@16 1095 matrix_assign<scalar_plus_assign> (*this, ae);
Chris@16 1096 return *this;
Chris@16 1097 }
Chris@16 1098 template<class AE>
Chris@16 1099 BOOST_UBLAS_INLINE
Chris@16 1100 triangular_adaptor& operator -= (const matrix_expression<AE> &ae) {
Chris@16 1101 matrix_assign<scalar_assign> (*this, matrix<value_type> (*this - ae));
Chris@16 1102 return *this;
Chris@16 1103 }
Chris@16 1104 template<class AE>
Chris@16 1105 BOOST_UBLAS_INLINE
Chris@16 1106 triangular_adaptor &minus_assign (const matrix_expression<AE> &ae) {
Chris@16 1107 matrix_assign<scalar_minus_assign> (*this, ae);
Chris@16 1108 return *this;
Chris@16 1109 }
Chris@16 1110 template<class AT>
Chris@16 1111 BOOST_UBLAS_INLINE
Chris@16 1112 triangular_adaptor& operator *= (const AT &at) {
Chris@16 1113 matrix_assign_scalar<scalar_multiplies_assign> (*this, at);
Chris@16 1114 return *this;
Chris@16 1115 }
Chris@16 1116 template<class AT>
Chris@16 1117 BOOST_UBLAS_INLINE
Chris@16 1118 triangular_adaptor& operator /= (const AT &at) {
Chris@16 1119 matrix_assign_scalar<scalar_divides_assign> (*this, at);
Chris@16 1120 return *this;
Chris@16 1121 }
Chris@16 1122
Chris@16 1123 // Closure comparison
Chris@16 1124 BOOST_UBLAS_INLINE
Chris@16 1125 bool same_closure (const triangular_adaptor &ta) const {
Chris@16 1126 return (*this).data ().same_closure (ta.data ());
Chris@16 1127 }
Chris@16 1128
Chris@16 1129 // Swapping
Chris@16 1130 BOOST_UBLAS_INLINE
Chris@16 1131 void swap (triangular_adaptor &m) {
Chris@16 1132 if (this != &m)
Chris@16 1133 matrix_swap<scalar_swap> (*this, m);
Chris@16 1134 }
Chris@16 1135 BOOST_UBLAS_INLINE
Chris@16 1136 friend void swap (triangular_adaptor &m1, triangular_adaptor &m2) {
Chris@16 1137 m1.swap (m2);
Chris@16 1138 }
Chris@16 1139
Chris@16 1140 // Iterator types
Chris@16 1141 private:
Chris@16 1142 typedef typename M::const_iterator1 const_subiterator1_type;
Chris@16 1143 typedef typename boost::mpl::if_<boost::is_const<M>,
Chris@16 1144 typename M::const_iterator1,
Chris@16 1145 typename M::iterator1>::type subiterator1_type;
Chris@16 1146 typedef typename M::const_iterator2 const_subiterator2_type;
Chris@16 1147 typedef typename boost::mpl::if_<boost::is_const<M>,
Chris@16 1148 typename M::const_iterator2,
Chris@16 1149 typename M::iterator2>::type subiterator2_type;
Chris@16 1150
Chris@16 1151 public:
Chris@16 1152 #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
Chris@16 1153 typedef indexed_iterator1<self_type, packed_random_access_iterator_tag> iterator1;
Chris@16 1154 typedef indexed_iterator2<self_type, packed_random_access_iterator_tag> iterator2;
Chris@16 1155 typedef indexed_const_iterator1<self_type, packed_random_access_iterator_tag> const_iterator1;
Chris@16 1156 typedef indexed_const_iterator2<self_type, packed_random_access_iterator_tag> const_iterator2;
Chris@16 1157 #else
Chris@16 1158 class const_iterator1;
Chris@16 1159 class iterator1;
Chris@16 1160 class const_iterator2;
Chris@16 1161 class iterator2;
Chris@16 1162 #endif
Chris@16 1163 typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
Chris@16 1164 typedef reverse_iterator_base1<iterator1> reverse_iterator1;
Chris@16 1165 typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
Chris@16 1166 typedef reverse_iterator_base2<iterator2> reverse_iterator2;
Chris@16 1167
Chris@16 1168 // Element lookup
Chris@16 1169 BOOST_UBLAS_INLINE
Chris@16 1170 const_iterator1 find1 (int rank, size_type i, size_type j) const {
Chris@16 1171 if (rank == 1)
Chris@16 1172 i = triangular_type::restrict1 (i, j, size1(), size2());
Chris@16 1173 if (rank == 0)
Chris@16 1174 i = triangular_type::global_restrict1 (i, size1(), j, size2());
Chris@16 1175 return const_iterator1 (*this, data ().find1 (rank, i, j));
Chris@16 1176 }
Chris@16 1177 BOOST_UBLAS_INLINE
Chris@16 1178 iterator1 find1 (int rank, size_type i, size_type j) {
Chris@16 1179 if (rank == 1)
Chris@16 1180 i = triangular_type::mutable_restrict1 (i, j, size1(), size2());
Chris@16 1181 if (rank == 0)
Chris@16 1182 i = triangular_type::global_mutable_restrict1 (i, size1(), j, size2());
Chris@16 1183 return iterator1 (*this, data ().find1 (rank, i, j));
Chris@16 1184 }
Chris@16 1185 BOOST_UBLAS_INLINE
Chris@16 1186 const_iterator2 find2 (int rank, size_type i, size_type j) const {
Chris@16 1187 if (rank == 1)
Chris@16 1188 j = triangular_type::restrict2 (i, j, size1(), size2());
Chris@16 1189 if (rank == 0)
Chris@16 1190 j = triangular_type::global_restrict2 (i, size1(), j, size2());
Chris@16 1191 return const_iterator2 (*this, data ().find2 (rank, i, j));
Chris@16 1192 }
Chris@16 1193 BOOST_UBLAS_INLINE
Chris@16 1194 iterator2 find2 (int rank, size_type i, size_type j) {
Chris@16 1195 if (rank == 1)
Chris@16 1196 j = triangular_type::mutable_restrict2 (i, j, size1(), size2());
Chris@16 1197 if (rank == 0)
Chris@16 1198 j = triangular_type::global_mutable_restrict2 (i, size1(), j, size2());
Chris@16 1199 return iterator2 (*this, data ().find2 (rank, i, j));
Chris@16 1200 }
Chris@16 1201
Chris@16 1202 // Iterators simply are indices.
Chris@16 1203
Chris@16 1204 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
Chris@16 1205 class const_iterator1:
Chris@16 1206 public container_const_reference<triangular_adaptor>,
Chris@16 1207 public random_access_iterator_base<typename iterator_restrict_traits<
Chris@16 1208 typename const_subiterator1_type::iterator_category, packed_random_access_iterator_tag>::iterator_category,
Chris@16 1209 const_iterator1, value_type> {
Chris@16 1210 public:
Chris@16 1211 typedef typename const_subiterator1_type::value_type value_type;
Chris@16 1212 typedef typename const_subiterator1_type::difference_type difference_type;
Chris@16 1213 typedef typename const_subiterator1_type::reference reference;
Chris@16 1214 typedef typename const_subiterator1_type::pointer pointer;
Chris@16 1215
Chris@16 1216 typedef const_iterator2 dual_iterator_type;
Chris@16 1217 typedef const_reverse_iterator2 dual_reverse_iterator_type;
Chris@16 1218
Chris@16 1219 // Construction and destruction
Chris@16 1220 BOOST_UBLAS_INLINE
Chris@16 1221 const_iterator1 ():
Chris@16 1222 container_const_reference<self_type> (), it1_ () {}
Chris@16 1223 BOOST_UBLAS_INLINE
Chris@16 1224 const_iterator1 (const self_type &m, const const_subiterator1_type &it1):
Chris@16 1225 container_const_reference<self_type> (m), it1_ (it1) {}
Chris@16 1226 BOOST_UBLAS_INLINE
Chris@16 1227 const_iterator1 (const iterator1 &it):
Chris@16 1228 container_const_reference<self_type> (it ()), it1_ (it.it1_) {}
Chris@16 1229
Chris@16 1230 // Arithmetic
Chris@16 1231 BOOST_UBLAS_INLINE
Chris@16 1232 const_iterator1 &operator ++ () {
Chris@16 1233 ++ it1_;
Chris@16 1234 return *this;
Chris@16 1235 }
Chris@16 1236 BOOST_UBLAS_INLINE
Chris@16 1237 const_iterator1 &operator -- () {
Chris@16 1238 -- it1_;
Chris@16 1239 return *this;
Chris@16 1240 }
Chris@16 1241 BOOST_UBLAS_INLINE
Chris@16 1242 const_iterator1 &operator += (difference_type n) {
Chris@16 1243 it1_ += n;
Chris@16 1244 return *this;
Chris@16 1245 }
Chris@16 1246 BOOST_UBLAS_INLINE
Chris@16 1247 const_iterator1 &operator -= (difference_type n) {
Chris@16 1248 it1_ -= n;
Chris@16 1249 return *this;
Chris@16 1250 }
Chris@16 1251 BOOST_UBLAS_INLINE
Chris@16 1252 difference_type operator - (const const_iterator1 &it) const {
Chris@16 1253 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 1254 return it1_ - it.it1_;
Chris@16 1255 }
Chris@16 1256
Chris@16 1257 // Dereference
Chris@16 1258 BOOST_UBLAS_INLINE
Chris@16 1259 const_reference operator * () const {
Chris@16 1260 size_type i = index1 ();
Chris@16 1261 size_type j = index2 ();
Chris@16 1262 BOOST_UBLAS_CHECK (i < (*this) ().size1 (), bad_index ());
Chris@16 1263 BOOST_UBLAS_CHECK (j < (*this) ().size2 (), bad_index ());
Chris@16 1264 if (triangular_type::other (i, j))
Chris@16 1265 return *it1_;
Chris@16 1266 else
Chris@16 1267 return (*this) () (i, j);
Chris@16 1268 }
Chris@16 1269 BOOST_UBLAS_INLINE
Chris@16 1270 const_reference operator [] (difference_type n) const {
Chris@16 1271 return *(*this + n);
Chris@16 1272 }
Chris@16 1273
Chris@16 1274 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
Chris@16 1275 BOOST_UBLAS_INLINE
Chris@16 1276 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1277 typename self_type::
Chris@16 1278 #endif
Chris@16 1279 const_iterator2 begin () const {
Chris@16 1280 return (*this) ().find2 (1, index1 (), 0);
Chris@16 1281 }
Chris@16 1282 BOOST_UBLAS_INLINE
Chris@16 1283 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1284 typename self_type::
Chris@16 1285 #endif
Chris@16 1286 const_iterator2 end () const {
Chris@16 1287 return (*this) ().find2 (1, index1 (), (*this) ().size2 ());
Chris@16 1288 }
Chris@16 1289 BOOST_UBLAS_INLINE
Chris@16 1290 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1291 typename self_type::
Chris@16 1292 #endif
Chris@16 1293 const_reverse_iterator2 rbegin () const {
Chris@16 1294 return const_reverse_iterator2 (end ());
Chris@16 1295 }
Chris@16 1296 BOOST_UBLAS_INLINE
Chris@16 1297 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1298 typename self_type::
Chris@16 1299 #endif
Chris@16 1300 const_reverse_iterator2 rend () const {
Chris@16 1301 return const_reverse_iterator2 (begin ());
Chris@16 1302 }
Chris@16 1303 #endif
Chris@16 1304
Chris@16 1305 // Indices
Chris@16 1306 BOOST_UBLAS_INLINE
Chris@16 1307 size_type index1 () const {
Chris@16 1308 return it1_.index1 ();
Chris@16 1309 }
Chris@16 1310 BOOST_UBLAS_INLINE
Chris@16 1311 size_type index2 () const {
Chris@16 1312 return it1_.index2 ();
Chris@16 1313 }
Chris@16 1314
Chris@16 1315 // Assignment
Chris@16 1316 BOOST_UBLAS_INLINE
Chris@16 1317 const_iterator1 &operator = (const const_iterator1 &it) {
Chris@16 1318 container_const_reference<self_type>::assign (&it ());
Chris@16 1319 it1_ = it.it1_;
Chris@16 1320 return *this;
Chris@16 1321 }
Chris@16 1322
Chris@16 1323 // Comparison
Chris@16 1324 BOOST_UBLAS_INLINE
Chris@16 1325 bool operator == (const const_iterator1 &it) const {
Chris@16 1326 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 1327 return it1_ == it.it1_;
Chris@16 1328 }
Chris@16 1329 BOOST_UBLAS_INLINE
Chris@16 1330 bool operator < (const const_iterator1 &it) const {
Chris@16 1331 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 1332 return it1_ < it.it1_;
Chris@16 1333 }
Chris@16 1334
Chris@16 1335 private:
Chris@16 1336 const_subiterator1_type it1_;
Chris@16 1337 };
Chris@16 1338 #endif
Chris@16 1339
Chris@16 1340 BOOST_UBLAS_INLINE
Chris@16 1341 const_iterator1 begin1 () const {
Chris@16 1342 return find1 (0, 0, 0);
Chris@16 1343 }
Chris@16 1344 BOOST_UBLAS_INLINE
Chris@16 1345 const_iterator1 end1 () const {
Chris@16 1346 return find1 (0, size1 (), 0);
Chris@16 1347 }
Chris@16 1348
Chris@16 1349 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
Chris@16 1350 class iterator1:
Chris@16 1351 public container_reference<triangular_adaptor>,
Chris@16 1352 public random_access_iterator_base<typename iterator_restrict_traits<
Chris@16 1353 typename subiterator1_type::iterator_category, packed_random_access_iterator_tag>::iterator_category,
Chris@16 1354 iterator1, value_type> {
Chris@16 1355 public:
Chris@16 1356 typedef typename subiterator1_type::value_type value_type;
Chris@16 1357 typedef typename subiterator1_type::difference_type difference_type;
Chris@16 1358 typedef typename subiterator1_type::reference reference;
Chris@16 1359 typedef typename subiterator1_type::pointer pointer;
Chris@16 1360
Chris@16 1361 typedef iterator2 dual_iterator_type;
Chris@16 1362 typedef reverse_iterator2 dual_reverse_iterator_type;
Chris@16 1363
Chris@16 1364 // Construction and destruction
Chris@16 1365 BOOST_UBLAS_INLINE
Chris@16 1366 iterator1 ():
Chris@16 1367 container_reference<self_type> (), it1_ () {}
Chris@16 1368 BOOST_UBLAS_INLINE
Chris@16 1369 iterator1 (self_type &m, const subiterator1_type &it1):
Chris@16 1370 container_reference<self_type> (m), it1_ (it1) {}
Chris@16 1371
Chris@16 1372 // Arithmetic
Chris@16 1373 BOOST_UBLAS_INLINE
Chris@16 1374 iterator1 &operator ++ () {
Chris@16 1375 ++ it1_;
Chris@16 1376 return *this;
Chris@16 1377 }
Chris@16 1378 BOOST_UBLAS_INLINE
Chris@16 1379 iterator1 &operator -- () {
Chris@16 1380 -- it1_;
Chris@16 1381 return *this;
Chris@16 1382 }
Chris@16 1383 BOOST_UBLAS_INLINE
Chris@16 1384 iterator1 &operator += (difference_type n) {
Chris@16 1385 it1_ += n;
Chris@16 1386 return *this;
Chris@16 1387 }
Chris@16 1388 BOOST_UBLAS_INLINE
Chris@16 1389 iterator1 &operator -= (difference_type n) {
Chris@16 1390 it1_ -= n;
Chris@16 1391 return *this;
Chris@16 1392 }
Chris@16 1393 BOOST_UBLAS_INLINE
Chris@16 1394 difference_type operator - (const iterator1 &it) const {
Chris@16 1395 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 1396 return it1_ - it.it1_;
Chris@16 1397 }
Chris@16 1398
Chris@16 1399 // Dereference
Chris@16 1400 BOOST_UBLAS_INLINE
Chris@16 1401 reference operator * () const {
Chris@16 1402 size_type i = index1 ();
Chris@16 1403 size_type j = index2 ();
Chris@16 1404 BOOST_UBLAS_CHECK (i < (*this) ().size1 (), bad_index ());
Chris@16 1405 BOOST_UBLAS_CHECK (j < (*this) ().size2 (), bad_index ());
Chris@16 1406 if (triangular_type::other (i, j))
Chris@16 1407 return *it1_;
Chris@16 1408 else
Chris@16 1409 return (*this) () (i, j);
Chris@16 1410 }
Chris@16 1411 BOOST_UBLAS_INLINE
Chris@16 1412 reference operator [] (difference_type n) const {
Chris@16 1413 return *(*this + n);
Chris@16 1414 }
Chris@16 1415
Chris@16 1416 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
Chris@16 1417 BOOST_UBLAS_INLINE
Chris@16 1418 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1419 typename self_type::
Chris@16 1420 #endif
Chris@16 1421 iterator2 begin () const {
Chris@16 1422 return (*this) ().find2 (1, index1 (), 0);
Chris@16 1423 }
Chris@16 1424 BOOST_UBLAS_INLINE
Chris@16 1425 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1426 typename self_type::
Chris@16 1427 #endif
Chris@16 1428 iterator2 end () const {
Chris@16 1429 return (*this) ().find2 (1, index1 (), (*this) ().size2 ());
Chris@16 1430 }
Chris@16 1431 BOOST_UBLAS_INLINE
Chris@16 1432 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1433 typename self_type::
Chris@16 1434 #endif
Chris@16 1435 reverse_iterator2 rbegin () const {
Chris@16 1436 return reverse_iterator2 (end ());
Chris@16 1437 }
Chris@16 1438 BOOST_UBLAS_INLINE
Chris@16 1439 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1440 typename self_type::
Chris@16 1441 #endif
Chris@16 1442 reverse_iterator2 rend () const {
Chris@16 1443 return reverse_iterator2 (begin ());
Chris@16 1444 }
Chris@16 1445 #endif
Chris@16 1446
Chris@16 1447 // Indices
Chris@16 1448 BOOST_UBLAS_INLINE
Chris@16 1449 size_type index1 () const {
Chris@16 1450 return it1_.index1 ();
Chris@16 1451 }
Chris@16 1452 BOOST_UBLAS_INLINE
Chris@16 1453 size_type index2 () const {
Chris@16 1454 return it1_.index2 ();
Chris@16 1455 }
Chris@16 1456
Chris@16 1457 // Assignment
Chris@16 1458 BOOST_UBLAS_INLINE
Chris@16 1459 iterator1 &operator = (const iterator1 &it) {
Chris@16 1460 container_reference<self_type>::assign (&it ());
Chris@16 1461 it1_ = it.it1_;
Chris@16 1462 return *this;
Chris@16 1463 }
Chris@16 1464
Chris@16 1465 // Comparison
Chris@16 1466 BOOST_UBLAS_INLINE
Chris@16 1467 bool operator == (const iterator1 &it) const {
Chris@16 1468 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 1469 return it1_ == it.it1_;
Chris@16 1470 }
Chris@16 1471 BOOST_UBLAS_INLINE
Chris@16 1472 bool operator < (const iterator1 &it) const {
Chris@16 1473 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 1474 return it1_ < it.it1_;
Chris@16 1475 }
Chris@16 1476
Chris@16 1477 private:
Chris@16 1478 subiterator1_type it1_;
Chris@16 1479
Chris@16 1480 friend class const_iterator1;
Chris@16 1481 };
Chris@16 1482 #endif
Chris@16 1483
Chris@16 1484 BOOST_UBLAS_INLINE
Chris@16 1485 iterator1 begin1 () {
Chris@16 1486 return find1 (0, 0, 0);
Chris@16 1487 }
Chris@16 1488 BOOST_UBLAS_INLINE
Chris@16 1489 iterator1 end1 () {
Chris@16 1490 return find1 (0, size1 (), 0);
Chris@16 1491 }
Chris@16 1492
Chris@16 1493 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
Chris@16 1494 class const_iterator2:
Chris@16 1495 public container_const_reference<triangular_adaptor>,
Chris@16 1496 public random_access_iterator_base<typename iterator_restrict_traits<
Chris@16 1497 typename const_subiterator1_type::iterator_category, packed_random_access_iterator_tag>::iterator_category,
Chris@16 1498 const_iterator2, value_type> {
Chris@16 1499 public:
Chris@16 1500 typedef typename const_subiterator2_type::value_type value_type;
Chris@16 1501 typedef typename const_subiterator2_type::difference_type difference_type;
Chris@16 1502 typedef typename const_subiterator2_type::reference reference;
Chris@16 1503 typedef typename const_subiterator2_type::pointer pointer;
Chris@16 1504
Chris@16 1505 typedef const_iterator1 dual_iterator_type;
Chris@16 1506 typedef const_reverse_iterator1 dual_reverse_iterator_type;
Chris@16 1507
Chris@16 1508 // Construction and destruction
Chris@16 1509 BOOST_UBLAS_INLINE
Chris@16 1510 const_iterator2 ():
Chris@16 1511 container_const_reference<self_type> (), it2_ () {}
Chris@16 1512 BOOST_UBLAS_INLINE
Chris@16 1513 const_iterator2 (const self_type &m, const const_subiterator2_type &it2):
Chris@16 1514 container_const_reference<self_type> (m), it2_ (it2) {}
Chris@16 1515 BOOST_UBLAS_INLINE
Chris@16 1516 const_iterator2 (const iterator2 &it):
Chris@16 1517 container_const_reference<self_type> (it ()), it2_ (it.it2_) {}
Chris@16 1518
Chris@16 1519 // Arithmetic
Chris@16 1520 BOOST_UBLAS_INLINE
Chris@16 1521 const_iterator2 &operator ++ () {
Chris@16 1522 ++ it2_;
Chris@16 1523 return *this;
Chris@16 1524 }
Chris@16 1525 BOOST_UBLAS_INLINE
Chris@16 1526 const_iterator2 &operator -- () {
Chris@16 1527 -- it2_;
Chris@16 1528 return *this;
Chris@16 1529 }
Chris@16 1530 BOOST_UBLAS_INLINE
Chris@16 1531 const_iterator2 &operator += (difference_type n) {
Chris@16 1532 it2_ += n;
Chris@16 1533 return *this;
Chris@16 1534 }
Chris@16 1535 BOOST_UBLAS_INLINE
Chris@16 1536 const_iterator2 &operator -= (difference_type n) {
Chris@16 1537 it2_ -= n;
Chris@16 1538 return *this;
Chris@16 1539 }
Chris@16 1540 BOOST_UBLAS_INLINE
Chris@16 1541 difference_type operator - (const const_iterator2 &it) const {
Chris@16 1542 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 1543 return it2_ - it.it2_;
Chris@16 1544 }
Chris@16 1545
Chris@16 1546 // Dereference
Chris@16 1547 BOOST_UBLAS_INLINE
Chris@16 1548 const_reference operator * () const {
Chris@16 1549 size_type i = index1 ();
Chris@16 1550 size_type j = index2 ();
Chris@16 1551 BOOST_UBLAS_CHECK (i < (*this) ().size1 (), bad_index ());
Chris@16 1552 BOOST_UBLAS_CHECK (j < (*this) ().size2 (), bad_index ());
Chris@16 1553 if (triangular_type::other (i, j))
Chris@16 1554 return *it2_;
Chris@16 1555 else
Chris@16 1556 return (*this) () (i, j);
Chris@16 1557 }
Chris@16 1558 BOOST_UBLAS_INLINE
Chris@16 1559 const_reference operator [] (difference_type n) const {
Chris@16 1560 return *(*this + n);
Chris@16 1561 }
Chris@16 1562
Chris@16 1563 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
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 const_iterator1 begin () const {
Chris@16 1569 return (*this) ().find1 (1, 0, index2 ());
Chris@16 1570 }
Chris@16 1571 BOOST_UBLAS_INLINE
Chris@16 1572 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1573 typename self_type::
Chris@16 1574 #endif
Chris@16 1575 const_iterator1 end () const {
Chris@16 1576 return (*this) ().find1 (1, (*this) ().size1 (), index2 ());
Chris@16 1577 }
Chris@16 1578 BOOST_UBLAS_INLINE
Chris@16 1579 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1580 typename self_type::
Chris@16 1581 #endif
Chris@16 1582 const_reverse_iterator1 rbegin () const {
Chris@16 1583 return const_reverse_iterator1 (end ());
Chris@16 1584 }
Chris@16 1585 BOOST_UBLAS_INLINE
Chris@16 1586 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1587 typename self_type::
Chris@16 1588 #endif
Chris@16 1589 const_reverse_iterator1 rend () const {
Chris@16 1590 return const_reverse_iterator1 (begin ());
Chris@16 1591 }
Chris@16 1592 #endif
Chris@16 1593
Chris@16 1594 // Indices
Chris@16 1595 BOOST_UBLAS_INLINE
Chris@16 1596 size_type index1 () const {
Chris@16 1597 return it2_.index1 ();
Chris@16 1598 }
Chris@16 1599 BOOST_UBLAS_INLINE
Chris@16 1600 size_type index2 () const {
Chris@16 1601 return it2_.index2 ();
Chris@16 1602 }
Chris@16 1603
Chris@16 1604 // Assignment
Chris@16 1605 BOOST_UBLAS_INLINE
Chris@16 1606 const_iterator2 &operator = (const const_iterator2 &it) {
Chris@16 1607 container_const_reference<self_type>::assign (&it ());
Chris@16 1608 it2_ = it.it2_;
Chris@16 1609 return *this;
Chris@16 1610 }
Chris@16 1611
Chris@16 1612 // Comparison
Chris@16 1613 BOOST_UBLAS_INLINE
Chris@16 1614 bool operator == (const const_iterator2 &it) const {
Chris@16 1615 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 1616 return it2_ == it.it2_;
Chris@16 1617 }
Chris@16 1618 BOOST_UBLAS_INLINE
Chris@16 1619 bool operator < (const const_iterator2 &it) const {
Chris@16 1620 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 1621 return it2_ < it.it2_;
Chris@16 1622 }
Chris@16 1623
Chris@16 1624 private:
Chris@16 1625 const_subiterator2_type it2_;
Chris@16 1626 };
Chris@16 1627 #endif
Chris@16 1628
Chris@16 1629 BOOST_UBLAS_INLINE
Chris@16 1630 const_iterator2 begin2 () const {
Chris@16 1631 return find2 (0, 0, 0);
Chris@16 1632 }
Chris@16 1633 BOOST_UBLAS_INLINE
Chris@16 1634 const_iterator2 end2 () const {
Chris@16 1635 return find2 (0, 0, size2 ());
Chris@16 1636 }
Chris@16 1637
Chris@16 1638 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
Chris@16 1639 class iterator2:
Chris@16 1640 public container_reference<triangular_adaptor>,
Chris@16 1641 public random_access_iterator_base<typename iterator_restrict_traits<
Chris@16 1642 typename subiterator1_type::iterator_category, packed_random_access_iterator_tag>::iterator_category,
Chris@16 1643 iterator2, value_type> {
Chris@16 1644 public:
Chris@16 1645 typedef typename subiterator2_type::value_type value_type;
Chris@16 1646 typedef typename subiterator2_type::difference_type difference_type;
Chris@16 1647 typedef typename subiterator2_type::reference reference;
Chris@16 1648 typedef typename subiterator2_type::pointer pointer;
Chris@16 1649
Chris@16 1650 typedef iterator1 dual_iterator_type;
Chris@16 1651 typedef reverse_iterator1 dual_reverse_iterator_type;
Chris@16 1652
Chris@16 1653 // Construction and destruction
Chris@16 1654 BOOST_UBLAS_INLINE
Chris@16 1655 iterator2 ():
Chris@16 1656 container_reference<self_type> (), it2_ () {}
Chris@16 1657 BOOST_UBLAS_INLINE
Chris@16 1658 iterator2 (self_type &m, const subiterator2_type &it2):
Chris@16 1659 container_reference<self_type> (m), it2_ (it2) {}
Chris@16 1660
Chris@16 1661 // Arithmetic
Chris@16 1662 BOOST_UBLAS_INLINE
Chris@16 1663 iterator2 &operator ++ () {
Chris@16 1664 ++ it2_;
Chris@16 1665 return *this;
Chris@16 1666 }
Chris@16 1667 BOOST_UBLAS_INLINE
Chris@16 1668 iterator2 &operator -- () {
Chris@16 1669 -- it2_;
Chris@16 1670 return *this;
Chris@16 1671 }
Chris@16 1672 BOOST_UBLAS_INLINE
Chris@16 1673 iterator2 &operator += (difference_type n) {
Chris@16 1674 it2_ += n;
Chris@16 1675 return *this;
Chris@16 1676 }
Chris@16 1677 BOOST_UBLAS_INLINE
Chris@16 1678 iterator2 &operator -= (difference_type n) {
Chris@16 1679 it2_ -= n;
Chris@16 1680 return *this;
Chris@16 1681 }
Chris@16 1682 BOOST_UBLAS_INLINE
Chris@16 1683 difference_type operator - (const iterator2 &it) const {
Chris@16 1684 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 1685 return it2_ - it.it2_;
Chris@16 1686 }
Chris@16 1687
Chris@16 1688 // Dereference
Chris@16 1689 BOOST_UBLAS_INLINE
Chris@16 1690 reference operator * () const {
Chris@16 1691 size_type i = index1 ();
Chris@16 1692 size_type j = index2 ();
Chris@16 1693 BOOST_UBLAS_CHECK (i < (*this) ().size1 (), bad_index ());
Chris@16 1694 BOOST_UBLAS_CHECK (j < (*this) ().size2 (), bad_index ());
Chris@16 1695 if (triangular_type::other (i, j))
Chris@16 1696 return *it2_;
Chris@16 1697 else
Chris@16 1698 return (*this) () (i, j);
Chris@16 1699 }
Chris@16 1700 BOOST_UBLAS_INLINE
Chris@16 1701 reference operator [] (difference_type n) const {
Chris@16 1702 return *(*this + n);
Chris@16 1703 }
Chris@16 1704
Chris@16 1705 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
Chris@16 1706 BOOST_UBLAS_INLINE
Chris@16 1707 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1708 typename self_type::
Chris@16 1709 #endif
Chris@16 1710 iterator1 begin () const {
Chris@16 1711 return (*this) ().find1 (1, 0, index2 ());
Chris@16 1712 }
Chris@16 1713 BOOST_UBLAS_INLINE
Chris@16 1714 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1715 typename self_type::
Chris@16 1716 #endif
Chris@16 1717 iterator1 end () const {
Chris@16 1718 return (*this) ().find1 (1, (*this) ().size1 (), index2 ());
Chris@16 1719 }
Chris@16 1720 BOOST_UBLAS_INLINE
Chris@16 1721 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1722 typename self_type::
Chris@16 1723 #endif
Chris@16 1724 reverse_iterator1 rbegin () const {
Chris@16 1725 return reverse_iterator1 (end ());
Chris@16 1726 }
Chris@16 1727 BOOST_UBLAS_INLINE
Chris@16 1728 #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
Chris@16 1729 typename self_type::
Chris@16 1730 #endif
Chris@16 1731 reverse_iterator1 rend () const {
Chris@16 1732 return reverse_iterator1 (begin ());
Chris@16 1733 }
Chris@16 1734 #endif
Chris@16 1735
Chris@16 1736 // Indices
Chris@16 1737 BOOST_UBLAS_INLINE
Chris@16 1738 size_type index1 () const {
Chris@16 1739 return it2_.index1 ();
Chris@16 1740 }
Chris@16 1741 BOOST_UBLAS_INLINE
Chris@16 1742 size_type index2 () const {
Chris@16 1743 return it2_.index2 ();
Chris@16 1744 }
Chris@16 1745
Chris@16 1746 // Assignment
Chris@16 1747 BOOST_UBLAS_INLINE
Chris@16 1748 iterator2 &operator = (const iterator2 &it) {
Chris@16 1749 container_reference<self_type>::assign (&it ());
Chris@16 1750 it2_ = it.it2_;
Chris@16 1751 return *this;
Chris@16 1752 }
Chris@16 1753
Chris@16 1754 // Comparison
Chris@16 1755 BOOST_UBLAS_INLINE
Chris@16 1756 bool operator == (const iterator2 &it) const {
Chris@16 1757 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 1758 return it2_ == it.it2_;
Chris@16 1759 }
Chris@16 1760 BOOST_UBLAS_INLINE
Chris@16 1761 bool operator < (const iterator2 &it) const {
Chris@16 1762 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
Chris@16 1763 return it2_ < it.it2_;
Chris@16 1764 }
Chris@16 1765
Chris@16 1766 private:
Chris@16 1767 subiterator2_type it2_;
Chris@16 1768
Chris@16 1769 friend class const_iterator2;
Chris@16 1770 };
Chris@16 1771 #endif
Chris@16 1772
Chris@16 1773 BOOST_UBLAS_INLINE
Chris@16 1774 iterator2 begin2 () {
Chris@16 1775 return find2 (0, 0, 0);
Chris@16 1776 }
Chris@16 1777 BOOST_UBLAS_INLINE
Chris@16 1778 iterator2 end2 () {
Chris@16 1779 return find2 (0, 0, size2 ());
Chris@16 1780 }
Chris@16 1781
Chris@16 1782 // Reverse iterators
Chris@16 1783
Chris@16 1784 BOOST_UBLAS_INLINE
Chris@16 1785 const_reverse_iterator1 rbegin1 () const {
Chris@16 1786 return const_reverse_iterator1 (end1 ());
Chris@16 1787 }
Chris@16 1788 BOOST_UBLAS_INLINE
Chris@16 1789 const_reverse_iterator1 rend1 () const {
Chris@16 1790 return const_reverse_iterator1 (begin1 ());
Chris@16 1791 }
Chris@16 1792
Chris@16 1793 BOOST_UBLAS_INLINE
Chris@16 1794 reverse_iterator1 rbegin1 () {
Chris@16 1795 return reverse_iterator1 (end1 ());
Chris@16 1796 }
Chris@16 1797 BOOST_UBLAS_INLINE
Chris@16 1798 reverse_iterator1 rend1 () {
Chris@16 1799 return reverse_iterator1 (begin1 ());
Chris@16 1800 }
Chris@16 1801
Chris@16 1802 BOOST_UBLAS_INLINE
Chris@16 1803 const_reverse_iterator2 rbegin2 () const {
Chris@16 1804 return const_reverse_iterator2 (end2 ());
Chris@16 1805 }
Chris@16 1806 BOOST_UBLAS_INLINE
Chris@16 1807 const_reverse_iterator2 rend2 () const {
Chris@16 1808 return const_reverse_iterator2 (begin2 ());
Chris@16 1809 }
Chris@16 1810
Chris@16 1811 BOOST_UBLAS_INLINE
Chris@16 1812 reverse_iterator2 rbegin2 () {
Chris@16 1813 return reverse_iterator2 (end2 ());
Chris@16 1814 }
Chris@16 1815 BOOST_UBLAS_INLINE
Chris@16 1816 reverse_iterator2 rend2 () {
Chris@16 1817 return reverse_iterator2 (begin2 ());
Chris@16 1818 }
Chris@16 1819
Chris@16 1820 private:
Chris@16 1821 matrix_closure_type data_;
Chris@16 1822 static const value_type zero_;
Chris@16 1823 static const value_type one_;
Chris@16 1824 };
Chris@16 1825
Chris@16 1826 template<class M, class TRI>
Chris@16 1827 const typename triangular_adaptor<M, TRI>::value_type triangular_adaptor<M, TRI>::zero_ = value_type/*zero*/();
Chris@16 1828 template<class M, class TRI>
Chris@16 1829 const typename triangular_adaptor<M, TRI>::value_type triangular_adaptor<M, TRI>::one_ (1);
Chris@16 1830
Chris@16 1831 template <class M, class TRI>
Chris@16 1832 struct vector_temporary_traits< triangular_adaptor<M, TRI> >
Chris@16 1833 : vector_temporary_traits< typename boost::remove_const<M>::type > {} ;
Chris@16 1834 template <class M, class TRI>
Chris@16 1835 struct vector_temporary_traits< const triangular_adaptor<M, TRI> >
Chris@16 1836 : vector_temporary_traits< typename boost::remove_const<M>::type > {} ;
Chris@16 1837
Chris@16 1838 template <class M, class TRI>
Chris@16 1839 struct matrix_temporary_traits< triangular_adaptor<M, TRI> >
Chris@16 1840 : matrix_temporary_traits< typename boost::remove_const<M>::type > {};
Chris@16 1841 template <class M, class TRI>
Chris@16 1842 struct matrix_temporary_traits< const triangular_adaptor<M, TRI> >
Chris@16 1843 : matrix_temporary_traits< typename boost::remove_const<M>::type > {};
Chris@16 1844
Chris@16 1845
Chris@16 1846 template<class E1, class E2>
Chris@16 1847 struct matrix_vector_solve_traits {
Chris@16 1848 typedef typename promote_traits<typename E1::value_type, typename E2::value_type>::promote_type promote_type;
Chris@16 1849 typedef vector<promote_type> result_type;
Chris@16 1850 };
Chris@16 1851
Chris@16 1852 // Operations:
Chris@16 1853 // n * (n - 1) / 2 + n = n * (n + 1) / 2 multiplications,
Chris@16 1854 // n * (n - 1) / 2 additions
Chris@16 1855
Chris@16 1856 // Dense (proxy) case
Chris@16 1857 template<class E1, class E2>
Chris@16 1858 BOOST_UBLAS_INLINE
Chris@16 1859 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 1860 lower_tag, column_major_tag, dense_proxy_tag) {
Chris@16 1861 typedef typename E2::size_type size_type;
Chris@16 1862 typedef typename E2::difference_type difference_type;
Chris@16 1863 typedef typename E2::value_type value_type;
Chris@16 1864
Chris@16 1865 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 1866 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
Chris@16 1867 size_type size = e2 ().size ();
Chris@16 1868 for (size_type n = 0; n < size; ++ n) {
Chris@16 1869 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 1870 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 1871 #else
Chris@16 1872 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 1873 singular ().raise ();
Chris@16 1874 #endif
Chris@16 1875 value_type t = e2 () (n) /= e1 () (n, n);
Chris@16 1876 if (t != value_type/*zero*/()) {
Chris@16 1877 for (size_type m = n + 1; m < size; ++ m)
Chris@16 1878 e2 () (m) -= e1 () (m, n) * t;
Chris@16 1879 }
Chris@16 1880 }
Chris@16 1881 }
Chris@16 1882 // Packed (proxy) case
Chris@16 1883 template<class E1, class E2>
Chris@16 1884 BOOST_UBLAS_INLINE
Chris@16 1885 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 1886 lower_tag, column_major_tag, packed_proxy_tag) {
Chris@16 1887 typedef typename E2::size_type size_type;
Chris@16 1888 typedef typename E2::difference_type difference_type;
Chris@16 1889 typedef typename E2::value_type value_type;
Chris@16 1890
Chris@16 1891 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 1892 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
Chris@16 1893 size_type size = e2 ().size ();
Chris@16 1894 for (size_type n = 0; n < size; ++ n) {
Chris@16 1895 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 1896 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 1897 #else
Chris@16 1898 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 1899 singular ().raise ();
Chris@16 1900 #endif
Chris@16 1901 value_type t = e2 () (n) /= e1 () (n, n);
Chris@16 1902 if (t != value_type/*zero*/()) {
Chris@16 1903 typename E1::const_iterator1 it1e1 (e1 ().find1 (1, n + 1, n));
Chris@16 1904 typename E1::const_iterator1 it1e1_end (e1 ().find1 (1, e1 ().size1 (), n));
Chris@16 1905 difference_type m (it1e1_end - it1e1);
Chris@16 1906 while (-- m >= 0)
Chris@16 1907 e2 () (it1e1.index1 ()) -= *it1e1 * t, ++ it1e1;
Chris@16 1908 }
Chris@16 1909 }
Chris@16 1910 }
Chris@16 1911 // Sparse (proxy) case
Chris@16 1912 template<class E1, class E2>
Chris@16 1913 BOOST_UBLAS_INLINE
Chris@16 1914 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 1915 lower_tag, column_major_tag, unknown_storage_tag) {
Chris@16 1916 typedef typename E2::size_type size_type;
Chris@16 1917 typedef typename E2::difference_type difference_type;
Chris@16 1918 typedef typename E2::value_type value_type;
Chris@16 1919
Chris@16 1920 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 1921 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
Chris@16 1922 size_type size = e2 ().size ();
Chris@16 1923 for (size_type n = 0; n < size; ++ n) {
Chris@16 1924 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 1925 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 1926 #else
Chris@16 1927 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 1928 singular ().raise ();
Chris@16 1929 #endif
Chris@16 1930 value_type t = e2 () (n) /= e1 () (n, n);
Chris@16 1931 if (t != value_type/*zero*/()) {
Chris@16 1932 typename E1::const_iterator1 it1e1 (e1 ().find1 (1, n + 1, n));
Chris@16 1933 typename E1::const_iterator1 it1e1_end (e1 ().find1 (1, e1 ().size1 (), n));
Chris@16 1934 while (it1e1 != it1e1_end)
Chris@16 1935 e2 () (it1e1.index1 ()) -= *it1e1 * t, ++ it1e1;
Chris@16 1936 }
Chris@16 1937 }
Chris@16 1938 }
Chris@16 1939
Chris@16 1940 // Dense (proxy) case
Chris@16 1941 template<class E1, class E2>
Chris@16 1942 BOOST_UBLAS_INLINE
Chris@16 1943 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 1944 lower_tag, row_major_tag, dense_proxy_tag) {
Chris@16 1945 typedef typename E2::size_type size_type;
Chris@16 1946 typedef typename E2::difference_type difference_type;
Chris@16 1947 typedef typename E2::value_type value_type;
Chris@16 1948
Chris@16 1949 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 1950 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
Chris@16 1951 size_type size = e2 ().size ();
Chris@16 1952 for (size_type n = 0; n < size; ++ n) {
Chris@16 1953 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 1954 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 1955 #else
Chris@16 1956 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 1957 singular ().raise ();
Chris@16 1958 #endif
Chris@16 1959 value_type t = e2 () (n) /= e1 () (n, n);
Chris@16 1960 if (t != value_type/*zero*/()) {
Chris@16 1961 for (size_type m = n + 1; m < size; ++ m)
Chris@16 1962 e2 () (m) -= e1 () (m, n) * t;
Chris@16 1963 }
Chris@16 1964 }
Chris@16 1965 }
Chris@16 1966 // Packed (proxy) case
Chris@16 1967 template<class E1, class E2>
Chris@16 1968 BOOST_UBLAS_INLINE
Chris@16 1969 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 1970 lower_tag, row_major_tag, packed_proxy_tag) {
Chris@16 1971 typedef typename E2::size_type size_type;
Chris@16 1972 typedef typename E2::difference_type difference_type;
Chris@16 1973 typedef typename E2::value_type value_type;
Chris@16 1974
Chris@16 1975 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 1976 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
Chris@16 1977 size_type size = e2 ().size ();
Chris@16 1978 for (size_type n = 0; n < size; ++ n) {
Chris@16 1979 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 1980 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 1981 #else
Chris@16 1982 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 1983 singular ().raise ();
Chris@16 1984 #endif
Chris@16 1985 value_type t = e2 () (n);
Chris@16 1986 typename E1::const_iterator2 it2e1 (e1 ().find2 (1, n, 0));
Chris@16 1987 typename E1::const_iterator2 it2e1_end (e1 ().find2 (1, n, n));
Chris@16 1988 while (it2e1 != it2e1_end) {
Chris@16 1989 t -= *it2e1 * e2 () (it2e1.index2());
Chris@16 1990 ++ it2e1;
Chris@16 1991 }
Chris@16 1992 e2() (n) = t / e1 () (n, n);
Chris@16 1993 }
Chris@16 1994 }
Chris@16 1995 // Sparse (proxy) case
Chris@16 1996 template<class E1, class E2>
Chris@16 1997 BOOST_UBLAS_INLINE
Chris@16 1998 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 1999 lower_tag, row_major_tag, unknown_storage_tag) {
Chris@16 2000 typedef typename E2::size_type size_type;
Chris@16 2001 typedef typename E2::difference_type difference_type;
Chris@16 2002 typedef typename E2::value_type value_type;
Chris@16 2003
Chris@16 2004 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2005 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
Chris@16 2006 size_type size = e2 ().size ();
Chris@16 2007 for (size_type n = 0; n < size; ++ n) {
Chris@16 2008 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2009 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2010 #else
Chris@16 2011 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2012 singular ().raise ();
Chris@16 2013 #endif
Chris@16 2014 value_type t = e2 () (n);
Chris@16 2015 typename E1::const_iterator2 it2e1 (e1 ().find2 (1, n, 0));
Chris@16 2016 typename E1::const_iterator2 it2e1_end (e1 ().find2 (1, n, n));
Chris@16 2017 while (it2e1 != it2e1_end) {
Chris@16 2018 t -= *it2e1 * e2 () (it2e1.index2());
Chris@16 2019 ++ it2e1;
Chris@16 2020 }
Chris@16 2021 e2() (n) = t / e1 () (n, n);
Chris@16 2022 }
Chris@16 2023 }
Chris@16 2024
Chris@16 2025 // Redirectors :-)
Chris@16 2026 template<class E1, class E2>
Chris@16 2027 BOOST_UBLAS_INLINE
Chris@16 2028 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2029 lower_tag, column_major_tag) {
Chris@16 2030 typedef typename E1::storage_category storage_category;
Chris@16 2031 inplace_solve (e1, e2,
Chris@16 2032 lower_tag (), column_major_tag (), storage_category ());
Chris@16 2033 }
Chris@16 2034 template<class E1, class E2>
Chris@16 2035 BOOST_UBLAS_INLINE
Chris@16 2036 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2037 lower_tag, row_major_tag) {
Chris@16 2038 typedef typename E1::storage_category storage_category;
Chris@16 2039 inplace_solve (e1, e2,
Chris@16 2040 lower_tag (), row_major_tag (), storage_category ());
Chris@16 2041 }
Chris@16 2042 // Dispatcher
Chris@16 2043 template<class E1, class E2>
Chris@16 2044 BOOST_UBLAS_INLINE
Chris@16 2045 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2046 lower_tag) {
Chris@16 2047 typedef typename E1::orientation_category orientation_category;
Chris@16 2048 inplace_solve (e1, e2,
Chris@16 2049 lower_tag (), orientation_category ());
Chris@16 2050 }
Chris@16 2051 template<class E1, class E2>
Chris@16 2052 BOOST_UBLAS_INLINE
Chris@16 2053 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2054 unit_lower_tag) {
Chris@16 2055 typedef typename E1::orientation_category orientation_category;
Chris@16 2056 inplace_solve (triangular_adaptor<const E1, unit_lower> (e1 ()), e2,
Chris@16 2057 unit_lower_tag (), orientation_category ());
Chris@16 2058 }
Chris@16 2059
Chris@16 2060 // Dense (proxy) case
Chris@16 2061 template<class E1, class E2>
Chris@16 2062 BOOST_UBLAS_INLINE
Chris@16 2063 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2064 upper_tag, column_major_tag, dense_proxy_tag) {
Chris@16 2065 typedef typename E2::size_type size_type;
Chris@16 2066 typedef typename E2::difference_type difference_type;
Chris@16 2067 typedef typename E2::value_type value_type;
Chris@16 2068
Chris@16 2069 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2070 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
Chris@16 2071 size_type size = e2 ().size ();
Chris@16 2072 for (difference_type n = size - 1; n >= 0; -- n) {
Chris@16 2073 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2074 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2075 #else
Chris@16 2076 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2077 singular ().raise ();
Chris@16 2078 #endif
Chris@16 2079 value_type t = e2 () (n) /= e1 () (n, n);
Chris@16 2080 if (t != value_type/*zero*/()) {
Chris@16 2081 for (difference_type m = n - 1; m >= 0; -- m)
Chris@16 2082 e2 () (m) -= e1 () (m, n) * t;
Chris@16 2083 }
Chris@16 2084 }
Chris@16 2085 }
Chris@16 2086 // Packed (proxy) case
Chris@16 2087 template<class E1, class E2>
Chris@16 2088 BOOST_UBLAS_INLINE
Chris@16 2089 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2090 upper_tag, column_major_tag, packed_proxy_tag) {
Chris@16 2091 typedef typename E2::size_type size_type;
Chris@16 2092 typedef typename E2::difference_type difference_type;
Chris@16 2093 typedef typename E2::value_type value_type;
Chris@16 2094
Chris@16 2095 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2096 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
Chris@16 2097 size_type size = e2 ().size ();
Chris@16 2098 for (difference_type n = size - 1; n >= 0; -- n) {
Chris@16 2099 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2100 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2101 #else
Chris@16 2102 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2103 singular ().raise ();
Chris@16 2104 #endif
Chris@16 2105 value_type t = e2 () (n) /= e1 () (n, n);
Chris@16 2106 if (t != value_type/*zero*/()) {
Chris@16 2107 typename E1::const_reverse_iterator1 it1e1 (e1 ().find1 (1, n, n));
Chris@16 2108 typename E1::const_reverse_iterator1 it1e1_rend (e1 ().find1 (1, 0, n));
Chris@16 2109 while (it1e1 != it1e1_rend) {
Chris@16 2110 e2 () (it1e1.index1 ()) -= *it1e1 * t, ++ it1e1;
Chris@16 2111 }
Chris@16 2112 }
Chris@16 2113 }
Chris@16 2114 }
Chris@16 2115 // Sparse (proxy) case
Chris@16 2116 template<class E1, class E2>
Chris@16 2117 BOOST_UBLAS_INLINE
Chris@16 2118 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2119 upper_tag, column_major_tag, unknown_storage_tag) {
Chris@16 2120 typedef typename E2::size_type size_type;
Chris@16 2121 typedef typename E2::difference_type difference_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 (difference_type n = size - 1; n >= 0; -- 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 typename E1::const_reverse_iterator1 it1e1 (e1 ().find1 (1, n, n));
Chris@16 2137 typename E1::const_reverse_iterator1 it1e1_rend (e1 ().find1 (1, 0, n));
Chris@16 2138 while (it1e1 != it1e1_rend) {
Chris@16 2139 e2 () (it1e1.index1 ()) -= *it1e1 * t, ++ it1e1;
Chris@16 2140 }
Chris@16 2141 }
Chris@16 2142 }
Chris@16 2143 }
Chris@16 2144
Chris@16 2145 // Dense (proxy) case
Chris@16 2146 template<class E1, class E2>
Chris@16 2147 BOOST_UBLAS_INLINE
Chris@16 2148 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2149 upper_tag, row_major_tag, dense_proxy_tag) {
Chris@16 2150 typedef typename E2::size_type size_type;
Chris@16 2151 typedef typename E2::difference_type difference_type;
Chris@16 2152 typedef typename E2::value_type value_type;
Chris@16 2153
Chris@16 2154 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2155 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
Chris@16 2156 size_type size = e1 ().size1 ();
Chris@16 2157 for (difference_type n = size-1; n >=0; -- n) {
Chris@16 2158 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2159 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2160 #else
Chris@16 2161 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2162 singular ().raise ();
Chris@16 2163 #endif
Chris@16 2164 value_type t = e2 () (n);
Chris@16 2165 for (difference_type m = n + 1; m < e1 ().size2(); ++ m) {
Chris@16 2166 t -= e1 () (n, m) * e2 () (m);
Chris@16 2167 }
Chris@16 2168 e2() (n) = t / e1 () (n, n);
Chris@16 2169 }
Chris@16 2170 }
Chris@16 2171 // Packed (proxy) case
Chris@16 2172 template<class E1, class E2>
Chris@16 2173 BOOST_UBLAS_INLINE
Chris@16 2174 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2175 upper_tag, row_major_tag, packed_proxy_tag) {
Chris@16 2176 typedef typename E2::size_type size_type;
Chris@16 2177 typedef typename E2::difference_type difference_type;
Chris@16 2178 typedef typename E2::value_type value_type;
Chris@16 2179
Chris@16 2180 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2181 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
Chris@16 2182 size_type size = e1 ().size1 ();
Chris@16 2183 for (difference_type n = size-1; n >=0; -- n) {
Chris@16 2184 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2185 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2186 #else
Chris@16 2187 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2188 singular ().raise ();
Chris@16 2189 #endif
Chris@16 2190 value_type t = e2 () (n);
Chris@16 2191 typename E1::const_iterator2 it2e1 (e1 ().find2 (1, n, n+1));
Chris@16 2192 typename E1::const_iterator2 it2e1_end (e1 ().find2 (1, n, e1 ().size2 ()));
Chris@16 2193 while (it2e1 != it2e1_end) {
Chris@16 2194 t -= *it2e1 * e2 () (it2e1.index2());
Chris@16 2195 ++ it2e1;
Chris@16 2196 }
Chris@16 2197 e2() (n) = t / e1 () (n, n);
Chris@16 2198
Chris@16 2199 }
Chris@16 2200 }
Chris@16 2201 // Sparse (proxy) case
Chris@16 2202 template<class E1, class E2>
Chris@16 2203 BOOST_UBLAS_INLINE
Chris@16 2204 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2205 upper_tag, row_major_tag, unknown_storage_tag) {
Chris@16 2206 typedef typename E2::size_type size_type;
Chris@16 2207 typedef typename E2::difference_type difference_type;
Chris@16 2208 typedef typename E2::value_type value_type;
Chris@16 2209
Chris@16 2210 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2211 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size (), bad_size ());
Chris@16 2212 size_type size = e1 ().size1 ();
Chris@16 2213 for (difference_type n = size-1; n >=0; -- n) {
Chris@16 2214 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2215 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2216 #else
Chris@16 2217 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2218 singular ().raise ();
Chris@16 2219 #endif
Chris@16 2220 value_type t = e2 () (n);
Chris@16 2221 typename E1::const_iterator2 it2e1 (e1 ().find2 (1, n, n+1));
Chris@16 2222 typename E1::const_iterator2 it2e1_end (e1 ().find2 (1, n, e1 ().size2 ()));
Chris@16 2223 while (it2e1 != it2e1_end) {
Chris@16 2224 t -= *it2e1 * e2 () (it2e1.index2());
Chris@16 2225 ++ it2e1;
Chris@16 2226 }
Chris@16 2227 e2() (n) = t / e1 () (n, n);
Chris@16 2228
Chris@16 2229 }
Chris@16 2230 }
Chris@16 2231
Chris@16 2232 // Redirectors :-)
Chris@16 2233 template<class E1, class E2>
Chris@16 2234 BOOST_UBLAS_INLINE
Chris@16 2235 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2236 upper_tag, column_major_tag) {
Chris@16 2237 typedef typename E1::storage_category storage_category;
Chris@16 2238 inplace_solve (e1, e2,
Chris@16 2239 upper_tag (), column_major_tag (), storage_category ());
Chris@16 2240 }
Chris@16 2241 template<class E1, class E2>
Chris@16 2242 BOOST_UBLAS_INLINE
Chris@16 2243 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2244 upper_tag, row_major_tag) {
Chris@16 2245 typedef typename E1::storage_category storage_category;
Chris@16 2246 inplace_solve (e1, e2,
Chris@16 2247 upper_tag (), row_major_tag (), storage_category ());
Chris@16 2248 }
Chris@16 2249 // Dispatcher
Chris@16 2250 template<class E1, class E2>
Chris@16 2251 BOOST_UBLAS_INLINE
Chris@16 2252 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2253 upper_tag) {
Chris@16 2254 typedef typename E1::orientation_category orientation_category;
Chris@16 2255 inplace_solve (e1, e2,
Chris@16 2256 upper_tag (), orientation_category ());
Chris@16 2257 }
Chris@16 2258 template<class E1, class E2>
Chris@16 2259 BOOST_UBLAS_INLINE
Chris@16 2260 void inplace_solve (const matrix_expression<E1> &e1, vector_expression<E2> &e2,
Chris@16 2261 unit_upper_tag) {
Chris@16 2262 typedef typename E1::orientation_category orientation_category;
Chris@16 2263 inplace_solve (triangular_adaptor<const E1, unit_upper> (e1 ()), e2,
Chris@16 2264 unit_upper_tag (), orientation_category ());
Chris@16 2265 }
Chris@16 2266
Chris@16 2267 template<class E1, class E2, class C>
Chris@16 2268 BOOST_UBLAS_INLINE
Chris@16 2269 typename matrix_vector_solve_traits<E1, E2>::result_type
Chris@16 2270 solve (const matrix_expression<E1> &e1,
Chris@16 2271 const vector_expression<E2> &e2,
Chris@16 2272 C) {
Chris@16 2273 typename matrix_vector_solve_traits<E1, E2>::result_type r (e2);
Chris@16 2274 inplace_solve (e1, r, C ());
Chris@16 2275 return r;
Chris@16 2276 }
Chris@16 2277
Chris@16 2278
Chris@16 2279 // Redirectors :-)
Chris@16 2280 template<class E1, class E2>
Chris@16 2281 BOOST_UBLAS_INLINE
Chris@16 2282 void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
Chris@16 2283 lower_tag, row_major_tag) {
Chris@16 2284 typedef typename E2::storage_category storage_category;
Chris@16 2285 inplace_solve (trans(e2), e1,
Chris@16 2286 upper_tag (), column_major_tag (), storage_category ());
Chris@16 2287 }
Chris@16 2288 template<class E1, class E2>
Chris@16 2289 BOOST_UBLAS_INLINE
Chris@16 2290 void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
Chris@16 2291 lower_tag, column_major_tag) {
Chris@16 2292 typedef typename E2::storage_category storage_category;
Chris@16 2293 inplace_solve (trans (e2), e1,
Chris@16 2294 upper_tag (), row_major_tag (), storage_category ());
Chris@16 2295 }
Chris@16 2296 // Dispatcher
Chris@16 2297 template<class E1, class E2>
Chris@16 2298 BOOST_UBLAS_INLINE
Chris@16 2299 void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
Chris@16 2300 lower_tag) {
Chris@16 2301 typedef typename E2::orientation_category orientation_category;
Chris@16 2302 inplace_solve (e1, e2,
Chris@16 2303 lower_tag (), orientation_category ());
Chris@16 2304 }
Chris@16 2305 template<class E1, class E2>
Chris@16 2306 BOOST_UBLAS_INLINE
Chris@16 2307 void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
Chris@16 2308 unit_lower_tag) {
Chris@16 2309 typedef typename E2::orientation_category orientation_category;
Chris@16 2310 inplace_solve (e1, triangular_adaptor<const E2, unit_lower> (e2 ()),
Chris@16 2311 unit_lower_tag (), orientation_category ());
Chris@16 2312 }
Chris@16 2313
Chris@16 2314
Chris@16 2315 // Redirectors :-)
Chris@16 2316 template<class E1, class E2>
Chris@16 2317 BOOST_UBLAS_INLINE
Chris@16 2318 void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
Chris@16 2319 upper_tag, row_major_tag) {
Chris@16 2320 typedef typename E2::storage_category storage_category;
Chris@16 2321 inplace_solve (trans(e2), e1,
Chris@16 2322 lower_tag (), column_major_tag (), storage_category ());
Chris@16 2323 }
Chris@16 2324 template<class E1, class E2>
Chris@16 2325 BOOST_UBLAS_INLINE
Chris@16 2326 void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
Chris@16 2327 upper_tag, column_major_tag) {
Chris@16 2328 typedef typename E2::storage_category storage_category;
Chris@16 2329 inplace_solve (trans (e2), e1,
Chris@16 2330 lower_tag (), row_major_tag (), storage_category ());
Chris@16 2331 }
Chris@16 2332 // Dispatcher
Chris@16 2333 template<class E1, class E2>
Chris@16 2334 BOOST_UBLAS_INLINE
Chris@16 2335 void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
Chris@16 2336 upper_tag) {
Chris@16 2337 typedef typename E2::orientation_category orientation_category;
Chris@16 2338 inplace_solve (e1, e2,
Chris@16 2339 upper_tag (), orientation_category ());
Chris@16 2340 }
Chris@16 2341 template<class E1, class E2>
Chris@16 2342 BOOST_UBLAS_INLINE
Chris@16 2343 void inplace_solve (vector_expression<E1> &e1, const matrix_expression<E2> &e2,
Chris@16 2344 unit_upper_tag) {
Chris@16 2345 typedef typename E2::orientation_category orientation_category;
Chris@16 2346 inplace_solve (e1, triangular_adaptor<const E2, unit_upper> (e2 ()),
Chris@16 2347 unit_upper_tag (), orientation_category ());
Chris@16 2348 }
Chris@16 2349
Chris@16 2350 template<class E1, class E2, class C>
Chris@16 2351 BOOST_UBLAS_INLINE
Chris@16 2352 typename matrix_vector_solve_traits<E1, E2>::result_type
Chris@16 2353 solve (const vector_expression<E1> &e1,
Chris@16 2354 const matrix_expression<E2> &e2,
Chris@16 2355 C) {
Chris@16 2356 typename matrix_vector_solve_traits<E1, E2>::result_type r (e1);
Chris@16 2357 inplace_solve (r, e2, C ());
Chris@16 2358 return r;
Chris@16 2359 }
Chris@16 2360
Chris@16 2361 template<class E1, class E2>
Chris@16 2362 struct matrix_matrix_solve_traits {
Chris@16 2363 typedef typename promote_traits<typename E1::value_type, typename E2::value_type>::promote_type promote_type;
Chris@16 2364 typedef matrix<promote_type> result_type;
Chris@16 2365 };
Chris@16 2366
Chris@16 2367 // Operations:
Chris@16 2368 // k * n * (n - 1) / 2 + k * n = k * n * (n + 1) / 2 multiplications,
Chris@16 2369 // k * n * (n - 1) / 2 additions
Chris@16 2370
Chris@16 2371 // Dense (proxy) case
Chris@16 2372 template<class E1, class E2>
Chris@16 2373 BOOST_UBLAS_INLINE
Chris@16 2374 void inplace_solve (const matrix_expression<E1> &e1, matrix_expression<E2> &e2,
Chris@16 2375 lower_tag, dense_proxy_tag) {
Chris@16 2376 typedef typename E2::size_type size_type;
Chris@16 2377 typedef typename E2::difference_type difference_type;
Chris@16 2378 typedef typename E2::value_type value_type;
Chris@16 2379
Chris@16 2380 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2381 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size1 (), bad_size ());
Chris@16 2382 size_type size1 = e2 ().size1 ();
Chris@16 2383 size_type size2 = e2 ().size2 ();
Chris@16 2384 for (size_type n = 0; n < size1; ++ n) {
Chris@16 2385 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2386 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2387 #else
Chris@16 2388 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2389 singular ().raise ();
Chris@16 2390 #endif
Chris@16 2391 for (size_type l = 0; l < size2; ++ l) {
Chris@16 2392 value_type t = e2 () (n, l) /= e1 () (n, n);
Chris@16 2393 if (t != value_type/*zero*/()) {
Chris@16 2394 for (size_type m = n + 1; m < size1; ++ m)
Chris@16 2395 e2 () (m, l) -= e1 () (m, n) * t;
Chris@16 2396 }
Chris@16 2397 }
Chris@16 2398 }
Chris@16 2399 }
Chris@16 2400 // Packed (proxy) case
Chris@16 2401 template<class E1, class E2>
Chris@16 2402 BOOST_UBLAS_INLINE
Chris@16 2403 void inplace_solve (const matrix_expression<E1> &e1, matrix_expression<E2> &e2,
Chris@16 2404 lower_tag, packed_proxy_tag) {
Chris@16 2405 typedef typename E2::size_type size_type;
Chris@16 2406 typedef typename E2::difference_type difference_type;
Chris@16 2407 typedef typename E2::value_type value_type;
Chris@16 2408
Chris@16 2409 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2410 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size1 (), bad_size ());
Chris@16 2411 size_type size1 = e2 ().size1 ();
Chris@16 2412 size_type size2 = e2 ().size2 ();
Chris@16 2413 for (size_type n = 0; n < size1; ++ n) {
Chris@16 2414 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2415 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2416 #else
Chris@16 2417 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2418 singular ().raise ();
Chris@16 2419 #endif
Chris@16 2420 for (size_type l = 0; l < size2; ++ l) {
Chris@16 2421 value_type t = e2 () (n, l) /= e1 () (n, n);
Chris@16 2422 if (t != value_type/*zero*/()) {
Chris@16 2423 typename E1::const_iterator1 it1e1 (e1 ().find1 (1, n + 1, n));
Chris@16 2424 typename E1::const_iterator1 it1e1_end (e1 ().find1 (1, e1 ().size1 (), n));
Chris@16 2425 difference_type m (it1e1_end - it1e1);
Chris@16 2426 while (-- m >= 0)
Chris@16 2427 e2 () (it1e1.index1 (), l) -= *it1e1 * t, ++ it1e1;
Chris@16 2428 }
Chris@16 2429 }
Chris@16 2430 }
Chris@16 2431 }
Chris@16 2432 // Sparse (proxy) case
Chris@16 2433 template<class E1, class E2>
Chris@16 2434 BOOST_UBLAS_INLINE
Chris@16 2435 void inplace_solve (const matrix_expression<E1> &e1, matrix_expression<E2> &e2,
Chris@16 2436 lower_tag, unknown_storage_tag) {
Chris@16 2437 typedef typename E2::size_type size_type;
Chris@16 2438 typedef typename E2::difference_type difference_type;
Chris@16 2439 typedef typename E2::value_type value_type;
Chris@16 2440
Chris@16 2441 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2442 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size1 (), bad_size ());
Chris@16 2443 size_type size1 = e2 ().size1 ();
Chris@16 2444 size_type size2 = e2 ().size2 ();
Chris@16 2445 for (size_type n = 0; n < size1; ++ n) {
Chris@16 2446 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2447 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2448 #else
Chris@16 2449 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2450 singular ().raise ();
Chris@16 2451 #endif
Chris@16 2452 for (size_type l = 0; l < size2; ++ l) {
Chris@16 2453 value_type t = e2 () (n, l) /= e1 () (n, n);
Chris@16 2454 if (t != value_type/*zero*/()) {
Chris@16 2455 typename E1::const_iterator1 it1e1 (e1 ().find1 (1, n + 1, n));
Chris@16 2456 typename E1::const_iterator1 it1e1_end (e1 ().find1 (1, e1 ().size1 (), n));
Chris@16 2457 while (it1e1 != it1e1_end)
Chris@16 2458 e2 () (it1e1.index1 (), l) -= *it1e1 * t, ++ it1e1;
Chris@16 2459 }
Chris@16 2460 }
Chris@16 2461 }
Chris@16 2462 }
Chris@16 2463 // Dispatcher
Chris@16 2464 template<class E1, class E2>
Chris@16 2465 BOOST_UBLAS_INLINE
Chris@16 2466 void inplace_solve (const matrix_expression<E1> &e1, matrix_expression<E2> &e2,
Chris@16 2467 lower_tag) {
Chris@16 2468 typedef typename E1::storage_category dispatch_category;
Chris@16 2469 inplace_solve (e1, e2,
Chris@16 2470 lower_tag (), dispatch_category ());
Chris@16 2471 }
Chris@16 2472 template<class E1, class E2>
Chris@16 2473 BOOST_UBLAS_INLINE
Chris@16 2474 void inplace_solve (const matrix_expression<E1> &e1, matrix_expression<E2> &e2,
Chris@16 2475 unit_lower_tag) {
Chris@16 2476 typedef typename E1::storage_category dispatch_category;
Chris@16 2477 inplace_solve (triangular_adaptor<const E1, unit_lower> (e1 ()), e2,
Chris@16 2478 unit_lower_tag (), dispatch_category ());
Chris@16 2479 }
Chris@16 2480
Chris@16 2481 // Dense (proxy) case
Chris@16 2482 template<class E1, class E2>
Chris@16 2483 BOOST_UBLAS_INLINE
Chris@16 2484 void inplace_solve (const matrix_expression<E1> &e1, matrix_expression<E2> &e2,
Chris@16 2485 upper_tag, dense_proxy_tag) {
Chris@16 2486 typedef typename E2::size_type size_type;
Chris@16 2487 typedef typename E2::difference_type difference_type;
Chris@16 2488 typedef typename E2::value_type value_type;
Chris@16 2489
Chris@16 2490 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2491 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size1 (), bad_size ());
Chris@16 2492 size_type size1 = e2 ().size1 ();
Chris@16 2493 size_type size2 = e2 ().size2 ();
Chris@16 2494 for (difference_type n = size1 - 1; n >= 0; -- n) {
Chris@16 2495 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2496 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2497 #else
Chris@16 2498 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2499 singular ().raise ();
Chris@16 2500 #endif
Chris@16 2501 for (difference_type l = size2 - 1; l >= 0; -- l) {
Chris@16 2502 value_type t = e2 () (n, l) /= e1 () (n, n);
Chris@16 2503 if (t != value_type/*zero*/()) {
Chris@16 2504 for (difference_type m = n - 1; m >= 0; -- m)
Chris@16 2505 e2 () (m, l) -= e1 () (m, n) * t;
Chris@16 2506 }
Chris@16 2507 }
Chris@16 2508 }
Chris@16 2509 }
Chris@16 2510 // Packed (proxy) case
Chris@16 2511 template<class E1, class E2>
Chris@16 2512 BOOST_UBLAS_INLINE
Chris@16 2513 void inplace_solve (const matrix_expression<E1> &e1, matrix_expression<E2> &e2,
Chris@16 2514 upper_tag, packed_proxy_tag) {
Chris@16 2515 typedef typename E2::size_type size_type;
Chris@16 2516 typedef typename E2::difference_type difference_type;
Chris@16 2517 typedef typename E2::value_type value_type;
Chris@16 2518
Chris@16 2519 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2520 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size1 (), bad_size ());
Chris@16 2521 size_type size1 = e2 ().size1 ();
Chris@16 2522 size_type size2 = e2 ().size2 ();
Chris@16 2523 for (difference_type n = size1 - 1; n >= 0; -- n) {
Chris@16 2524 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2525 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2526 #else
Chris@16 2527 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2528 singular ().raise ();
Chris@16 2529 #endif
Chris@16 2530 for (difference_type l = size2 - 1; l >= 0; -- l) {
Chris@16 2531 value_type t = e2 () (n, l) /= e1 () (n, n);
Chris@16 2532 if (t != value_type/*zero*/()) {
Chris@16 2533 typename E1::const_reverse_iterator1 it1e1 (e1 ().find1 (1, n, n));
Chris@16 2534 typename E1::const_reverse_iterator1 it1e1_rend (e1 ().find1 (1, 0, n));
Chris@16 2535 difference_type m (it1e1_rend - it1e1);
Chris@16 2536 while (-- m >= 0)
Chris@16 2537 e2 () (it1e1.index1 (), l) -= *it1e1 * t, ++ it1e1;
Chris@16 2538 }
Chris@16 2539 }
Chris@16 2540 }
Chris@16 2541 }
Chris@16 2542 // Sparse (proxy) case
Chris@16 2543 template<class E1, class E2>
Chris@16 2544 BOOST_UBLAS_INLINE
Chris@16 2545 void inplace_solve (const matrix_expression<E1> &e1, matrix_expression<E2> &e2,
Chris@16 2546 upper_tag, unknown_storage_tag) {
Chris@16 2547 typedef typename E2::size_type size_type;
Chris@16 2548 typedef typename E2::difference_type difference_type;
Chris@16 2549 typedef typename E2::value_type value_type;
Chris@16 2550
Chris@16 2551 BOOST_UBLAS_CHECK (e1 ().size1 () == e1 ().size2 (), bad_size ());
Chris@16 2552 BOOST_UBLAS_CHECK (e1 ().size2 () == e2 ().size1 (), bad_size ());
Chris@16 2553 size_type size1 = e2 ().size1 ();
Chris@16 2554 size_type size2 = e2 ().size2 ();
Chris@16 2555 for (difference_type n = size1 - 1; n >= 0; -- n) {
Chris@16 2556 #ifndef BOOST_UBLAS_SINGULAR_CHECK
Chris@16 2557 BOOST_UBLAS_CHECK (e1 () (n, n) != value_type/*zero*/(), singular ());
Chris@16 2558 #else
Chris@16 2559 if (e1 () (n, n) == value_type/*zero*/())
Chris@16 2560 singular ().raise ();
Chris@16 2561 #endif
Chris@16 2562 for (difference_type l = size2 - 1; l >= 0; -- l) {
Chris@16 2563 value_type t = e2 () (n, l) /= e1 () (n, n);
Chris@16 2564 if (t != value_type/*zero*/()) {
Chris@16 2565 typename E1::const_reverse_iterator1 it1e1 (e1 ().find1 (1, n, n));
Chris@16 2566 typename E1::const_reverse_iterator1 it1e1_rend (e1 ().find1 (1, 0, n));
Chris@16 2567 while (it1e1 != it1e1_rend)
Chris@16 2568 e2 () (it1e1.index1 (), l) -= *it1e1 * t, ++ it1e1;
Chris@16 2569 }
Chris@16 2570 }
Chris@16 2571 }
Chris@16 2572 }
Chris@16 2573 // Dispatcher
Chris@16 2574 template<class E1, class E2>
Chris@16 2575 BOOST_UBLAS_INLINE
Chris@16 2576 void inplace_solve (const matrix_expression<E1> &e1, matrix_expression<E2> &e2,
Chris@16 2577 upper_tag) {
Chris@16 2578 typedef typename E1::storage_category dispatch_category;
Chris@16 2579 inplace_solve (e1, e2,
Chris@16 2580 upper_tag (), dispatch_category ());
Chris@16 2581 }
Chris@16 2582 template<class E1, class E2>
Chris@16 2583 BOOST_UBLAS_INLINE
Chris@16 2584 void inplace_solve (const matrix_expression<E1> &e1, matrix_expression<E2> &e2,
Chris@16 2585 unit_upper_tag) {
Chris@16 2586 typedef typename E1::storage_category dispatch_category;
Chris@16 2587 inplace_solve (triangular_adaptor<const E1, unit_upper> (e1 ()), e2,
Chris@16 2588 unit_upper_tag (), dispatch_category ());
Chris@16 2589 }
Chris@16 2590
Chris@16 2591 template<class E1, class E2, class C>
Chris@16 2592 BOOST_UBLAS_INLINE
Chris@16 2593 typename matrix_matrix_solve_traits<E1, E2>::result_type
Chris@16 2594 solve (const matrix_expression<E1> &e1,
Chris@16 2595 const matrix_expression<E2> &e2,
Chris@16 2596 C) {
Chris@16 2597 typename matrix_matrix_solve_traits<E1, E2>::result_type r (e2);
Chris@16 2598 inplace_solve (e1, r, C ());
Chris@16 2599 return r;
Chris@16 2600 }
Chris@16 2601
Chris@16 2602 }}}
Chris@16 2603
Chris@16 2604 #endif