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: 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>
36#include <casacore/casa/BasicMath/Math.h>
37#include <casacore/tables/Tables/TableVector.h>
38#include <casacore/tables/Tables/TVecMath.h>
39
40
41namespace 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.
62template<class T> inline
63 void operator+= (TableVector<T>& left, const TableVector<T>& right);
64// Subtract 2 table vectors storing result in first one.
65template<class T> inline
66 void operator-= (TableVector<T>& left, const TableVector<T>& right);
67// Multiple 2 table vectors storing result in first one.
68template<class T> inline
69 void operator*= (TableVector<T>& left, const TableVector<T>& right);
70// Divide 2 table vectors storing result in first one.
71template<class T> inline
72 void operator/= (TableVector<T>& left, const TableVector<T>& right);
74// Add a scalar to each element in the table vector.
75template<class T> inline
76 void operator+= (TableVector<T>& left, const T& right);
77// Subtract a scalar from each element in the table vector.
78template<class T> inline
79 void operator-= (TableVector<T>& left, const T& right);
80// Multiple each element in the table vector with a scalar.
81template<class T> inline
82 void operator*= (TableVector<T>& left, const T& right);
83// Divide each element in the table vector by a scalar.
84template<class T> inline
85 void operator/= (TableVector<T>& left, const T& right);
86
87// Unary plus.
88template<class T> inline
90// Unary minus.
91template<class T> inline
93
94// Add 2 table vectors storing result in a new one.
95template<class T> inline
97 const TableVector<T>& right);
98// Subtract 2 table vectors storing result in a new one.
99template<class T> inline
101 const TableVector<T>& right);
102// Multiple 2 table vectors storing result in a new one.
103template<class T> inline
105 const TableVector<T>& right);
106// Divide 2 table vectors storing result in a new one.
107template<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.
113template<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.
117template<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.
121template<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.
125template<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.
130template<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.
134template<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.
138template<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.
142template<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>
166template<class T> inline TableVector<T> cos (const TableVector<T>&);
167template<class T> inline TableVector<T> cosh (const TableVector<T>&);
168template<class T> inline TableVector<T> exp (const TableVector<T>&);
169template<class T> inline TableVector<T> log (const TableVector<T>&);
170template<class T> inline TableVector<T> log10(const TableVector<T>&);
171template<class T> inline TableVector<T> pow (const TableVector<T>& value,
172 const TableVector<T>& exponent);
173template<class T> inline TableVector<T> sin (const TableVector<T>&);
174template<class T> inline TableVector<T> sinh (const TableVector<T>&);
175template<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>
198template<class T> inline TableVector<T> acos (const TableVector<T>&);
199template<class T> inline TableVector<T> asin (const TableVector<T>&);
200template<class T> inline TableVector<T> atan (const TableVector<T>&);
201template<class T> inline TableVector<T> atan2(const TableVector<T>& y,
202 const TableVector<T>& x);
203template<class T> inline TableVector<T> ceil (const TableVector<T>&);
204template<class T> inline TableVector<T> fabs (const TableVector<T>&);
205template<class T> inline TableVector<T> floor(const TableVector<T>&);
206template<class T> inline TableVector<T> fmod (const TableVector<T>& value,
207 const TableVector<T>& modulo);
208template<class T> inline TableVector<T> pow (const TableVector<T>& value,
209 const double& exponent);
210template<class T> inline TableVector<T> tan (const TableVector<T>&);
211template<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.
234template<class T> inline
235 void minMax (T& min, T& max, const TableVector<T>&);
237// The minimum element of the table vector.
238// Requires that the type "T" has comparison operators.
239template<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.
244template<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.
249template<class T> inline
250 void indgen (TableVector<T>&, T start, T 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.
254template<class T> inline
255 void indgen (TableVector<T>&, T start);
256
257// Fills all elements of the table vector with a sequence starting with
258// 0 and ending with nelements() - 1.
259template<class T> inline
261
262// Sum of all the elements of a table vector.
263template<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>
270template<class T> inline 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).
293template<class T> inline
294 T innerProduct (const TableVector<T>& left,
295 const TableVector<T>& right);
296
297// The norm of a table vector.
298template<class T> inline
300
301// The cross product of 2 table vectors containing 3 elements.
302template<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) \
316template<class T> inline \
317TableVector<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)); } \
321template<class T> inline \
322TableVector<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())); } \
326template<class T> inline \
327TableVector<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())); } \
331template<class T> inline \
332void aips_name2(operato,OPA) (TableVector<T>& tv, const T& v) \
333 { aips_name2(tabVecRepvalass,NAME) (tv.tabVec(), v); } \
334template<class T> inline \
335void aips_name2(operato,OPA) (TableVector<T>& l, \
336 const TableVector<T>& r) \
337 { aips_name2(tabVecReptvass,NAME) (l.tabVec(), r.tabVec()); }
338
339TABVECMATHOPER(add,r+,r+=)
340TABVECMATHOPER(sub,r-,r-=)
341TABVECMATHOPER(tim,r*,r*=)
342TABVECMATHOPER(div,r/,r/=)
343
344
345#define TABVECMATHFUNC(NAME) \
346template<class T> inline \
347TableVector<T> NAME (const TableVector<T>& tv) \
348 { return TableVector<T> (aips_name2(tabVecRep,NAME) (tv.tabVec())); }
349#define TABVECMATHFUNC2(NAME) \
350template<class T> inline \
351TableVector<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
356TABVECMATHFUNC (cos)
357TABVECMATHFUNC (cosh)
358TABVECMATHFUNC (exp)
359TABVECMATHFUNC (log)
360TABVECMATHFUNC (log10)
362TABVECMATHFUNC (sin)
363TABVECMATHFUNC (sinh)
364TABVECMATHFUNC (sqrt)
365TABVECMATHFUNC (acos)
366TABVECMATHFUNC (asin)
367TABVECMATHFUNC (atan)
368TABVECMATHFUNC2(atan2)
369TABVECMATHFUNC (ceil)
370TABVECMATHFUNC (fabs)
371TABVECMATHFUNC (floor)
372TABVECMATHFUNC2(fmod)
373TABVECMATHFUNC (tan)
374TABVECMATHFUNC (tanh)
375
376template<class T> inline
377TableVector<T> pow (const TableVector<T>& tv, const double& exp)
378 { return TableVector<T> (tabVecReppowd (tv.tabVec(), exp)); }
379
380
381template<class T> inline
382T sum (const TableVector<T>& tv)
383 { return tabVecRepsum (tv.tabVec()); }
384template<class T> inline
386 { return tabVecRepproduct (tv.tabVec()); }
387
388
389template<class T> inline
390void minMax (T& min, T& max, const TableVector<T>& tv)
391 { tabVecRepminmax (min, max, tv.tabVec()); }
392template<class T> inline
393T min (const TableVector<T>& tv)
394 { T Min,Max; tabVecRepminmax (Min, Max, tv.tabVec()); return Min; }
395template<class T> inline
396T max (const TableVector<T>& tv)
397 { T Min,Max; tabVecRepminmax (Min, Max, tv.tabVec()); return Max; }
398
399template<class T> inline
400void indgen (TableVector<T>& tv, T start, T inc)
401 { tabVecRepindgen (tv.tabVec(), start, inc); }
402template<class T> inline
403void indgen (TableVector<T>& tv, T start)
404 { tabVecRepindgen (tv.tabVec(), start, T(1)); }
405template<class T> inline
407 { tabVecRepindgen (tv.tabVec(), T(0), T(1)); }
408
409
410template<class T> inline
412 { return tabVecRepinnerproduct (l.tabVec(), r.tabVec()); }
413template<class T> inline
414T norm (const TableVector<T>& tv)
415 { return tabVecRepnorm (tv.tabVec()); }
416template<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
#define TABVECMATHFUNC(NAME)
Definition TabVecMath.h:345
#define TABVECMATHOPER(NAME, OP, OPA)
Definition TabVecMath.h:315
#define TABVECMATHFUNC2(NAME)
Definition TabVecMath.h:349
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:390
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:411
LatticeExprNode max(const LatticeExprNode &left, const LatticeExprNode &right)
void indgen(TableVector< T > &tv, T start, T inc)
Definition TabVecMath.h:400
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:414
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:417
LatticeExprNode sqrt(const LatticeExprNode &expr)
T product(const TableVector< T > &tv)
Definition TabVecMath.h:385
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:590
Functor to get minimum of two values.
Definition Functors.h:582
Further transcendental math for table vectors.
Definition TabVecMath.h:198
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:166
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:231
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:291
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.