![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
This is some awesome robot code
Dependencies: mbed-rtos mbed QEI
Fork of ICRSEurobot13 by
tvmet/xpr/MMProductTransposed.h@90:e4164bb8c60e, 2013-04-17 (annotated)
- Committer:
- madcowswe
- Date:
- Wed Apr 17 23:16:25 2013 +0000
- Revision:
- 90:e4164bb8c60e
- Parent:
- 15:9c5aaeda36dc
final state at end of competition. Includes avoid wooden team hack
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
madcowswe | 15:9c5aaeda36dc | 1 | /* |
madcowswe | 15:9c5aaeda36dc | 2 | * Tiny Vector Matrix Library |
madcowswe | 15:9c5aaeda36dc | 3 | * Dense Vector Matrix Libary of Tiny size using Expression Templates |
madcowswe | 15:9c5aaeda36dc | 4 | * |
madcowswe | 15:9c5aaeda36dc | 5 | * Copyright (C) 2001 - 2007 Olaf Petzold <opetzold@users.sourceforge.net> |
madcowswe | 15:9c5aaeda36dc | 6 | * |
madcowswe | 15:9c5aaeda36dc | 7 | * This library is free software; you can redistribute it and/or |
madcowswe | 15:9c5aaeda36dc | 8 | * modify it under the terms of the GNU Lesser General Public |
madcowswe | 15:9c5aaeda36dc | 9 | * License as published by the Free Software Foundation; either |
madcowswe | 15:9c5aaeda36dc | 10 | * version 2.1 of the License, or (at your option) any later version. |
madcowswe | 15:9c5aaeda36dc | 11 | * |
madcowswe | 15:9c5aaeda36dc | 12 | * This library is distributed in the hope that it will be useful, |
madcowswe | 15:9c5aaeda36dc | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
madcowswe | 15:9c5aaeda36dc | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
madcowswe | 15:9c5aaeda36dc | 15 | * Lesser General Public License for more details. |
madcowswe | 15:9c5aaeda36dc | 16 | * |
madcowswe | 15:9c5aaeda36dc | 17 | * You should have received a copy of the GNU Lesser General Public |
madcowswe | 15:9c5aaeda36dc | 18 | * License along with this library; if not, write to the Free Software |
madcowswe | 15:9c5aaeda36dc | 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
madcowswe | 15:9c5aaeda36dc | 20 | * |
madcowswe | 15:9c5aaeda36dc | 21 | * $Id: MMProductTransposed.h,v 1.20 2007-06-23 15:58:59 opetzold Exp $ |
madcowswe | 15:9c5aaeda36dc | 22 | */ |
madcowswe | 15:9c5aaeda36dc | 23 | |
madcowswe | 15:9c5aaeda36dc | 24 | #ifndef TVMET_XPR_MMPRODUCT_TRANSPOSED_H |
madcowswe | 15:9c5aaeda36dc | 25 | #define TVMET_XPR_MMPRODUCT_TRANSPOSED_H |
madcowswe | 15:9c5aaeda36dc | 26 | |
madcowswe | 15:9c5aaeda36dc | 27 | #include <tvmet/meta/Gemm.h> |
madcowswe | 15:9c5aaeda36dc | 28 | #include <tvmet/loop/Gemm.h> |
madcowswe | 15:9c5aaeda36dc | 29 | |
madcowswe | 15:9c5aaeda36dc | 30 | namespace tvmet { |
madcowswe | 15:9c5aaeda36dc | 31 | |
madcowswe | 15:9c5aaeda36dc | 32 | |
madcowswe | 15:9c5aaeda36dc | 33 | /** |
madcowswe | 15:9c5aaeda36dc | 34 | * \class XprMMProductTransposed MMProductTransposed.h "tvmet/xpr/MMProductTransposed.h" |
madcowswe | 15:9c5aaeda36dc | 35 | * \brief Expression for transpose(matrix-matrix product). |
madcowswe | 15:9c5aaeda36dc | 36 | * Using formula: |
madcowswe | 15:9c5aaeda36dc | 37 | * \f[ |
madcowswe | 15:9c5aaeda36dc | 38 | * (M_1\,M_2)^T |
madcowswe | 15:9c5aaeda36dc | 39 | * \f] |
madcowswe | 15:9c5aaeda36dc | 40 | * \note The Rows2 has to be equal to Cols1. |
madcowswe | 15:9c5aaeda36dc | 41 | * The result is a (Cols2 x Rows1) matrix. |
madcowswe | 15:9c5aaeda36dc | 42 | */ |
madcowswe | 15:9c5aaeda36dc | 43 | template<class E1, std::size_t Rows1, std::size_t Cols1, |
madcowswe | 15:9c5aaeda36dc | 44 | class E2, std::size_t Cols2> |
madcowswe | 15:9c5aaeda36dc | 45 | class XprMMProductTransposed |
madcowswe | 15:9c5aaeda36dc | 46 | : public TvmetBase< XprMMProductTransposed<E1, Rows1, Cols1, E2, Cols2> > |
madcowswe | 15:9c5aaeda36dc | 47 | { |
madcowswe | 15:9c5aaeda36dc | 48 | private: |
madcowswe | 15:9c5aaeda36dc | 49 | XprMMProductTransposed(); |
madcowswe | 15:9c5aaeda36dc | 50 | XprMMProductTransposed& operator=(const XprMMProductTransposed&); |
madcowswe | 15:9c5aaeda36dc | 51 | |
madcowswe | 15:9c5aaeda36dc | 52 | public: |
madcowswe | 15:9c5aaeda36dc | 53 | typedef typename PromoteTraits< |
madcowswe | 15:9c5aaeda36dc | 54 | typename E1::value_type, |
madcowswe | 15:9c5aaeda36dc | 55 | typename E2::value_type |
madcowswe | 15:9c5aaeda36dc | 56 | >::value_type value_type; |
madcowswe | 15:9c5aaeda36dc | 57 | |
madcowswe | 15:9c5aaeda36dc | 58 | public: |
madcowswe | 15:9c5aaeda36dc | 59 | /** Complexity counter. */ |
madcowswe | 15:9c5aaeda36dc | 60 | enum { |
madcowswe | 15:9c5aaeda36dc | 61 | ops_lhs = E1::ops, |
madcowswe | 15:9c5aaeda36dc | 62 | ops_rhs = E2::ops, |
madcowswe | 15:9c5aaeda36dc | 63 | M = Rows1 * Cols1 * Cols2, |
madcowswe | 15:9c5aaeda36dc | 64 | N = Rows1 * (Cols1-1) * Cols2, |
madcowswe | 15:9c5aaeda36dc | 65 | ops_plus = M * NumericTraits<value_type>::ops_plus, |
madcowswe | 15:9c5aaeda36dc | 66 | ops_muls = N * NumericTraits<value_type>::ops_muls, |
madcowswe | 15:9c5aaeda36dc | 67 | ops = ops_plus + ops_muls, |
madcowswe | 15:9c5aaeda36dc | 68 | use_meta = Cols2*Rows1 < TVMET_COMPLEXITY_MM_TRIGGER ? true : false |
madcowswe | 15:9c5aaeda36dc | 69 | }; |
madcowswe | 15:9c5aaeda36dc | 70 | |
madcowswe | 15:9c5aaeda36dc | 71 | public: |
madcowswe | 15:9c5aaeda36dc | 72 | /** Constructor. */ |
madcowswe | 15:9c5aaeda36dc | 73 | explicit XprMMProductTransposed(const E1& lhs, const E2& rhs) |
madcowswe | 15:9c5aaeda36dc | 74 | : m_lhs(lhs), m_rhs(rhs) { } |
madcowswe | 15:9c5aaeda36dc | 75 | |
madcowswe | 15:9c5aaeda36dc | 76 | /** Copy Constructor. Not explicit! */ |
madcowswe | 15:9c5aaeda36dc | 77 | #if defined(TVMET_OPTIMIZE_XPR_MANUAL_CCTOR) |
madcowswe | 15:9c5aaeda36dc | 78 | XprMMProductTransposed(const XprMMProductTransposed& e) |
madcowswe | 15:9c5aaeda36dc | 79 | : m_lhs(e.m_lhs), m_rhs(e.m_rhs) |
madcowswe | 15:9c5aaeda36dc | 80 | { } |
madcowswe | 15:9c5aaeda36dc | 81 | #endif |
madcowswe | 15:9c5aaeda36dc | 82 | |
madcowswe | 15:9c5aaeda36dc | 83 | private: |
madcowswe | 15:9c5aaeda36dc | 84 | /** Wrapper for meta gemm. */ |
madcowswe | 15:9c5aaeda36dc | 85 | static inline |
madcowswe | 15:9c5aaeda36dc | 86 | value_type do_gemm(dispatch<true>, const E1& lhs, const E2& rhs, std::size_t i, std::size_t j) { |
madcowswe | 15:9c5aaeda36dc | 87 | return meta::gemm<Rows1, Cols1, |
madcowswe | 15:9c5aaeda36dc | 88 | Cols2, |
madcowswe | 15:9c5aaeda36dc | 89 | 0>::prod(lhs, rhs, i, j); |
madcowswe | 15:9c5aaeda36dc | 90 | } |
madcowswe | 15:9c5aaeda36dc | 91 | |
madcowswe | 15:9c5aaeda36dc | 92 | /** Wrapper for loop gemm. */ |
madcowswe | 15:9c5aaeda36dc | 93 | static inline |
madcowswe | 15:9c5aaeda36dc | 94 | value_type do_gemm(dispatch<false>, const E1& lhs, const E2& rhs, std::size_t i, std::size_t j) { |
madcowswe | 15:9c5aaeda36dc | 95 | return loop::gemm<Rows1, Cols1, Cols2>::prod(lhs, rhs, i, j); |
madcowswe | 15:9c5aaeda36dc | 96 | } |
madcowswe | 15:9c5aaeda36dc | 97 | |
madcowswe | 15:9c5aaeda36dc | 98 | public: |
madcowswe | 15:9c5aaeda36dc | 99 | /** index operator for arrays/matrices */ |
madcowswe | 15:9c5aaeda36dc | 100 | value_type operator()(std::size_t i, std::size_t j) const { |
madcowswe | 15:9c5aaeda36dc | 101 | TVMET_RT_CONDITION((i < Cols2) && (j < Rows1), "XprMMProductTransposed Bounce Violation") |
madcowswe | 15:9c5aaeda36dc | 102 | return do_gemm(dispatch<use_meta>(), m_lhs, m_rhs, j, i); |
madcowswe | 15:9c5aaeda36dc | 103 | } |
madcowswe | 15:9c5aaeda36dc | 104 | |
madcowswe | 15:9c5aaeda36dc | 105 | public: // debugging Xpr parse tree |
madcowswe | 15:9c5aaeda36dc | 106 | void print_xpr(std::ostream& os, std::size_t l=0) const { |
madcowswe | 15:9c5aaeda36dc | 107 | os << IndentLevel(l++) |
madcowswe | 15:9c5aaeda36dc | 108 | << "XprMMProductTransposed[" |
madcowswe | 15:9c5aaeda36dc | 109 | << (use_meta ? "M" : "L") << ", O=" << ops |
madcowswe | 15:9c5aaeda36dc | 110 | << ", (O1=" << ops_lhs << ", O2=" << ops_rhs << ")]<" |
madcowswe | 15:9c5aaeda36dc | 111 | << std::endl; |
madcowswe | 15:9c5aaeda36dc | 112 | m_lhs.print_xpr(os, l); |
madcowswe | 15:9c5aaeda36dc | 113 | os << IndentLevel(l) |
madcowswe | 15:9c5aaeda36dc | 114 | << "R1=" << Rows1 << ", C1=" << Cols1 << ",\n"; |
madcowswe | 15:9c5aaeda36dc | 115 | m_rhs.print_xpr(os, l); |
madcowswe | 15:9c5aaeda36dc | 116 | os << IndentLevel(l) |
madcowswe | 15:9c5aaeda36dc | 117 | << "C2=" << Cols2 << ",\n" |
madcowswe | 15:9c5aaeda36dc | 118 | << IndentLevel(l) |
madcowswe | 15:9c5aaeda36dc | 119 | << "\n" |
madcowswe | 15:9c5aaeda36dc | 120 | << IndentLevel(--l) |
madcowswe | 15:9c5aaeda36dc | 121 | << ">," << std::endl; |
madcowswe | 15:9c5aaeda36dc | 122 | } |
madcowswe | 15:9c5aaeda36dc | 123 | |
madcowswe | 15:9c5aaeda36dc | 124 | private: |
madcowswe | 15:9c5aaeda36dc | 125 | const E1 m_lhs; |
madcowswe | 15:9c5aaeda36dc | 126 | const E2 m_rhs; |
madcowswe | 15:9c5aaeda36dc | 127 | }; |
madcowswe | 15:9c5aaeda36dc | 128 | |
madcowswe | 15:9c5aaeda36dc | 129 | |
madcowswe | 15:9c5aaeda36dc | 130 | } // namespace tvmet |
madcowswe | 15:9c5aaeda36dc | 131 | |
madcowswe | 15:9c5aaeda36dc | 132 | #endif // TVMET_XPR_MMPRODUCT_TRANSPOSED_H |
madcowswe | 15:9c5aaeda36dc | 133 | |
madcowswe | 15:9c5aaeda36dc | 134 | // Local Variables: |
madcowswe | 15:9c5aaeda36dc | 135 | // mode:C++ |
madcowswe | 15:9c5aaeda36dc | 136 | // tab-width:8 |
madcowswe | 15:9c5aaeda36dc | 137 | // End: |