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