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