![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
We are going to win! wohoo
tvmet/meta/Vector.h@9:08552997b544, 2012-11-14 (annotated)
- Committer:
- madcowswe
- Date:
- Wed Nov 14 17:15:53 2012 +0000
- Revision:
- 9:08552997b544
- Parent:
- 1:6799c07fe510
Added an important comment
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: Vector.h,v 1.24 2007-06-23 15:58:59 opetzold Exp $ |
sv | 1:6799c07fe510 | 22 | */ |
sv | 1:6799c07fe510 | 23 | |
sv | 1:6799c07fe510 | 24 | #ifndef TVMET_META_VECTOR_H |
sv | 1:6799c07fe510 | 25 | #define TVMET_META_VECTOR_H |
sv | 1:6799c07fe510 | 26 | |
sv | 1:6799c07fe510 | 27 | #include <tvmet/NumericTraits.h> |
sv | 1:6799c07fe510 | 28 | #include <tvmet/xpr/Null.h> |
sv | 1:6799c07fe510 | 29 | |
sv | 1:6799c07fe510 | 30 | namespace tvmet { |
sv | 1:6799c07fe510 | 31 | |
sv | 1:6799c07fe510 | 32 | /* forwards */ |
sv | 1:6799c07fe510 | 33 | template<class T, std::size_t Sz> class Vector; |
sv | 1:6799c07fe510 | 34 | |
sv | 1:6799c07fe510 | 35 | |
sv | 1:6799c07fe510 | 36 | namespace meta { |
sv | 1:6799c07fe510 | 37 | |
sv | 1:6799c07fe510 | 38 | |
sv | 1:6799c07fe510 | 39 | /** |
sv | 1:6799c07fe510 | 40 | * \class Vector Vector.h "tvmet/meta/Vector.h" |
sv | 1:6799c07fe510 | 41 | * \brief Meta %Vector class using expression templates |
sv | 1:6799c07fe510 | 42 | */ |
sv | 1:6799c07fe510 | 43 | template<std::size_t Sz, std::size_t K=0> |
sv | 1:6799c07fe510 | 44 | class Vector |
sv | 1:6799c07fe510 | 45 | { |
sv | 1:6799c07fe510 | 46 | Vector(); |
sv | 1:6799c07fe510 | 47 | Vector(const Vector&); |
sv | 1:6799c07fe510 | 48 | Vector& operator=(const Vector&); |
sv | 1:6799c07fe510 | 49 | |
sv | 1:6799c07fe510 | 50 | private: |
sv | 1:6799c07fe510 | 51 | enum { |
sv | 1:6799c07fe510 | 52 | doIt = (K < (Sz-1)) ? 1 : 0 /**< recursive counter */ |
sv | 1:6799c07fe510 | 53 | }; |
sv | 1:6799c07fe510 | 54 | |
sv | 1:6799c07fe510 | 55 | public: |
sv | 1:6799c07fe510 | 56 | /** assign an expression expr using the functional assign_fn. */ |
sv | 1:6799c07fe510 | 57 | template <class Dest, class Src, class Assign> |
sv | 1:6799c07fe510 | 58 | static inline |
sv | 1:6799c07fe510 | 59 | void assign(Dest& lhs, const Src& rhs, const Assign& assign_fn) { |
sv | 1:6799c07fe510 | 60 | assign_fn.apply_on(lhs(K), rhs(K)); |
sv | 1:6799c07fe510 | 61 | meta::Vector<Sz * doIt, (K+1) * doIt>::assign(lhs, rhs, assign_fn); |
sv | 1:6799c07fe510 | 62 | } |
sv | 1:6799c07fe510 | 63 | |
sv | 1:6799c07fe510 | 64 | /** build the sum of the vector. */ |
sv | 1:6799c07fe510 | 65 | template<class E> |
sv | 1:6799c07fe510 | 66 | static inline |
sv | 1:6799c07fe510 | 67 | typename E::value_type |
sv | 1:6799c07fe510 | 68 | sum(const E& e) { |
sv | 1:6799c07fe510 | 69 | return e(K) + meta::Vector<Sz * doIt, (K+1) * doIt>::sum(e); |
sv | 1:6799c07fe510 | 70 | } |
sv | 1:6799c07fe510 | 71 | |
sv | 1:6799c07fe510 | 72 | /** build the product of the vector. */ |
sv | 1:6799c07fe510 | 73 | template<class E> |
sv | 1:6799c07fe510 | 74 | static inline |
sv | 1:6799c07fe510 | 75 | typename NumericTraits< |
sv | 1:6799c07fe510 | 76 | typename E::value_type |
sv | 1:6799c07fe510 | 77 | >::sum_type |
sv | 1:6799c07fe510 | 78 | product(const E& e) { |
sv | 1:6799c07fe510 | 79 | return e(K) * meta::Vector<Sz * doIt, (K+1) * doIt>::product(e); |
sv | 1:6799c07fe510 | 80 | } |
sv | 1:6799c07fe510 | 81 | |
sv | 1:6799c07fe510 | 82 | /** build the dot product of the vector. */ |
sv | 1:6799c07fe510 | 83 | template<class Dest, class Src> |
sv | 1:6799c07fe510 | 84 | static inline |
sv | 1:6799c07fe510 | 85 | typename PromoteTraits< |
sv | 1:6799c07fe510 | 86 | typename Dest::value_type, |
sv | 1:6799c07fe510 | 87 | typename Src::value_type |
sv | 1:6799c07fe510 | 88 | >::value_type |
sv | 1:6799c07fe510 | 89 | dot(const Dest& lhs, const Src& rhs) { |
sv | 1:6799c07fe510 | 90 | return lhs(K) * rhs(K) |
sv | 1:6799c07fe510 | 91 | + meta::Vector<Sz * doIt, (K+1) * doIt>::dot(lhs, rhs); |
sv | 1:6799c07fe510 | 92 | } |
sv | 1:6799c07fe510 | 93 | |
sv | 1:6799c07fe510 | 94 | /** check for all elements */ |
sv | 1:6799c07fe510 | 95 | template<class E> |
sv | 1:6799c07fe510 | 96 | static inline |
sv | 1:6799c07fe510 | 97 | bool |
sv | 1:6799c07fe510 | 98 | all_elements(const E& e) { |
sv | 1:6799c07fe510 | 99 | if(!e(K)) return false; |
sv | 1:6799c07fe510 | 100 | return meta::Vector<Sz * doIt, (K+1) * doIt>::all_elements(e); |
sv | 1:6799c07fe510 | 101 | } |
sv | 1:6799c07fe510 | 102 | |
sv | 1:6799c07fe510 | 103 | /** check for any elements */ |
sv | 1:6799c07fe510 | 104 | template<class E> |
sv | 1:6799c07fe510 | 105 | static inline |
sv | 1:6799c07fe510 | 106 | bool |
sv | 1:6799c07fe510 | 107 | any_elements(const E& e) { |
sv | 1:6799c07fe510 | 108 | if(e(K)) return true; |
sv | 1:6799c07fe510 | 109 | return meta::Vector<Sz * doIt, (K+1) * doIt>::any_elements(e); |
sv | 1:6799c07fe510 | 110 | } |
sv | 1:6799c07fe510 | 111 | }; |
sv | 1:6799c07fe510 | 112 | |
sv | 1:6799c07fe510 | 113 | |
sv | 1:6799c07fe510 | 114 | /** |
sv | 1:6799c07fe510 | 115 | * \class Vector<0,0> Vector.h "tvmet/meta/Vector.h" |
sv | 1:6799c07fe510 | 116 | * \brief Meta %Vector Specialized for recursion |
sv | 1:6799c07fe510 | 117 | */ |
sv | 1:6799c07fe510 | 118 | template<> |
sv | 1:6799c07fe510 | 119 | class Vector<0,0> |
sv | 1:6799c07fe510 | 120 | { |
sv | 1:6799c07fe510 | 121 | Vector(); |
sv | 1:6799c07fe510 | 122 | Vector(const Vector&); |
sv | 1:6799c07fe510 | 123 | Vector& operator=(const Vector&); |
sv | 1:6799c07fe510 | 124 | |
sv | 1:6799c07fe510 | 125 | public: |
sv | 1:6799c07fe510 | 126 | template <class Dest, class Src, class Assign> |
sv | 1:6799c07fe510 | 127 | static inline void assign(Dest&, const Src&, const Assign&) { } |
sv | 1:6799c07fe510 | 128 | |
sv | 1:6799c07fe510 | 129 | template<class E> |
sv | 1:6799c07fe510 | 130 | static inline XprNull sum(const E&) { return XprNull(); } |
sv | 1:6799c07fe510 | 131 | |
sv | 1:6799c07fe510 | 132 | template<class E> |
sv | 1:6799c07fe510 | 133 | static inline XprNull product(const E&) { return XprNull(); } |
sv | 1:6799c07fe510 | 134 | |
sv | 1:6799c07fe510 | 135 | template<class Dest, class Src> |
sv | 1:6799c07fe510 | 136 | static inline XprNull dot(const Dest&, const Src&) { return XprNull(); } |
sv | 1:6799c07fe510 | 137 | |
sv | 1:6799c07fe510 | 138 | template<class E> |
sv | 1:6799c07fe510 | 139 | static inline bool all_elements(const E&) { return true; } |
sv | 1:6799c07fe510 | 140 | |
sv | 1:6799c07fe510 | 141 | template<class E> |
sv | 1:6799c07fe510 | 142 | static inline bool any_elements(const E&) { return false; } |
sv | 1:6799c07fe510 | 143 | }; |
sv | 1:6799c07fe510 | 144 | |
sv | 1:6799c07fe510 | 145 | |
sv | 1:6799c07fe510 | 146 | } // namespace meta |
sv | 1:6799c07fe510 | 147 | |
sv | 1:6799c07fe510 | 148 | } // namespace tvmet |
sv | 1:6799c07fe510 | 149 | |
sv | 1:6799c07fe510 | 150 | #endif /* TVMET_META_VECTOR_H */ |
sv | 1:6799c07fe510 | 151 | |
sv | 1:6799c07fe510 | 152 | // Local Variables: |
sv | 1:6799c07fe510 | 153 | // mode:C++ |
sv | 1:6799c07fe510 | 154 | // tab-width:8 |
sv | 1:6799c07fe510 | 155 | // End: |