casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TabVecMath.h
Go to the documentation of this file.
1 //# TabVecMath.h: Global functions for table vector mathematics
2 //# Copyright (C) 1994,1995,1996,1999,2003
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef TABLES_TABVECMATH_H
29 #define TABLES_TABVECMATH_H
30 
31 //# Global functions similar to those defined in ArrayMath are defined for
32 //# the table vectors. Furthermore vector functions like norm are defined.
33 
34 //# Includes
35 #include <casacore/casa/aips.h>
39 
40 
41 namespace casacore { //# NAMESPACE CASACORE - BEGIN
42 
43 // <summary>
44 // Basic math for table vectors.
45 // </summary>
46 
47 // <use visibility=export>
48 
49 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
50 // </reviewed>
51 
52 // <synopsis>
53 // These global functions do the basic math for table vectors.
54 // This means addition, subtraction, multiplication, division
55 // and negation.
56 // In case two table vectors are used, the left and right operand
57 // must be conformant (i.e. have equal length).
58 // </synopsis>
59 
60 // <group name=basicMath>
61 // Add 2 table vectors storing result in first one.
62 template<class T> inline
63  void operator+= (TableVector<T>& left, const TableVector<T>& right);
64 // Subtract 2 table vectors storing result in first one.
65 template<class T> inline
66  void operator-= (TableVector<T>& left, const TableVector<T>& right);
67 // Multiple 2 table vectors storing result in first one.
68 template<class T> inline
69  void operator*= (TableVector<T>& left, const TableVector<T>& right);
70 // Divide 2 table vectors storing result in first one.
71 template<class T> inline
72  void operator/= (TableVector<T>& left, const TableVector<T>& right);
73 
74 // Add a scalar to each element in the table vector.
75 template<class T> inline
76  void operator+= (TableVector<T>& left, const T& right);
77 // Subtract a scalar from each element in the table vector.
78 template<class T> inline
79  void operator-= (TableVector<T>& left, const T& right);
80 // Multiple each element in the table vector with a scalar.
81 template<class T> inline
82  void operator*= (TableVector<T>& left, const T& right);
83 // Divide each element in the table vector by a scalar.
84 template<class T> inline
85  void operator/= (TableVector<T>& left, const T& right);
86 
87 // Unary plus.
88 template<class T> inline
90 // Unary minus.
91 template<class T> inline
93 
94 // Add 2 table vectors storing result in a new one.
95 template<class T> inline
97  const TableVector<T>& right);
98 // Subtract 2 table vectors storing result in a new one.
99 template<class T> inline
101  const TableVector<T>& right);
102 // Multiple 2 table vectors storing result in a new one.
103 template<class T> inline
105  const TableVector<T>& right);
106 // Divide 2 table vectors storing result in a new one.
107 template<class T> inline
109  const TableVector<T>& right);
110 
111 // Add a scalar to each element in the table vector storing result
112 // in a new table vector.
113 template<class T> inline
114  TableVector<T> operator+ (const TableVector<T>& left, const T& right);
115 // Subtract a scalar from each element in the table vector storing result
116 // in a new table vector.
117 template<class T> inline
118  TableVector<T> operator- (const TableVector<T>& left, const T& right);
119 // Multiple each element in the table vector with a scalar storing result
120 // in a new table vector.
121 template<class T> inline
122  TableVector<T> operator* (const TableVector<T>& left, const T& right);
123 // Divide each element in the table vector by a scalar storing result
124 // in a new table vector.
125 template<class T> inline
126  TableVector<T> operator/ (const TableVector<T>& left, const T& right);
127 
128 // Add a scalar to each element in the table vector storing result
129 // in a new table vector.
130 template<class T> inline
131  TableVector<T> operator+ (const T& left, const TableVector<T>& right);
132 // Subtract a scalar from each element in the table vector storing result
133 // in a new table vector.
134 template<class T> inline
135  TableVector<T> operator- (const T& left, const TableVector<T>& right);
136 // Multiple each element in the table vector with a scalar storing result
137 // in a new table vector.
138 template<class T> inline
139  TableVector<T> operator* (const T& left, const TableVector<T>& right);
140 // Divide each element in the table vector by a scalar storing result
141 // in a new table vector.
142 template<class T> inline
143  TableVector<T> operator/ (const T& left, const TableVector<T>& right);
144 // </group>
145 
146 
147 
148 // <summary>
149 // Transcendental math for table vectors.
150 // </summary>
151 
152 // <use visibility=export>
153 
154 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
155 // </reviewed>
156 
157 // <synopsis>
158 // These global functions do the transcendental math for table vectors
159 // for essentially all numeric types.
160 // The functions are sin, sinh, exp, log, pow, etc..
161 // In case two table vectors are used, the left and right operand
162 // must be conformant (i.e. have equal length).
163 // </synopsis>
164 
165 // <group name=basicTransMath>
166 template<class T> inline TableVector<T> cos (const TableVector<T>&);
167 template<class T> inline TableVector<T> cosh (const TableVector<T>&);
168 template<class T> inline TableVector<T> exp (const TableVector<T>&);
169 template<class T> inline TableVector<T> log (const TableVector<T>&);
170 template<class T> inline TableVector<T> log10(const TableVector<T>&);
171 template<class T> inline TableVector<T> pow (const TableVector<T>& value,
172  const TableVector<T>& exponent);
173 template<class T> inline TableVector<T> sin (const TableVector<T>&);
174 template<class T> inline TableVector<T> sinh (const TableVector<T>&);
175 template<class T> inline TableVector<T> sqrt (const TableVector<T>&);
176 // </group>
177 
178 
179 
180 // <summary>
181 // Further transcendental math for table vectors.
182 // </summary>
183 
184 // <use visibility=export>
185 
186 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
187 // </reviewed>
188 
189 // <synopsis>
190 // These global functions do the transcendental math for table vectors
191 // for a limited set of numeric types.
192 // The functions are asin, ceil, etc..
193 // In case two table vectors are used, the left and right operand
194 // must be conformant (i.e. have equal length).
195 // </synopsis>
196 
197 // <group name=advTransMath>
198 template<class T> inline TableVector<T> acos (const TableVector<T>&);
199 template<class T> inline TableVector<T> asin (const TableVector<T>&);
200 template<class T> inline TableVector<T> atan (const TableVector<T>&);
201 template<class T> inline TableVector<T> atan2(const TableVector<T>& y,
202  const TableVector<T>& x);
203 template<class T> inline TableVector<T> ceil (const TableVector<T>&);
204 template<class T> inline TableVector<T> fabs (const TableVector<T>&);
205 template<class T> inline TableVector<T> floor(const TableVector<T>&);
206 template<class T> inline TableVector<T> fmod (const TableVector<T>& value,
207  const TableVector<T>& modulo);
208 template<class T> inline TableVector<T> pow (const TableVector<T>& value,
209  const double& exponent);
210 template<class T> inline TableVector<T> tan (const TableVector<T>&);
211 template<class T> inline TableVector<T> tanh (const TableVector<T>&);
212 // </group>
213 
214 
215 
216 // <summary>
217 // Miscellaneous table vector operations.
218 // </summary>
219 
220 // <use visibility=export>
221 
222 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
223 // </reviewed>
224 
225 // <synopsis>
226 // Fill a table vector or calculate the sum, product, minimum or
227 // maximum of its elements.
228 // </synopsis>
229 
230 // <group name=miscellaneous>
231 // This sets min and max to the min and max of the vector to avoid having
232 // to do two passes with max() and min() separately.
233 // Requires that the type "T" has comparison operators.
234 template<class T> inline
235  void minMax (T& min, T& max, const TableVector<T>&);
236 
237 // The minimum element of the table vector.
238 // Requires that the type "T" has comparison operators.
239 template<class T> inline
240  T min (const TableVector<T>&);
241 
242 // The maximum element of the table vector.
243 // Requires that the type "T" has comparison operators.
244 template<class T> inline
245  T max (const TableVector<T>&);
246 
247 // Fills all elements of the table vector with a sequence starting with
248 // "start" and incrementing by "inc" for each element.
249 template<class T> inline
250  void indgen (TableVector<T>&, Int start, Int inc);
251 
252 // Fills all elements of the table vector with a sequence starting with
253 // "start" incremented by one for each position in the table vector.
254 template<class T> inline
255  void indgen (TableVector<T>&, Int start);
256 
257 // Fills all elements of the table vector with a sequence starting with
258 // 0 and ending with nelements() - 1.
259 template<class T> inline
260  void indgen (TableVector<T>&);
261 
262 // Sum of all the elements of a table vector.
263 template<class T> inline
264  T sum (const TableVector<T>&);
265 
266 // Product of all the elements of a table vector.
267 // <note role=warning>
268 // product can easily overflow.
269 // </note>
270 template<class T> inline T
271  product (const TableVector<T>&);
272 // </group>
273 
274 
275 
276 
277 // <summary>
278 // Vector operations on a table vector.
279 // </summary>
280 
281 // <use visibility=export>
282 
283 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
284 // </reviewed>
285 
286 // <synopsis>
287 // Do vector operations on a table vector (like inner product).
288 // </synopsis>
289 
290 // <group name=vectorMath>
291 // The inner product of 2 table vectors.
292 // The left and right operands must be conformant (i.e. have equal length).
293 template<class T> inline
294  T innerProduct (const TableVector<T>& left,
295  const TableVector<T>& right);
296 
297 // The norm of a table vector.
298 template<class T> inline
299  T norm (const TableVector<T>&);
300 
301 // The cross product of 2 table vectors containing 3 elements.
302 template<class T> inline
304  const TableVector<T>& right);
305 // </group>
306 
307 
308 
309 //# Inline all these functions.
310 //# The actual work is done by functions (tabVecRep...) operating on TabVecRep.
311 //# Because the preprocessor of gcc-3 gives warnings when using the macro as
312 //# e.g. TABVECMATHOPER(add,+,+=), the r is removed from the function name and
313 //# put befroe the + in the macro call.
314 
315 #define TABVECMATHOPER(NAME,OP,OPA) \
316 template<class T> inline \
317 TableVector<T> aips_name2(operato,OP) (const TableVector<T>& tv, \
318  const T& v) \
319  { return TableVector<T> (aips_name2(tabVecRepvalr,NAME) (tv.tabVec(), \
320  v)); } \
321 template<class T> inline \
322 TableVector<T> aips_name2(operato,OP) (const T& v, \
323  const TableVector<T>& tv) \
324  { return TableVector<T> (aips_name2(tabVecRepvall,NAME) (v, \
325  tv.tabVec())); } \
326 template<class T> inline \
327 TableVector<T> aips_name2(operato,OP) (const TableVector<T>& l, \
328  const TableVector<T>& r) \
329  { return TableVector<T> (aips_name2(tabVecReptv,NAME) (l.tabVec(), \
330  r.tabVec())); } \
331 template<class T> inline \
332 void aips_name2(operato,OPA) (TableVector<T>& tv, const T& v) \
333  { aips_name2(tabVecRepvalass,NAME) (tv.tabVec(), v); } \
334 template<class T> inline \
335 void aips_name2(operato,OPA) (TableVector<T>& l, \
336  const TableVector<T>& r) \
337  { aips_name2(tabVecReptvass,NAME) (l.tabVec(), r.tabVec()); }
338 
339 TABVECMATHOPER(add,r+,r+=)
340 TABVECMATHOPER(sub,r-,r-=)
341 TABVECMATHOPER(tim,r*,r*=)
342 TABVECMATHOPER(div,r/,r/=)
343 
344 
345 #define TABVECMATHFUNC(NAME) \
346 template<class T> inline \
347 TableVector<T> NAME (const TableVector<T>& tv) \
348  { return TableVector<T> (aips_name2(tabVecRep,NAME) (tv.tabVec())); }
349 #define TABVECMATHFUNC2(NAME) \
350 template<class T> inline \
351 TableVector<T> NAME (const TableVector<T>& l, \
352  const TableVector<T>& r) \
353  { return TableVector<T> (aips_name2(tabVecRep,NAME) (l.tabVec(), \
354  r.tabVec())); }
355 
370 TABVECMATHFUNC (fabs)
375 
376 template<class T> inline
377 TableVector<T> pow (const TableVector<T>& tv, const double& exp)
378  { return TableVector<T> (tabVecReppowd (tv.tabVec(), exp)); }
379 
380 
381 template<class T> inline
382 T sum (const TableVector<T>& tv)
383  { return tabVecRepsum (tv.tabVec()); }
384 template<class T> inline
385 T product (const TableVector<T>& tv)
386  { return tabVecRepproduct (tv.tabVec()); }
387 
388 
389 template<class T> inline
390 void minMax (T& min, T& max, const TableVector<T>& tv)
391  { tabVecRepminmax (min, max, tv.tabVec()); }
392 template<class T> inline
393 T min (const TableVector<T>& tv)
394  { T Min,Max; tabVecRepminmax (Min, Max, tv.tabVec()); return Min; }
395 template<class T> inline
396 T max (const TableVector<T>& tv)
397  { T Min,Max; tabVecRepminmax (Min, Max, tv.tabVec()); return Max; }
398 
399 template<class T> inline
400 void indgen (TableVector<T>& tv, Int start, Int inc)
401  { tabVecRepindgen (tv.tabVec(), start, inc); }
402 template<class T> inline
403 void indgen (TableVector<T>& tv, Int start)
404  { tabVecRepindgen (tv.tabVec(), start, 1); }
405 template<class T> inline
407  { tabVecRepindgen (tv.tabVec(), 0, 1); }
408 
409 
410 template<class T> inline
412  { return tabVecRepinnerproduct (l.tabVec(), r.tabVec()); }
413 template<class T> inline
414 T norm (const TableVector<T>& tv)
415  { return tabVecRepnorm (tv.tabVec()); }
416 template<class T> inline
418  const TableVector<T>& r)
419  { return TableVector<T> (tabVecRepcrossproduct (l.tabVec(), r.tabVec())); }
420 
421 
422 
423 } //# NAMESPACE CASACORE - END
424 
425 #endif
LatticeExprNode log10(const LatticeExprNode &expr)
int Int
Definition: aipstype.h:50
LatticeExprNode log(const LatticeExprNode &expr)
LatticeExprNode operator/(const LatticeExprNode &left, const LatticeExprNode &right)
TableVector< T > crossProduct(const TableVector< T > &l, const TableVector< T > &r)
Definition: TabVecMath.h:417
Templated readonly table column vectors.
Definition: TableVector.h:118
LatticeExprNode sum(const LatticeExprNode &expr)
LatticeExprNode max(const LatticeExprNode &left, const LatticeExprNode &right)
Functor to get maximum of two values.
Definition: Functors.h:589
LatticeExprNode exp(const LatticeExprNode &expr)
LatticeExprNode floor(const LatticeExprNode &expr)
MVEarthMagnetic operator*(const RotMatrix &left, const MVEarthMagnetic &right)
Rotate a EarthMagnetic vector with rotation matrix and other multiplications.
LatticeExprNode cos(const LatticeExprNode &expr)
Functor to get minimum of two values.
Definition: Functors.h:581
T innerProduct(const TableVector< T > &l, const TableVector< T > &r)
Definition: TabVecMath.h:411
#define TABVECMATHFUNC(NAME)
Definition: TabVecMath.h:345
TabVecRep< T > & tabVec()
Return the TabVecRep reference.
Definition: TableVector.h:253
#define TABVECMATHFUNC2(NAME)
Definition: TabVecMath.h:349
LatticeExprNode tanh(const LatticeExprNode &expr)
LatticeExprNode min(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode sqrt(const LatticeExprNode &expr)
LatticeExprNode tan(const LatticeExprNode &expr)
void indgen(TableVector< T > &tv, Int start, Int inc)
Definition: TabVecMath.h:400
LatticeExprNode atan(const LatticeExprNode &expr)
TableExprNode product(const TableExprNode &array)
Definition: ExprNode.h:1607
void minMax(T &min, T &max, const TableVector< T > &tv)
Definition: TabVecMath.h:390
#define TABVECMATHOPER(NAME, OP, OPA)
Definition: TabVecMath.h:315
void add(casacore::Int spectralWindow, casacore::Int firstChannel, casacore::Int nChannels, casacore::Int increment=1)
LatticeExprNode atan2(const LatticeExprNode &left, const LatticeExprNode &right)
Numerical 2-argument functions.
LatticeExprNode operator+(const LatticeExprNode &expr)
Global functions operating on a LatticeExprNode.
LatticeExprNode fmod(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode asin(const LatticeExprNode &expr)
LatticeExprNode sinh(const LatticeExprNode &expr)
LatticeExprNode acos(const LatticeExprNode &expr)
LatticeExprNode operator-(const LatticeExprNode &expr)
LatticeExprNode ceil(const LatticeExprNode &expr)
LatticeExprNode pow(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode cosh(const LatticeExprNode &expr)
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
LatticeExprNode sin(const LatticeExprNode &expr)
Numerical 1-argument functions.
TableExprNode norm(const TableExprNode &node)
Definition: ExprNode.h:1317
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42