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