annotate DEPENDENCIES/generic/include/boost/numeric/ublas/assignment.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 //
Chris@16 2 // Copyright (c) 2010 Athanasios Iliopoulos
Chris@16 3 //
Chris@16 4 // Distributed under the Boost Software License, Version 1.0. (See
Chris@16 5 // accompanying file LICENSE_1_0.txt or copy at
Chris@16 6 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 7 //
Chris@16 8
Chris@16 9 #ifndef ASSIGNMENT_HPP
Chris@16 10 #define ASSIGNMENT_HPP
Chris@16 11 #include <boost/numeric/ublas/vector_expression.hpp>
Chris@16 12 #include <boost/numeric/ublas/matrix_expression.hpp>
Chris@16 13
Chris@16 14 /*! \file assignment.hpp
Chris@16 15 \brief uBlas assignment operator <<=.
Chris@16 16 */
Chris@16 17
Chris@16 18 namespace boost { namespace numeric { namespace ublas {
Chris@16 19
Chris@16 20 /** \brief A CRTP and Barton-Nackman trick index manipulator wrapper class.
Chris@16 21 *
Chris@16 22 * This class is not meant to be used directly.
Chris@16 23 */
Chris@16 24 template <class TV>
Chris@16 25 class index_manipulator {
Chris@16 26 public:
Chris@16 27 typedef TV type;
Chris@16 28 BOOST_UBLAS_INLINE
Chris@16 29 const type &operator () () const {
Chris@16 30 return *static_cast<const type *> (this);
Chris@16 31 }
Chris@16 32 BOOST_UBLAS_INLINE
Chris@16 33 type &operator () () {
Chris@16 34 return *static_cast<type *> (this);
Chris@16 35 }
Chris@16 36 };
Chris@16 37
Chris@16 38 /** \brief A move_to vector index manipulator.
Chris@16 39 *
Chris@16 40 * When member function \c manip is called the referenced
Chris@16 41 * index will be set to the manipulators' index.
Chris@16 42 *
Chris@16 43 * \sa move_to(T i)
Chris@16 44 */
Chris@16 45 template <typename T>
Chris@16 46 class vector_move_to_manip: public index_manipulator<vector_move_to_manip<T> > {
Chris@16 47 public:
Chris@16 48 BOOST_UBLAS_INLINE
Chris@16 49 vector_move_to_manip(const T &k): i(k) { }
Chris@16 50
Chris@16 51 template <typename V>
Chris@16 52 BOOST_UBLAS_INLINE
Chris@16 53 void manip(V &k) const { k=i; }
Chris@16 54 private:
Chris@16 55 T i;
Chris@16 56 };
Chris@16 57
Chris@16 58 /** \brief An object generator that returns a move_to vector index manipulator
Chris@16 59 *
Chris@16 60 * \param i The element number the manipulator will move to when \c manip member function is called
Chris@16 61 * \return A move_to vector manipulator
Chris@16 62 *
Chris@16 63 * Example usage:
Chris@16 64 * \code
Chris@16 65 * vector<double> a(6, 0);
Chris@16 66 * a <<= 1, 2, move_to(5), 3;
Chris@16 67 * \endcode
Chris@16 68 * will result in:
Chris@16 69 * \code
Chris@16 70 * 1 2 0 0 0 3
Chris@16 71 * \endcode
Chris@16 72 *
Chris@16 73 * \tparam T Size type
Chris@16 74 * \sa move_to()
Chris@16 75 */
Chris@16 76 template <typename T>
Chris@16 77 BOOST_UBLAS_INLINE vector_move_to_manip<T> move_to(T i) {
Chris@16 78 return vector_move_to_manip<T>(i);
Chris@16 79 }
Chris@16 80
Chris@16 81 /** \brief A static move to vector manipulator.
Chris@16 82 *
Chris@16 83 * When member function \c manip is called the referenced
Chris@16 84 * index will be set to the manipulators' index
Chris@16 85 *
Chris@16 86 * \sa move_to(T i) and move_to()
Chris@16 87 */
Chris@16 88 template <std::size_t I>
Chris@16 89 class static_vector_move_to_manip: public index_manipulator<static_vector_move_to_manip<I> > {
Chris@16 90 public:
Chris@16 91 template <typename V>
Chris@16 92 BOOST_UBLAS_INLINE
Chris@16 93 void manip(V &k) const { k=I; }
Chris@16 94 };
Chris@16 95
Chris@16 96 /** \brief An object generator that returns a static move_to vector index manipulator.
Chris@16 97 *
Chris@16 98 * Typically faster than the dynamic version, but can be used only when the
Chris@16 99 * values are known at compile time.
Chris@16 100 *
Chris@16 101 * \return A static move_to vector manipulator
Chris@16 102 *
Chris@16 103 * Example usage:
Chris@16 104 * \code
Chris@16 105 * vector<double> a(6, 0);
Chris@16 106 * a <<= 1, 2, move_to<5>(), 3;
Chris@16 107 * \endcode
Chris@16 108 * will result in:
Chris@16 109 * \code
Chris@16 110 * 1 2 0 0 0 3
Chris@16 111 * \endcode
Chris@16 112 *
Chris@16 113 * \tparam I The number of elements the manipulator will traverse the index when \c manip function is called
Chris@16 114 */
Chris@16 115 template <std::size_t I>
Chris@16 116 BOOST_UBLAS_INLINE static_vector_move_to_manip<I> move_to() {
Chris@16 117 return static_vector_move_to_manip<I>();
Chris@16 118 }
Chris@16 119
Chris@16 120 /** \brief A move vector index manipulator.
Chris@16 121 *
Chris@16 122 * When member function traverse is called the manipulators'
Chris@16 123 * index will be added to the referenced index.
Chris@16 124 *
Chris@16 125 * \see move(T i)
Chris@16 126 */
Chris@16 127 template <typename T>
Chris@16 128 class vector_move_manip: public index_manipulator<vector_move_manip<T> > {
Chris@16 129 public:
Chris@16 130 BOOST_UBLAS_INLINE
Chris@16 131 vector_move_manip(const T &k): i(k) { }
Chris@16 132
Chris@16 133 template <typename V>
Chris@16 134 BOOST_UBLAS_INLINE void manip(V &k) const { k+=i; }
Chris@16 135 private:
Chris@16 136 T i;
Chris@16 137 };
Chris@16 138
Chris@16 139 /**
Chris@16 140 * \brief An object generator that returns a move vector index manipulator
Chris@16 141 *
Chris@16 142 * \tparam T Size type
Chris@16 143 * \param i The number of elements the manipulator will traverse the index when \c manip
Chris@16 144 * member function is called. Negative values can be used.
Chris@16 145 * \return A move vector manipulator
Chris@16 146 *
Chris@16 147 * Example usage:
Chris@16 148 * \code
Chris@16 149 * vector<double> a(6, 0);
Chris@16 150 * a <<= 1, 2, move(3), 3;
Chris@16 151 * \endcode
Chris@16 152 * will result in:
Chris@16 153 * \code
Chris@16 154 * 1 2 0 0 0 3
Chris@16 155 * \endcode
Chris@16 156 *
Chris@16 157 */
Chris@16 158 template <typename T>
Chris@16 159 BOOST_UBLAS_INLINE vector_move_manip<T> move(T i) {
Chris@16 160 return vector_move_manip<T>(i);
Chris@16 161 }
Chris@16 162
Chris@16 163 /**
Chris@16 164 * \brief A static move vector manipulator
Chris@16 165 *
Chris@16 166 * When member function \c manip is called the manipulators
Chris@16 167 * index will be added to the referenced index
Chris@16 168 *
Chris@16 169 * \sa move()
Chris@16 170 *
Chris@16 171 * \todo Doxygen has some problems with similar template functions. Correct that.
Chris@16 172 */
Chris@101 173 template <std::ptrdiff_t I>
Chris@16 174 class static_vector_move_manip: public index_manipulator<static_vector_move_manip<I> > {
Chris@16 175 public:
Chris@16 176 template <typename V>
Chris@16 177 BOOST_UBLAS_INLINE void manip(V &k) const { k+=I; }
Chris@16 178 };
Chris@16 179
Chris@16 180 /**
Chris@16 181 * \brief An object generator that returns a static move vector index manipulator.
Chris@16 182 *
Chris@16 183 * Typically faster than the dynamic version, but can be used only when the
Chris@16 184 * values are known at compile time.
Chris@16 185 * \tparam I The Number of elements the manipulator will traverse the index when \c manip
Chris@16 186 * function is called.Negative values can be used.
Chris@16 187 * \return A static move vector manipulator
Chris@16 188 *
Chris@16 189 * Example usage:
Chris@16 190 * \code
Chris@16 191 * vector<double> a(6, 0);
Chris@16 192 * a <<= 1, 2, move<3>(), 3;
Chris@16 193 * \endcode
Chris@16 194 * will result in:
Chris@16 195 * \code
Chris@16 196 * 1 2 0 0 0 3
Chris@16 197 * \endcode
Chris@16 198 *
Chris@16 199 * \todo Doxygen has some problems with similar template functions. Correct that.
Chris@16 200 */
Chris@101 201 template <std::ptrdiff_t I>
Chris@101 202 static_vector_move_manip<I> move() {
Chris@16 203 return static_vector_move_manip<I>();
Chris@16 204 }
Chris@16 205
Chris@16 206 /**
Chris@16 207 * \brief A move_to matrix manipulator
Chris@16 208 *
Chris@16 209 * When member function \c manip is called the referenced
Chris@16 210 * index will be set to the manipulators' index
Chris@16 211 *
Chris@16 212 * \sa move_to(T i, T j)
Chris@16 213 *
Chris@16 214 * \todo Doxygen has some problems with similar template functions. Correct that.
Chris@16 215 */
Chris@16 216 template <typename T>
Chris@16 217 class matrix_move_to_manip: public index_manipulator<matrix_move_to_manip<T> > {
Chris@16 218 public:
Chris@16 219 BOOST_UBLAS_INLINE
Chris@16 220 matrix_move_to_manip(T k, T l): i(k), j(l) { }
Chris@16 221
Chris@16 222 template <typename V1, typename V2>
Chris@16 223 BOOST_UBLAS_INLINE
Chris@16 224 void manip(V1 &k, V2 &l) const {
Chris@16 225 k=i;
Chris@16 226 l=j;
Chris@16 227 }
Chris@16 228 private:
Chris@16 229 T i, j;
Chris@16 230 };
Chris@16 231
Chris@16 232 /**
Chris@16 233 * \brief An object generator that returns a "move_to" matrix index manipulator
Chris@16 234 *
Chris@16 235 * \tparam size type
Chris@16 236 * \param i The row number the manipulator will move to when \c manip
Chris@16 237 * member function is called
Chris@16 238 * \param j The column number the manipulator will move to when \c manip
Chris@16 239 * member function is called
Chris@16 240 * \return A move matrix manipulator
Chris@16 241 *
Chris@16 242 * Example usage:
Chris@16 243 * \code:
Chris@16 244 * matrix<double> A(3, 3, 0);
Chris@16 245 * A <<= 1, 2, move_to(A.size1()-1, A.size1()-1), 3;
Chris@16 246 * \endcode
Chris@16 247 * will result in:
Chris@16 248 * \code
Chris@16 249 * 1 2 0
Chris@16 250 * 0 0 0
Chris@16 251 * 0 0 3
Chris@16 252 * \endcode
Chris@16 253 * \sa move_to(T i, T j) and static_matrix_move_to_manip
Chris@16 254 *
Chris@16 255 * \todo Doxygen has some problems with similar template functions. Correct that.
Chris@16 256 */
Chris@16 257 template <typename T>
Chris@16 258 BOOST_UBLAS_INLINE matrix_move_to_manip<T> move_to(T i, T j) {
Chris@16 259 return matrix_move_to_manip<T>(i, j);
Chris@16 260 }
Chris@16 261
Chris@16 262
Chris@16 263 /**
Chris@16 264 * \brief A static move_to matrix manipulator
Chris@16 265 * When member function traverse is called the referenced
Chris@16 266 * index will be set to the manipulators' index
Chris@16 267 *
Chris@16 268 * \sa move_to()
Chris@16 269 *
Chris@16 270 * \todo Doxygen has some problems with similar template functions. Correct that.
Chris@16 271 */
Chris@101 272 template <std::size_t I,std::size_t J>
Chris@16 273 class static_matrix_move_to_manip: public index_manipulator<static_matrix_move_to_manip<I, J> > {
Chris@16 274 public:
Chris@16 275 template <typename V, typename K>
Chris@16 276 BOOST_UBLAS_INLINE
Chris@16 277 void manip(V &k, K &l) const {
Chris@16 278 k=I;
Chris@16 279 l=J;
Chris@16 280 }
Chris@16 281 };
Chris@16 282
Chris@16 283 /**
Chris@16 284 * \brief An object generator that returns a static move_to matrix index manipulator.
Chris@16 285 *
Chris@16 286 * Typically faster than the dynamic version, but can be used only when the
Chris@16 287 * values are known at compile time.
Chris@16 288 * \tparam I The row number the manipulator will set the matrix assigner index to.
Chris@16 289 * \tparam J The column number the manipulator will set the matrix assigner index to.
Chris@16 290 * \return A static move_to matrix manipulator
Chris@16 291 *
Chris@16 292 * Example usage:
Chris@16 293 * \code:
Chris@16 294 * matrix<double> A(3, 3, 0);
Chris@16 295 * A <<= 1, 2, move_to<2,2>, 3;
Chris@16 296 * \endcode
Chris@16 297 * will result in:
Chris@16 298 * \code
Chris@16 299 * 1 2 0
Chris@16 300 * 0 0 0
Chris@16 301 * 0 0 3
Chris@16 302 * \endcode
Chris@16 303 * \sa move_to(T i, T j) and static_matrix_move_to_manip
Chris@16 304 */
Chris@16 305 template <std::size_t I, std::size_t J>
Chris@16 306 BOOST_UBLAS_INLINE static_matrix_move_to_manip<I, J> move_to() {
Chris@16 307 return static_matrix_move_to_manip<I, J>();
Chris@16 308 }
Chris@16 309
Chris@16 310 /**
Chris@16 311 * \brief A move matrix index manipulator.
Chris@16 312 *
Chris@16 313 * When member function \c manip is called the manipulator's
Chris@16 314 * index will be added to the referenced' index.
Chris@16 315 *
Chris@16 316 * \sa move(T i, T j)
Chris@16 317 */
Chris@16 318 template <typename T>
Chris@16 319 class matrix_move_manip: public index_manipulator<matrix_move_manip<T> > {
Chris@16 320 public:
Chris@16 321 BOOST_UBLAS_INLINE
Chris@16 322 matrix_move_manip(T k, T l): i(k), j(l) { }
Chris@16 323
Chris@16 324 template <typename V, typename K>
Chris@16 325 BOOST_UBLAS_INLINE
Chris@16 326 void manip(V &k, K &l) const {
Chris@16 327 k+=i;
Chris@16 328 l+=j;
Chris@16 329 }
Chris@16 330 private:
Chris@16 331 T i, j;
Chris@16 332 };
Chris@16 333
Chris@16 334 /**
Chris@16 335 * \brief An object generator that returns a move matrix index manipulator
Chris@16 336 *
Chris@16 337 * \tparam size type
Chris@16 338 * \param i The number of rows the manipulator will traverse the index when "manip"
Chris@16 339 * member function is called
Chris@16 340 * \param j The number of columns the manipulator will traverse the index when "manip"
Chris@16 341 * member function is called
Chris@16 342 * \return A move matrix manipulator
Chris@16 343 *
Chris@16 344 * Example:
Chris@16 345 * \code:
Chris@16 346 * matrix<double> A(3, 3, 0);
Chris@16 347 * A <<= 1, 2, move(1,0),
Chris@16 348 * 3,;
Chris@16 349 * \endcode
Chris@16 350 * will result in:
Chris@16 351 * \code
Chris@16 352 * 1 2 0
Chris@16 353 * 0 0 3
Chris@16 354 * 0 0 0
Chris@16 355 * \endcode
Chris@16 356 */
Chris@16 357 template <typename T>
Chris@16 358 BOOST_UBLAS_INLINE matrix_move_manip<T> move(T i, T j) {
Chris@16 359 return matrix_move_manip<T>(i, j);
Chris@16 360 }
Chris@16 361
Chris@16 362 /**
Chris@16 363 * \brief A static move matrix index manipulator.
Chris@16 364 *
Chris@16 365 * When member function traverse is called the manipulator's
Chris@16 366 * index will be added to the referenced' index.
Chris@16 367 *
Chris@16 368 * \sa move()
Chris@16 369 *
Chris@16 370 * \todo Doxygen has some problems with similar template functions. Correct that.
Chris@16 371 */
Chris@101 372 template <std::ptrdiff_t I, std::ptrdiff_t J>
Chris@16 373 class static_matrix_move_manip: public index_manipulator<static_matrix_move_manip<I, J> > {
Chris@16 374 public:
Chris@16 375 template <typename V, typename K>
Chris@16 376 BOOST_UBLAS_INLINE
Chris@16 377 void manip(V &k, K &l) const {
Chris@16 378 k+=I;
Chris@16 379 l+=J;
Chris@16 380 }
Chris@16 381 };
Chris@16 382
Chris@16 383 /**
Chris@16 384 * \brief An object generator that returns a static "move" matrix index manipulator.
Chris@16 385 *
Chris@16 386 * Typically faster than the dynamic version, but can be used only when the
Chris@16 387 * values are known at compile time. Negative values can be used.
Chris@16 388 * \tparam I The number of rows the manipulator will trasverse the matrix assigner index.
Chris@16 389 * \tparam J The number of columns the manipulator will trasverse the matrix assigner index.
Chris@16 390 * \tparam size type
Chris@16 391 * \return A static move matrix manipulator
Chris@16 392 *
Chris@16 393 * Example:
Chris@16 394 * \code:
Chris@16 395 * matrix<double> A(3, 3, 0);
Chris@16 396 * A <<= 1, 2, move<1,0>(),
Chris@16 397 * 3,;
Chris@16 398 * \endcode
Chris@16 399 * will result in:
Chris@16 400 * \code
Chris@16 401 * 1 2 0
Chris@16 402 * 0 0 3
Chris@16 403 * 0 0 0
Chris@16 404 * \endcode
Chris@16 405 *
Chris@16 406 * \sa move_to()
Chris@16 407 *
Chris@16 408 * \todo Doxygen has some problems with similar template functions. Correct that.
Chris@16 409 */
Chris@101 410 template <std::ptrdiff_t I, std::ptrdiff_t J>
Chris@16 411 BOOST_UBLAS_INLINE static_matrix_move_manip<I, J> move() {
Chris@16 412 return static_matrix_move_manip<I, J>();
Chris@16 413 }
Chris@16 414
Chris@16 415 /**
Chris@16 416 * \brief A begining of row manipulator
Chris@16 417 *
Chris@16 418 * When member function \c manip is called the referenced
Chris@16 419 * index will be be set to the begining of the row (i.e. column = 0)
Chris@16 420 *
Chris@16 421 * \sa begin1()
Chris@16 422 */
Chris@16 423 class begin1_manip: public index_manipulator<begin1_manip > {
Chris@16 424 public:
Chris@16 425 template <typename V, typename K>
Chris@16 426 BOOST_UBLAS_INLINE
Chris@16 427 void manip(V & k, K &/*l*/) const {
Chris@16 428 k=0;
Chris@16 429 }
Chris@16 430 };
Chris@16 431
Chris@16 432 /**
Chris@16 433 * \brief An object generator that returns a begin1 manipulator.
Chris@16 434 *
Chris@16 435 * The resulted manipulator will traverse the index to the begining
Chris@16 436 * of the current column when its' \c manip member function is called.
Chris@16 437 *
Chris@16 438 * \return A begin1 matrix index manipulator
Chris@16 439 *
Chris@16 440 * Example usage:
Chris@16 441 * \code:
Chris@16 442 * matrix<double> A(3, 3, 0);
Chris@16 443 * A <<= 1, 2, next_row(),
Chris@16 444 * 3, 4, begin1(), 1;
Chris@16 445 * \endcode
Chris@16 446 * will result in:
Chris@16 447 * \code
Chris@16 448 * 1 2 1
Chris@16 449 * 3 4 0
Chris@16 450 * 0 0 0
Chris@16 451 * \endcode
Chris@16 452 * \sa begin2()
Chris@16 453 */
Chris@16 454 inline begin1_manip begin1() {
Chris@16 455 return begin1_manip();
Chris@16 456 }
Chris@16 457
Chris@16 458 /**
Chris@16 459 * \brief A begining of column manipulator
Chris@16 460 *
Chris@16 461 * When member function \c manip is called the referenced
Chris@16 462 * index will be be set to the begining of the column (i.e. row = 0).
Chris@16 463 *
Chris@16 464 *
Chris@16 465 * \sa begin2()
Chris@16 466 */
Chris@16 467 class begin2_manip: public index_manipulator<begin2_manip > {
Chris@16 468 public:
Chris@16 469 template <typename V, typename K>
Chris@16 470 BOOST_UBLAS_INLINE
Chris@16 471 void manip(V &/*k*/, K &l) const {
Chris@16 472 l=0;
Chris@16 473 }
Chris@16 474 };
Chris@16 475
Chris@16 476 /**
Chris@16 477 * \brief An object generator that returns a begin2 manipulator to be used to traverse a matrix.
Chris@16 478 *
Chris@16 479 * The resulted manipulator will traverse the index to the begining
Chris@16 480 * of the current row when its' \c manip member function is called.
Chris@16 481 *
Chris@16 482 * \return A begin2 matrix manipulator
Chris@16 483 *
Chris@16 484 * Example:
Chris@16 485 * \code:
Chris@16 486 * matrix<double> A(3, 3, 0);
Chris@16 487 * A <<= 1, 2, move<1,0>(),
Chris@16 488 * 3, begin2(), 1;
Chris@16 489 * \endcode
Chris@16 490 * will result in:
Chris@16 491 * \code
Chris@16 492 * 1 2 0
Chris@16 493 * 1 0 3
Chris@16 494 * 0 0 0
Chris@16 495 * \endcode
Chris@16 496 * \sa begin1() begin2_manip
Chris@16 497 */
Chris@16 498 inline begin2_manip begin2() {
Chris@16 499 return begin2_manip();
Chris@16 500 }
Chris@16 501
Chris@16 502
Chris@16 503 /**
Chris@16 504 * \brief A next row matrix manipulator.
Chris@16 505 *
Chris@16 506 * When member function traverse is called the referenced
Chris@16 507 * index will be traveresed to the begining of next row.
Chris@16 508 *
Chris@16 509 * \sa next_row()
Chris@16 510 */
Chris@16 511 class next_row_manip: public index_manipulator<next_row_manip> {
Chris@16 512 public:
Chris@16 513 template <typename V, typename K>
Chris@16 514 BOOST_UBLAS_INLINE
Chris@16 515 void manip(V &k, K &l) const {
Chris@16 516 k++;
Chris@16 517 l=0;
Chris@16 518 }
Chris@16 519 };
Chris@16 520
Chris@16 521 /**
Chris@16 522 * \brief An object generator that returns a next_row manipulator.
Chris@16 523 *
Chris@16 524 * The resulted manipulator will traverse the index to the begining
Chris@16 525 * of the next row when it's manip member function is called.
Chris@16 526 *
Chris@16 527 * \return A next_row matrix manipulator.
Chris@16 528 *
Chris@16 529 * Example:
Chris@16 530 * \code:
Chris@16 531 * matrix<double> A(3, 3, 0);
Chris@16 532 * A <<= 1, 2, next_row(),
Chris@16 533 * 3, 4;
Chris@16 534 * \endcode
Chris@16 535 * will result in:
Chris@16 536 * \code
Chris@16 537 * 1 2 0
Chris@16 538 * 3 4 0
Chris@16 539 * 0 0 0
Chris@16 540 * \endcode
Chris@16 541 * \sa next_column()
Chris@16 542 */
Chris@16 543 inline next_row_manip next_row() {
Chris@16 544 return next_row_manip();
Chris@16 545 }
Chris@16 546
Chris@16 547 /**
Chris@16 548 * \brief A next column matrix manipulator.
Chris@16 549 *
Chris@16 550 * When member function traverse is called the referenced
Chris@16 551 * index will be traveresed to the begining of next column.
Chris@16 552 *
Chris@16 553 * \sa next_column()
Chris@16 554 */
Chris@16 555 class next_column_manip: public index_manipulator<next_column_manip> {
Chris@16 556 public:
Chris@16 557 template <typename V, typename K>
Chris@16 558 BOOST_UBLAS_INLINE
Chris@16 559 void manip(V &k, K &l) const {
Chris@16 560 k=0;
Chris@16 561 l++;
Chris@16 562 }
Chris@16 563 };
Chris@16 564
Chris@16 565 /**
Chris@16 566 * \brief An object generator that returns a next_row manipulator.
Chris@16 567 *
Chris@16 568 * The resulted manipulator will traverse the index to the begining
Chris@16 569 * of the next column when it's manip member function is called.
Chris@16 570 *
Chris@16 571 * \return A next_column matrix manipulator.
Chris@16 572 *
Chris@16 573 * Example:
Chris@16 574 * \code:
Chris@16 575 * matrix<double> A(3, 3, 0);
Chris@16 576 * A <<= 1, 2, 0,
Chris@16 577 * 3, next_column(), 4;
Chris@16 578 * \endcode
Chris@16 579 * will result in:
Chris@16 580 * \code
Chris@16 581 * 1 2 4
Chris@16 582 * 3 0 0
Chris@16 583 * 0 0 0
Chris@16 584 * \endcode
Chris@16 585 *
Chris@16 586 */
Chris@16 587 inline next_column_manip next_column() {
Chris@16 588 return next_column_manip();
Chris@16 589 }
Chris@16 590
Chris@16 591 /**
Chris@16 592 * \brief A wrapper for fill policy classes
Chris@16 593 *
Chris@16 594 */
Chris@16 595 template <class T>
Chris@16 596 class fill_policy_wrapper {
Chris@16 597 public:
Chris@16 598 typedef T type;
Chris@16 599 };
Chris@16 600
Chris@16 601 // Collection of the fill policies
Chris@16 602 namespace fill_policy {
Chris@16 603
Chris@16 604 /**
Chris@16 605 * \brief An index assign policy
Chris@16 606 *
Chris@16 607 * This policy is used to for the simplified ublas assign through
Chris@16 608 * normal indexing.
Chris@16 609 *
Chris@16 610 *
Chris@16 611 */
Chris@16 612 class index_assign :public fill_policy_wrapper<index_assign> {
Chris@16 613 public:
Chris@16 614 template <class T, typename S, typename V>
Chris@16 615 BOOST_UBLAS_INLINE
Chris@16 616 static void apply(T &e, const S &i, const V &v) {
Chris@16 617 e()(i) = v;
Chris@16 618 }
Chris@16 619 template <class T, typename S, typename V>
Chris@16 620 BOOST_UBLAS_INLINE
Chris@16 621 static void apply(T &e, const S &i, const S &j, const V &v) {
Chris@16 622 e()(i, j) = v;
Chris@16 623 }
Chris@16 624 };
Chris@16 625
Chris@16 626 /**
Chris@16 627 * \brief An index plus assign policy
Chris@16 628 *
Chris@16 629 * This policy is used when the assignment is desired to be followed
Chris@16 630 * by an addition.
Chris@16 631 *
Chris@16 632 *
Chris@16 633 */
Chris@16 634 class index_plus_assign :public fill_policy_wrapper<index_plus_assign> {
Chris@16 635 public:
Chris@16 636 template <class T, typename S, typename V>
Chris@16 637 BOOST_UBLAS_INLINE
Chris@16 638 static void apply(T &e, const S &i, const V &v) {
Chris@16 639 e()(i) += v;
Chris@16 640 }
Chris@16 641 template <class T, typename S, typename V>
Chris@16 642 BOOST_UBLAS_INLINE
Chris@16 643 static void apply(T &e, const S &i, const S &j, const V &v) {
Chris@16 644 e()(i, j) += v;
Chris@16 645 }
Chris@16 646 };
Chris@16 647
Chris@16 648 /**
Chris@16 649 * \brief An index minus assign policy
Chris@16 650 *
Chris@16 651 * This policy is used when the assignment is desired to be followed
Chris@16 652 * by a substraction.
Chris@16 653 *
Chris@16 654 *
Chris@16 655 */
Chris@16 656 class index_minus_assign :public fill_policy_wrapper<index_minus_assign> {
Chris@16 657 public:
Chris@16 658 template <class T, typename S, typename V>
Chris@16 659 BOOST_UBLAS_INLINE
Chris@16 660 static void apply(T &e, const S &i, const V &v) {
Chris@16 661 e()(i) -= v;
Chris@16 662 }
Chris@16 663 template <class T, typename S, typename V>
Chris@16 664 BOOST_UBLAS_INLINE
Chris@16 665 static void apply(T &e, const S &i, const S &j, const V &v) {
Chris@16 666 e()(i, j) -= v;
Chris@16 667 }
Chris@16 668 };
Chris@16 669
Chris@16 670 /**
Chris@16 671 * \brief The sparse push_back fill policy.
Chris@16 672 *
Chris@16 673 * This policy is adequate for sparse types, when fast filling is required, where indexing
Chris@16 674 * assign is pretty slow.
Chris@16 675
Chris@16 676 * It is important to note that push_back assign cannot be used to add elements before elements
Chris@16 677 * already existing in a sparse container. To achieve that please use the sparse_insert fill policy.
Chris@16 678 */
Chris@16 679 class sparse_push_back :public fill_policy_wrapper<sparse_push_back > {
Chris@16 680 public:
Chris@16 681 template <class T, class S, class V>
Chris@16 682 BOOST_UBLAS_INLINE
Chris@16 683 static void apply(T &e, const S &i, const V &v) {
Chris@16 684 e().push_back(i, v);
Chris@16 685 }
Chris@16 686 template <class T, class S, class V>
Chris@16 687 BOOST_UBLAS_INLINE
Chris@16 688 static void apply(T &e, const S &i, const S &j, const V &v) {
Chris@16 689 e().push_back(i,j, v);
Chris@16 690 }
Chris@16 691 };
Chris@16 692
Chris@16 693 /**
Chris@16 694 * \brief The sparse insert fill policy.
Chris@16 695 *
Chris@16 696 * This policy is adequate for sparse types, when fast filling is required, where indexing
Chris@16 697 * assign is pretty slow. It is slower than sparse_push_back fill policy, but it can be used to
Chris@16 698 * insert elements anywhere inside the container.
Chris@16 699 */
Chris@16 700 class sparse_insert :public fill_policy_wrapper<sparse_insert> {
Chris@16 701 public:
Chris@16 702 template <class T, class S, class V>
Chris@16 703 BOOST_UBLAS_INLINE
Chris@16 704 static void apply(T &e, const S &i, const V &v) {
Chris@16 705 e().insert_element(i, v);
Chris@16 706 }
Chris@16 707 template <class T, class S, class V>
Chris@16 708 BOOST_UBLAS_INLINE
Chris@16 709 static void apply(T &e, const S &i, const S &j, const V &v) {
Chris@16 710 e().insert_element(i,j, v);
Chris@16 711 }
Chris@16 712 };
Chris@16 713
Chris@16 714 }
Chris@16 715
Chris@16 716 /** \brief A wrapper for traverse policy classes
Chris@16 717 *
Chris@16 718 */
Chris@16 719 template <class T>
Chris@16 720 class traverse_policy_wrapper {
Chris@16 721 public:
Chris@16 722 typedef T type;
Chris@16 723 };
Chris@16 724
Chris@16 725 // Collection of the traverse policies
Chris@16 726 namespace traverse_policy {
Chris@16 727
Chris@16 728
Chris@16 729 /**
Chris@16 730 * \brief The no wrap policy.
Chris@16 731 *
Chris@16 732 * The no wrap policy does not allow wrapping when assigning to a matrix
Chris@16 733 */
Chris@16 734 struct no_wrap {
Chris@16 735 /**
Chris@16 736 * \brief Element wrap method
Chris@16 737 */
Chris@16 738 template <class S1, class S2, class S3>
Chris@16 739 BOOST_UBLAS_INLINE
Chris@16 740 static void apply1(const S1 &/*s*/, S2 &/*i*/, S3 &/*j*/) {
Chris@16 741 }
Chris@16 742
Chris@16 743 /**
Chris@16 744 * \brief Matrix block wrap method
Chris@16 745 */
Chris@16 746 template <class S1, class S2, class S3>
Chris@16 747 BOOST_UBLAS_INLINE
Chris@16 748 static void apply2(const S1 &/*s1*/, const S1 &/*s2*/, S2 &/*i1*/, S3 &/*i2*/) {
Chris@16 749 }
Chris@16 750 };
Chris@16 751
Chris@16 752 /**
Chris@16 753 * \brief The wrap policy.
Chris@16 754 *
Chris@16 755 * The wrap policy enables element wrapping when assigning to a matrix
Chris@16 756 */
Chris@16 757 struct wrap {
Chris@16 758 /**
Chris@16 759 * \brief Element wrap method
Chris@16 760 */
Chris@16 761 template <class S1, class S2, class S3>
Chris@16 762 BOOST_UBLAS_INLINE
Chris@16 763 static void apply1(const S1 &s, S2 &i1, S3 &i2) {
Chris@16 764 if (i2>=s) {
Chris@16 765 i1++;
Chris@16 766 i2=0;
Chris@16 767 }
Chris@16 768 }
Chris@16 769
Chris@16 770 /**
Chris@16 771 * \brief Matrix block wrap method
Chris@16 772 */
Chris@16 773 template <class S1, class S2, class S3>
Chris@16 774 BOOST_UBLAS_INLINE
Chris@16 775 static void apply2(const S1 &s1, const S1 &s2, S2 &i1, S3 &i2) {
Chris@16 776 if (i2>=s2) i2=0; // Wrap to the next block
Chris@16 777 else i1-=s1; // Move up (or right) one block
Chris@16 778 }
Chris@16 779 };
Chris@16 780
Chris@16 781 /**
Chris@16 782 * \brief The row_by_row traverse policy
Chris@16 783 *
Chris@16 784 * This policy is used when the assignment is desired to happen
Chris@16 785 * row_major wise for performance or other reasons.
Chris@16 786 *
Chris@16 787 * This is the default behaviour. To change it globally please define BOOST_UBLAS_DEFAULT_ASSIGN_BY_COLUMN
Chris@16 788 * in the compilation options or in an adequate header file.
Chris@16 789 *
Chris@16 790 * Please see EXAMPLES_LINK for usage information.
Chris@16 791 *
Chris@16 792 * \todo Add examples link
Chris@16 793 */
Chris@16 794 template <class Wrap = wrap>
Chris@16 795 class by_row_policy :public traverse_policy_wrapper<by_row_policy<Wrap> > {
Chris@16 796 public:
Chris@16 797 template <typename S1, typename S2>
Chris@16 798 BOOST_UBLAS_INLINE
Chris@16 799 static void advance(S1 &/*i*/, S2 &j) { j++;}
Chris@16 800
Chris@16 801 template <class E1, class E2, typename S1, typename S2, typename S3, typename S4, typename S5>
Chris@16 802 BOOST_UBLAS_INLINE
Chris@16 803 static bool next(const E1 &e, const E2 &me, S1 &i, S2 &j, const S3 &/*i0*/, const S3 &j0, S4 &k, S5 &l) {
Chris@16 804 l++; j++;
Chris@16 805 if (l>=e().size2()) {
Chris@16 806 l=0; k++; j=j0; i++;
Chris@101 807 // It is assumed that the iteration starts from 0 and progresses only using this function from within
Chris@16 808 // an assigner object.
Chris@16 809 // Otherwise (i.e. if it is called outside the assigner object) apply2 should have been
Chris@16 810 // outside the if statement.
Chris@16 811 if (k>=e().size1()) {
Chris@16 812 j=j0+e().size2();
Chris@16 813 Wrap::apply2(e().size1(), me().size2(), i, j);
Chris@16 814 return false;
Chris@16 815 }
Chris@16 816 }
Chris@16 817 return true;
Chris@16 818 }
Chris@16 819
Chris@16 820 template <class E, typename S1, typename S2>
Chris@16 821 BOOST_UBLAS_INLINE
Chris@16 822 static void apply_wrap(const E& e, S1 &i, S2 &j) {
Chris@16 823 Wrap::apply1(e().size2(), i, j);
Chris@16 824 }
Chris@16 825 };
Chris@16 826
Chris@16 827 /**
Chris@16 828 * \brief The column_by_column traverse policy
Chris@16 829 *
Chris@16 830 * This policy is used when the assignment is desired to happen
Chris@16 831 * column_major wise, for performance or other reasons.
Chris@16 832 *
Chris@16 833 * This is the NOT the default behaviour. To set this as the default define BOOST_UBLAS_DEFAULT_ASSIGN_BY_COLUMN
Chris@16 834 * in the compilation options or in an adequate header file.
Chris@16 835 *
Chris@16 836 * Please see EXAMPLES_LINK for usage information.
Chris@16 837 *
Chris@16 838 * \todo Add examples link
Chris@16 839 */
Chris@16 840 template <class Wrap = wrap>
Chris@16 841 class by_column_policy :public traverse_policy_wrapper<by_column_policy<Wrap> > {
Chris@16 842 public:
Chris@16 843 template <typename S1, typename S2>
Chris@16 844 BOOST_UBLAS_INLINE
Chris@16 845 static void advance(S1 &i, S2 &/*j*/) { i++;}
Chris@16 846
Chris@16 847 template <class E1, class E2, typename S1, typename S2, typename S3, typename S4, typename S5>
Chris@16 848 BOOST_UBLAS_INLINE
Chris@16 849 static bool next(const E1 &e, const E2 &me, S1 &i, S2 &j, const S3 &i0, const S3 &/*j0*/, S4 &k, S5 &l) {
Chris@16 850 k++; i++;
Chris@16 851 if (k>=e().size1()) {
Chris@16 852 k=0; l++; i=i0; j++;
Chris@101 853 // It is assumed that the iteration starts from 0 and progresses only using this function from within
Chris@16 854 // an assigner object.
Chris@16 855 // Otherwise (i.e. if it is called outside the assigner object) apply2 should have been
Chris@16 856 // outside the if statement.
Chris@16 857 if (l>=e().size2()) {
Chris@16 858 i=i0+e().size1();
Chris@16 859 Wrap::apply2(e().size2(), me().size1(), j, i);
Chris@16 860 return false;
Chris@16 861 }
Chris@16 862 }
Chris@16 863 return true;
Chris@16 864 }
Chris@16 865
Chris@16 866 template <class E, typename S1, typename S2>
Chris@16 867 BOOST_UBLAS_INLINE
Chris@16 868 static void apply_wrap(const E& e, S1 &i, S2 &j) {
Chris@16 869 Wrap::apply1(e().size1(), j, i);
Chris@16 870 }
Chris@16 871 };
Chris@16 872 }
Chris@16 873 #ifndef BOOST_UBLAS_DEFAULT_NO_WRAP_POLICY
Chris@16 874 typedef traverse_policy::wrap DEFAULT_WRAP_POLICY;
Chris@16 875 #else
Chris@16 876 typedef traverse_policy::no_wrap DEFAULT_WRAP_POLICY;
Chris@16 877 #endif
Chris@16 878
Chris@16 879 #ifndef BOOST_UBLAS_DEFAULT_ASSIGN_BY_COLUMN
Chris@16 880 typedef traverse_policy::by_row_policy<DEFAULT_WRAP_POLICY> DEFAULT_TRAVERSE_POLICY;
Chris@16 881 #else
Chris@16 882 typedef traverse_policy::by_column<DEFAULT_WRAP_POLICY> DEFAULT_TRAVERSE_POLICY;
Chris@16 883 #endif
Chris@16 884
Chris@16 885 // Traverse policy namespace
Chris@16 886 namespace traverse_policy {
Chris@16 887
Chris@16 888 inline by_row_policy<DEFAULT_WRAP_POLICY> by_row() {
Chris@16 889 return by_row_policy<DEFAULT_WRAP_POLICY>();
Chris@16 890 }
Chris@16 891
Chris@16 892 inline by_row_policy<wrap> by_row_wrap() {
Chris@16 893 return by_row_policy<wrap>();
Chris@16 894 }
Chris@16 895
Chris@16 896 inline by_row_policy<no_wrap> by_row_no_wrap() {
Chris@16 897 return by_row_policy<no_wrap>();
Chris@16 898 }
Chris@16 899
Chris@16 900 inline by_column_policy<DEFAULT_WRAP_POLICY> by_column() {
Chris@16 901 return by_column_policy<DEFAULT_WRAP_POLICY>();
Chris@16 902 }
Chris@16 903
Chris@16 904 inline by_column_policy<wrap> by_column_wrap() {
Chris@16 905 return by_column_policy<wrap>();
Chris@16 906 }
Chris@16 907
Chris@16 908 inline by_column_policy<no_wrap> by_column_no_wrap() {
Chris@16 909 return by_column_policy<no_wrap>();
Chris@16 910 }
Chris@16 911
Chris@16 912 }
Chris@16 913
Chris@16 914 /**
Chris@16 915 * \brief An assigner object used to fill a vector using operator <<= and operator, (comma)
Chris@16 916 *
Chris@16 917 * This object is meant to be created by appropriate object generators.
Chris@16 918 * Please see EXAMPLES_LINK for usage information.
Chris@16 919 *
Chris@16 920 * \todo Add examples link
Chris@16 921 */
Chris@16 922 template <class E, class Fill_Policy = fill_policy::index_assign>
Chris@16 923 class vector_expression_assigner {
Chris@16 924 public:
Chris@16 925 typedef typename E::expression_type::value_type value_type;
Chris@16 926 typedef typename E::expression_type::size_type size_type;
Chris@16 927
Chris@16 928 BOOST_UBLAS_INLINE
Chris@16 929 vector_expression_assigner(E &e):ve(e), i(0) {
Chris@16 930 }
Chris@16 931
Chris@16 932 BOOST_UBLAS_INLINE
Chris@16 933 vector_expression_assigner(size_type k, E &e):ve(e), i(k) {
Chris@16 934 // Overloaded like that so it can be differentiated from (E, val).
Chris@16 935 // Otherwise there would be an ambiquity when value_type == size_type.
Chris@16 936 }
Chris@16 937
Chris@16 938 BOOST_UBLAS_INLINE
Chris@16 939 vector_expression_assigner(E &e, value_type val):ve(e), i(0) {
Chris@16 940 operator,(val);
Chris@16 941 }
Chris@16 942
Chris@16 943 template <class AE>
Chris@16 944 BOOST_UBLAS_INLINE
Chris@16 945 vector_expression_assigner(E &e, const vector_expression<AE> &nve):ve(e), i(0) {
Chris@16 946 operator,(nve);
Chris@16 947 }
Chris@16 948
Chris@16 949 template <typename T>
Chris@16 950 BOOST_UBLAS_INLINE
Chris@16 951 vector_expression_assigner(E &e, const index_manipulator<T> &ta):ve(e), i(0) {
Chris@16 952 operator,(ta);
Chris@16 953 }
Chris@16 954
Chris@16 955 BOOST_UBLAS_INLINE
Chris@16 956 vector_expression_assigner &operator, (const value_type& val) {
Chris@16 957 apply(val);
Chris@16 958 return *this;
Chris@16 959 }
Chris@16 960
Chris@16 961 template <class AE>
Chris@16 962 BOOST_UBLAS_INLINE
Chris@16 963 vector_expression_assigner &operator, (const vector_expression<AE> &nve) {
Chris@16 964 for (typename AE::size_type k = 0; k!= nve().size(); k++)
Chris@16 965 operator,(nve()(k));
Chris@16 966 return *this;
Chris@16 967 }
Chris@16 968
Chris@16 969 template <typename T>
Chris@16 970 BOOST_UBLAS_INLINE
Chris@16 971 vector_expression_assigner &operator, (const index_manipulator<T> &ta) {
Chris@16 972 ta().manip(i);
Chris@16 973 return *this;
Chris@16 974 }
Chris@16 975
Chris@16 976 template <class T>
Chris@16 977 BOOST_UBLAS_INLINE
Chris@16 978 vector_expression_assigner<E, T> operator, (fill_policy_wrapper<T>) const {
Chris@16 979 return vector_expression_assigner<E, T>(i, ve);
Chris@16 980 }
Chris@16 981
Chris@16 982 private:
Chris@16 983 BOOST_UBLAS_INLINE
Chris@16 984 vector_expression_assigner &apply(const typename E::expression_type::value_type& val) {
Chris@16 985 Fill_Policy::apply(ve, i++, val);
Chris@16 986 return *this;
Chris@16 987 }
Chris@16 988
Chris@16 989 private:
Chris@16 990 E &ve;
Chris@16 991 size_type i;
Chris@16 992 };
Chris@16 993
Chris@16 994 /*
Chris@16 995 // The following static assigner is about 30% slower than the dynamic one, probably due to the recursive creation of assigner objects.
Chris@16 996 // It remains commented here for future reference.
Chris@16 997
Chris@16 998 template <class E, std::size_t I=0>
Chris@16 999 class static_vector_expression_assigner {
Chris@16 1000 public:
Chris@16 1001 typedef typename E::expression_type::value_type value_type;
Chris@16 1002 typedef typename E::expression_type::size_type size_type;
Chris@16 1003
Chris@16 1004 BOOST_UBLAS_INLINE
Chris@16 1005 static_vector_expression_assigner(E &e):ve(e) {
Chris@16 1006 }
Chris@16 1007
Chris@16 1008 BOOST_UBLAS_INLINE
Chris@16 1009 static_vector_expression_assigner(E &e, value_type val):ve(e) {
Chris@16 1010 operator,(val);
Chris@16 1011 }
Chris@16 1012
Chris@16 1013 BOOST_UBLAS_INLINE
Chris@16 1014 static_vector_expression_assigner<E, I+1> operator, (const value_type& val) {
Chris@16 1015 return apply(val);
Chris@16 1016 }
Chris@16 1017
Chris@16 1018 private:
Chris@16 1019 BOOST_UBLAS_INLINE
Chris@16 1020 static_vector_expression_assigner<E, I+1> apply(const typename E::expression_type::value_type& val) {
Chris@16 1021 ve()(I)=val;
Chris@16 1022 return static_vector_expression_assigner<E, I+1>(ve);
Chris@16 1023 }
Chris@16 1024
Chris@16 1025 private:
Chris@16 1026 E &ve;
Chris@16 1027 };
Chris@16 1028
Chris@16 1029 template <class E>
Chris@16 1030 BOOST_UBLAS_INLINE
Chris@16 1031 static_vector_expression_assigner<vector_expression<E>, 1 > test_static(vector_expression<E> &v, const typename E::value_type &val) {
Chris@16 1032 v()(0)=val;
Chris@16 1033 return static_vector_expression_assigner<vector_expression<E>, 1 >(v);
Chris@16 1034 }
Chris@16 1035 */
Chris@16 1036
Chris@16 1037
Chris@16 1038 /**
Chris@16 1039 * \brief A vector_expression_assigner generator used with operator<<= for simple types
Chris@16 1040 *
Chris@16 1041 * Please see EXAMPLES_LINK for usage information.
Chris@16 1042 *
Chris@16 1043 * \todo Add examples link
Chris@16 1044 */
Chris@16 1045 template <class E>
Chris@16 1046 BOOST_UBLAS_INLINE
Chris@16 1047 vector_expression_assigner<vector_expression<E> > operator<<=(vector_expression<E> &v, const typename E::value_type &val) {
Chris@16 1048 return vector_expression_assigner<vector_expression<E> >(v,val);
Chris@16 1049 }
Chris@16 1050
Chris@16 1051 /**
Chris@16 1052 * \brief ! A vector_expression_assigner generator used with operator<<= for vector expressions
Chris@16 1053 *
Chris@16 1054 * Please see EXAMPLES_LINK for usage information.
Chris@16 1055 *
Chris@16 1056 * \todo Add examples link
Chris@16 1057 */
Chris@16 1058 template <class E1, class E2>
Chris@16 1059 BOOST_UBLAS_INLINE
Chris@16 1060 vector_expression_assigner<vector_expression<E1> > operator<<=(vector_expression<E1> &v, const vector_expression<E2> &ve) {
Chris@16 1061 return vector_expression_assigner<vector_expression<E1> >(v,ve);
Chris@16 1062 }
Chris@16 1063
Chris@16 1064 /**
Chris@16 1065 * \brief A vector_expression_assigner generator used with operator<<= for traverse manipulators
Chris@16 1066 *
Chris@16 1067 * Please see EXAMPLES_LINK for usage information.
Chris@16 1068 *
Chris@16 1069 * \todo Add examples link
Chris@16 1070 */
Chris@16 1071 template <class E, typename T>
Chris@16 1072 BOOST_UBLAS_INLINE
Chris@16 1073 vector_expression_assigner<vector_expression<E> > operator<<=(vector_expression<E> &v, const index_manipulator<T> &nv) {
Chris@16 1074 return vector_expression_assigner<vector_expression<E> >(v,nv);
Chris@16 1075 }
Chris@16 1076
Chris@16 1077 /**
Chris@16 1078 * \brief A vector_expression_assigner generator used with operator<<= for choice of fill policy
Chris@16 1079 *
Chris@16 1080 * Please see EXAMPLES_LINK for usage information.
Chris@16 1081 *
Chris@16 1082 * \todo Add examples link
Chris@16 1083 */
Chris@16 1084 template <class E, typename T>
Chris@16 1085 BOOST_UBLAS_INLINE
Chris@16 1086 vector_expression_assigner<vector_expression<E>, T> operator<<=(vector_expression<E> &v, fill_policy_wrapper<T>) {
Chris@16 1087 return vector_expression_assigner<vector_expression<E>, T>(v);
Chris@16 1088 }
Chris@16 1089
Chris@16 1090 /**
Chris@16 1091 * \brief An assigner object used to fill a vector using operator <<= and operator, (comma)
Chris@16 1092 *
Chris@16 1093 * This object is meant to be created by appropriate object generators.
Chris@16 1094 * Please see EXAMPLES_LINK for usage information.
Chris@16 1095 *
Chris@16 1096 * \todo Add examples link
Chris@16 1097 */
Chris@16 1098 template <class E, class Fill_Policy = fill_policy::index_assign, class Traverse_Policy = DEFAULT_TRAVERSE_POLICY >
Chris@16 1099 class matrix_expression_assigner {
Chris@16 1100 public:
Chris@16 1101 typedef typename E::expression_type::size_type size_type;
Chris@16 1102
Chris@16 1103 BOOST_UBLAS_INLINE
Chris@16 1104 matrix_expression_assigner(E &e): me(e), i(0), j(0) {
Chris@16 1105 }
Chris@16 1106
Chris@16 1107 BOOST_UBLAS_INLINE
Chris@16 1108 matrix_expression_assigner(E &e, size_type k, size_type l): me(e), i(k), j(l) {
Chris@16 1109 }
Chris@16 1110
Chris@16 1111 BOOST_UBLAS_INLINE
Chris@16 1112 matrix_expression_assigner(E &e, typename E::expression_type::value_type val): me(e), i(0), j(0) {
Chris@16 1113 operator,(val);
Chris@16 1114 }
Chris@16 1115
Chris@16 1116 template <class AE>
Chris@16 1117 BOOST_UBLAS_INLINE
Chris@16 1118 matrix_expression_assigner(E &e, const vector_expression<AE> &nve):me(e), i(0), j(0) {
Chris@16 1119 operator,(nve);
Chris@16 1120 }
Chris@16 1121
Chris@16 1122 template <class AE>
Chris@16 1123 BOOST_UBLAS_INLINE
Chris@16 1124 matrix_expression_assigner(E &e, const matrix_expression<AE> &nme):me(e), i(0), j(0) {
Chris@16 1125 operator,(nme);
Chris@16 1126 }
Chris@16 1127
Chris@16 1128 template <typename T>
Chris@16 1129 BOOST_UBLAS_INLINE
Chris@16 1130 matrix_expression_assigner(E &e, const index_manipulator<T> &ta):me(e), i(0), j(0) {
Chris@16 1131 operator,(ta);
Chris@16 1132 }
Chris@16 1133
Chris@16 1134 BOOST_UBLAS_INLINE
Chris@16 1135 matrix_expression_assigner &operator, (const typename E::expression_type::value_type& val) {
Chris@16 1136 Traverse_Policy::apply_wrap(me, i ,j);
Chris@16 1137 return apply(val);
Chris@16 1138 }
Chris@16 1139
Chris@16 1140 template <class AE>
Chris@16 1141 BOOST_UBLAS_INLINE
Chris@16 1142 matrix_expression_assigner &operator, (const vector_expression<AE> &nve) {
Chris@16 1143 for (typename AE::size_type k = 0; k!= nve().size(); k++) {
Chris@16 1144 operator,(nve()(k));
Chris@16 1145 }
Chris@16 1146 return *this;
Chris@16 1147 }
Chris@16 1148
Chris@16 1149 template <class AE>
Chris@16 1150 BOOST_UBLAS_INLINE
Chris@16 1151 matrix_expression_assigner &operator, (const matrix_expression<AE> &nme) {
Chris@16 1152 return apply(nme);
Chris@16 1153 }
Chris@16 1154
Chris@16 1155 template <typename T>
Chris@16 1156 BOOST_UBLAS_INLINE
Chris@16 1157 matrix_expression_assigner &operator, (const index_manipulator<T> &ta) {
Chris@16 1158 ta().manip(i, j);
Chris@16 1159 return *this;
Chris@16 1160 }
Chris@16 1161
Chris@16 1162 template <class T>
Chris@16 1163 BOOST_UBLAS_INLINE
Chris@16 1164 matrix_expression_assigner<E, T, Traverse_Policy> operator, (fill_policy_wrapper<T>) const {
Chris@16 1165 return matrix_expression_assigner<E, T, Traverse_Policy>(me, i, j);
Chris@16 1166 }
Chris@16 1167
Chris@16 1168
Chris@16 1169 template <class T>
Chris@16 1170 BOOST_UBLAS_INLINE
Chris@16 1171 matrix_expression_assigner<E, Fill_Policy, T> operator, (traverse_policy_wrapper<T>) {
Chris@16 1172 Traverse_Policy::apply_wrap(me, i ,j);
Chris@16 1173 return matrix_expression_assigner<E, Fill_Policy, T>(me, i, j);
Chris@16 1174 }
Chris@16 1175
Chris@16 1176 private:
Chris@16 1177 BOOST_UBLAS_INLINE
Chris@16 1178 matrix_expression_assigner &apply(const typename E::expression_type::value_type& val) {
Chris@16 1179 Fill_Policy::apply(me, i, j, val);
Chris@16 1180 Traverse_Policy::advance(i,j);
Chris@16 1181 return *this;
Chris@16 1182 }
Chris@16 1183
Chris@16 1184 template <class AE>
Chris@16 1185 BOOST_UBLAS_INLINE
Chris@16 1186 matrix_expression_assigner &apply(const matrix_expression<AE> &nme) {
Chris@16 1187 size_type bi = i;
Chris@16 1188 size_type bj = j;
Chris@16 1189 typename AE::size_type k=0, l=0;
Chris@16 1190 Fill_Policy::apply(me, i, j, nme()(k, l));
Chris@16 1191 while (Traverse_Policy::next(nme, me, i, j, bi, bj, k, l))
Chris@16 1192 Fill_Policy::apply(me, i, j, nme()(k, l));
Chris@16 1193 return *this;
Chris@16 1194 }
Chris@16 1195
Chris@16 1196 private:
Chris@16 1197 E &me;
Chris@16 1198 size_type i, j;
Chris@16 1199 };
Chris@16 1200
Chris@16 1201 /**
Chris@16 1202 * \brief A matrix_expression_assigner generator used with operator<<= for simple types
Chris@16 1203 *
Chris@16 1204 * Please see EXAMPLES_LINK for usage information.
Chris@16 1205 *
Chris@16 1206 * \todo Add examples link
Chris@16 1207 */
Chris@16 1208 template <class E>
Chris@16 1209 BOOST_UBLAS_INLINE
Chris@16 1210 matrix_expression_assigner<matrix_expression<E> > operator<<=(matrix_expression<E> &me, const typename E::value_type &val) {
Chris@16 1211 return matrix_expression_assigner<matrix_expression<E> >(me,val);
Chris@16 1212 }
Chris@16 1213
Chris@16 1214 /**
Chris@16 1215 * \brief A matrix_expression_assigner generator used with operator<<= for choice of fill policy
Chris@16 1216 *
Chris@16 1217 * Please see EXAMPLES_LINK for usage information.
Chris@16 1218 *
Chris@16 1219 * \todo Add examples link
Chris@16 1220 */
Chris@16 1221 template <class E, typename T>
Chris@16 1222 BOOST_UBLAS_INLINE
Chris@16 1223 matrix_expression_assigner<matrix_expression<E>, T> operator<<=(matrix_expression<E> &me, fill_policy_wrapper<T>) {
Chris@16 1224 return matrix_expression_assigner<matrix_expression<E>, T>(me);
Chris@16 1225 }
Chris@16 1226
Chris@16 1227 /**
Chris@16 1228 * \brief A matrix_expression_assigner generator used with operator<<= for traverse manipulators
Chris@16 1229 *
Chris@16 1230 * Please see EXAMPLES_LINK for usage information.
Chris@16 1231 *
Chris@16 1232 * \todo Add examples link
Chris@16 1233 */
Chris@16 1234 template <class E, typename T>
Chris@16 1235 BOOST_UBLAS_INLINE
Chris@16 1236 matrix_expression_assigner<matrix_expression<E> > operator<<=(matrix_expression<E> &me, const index_manipulator<T> &ta) {
Chris@16 1237 return matrix_expression_assigner<matrix_expression<E> >(me,ta);
Chris@16 1238 }
Chris@16 1239
Chris@16 1240 /**
Chris@16 1241 * \brief A matrix_expression_assigner generator used with operator<<= for traverse manipulators
Chris@16 1242 *
Chris@16 1243 * Please see EXAMPLES_LINK for usage information.
Chris@16 1244 *
Chris@16 1245 * \todo Add examples link
Chris@16 1246 */
Chris@16 1247 template <class E, typename T>
Chris@16 1248 BOOST_UBLAS_INLINE
Chris@16 1249 matrix_expression_assigner<matrix_expression<E>, fill_policy::index_assign, T> operator<<=(matrix_expression<E> &me, traverse_policy_wrapper<T>) {
Chris@16 1250 return matrix_expression_assigner<matrix_expression<E>, fill_policy::index_assign, T>(me);
Chris@16 1251 }
Chris@16 1252
Chris@16 1253 /**
Chris@16 1254 * \brief A matrix_expression_assigner generator used with operator<<= for vector expressions
Chris@16 1255 *
Chris@16 1256 * Please see EXAMPLES_LINK for usage information.
Chris@16 1257 *
Chris@16 1258 * \todo Add examples link
Chris@16 1259 */
Chris@16 1260 template <class E1, class E2>
Chris@16 1261 BOOST_UBLAS_INLINE
Chris@16 1262 matrix_expression_assigner<matrix_expression<E1> > operator<<=(matrix_expression<E1> &me, const vector_expression<E2> &ve) {
Chris@16 1263 return matrix_expression_assigner<matrix_expression<E1> >(me,ve);
Chris@16 1264 }
Chris@16 1265
Chris@16 1266 /**
Chris@16 1267 * \brief A matrix_expression_assigner generator used with operator<<= for matrix expressions
Chris@16 1268 *
Chris@16 1269 * Please see EXAMPLES_LINK for usage information.
Chris@16 1270 *
Chris@16 1271 * \todo Add examples link
Chris@16 1272 */
Chris@16 1273 template <class E1, class E2>
Chris@16 1274 BOOST_UBLAS_INLINE
Chris@16 1275 matrix_expression_assigner<matrix_expression<E1> > operator<<=(matrix_expression<E1> &me1, const matrix_expression<E2> &me2) {
Chris@16 1276 return matrix_expression_assigner<matrix_expression<E1> >(me1,me2);
Chris@16 1277 }
Chris@16 1278
Chris@16 1279 } } }
Chris@16 1280
Chris@16 1281 #endif // ASSIGNMENT_HPP