Eurobot2012_Primary

Dependencies:   mbed Eurobot_2012_Primary

Committer:
narshu
Date:
Wed Oct 17 22:22:47 2012 +0000
Revision:
26:0995f61cb7b8
Parent:
25:143b19c1fb05
Eurobot 2012 Primary;

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