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