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