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