ICRS Eurobot 2013
Dependencies: mbed mbed-rtos Servo QEI
Matrix.h
00001 /* 00002 * Tiny Vector Matrix Library 00003 * Dense Vector Matrix Libary of Tiny size using Expression Templates 00004 * 00005 * Copyright (C) 2001 - 2007 Olaf Petzold <opetzold@users.sourceforge.net> 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 * 00021 * $Id: Matrix.h,v 1.19 2007-06-23 15:58:59 opetzold Exp $ 00022 */ 00023 00024 #ifndef TVMET_META_MATRIX_H 00025 #define TVMET_META_MATRIX_H 00026 00027 #include <tvmet/NumericTraits.h> 00028 #include <tvmet/xpr/Null.h> 00029 00030 namespace tvmet { 00031 00032 namespace meta { 00033 00034 00035 /** 00036 * \class Matrix Matrix.h "tvmet/meta/Matrix.h" 00037 * \brief Meta %Matrix class using expression and meta templates. 00038 */ 00039 template<std::size_t Rows, std::size_t Cols, 00040 std::size_t M=0, std::size_t N=0> 00041 class Matrix 00042 { 00043 Matrix(); 00044 Matrix(const Matrix&); 00045 Matrix& operator=(const Matrix&); 00046 00047 private: 00048 enum { 00049 doRows = (M < Rows - 1) ? 1 : 0, /**< recursive counter Rows. */ 00050 doCols = (N < Cols - 1) ? 1 : 0 /**< recursive counter Cols. */ 00051 }; 00052 00053 public: 00054 /** assign an expression on columns on given row using the functional assign_fn. */ 00055 template<class Dest, class Src, class Assign> 00056 static inline 00057 void assign2(Dest& lhs, const Src& rhs, const Assign& assign_fn) { 00058 assign_fn.apply_on(lhs(M, N), rhs(M, N)); 00059 Matrix<Rows * doCols, Cols * doCols, 00060 M * doCols, (N+1) * doCols>::assign2(lhs, rhs, assign_fn); 00061 } 00062 00063 /** assign an expression on row-wise using the functional assign_fn. */ 00064 template<class Dest, class Src, class Assign> 00065 static inline 00066 void assign(Dest& lhs, const Src& rhs, const Assign& assign_fn) { 00067 Matrix<Rows, Cols, 00068 M, 0>::assign2(lhs, rhs, assign_fn); 00069 Matrix<Rows * doRows, Cols * doRows, 00070 (M+1) * doRows, 0>::assign(lhs, rhs, assign_fn); 00071 } 00072 00073 /** evaluate a given matrix expression, column wise. */ 00074 template<class E> 00075 static inline 00076 bool all_elements2(const E& e) { 00077 if(!e(M, N)) return false; 00078 return Matrix<Rows * doCols, Cols * doCols, 00079 M * doCols, (N+1) * doCols>::all_elements2(e); 00080 } 00081 00082 /** evaluate a given matrix expression, row wise. */ 00083 template<class E> 00084 static inline 00085 bool all_elements(const E& e) { 00086 if(!Matrix<Rows, Cols, M, 0>::all_elements2(e) ) return false; 00087 return Matrix<Rows * doRows, Cols * doRows, 00088 (M+1) * doRows, 0>::all_elements(e); 00089 } 00090 00091 /** evaluate a given matrix expression, column wise. */ 00092 template<class E> 00093 static inline 00094 bool any_elements2(const E& e) { 00095 if(e(M, N)) return true; 00096 return Matrix<Rows * doCols, Cols * doCols, 00097 M * doCols, (N+1) * doCols>::any_elements2(e); 00098 } 00099 00100 /** evaluate a given matrix expression, row wise. */ 00101 template<class E> 00102 static inline 00103 bool any_elements(const E& e) { 00104 if(Matrix<Rows, Cols, M, 0>::any_elements2(e) ) return true; 00105 return Matrix<Rows * doRows, Cols * doRows, 00106 (M+1) * doRows, 0>::any_elements(e); 00107 } 00108 00109 /** trace a given matrix expression. */ 00110 template<class E> 00111 static inline 00112 typename E::value_type 00113 trace(const E& e) { 00114 return e(M, N) 00115 + Matrix<Rows * doCols, Cols * doCols, 00116 (M+1) * doCols, (N+1) * doCols>::trace(e); 00117 } 00118 00119 }; 00120 00121 00122 /** 00123 * \class Matrix<0, 0, 0, 0> Matrix.h "tvmet/meta/Matrix.h" 00124 * \brief Meta %Matrix specialized for recursion. 00125 */ 00126 template<> 00127 class Matrix<0, 0, 0, 0> 00128 { 00129 Matrix(); 00130 Matrix(const Matrix&); 00131 Matrix& operator=(const Matrix&); 00132 00133 public: 00134 template<class Dest, class Src, class Assign> 00135 static inline void assign2(Dest&, const Src&, const Assign&) { } 00136 00137 template<class Dest, class Src, class Assign> 00138 static inline void assign(Dest&, const Src&, const Assign&) { } 00139 00140 template<class E> 00141 static inline bool all_elements2(const E&) { return true; } 00142 00143 template<class E> 00144 static inline bool all_elements(const E&) { return true; } 00145 00146 template<class E> 00147 static inline bool any_elements2(const E&) { return false; } 00148 00149 template<class E> 00150 static inline bool any_elements(const E&) { return false; } 00151 00152 template<class E> 00153 static inline XprNull trace(const E&) { return XprNull(); } 00154 }; 00155 00156 00157 } // namespace meta 00158 00159 } // namespace tvmet 00160 00161 #endif /* TVMET_META_MATRIX_H */ 00162 00163 // Local Variables: 00164 // mode:C++ 00165 // tab-width:8 00166 // End:
Generated on Wed Jul 13 2022 18:28:36 by 1.7.2