casacore
Loading...
Searching...
No Matches
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: casa-feedback@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#ifndef TABLES_TABVECMATH_H
27#define TABLES_TABVECMATH_H
28
29//# Global functions similar to those defined in ArrayMath are defined for
30//# the table vectors. Furthermore vector functions like norm are defined.
31
32//# Includes
33#include <casacore/casa/aips.h>
34#include <casacore/casa/BasicMath/Math.h>
35#include <casacore/tables/Tables/TableVector.h>
36#include <casacore/tables/Tables/TVecMath.h>
37
38
39namespace casacore { //# NAMESPACE CASACORE - BEGIN
40
41// <summary>
42// Basic math for table vectors.
43// </summary>
44
45// <use visibility=export>
46
47// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
48// </reviewed>
49
50// <synopsis>
51// These global functions do the basic math for table vectors.
52// This means addition, subtraction, multiplication, division
53// and negation.
54// In case two table vectors are used, the left and right operand
55// must be conformant (i.e. have equal length).
56// </synopsis>
57
58// <group name=basicMath>
59// Add 2 table vectors storing result in first one.
60template<class T> inline
61 void operator+= (TableVector<T>& left, const TableVector<T>& right);
62// Subtract 2 table vectors storing result in first one.
63template<class T> inline
64 void operator-= (TableVector<T>& left, const TableVector<T>& right);
65// Multiple 2 table vectors storing result in first one.
66template<class T> inline
67 void operator*= (TableVector<T>& left, const TableVector<T>& right);
68// Divide 2 table vectors storing result in first one.
69template<class T> inline
70 void operator/= (TableVector<T>& left, const TableVector<T>& right);
72// Add a scalar to each element in the table vector.
73template<class T> inline
74 void operator+= (TableVector<T>& left, const T& right);
75// Subtract a scalar from each element in the table vector.
76template<class T> inline
77 void operator-= (TableVector<T>& left, const T& right);
78// Multiple each element in the table vector with a scalar.
79template<class T> inline
80 void operator*= (TableVector<T>& left, const T& right);
81// Divide each element in the table vector by a scalar.
82template<class T> inline
83 void operator/= (TableVector<T>& left, const T& right);
84
85// Unary plus.
86template<class T> inline
88// Unary minus.
89template<class T> inline
91
92// Add 2 table vectors storing result in a new one.
93template<class T> inline
95 const TableVector<T>& right);
96// Subtract 2 table vectors storing result in a new one.
97template<class T> inline
99 const TableVector<T>& right);
100// Multiple 2 table vectors storing result in a new one.
101template<class T> inline
103 const TableVector<T>& right);
104// Divide 2 table vectors storing result in a new one.
105template<class T> inline
107 const TableVector<T>& right);
108
109// Add a scalar to each element in the table vector storing result
110// in a new table vector.
111template<class T> inline
112 TableVector<T> operator+ (const TableVector<T>& left, const T& right);
113// Subtract a scalar from each element in the table vector storing result
114// in a new table vector.
115template<class T> inline
116 TableVector<T> operator- (const TableVector<T>& left, const T& right);
117// Multiple each element in the table vector with a scalar storing result
118// in a new table vector.
119template<class T> inline
120 TableVector<T> operator* (const TableVector<T>& left, const T& right);
121// Divide each element in the table vector by a scalar storing result
122// in a new table vector.
123template<class T> inline
124 TableVector<T> operator/ (const TableVector<T>& left, const T& right);
125
126// Add a scalar to each element in the table vector storing result
127// in a new table vector.
128template<class T> inline
129 TableVector<T> operator+ (const T& left, const TableVector<T>& right);
130// Subtract a scalar from each element in the table vector storing result
131// in a new table vector.
132template<class T> inline
133 TableVector<T> operator- (const T& left, const TableVector<T>& right);
134// Multiple each element in the table vector with a scalar storing result
135// in a new table vector.
136template<class T> inline
137 TableVector<T> operator* (const T& left, const TableVector<T>& right);
138// Divide each element in the table vector by a scalar storing result
139// in a new table vector.
140template<class T> inline
141 TableVector<T> operator/ (const T& left, const TableVector<T>& right);
142// </group>
143
144
145
146// <summary>
147// Transcendental math for table vectors.
148// </summary>
149
150// <use visibility=export>
151
152// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
153// </reviewed>
154
155// <synopsis>
156// These global functions do the transcendental math for table vectors
157// for essentially all numeric types.
158// The functions are sin, sinh, exp, log, pow, etc..
159// In case two table vectors are used, the left and right operand
160// must be conformant (i.e. have equal length).
161// </synopsis>
162
163// <group name=basicTransMath>
164template<class T> inline TableVector<T> cos (const TableVector<T>&);
165template<class T> inline TableVector<T> cosh (const TableVector<T>&);
166template<class T> inline TableVector<T> exp (const TableVector<T>&);
167template<class T> inline TableVector<T> log (const TableVector<T>&);
168template<class T> inline TableVector<T> log10(const TableVector<T>&);
169template<class T> inline TableVector<T> pow (const TableVector<T>& value,
170 const TableVector<T>& exponent);
171template<class T> inline TableVector<T> sin (const TableVector<T>&);
172template<class T> inline TableVector<T> sinh (const TableVector<T>&);
173template<class T> inline TableVector<T> sqrt (const TableVector<T>&);
174// </group>
175
176
177
178// <summary>
179// Further transcendental math for table vectors.
180// </summary>
181
182// <use visibility=export>
183
184// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
185// </reviewed>
186
187// <synopsis>
188// These global functions do the transcendental math for table vectors
189// for a limited set of numeric types.
190// The functions are asin, ceil, etc..
191// In case two table vectors are used, the left and right operand
192// must be conformant (i.e. have equal length).
193// </synopsis>
194
195// <group name=advTransMath>
196template<class T> inline TableVector<T> acos (const TableVector<T>&);
197template<class T> inline TableVector<T> asin (const TableVector<T>&);
198template<class T> inline TableVector<T> atan (const TableVector<T>&);
199template<class T> inline TableVector<T> atan2(const TableVector<T>& y,
200 const TableVector<T>& x);
201template<class T> inline TableVector<T> ceil (const TableVector<T>&);
202template<class T> inline TableVector<T> fabs (const TableVector<T>&);
203template<class T> inline TableVector<T> floor(const TableVector<T>&);
204template<class T> inline TableVector<T> fmod (const TableVector<T>& value,
205 const TableVector<T>& modulo);
206template<class T> inline TableVector<T> pow (const TableVector<T>& value,
207 const double& exponent);
208template<class T> inline TableVector<T> tan (const TableVector<T>&);
209template<class T> inline TableVector<T> tanh (const TableVector<T>&);
210// </group>
211
212
213
214// <summary>
215// Miscellaneous table vector operations.
216// </summary>
217
218// <use visibility=export>
219
220// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
221// </reviewed>
222
223// <synopsis>
224// Fill a table vector or calculate the sum, product, minimum or
225// maximum of its elements.
226// </synopsis>
227
228// <group name=miscellaneous>
229// This sets min and max to the min and max of the vector to avoid having
230// to do two passes with max() and min() separately.
231// Requires that the type "T" has comparison operators.
232template<class T> inline
233 void minMax (T& min, T& max, const TableVector<T>&);
235// The minimum element of the table vector.
236// Requires that the type "T" has comparison operators.
237template<class T> inline
238 T min (const TableVector<T>&);
239
240// The maximum element of the table vector.
241// Requires that the type "T" has comparison operators.
242template<class T> inline
243 T max (const TableVector<T>&);
244
245// Fills all elements of the table vector with a sequence starting with
246// "start" and incrementing by "inc" for each element.
247template<class T> inline
248 void indgen (TableVector<T>&, T start, T inc);
249
250// Fills all elements of the table vector with a sequence starting with
251// "start" incremented by one for each position in the table vector.
252template<class T> inline
253 void indgen (TableVector<T>&, T start);
254
255// Fills all elements of the table vector with a sequence starting with
256// 0 and ending with nelements() - 1.
257template<class T> inline
259
260// Sum of all the elements of a table vector.
261template<class T> inline
262 T sum (const TableVector<T>&);
263
264// Product of all the elements of a table vector.
265// <note role=warning>
266// product can easily overflow.
267// </note>
268template<class T> inline T
270// </group>
271
272
273
274
275// <summary>
276// Vector operations on a table vector.
277// </summary>
278
279// <use visibility=export>
280
281// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
282// </reviewed>
283
284// <synopsis>
285// Do vector operations on a table vector (like inner product).
286// </synopsis>
287
288// <group name=vectorMath>
289// The inner product of 2 table vectors.
290// The left and right operands must be conformant (i.e. have equal length).
291template<class T> inline
292 T innerProduct (const TableVector<T>& left,
293 const TableVector<T>& right);
294
295// The norm of a table vector.
296template<class T> inline
298
299// The cross product of 2 table vectors containing 3 elements.
300template<class T> inline
302 const TableVector<T>& right);
303// </group>
304
305
306
307//# Inline all these functions.
308//# The actual work is done by functions (tabVecRep...) operating on TabVecRep.
309//# Because the preprocessor of gcc-3 gives warnings when using the macro as
310//# e.g. TABVECMATHOPER(add,+,+=), the r is removed from the function name and
311//# put befroe the + in the macro call.
312
313#define TABVECMATHOPER(NAME,OP,OPA) \
314template<class T> inline \
315TableVector<T> aips_name2(operato,OP) (const TableVector<T>& tv, \
316 const T& v) \
317 { return TableVector<T> (aips_name2(tabVecRepvalr,NAME) (tv.tabVec(), \
318 v)); } \
319template<class T> inline \
320TableVector<T> aips_name2(operato,OP) (const T& v, \
321 const TableVector<T>& tv) \
322 { return TableVector<T> (aips_name2(tabVecRepvall,NAME) (v, \
323 tv.tabVec())); } \
324template<class T> inline \
325TableVector<T> aips_name2(operato,OP) (const TableVector<T>& l, \
326 const TableVector<T>& r) \
327 { return TableVector<T> (aips_name2(tabVecReptv,NAME) (l.tabVec(), \
328 r.tabVec())); } \
329template<class T> inline \
330void aips_name2(operato,OPA) (TableVector<T>& tv, const T& v) \
331 { aips_name2(tabVecRepvalass,NAME) (tv.tabVec(), v); } \
332template<class T> inline \
333void aips_name2(operato,OPA) (TableVector<T>& l, \
334 const TableVector<T>& r) \
335 { aips_name2(tabVecReptvass,NAME) (l.tabVec(), r.tabVec()); }
336
337TABVECMATHOPER(add,r+,r+=)
338TABVECMATHOPER(sub,r-,r-=)
339TABVECMATHOPER(tim,r*,r*=)
340TABVECMATHOPER(div,r/,r/=)
341
342
343#define TABVECMATHFUNC(NAME) \
344template<class T> inline \
345TableVector<T> NAME (const TableVector<T>& tv) \
346 { return TableVector<T> (aips_name2(tabVecRep,NAME) (tv.tabVec())); }
347#define TABVECMATHFUNC2(NAME) \
348template<class T> inline \
349TableVector<T> NAME (const TableVector<T>& l, \
350 const TableVector<T>& r) \
351 { return TableVector<T> (aips_name2(tabVecRep,NAME) (l.tabVec(), \
352 r.tabVec())); }
353
354TABVECMATHFUNC (cos)
355TABVECMATHFUNC (cosh)
356TABVECMATHFUNC (exp)
357TABVECMATHFUNC (log)
358TABVECMATHFUNC (log10)
360TABVECMATHFUNC (sin)
361TABVECMATHFUNC (sinh)
362TABVECMATHFUNC (sqrt)
363TABVECMATHFUNC (acos)
364TABVECMATHFUNC (asin)
365TABVECMATHFUNC (atan)
366TABVECMATHFUNC2(atan2)
367TABVECMATHFUNC (ceil)
368TABVECMATHFUNC (fabs)
369TABVECMATHFUNC (floor)
370TABVECMATHFUNC2(fmod)
371TABVECMATHFUNC (tan)
372TABVECMATHFUNC (tanh)
373
374template<class T> inline
375TableVector<T> pow (const TableVector<T>& tv, const double& exp)
376 { return TableVector<T> (tabVecReppowd (tv.tabVec(), exp)); }
377
378
379template<class T> inline
380T sum (const TableVector<T>& tv)
381 { return tabVecRepsum (tv.tabVec()); }
382template<class T> inline
384 { return tabVecRepproduct (tv.tabVec()); }
385
386
387template<class T> inline
388void minMax (T& min, T& max, const TableVector<T>& tv)
389 { tabVecRepminmax (min, max, tv.tabVec()); }
390template<class T> inline
391T min (const TableVector<T>& tv)
392 { T Min,Max; tabVecRepminmax (Min, Max, tv.tabVec()); return Min; }
393template<class T> inline
394T max (const TableVector<T>& tv)
395 { T Min,Max; tabVecRepminmax (Min, Max, tv.tabVec()); return Max; }
396
397template<class T> inline
398void indgen (TableVector<T>& tv, T start, T inc)
399 { tabVecRepindgen (tv.tabVec(), start, inc); }
400template<class T> inline
401void indgen (TableVector<T>& tv, T start)
402 { tabVecRepindgen (tv.tabVec(), start, T(1)); }
403template<class T> inline
405 { tabVecRepindgen (tv.tabVec(), T(0), T(1)); }
406
407
408template<class T> inline
410 { return tabVecRepinnerproduct (l.tabVec(), r.tabVec()); }
411template<class T> inline
412T norm (const TableVector<T>& tv)
413 { return tabVecRepnorm (tv.tabVec()); }
414template<class T> inline
416 const TableVector<T>& r)
417 { return TableVector<T> (tabVecRepcrossproduct (l.tabVec(), r.tabVec())); }
418
419
420
421} //# NAMESPACE CASACORE - END
422
423#endif
#define TABVECMATHFUNC(NAME)
Definition TabVecMath.h:343
#define TABVECMATHOPER(NAME, OP, OPA)
Definition TabVecMath.h:313
#define TABVECMATHFUNC2(NAME)
Definition TabVecMath.h:347
TabVecRep< T > & tabVec()
Return the TabVecRep reference.
this file contains all the compiler specific defines
Definition mainpage.dox:28
LatticeExprNode exp(const LatticeExprNode &expr)
LatticeExprNode asin(const LatticeExprNode &expr)
void minMax(T &min, T &max, const TableVector< T > &tv)
Definition TabVecMath.h:388
LatticeExprNode fmod(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode acos(const LatticeExprNode &expr)
T innerProduct(const TableVector< T > &l, const TableVector< T > &r)
Definition TabVecMath.h:409
LatticeExprNode max(const LatticeExprNode &left, const LatticeExprNode &right)
void indgen(TableVector< T > &tv, T start, T inc)
Definition TabVecMath.h:398
LatticeExprNode cosh(const LatticeExprNode &expr)
LatticeExprNode atan(const LatticeExprNode &expr)
LatticeExprNode tanh(const LatticeExprNode &expr)
LatticeExprNode log10(const LatticeExprNode &expr)
LatticeExprNode sinh(const LatticeExprNode &expr)
LatticeExprNode sum(const LatticeExprNode &expr)
LatticeExprNode operator+(const LatticeExprNode &expr)
Global functions operating on a LatticeExprNode.
MVBaseline operator*(const RotMatrix &left, const MVBaseline &right)
Rotate a Baseline vector with rotation matrix and other multiplications.
LatticeExprNode min(const LatticeExprNode &left, const LatticeExprNode &right)
T norm(const TableVector< T > &tv)
Definition TabVecMath.h:412
LatticeExprNode operator-(const LatticeExprNode &expr)
LatticeExprNode tan(const LatticeExprNode &expr)
LatticeExprNode sin(const LatticeExprNode &expr)
Numerical 1-argument functions.
LatticeExprNode operator/(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode atan2(const LatticeExprNode &left, const LatticeExprNode &right)
Numerical 2-argument functions.
TableVector< T > crossProduct(const TableVector< T > &l, const TableVector< T > &r)
Definition TabVecMath.h:415
LatticeExprNode sqrt(const LatticeExprNode &expr)
T product(const TableVector< T > &tv)
Definition TabVecMath.h:383
LatticeExprNode pow(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode log(const LatticeExprNode &expr)
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
LatticeExprNode cos(const LatticeExprNode &expr)
LatticeExprNode floor(const LatticeExprNode &expr)
LatticeExprNode ceil(const LatticeExprNode &expr)
Functor to get maximum of two values.
Definition Functors.h:588
Functor to get minimum of two values.
Definition Functors.h:580
Further transcendental math for table vectors.
Definition TabVecMath.h:196
TableVector< T > asin(const TableVector< T > &)
TableVector< T > acos(const TableVector< T > &)
TableVector< T > ceil(const TableVector< T > &)
TableVector< T > fabs(const TableVector< T > &)
TableVector< T > pow(const TableVector< T > &value, const double &exponent)
TableVector< T > tan(const TableVector< T > &)
TableVector< T > atan2(const TableVector< T > &y, const TableVector< T > &x)
TableVector< T > floor(const TableVector< T > &)
TableVector< T > tanh(const TableVector< T > &)
TableVector< T > fmod(const TableVector< T > &value, const TableVector< T > &modulo)
TableVector< T > atan(const TableVector< T > &)
void operator/=(TableVector< T > &left, const TableVector< T > &right)
Divide 2 table vectors storing result in first one.
TableVector< T > operator*(const TableVector< T > &left, const TableVector< T > &right)
Multiple 2 table vectors storing result in a new one.
TableVector< T > operator/(const TableVector< T > &left, const TableVector< T > &right)
Divide 2 table vectors storing result in a new one.
void operator*=(TableVector< T > &left, const TableVector< T > &right)
Multiple 2 table vectors storing result in first one.
TableVector< T > operator-(const TableVector< T > &)
Unary minus.
void operator+=(TableVector< T > &left, const TableVector< T > &right)
Add 2 table vectors storing result in first one.
TableVector< T > operator+(const TableVector< T > &)
Unary plus.
void operator-=(TableVector< T > &left, const TableVector< T > &right)
Subtract 2 table vectors storing result in first one.
Transcendental math for table vectors.
Definition TabVecMath.h:164
TableVector< T > sin(const TableVector< T > &)
TableVector< T > cos(const TableVector< T > &)
TableVector< T > cosh(const TableVector< T > &)
TableVector< T > sinh(const TableVector< T > &)
TableVector< T > log(const TableVector< T > &)
TableVector< T > sqrt(const TableVector< T > &)
TableVector< T > log10(const TableVector< T > &)
TableVector< T > pow(const TableVector< T > &value, const TableVector< T > &exponent)
TableVector< T > exp(const TableVector< T > &)
Miscellaneous table vector operations.
Definition TabVecMath.h:229
T sum(const TableVector< T > &)
Sum of all the elements of a table vector.
void indgen(TableVector< T > &, T start)
Fills all elements of the table vector with a sequence starting with "start" incremented by one for e...
void indgen(TableVector< T > &, T start, T inc)
Fills all elements of the table vector with a sequence starting with "start" and incrementing by "inc...
T min(const TableVector< T > &)
The minimum element of the table vector.
void minMax(T &min, T &max, const TableVector< T > &)
This sets min and max to the min and max of the vector to avoid having to do two passes with max() an...
T max(const TableVector< T > &)
The maximum element of the table vector.
void indgen(TableVector< T > &)
Fills all elements of the table vector with a sequence starting with 0 and ending with nelements() - ...
T product(const TableVector< T > &)
Product of all the elements of a table vector.
Vector operations on a table vector.
Definition TabVecMath.h:289
T innerProduct(const TableVector< T > &left, const TableVector< T > &right)
The inner product of 2 table vectors.
T norm(const TableVector< T > &)
The norm of a table vector.
TableVector< T > crossProduct(const TableVector< T > &left, const TableVector< T > &right)
The cross product of 2 table vectors containing 3 elements.