Eurobot2012_Primary

Dependencies:   mbed Eurobot_2012_Primary

Committer:
narshu
Date:
Wed Oct 17 22:22:28 2012 +0000
Revision:
25:143b19c1fb05
Commit before publishing;

Who changed what in which revision?

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