VectorOperators.hpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
44 #ifndef GNSSTK_VECTOR_OPERATORS_HPP
45 #define GNSSTK_VECTOR_OPERATORS_HPP
46 
47 #include "Vector.hpp"
48 
49 namespace std
50 {
51 
53 
54 
55 #define VecBaseNewUnaryOperator(func) \
56  \
57  template <class T, class BaseClass> \
58  gnsstk::Vector<T> func(const gnsstk::ConstVectorBase<T, BaseClass>& x) \
59  { \
60  BaseClass toReturn(x.size()); \
61  size_t i; for (i=0; i < x.size(); i++) toReturn[i] = func(x[i]); \
62  return toReturn; \
63  }
64 
65 // VecBaseNewUnaryOperator(-)
80 }
81 
82 namespace gnsstk
83 {
84 
85 #define VecBaseNewBinaryOperator(func, retval) \
86  \
87  template <class T, class BaseClass, class BaseClass2> \
88  retval operator func(const ConstVectorBase<T, BaseClass>& l, \
89  const ConstVectorBase<T, BaseClass2>& r) \
90  { \
91  if (l.size() != r.size()) \
92  { \
93  VectorException e("Unequal lengths vectors"); \
94  GNSSTK_THROW(e); \
95  } \
96  retval toReturn(l.size()); \
97  size_t i; \
98  for (i=0; i < l.size(); i++) toReturn[i] = l[i] func r[i]; \
99  return toReturn; \
100  } \
101  \
102  template <class T, class BaseClass> \
103  retval operator func(const ConstVectorBase<T, BaseClass>& l, const T r) \
104  { \
105  retval toReturn(l.size()); \
106  size_t i; \
107  for (i=0; i < l.size(); i++) toReturn[i] = l[i] func r; \
108  return toReturn; \
109  } \
110  \
111  template <class T, class BaseClass> \
112  retval operator func(const T l, const ConstVectorBase<T, BaseClass>& r) \
113  { \
114  retval toReturn(r.size()); \
115  size_t i; \
116  for (i=0; i < r.size(); i++) toReturn[i] = l func r[i]; \
117  return toReturn; \
118  }
119 
120  VecBaseNewBinaryOperator(*, Vector<T>)
121  VecBaseNewBinaryOperator(/, Vector<T>)
122  VecBaseNewBinaryOperator(%, Vector<T>)
123  VecBaseNewBinaryOperator(+, Vector<T>)
124  VecBaseNewBinaryOperator(-, Vector<T>)
125  VecBaseNewBinaryOperator(^, Vector<T>)
126  VecBaseNewBinaryOperator(&, Vector<T>)
127  VecBaseNewBinaryOperator(|, Vector<T>)
128 
129  VecBaseNewBinaryOperator(==, Vector<bool>)
130  VecBaseNewBinaryOperator(<, Vector<bool>)
131  VecBaseNewBinaryOperator(>, Vector<bool>)
132  VecBaseNewBinaryOperator(!=, Vector<bool>)
133  VecBaseNewBinaryOperator(<=, Vector<bool>)
134  VecBaseNewBinaryOperator(>=, Vector<bool>)
135 
136 #define VecBaseNewBinaryTranscendentalOperator(func, retval) \
137  \
138  template <class T, class BaseClass, class BaseClass2> \
139  retval func(const gnsstk::ConstVectorBase<T, BaseClass>& l, \
140  const gnsstk::ConstVectorBase<T, BaseClass2>& r) \
141  { \
142  retval toReturn(l.size()); \
143  size_t i; \
144  for (i=0; i < l.size(); i++) toReturn[i] = func(l[i], r[i]); \
145  return toReturn; \
146  } \
147  \
148  template <class T, class BaseClass> \
149  retval func(const gnsstk::ConstVectorBase<T, BaseClass>& l, const T r) \
150  { \
151  retval toReturn(l.size()); \
152  size_t i; \
153  for (i=0; i < l.size(); i++) toReturn[i] = func(l[i], r); \
154  return toReturn; \
155  } \
156  \
157  template <class T, class BaseClass> \
158  retval func(const T l, const gnsstk::ConstVectorBase<T, BaseClass>& r) \
159  { \
160  retval toReturn(r.size()); \
161  size_t i; \
162  for (i=0; i < r.size(); i++) toReturn[i] = func(l, r[i]); \
163  return toReturn; \
164  }
165 
169  template <class T, class BaseClass, class BaseClass2>
172  {
173  if ((l.size() != 3) && (r.size() != 3))
174  {
175  VectorException e("Cross product requires vectors of size 3");
176  GNSSTK_THROW(e);
177  }
178  BaseClass toReturn(3);
179  toReturn[0] = l[1] * r[2] - l[2] * r[1];
180  toReturn[1] = l[2] * r[0] - l[0] * r[2];
181  toReturn[2] = l[0] * r[1] - l[1] * r[0];
182  return toReturn;
183  }
184 
186  template <class T, class BaseClass>
188  { return l / norm(l); }
189 
191  template <class T, class BaseClass>
193  { return norm(l); }
194 
196  template <class T, class BaseClass>
198  { return norm(l)/SQRT(T(l.size())); }
199 
201 
202 } // namespace
203 
204 namespace std
205 {
208 }
209 
210 #endif
SQRT
#define SQRT(x)
Definition: MathBase.hpp:74
gnsstk::VecBaseNewBinaryOperator
VecBaseNewBinaryOperator Vector VecBaseNewBinaryOperator(/, Vector< T >) VecBaseNewBinaryOperator(%
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
std::sin
double sin(gnsstk::Angle x)
Definition: Angle.hpp:144
gnsstk::cross
class BaseClass2 Vector< T > cross(const ConstVectorBase< T, BaseClass > &l, const ConstVectorBase< T, BaseClass2 > &r)
Definition: VectorOperators.hpp:170
log
#define log
Definition: DiscCorr.cpp:625
VecBaseNewUnaryOperator
#define VecBaseNewUnaryOperator(func)
Definition: VectorOperators.hpp:55
std::cos
double cos(gnsstk::Angle x)
Definition: Angle.hpp:146
gnsstk::RSS
T RSS(T aa, T bb, T cc)
Perform the root sum square of aa, bb and cc.
Definition: MiscMath.hpp:246
gnsstk::Vector
Definition: Vector.hpp:67
gnsstk::ConstVectorBase::size
size_t size() const
Returns the size of the base class.
Definition: VectorBase.hpp:112
gnsstk::normalize
Vector< T > normalize(const ConstVectorBase< T, BaseClass > &l)
Definition: VectorOperators.hpp:187
std::tan
double tan(gnsstk::Angle x)
Definition: Angle.hpp:148
std::VecBaseNewBinaryTranscendentalOperator
VecBaseNewBinaryTranscendentalOperator(atan2, gnsstk::Vector< T >) VecBaseNewBinaryTranscendentalOperator(pow
gnsstk::ConstVectorBase
Definition: VectorBase.hpp:105
std
Definition: Angle.hpp:142
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366
gnsstk::norm
T norm(const SparseVector< T > &SV)
Definition: SparseVector.hpp:705
gnsstk::RMS
T RMS(const ConstVectorBase< T, BaseClass > &l)
Definition: VectorOperators.hpp:197
Vector.hpp


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:42