00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MTL_MORTON_DENSE_INCLUDE
00013 #define MTL_MORTON_DENSE_INCLUDE
00014
00015 #include <boost/type_traits.hpp>
00016 #include <boost/mpl/if.hpp>
00017
00018 #include <boost/numeric/mtl/utility/common_include.hpp>
00019 #include <boost/numeric/mtl/utility/tag.hpp>
00020 #include <boost/numeric/mtl/utility/exception.hpp>
00021 #include <boost/numeric/mtl/matrix/crtp_base_matrix.hpp>
00022 #include <boost/numeric/mtl/matrix/base_sub_matrix.hpp>
00023 #include <boost/numeric/mtl/detail/contiguous_memory_block.hpp>
00024 #include <boost/numeric/mtl/detail/dilated_int.hpp>
00025 #include <boost/numeric/mtl/utility/iterator_adaptor.hpp>
00026 #include <boost/numeric/mtl/operation/set_to_zero.hpp>
00027 #include <boost/numeric/mtl/matrix/mat_expr.hpp>
00028 #include <boost/numeric/mtl/operation/print_matrix.hpp>
00029 #include <boost/numeric/mtl/operation/compute_factors.hpp>
00030 #include <boost/numeric/mtl/operation/clone.hpp>
00031
00032
00033
00034 namespace mtl { namespace matrix {
00035
00036
00037 struct morton_dense_sub_ctor {};
00038
00039 template <unsigned long BitMask>
00040 struct morton_dense_key
00041 {
00042 typedef std::size_t size_type;
00043 typedef dilated_int<std::size_t, BitMask, true> dilated_row_t;
00044 typedef dilated_int<std::size_t, ~BitMask, true> dilated_col_t;
00045 typedef morton_dense_key self;
00046
00047 morton_dense_key(size_type my_row, size_type my_col)
00048 : my_row(my_row), my_col(my_col), dilated_row(my_row), dilated_col(my_col)
00049 {}
00050
00051 bool operator== (self const& x) const
00052 {
00053 return my_row == x.my_row && my_col == x.my_col;
00054 }
00055
00056 bool operator!= (self const& x)
00057 {
00058 return !(*this == x);
00059 }
00060
00061 size_type row() const
00062 {
00063 return my_row;
00064 }
00065
00066 size_type col() const
00067 {
00068 return my_col;
00069 }
00070
00071 self& advance_row(int row_inc)
00072 {
00073 dilated_row.advance(row_inc);
00074
00075 my_row+= row_inc;
00076 return *this;
00077 }
00078
00079 self& advance_col(int col_inc)
00080 {
00081 dilated_col.advance(col_inc);
00082
00083 my_col+= col_inc;
00084 return *this;
00085 }
00086
00087 self& advance(int row_inc, int col_inc)
00088 {
00089 advance_row(row_inc);
00090 advance_col(col_inc);
00091 return *this;
00092 }
00093
00094 public:
00095 size_type my_row, my_col;
00096 dilated_row_t dilated_row;
00097 dilated_col_t dilated_col;
00098 };
00099
00100 template <unsigned long BitMask>
00101 struct morton_dense_el_cursor
00102 : public morton_dense_key<BitMask>
00103 {
00104 typedef std::size_t size_type;
00105 typedef dilated_int<std::size_t, ~BitMask, true> dilated_col_t;
00106 typedef morton_dense_el_cursor self;
00107 typedef morton_dense_key<BitMask> base;
00108 typedef base key_type;
00109
00110 morton_dense_el_cursor(size_type my_row, size_type my_col, size_type num_cols)
00111 : base(my_row, my_col), num_cols(num_cols)
00112 {}
00113
00114 self& operator++ ()
00115 {
00116 ++this->my_col; ++this->dilated_col;
00117 if (this->my_col == num_cols) {
00118 this->my_col= 0; this->dilated_col= dilated_col_t(0);
00119 ++this->my_row; ++this->dilated_row;
00120 }
00121 return *this;
00122 }
00123
00124 base& operator* ()
00125 {
00126 return *this;
00127 }
00128
00129 const base& operator* () const
00130 {
00131 return *this;
00132 }
00133
00134 protected:
00135 size_t num_cols;
00136 };
00137
00138 template <unsigned long BitMask>
00139 struct morton_dense_row_cursor
00140 : public morton_dense_key<BitMask>
00141 {
00142 typedef std::size_t size_type;
00143 typedef morton_dense_row_cursor self;
00144 typedef morton_dense_key<BitMask> base;
00145 typedef base key_type;
00146
00147 morton_dense_row_cursor(size_type my_row, size_type my_col)
00148 : base(my_row, my_col)
00149 {}
00150
00151 self& operator++ ()
00152 {
00153 ++this->my_row; ++this->dilated_row;
00154 return *this;
00155 }
00156
00157 self& operator+=(int inc)
00158 {
00159 this->advance_row(inc);
00160 return *this;
00161 };
00162
00163 self& operator-- ()
00164 {
00165 --this->my_row; --this->dilated_row;
00166 return *this;
00167 }
00168
00169 self& operator-=(int dec)
00170 {
00171 this->advance_row(-dec);
00172 return *this;
00173 };
00174
00175 self operator+ (int inc) const
00176 {
00177 self tmp(*this);
00178 tmp.advance_row(inc);
00179 return tmp;
00180 }
00181
00182 base& operator* ()
00183 {
00184 return *this;
00185 }
00186
00187 const base& operator* () const
00188 {
00189 return *this;
00190 }
00191 };
00192
00193 template <unsigned long BitMask>
00194 struct morton_dense_col_cursor
00195 : public morton_dense_key<BitMask>
00196 {
00197 typedef std::size_t size_type;
00198 typedef morton_dense_col_cursor self;
00199 typedef morton_dense_key<BitMask> base;
00200 typedef base key_type;
00201
00202 morton_dense_col_cursor(size_type my_row, size_type my_col)
00203 : base(my_row, my_col)
00204 {}
00205
00206 self& operator++ ()
00207 {
00208 ++this->my_col; ++this->dilated_col;
00209 return *this;
00210 }
00211
00212 self& operator+=(int inc)
00213 {
00214 this->advance_col(inc);
00215 return *this;
00216 };
00217
00218 self& operator-- ()
00219 {
00220 --this->my_col; --this->dilated_col;
00221 return *this;
00222 }
00223
00224 self& operator-=(int dec)
00225 {
00226 this->advance_col(-dec);
00227 return *this;
00228 };
00229
00230 self operator+ (int inc) const
00231 {
00232 self tmp(*this);
00233 tmp.advance_col(inc);
00234 return tmp;
00235 }
00236
00237 base& operator* ()
00238 {
00239 return *this;
00240 }
00241
00242 const base& operator* () const
00243 {
00244 return *this;
00245 }
00246 };
00247
00248
00249 template <typename Matrix>
00250 struct morton_dense_row_const_iterator
00251 : utilities::const_iterator_adaptor<typename mtl::traits::const_value<Matrix>::type, morton_dense_row_cursor<Matrix::mask>,
00252 typename Matrix::value_type>
00253 {
00254 static const unsigned long mask= Matrix::mask;
00255 typedef morton_dense_row_cursor<mask> cursor_type;
00256 typedef typename mtl::traits::const_value<Matrix>::type map_type;
00257 typedef typename Matrix::value_type value_type;
00258 typedef typename Matrix::size_type size_type;
00259 typedef utilities::const_iterator_adaptor<map_type, cursor_type, value_type> base;
00260
00261 morton_dense_row_const_iterator(const Matrix& matrix, size_type row, size_type col)
00262 : base(map_type(matrix), cursor_type(row, col))
00263 {}
00264 };
00265
00266
00267 template <typename Matrix>
00268 struct morton_dense_row_iterator
00269 : utilities::iterator_adaptor<typename mtl::traits::value<Matrix>::type, morton_dense_row_cursor<Matrix::mask>,
00270 typename Matrix::value_type>
00271 {
00272 static const unsigned long mask= Matrix::mask;
00273 typedef morton_dense_row_cursor<mask> cursor_type;
00274 typedef typename mtl::traits::value<Matrix>::type map_type;
00275 typedef typename Matrix::value_type value_type;
00276 typedef typename Matrix::size_type size_type;
00277 typedef utilities::iterator_adaptor<map_type, cursor_type, value_type> base;
00278
00279 morton_dense_row_iterator(Matrix& matrix, size_type row, size_type col)
00280 : base(map_type(matrix), cursor_type(row, col))
00281 {}
00282 };
00283
00284
00285 template <typename Matrix>
00286 struct morton_dense_col_const_iterator
00287 : utilities::const_iterator_adaptor<typename mtl::traits::const_value<Matrix>::type, morton_dense_col_cursor<Matrix::mask>,
00288 typename Matrix::value_type>
00289 {
00290 static const unsigned long mask= Matrix::mask;
00291 typedef morton_dense_col_cursor<mask> cursor_type;
00292 typedef typename mtl::traits::const_value<Matrix>::type map_type;
00293 typedef typename Matrix::value_type value_type;
00294 typedef typename Matrix::size_type size_type;
00295 typedef utilities::const_iterator_adaptor<map_type, cursor_type, value_type> base;
00296
00297 morton_dense_col_const_iterator(const Matrix& matrix, size_type row, size_type col)
00298 : base(map_type(matrix), cursor_type(row, col))
00299 {}
00300 };
00301
00302
00303 template <typename Matrix>
00304 struct morton_dense_col_iterator
00305 : utilities::iterator_adaptor<typename mtl::traits::value<Matrix>::type, morton_dense_col_cursor<Matrix::mask>,
00306 typename Matrix::value_type>
00307 {
00308 static const unsigned long mask= Matrix::mask;
00309 typedef morton_dense_col_cursor<mask> cursor_type;
00310 typedef typename mtl::traits::value<Matrix>::type map_type;
00311 typedef typename Matrix::value_type value_type;
00312 typedef typename Matrix::size_type size_type;
00313 typedef utilities::iterator_adaptor<map_type, cursor_type, value_type> base;
00314
00315 morton_dense_col_iterator(Matrix& matrix, size_type row, size_type col)
00316 : base(map_type(matrix), cursor_type(row, col)) {}
00317 };
00318
00319
00320
00321
00322 template <typename Elt, unsigned long BitMask, typename Parameters = mtl::matrix::parameters<> >
00323 class morton_dense : public base_sub_matrix<Elt, Parameters>,
00324 public mtl::detail::contiguous_memory_block<Elt, false>,
00325 public crtp_base_matrix< morton_dense<Elt, BitMask, Parameters>, Elt, std::size_t >,
00326 public mat_expr< morton_dense<Elt, BitMask, Parameters> >
00327 {
00328 typedef base_sub_matrix<Elt, Parameters> super;
00329 typedef mtl::detail::contiguous_memory_block<Elt, false> memory_base;
00330 typedef morton_dense self;
00331 typedef mat_expr< morton_dense<Elt, BitMask, Parameters> > expr_base;
00332 typedef crtp_matrix_assign< self, Elt, std::size_t > assign_base;
00333
00334 public:
00335
00336 typedef Parameters parameters;
00337 typedef typename Parameters::orientation orientation;
00338 typedef typename Parameters::index index_type;
00339 typedef typename Parameters::dimensions dim_type;
00340 typedef Elt value_type;
00341 typedef const value_type& const_reference;
00342 typedef value_type& reference;
00343 typedef std::size_t size_type;
00344 const static size_type mask= BitMask;
00345
00346
00347
00348
00349 typedef morton_dense_key<BitMask> key_type;
00350 typedef morton_dense_el_cursor<BitMask> el_cursor_type;
00351
00352 typedef dilated_int<std::size_t, BitMask, true> dilated_row_t;
00353 typedef dilated_int<std::size_t, ~BitMask, true> dilated_col_t;
00354
00355 protected:
00356
00357
00358 dilated_row_t my_begin_row, my_end_row;
00359 dilated_col_t my_begin_col, my_end_col;
00360
00361
00362 void set_ranges(size_type begin_r, size_type end_r, size_type begin_c, size_type end_c)
00363 {
00364 super::set_ranges(begin_r, end_r, begin_c, end_c);
00365 my_begin_row= begin_r; my_end_row= end_r;
00366 my_begin_col= begin_c; my_end_col= end_c;
00367 set_nnz();
00368 }
00369
00370
00371 void set_ranges(size_type num_rows, size_type num_cols)
00372 {
00373 set_ranges(this->begin_row(), this->begin_row() + num_rows,
00374 this->begin_col(), this->begin_col() + num_cols);
00375 }
00376
00377 void init(size_type num_rows, size_type num_cols)
00378 {
00379 set_ranges(num_rows, num_cols);
00380
00381 }
00382
00383 public:
00384
00385 morton_dense() : memory_base(memory_need(dim_type().num_rows(), dim_type().num_cols()))
00386 {
00387 init(dim_type().num_rows(), dim_type().num_cols());
00388 }
00389
00390
00391 explicit morton_dense(mtl::non_fixed::dimensions d)
00392 : memory_base(memory_need(d.num_rows(), d.num_cols()))
00393 {
00394 init(d.num_rows(), d.num_cols());
00395 }
00396
00397
00398 morton_dense(size_type num_rows, size_type num_cols)
00399 : memory_base(memory_need(num_rows, num_cols))
00400 {
00401 init(num_rows, num_cols);
00402 }
00403
00404
00405 explicit morton_dense(mtl::non_fixed::dimensions d, value_type* a)
00406 : memory_base(a, memory_need(d.num_rows(), d.num_cols()))
00407 {
00408 set_ranges(d.num_rows(), d.num_cols());
00409 }
00410
00411
00412 explicit morton_dense(size_type num_rows, size_type num_cols, value_type* a)
00413 : memory_base(a, memory_need(num_rows, num_cols))
00414 {
00415 set_ranges(num_rows, num_cols);
00416 }
00417
00418
00419
00420 explicit morton_dense(value_type* a)
00421 : memory_base(a, memory_need(dim_type().num_rows(), dim_type().num_cols()))
00422 {
00423 BOOST_ASSERT((dim_type::is_static));
00424 set_ranges(dim_type().num_rows(), dim_type().num_cols());
00425 }
00426
00427
00428 morton_dense(const self& m) : memory_base(m)
00429 {
00430 set_ranges(m.num_rows(), m.num_cols());
00431
00432 }
00433
00434 explicit morton_dense(const self& m, clone_ctor)
00435 : memory_base(m, clone_ctor())
00436 {
00437 init(m.num_rows(), m.num_cols());
00438 *this= m;
00439
00440 }
00441
00442
00443 template <typename MatrixSrc>
00444 explicit morton_dense(const MatrixSrc& src)
00445 : memory_base(memory_need(dim_type().num_rows(), dim_type().num_cols()))
00446 {
00447 init(dim_type().num_rows(), dim_type().num_cols());
00448 *this= src;
00449 }
00450
00451
00452
00453 explicit morton_dense(self& matrix, morton_dense_sub_ctor,
00454 size_type begin_r, size_type end_r, size_type begin_c, size_type end_c)
00455 : memory_base(matrix.data, memory_need(end_r - begin_r, end_c - begin_c), true)
00456 {
00457 matrix.check_ranges(begin_r, end_r, begin_c, end_c);
00458
00459 if (begin_r >= end_r || begin_c >= end_c) {
00460 set_ranges(0, 0);
00461 return;
00462 }
00463
00464
00465
00466 MTL_DEBUG_THROW_IF(&matrix[end_r-1][end_c-1] - &matrix[begin_r][begin_c]
00467 != &matrix[end_r-begin_r-1][end_c-begin_c-1] - &matrix[0][0],
00468 range_error("This sub-matrix cannot be used because it is split in memory"));
00469
00470
00471 dilated_row_t dilated_row(begin_r);
00472 dilated_col_t dilated_col(begin_c);
00473
00474
00475 this->data += dilated_row.dilated_value() + dilated_col.dilated_value();
00476 set_ranges(end_r - begin_r, end_c - begin_c);
00477 }
00478
00479
00480 void change_dim(size_type num_rows, size_type num_cols)
00481 {
00482 set_ranges(num_rows, num_cols);
00483 this->realloc(memory_need(num_rows, num_cols));
00484 }
00485
00486
00487 self& operator=(self src)
00488 {
00489
00490 assert(this != &src);
00491
00492 check_dim(src.num_rows(), src.num_cols());
00493 if (this->category == memory_base::view || src.category == memory_base::view)
00494 matrix_copy(src, *this);
00495 else
00496 memory_base::move_assignment(src);
00497 return *this;
00498 }
00499
00500
00501 using assign_base::operator=;
00502
00503
00504 value_type operator() (key_type const& key) const
00505 {
00506 return this->data[key.dilated_row.dilated_value() + key.dilated_col.dilated_value()];
00507 }
00508
00509 void operator()(key_type const& key, value_type const& value)
00510 {
00511 this->data[key.dilated_row.dilated_value() + key.dilated_col.dilated_value()]= value;
00512 }
00513
00514 const_reference operator() (size_type row, size_type col) const
00515 {
00516 MTL_DEBUG_THROW_IF(row < 0 || row >= this->num_rows() || col < 0 || col >= this->num_cols(), index_out_of_range());
00517 return this->data[dilated_row_t(row).dilated_value() + dilated_col_t(col).dilated_value()];
00518 }
00519
00520 value_type& operator() (size_type row, size_type col)
00521 {
00522 MTL_DEBUG_THROW_IF(row < 0 || row >= this->num_rows() || col < 0 || col >= this->num_cols(), index_out_of_range());
00523 return this->data[dilated_row_t(row).dilated_value() + dilated_col_t(col).dilated_value()];
00524 }
00525
00526 void crop() {}
00527
00528 protected:
00529 void set_nnz()
00530 {
00531 this->my_nnz = this->num_rows() * this->num_cols();
00532 }
00533
00534 size_type memory_need(size_type rows, size_type cols)
00535 {
00536 dilated_row_t n_rows(rows - 1);
00537 dilated_col_t n_cols(cols - 1);
00538 return (n_rows.dilated_value() + n_cols.dilated_value() + 1);
00539 }
00540
00541 friend void swap(self& matrix1, self& matrix2)
00542 {
00543 swap(static_cast<memory_base&>(matrix1), static_cast<memory_base&>(matrix2));
00544 swap(static_cast<super&>(matrix1), static_cast<super&>(matrix2));
00545 }
00546
00547 template <typename> friend struct sub_matrix_t;
00548 };
00549
00550
00551
00552
00553
00554
00555 template <typename Value, unsigned long Mask, typename Parameters>
00556 typename morton_dense<Value, Mask, Parameters>::size_type
00557 inline num_rows(const morton_dense<Value, Mask, Parameters>& matrix)
00558 {
00559 return matrix.num_rows();
00560 }
00561
00562 template <typename Value, unsigned long Mask, typename Parameters>
00563 typename morton_dense<Value, Mask, Parameters>::size_type
00564 inline num_cols(const morton_dense<Value, Mask, Parameters>& matrix)
00565 {
00566 return matrix.num_cols();
00567 }
00568
00569 template <typename Value, unsigned long Mask, typename Parameters>
00570 typename morton_dense<Value, Mask, Parameters>::size_type
00571 inline size(const morton_dense<Value, Mask, Parameters>& matrix)
00572 {
00573 return matrix.num_cols() * matrix.num_rows();
00574 }
00575
00576 }}
00577
00578
00579
00580
00581
00582
00583
00584
00585 namespace mtl { namespace traits {
00586
00587
00588 using mtl::matrix::morton_dense;
00589 using mtl::matrix::morton_dense_el_cursor;
00590 using mtl::matrix::morton_dense_col_cursor;
00591 using mtl::matrix::morton_dense_row_cursor;
00592 using mtl::matrix::morton_dense_col_const_iterator;
00593 using mtl::matrix::morton_dense_row_const_iterator;
00594 using mtl::matrix::morton_dense_col_iterator;
00595 using mtl::matrix::morton_dense_row_iterator;
00596
00597
00598
00599
00600
00601 template <class Elt, unsigned long BitMask, class Parameters>
00602 struct range_generator<glas::tag::all, morton_dense<Elt, BitMask, Parameters> >
00603 {
00604 typedef morton_dense<Elt, BitMask, Parameters> Matrix;
00605 typedef complexity_classes::linear_cached complexity;
00606 static int const level = 1;
00607 typedef morton_dense_el_cursor<BitMask> type;
00608 type begin(Matrix const& matrix)
00609 {
00610 return type(matrix.begin_row(), matrix.begin_col(), matrix.num_cols());
00611 }
00612 type end(Matrix const& matrix)
00613 {
00614 return type(matrix.end_row(), matrix.begin_col(), matrix.num_cols());
00615 }
00616 };
00617
00618 template <class Elt, unsigned long BitMask, class Parameters>
00619 struct range_generator<glas::tag::nz, morton_dense<Elt, BitMask, Parameters> >
00620 : range_generator<glas::tag::all, morton_dense<Elt, BitMask, Parameters> >
00621 {};
00622
00623 template <class Elt, unsigned long BitMask, class Parameters>
00624 struct range_generator<glas::tag::row, morton_dense<Elt, BitMask, Parameters> >
00625 : detail::all_rows_range_generator<morton_dense<Elt, BitMask, Parameters>, complexity_classes::linear_cached>
00626 {};
00627
00628
00629 template <class Elt, unsigned long BitMask, class Parameters>
00630 struct range_generator<glas::tag::nz,
00631 detail::sub_matrix_cursor<morton_dense<Elt, BitMask, Parameters>, glas::tag::row, 2> >
00632 {
00633 typedef morton_dense<Elt, BitMask, Parameters> matrix;
00634 typedef typename Collection<matrix>::size_type size_type;
00635 typedef detail::sub_matrix_cursor<matrix, glas::tag::row, 2> cursor;
00636 typedef complexity_classes::linear_cached complexity;
00637 static int const level = 1;
00638 typedef morton_dense_col_cursor<BitMask> type;
00639
00640 type begin(cursor const& c) const
00641 {
00642 return type(c.key, c.ref.begin_col());
00643 }
00644 type end(cursor const& c) const
00645 {
00646 return type(c.key, c.ref.end_col());
00647 }
00648 type lower_bound(cursor const& c, size_type position) const
00649 {
00650 return type(c.key, std::min(c.ref.end_col(), position));
00651 }
00652 };
00653
00654 template <class Elt, unsigned long BitMask, class Parameters>
00655 struct range_generator<glas::tag::all,
00656 detail::sub_matrix_cursor<morton_dense<Elt, BitMask, Parameters>, glas::tag::row, 2> >
00657 : range_generator<glas::tag::nz,
00658 detail::sub_matrix_cursor<morton_dense<Elt, BitMask, Parameters>, glas::tag::row, 2> >
00659 {};
00660
00661 template <class Elt, unsigned long BitMask, class Parameters>
00662 struct range_generator<glas::tag::col, morton_dense<Elt, BitMask, Parameters> >
00663 : detail::all_cols_range_generator<morton_dense<Elt, BitMask, Parameters>, complexity_classes::linear_cached>
00664 {};
00665
00666
00667 template <class Elt, unsigned long BitMask, class Parameters>
00668 struct range_generator<glas::tag::nz,
00669 detail::sub_matrix_cursor<morton_dense<Elt, BitMask, Parameters>, glas::tag::col, 2> >
00670 {
00671 typedef morton_dense<Elt, BitMask, Parameters> matrix;
00672 typedef typename Collection<matrix>::size_type size_type;
00673 typedef detail::sub_matrix_cursor<matrix, glas::tag::col, 2> cursor;
00674 typedef complexity_classes::linear_cached complexity;
00675 static int const level = 1;
00676 typedef morton_dense_row_cursor<BitMask> type;
00677
00678 type begin(cursor const& c)
00679 {
00680 return type(c.ref.begin_row(), c.key);
00681 }
00682 type end(cursor const& c)
00683 {
00684 return type(c.ref.end_row(), c.key);
00685 }
00686 type lower_bound(cursor const& c, size_type position) const
00687 {
00688 return type(std::min(c.ref.end_row(), position), c.key);
00689 }
00690 };
00691
00692 template <class Elt, unsigned long BitMask, class Parameters>
00693 struct range_generator<glas::tag::all,
00694 detail::sub_matrix_cursor<morton_dense<Elt, BitMask, Parameters>, glas::tag::col, 2> >
00695 : range_generator<glas::tag::nz,
00696 detail::sub_matrix_cursor<morton_dense<Elt, BitMask, Parameters>, glas::tag::col, 2> >
00697 {};
00698
00699
00700
00701
00702
00703
00704 namespace detail {
00705
00706 template <typename OuterTag, typename Matrix, bool is_const>
00707 struct morton_dense_iterator_range_generator
00708 {
00709 typedef Matrix matrix_type;
00710 typedef typename matrix_type::size_type size_type;
00711 typedef typename matrix_type::value_type value_type;
00712 typedef typename matrix_type::parameters parameters;
00713 typedef detail::sub_matrix_cursor<matrix_type, OuterTag, 2> cursor;
00714
00715 typedef complexity_classes::linear_cached complexity;
00716 static int const level = 1;
00717
00718 typedef typename boost::mpl::if_<
00719 boost::is_same<OuterTag, glas::tag::row>
00720 , typename boost::mpl::if_c<
00721 is_const
00722 , morton_dense_col_const_iterator<Matrix>
00723 , morton_dense_col_iterator<Matrix>
00724 >::type
00725 , typename boost::mpl::if_c<
00726 is_const
00727 , morton_dense_row_const_iterator<Matrix>
00728 , morton_dense_row_iterator<Matrix>
00729 >::type
00730 >::type type;
00731
00732 private:
00733
00734 typedef typename boost::mpl::if_c<is_const, const Matrix&, Matrix&>::type mref_type;
00735
00736 type begin_dispatch(cursor const& c, glas::tag::row)
00737 {
00738 return type(const_cast<mref_type>(c.ref), c.key, c.ref.begin_col());
00739 }
00740
00741 type end_dispatch(cursor const& c, glas::tag::row)
00742 {
00743 return type(const_cast<mref_type>(c.ref), c.key, c.ref.end_col());
00744 }
00745
00746 type begin_dispatch(cursor const& c, glas::tag::col)
00747 {
00748 return type(const_cast<mref_type>(c.ref), c.ref.begin_row(), c.key);
00749 }
00750
00751 type end_dispatch(cursor const& c, glas::tag::col)
00752 {
00753 return type(const_cast<mref_type>(c.ref), c.ref.end_row(), c.key);
00754 }
00755
00756 public:
00757
00758 type begin(cursor const& c)
00759 {
00760 return begin_dispatch(c, OuterTag());
00761 }
00762
00763 type end(cursor const& c)
00764 {
00765 return end_dispatch(c, OuterTag());
00766 }
00767 };
00768
00769 }
00770
00771
00772 template <typename Value, unsigned long BitMask, typename Parameters, typename OuterTag>
00773 struct range_generator<tag::iter::nz,
00774 detail::sub_matrix_cursor<morton_dense<Value, BitMask, Parameters>, OuterTag, 2> >
00775 : public detail::morton_dense_iterator_range_generator<OuterTag, morton_dense<Value, BitMask, Parameters>, false>
00776 {};
00777
00778 template <typename Value, unsigned long BitMask, typename Parameters, typename OuterTag>
00779 struct range_generator<tag::iter::all,
00780 detail::sub_matrix_cursor<morton_dense<Value, BitMask, Parameters>, OuterTag, 2> >
00781 : public detail::morton_dense_iterator_range_generator<OuterTag, morton_dense<Value, BitMask, Parameters>, false>
00782 {};
00783
00784 template <typename Value, unsigned long BitMask, typename Parameters, typename OuterTag>
00785 struct range_generator<tag::const_iter::nz,
00786 detail::sub_matrix_cursor<morton_dense<Value, BitMask, Parameters>, OuterTag, 2> >
00787 : public detail::morton_dense_iterator_range_generator<OuterTag, morton_dense<Value, BitMask, Parameters>, true>
00788 {};
00789
00790 template <typename Value, unsigned long BitMask, typename Parameters, typename OuterTag>
00791 struct range_generator<tag::const_iter::all,
00792 detail::sub_matrix_cursor<morton_dense<Value, BitMask, Parameters>, OuterTag, 2> >
00793 : public detail::morton_dense_iterator_range_generator<OuterTag, morton_dense<Value, BitMask, Parameters>, true>
00794 {};
00795
00796
00797 }}
00798
00799
00800 namespace mtl { namespace matrix {
00801
00802
00803
00804
00805
00806 template <typename Value, unsigned long BitMask, typename Parameters>
00807 struct sub_matrix_t<morton_dense<Value, BitMask, Parameters> >
00808 {
00809 typedef morton_dense<Value, BitMask, Parameters> matrix_type;
00810 typedef matrix_type sub_matrix_type;
00811 typedef matrix_type const const_sub_matrix_type;
00812 typedef typename matrix_type::size_type size_type;
00813
00814 sub_matrix_type operator()(matrix_type& matrix, size_type begin_r, size_type end_r, size_type begin_c, size_type end_c)
00815 {
00816 return sub_matrix_type(matrix, morton_dense_sub_ctor(), begin_r, end_r, begin_c, end_c);
00817 }
00818
00819 const_sub_matrix_type
00820 operator()(matrix_type const& matrix, size_type begin_r, size_type end_r, size_type begin_c, size_type end_c)
00821 {
00822
00823 sub_matrix_type tmp((*this)(const_cast<matrix_type&>(matrix), begin_r, end_r, begin_c, end_c));
00824 return tmp;
00825 }
00826 };
00827
00828 }}
00829
00830 namespace mtl {
00831
00832
00833 template <typename Value, unsigned long BitMask, typename Parameters>
00834 struct is_clonable< morton_dense<Value, BitMask, Parameters> > : boost::mpl::true_ {};
00835
00836 }
00837
00838 #endif // MTL_MORTON_DENSE_INCLUDE