casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MaskedArray.h
Go to the documentation of this file.
1 //# MaskedArray.h: A templated N-D masked array class with zero origin.
2 //# Copyright (C) 1993,1994,1995,1996,1997,1999,2000,2005
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_MASKEDARRAY_H
29 #define CASA_MASKEDARRAY_H
30 
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
38 
39 namespace casacore { //# NAMESPACE CASACORE - BEGIN
40 
41 //# Forward declarations
42 //# <note role=warning>
43 //# Array.h cannot be included in this header file. Anything needed
44 //# from it must be forwarded. This is why LogicalArrayFwd.h is
45 //# included instead of LogicalArray.h .
46 //# </note>
47 template <class T> class Array;
48 class Slicer;
49 
50 
51 // <summary> Class for masking an Array for operations on that Array. </summary>
52 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tMaskedArray tMaskArrExcp">
53 // </reviewed>
54 //
55 // <prerequisite>
56 // <li> <linkto class=Array>Array</linkto>
57 // <li> <linkto group="LogiArray.h#LogicalArray">LogicalArray</linkto>
58 // </prerequisite>
59 //
60 // <etymology>
61 // MaskedArray is a class for masking elements of an Array while performing
62 // operations on that Array.
63 // </etymology>
64 //
65 // <synopsis>
66 // A MaskedArray is an association between an Array and a mask. The mask
67 // selects elements of the Array. Only elements of the Array where the
68 // corresponding element of the mask is True are defined. Thus, operations
69 // on a MaskedArray only operate on those elements of the Array where the
70 // corresponding element of the mask is True.
71 //
72 // A MaskedArray should be thought of as a manipulator for an Array, analogous
73 // to an iterator. It allows one to perform whole Array operations on selected
74 // elements of the Array.
75 //
76 // The mask used in the constructor for the MaskedArray must conform to
77 // the Array, thus have the same shape.
78 // The internal mask is (will be) copy constructed with reference semantics
79 // from the input mask. Therefore, it is (will be) possible to change the
80 // internal mask by changing values in the input mask *after* the MaskedArray
81 // has been constructed. To ensure that the internal mask is independent of
82 // the input mask after construction, use mask.copy() as the input argument.
83 //
84 // One can explicitly construct a MaskedArray from an Array and a mask or
85 // a MaskedArray and a mask. One can also use operator() on an Array or
86 // a MaskedArray to implicitly create a MaskedArray.
87 //
88 // One can create a MaskedArray from a MaskedArray and a mask. The resulting
89 // MaskedArray has as its Array the Array from the original MaskedArray.
90 // The mask for the resulting MaskedArray is the AND of the mask from the
91 // original MaskedArray and the input mask.
92 //
93 // Any operation involving a MaskedArray or a set of MaskedArrays is only
94 // performed for those elements where the AND of the masks is True.
95 //
96 // Any operation involving a MaskedArray or a set of MaskedArrays results
97 // in a MaskedArray whose mask is the AND of the masks of the original
98 // MaskedArrays. The only exception to this is assignment, where the
99 // mask determines which elements of the underlying Array are assigned.
100 //
101 // Masks, which are LogicalArrays, can be constructed by logical operations
102 // involving Arrays. They can also, of course, be constructed by individually
103 // setting individual elements of an LogicalArray.
104 //
105 // MaskedArrays constructed directly from Arrays are by default writeable.
106 // MaskedArrays constructed indirectly from Arrays by <src>operator()</src>
107 // are writeable if the Array is non-const and are readonly if the
108 // Array is const.
109 // MaskedArrays constructed from other MaskedArrays, either directly by
110 // constructors or indirectly by <src>operator()</src>, are by default
111 // writeable if the input MaskedArray is writeable, and readonly if the
112 // input MaskedArray is readonly.
113 //
114 // A given MaskedArray can be set to be readonly. One specifies
115 // this in the constructor with the Bool argument <src>isreadonly</src>,
116 // or calls the <src>setReadOnly()</src> member function.
117 // A MaskedArray which would default to be readonly cannot be forced to
118 // be writeable. It will remain readonly even if the Bool argument
119 // <src>isreadonly</src> is set to be <src>False</src>.
120 //
121 // The <src>isReadOnly(),</src> member function is used to test whether
122 // the MaskedArray is readonly.
123 //
124 // Member functions which change the MaskedArray test to see whether
125 // the MaskedArray is readonly, and throw an ArrayError exception if
126 // it is. These member functions are:
127 // <ul>
128 // <li> <src>operator=()</src>
129 // <li> <src>getRWArray()</src>
130 // <li> <src>getRWArrayStorage()</src>
131 // <li> <src>putArrayStorage()</src>
132 // </ul>
133 //
134 // The copy() member function makes a deep copy of a MaskedArray.
135 // By default it returns a writeable MaskedArray, but the MaskedArray
136 // returned can be made readonly by using the Bool argument "isreadonly"
137 // to copy() (or by calling setReadOnly() on the new MaskedArray).
138 //
139 // The valid elements of the MaskedArray can be manipulated as a
140 // "compressed" Array which contains only the valid elements.
141 // The number of elements in this "compressed" Array is the number of valid
142 // elements in the MaskedArray, <src>nelementsValid()</src>.
143 // The "compressed" Array can have any shape which meets this requirement.
144 // The MaskedArray can have any shape.
145 //
146 // The <src>getCompressedArray()</src> member functions get a compressed
147 // Array from the valid members of the MaskedArray, while the
148 // <src>setCompressedArray()</src> member function sets the valid members
149 // of the MaskedArray from the input compressed Array.
150 //
151 // Many mathematical and logical global operators and functions which operate
152 // on MaskedArrays are defined. Typically, they are defined for all sensible
153 // combinations of MaskedArrays, Arrays, and scalars.
154 //
155 // Mathematical global operators and functions are defined in
156 // Arrays/MaskArrMath.h .
157 // The list is:
158 // <ul>
159 // <li> operator+= ()
160 // <li> operator-= ()
161 // <li> operator*= ()
162 // <li> operator/= ()
163 // <li> operator+ ()
164 // <li> operator- ()
165 // <li> operator* ()
166 // <li> operator/ ()
167 // <li> sin ()
168 // <li> cos ()
169 // <li> tan ()
170 // <li> asin ()
171 // <li> acos ()
172 // <li> atan ()
173 // <li> sinh ()
174 // <li> cosh ()
175 // <li> tanh ()
176 // <li> exp ()
177 // <li> log ()
178 // <li> log10 ()
179 // <li> sqrt ()
180 // <li> abs ()
181 // <li> fabs ()
182 // <li> ceil ()
183 // <li> floor ()
184 // <li> atan2 ()
185 // <li> fmod ()
186 // <li> pow ()
187 // <li> minMax ()
188 // <li> min ()
189 // <li> max ()
190 // <li> indgen ()
191 // <li> sum ()
192 // <li> sumsquares ()
193 // <li> product ()
194 // <li> mean ()
195 // <li> variance ()
196 // <li> stddev ()
197 // <li> avdev ()
198 // <li> median ()
199 // <li> square ()
200 // <li> cube ()
201 // </ul>
202 //
203 // Logical global operators and functions are defined in
204 // Arrays/MaskArrLogi.h .
205 // The list is:
206 // <ul>
207 // <li> allLE ()
208 // <li> allLT ()
209 // <li> allGE ()
210 // <li> allGT ()
211 // <li> allEQ ()
212 // <li> allNE ()
213 // <li> allAND ()
214 // <li> allOR ()
215 // <li> anyLE ()
216 // <li> anyLT ()
217 // <li> anyGE ()
218 // <li> anyGT ()
219 // <li> anyEQ ()
220 // <li> anyNE ()
221 // <li> anyAND ()
222 // <li> anyOR ()
223 // <li> operator<= ()
224 // <li> operator< ()
225 // <li> operator>= ()
226 // <li> operator< ()
227 // <li> operator== ()
228 // <li> operator!= ()
229 // <li> operator&& ()
230 // <li> operator|| ()
231 // </ul>
232 // </synopsis>
233 //
234 // <example>
235 // Use an explicit MaskedArray to limit the maximum value of an Array.
236 //
237 // <srcblock>
238 // Vector<Int> arr (20);
239 // . . .
240 // MaskedArray<Int> marr (arr, (arr > 5));
241 // marr = 5;
242 // </srcblock>
243 //
244 // This sets all elements of arr which are greater than 5 to 5.
245 // </example>
246 //
247 // <example>
248 // Use an implicit MaskedArray to limit the minimum value of an Array.
249 //
250 // <srcblock>
251 // Vector<Int> arr (20);
252 // . . .
253 // arr (arr < 0) = 0;
254 // </srcblock>
255 //
256 // This sets all elements of arr which are less than 0 to 0.
257 // </example>
258 //
259 // <example>
260 // It does not matter where in an expression the MaskedArrays are located.
261 // The operation is only performed on those elements where the AND of the
262 // masks is True.
263 //
264 // The following expressions are all equivalent.
265 // The first (and second) expressions are the most efficient, since the sum
266 // is only performed for those elements where ((a > 0) && (b > 0)).
267 // The third example is less efficient, since the sum is performed for
268 // all elements of a and b, and then the assignment is only performed for
269 // those elements where ((a > 0) && (b > 0)).
270 //
271 // <srcblock>
272 // Vector<Int> arr (20);
273 // Vector<Int> a (20);
274 // Vector<Int> b (20);
275 // . . .
276 // arr = a(a > 0) + b(b > 0);
277 //
278 // arr = a(b > 0) + b(a > 0);
279 //
280 // arr ((a > 0) && (b > 0)) = a + b;
281 //
282 // arr = (a + b) ((a > 0) && (b > 0));
283 //
284 // arr (a > 0) = a + b(b > 0);
285 //
286 // </srcblock>
287 //
288 // All of these expressions set those elements of arr where
289 // ((a > 0) && (b > 0)) to a + b. Those elements of arr where the condition
290 // is False are unchanged.
291 // </example>
292 //
293 // <example>
294 // This example extracts the valid elements of the MaskedArray as a
295 // "compressed" Vector, manipulates this Vector, and then puts the result
296 // back into the MaskedArray.
297 //
298 // <srcblock>
299 // Matrix<Int> arr (20,5);
300 // . . .
301 // MaskedArray<Int> marr (arr, (arr>0) && (arr<10));
302 // Vector<Int> vec (marr.getCompressedArray());
303 // . . .
304 // marr.setCompressedArray (vec);
305 // </srcblock>
306 //
307 // </example>
308 //
309 // <motivation>
310 // A MaskedArray is an association between an Array and a LogicalArray which
311 // masks the Array. It allows one to perform whole Array manipulations
312 // with a single expression, selecting those elements of the Array to modify
313 // based either on a logical expression, typically involving some of the
314 // Arrays involved in the expression, or based on a specifically set mask.
315 // </motivation>
316 //
317 // <todo asof="$DATE:$>
318 // <li> Consider whether there should be constructors for masks
319 // specified as Array<Bool>.
320 // <li> Change constructors to always do copy construction with
321 // reference semantics when creating the internal mask.
322 // </todo>
323 
324 
325 template<class T> class MaskedArray
326 {
327 
328 public:
329  // Default constructor for a MaskedArray does not allocate any memory
330  // for the Data array or Mask. Hence the masked array
331  // should not be used until some data is allocated to the object using one
332  // of the set functions.
333  MaskedArray();
334  // Reset the data and mask of the the MaskedArray. There should perhaps be
335  // a whole family of setData functions with different arguements,
336  // analogous to the constructors. However these are sufficient for the
337  // moment.
338  void setData(const Array<T> & data, const LogicalArray & mask,
340  void setData(const MaskedArray<T> & array, Bool isReadOnly=False);
341  // Create a MaskedArray from an Array and a LogicalArray.
342  //
343  // The internal mask is a total copy of the input mask, and is
344  // completely independent of the input mask.
345  //
346  // The Array is copy constructed, which means that it is a really smart
347  // pointer to the underlying Block, and shares this Block with the input
348  // Array.
349  //
350  // By default, the MaskedArray constructed is writeable. If
351  // <src>isreadonly</src> is <src>True</src>, then the MaskedArray
352  // returned is readonly.
353  //
354  // <thrown>
355  // <li> ArrayConformanceError
356  // </thrown>
357  //
358  // <group>
359  MaskedArray(const Array<T> &inarray, const LogicalArray &inmask,
360  Bool isreadonly);
361  MaskedArray(const Array<T> &inarray, const LogicalArray &inmask);
362  // </group>
363 
364  // Create a MaskedArray from a MaskedArray and a LogicalArray.
365  //
366  // The internal mask is the AND of the input mask and the mask of
367  // the input MaskedArray.
368  //
369  // The Array from the input MaskedArray is copy constructed, which
370  // means that it is a really smart pointer to the underlying Block, and
371  // shares this Block with the Array from the input MaskedArray.
372  //
373  // By default, the MaskedArray constructed is writeable if the input
374  // MaskedArray is writeable, and readonly if the input MaskedArray
375  // is readonly. If <src>isreadonly</src> is <src>True</src>, then
376  // the MaskedArray returned is readonly. If <src>isreadonly</src> is
377  // <src>False</src> and the input MaskedArray is readonly, then the
378  // constructed MaskedArray is readonly.
379  //
380  // <thrown>
381  // <li> ArrayConformanceError
382  // </thrown>
383  //
384  // <group>
385  MaskedArray(const MaskedArray<T> &inarray, const LogicalArray &inmask,
386  Bool isreadonly);
387  MaskedArray(const MaskedArray<T> &inarray, const LogicalArray &inmask);
388  // </group>
389 
390  // Create a MaskedArray from an Array and a MaskedLogicalArray.
391  //
392  // The internal mask is the AND of the internal LogicalArray and the
393  // internal mask of the MaskedLogicalArray.
394  //
395  // The Array is copy constructed, which means that it is a really smart
396  // pointer to the underlying Block, and shares this Block with the input
397  // Array.
398  //
399  // By default, the MaskedArray constructed is writeable. If
400  // <src>isreadonly</src> is <src>True</src>, then the MaskedArray
401  // returned is readonly.
402  //
403  // <thrown>
404  // <li> ArrayConformanceError
405  // </thrown>
406  //
407  // <group>
408  MaskedArray(const Array<T> &inarray, const MaskedLogicalArray &inmask,
409  Bool isreadonly);
410  MaskedArray(const Array<T> &inarray, const MaskedLogicalArray &inmask);
411  // </group>
412 
413  // Create a MaskedArray from a MaskedArray and a MaskedLogicalArray.
414  //
415  // The internal mask is the AND of the internal LogicalArray and the
416  // internal mask of the MaskedLogicalArray, ANDed with the mask of
417  // the input MaskedArray.
418  //
419  // The Array from the input MaskedArray is copy constructed, which
420  // means that it is a really smart pointer to the underlying Block, and
421  // shares this Block with the Array from the input MaskedArray.
422  //
423  // By default, the MaskedArray constructed is writeable if the input
424  // MaskedArray is writeable, and readonly if the input MaskedArray
425  // is readonly. If <src>isreadonly</src> is <src>True</src>, then
426  // the MaskedArray returned is readonly. If <src>isreadonly</src> is
427  // <src>False</src> and the input MaskedArray is readonly, then the
428  // constructed MaskedArray is readonly.
429  //
430  // <thrown>
431  // <li> ArrayConformanceError
432  // </thrown>
433  //
434  // <group>
435  MaskedArray(const MaskedArray<T> &inarray,
436  const MaskedLogicalArray &inmask,
437  Bool isreadonly);
438  MaskedArray(const MaskedArray<T> &inarray,
439  const MaskedLogicalArray &inmask);
440  // </group>
441 
442  // Copy constructor.
443  //
444  // The internal mask is a total copy of the mask from the input
445  // MaskedArray, and is completely independent of this input mask.
446  //
447  // The Array from the input MaskedArray is copy constructed, which
448  // means that it is a really smart pointer to the underlying Block, and
449  // shares this Block with the Array from the input MaskedArray.
450  //
451  // By default, the MaskedArray constructed is writeable if the input
452  // MaskedArray is writeable, and readonly if the input MaskedArray
453  // is readonly. If <src>isreadonly</src> is <src>True</src>, then
454  // the MaskedArray returned is readonly. If <src>isreadonly</src> is
455  // <src>False</src> and the input MaskedArray is readonly, then the
456  // constructed MaskedArray is readonly.
457  //
458  // <group>
459  MaskedArray(const MaskedArray<T> &other, Bool isreadonly);
460  MaskedArray(const MaskedArray<T> &other);
461  // </group>
462 
463  ~MaskedArray();
464 
465  // Return a MaskedArray. The new MaskedArray is masked by the input
466  // LogicalArray "anded" with the mask of the original MaskedArray.
467  // This mask must conform to the array.
468  //
469  // The MaskedArray constructed is writeable if the input
470  // MaskedArray is writeable, and readonly if the input MaskedArray
471  // is readonly.
472  //
473  MaskedArray<T> operator() (const LogicalArray &mask) const;
474 
475  // Return a MaskedArray. The new MaskedArray is masked by the input
476  // MaskedLogicalArray "anded" with the mask of the original MaskedArray.
477  // This mask must conform to the array.
478  //
479  // The MaskedArray constructed is writeable if the input
480  // MaskedArray is writeable, and readonly if the input MaskedArray
481  // is readonly.
482  //
483  MaskedArray<T> operator() (const MaskedLogicalArray &mask) const;
484 
485  // Get a reference to an array part which extends from "start" to end."
486  // <group>
487  MaskedArray<T> operator()(const IPosition &start, const IPosition &end);
488  // Along the ith axis, every inc[i]'th element is chosen.
489  MaskedArray<T> operator()(const IPosition &start, const IPosition &end,
490  const IPosition &inc);
491  // </group>
492 
493  // Get a reference to an array using a Slicer.
494  MaskedArray<T> operator()(const Slicer&);
495 
496  // Make a copy of the masked array.
497  //
498  // This is a deep copy. The Array and mask components of the returned
499  // MaskedArray are deep copies of the Array and mask in the input
500  // MaskedArray pointed to by this. In other words, the Array and mask
501  // in the output MaskedArray are completely independent of those in
502  // the input MaskedArray.
503  //
504  // By default, the MaskedArray returned is writeable. If
505  // <src>isreadonly</src> is <src>True</src>, then the MaskedArray
506  // returned is readonly.
507  //
508  // <group>
509  MaskedArray<T> copy(Bool isreadonly) const;
510  MaskedArray<T> copy() const;
511  // </group>
512 
513  // Return the internal Array.
514  const Array<T> & getArray() const;
515 
516  // Return the internal Array, writeable.
517  //
518  // <thrown>
519  // <li> ArrayError
520  // </thrown>
521  //
522  Array<T> & getRWArray() const;
523 
524  // Return the (const) internal Mask.
525  const LogicalArray & getMask() const;
526 
527  // The dimensionality of this masked array.
528  uInt ndim() const;
529 
530  // The number of elements of this masked array.
531  // This is the number of elements in the underlying Array.
532  // <group>
533  uInt nelements() const;
534  uInt size() const
535  { return nelements(); }
536  // </group>
537 
538  // The number of valid elements of this masked array.
539  // This is the number of elements of the mask which are TRUE.
540  uInt nelementsValid() const;
541 
542 
543  // Check to see if the masked array is consistent. This is about the same
544  // thing as checking for invariants. If AIPS_DEBUG is defined, this is
545  // invoked after construction and on entry to most member functions.
546  Bool ok() const;
547 
548  // Are the shapes identical?
549  // <group>
550  Bool conform(const Array<T> &other) const;
551  Bool conform(const MaskedArray<T> &other) const;
552  // </group>
553 
554  // The length of each axis.
555  const IPosition& shape() const
556  { return pArray->shape(); }
557 
558  // Is the array read only?
559  Bool isReadOnly() const
560  { return isRO; }
561 
562  // Set the array to be read only.
563  void setReadOnly() const;
564 
565 
566  // Copy the values in inarray to this, only copying those elements
567  // for which the corresponding mask element is True.
568  //
569  // <thrown>
570  // <li> ArrayConformanceError
571  // <li> ArrayError
572  // </thrown>
573  //
574  MaskedArray<T> &operator=(const Array<T> &inarray);
575 
576  // Copy the values in other to this, only copying those elements
577  // for which the logical AND of the corresponding mask elements
578  // of both MaskedArrays is True.
579  //
580  // <thrown>
581  // <li> ArrayConformanceError
582  // <li> ArrayError
583  // </thrown>
584  //
585  // <group>
586  MaskedArray<T> &operator=(const MaskedArray<T> &other);
587  // </group>
588 
589  // Set every element of this array to "value", only setting those elements
590  // for which the corresponding mask element is True.
591  // In other words, a scalar behaves as if it were a constant conformant
592  // array.
593  //
594  // <thrown>
595  // <li> ArrayError
596  // </thrown>
597  //
598  MaskedArray<T> &operator=(const T &value);
599 
600  // Return a "compressed" Array containing only the valid
601  // elements of the MaskedArray. The number of elements in the
602  // Array will be <src>nelementsValid()</src> for the
603  // MaskedArray. The MaskedArray can have any shape.
604  // <group>
605 
606  // The returned Array will have dimension one.
607  Array<T> getCompressedArray () const;
608 
609  // The returned Array will have the input shape. This shape must
610  // give the returned Array the required number of elements.
611  //
612  // <thrown>
613  // <li> ArrayError
614  // </thrown>
615  //
616  Array<T> getCompressedArray (const IPosition & shape) const;
617 
618  // </group>
619 
620  // Fill the argument "compressed" Array with only the
621  // valid elements of the MaskedArray. The size of the
622  // Array must be <src>nelementsValid()</src> for the MaskedArray.
623  // The Array can have any shape which meets this requirement.
624  // The MaskedArray can have any shape.
625  //
626  // <thrown>
627  // <li> ArrayError
628  // </thrown>
629  //
630  void getCompressedArray (Array<T> & inarr) const;
631 
632  // Set only the valid elements of the MaskedArray from the argument
633  // "compressed" Array. The size of the
634  // Array must be <src>nelementsValid()</src> for the MaskedArray.
635  // The Array can have any shape which meets this requirement.
636  // The MaskedArray can have any shape.
637  //
638  // <thrown>
639  // <li> ArrayError
640  // </thrown>
641  //
642  void setCompressedArray (const Array<T> & inarr);
643 
644  // Manipulate the storage for the underlying Array.
645  // See the description of the corresponding Array functions
646  // for more information.
647  // <group>
648  const T * getArrayStorage (Bool &deleteIt) const;
649  //
650  // <thrown>
651  // <li> ArrayError
652  // </thrown>
653  //
654  T * getRWArrayStorage (Bool &deleteIt) const;
655  //
656  void freeArrayStorage(const T *&storage, Bool deleteIt) const;
657  //
658  // <thrown>
659  // <li> ArrayError
660  // </thrown>
661  //
662  void putArrayStorage(T *&storage, Bool deleteAndCopy) const;
663  // </group>
664 
665 
666  // Manipulate the storage for the underlying Mask.
667  // See the description of the corresponding Array functions
668  // for more information.
669  // <group>
670  const LogicalArrayElem *getMaskStorage (Bool &deleteIt) const;
671  //
672  void freeMaskStorage(const LogicalArrayElem *&storage, Bool deleteIt) const;
673  // </group>
674 
675 
676 protected:
677  // The array.
679 
680  // The mask.
681  LogicalArray *pMask;
682 
683  // Cache the number of valid elements.
685 
686  // Is the number of valid elements cache OK?
687  // i.e. has it been calculated?
689 
690  // Is the array read only?
692 
693 };
694 
695 
696 // <summary> General global functions for MaskedArrays, and MaskedArrays and Arrays. </summary>
697 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tMaskedArray">
698 //
699 // <prerequisite>
700 // <li> <linkto class=Array>Array</linkto>
701 // <li> <linkto group="LogiArray.h#LogicalArray">LogicalArray</linkto>
702 // <li> <linkto class=MaskedArray>MaskedArray</linkto>
703 // </prerequisite>
704 //
705 // <synopsis>
706 // These are generally useful global functions which operate on all
707 // MaskedArrays, or on MaskedArrays and Arrays.
708 // </synopsis>
709 //
710 // <linkfrom anchor="MaskedArray general global functions" classes="MaskedArray Array Vector Matrix Cube">
711 // <here>MaskedArray general global functions</here> -- General global
712 // functions for MaskedArrays, and between MaskedArrays and Arrays.
713 // </linkfrom>
714 //
715 // <group name="MaskedArray general global functions">
717 
718 // Test conformance for masked arrays and arrays of different types.
719 // Are the shapes identical?
720 //
721 // <group name=conform2>
722 //
723 template<class T, class U>
724  Bool conform2 (const MaskedArray<T> &left, const Array<U> &right);
725 template<class T, class U>
726  Bool conform2 (const Array<T> &left, const MaskedArray<U> &right);
727 template<class T, class U>
728  Bool conform2 (const MaskedArray<T> &left, const MaskedArray<U> &right);
729 //
730 // </group>
731 
732 // </group>
733 
734 
735 } //# NAMESPACE CASACORE - END
736 
737 #ifndef CASACORE_NO_AUTO_TEMPLATES
738 #include <casacore/casa/Arrays/MaskedArray.tcc>
739 #endif //# CASACORE_NO_AUTO_TEMPLATES
740 #endif
MaskedArray< T > copy() const
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
Array< T > & getRWArray() const
Return the internal Array, writeable.
Bool isReadOnly() const
Is the array read only?
Definition: MaskedArray.h:559
void setReadOnly() const
Set the array to be read only.
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
const IPosition & shape() const
The length of each axis.
Definition: MaskedArray.h:555
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
Array< T > * pArray
The array.
Definition: MaskedArray.h:678
uInt nelements() const
The number of elements of this masked array.
const_iterator end() const
Bool conform(const Array< T > &other) const
Are the shapes identical?
Bool isRO
Is the array read only?
Definition: MaskedArray.h:691
ABSTRACT CLASSES Deliberately vague to be general enough to allow for many different types of data
Definition: PlotData.h:48
Class for masking an Array for operations on that Array.
void putArrayStorage(T *&storage, Bool deleteAndCopy) const
const LogicalArrayElem * getMaskStorage(Bool &deleteIt) const
Manipulate the storage for the underlying Mask.
T * getRWArrayStorage(Bool &deleteIt) const
void freeArrayStorage(const T *&storage, Bool deleteIt) const
Array< T > getCompressedArray() const
Return a &quot;compressed&quot; Array containing only the valid elements of the MaskedArray.
MaskedArray< T > & operator=(const Array< T > &inarray)
Copy the values in inarray to this, only copying those elements for which the corresponding mask elem...
MaskedArray()
Default constructor for a MaskedArray does not allocate any memory for the Data array or Mask...
const Array< T > & getArray() const
Return the internal Array.
void freeMaskStorage(const LogicalArrayElem *&storage, Bool deleteIt) const
void setData(const Array< T > &data, const LogicalArray &mask, Bool isReadOnly=False)
Reset the data and mask of the the MaskedArray.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
void setCompressedArray(const Array< T > &inarr)
Set only the valid elements of the MaskedArray from the argument &quot;compressed&quot; Array.
const Bool False
Definition: aipstype.h:44
Bool ok() const
Check to see if the masked array is consistent.
Bool nelemValidIsOK
Is the number of valid elements cache OK? i.e.
Definition: MaskedArray.h:688
template &lt;class T, class U&gt; class vector;
Definition: MSFlagger.h:37
uInt nelemValid
Cache the number of valid elements.
Definition: MaskedArray.h:684
LogicalArray * pMask
The mask.
Definition: MaskedArray.h:681
MaskedArray< T > operator()(const LogicalArray &mask) const
Return a MaskedArray.
const T * getArrayStorage(Bool &deleteIt) const
Manipulate the storage for the underlying Array.
uInt ndim() const
The dimensionality of this masked array.
uInt size() const
Definition: MaskedArray.h:534
const LogicalArray & getMask() const
Return the (const) internal Mask.
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
unsigned int uInt
Definition: aipstype.h:51
uInt nelementsValid() const
The number of valid elements of this masked array.
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42