Oskar Weigl
/
Eurobot2013
We are going to win! wohoo
tvmet/meta/Matrix.h@9:08552997b544, 2012-11-14 (annotated)
- 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?
User | Revision | Line number | New 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.19 2007-06-23 15:58:59 opetzold Exp $ |
sv | 1:6799c07fe510 | 22 | */ |
sv | 1:6799c07fe510 | 23 | |
sv | 1:6799c07fe510 | 24 | #ifndef TVMET_META_MATRIX_H |
sv | 1:6799c07fe510 | 25 | #define TVMET_META_MATRIX_H |
sv | 1:6799c07fe510 | 26 | |
sv | 1:6799c07fe510 | 27 | #include <tvmet/NumericTraits.h> |
sv | 1:6799c07fe510 | 28 | #include <tvmet/xpr/Null.h> |
sv | 1:6799c07fe510 | 29 | |
sv | 1:6799c07fe510 | 30 | namespace tvmet { |
sv | 1:6799c07fe510 | 31 | |
sv | 1:6799c07fe510 | 32 | namespace meta { |
sv | 1:6799c07fe510 | 33 | |
sv | 1:6799c07fe510 | 34 | |
sv | 1:6799c07fe510 | 35 | /** |
sv | 1:6799c07fe510 | 36 | * \class Matrix Matrix.h "tvmet/meta/Matrix.h" |
sv | 1:6799c07fe510 | 37 | * \brief Meta %Matrix class using expression and meta templates. |
sv | 1:6799c07fe510 | 38 | */ |
sv | 1:6799c07fe510 | 39 | template<std::size_t Rows, std::size_t Cols, |
sv | 1:6799c07fe510 | 40 | std::size_t M=0, std::size_t N=0> |
sv | 1:6799c07fe510 | 41 | class Matrix |
sv | 1:6799c07fe510 | 42 | { |
sv | 1:6799c07fe510 | 43 | Matrix(); |
sv | 1:6799c07fe510 | 44 | Matrix(const Matrix&); |
sv | 1:6799c07fe510 | 45 | Matrix& operator=(const Matrix&); |
sv | 1:6799c07fe510 | 46 | |
sv | 1:6799c07fe510 | 47 | private: |
sv | 1:6799c07fe510 | 48 | enum { |
sv | 1:6799c07fe510 | 49 | doRows = (M < Rows - 1) ? 1 : 0, /**< recursive counter Rows. */ |
sv | 1:6799c07fe510 | 50 | doCols = (N < Cols - 1) ? 1 : 0 /**< recursive counter Cols. */ |
sv | 1:6799c07fe510 | 51 | }; |
sv | 1:6799c07fe510 | 52 | |
sv | 1:6799c07fe510 | 53 | public: |
sv | 1:6799c07fe510 | 54 | /** assign an expression on columns on given row using the functional assign_fn. */ |
sv | 1:6799c07fe510 | 55 | template<class Dest, class Src, class Assign> |
sv | 1:6799c07fe510 | 56 | static inline |
sv | 1:6799c07fe510 | 57 | void assign2(Dest& lhs, const Src& rhs, const Assign& assign_fn) { |
sv | 1:6799c07fe510 | 58 | assign_fn.apply_on(lhs(M, N), rhs(M, N)); |
sv | 1:6799c07fe510 | 59 | Matrix<Rows * doCols, Cols * doCols, |
sv | 1:6799c07fe510 | 60 | M * doCols, (N+1) * doCols>::assign2(lhs, rhs, assign_fn); |
sv | 1:6799c07fe510 | 61 | } |
sv | 1:6799c07fe510 | 62 | |
sv | 1:6799c07fe510 | 63 | /** assign an expression on row-wise using the functional assign_fn. */ |
sv | 1:6799c07fe510 | 64 | template<class Dest, class Src, class Assign> |
sv | 1:6799c07fe510 | 65 | static inline |
sv | 1:6799c07fe510 | 66 | void assign(Dest& lhs, const Src& rhs, const Assign& assign_fn) { |
sv | 1:6799c07fe510 | 67 | Matrix<Rows, Cols, |
sv | 1:6799c07fe510 | 68 | M, 0>::assign2(lhs, rhs, assign_fn); |
sv | 1:6799c07fe510 | 69 | Matrix<Rows * doRows, Cols * doRows, |
sv | 1:6799c07fe510 | 70 | (M+1) * doRows, 0>::assign(lhs, rhs, assign_fn); |
sv | 1:6799c07fe510 | 71 | } |
sv | 1:6799c07fe510 | 72 | |
sv | 1:6799c07fe510 | 73 | /** evaluate a given matrix expression, column wise. */ |
sv | 1:6799c07fe510 | 74 | template<class E> |
sv | 1:6799c07fe510 | 75 | static inline |
sv | 1:6799c07fe510 | 76 | bool all_elements2(const E& e) { |
sv | 1:6799c07fe510 | 77 | if(!e(M, N)) return false; |
sv | 1:6799c07fe510 | 78 | return Matrix<Rows * doCols, Cols * doCols, |
sv | 1:6799c07fe510 | 79 | M * doCols, (N+1) * doCols>::all_elements2(e); |
sv | 1:6799c07fe510 | 80 | } |
sv | 1:6799c07fe510 | 81 | |
sv | 1:6799c07fe510 | 82 | /** evaluate a given matrix expression, row wise. */ |
sv | 1:6799c07fe510 | 83 | template<class E> |
sv | 1:6799c07fe510 | 84 | static inline |
sv | 1:6799c07fe510 | 85 | bool all_elements(const E& e) { |
sv | 1:6799c07fe510 | 86 | if(!Matrix<Rows, Cols, M, 0>::all_elements2(e) ) return false; |
sv | 1:6799c07fe510 | 87 | return Matrix<Rows * doRows, Cols * doRows, |
sv | 1:6799c07fe510 | 88 | (M+1) * doRows, 0>::all_elements(e); |
sv | 1:6799c07fe510 | 89 | } |
sv | 1:6799c07fe510 | 90 | |
sv | 1:6799c07fe510 | 91 | /** evaluate a given matrix expression, column wise. */ |
sv | 1:6799c07fe510 | 92 | template<class E> |
sv | 1:6799c07fe510 | 93 | static inline |
sv | 1:6799c07fe510 | 94 | bool any_elements2(const E& e) { |
sv | 1:6799c07fe510 | 95 | if(e(M, N)) return true; |
sv | 1:6799c07fe510 | 96 | return Matrix<Rows * doCols, Cols * doCols, |
sv | 1:6799c07fe510 | 97 | M * doCols, (N+1) * doCols>::any_elements2(e); |
sv | 1:6799c07fe510 | 98 | } |
sv | 1:6799c07fe510 | 99 | |
sv | 1:6799c07fe510 | 100 | /** evaluate a given matrix expression, row wise. */ |
sv | 1:6799c07fe510 | 101 | template<class E> |
sv | 1:6799c07fe510 | 102 | static inline |
sv | 1:6799c07fe510 | 103 | bool any_elements(const E& e) { |
sv | 1:6799c07fe510 | 104 | if(Matrix<Rows, Cols, M, 0>::any_elements2(e) ) return true; |
sv | 1:6799c07fe510 | 105 | return Matrix<Rows * doRows, Cols * doRows, |
sv | 1:6799c07fe510 | 106 | (M+1) * doRows, 0>::any_elements(e); |
sv | 1:6799c07fe510 | 107 | } |
sv | 1:6799c07fe510 | 108 | |
sv | 1:6799c07fe510 | 109 | /** trace a given matrix expression. */ |
sv | 1:6799c07fe510 | 110 | template<class E> |
sv | 1:6799c07fe510 | 111 | static inline |
sv | 1:6799c07fe510 | 112 | typename E::value_type |
sv | 1:6799c07fe510 | 113 | trace(const E& e) { |
sv | 1:6799c07fe510 | 114 | return e(M, N) |
sv | 1:6799c07fe510 | 115 | + Matrix<Rows * doCols, Cols * doCols, |
sv | 1:6799c07fe510 | 116 | (M+1) * doCols, (N+1) * doCols>::trace(e); |
sv | 1:6799c07fe510 | 117 | } |
sv | 1:6799c07fe510 | 118 | |
sv | 1:6799c07fe510 | 119 | }; |
sv | 1:6799c07fe510 | 120 | |
sv | 1:6799c07fe510 | 121 | |
sv | 1:6799c07fe510 | 122 | /** |
sv | 1:6799c07fe510 | 123 | * \class Matrix<0, 0, 0, 0> Matrix.h "tvmet/meta/Matrix.h" |
sv | 1:6799c07fe510 | 124 | * \brief Meta %Matrix specialized for recursion. |
sv | 1:6799c07fe510 | 125 | */ |
sv | 1:6799c07fe510 | 126 | template<> |
sv | 1:6799c07fe510 | 127 | class Matrix<0, 0, 0, 0> |
sv | 1:6799c07fe510 | 128 | { |
sv | 1:6799c07fe510 | 129 | Matrix(); |
sv | 1:6799c07fe510 | 130 | Matrix(const Matrix&); |
sv | 1:6799c07fe510 | 131 | Matrix& operator=(const Matrix&); |
sv | 1:6799c07fe510 | 132 | |
sv | 1:6799c07fe510 | 133 | public: |
sv | 1:6799c07fe510 | 134 | template<class Dest, class Src, class Assign> |
sv | 1:6799c07fe510 | 135 | static inline void assign2(Dest&, const Src&, const Assign&) { } |
sv | 1:6799c07fe510 | 136 | |
sv | 1:6799c07fe510 | 137 | template<class Dest, class Src, class Assign> |
sv | 1:6799c07fe510 | 138 | static inline void assign(Dest&, const Src&, const Assign&) { } |
sv | 1:6799c07fe510 | 139 | |
sv | 1:6799c07fe510 | 140 | template<class E> |
sv | 1:6799c07fe510 | 141 | static inline bool all_elements2(const E&) { return true; } |
sv | 1:6799c07fe510 | 142 | |
sv | 1:6799c07fe510 | 143 | template<class E> |
sv | 1:6799c07fe510 | 144 | static inline bool all_elements(const E&) { return true; } |
sv | 1:6799c07fe510 | 145 | |
sv | 1:6799c07fe510 | 146 | template<class E> |
sv | 1:6799c07fe510 | 147 | static inline bool any_elements2(const E&) { return false; } |
sv | 1:6799c07fe510 | 148 | |
sv | 1:6799c07fe510 | 149 | template<class E> |
sv | 1:6799c07fe510 | 150 | static inline bool any_elements(const E&) { return false; } |
sv | 1:6799c07fe510 | 151 | |
sv | 1:6799c07fe510 | 152 | template<class E> |
sv | 1:6799c07fe510 | 153 | static inline XprNull trace(const E&) { return XprNull(); } |
sv | 1:6799c07fe510 | 154 | }; |
sv | 1:6799c07fe510 | 155 | |
sv | 1:6799c07fe510 | 156 | |
sv | 1:6799c07fe510 | 157 | } // namespace meta |
sv | 1:6799c07fe510 | 158 | |
sv | 1:6799c07fe510 | 159 | } // namespace tvmet |
sv | 1:6799c07fe510 | 160 | |
sv | 1:6799c07fe510 | 161 | #endif /* TVMET_META_MATRIX_H */ |
sv | 1:6799c07fe510 | 162 | |
sv | 1:6799c07fe510 | 163 | // Local Variables: |
sv | 1:6799c07fe510 | 164 | // mode:C++ |
sv | 1:6799c07fe510 | 165 | // tab-width:8 |
sv | 1:6799c07fe510 | 166 | // End: |