casa
$Rev:20696$
|
00001 //# TabVecMath.h: Global functions for table vector mathematics 00002 //# Copyright (C) 1994,1995,1996,1999,2003 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id: TabVecMath.h 21298 2012-12-07 14:53:03Z gervandiepen $ 00027 00028 #ifndef TABLES_TABVECMATH_H 00029 #define TABLES_TABVECMATH_H 00030 00031 //# Global functions similar to those defined in ArrayMath are defined for 00032 //# the table vectors. Furthermore vector functions like norm are defined. 00033 00034 //# Includes 00035 #include <casa/aips.h> 00036 #include <casa/BasicMath/Math.h> 00037 #include <tables/Tables/TableVector.h> 00038 #include <tables/Tables/TVecMath.h> 00039 00040 00041 namespace casa { //# NAMESPACE CASA - BEGIN 00042 00043 // <summary> 00044 // Basic math for table vectors. 00045 // </summary> 00046 00047 // <use visibility=export> 00048 00049 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00050 // </reviewed> 00051 00052 // <synopsis> 00053 // These global functions do the basic math for table vectors. 00054 // This means addition, subtraction, multiplication, division 00055 // and negation. 00056 // In case two table vectors are used, the left and right operand 00057 // must be conformant (i.e. have equal length). 00058 // </synopsis> 00059 00060 // <group name=basicMath> 00061 // Add 2 table vectors storing result in first one. 00062 template<class T> inline 00063 void operator+= (TableVector<T>& left, const TableVector<T>& right); 00064 // Subtract 2 table vectors storing result in first one. 00065 template<class T> inline 00066 void operator-= (TableVector<T>& left, const TableVector<T>& right); 00067 // Multiple 2 table vectors storing result in first one. 00068 template<class T> inline 00069 void operator*= (TableVector<T>& left, const TableVector<T>& right); 00070 // Divide 2 table vectors storing result in first one. 00071 template<class T> inline 00072 void operator/= (TableVector<T>& left, const TableVector<T>& right); 00073 00074 // Add a scalar to each element in the table vector. 00075 template<class T> inline 00076 void operator+= (TableVector<T>& left, const T& right); 00077 // Subtract a scalar from each element in the table vector. 00078 template<class T> inline 00079 void operator-= (TableVector<T>& left, const T& right); 00080 // Multiple each element in the table vector with a scalar. 00081 template<class T> inline 00082 void operator*= (TableVector<T>& left, const T& right); 00083 // Divide each element in the table vector by a scalar. 00084 template<class T> inline 00085 void operator/= (TableVector<T>& left, const T& right); 00086 00087 // Unary plus. 00088 template<class T> inline 00089 TableVector<T> operator+ (const TableVector<T>&); 00090 // Unary minus. 00091 template<class T> inline 00092 TableVector<T> operator- (const TableVector<T>&); 00093 00094 // Add 2 table vectors storing result in a new one. 00095 template<class T> inline 00096 TableVector<T> operator+ (const TableVector<T>& left, 00097 const TableVector<T>& right); 00098 // Subtract 2 table vectors storing result in a new one. 00099 template<class T> inline 00100 TableVector<T> operator- (const TableVector<T>& left, 00101 const TableVector<T>& right); 00102 // Multiple 2 table vectors storing result in a new one. 00103 template<class T> inline 00104 TableVector<T> operator* (const TableVector<T>& left, 00105 const TableVector<T>& right); 00106 // Divide 2 table vectors storing result in a new one. 00107 template<class T> inline 00108 TableVector<T> operator/ (const TableVector<T>& left, 00109 const TableVector<T>& right); 00110 00111 // Add a scalar to each element in the table vector storing result 00112 // in a new table vector. 00113 template<class T> inline 00114 TableVector<T> operator+ (const TableVector<T>& left, const T& right); 00115 // Subtract a scalar from each element in the table vector storing result 00116 // in a new table vector. 00117 template<class T> inline 00118 TableVector<T> operator- (const TableVector<T>& left, const T& right); 00119 // Multiple each element in the table vector with a scalar storing result 00120 // in a new table vector. 00121 template<class T> inline 00122 TableVector<T> operator* (const TableVector<T>& left, const T& right); 00123 // Divide each element in the table vector by a scalar storing result 00124 // in a new table vector. 00125 template<class T> inline 00126 TableVector<T> operator/ (const TableVector<T>& left, const T& right); 00127 00128 // Add a scalar to each element in the table vector storing result 00129 // in a new table vector. 00130 template<class T> inline 00131 TableVector<T> operator+ (const T& left, const TableVector<T>& right); 00132 // Subtract a scalar from each element in the table vector storing result 00133 // in a new table vector. 00134 template<class T> inline 00135 TableVector<T> operator- (const T& left, const TableVector<T>& right); 00136 // Multiple each element in the table vector with a scalar storing result 00137 // in a new table vector. 00138 template<class T> inline 00139 TableVector<T> operator* (const T& left, const TableVector<T>& right); 00140 // Divide each element in the table vector by a scalar storing result 00141 // in a new table vector. 00142 template<class T> inline 00143 TableVector<T> operator/ (const T& left, const TableVector<T>& right); 00144 // </group> 00145 00146 00147 00148 // <summary> 00149 // Transcendental math for table vectors. 00150 // </summary> 00151 00152 // <use visibility=export> 00153 00154 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00155 // </reviewed> 00156 00157 // <synopsis> 00158 // These global functions do the transcendental math for table vectors 00159 // for essentially all numeric types. 00160 // The functions are sin, sinh, exp, log, pow, etc.. 00161 // In case two table vectors are used, the left and right operand 00162 // must be conformant (i.e. have equal length). 00163 // </synopsis> 00164 00165 // <group name=basicTransMath> 00166 template<class T> inline TableVector<T> cos (const TableVector<T>&); 00167 template<class T> inline TableVector<T> cosh (const TableVector<T>&); 00168 template<class T> inline TableVector<T> exp (const TableVector<T>&); 00169 template<class T> inline TableVector<T> log (const TableVector<T>&); 00170 template<class T> inline TableVector<T> log10(const TableVector<T>&); 00171 template<class T> inline TableVector<T> pow (const TableVector<T>& value, 00172 const TableVector<T>& exponent); 00173 template<class T> inline TableVector<T> sin (const TableVector<T>&); 00174 template<class T> inline TableVector<T> sinh (const TableVector<T>&); 00175 template<class T> inline TableVector<T> sqrt (const TableVector<T>&); 00176 // </group> 00177 00178 00179 00180 // <summary> 00181 // Further transcendental math for table vectors. 00182 // </summary> 00183 00184 // <use visibility=export> 00185 00186 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00187 // </reviewed> 00188 00189 // <synopsis> 00190 // These global functions do the transcendental math for table vectors 00191 // for a limited set of numeric types. 00192 // The functions are asin, ceil, etc.. 00193 // In case two table vectors are used, the left and right operand 00194 // must be conformant (i.e. have equal length). 00195 // </synopsis> 00196 00197 // <group name=advTransMath> 00198 template<class T> inline TableVector<T> acos (const TableVector<T>&); 00199 template<class T> inline TableVector<T> asin (const TableVector<T>&); 00200 template<class T> inline TableVector<T> atan (const TableVector<T>&); 00201 template<class T> inline TableVector<T> atan2(const TableVector<T>& y, 00202 const TableVector<T>& x); 00203 template<class T> inline TableVector<T> ceil (const TableVector<T>&); 00204 template<class T> inline TableVector<T> fabs (const TableVector<T>&); 00205 template<class T> inline TableVector<T> floor(const TableVector<T>&); 00206 template<class T> inline TableVector<T> fmod (const TableVector<T>& value, 00207 const TableVector<T>& modulo); 00208 template<class T> inline TableVector<T> pow (const TableVector<T>& value, 00209 const double& exponent); 00210 template<class T> inline TableVector<T> tan (const TableVector<T>&); 00211 template<class T> inline TableVector<T> tanh (const TableVector<T>&); 00212 // </group> 00213 00214 00215 00216 // <summary> 00217 // Miscellaneous table vector operations. 00218 // </summary> 00219 00220 // <use visibility=export> 00221 00222 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00223 // </reviewed> 00224 00225 // <synopsis> 00226 // Fill a table vector or calculate the sum, product, minimum or 00227 // maximum of its elements. 00228 // </synopsis> 00229 00230 // <group name=miscellaneous> 00231 // This sets min and max to the min and max of the vector to avoid having 00232 // to do two passes with max() and min() separately. 00233 // Requires that the type "T" has comparison operators. 00234 template<class T> inline 00235 void minMax (T& min, T& max, const TableVector<T>&); 00236 00237 // The minimum element of the table vector. 00238 // Requires that the type "T" has comparison operators. 00239 template<class T> inline 00240 T min (const TableVector<T>&); 00241 00242 // The maximum element of the table vector. 00243 // Requires that the type "T" has comparison operators. 00244 template<class T> inline 00245 T max (const TableVector<T>&); 00246 00247 // Fills all elements of the table vector with a sequence starting with 00248 // "start" and incrementing by "inc" for each element. 00249 template<class T> inline 00250 void indgen (TableVector<T>&, Int start, Int inc); 00251 00252 // Fills all elements of the table vector with a sequence starting with 00253 // "start" incremented by one for each position in the table vector. 00254 template<class T> inline 00255 void indgen (TableVector<T>&, Int start); 00256 00257 // Fills all elements of the table vector with a sequence starting with 00258 // 0 and ending with nelements() - 1. 00259 template<class T> inline 00260 void indgen (TableVector<T>&); 00261 00262 // Sum of all the elements of a table vector. 00263 template<class T> inline 00264 T sum (const TableVector<T>&); 00265 00266 // Product of all the elements of a table vector. 00267 // <note role=warning> 00268 // product can easily overflow. 00269 // </note> 00270 template<class T> inline T 00271 product (const TableVector<T>&); 00272 // </group> 00273 00274 00275 00276 00277 // <summary> 00278 // Vector operations on a table vector. 00279 // </summary> 00280 00281 // <use visibility=export> 00282 00283 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00284 // </reviewed> 00285 00286 // <synopsis> 00287 // Do vector operations on a table vector (like inner product). 00288 // </synopsis> 00289 00290 // <group name=vectorMath> 00291 // The inner product of 2 table vectors. 00292 // The left and right operands must be conformant (i.e. have equal length). 00293 template<class T> inline 00294 T innerProduct (const TableVector<T>& left, 00295 const TableVector<T>& right); 00296 00297 // The norm of a table vector. 00298 template<class T> inline 00299 T norm (const TableVector<T>&); 00300 00301 // The cross product of 2 table vectors containing 3 elements. 00302 template<class T> inline 00303 TableVector<T> crossProduct (const TableVector<T>& left, 00304 const TableVector<T>& right); 00305 // </group> 00306 00307 00308 00309 //# Inline all these functions. 00310 //# The actual work is done by functions (tabVecRep...) operating on TabVecRep. 00311 //# Because the preprocessor of gcc-3 gives warnings when using the macro as 00312 //# e.g. TABVECMATHOPER(add,+,+=), the r is removed from the function name and 00313 //# put befroe the + in the macro call. 00314 00315 #define TABVECMATHOPER(NAME,OP,OPA) \ 00316 template<class T> inline \ 00317 TableVector<T> aips_name2(operato,OP) (const TableVector<T>& tv, \ 00318 const T& v) \ 00319 { return TableVector<T> (aips_name2(tabVecRepvalr,NAME) (tv.tabVec(), \ 00320 v)); } \ 00321 template<class T> inline \ 00322 TableVector<T> aips_name2(operato,OP) (const T& v, \ 00323 const TableVector<T>& tv) \ 00324 { return TableVector<T> (aips_name2(tabVecRepvall,NAME) (v, \ 00325 tv.tabVec())); } \ 00326 template<class T> inline \ 00327 TableVector<T> aips_name2(operato,OP) (const TableVector<T>& l, \ 00328 const TableVector<T>& r) \ 00329 { return TableVector<T> (aips_name2(tabVecReptv,NAME) (l.tabVec(), \ 00330 r.tabVec())); } \ 00331 template<class T> inline \ 00332 void aips_name2(operato,OPA) (TableVector<T>& tv, const T& v) \ 00333 { aips_name2(tabVecRepvalass,NAME) (tv.tabVec(), v); } \ 00334 template<class T> inline \ 00335 void aips_name2(operato,OPA) (TableVector<T>& l, \ 00336 const TableVector<T>& r) \ 00337 { aips_name2(tabVecReptvass,NAME) (l.tabVec(), r.tabVec()); } 00338 00339 TABVECMATHOPER(add,r+,r+=) 00340 TABVECMATHOPER(sub,r-,r-=) 00341 TABVECMATHOPER(tim,r*,r*=) 00342 TABVECMATHOPER(div,r/,r/=) 00343 00344 00345 #define TABVECMATHFUNC(NAME) \ 00346 template<class T> inline \ 00347 TableVector<T> NAME (const TableVector<T>& tv) \ 00348 { return TableVector<T> (aips_name2(tabVecRep,NAME) (tv.tabVec())); } 00349 #define TABVECMATHFUNC2(NAME) \ 00350 template<class T> inline \ 00351 TableVector<T> NAME (const TableVector<T>& l, \ 00352 const TableVector<T>& r) \ 00353 { return TableVector<T> (aips_name2(tabVecRep,NAME) (l.tabVec(), \ 00354 r.tabVec())); } 00355 00356 TABVECMATHFUNC (cos) 00357 TABVECMATHFUNC (cosh) 00358 TABVECMATHFUNC (exp) 00359 TABVECMATHFUNC (log) 00360 TABVECMATHFUNC (log10) 00361 TABVECMATHFUNC2(pow) 00362 TABVECMATHFUNC (sin) 00363 TABVECMATHFUNC (sinh) 00364 TABVECMATHFUNC (sqrt) 00365 TABVECMATHFUNC (acos) 00366 TABVECMATHFUNC (asin) 00367 TABVECMATHFUNC (atan) 00368 TABVECMATHFUNC2(atan2) 00369 TABVECMATHFUNC (ceil) 00370 TABVECMATHFUNC (fabs) 00371 TABVECMATHFUNC (floor) 00372 TABVECMATHFUNC2(fmod) 00373 TABVECMATHFUNC (tan) 00374 TABVECMATHFUNC (tanh) 00375 00376 template<class T> inline 00377 TableVector<T> pow (const TableVector<T>& tv, const double& exp) 00378 { return TableVector<T> (tabVecReppowd (tv.tabVec(), exp)); } 00379 00380 00381 template<class T> inline 00382 T sum (const TableVector<T>& tv) 00383 { return tabVecRepsum (tv.tabVec()); } 00384 template<class T> inline 00385 T product (const TableVector<T>& tv) 00386 { return tabVecRepproduct (tv.tabVec()); } 00387 00388 00389 template<class T> inline 00390 void minMax (T& min, T& max, const TableVector<T>& tv) 00391 { tabVecRepminmax (min, max, tv.tabVec()); } 00392 template<class T> inline 00393 T min (const TableVector<T>& tv) 00394 { T Min,Max; tabVecRepminmax (Min, Max, tv.tabVec()); return Min; } 00395 template<class T> inline 00396 T max (const TableVector<T>& tv) 00397 { T Min,Max; tabVecRepminmax (Min, Max, tv.tabVec()); return Max; } 00398 00399 template<class T> inline 00400 void indgen (TableVector<T>& tv, Int start, Int inc) 00401 { tabVecRepindgen (tv.tabVec(), start, inc); } 00402 template<class T> inline 00403 void indgen (TableVector<T>& tv, Int start) 00404 { tabVecRepindgen (tv.tabVec(), start, 1); } 00405 template<class T> inline 00406 void indgen (TableVector<T>& tv) 00407 { tabVecRepindgen (tv.tabVec(), 0, 1); } 00408 00409 00410 template<class T> inline 00411 T innerProduct (const TableVector<T>& l, const TableVector<T>& r) 00412 { return tabVecRepinnerproduct (l.tabVec(), r.tabVec()); } 00413 template<class T> inline 00414 T norm (const TableVector<T>& tv) 00415 { return tabVecRepnorm (tv.tabVec()); } 00416 template<class T> inline 00417 TableVector<T> crossProduct (const TableVector<T>& l, 00418 const TableVector<T>& r) 00419 { return TableVector<T> (tabVecRepcrossproduct (l.tabVec(), r.tabVec())); } 00420 00421 00422 00423 } //# NAMESPACE CASA - END 00424 00425 #endif