casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MaskArrLogi.h
Go to the documentation of this file.
1 //# MaskArrLogi.h: Element by element logical operations on masked arrays.
2 //# Copyright (C) 1993,1994,1995,1999,2001
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 CASA_MASKARRLOGI_H
29 #define CASA_MASKARRLOGI_H
30 
31 
32 #include <casacore/casa/aips.h>
36 
37 namespace casacore { //# NAMESPACE CASACORE - BEGIN
38 
39 // <summary>
40 // Logical operations for MaskedArrays, and between MaskedArrays and Arrays.
41 // </summary>
42 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tMaskArrLogi tMaskArrExcp">
43 //
44 // <prerequisite>
45 // <li> <linkto class=Array>Array</linkto>
46 // <li> <linkto group="LogiArray.h#LogicalArray">LogicalArray</linkto>
47 // <li> <linkto class=MaskedArray>MaskedArray</linkto>
48 // </prerequisite>
49 //
50 // <etymology>
51 // MaskArrLogi is short for MaskedArrayLogical, which is too long by the
52 // old AIPS++ file naming conventions. This file contains global functions
53 // which perform element by element logical operations on masked arrays.
54 // </etymology>
55 //
56 // <synopsis>
57 // These functions perform element by element logical operations on
58 // masked arrays. With two arrays, they must both conform, and the result
59 // is done element by element, for those locations where the mask of the
60 // MaskedArray is True. For two MaskedArrays, the "and" of the masks is used.
61 //
62 // There are two classes of functions. One class returns a MaskedLogicalArray.
63 // In these functions, the value of an element of the MaskedLogicalArray is
64 // the value of the logical operation applied to the corresponding elements
65 // of the input MaskedArrays. The other class of functions returns a single
66 // Bool. The return value is True if the logical operation returns True for
67 // all elements of the input masked arrays for the "all" functions
68 // (e.g. allLE()), and returns True if the logical operation returns True for
69 // any elements of the input masked arrays for the "any" functions
70 // (e.g. anyLE()). The functions which return a single Bool throw an exception
71 // if the AND of the masks of the input masked arrays has no True elements.
72 //
73 // For instance allLE (a, b) imples that every element of a is
74 // less than or equal to every element of b. Note that with this definition
75 // allLE (a, b) and allGE (a, b) can both be false (e.g. a = [1,0] b = [0,1]).
76 //
77 // NB comparison between two zero-sized arrays is not defined (should it
78 // throw an exception?).
79 // </synopsis>
80 //
81 // <example>
82 // <srcblock>
83 // Vector<Int> a(10);
84 // Vector<Int> b(10);
85 // LogicalVector l(10);
86 // . . .
87 // l = a(a>0) < b(b>0);
88 // </srcblock>
89 // This example sets those elements of l where ((a>0) && (b>0)) to (a<b).
90 // Elements of l where !((a>0) && (b>0)) are unchanged. The result of
91 // the comparison is a MaskedLogicalArray. The assignment from this
92 // MaskedLogicalArray to the LogicalArray l only assigns those elements
93 // where the mask is True.
94 // </example>
95 //
96 // <example>
97 // <srcblock>
98 // Vector<Int> a(10);
99 // Vector<Int> b(10);
100 // Bool result;
101 // . . .
102 // result = allLT (a(a>0), b(b>0));
103 // </srcblock>
104 // This example sets result to True if, for all elements where
105 // ((a>0) && (b>0)), a<b.
106 // </example>
107 //
108 // <motivation>
109 // One wants to be able to mask arrays and perform logical operations on
110 // those masked arrays. Since the masked arrays are only defined where
111 // the masks are True, the result must be a MaskedLogicalArray, or a single
112 // Bool.
113 // </motivation>
114 //
115 // <todo asof="$DATE:$>
116 // <li> Reconsider where the origin of the returned LogicalArray should
117 // be located.
118 // </todo>
119 //
120 // <linkfrom anchor="MaskedArray logical operations" classes="MaskedArray Array Vector Matrix Cube">
121 // <here>MaskedArray logical operations</here> -- Logical operations
122 // for MaskedArrays, and between MaskedArrays and Arrays.
123 // </linkfrom>
124 //
125 // <group name="MaskedArray logical operations">
127 
128 //
129 // Element by element comparisons between the "l" and "r" arrays. The result
130 // is true only if the comparison is true for every element of the arrays
131 // for which the mask of the MaskedArray is True. For two MaskedArrays,
132 // the "and" of the masks is used.
133 //
134 // <thrown>
135 // <li> ArrayConformanceError
136 // <li> ArrayError
137 // </thrown>
138 //
139 // <group>
140 template<class T> Bool allLE (const MaskedArray<T> &l, const Array<T> &r);
141 template<class T> Bool allLT (const MaskedArray<T> &l, const Array<T> &r);
142 template<class T> Bool allGE (const MaskedArray<T> &l, const Array<T> &r);
143 template<class T> Bool allGT (const MaskedArray<T> &l, const Array<T> &r);
144 template<class T> Bool allEQ (const MaskedArray<T> &l, const Array<T> &r);
145 template<class T> Bool allNE (const MaskedArray<T> &l, const Array<T> &r);
146 //
147 // This only makes sense if the array element type is logical valued.
148 // <group>
149 template<class T> Bool allAND (const MaskedArray<T> &l, const Array<T> &r);
150 template<class T> Bool allOR (const MaskedArray<T> &l, const Array<T> &r);
151 // </group>
152 
153 template<class T> Bool allLE (const Array<T> &l, const MaskedArray<T> &r);
154 template<class T> Bool allLT (const Array<T> &l, const MaskedArray<T> &r);
155 template<class T> Bool allGE (const Array<T> &l, const MaskedArray<T> &r);
156 template<class T> Bool allGT (const Array<T> &l, const MaskedArray<T> &r);
157 template<class T> Bool allEQ (const Array<T> &l, const MaskedArray<T> &r);
158 template<class T> Bool allNE (const Array<T> &l, const MaskedArray<T> &r);
159 //
160 // This only makes sense if the array element type is logical valued.
161 // <group>
162 template<class T> Bool allAND (const Array<T> &l, const MaskedArray<T> &r);
163 template<class T> Bool allOR (const Array<T> &l, const MaskedArray<T> &r);
164 // </group>
165 
166 template<class T>
167  Bool allLE (const MaskedArray<T> &l, const MaskedArray<T> &r);
168 template<class T>
169  Bool allLT (const MaskedArray<T> &l, const MaskedArray<T> &r);
170 template<class T>
171  Bool allGE (const MaskedArray<T> &l, const MaskedArray<T> &r);
172 template<class T>
173  Bool allGT (const MaskedArray<T> &l, const MaskedArray<T> &r);
174 template<class T>
175  Bool allEQ (const MaskedArray<T> &l, const MaskedArray<T> &r);
176 template<class T>
177  Bool allNE (const MaskedArray<T> &l, const MaskedArray<T> &r);
178 //
179 // This only makes sense if the array element type is logical valued.
180 // <group>
181 template<class T>
182  Bool allAND (const MaskedArray<T> &l, const MaskedArray<T> &r);
183 template<class T>
184  Bool allOR (const MaskedArray<T> &l, const MaskedArray<T> &r);
185 // </group>
186 
187 // </group>
188 
189 
190 //
191 // Element by element comparisons between the "l" and "r" arrays. The result
192 // is a MaskedLogicalArray.
193 //
194 // The arrays must conform or an exception is thrown.
195 //
196 // <thrown>
197 // <li> ArrayConformanceError
198 // </thrown>
199 //
200 // <group>
201 template<class T>
202  MaskedLogicalArray operator <= (const MaskedArray<T> &l, const Array<T> &r);
203 template<class T>
204  MaskedLogicalArray operator < (const MaskedArray<T> &l, const Array<T> &r);
205 template<class T>
206  MaskedLogicalArray operator >= (const MaskedArray<T> &l, const Array<T> &r);
207 template<class T>
208  MaskedLogicalArray operator > (const MaskedArray<T> &l, const Array<T> &r);
209 template<class T>
210  MaskedLogicalArray operator == (const MaskedArray<T> &l, const Array<T> &r);
211 template<class T>
212  MaskedLogicalArray operator != (const MaskedArray<T> &l, const Array<T> &r);
213 //
214 // This only makes sense if the array element type is logical valued.
215 // <group>
216 template<class T>
217  MaskedLogicalArray operator && (const MaskedArray<T> &l, const Array<T> &r);
218 template<class T>
219  MaskedLogicalArray operator || (const MaskedArray<T> &l, const Array<T> &r);
220 // </group>
221 
222 template<class T>
223  MaskedLogicalArray operator <= (const Array<T> &l, const MaskedArray<T> &r);
224 template<class T>
225  MaskedLogicalArray operator < (const Array<T> &l, const MaskedArray<T> &r);
226 template<class T>
227  MaskedLogicalArray operator >= (const Array<T> &l, const MaskedArray<T> &r);
228 template<class T>
229  MaskedLogicalArray operator > (const Array<T> &l, const MaskedArray<T> &r);
230 template<class T>
231  MaskedLogicalArray operator == (const Array<T> &l, const MaskedArray<T> &r);
232 template<class T>
233  MaskedLogicalArray operator != (const Array<T> &l, const MaskedArray<T> &r);
234 //
235 // This only makes sense if the array element type is logical valued.
236 // <group>
237 template<class T>
238  MaskedLogicalArray operator && (const Array<T> &l, const MaskedArray<T> &r);
239 template<class T>
240  MaskedLogicalArray operator || (const Array<T> &l, const MaskedArray<T> &r);
241 // </group>
242 
243 template<class T>
244  MaskedLogicalArray operator <= (const MaskedArray<T> &l,
245  const MaskedArray<T> &r);
246 template<class T>
247  MaskedLogicalArray operator < (const MaskedArray<T> &l,
248  const MaskedArray<T> &r);
249 template<class T>
250  MaskedLogicalArray operator >= (const MaskedArray<T> &l,
251  const MaskedArray<T> &r);
252 template<class T>
253  MaskedLogicalArray operator > (const MaskedArray<T> &l,
254  const MaskedArray<T> &r);
255 template<class T>
256  MaskedLogicalArray operator == (const MaskedArray<T> &l,
257  const MaskedArray<T> &r);
258 template<class T>
259  MaskedLogicalArray operator != (const MaskedArray<T> &l,
260  const MaskedArray<T> &r);
261 //
262 // This only makes sense if the array element type is logical valued.
263 // <group>
264 template<class T>
265  MaskedLogicalArray operator && (const MaskedArray<T> &l,
266  const MaskedArray<T> &r);
267 template<class T>
268  MaskedLogicalArray operator || (const MaskedArray<T> &l,
269  const MaskedArray<T> &r);
270 // </group>
271 
272 // </group>
273 
274 
275 //
276 // Logical negation of a MaskedArray. This only makes sense if the array
277 // element type is logical valued.
278 template<class T>
279 MaskedLogicalArray operator ! (const MaskedArray<T> &marray);
280 
281 
282 //
283 // Element by element comparisons between an array and a scalar, which
284 // behaves as if it were a conformant array filled with the value "val."
285 // The result is true only if the comparison is true for every element
286 // for which the mask of the MaskedArray is True.
287 // <thrown>
288 // <li> ArrayError
289 // </thrown>
290 //
291 // <group>
292 template<class T> Bool allLE (const MaskedArray<T> &array, const T &val);
293 template<class T> Bool allLE (const T &val, const MaskedArray<T> &array);
294 template<class T> Bool allLT (const MaskedArray<T> &array, const T &val);
295 template<class T> Bool allLT (const T &val, const MaskedArray<T> &array);
296 template<class T> Bool allGE (const MaskedArray<T> &array, const T &val);
297 template<class T> Bool allGE (const T &val, const MaskedArray<T> &array);
298 template<class T> Bool allGT (const MaskedArray<T> &array, const T &val);
299 template<class T> Bool allGT (const T &val, const MaskedArray<T> &array);
300 template<class T> Bool allEQ (const MaskedArray<T> &array, const T &val);
301 template<class T> Bool allEQ (const T &val, const MaskedArray<T> &array);
302 template<class T> Bool allNE (const MaskedArray<T> &array, const T &val);
303 template<class T> Bool allNE (const T &val, const MaskedArray<T> &array);
304 //
305 // This only makes sense if the array element type is logical valued.
306 // <group>
307 template<class T> Bool allAND (const MaskedArray<T> &array, const T &val);
308 template<class T> Bool allAND (const T &val, const MaskedArray<T> &array);
309 template<class T> Bool allOR (const MaskedArray<T> &array, const T &val);
310 template<class T> Bool allOR (const T &val, const MaskedArray<T> &array);
311 // </group>
312 //
313 // </group>
314 
315 
316 //
317 // Element by element comparisons between an array and a scalar, which
318 // behaves as if it were a conformant array filled with the value "val."
319 // The result is an MaskedLogicalArray.
320 // <group>
321 //
322 template<class T>
323  MaskedLogicalArray operator <= (const MaskedArray<T> &array, const T &val);
324 template<class T>
325  MaskedLogicalArray operator <= (const T &val, const MaskedArray<T> &array);
326 template<class T>
327  MaskedLogicalArray operator < (const MaskedArray<T> &array, const T &val);
328 template<class T>
329  MaskedLogicalArray operator < (const T &val, const MaskedArray<T> &array);
330 template<class T>
331  MaskedLogicalArray operator >= (const MaskedArray<T> &array, const T &val);
332 template<class T>
333  MaskedLogicalArray operator >= (const T &val, const MaskedArray<T> &array);
334 template<class T>
335  MaskedLogicalArray operator > (const MaskedArray<T> &array, const T &val);
336 template<class T>
337  MaskedLogicalArray operator > (const T &val, const MaskedArray<T> &array);
338 template<class T>
339  MaskedLogicalArray operator == (const MaskedArray<T> &array, const T &val);
340 template<class T>
341  MaskedLogicalArray operator == (const T &val, const MaskedArray<T> &array);
342 template<class T>
343  MaskedLogicalArray operator != (const MaskedArray<T> &array, const T &val);
344 template<class T>
345  MaskedLogicalArray operator != (const T &val, const MaskedArray<T> &array);
346 //
347 // This only makes sense if the array element type is logical valued.
348 // <group>
349 template<class T>
350  MaskedLogicalArray operator && (const MaskedArray<T> &array, const T &val);
351 template<class T>
352  MaskedLogicalArray operator && (const T &val, const MaskedArray<T> &array);
353 template<class T>
354  MaskedLogicalArray operator || (const MaskedArray<T> &array, const T &val);
355 template<class T>
356  MaskedLogicalArray operator || (const T &val, const MaskedArray<T> &array);
357 // </group>
358 //
359 // </group>
360 
361 
362 //# With two arrays, they must both conform, and the result is done element
363 //# by element. For instance anyLE (a, b) imples that some element of a is
364 //# less than or equal to every element of b.
365 //# NB comparison between two zero-sized arrays is not defined (should it
366 //# throw an exception?).
367 
368 //
369 // Element by element comparisons between the "l" and "r" arrays. The result
370 // is true only if the comparison is true for some element of the arrays
371 // for which the mask of the MaskedArray is True. For two MaskedArrays,
372 // the "and" of the masks is used.
373 //
374 // <thrown>
375 // <li> ArrayConformanceError
376 // <li> ArrayError
377 // </thrown>
378 //
379 // <group>
380 //
381 template<class T> Bool anyLE (const MaskedArray<T> &l, const Array<T> &r);
382 template<class T> Bool anyLT (const MaskedArray<T> &l, const Array<T> &r);
383 template<class T> Bool anyGE (const MaskedArray<T> &l, const Array<T> &r);
384 template<class T> Bool anyGT (const MaskedArray<T> &l, const Array<T> &r);
385 template<class T> Bool anyEQ (const MaskedArray<T> &l, const Array<T> &r);
386 template<class T> Bool anyNE (const MaskedArray<T> &l, const Array<T> &r);
387 //
388 // This only makes sense if the array element type is logical valued.
389 // <group>
390 template<class T> Bool anyAND (const MaskedArray<T> &l, const Array<T> &r);
391 template<class T> Bool anyOR (const MaskedArray<T> &l, const Array<T> &r);
392 // </group>
393 
394 
395 template<class T> Bool anyLE (const Array<T> &l, const MaskedArray<T> &r);
396 template<class T> Bool anyLT (const Array<T> &l, const MaskedArray<T> &r);
397 template<class T> Bool anyGE (const Array<T> &l, const MaskedArray<T> &r);
398 template<class T> Bool anyGT (const Array<T> &l, const MaskedArray<T> &r);
399 template<class T> Bool anyEQ (const Array<T> &l, const MaskedArray<T> &r);
400 template<class T> Bool anyNE (const Array<T> &l, const MaskedArray<T> &r);
401 //
402 // This only makes sense if the array element type is logical valued.
403 // <group>
404 template<class T> Bool anyAND (const Array<T> &l, const MaskedArray<T> &r);
405 template<class T> Bool anyOR (const Array<T> &l, const MaskedArray<T> &r);
406 // </group>
407 
408 
409 template<class T>
410  Bool anyLE (const MaskedArray<T> &l, const MaskedArray<T> &r);
411 template<class T>
412  Bool anyLT (const MaskedArray<T> &l, const MaskedArray<T> &r);
413 template<class T>
414  Bool anyGE (const MaskedArray<T> &l, const MaskedArray<T> &r);
415 template<class T>
416  Bool anyGT (const MaskedArray<T> &l, const MaskedArray<T> &r);
417 template<class T>
418  Bool anyEQ (const MaskedArray<T> &l, const MaskedArray<T> &r);
419 template<class T>
420  Bool anyNE (const MaskedArray<T> &l, const MaskedArray<T> &r);
421 //
422 // This only makes sense if the array element type is logical valued.
423 // <group>
424 template<class T>
425  Bool anyAND (const MaskedArray<T> &l, const MaskedArray<T> &r);
426 template<class T>
427  Bool anyOR (const MaskedArray<T> &l, const MaskedArray<T> &r);
428 // </group>
429 
430 // </group>
431 
432 
433 //
434 // Element by element comparisons between an array and a scalar, which
435 // behaves as if it were a conformant array filled with the value "val."
436 // The result is true only if the comparison is true for some element
437 // for which the mask of the MaskedArray is True.
438 //
439 // <thrown>
440 // <li> ArrayError
441 // </thrown>
442 //
443 // <group>
444 //
445 template<class T> Bool anyLE (const MaskedArray<T> &array, const T &val);
446 template<class T> Bool anyLE (const T &val, const MaskedArray<T> &array);
447 template<class T> Bool anyLT (const MaskedArray<T> &array, const T &val);
448 template<class T> Bool anyLT (const T &val, const MaskedArray<T> &array);
449 template<class T> Bool anyGE (const MaskedArray<T> &array, const T &val);
450 template<class T> Bool anyGE (const T &val, const MaskedArray<T> &array);
451 template<class T> Bool anyGT (const MaskedArray<T> &array, const T &val);
452 template<class T> Bool anyGT (const T &val, const MaskedArray<T> &array);
453 template<class T> Bool anyEQ (const MaskedArray<T> &array, const T &val);
454 template<class T> Bool anyEQ (const T &val, const MaskedArray<T> &array);
455 template<class T> Bool anyNE (const MaskedArray<T> &array, const T &val);
456 template<class T> Bool anyNE (const T &val, const MaskedArray<T> &array);
457 //
458 // This only makes sense if the array element type is logical valued.
459 // <group>
460 template<class T> Bool anyAND (const MaskedArray<T> &array, const T &val);
461 template<class T> Bool anyAND (const T &val, const MaskedArray<T> &array);
462 template<class T> Bool anyOR (const MaskedArray<T> &array, const T &val);
463 template<class T> Bool anyOR (const T &val, const MaskedArray<T> &array);
464 // </group>
465 //
466 // </group>
467 
468 // </group>
469 
470 
471 } //# NAMESPACE CASACORE - END
472 
473 #ifndef CASACORE_NO_AUTO_TEMPLATES
474 #include <casacore/casa/Arrays/MaskArrLogi.tcc>
475 #endif //# CASACORE_NO_AUTO_TEMPLATES
476 #endif
Bool anyLT(const TableVector< T > &l, const TableVector< T > &r)
Definition: TabVecLogic.h:153
TableExprNode array(const TableExprNode &values, const TableExprNodeSet &shape)
Create an array of the given shape and fill it with the values.
Definition: ExprNode.h:1886
LatticeExprNode operator!=(const LatticeExprNode &left, const LatticeExprNode &right)
TableExprNode marray(const TableExprNode &array, const TableExprNode &mask)
Form a masked array.
Definition: ExprNode.h:1892
LatticeExprNode operator>=(const LatticeExprNode &left, const LatticeExprNode &right)
Bool anyNE(const TableVector< T > &l, const TableVector< T > &r)
Definition: TabVecLogic.h:173
Class for masking an Array for operations on that Array.
LatticeExprNode operator!(const LatticeExprNode &expr)
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Bool anyGE(const TableVector< T > &l, const TableVector< T > &r)
Definition: TabVecLogic.h:158
Bool anyGT(const TableVector< T > &l, const TableVector< T > &r)
Definition: TabVecLogic.h:163
template &lt;class T, class U&gt; class vector;
Definition: MSFlagger.h:37
LatticeExprNode operator>(const LatticeExprNode &left, const LatticeExprNode &right)
Bool anyEQ(const TableVector< T > &l, const TableVector< T > &r)
Definition: TabVecLogic.h:168
Bool operator==(const MVTime &lh, const MVTime &rh)
is equal operator, uses operator Double which returns days
Definition: MVTime.h:465
Bool anyLE(const TableVector< T > &l, const TableVector< T > &r)
Element by element comparisons between the &quot;l&quot; and &quot;r&quot; table vectors.
Definition: TabVecLogic.h:148
LatticeExprNode operator||(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode operator&&(const LatticeExprNode &left, const LatticeExprNode &right)
Logical binary operators.
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42