This is some awesome robot code

Dependencies:   mbed-rtos mbed QEI

Fork of ICRSEurobot13 by Thomas Branch

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?

UserRevisionLine numberNew 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: Gemtm.h,v 1.9 2007-06-23 15:58:59 opetzold Exp $
madcowswe 15:9c5aaeda36dc 22 */
madcowswe 15:9c5aaeda36dc 23
madcowswe 15:9c5aaeda36dc 24 #ifndef TVMET_LOOP_GEMTM_H
madcowswe 15:9c5aaeda36dc 25 #define TVMET_LOOP_GEMTM_H
madcowswe 15:9c5aaeda36dc 26
madcowswe 15:9c5aaeda36dc 27 namespace tvmet {
madcowswe 15:9c5aaeda36dc 28
madcowswe 15:9c5aaeda36dc 29 namespace loop {
madcowswe 15:9c5aaeda36dc 30
madcowswe 15:9c5aaeda36dc 31
madcowswe 15:9c5aaeda36dc 32 /**
madcowswe 15:9c5aaeda36dc 33 * \class gemtm Gemtm.h "tvmet/loop/Gemtm.h"
madcowswe 15:9c5aaeda36dc 34 * \brief class for matrix-matrix product using loop unrolling.
madcowswe 15:9c5aaeda36dc 35 * using formula
madcowswe 15:9c5aaeda36dc 36 * \f[
madcowswe 15:9c5aaeda36dc 37 * M_1^{T}\,M_2
madcowswe 15:9c5aaeda36dc 38 * \f]
madcowswe 15:9c5aaeda36dc 39 * \par Example:
madcowswe 15:9c5aaeda36dc 40 * \code
madcowswe 15:9c5aaeda36dc 41 * template<class T, std::size_t Rows1, std::size_t Cols1, std::size_t Cols2>
madcowswe 15:9c5aaeda36dc 42 * inline
madcowswe 15:9c5aaeda36dc 43 * void
madcowswe 15:9c5aaeda36dc 44 * prod(const Matrix<T, Rows1, Cols1>& lhs, const Matrix<T, Rows1, Cols2>& rhs,
madcowswe 15:9c5aaeda36dc 45 * Matrix<T, Cols2, Cols1>& dest)
madcowswe 15:9c5aaeda36dc 46 * {
madcowswe 15:9c5aaeda36dc 47 * for (std::size_t i = 0; i != Cols1; ++i) {
madcowswe 15:9c5aaeda36dc 48 * for (std::size_t j = 0; j != Cols2; ++j) {
madcowswe 15:9c5aaeda36dc 49 * dest(i, j) = tvmet::loop::gemtm<Rows1, Cols1, Cols2>::prod(lhs, rhs, i, j);
madcowswe 15:9c5aaeda36dc 50 * }
madcowswe 15:9c5aaeda36dc 51 * }
madcowswe 15:9c5aaeda36dc 52 * }
madcowswe 15:9c5aaeda36dc 53 * \endcode
madcowswe 15:9c5aaeda36dc 54 * \note The number of rows of rhs matrix have to be equal rows of rhs matrix,
madcowswe 15:9c5aaeda36dc 55 * since lhs matrix 1 is transposed.
madcowswe 15:9c5aaeda36dc 56 * The result is a (Cols1 x Cols2) matrix.
madcowswe 15:9c5aaeda36dc 57 */
madcowswe 15:9c5aaeda36dc 58 template<std::size_t Rows1, std::size_t Cols1,
madcowswe 15:9c5aaeda36dc 59 std::size_t Cols2>
madcowswe 15:9c5aaeda36dc 60 class gemtm
madcowswe 15:9c5aaeda36dc 61 {
madcowswe 15:9c5aaeda36dc 62 gemtm(const gemtm&);
madcowswe 15:9c5aaeda36dc 63 gemtm& operator=(const gemtm&);
madcowswe 15:9c5aaeda36dc 64
madcowswe 15:9c5aaeda36dc 65 private:
madcowswe 15:9c5aaeda36dc 66 enum {
madcowswe 15:9c5aaeda36dc 67 count = Cols1,
madcowswe 15:9c5aaeda36dc 68 N = (count+7)/8
madcowswe 15:9c5aaeda36dc 69 };
madcowswe 15:9c5aaeda36dc 70
madcowswe 15:9c5aaeda36dc 71 public:
madcowswe 15:9c5aaeda36dc 72 gemtm() { }
madcowswe 15:9c5aaeda36dc 73
madcowswe 15:9c5aaeda36dc 74 public:
madcowswe 15:9c5aaeda36dc 75 template<class E1, class E2>
madcowswe 15:9c5aaeda36dc 76 static inline
madcowswe 15:9c5aaeda36dc 77 typename PromoteTraits<
madcowswe 15:9c5aaeda36dc 78 typename E1::value_type,
madcowswe 15:9c5aaeda36dc 79 typename E2::value_type
madcowswe 15:9c5aaeda36dc 80 >::value_type
madcowswe 15:9c5aaeda36dc 81 prod(const E1& lhs, const E2& rhs, std::size_t i, std::size_t j) {
madcowswe 15:9c5aaeda36dc 82 typename PromoteTraits<
madcowswe 15:9c5aaeda36dc 83 typename E1::value_type,
madcowswe 15:9c5aaeda36dc 84 typename E2::value_type
madcowswe 15:9c5aaeda36dc 85 >::value_type sum(0);
madcowswe 15:9c5aaeda36dc 86 std::size_t k(0);
madcowswe 15:9c5aaeda36dc 87 std::size_t n(N);
madcowswe 15:9c5aaeda36dc 88
madcowswe 15:9c5aaeda36dc 89 // Duff's device
madcowswe 15:9c5aaeda36dc 90 switch(count % 8) {
madcowswe 15:9c5aaeda36dc 91 case 0: do { sum += lhs(k, i) * rhs(k, j); ++k;
madcowswe 15:9c5aaeda36dc 92 case 7: sum += lhs(k, i) * rhs(k, j); ++k;
madcowswe 15:9c5aaeda36dc 93 case 6: sum += lhs(k, i) * rhs(k, j); ++k;
madcowswe 15:9c5aaeda36dc 94 case 5: sum += lhs(k, i) * rhs(k, j); ++k;
madcowswe 15:9c5aaeda36dc 95 case 4: sum += lhs(k, i) * rhs(k, j); ++k;
madcowswe 15:9c5aaeda36dc 96 case 3: sum += lhs(k, i) * rhs(k, j); ++k;
madcowswe 15:9c5aaeda36dc 97 case 2: sum += lhs(k, i) * rhs(k, j); ++k;
madcowswe 15:9c5aaeda36dc 98 case 1: sum += lhs(k, i) * rhs(k, j); ++k;
madcowswe 15:9c5aaeda36dc 99 } while(--n != 0);
madcowswe 15:9c5aaeda36dc 100 }
madcowswe 15:9c5aaeda36dc 101
madcowswe 15:9c5aaeda36dc 102 return sum;
madcowswe 15:9c5aaeda36dc 103 }
madcowswe 15:9c5aaeda36dc 104 };
madcowswe 15:9c5aaeda36dc 105
madcowswe 15:9c5aaeda36dc 106
madcowswe 15:9c5aaeda36dc 107 } // namespace loop
madcowswe 15:9c5aaeda36dc 108
madcowswe 15:9c5aaeda36dc 109 } // namespace tvmet
madcowswe 15:9c5aaeda36dc 110
madcowswe 15:9c5aaeda36dc 111 #endif /* TVMET_LOOP_GEMTM_H */
madcowswe 15:9c5aaeda36dc 112
madcowswe 15:9c5aaeda36dc 113 // Local Variables:
madcowswe 15:9c5aaeda36dc 114 // mode:C++
madcowswe 15:9c5aaeda36dc 115 // tab-width:8
madcowswe 15:9c5aaeda36dc 116 // End: