working version with calibration done

Fork of Eurobot2013 by Oskar Weigl

Committer:
xiaxia686
Date:
Tue Apr 09 15:32:47 2013 +0000
Revision:
11:5ba926692210
Parent:
1:6799c07fe510
woking version (calibrated)

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: MatrixFunctions.h,v 1.44 2007-06-23 15:59:00 opetzold Exp $
sv 1:6799c07fe510 22 */
sv 1:6799c07fe510 23
sv 1:6799c07fe510 24 #ifndef TVMET_XPR_MATRIX_FUNCTIONS_H
sv 1:6799c07fe510 25 #define TVMET_XPR_MATRIX_FUNCTIONS_H
sv 1:6799c07fe510 26
sv 1:6799c07fe510 27 namespace tvmet {
sv 1:6799c07fe510 28
sv 1:6799c07fe510 29
sv 1:6799c07fe510 30 /* forwards */
sv 1:6799c07fe510 31 template<class T, std::size_t Rows, std::size_t Cols> class Matrix;
sv 1:6799c07fe510 32 template<class T, std::size_t Sz> class Vector;
sv 1:6799c07fe510 33 template<class E, std::size_t Sz> class XprVector;
sv 1:6799c07fe510 34 template<class E> class XprMatrixTranspose;
sv 1:6799c07fe510 35 template<class E, std::size_t Sz> class XprMatrixDiag;
sv 1:6799c07fe510 36 template<class E, std::size_t Rows, std::size_t Cols> class XprMatrixRow;
sv 1:6799c07fe510 37 template<class E, std::size_t Rows, std::size_t Cols> class XprMatrixCol;
sv 1:6799c07fe510 38
sv 1:6799c07fe510 39
sv 1:6799c07fe510 40 /*********************************************************
sv 1:6799c07fe510 41 * PART I: DECLARATION
sv 1:6799c07fe510 42 *********************************************************/
sv 1:6799c07fe510 43
sv 1:6799c07fe510 44
sv 1:6799c07fe510 45 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sv 1:6799c07fe510 46 * Matrix arithmetic functions add, sub, mul and div
sv 1:6799c07fe510 47 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
sv 1:6799c07fe510 48
sv 1:6799c07fe510 49
sv 1:6799c07fe510 50 /*
sv 1:6799c07fe510 51 * function(XprMatrix<E1, Rows, Cols>, XprMatrix<E2, Rows, Cols>)
sv 1:6799c07fe510 52 */
sv 1:6799c07fe510 53 #define TVMET_DECLARE_MACRO(NAME) \
sv 1:6799c07fe510 54 template<class E1, class E2, std::size_t Rows, std::size_t Cols> \
sv 1:6799c07fe510 55 XprMatrix< \
sv 1:6799c07fe510 56 XprBinOp< \
sv 1:6799c07fe510 57 Fcnl_##NAME<typename E1::value_type, typename E2::value_type>, \
sv 1:6799c07fe510 58 XprMatrix<E1, Rows, Cols>, \
sv 1:6799c07fe510 59 XprMatrix<E2, Rows, Cols> \
sv 1:6799c07fe510 60 >, \
sv 1:6799c07fe510 61 Rows, Cols \
sv 1:6799c07fe510 62 > \
sv 1:6799c07fe510 63 NAME (const XprMatrix<E1, Rows, Cols>& lhs, \
sv 1:6799c07fe510 64 const XprMatrix<E2, Rows, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 65
sv 1:6799c07fe510 66 TVMET_DECLARE_MACRO(add) // per se element wise
sv 1:6799c07fe510 67 TVMET_DECLARE_MACRO(sub) // per se element wise
sv 1:6799c07fe510 68 namespace element_wise {
sv 1:6799c07fe510 69 TVMET_DECLARE_MACRO(mul) // not defined for matrizes
sv 1:6799c07fe510 70 TVMET_DECLARE_MACRO(div) // not defined for matrizes
sv 1:6799c07fe510 71 }
sv 1:6799c07fe510 72
sv 1:6799c07fe510 73 #undef TVMET_DECLARE_MACRO
sv 1:6799c07fe510 74
sv 1:6799c07fe510 75
sv 1:6799c07fe510 76 /*
sv 1:6799c07fe510 77 * function(XprMatrix<E, Rows, Cols>, POD)
sv 1:6799c07fe510 78 * function(POD, XprMatrix<E, Rows, Cols>)
sv 1:6799c07fe510 79 * Note: - operations +,-,*,/ are per se element wise
sv 1:6799c07fe510 80 */
sv 1:6799c07fe510 81 #define TVMET_DECLARE_MACRO(NAME, POD) \
sv 1:6799c07fe510 82 template<class E, std::size_t Rows, std::size_t Cols> \
sv 1:6799c07fe510 83 XprMatrix< \
sv 1:6799c07fe510 84 XprBinOp< \
sv 1:6799c07fe510 85 Fcnl_##NAME<typename E::value_type, POD >, \
sv 1:6799c07fe510 86 XprMatrix<E, Rows, Cols>, \
sv 1:6799c07fe510 87 XprLiteral< POD > \
sv 1:6799c07fe510 88 >, \
sv 1:6799c07fe510 89 Rows, Cols \
sv 1:6799c07fe510 90 > \
sv 1:6799c07fe510 91 NAME (const XprMatrix<E, Rows, Cols>& lhs, \
sv 1:6799c07fe510 92 POD rhs) TVMET_CXX_ALWAYS_INLINE; \
sv 1:6799c07fe510 93 \
sv 1:6799c07fe510 94 template<class E, std::size_t Rows, std::size_t Cols> \
sv 1:6799c07fe510 95 XprMatrix< \
sv 1:6799c07fe510 96 XprBinOp< \
sv 1:6799c07fe510 97 Fcnl_##NAME< POD, typename E::value_type>, \
sv 1:6799c07fe510 98 XprLiteral< POD >, \
sv 1:6799c07fe510 99 XprMatrix<E, Rows, Cols> \
sv 1:6799c07fe510 100 >, \
sv 1:6799c07fe510 101 Rows, Cols \
sv 1:6799c07fe510 102 > \
sv 1:6799c07fe510 103 NAME (POD lhs, \
sv 1:6799c07fe510 104 const XprMatrix<E, Rows, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 105
sv 1:6799c07fe510 106 TVMET_DECLARE_MACRO(add, int)
sv 1:6799c07fe510 107 TVMET_DECLARE_MACRO(sub, int)
sv 1:6799c07fe510 108 TVMET_DECLARE_MACRO(mul, int)
sv 1:6799c07fe510 109 TVMET_DECLARE_MACRO(div, int)
sv 1:6799c07fe510 110
sv 1:6799c07fe510 111 #if defined(TVMET_HAVE_LONG_LONG)
sv 1:6799c07fe510 112 TVMET_DECLARE_MACRO(add, long long int)
sv 1:6799c07fe510 113 TVMET_DECLARE_MACRO(sub, long long int)
sv 1:6799c07fe510 114 TVMET_DECLARE_MACRO(mul, long long int)
sv 1:6799c07fe510 115 TVMET_DECLARE_MACRO(div, long long int)
sv 1:6799c07fe510 116 #endif
sv 1:6799c07fe510 117
sv 1:6799c07fe510 118 TVMET_DECLARE_MACRO(add, float)
sv 1:6799c07fe510 119 TVMET_DECLARE_MACRO(sub, float)
sv 1:6799c07fe510 120 TVMET_DECLARE_MACRO(mul, float)
sv 1:6799c07fe510 121 TVMET_DECLARE_MACRO(div, float)
sv 1:6799c07fe510 122
sv 1:6799c07fe510 123 TVMET_DECLARE_MACRO(add, double)
sv 1:6799c07fe510 124 TVMET_DECLARE_MACRO(sub, double)
sv 1:6799c07fe510 125 TVMET_DECLARE_MACRO(mul, double)
sv 1:6799c07fe510 126 TVMET_DECLARE_MACRO(div, double)
sv 1:6799c07fe510 127
sv 1:6799c07fe510 128 #if defined(TVMET_HAVE_LONG_DOUBLE)
sv 1:6799c07fe510 129 TVMET_DECLARE_MACRO(add, long double)
sv 1:6799c07fe510 130 TVMET_DECLARE_MACRO(sub, long double)
sv 1:6799c07fe510 131 TVMET_DECLARE_MACRO(mul, long double)
sv 1:6799c07fe510 132 TVMET_DECLARE_MACRO(div, long double)
sv 1:6799c07fe510 133 #endif
sv 1:6799c07fe510 134
sv 1:6799c07fe510 135 #undef TVMET_DECLARE_MACRO
sv 1:6799c07fe510 136
sv 1:6799c07fe510 137
sv 1:6799c07fe510 138 #if defined(TVMET_HAVE_COMPLEX)
sv 1:6799c07fe510 139 /*
sv 1:6799c07fe510 140 * function(XprMatrix<E, Rows, Cols>, complex<T>)
sv 1:6799c07fe510 141 * function(complex<T>, XprMatrix<E, Rows, Cols>)
sv 1:6799c07fe510 142 * Note: - operations +,-,*,/ are per se element wise
sv 1:6799c07fe510 143 * \todo type promotion
sv 1:6799c07fe510 144 */
sv 1:6799c07fe510 145 #define TVMET_DECLARE_MACRO(NAME) \
sv 1:6799c07fe510 146 template<class E, class T, std::size_t Rows, std::size_t Cols> \
sv 1:6799c07fe510 147 XprMatrix< \
sv 1:6799c07fe510 148 XprBinOp< \
sv 1:6799c07fe510 149 Fcnl_##NAME<typename E::value_type, std::complex<T> >, \
sv 1:6799c07fe510 150 XprMatrix<E, Rows, Cols>, \
sv 1:6799c07fe510 151 XprLiteral< std::complex<T> > \
sv 1:6799c07fe510 152 >, \
sv 1:6799c07fe510 153 Rows, Cols \
sv 1:6799c07fe510 154 > \
sv 1:6799c07fe510 155 NAME (const XprMatrix<E, Rows, Cols>& lhs, \
sv 1:6799c07fe510 156 const std::complex<T>& rhs) TVMET_CXX_ALWAYS_INLINE; \
sv 1:6799c07fe510 157 \
sv 1:6799c07fe510 158 template<class T, class E, std::size_t Rows, std::size_t Cols> \
sv 1:6799c07fe510 159 XprMatrix< \
sv 1:6799c07fe510 160 XprBinOp< \
sv 1:6799c07fe510 161 Fcnl_##NAME< std::complex<T>, typename E::value_type>, \
sv 1:6799c07fe510 162 XprLiteral< std::complex<T> >, \
sv 1:6799c07fe510 163 XprMatrix<E, Rows, Cols> \
sv 1:6799c07fe510 164 >, \
sv 1:6799c07fe510 165 Rows, Cols \
sv 1:6799c07fe510 166 > \
sv 1:6799c07fe510 167 NAME (const std::complex<T>& lhs, \
sv 1:6799c07fe510 168 const XprMatrix<E, Rows, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 169
sv 1:6799c07fe510 170 TVMET_DECLARE_MACRO(add)
sv 1:6799c07fe510 171 TVMET_DECLARE_MACRO(sub)
sv 1:6799c07fe510 172 TVMET_DECLARE_MACRO(mul)
sv 1:6799c07fe510 173 TVMET_DECLARE_MACRO(div)
sv 1:6799c07fe510 174
sv 1:6799c07fe510 175 #undef TVMET_DECLARE_MACRO
sv 1:6799c07fe510 176
sv 1:6799c07fe510 177 #endif // defined(TVMET_HAVE_COMPLEX)
sv 1:6799c07fe510 178
sv 1:6799c07fe510 179
sv 1:6799c07fe510 180 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sv 1:6799c07fe510 181 * matrix prod( ... ) functions
sv 1:6799c07fe510 182 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
sv 1:6799c07fe510 183
sv 1:6799c07fe510 184
sv 1:6799c07fe510 185 template<class E1, std::size_t Rows1, std::size_t Cols1,
sv 1:6799c07fe510 186 class E2, std::size_t Cols2>
sv 1:6799c07fe510 187 XprMatrix<
sv 1:6799c07fe510 188 XprMMProduct<
sv 1:6799c07fe510 189 XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1)
sv 1:6799c07fe510 190 XprMatrix<E2, Cols1, Cols2>, Cols2
sv 1:6799c07fe510 191 >,
sv 1:6799c07fe510 192 Rows1, Cols2 // return Dim
sv 1:6799c07fe510 193 >
sv 1:6799c07fe510 194 prod(const XprMatrix<E1, Rows1, Cols1>& lhs,
sv 1:6799c07fe510 195 const XprMatrix<E2, Cols1, Cols2>& rhs) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 196
sv 1:6799c07fe510 197
sv 1:6799c07fe510 198 template<class E1, std::size_t Rows1, std::size_t Cols1,
sv 1:6799c07fe510 199 class E2, std::size_t Cols2>
sv 1:6799c07fe510 200 XprMatrix<
sv 1:6799c07fe510 201 XprMMProductTransposed<
sv 1:6799c07fe510 202 XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1)
sv 1:6799c07fe510 203 XprMatrix<E2, Cols1, Cols2>, Cols2 // M2(Cols1, Cols2)
sv 1:6799c07fe510 204 >,
sv 1:6799c07fe510 205 Cols2, Rows1 // return Dim
sv 1:6799c07fe510 206 >
sv 1:6799c07fe510 207 trans_prod(const XprMatrix<E1, Rows1, Cols1>& lhs,
sv 1:6799c07fe510 208 const XprMatrix<E2, Cols1, Cols2>& rhs) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 209
sv 1:6799c07fe510 210
sv 1:6799c07fe510 211 template<class E1, std::size_t Rows1, std::size_t Cols1,
sv 1:6799c07fe510 212 class E2, std::size_t Cols2> // Rows2 = Rows1
sv 1:6799c07fe510 213 XprMatrix<
sv 1:6799c07fe510 214 XprMtMProduct<
sv 1:6799c07fe510 215 XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1)
sv 1:6799c07fe510 216 XprMatrix<E2, Rows1, Cols2>, Cols2 // M2(Rows1, Cols2)
sv 1:6799c07fe510 217 >,
sv 1:6799c07fe510 218 Cols1, Cols2 // return Dim
sv 1:6799c07fe510 219 >
sv 1:6799c07fe510 220 MtM_prod(const XprMatrix<E1, Rows1, Cols1>& lhs,
sv 1:6799c07fe510 221 const XprMatrix<E2, Rows1, Cols2>& rhs) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 222
sv 1:6799c07fe510 223
sv 1:6799c07fe510 224 template<class E1, std::size_t Rows1, std::size_t Cols1,
sv 1:6799c07fe510 225 class E2, std::size_t Rows2> // Cols2 = Cols1
sv 1:6799c07fe510 226 XprMatrix<
sv 1:6799c07fe510 227 XprMMtProduct<
sv 1:6799c07fe510 228 XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1)
sv 1:6799c07fe510 229 XprMatrix<E2, Rows2, Cols1>, Cols1 // M2(Rows2, Cols1)
sv 1:6799c07fe510 230 >,
sv 1:6799c07fe510 231 Rows1, Rows2 // return Dim
sv 1:6799c07fe510 232 >
sv 1:6799c07fe510 233 MMt_prod(const XprMatrix<E1, Rows1, Cols1>& lhs,
sv 1:6799c07fe510 234 const XprMatrix<E2, Rows2, Cols1>& rhs) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 235
sv 1:6799c07fe510 236
sv 1:6799c07fe510 237 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sv 1:6799c07fe510 238 * matrix-vector specific prod( ... ) functions
sv 1:6799c07fe510 239 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
sv 1:6799c07fe510 240
sv 1:6799c07fe510 241
sv 1:6799c07fe510 242 template<class E1, std::size_t Rows, std::size_t Cols,
sv 1:6799c07fe510 243 class E2>
sv 1:6799c07fe510 244 XprVector<
sv 1:6799c07fe510 245 XprMVProduct<
sv 1:6799c07fe510 246 XprMatrix<E1, Rows, Cols>, Rows, Cols,
sv 1:6799c07fe510 247 XprVector<E2, Cols>
sv 1:6799c07fe510 248 >,
sv 1:6799c07fe510 249 Rows
sv 1:6799c07fe510 250 >
sv 1:6799c07fe510 251 prod(const XprMatrix<E1, Rows, Cols>& lhs,
sv 1:6799c07fe510 252 const XprVector<E2, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 253
sv 1:6799c07fe510 254
sv 1:6799c07fe510 255 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sv 1:6799c07fe510 256 * matrix specific functions
sv 1:6799c07fe510 257 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
sv 1:6799c07fe510 258
sv 1:6799c07fe510 259
sv 1:6799c07fe510 260 template<class E, std::size_t Rows, std::size_t Cols>
sv 1:6799c07fe510 261 XprMatrix<
sv 1:6799c07fe510 262 XprMatrixTranspose<
sv 1:6799c07fe510 263 XprMatrix<E, Rows, Cols>
sv 1:6799c07fe510 264 >,
sv 1:6799c07fe510 265 Cols, Rows
sv 1:6799c07fe510 266 >
sv 1:6799c07fe510 267 trans(const XprMatrix<E, Rows, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 268
sv 1:6799c07fe510 269
sv 1:6799c07fe510 270 template<class E, std::size_t Sz>
sv 1:6799c07fe510 271 typename NumericTraits<typename E::value_type>::sum_type
sv 1:6799c07fe510 272 trace(const XprMatrix<E, Sz, Sz>& m) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 273
sv 1:6799c07fe510 274
sv 1:6799c07fe510 275 template<class E, std::size_t Rows, std::size_t Cols>
sv 1:6799c07fe510 276 XprVector<
sv 1:6799c07fe510 277 XprMatrixRow<
sv 1:6799c07fe510 278 XprMatrix<E, Rows, Cols>,
sv 1:6799c07fe510 279 Rows, Cols
sv 1:6799c07fe510 280 >,
sv 1:6799c07fe510 281 Cols
sv 1:6799c07fe510 282 >
sv 1:6799c07fe510 283 row(const XprMatrix<E, Rows, Cols>& m,
sv 1:6799c07fe510 284 std::size_t no) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 285
sv 1:6799c07fe510 286
sv 1:6799c07fe510 287 template<class E, std::size_t Rows, std::size_t Cols>
sv 1:6799c07fe510 288 XprVector<
sv 1:6799c07fe510 289 XprMatrixCol<
sv 1:6799c07fe510 290 XprMatrix<E, Rows, Cols>,
sv 1:6799c07fe510 291 Rows, Cols
sv 1:6799c07fe510 292 >,
sv 1:6799c07fe510 293 Rows
sv 1:6799c07fe510 294 >
sv 1:6799c07fe510 295 col(const XprMatrix<E, Rows, Cols>& m, std::size_t no) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 296
sv 1:6799c07fe510 297
sv 1:6799c07fe510 298 template<class E, std::size_t Sz>
sv 1:6799c07fe510 299 XprVector<
sv 1:6799c07fe510 300 XprMatrixDiag<
sv 1:6799c07fe510 301 XprMatrix<E, Sz, Sz>,
sv 1:6799c07fe510 302 Sz
sv 1:6799c07fe510 303 >,
sv 1:6799c07fe510 304 Sz
sv 1:6799c07fe510 305 >
sv 1:6799c07fe510 306 diag(const XprMatrix<E, Sz, Sz>& m) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 307
sv 1:6799c07fe510 308
sv 1:6799c07fe510 309 /*********************************************************
sv 1:6799c07fe510 310 * PART II: IMPLEMENTATION
sv 1:6799c07fe510 311 *********************************************************/
sv 1:6799c07fe510 312
sv 1:6799c07fe510 313
sv 1:6799c07fe510 314 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sv 1:6799c07fe510 315 * Matrix arithmetic functions add, sub, mul and div
sv 1:6799c07fe510 316 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
sv 1:6799c07fe510 317
sv 1:6799c07fe510 318
sv 1:6799c07fe510 319 /*
sv 1:6799c07fe510 320 * function(XprMatrix<E1, Rows, Cols>, XprMatrix<E2, Rows, Cols>)
sv 1:6799c07fe510 321 */
sv 1:6799c07fe510 322 #define TVMET_IMPLEMENT_MACRO(NAME) \
sv 1:6799c07fe510 323 template<class E1, class E2, std::size_t Rows, std::size_t Cols> \
sv 1:6799c07fe510 324 inline \
sv 1:6799c07fe510 325 XprMatrix< \
sv 1:6799c07fe510 326 XprBinOp< \
sv 1:6799c07fe510 327 Fcnl_##NAME<typename E1::value_type, typename E2::value_type>, \
sv 1:6799c07fe510 328 XprMatrix<E1, Rows, Cols>, \
sv 1:6799c07fe510 329 XprMatrix<E2, Rows, Cols> \
sv 1:6799c07fe510 330 >, \
sv 1:6799c07fe510 331 Rows, Cols \
sv 1:6799c07fe510 332 > \
sv 1:6799c07fe510 333 NAME (const XprMatrix<E1, Rows, Cols>& lhs, \
sv 1:6799c07fe510 334 const XprMatrix<E2, Rows, Cols>& rhs) { \
sv 1:6799c07fe510 335 typedef XprBinOp< \
sv 1:6799c07fe510 336 Fcnl_##NAME<typename E1::value_type, typename E2::value_type>, \
sv 1:6799c07fe510 337 XprMatrix<E1, Rows, Cols>, \
sv 1:6799c07fe510 338 XprMatrix<E2, Rows, Cols> \
sv 1:6799c07fe510 339 > expr_type; \
sv 1:6799c07fe510 340 return XprMatrix<expr_type, Rows, Cols>(expr_type(lhs, rhs)); \
sv 1:6799c07fe510 341 }
sv 1:6799c07fe510 342
sv 1:6799c07fe510 343 TVMET_IMPLEMENT_MACRO(add) // per se element wise
sv 1:6799c07fe510 344 TVMET_IMPLEMENT_MACRO(sub) // per se element wise
sv 1:6799c07fe510 345 namespace element_wise {
sv 1:6799c07fe510 346 TVMET_IMPLEMENT_MACRO(mul) // not defined for matrizes
sv 1:6799c07fe510 347 TVMET_IMPLEMENT_MACRO(div) // not defined for matrizes
sv 1:6799c07fe510 348 }
sv 1:6799c07fe510 349
sv 1:6799c07fe510 350 #undef TVMET_IMPLEMENT_MACRO
sv 1:6799c07fe510 351
sv 1:6799c07fe510 352
sv 1:6799c07fe510 353 /*
sv 1:6799c07fe510 354 * function(XprMatrix<E, Rows, Cols>, POD)
sv 1:6799c07fe510 355 * function(POD, XprMatrix<E, Rows, Cols>)
sv 1:6799c07fe510 356 * Note: - operations +,-,*,/ are per se element wise
sv 1:6799c07fe510 357 */
sv 1:6799c07fe510 358 #define TVMET_IMPLEMENT_MACRO(NAME, POD) \
sv 1:6799c07fe510 359 template<class E, std::size_t Rows, std::size_t Cols> \
sv 1:6799c07fe510 360 inline \
sv 1:6799c07fe510 361 XprMatrix< \
sv 1:6799c07fe510 362 XprBinOp< \
sv 1:6799c07fe510 363 Fcnl_##NAME<typename E::value_type, POD >, \
sv 1:6799c07fe510 364 XprMatrix<E, Rows, Cols>, \
sv 1:6799c07fe510 365 XprLiteral< POD > \
sv 1:6799c07fe510 366 >, \
sv 1:6799c07fe510 367 Rows, Cols \
sv 1:6799c07fe510 368 > \
sv 1:6799c07fe510 369 NAME (const XprMatrix<E, Rows, Cols>& lhs, POD rhs) { \
sv 1:6799c07fe510 370 typedef XprBinOp< \
sv 1:6799c07fe510 371 Fcnl_##NAME<typename E::value_type, POD >, \
sv 1:6799c07fe510 372 XprMatrix<E, Rows, Cols>, \
sv 1:6799c07fe510 373 XprLiteral< POD > \
sv 1:6799c07fe510 374 > expr_type; \
sv 1:6799c07fe510 375 return XprMatrix<expr_type, Rows, Cols>( \
sv 1:6799c07fe510 376 expr_type(lhs, XprLiteral< POD >(rhs))); \
sv 1:6799c07fe510 377 } \
sv 1:6799c07fe510 378 \
sv 1:6799c07fe510 379 template<class E, std::size_t Rows, std::size_t Cols> \
sv 1:6799c07fe510 380 inline \
sv 1:6799c07fe510 381 XprMatrix< \
sv 1:6799c07fe510 382 XprBinOp< \
sv 1:6799c07fe510 383 Fcnl_##NAME< POD, typename E::value_type>, \
sv 1:6799c07fe510 384 XprLiteral< POD >, \
sv 1:6799c07fe510 385 XprMatrix<E, Rows, Cols> \
sv 1:6799c07fe510 386 >, \
sv 1:6799c07fe510 387 Rows, Cols \
sv 1:6799c07fe510 388 > \
sv 1:6799c07fe510 389 NAME (POD lhs, const XprMatrix<E, Rows, Cols>& rhs) { \
sv 1:6799c07fe510 390 typedef XprBinOp< \
sv 1:6799c07fe510 391 Fcnl_##NAME< POD, typename E::value_type>, \
sv 1:6799c07fe510 392 XprLiteral< POD >, \
sv 1:6799c07fe510 393 XprMatrix<E, Rows, Cols> \
sv 1:6799c07fe510 394 > expr_type; \
sv 1:6799c07fe510 395 return XprMatrix<expr_type, Rows, Cols>( \
sv 1:6799c07fe510 396 expr_type(XprLiteral< POD >(lhs), rhs)); \
sv 1:6799c07fe510 397 }
sv 1:6799c07fe510 398
sv 1:6799c07fe510 399 TVMET_IMPLEMENT_MACRO(add, int)
sv 1:6799c07fe510 400 TVMET_IMPLEMENT_MACRO(sub, int)
sv 1:6799c07fe510 401 TVMET_IMPLEMENT_MACRO(mul, int)
sv 1:6799c07fe510 402 TVMET_IMPLEMENT_MACRO(div, int)
sv 1:6799c07fe510 403
sv 1:6799c07fe510 404 #if defined(TVMET_HAVE_LONG_LONG)
sv 1:6799c07fe510 405 TVMET_IMPLEMENT_MACRO(add, long long int)
sv 1:6799c07fe510 406 TVMET_IMPLEMENT_MACRO(sub, long long int)
sv 1:6799c07fe510 407 TVMET_IMPLEMENT_MACRO(mul, long long int)
sv 1:6799c07fe510 408 TVMET_IMPLEMENT_MACRO(div, long long int)
sv 1:6799c07fe510 409 #endif
sv 1:6799c07fe510 410
sv 1:6799c07fe510 411 TVMET_IMPLEMENT_MACRO(add, float)
sv 1:6799c07fe510 412 TVMET_IMPLEMENT_MACRO(sub, float)
sv 1:6799c07fe510 413 TVMET_IMPLEMENT_MACRO(mul, float)
sv 1:6799c07fe510 414 TVMET_IMPLEMENT_MACRO(div, float)
sv 1:6799c07fe510 415
sv 1:6799c07fe510 416 TVMET_IMPLEMENT_MACRO(add, double)
sv 1:6799c07fe510 417 TVMET_IMPLEMENT_MACRO(sub, double)
sv 1:6799c07fe510 418 TVMET_IMPLEMENT_MACRO(mul, double)
sv 1:6799c07fe510 419 TVMET_IMPLEMENT_MACRO(div, double)
sv 1:6799c07fe510 420
sv 1:6799c07fe510 421 #if defined(TVMET_HAVE_LONG_DOUBLE)
sv 1:6799c07fe510 422 TVMET_IMPLEMENT_MACRO(add, long double)
sv 1:6799c07fe510 423 TVMET_IMPLEMENT_MACRO(sub, long double)
sv 1:6799c07fe510 424 TVMET_IMPLEMENT_MACRO(mul, long double)
sv 1:6799c07fe510 425 TVMET_IMPLEMENT_MACRO(div, long double)
sv 1:6799c07fe510 426 #endif
sv 1:6799c07fe510 427
sv 1:6799c07fe510 428 #undef TVMET_IMPLEMENT_MACRO
sv 1:6799c07fe510 429
sv 1:6799c07fe510 430
sv 1:6799c07fe510 431 #if defined(TVMET_HAVE_COMPLEX)
sv 1:6799c07fe510 432 /*
sv 1:6799c07fe510 433 * function(XprMatrix<E, Rows, Cols>, complex<T>)
sv 1:6799c07fe510 434 * function(complex<T>, XprMatrix<E, Rows, Cols>)
sv 1:6799c07fe510 435 * Note: - operations +,-,*,/ are per se element wise
sv 1:6799c07fe510 436 * \todo type promotion
sv 1:6799c07fe510 437 */
sv 1:6799c07fe510 438 #define TVMET_IMPLEMENT_MACRO(NAME) \
sv 1:6799c07fe510 439 template<class E, class T, std::size_t Rows, std::size_t Cols> \
sv 1:6799c07fe510 440 inline \
sv 1:6799c07fe510 441 XprMatrix< \
sv 1:6799c07fe510 442 XprBinOp< \
sv 1:6799c07fe510 443 Fcnl_##NAME<typename E::value_type, std::complex<T> >, \
sv 1:6799c07fe510 444 XprMatrix<E, Rows, Cols>, \
sv 1:6799c07fe510 445 XprLiteral< std::complex<T> > \
sv 1:6799c07fe510 446 >, \
sv 1:6799c07fe510 447 Rows, Cols \
sv 1:6799c07fe510 448 > \
sv 1:6799c07fe510 449 NAME (const XprMatrix<E, Rows, Cols>& lhs, \
sv 1:6799c07fe510 450 const std::complex<T>& rhs) { \
sv 1:6799c07fe510 451 typedef XprBinOp< \
sv 1:6799c07fe510 452 Fcnl_##NAME<typename E::value_type, std::complex<T> >, \
sv 1:6799c07fe510 453 XprMatrix<E, Rows, Cols>, \
sv 1:6799c07fe510 454 XprLiteral< std::complex<T> > \
sv 1:6799c07fe510 455 > expr_type; \
sv 1:6799c07fe510 456 return XprMatrix<expr_type, Rows, Cols>( \
sv 1:6799c07fe510 457 expr_type(lhs, XprLiteral< std::complex<T> >(rhs))); \
sv 1:6799c07fe510 458 } \
sv 1:6799c07fe510 459 \
sv 1:6799c07fe510 460 template<class T, class E, std::size_t Rows, std::size_t Cols> \
sv 1:6799c07fe510 461 inline \
sv 1:6799c07fe510 462 XprMatrix< \
sv 1:6799c07fe510 463 XprBinOp< \
sv 1:6799c07fe510 464 Fcnl_##NAME< std::complex<T>, typename E::value_type>, \
sv 1:6799c07fe510 465 XprLiteral< std::complex<T> >, \
sv 1:6799c07fe510 466 XprMatrix<E, Rows, Cols> \
sv 1:6799c07fe510 467 >, \
sv 1:6799c07fe510 468 Rows, Cols \
sv 1:6799c07fe510 469 > \
sv 1:6799c07fe510 470 NAME (const std::complex<T>& lhs, \
sv 1:6799c07fe510 471 const XprMatrix<E, Rows, Cols>& rhs) { \
sv 1:6799c07fe510 472 typedef XprBinOp< \
sv 1:6799c07fe510 473 Fcnl_##NAME< std::complex<T>, typename E::value_type>, \
sv 1:6799c07fe510 474 XprLiteral< std::complex<T> >, \
sv 1:6799c07fe510 475 XprMatrix<E, Rows, Cols> \
sv 1:6799c07fe510 476 > expr_type; \
sv 1:6799c07fe510 477 return XprMatrix<expr_type, Rows, Cols>( \
sv 1:6799c07fe510 478 expr_type(XprLiteral< std::complex<T> >(lhs), rhs)); \
sv 1:6799c07fe510 479 }
sv 1:6799c07fe510 480
sv 1:6799c07fe510 481 TVMET_IMPLEMENT_MACRO(add)
sv 1:6799c07fe510 482 TVMET_IMPLEMENT_MACRO(sub)
sv 1:6799c07fe510 483 TVMET_IMPLEMENT_MACRO(mul)
sv 1:6799c07fe510 484 TVMET_IMPLEMENT_MACRO(div)
sv 1:6799c07fe510 485
sv 1:6799c07fe510 486 #undef TVMET_IMPLEMENT_MACRO
sv 1:6799c07fe510 487
sv 1:6799c07fe510 488 #endif // defined(TVMET_HAVE_COMPLEX)
sv 1:6799c07fe510 489
sv 1:6799c07fe510 490
sv 1:6799c07fe510 491 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sv 1:6799c07fe510 492 * matrix prod( ... ) functions
sv 1:6799c07fe510 493 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
sv 1:6799c07fe510 494
sv 1:6799c07fe510 495
sv 1:6799c07fe510 496 /**
sv 1:6799c07fe510 497 * \fn prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Cols1, Cols2>& rhs)
sv 1:6799c07fe510 498 * \brief Evaluate the product of two XprMatrix.
sv 1:6799c07fe510 499 * Perform on given Matrix M1 and M2:
sv 1:6799c07fe510 500 * \f[
sv 1:6799c07fe510 501 * M_1\,M_2
sv 1:6799c07fe510 502 * \f]
sv 1:6799c07fe510 503 * \note The numer of Rows2 has to be equal to Cols1.
sv 1:6799c07fe510 504 * \ingroup _binary_function
sv 1:6799c07fe510 505 */
sv 1:6799c07fe510 506 template<class E1, std::size_t Rows1, std::size_t Cols1,
sv 1:6799c07fe510 507 class E2, std::size_t Cols2>
sv 1:6799c07fe510 508 inline
sv 1:6799c07fe510 509 XprMatrix<
sv 1:6799c07fe510 510 XprMMProduct<
sv 1:6799c07fe510 511 XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1)
sv 1:6799c07fe510 512 XprMatrix<E2, Cols1, Cols2>, Cols2
sv 1:6799c07fe510 513 >,
sv 1:6799c07fe510 514 Rows1, Cols2 // return Dim
sv 1:6799c07fe510 515 >
sv 1:6799c07fe510 516 prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Cols1, Cols2>& rhs) {
sv 1:6799c07fe510 517 typedef XprMMProduct<
sv 1:6799c07fe510 518 XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1,
sv 1:6799c07fe510 519 XprMatrix<E2, Cols1, Cols2>, Cols2
sv 1:6799c07fe510 520 > expr_type;
sv 1:6799c07fe510 521 return XprMatrix<expr_type, Rows1, Cols2>(expr_type(lhs, rhs));
sv 1:6799c07fe510 522 }
sv 1:6799c07fe510 523
sv 1:6799c07fe510 524
sv 1:6799c07fe510 525 /**
sv 1:6799c07fe510 526 * \fn trans_prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Cols1, Cols2>& rhs)
sv 1:6799c07fe510 527 * \brief Function for the trans(matrix-matrix-product)
sv 1:6799c07fe510 528 * Perform on given Matrix M1 and M2:
sv 1:6799c07fe510 529 * \f[
sv 1:6799c07fe510 530 * (M_1\,M_2)^T
sv 1:6799c07fe510 531 * \f]
sv 1:6799c07fe510 532 * \note The numer of Rows2 has to be equal to Cols1.
sv 1:6799c07fe510 533 * \ingroup _binary_function
sv 1:6799c07fe510 534 */
sv 1:6799c07fe510 535 template<class E1, std::size_t Rows1, std::size_t Cols1,
sv 1:6799c07fe510 536 class E2, std::size_t Cols2>
sv 1:6799c07fe510 537 inline
sv 1:6799c07fe510 538 XprMatrix<
sv 1:6799c07fe510 539 XprMMProductTransposed<
sv 1:6799c07fe510 540 XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1)
sv 1:6799c07fe510 541 XprMatrix<E2, Cols1, Cols2>, Cols2 // M2(Cols1, Cols2)
sv 1:6799c07fe510 542 >,
sv 1:6799c07fe510 543 Cols2, Rows1 // return Dim
sv 1:6799c07fe510 544 >
sv 1:6799c07fe510 545 trans_prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Cols1, Cols2>& rhs) {
sv 1:6799c07fe510 546 typedef XprMMProductTransposed<
sv 1:6799c07fe510 547 XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1,
sv 1:6799c07fe510 548 XprMatrix<E2, Cols1, Cols2>, Cols2
sv 1:6799c07fe510 549 > expr_type;
sv 1:6799c07fe510 550 return XprMatrix<expr_type, Cols2, Rows1>(expr_type(lhs, rhs));
sv 1:6799c07fe510 551 }
sv 1:6799c07fe510 552
sv 1:6799c07fe510 553
sv 1:6799c07fe510 554 /**
sv 1:6799c07fe510 555 * \fn MtM_prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Rows1, Cols2>& rhs)
sv 1:6799c07fe510 556 * \brief Function for the trans(matrix)-matrix-product.
sv 1:6799c07fe510 557 * using formula
sv 1:6799c07fe510 558 * \f[
sv 1:6799c07fe510 559 * M_1^{T}\,M_2
sv 1:6799c07fe510 560 * \f]
sv 1:6799c07fe510 561 * \note The number of cols of matrix 2 have to be equal to number of rows of
sv 1:6799c07fe510 562 * matrix 1, since matrix 1 is trans - the result is a (Cols1 x Cols2)
sv 1:6799c07fe510 563 * matrix.
sv 1:6799c07fe510 564 * \ingroup _binary_function
sv 1:6799c07fe510 565 */
sv 1:6799c07fe510 566 template<class E1, std::size_t Rows1, std::size_t Cols1,
sv 1:6799c07fe510 567 class E2, std::size_t Cols2> // Rows2 = Rows1
sv 1:6799c07fe510 568 inline
sv 1:6799c07fe510 569 XprMatrix<
sv 1:6799c07fe510 570 XprMtMProduct<
sv 1:6799c07fe510 571 XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1)
sv 1:6799c07fe510 572 XprMatrix<E2, Rows1, Cols2>, Cols2 // M2(Rows1, Cols2)
sv 1:6799c07fe510 573 >,
sv 1:6799c07fe510 574 Cols1, Cols2 // return Dim
sv 1:6799c07fe510 575 >
sv 1:6799c07fe510 576 MtM_prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Rows1, Cols2>& rhs) {
sv 1:6799c07fe510 577 typedef XprMtMProduct<
sv 1:6799c07fe510 578 XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1,
sv 1:6799c07fe510 579 XprMatrix<E2, Rows1, Cols2>, Cols2
sv 1:6799c07fe510 580 > expr_type;
sv 1:6799c07fe510 581 return XprMatrix<expr_type, Cols1, Cols2>(expr_type(lhs, rhs));
sv 1:6799c07fe510 582 }
sv 1:6799c07fe510 583
sv 1:6799c07fe510 584
sv 1:6799c07fe510 585 /**
sv 1:6799c07fe510 586 * \fn MMt_prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Rows2, Cols1>& rhs)
sv 1:6799c07fe510 587 * \brief Function for the matrix-trans(matrix)-product.
sv 1:6799c07fe510 588 * \ingroup _binary_function
sv 1:6799c07fe510 589 * \note The cols2 has to be equal to cols1.
sv 1:6799c07fe510 590 */
sv 1:6799c07fe510 591 template<class E1, std::size_t Rows1, std::size_t Cols1,
sv 1:6799c07fe510 592 class E2, std::size_t Rows2> // Cols2 = Cols1
sv 1:6799c07fe510 593 inline
sv 1:6799c07fe510 594 XprMatrix<
sv 1:6799c07fe510 595 XprMMtProduct<
sv 1:6799c07fe510 596 XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1)
sv 1:6799c07fe510 597 XprMatrix<E2, Rows2, Cols1>, Cols1 // M2(Rows2, Cols1)
sv 1:6799c07fe510 598 >,
sv 1:6799c07fe510 599 Rows1, Rows2 // return Dim
sv 1:6799c07fe510 600 >
sv 1:6799c07fe510 601 MMt_prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Rows2, Cols1>& rhs) {
sv 1:6799c07fe510 602 typedef XprMMtProduct<
sv 1:6799c07fe510 603 XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1,
sv 1:6799c07fe510 604 XprMatrix<E2, Rows2, Cols1>, Cols1
sv 1:6799c07fe510 605 > expr_type;
sv 1:6799c07fe510 606 return XprMatrix<expr_type, Rows1, Rows2>(expr_type(lhs, rhs));
sv 1:6799c07fe510 607 }
sv 1:6799c07fe510 608
sv 1:6799c07fe510 609
sv 1:6799c07fe510 610 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sv 1:6799c07fe510 611 * matrix-vector specific prod( ... ) functions
sv 1:6799c07fe510 612 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
sv 1:6799c07fe510 613
sv 1:6799c07fe510 614
sv 1:6799c07fe510 615 /**
sv 1:6799c07fe510 616 * \fn prod(const XprMatrix<E1, Rows, Cols>& lhs, const XprVector<E2, Cols>& rhs)
sv 1:6799c07fe510 617 * \brief Evaluate the product of XprMatrix and XprVector.
sv 1:6799c07fe510 618 * \ingroup _binary_function
sv 1:6799c07fe510 619 */
sv 1:6799c07fe510 620 template<class E1, std::size_t Rows, std::size_t Cols,
sv 1:6799c07fe510 621 class E2>
sv 1:6799c07fe510 622 inline
sv 1:6799c07fe510 623 XprVector<
sv 1:6799c07fe510 624 XprMVProduct<
sv 1:6799c07fe510 625 XprMatrix<E1, Rows, Cols>, Rows, Cols,
sv 1:6799c07fe510 626 XprVector<E2, Cols>
sv 1:6799c07fe510 627 >,
sv 1:6799c07fe510 628 Rows
sv 1:6799c07fe510 629 >
sv 1:6799c07fe510 630 prod(const XprMatrix<E1, Rows, Cols>& lhs, const XprVector<E2, Cols>& rhs) {
sv 1:6799c07fe510 631 typedef XprMVProduct<
sv 1:6799c07fe510 632 XprMatrix<E1, Rows, Cols>, Rows, Cols,
sv 1:6799c07fe510 633 XprVector<E2, Cols>
sv 1:6799c07fe510 634 > expr_type;
sv 1:6799c07fe510 635 return XprVector<expr_type, Rows>(expr_type(lhs, rhs));
sv 1:6799c07fe510 636 }
sv 1:6799c07fe510 637
sv 1:6799c07fe510 638
sv 1:6799c07fe510 639 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sv 1:6799c07fe510 640 * matrix specific functions
sv 1:6799c07fe510 641 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
sv 1:6799c07fe510 642
sv 1:6799c07fe510 643
sv 1:6799c07fe510 644 /**
sv 1:6799c07fe510 645 * \fn trans(const XprMatrix<E, Rows, Cols>& rhs)
sv 1:6799c07fe510 646 * \brief Transpose an expression matrix.
sv 1:6799c07fe510 647 * \ingroup _unary_function
sv 1:6799c07fe510 648 */
sv 1:6799c07fe510 649 template<class E, std::size_t Rows, std::size_t Cols>
sv 1:6799c07fe510 650 inline
sv 1:6799c07fe510 651 XprMatrix<
sv 1:6799c07fe510 652 XprMatrixTranspose<
sv 1:6799c07fe510 653 XprMatrix<E, Rows, Cols>
sv 1:6799c07fe510 654 >,
sv 1:6799c07fe510 655 Cols, Rows
sv 1:6799c07fe510 656 >
sv 1:6799c07fe510 657 trans(const XprMatrix<E, Rows, Cols>& rhs) {
sv 1:6799c07fe510 658 typedef XprMatrixTranspose<
sv 1:6799c07fe510 659 XprMatrix<E, Rows, Cols>
sv 1:6799c07fe510 660 > expr_type;
sv 1:6799c07fe510 661 return XprMatrix<expr_type, Cols, Rows>(expr_type(rhs));
sv 1:6799c07fe510 662 }
sv 1:6799c07fe510 663
sv 1:6799c07fe510 664
sv 1:6799c07fe510 665 /*
sv 1:6799c07fe510 666 * \fn trace(const XprMatrix<E, Sz, Sz>& m)
sv 1:6799c07fe510 667 * \brief Compute the trace of a square matrix.
sv 1:6799c07fe510 668 * \ingroup _unary_function
sv 1:6799c07fe510 669 *
sv 1:6799c07fe510 670 * Simply compute the trace of the given matrix expression as:
sv 1:6799c07fe510 671 * \f[
sv 1:6799c07fe510 672 * \sum_{k = 0}^{Sz-1} m(k, k)
sv 1:6799c07fe510 673 * \f]
sv 1:6799c07fe510 674 */
sv 1:6799c07fe510 675 template<class E, std::size_t Sz>
sv 1:6799c07fe510 676 inline
sv 1:6799c07fe510 677 typename NumericTraits<typename E::value_type>::sum_type
sv 1:6799c07fe510 678 trace(const XprMatrix<E, Sz, Sz>& m) {
sv 1:6799c07fe510 679 return meta::Matrix<Sz, Sz, 0, 0>::trace(m);
sv 1:6799c07fe510 680 }
sv 1:6799c07fe510 681
sv 1:6799c07fe510 682
sv 1:6799c07fe510 683 /**
sv 1:6799c07fe510 684 * \fn row(const XprMatrix<E, Rows, Cols>& m, std::size_t no)
sv 1:6799c07fe510 685 * \brief Returns a row vector of the given matrix.
sv 1:6799c07fe510 686 * \ingroup _binary_function
sv 1:6799c07fe510 687 */
sv 1:6799c07fe510 688 template<class E, std::size_t Rows, std::size_t Cols>
sv 1:6799c07fe510 689 inline
sv 1:6799c07fe510 690 XprVector<
sv 1:6799c07fe510 691 XprMatrixRow<
sv 1:6799c07fe510 692 XprMatrix<E, Rows, Cols>,
sv 1:6799c07fe510 693 Rows, Cols
sv 1:6799c07fe510 694 >,
sv 1:6799c07fe510 695 Cols
sv 1:6799c07fe510 696 >
sv 1:6799c07fe510 697 row(const XprMatrix<E, Rows, Cols>& m, std::size_t no) {
sv 1:6799c07fe510 698 typedef XprMatrixRow<
sv 1:6799c07fe510 699 XprMatrix<E, Rows, Cols>,
sv 1:6799c07fe510 700 Rows, Cols
sv 1:6799c07fe510 701 > expr_type;
sv 1:6799c07fe510 702
sv 1:6799c07fe510 703 return XprVector<expr_type, Cols>(expr_type(m, no));
sv 1:6799c07fe510 704 }
sv 1:6799c07fe510 705
sv 1:6799c07fe510 706
sv 1:6799c07fe510 707 /**
sv 1:6799c07fe510 708 * \fn col(const XprMatrix<E, Rows, Cols>& m, std::size_t no)
sv 1:6799c07fe510 709 * \brief Returns a column vector of the given matrix.
sv 1:6799c07fe510 710 * \ingroup _binary_function
sv 1:6799c07fe510 711 */
sv 1:6799c07fe510 712 template<class E, std::size_t Rows, std::size_t Cols>
sv 1:6799c07fe510 713 inline
sv 1:6799c07fe510 714 XprVector<
sv 1:6799c07fe510 715 XprMatrixCol<
sv 1:6799c07fe510 716 XprMatrix<E, Rows, Cols>,
sv 1:6799c07fe510 717 Rows, Cols
sv 1:6799c07fe510 718 >,
sv 1:6799c07fe510 719 Rows
sv 1:6799c07fe510 720 >
sv 1:6799c07fe510 721 col(const XprMatrix<E, Rows, Cols>& m, std::size_t no) {
sv 1:6799c07fe510 722 typedef XprMatrixCol<
sv 1:6799c07fe510 723 XprMatrix<E, Rows, Cols>,
sv 1:6799c07fe510 724 Rows, Cols
sv 1:6799c07fe510 725 > expr_type;
sv 1:6799c07fe510 726
sv 1:6799c07fe510 727 return XprVector<expr_type, Cols>(expr_type(m, no));
sv 1:6799c07fe510 728 }
sv 1:6799c07fe510 729
sv 1:6799c07fe510 730
sv 1:6799c07fe510 731 /**
sv 1:6799c07fe510 732 * \fn diag(const XprMatrix<E, Sz, Sz>& m)
sv 1:6799c07fe510 733 * \brief Returns the diagonal vector of the given square matrix.
sv 1:6799c07fe510 734 * \ingroup _unary_function
sv 1:6799c07fe510 735 */
sv 1:6799c07fe510 736 template<class E, std::size_t Sz>
sv 1:6799c07fe510 737 inline
sv 1:6799c07fe510 738 XprVector<
sv 1:6799c07fe510 739 XprMatrixDiag<
sv 1:6799c07fe510 740 XprMatrix<E, Sz, Sz>,
sv 1:6799c07fe510 741 Sz
sv 1:6799c07fe510 742 >,
sv 1:6799c07fe510 743 Sz
sv 1:6799c07fe510 744 >
sv 1:6799c07fe510 745 diag(const XprMatrix<E, Sz, Sz>& m) {
sv 1:6799c07fe510 746 typedef XprMatrixDiag<
sv 1:6799c07fe510 747 XprMatrix<E, Sz, Sz>,
sv 1:6799c07fe510 748 Sz> expr_type;
sv 1:6799c07fe510 749
sv 1:6799c07fe510 750 return XprVector<expr_type, Sz>(expr_type(m));
sv 1:6799c07fe510 751 }
sv 1:6799c07fe510 752
sv 1:6799c07fe510 753
sv 1:6799c07fe510 754 } // namespace tvmet
sv 1:6799c07fe510 755
sv 1:6799c07fe510 756 #endif // TVMET_XPR_MATRIX_FUNCTIONS_H
sv 1:6799c07fe510 757
sv 1:6799c07fe510 758 // Local Variables:
sv 1:6799c07fe510 759 // mode:C++
sv 1:6799c07fe510 760 // tab-width:8
sv 1:6799c07fe510 761 // End: