Eurobot2012_Secondary

Fork of Eurobot_2012_Secondary by Shuto Naruse

Committer:
narshu
Date:
Wed Oct 17 22:25:31 2012 +0000
Revision:
1:cc2a9eb0bd55
Commit before publishing

Who changed what in which revision?

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