Eurobot2012_Primary

Dependencies:   mbed Eurobot_2012_Primary

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

Who changed what in which revision?

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