00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MTL_BASE_MATRIX_INCLUDE
00013 #define MTL_BASE_MATRIX_INCLUDE
00014
00015 #include <algorithm>
00016 #include <boost/static_assert.hpp>
00017 #include <boost/mpl/bool.hpp>
00018 #include <boost/numeric/mtl/matrix/dimension.hpp>
00019 #include <boost/numeric/mtl/detail/index.hpp>
00020 #include <boost/numeric/mtl/utility/tag.hpp>
00021 #include <boost/numeric/mtl/utility/exception.hpp>
00022 #include <boost/numeric/mtl/utility/is_static.hpp>
00023
00024 namespace mtl { namespace matrix {
00025
00027 template <class Elt, class Parameters>
00028 struct base_matrix
00029 {
00030 typedef base_matrix self;
00031 typedef Elt value_type;
00032 typedef typename Parameters::orientation orientation;
00033 typedef typename Parameters::index index_type;
00034 typedef typename Parameters::dimensions dim_type;
00035 static bool const on_stack= Parameters::on_stack;
00036 typedef std::size_t size_type;
00037 protected:
00038 dim_type dim;
00039 size_type my_nnz;
00040 typedef mtl::traits::is_static<dim_type> static_bool;
00041
00042 public:
00043 base_matrix() : my_nnz(0) {}
00044
00046 explicit base_matrix(mtl::non_fixed::dimensions d) : dim(d), my_nnz(0) {}
00047
00049 friend void swap(self& x, self& y)
00050 {
00051 using std::swap;
00052 swap(x.my_nnz, y.my_nnz);
00053 swap(x.dim, y.dim);
00054 }
00055
00057
00060 void check_dim(size_type num_rows, size_type num_cols) const
00061 {
00062 MTL_DEBUG_THROW_IF(this->num_rows() * this->num_cols() != 0
00063 && (this->num_rows() != num_rows || this->num_cols() != num_cols),
00064 incompatible_size());
00065 }
00066
00067 protected:
00068 #if 0
00069
00070 void change_dim(mtl::non_fixed::dimensions d) { dim= d; }
00071
00072 template <std::size_t Rows, std::size_t Cols>
00073 void change_dim(mtl::fixed::dimensions<Rows, Cols> d) {}
00074 #endif
00075
00076 void change_dim(size_type r, size_type c, boost::mpl::false_) { dim= dim_type(r, c); }
00077 void change_dim(size_type r, size_type c, boost::mpl::true_) { check_dim(r, c); }
00078
00079 void change_dim(size_type r, size_type c) { change_dim(r, c, static_bool()); }
00080
00081 public:
00082
00083 size_type num_rows() const
00084 {
00085 return dim.num_rows();
00086 }
00087
00088 size_type begin_row() const
00089 {
00090 return index::change_to(index_type(), 0);
00091 }
00092
00093 size_type end_row() const
00094 {
00095 return index::change_to(index_type(), num_rows());
00096 }
00097
00098
00099 size_type num_cols() const
00100 {
00101 return dim.num_cols();
00102 }
00103
00104 size_type begin_col() const
00105 {
00106 return index::change_to(index_type(), 0);
00107 }
00108
00109 size_type end_col() const
00110 {
00111 return index::change_to(index_type(), num_cols());
00112 }
00113
00114
00115 size_type nnz() const
00116 {
00117 return my_nnz;
00118 }
00119
00120 protected:
00121
00122 size_type dim1(row_major) const
00123 {
00124 return num_rows();
00125 }
00126 size_type dim1(col_major) const
00127 {
00128 return num_cols();
00129 }
00130
00131
00132 size_type dim2(row_major) const
00133 {
00134 return num_cols();
00135 }
00136 size_type dim2(col_major) const
00137 {
00138 return num_rows();
00139 }
00140
00141
00142
00143 size_type major_(size_type r, size_type, row_major) const
00144 {
00145 return r;
00146 }
00147 size_type major_(size_type, size_type c, col_major) const
00148 {
00149 return c;
00150 }
00151
00152 public:
00153
00154 size_type dim1() const
00155 {
00156 return dim1(orientation());
00157 }
00158
00159
00160 size_type dim2() const
00161 {
00162 return dim2(orientation());
00163 }
00164
00165
00166
00167 size_type major_(size_type r, size_type c) const
00168 {
00169 return major_(r, c, orientation());
00170 }
00171
00172
00173
00174 size_type minor_(size_type r, size_type c) const
00175 {
00176 return major_(c, r, orientation());
00177 }
00178
00179
00180 dim_type get_dimensions() const
00181 {
00182 return dim;
00183 }
00184 };
00185
00186
00187
00188 }}
00189
00190 #endif // MTL_BASE_MATRIX_INCLUDE