2014 Eurobot fork

Dependencies:   mbed-rtos mbed QEI

Committer:
rsavitski
Date:
Tue Oct 15 12:19:32 2013 +0000
Revision:
92:4a1225fbb146
Parent:
15:9c5aaeda36dc
touch: ripped out 2013-specific bits. Need to address "2014" comments. Rewrite AI layer and other deleted parts.

Who changed what in which revision?

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