Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Eurobot_2012_Secondary by
MtVProduct.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: MtVProduct.h,v 1.14 2007-06-23 15:59:00 opetzold Exp $ 00022 */ 00023 00024 #ifndef TVMET_XPR_MTVPRODUCT_H 00025 #define TVMET_XPR_MTVPRODUCT_H 00026 00027 #include <tvmet/meta/Gemtv.h> 00028 #include <tvmet/loop/Gemtv.h> 00029 00030 namespace tvmet { 00031 00032 00033 /** 00034 * \class XprMtVProduct MtVProduct.h "tvmet/xpr/MtVProduct.h" 00035 * \brief Expression for matrix-transposed vector product 00036 * using formula 00037 * \f[ 00038 * M^T\,v 00039 * \f] 00040 */ 00041 template<class E1, std::size_t Rows, std::size_t Cols, 00042 class E2> 00043 class XprMtVProduct 00044 : public TvmetBase< XprMtVProduct<E1, Rows, Cols, E2> > 00045 { 00046 XprMtVProduct(); 00047 XprMtVProduct& operator=(const XprMtVProduct&); 00048 00049 public: 00050 typedef typename PromoteTraits< 00051 typename E1::value_type, 00052 typename E2::value_type 00053 >::value_type value_type; 00054 00055 public: 00056 /** Complexity counter. */ 00057 enum { 00058 ops_lhs = E1::ops, 00059 ops_rhs = E2::ops, 00060 M = Cols * Rows, 00061 N = Cols * (Rows - 1), 00062 ops_plus = M * NumericTraits<value_type>::ops_plus, 00063 ops_muls = N * NumericTraits<value_type>::ops_muls, 00064 ops = ops_plus + ops_muls, 00065 use_meta = Rows*Cols < TVMET_COMPLEXITY_MV_TRIGGER ? true : false 00066 }; 00067 00068 public: 00069 /** Constructor. */ 00070 explicit XprMtVProduct(const E1& lhs, const E2& rhs) 00071 : m_lhs(lhs), m_rhs(rhs) 00072 { } 00073 00074 /** Copy Constructor. Not explicit! */ 00075 #if defined(TVMET_OPTIMIZE_XPR_MANUAL_CCTOR) 00076 XprMtVProduct(const XprMtVProduct& e) 00077 : m_lhs(e.m_lhs), m_rhs(e.m_rhs) 00078 { } 00079 #endif 00080 00081 private: 00082 /** Wrapper for meta gemm. */ 00083 static inline 00084 value_type do_gemtv(dispatch<true>, const E1& lhs, const E2& rhs, std::size_t i) { 00085 return meta::gemtv<Rows, Cols, 0>::prod(lhs, rhs, i); 00086 } 00087 00088 /** Wrapper for loop gemm. */ 00089 static inline 00090 value_type do_gemtv(dispatch<false>, const E1& lhs, const E2& rhs, std::size_t i) { 00091 return loop::gemtv<Rows, Cols>::prod(lhs, rhs, i); 00092 } 00093 00094 public: 00095 /** index operator, returns the expression by index. This is the vector 00096 style since a matrix*vector gives a vector. */ 00097 value_type operator()(std::size_t j) const { 00098 TVMET_RT_CONDITION(j < Cols , "XprMtVProduct Bounce Violation") 00099 return do_gemtv(dispatch<use_meta>(), m_lhs, m_rhs, j); 00100 } 00101 00102 public: // debugging Xpr parse tree 00103 void print_xpr(std::ostream& os, std::size_t l=0) const { 00104 os << IndentLevel(l++) 00105 << "XprMtVProduct[O=" << ops << ", (O1=" << ops_lhs << ", O2=" << ops_rhs << ")]<" 00106 << std::endl; 00107 m_lhs.print_xpr(os, l); 00108 os << IndentLevel(l) 00109 << "R=" << Rows << ", C=" << Cols << ",\n"; 00110 m_rhs.print_xpr(os, l); 00111 os << IndentLevel(--l) 00112 << ">," << std::endl; 00113 } 00114 00115 private: 00116 const E1 m_lhs; 00117 const E2 m_rhs; 00118 }; 00119 00120 00121 } // namespace tvmet 00122 00123 #endif // TVMET_XPR_MTVPRODUCT_H 00124 00125 // Local Variables: 00126 // mode:C++ 00127 // tab-width:8 00128 // End:
Generated on Tue Jul 12 2022 21:02:13 by
