This is the Tiny Vector Matrix Expression Templates library found at http://tvmet.sourceforge.net. It is the fastest and most compact matrix lib out there (for < 10x10 matricies). I have done some minor tweaks to make it compile for mbed. For examples and hints on how to use, see: http://tvmet.sourceforge.net/usage.html
Dependents: Eurobot_2012_Secondary
Eval.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: Eval.h,v 1.13 2007-06-23 15:58:59 opetzold Exp $ 00022 */ 00023 00024 #ifndef TVMET_XPR_EVAL_H 00025 #define TVMET_XPR_EVAL_H 00026 00027 namespace tvmet { 00028 00029 00030 /** 00031 * \class XprEval Eval.h "tvmet/xpr/Eval.h" 00032 * \brief evaluate the expression 00033 * 00034 * Since we can't overwrite the ? operator we have to write a wrapper 00035 * for expression like return v1>v2 ? true : false 00036 */ 00037 template<class E1, class E2, class E3> 00038 class XprEval 00039 : public TvmetBase< XprEval<E1, E2, E3> > 00040 { 00041 public: 00042 typedef E1 expr1_type; 00043 typedef E2 expr2_type; 00044 typedef E3 expr3_type; 00045 00046 typedef typename expr2_type::value_type value2_type; 00047 typedef typename expr3_type::value_type value3_type; 00048 00049 typedef typename 00050 PromoteTraits<value2_type, value3_type>::value_type value_type; 00051 00052 public: 00053 /** Complexity Counter */ 00054 enum { 00055 ops_expr1 = E1::ops, 00056 ops_expr2 = E2::ops, 00057 ops_expr3 = E3::ops, 00058 ops = ops_expr1 // only (e1 op e2) are evaluated 00059 }; 00060 00061 private: 00062 XprEval(); 00063 XprEval& operator=(const XprEval<expr1_type, expr2_type, expr3_type>&); 00064 00065 public: 00066 /** Constructor */ 00067 explicit XprEval(const expr1_type& e1, const expr2_type& e2, const expr3_type& e3) 00068 : m_expr1(e1), m_expr2(e2), m_expr3(e3) 00069 { } 00070 00071 /** Copy Constructor. Not explicit! */ 00072 #if defined(TVMET_OPTIMIZE_XPR_MANUAL_CCTOR) 00073 XprEval(const XprEval& rhs) 00074 : m_expr1(rhs.m_expr1), m_expr2(rhs.m_expr2), m_expr3(rhs.m_expr3) 00075 { } 00076 #endif 00077 00078 public: //access 00079 /** index operator for vectors. */ 00080 value_type operator()(std::size_t i) const { 00081 return m_expr1(i) ? m_expr2(i) : m_expr3(i); 00082 } 00083 00084 /** index operator for matrizes. */ 00085 value_type operator()(std::size_t i, std::size_t j) const { 00086 return m_expr1(i, j) ? m_expr2(i, j) : m_expr3(i, j); 00087 } 00088 00089 public: // debugging Xpr parse tree 00090 void print_xpr(std::ostream& os, std::size_t l=0) const { 00091 os << IndentLevel(l++) 00092 << "XprEval[" << ops << ", (" 00093 << ops_expr1 << ", " << ops_expr2 << ", " << ops_expr3 << ")]<" 00094 << std::endl; 00095 m_expr1.print_xpr(os, l); 00096 m_expr2.print_xpr(os, l); 00097 m_expr3.print_xpr(os, l); 00098 os << IndentLevel(--l) 00099 << ">," << std::endl; 00100 } 00101 00102 private: 00103 const expr1_type m_expr1; 00104 const expr2_type m_expr2; 00105 const expr3_type m_expr3; 00106 }; 00107 00108 00109 } // namespace tvmet 00110 00111 #endif // TVMET_XPR_EVAL_H 00112 00113 // Local Variables: 00114 // mode:C++ 00115 // tab-width:8 00116 // End:
Generated on Tue Jul 12 2022 19:00:11 by 1.7.2