working version with calibration done

Fork of Eurobot2013 by Oskar Weigl

Committer:
sv
Date:
Wed Nov 07 14:37:35 2012 +0000
Revision:
1:6799c07fe510
Preliminary copy of 2012 code

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: MMProductTransposed.h,v 1.20 2007-06-23 15:58:59 opetzold Exp $
sv 1:6799c07fe510 22 */
sv 1:6799c07fe510 23
sv 1:6799c07fe510 24 #ifndef TVMET_XPR_MMPRODUCT_TRANSPOSED_H
sv 1:6799c07fe510 25 #define TVMET_XPR_MMPRODUCT_TRANSPOSED_H
sv 1:6799c07fe510 26
sv 1:6799c07fe510 27 #include <tvmet/meta/Gemm.h>
sv 1:6799c07fe510 28 #include <tvmet/loop/Gemm.h>
sv 1:6799c07fe510 29
sv 1:6799c07fe510 30 namespace tvmet {
sv 1:6799c07fe510 31
sv 1:6799c07fe510 32
sv 1:6799c07fe510 33 /**
sv 1:6799c07fe510 34 * \class XprMMProductTransposed MMProductTransposed.h "tvmet/xpr/MMProductTransposed.h"
sv 1:6799c07fe510 35 * \brief Expression for transpose(matrix-matrix product).
sv 1:6799c07fe510 36 * Using formula:
sv 1:6799c07fe510 37 * \f[
sv 1:6799c07fe510 38 * (M_1\,M_2)^T
sv 1:6799c07fe510 39 * \f]
sv 1:6799c07fe510 40 * \note The Rows2 has to be equal to Cols1.
sv 1:6799c07fe510 41 * The result is a (Cols2 x Rows1) matrix.
sv 1:6799c07fe510 42 */
sv 1:6799c07fe510 43 template<class E1, std::size_t Rows1, std::size_t Cols1,
sv 1:6799c07fe510 44 class E2, std::size_t Cols2>
sv 1:6799c07fe510 45 class XprMMProductTransposed
sv 1:6799c07fe510 46 : public TvmetBase< XprMMProductTransposed<E1, Rows1, Cols1, E2, Cols2> >
sv 1:6799c07fe510 47 {
sv 1:6799c07fe510 48 private:
sv 1:6799c07fe510 49 XprMMProductTransposed();
sv 1:6799c07fe510 50 XprMMProductTransposed& operator=(const XprMMProductTransposed&);
sv 1:6799c07fe510 51
sv 1:6799c07fe510 52 public:
sv 1:6799c07fe510 53 typedef typename PromoteTraits<
sv 1:6799c07fe510 54 typename E1::value_type,
sv 1:6799c07fe510 55 typename E2::value_type
sv 1:6799c07fe510 56 >::value_type value_type;
sv 1:6799c07fe510 57
sv 1:6799c07fe510 58 public:
sv 1:6799c07fe510 59 /** Complexity counter. */
sv 1:6799c07fe510 60 enum {
sv 1:6799c07fe510 61 ops_lhs = E1::ops,
sv 1:6799c07fe510 62 ops_rhs = E2::ops,
sv 1:6799c07fe510 63 M = Rows1 * Cols1 * Cols2,
sv 1:6799c07fe510 64 N = Rows1 * (Cols1-1) * Cols2,
sv 1:6799c07fe510 65 ops_plus = M * NumericTraits<value_type>::ops_plus,
sv 1:6799c07fe510 66 ops_muls = N * NumericTraits<value_type>::ops_muls,
sv 1:6799c07fe510 67 ops = ops_plus + ops_muls,
sv 1:6799c07fe510 68 use_meta = Cols2*Rows1 < TVMET_COMPLEXITY_MM_TRIGGER ? true : false
sv 1:6799c07fe510 69 };
sv 1:6799c07fe510 70
sv 1:6799c07fe510 71 public:
sv 1:6799c07fe510 72 /** Constructor. */
sv 1:6799c07fe510 73 explicit XprMMProductTransposed(const E1& lhs, const E2& rhs)
sv 1:6799c07fe510 74 : m_lhs(lhs), m_rhs(rhs) { }
sv 1:6799c07fe510 75
sv 1:6799c07fe510 76 /** Copy Constructor. Not explicit! */
sv 1:6799c07fe510 77 #if defined(TVMET_OPTIMIZE_XPR_MANUAL_CCTOR)
sv 1:6799c07fe510 78 XprMMProductTransposed(const XprMMProductTransposed& e)
sv 1:6799c07fe510 79 : m_lhs(e.m_lhs), m_rhs(e.m_rhs)
sv 1:6799c07fe510 80 { }
sv 1:6799c07fe510 81 #endif
sv 1:6799c07fe510 82
sv 1:6799c07fe510 83 private:
sv 1:6799c07fe510 84 /** Wrapper for meta gemm. */
sv 1:6799c07fe510 85 static inline
sv 1:6799c07fe510 86 value_type do_gemm(dispatch<true>, const E1& lhs, const E2& rhs, std::size_t i, std::size_t j) {
sv 1:6799c07fe510 87 return meta::gemm<Rows1, Cols1,
sv 1:6799c07fe510 88 Cols2,
sv 1:6799c07fe510 89 0>::prod(lhs, rhs, i, j);
sv 1:6799c07fe510 90 }
sv 1:6799c07fe510 91
sv 1:6799c07fe510 92 /** Wrapper for loop gemm. */
sv 1:6799c07fe510 93 static inline
sv 1:6799c07fe510 94 value_type do_gemm(dispatch<false>, const E1& lhs, const E2& rhs, std::size_t i, std::size_t j) {
sv 1:6799c07fe510 95 return loop::gemm<Rows1, Cols1, Cols2>::prod(lhs, rhs, i, j);
sv 1:6799c07fe510 96 }
sv 1:6799c07fe510 97
sv 1:6799c07fe510 98 public:
sv 1:6799c07fe510 99 /** index operator for arrays/matrices */
sv 1:6799c07fe510 100 value_type operator()(std::size_t i, std::size_t j) const {
sv 1:6799c07fe510 101 TVMET_RT_CONDITION((i < Cols2) && (j < Rows1), "XprMMProductTransposed Bounce Violation")
sv 1:6799c07fe510 102 return do_gemm(dispatch<use_meta>(), m_lhs, m_rhs, j, i);
sv 1:6799c07fe510 103 }
sv 1:6799c07fe510 104
sv 1:6799c07fe510 105 public: // debugging Xpr parse tree
sv 1:6799c07fe510 106 void print_xpr(std::ostream& os, std::size_t l=0) const {
sv 1:6799c07fe510 107 os << IndentLevel(l++)
sv 1:6799c07fe510 108 << "XprMMProductTransposed["
sv 1:6799c07fe510 109 << (use_meta ? "M" : "L") << ", O=" << ops
sv 1:6799c07fe510 110 << ", (O1=" << ops_lhs << ", O2=" << ops_rhs << ")]<"
sv 1:6799c07fe510 111 << std::endl;
sv 1:6799c07fe510 112 m_lhs.print_xpr(os, l);
sv 1:6799c07fe510 113 os << IndentLevel(l)
sv 1:6799c07fe510 114 << "R1=" << Rows1 << ", C1=" << Cols1 << ",\n";
sv 1:6799c07fe510 115 m_rhs.print_xpr(os, l);
sv 1:6799c07fe510 116 os << IndentLevel(l)
sv 1:6799c07fe510 117 << "C2=" << Cols2 << ",\n"
sv 1:6799c07fe510 118 << IndentLevel(l)
sv 1:6799c07fe510 119 << "\n"
sv 1:6799c07fe510 120 << IndentLevel(--l)
sv 1:6799c07fe510 121 << ">," << std::endl;
sv 1:6799c07fe510 122 }
sv 1:6799c07fe510 123
sv 1:6799c07fe510 124 private:
sv 1:6799c07fe510 125 const E1 m_lhs;
sv 1:6799c07fe510 126 const E2 m_rhs;
sv 1:6799c07fe510 127 };
sv 1:6799c07fe510 128
sv 1:6799c07fe510 129
sv 1:6799c07fe510 130 } // namespace tvmet
sv 1:6799c07fe510 131
sv 1:6799c07fe510 132 #endif // TVMET_XPR_MMPRODUCT_TRANSPOSED_H
sv 1:6799c07fe510 133
sv 1:6799c07fe510 134 // Local Variables:
sv 1:6799c07fe510 135 // mode:C++
sv 1:6799c07fe510 136 // tab-width:8
sv 1:6799c07fe510 137 // End: