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