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

Committer:
madcowswe
Date:
Wed Mar 28 15:53:45 2012 +0000
Revision:
0:feb4117d16d8

        

Who changed what in which revision?

UserRevisionLine numberNew 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: MVProduct.h,v 1.21 2007-06-23 15:59:00 opetzold Exp $
madcowswe 0:feb4117d16d8 22 */
madcowswe 0:feb4117d16d8 23
madcowswe 0:feb4117d16d8 24 #ifndef TVMET_XPR_MVPRODUCT_H
madcowswe 0:feb4117d16d8 25 #define TVMET_XPR_MVPRODUCT_H
madcowswe 0:feb4117d16d8 26
madcowswe 0:feb4117d16d8 27 #include <tvmet/meta/Gemv.h>
madcowswe 0:feb4117d16d8 28 #include <tvmet/loop/Gemv.h>
madcowswe 0:feb4117d16d8 29
madcowswe 0:feb4117d16d8 30 namespace tvmet {
madcowswe 0:feb4117d16d8 31
madcowswe 0:feb4117d16d8 32
madcowswe 0:feb4117d16d8 33 /**
madcowswe 0:feb4117d16d8 34 * \class XprMVProduct MVProduct.h "tvmet/xpr/MVProduct.h"
madcowswe 0:feb4117d16d8 35 * \brief Expression for matrix-vector product
madcowswe 0:feb4117d16d8 36 * using formula
madcowswe 0:feb4117d16d8 37 * \f[
madcowswe 0:feb4117d16d8 38 * M\,v
madcowswe 0:feb4117d16d8 39 * \f]
madcowswe 0:feb4117d16d8 40 */
madcowswe 0:feb4117d16d8 41 template<class E1, std::size_t Rows, std::size_t Cols,
madcowswe 0:feb4117d16d8 42 class E2>
madcowswe 0:feb4117d16d8 43 class XprMVProduct
madcowswe 0:feb4117d16d8 44 : public TvmetBase< XprMVProduct<E1, Rows, Cols, E2> >
madcowswe 0:feb4117d16d8 45 {
madcowswe 0:feb4117d16d8 46 XprMVProduct();
madcowswe 0:feb4117d16d8 47 XprMVProduct& operator=(const XprMVProduct&);
madcowswe 0:feb4117d16d8 48
madcowswe 0:feb4117d16d8 49 public:
madcowswe 0:feb4117d16d8 50 typedef typename PromoteTraits<
madcowswe 0:feb4117d16d8 51 typename E1::value_type,
madcowswe 0:feb4117d16d8 52 typename E2::value_type
madcowswe 0:feb4117d16d8 53 >::value_type value_type;
madcowswe 0:feb4117d16d8 54
madcowswe 0:feb4117d16d8 55 public:
madcowswe 0:feb4117d16d8 56 /** Complexity counter. */
madcowswe 0:feb4117d16d8 57 enum {
madcowswe 0:feb4117d16d8 58 ops_lhs = E1::ops,
madcowswe 0:feb4117d16d8 59 ops_rhs = E2::ops,
madcowswe 0:feb4117d16d8 60 M = Rows * Cols,
madcowswe 0:feb4117d16d8 61 N = Rows * (Cols - 1),
madcowswe 0:feb4117d16d8 62 ops_plus = M * NumericTraits<value_type>::ops_plus,
madcowswe 0:feb4117d16d8 63 ops_muls = N * NumericTraits<value_type>::ops_muls,
madcowswe 0:feb4117d16d8 64 ops = ops_plus + ops_muls,
madcowswe 0:feb4117d16d8 65 use_meta = Rows*Cols < TVMET_COMPLEXITY_MV_TRIGGER ? true : false
madcowswe 0:feb4117d16d8 66 };
madcowswe 0:feb4117d16d8 67
madcowswe 0:feb4117d16d8 68 public:
madcowswe 0:feb4117d16d8 69 /** Constructor. */
madcowswe 0:feb4117d16d8 70 explicit XprMVProduct(const E1& lhs, const E2& rhs)
madcowswe 0:feb4117d16d8 71 : m_lhs(lhs), m_rhs(rhs)
madcowswe 0:feb4117d16d8 72 { }
madcowswe 0:feb4117d16d8 73
madcowswe 0:feb4117d16d8 74 /** Copy Constructor. Not explicit! */
madcowswe 0:feb4117d16d8 75 #if defined(TVMET_OPTIMIZE_XPR_MANUAL_CCTOR)
madcowswe 0:feb4117d16d8 76 XprMVProduct(const XprMVProduct& e)
madcowswe 0:feb4117d16d8 77 : m_lhs(e.m_lhs), m_rhs(e.m_rhs)
madcowswe 0:feb4117d16d8 78 { }
madcowswe 0:feb4117d16d8 79 #endif
madcowswe 0:feb4117d16d8 80
madcowswe 0:feb4117d16d8 81 private:
madcowswe 0:feb4117d16d8 82 /** Wrapper for meta gemm. */
madcowswe 0:feb4117d16d8 83 static inline
madcowswe 0:feb4117d16d8 84 value_type do_gemv(dispatch<true>, const E1& lhs, const E2& rhs, std::size_t j) {
madcowswe 0:feb4117d16d8 85 return meta::gemv<Rows, Cols,
madcowswe 0:feb4117d16d8 86 0>::prod(lhs, rhs, j);
madcowswe 0:feb4117d16d8 87 }
madcowswe 0:feb4117d16d8 88
madcowswe 0:feb4117d16d8 89 /** Wrapper for loop gemm. */
madcowswe 0:feb4117d16d8 90 static inline
madcowswe 0:feb4117d16d8 91 value_type do_gemv(dispatch<false>, const E1& lhs, const E2& rhs, std::size_t j) {
madcowswe 0:feb4117d16d8 92 return loop::gemv<Rows, Cols>::prod(lhs, rhs, j);
madcowswe 0:feb4117d16d8 93 }
madcowswe 0:feb4117d16d8 94
madcowswe 0:feb4117d16d8 95 public:
madcowswe 0:feb4117d16d8 96 /** index operator, returns the expression by index. This is the vector
madcowswe 0:feb4117d16d8 97 style since a matrix*vector gives a vector. */
madcowswe 0:feb4117d16d8 98 value_type operator()(std::size_t j) const {
madcowswe 0:feb4117d16d8 99 TVMET_RT_CONDITION(j < Rows , "XprMVProduct Bounce Violation")
madcowswe 0:feb4117d16d8 100 return do_gemv(dispatch<use_meta>(), m_lhs, m_rhs, j);
madcowswe 0:feb4117d16d8 101 }
madcowswe 0:feb4117d16d8 102
madcowswe 0:feb4117d16d8 103 public: // debugging Xpr parse tree
madcowswe 0:feb4117d16d8 104 void print_xpr(std::ostream& os, std::size_t l=0) const {
madcowswe 0:feb4117d16d8 105 os << IndentLevel(l++)
madcowswe 0:feb4117d16d8 106 << "XprMVProduct["
madcowswe 0:feb4117d16d8 107 << (use_meta ? "M" : "L") << ", O=" << ops
madcowswe 0:feb4117d16d8 108 << ", (O1=" << ops_lhs << ", O2=" << ops_rhs << ")]<"
madcowswe 0:feb4117d16d8 109 << std::endl;
madcowswe 0:feb4117d16d8 110 m_lhs.print_xpr(os, l);
madcowswe 0:feb4117d16d8 111 os << IndentLevel(l)
madcowswe 0:feb4117d16d8 112 << "R=" << Rows << ", C=" << Cols << ",\n";
madcowswe 0:feb4117d16d8 113 m_rhs.print_xpr(os, l);
madcowswe 0:feb4117d16d8 114 os << IndentLevel(--l)
madcowswe 0:feb4117d16d8 115 << ">," << std::endl;
madcowswe 0:feb4117d16d8 116 }
madcowswe 0:feb4117d16d8 117
madcowswe 0:feb4117d16d8 118 private:
madcowswe 0:feb4117d16d8 119 const E1 m_lhs;
madcowswe 0:feb4117d16d8 120 const E2 m_rhs;
madcowswe 0:feb4117d16d8 121 };
madcowswe 0:feb4117d16d8 122
madcowswe 0:feb4117d16d8 123
madcowswe 0:feb4117d16d8 124 } // namespace tvmet
madcowswe 0:feb4117d16d8 125
madcowswe 0:feb4117d16d8 126 #endif // TVMET_XPR_MVPRODUCT_H
madcowswe 0:feb4117d16d8 127
madcowswe 0:feb4117d16d8 128 // Local Variables:
madcowswe 0:feb4117d16d8 129 // mode:C++
madcowswe 0:feb4117d16d8 130 // tab-width:8
madcowswe 0:feb4117d16d8 131 // End: