Eurobot2012_Secondary

Fork of Eurobot_2012_Secondary by Shuto Naruse

Committer:
narshu
Date:
Wed Oct 17 22:25:31 2012 +0000
Revision:
1:cc2a9eb0bd55
Commit before publishing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
narshu 1:cc2a9eb0bd55 1 /*
narshu 1:cc2a9eb0bd55 2 * Tiny Vector Matrix Library
narshu 1:cc2a9eb0bd55 3 * Dense Vector Matrix Libary of Tiny size using Expression Templates
narshu 1:cc2a9eb0bd55 4 *
narshu 1:cc2a9eb0bd55 5 * Copyright (C) 2001 - 2007 Olaf Petzold <opetzold@users.sourceforge.net>
narshu 1:cc2a9eb0bd55 6 *
narshu 1:cc2a9eb0bd55 7 * This library is free software; you can redistribute it and/or
narshu 1:cc2a9eb0bd55 8 * modify it under the terms of the GNU lesser General Public
narshu 1:cc2a9eb0bd55 9 * License as published by the Free Software Foundation; either
narshu 1:cc2a9eb0bd55 10 * version 2.1 of the License, or (at your option) any later version.
narshu 1:cc2a9eb0bd55 11 *
narshu 1:cc2a9eb0bd55 12 * This library is distributed in the hope that it will be useful,
narshu 1:cc2a9eb0bd55 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
narshu 1:cc2a9eb0bd55 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
narshu 1:cc2a9eb0bd55 15 * lesser General Public License for more details.
narshu 1:cc2a9eb0bd55 16 *
narshu 1:cc2a9eb0bd55 17 * You should have received a copy of the GNU lesser General Public
narshu 1:cc2a9eb0bd55 18 * License along with this library; if not, write to the Free Software
narshu 1:cc2a9eb0bd55 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
narshu 1:cc2a9eb0bd55 20 *
narshu 1:cc2a9eb0bd55 21 * $Id: MatrixImpl.h,v 1.31 2007-06-23 15:58:58 opetzold Exp $
narshu 1:cc2a9eb0bd55 22 */
narshu 1:cc2a9eb0bd55 23
narshu 1:cc2a9eb0bd55 24 #ifndef TVMET_MATRIX_IMPL_H
narshu 1:cc2a9eb0bd55 25 #define TVMET_MATRIX_IMPL_H
narshu 1:cc2a9eb0bd55 26
narshu 1:cc2a9eb0bd55 27 #include <iomanip> // setw
narshu 1:cc2a9eb0bd55 28
narshu 1:cc2a9eb0bd55 29 #include <tvmet/Functional.h>
narshu 1:cc2a9eb0bd55 30 #include <tvmet/Io.h>
narshu 1:cc2a9eb0bd55 31
narshu 1:cc2a9eb0bd55 32
narshu 1:cc2a9eb0bd55 33 namespace tvmet {
narshu 1:cc2a9eb0bd55 34
narshu 1:cc2a9eb0bd55 35
narshu 1:cc2a9eb0bd55 36 /*
narshu 1:cc2a9eb0bd55 37 * member operators for i/o
narshu 1:cc2a9eb0bd55 38 */
narshu 1:cc2a9eb0bd55 39 template<class T, std::size_t NRows, std::size_t NCols>
narshu 1:cc2a9eb0bd55 40 std::ostream& Matrix<T, NRows, NCols>::print_xpr(std::ostream& os, std::size_t l) const
narshu 1:cc2a9eb0bd55 41 {
narshu 1:cc2a9eb0bd55 42 os << IndentLevel(l++) << "Matrix[" << ops << "]<"
narshu 1:cc2a9eb0bd55 43 << typeid(T).name() << ", " << Rows << ", " << Cols << ">,"
narshu 1:cc2a9eb0bd55 44 << IndentLevel(--l)
narshu 1:cc2a9eb0bd55 45 << std::endl;
narshu 1:cc2a9eb0bd55 46
narshu 1:cc2a9eb0bd55 47 return os;
narshu 1:cc2a9eb0bd55 48 }
narshu 1:cc2a9eb0bd55 49
narshu 1:cc2a9eb0bd55 50
narshu 1:cc2a9eb0bd55 51 template<class T, std::size_t NRows, std::size_t NCols>
narshu 1:cc2a9eb0bd55 52 std::ostream& Matrix<T, NRows, NCols>::print_on(std::ostream& os) const
narshu 1:cc2a9eb0bd55 53 {
narshu 1:cc2a9eb0bd55 54 enum {
narshu 1:cc2a9eb0bd55 55 complex_type = NumericTraits<value_type>::is_complex
narshu 1:cc2a9eb0bd55 56 };
narshu 1:cc2a9eb0bd55 57
narshu 1:cc2a9eb0bd55 58 std::streamsize w = IoPrintHelper<Matrix>::width(dispatch<complex_type>(), *this);
narshu 1:cc2a9eb0bd55 59
narshu 1:cc2a9eb0bd55 60 os << std::setw(0) << "[\n";
narshu 1:cc2a9eb0bd55 61 for(std::size_t i = 0; i < Rows; ++i) {
narshu 1:cc2a9eb0bd55 62 os << " [";
narshu 1:cc2a9eb0bd55 63 for(std::size_t j = 0; j < (Cols - 1); ++j) {
narshu 1:cc2a9eb0bd55 64 os << std::setw(w) << this->operator()(i, j) << ", ";
narshu 1:cc2a9eb0bd55 65 }
narshu 1:cc2a9eb0bd55 66 os << std::setw(w) << this->operator()(i, Cols - 1)
narshu 1:cc2a9eb0bd55 67 << (i != (Rows-1) ? "],\n" : "]\n");
narshu 1:cc2a9eb0bd55 68 }
narshu 1:cc2a9eb0bd55 69 os << "]";
narshu 1:cc2a9eb0bd55 70
narshu 1:cc2a9eb0bd55 71 return os;
narshu 1:cc2a9eb0bd55 72 }
narshu 1:cc2a9eb0bd55 73
narshu 1:cc2a9eb0bd55 74
narshu 1:cc2a9eb0bd55 75 /*
narshu 1:cc2a9eb0bd55 76 * member operators with scalars, per se element wise
narshu 1:cc2a9eb0bd55 77 */
narshu 1:cc2a9eb0bd55 78 #define TVMET_IMPLEMENT_MACRO(NAME, OP) \
narshu 1:cc2a9eb0bd55 79 template<class T, std::size_t NRows, std::size_t NCols> \
narshu 1:cc2a9eb0bd55 80 inline \
narshu 1:cc2a9eb0bd55 81 Matrix<T, NRows, NCols>& \
narshu 1:cc2a9eb0bd55 82 Matrix<T, NRows, NCols>::operator OP (value_type rhs) { \
narshu 1:cc2a9eb0bd55 83 typedef XprLiteral<value_type> expr_type; \
narshu 1:cc2a9eb0bd55 84 this->M_##NAME(XprMatrix<expr_type, Rows, Cols>(expr_type(rhs))); \
narshu 1:cc2a9eb0bd55 85 return *this; \
narshu 1:cc2a9eb0bd55 86 }
narshu 1:cc2a9eb0bd55 87
narshu 1:cc2a9eb0bd55 88 TVMET_IMPLEMENT_MACRO(add_eq, +=)
narshu 1:cc2a9eb0bd55 89 TVMET_IMPLEMENT_MACRO(sub_eq, -=)
narshu 1:cc2a9eb0bd55 90 TVMET_IMPLEMENT_MACRO(mul_eq, *=)
narshu 1:cc2a9eb0bd55 91 TVMET_IMPLEMENT_MACRO(div_eq, /=)
narshu 1:cc2a9eb0bd55 92 #undef TVMET_IMPLEMENT_MACRO
narshu 1:cc2a9eb0bd55 93
narshu 1:cc2a9eb0bd55 94
narshu 1:cc2a9eb0bd55 95 #define TVMET_IMPLEMENT_MACRO(NAME, OP) \
narshu 1:cc2a9eb0bd55 96 template<class T, std::size_t NRows, std::size_t NCols> \
narshu 1:cc2a9eb0bd55 97 inline \
narshu 1:cc2a9eb0bd55 98 Matrix<T, NRows, NCols>& \
narshu 1:cc2a9eb0bd55 99 Matrix<T, NRows, NCols>::operator OP (std::size_t rhs) { \
narshu 1:cc2a9eb0bd55 100 typedef XprLiteral<value_type> expr_type; \
narshu 1:cc2a9eb0bd55 101 this->M_##NAME(XprMatrix<expr_type, Rows, Cols>(expr_type(rhs))); \
narshu 1:cc2a9eb0bd55 102 return *this; \
narshu 1:cc2a9eb0bd55 103 }
narshu 1:cc2a9eb0bd55 104
narshu 1:cc2a9eb0bd55 105 TVMET_IMPLEMENT_MACRO(mod_eq, %=)
narshu 1:cc2a9eb0bd55 106 TVMET_IMPLEMENT_MACRO(xor_eq,^=)
narshu 1:cc2a9eb0bd55 107 TVMET_IMPLEMENT_MACRO(and_eq, &=)
narshu 1:cc2a9eb0bd55 108 TVMET_IMPLEMENT_MACRO(or_eq, |=)
narshu 1:cc2a9eb0bd55 109 TVMET_IMPLEMENT_MACRO(shl_eq, <<=)
narshu 1:cc2a9eb0bd55 110 TVMET_IMPLEMENT_MACRO(shr_eq, >>=)
narshu 1:cc2a9eb0bd55 111 #undef TVMET_IMPLEMENT_MACRO
narshu 1:cc2a9eb0bd55 112
narshu 1:cc2a9eb0bd55 113
narshu 1:cc2a9eb0bd55 114 /*
narshu 1:cc2a9eb0bd55 115 * member functions (operators) with matrizes, for use with +=,-= ... <<=
narshu 1:cc2a9eb0bd55 116 */
narshu 1:cc2a9eb0bd55 117 #define TVMET_IMPLEMENT_MACRO(NAME) \
narshu 1:cc2a9eb0bd55 118 template<class T1, std::size_t NRows, std::size_t NCols> \
narshu 1:cc2a9eb0bd55 119 template <class T2> \
narshu 1:cc2a9eb0bd55 120 inline \
narshu 1:cc2a9eb0bd55 121 Matrix<T1, NRows, NCols>& \
narshu 1:cc2a9eb0bd55 122 Matrix<T1, NRows, NCols>::M_##NAME (const Matrix<T2, Rows, Cols>& rhs) { \
narshu 1:cc2a9eb0bd55 123 this->M_##NAME( XprMatrix<typename Matrix<T2, Rows, Cols>::ConstReference, Rows, Cols>(rhs.const_ref()) ); \
narshu 1:cc2a9eb0bd55 124 return *this; \
narshu 1:cc2a9eb0bd55 125 }
narshu 1:cc2a9eb0bd55 126
narshu 1:cc2a9eb0bd55 127 TVMET_IMPLEMENT_MACRO(add_eq)
narshu 1:cc2a9eb0bd55 128 TVMET_IMPLEMENT_MACRO(sub_eq)
narshu 1:cc2a9eb0bd55 129 TVMET_IMPLEMENT_MACRO(mul_eq)
narshu 1:cc2a9eb0bd55 130 TVMET_IMPLEMENT_MACRO(div_eq)
narshu 1:cc2a9eb0bd55 131 TVMET_IMPLEMENT_MACRO(mod_eq)
narshu 1:cc2a9eb0bd55 132 TVMET_IMPLEMENT_MACRO(xor_eq)
narshu 1:cc2a9eb0bd55 133 TVMET_IMPLEMENT_MACRO(and_eq)
narshu 1:cc2a9eb0bd55 134 TVMET_IMPLEMENT_MACRO(or_eq)
narshu 1:cc2a9eb0bd55 135 TVMET_IMPLEMENT_MACRO(shl_eq)
narshu 1:cc2a9eb0bd55 136 TVMET_IMPLEMENT_MACRO(shr_eq)
narshu 1:cc2a9eb0bd55 137 #undef TVMET_IMPLEMENT_MACRO
narshu 1:cc2a9eb0bd55 138
narshu 1:cc2a9eb0bd55 139
narshu 1:cc2a9eb0bd55 140 /*
narshu 1:cc2a9eb0bd55 141 * member functions (operators) with expressions, for use width +=,-= ... <<=
narshu 1:cc2a9eb0bd55 142 */
narshu 1:cc2a9eb0bd55 143 #define TVMET_IMPLEMENT_MACRO(NAME) \
narshu 1:cc2a9eb0bd55 144 template<class T, std::size_t NRows, std::size_t NCols> \
narshu 1:cc2a9eb0bd55 145 template<class E> \
narshu 1:cc2a9eb0bd55 146 inline \
narshu 1:cc2a9eb0bd55 147 Matrix<T, NRows, NCols>& \
narshu 1:cc2a9eb0bd55 148 Matrix<T, NRows, NCols>::M_##NAME (const XprMatrix<E, Rows, Cols>& rhs) { \
narshu 1:cc2a9eb0bd55 149 rhs.assign_to(*this, Fcnl_##NAME<value_type, typename E::value_type>()); \
narshu 1:cc2a9eb0bd55 150 return *this; \
narshu 1:cc2a9eb0bd55 151 }
narshu 1:cc2a9eb0bd55 152
narshu 1:cc2a9eb0bd55 153 TVMET_IMPLEMENT_MACRO(add_eq)
narshu 1:cc2a9eb0bd55 154 TVMET_IMPLEMENT_MACRO(sub_eq)
narshu 1:cc2a9eb0bd55 155 TVMET_IMPLEMENT_MACRO(mul_eq)
narshu 1:cc2a9eb0bd55 156 TVMET_IMPLEMENT_MACRO(div_eq)
narshu 1:cc2a9eb0bd55 157 TVMET_IMPLEMENT_MACRO(mod_eq)
narshu 1:cc2a9eb0bd55 158 TVMET_IMPLEMENT_MACRO(xor_eq)
narshu 1:cc2a9eb0bd55 159 TVMET_IMPLEMENT_MACRO(and_eq)
narshu 1:cc2a9eb0bd55 160 TVMET_IMPLEMENT_MACRO(or_eq)
narshu 1:cc2a9eb0bd55 161 TVMET_IMPLEMENT_MACRO(shl_eq)
narshu 1:cc2a9eb0bd55 162 TVMET_IMPLEMENT_MACRO(shr_eq)
narshu 1:cc2a9eb0bd55 163 #undef TVMET_IMPLEMENT_MACRO
narshu 1:cc2a9eb0bd55 164
narshu 1:cc2a9eb0bd55 165
narshu 1:cc2a9eb0bd55 166 /*
narshu 1:cc2a9eb0bd55 167 * aliased member functions (operators) with matrizes,
narshu 1:cc2a9eb0bd55 168 * for use with +=,-= ... <<=
narshu 1:cc2a9eb0bd55 169 */
narshu 1:cc2a9eb0bd55 170 #define TVMET_IMPLEMENT_MACRO(NAME) \
narshu 1:cc2a9eb0bd55 171 template<class T1, std::size_t NRows, std::size_t NCols> \
narshu 1:cc2a9eb0bd55 172 template <class T2> \
narshu 1:cc2a9eb0bd55 173 inline \
narshu 1:cc2a9eb0bd55 174 Matrix<T1, NRows, NCols>& \
narshu 1:cc2a9eb0bd55 175 Matrix<T1, NRows, NCols>::alias_##NAME (const Matrix<T2, Rows, Cols>& rhs) { \
narshu 1:cc2a9eb0bd55 176 this->alias_##NAME( XprMatrix<typename Matrix<T2, Rows, Cols>::ConstReference, Rows, Cols>(rhs.const_ref()) ); \
narshu 1:cc2a9eb0bd55 177 return *this; \
narshu 1:cc2a9eb0bd55 178 }
narshu 1:cc2a9eb0bd55 179
narshu 1:cc2a9eb0bd55 180 TVMET_IMPLEMENT_MACRO(assign)
narshu 1:cc2a9eb0bd55 181 TVMET_IMPLEMENT_MACRO(add_eq)
narshu 1:cc2a9eb0bd55 182 TVMET_IMPLEMENT_MACRO(sub_eq)
narshu 1:cc2a9eb0bd55 183 TVMET_IMPLEMENT_MACRO(mul_eq)
narshu 1:cc2a9eb0bd55 184 TVMET_IMPLEMENT_MACRO(div_eq)
narshu 1:cc2a9eb0bd55 185 #undef TVMET_IMPLEMENT_MACRO
narshu 1:cc2a9eb0bd55 186
narshu 1:cc2a9eb0bd55 187
narshu 1:cc2a9eb0bd55 188 /*
narshu 1:cc2a9eb0bd55 189 * aliased member functions (operators) with expressions,
narshu 1:cc2a9eb0bd55 190 * for use width +=,-= ... <<= and aliased(),
narshu 1:cc2a9eb0bd55 191 */
narshu 1:cc2a9eb0bd55 192 #define TVMET_IMPLEMENT_MACRO(NAME) \
narshu 1:cc2a9eb0bd55 193 template<class T, std::size_t NRows, std::size_t NCols> \
narshu 1:cc2a9eb0bd55 194 template<class E> \
narshu 1:cc2a9eb0bd55 195 inline \
narshu 1:cc2a9eb0bd55 196 Matrix<T, NRows, NCols>& \
narshu 1:cc2a9eb0bd55 197 Matrix<T, NRows, NCols>::alias_##NAME (const XprMatrix<E, Rows, Cols>& rhs) { \
narshu 1:cc2a9eb0bd55 198 typedef Matrix<T, NRows, NCols> temp_type; \
narshu 1:cc2a9eb0bd55 199 temp_type(rhs).assign_to(*this, Fcnl_##NAME<value_type, typename E::value_type>()); \
narshu 1:cc2a9eb0bd55 200 return *this; \
narshu 1:cc2a9eb0bd55 201 }
narshu 1:cc2a9eb0bd55 202
narshu 1:cc2a9eb0bd55 203 TVMET_IMPLEMENT_MACRO(assign)
narshu 1:cc2a9eb0bd55 204 TVMET_IMPLEMENT_MACRO(add_eq)
narshu 1:cc2a9eb0bd55 205 TVMET_IMPLEMENT_MACRO(sub_eq)
narshu 1:cc2a9eb0bd55 206 TVMET_IMPLEMENT_MACRO(mul_eq)
narshu 1:cc2a9eb0bd55 207 TVMET_IMPLEMENT_MACRO(div_eq)
narshu 1:cc2a9eb0bd55 208 #undef TVMET_IMPLEMENT_MACRO
narshu 1:cc2a9eb0bd55 209
narshu 1:cc2a9eb0bd55 210
narshu 1:cc2a9eb0bd55 211 } // namespace tvmet
narshu 1:cc2a9eb0bd55 212
narshu 1:cc2a9eb0bd55 213 #endif // TVMET_MATRIX_IMPL_H
narshu 1:cc2a9eb0bd55 214
narshu 1:cc2a9eb0bd55 215 // Local Variables:
narshu 1:cc2a9eb0bd55 216 // mode:C++
narshu 1:cc2a9eb0bd55 217 // tab-width:8
narshu 1:cc2a9eb0bd55 218 // End: