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: MatrixOperators.h,v 1.23 2007-06-23 15:59:00 opetzold Exp $
sv 1:6799c07fe510 22 */
sv 1:6799c07fe510 23
sv 1:6799c07fe510 24 #ifndef TVMET_XPR_MATRIX_OPERATORS_H
sv 1:6799c07fe510 25 #define TVMET_XPR_MATRIX_OPERATORS_H
sv 1:6799c07fe510 26
sv 1:6799c07fe510 27 namespace tvmet {
sv 1:6799c07fe510 28
sv 1:6799c07fe510 29
sv 1:6799c07fe510 30 /*********************************************************
sv 1:6799c07fe510 31 * PART I: DECLARATION
sv 1:6799c07fe510 32 *********************************************************/
sv 1:6799c07fe510 33
sv 1:6799c07fe510 34
sv 1:6799c07fe510 35 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sv 1:6799c07fe510 36 * Matrix arithmetic operators implemented by functions
sv 1:6799c07fe510 37 * add, sub, mul and div
sv 1:6799c07fe510 38 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
sv 1:6799c07fe510 39
sv 1:6799c07fe510 40
sv 1:6799c07fe510 41 /*
sv 1:6799c07fe510 42 * operator(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Cols1,Cols2>& rhs)
sv 1:6799c07fe510 43 *
sv 1:6799c07fe510 44 * Note: operations +,-,*,/ are per se element wise. Further more,
sv 1:6799c07fe510 45 * element wise operations make sense only for matrices of the same
sv 1:6799c07fe510 46 * size [varg].
sv 1:6799c07fe510 47 */
sv 1:6799c07fe510 48 #define TVMET_DECLARE_MACRO(NAME, OP) \
sv 1:6799c07fe510 49 template<class E1, std::size_t Rows1, std::size_t Cols1, \
sv 1:6799c07fe510 50 class E2> \
sv 1:6799c07fe510 51 XprMatrix< \
sv 1:6799c07fe510 52 XprBinOp< \
sv 1:6799c07fe510 53 Fcnl_##NAME<typename E1::value_type, typename E2::value_type>, \
sv 1:6799c07fe510 54 XprMatrix<E1, Rows1, Cols1>, \
sv 1:6799c07fe510 55 XprMatrix<E2, Rows1, Cols1> \
sv 1:6799c07fe510 56 >, \
sv 1:6799c07fe510 57 Rows1, Cols1 \
sv 1:6799c07fe510 58 > \
sv 1:6799c07fe510 59 operator OP (const XprMatrix<E1, Rows1, Cols1>& lhs, \
sv 1:6799c07fe510 60 const XprMatrix<E2, Rows1, Cols1>& rhs) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 61
sv 1:6799c07fe510 62 TVMET_DECLARE_MACRO(add, +) // per se element wise
sv 1:6799c07fe510 63 TVMET_DECLARE_MACRO(sub, -) // per se element wise
sv 1:6799c07fe510 64 namespace element_wise {
sv 1:6799c07fe510 65 TVMET_DECLARE_MACRO(mul, *) // see as prod()
sv 1:6799c07fe510 66 TVMET_DECLARE_MACRO(div, /) // not defined for matrizes, must be element_wise
sv 1:6799c07fe510 67 }
sv 1:6799c07fe510 68 #undef TVMET_DECLARE_MACRO
sv 1:6799c07fe510 69
sv 1:6799c07fe510 70
sv 1:6799c07fe510 71 /*
sv 1:6799c07fe510 72 * operator(XprMatrix<E, Rows, Cols>, POD)
sv 1:6799c07fe510 73 * operator(POD, XprMatrix<E, Rows, Cols>)
sv 1:6799c07fe510 74 * Note: operations +,-,*,/ are per se element wise
sv 1:6799c07fe510 75 */
sv 1:6799c07fe510 76 #define TVMET_DECLARE_MACRO(NAME, OP, POD) \
sv 1:6799c07fe510 77 template<class E, std::size_t Rows, std::size_t Cols> \
sv 1:6799c07fe510 78 XprMatrix< \
sv 1:6799c07fe510 79 XprBinOp< \
sv 1:6799c07fe510 80 Fcnl_##NAME<typename E::value_type, POD >, \
sv 1:6799c07fe510 81 XprMatrix<E, Rows, Cols>, \
sv 1:6799c07fe510 82 XprLiteral< POD > \
sv 1:6799c07fe510 83 >, \
sv 1:6799c07fe510 84 Rows, Cols \
sv 1:6799c07fe510 85 > \
sv 1:6799c07fe510 86 operator OP (const XprMatrix<E, Rows, Cols>& lhs, \
sv 1:6799c07fe510 87 POD rhs) TVMET_CXX_ALWAYS_INLINE; \
sv 1:6799c07fe510 88 \
sv 1:6799c07fe510 89 template<class E,std::size_t Rows, std::size_t Cols> \
sv 1:6799c07fe510 90 XprMatrix< \
sv 1:6799c07fe510 91 XprBinOp< \
sv 1:6799c07fe510 92 Fcnl_##NAME<POD, typename E::value_type>, \
sv 1:6799c07fe510 93 XprLiteral< POD >, \
sv 1:6799c07fe510 94 XprMatrix<E, Rows, Cols> \
sv 1:6799c07fe510 95 >, \
sv 1:6799c07fe510 96 Rows, Cols \
sv 1:6799c07fe510 97 > \
sv 1:6799c07fe510 98 operator OP (POD lhs, \
sv 1:6799c07fe510 99 const XprMatrix<E, Rows, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 100
sv 1:6799c07fe510 101 TVMET_DECLARE_MACRO(add, +, int)
sv 1:6799c07fe510 102 TVMET_DECLARE_MACRO(sub, -, int)
sv 1:6799c07fe510 103 TVMET_DECLARE_MACRO(mul, *, int)
sv 1:6799c07fe510 104 TVMET_DECLARE_MACRO(div, /, int)
sv 1:6799c07fe510 105
sv 1:6799c07fe510 106 #if defined(TVMET_HAVE_LONG_LONG)
sv 1:6799c07fe510 107 TVMET_DECLARE_MACRO(add, +, long long int)
sv 1:6799c07fe510 108 TVMET_DECLARE_MACRO(sub, -, long long int)
sv 1:6799c07fe510 109 TVMET_DECLARE_MACRO(mul, *, long long int)
sv 1:6799c07fe510 110 TVMET_DECLARE_MACRO(div, /, long long int)
sv 1:6799c07fe510 111 #endif // defined(TVMET_HAVE_LONG_LONG)
sv 1:6799c07fe510 112
sv 1:6799c07fe510 113 TVMET_DECLARE_MACRO(add, +, float)
sv 1:6799c07fe510 114 TVMET_DECLARE_MACRO(sub, -, float)
sv 1:6799c07fe510 115 TVMET_DECLARE_MACRO(mul, *, float)
sv 1:6799c07fe510 116 TVMET_DECLARE_MACRO(div, /, float)
sv 1:6799c07fe510 117
sv 1:6799c07fe510 118 TVMET_DECLARE_MACRO(add, +, double)
sv 1:6799c07fe510 119 TVMET_DECLARE_MACRO(sub, -, double)
sv 1:6799c07fe510 120 TVMET_DECLARE_MACRO(mul, *, double)
sv 1:6799c07fe510 121 TVMET_DECLARE_MACRO(div, /, double)
sv 1:6799c07fe510 122
sv 1:6799c07fe510 123 #if defined(TVMET_HAVE_LONG_DOUBLE)
sv 1:6799c07fe510 124 TVMET_DECLARE_MACRO(add, +, long double)
sv 1:6799c07fe510 125 TVMET_DECLARE_MACRO(sub, -, long double)
sv 1:6799c07fe510 126 TVMET_DECLARE_MACRO(mul, *, long double)
sv 1:6799c07fe510 127 TVMET_DECLARE_MACRO(div, /, long double)
sv 1:6799c07fe510 128 #endif // defined(TVMET_HAVE_LONG_DOUBLE)
sv 1:6799c07fe510 129
sv 1:6799c07fe510 130 #undef TVMET_DECLARE_MACRO
sv 1:6799c07fe510 131
sv 1:6799c07fe510 132
sv 1:6799c07fe510 133 #if defined(TVMET_HAVE_COMPLEX)
sv 1:6799c07fe510 134 /*
sv 1:6799c07fe510 135 * operator(XprMatrix<E, Rows, Cols>, complex<>)
sv 1:6799c07fe510 136 * operator(complex<>, XprMatrix<E, Rows, Cols>)
sv 1:6799c07fe510 137 * Note: operations +,-,*,/ are per se element wise
sv 1:6799c07fe510 138 * \todo type promotion
sv 1:6799c07fe510 139 */
sv 1:6799c07fe510 140 #define TVMET_DECLARE_MACRO(NAME, OP) \
sv 1:6799c07fe510 141 template<class E, std::size_t Rows, std::size_t Cols, class T> \
sv 1:6799c07fe510 142 XprMatrix< \
sv 1:6799c07fe510 143 XprBinOp< \
sv 1:6799c07fe510 144 Fcnl_##NAME<typename E::value_type, std::complex<T> >, \
sv 1:6799c07fe510 145 XprMatrix<E, Rows, Cols>, \
sv 1:6799c07fe510 146 XprLiteral< std::complex<T> > \
sv 1:6799c07fe510 147 >, \
sv 1:6799c07fe510 148 Rows, Cols \
sv 1:6799c07fe510 149 > \
sv 1:6799c07fe510 150 operator OP (const XprMatrix<E, Rows, Cols>& lhs, \
sv 1:6799c07fe510 151 const std::complex<T>& rhs) TVMET_CXX_ALWAYS_INLINE; \
sv 1:6799c07fe510 152 \
sv 1:6799c07fe510 153 template<class E, std::size_t Rows, std::size_t Cols, class T> \
sv 1:6799c07fe510 154 XprMatrix< \
sv 1:6799c07fe510 155 XprBinOp< \
sv 1:6799c07fe510 156 Fcnl_##NAME<std::complex<T>, typename E::value_type>, \
sv 1:6799c07fe510 157 XprLiteral< std::complex<T> >, \
sv 1:6799c07fe510 158 XprMatrix<E, Rows, Cols> \
sv 1:6799c07fe510 159 >, \
sv 1:6799c07fe510 160 Rows, Cols \
sv 1:6799c07fe510 161 > \
sv 1:6799c07fe510 162 operator OP (const std::complex<T>& lhs, \
sv 1:6799c07fe510 163 const XprMatrix<E, Rows, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 164
sv 1:6799c07fe510 165 TVMET_DECLARE_MACRO(add, +)
sv 1:6799c07fe510 166 TVMET_DECLARE_MACRO(sub, -)
sv 1:6799c07fe510 167 TVMET_DECLARE_MACRO(mul, *)
sv 1:6799c07fe510 168 TVMET_DECLARE_MACRO(div, /)
sv 1:6799c07fe510 169
sv 1:6799c07fe510 170 #undef TVMET_DECLARE_MACRO
sv 1:6799c07fe510 171
sv 1:6799c07fe510 172 #endif // defined(TVMET_HAVE_COMPLEX)
sv 1:6799c07fe510 173
sv 1:6799c07fe510 174
sv 1:6799c07fe510 175 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sv 1:6799c07fe510 176 * matrix specific operator*() = prod() operations
sv 1:6799c07fe510 177 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
sv 1:6799c07fe510 178
sv 1:6799c07fe510 179
sv 1:6799c07fe510 180 /**
sv 1:6799c07fe510 181 * \fn operator*(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Cols1, Cols2>& rhs)
sv 1:6799c07fe510 182 * \brief Evaluate the product of two XprMatrix.
sv 1:6799c07fe510 183 * \ingroup _binary_operator
sv 1:6799c07fe510 184 * \sa prod(XprMatrix<E1, Rows1, Cols1> lhs, XprMatrix<E2, Cols1, Cols2> rhs)
sv 1:6799c07fe510 185 */
sv 1:6799c07fe510 186 template<class E1, std::size_t Rows1, std::size_t Cols1,
sv 1:6799c07fe510 187 class E2, std::size_t Cols2>
sv 1:6799c07fe510 188 XprMatrix<
sv 1:6799c07fe510 189 XprMMProduct<
sv 1:6799c07fe510 190 XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1)
sv 1:6799c07fe510 191 XprMatrix<E2, Cols1, Cols2>, Cols2 // M2(Cols1, Cols2)
sv 1:6799c07fe510 192 >,
sv 1:6799c07fe510 193 Rows1, Cols2
sv 1:6799c07fe510 194 >
sv 1:6799c07fe510 195 operator*(const XprMatrix<E1, Rows1, Cols1>& lhs,
sv 1:6799c07fe510 196 const XprMatrix<E2, Cols1, Cols2>& rhs) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 197
sv 1:6799c07fe510 198
sv 1:6799c07fe510 199 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sv 1:6799c07fe510 200 * matrix-vector specific prod( ... ) operators
sv 1:6799c07fe510 201 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
sv 1:6799c07fe510 202
sv 1:6799c07fe510 203
sv 1:6799c07fe510 204 /**
sv 1:6799c07fe510 205 * \fn operator*(const XprMatrix<E1, Rows, Cols>& lhs, const XprVector<E2, Cols>& rhs)
sv 1:6799c07fe510 206 * \brief Evaluate the product of XprMatrix and XprVector.
sv 1:6799c07fe510 207 * \ingroup _binary_operator
sv 1:6799c07fe510 208 * \sa prod(XprMatrix<E1, Rows, Cols> lhs, XprVector<E2, Cols> rhs)
sv 1:6799c07fe510 209 */
sv 1:6799c07fe510 210 template<class E1, std::size_t Rows, std::size_t Cols,
sv 1:6799c07fe510 211 class E2>
sv 1:6799c07fe510 212 XprVector<
sv 1:6799c07fe510 213 XprMVProduct<
sv 1:6799c07fe510 214 XprMatrix<E1, Rows, Cols>, Rows, Cols,
sv 1:6799c07fe510 215 XprVector<E2, Cols>
sv 1:6799c07fe510 216 >,
sv 1:6799c07fe510 217 Rows
sv 1:6799c07fe510 218 >
sv 1:6799c07fe510 219 operator*(const XprMatrix<E1, Rows, Cols>& lhs,
sv 1:6799c07fe510 220 const XprVector<E2, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 221
sv 1:6799c07fe510 222
sv 1:6799c07fe510 223 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sv 1:6799c07fe510 224 * Matrix integer and compare operators
sv 1:6799c07fe510 225 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
sv 1:6799c07fe510 226
sv 1:6799c07fe510 227
sv 1:6799c07fe510 228 /*
sv 1:6799c07fe510 229 * operator(XprMatrix<>, XprMatrix<>)
sv 1:6799c07fe510 230 * Note: operations are per se element wise
sv 1:6799c07fe510 231 */
sv 1:6799c07fe510 232 #define TVMET_DECLARE_MACRO(NAME, OP) \
sv 1:6799c07fe510 233 template<class E1, std::size_t Rows, std::size_t Cols, \
sv 1:6799c07fe510 234 class E2> \
sv 1:6799c07fe510 235 XprMatrix< \
sv 1:6799c07fe510 236 XprBinOp< \
sv 1:6799c07fe510 237 Fcnl_##NAME<typename E1::value_type, typename E2::value_type>, \
sv 1:6799c07fe510 238 XprMatrix<E1, Rows, Cols>, \
sv 1:6799c07fe510 239 XprMatrix<E2, Rows, Cols> \
sv 1:6799c07fe510 240 >, \
sv 1:6799c07fe510 241 Rows, Cols \
sv 1:6799c07fe510 242 > \
sv 1:6799c07fe510 243 operator OP (const XprMatrix<E1, Rows, Cols>& lhs, \
sv 1:6799c07fe510 244 const XprMatrix<E2, Rows, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 245
sv 1:6799c07fe510 246 // integer operators only, e.g used on double you will get an error
sv 1:6799c07fe510 247 namespace element_wise {
sv 1:6799c07fe510 248 TVMET_DECLARE_MACRO(mod, %)
sv 1:6799c07fe510 249 TVMET_DECLARE_MACRO(bitxor, ^)
sv 1:6799c07fe510 250 TVMET_DECLARE_MACRO(bitand, &)
sv 1:6799c07fe510 251 TVMET_DECLARE_MACRO(bitor, |)
sv 1:6799c07fe510 252 TVMET_DECLARE_MACRO(shl, <<)
sv 1:6799c07fe510 253 TVMET_DECLARE_MACRO(shr, >>)
sv 1:6799c07fe510 254 }
sv 1:6799c07fe510 255
sv 1:6799c07fe510 256 // necessary operators for eval functions
sv 1:6799c07fe510 257 TVMET_DECLARE_MACRO(greater, >)
sv 1:6799c07fe510 258 TVMET_DECLARE_MACRO(less, <)
sv 1:6799c07fe510 259 TVMET_DECLARE_MACRO(greater_eq, >=)
sv 1:6799c07fe510 260 TVMET_DECLARE_MACRO(less_eq, <=)
sv 1:6799c07fe510 261 TVMET_DECLARE_MACRO(eq, ==)
sv 1:6799c07fe510 262 TVMET_DECLARE_MACRO(not_eq, !=)
sv 1:6799c07fe510 263 TVMET_DECLARE_MACRO(and, &&)
sv 1:6799c07fe510 264 TVMET_DECLARE_MACRO(or, ||)
sv 1:6799c07fe510 265
sv 1:6799c07fe510 266 #undef TVMET_DECLARE_MACRO
sv 1:6799c07fe510 267
sv 1:6799c07fe510 268
sv 1:6799c07fe510 269 #if defined(TVMET_HAVE_COMPLEX)
sv 1:6799c07fe510 270 /*
sv 1:6799c07fe510 271 * operator(XprMatrix<E, Rows, Cols>, std::complex<>)
sv 1:6799c07fe510 272 * operator(std::complex<>, XprMatrix<E, Rows, Cols>)
sv 1:6799c07fe510 273 * Note: - per se element wise
sv 1:6799c07fe510 274 * - bit ops on complex<int> doesn't make sense, stay away
sv 1:6799c07fe510 275 * \todo type promotion
sv 1:6799c07fe510 276 */
sv 1:6799c07fe510 277 #define TVMET_DECLARE_MACRO(NAME, OP) \
sv 1:6799c07fe510 278 template<class E, std::size_t Rows, std::size_t Cols, class T> \
sv 1:6799c07fe510 279 XprMatrix< \
sv 1:6799c07fe510 280 XprBinOp< \
sv 1:6799c07fe510 281 Fcnl_##NAME<typename E::value_type, std::complex<T> >, \
sv 1:6799c07fe510 282 XprMatrix<E, Rows, Cols>, \
sv 1:6799c07fe510 283 XprLiteral< std::complex<T> > \
sv 1:6799c07fe510 284 >, \
sv 1:6799c07fe510 285 Rows, Cols \
sv 1:6799c07fe510 286 > \
sv 1:6799c07fe510 287 operator OP (const XprMatrix<E, Rows, Cols>& lhs, \
sv 1:6799c07fe510 288 const std::complex<T>& rhs) TVMET_CXX_ALWAYS_INLINE; \
sv 1:6799c07fe510 289 \
sv 1:6799c07fe510 290 template<class E, std::size_t Rows, std::size_t Cols, class T> \
sv 1:6799c07fe510 291 XprMatrix< \
sv 1:6799c07fe510 292 XprBinOp< \
sv 1:6799c07fe510 293 Fcnl_##NAME<std::complex<T>, typename E::value_type>, \
sv 1:6799c07fe510 294 XprLiteral< std::complex<T> >, \
sv 1:6799c07fe510 295 XprMatrix<E, Rows, Cols> \
sv 1:6799c07fe510 296 >, \
sv 1:6799c07fe510 297 Rows, Cols \
sv 1:6799c07fe510 298 > \
sv 1:6799c07fe510 299 operator OP (const std::complex<T>& lhs, \
sv 1:6799c07fe510 300 const XprMatrix<E, Rows, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 301
sv 1:6799c07fe510 302 // necessary operators for eval functions
sv 1:6799c07fe510 303 TVMET_DECLARE_MACRO(greater, >)
sv 1:6799c07fe510 304 TVMET_DECLARE_MACRO(less, <)
sv 1:6799c07fe510 305 TVMET_DECLARE_MACRO(greater_eq, >=)
sv 1:6799c07fe510 306 TVMET_DECLARE_MACRO(less_eq, <=)
sv 1:6799c07fe510 307 TVMET_DECLARE_MACRO(eq, ==)
sv 1:6799c07fe510 308 TVMET_DECLARE_MACRO(not_eq, !=)
sv 1:6799c07fe510 309 TVMET_DECLARE_MACRO(and, &&)
sv 1:6799c07fe510 310 TVMET_DECLARE_MACRO(or, ||)
sv 1:6799c07fe510 311
sv 1:6799c07fe510 312 #undef TVMET_DECLARE_MACRO
sv 1:6799c07fe510 313
sv 1:6799c07fe510 314 #endif // defined(TVMET_HAVE_COMPLEX)
sv 1:6799c07fe510 315
sv 1:6799c07fe510 316
sv 1:6799c07fe510 317 /*
sv 1:6799c07fe510 318 * operator(XprMatrix<E, Rows, Cols>, POD)
sv 1:6799c07fe510 319 * operator(POD, XprMatrix<E, Rows, Cols>)
sv 1:6799c07fe510 320 * Note: operations are per se element wise
sv 1:6799c07fe510 321 */
sv 1:6799c07fe510 322 #define TVMET_DECLARE_MACRO(NAME, OP, TP) \
sv 1:6799c07fe510 323 template<class E, std::size_t Rows, std::size_t Cols> \
sv 1:6799c07fe510 324 XprMatrix< \
sv 1:6799c07fe510 325 XprBinOp< \
sv 1:6799c07fe510 326 Fcnl_##NAME<typename E::value_type, TP >, \
sv 1:6799c07fe510 327 XprMatrix<E, Rows, Cols>, \
sv 1:6799c07fe510 328 XprLiteral< TP > \
sv 1:6799c07fe510 329 >, \
sv 1:6799c07fe510 330 Rows, Cols \
sv 1:6799c07fe510 331 > \
sv 1:6799c07fe510 332 operator OP (const XprMatrix<E, Rows, Cols>& lhs, \
sv 1:6799c07fe510 333 TP rhs) TVMET_CXX_ALWAYS_INLINE; \
sv 1:6799c07fe510 334 \
sv 1:6799c07fe510 335 template<class E, std::size_t Rows, std::size_t Cols> \
sv 1:6799c07fe510 336 XprMatrix< \
sv 1:6799c07fe510 337 XprBinOp< \
sv 1:6799c07fe510 338 Fcnl_##NAME<TP, typename E::value_type>, \
sv 1:6799c07fe510 339 XprLiteral< TP >, \
sv 1:6799c07fe510 340 XprMatrix<E, Rows, Cols> \
sv 1:6799c07fe510 341 >, \
sv 1:6799c07fe510 342 Rows, Cols \
sv 1:6799c07fe510 343 > \
sv 1:6799c07fe510 344 operator OP (TP lhs, \
sv 1:6799c07fe510 345 const XprMatrix<E, Rows, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 346
sv 1:6799c07fe510 347 // integer operators only, e.g used on double you will get an error
sv 1:6799c07fe510 348 namespace element_wise {
sv 1:6799c07fe510 349 TVMET_DECLARE_MACRO(mod, %, int)
sv 1:6799c07fe510 350 TVMET_DECLARE_MACRO(bitxor, ^, int)
sv 1:6799c07fe510 351 TVMET_DECLARE_MACRO(bitand, &, int)
sv 1:6799c07fe510 352 TVMET_DECLARE_MACRO(bitor, |, int)
sv 1:6799c07fe510 353 TVMET_DECLARE_MACRO(shl, <<, int)
sv 1:6799c07fe510 354 TVMET_DECLARE_MACRO(shr, >>, int)
sv 1:6799c07fe510 355 }
sv 1:6799c07fe510 356
sv 1:6799c07fe510 357 // necessary operators for eval functions
sv 1:6799c07fe510 358 TVMET_DECLARE_MACRO(greater, >, int)
sv 1:6799c07fe510 359 TVMET_DECLARE_MACRO(less, <, int)
sv 1:6799c07fe510 360 TVMET_DECLARE_MACRO(greater_eq, >=, int)
sv 1:6799c07fe510 361 TVMET_DECLARE_MACRO(less_eq, <=, int)
sv 1:6799c07fe510 362 TVMET_DECLARE_MACRO(eq, ==, int)
sv 1:6799c07fe510 363 TVMET_DECLARE_MACRO(not_eq, !=, int)
sv 1:6799c07fe510 364 TVMET_DECLARE_MACRO(and, &&, int)
sv 1:6799c07fe510 365 TVMET_DECLARE_MACRO(or, ||, int)
sv 1:6799c07fe510 366
sv 1:6799c07fe510 367 #if defined(TVMET_HAVE_LONG_LONG)
sv 1:6799c07fe510 368 // integer operators only
sv 1:6799c07fe510 369 namespace element_wise {
sv 1:6799c07fe510 370 TVMET_DECLARE_MACRO(mod, %, long long int)
sv 1:6799c07fe510 371 TVMET_DECLARE_MACRO(bitxor, ^, long long int)
sv 1:6799c07fe510 372 TVMET_DECLARE_MACRO(bitand, &, long long int)
sv 1:6799c07fe510 373 TVMET_DECLARE_MACRO(bitor, |, long long int)
sv 1:6799c07fe510 374 TVMET_DECLARE_MACRO(shl, <<, long long int)
sv 1:6799c07fe510 375 TVMET_DECLARE_MACRO(shr, >>, long long int)
sv 1:6799c07fe510 376 }
sv 1:6799c07fe510 377
sv 1:6799c07fe510 378 // necessary operators for eval functions
sv 1:6799c07fe510 379 TVMET_DECLARE_MACRO(greater, >, long long int)
sv 1:6799c07fe510 380 TVMET_DECLARE_MACRO(less, <, long long int)
sv 1:6799c07fe510 381 TVMET_DECLARE_MACRO(greater_eq, >=, long long int)
sv 1:6799c07fe510 382 TVMET_DECLARE_MACRO(less_eq, <=, long long int)
sv 1:6799c07fe510 383 TVMET_DECLARE_MACRO(eq, ==, long long int)
sv 1:6799c07fe510 384 TVMET_DECLARE_MACRO(not_eq, !=, long long int)
sv 1:6799c07fe510 385 TVMET_DECLARE_MACRO(and, &&, long long int)
sv 1:6799c07fe510 386 TVMET_DECLARE_MACRO(or, ||, long long int)
sv 1:6799c07fe510 387 #endif // defined(TVMET_HAVE_LONG_LONG)
sv 1:6799c07fe510 388
sv 1:6799c07fe510 389 // necessary operators for eval functions
sv 1:6799c07fe510 390 TVMET_DECLARE_MACRO(greater, >, float)
sv 1:6799c07fe510 391 TVMET_DECLARE_MACRO(less, <, float)
sv 1:6799c07fe510 392 TVMET_DECLARE_MACRO(greater_eq, >=, float)
sv 1:6799c07fe510 393 TVMET_DECLARE_MACRO(less_eq, <=, float)
sv 1:6799c07fe510 394 TVMET_DECLARE_MACRO(eq, ==, float)
sv 1:6799c07fe510 395 TVMET_DECLARE_MACRO(not_eq, !=, float)
sv 1:6799c07fe510 396 TVMET_DECLARE_MACRO(and, &&, float)
sv 1:6799c07fe510 397 TVMET_DECLARE_MACRO(or, ||, float)
sv 1:6799c07fe510 398
sv 1:6799c07fe510 399 // necessary operators for eval functions
sv 1:6799c07fe510 400 TVMET_DECLARE_MACRO(greater, >, double)
sv 1:6799c07fe510 401 TVMET_DECLARE_MACRO(less, <, double)
sv 1:6799c07fe510 402 TVMET_DECLARE_MACRO(greater_eq, >=, double)
sv 1:6799c07fe510 403 TVMET_DECLARE_MACRO(less_eq, <=, double)
sv 1:6799c07fe510 404 TVMET_DECLARE_MACRO(eq, ==, double)
sv 1:6799c07fe510 405 TVMET_DECLARE_MACRO(not_eq, !=, double)
sv 1:6799c07fe510 406 TVMET_DECLARE_MACRO(and, &&, double)
sv 1:6799c07fe510 407 TVMET_DECLARE_MACRO(or, ||, double)
sv 1:6799c07fe510 408
sv 1:6799c07fe510 409 #if defined(TVMET_HAVE_LONG_DOUBLE)
sv 1:6799c07fe510 410 // necessary operators for eval functions
sv 1:6799c07fe510 411 TVMET_DECLARE_MACRO(greater, >, long double)
sv 1:6799c07fe510 412 TVMET_DECLARE_MACRO(less, <, long double)
sv 1:6799c07fe510 413 TVMET_DECLARE_MACRO(greater_eq, >=, long double)
sv 1:6799c07fe510 414 TVMET_DECLARE_MACRO(less_eq, <=, long double)
sv 1:6799c07fe510 415 TVMET_DECLARE_MACRO(eq, ==, long double)
sv 1:6799c07fe510 416 TVMET_DECLARE_MACRO(not_eq, !=, long double)
sv 1:6799c07fe510 417 TVMET_DECLARE_MACRO(and, &&, long double)
sv 1:6799c07fe510 418 TVMET_DECLARE_MACRO(or, ||, long double)
sv 1:6799c07fe510 419 #endif // defined(TVMET_HAVE_LONG_DOUBLE)
sv 1:6799c07fe510 420
sv 1:6799c07fe510 421 #undef TVMET_DECLARE_MACRO
sv 1:6799c07fe510 422
sv 1:6799c07fe510 423
sv 1:6799c07fe510 424 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sv 1:6799c07fe510 425 * global unary operators
sv 1:6799c07fe510 426 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
sv 1:6799c07fe510 427
sv 1:6799c07fe510 428
sv 1:6799c07fe510 429 /*
sv 1:6799c07fe510 430 * unary_operator(const XprMatrix<E, Rows, Cols>& m)
sv 1:6799c07fe510 431 * Note: per se element wise
sv 1:6799c07fe510 432 */
sv 1:6799c07fe510 433 #define TVMET_DECLARE_MACRO(NAME, OP) \
sv 1:6799c07fe510 434 template <class E, std::size_t Rows, std::size_t Cols> \
sv 1:6799c07fe510 435 XprMatrix< \
sv 1:6799c07fe510 436 XprUnOp< \
sv 1:6799c07fe510 437 Fcnl_##NAME<typename E::value_type>, \
sv 1:6799c07fe510 438 XprMatrix<E, Rows, Cols> \
sv 1:6799c07fe510 439 >, \
sv 1:6799c07fe510 440 Rows, Cols \
sv 1:6799c07fe510 441 > \
sv 1:6799c07fe510 442 operator OP (const XprMatrix<E, Rows, Cols>& m) TVMET_CXX_ALWAYS_INLINE;
sv 1:6799c07fe510 443
sv 1:6799c07fe510 444 TVMET_DECLARE_MACRO(not, !)
sv 1:6799c07fe510 445 TVMET_DECLARE_MACRO(compl, ~)
sv 1:6799c07fe510 446 TVMET_DECLARE_MACRO(neg, -)
sv 1:6799c07fe510 447
sv 1:6799c07fe510 448 #undef TVMET_DECLARE_MACRO
sv 1:6799c07fe510 449
sv 1:6799c07fe510 450
sv 1:6799c07fe510 451 /*********************************************************
sv 1:6799c07fe510 452 * PART II: IMPLEMENTATION
sv 1:6799c07fe510 453 *********************************************************/
sv 1:6799c07fe510 454
sv 1:6799c07fe510 455
sv 1:6799c07fe510 456
sv 1:6799c07fe510 457 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sv 1:6799c07fe510 458 * Matrix arithmetic operators implemented by functions
sv 1:6799c07fe510 459 * add, sub, mul and div
sv 1:6799c07fe510 460 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
sv 1:6799c07fe510 461
sv 1:6799c07fe510 462
sv 1:6799c07fe510 463 /*
sv 1:6799c07fe510 464 * operator(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Cols1,Cols2>& rhs)
sv 1:6799c07fe510 465 *
sv 1:6799c07fe510 466 * Note: operations +,-,*,/ are per se element wise. Further more,
sv 1:6799c07fe510 467 * element wise operations make sense only for matrices of the same
sv 1:6799c07fe510 468 * size [varg].
sv 1:6799c07fe510 469 */
sv 1:6799c07fe510 470 #define TVMET_IMPLEMENT_MACRO(NAME, OP) \
sv 1:6799c07fe510 471 template<class E1, std::size_t Rows1, std::size_t Cols1, \
sv 1:6799c07fe510 472 class E2> \
sv 1:6799c07fe510 473 inline \
sv 1:6799c07fe510 474 XprMatrix< \
sv 1:6799c07fe510 475 XprBinOp< \
sv 1:6799c07fe510 476 Fcnl_##NAME<typename E1::value_type, typename E2::value_type>, \
sv 1:6799c07fe510 477 XprMatrix<E1, Rows1, Cols1>, \
sv 1:6799c07fe510 478 XprMatrix<E2, Rows1, Cols1> \
sv 1:6799c07fe510 479 >, \
sv 1:6799c07fe510 480 Rows1, Cols1 \
sv 1:6799c07fe510 481 > \
sv 1:6799c07fe510 482 operator OP (const XprMatrix<E1, Rows1, Cols1>& lhs, \
sv 1:6799c07fe510 483 const XprMatrix<E2, Rows1, Cols1>& rhs) { \
sv 1:6799c07fe510 484 return NAME (lhs, rhs); \
sv 1:6799c07fe510 485 }
sv 1:6799c07fe510 486
sv 1:6799c07fe510 487 TVMET_IMPLEMENT_MACRO(add, +) // per se element wise
sv 1:6799c07fe510 488 TVMET_IMPLEMENT_MACRO(sub, -) // per se element wise
sv 1:6799c07fe510 489 namespace element_wise {
sv 1:6799c07fe510 490 TVMET_IMPLEMENT_MACRO(mul, *) // see as prod()
sv 1:6799c07fe510 491 TVMET_IMPLEMENT_MACRO(div, /) // not defined for matrizes, must be element_wise
sv 1:6799c07fe510 492 }
sv 1:6799c07fe510 493 #undef TVMET_IMPLEMENT_MACRO
sv 1:6799c07fe510 494
sv 1:6799c07fe510 495
sv 1:6799c07fe510 496 /*
sv 1:6799c07fe510 497 * operator(XprMatrix<E, Rows, Cols>, POD)
sv 1:6799c07fe510 498 * operator(POD, XprMatrix<E, Rows, Cols>)
sv 1:6799c07fe510 499 * Note: operations +,-,*,/ are per se element wise
sv 1:6799c07fe510 500 */
sv 1:6799c07fe510 501 #define TVMET_IMPLEMENT_MACRO(NAME, OP, POD) \
sv 1:6799c07fe510 502 template<class E, std::size_t Rows, std::size_t Cols> \
sv 1:6799c07fe510 503 inline \
sv 1:6799c07fe510 504 XprMatrix< \
sv 1:6799c07fe510 505 XprBinOp< \
sv 1:6799c07fe510 506 Fcnl_##NAME<typename E::value_type, POD >, \
sv 1:6799c07fe510 507 XprMatrix<E, Rows, Cols>, \
sv 1:6799c07fe510 508 XprLiteral< POD > \
sv 1:6799c07fe510 509 >, \
sv 1:6799c07fe510 510 Rows, Cols \
sv 1:6799c07fe510 511 > \
sv 1:6799c07fe510 512 operator OP (const XprMatrix<E, Rows, Cols>& lhs, POD rhs) { \
sv 1:6799c07fe510 513 return NAME (lhs, rhs); \
sv 1:6799c07fe510 514 } \
sv 1:6799c07fe510 515 \
sv 1:6799c07fe510 516 template<class E,std::size_t Rows, std::size_t Cols> \
sv 1:6799c07fe510 517 inline \
sv 1:6799c07fe510 518 XprMatrix< \
sv 1:6799c07fe510 519 XprBinOp< \
sv 1:6799c07fe510 520 Fcnl_##NAME<POD, typename E::value_type>, \
sv 1:6799c07fe510 521 XprLiteral< POD >, \
sv 1:6799c07fe510 522 XprMatrix<E, Rows, Cols> \
sv 1:6799c07fe510 523 >, \
sv 1:6799c07fe510 524 Rows, Cols \
sv 1:6799c07fe510 525 > \
sv 1:6799c07fe510 526 operator OP (POD lhs, const XprMatrix<E, Rows, Cols>& rhs) { \
sv 1:6799c07fe510 527 return NAME (lhs, rhs); \
sv 1:6799c07fe510 528 }
sv 1:6799c07fe510 529
sv 1:6799c07fe510 530 TVMET_IMPLEMENT_MACRO(add, +, int)
sv 1:6799c07fe510 531 TVMET_IMPLEMENT_MACRO(sub, -, int)
sv 1:6799c07fe510 532 TVMET_IMPLEMENT_MACRO(mul, *, int)
sv 1:6799c07fe510 533 TVMET_IMPLEMENT_MACRO(div, /, int)
sv 1:6799c07fe510 534
sv 1:6799c07fe510 535 #if defined(TVMET_HAVE_LONG_LONG)
sv 1:6799c07fe510 536 TVMET_IMPLEMENT_MACRO(add, +, long long int)
sv 1:6799c07fe510 537 TVMET_IMPLEMENT_MACRO(sub, -, long long int)
sv 1:6799c07fe510 538 TVMET_IMPLEMENT_MACRO(mul, *, long long int)
sv 1:6799c07fe510 539 TVMET_IMPLEMENT_MACRO(div, /, long long int)
sv 1:6799c07fe510 540 #endif // defined(TVMET_HAVE_LONG_LONG)
sv 1:6799c07fe510 541
sv 1:6799c07fe510 542 TVMET_IMPLEMENT_MACRO(add, +, float)
sv 1:6799c07fe510 543 TVMET_IMPLEMENT_MACRO(sub, -, float)
sv 1:6799c07fe510 544 TVMET_IMPLEMENT_MACRO(mul, *, float)
sv 1:6799c07fe510 545 TVMET_IMPLEMENT_MACRO(div, /, float)
sv 1:6799c07fe510 546
sv 1:6799c07fe510 547 TVMET_IMPLEMENT_MACRO(add, +, double)
sv 1:6799c07fe510 548 TVMET_IMPLEMENT_MACRO(sub, -, double)
sv 1:6799c07fe510 549 TVMET_IMPLEMENT_MACRO(mul, *, double)
sv 1:6799c07fe510 550 TVMET_IMPLEMENT_MACRO(div, /, double)
sv 1:6799c07fe510 551
sv 1:6799c07fe510 552 #if defined(TVMET_HAVE_LONG_DOUBLE)
sv 1:6799c07fe510 553 TVMET_IMPLEMENT_MACRO(add, +, long double)
sv 1:6799c07fe510 554 TVMET_IMPLEMENT_MACRO(sub, -, long double)
sv 1:6799c07fe510 555 TVMET_IMPLEMENT_MACRO(mul, *, long double)
sv 1:6799c07fe510 556 TVMET_IMPLEMENT_MACRO(div, /, long double)
sv 1:6799c07fe510 557 #endif // defined(TVMET_HAVE_LONG_DOUBLE)
sv 1:6799c07fe510 558
sv 1:6799c07fe510 559 #undef TVMET_IMPLEMENT_MACRO
sv 1:6799c07fe510 560
sv 1:6799c07fe510 561
sv 1:6799c07fe510 562 #if defined(TVMET_HAVE_COMPLEX)
sv 1:6799c07fe510 563 /*
sv 1:6799c07fe510 564 * operator(XprMatrix<E, Rows, Cols>, complex<>)
sv 1:6799c07fe510 565 * operator(complex<>, XprMatrix<E, Rows, Cols>)
sv 1:6799c07fe510 566 * Note: operations +,-,*,/ are per se element wise
sv 1:6799c07fe510 567 * \todo type promotion
sv 1:6799c07fe510 568 */
sv 1:6799c07fe510 569 #define TVMET_IMPLEMENT_MACRO(NAME, OP) \
sv 1:6799c07fe510 570 template<class E, std::size_t Rows, std::size_t Cols, class T> \
sv 1:6799c07fe510 571 inline \
sv 1:6799c07fe510 572 XprMatrix< \
sv 1:6799c07fe510 573 XprBinOp< \
sv 1:6799c07fe510 574 Fcnl_##NAME<typename E::value_type, std::complex<T> >, \
sv 1:6799c07fe510 575 XprMatrix<E, Rows, Cols>, \
sv 1:6799c07fe510 576 XprLiteral< std::complex<T> > \
sv 1:6799c07fe510 577 >, \
sv 1:6799c07fe510 578 Rows, Cols \
sv 1:6799c07fe510 579 > \
sv 1:6799c07fe510 580 operator OP (const XprMatrix<E, Rows, Cols>& lhs, \
sv 1:6799c07fe510 581 const std::complex<T>& rhs) { \
sv 1:6799c07fe510 582 return NAME (lhs, rhs); \
sv 1:6799c07fe510 583 } \
sv 1:6799c07fe510 584 \
sv 1:6799c07fe510 585 template<class E, std::size_t Rows, std::size_t Cols, class T> \
sv 1:6799c07fe510 586 inline \
sv 1:6799c07fe510 587 XprMatrix< \
sv 1:6799c07fe510 588 XprBinOp< \
sv 1:6799c07fe510 589 Fcnl_##NAME<std::complex<T>, typename E::value_type>, \
sv 1:6799c07fe510 590 XprLiteral< std::complex<T> >, \
sv 1:6799c07fe510 591 XprMatrix<E, Rows, Cols> \
sv 1:6799c07fe510 592 >, \
sv 1:6799c07fe510 593 Rows, Cols \
sv 1:6799c07fe510 594 > \
sv 1:6799c07fe510 595 operator OP (const std::complex<T>& lhs, \
sv 1:6799c07fe510 596 const XprMatrix<E, Rows, Cols>& rhs) { \
sv 1:6799c07fe510 597 return NAME (lhs, rhs); \
sv 1:6799c07fe510 598 }
sv 1:6799c07fe510 599
sv 1:6799c07fe510 600 TVMET_IMPLEMENT_MACRO(add, +)
sv 1:6799c07fe510 601 TVMET_IMPLEMENT_MACRO(sub, -)
sv 1:6799c07fe510 602 TVMET_IMPLEMENT_MACRO(mul, *)
sv 1:6799c07fe510 603 TVMET_IMPLEMENT_MACRO(div, /)
sv 1:6799c07fe510 604
sv 1:6799c07fe510 605 #undef TVMET_IMPLEMENT_MACRO
sv 1:6799c07fe510 606
sv 1:6799c07fe510 607 #endif // defined(TVMET_HAVE_COMPLEX)
sv 1:6799c07fe510 608
sv 1:6799c07fe510 609
sv 1:6799c07fe510 610 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sv 1:6799c07fe510 611 * matrix specific operator*() = prod() operations
sv 1:6799c07fe510 612 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
sv 1:6799c07fe510 613
sv 1:6799c07fe510 614
sv 1:6799c07fe510 615 /**
sv 1:6799c07fe510 616 * \fn operator*(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Cols1, Cols2>& rhs)
sv 1:6799c07fe510 617 * \brief Evaluate the product of two XprMatrix.
sv 1:6799c07fe510 618 * \ingroup _binary_operator
sv 1:6799c07fe510 619 * \sa prod(XprMatrix<E1, Rows1, Cols1> lhs, XprMatrix<E2, Cols1, Cols2> rhs)
sv 1:6799c07fe510 620 */
sv 1:6799c07fe510 621 template<class E1, std::size_t Rows1, std::size_t Cols1,
sv 1:6799c07fe510 622 class E2, std::size_t Cols2>
sv 1:6799c07fe510 623 inline
sv 1:6799c07fe510 624 XprMatrix<
sv 1:6799c07fe510 625 XprMMProduct<
sv 1:6799c07fe510 626 XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1)
sv 1:6799c07fe510 627 XprMatrix<E2, Cols1, Cols2>, Cols2 // M2(Cols1, Cols2)
sv 1:6799c07fe510 628 >,
sv 1:6799c07fe510 629 Rows1, Cols2
sv 1:6799c07fe510 630 >
sv 1:6799c07fe510 631 operator*(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Cols1, Cols2>& rhs) {
sv 1:6799c07fe510 632 return prod(lhs, rhs);
sv 1:6799c07fe510 633 }
sv 1:6799c07fe510 634
sv 1:6799c07fe510 635
sv 1:6799c07fe510 636 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sv 1:6799c07fe510 637 * matrix-vector specific prod( ... ) operators
sv 1:6799c07fe510 638 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
sv 1:6799c07fe510 639
sv 1:6799c07fe510 640
sv 1:6799c07fe510 641 /**
sv 1:6799c07fe510 642 * \fn operator*(const XprMatrix<E1, Rows, Cols>& lhs, const XprVector<E2, Cols>& rhs)
sv 1:6799c07fe510 643 * \brief Evaluate the product of XprMatrix and XprVector.
sv 1:6799c07fe510 644 * \ingroup _binary_operator
sv 1:6799c07fe510 645 * \sa prod(XprMatrix<E1, Rows, Cols> lhs, XprVector<E2, Cols> rhs)
sv 1:6799c07fe510 646 */
sv 1:6799c07fe510 647 template<class E1, std::size_t Rows, std::size_t Cols,
sv 1:6799c07fe510 648 class E2>
sv 1:6799c07fe510 649 inline
sv 1:6799c07fe510 650 XprVector<
sv 1:6799c07fe510 651 XprMVProduct<
sv 1:6799c07fe510 652 XprMatrix<E1, Rows, Cols>, Rows, Cols,
sv 1:6799c07fe510 653 XprVector<E2, Cols>
sv 1:6799c07fe510 654 >,
sv 1:6799c07fe510 655 Rows
sv 1:6799c07fe510 656 >
sv 1:6799c07fe510 657 operator*(const XprMatrix<E1, Rows, Cols>& lhs, const XprVector<E2, Cols>& rhs) {
sv 1:6799c07fe510 658 return prod(lhs, rhs);
sv 1:6799c07fe510 659 }
sv 1:6799c07fe510 660
sv 1:6799c07fe510 661
sv 1:6799c07fe510 662 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sv 1:6799c07fe510 663 * Matrix integer and compare operators
sv 1:6799c07fe510 664 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
sv 1:6799c07fe510 665
sv 1:6799c07fe510 666
sv 1:6799c07fe510 667 /*
sv 1:6799c07fe510 668 * operator(XprMatrix<>, XprMatrix<>)
sv 1:6799c07fe510 669 * Note: operations are per se element wise
sv 1:6799c07fe510 670 */
sv 1:6799c07fe510 671 #define TVMET_IMPLEMENT_MACRO(NAME, OP) \
sv 1:6799c07fe510 672 template<class E1, std::size_t Rows, std::size_t Cols, \
sv 1:6799c07fe510 673 class E2> \
sv 1:6799c07fe510 674 inline \
sv 1:6799c07fe510 675 XprMatrix< \
sv 1:6799c07fe510 676 XprBinOp< \
sv 1:6799c07fe510 677 Fcnl_##NAME<typename E1::value_type, typename E2::value_type>, \
sv 1:6799c07fe510 678 XprMatrix<E1, Rows, Cols>, \
sv 1:6799c07fe510 679 XprMatrix<E2, Rows, Cols> \
sv 1:6799c07fe510 680 >, \
sv 1:6799c07fe510 681 Rows, Cols \
sv 1:6799c07fe510 682 > \
sv 1:6799c07fe510 683 operator OP (const XprMatrix<E1, Rows, Cols>& lhs, \
sv 1:6799c07fe510 684 const XprMatrix<E2, Rows, Cols>& rhs) { \
sv 1:6799c07fe510 685 typedef XprBinOp< \
sv 1:6799c07fe510 686 Fcnl_##NAME<typename E1::value_type, typename E2::value_type>, \
sv 1:6799c07fe510 687 XprMatrix<E1, Rows, Cols>, \
sv 1:6799c07fe510 688 XprMatrix<E2, Rows, Cols> \
sv 1:6799c07fe510 689 > expr_type; \
sv 1:6799c07fe510 690 return XprMatrix<expr_type, Rows, Cols>(expr_type(lhs, rhs)); \
sv 1:6799c07fe510 691 }
sv 1:6799c07fe510 692
sv 1:6799c07fe510 693 // integer operators only, e.g used on double you will get an error
sv 1:6799c07fe510 694 namespace element_wise {
sv 1:6799c07fe510 695 TVMET_IMPLEMENT_MACRO(mod, %)
sv 1:6799c07fe510 696 TVMET_IMPLEMENT_MACRO(bitxor, ^)
sv 1:6799c07fe510 697 TVMET_IMPLEMENT_MACRO(bitand, &)
sv 1:6799c07fe510 698 TVMET_IMPLEMENT_MACRO(bitor, |)
sv 1:6799c07fe510 699 TVMET_IMPLEMENT_MACRO(shl, <<)
sv 1:6799c07fe510 700 TVMET_IMPLEMENT_MACRO(shr, >>)
sv 1:6799c07fe510 701 }
sv 1:6799c07fe510 702
sv 1:6799c07fe510 703 // necessary operators for eval functions
sv 1:6799c07fe510 704 TVMET_IMPLEMENT_MACRO(greater, >)
sv 1:6799c07fe510 705 TVMET_IMPLEMENT_MACRO(less, <)
sv 1:6799c07fe510 706 TVMET_IMPLEMENT_MACRO(greater_eq, >=)
sv 1:6799c07fe510 707 TVMET_IMPLEMENT_MACRO(less_eq, <=)
sv 1:6799c07fe510 708 TVMET_IMPLEMENT_MACRO(eq, ==)
sv 1:6799c07fe510 709 TVMET_IMPLEMENT_MACRO(not_eq, !=)
sv 1:6799c07fe510 710 TVMET_IMPLEMENT_MACRO(and, &&)
sv 1:6799c07fe510 711 TVMET_IMPLEMENT_MACRO(or, ||)
sv 1:6799c07fe510 712
sv 1:6799c07fe510 713 #undef TVMET_IMPLEMENT_MACRO
sv 1:6799c07fe510 714
sv 1:6799c07fe510 715
sv 1:6799c07fe510 716 #if defined(TVMET_HAVE_COMPLEX)
sv 1:6799c07fe510 717 /*
sv 1:6799c07fe510 718 * operator(XprMatrix<E, Rows, Cols>, std::complex<>)
sv 1:6799c07fe510 719 * operator(std::complex<>, XprMatrix<E, Rows, Cols>)
sv 1:6799c07fe510 720 * Note: - per se element wise
sv 1:6799c07fe510 721 * - bit ops on complex<int> doesn't make sense, stay away
sv 1:6799c07fe510 722 * \todo type promotion
sv 1:6799c07fe510 723 */
sv 1:6799c07fe510 724 #define TVMET_IMPLEMENT_MACRO(NAME, OP) \
sv 1:6799c07fe510 725 template<class E, std::size_t Rows, std::size_t Cols, class T> \
sv 1:6799c07fe510 726 inline \
sv 1:6799c07fe510 727 XprMatrix< \
sv 1:6799c07fe510 728 XprBinOp< \
sv 1:6799c07fe510 729 Fcnl_##NAME<typename E::value_type, std::complex<T> >, \
sv 1:6799c07fe510 730 XprMatrix<E, Rows, Cols>, \
sv 1:6799c07fe510 731 XprLiteral< std::complex<T> > \
sv 1:6799c07fe510 732 >, \
sv 1:6799c07fe510 733 Rows, Cols \
sv 1:6799c07fe510 734 > \
sv 1:6799c07fe510 735 operator OP (const XprMatrix<E, Rows, Cols>& lhs, \
sv 1:6799c07fe510 736 const std::complex<T>& rhs) { \
sv 1:6799c07fe510 737 typedef XprBinOp< \
sv 1:6799c07fe510 738 Fcnl_##NAME<typename E::value_type, std::complex<T> >, \
sv 1:6799c07fe510 739 XprMatrix<E, Rows, Cols>, \
sv 1:6799c07fe510 740 XprLiteral< std::complex<T> > \
sv 1:6799c07fe510 741 > expr_type; \
sv 1:6799c07fe510 742 return XprMatrix<expr_type, Rows, Cols>( \
sv 1:6799c07fe510 743 expr_type(lhs, XprLiteral< std::complex<T> >(rhs))); \
sv 1:6799c07fe510 744 } \
sv 1:6799c07fe510 745 \
sv 1:6799c07fe510 746 template<class E, std::size_t Rows, std::size_t Cols, class T> \
sv 1:6799c07fe510 747 inline \
sv 1:6799c07fe510 748 XprMatrix< \
sv 1:6799c07fe510 749 XprBinOp< \
sv 1:6799c07fe510 750 Fcnl_##NAME<std::complex<T>, typename E::value_type>, \
sv 1:6799c07fe510 751 XprLiteral< std::complex<T> >, \
sv 1:6799c07fe510 752 XprMatrix<E, Rows, Cols> \
sv 1:6799c07fe510 753 >, \
sv 1:6799c07fe510 754 Rows, Cols \
sv 1:6799c07fe510 755 > \
sv 1:6799c07fe510 756 operator OP (const std::complex<T>& lhs, \
sv 1:6799c07fe510 757 const XprMatrix<E, Rows, Cols>& rhs) { \
sv 1:6799c07fe510 758 typedef XprBinOp< \
sv 1:6799c07fe510 759 Fcnl_##NAME< std::complex<T>, typename E::value_type>, \
sv 1:6799c07fe510 760 XprLiteral< std::complex<T> >, \
sv 1:6799c07fe510 761 XprMatrix<E, Rows, Cols> \
sv 1:6799c07fe510 762 > expr_type; \
sv 1:6799c07fe510 763 return XprMatrix<expr_type, Rows, Cols>( \
sv 1:6799c07fe510 764 expr_type(XprLiteral< std::complex<T> >(lhs), rhs)); \
sv 1:6799c07fe510 765 }
sv 1:6799c07fe510 766
sv 1:6799c07fe510 767 // necessary operators for eval functions
sv 1:6799c07fe510 768 TVMET_IMPLEMENT_MACRO(greater, >)
sv 1:6799c07fe510 769 TVMET_IMPLEMENT_MACRO(less, <)
sv 1:6799c07fe510 770 TVMET_IMPLEMENT_MACRO(greater_eq, >=)
sv 1:6799c07fe510 771 TVMET_IMPLEMENT_MACRO(less_eq, <=)
sv 1:6799c07fe510 772 TVMET_IMPLEMENT_MACRO(eq, ==)
sv 1:6799c07fe510 773 TVMET_IMPLEMENT_MACRO(not_eq, !=)
sv 1:6799c07fe510 774 TVMET_IMPLEMENT_MACRO(and, &&)
sv 1:6799c07fe510 775 TVMET_IMPLEMENT_MACRO(or, ||)
sv 1:6799c07fe510 776
sv 1:6799c07fe510 777 #undef TVMET_IMPLEMENT_MACRO
sv 1:6799c07fe510 778
sv 1:6799c07fe510 779 #endif // defined(TVMET_HAVE_COMPLEX)
sv 1:6799c07fe510 780
sv 1:6799c07fe510 781
sv 1:6799c07fe510 782 /*
sv 1:6799c07fe510 783 * operator(XprMatrix<E, Rows, Cols>, POD)
sv 1:6799c07fe510 784 * operator(POD, XprMatrix<E, Rows, Cols>)
sv 1:6799c07fe510 785 * Note: operations are per se element wise
sv 1:6799c07fe510 786 */
sv 1:6799c07fe510 787 #define TVMET_IMPLEMENT_MACRO(NAME, OP, TP) \
sv 1:6799c07fe510 788 template<class E, std::size_t Rows, std::size_t Cols> \
sv 1:6799c07fe510 789 inline \
sv 1:6799c07fe510 790 XprMatrix< \
sv 1:6799c07fe510 791 XprBinOp< \
sv 1:6799c07fe510 792 Fcnl_##NAME<typename E::value_type, TP >, \
sv 1:6799c07fe510 793 XprMatrix<E, Rows, Cols>, \
sv 1:6799c07fe510 794 XprLiteral< TP > \
sv 1:6799c07fe510 795 >, \
sv 1:6799c07fe510 796 Rows, Cols \
sv 1:6799c07fe510 797 > \
sv 1:6799c07fe510 798 operator OP (const XprMatrix<E, Rows, Cols>& lhs, TP rhs) { \
sv 1:6799c07fe510 799 typedef XprBinOp< \
sv 1:6799c07fe510 800 Fcnl_##NAME<typename E::value_type, TP >, \
sv 1:6799c07fe510 801 XprMatrix<E, Rows, Cols>, \
sv 1:6799c07fe510 802 XprLiteral< TP > \
sv 1:6799c07fe510 803 > expr_type; \
sv 1:6799c07fe510 804 return XprMatrix<expr_type, Rows, Cols>( \
sv 1:6799c07fe510 805 expr_type(lhs, XprLiteral< TP >(rhs))); \
sv 1:6799c07fe510 806 } \
sv 1:6799c07fe510 807 \
sv 1:6799c07fe510 808 template<class E, std::size_t Rows, std::size_t Cols> \
sv 1:6799c07fe510 809 inline \
sv 1:6799c07fe510 810 XprMatrix< \
sv 1:6799c07fe510 811 XprBinOp< \
sv 1:6799c07fe510 812 Fcnl_##NAME<TP, typename E::value_type>, \
sv 1:6799c07fe510 813 XprLiteral< TP >, \
sv 1:6799c07fe510 814 XprMatrix<E, Rows, Cols> \
sv 1:6799c07fe510 815 >, \
sv 1:6799c07fe510 816 Rows, Cols \
sv 1:6799c07fe510 817 > \
sv 1:6799c07fe510 818 operator OP (TP lhs, const XprMatrix<E, Rows, Cols>& rhs) { \
sv 1:6799c07fe510 819 typedef XprBinOp< \
sv 1:6799c07fe510 820 Fcnl_##NAME< TP, typename E::value_type>, \
sv 1:6799c07fe510 821 XprLiteral< TP >, \
sv 1:6799c07fe510 822 XprMatrix<E, Rows, Cols> \
sv 1:6799c07fe510 823 > expr_type; \
sv 1:6799c07fe510 824 return XprMatrix<expr_type, Rows, Cols>( \
sv 1:6799c07fe510 825 expr_type(XprLiteral< TP >(lhs), rhs)); \
sv 1:6799c07fe510 826 }
sv 1:6799c07fe510 827
sv 1:6799c07fe510 828
sv 1:6799c07fe510 829 // integer operators only, e.g used on double you will get an error
sv 1:6799c07fe510 830 namespace element_wise {
sv 1:6799c07fe510 831 TVMET_IMPLEMENT_MACRO(mod, %, int)
sv 1:6799c07fe510 832 TVMET_IMPLEMENT_MACRO(bitxor, ^, int)
sv 1:6799c07fe510 833 TVMET_IMPLEMENT_MACRO(bitand, &, int)
sv 1:6799c07fe510 834 TVMET_IMPLEMENT_MACRO(bitor, |, int)
sv 1:6799c07fe510 835 TVMET_IMPLEMENT_MACRO(shl, <<, int)
sv 1:6799c07fe510 836 TVMET_IMPLEMENT_MACRO(shr, >>, int)
sv 1:6799c07fe510 837 }
sv 1:6799c07fe510 838
sv 1:6799c07fe510 839 // necessary operators for eval functions
sv 1:6799c07fe510 840 TVMET_IMPLEMENT_MACRO(greater, >, int)
sv 1:6799c07fe510 841 TVMET_IMPLEMENT_MACRO(less, <, int)
sv 1:6799c07fe510 842 TVMET_IMPLEMENT_MACRO(greater_eq, >=, int)
sv 1:6799c07fe510 843 TVMET_IMPLEMENT_MACRO(less_eq, <=, int)
sv 1:6799c07fe510 844 TVMET_IMPLEMENT_MACRO(eq, ==, int)
sv 1:6799c07fe510 845 TVMET_IMPLEMENT_MACRO(not_eq, !=, int)
sv 1:6799c07fe510 846 TVMET_IMPLEMENT_MACRO(and, &&, int)
sv 1:6799c07fe510 847 TVMET_IMPLEMENT_MACRO(or, ||, int)
sv 1:6799c07fe510 848
sv 1:6799c07fe510 849 #if defined(TVMET_HAVE_LONG_LONG)
sv 1:6799c07fe510 850 // integer operators only
sv 1:6799c07fe510 851 namespace element_wise {
sv 1:6799c07fe510 852 TVMET_IMPLEMENT_MACRO(mod, %, long long int)
sv 1:6799c07fe510 853 TVMET_IMPLEMENT_MACRO(bitxor, ^, long long int)
sv 1:6799c07fe510 854 TVMET_IMPLEMENT_MACRO(bitand, &, long long int)
sv 1:6799c07fe510 855 TVMET_IMPLEMENT_MACRO(bitor, |, long long int)
sv 1:6799c07fe510 856 TVMET_IMPLEMENT_MACRO(shl, <<, long long int)
sv 1:6799c07fe510 857 TVMET_IMPLEMENT_MACRO(shr, >>, long long int)
sv 1:6799c07fe510 858 }
sv 1:6799c07fe510 859
sv 1:6799c07fe510 860 // necessary operators for eval functions
sv 1:6799c07fe510 861 TVMET_IMPLEMENT_MACRO(greater, >, long long int)
sv 1:6799c07fe510 862 TVMET_IMPLEMENT_MACRO(less, <, long long int)
sv 1:6799c07fe510 863 TVMET_IMPLEMENT_MACRO(greater_eq, >=, long long int)
sv 1:6799c07fe510 864 TVMET_IMPLEMENT_MACRO(less_eq, <=, long long int)
sv 1:6799c07fe510 865 TVMET_IMPLEMENT_MACRO(eq, ==, long long int)
sv 1:6799c07fe510 866 TVMET_IMPLEMENT_MACRO(not_eq, !=, long long int)
sv 1:6799c07fe510 867 TVMET_IMPLEMENT_MACRO(and, &&, long long int)
sv 1:6799c07fe510 868 TVMET_IMPLEMENT_MACRO(or, ||, long long int)
sv 1:6799c07fe510 869 #endif // defined(TVMET_HAVE_LONG_LONG)
sv 1:6799c07fe510 870
sv 1:6799c07fe510 871 // necessary operators for eval functions
sv 1:6799c07fe510 872 TVMET_IMPLEMENT_MACRO(greater, >, float)
sv 1:6799c07fe510 873 TVMET_IMPLEMENT_MACRO(less, <, float)
sv 1:6799c07fe510 874 TVMET_IMPLEMENT_MACRO(greater_eq, >=, float)
sv 1:6799c07fe510 875 TVMET_IMPLEMENT_MACRO(less_eq, <=, float)
sv 1:6799c07fe510 876 TVMET_IMPLEMENT_MACRO(eq, ==, float)
sv 1:6799c07fe510 877 TVMET_IMPLEMENT_MACRO(not_eq, !=, float)
sv 1:6799c07fe510 878 TVMET_IMPLEMENT_MACRO(and, &&, float)
sv 1:6799c07fe510 879 TVMET_IMPLEMENT_MACRO(or, ||, float)
sv 1:6799c07fe510 880
sv 1:6799c07fe510 881 // necessary operators for eval functions
sv 1:6799c07fe510 882 TVMET_IMPLEMENT_MACRO(greater, >, double)
sv 1:6799c07fe510 883 TVMET_IMPLEMENT_MACRO(less, <, double)
sv 1:6799c07fe510 884 TVMET_IMPLEMENT_MACRO(greater_eq, >=, double)
sv 1:6799c07fe510 885 TVMET_IMPLEMENT_MACRO(less_eq, <=, double)
sv 1:6799c07fe510 886 TVMET_IMPLEMENT_MACRO(eq, ==, double)
sv 1:6799c07fe510 887 TVMET_IMPLEMENT_MACRO(not_eq, !=, double)
sv 1:6799c07fe510 888 TVMET_IMPLEMENT_MACRO(and, &&, double)
sv 1:6799c07fe510 889 TVMET_IMPLEMENT_MACRO(or, ||, double)
sv 1:6799c07fe510 890
sv 1:6799c07fe510 891 #if defined(TVMET_HAVE_LONG_DOUBLE)
sv 1:6799c07fe510 892 // necessary operators for eval functions
sv 1:6799c07fe510 893 TVMET_IMPLEMENT_MACRO(greater, >, long double)
sv 1:6799c07fe510 894 TVMET_IMPLEMENT_MACRO(less, <, long double)
sv 1:6799c07fe510 895 TVMET_IMPLEMENT_MACRO(greater_eq, >=, long double)
sv 1:6799c07fe510 896 TVMET_IMPLEMENT_MACRO(less_eq, <=, long double)
sv 1:6799c07fe510 897 TVMET_IMPLEMENT_MACRO(eq, ==, long double)
sv 1:6799c07fe510 898 TVMET_IMPLEMENT_MACRO(not_eq, !=, long double)
sv 1:6799c07fe510 899 TVMET_IMPLEMENT_MACRO(and, &&, long double)
sv 1:6799c07fe510 900 TVMET_IMPLEMENT_MACRO(or, ||, long double)
sv 1:6799c07fe510 901 #endif // defined(TVMET_HAVE_LONG_DOUBLE)
sv 1:6799c07fe510 902
sv 1:6799c07fe510 903 #undef TVMET_IMPLEMENT_MACRO
sv 1:6799c07fe510 904
sv 1:6799c07fe510 905
sv 1:6799c07fe510 906 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sv 1:6799c07fe510 907 * global unary operators
sv 1:6799c07fe510 908 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
sv 1:6799c07fe510 909
sv 1:6799c07fe510 910
sv 1:6799c07fe510 911 /*
sv 1:6799c07fe510 912 * unary_operator(const XprMatrix<E, Rows, Cols>& m)
sv 1:6799c07fe510 913 * Note: per se element wise
sv 1:6799c07fe510 914 */
sv 1:6799c07fe510 915 #define TVMET_IMPLEMENT_MACRO(NAME, OP) \
sv 1:6799c07fe510 916 template <class E, std::size_t Rows, std::size_t Cols> \
sv 1:6799c07fe510 917 inline \
sv 1:6799c07fe510 918 XprMatrix< \
sv 1:6799c07fe510 919 XprUnOp< \
sv 1:6799c07fe510 920 Fcnl_##NAME<typename E::value_type>, \
sv 1:6799c07fe510 921 XprMatrix<E, Rows, Cols> \
sv 1:6799c07fe510 922 >, \
sv 1:6799c07fe510 923 Rows, Cols \
sv 1:6799c07fe510 924 > \
sv 1:6799c07fe510 925 operator OP (const XprMatrix<E, Rows, Cols>& m) { \
sv 1:6799c07fe510 926 typedef XprUnOp< \
sv 1:6799c07fe510 927 Fcnl_##NAME<typename E::value_type>, \
sv 1:6799c07fe510 928 XprMatrix<E, Rows, Cols> \
sv 1:6799c07fe510 929 > expr_type; \
sv 1:6799c07fe510 930 return XprMatrix<expr_type, Rows, Cols>(expr_type(m)); \
sv 1:6799c07fe510 931 }
sv 1:6799c07fe510 932
sv 1:6799c07fe510 933 TVMET_IMPLEMENT_MACRO(not, !)
sv 1:6799c07fe510 934 TVMET_IMPLEMENT_MACRO(compl, ~)
sv 1:6799c07fe510 935 TVMET_IMPLEMENT_MACRO(neg, -)
sv 1:6799c07fe510 936
sv 1:6799c07fe510 937 #undef TVMET_IMPLEMENT_MACRO
sv 1:6799c07fe510 938
sv 1:6799c07fe510 939
sv 1:6799c07fe510 940 } // namespace tvmet
sv 1:6799c07fe510 941
sv 1:6799c07fe510 942 #endif // TVMET_XPR_MATRIX_OPERATORS_H
sv 1:6799c07fe510 943
sv 1:6799c07fe510 944 // Local Variables:
sv 1:6799c07fe510 945 // mode:C++
sv 1:6799c07fe510 946 // tab-width:8
sv 1:6799c07fe510 947 // End: