casa
$Rev:20696$
|
00001 //# MaskArrLogi.h: Element by element logical operations on masked arrays. 00002 //# Copyright (C) 1993,1994,1995,1999,2001 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: MaskArrLogi.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $ 00027 00028 #ifndef CASA_MASKARRLOGI_H 00029 #define CASA_MASKARRLOGI_H 00030 00031 00032 #include <casa/aips.h> 00033 #include <casa/Arrays/Array.h> 00034 #include <casa/Arrays/MaskedArray.h> 00035 #include <casa/Arrays/MaskLogiArr.h> 00036 00037 namespace casa { //# NAMESPACE CASA - BEGIN 00038 00039 // <summary> 00040 // Logical operations for MaskedArrays, and between MaskedArrays and Arrays. 00041 // </summary> 00042 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tMaskArrLogi tMaskArrExcp"> 00043 // 00044 // <prerequisite> 00045 // <li> <linkto class=Array>Array</linkto> 00046 // <li> <linkto group="LogiArray.h#LogicalArray">LogicalArray</linkto> 00047 // <li> <linkto class=MaskedArray>MaskedArray</linkto> 00048 // </prerequisite> 00049 // 00050 // <etymology> 00051 // MaskArrLogi is short for MaskedArrayLogical, which is too long by 00052 // AIPS++ file naming conventions. This file contains global functions 00053 // which perform element by element logical operations on masked arrays. 00054 // </etymology> 00055 // 00056 // <synopsis> 00057 // These functions perform element by element logical operations on 00058 // masked arrays. With two arrays, they must both conform, and the result 00059 // is done element by element, for those locations where the mask of the 00060 // MaskedArray is True. For two MaskedArrays, the "and" of the masks is used. 00061 // 00062 // There are two classes of functions. One class returns a MaskedLogicalArray. 00063 // In these functions, the value of an element of the MaskedLogicalArray is 00064 // the value of the logical operation applied to the corresponding elements 00065 // of the input MaskedArrays. The other class of functions returns a single 00066 // Bool. The return value is True if the logical operation returns True for 00067 // all elements of the input masked arrays for the "all" functions 00068 // (e.g. allLE()), and returns True if the logical operation returns True for 00069 // any elements of the input masked arrays for the "any" functions 00070 // (e.g. anyLE()). The functions which return a single Bool throw an exception 00071 // if the AND of the masks of the input masked arrays has no True elements. 00072 // 00073 // For instance allLE (a, b) imples that every element of a is 00074 // less than or equal to every element of b. Note that with this definition 00075 // allLE (a, b) and allGE (a, b) can both be false (e.g. a = [1,0] b = [0,1]). 00076 // 00077 // NB comparison between two zero-sized arrays is not defined (should it 00078 // throw an exception?). 00079 // </synopsis> 00080 // 00081 // <example> 00082 // <srcblock> 00083 // Vector<Int> a(10); 00084 // Vector<Int> b(10); 00085 // LogicalVector l(10); 00086 // . . . 00087 // l = a(a>0) < b(b>0); 00088 // </srcblock> 00089 // This example sets those elements of l where ((a>0) && (b>0)) to (a<b). 00090 // Elements of l where !((a>0) && (b>0)) are unchanged. The result of 00091 // the comparison is a MaskedLogicalArray. The assignment from this 00092 // MaskedLogicalArray to the LogicalArray l only assigns those elements 00093 // where the mask is True. 00094 // </example> 00095 // 00096 // <example> 00097 // <srcblock> 00098 // Vector<Int> a(10); 00099 // Vector<Int> b(10); 00100 // Bool result; 00101 // . . . 00102 // result = allLT (a(a>0), b(b>0)); 00103 // </srcblock> 00104 // This example sets result to True if, for all elements where 00105 // ((a>0) && (b>0)), a<b. 00106 // </example> 00107 // 00108 // <motivation> 00109 // One wants to be able to mask arrays and perform logical operations on 00110 // those masked arrays. Since the masked arrays are only defined where 00111 // the masks are True, the result must be a MaskedLogicalArray, or a single 00112 // Bool. 00113 // </motivation> 00114 // 00115 // <todo asof="$DATE:$> 00116 // <li> Reconsider where the origin of the returned LogicalArray should 00117 // be located. 00118 // </todo> 00119 // 00120 // <linkfrom anchor="MaskedArray logical operations" classes="MaskedArray Array Vector Matrix Cube"> 00121 // <here>MaskedArray logical operations</here> -- Logical operations 00122 // for MaskedArrays, and between MaskedArrays and Arrays. 00123 // </linkfrom> 00124 // 00125 // <group name="MaskedArray logical operations"> 00126 00127 00128 // 00129 // Element by element comparisons between the "l" and "r" arrays. The result 00130 // is true only if the comparison is true for every element of the arrays 00131 // for which the mask of the MaskedArray is True. For two MaskedArrays, 00132 // the "and" of the masks is used. 00133 // 00134 // <thrown> 00135 // <li> ArrayConformanceError 00136 // <li> ArrayError 00137 // </thrown> 00138 // 00139 // <group> 00140 template<class T> Bool allLE (const MaskedArray<T> &l, const Array<T> &r); 00141 template<class T> Bool allLT (const MaskedArray<T> &l, const Array<T> &r); 00142 template<class T> Bool allGE (const MaskedArray<T> &l, const Array<T> &r); 00143 template<class T> Bool allGT (const MaskedArray<T> &l, const Array<T> &r); 00144 template<class T> Bool allEQ (const MaskedArray<T> &l, const Array<T> &r); 00145 template<class T> Bool allNE (const MaskedArray<T> &l, const Array<T> &r); 00146 // 00147 // This only makes sense if the array element type is logical valued. 00148 // <group> 00149 template<class T> Bool allAND (const MaskedArray<T> &l, const Array<T> &r); 00150 template<class T> Bool allOR (const MaskedArray<T> &l, const Array<T> &r); 00151 // </group> 00152 00153 template<class T> Bool allLE (const Array<T> &l, const MaskedArray<T> &r); 00154 template<class T> Bool allLT (const Array<T> &l, const MaskedArray<T> &r); 00155 template<class T> Bool allGE (const Array<T> &l, const MaskedArray<T> &r); 00156 template<class T> Bool allGT (const Array<T> &l, const MaskedArray<T> &r); 00157 template<class T> Bool allEQ (const Array<T> &l, const MaskedArray<T> &r); 00158 template<class T> Bool allNE (const Array<T> &l, const MaskedArray<T> &r); 00159 // 00160 // This only makes sense if the array element type is logical valued. 00161 // <group> 00162 template<class T> Bool allAND (const Array<T> &l, const MaskedArray<T> &r); 00163 template<class T> Bool allOR (const Array<T> &l, const MaskedArray<T> &r); 00164 // </group> 00165 00166 template<class T> 00167 Bool allLE (const MaskedArray<T> &l, const MaskedArray<T> &r); 00168 template<class T> 00169 Bool allLT (const MaskedArray<T> &l, const MaskedArray<T> &r); 00170 template<class T> 00171 Bool allGE (const MaskedArray<T> &l, const MaskedArray<T> &r); 00172 template<class T> 00173 Bool allGT (const MaskedArray<T> &l, const MaskedArray<T> &r); 00174 template<class T> 00175 Bool allEQ (const MaskedArray<T> &l, const MaskedArray<T> &r); 00176 template<class T> 00177 Bool allNE (const MaskedArray<T> &l, const MaskedArray<T> &r); 00178 // 00179 // This only makes sense if the array element type is logical valued. 00180 // <group> 00181 template<class T> 00182 Bool allAND (const MaskedArray<T> &l, const MaskedArray<T> &r); 00183 template<class T> 00184 Bool allOR (const MaskedArray<T> &l, const MaskedArray<T> &r); 00185 // </group> 00186 00187 // </group> 00188 00189 00190 // 00191 // Element by element comparisons between the "l" and "r" arrays. The result 00192 // is a MaskedLogicalArray. 00193 // 00194 // The arrays must conform or an exception is thrown. 00195 // 00196 // <thrown> 00197 // <li> ArrayConformanceError 00198 // </thrown> 00199 // 00200 // <group> 00201 template<class T> 00202 MaskedLogicalArray operator <= (const MaskedArray<T> &l, const Array<T> &r); 00203 template<class T> 00204 MaskedLogicalArray operator < (const MaskedArray<T> &l, const Array<T> &r); 00205 template<class T> 00206 MaskedLogicalArray operator >= (const MaskedArray<T> &l, const Array<T> &r); 00207 template<class T> 00208 MaskedLogicalArray operator > (const MaskedArray<T> &l, const Array<T> &r); 00209 template<class T> 00210 MaskedLogicalArray operator == (const MaskedArray<T> &l, const Array<T> &r); 00211 template<class T> 00212 MaskedLogicalArray operator != (const MaskedArray<T> &l, const Array<T> &r); 00213 // 00214 // This only makes sense if the array element type is logical valued. 00215 // <group> 00216 template<class T> 00217 MaskedLogicalArray operator && (const MaskedArray<T> &l, const Array<T> &r); 00218 template<class T> 00219 MaskedLogicalArray operator || (const MaskedArray<T> &l, const Array<T> &r); 00220 // </group> 00221 00222 template<class T> 00223 MaskedLogicalArray operator <= (const Array<T> &l, const MaskedArray<T> &r); 00224 template<class T> 00225 MaskedLogicalArray operator < (const Array<T> &l, const MaskedArray<T> &r); 00226 template<class T> 00227 MaskedLogicalArray operator >= (const Array<T> &l, const MaskedArray<T> &r); 00228 template<class T> 00229 MaskedLogicalArray operator > (const Array<T> &l, const MaskedArray<T> &r); 00230 template<class T> 00231 MaskedLogicalArray operator == (const Array<T> &l, const MaskedArray<T> &r); 00232 template<class T> 00233 MaskedLogicalArray operator != (const Array<T> &l, const MaskedArray<T> &r); 00234 // 00235 // This only makes sense if the array element type is logical valued. 00236 // <group> 00237 template<class T> 00238 MaskedLogicalArray operator && (const Array<T> &l, const MaskedArray<T> &r); 00239 template<class T> 00240 MaskedLogicalArray operator || (const Array<T> &l, const MaskedArray<T> &r); 00241 // </group> 00242 00243 template<class T> 00244 MaskedLogicalArray operator <= (const MaskedArray<T> &l, 00245 const MaskedArray<T> &r); 00246 template<class T> 00247 MaskedLogicalArray operator < (const MaskedArray<T> &l, 00248 const MaskedArray<T> &r); 00249 template<class T> 00250 MaskedLogicalArray operator >= (const MaskedArray<T> &l, 00251 const MaskedArray<T> &r); 00252 template<class T> 00253 MaskedLogicalArray operator > (const MaskedArray<T> &l, 00254 const MaskedArray<T> &r); 00255 template<class T> 00256 MaskedLogicalArray operator == (const MaskedArray<T> &l, 00257 const MaskedArray<T> &r); 00258 template<class T> 00259 MaskedLogicalArray operator != (const MaskedArray<T> &l, 00260 const MaskedArray<T> &r); 00261 // 00262 // This only makes sense if the array element type is logical valued. 00263 // <group> 00264 template<class T> 00265 MaskedLogicalArray operator && (const MaskedArray<T> &l, 00266 const MaskedArray<T> &r); 00267 template<class T> 00268 MaskedLogicalArray operator || (const MaskedArray<T> &l, 00269 const MaskedArray<T> &r); 00270 // </group> 00271 00272 // </group> 00273 00274 00275 // 00276 // Logical negation of a MaskedArray. This only makes sense if the array 00277 // element type is logical valued. 00278 template<class T> 00279 MaskedLogicalArray operator ! (const MaskedArray<T> &marray); 00280 00281 00282 // 00283 // Element by element comparisons between an array and a scalar, which 00284 // behaves as if it were a conformant array filled with the value "val." 00285 // The result is true only if the comparison is true for every element 00286 // for which the mask of the MaskedArray is True. 00287 // <thrown> 00288 // <li> ArrayError 00289 // </thrown> 00290 // 00291 // <group> 00292 template<class T> Bool allLE (const MaskedArray<T> &array, const T &val); 00293 template<class T> Bool allLE (const T &val, const MaskedArray<T> &array); 00294 template<class T> Bool allLT (const MaskedArray<T> &array, const T &val); 00295 template<class T> Bool allLT (const T &val, const MaskedArray<T> &array); 00296 template<class T> Bool allGE (const MaskedArray<T> &array, const T &val); 00297 template<class T> Bool allGE (const T &val, const MaskedArray<T> &array); 00298 template<class T> Bool allGT (const MaskedArray<T> &array, const T &val); 00299 template<class T> Bool allGT (const T &val, const MaskedArray<T> &array); 00300 template<class T> Bool allEQ (const MaskedArray<T> &array, const T &val); 00301 template<class T> Bool allEQ (const T &val, const MaskedArray<T> &array); 00302 template<class T> Bool allNE (const MaskedArray<T> &array, const T &val); 00303 template<class T> Bool allNE (const T &val, const MaskedArray<T> &array); 00304 // 00305 // This only makes sense if the array element type is logical valued. 00306 // <group> 00307 template<class T> Bool allAND (const MaskedArray<T> &array, const T &val); 00308 template<class T> Bool allAND (const T &val, const MaskedArray<T> &array); 00309 template<class T> Bool allOR (const MaskedArray<T> &array, const T &val); 00310 template<class T> Bool allOR (const T &val, const MaskedArray<T> &array); 00311 // </group> 00312 // 00313 // </group> 00314 00315 00316 // 00317 // Element by element comparisons between an array and a scalar, which 00318 // behaves as if it were a conformant array filled with the value "val." 00319 // The result is an MaskedLogicalArray. 00320 // <group> 00321 // 00322 template<class T> 00323 MaskedLogicalArray operator <= (const MaskedArray<T> &array, const T &val); 00324 template<class T> 00325 MaskedLogicalArray operator <= (const T &val, const MaskedArray<T> &array); 00326 template<class T> 00327 MaskedLogicalArray operator < (const MaskedArray<T> &array, const T &val); 00328 template<class T> 00329 MaskedLogicalArray operator < (const T &val, const MaskedArray<T> &array); 00330 template<class T> 00331 MaskedLogicalArray operator >= (const MaskedArray<T> &array, const T &val); 00332 template<class T> 00333 MaskedLogicalArray operator >= (const T &val, const MaskedArray<T> &array); 00334 template<class T> 00335 MaskedLogicalArray operator > (const MaskedArray<T> &array, const T &val); 00336 template<class T> 00337 MaskedLogicalArray operator > (const T &val, const MaskedArray<T> &array); 00338 template<class T> 00339 MaskedLogicalArray operator == (const MaskedArray<T> &array, const T &val); 00340 template<class T> 00341 MaskedLogicalArray operator == (const T &val, const MaskedArray<T> &array); 00342 template<class T> 00343 MaskedLogicalArray operator != (const MaskedArray<T> &array, const T &val); 00344 template<class T> 00345 MaskedLogicalArray operator != (const T &val, const MaskedArray<T> &array); 00346 // 00347 // This only makes sense if the array element type is logical valued. 00348 // <group> 00349 template<class T> 00350 MaskedLogicalArray operator && (const MaskedArray<T> &array, const T &val); 00351 template<class T> 00352 MaskedLogicalArray operator && (const T &val, const MaskedArray<T> &array); 00353 template<class T> 00354 MaskedLogicalArray operator || (const MaskedArray<T> &array, const T &val); 00355 template<class T> 00356 MaskedLogicalArray operator || (const T &val, const MaskedArray<T> &array); 00357 // </group> 00358 // 00359 // </group> 00360 00361 00362 //# With two arrays, they must both conform, and the result is done element 00363 //# by element. For instance anyLE (a, b) imples that some element of a is 00364 //# less than or equal to every element of b. 00365 //# NB comparison between two zero-sized arrays is not defined (should it 00366 //# throw an exception?). 00367 00368 // 00369 // Element by element comparisons between the "l" and "r" arrays. The result 00370 // is true only if the comparison is true for some element of the arrays 00371 // for which the mask of the MaskedArray is True. For two MaskedArrays, 00372 // the "and" of the masks is used. 00373 // 00374 // <thrown> 00375 // <li> ArrayConformanceError 00376 // <li> ArrayError 00377 // </thrown> 00378 // 00379 // <group> 00380 // 00381 template<class T> Bool anyLE (const MaskedArray<T> &l, const Array<T> &r); 00382 template<class T> Bool anyLT (const MaskedArray<T> &l, const Array<T> &r); 00383 template<class T> Bool anyGE (const MaskedArray<T> &l, const Array<T> &r); 00384 template<class T> Bool anyGT (const MaskedArray<T> &l, const Array<T> &r); 00385 template<class T> Bool anyEQ (const MaskedArray<T> &l, const Array<T> &r); 00386 template<class T> Bool anyNE (const MaskedArray<T> &l, const Array<T> &r); 00387 // 00388 // This only makes sense if the array element type is logical valued. 00389 // <group> 00390 template<class T> Bool anyAND (const MaskedArray<T> &l, const Array<T> &r); 00391 template<class T> Bool anyOR (const MaskedArray<T> &l, const Array<T> &r); 00392 // </group> 00393 00394 00395 template<class T> Bool anyLE (const Array<T> &l, const MaskedArray<T> &r); 00396 template<class T> Bool anyLT (const Array<T> &l, const MaskedArray<T> &r); 00397 template<class T> Bool anyGE (const Array<T> &l, const MaskedArray<T> &r); 00398 template<class T> Bool anyGT (const Array<T> &l, const MaskedArray<T> &r); 00399 template<class T> Bool anyEQ (const Array<T> &l, const MaskedArray<T> &r); 00400 template<class T> Bool anyNE (const Array<T> &l, const MaskedArray<T> &r); 00401 // 00402 // This only makes sense if the array element type is logical valued. 00403 // <group> 00404 template<class T> Bool anyAND (const Array<T> &l, const MaskedArray<T> &r); 00405 template<class T> Bool anyOR (const Array<T> &l, const MaskedArray<T> &r); 00406 // </group> 00407 00408 00409 template<class T> 00410 Bool anyLE (const MaskedArray<T> &l, const MaskedArray<T> &r); 00411 template<class T> 00412 Bool anyLT (const MaskedArray<T> &l, const MaskedArray<T> &r); 00413 template<class T> 00414 Bool anyGE (const MaskedArray<T> &l, const MaskedArray<T> &r); 00415 template<class T> 00416 Bool anyGT (const MaskedArray<T> &l, const MaskedArray<T> &r); 00417 template<class T> 00418 Bool anyEQ (const MaskedArray<T> &l, const MaskedArray<T> &r); 00419 template<class T> 00420 Bool anyNE (const MaskedArray<T> &l, const MaskedArray<T> &r); 00421 // 00422 // This only makes sense if the array element type is logical valued. 00423 // <group> 00424 template<class T> 00425 Bool anyAND (const MaskedArray<T> &l, const MaskedArray<T> &r); 00426 template<class T> 00427 Bool anyOR (const MaskedArray<T> &l, const MaskedArray<T> &r); 00428 // </group> 00429 00430 // </group> 00431 00432 00433 // 00434 // Element by element comparisons between an array and a scalar, which 00435 // behaves as if it were a conformant array filled with the value "val." 00436 // The result is true only if the comparison is true for some element 00437 // for which the mask of the MaskedArray is True. 00438 // 00439 // <thrown> 00440 // <li> ArrayError 00441 // </thrown> 00442 // 00443 // <group> 00444 // 00445 template<class T> Bool anyLE (const MaskedArray<T> &array, const T &val); 00446 template<class T> Bool anyLE (const T &val, const MaskedArray<T> &array); 00447 template<class T> Bool anyLT (const MaskedArray<T> &array, const T &val); 00448 template<class T> Bool anyLT (const T &val, const MaskedArray<T> &array); 00449 template<class T> Bool anyGE (const MaskedArray<T> &array, const T &val); 00450 template<class T> Bool anyGE (const T &val, const MaskedArray<T> &array); 00451 template<class T> Bool anyGT (const MaskedArray<T> &array, const T &val); 00452 template<class T> Bool anyGT (const T &val, const MaskedArray<T> &array); 00453 template<class T> Bool anyEQ (const MaskedArray<T> &array, const T &val); 00454 template<class T> Bool anyEQ (const T &val, const MaskedArray<T> &array); 00455 template<class T> Bool anyNE (const MaskedArray<T> &array, const T &val); 00456 template<class T> Bool anyNE (const T &val, const MaskedArray<T> &array); 00457 // 00458 // This only makes sense if the array element type is logical valued. 00459 // <group> 00460 template<class T> Bool anyAND (const MaskedArray<T> &array, const T &val); 00461 template<class T> Bool anyAND (const T &val, const MaskedArray<T> &array); 00462 template<class T> Bool anyOR (const MaskedArray<T> &array, const T &val); 00463 template<class T> Bool anyOR (const T &val, const MaskedArray<T> &array); 00464 // </group> 00465 // 00466 // </group> 00467 00468 // </group> 00469 00470 00471 } //# NAMESPACE CASA - END 00472 00473 #ifndef CASACORE_NO_AUTO_TEMPLATES 00474 #include <casa/Arrays/MaskArrLogi.tcc> 00475 #endif //# CASACORE_NO_AUTO_TEMPLATES 00476 #endif