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
BinOperator.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: BinOperator.h,v 1.19 2007-06-23 15:58:59 opetzold Exp $ 00022 */ 00023 00024 #ifndef TVMET_XPR_BINOPERATOR_H 00025 #define TVMET_XPR_BINOPERATOR_H 00026 00027 #include <tvmet/TypePromotion.h> 00028 00029 namespace tvmet { 00030 00031 00032 /** 00033 * \class XprBinOp BinOperator.h "tvmet/xpr/BinOperator.h" 00034 * \brief Binary operators working on two sub expressions. 00035 * 00036 * On acessing using the index operator() the binary operation will be 00037 * evaluated at compile time. 00038 */ 00039 template<class BinOp, class E1, class E2> 00040 class XprBinOp 00041 : public TvmetBase< XprBinOp<BinOp, E1, E2> > 00042 { 00043 XprBinOp(); 00044 XprBinOp& operator=(const XprBinOp&); 00045 00046 public: 00047 typedef typename BinOp::value_type value_type; 00048 00049 public: 00050 /** Complexity counter. */ 00051 enum { 00052 ops_lhs = E1::ops, 00053 ops_rhs = E2::ops, 00054 ops = 2 * (ops_lhs + ops_rhs) // lhs op rhs 00055 }; 00056 00057 public: 00058 /** Constructor for two expressions. */ 00059 explicit XprBinOp(const E1& lhs, const E2& rhs) 00060 : m_lhs(lhs), m_rhs(rhs) 00061 { } 00062 00063 /** Copy Constructor. Not explicit! */ 00064 #if defined(TVMET_OPTIMIZE_XPR_MANUAL_CCTOR) 00065 XprBinOp(const XprBinOp& e) 00066 : m_lhs(e.m_lhs), m_rhs(e.m_rhs) 00067 { } 00068 #endif 00069 00070 /** Index operator, evaluates the expression inside. */ 00071 value_type operator()(std::size_t i) const { 00072 return BinOp::apply_on(m_lhs(i), m_rhs(i)); 00073 } 00074 00075 /** Index operator for arrays/matrices */ 00076 value_type operator()(std::size_t i, std::size_t j) const { 00077 return BinOp::apply_on(m_lhs(i, j), m_rhs(i, j)); 00078 } 00079 00080 public: // debugging Xpr parse tree 00081 void print_xpr(std::ostream& os, std::size_t l=0) const { 00082 os << IndentLevel(l++) 00083 << "XprBinOp[O="<< ops << ", (O1=" << ops_lhs << ", O2=" << ops_rhs << ")]<" 00084 << std::endl; 00085 BinOp::print_xpr(os, l); 00086 m_lhs.print_xpr(os, l); 00087 m_rhs.print_xpr(os, l); 00088 os << IndentLevel(--l) 00089 << ">," << std::endl; 00090 } 00091 00092 private: 00093 const E1 m_lhs; 00094 const E2 m_rhs; 00095 }; 00096 00097 00098 } // namespace tvmet 00099 00100 #endif // TVMET_XPR_BINOPERATOR_H 00101 00102 // Local Variables: 00103 // mode:C++ 00104 // tab-width:8 00105 // End:
Generated on Tue Jul 12 2022 19:00:11 by 1.7.2