We are going to win! wohoo

Dependencies:   mbed mbed-rtos

Committer:
madcowswe
Date:
Wed Nov 14 17:15:53 2012 +0000
Revision:
9:08552997b544
Parent:
1:6799c07fe510
Added an important comment

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sv 1:6799c07fe510 1 /*
sv 1:6799c07fe510 2 * Tiny Vector Matrix Library
sv 1:6799c07fe510 3 * Dense Vector Matrix Libary of Tiny size using Expression Templates
sv 1:6799c07fe510 4 *
sv 1:6799c07fe510 5 * Copyright (C) 2001 - 2007 Olaf Petzold <opetzold@users.sourceforge.net>
sv 1:6799c07fe510 6 *
sv 1:6799c07fe510 7 * This library is free software; you can redistribute it and/or
sv 1:6799c07fe510 8 * modify it under the terms of the GNU lesser General Public
sv 1:6799c07fe510 9 * License as published by the Free Software Foundation; either
sv 1:6799c07fe510 10 * version 2.1 of the License, or (at your option) any later version.
sv 1:6799c07fe510 11 *
sv 1:6799c07fe510 12 * This library is distributed in the hope that it will be useful,
sv 1:6799c07fe510 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
sv 1:6799c07fe510 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
sv 1:6799c07fe510 15 * lesser General Public License for more details.
sv 1:6799c07fe510 16 *
sv 1:6799c07fe510 17 * You should have received a copy of the GNU lesser General Public
sv 1:6799c07fe510 18 * License along with this library; if not, write to the Free Software
sv 1:6799c07fe510 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
sv 1:6799c07fe510 20 *
sv 1:6799c07fe510 21 * $Id: Matrix.h,v 1.58 2007-06-23 15:58:58 opetzold Exp $
sv 1:6799c07fe510 22 */
sv 1:6799c07fe510 23
sv 1:6799c07fe510 24 #ifndef TVMET_MATRIX_H
sv 1:6799c07fe510 25 #define TVMET_MATRIX_H
sv 1:6799c07fe510 26
sv 1:6799c07fe510 27 #include <iterator> // reverse_iterator
sv 1:6799c07fe510 28
sv 1:6799c07fe510 29 #include <tvmet/tvmet.h>
sv 1:6799c07fe510 30 #include <tvmet/TypePromotion.h>
sv 1:6799c07fe510 31 #include <tvmet/CommaInitializer.h>
sv 1:6799c07fe510 32 #include <tvmet/RunTimeError.h>
sv 1:6799c07fe510 33
sv 1:6799c07fe510 34 #include <tvmet/xpr/Matrix.h>
sv 1:6799c07fe510 35 #include <tvmet/xpr/MatrixRow.h>
sv 1:6799c07fe510 36 #include <tvmet/xpr/MatrixCol.h>
sv 1:6799c07fe510 37 #include <tvmet/xpr/MatrixDiag.h>
sv 1:6799c07fe510 38
sv 1:6799c07fe510 39 namespace tvmet {
sv 1:6799c07fe510 40
sv 1:6799c07fe510 41
sv 1:6799c07fe510 42 /* forwards */
sv 1:6799c07fe510 43 template<class T, std::size_t Rows, std::size_t Cols> class Matrix;
sv 1:6799c07fe510 44 template<class T,
sv 1:6799c07fe510 45 std::size_t RowsBgn, std::size_t RowsEnd,
sv 1:6799c07fe510 46 std::size_t ColsBgn, std::size_t ColsEnd,
sv 1:6799c07fe510 47 std::size_t RowStride, std::size_t ColStride /*=1*/>
sv 1:6799c07fe510 48 class MatrixSliceConstReference; // unused here; for me only
sv 1:6799c07fe510 49
sv 1:6799c07fe510 50
sv 1:6799c07fe510 51 /**
sv 1:6799c07fe510 52 * \class MatrixConstReference Matrix.h "tvmet/Matrix.h"
sv 1:6799c07fe510 53 * \brief value iterator for ET
sv 1:6799c07fe510 54 */
sv 1:6799c07fe510 55 template<class T, std::size_t NRows, std::size_t NCols>
sv 1:6799c07fe510 56 class MatrixConstReference
sv 1:6799c07fe510 57 : public TvmetBase < MatrixConstReference<T, NRows, NCols> >
sv 1:6799c07fe510 58 {
sv 1:6799c07fe510 59 public:
sv 1:6799c07fe510 60 typedef T value_type;
sv 1:6799c07fe510 61 typedef T* pointer;
sv 1:6799c07fe510 62 typedef const T* const_pointer;
sv 1:6799c07fe510 63
sv 1:6799c07fe510 64 /** Dimensions. */
sv 1:6799c07fe510 65 enum {
sv 1:6799c07fe510 66 Rows = NRows, /**< Number of rows. */
sv 1:6799c07fe510 67 Cols = NCols, /**< Number of cols. */
sv 1:6799c07fe510 68 Size = Rows * Cols /**< Complete Size of Matrix. */
sv 1:6799c07fe510 69 };
sv 1:6799c07fe510 70
sv 1:6799c07fe510 71 public:
sv 1:6799c07fe510 72 /** Complexity counter. */
sv 1:6799c07fe510 73 enum {
sv 1:6799c07fe510 74 ops = Rows * Cols
sv 1:6799c07fe510 75 };
sv 1:6799c07fe510 76
sv 1:6799c07fe510 77 private:
sv 1:6799c07fe510 78 MatrixConstReference();
sv 1:6799c07fe510 79 MatrixConstReference& operator=(const MatrixConstReference&);
sv 1:6799c07fe510 80
sv 1:6799c07fe510 81 public:
sv 1:6799c07fe510 82 /** Constructor. */
sv 1:6799c07fe510 83 explicit MatrixConstReference(const Matrix<T, Rows, Cols>& rhs)
sv 1:6799c07fe510 84 : m_data(rhs.data())
sv 1:6799c07fe510 85 { }
sv 1:6799c07fe510 86
sv 1:6799c07fe510 87 /** Constructor by a given memory pointer. */
sv 1:6799c07fe510 88 explicit MatrixConstReference(const_pointer data)
sv 1:6799c07fe510 89 : m_data(data)
sv 1:6799c07fe510 90 { }
sv 1:6799c07fe510 91
sv 1:6799c07fe510 92 public: // access operators
sv 1:6799c07fe510 93 /** access by index. */
sv 1:6799c07fe510 94 value_type operator()(std::size_t i, std::size_t j) const {
sv 1:6799c07fe510 95 TVMET_RT_CONDITION((i < Rows) && (j < Cols), "MatrixConstReference Bounce Violation")
sv 1:6799c07fe510 96 return m_data[i * Cols + j];
sv 1:6799c07fe510 97 }
sv 1:6799c07fe510 98
sv 1:6799c07fe510 99 public: // debugging Xpr parse tree
sv 1:6799c07fe510 100 void print_xpr(std::ostream& os, std::size_t l=0) const {
sv 1:6799c07fe510 101 os << IndentLevel(l)
sv 1:6799c07fe510 102 << "MatrixConstReference[O=" << ops << "]<"
sv 1:6799c07fe510 103 << "T=" << typeid(value_type).name() << ">,"
sv 1:6799c07fe510 104 << std::endl;
sv 1:6799c07fe510 105 }
sv 1:6799c07fe510 106
sv 1:6799c07fe510 107 private:
sv 1:6799c07fe510 108 const_pointer _tvmet_restrict m_data;
sv 1:6799c07fe510 109 };
sv 1:6799c07fe510 110
sv 1:6799c07fe510 111
sv 1:6799c07fe510 112 /**
sv 1:6799c07fe510 113 * \class Matrix Matrix.h "tvmet/Matrix.h"
sv 1:6799c07fe510 114 * \brief A tiny matrix class.
sv 1:6799c07fe510 115 *
sv 1:6799c07fe510 116 * The array syntax A[j][j] isn't supported here. The reason is that
sv 1:6799c07fe510 117 * operator[] always takes exactly one parameter, but operator() can
sv 1:6799c07fe510 118 * take any number of parameters (in the case of a rectangular matrix,
sv 1:6799c07fe510 119 * two paramters are needed). Therefore the cleanest way to do it is
sv 1:6799c07fe510 120 * with operator() rather than with operator[]. \see C++ FAQ Lite 13.8
sv 1:6799c07fe510 121 */
sv 1:6799c07fe510 122 template<class T, std::size_t NRows, std::size_t NCols>
sv 1:6799c07fe510 123 class Matrix
sv 1:6799c07fe510 124 {
sv 1:6799c07fe510 125 public:
sv 1:6799c07fe510 126 /** Data type of the tvmet::Matrix. */
sv 1:6799c07fe510 127 typedef T value_type;
sv 1:6799c07fe510 128
sv 1:6799c07fe510 129 /** Reference type of the tvmet::Matrix data elements. */
sv 1:6799c07fe510 130 typedef T& reference;
sv 1:6799c07fe510 131
sv 1:6799c07fe510 132 /** const reference type of the tvmet::Matrix data elements. */
sv 1:6799c07fe510 133 typedef const T& const_reference;
sv 1:6799c07fe510 134
sv 1:6799c07fe510 135 /** STL iterator interface. */
sv 1:6799c07fe510 136 typedef T* iterator;
sv 1:6799c07fe510 137
sv 1:6799c07fe510 138 /** STL const_iterator interface. */
sv 1:6799c07fe510 139 typedef const T* const_iterator;
sv 1:6799c07fe510 140
sv 1:6799c07fe510 141 /** STL reverse iterator interface. */
sv 1:6799c07fe510 142 typedef std::reverse_iterator<iterator> reverse_iterator;
sv 1:6799c07fe510 143
sv 1:6799c07fe510 144 /** STL const reverse iterator interface. */
sv 1:6799c07fe510 145 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
sv 1:6799c07fe510 146
sv 1:6799c07fe510 147 public:
sv 1:6799c07fe510 148 /** Dimensions. */
sv 1:6799c07fe510 149 enum {
sv 1:6799c07fe510 150 Rows = NRows, /**< Number of rows. */
sv 1:6799c07fe510 151 Cols = NCols, /**< Number of cols. */
sv 1:6799c07fe510 152 Size = Rows * Cols /**< Complete Size of Matrix. */
sv 1:6799c07fe510 153 };
sv 1:6799c07fe510 154
sv 1:6799c07fe510 155 public:
sv 1:6799c07fe510 156 /** Complexity counter. */
sv 1:6799c07fe510 157 enum {
sv 1:6799c07fe510 158 ops_assign = Rows * Cols,
sv 1:6799c07fe510 159 ops = ops_assign,
sv 1:6799c07fe510 160 use_meta = ops < TVMET_COMPLEXITY_M_ASSIGN_TRIGGER ? true : false
sv 1:6799c07fe510 161 };
sv 1:6799c07fe510 162
sv 1:6799c07fe510 163 public: // STL interface
sv 1:6799c07fe510 164 /** STL iterator interface. */
sv 1:6799c07fe510 165 iterator begin() { return m_data; }
sv 1:6799c07fe510 166
sv 1:6799c07fe510 167 /** STL iterator interface. */
sv 1:6799c07fe510 168 iterator end() { return m_data + Size; }
sv 1:6799c07fe510 169
sv 1:6799c07fe510 170 /** STL const_iterator interface. */
sv 1:6799c07fe510 171 const_iterator begin() const { return m_data; }
sv 1:6799c07fe510 172
sv 1:6799c07fe510 173 /** STL const_iterator interface. */
sv 1:6799c07fe510 174 const_iterator end() const { return m_data + Size; }
sv 1:6799c07fe510 175
sv 1:6799c07fe510 176 /** STL reverse iterator interface reverse begin. */
sv 1:6799c07fe510 177 reverse_iterator rbegin() { return reverse_iterator( end() ); }
sv 1:6799c07fe510 178
sv 1:6799c07fe510 179 /** STL const reverse iterator interface reverse begin. */
sv 1:6799c07fe510 180 const_reverse_iterator rbegin() const {
sv 1:6799c07fe510 181 return const_reverse_iterator( end() );
sv 1:6799c07fe510 182 }
sv 1:6799c07fe510 183
sv 1:6799c07fe510 184 /** STL reverse iterator interface reverse end. */
sv 1:6799c07fe510 185 reverse_iterator rend() { return reverse_iterator( begin() ); }
sv 1:6799c07fe510 186
sv 1:6799c07fe510 187 /** STL const reverse iterator interface reverse end. */
sv 1:6799c07fe510 188 const_reverse_iterator rend() const {
sv 1:6799c07fe510 189 return const_reverse_iterator( begin() );
sv 1:6799c07fe510 190 }
sv 1:6799c07fe510 191
sv 1:6799c07fe510 192 /** The size of the matrix. */
sv 1:6799c07fe510 193 static std::size_t size() { return Size; }
sv 1:6799c07fe510 194
sv 1:6799c07fe510 195 /** STL vector max_size() - returns allways rows()*cols(). */
sv 1:6799c07fe510 196 static std::size_t max_size() { return Size; }
sv 1:6799c07fe510 197
sv 1:6799c07fe510 198 /** STL vector empty() - returns allways false. */
sv 1:6799c07fe510 199 static bool empty() { return false; }
sv 1:6799c07fe510 200
sv 1:6799c07fe510 201 public:
sv 1:6799c07fe510 202 /** The number of rows of matrix. */
sv 1:6799c07fe510 203 static std::size_t rows() { return Rows; }
sv 1:6799c07fe510 204
sv 1:6799c07fe510 205 /** The number of columns of matrix. */
sv 1:6799c07fe510 206 static std::size_t cols() { return Cols; }
sv 1:6799c07fe510 207
sv 1:6799c07fe510 208 public:
sv 1:6799c07fe510 209 /** Default Destructor */
sv 1:6799c07fe510 210 ~Matrix() {
sv 1:6799c07fe510 211 #if defined(TVMET_DYNAMIC_MEMORY)
sv 1:6799c07fe510 212 delete [] m_data;
sv 1:6799c07fe510 213 #endif
sv 1:6799c07fe510 214 }
sv 1:6799c07fe510 215
sv 1:6799c07fe510 216 /** Default Constructor. The allocated memory region isn't cleared. If you want
sv 1:6799c07fe510 217 a clean use the constructor argument zero. */
sv 1:6799c07fe510 218 explicit Matrix()
sv 1:6799c07fe510 219 #if defined(TVMET_DYNAMIC_MEMORY)
sv 1:6799c07fe510 220 : m_data( new value_type[Size] )
sv 1:6799c07fe510 221 #endif
sv 1:6799c07fe510 222 { }
sv 1:6799c07fe510 223
sv 1:6799c07fe510 224 /** Copy Constructor, not explicit! */
sv 1:6799c07fe510 225 Matrix(const Matrix& rhs)
sv 1:6799c07fe510 226 #if defined(TVMET_DYNAMIC_MEMORY)
sv 1:6799c07fe510 227 : m_data( new value_type[Size] )
sv 1:6799c07fe510 228 #endif
sv 1:6799c07fe510 229 {
sv 1:6799c07fe510 230 *this = XprMatrix<ConstReference, Rows, Cols>(rhs.const_ref());
sv 1:6799c07fe510 231 }
sv 1:6799c07fe510 232
sv 1:6799c07fe510 233 /**
sv 1:6799c07fe510 234 * Constructor with STL iterator interface. The data will be copied into the matrix
sv 1:6799c07fe510 235 * self, there isn't any stored reference to the array pointer.
sv 1:6799c07fe510 236 */
sv 1:6799c07fe510 237 template<class InputIterator>
sv 1:6799c07fe510 238 explicit Matrix(InputIterator first, InputIterator last)
sv 1:6799c07fe510 239 #if defined(TVMET_DYNAMIC_MEMORY)
sv 1:6799c07fe510 240 : m_data( new value_type[Size] )
sv 1:6799c07fe510 241 #endif
sv 1:6799c07fe510 242 {
sv 1:6799c07fe510 243 TVMET_RT_CONDITION(static_cast<std::size_t>(std::distance(first, last)) <= Size,
sv 1:6799c07fe510 244 "InputIterator doesn't fits in size" )
sv 1:6799c07fe510 245 std::copy(first, last, m_data);
sv 1:6799c07fe510 246 }
sv 1:6799c07fe510 247
sv 1:6799c07fe510 248 /**
sv 1:6799c07fe510 249 * Constructor with STL iterator interface. The data will be copied into the matrix
sv 1:6799c07fe510 250 * self, there isn't any stored reference to the array pointer.
sv 1:6799c07fe510 251 */
sv 1:6799c07fe510 252 template<class InputIterator>
sv 1:6799c07fe510 253 explicit Matrix(InputIterator first, std::size_t sz)
sv 1:6799c07fe510 254 #if defined(TVMET_DYNAMIC_MEMORY)
sv 1:6799c07fe510 255 : m_data( new value_type[Size] )
sv 1:6799c07fe510 256 #endif
sv 1:6799c07fe510 257 {
sv 1:6799c07fe510 258 TVMET_RT_CONDITION(sz <= Size, "InputIterator doesn't fits in size" )
sv 1:6799c07fe510 259 std::copy(first, first + sz, m_data);
sv 1:6799c07fe510 260 }
sv 1:6799c07fe510 261
sv 1:6799c07fe510 262 /** Construct the matrix by value. */
sv 1:6799c07fe510 263 explicit Matrix(value_type rhs)
sv 1:6799c07fe510 264 #if defined(TVMET_DYNAMIC_MEMORY)
sv 1:6799c07fe510 265 : m_data( new value_type[Size] )
sv 1:6799c07fe510 266 #endif
sv 1:6799c07fe510 267 {
sv 1:6799c07fe510 268 typedef XprLiteral<value_type> expr_type;
sv 1:6799c07fe510 269 *this = XprMatrix<expr_type, Rows, Cols>(expr_type(rhs));
sv 1:6799c07fe510 270 }
sv 1:6799c07fe510 271
sv 1:6799c07fe510 272 /** Construct a matrix by expression. */
sv 1:6799c07fe510 273 template<class E>
sv 1:6799c07fe510 274 explicit Matrix(const XprMatrix<E, Rows, Cols>& e)
sv 1:6799c07fe510 275 #if defined(TVMET_DYNAMIC_MEMORY)
sv 1:6799c07fe510 276 : m_data( new value_type[Size] )
sv 1:6799c07fe510 277 #endif
sv 1:6799c07fe510 278 {
sv 1:6799c07fe510 279 *this = e;
sv 1:6799c07fe510 280 }
sv 1:6799c07fe510 281
sv 1:6799c07fe510 282 /** assign a value_type on array, this can be used for a single value
sv 1:6799c07fe510 283 or a comma separeted list of values. */
sv 1:6799c07fe510 284 CommaInitializer<Matrix, Size> operator=(value_type rhs) {
sv 1:6799c07fe510 285 return CommaInitializer<Matrix, Size>(*this, rhs);
sv 1:6799c07fe510 286 }
sv 1:6799c07fe510 287
sv 1:6799c07fe510 288 public: // access operators
sv 1:6799c07fe510 289 value_type* _tvmet_restrict data() { return m_data; }
sv 1:6799c07fe510 290 const value_type* _tvmet_restrict data() const { return m_data; }
sv 1:6799c07fe510 291
sv 1:6799c07fe510 292 public: // index access operators
sv 1:6799c07fe510 293 value_type& _tvmet_restrict operator()(std::size_t i, std::size_t j) {
sv 1:6799c07fe510 294 // Note: g++-2.95.3 does have problems on typedef reference
sv 1:6799c07fe510 295 TVMET_RT_CONDITION((i < Rows) && (j < Cols), "Matrix Bounce Violation")
sv 1:6799c07fe510 296 return m_data[i * Cols + j];
sv 1:6799c07fe510 297 }
sv 1:6799c07fe510 298
sv 1:6799c07fe510 299 value_type operator()(std::size_t i, std::size_t j) const {
sv 1:6799c07fe510 300 TVMET_RT_CONDITION((i < Rows) && (j < Cols), "Matrix Bounce Violation")
sv 1:6799c07fe510 301 return m_data[i * Cols + j];
sv 1:6799c07fe510 302 }
sv 1:6799c07fe510 303
sv 1:6799c07fe510 304 public: // ET interface
sv 1:6799c07fe510 305 typedef MatrixConstReference<T, Rows, Cols> ConstReference;
sv 1:6799c07fe510 306
sv 1:6799c07fe510 307 typedef MatrixSliceConstReference<
sv 1:6799c07fe510 308 T,
sv 1:6799c07fe510 309 0, Rows, 0, Cols,
sv 1:6799c07fe510 310 Rows, 1
sv 1:6799c07fe510 311 > SliceConstReference;
sv 1:6799c07fe510 312
sv 1:6799c07fe510 313 /** Return a const Reference of the internal data */
sv 1:6799c07fe510 314 ConstReference const_ref() const { return ConstReference(*this); }
sv 1:6799c07fe510 315
sv 1:6799c07fe510 316 /**
sv 1:6799c07fe510 317 * Return a sliced const Reference of the internal data.
sv 1:6799c07fe510 318 * \note Doesn't work since isn't implemented, but it is in
sv 1:6799c07fe510 319 * progress. Therefore this is a placeholder. */
sv 1:6799c07fe510 320 ConstReference const_sliceref() const { return SliceConstReference(*this); }
sv 1:6799c07fe510 321
sv 1:6799c07fe510 322 /** Return the vector as const expression. */
sv 1:6799c07fe510 323 XprMatrix<ConstReference, Rows, Cols> as_expr() const {
sv 1:6799c07fe510 324 return XprMatrix<ConstReference, Rows, Cols>(this->const_ref());
sv 1:6799c07fe510 325 }
sv 1:6799c07fe510 326
sv 1:6799c07fe510 327 private:
sv 1:6799c07fe510 328 /** Wrapper for meta assign. */
sv 1:6799c07fe510 329 template<class Dest, class Src, class Assign>
sv 1:6799c07fe510 330 static inline
sv 1:6799c07fe510 331 void do_assign(dispatch<true>, Dest& dest, const Src& src, const Assign& assign_fn) {
sv 1:6799c07fe510 332 meta::Matrix<Rows, Cols, 0, 0>::assign(dest, src, assign_fn);
sv 1:6799c07fe510 333 }
sv 1:6799c07fe510 334
sv 1:6799c07fe510 335 /** Wrapper for loop assign. */
sv 1:6799c07fe510 336 template<class Dest, class Src, class Assign>
sv 1:6799c07fe510 337 static inline
sv 1:6799c07fe510 338 void do_assign(dispatch<false>, Dest& dest, const Src& src, const Assign& assign_fn) {
sv 1:6799c07fe510 339 loop::Matrix<Rows, Cols>::assign(dest, src, assign_fn);
sv 1:6799c07fe510 340 }
sv 1:6799c07fe510 341
sv 1:6799c07fe510 342 private:
sv 1:6799c07fe510 343 /** assign this to a matrix of a different type T2 using
sv 1:6799c07fe510 344 the functional assign_fn. */
sv 1:6799c07fe510 345 template<class T2, class Assign>
sv 1:6799c07fe510 346 void assign_to(Matrix<T2, Rows, Cols>& dest, const Assign& assign_fn) const {
sv 1:6799c07fe510 347 do_assign(dispatch<use_meta>(), dest, *this, assign_fn);
sv 1:6799c07fe510 348 }
sv 1:6799c07fe510 349
sv 1:6799c07fe510 350 public: // assign operations
sv 1:6799c07fe510 351 /** assign a given matrix of a different type T2 element wise
sv 1:6799c07fe510 352 to this matrix. The operator=(const Matrix&) is compiler
sv 1:6799c07fe510 353 generated. */
sv 1:6799c07fe510 354 template<class T2>
sv 1:6799c07fe510 355 Matrix& operator=(const Matrix<T2, Rows, Cols>& rhs) {
sv 1:6799c07fe510 356 rhs.assign_to(*this, Fcnl_assign<value_type, T2>());
sv 1:6799c07fe510 357 return *this;
sv 1:6799c07fe510 358 }
sv 1:6799c07fe510 359
sv 1:6799c07fe510 360 /** assign a given XprMatrix element wise to this matrix. */
sv 1:6799c07fe510 361 template <class E>
sv 1:6799c07fe510 362 Matrix& operator=(const XprMatrix<E, Rows, Cols>& rhs) {
sv 1:6799c07fe510 363 rhs.assign_to(*this, Fcnl_assign<value_type, typename E::value_type>());
sv 1:6799c07fe510 364 return *this;
sv 1:6799c07fe510 365 }
sv 1:6799c07fe510 366
sv 1:6799c07fe510 367 private:
sv 1:6799c07fe510 368 template<class Obj, std::size_t LEN> friend class CommaInitializer;
sv 1:6799c07fe510 369
sv 1:6799c07fe510 370 /** This is a helper for assigning a comma separated initializer
sv 1:6799c07fe510 371 list. It's equal to Matrix& operator=(value_type) which does
sv 1:6799c07fe510 372 replace it. */
sv 1:6799c07fe510 373 Matrix& assign_value(value_type rhs) {
sv 1:6799c07fe510 374 typedef XprLiteral<value_type> expr_type;
sv 1:6799c07fe510 375 *this = XprMatrix<expr_type, Rows, Cols>(expr_type(rhs));
sv 1:6799c07fe510 376 return *this;
sv 1:6799c07fe510 377 }
sv 1:6799c07fe510 378
sv 1:6799c07fe510 379 public: // math operators with scalars
sv 1:6799c07fe510 380 // NOTE: this meaning is clear - element wise ops even if not in ns element_wise
sv 1:6799c07fe510 381 Matrix& operator+=(value_type) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 382 Matrix& operator-=(value_type) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 383 Matrix& operator*=(value_type) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 384 Matrix& operator/=(value_type) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 385
sv 1:6799c07fe510 386 Matrix& operator%=(std::size_t) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 387 Matrix& operator^=(std::size_t) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 388 Matrix& operator&=(std::size_t) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 389 Matrix& operator|=(std::size_t) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 390 Matrix& operator<<=(std::size_t) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 391 Matrix& operator>>=(std::size_t) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 392
sv 1:6799c07fe510 393 public: // math operators with matrizes
sv 1:6799c07fe510 394 // NOTE: access using the operators in ns element_wise, since that's what is does
sv 1:6799c07fe510 395 template <class T2> Matrix& M_add_eq(const Matrix<T2, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 396 template <class T2> Matrix& M_sub_eq(const Matrix<T2, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 397 template <class T2> Matrix& M_mul_eq(const Matrix<T2, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 398 template <class T2> Matrix& M_div_eq(const Matrix<T2, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 399 template <class T2> Matrix& M_mod_eq(const Matrix<T2, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 400 template <class T2> Matrix& M_xor_eq(const Matrix<T2, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 401 template <class T2> Matrix& M_and_eq(const Matrix<T2, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 402 template <class T2> Matrix& M_or_eq (const Matrix<T2, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 403 template <class T2> Matrix& M_shl_eq(const Matrix<T2, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 404 template <class T2> Matrix& M_shr_eq(const Matrix<T2, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 405
sv 1:6799c07fe510 406 public: // math operators with expressions
sv 1:6799c07fe510 407 // NOTE: access using the operators in ns element_wise, since that's what is does
sv 1:6799c07fe510 408 template <class E> Matrix& M_add_eq(const XprMatrix<E, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 409 template <class E> Matrix& M_sub_eq(const XprMatrix<E, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 410 template <class E> Matrix& M_mul_eq(const XprMatrix<E, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 411 template <class E> Matrix& M_div_eq(const XprMatrix<E, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 412 template <class E> Matrix& M_mod_eq(const XprMatrix<E, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 413 template <class E> Matrix& M_xor_eq(const XprMatrix<E, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 414 template <class E> Matrix& M_and_eq(const XprMatrix<E, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 415 template <class E> Matrix& M_or_eq (const XprMatrix<E, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 416 template <class E> Matrix& M_shl_eq(const XprMatrix<E, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 417 template <class E> Matrix& M_shr_eq(const XprMatrix<E, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 418
sv 1:6799c07fe510 419 public: // aliased math operators with expressions
sv 1:6799c07fe510 420 template <class T2> Matrix& alias_assign(const Matrix<T2, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 421 template <class T2> Matrix& alias_add_eq(const Matrix<T2, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 422 template <class T2> Matrix& alias_sub_eq(const Matrix<T2, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 423 template <class T2> Matrix& alias_mul_eq(const Matrix<T2, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 424 template <class T2> Matrix& alias_div_eq(const Matrix<T2, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 425
sv 1:6799c07fe510 426 template <class E> Matrix& alias_assign(const XprMatrix<E, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 427 template <class E> Matrix& alias_add_eq(const XprMatrix<E, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 428 template <class E> Matrix& alias_sub_eq(const XprMatrix<E, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 429 template <class E> Matrix& alias_mul_eq(const XprMatrix<E, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 430 template <class E> Matrix& alias_div_eq(const XprMatrix<E, Rows, Cols>&) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 431
sv 1:6799c07fe510 432 public: // io
sv 1:6799c07fe510 433 /** Structure for info printing as Matrix<T, Rows, Cols>. */
sv 1:6799c07fe510 434 struct Info : public TvmetBase<Info> {
sv 1:6799c07fe510 435 std::ostream& print_xpr(std::ostream& os) const {
sv 1:6799c07fe510 436 os << "Matrix<T=" << typeid(value_type).name()
sv 1:6799c07fe510 437 << ", R=" << Rows << ", C=" << Cols << ">";
sv 1:6799c07fe510 438 return os;
sv 1:6799c07fe510 439 }
sv 1:6799c07fe510 440 };
sv 1:6799c07fe510 441
sv 1:6799c07fe510 442 /** Get an info object of this matrix. */
sv 1:6799c07fe510 443 static Info info() { return Info(); }
sv 1:6799c07fe510 444
sv 1:6799c07fe510 445 /** Member function for expression level printing. */
sv 1:6799c07fe510 446 std::ostream& print_xpr(std::ostream& os, std::size_t l=0) const;
sv 1:6799c07fe510 447
sv 1:6799c07fe510 448 /** Member function for printing internal data. */
sv 1:6799c07fe510 449 std::ostream& print_on(std::ostream& os) const;
sv 1:6799c07fe510 450
sv 1:6799c07fe510 451 private:
sv 1:6799c07fe510 452 /** The data of matrix self. */
sv 1:6799c07fe510 453 #if defined(TVMET_DYNAMIC_MEMORY)
sv 1:6799c07fe510 454 value_type* m_data;
sv 1:6799c07fe510 455 #else
sv 1:6799c07fe510 456 value_type m_data[Size];
sv 1:6799c07fe510 457 #endif
sv 1:6799c07fe510 458 };
sv 1:6799c07fe510 459
sv 1:6799c07fe510 460
sv 1:6799c07fe510 461 } // namespace tvmet
sv 1:6799c07fe510 462
sv 1:6799c07fe510 463 #include <tvmet/MatrixImpl.h>
sv 1:6799c07fe510 464 #include <tvmet/MatrixFunctions.h>
sv 1:6799c07fe510 465 #include <tvmet/MatrixBinaryFunctions.h>
sv 1:6799c07fe510 466 #include <tvmet/MatrixUnaryFunctions.h>
sv 1:6799c07fe510 467 #include <tvmet/MatrixOperators.h>
sv 1:6799c07fe510 468 #include <tvmet/MatrixEval.h>
sv 1:6799c07fe510 469 #include <tvmet/AliasProxy.h>
sv 1:6799c07fe510 470
sv 1:6799c07fe510 471 #endif // TVMET_MATRIX_H
sv 1:6799c07fe510 472
sv 1:6799c07fe510 473 // Local Variables:
sv 1:6799c07fe510 474 // mode:C++
sv 1:6799c07fe510 475 // tab-width:8
sv 1:6799c07fe510 476 // End: