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
meta/Gemtm.h@0:feb4117d16d8, 2012-03-28 (annotated)
- Committer:
- madcowswe
- Date:
- Wed Mar 28 15:53:45 2012 +0000
- Revision:
- 0:feb4117d16d8
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
madcowswe | 0:feb4117d16d8 | 1 | /* |
madcowswe | 0:feb4117d16d8 | 2 | * Tiny Vector Matrix Library |
madcowswe | 0:feb4117d16d8 | 3 | * Dense Vector Matrix Libary of Tiny size using Expression Templates |
madcowswe | 0:feb4117d16d8 | 4 | * |
madcowswe | 0:feb4117d16d8 | 5 | * Copyright (C) 2001 - 2007 Olaf Petzold <opetzold@users.sourceforge.net> |
madcowswe | 0:feb4117d16d8 | 6 | * |
madcowswe | 0:feb4117d16d8 | 7 | * This library is free software; you can redistribute it and/or |
madcowswe | 0:feb4117d16d8 | 8 | * modify it under the terms of the GNU Lesser General Public |
madcowswe | 0:feb4117d16d8 | 9 | * License as published by the Free Software Foundation; either |
madcowswe | 0:feb4117d16d8 | 10 | * version 2.1 of the License, or (at your option) any later version. |
madcowswe | 0:feb4117d16d8 | 11 | * |
madcowswe | 0:feb4117d16d8 | 12 | * This library is distributed in the hope that it will be useful, |
madcowswe | 0:feb4117d16d8 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
madcowswe | 0:feb4117d16d8 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
madcowswe | 0:feb4117d16d8 | 15 | * Lesser General Public License for more details. |
madcowswe | 0:feb4117d16d8 | 16 | * |
madcowswe | 0:feb4117d16d8 | 17 | * You should have received a copy of the GNU Lesser General Public |
madcowswe | 0:feb4117d16d8 | 18 | * License along with this library; if not, write to the Free Software |
madcowswe | 0:feb4117d16d8 | 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
madcowswe | 0:feb4117d16d8 | 20 | * |
madcowswe | 0:feb4117d16d8 | 21 | * $Id: Gemtm.h,v 1.12 2007-06-23 15:58:59 opetzold Exp $ |
madcowswe | 0:feb4117d16d8 | 22 | */ |
madcowswe | 0:feb4117d16d8 | 23 | |
madcowswe | 0:feb4117d16d8 | 24 | #ifndef TVMET_META_GEMTM_H |
madcowswe | 0:feb4117d16d8 | 25 | #define TVMET_META_GEMTM_H |
madcowswe | 0:feb4117d16d8 | 26 | |
madcowswe | 0:feb4117d16d8 | 27 | #include <tvmet/xpr/Null.h> |
madcowswe | 0:feb4117d16d8 | 28 | |
madcowswe | 0:feb4117d16d8 | 29 | namespace tvmet { |
madcowswe | 0:feb4117d16d8 | 30 | |
madcowswe | 0:feb4117d16d8 | 31 | namespace meta { |
madcowswe | 0:feb4117d16d8 | 32 | |
madcowswe | 0:feb4117d16d8 | 33 | |
madcowswe | 0:feb4117d16d8 | 34 | /** |
madcowswe | 0:feb4117d16d8 | 35 | * \class gemtm Gemtm.h "tvmet/meta/Gemtm.h" |
madcowswe | 0:feb4117d16d8 | 36 | * \brief Meta class for trans(matrix)-matrix operations, like product. |
madcowswe | 0:feb4117d16d8 | 37 | * using formula |
madcowswe | 0:feb4117d16d8 | 38 | * \f[ |
madcowswe | 0:feb4117d16d8 | 39 | * M_1^{T}\,M_2 |
madcowswe | 0:feb4117d16d8 | 40 | * \f] |
madcowswe | 0:feb4117d16d8 | 41 | * \note The number of cols of matrix 2 have to be equal to number of rows of |
madcowswe | 0:feb4117d16d8 | 42 | * matrix 1, since matrix 1 is transposed - the result is a (Cols1 x Cols2) |
madcowswe | 0:feb4117d16d8 | 43 | * matrix. |
madcowswe | 0:feb4117d16d8 | 44 | */ |
madcowswe | 0:feb4117d16d8 | 45 | |
madcowswe | 0:feb4117d16d8 | 46 | template<std::size_t Rows1, std::size_t Cols1, |
madcowswe | 0:feb4117d16d8 | 47 | std::size_t Cols2, |
madcowswe | 0:feb4117d16d8 | 48 | std::size_t K> |
madcowswe | 0:feb4117d16d8 | 49 | class gemtm |
madcowswe | 0:feb4117d16d8 | 50 | { |
madcowswe | 0:feb4117d16d8 | 51 | private: |
madcowswe | 0:feb4117d16d8 | 52 | gemtm(); |
madcowswe | 0:feb4117d16d8 | 53 | gemtm(const gemtm&); |
madcowswe | 0:feb4117d16d8 | 54 | gemtm& operator=(const gemtm&); |
madcowswe | 0:feb4117d16d8 | 55 | |
madcowswe | 0:feb4117d16d8 | 56 | private: |
madcowswe | 0:feb4117d16d8 | 57 | enum { |
madcowswe | 0:feb4117d16d8 | 58 | doIt = (K != Rows1 - 1) /**< recursive counter */ |
madcowswe | 0:feb4117d16d8 | 59 | }; |
madcowswe | 0:feb4117d16d8 | 60 | |
madcowswe | 0:feb4117d16d8 | 61 | public: |
madcowswe | 0:feb4117d16d8 | 62 | template<class E1, class E2> |
madcowswe | 0:feb4117d16d8 | 63 | static inline |
madcowswe | 0:feb4117d16d8 | 64 | typename PromoteTraits< |
madcowswe | 0:feb4117d16d8 | 65 | typename E1::value_type, |
madcowswe | 0:feb4117d16d8 | 66 | typename E2::value_type |
madcowswe | 0:feb4117d16d8 | 67 | >::value_type |
madcowswe | 0:feb4117d16d8 | 68 | prod(const E1& lhs, const E2& rhs, std::size_t i, std::size_t j) { |
madcowswe | 0:feb4117d16d8 | 69 | return lhs(K, i) * rhs(K, j) |
madcowswe | 0:feb4117d16d8 | 70 | + gemtm<Rows1 * doIt, Cols1 * doIt, |
madcowswe | 0:feb4117d16d8 | 71 | Cols2 * doIt, |
madcowswe | 0:feb4117d16d8 | 72 | (K+1) * doIt>::prod(lhs, rhs, i, j); |
madcowswe | 0:feb4117d16d8 | 73 | } |
madcowswe | 0:feb4117d16d8 | 74 | }; |
madcowswe | 0:feb4117d16d8 | 75 | |
madcowswe | 0:feb4117d16d8 | 76 | |
madcowswe | 0:feb4117d16d8 | 77 | /** |
madcowswe | 0:feb4117d16d8 | 78 | * \class gemtm<0,0,0,0> Gemtm.h "tvmet/meta/Gemtm.h" |
madcowswe | 0:feb4117d16d8 | 79 | * \brief gemtm Specialized for recursion. |
madcowswe | 0:feb4117d16d8 | 80 | */ |
madcowswe | 0:feb4117d16d8 | 81 | template<> |
madcowswe | 0:feb4117d16d8 | 82 | class gemtm<0,0,0,0> |
madcowswe | 0:feb4117d16d8 | 83 | { |
madcowswe | 0:feb4117d16d8 | 84 | gemtm(); |
madcowswe | 0:feb4117d16d8 | 85 | gemtm(const gemtm&); |
madcowswe | 0:feb4117d16d8 | 86 | gemtm& operator=(const gemtm&); |
madcowswe | 0:feb4117d16d8 | 87 | |
madcowswe | 0:feb4117d16d8 | 88 | public: |
madcowswe | 0:feb4117d16d8 | 89 | template<class E1, class E2> |
madcowswe | 0:feb4117d16d8 | 90 | static inline |
madcowswe | 0:feb4117d16d8 | 91 | XprNull prod(const E1&, const E2&, std::size_t, std::size_t) { |
madcowswe | 0:feb4117d16d8 | 92 | return XprNull(); |
madcowswe | 0:feb4117d16d8 | 93 | } |
madcowswe | 0:feb4117d16d8 | 94 | }; |
madcowswe | 0:feb4117d16d8 | 95 | |
madcowswe | 0:feb4117d16d8 | 96 | |
madcowswe | 0:feb4117d16d8 | 97 | } // namespace meta |
madcowswe | 0:feb4117d16d8 | 98 | |
madcowswe | 0:feb4117d16d8 | 99 | } // namespace tvmet |
madcowswe | 0:feb4117d16d8 | 100 | |
madcowswe | 0:feb4117d16d8 | 101 | #endif /* TVMET_META_GEMTM_H */ |
madcowswe | 0:feb4117d16d8 | 102 | |
madcowswe | 0:feb4117d16d8 | 103 | // Local Variables: |
madcowswe | 0:feb4117d16d8 | 104 | // mode:C++ |
madcowswe | 0:feb4117d16d8 | 105 | // tab-width:8 |
madcowswe | 0:feb4117d16d8 | 106 | // End: |