We are going to win! wohoo

Dependencies:   mbed mbed-rtos

Committer:
madcowswe
Date:
Wed Nov 14 17:15:53 2012 +0000
Revision:
9:08552997b544
Parent:
1:6799c07fe510
Added an important comment

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sv 1:6799c07fe510 1 /*
sv 1:6799c07fe510 2 * Tiny Vector Matrix Library
sv 1:6799c07fe510 3 * Dense Vector Matrix Libary of Tiny size using Expression Templates
sv 1:6799c07fe510 4 *
sv 1:6799c07fe510 5 * Copyright (C) 2001 - 2007 Olaf Petzold <opetzold@users.sourceforge.net>
sv 1:6799c07fe510 6 *
sv 1:6799c07fe510 7 * This library is free software; you can redistribute it and/or
sv 1:6799c07fe510 8 * modify it under the terms of the GNU Lesser General Public
sv 1:6799c07fe510 9 * License as published by the Free Software Foundation; either
sv 1:6799c07fe510 10 * version 2.1 of the License, or (at your option) any later version.
sv 1:6799c07fe510 11 *
sv 1:6799c07fe510 12 * This library is distributed in the hope that it will be useful,
sv 1:6799c07fe510 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
sv 1:6799c07fe510 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
sv 1:6799c07fe510 15 * Lesser General Public License for more details.
sv 1:6799c07fe510 16 *
sv 1:6799c07fe510 17 * You should have received a copy of the GNU Lesser General Public
sv 1:6799c07fe510 18 * License along with this library; if not, write to the Free Software
sv 1:6799c07fe510 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
sv 1:6799c07fe510 20 *
sv 1:6799c07fe510 21 * $Id: Gemtm.h,v 1.9 2007-06-23 15:58:59 opetzold Exp $
sv 1:6799c07fe510 22 */
sv 1:6799c07fe510 23
sv 1:6799c07fe510 24 #ifndef TVMET_LOOP_GEMTM_H
sv 1:6799c07fe510 25 #define TVMET_LOOP_GEMTM_H
sv 1:6799c07fe510 26
sv 1:6799c07fe510 27 namespace tvmet {
sv 1:6799c07fe510 28
sv 1:6799c07fe510 29 namespace loop {
sv 1:6799c07fe510 30
sv 1:6799c07fe510 31
sv 1:6799c07fe510 32 /**
sv 1:6799c07fe510 33 * \class gemtm Gemtm.h "tvmet/loop/Gemtm.h"
sv 1:6799c07fe510 34 * \brief class for matrix-matrix product using loop unrolling.
sv 1:6799c07fe510 35 * using formula
sv 1:6799c07fe510 36 * \f[
sv 1:6799c07fe510 37 * M_1^{T}\,M_2
sv 1:6799c07fe510 38 * \f]
sv 1:6799c07fe510 39 * \par Example:
sv 1:6799c07fe510 40 * \code
sv 1:6799c07fe510 41 * template<class T, std::size_t Rows1, std::size_t Cols1, std::size_t Cols2>
sv 1:6799c07fe510 42 * inline
sv 1:6799c07fe510 43 * void
sv 1:6799c07fe510 44 * prod(const Matrix<T, Rows1, Cols1>& lhs, const Matrix<T, Rows1, Cols2>& rhs,
sv 1:6799c07fe510 45 * Matrix<T, Cols2, Cols1>& dest)
sv 1:6799c07fe510 46 * {
sv 1:6799c07fe510 47 * for (std::size_t i = 0; i != Cols1; ++i) {
sv 1:6799c07fe510 48 * for (std::size_t j = 0; j != Cols2; ++j) {
sv 1:6799c07fe510 49 * dest(i, j) = tvmet::loop::gemtm<Rows1, Cols1, Cols2>::prod(lhs, rhs, i, j);
sv 1:6799c07fe510 50 * }
sv 1:6799c07fe510 51 * }
sv 1:6799c07fe510 52 * }
sv 1:6799c07fe510 53 * \endcode
sv 1:6799c07fe510 54 * \note The number of rows of rhs matrix have to be equal rows of rhs matrix,
sv 1:6799c07fe510 55 * since lhs matrix 1 is transposed.
sv 1:6799c07fe510 56 * The result is a (Cols1 x Cols2) matrix.
sv 1:6799c07fe510 57 */
sv 1:6799c07fe510 58 template<std::size_t Rows1, std::size_t Cols1,
sv 1:6799c07fe510 59 std::size_t Cols2>
sv 1:6799c07fe510 60 class gemtm
sv 1:6799c07fe510 61 {
sv 1:6799c07fe510 62 gemtm(const gemtm&);
sv 1:6799c07fe510 63 gemtm& operator=(const gemtm&);
sv 1:6799c07fe510 64
sv 1:6799c07fe510 65 private:
sv 1:6799c07fe510 66 enum {
sv 1:6799c07fe510 67 count = Cols1,
sv 1:6799c07fe510 68 N = (count+7)/8
sv 1:6799c07fe510 69 };
sv 1:6799c07fe510 70
sv 1:6799c07fe510 71 public:
sv 1:6799c07fe510 72 gemtm() { }
sv 1:6799c07fe510 73
sv 1:6799c07fe510 74 public:
sv 1:6799c07fe510 75 template<class E1, class E2>
sv 1:6799c07fe510 76 static inline
sv 1:6799c07fe510 77 typename PromoteTraits<
sv 1:6799c07fe510 78 typename E1::value_type,
sv 1:6799c07fe510 79 typename E2::value_type
sv 1:6799c07fe510 80 >::value_type
sv 1:6799c07fe510 81 prod(const E1& lhs, const E2& rhs, std::size_t i, std::size_t j) {
sv 1:6799c07fe510 82 typename PromoteTraits<
sv 1:6799c07fe510 83 typename E1::value_type,
sv 1:6799c07fe510 84 typename E2::value_type
sv 1:6799c07fe510 85 >::value_type sum(0);
sv 1:6799c07fe510 86 std::size_t k(0);
sv 1:6799c07fe510 87 std::size_t n(N);
sv 1:6799c07fe510 88
sv 1:6799c07fe510 89 // Duff's device
sv 1:6799c07fe510 90 switch(count % 8) {
sv 1:6799c07fe510 91 case 0: do { sum += lhs(k, i) * rhs(k, j); ++k;
sv 1:6799c07fe510 92 case 7: sum += lhs(k, i) * rhs(k, j); ++k;
sv 1:6799c07fe510 93 case 6: sum += lhs(k, i) * rhs(k, j); ++k;
sv 1:6799c07fe510 94 case 5: sum += lhs(k, i) * rhs(k, j); ++k;
sv 1:6799c07fe510 95 case 4: sum += lhs(k, i) * rhs(k, j); ++k;
sv 1:6799c07fe510 96 case 3: sum += lhs(k, i) * rhs(k, j); ++k;
sv 1:6799c07fe510 97 case 2: sum += lhs(k, i) * rhs(k, j); ++k;
sv 1:6799c07fe510 98 case 1: sum += lhs(k, i) * rhs(k, j); ++k;
sv 1:6799c07fe510 99 } while(--n != 0);
sv 1:6799c07fe510 100 }
sv 1:6799c07fe510 101
sv 1:6799c07fe510 102 return sum;
sv 1:6799c07fe510 103 }
sv 1:6799c07fe510 104 };
sv 1:6799c07fe510 105
sv 1:6799c07fe510 106
sv 1:6799c07fe510 107 } // namespace loop
sv 1:6799c07fe510 108
sv 1:6799c07fe510 109 } // namespace tvmet
sv 1:6799c07fe510 110
sv 1:6799c07fe510 111 #endif /* TVMET_LOOP_GEMTM_H */
sv 1:6799c07fe510 112
sv 1:6799c07fe510 113 // Local Variables:
sv 1:6799c07fe510 114 // mode:C++
sv 1:6799c07fe510 115 // tab-width:8
sv 1:6799c07fe510 116 // End: