Cooper Liu
/
Eurobot2013_Co-Processor
working version with calibration done
Fork of Eurobot2013 by
tvmet/xpr/VectorFunctions.h@1:6799c07fe510, 2012-11-07 (annotated)
- Committer:
- sv
- Date:
- Wed Nov 07 14:37:35 2012 +0000
- Revision:
- 1:6799c07fe510
Preliminary copy of 2012 code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sv | 1:6799c07fe510 | 1 | /* |
sv | 1:6799c07fe510 | 2 | * Tiny Vector Matrix Library |
sv | 1:6799c07fe510 | 3 | * Dense Vector Matrix Libary of Tiny size using Expression Templates |
sv | 1:6799c07fe510 | 4 | * |
sv | 1:6799c07fe510 | 5 | * Copyright (C) 2001 - 2007 Olaf Petzold <opetzold@users.sourceforge.net> |
sv | 1:6799c07fe510 | 6 | * |
sv | 1:6799c07fe510 | 7 | * This library is free software; you can redistribute it and/or |
sv | 1:6799c07fe510 | 8 | * modify it under the terms of the GNU Lesser General Public |
sv | 1:6799c07fe510 | 9 | * License as published by the Free Software Foundation; either |
sv | 1:6799c07fe510 | 10 | * version 2.1 of the License, or (at your option) any later version. |
sv | 1:6799c07fe510 | 11 | * |
sv | 1:6799c07fe510 | 12 | * This library is distributed in the hope that it will be useful, |
sv | 1:6799c07fe510 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
sv | 1:6799c07fe510 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
sv | 1:6799c07fe510 | 15 | * Lesser General Public License for more details. |
sv | 1:6799c07fe510 | 16 | * |
sv | 1:6799c07fe510 | 17 | * You should have received a copy of the GNU Lesser General Public |
sv | 1:6799c07fe510 | 18 | * License along with this library; if not, write to the Free Software |
sv | 1:6799c07fe510 | 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
sv | 1:6799c07fe510 | 20 | * |
sv | 1:6799c07fe510 | 21 | * $Id: VectorFunctions.h,v 1.21 2007-06-23 15:59:00 opetzold Exp $ |
sv | 1:6799c07fe510 | 22 | */ |
sv | 1:6799c07fe510 | 23 | |
sv | 1:6799c07fe510 | 24 | #ifndef TVMET_XPR_VECTOR_FUNCTIONS_H |
sv | 1:6799c07fe510 | 25 | #define TVMET_XPR_VECTOR_FUNCTIONS_H |
sv | 1:6799c07fe510 | 26 | |
sv | 1:6799c07fe510 | 27 | namespace tvmet { |
sv | 1:6799c07fe510 | 28 | |
sv | 1:6799c07fe510 | 29 | |
sv | 1:6799c07fe510 | 30 | /* forwards */ |
sv | 1:6799c07fe510 | 31 | template<class T, std::size_t Sz> class Vector; |
sv | 1:6799c07fe510 | 32 | |
sv | 1:6799c07fe510 | 33 | |
sv | 1:6799c07fe510 | 34 | /********************************************************* |
sv | 1:6799c07fe510 | 35 | * PART I: DECLARATION |
sv | 1:6799c07fe510 | 36 | *********************************************************/ |
sv | 1:6799c07fe510 | 37 | |
sv | 1:6799c07fe510 | 38 | |
sv | 1:6799c07fe510 | 39 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
sv | 1:6799c07fe510 | 40 | * Vector arithmetic functions add, sub, mul and div |
sv | 1:6799c07fe510 | 41 | *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
sv | 1:6799c07fe510 | 42 | |
sv | 1:6799c07fe510 | 43 | |
sv | 1:6799c07fe510 | 44 | /* |
sv | 1:6799c07fe510 | 45 | * function(XprVector<E1, Sz>, XprVector<E2, Sz>) |
sv | 1:6799c07fe510 | 46 | */ |
sv | 1:6799c07fe510 | 47 | #define TVMET_DECLARE_MACRO(NAME) \ |
sv | 1:6799c07fe510 | 48 | template<class E1, class E2, std::size_t Sz> \ |
sv | 1:6799c07fe510 | 49 | XprVector< \ |
sv | 1:6799c07fe510 | 50 | XprBinOp< \ |
sv | 1:6799c07fe510 | 51 | Fcnl_##NAME<typename E1::value_type, typename E2::value_type>, \ |
sv | 1:6799c07fe510 | 52 | XprVector<E1, Sz>, \ |
sv | 1:6799c07fe510 | 53 | XprVector<E2, Sz> \ |
sv | 1:6799c07fe510 | 54 | >, \ |
sv | 1:6799c07fe510 | 55 | Sz \ |
sv | 1:6799c07fe510 | 56 | > \ |
sv | 1:6799c07fe510 | 57 | NAME (const XprVector<E1, Sz>& lhs, \ |
sv | 1:6799c07fe510 | 58 | const XprVector<E2, Sz>& rhs) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 59 | |
sv | 1:6799c07fe510 | 60 | TVMET_DECLARE_MACRO(add) // per se element wise |
sv | 1:6799c07fe510 | 61 | TVMET_DECLARE_MACRO(sub) // per se element wise |
sv | 1:6799c07fe510 | 62 | TVMET_DECLARE_MACRO(mul) // per se element wise |
sv | 1:6799c07fe510 | 63 | namespace element_wise { |
sv | 1:6799c07fe510 | 64 | TVMET_DECLARE_MACRO(div) // not defined for vectors |
sv | 1:6799c07fe510 | 65 | } |
sv | 1:6799c07fe510 | 66 | |
sv | 1:6799c07fe510 | 67 | #undef TVMET_DECLARE_MACRO |
sv | 1:6799c07fe510 | 68 | |
sv | 1:6799c07fe510 | 69 | |
sv | 1:6799c07fe510 | 70 | /* |
sv | 1:6799c07fe510 | 71 | * function(XprVector<E, Sz>, POD) |
sv | 1:6799c07fe510 | 72 | * function(POD, XprVector<E, Sz>) |
sv | 1:6799c07fe510 | 73 | * Note: - operations +,-,*,/ are per se element wise |
sv | 1:6799c07fe510 | 74 | */ |
sv | 1:6799c07fe510 | 75 | #define TVMET_DECLARE_MACRO(NAME, POD) \ |
sv | 1:6799c07fe510 | 76 | template<class E, std::size_t Sz> \ |
sv | 1:6799c07fe510 | 77 | XprVector< \ |
sv | 1:6799c07fe510 | 78 | XprBinOp< \ |
sv | 1:6799c07fe510 | 79 | Fcnl_##NAME< typename E::value_type, POD >, \ |
sv | 1:6799c07fe510 | 80 | XprVector<E, Sz>, \ |
sv | 1:6799c07fe510 | 81 | XprLiteral< POD > \ |
sv | 1:6799c07fe510 | 82 | >, \ |
sv | 1:6799c07fe510 | 83 | Sz \ |
sv | 1:6799c07fe510 | 84 | > \ |
sv | 1:6799c07fe510 | 85 | NAME (const XprVector<E, Sz>& lhs, \ |
sv | 1:6799c07fe510 | 86 | POD rhs) TVMET_CXX_ALWAYS_INLINE; \ |
sv | 1:6799c07fe510 | 87 | \ |
sv | 1:6799c07fe510 | 88 | template<class E, std::size_t Sz> \ |
sv | 1:6799c07fe510 | 89 | XprVector< \ |
sv | 1:6799c07fe510 | 90 | XprBinOp< \ |
sv | 1:6799c07fe510 | 91 | Fcnl_##NAME< POD, typename E::value_type>, \ |
sv | 1:6799c07fe510 | 92 | XprLiteral< POD >, \ |
sv | 1:6799c07fe510 | 93 | XprVector<E, Sz> \ |
sv | 1:6799c07fe510 | 94 | >, \ |
sv | 1:6799c07fe510 | 95 | Sz \ |
sv | 1:6799c07fe510 | 96 | > \ |
sv | 1:6799c07fe510 | 97 | NAME (POD lhs, \ |
sv | 1:6799c07fe510 | 98 | const XprVector<E, Sz>& rhs) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 99 | |
sv | 1:6799c07fe510 | 100 | TVMET_DECLARE_MACRO(add, int) |
sv | 1:6799c07fe510 | 101 | TVMET_DECLARE_MACRO(sub, int) |
sv | 1:6799c07fe510 | 102 | TVMET_DECLARE_MACRO(mul, int) |
sv | 1:6799c07fe510 | 103 | TVMET_DECLARE_MACRO(div, int) |
sv | 1:6799c07fe510 | 104 | |
sv | 1:6799c07fe510 | 105 | #if defined(TVMET_HAVE_LONG_LONG) |
sv | 1:6799c07fe510 | 106 | TVMET_DECLARE_MACRO(add, long long int) |
sv | 1:6799c07fe510 | 107 | TVMET_DECLARE_MACRO(sub, long long int) |
sv | 1:6799c07fe510 | 108 | TVMET_DECLARE_MACRO(mul, long long int) |
sv | 1:6799c07fe510 | 109 | TVMET_DECLARE_MACRO(div, long long int) |
sv | 1:6799c07fe510 | 110 | #endif |
sv | 1:6799c07fe510 | 111 | |
sv | 1:6799c07fe510 | 112 | TVMET_DECLARE_MACRO(add, float) |
sv | 1:6799c07fe510 | 113 | TVMET_DECLARE_MACRO(sub, float) |
sv | 1:6799c07fe510 | 114 | TVMET_DECLARE_MACRO(mul, float) |
sv | 1:6799c07fe510 | 115 | TVMET_DECLARE_MACRO(div, float) |
sv | 1:6799c07fe510 | 116 | |
sv | 1:6799c07fe510 | 117 | TVMET_DECLARE_MACRO(add, double) |
sv | 1:6799c07fe510 | 118 | TVMET_DECLARE_MACRO(sub, double) |
sv | 1:6799c07fe510 | 119 | TVMET_DECLARE_MACRO(mul, double) |
sv | 1:6799c07fe510 | 120 | TVMET_DECLARE_MACRO(div, double) |
sv | 1:6799c07fe510 | 121 | |
sv | 1:6799c07fe510 | 122 | #if defined(TVMET_HAVE_LONG_DOUBLE) |
sv | 1:6799c07fe510 | 123 | TVMET_DECLARE_MACRO(add, long double) |
sv | 1:6799c07fe510 | 124 | TVMET_DECLARE_MACRO(sub, long double) |
sv | 1:6799c07fe510 | 125 | TVMET_DECLARE_MACRO(mul, long double) |
sv | 1:6799c07fe510 | 126 | TVMET_DECLARE_MACRO(div, long double) |
sv | 1:6799c07fe510 | 127 | #endif |
sv | 1:6799c07fe510 | 128 | |
sv | 1:6799c07fe510 | 129 | #undef TVMET_DECLARE_MACRO |
sv | 1:6799c07fe510 | 130 | |
sv | 1:6799c07fe510 | 131 | |
sv | 1:6799c07fe510 | 132 | #if defined(TVMET_HAVE_COMPLEX) |
sv | 1:6799c07fe510 | 133 | /* |
sv | 1:6799c07fe510 | 134 | * function(XprMatrix<E, Rows, Cols>, complex<T>) |
sv | 1:6799c07fe510 | 135 | * function(complex<T>, XprMatrix<E, Rows, Cols>) |
sv | 1:6799c07fe510 | 136 | * Note: - operations +,-,*,/ are per se element wise |
sv | 1:6799c07fe510 | 137 | * \todo type promotion |
sv | 1:6799c07fe510 | 138 | */ |
sv | 1:6799c07fe510 | 139 | #define TVMET_DECLARE_MACRO(NAME) \ |
sv | 1:6799c07fe510 | 140 | template<class E, std::size_t Sz, class T> \ |
sv | 1:6799c07fe510 | 141 | XprVector< \ |
sv | 1:6799c07fe510 | 142 | XprBinOp< \ |
sv | 1:6799c07fe510 | 143 | Fcnl_##NAME< typename E::value_type, std::complex<T> >, \ |
sv | 1:6799c07fe510 | 144 | XprVector<E, Sz>, \ |
sv | 1:6799c07fe510 | 145 | XprLiteral< std::complex<T> > \ |
sv | 1:6799c07fe510 | 146 | >, \ |
sv | 1:6799c07fe510 | 147 | Sz \ |
sv | 1:6799c07fe510 | 148 | > \ |
sv | 1:6799c07fe510 | 149 | NAME (const XprVector<E, Sz>& lhs, \ |
sv | 1:6799c07fe510 | 150 | const std::complex<T>& rhs) TVMET_CXX_ALWAYS_INLINE; \ |
sv | 1:6799c07fe510 | 151 | \ |
sv | 1:6799c07fe510 | 152 | template<class E, std::size_t Sz, class T> \ |
sv | 1:6799c07fe510 | 153 | XprVector< \ |
sv | 1:6799c07fe510 | 154 | XprBinOp< \ |
sv | 1:6799c07fe510 | 155 | Fcnl_##NAME< std::complex<T>, typename E::value_type>, \ |
sv | 1:6799c07fe510 | 156 | XprLiteral< std::complex<T> >, \ |
sv | 1:6799c07fe510 | 157 | XprVector<E, Sz> \ |
sv | 1:6799c07fe510 | 158 | >, \ |
sv | 1:6799c07fe510 | 159 | Sz \ |
sv | 1:6799c07fe510 | 160 | > \ |
sv | 1:6799c07fe510 | 161 | NAME (const std::complex<T>& lhs, \ |
sv | 1:6799c07fe510 | 162 | const XprVector<E, Sz>& rhs) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 163 | |
sv | 1:6799c07fe510 | 164 | TVMET_DECLARE_MACRO(add) |
sv | 1:6799c07fe510 | 165 | TVMET_DECLARE_MACRO(sub) |
sv | 1:6799c07fe510 | 166 | TVMET_DECLARE_MACRO(mul) |
sv | 1:6799c07fe510 | 167 | TVMET_DECLARE_MACRO(div) |
sv | 1:6799c07fe510 | 168 | |
sv | 1:6799c07fe510 | 169 | #undef TVMET_DECLARE_MACRO |
sv | 1:6799c07fe510 | 170 | |
sv | 1:6799c07fe510 | 171 | #endif // defined(TVMET_HAVE_COMPLEX) |
sv | 1:6799c07fe510 | 172 | |
sv | 1:6799c07fe510 | 173 | |
sv | 1:6799c07fe510 | 174 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
sv | 1:6799c07fe510 | 175 | * vector specific functions |
sv | 1:6799c07fe510 | 176 | *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
sv | 1:6799c07fe510 | 177 | |
sv | 1:6799c07fe510 | 178 | |
sv | 1:6799c07fe510 | 179 | template<class E, std::size_t Sz> |
sv | 1:6799c07fe510 | 180 | typename NumericTraits<typename E::value_type>::sum_type |
sv | 1:6799c07fe510 | 181 | sum(const XprVector<E, Sz>& v) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 182 | |
sv | 1:6799c07fe510 | 183 | |
sv | 1:6799c07fe510 | 184 | template<class E, std::size_t Sz> |
sv | 1:6799c07fe510 | 185 | typename NumericTraits<typename E::value_type>::sum_type |
sv | 1:6799c07fe510 | 186 | product(const XprVector<E, Sz>& v) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 187 | |
sv | 1:6799c07fe510 | 188 | |
sv | 1:6799c07fe510 | 189 | template<class E1, class E2, std::size_t Sz> |
sv | 1:6799c07fe510 | 190 | typename PromoteTraits< |
sv | 1:6799c07fe510 | 191 | typename E1::value_type, |
sv | 1:6799c07fe510 | 192 | typename E2::value_type |
sv | 1:6799c07fe510 | 193 | >::value_type |
sv | 1:6799c07fe510 | 194 | dot(const XprVector<E1, Sz>& lhs, |
sv | 1:6799c07fe510 | 195 | const XprVector<E2, Sz>& rhs) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 196 | |
sv | 1:6799c07fe510 | 197 | |
sv | 1:6799c07fe510 | 198 | template<class T, class E, std::size_t Sz> |
sv | 1:6799c07fe510 | 199 | typename PromoteTraits<T, typename E::value_type>::value_type |
sv | 1:6799c07fe510 | 200 | dot(const Vector<T, Sz>& lhs, |
sv | 1:6799c07fe510 | 201 | const XprVector<E, Sz>& rhs) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 202 | |
sv | 1:6799c07fe510 | 203 | |
sv | 1:6799c07fe510 | 204 | template<class E, class T, std::size_t Sz> |
sv | 1:6799c07fe510 | 205 | typename PromoteTraits<T, typename E::value_type>::value_type |
sv | 1:6799c07fe510 | 206 | dot(const XprVector<E, Sz>& lhs, |
sv | 1:6799c07fe510 | 207 | const Vector<T, Sz>& rhs) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 208 | |
sv | 1:6799c07fe510 | 209 | |
sv | 1:6799c07fe510 | 210 | template<class E1, class E2> |
sv | 1:6799c07fe510 | 211 | Vector< |
sv | 1:6799c07fe510 | 212 | typename PromoteTraits< |
sv | 1:6799c07fe510 | 213 | typename E1::value_type, |
sv | 1:6799c07fe510 | 214 | typename E2::value_type |
sv | 1:6799c07fe510 | 215 | >::value_type, |
sv | 1:6799c07fe510 | 216 | 3 |
sv | 1:6799c07fe510 | 217 | > |
sv | 1:6799c07fe510 | 218 | cross(const XprVector<E1, 3>& lhs, |
sv | 1:6799c07fe510 | 219 | const XprVector<E2, 3>& rhs) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 220 | |
sv | 1:6799c07fe510 | 221 | |
sv | 1:6799c07fe510 | 222 | template<class T, class E> |
sv | 1:6799c07fe510 | 223 | Vector< |
sv | 1:6799c07fe510 | 224 | typename PromoteTraits<T, typename E::value_type>::value_type, 3> |
sv | 1:6799c07fe510 | 225 | cross(const Vector<T, 3>& lhs, |
sv | 1:6799c07fe510 | 226 | const XprVector<E, 3>& rhs) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 227 | |
sv | 1:6799c07fe510 | 228 | |
sv | 1:6799c07fe510 | 229 | template<class E, class T> |
sv | 1:6799c07fe510 | 230 | Vector< |
sv | 1:6799c07fe510 | 231 | typename PromoteTraits<T, typename E::value_type>::value_type, 3> |
sv | 1:6799c07fe510 | 232 | cross(const XprVector<E, 3>& lhs, |
sv | 1:6799c07fe510 | 233 | const Vector<T, 3>& rhs) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 234 | |
sv | 1:6799c07fe510 | 235 | |
sv | 1:6799c07fe510 | 236 | template<class E, std::size_t Sz> |
sv | 1:6799c07fe510 | 237 | typename NumericTraits<typename E::value_type>::sum_type |
sv | 1:6799c07fe510 | 238 | norm1(const XprVector<E, Sz>& v) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 239 | |
sv | 1:6799c07fe510 | 240 | |
sv | 1:6799c07fe510 | 241 | template<class E, std::size_t Sz> |
sv | 1:6799c07fe510 | 242 | typename NumericTraits<typename E::value_type>::sum_type |
sv | 1:6799c07fe510 | 243 | norm2(const XprVector<E, Sz>& v) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 244 | |
sv | 1:6799c07fe510 | 245 | |
sv | 1:6799c07fe510 | 246 | template<class E, std::size_t Sz> |
sv | 1:6799c07fe510 | 247 | XprVector< |
sv | 1:6799c07fe510 | 248 | XprBinOp< |
sv | 1:6799c07fe510 | 249 | Fcnl_div<typename E::value_type, typename E::value_type>, |
sv | 1:6799c07fe510 | 250 | XprVector<E, Sz>, |
sv | 1:6799c07fe510 | 251 | XprLiteral<typename E::value_type> |
sv | 1:6799c07fe510 | 252 | >, |
sv | 1:6799c07fe510 | 253 | Sz |
sv | 1:6799c07fe510 | 254 | > |
sv | 1:6799c07fe510 | 255 | normalize(const XprVector<E, Sz>& v) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 256 | |
sv | 1:6799c07fe510 | 257 | |
sv | 1:6799c07fe510 | 258 | /********************************************************* |
sv | 1:6799c07fe510 | 259 | * PART II: IMPLEMENTATION |
sv | 1:6799c07fe510 | 260 | *********************************************************/ |
sv | 1:6799c07fe510 | 261 | |
sv | 1:6799c07fe510 | 262 | |
sv | 1:6799c07fe510 | 263 | /* |
sv | 1:6799c07fe510 | 264 | * function(XprVector<E1, Sz>, XprVector<E2, Sz>) |
sv | 1:6799c07fe510 | 265 | */ |
sv | 1:6799c07fe510 | 266 | #define TVMET_IMPLEMENT_MACRO(NAME) \ |
sv | 1:6799c07fe510 | 267 | template<class E1, class E2, std::size_t Sz> \ |
sv | 1:6799c07fe510 | 268 | inline \ |
sv | 1:6799c07fe510 | 269 | XprVector< \ |
sv | 1:6799c07fe510 | 270 | XprBinOp< \ |
sv | 1:6799c07fe510 | 271 | Fcnl_##NAME<typename E1::value_type, typename E2::value_type>, \ |
sv | 1:6799c07fe510 | 272 | XprVector<E1, Sz>, \ |
sv | 1:6799c07fe510 | 273 | XprVector<E2, Sz> \ |
sv | 1:6799c07fe510 | 274 | >, \ |
sv | 1:6799c07fe510 | 275 | Sz \ |
sv | 1:6799c07fe510 | 276 | > \ |
sv | 1:6799c07fe510 | 277 | NAME (const XprVector<E1, Sz>& lhs, const XprVector<E2, Sz>& rhs) { \ |
sv | 1:6799c07fe510 | 278 | typedef XprBinOp< \ |
sv | 1:6799c07fe510 | 279 | Fcnl_##NAME<typename E1::value_type, typename E2::value_type>, \ |
sv | 1:6799c07fe510 | 280 | XprVector<E1, Sz>, \ |
sv | 1:6799c07fe510 | 281 | XprVector<E2, Sz> \ |
sv | 1:6799c07fe510 | 282 | > expr_type; \ |
sv | 1:6799c07fe510 | 283 | return XprVector<expr_type, Sz>(expr_type(lhs, rhs)); \ |
sv | 1:6799c07fe510 | 284 | } |
sv | 1:6799c07fe510 | 285 | |
sv | 1:6799c07fe510 | 286 | TVMET_IMPLEMENT_MACRO(add) // per se element wise |
sv | 1:6799c07fe510 | 287 | TVMET_IMPLEMENT_MACRO(sub) // per se element wise |
sv | 1:6799c07fe510 | 288 | TVMET_IMPLEMENT_MACRO(mul) // per se element wise |
sv | 1:6799c07fe510 | 289 | namespace element_wise { |
sv | 1:6799c07fe510 | 290 | TVMET_IMPLEMENT_MACRO(div) // not defined for vectors |
sv | 1:6799c07fe510 | 291 | } |
sv | 1:6799c07fe510 | 292 | |
sv | 1:6799c07fe510 | 293 | #undef TVMET_IMPLEMENT_MACRO |
sv | 1:6799c07fe510 | 294 | |
sv | 1:6799c07fe510 | 295 | |
sv | 1:6799c07fe510 | 296 | /* |
sv | 1:6799c07fe510 | 297 | * function(XprVector<E, Sz>, POD) |
sv | 1:6799c07fe510 | 298 | * function(POD, XprVector<E, Sz>) |
sv | 1:6799c07fe510 | 299 | * Note: - operations +,-,*,/ are per se element wise |
sv | 1:6799c07fe510 | 300 | */ |
sv | 1:6799c07fe510 | 301 | #define TVMET_IMPLEMENT_MACRO(NAME, POD) \ |
sv | 1:6799c07fe510 | 302 | template<class E, std::size_t Sz> \ |
sv | 1:6799c07fe510 | 303 | inline \ |
sv | 1:6799c07fe510 | 304 | XprVector< \ |
sv | 1:6799c07fe510 | 305 | XprBinOp< \ |
sv | 1:6799c07fe510 | 306 | Fcnl_##NAME< typename E::value_type, POD >, \ |
sv | 1:6799c07fe510 | 307 | XprVector<E, Sz>, \ |
sv | 1:6799c07fe510 | 308 | XprLiteral< POD > \ |
sv | 1:6799c07fe510 | 309 | >, \ |
sv | 1:6799c07fe510 | 310 | Sz \ |
sv | 1:6799c07fe510 | 311 | > \ |
sv | 1:6799c07fe510 | 312 | NAME (const XprVector<E, Sz>& lhs, POD rhs) { \ |
sv | 1:6799c07fe510 | 313 | typedef XprBinOp< \ |
sv | 1:6799c07fe510 | 314 | Fcnl_##NAME< typename E::value_type, POD >, \ |
sv | 1:6799c07fe510 | 315 | XprVector<E, Sz>, \ |
sv | 1:6799c07fe510 | 316 | XprLiteral< POD > \ |
sv | 1:6799c07fe510 | 317 | > expr_type; \ |
sv | 1:6799c07fe510 | 318 | return XprVector<expr_type, Sz>( \ |
sv | 1:6799c07fe510 | 319 | expr_type(lhs, XprLiteral< POD >(rhs))); \ |
sv | 1:6799c07fe510 | 320 | } \ |
sv | 1:6799c07fe510 | 321 | \ |
sv | 1:6799c07fe510 | 322 | template<class E, std::size_t Sz> \ |
sv | 1:6799c07fe510 | 323 | inline \ |
sv | 1:6799c07fe510 | 324 | XprVector< \ |
sv | 1:6799c07fe510 | 325 | XprBinOp< \ |
sv | 1:6799c07fe510 | 326 | Fcnl_##NAME< POD, typename E::value_type>, \ |
sv | 1:6799c07fe510 | 327 | XprLiteral< POD >, \ |
sv | 1:6799c07fe510 | 328 | XprVector<E, Sz> \ |
sv | 1:6799c07fe510 | 329 | >, \ |
sv | 1:6799c07fe510 | 330 | Sz \ |
sv | 1:6799c07fe510 | 331 | > \ |
sv | 1:6799c07fe510 | 332 | NAME (POD lhs, const XprVector<E, Sz>& rhs) { \ |
sv | 1:6799c07fe510 | 333 | typedef XprBinOp< \ |
sv | 1:6799c07fe510 | 334 | Fcnl_##NAME< POD, typename E::value_type>, \ |
sv | 1:6799c07fe510 | 335 | XprLiteral< POD >, \ |
sv | 1:6799c07fe510 | 336 | XprVector<E, Sz> \ |
sv | 1:6799c07fe510 | 337 | > expr_type; \ |
sv | 1:6799c07fe510 | 338 | return XprVector<expr_type, Sz>( \ |
sv | 1:6799c07fe510 | 339 | expr_type(XprLiteral< POD >(lhs), rhs)); \ |
sv | 1:6799c07fe510 | 340 | } |
sv | 1:6799c07fe510 | 341 | |
sv | 1:6799c07fe510 | 342 | TVMET_IMPLEMENT_MACRO(add, int) |
sv | 1:6799c07fe510 | 343 | TVMET_IMPLEMENT_MACRO(sub, int) |
sv | 1:6799c07fe510 | 344 | TVMET_IMPLEMENT_MACRO(mul, int) |
sv | 1:6799c07fe510 | 345 | TVMET_IMPLEMENT_MACRO(div, int) |
sv | 1:6799c07fe510 | 346 | |
sv | 1:6799c07fe510 | 347 | #if defined(TVMET_HAVE_LONG_LONG) |
sv | 1:6799c07fe510 | 348 | TVMET_IMPLEMENT_MACRO(add, long long int) |
sv | 1:6799c07fe510 | 349 | TVMET_IMPLEMENT_MACRO(sub, long long int) |
sv | 1:6799c07fe510 | 350 | TVMET_IMPLEMENT_MACRO(mul, long long int) |
sv | 1:6799c07fe510 | 351 | TVMET_IMPLEMENT_MACRO(div, long long int) |
sv | 1:6799c07fe510 | 352 | #endif |
sv | 1:6799c07fe510 | 353 | |
sv | 1:6799c07fe510 | 354 | TVMET_IMPLEMENT_MACRO(add, float) |
sv | 1:6799c07fe510 | 355 | TVMET_IMPLEMENT_MACRO(sub, float) |
sv | 1:6799c07fe510 | 356 | TVMET_IMPLEMENT_MACRO(mul, float) |
sv | 1:6799c07fe510 | 357 | TVMET_IMPLEMENT_MACRO(div, float) |
sv | 1:6799c07fe510 | 358 | |
sv | 1:6799c07fe510 | 359 | TVMET_IMPLEMENT_MACRO(add, double) |
sv | 1:6799c07fe510 | 360 | TVMET_IMPLEMENT_MACRO(sub, double) |
sv | 1:6799c07fe510 | 361 | TVMET_IMPLEMENT_MACRO(mul, double) |
sv | 1:6799c07fe510 | 362 | TVMET_IMPLEMENT_MACRO(div, double) |
sv | 1:6799c07fe510 | 363 | |
sv | 1:6799c07fe510 | 364 | #if defined(TVMET_HAVE_LONG_DOUBLE) |
sv | 1:6799c07fe510 | 365 | TVMET_IMPLEMENT_MACRO(add, long double) |
sv | 1:6799c07fe510 | 366 | TVMET_IMPLEMENT_MACRO(sub, long double) |
sv | 1:6799c07fe510 | 367 | TVMET_IMPLEMENT_MACRO(mul, long double) |
sv | 1:6799c07fe510 | 368 | TVMET_IMPLEMENT_MACRO(div, long double) |
sv | 1:6799c07fe510 | 369 | #endif |
sv | 1:6799c07fe510 | 370 | |
sv | 1:6799c07fe510 | 371 | #undef TVMET_IMPLEMENT_MACRO |
sv | 1:6799c07fe510 | 372 | |
sv | 1:6799c07fe510 | 373 | |
sv | 1:6799c07fe510 | 374 | #if defined(TVMET_HAVE_COMPLEX) |
sv | 1:6799c07fe510 | 375 | /* |
sv | 1:6799c07fe510 | 376 | * function(XprMatrix<E, Rows, Cols>, complex<T>) |
sv | 1:6799c07fe510 | 377 | * function(complex<T>, XprMatrix<E, Rows, Cols>) |
sv | 1:6799c07fe510 | 378 | * Note: - operations +,-,*,/ are per se element wise |
sv | 1:6799c07fe510 | 379 | * \todo type promotion |
sv | 1:6799c07fe510 | 380 | */ |
sv | 1:6799c07fe510 | 381 | #define TVMET_IMPLEMENT_MACRO(NAME) \ |
sv | 1:6799c07fe510 | 382 | template<class E, std::size_t Sz, class T> \ |
sv | 1:6799c07fe510 | 383 | inline \ |
sv | 1:6799c07fe510 | 384 | XprVector< \ |
sv | 1:6799c07fe510 | 385 | XprBinOp< \ |
sv | 1:6799c07fe510 | 386 | Fcnl_##NAME< typename E::value_type, std::complex<T> >, \ |
sv | 1:6799c07fe510 | 387 | XprVector<E, Sz>, \ |
sv | 1:6799c07fe510 | 388 | XprLiteral< std::complex<T> > \ |
sv | 1:6799c07fe510 | 389 | >, \ |
sv | 1:6799c07fe510 | 390 | Sz \ |
sv | 1:6799c07fe510 | 391 | > \ |
sv | 1:6799c07fe510 | 392 | NAME (const XprVector<E, Sz>& lhs, const std::complex<T>& rhs) { \ |
sv | 1:6799c07fe510 | 393 | typedef XprBinOp< \ |
sv | 1:6799c07fe510 | 394 | Fcnl_##NAME< typename E::value_type, std::complex<T> >, \ |
sv | 1:6799c07fe510 | 395 | XprVector<E, Sz>, \ |
sv | 1:6799c07fe510 | 396 | XprLiteral< std::complex<T> > \ |
sv | 1:6799c07fe510 | 397 | > expr_type; \ |
sv | 1:6799c07fe510 | 398 | return XprVector<expr_type, Sz>( \ |
sv | 1:6799c07fe510 | 399 | expr_type(lhs, XprLiteral< std::complex<T> >(rhs))); \ |
sv | 1:6799c07fe510 | 400 | } \ |
sv | 1:6799c07fe510 | 401 | \ |
sv | 1:6799c07fe510 | 402 | template<class E, std::size_t Sz, class T> \ |
sv | 1:6799c07fe510 | 403 | inline \ |
sv | 1:6799c07fe510 | 404 | XprVector< \ |
sv | 1:6799c07fe510 | 405 | XprBinOp< \ |
sv | 1:6799c07fe510 | 406 | Fcnl_##NAME< std::complex<T>, typename E::value_type>, \ |
sv | 1:6799c07fe510 | 407 | XprLiteral< std::complex<T> >, \ |
sv | 1:6799c07fe510 | 408 | XprVector<E, Sz> \ |
sv | 1:6799c07fe510 | 409 | >, \ |
sv | 1:6799c07fe510 | 410 | Sz \ |
sv | 1:6799c07fe510 | 411 | > \ |
sv | 1:6799c07fe510 | 412 | NAME (const std::complex<T>& lhs, const XprVector<E, Sz>& rhs) { \ |
sv | 1:6799c07fe510 | 413 | typedef XprBinOp< \ |
sv | 1:6799c07fe510 | 414 | Fcnl_##NAME< std::complex<T>, typename E::value_type>, \ |
sv | 1:6799c07fe510 | 415 | XprLiteral< std::complex<T> >, \ |
sv | 1:6799c07fe510 | 416 | XprVector<E, Sz> \ |
sv | 1:6799c07fe510 | 417 | > expr_type; \ |
sv | 1:6799c07fe510 | 418 | return XprVector<expr_type, Sz>( \ |
sv | 1:6799c07fe510 | 419 | expr_type(XprLiteral< std::complex<T> >(lhs), rhs)); \ |
sv | 1:6799c07fe510 | 420 | } |
sv | 1:6799c07fe510 | 421 | |
sv | 1:6799c07fe510 | 422 | TVMET_IMPLEMENT_MACRO(add) |
sv | 1:6799c07fe510 | 423 | TVMET_IMPLEMENT_MACRO(sub) |
sv | 1:6799c07fe510 | 424 | TVMET_IMPLEMENT_MACRO(mul) |
sv | 1:6799c07fe510 | 425 | TVMET_IMPLEMENT_MACRO(div) |
sv | 1:6799c07fe510 | 426 | |
sv | 1:6799c07fe510 | 427 | #undef TVMET_IMPLEMENT_MACRO |
sv | 1:6799c07fe510 | 428 | |
sv | 1:6799c07fe510 | 429 | #endif // defined(TVMET_HAVE_COMPLEX) |
sv | 1:6799c07fe510 | 430 | |
sv | 1:6799c07fe510 | 431 | |
sv | 1:6799c07fe510 | 432 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
sv | 1:6799c07fe510 | 433 | * vector specific functions |
sv | 1:6799c07fe510 | 434 | *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
sv | 1:6799c07fe510 | 435 | |
sv | 1:6799c07fe510 | 436 | |
sv | 1:6799c07fe510 | 437 | /** |
sv | 1:6799c07fe510 | 438 | * \fn sum(const XprVector<E, Sz>& v) |
sv | 1:6799c07fe510 | 439 | * \brief Compute the sum of the vector expression. |
sv | 1:6799c07fe510 | 440 | * \ingroup _unary_function |
sv | 1:6799c07fe510 | 441 | * |
sv | 1:6799c07fe510 | 442 | * Simply compute the sum of the given vector as: |
sv | 1:6799c07fe510 | 443 | * \f[ |
sv | 1:6799c07fe510 | 444 | * \sum_{i = 0}^{Sz-1} v[i] |
sv | 1:6799c07fe510 | 445 | * \f] |
sv | 1:6799c07fe510 | 446 | */ |
sv | 1:6799c07fe510 | 447 | template<class E, std::size_t Sz> |
sv | 1:6799c07fe510 | 448 | inline |
sv | 1:6799c07fe510 | 449 | typename NumericTraits<typename E::value_type>::sum_type |
sv | 1:6799c07fe510 | 450 | sum(const XprVector<E, Sz>& v) { |
sv | 1:6799c07fe510 | 451 | return meta::Vector<Sz>::sum(v); |
sv | 1:6799c07fe510 | 452 | } |
sv | 1:6799c07fe510 | 453 | |
sv | 1:6799c07fe510 | 454 | |
sv | 1:6799c07fe510 | 455 | /** |
sv | 1:6799c07fe510 | 456 | * \fn product(const XprVector<E, Sz>& v) |
sv | 1:6799c07fe510 | 457 | * \brief Compute the product of the vector elements. |
sv | 1:6799c07fe510 | 458 | * \ingroup _unary_function |
sv | 1:6799c07fe510 | 459 | * |
sv | 1:6799c07fe510 | 460 | * Simply computer the product of the given vector expression as: |
sv | 1:6799c07fe510 | 461 | * \f[ |
sv | 1:6799c07fe510 | 462 | * \prod_{i = 0}^{Sz - 1} v[i] |
sv | 1:6799c07fe510 | 463 | * \f] |
sv | 1:6799c07fe510 | 464 | */ |
sv | 1:6799c07fe510 | 465 | template<class E, std::size_t Sz> |
sv | 1:6799c07fe510 | 466 | inline |
sv | 1:6799c07fe510 | 467 | typename NumericTraits<typename E::value_type>::sum_type |
sv | 1:6799c07fe510 | 468 | product(const XprVector<E, Sz>& v) { |
sv | 1:6799c07fe510 | 469 | return meta::Vector<Sz>::product(v); |
sv | 1:6799c07fe510 | 470 | } |
sv | 1:6799c07fe510 | 471 | |
sv | 1:6799c07fe510 | 472 | |
sv | 1:6799c07fe510 | 473 | /** |
sv | 1:6799c07fe510 | 474 | * \fn dot(const XprVector<E1, Sz>& lhs, const XprVector<E2, Sz>& rhs) |
sv | 1:6799c07fe510 | 475 | * \brief Compute the dot/inner product |
sv | 1:6799c07fe510 | 476 | * \ingroup _binary_function |
sv | 1:6799c07fe510 | 477 | * |
sv | 1:6799c07fe510 | 478 | * Compute the dot product as: |
sv | 1:6799c07fe510 | 479 | * \f[ |
sv | 1:6799c07fe510 | 480 | * \sum_{i = 0}^{Sz - 1} ( lhs[i] * rhs[i] ) |
sv | 1:6799c07fe510 | 481 | * \f] |
sv | 1:6799c07fe510 | 482 | * where lhs is a column vector and rhs is a row vector, both vectors |
sv | 1:6799c07fe510 | 483 | * have the same dimension. |
sv | 1:6799c07fe510 | 484 | */ |
sv | 1:6799c07fe510 | 485 | template<class E1, class E2, std::size_t Sz> |
sv | 1:6799c07fe510 | 486 | inline |
sv | 1:6799c07fe510 | 487 | typename PromoteTraits< |
sv | 1:6799c07fe510 | 488 | typename E1::value_type, |
sv | 1:6799c07fe510 | 489 | typename E2::value_type |
sv | 1:6799c07fe510 | 490 | >::value_type |
sv | 1:6799c07fe510 | 491 | dot(const XprVector<E1, Sz>& lhs, const XprVector<E2, Sz>& rhs) { |
sv | 1:6799c07fe510 | 492 | return meta::Vector<Sz>::dot(lhs, rhs); |
sv | 1:6799c07fe510 | 493 | } |
sv | 1:6799c07fe510 | 494 | |
sv | 1:6799c07fe510 | 495 | |
sv | 1:6799c07fe510 | 496 | /** |
sv | 1:6799c07fe510 | 497 | * \fn dot(const Vector<T, Sz>& lhs, const XprVector<E, Sz>& rhs) |
sv | 1:6799c07fe510 | 498 | * \brief Compute the dot/inner product |
sv | 1:6799c07fe510 | 499 | * \ingroup _binary_function |
sv | 1:6799c07fe510 | 500 | * |
sv | 1:6799c07fe510 | 501 | * Compute the dot product as: |
sv | 1:6799c07fe510 | 502 | * \f[ |
sv | 1:6799c07fe510 | 503 | * \sum_{i = 0}^{Sz - 1} ( lhs[i] * rhs[i] ) |
sv | 1:6799c07fe510 | 504 | * \f] |
sv | 1:6799c07fe510 | 505 | * where lhs is a column vector and rhs is a row vector, both vectors |
sv | 1:6799c07fe510 | 506 | * have the same dimension. |
sv | 1:6799c07fe510 | 507 | */ |
sv | 1:6799c07fe510 | 508 | template<class T, class E, std::size_t Sz> |
sv | 1:6799c07fe510 | 509 | inline |
sv | 1:6799c07fe510 | 510 | typename PromoteTraits<T, typename E::value_type>::value_type |
sv | 1:6799c07fe510 | 511 | dot(const Vector<T, Sz>& lhs, const XprVector<E, Sz>& rhs) { |
sv | 1:6799c07fe510 | 512 | return meta::Vector<Sz>::dot(lhs, rhs); |
sv | 1:6799c07fe510 | 513 | } |
sv | 1:6799c07fe510 | 514 | |
sv | 1:6799c07fe510 | 515 | |
sv | 1:6799c07fe510 | 516 | /** |
sv | 1:6799c07fe510 | 517 | * \fn dot(const XprVector<E, Sz>& lhs, const Vector<T, Sz>& rhs) |
sv | 1:6799c07fe510 | 518 | * \brief Compute the dot/inner product |
sv | 1:6799c07fe510 | 519 | * \ingroup _binary_function |
sv | 1:6799c07fe510 | 520 | * |
sv | 1:6799c07fe510 | 521 | * Compute the dot product as: |
sv | 1:6799c07fe510 | 522 | * \f[ |
sv | 1:6799c07fe510 | 523 | * \sum_{i = 0}^{Sz - 1} ( lhs[i] * rhs[i] ) |
sv | 1:6799c07fe510 | 524 | * \f] |
sv | 1:6799c07fe510 | 525 | * where lhs is a column vector and rhs is a row vector, both vectors |
sv | 1:6799c07fe510 | 526 | * have the same dimension. |
sv | 1:6799c07fe510 | 527 | */ |
sv | 1:6799c07fe510 | 528 | template<class E, class T, std::size_t Sz> |
sv | 1:6799c07fe510 | 529 | inline |
sv | 1:6799c07fe510 | 530 | typename PromoteTraits<T, typename E::value_type>::value_type |
sv | 1:6799c07fe510 | 531 | dot(const XprVector<E, Sz>& lhs, const Vector<T, Sz>& rhs) { |
sv | 1:6799c07fe510 | 532 | return meta::Vector<Sz>::dot(lhs, rhs); |
sv | 1:6799c07fe510 | 533 | } |
sv | 1:6799c07fe510 | 534 | |
sv | 1:6799c07fe510 | 535 | |
sv | 1:6799c07fe510 | 536 | /** |
sv | 1:6799c07fe510 | 537 | * \fn cross(const XprVector<E1, 3>& lhs, const XprVector<E2, 3>& rhs) |
sv | 1:6799c07fe510 | 538 | * \brief Compute the cross/outer product |
sv | 1:6799c07fe510 | 539 | * \ingroup _binary_function |
sv | 1:6799c07fe510 | 540 | * \note working only for vectors of size = 3 |
sv | 1:6799c07fe510 | 541 | * \todo Implement vector outer product as ET and MT, returning a XprVector |
sv | 1:6799c07fe510 | 542 | */ |
sv | 1:6799c07fe510 | 543 | template<class E1, class E2> |
sv | 1:6799c07fe510 | 544 | inline |
sv | 1:6799c07fe510 | 545 | Vector< |
sv | 1:6799c07fe510 | 546 | typename PromoteTraits< |
sv | 1:6799c07fe510 | 547 | typename E1::value_type, |
sv | 1:6799c07fe510 | 548 | typename E2::value_type |
sv | 1:6799c07fe510 | 549 | >::value_type, |
sv | 1:6799c07fe510 | 550 | 3 |
sv | 1:6799c07fe510 | 551 | > |
sv | 1:6799c07fe510 | 552 | cross(const XprVector<E1, 3>& lhs, const XprVector<E2, 3>& rhs) { |
sv | 1:6799c07fe510 | 553 | typedef typename PromoteTraits< |
sv | 1:6799c07fe510 | 554 | typename E1::value_type, |
sv | 1:6799c07fe510 | 555 | typename E2::value_type |
sv | 1:6799c07fe510 | 556 | >::value_type value_type; |
sv | 1:6799c07fe510 | 557 | return Vector<value_type, 3>(lhs(1)*rhs(2) - rhs(1)*lhs(2), |
sv | 1:6799c07fe510 | 558 | rhs(0)*lhs(2) - lhs(0)*rhs(2), |
sv | 1:6799c07fe510 | 559 | lhs(0)*rhs(1) - rhs(0)*lhs(1)); |
sv | 1:6799c07fe510 | 560 | } |
sv | 1:6799c07fe510 | 561 | |
sv | 1:6799c07fe510 | 562 | |
sv | 1:6799c07fe510 | 563 | /** |
sv | 1:6799c07fe510 | 564 | * \fn cross(const XprVector<E, 3>& lhs, const Vector<T, 3>& rhs) |
sv | 1:6799c07fe510 | 565 | * \brief Compute the cross/outer product |
sv | 1:6799c07fe510 | 566 | * \ingroup _binary_function |
sv | 1:6799c07fe510 | 567 | * \note working only for vectors of size = 3 |
sv | 1:6799c07fe510 | 568 | * \todo Implement vector outer product as ET and MT, returning a XprVector |
sv | 1:6799c07fe510 | 569 | */ |
sv | 1:6799c07fe510 | 570 | template<class E, class T> |
sv | 1:6799c07fe510 | 571 | inline |
sv | 1:6799c07fe510 | 572 | Vector< |
sv | 1:6799c07fe510 | 573 | typename PromoteTraits<T, typename E::value_type>::value_type, 3> |
sv | 1:6799c07fe510 | 574 | cross(const XprVector<E, 3>& lhs, const Vector<T, 3>& rhs) { |
sv | 1:6799c07fe510 | 575 | typedef typename PromoteTraits< |
sv | 1:6799c07fe510 | 576 | typename E::value_type, T>::value_type value_type; |
sv | 1:6799c07fe510 | 577 | return Vector<value_type, 3>(lhs(1)*rhs(2) - rhs(1)*lhs(2), |
sv | 1:6799c07fe510 | 578 | rhs(0)*lhs(2) - lhs(0)*rhs(2), |
sv | 1:6799c07fe510 | 579 | lhs(0)*rhs(1) - rhs(0)*lhs(1)); |
sv | 1:6799c07fe510 | 580 | } |
sv | 1:6799c07fe510 | 581 | |
sv | 1:6799c07fe510 | 582 | |
sv | 1:6799c07fe510 | 583 | /** |
sv | 1:6799c07fe510 | 584 | * \fn cross(const Vector<T, 3>& lhs, const XprVector<E, 3>& rhs) |
sv | 1:6799c07fe510 | 585 | * \brief Compute the cross/outer product |
sv | 1:6799c07fe510 | 586 | * \ingroup _binary_function |
sv | 1:6799c07fe510 | 587 | * \note working only for vectors of size = 3 |
sv | 1:6799c07fe510 | 588 | * \todo Implement vector outer product as ET and MT, returning a XprVector |
sv | 1:6799c07fe510 | 589 | */ |
sv | 1:6799c07fe510 | 590 | template<class T1, class E2> |
sv | 1:6799c07fe510 | 591 | inline |
sv | 1:6799c07fe510 | 592 | Vector< |
sv | 1:6799c07fe510 | 593 | typename PromoteTraits<T1, typename E2::value_type>::value_type, 3> |
sv | 1:6799c07fe510 | 594 | cross(const Vector<T1, 3>& lhs, const XprVector<E2, 3>& rhs) { |
sv | 1:6799c07fe510 | 595 | typedef typename PromoteTraits< |
sv | 1:6799c07fe510 | 596 | typename E2::value_type, T1>::value_type value_type; |
sv | 1:6799c07fe510 | 597 | return Vector<value_type, 3>(lhs(1)*rhs(2) - rhs(1)*lhs(2), |
sv | 1:6799c07fe510 | 598 | rhs(0)*lhs(2) - lhs(0)*rhs(2), |
sv | 1:6799c07fe510 | 599 | lhs(0)*rhs(1) - rhs(0)*lhs(1)); |
sv | 1:6799c07fe510 | 600 | } |
sv | 1:6799c07fe510 | 601 | |
sv | 1:6799c07fe510 | 602 | |
sv | 1:6799c07fe510 | 603 | /** |
sv | 1:6799c07fe510 | 604 | * \fn norm1(const XprVector<E, Sz>& v) |
sv | 1:6799c07fe510 | 605 | * \brief The \f$l_1\f$ norm of a vector expression. |
sv | 1:6799c07fe510 | 606 | * \ingroup _unary_function |
sv | 1:6799c07fe510 | 607 | * The norm of any vector is just the square root of the dot product of |
sv | 1:6799c07fe510 | 608 | * a vector with itself, or |
sv | 1:6799c07fe510 | 609 | * |
sv | 1:6799c07fe510 | 610 | * \f[ |
sv | 1:6799c07fe510 | 611 | * |Vector<T, Sz> v| = |v| = \sum_{i=0}^{Sz-1}\,|v[i]| |
sv | 1:6799c07fe510 | 612 | * \f] |
sv | 1:6799c07fe510 | 613 | */ |
sv | 1:6799c07fe510 | 614 | template<class E, std::size_t Sz> |
sv | 1:6799c07fe510 | 615 | inline |
sv | 1:6799c07fe510 | 616 | typename NumericTraits<typename E::value_type>::sum_type |
sv | 1:6799c07fe510 | 617 | norm1(const XprVector<E, Sz>& v) { |
sv | 1:6799c07fe510 | 618 | return sum(abs(v)); |
sv | 1:6799c07fe510 | 619 | } |
sv | 1:6799c07fe510 | 620 | |
sv | 1:6799c07fe510 | 621 | |
sv | 1:6799c07fe510 | 622 | /** |
sv | 1:6799c07fe510 | 623 | * \fn norm2(const XprVector<E, Sz>& v) |
sv | 1:6799c07fe510 | 624 | * \brief The euklidian norm (or \f$l_2\f$ norm) of a vector expression. |
sv | 1:6799c07fe510 | 625 | * \ingroup _unary_function |
sv | 1:6799c07fe510 | 626 | * The norm of any vector is just the square root of the dot product of |
sv | 1:6799c07fe510 | 627 | * a vector with itself, or |
sv | 1:6799c07fe510 | 628 | * |
sv | 1:6799c07fe510 | 629 | * \f[ |
sv | 1:6799c07fe510 | 630 | * |Vector<T, Sz> v| = |v| = \sqrt{ \sum_{i=0}^{Sz-1}\,v[i]^2 } |
sv | 1:6799c07fe510 | 631 | * \f] |
sv | 1:6799c07fe510 | 632 | * |
sv | 1:6799c07fe510 | 633 | * \note The internal cast for Vector<int> avoids warnings on sqrt. |
sv | 1:6799c07fe510 | 634 | */ |
sv | 1:6799c07fe510 | 635 | template<class E, std::size_t Sz> |
sv | 1:6799c07fe510 | 636 | inline |
sv | 1:6799c07fe510 | 637 | typename NumericTraits<typename E::value_type>::sum_type |
sv | 1:6799c07fe510 | 638 | norm2(const XprVector<E, Sz>& v) { |
sv | 1:6799c07fe510 | 639 | typedef typename E::value_type value_type; |
sv | 1:6799c07fe510 | 640 | return static_cast<value_type>( std::sqrt(static_cast<value_type>(dot(v, v))) ); |
sv | 1:6799c07fe510 | 641 | } |
sv | 1:6799c07fe510 | 642 | |
sv | 1:6799c07fe510 | 643 | |
sv | 1:6799c07fe510 | 644 | /** |
sv | 1:6799c07fe510 | 645 | * \fn normalize(const XprVector<E, Sz>& v) |
sv | 1:6799c07fe510 | 646 | * \brief Normalize the given vector expression. |
sv | 1:6799c07fe510 | 647 | * \ingroup _unary_function |
sv | 1:6799c07fe510 | 648 | * \sa norm2 |
sv | 1:6799c07fe510 | 649 | * |
sv | 1:6799c07fe510 | 650 | * using the equation: |
sv | 1:6799c07fe510 | 651 | * \f[ |
sv | 1:6799c07fe510 | 652 | * \frac{Vector<T, Sz> v}{\sqrt{ \sum_{i=0}^{Sz-1}\,v[i]^2 }} |
sv | 1:6799c07fe510 | 653 | * \f] |
sv | 1:6799c07fe510 | 654 | */ |
sv | 1:6799c07fe510 | 655 | template<class E, std::size_t Sz> |
sv | 1:6799c07fe510 | 656 | inline |
sv | 1:6799c07fe510 | 657 | XprVector< |
sv | 1:6799c07fe510 | 658 | XprBinOp< |
sv | 1:6799c07fe510 | 659 | Fcnl_div<typename E::value_type, typename E::value_type>, |
sv | 1:6799c07fe510 | 660 | XprVector<E, Sz>, |
sv | 1:6799c07fe510 | 661 | XprLiteral<typename E::value_type> |
sv | 1:6799c07fe510 | 662 | >, |
sv | 1:6799c07fe510 | 663 | Sz |
sv | 1:6799c07fe510 | 664 | > |
sv | 1:6799c07fe510 | 665 | normalize(const XprVector<E, Sz>& v) { |
sv | 1:6799c07fe510 | 666 | typedef typename E::value_type value_type; |
sv | 1:6799c07fe510 | 667 | typedef XprBinOp< |
sv | 1:6799c07fe510 | 668 | Fcnl_div<value_type, value_type>, |
sv | 1:6799c07fe510 | 669 | XprVector<E, Sz>, |
sv | 1:6799c07fe510 | 670 | XprLiteral<value_type> |
sv | 1:6799c07fe510 | 671 | > expr_type; |
sv | 1:6799c07fe510 | 672 | return XprVector<expr_type, Sz>( |
sv | 1:6799c07fe510 | 673 | expr_type(v, XprLiteral< value_type >(norm2(v)))); |
sv | 1:6799c07fe510 | 674 | } |
sv | 1:6799c07fe510 | 675 | |
sv | 1:6799c07fe510 | 676 | |
sv | 1:6799c07fe510 | 677 | } // namespace tvmet |
sv | 1:6799c07fe510 | 678 | |
sv | 1:6799c07fe510 | 679 | #endif // TVMET_XPR_VECTOR_FUNCTIONS_H |
sv | 1:6799c07fe510 | 680 | |
sv | 1:6799c07fe510 | 681 | // Local Variables: |
sv | 1:6799c07fe510 | 682 | // mode:C++ |
sv | 1:6799c07fe510 | 683 | // tab-width:8 |
sv | 1:6799c07fe510 | 684 | // End: |