2014 Eurobot fork

Dependencies:   mbed-rtos mbed QEI

Committer:
madcowswe
Date:
Sat Apr 06 20:57:54 2013 +0000
Revision:
15:9c5aaeda36dc
Encoders fairly tuned, still has random noise in it

Who changed what in which revision?

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