Eurobot2012_Primary

Dependencies:   mbed Eurobot_2012_Primary

Committer:
narshu
Date:
Wed Oct 17 22:22:47 2012 +0000
Revision:
26:0995f61cb7b8
Parent:
25:143b19c1fb05
Eurobot 2012 Primary;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
narshu 25:143b19c1fb05 1 /*
narshu 25:143b19c1fb05 2 * Tiny Vector Matrix Library
narshu 25:143b19c1fb05 3 * Dense Vector Matrix Libary of Tiny size using Expression Templates
narshu 25:143b19c1fb05 4 *
narshu 25:143b19c1fb05 5 * Copyright (C) 2001 - 2007 Olaf Petzold <opetzold@users.sourceforge.net>
narshu 25:143b19c1fb05 6 *
narshu 25:143b19c1fb05 7 * This library is free software; you can redistribute it and/or
narshu 25:143b19c1fb05 8 * modify it under the terms of the GNU lesser General Public
narshu 25:143b19c1fb05 9 * License as published by the Free Software Foundation; either
narshu 25:143b19c1fb05 10 * version 2.1 of the License, or (at your option) any later version.
narshu 25:143b19c1fb05 11 *
narshu 25:143b19c1fb05 12 * This library is distributed in the hope that it will be useful,
narshu 25:143b19c1fb05 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
narshu 25:143b19c1fb05 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
narshu 25:143b19c1fb05 15 * lesser General Public License for more details.
narshu 25:143b19c1fb05 16 *
narshu 25:143b19c1fb05 17 * You should have received a copy of the GNU lesser General Public
narshu 25:143b19c1fb05 18 * License along with this library; if not, write to the Free Software
narshu 25:143b19c1fb05 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
narshu 25:143b19c1fb05 20 *
narshu 25:143b19c1fb05 21 * $Id: Matrix.h,v 1.26 2007-06-23 15:59:00 opetzold Exp $
narshu 25:143b19c1fb05 22 */
narshu 25:143b19c1fb05 23
narshu 25:143b19c1fb05 24 #ifndef TVMET_XPR_MATRIX_H
narshu 25:143b19c1fb05 25 #define TVMET_XPR_MATRIX_H
narshu 25:143b19c1fb05 26
narshu 25:143b19c1fb05 27 #include <tvmet/meta/Matrix.h>
narshu 25:143b19c1fb05 28 #include <tvmet/loop/Matrix.h>
narshu 25:143b19c1fb05 29
narshu 25:143b19c1fb05 30 namespace tvmet {
narshu 25:143b19c1fb05 31
narshu 25:143b19c1fb05 32
narshu 25:143b19c1fb05 33 /* forwards */
narshu 25:143b19c1fb05 34 template <class T, std::size_t Rows, std::size_t Cols> class Matrix;
narshu 25:143b19c1fb05 35
narshu 25:143b19c1fb05 36 /**
narshu 25:143b19c1fb05 37 * \class XprMatrix Matrix.h "tvmet/xpr/Matrix.h"
narshu 25:143b19c1fb05 38 * \brief Represents the expression for vectors at any node in the parse tree.
narshu 25:143b19c1fb05 39 *
narshu 25:143b19c1fb05 40 * Specifically, XprMatrix is the class that wraps the expression, and the
narshu 25:143b19c1fb05 41 * expression itself is represented by the template parameter E. The
narshu 25:143b19c1fb05 42 * class XprMatrix is known as an anonymizing expression wrapper because
narshu 25:143b19c1fb05 43 * it can hold any subexpression of arbitrary complexity, allowing
narshu 25:143b19c1fb05 44 * clients to work with any expression by holding on to it via the
narshu 25:143b19c1fb05 45 * wrapper, without having to know the name of the type object that
narshu 25:143b19c1fb05 46 * actually implements the expression.
narshu 25:143b19c1fb05 47 * \note leave the CCtors non-explicit to allow implicit type conversation.
narshu 25:143b19c1fb05 48 */
narshu 25:143b19c1fb05 49 template<class E, std::size_t NRows, std::size_t NCols>
narshu 25:143b19c1fb05 50 class XprMatrix
narshu 25:143b19c1fb05 51 : public TvmetBase< XprMatrix<E, NRows, NCols> >
narshu 25:143b19c1fb05 52 {
narshu 25:143b19c1fb05 53 XprMatrix();
narshu 25:143b19c1fb05 54 XprMatrix& operator=(const XprMatrix&);
narshu 25:143b19c1fb05 55
narshu 25:143b19c1fb05 56 public:
narshu 25:143b19c1fb05 57 /** Dimensions. */
narshu 25:143b19c1fb05 58 enum {
narshu 25:143b19c1fb05 59 Rows = NRows, /**< Number of rows. */
narshu 25:143b19c1fb05 60 Cols = NCols, /**< Number of cols. */
narshu 25:143b19c1fb05 61 Size = Rows * Cols /**< Complete Size of Matrix. */
narshu 25:143b19c1fb05 62 };
narshu 25:143b19c1fb05 63
narshu 25:143b19c1fb05 64 public:
narshu 25:143b19c1fb05 65 /** Complexity counter. */
narshu 25:143b19c1fb05 66 enum {
narshu 25:143b19c1fb05 67 ops_assign = Rows * Cols,
narshu 25:143b19c1fb05 68 ops = E::ops,
narshu 25:143b19c1fb05 69 use_meta = ops_assign < TVMET_COMPLEXITY_M_ASSIGN_TRIGGER ? true : false
narshu 25:143b19c1fb05 70 };
narshu 25:143b19c1fb05 71
narshu 25:143b19c1fb05 72 public:
narshu 25:143b19c1fb05 73 typedef typename E::value_type value_type;
narshu 25:143b19c1fb05 74
narshu 25:143b19c1fb05 75 public:
narshu 25:143b19c1fb05 76 /** Constructor. */
narshu 25:143b19c1fb05 77 explicit XprMatrix(const E& e)
narshu 25:143b19c1fb05 78 : m_expr(e)
narshu 25:143b19c1fb05 79 { }
narshu 25:143b19c1fb05 80
narshu 25:143b19c1fb05 81 /** Copy Constructor. Not explicit! */
narshu 25:143b19c1fb05 82 #if defined(TVMET_OPTIMIZE_XPR_MANUAL_CCTOR)
narshu 25:143b19c1fb05 83 XprMatrix(const XprMatrix& rhs)
narshu 25:143b19c1fb05 84 : m_expr(rhs.m_expr)
narshu 25:143b19c1fb05 85 { }
narshu 25:143b19c1fb05 86 #endif
narshu 25:143b19c1fb05 87
narshu 25:143b19c1fb05 88 /** access by index. */
narshu 25:143b19c1fb05 89 value_type operator()(std::size_t i, std::size_t j) const {
narshu 25:143b19c1fb05 90 TVMET_RT_CONDITION((i < Rows) && (j < Cols), "XprMatrix Bounce Violation")
narshu 25:143b19c1fb05 91 return m_expr(i, j);
narshu 25:143b19c1fb05 92 }
narshu 25:143b19c1fb05 93
narshu 25:143b19c1fb05 94 private:
narshu 25:143b19c1fb05 95 /** Wrapper for meta assign. */
narshu 25:143b19c1fb05 96 template<class Dest, class Src, class Assign>
narshu 25:143b19c1fb05 97 static inline
narshu 25:143b19c1fb05 98 void do_assign(dispatch<true>, Dest& dest, const Src& src, const Assign& assign_fn) {
narshu 25:143b19c1fb05 99 meta::Matrix<Rows, Cols, 0, 0>::assign(dest, src, assign_fn);
narshu 25:143b19c1fb05 100 }
narshu 25:143b19c1fb05 101
narshu 25:143b19c1fb05 102 /** Wrapper for loop assign. */
narshu 25:143b19c1fb05 103 template<class Dest, class Src, class Assign>
narshu 25:143b19c1fb05 104 static inline
narshu 25:143b19c1fb05 105 void do_assign(dispatch<false>, Dest& dest, const Src& src, const Assign& assign_fn) {
narshu 25:143b19c1fb05 106 loop::Matrix<Rows, Cols>::assign(dest, src, assign_fn);
narshu 25:143b19c1fb05 107 }
narshu 25:143b19c1fb05 108
narshu 25:143b19c1fb05 109 public:
narshu 25:143b19c1fb05 110 /** assign this expression to Matrix dest. */
narshu 25:143b19c1fb05 111 template<class Dest, class Assign>
narshu 25:143b19c1fb05 112 void assign_to(Dest& dest, const Assign& assign_fn) const {
narshu 25:143b19c1fb05 113 /* here is a way for caching, since each complex 'Node'
narshu 25:143b19c1fb05 114 is of type XprMatrix. */
narshu 25:143b19c1fb05 115 do_assign(dispatch<use_meta>(), dest, *this, assign_fn);
narshu 25:143b19c1fb05 116 }
narshu 25:143b19c1fb05 117
narshu 25:143b19c1fb05 118 public: // debugging Xpr parse tree
narshu 25:143b19c1fb05 119 void print_xpr(std::ostream& os, std::size_t l=0) const {
narshu 25:143b19c1fb05 120 os << IndentLevel(l++)
narshu 25:143b19c1fb05 121 << "XprMatrix["
narshu 25:143b19c1fb05 122 << (use_meta ? "M" : "L") << ", O=" << ops << "]<"
narshu 25:143b19c1fb05 123 << std::endl;
narshu 25:143b19c1fb05 124 m_expr.print_xpr(os, l);
narshu 25:143b19c1fb05 125 os << IndentLevel(l)
narshu 25:143b19c1fb05 126 << "R=" << Rows << ", C=" << Cols << std::endl;
narshu 25:143b19c1fb05 127 os << IndentLevel(--l) << ">"
narshu 25:143b19c1fb05 128 << ((l != 0) ? "," : "") << std::endl;
narshu 25:143b19c1fb05 129 }
narshu 25:143b19c1fb05 130
narshu 25:143b19c1fb05 131 private:
narshu 25:143b19c1fb05 132 const E m_expr;
narshu 25:143b19c1fb05 133 };
narshu 25:143b19c1fb05 134
narshu 25:143b19c1fb05 135
narshu 25:143b19c1fb05 136 } // namespace tvmet
narshu 25:143b19c1fb05 137
narshu 25:143b19c1fb05 138 #include <tvmet/Functional.h>
narshu 25:143b19c1fb05 139
narshu 25:143b19c1fb05 140 #include <tvmet/xpr/BinOperator.h>
narshu 25:143b19c1fb05 141 #include <tvmet/xpr/UnOperator.h>
narshu 25:143b19c1fb05 142 #include <tvmet/xpr/Literal.h>
narshu 25:143b19c1fb05 143
narshu 25:143b19c1fb05 144 #include <tvmet/xpr/Identity.h>
narshu 25:143b19c1fb05 145
narshu 25:143b19c1fb05 146 #include <tvmet/xpr/MMProduct.h>
narshu 25:143b19c1fb05 147 #include <tvmet/xpr/MMProductTransposed.h>
narshu 25:143b19c1fb05 148 #include <tvmet/xpr/MMtProduct.h>
narshu 25:143b19c1fb05 149 #include <tvmet/xpr/MtMProduct.h>
narshu 25:143b19c1fb05 150 #include <tvmet/xpr/MVProduct.h>
narshu 25:143b19c1fb05 151 #include <tvmet/xpr/MtVProduct.h>
narshu 25:143b19c1fb05 152 #include <tvmet/xpr/MatrixTranspose.h>
narshu 25:143b19c1fb05 153
narshu 25:143b19c1fb05 154 #include <tvmet/xpr/MatrixFunctions.h>
narshu 25:143b19c1fb05 155 #include <tvmet/xpr/MatrixBinaryFunctions.h>
narshu 25:143b19c1fb05 156 #include <tvmet/xpr/MatrixUnaryFunctions.h>
narshu 25:143b19c1fb05 157 #include <tvmet/xpr/MatrixOperators.h>
narshu 25:143b19c1fb05 158 #include <tvmet/xpr/Eval.h>
narshu 25:143b19c1fb05 159
narshu 25:143b19c1fb05 160 #endif // TVMET_XPR_MATRIX_H
narshu 25:143b19c1fb05 161
narshu 25:143b19c1fb05 162 // Local Variables:
narshu 25:143b19c1fb05 163 // mode:C++
narshu 25:143b19c1fb05 164 // tab-width:8
narshu 25:143b19c1fb05 165 // End: