We are going to win! wohoo

Dependencies:   mbed mbed-rtos

Committer:
madcowswe
Date:
Wed Nov 14 17:15:53 2012 +0000
Revision:
9:08552997b544
Parent:
1:6799c07fe510
Added an important comment

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: MatrixImpl.h,v 1.31 2007-06-23 15:58:58 opetzold Exp $
sv 1:6799c07fe510 22 */
sv 1:6799c07fe510 23
sv 1:6799c07fe510 24 #ifndef TVMET_MATRIX_IMPL_H
sv 1:6799c07fe510 25 #define TVMET_MATRIX_IMPL_H
sv 1:6799c07fe510 26
sv 1:6799c07fe510 27 #include <iomanip> // setw
sv 1:6799c07fe510 28
sv 1:6799c07fe510 29 #include <tvmet/Functional.h>
sv 1:6799c07fe510 30 #include <tvmet/Io.h>
sv 1:6799c07fe510 31
sv 1:6799c07fe510 32
sv 1:6799c07fe510 33 namespace tvmet {
sv 1:6799c07fe510 34
sv 1:6799c07fe510 35
sv 1:6799c07fe510 36 /*
sv 1:6799c07fe510 37 * member operators for i/o
sv 1:6799c07fe510 38 */
sv 1:6799c07fe510 39 template<class T, std::size_t NRows, std::size_t NCols>
sv 1:6799c07fe510 40 std::ostream& Matrix<T, NRows, NCols>::print_xpr(std::ostream& os, std::size_t l) const
sv 1:6799c07fe510 41 {
sv 1:6799c07fe510 42 os << IndentLevel(l++) << "Matrix[" << ops << "]<"
sv 1:6799c07fe510 43 << typeid(T).name() << ", " << Rows << ", " << Cols << ">,"
sv 1:6799c07fe510 44 << IndentLevel(--l)
sv 1:6799c07fe510 45 << std::endl;
sv 1:6799c07fe510 46
sv 1:6799c07fe510 47 return os;
sv 1:6799c07fe510 48 }
sv 1:6799c07fe510 49
sv 1:6799c07fe510 50
sv 1:6799c07fe510 51 template<class T, std::size_t NRows, std::size_t NCols>
sv 1:6799c07fe510 52 std::ostream& Matrix<T, NRows, NCols>::print_on(std::ostream& os) const
sv 1:6799c07fe510 53 {
sv 1:6799c07fe510 54 enum {
sv 1:6799c07fe510 55 complex_type = NumericTraits<value_type>::is_complex
sv 1:6799c07fe510 56 };
sv 1:6799c07fe510 57
sv 1:6799c07fe510 58 std::streamsize w = IoPrintHelper<Matrix>::width(dispatch<complex_type>(), *this);
sv 1:6799c07fe510 59
sv 1:6799c07fe510 60 os << std::setw(0) << "[\n";
sv 1:6799c07fe510 61 for(std::size_t i = 0; i < Rows; ++i) {
sv 1:6799c07fe510 62 os << " [";
sv 1:6799c07fe510 63 for(std::size_t j = 0; j < (Cols - 1); ++j) {
sv 1:6799c07fe510 64 os << std::setw(w) << this->operator()(i, j) << ", ";
sv 1:6799c07fe510 65 }
sv 1:6799c07fe510 66 os << std::setw(w) << this->operator()(i, Cols - 1)
sv 1:6799c07fe510 67 << (i != (Rows-1) ? "],\n" : "]\n");
sv 1:6799c07fe510 68 }
sv 1:6799c07fe510 69 os << "]";
sv 1:6799c07fe510 70
sv 1:6799c07fe510 71 return os;
sv 1:6799c07fe510 72 }
sv 1:6799c07fe510 73
sv 1:6799c07fe510 74
sv 1:6799c07fe510 75 /*
sv 1:6799c07fe510 76 * member operators with scalars, per se element wise
sv 1:6799c07fe510 77 */
sv 1:6799c07fe510 78 #define TVMET_IMPLEMENT_MACRO(NAME, OP) \
sv 1:6799c07fe510 79 template<class T, std::size_t NRows, std::size_t NCols> \
sv 1:6799c07fe510 80 inline \
sv 1:6799c07fe510 81 Matrix<T, NRows, NCols>& \
sv 1:6799c07fe510 82 Matrix<T, NRows, NCols>::operator OP (value_type rhs) { \
sv 1:6799c07fe510 83 typedef XprLiteral<value_type> expr_type; \
sv 1:6799c07fe510 84 this->M_##NAME(XprMatrix<expr_type, Rows, Cols>(expr_type(rhs))); \
sv 1:6799c07fe510 85 return *this; \
sv 1:6799c07fe510 86 }
sv 1:6799c07fe510 87
sv 1:6799c07fe510 88 TVMET_IMPLEMENT_MACRO(add_eq, +=)
sv 1:6799c07fe510 89 TVMET_IMPLEMENT_MACRO(sub_eq, -=)
sv 1:6799c07fe510 90 TVMET_IMPLEMENT_MACRO(mul_eq, *=)
sv 1:6799c07fe510 91 TVMET_IMPLEMENT_MACRO(div_eq, /=)
sv 1:6799c07fe510 92 #undef TVMET_IMPLEMENT_MACRO
sv 1:6799c07fe510 93
sv 1:6799c07fe510 94
sv 1:6799c07fe510 95 #define TVMET_IMPLEMENT_MACRO(NAME, OP) \
sv 1:6799c07fe510 96 template<class T, std::size_t NRows, std::size_t NCols> \
sv 1:6799c07fe510 97 inline \
sv 1:6799c07fe510 98 Matrix<T, NRows, NCols>& \
sv 1:6799c07fe510 99 Matrix<T, NRows, NCols>::operator OP (std::size_t rhs) { \
sv 1:6799c07fe510 100 typedef XprLiteral<value_type> expr_type; \
sv 1:6799c07fe510 101 this->M_##NAME(XprMatrix<expr_type, Rows, Cols>(expr_type(rhs))); \
sv 1:6799c07fe510 102 return *this; \
sv 1:6799c07fe510 103 }
sv 1:6799c07fe510 104
sv 1:6799c07fe510 105 TVMET_IMPLEMENT_MACRO(mod_eq, %=)
sv 1:6799c07fe510 106 TVMET_IMPLEMENT_MACRO(xor_eq,^=)
sv 1:6799c07fe510 107 TVMET_IMPLEMENT_MACRO(and_eq, &=)
sv 1:6799c07fe510 108 TVMET_IMPLEMENT_MACRO(or_eq, |=)
sv 1:6799c07fe510 109 TVMET_IMPLEMENT_MACRO(shl_eq, <<=)
sv 1:6799c07fe510 110 TVMET_IMPLEMENT_MACRO(shr_eq, >>=)
sv 1:6799c07fe510 111 #undef TVMET_IMPLEMENT_MACRO
sv 1:6799c07fe510 112
sv 1:6799c07fe510 113
sv 1:6799c07fe510 114 /*
sv 1:6799c07fe510 115 * member functions (operators) with matrizes, for use with +=,-= ... <<=
sv 1:6799c07fe510 116 */
sv 1:6799c07fe510 117 #define TVMET_IMPLEMENT_MACRO(NAME) \
sv 1:6799c07fe510 118 template<class T1, std::size_t NRows, std::size_t NCols> \
sv 1:6799c07fe510 119 template <class T2> \
sv 1:6799c07fe510 120 inline \
sv 1:6799c07fe510 121 Matrix<T1, NRows, NCols>& \
sv 1:6799c07fe510 122 Matrix<T1, NRows, NCols>::M_##NAME (const Matrix<T2, Rows, Cols>& rhs) { \
sv 1:6799c07fe510 123 this->M_##NAME( XprMatrix<typename Matrix<T2, Rows, Cols>::ConstReference, Rows, Cols>(rhs.const_ref()) ); \
sv 1:6799c07fe510 124 return *this; \
sv 1:6799c07fe510 125 }
sv 1:6799c07fe510 126
sv 1:6799c07fe510 127 TVMET_IMPLEMENT_MACRO(add_eq)
sv 1:6799c07fe510 128 TVMET_IMPLEMENT_MACRO(sub_eq)
sv 1:6799c07fe510 129 TVMET_IMPLEMENT_MACRO(mul_eq)
sv 1:6799c07fe510 130 TVMET_IMPLEMENT_MACRO(div_eq)
sv 1:6799c07fe510 131 TVMET_IMPLEMENT_MACRO(mod_eq)
sv 1:6799c07fe510 132 TVMET_IMPLEMENT_MACRO(xor_eq)
sv 1:6799c07fe510 133 TVMET_IMPLEMENT_MACRO(and_eq)
sv 1:6799c07fe510 134 TVMET_IMPLEMENT_MACRO(or_eq)
sv 1:6799c07fe510 135 TVMET_IMPLEMENT_MACRO(shl_eq)
sv 1:6799c07fe510 136 TVMET_IMPLEMENT_MACRO(shr_eq)
sv 1:6799c07fe510 137 #undef TVMET_IMPLEMENT_MACRO
sv 1:6799c07fe510 138
sv 1:6799c07fe510 139
sv 1:6799c07fe510 140 /*
sv 1:6799c07fe510 141 * member functions (operators) with expressions, for use width +=,-= ... <<=
sv 1:6799c07fe510 142 */
sv 1:6799c07fe510 143 #define TVMET_IMPLEMENT_MACRO(NAME) \
sv 1:6799c07fe510 144 template<class T, std::size_t NRows, std::size_t NCols> \
sv 1:6799c07fe510 145 template<class E> \
sv 1:6799c07fe510 146 inline \
sv 1:6799c07fe510 147 Matrix<T, NRows, NCols>& \
sv 1:6799c07fe510 148 Matrix<T, NRows, NCols>::M_##NAME (const XprMatrix<E, Rows, Cols>& rhs) { \
sv 1:6799c07fe510 149 rhs.assign_to(*this, Fcnl_##NAME<value_type, typename E::value_type>()); \
sv 1:6799c07fe510 150 return *this; \
sv 1:6799c07fe510 151 }
sv 1:6799c07fe510 152
sv 1:6799c07fe510 153 TVMET_IMPLEMENT_MACRO(add_eq)
sv 1:6799c07fe510 154 TVMET_IMPLEMENT_MACRO(sub_eq)
sv 1:6799c07fe510 155 TVMET_IMPLEMENT_MACRO(mul_eq)
sv 1:6799c07fe510 156 TVMET_IMPLEMENT_MACRO(div_eq)
sv 1:6799c07fe510 157 TVMET_IMPLEMENT_MACRO(mod_eq)
sv 1:6799c07fe510 158 TVMET_IMPLEMENT_MACRO(xor_eq)
sv 1:6799c07fe510 159 TVMET_IMPLEMENT_MACRO(and_eq)
sv 1:6799c07fe510 160 TVMET_IMPLEMENT_MACRO(or_eq)
sv 1:6799c07fe510 161 TVMET_IMPLEMENT_MACRO(shl_eq)
sv 1:6799c07fe510 162 TVMET_IMPLEMENT_MACRO(shr_eq)
sv 1:6799c07fe510 163 #undef TVMET_IMPLEMENT_MACRO
sv 1:6799c07fe510 164
sv 1:6799c07fe510 165
sv 1:6799c07fe510 166 /*
sv 1:6799c07fe510 167 * aliased member functions (operators) with matrizes,
sv 1:6799c07fe510 168 * for use with +=,-= ... <<=
sv 1:6799c07fe510 169 */
sv 1:6799c07fe510 170 #define TVMET_IMPLEMENT_MACRO(NAME) \
sv 1:6799c07fe510 171 template<class T1, std::size_t NRows, std::size_t NCols> \
sv 1:6799c07fe510 172 template <class T2> \
sv 1:6799c07fe510 173 inline \
sv 1:6799c07fe510 174 Matrix<T1, NRows, NCols>& \
sv 1:6799c07fe510 175 Matrix<T1, NRows, NCols>::alias_##NAME (const Matrix<T2, Rows, Cols>& rhs) { \
sv 1:6799c07fe510 176 this->alias_##NAME( XprMatrix<typename Matrix<T2, Rows, Cols>::ConstReference, Rows, Cols>(rhs.const_ref()) ); \
sv 1:6799c07fe510 177 return *this; \
sv 1:6799c07fe510 178 }
sv 1:6799c07fe510 179
sv 1:6799c07fe510 180 TVMET_IMPLEMENT_MACRO(assign)
sv 1:6799c07fe510 181 TVMET_IMPLEMENT_MACRO(add_eq)
sv 1:6799c07fe510 182 TVMET_IMPLEMENT_MACRO(sub_eq)
sv 1:6799c07fe510 183 TVMET_IMPLEMENT_MACRO(mul_eq)
sv 1:6799c07fe510 184 TVMET_IMPLEMENT_MACRO(div_eq)
sv 1:6799c07fe510 185 #undef TVMET_IMPLEMENT_MACRO
sv 1:6799c07fe510 186
sv 1:6799c07fe510 187
sv 1:6799c07fe510 188 /*
sv 1:6799c07fe510 189 * aliased member functions (operators) with expressions,
sv 1:6799c07fe510 190 * for use width +=,-= ... <<= and aliased(),
sv 1:6799c07fe510 191 */
sv 1:6799c07fe510 192 #define TVMET_IMPLEMENT_MACRO(NAME) \
sv 1:6799c07fe510 193 template<class T, std::size_t NRows, std::size_t NCols> \
sv 1:6799c07fe510 194 template<class E> \
sv 1:6799c07fe510 195 inline \
sv 1:6799c07fe510 196 Matrix<T, NRows, NCols>& \
sv 1:6799c07fe510 197 Matrix<T, NRows, NCols>::alias_##NAME (const XprMatrix<E, Rows, Cols>& rhs) { \
sv 1:6799c07fe510 198 typedef Matrix<T, NRows, NCols> temp_type; \
sv 1:6799c07fe510 199 temp_type(rhs).assign_to(*this, Fcnl_##NAME<value_type, typename E::value_type>()); \
sv 1:6799c07fe510 200 return *this; \
sv 1:6799c07fe510 201 }
sv 1:6799c07fe510 202
sv 1:6799c07fe510 203 TVMET_IMPLEMENT_MACRO(assign)
sv 1:6799c07fe510 204 TVMET_IMPLEMENT_MACRO(add_eq)
sv 1:6799c07fe510 205 TVMET_IMPLEMENT_MACRO(sub_eq)
sv 1:6799c07fe510 206 TVMET_IMPLEMENT_MACRO(mul_eq)
sv 1:6799c07fe510 207 TVMET_IMPLEMENT_MACRO(div_eq)
sv 1:6799c07fe510 208 #undef TVMET_IMPLEMENT_MACRO
sv 1:6799c07fe510 209
sv 1:6799c07fe510 210
sv 1:6799c07fe510 211 } // namespace tvmet
sv 1:6799c07fe510 212
sv 1:6799c07fe510 213 #endif // TVMET_MATRIX_IMPL_H
sv 1:6799c07fe510 214
sv 1:6799c07fe510 215 // Local Variables:
sv 1:6799c07fe510 216 // mode:C++
sv 1:6799c07fe510 217 // tab-width:8
sv 1:6799c07fe510 218 // End: