casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Friends | List of all members
casacore::Array< T > Class Template Reference

template <class T, class U> class vector; More...

#include <Array.h>

Inheritance diagram for casacore::Array< T >:
casacore::ArrayBase casacore::Cube< T > casacore::Matrix< T > casacore::Vector< T > casacore::Cube< casacore::RigidVector< Double, 2 > > casacore::Matrix< casacore::GaussianBeam > casacore::Matrix< casacore::SquareMatrix< Complex, 2 > > casacore::Vector< ArgType > casacore::Vector< AutoDiff< T > > casacore::Vector< AutoDiffA< T > > casacore::Vector< casacore::AutoDiff< Double > > casacore::Vector< casacore::MDirection > casacore::Vector< casacore::MeasComet * > casacore::Vector< casacore::MEpoch > casacore::Vector< casacore::MFrequency > casacore::Vector< casacore::Quantum > casacore::Vector< casacore::Quantum< Double > > casacore::Vector< casacore::RORecordFieldPtr< Double > > casacore::Vector< casacore::Slicer * > casacore::Vector< casacore::SquareMatrix< Complex, 2 > > casacore::Vector< casacore::Unit > casacore::Vector< casacore::Vector< Range > > casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< DComplex >::BaseType >::base > > casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< Double >::BaseType >::base > > casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< T >::BaseType >::base > > casacore::Vector< Domain > casacore::Vector< double > casacore::Vector< Type > casacore::Vector< typename casacore::FunctionTraits< DComplex >::ArgType > casacore::Vector< typename casacore::FunctionTraits< DComplex >::BaseType > casacore::Vector< typename casacore::FunctionTraits< DComplex >::DiffType > casacore::Vector< typename casacore::FunctionTraits< Double >::ArgType > casacore::Vector< typename casacore::FunctionTraits< Double >::BaseType > casacore::Vector< typename casacore::FunctionTraits< Double >::DiffType > casacore::Vector< typename casacore::FunctionTraits< T >::ArgType > casacore::Vector< typename casacore::FunctionTraits< T >::BaseType > casacore::Vector< typename casacore::FunctionTraits< T >::DiffType > casacore::Vector< uInt >

Classes

class  BaseIteratorSTL
 See the function begin() and end() for a detailed description of the STL iterator capability. More...
 
class  ConstIteratorSTL
 
class  IteratorSTL
 

Public Member Functions

 Array ()
 Result has dimensionality of zero, and nelements is zero. More...
 
 Array (const IPosition &shape)
 Create an array of the given shape, i.e. More...
 
 Array (const IPosition &shape, ArrayInitPolicy initPolicy)
 Create an array of the given shape, i.e. More...
 
 Array (const IPosition &shape, const T &initialValue)
 Create an array of the given shape and initialize it with the initial value. More...
 
 Array (const Array< T > &other)
 After construction, this and other reference the same storage. More...
 
 Array (const IPosition &shape, T *storage, StorageInitPolicy policy=COPY)
 Create an Array of a given shape from a pointer. More...
 
 Array (const IPosition &shape, T *storage, StorageInitPolicy policy, AbstractAllocator< T > const &allocator)
 Create an Array of a given shape from a pointer. More...
 
 Array (const IPosition &shape, const T *storage)
 Create an Array of a given shape from a pointer. More...
 
virtual ~Array ()
 Frees up storage only if this array was the last reference to it. More...
 
virtual CountedPtr< ArrayBasemakeArray () const
 Make an empty array of the same template type. More...
 
virtual void assign (const Array< T > &other)
 Assign the other array to this array. More...
 
virtual void assignBase (const ArrayBase &other, Bool checkType=True)
 Assign the source array to this array. More...
 
void set (const T &value)
 Set every element of the array to "value." Also could use the assignment operator which assigns an array from a scalar. More...
 
void apply (T(*function)(T))
 Apply the function to every element of the array. More...
 
void apply (T(*function)(const T &))
 This version takes a function which takes a const T reference and returns a T. More...
 
void apply (const Functional< T, T > &function)
 This version applies a functional. More...
 
virtual void reference (const Array< T > &other)
 After invocation, this array and other reference the same storage. More...
 
virtual Array< T > & operator= (const Array< T > &other)
 Copy the values in other to this. More...
 
Array< T > & operator= (const T &value)
 Set every element of this array to "value". More...
 
Array< T > & operator= (const MaskedArray< T > &marray)
 Copy to this those values in marray whose corresponding elements in marray's mask are True. More...
 
Array< T > copy (ArrayInitPolicy policy=ArrayInitPolicy::NO_INIT) const
 This makes a copy of the array and returns it. More...
 
void copyMatchingPart (const Array< T > &from)
 This function copies the matching part of from array to this array. More...
 
void unique ()
 This ensures that this array does not reference any other storage. More...
 
template<class U >
void tovector (vector< T, U > &out) const
 Create an STL vector from an Array. More...
 
vector< T > tovector () const
 
Array< T > reform (const IPosition &shape) const
 It is occasionally useful to have an array which access the same storage appear to have a different shape. More...
 
bool reformOrResize (const IPosition &newShape, uInt resizePercentage=0, Bool resizeIfNeeded=True)
 Having an array that can be reused without requiring reallocation can be useful for large arrays. More...
 
bool adjustLastAxis (const IPosition &newShape, uInt resizePercentage=0, bool resizeIfNeeded=True)
 Use this method to extend or reduce the last dimension of an array. More...
 
size_t capacity () const
 Returns the number of elements allocated. More...
 
Array< T > nonDegenerate (uInt startingAxis=0, Bool throwIfError=True) const
 These member functions remove degenerate (ie. More...
 
Array< T > nonDegenerate (const IPosition &ignoreAxes) const
 
void nonDegenerate (const Array< T > &other, uInt startingAxis=0, Bool throwIfError=True)
 
void nonDegenerate (const Array< T > &other, const IPosition &ignoreAxes)
 
void removeDegenerate (uInt startingAxis=0, Bool throwIfError=True)
 Remove degenerate axes from this Array object. More...
 
void removeDegenerate (const IPosition &ignoreAxes)
 
const Array< T > addDegenerate (uInt numAxes) const
 This member function returns an Array reference with the specified number of extra axes, all of length one, appended to the end of the Array. More...
 
Array< T > addDegenerate (uInt numAxes)
 
virtual void resize ()
 Make this array a different shape. More...
 
virtual void resize (const IPosition &newShape, Bool copyValues=False)
 Resize the array and optionally copy the values. More...
 
virtual void resize (const IPosition &newShape, Bool copyValues, ArrayInitPolicy policy)
 Resize the array and optionally copy the values. More...
 
T & operator() (const IPosition &)
 Access a single element of the array. More...
 
const T & operator() (const IPosition &) const
 
Array< T > operator() (const IPosition &start, const IPosition &end)
 Get a reference to an array section extending from start to end (inclusive). More...
 
const Array< T > operator() (const IPosition &start, const IPosition &end) const
 
Array< T > operator() (const IPosition &start, const IPosition &end, const IPosition &inc)
 Along the ith axis, every inc[i]'th element is chosen. More...
 
const Array< T > operator() (const IPosition &start, const IPosition &end, const IPosition &inc) const
 
Array< T > operator() (const Slicer &)
 Get a reference to an array section using a Slicer. More...
 
const Array< T > operator() (const Slicer &) const
 
virtual CountedPtr< ArrayBasegetSection (const Slicer &) const
 Get a reference to a section of an array. More...
 
Array< T > operator[] (size_t i) const
 Get the subset given by the i-th value of the last axis. More...
 
Array< T > diagonals (uInt firstAxis=0, Int64 diag=0) const
 Get the diagonal of each matrix part in the full array. More...
 
const MaskedArray< T > operator() (const LogicalArray &mask) const
 The array is masked by the input LogicalArray. More...
 
MaskedArray< T > operator() (const LogicalArray &mask)
 
const MaskedArray< T > operator() (const MaskedLogicalArray &mask) const
 The array is masked by the input MaskedLogicalArray. More...
 
MaskedArray< T > operator() (const MaskedLogicalArray &mask)
 
uInt nrefs () const
 The number of references the underlying storage has assigned to it. More...
 
virtual Bool ok () const
 Check to see if the Array is consistent. More...
 
Bool conform (const Array< T > &other) const
 Are the shapes identical? More...
 
Bool conform (const MaskedArray< T > &other) const
 
T * data ()
 Get a pointer to the beginning of the array. More...
 
const T * data () const
 
T * getStorage (Bool &deleteIt)
 Generally use of this should be shunned, except to use a FORTRAN routine or something similar. More...
 
const T * getStorage (Bool &deleteIt) const
 
virtual void * getVStorage (Bool &deleteIt)
 The following functions behave the same as the corresponding getStorage functions in the derived templated Array class. More...
 
virtual const void * getVStorage (Bool &deleteIt) const
 
void putStorage (T *&storage, Bool deleteAndCopy)
 putStorage() is normally called after a call to getStorage() (cf). More...
 
virtual void putVStorage (void *&storage, Bool deleteAndCopy)
 
void freeStorage (const T *&storage, Bool deleteIt) const
 If deleteIt is set, delete "storage". More...
 
void freeVStorage (const void *&storage, Bool deleteIt) const
 
virtual void takeStorage (const IPosition &shape, T *storage, StorageInitPolicy policy=COPY)
 Replace the data values with those in the pointer storage. More...
 
virtual void takeStorage (const IPosition &shape, T *storage, StorageInitPolicy policy, AbstractAllocator< T > const &allocator)
 If policy is COPY, storage of a new copy is allocated by allocator. More...
 
virtual void takeStorage (const IPosition &shape, const T *storage)
 Since the pointer is const, a copy is always taken. More...
 
virtual void takeStorage (const IPosition &shape, const T *storage, AbstractAllocator< T > const &allocator)
 Since the pointer is const, a copy is always taken. More...
 
virtual CountedPtr
< ArrayPositionIterator
makeIterator (uInt byDim) const
 Create an ArrayIterator object of the correct type. More...
 
- Public Member Functions inherited from casacore::ArrayBase
 ArrayBase ()
 
 ArrayBase (const IPosition &shape)
 Create an array of the given shape, i.e. More...
 
 ArrayBase (const ArrayBase &other)
 Copy constructor. More...
 
ArrayBaseoperator= (const ArrayBase &)
 Assignment. More...
 
virtual ~ArrayBase ()
 Destructor. More...
 
uInt ndim () const
 The dimensionality of this array. More...
 
size_t nelements () const
 How many elements does this array have? Product of all axis lengths. More...
 
size_t size () const
 
Bool empty () const
 Is the array empty (i.e. More...
 
Bool contiguousStorage () const
 Are the array data contiguous? If they are not contiguous, getStorage (see below) needs to make a copy. More...
 
const IPositionshape () const
 The length of each axis. More...
 
IPosition endPosition () const
 A convenience function: endPosition(i) = shape(i) - 1; i.e. More...
 
const IPositionsteps () const
 Return steps to be made if stepping one element in a dimension. More...
 
void validateConformance (const ArrayBase &) const
 Various helper functions. More...
 
void validateIndex (const IPosition &) const
 
void validateIndex (uInt index) const
 
void validateIndex (uInt index1, uInt index2) const
 
void validateIndex (uInt index1, uInt index2, uInt index3) const
 

Friends

class ArrayIterator< T >
 Used to iterate through Arrays. More...
 
class Matrix< T >
 Needed to be a friend for Matrix<T>::reference() More...
 
typedef T value_type
 Define the STL-style iterator functions (only forward iterator). More...
 
typedef IteratorSTL iterator
 
typedef ConstIteratorSTL const_iterator
 
typedef T * contiter
 
typedef const T * const_contiter
 
CountedPtr< Block< T > > data_p
 Reference counted block that contains the storage. More...
 
T * begin_p
 This pointer is adjusted to point to the first element of the array. More...
 
T * end_p
 The end for an STL-style iteration. More...
 
iterator begin ()
 Get the begin iterator object for any array. More...
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
contiter cbegin ()
 Get the begin iterator object for a contiguous array. More...
 
const_contiter cbegin () const
 
contiter cend ()
 
const_contiter cend () const
 
 Array (Allocator_private::AllocSpec< T > allocator)
 
 Array (const IPosition &shape, ArrayInitPolicy initPolicy, Allocator_private::BulkAllocator< T > *allocator)
 
Array< T > copy (ArrayInitPolicy policy, Allocator_private::BulkAllocator< T > *allocator) const
 Makes a copy using the allocator. More...
 
Allocator_private::BulkAllocator
< T > * 
nonNewDelAllocator () const
 If the current allocator is NewDelAllocator<T>, BulkAllocator for DefaultAllocator<T> is returned, otherwise BulkAllocator for the current allocator is returned. More...
 
static ArrayInitPolicy defaultArrayInitPolicy ()
 
static void copyToContiguousStorage (T *dst, Array< T > const &src, ArrayInitPolicy policy)
 
virtual void preTakeStorage (const IPosition &)
 pre/post processing hook of takeStorage() for subclasses. More...
 
virtual void postTakeStorage ()
 
virtual void doNonDegenerate (const Array< T > &other, const IPosition &ignoreAxes)
 Remove the degenerate axes from the Array object. More...
 
void makeSteps ()
 Fill the steps and the end for a derived class. More...
 
void setEndIter ()
 Set the end iterator. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from casacore::ArrayBase
static uInt arrayVersion ()
 Array version for major change (used by ArrayIO). More...
 
- Protected Member Functions inherited from casacore::ArrayBase
void baseCopy (const ArrayBase &that)
 
Bool reformOrResize (const IPosition &newShape, Bool resizeIfNeeded, uInt nReferences, Int64 nElementsAllocated, Bool copyDataIfNeeded, uInt resizePercentage)
 Either reforms the array if size permits or resizes it to the new shape. More...
 
Bool isStorageContiguous () const
 Determine if the storage of a subset is contiguous. More...
 
void checkVectorShape ()
 Check if the shape of a vector is correct. More...
 
void checkMatrixShape ()
 Check if the shape of a matrix is correct. More...
 
void checkCubeShape ()
 Check if the shape of a cube is correct. More...
 
void baseReform (ArrayBase &tmp, const IPosition &shape, Bool strict=True) const
 Reform the array to a shape with the same nr of elements. More...
 
void baseNonDegenerate (const ArrayBase &other, const IPosition &ignoreAxes)
 Remove the degenerate axes from the Array object. More...
 
void baseAddDegenerate (ArrayBase &, uInt numAxes)
 These member functions return an Array reference with the specified number of extra axes, all of length one, appended to the end of the Array. More...
 
size_t makeSubset (ArrayBase &out, const IPosition &b, const IPosition &e, const IPosition &i)
 Make a subset of an array. More...
 
size_t makeDiagonal (uInt firstAxis, Int64 diag)
 Set the length and stride such that the diagonal of the matrices defined by two consecutive axes is formed. More...
 
Bool conform2 (const ArrayBase &other) const
 Are the shapes identical? More...
 
void baseMakeSteps ()
 Make the indexing step sizes. More...
 
void throwNdimVector ()
 Throw expection if vector dimensionality is incorrect. More...
 
Bool copyVectorHelper (const ArrayBase &other)
 Helper function for templated Vector class. More...
 
- Protected Attributes inherited from casacore::ArrayBase
size_t nels_p
 Number of elements in the array. More...
 
uInt ndimen_p
 Dimensionality of the array. More...
 
Bool contiguous_p
 Are the data contiguous? More...
 
IPosition length_p
 Used to hold the shape, increment into the underlying storage and originalLength of the array. More...
 
IPosition inc_p
 
IPosition originalLength_p
 
IPosition steps_p
 Used to hold the step to next element in each dimension. More...
 

Detailed Description

template<class T>
class casacore::Array< T >

template <class T, class U> class vector;

forward declarations:

A templated N-D Array class with zero origin Array<T> is a templated, N-dimensional, Array class. The origin is zero, but by default indices are zero-based. This Array class is the base class for specialized Vector<T>, Matrix<T>, and Cube<T> classes.

Indexing into the array, and positions in general, are given with IPosition (essentially a vector of integers) objects. That is, an N-dimensional array requires a length-N IPosition to define a position within the array. Unlike C, indexing is done with (), not []. Also, the storage order is the same as in FORTRAN, i.e. memory varies most rapidly with the first index.

// axisLengths = [1,2,3,4,5]
IPosition axisLengths(5, 1, 2, 3, 4, 5);
Array<Int> ai(axisLengths); // ai is a 5 dimensional array of
// integers; indices are 0-based
// => ai.nelements() == 120
Array<Int> ai2(axisLengths); // The first element is at index 0
IPosition zero(5); zero = 0; // [0,0,0,0,0]
//..\.

Indexing into an N-dimensional array is relatively expensive. Normally you will index into a Vector, Matrix, or Cube. These may be obtained from an N-dimensional array by creating a reference, or by using an ArrayIterator. The "shape" of the array is an IPosition which gives the length of each axis.

An Array may be standalone, or it may refer to another array, or to part of another array (by refer we mean that if you change a pixel in the current array, a pixel in the referred to array also changes, i.e. they share underlying storage).
Warning: One way one array can reference another is through the copy constructor; While this might be what you want, you should probably use the reference() member function to make it explicit; The copy constructor is used when arguments are passed by value; normally functions should not pass Arrays by value, rather they should pass a reference or a const reference; On the positive side, returning an array from a function is efficient since no copying need be done;

Aside from the explicit reference() member function, a user will most commonly encounter an array which references another array when he takes an array slice (or section). A slice is a sub-region of an array (which might also have a stride: every nth row, every mth column, ...).

IPosition lengths(3,10,20,30);
Array<Int> ai(lengths); // A 10x20x30 cube
Cube<Int> ci;
//..\.
ci.reference(ai1); // ci and ai now reference the same
// storage
ci(0,0,0) = 123; // Can use Cube indexing
ci.xyPlane(2) = 0; // and other member functions
IPosition zero(3,0,0,0);
assert(ai(zero) == 123); // True because ai, ci are references
//..\.
Array<Int> subArray;
IPosition blc(3,0,0,0), trc(3,5,5,5);
subArray.reference(ai(blc, trc));
subArray = 10; // All of subArray, which is the
// subcube from 0,0,0 to 5,5,5 in
// ai, has the value 10.

While the last example has an array slice referenced explicitly by another array variable, normally the user will often only use the slice as a temporary in an expresion, for example:

Array<Complex> array;
IPosition blc, trc, offset;
//..\.
// Copy from one region of the array into another
array(blc, trc) = array(blc+offset, trc+offset);

The Array classes are intended to operate on relatively large amounts of data. While they haven't been extensively tuned yet, they are relatively efficient in terms of speed. Presently they are not space efficient – the overhead is about 15 words. While this will be improved (probably to about 1/2 that), these array classes are not appropriate for very large numbers of very small arrays. The Block<T> class may be what you want in this circumstance.

Element by element mathematical and logical operations are available for arrays (defined in aips/ArrayMath.h and aips/ArrayLogical.h). Because arithmetic and logical functions are split out, it is possible to create an Array<T> (and hence Vector<T> etc) for any type T that has a default constructor, assignment operator, and copy constructor. In particular, Array<String> works.

If compiled with the preprocessor symbol AIPS_DEBUG symbol, array consistency ("invariants") will be checked in most member functions, and indexing will be range-checked. This should not be defined for production runs.


Tip: Most of the data members and functions which are "protected" should likely become "private";

To Do

Definition at line 169 of file Array.h.

Member Typedef Documentation

template<class T>
typedef const T* casacore::Array< T >::const_contiter

Definition at line 855 of file Array.h.

template<class T>
typedef ConstIteratorSTL casacore::Array< T >::const_iterator

Definition at line 853 of file Array.h.

template<class T>
typedef T* casacore::Array< T >::contiter

Definition at line 854 of file Array.h.

template<class T>
typedef IteratorSTL casacore::Array< T >::iterator

Definition at line 852 of file Array.h.

template<class T>
typedef T casacore::Array< T >::value_type

Define the STL-style iterator functions (only forward iterator).

It makes it possible to iterate through all data elements of an array and to use it common STL functions. The end() function is relatively expensive, so it should not be used inside a for statement. It is much better to call it beforehand as shown in the example below. Furthermore it is very important to use ++iter, because iter++ is 4 times slower.

Array<Int> arr(shape);
Array<Int>::iterator iterend(arr.end());
for (Array<Int>::iterator iter=arr.begin(); iter!=iterend; ++iter) {
iter += 1;
}

The Array class supports random access, so in principle a random iterator could be implemented, but its performance would not be great, especially for non-contiguous arrays.
Some other STL like functions exist for performance reasons. If the array is contiguous, it is possible to use the cbegin and cend functions which are about 10% faster. STL-style typedefs.

Definition at line 851 of file Array.h.

Constructor & Destructor Documentation

template<class T>
casacore::Array< T >::Array ( )

Result has dimensionality of zero, and nelements is zero.

Storage will be allocated by DefaultAllocator<T>.

template<class T>
casacore::Array< T >::Array ( const IPosition shape)
explicit

Create an array of the given shape, i.e.

after construction array.ndim() == shape.nelements() and array.shape() == shape. The origin of the Array is zero. Storage is allocated by DefaultAllocator<T>. Without initPolicy parameter, the initialization of elements depends on type T. When T is a fundamental type like int, elements are NOT initialized. When T is a class type like casacore::Complex or std::string, elements are initialized. This inconsistent behavior confuses programmers and make it hard to write efficient and generic code using template. Especially when T is of type Complex or DComplex and it is unnecessary to initialize, provide initPolicy with value NO_INIT to skip the initialization. Therefore, it is strongly recommended to explicitly provide initPolicy parameter,

template<class T>
casacore::Array< T >::Array ( const IPosition shape,
ArrayInitPolicy  initPolicy 
)

Create an array of the given shape, i.e.

after construction array.ndim() == shape.nelements() and array.shape() == shape. The origin of the Array is zero. Storage is allocated by DefaultAllocator<T>. When initPolicy parameter is INIT, elements are initialized with the default value of T(). When initPolicy parameter is NO_INIT, elements are NOT initialized and programmers are responsible to initialize elements before they are referred, especially when T is such type like std::string.

IPosition shape(1, 10);
Array<Int> ai(shape, ArrayInitPolicy::NO_INIT);
size_t nread = fread(ai.data(), sizeof(Int), ai.nelements(), fp);
template<class T>
casacore::Array< T >::Array ( const IPosition shape,
const T &  initialValue 
)

Create an array of the given shape and initialize it with the initial value.

Storage is allocated by DefaultAllocator<T>.

template<class T>
casacore::Array< T >::Array ( const Array< T > &  other)

After construction, this and other reference the same storage.

template<class T>
casacore::Array< T >::Array ( const IPosition shape,
T *  storage,
StorageInitPolicy  policy = COPY 
)

Create an Array of a given shape from a pointer.

If policy is COPY, storage of a new copy is allocated by DefaultAllocator<T>. If policy is TAKE_OVER, storage will be destructed and released by NewDelAllocator<T>. It is strongly recommended to supply an appropriate allocator argument explicitly whenever policy == TAKE_OVER to let Array to know how to release the storage.

template<class T>
casacore::Array< T >::Array ( const IPosition shape,
T *  storage,
StorageInitPolicy  policy,
AbstractAllocator< T > const &  allocator 
)

Create an Array of a given shape from a pointer.

If policy is COPY, storage of a new copy is allocated by the specified allocator. If policy is TAKE_OVER, storage will be destructed and released by the specified allocator. Otherwise, allocator is ignored. It is strongly recommended to allocate and initialize storage with DefaultAllocator<T> rather than new[] or NewDelAllocator<T> because new[] can't decouple allocation and initialization. DefaultAllocator<T>::type is a subclass of std::allocator. You can allocate storage via the allocator as below.

FILE *fp = ...;
typedef DefaultAllocator<Int> Alloc;
Alloc::type alloc;
IPosition shape(1, 10);
Int *ptr = alloc.allocate(shape.product());
size_t nread = fread(ptr, sizeof(Int), shape.product(), fp);
Array<Int> ai(shape, ptr, TAKE_OVER, Alloc::value);
template<class T>
casacore::Array< T >::Array ( const IPosition shape,
const T *  storage 
)

Create an Array of a given shape from a pointer.

Because the pointer is const, a copy is always made. The copy is allocated by DefaultAllocator<T>.

template<class T>
virtual casacore::Array< T >::~Array ( )
virtual

Frees up storage only if this array was the last reference to it.

template<class T>
casacore::Array< T >::Array ( Allocator_private::AllocSpec< T >  allocator)
private
template<class T>
casacore::Array< T >::Array ( const IPosition shape,
ArrayInitPolicy  initPolicy,
Allocator_private::BulkAllocator< T > *  allocator 
)
private

Member Function Documentation

template<class T>
const Array<T> casacore::Array< T >::addDegenerate ( uInt  numAxes) const

This member function returns an Array reference with the specified number of extra axes, all of length one, appended to the end of the Array.

Note that the reform function can also be used to add extra axes.

template<class T>
Array<T> casacore::Array< T >::addDegenerate ( uInt  numAxes)
template<class T>
bool casacore::Array< T >::adjustLastAxis ( const IPosition newShape,
uInt  resizePercentage = 0,
bool  resizeIfNeeded = True 
)

Use this method to extend or reduce the last dimension of an array.

If sufficient excess capacity exists then the bookkeeping is adjusted to support the new shape. If insufficient storage exists then a new array is allocated (unless resizeIfNeeded is false; then an exception is thrown). If resizing is not required then the data remains untouched; if resizing is required then the data is copied into the new storage. The resizePercentage works the same as for reformOrResize (see above). This method never releases extra storage; use "resize" to do this. Array may not be sharing storage with another array at call time; an exception will be thrown if the array is shared. Returns true if the array was extension required a Array<T>::resize operation.

template<class T>
void casacore::Array< T >::apply ( T(*)(T)  function)

Apply the function to every element of the array.

This modifies the array in place.

This version takes a function which takes a T and returns a T.

template<class T>
void casacore::Array< T >::apply ( T(*)(const T &)  function)

This version takes a function which takes a const T reference and returns a T.

template<class T>
void casacore::Array< T >::apply ( const Functional< T, T > &  function)

This version applies a functional.

template<class T>
virtual void casacore::Array< T >::assign ( const Array< T > &  other)
virtual
template<class T>
virtual void casacore::Array< T >::assignBase ( const ArrayBase source,
Bool  checkType = True 
)
virtual

Assign the source array to this array.

If checkType==True, it is checked if the underlying template types match. Otherwise, it is only checked in debug mode (for performance).
The default implementation in ArrayBase throws an exception.

Reimplemented from casacore::ArrayBase.

template<class T>
iterator casacore::Array< T >::begin ( )
inline
template<class T>
const_iterator casacore::Array< T >::begin ( ) const
inline

Definition at line 861 of file Array.h.

template<class T>
size_t casacore::Array< T >::capacity ( ) const

Returns the number of elements allocated.

This value is >= to the value returned by size().

template<class T>
contiter casacore::Array< T >::cbegin ( )
inline
template<class T>
const_contiter casacore::Array< T >::cbegin ( ) const
inline

Definition at line 873 of file Array.h.

template<class T>
contiter casacore::Array< T >::cend ( )
inline
template<class T>
const_contiter casacore::Array< T >::cend ( ) const
inline

Definition at line 877 of file Array.h.

template<class T>
Bool casacore::Array< T >::conform ( const Array< T > &  other) const
inline

Are the shapes identical?

Definition at line 592 of file Array.h.

template<class T>
Bool casacore::Array< T >::conform ( const MaskedArray< T > &  other) const
template<class T>
Array<T> casacore::Array< T >::copy ( ArrayInitPolicy  policy = ArrayInitPolicy::NO_INIT) const

This makes a copy of the array and returns it.

This can be useful for, e.g. making working copies of function arguments that you can write into.

void someFunction(const Array<Int> &arg)
{
Array<Int> tmp(arg.copy());
// ..\.
}

Note that since the copy constructor makes a reference, if we just created used to copy constructor, modifying "tmp" would also modify "arg". Clearly another alternative would simply be:

void someFunction(const Array<Int> &arg)
{
Array<Int> tmp;
tmp = arg;
// ..\.
}

which likely would be simpler to understand. (Should copy() be deprecated and removed?)

template<class T>
Array<T> casacore::Array< T >::copy ( ArrayInitPolicy  policy,
Allocator_private::BulkAllocator< T > *  allocator 
) const
private

Makes a copy using the allocator.

template<class T>
void casacore::Array< T >::copyMatchingPart ( const Array< T > &  from)

This function copies the matching part of from array to this array.

The matching part is the part with the minimum size for each axis. E.g. if this array has shape [4,5,6] and from array has shape [7,3], the matching part has shape [4,3].
Note it is used by the resize function if copyValues==True.

template<class T>
static void casacore::Array< T >::copyToContiguousStorage ( T *  dst,
Array< T > const &  src,
ArrayInitPolicy  policy 
)
staticprotected
template<class T>
T* casacore::Array< T >::data ( )
inline
template<class T>
const T* casacore::Array< T >::data ( ) const
inline

Definition at line 602 of file Array.h.

template<class T>
static ArrayInitPolicy casacore::Array< T >::defaultArrayInitPolicy ( )
inlinestaticprotected

Definition at line 893 of file Array.h.

template<class T>
Array<T> casacore::Array< T >::diagonals ( uInt  firstAxis = 0,
Int64  diag = 0 
) const

Get the diagonal of each matrix part in the full array.

The matrices are taken using axes firstAxes and firstAxis+1. diag==0 is main diagonal; diag>0 above the main diagonal; diag<0 below.

template<class T>
virtual void casacore::Array< T >::doNonDegenerate ( const Array< T > &  other,
const IPosition ignoreAxes 
)
protectedvirtual
template<class T>
iterator casacore::Array< T >::end ( )
inline
template<class T>
const_iterator casacore::Array< T >::end ( ) const
inline

Definition at line 865 of file Array.h.

template<class T>
void casacore::Array< T >::freeStorage ( const T *&  storage,
Bool  deleteIt 
) const

If deleteIt is set, delete "storage".

Normally freeStorage calls will follow calls to getStorage. The reason the pointer is "const" is because only const pointers are released from const arrays. The "storage" pointer is set to zero.

template<class T>
void casacore::Array< T >::freeVStorage ( const void *&  storage,
Bool  deleteIt 
) const
virtual

Reimplemented from casacore::ArrayBase.

template<class T>
virtual CountedPtr<ArrayBase> casacore::Array< T >::getSection ( const Slicer ) const
virtual

Get a reference to a section of an array.

This is the same as operator(), but can be used in a type-agnostic way.

Reimplemented from casacore::ArrayBase.

template<class T>
T* casacore::Array< T >::getStorage ( Bool deleteIt)

Generally use of this should be shunned, except to use a FORTRAN routine or something similar.

Because you can't know the state of the underlying data layout (in particular, if there are increments) sometimes the pointer returned will be to a copy, but often this won't be necessary. A boolean is returned which tells you if this is a copy (and hence the storage must be deleted). Note that if you don't do anything unusual, getStorage followed by freeStorage or putStorage will do the deletion for you (if required). e.g.:

Array<Int> a(shape); ..\.
Bool deleteIt; Int *storage = a.getStorage(deleteIt);
foo(storage, a.nelements()); a.puStorage(storage, deleteIt);
// or a.freeStorage(storage, deleteIt) if a is const.

NB: However, if you only use getStorage, you will have to delete the pointer yourself using freeStorage().

It would probably be useful to have corresponding "copyin" "copyout" functions that used a user supplied buffer. Note that deleteIt is set in this function.

Referenced by casacore::Array< casacore::String >::getStorage().

template<class T>
const T* casacore::Array< T >::getStorage ( Bool deleteIt) const
inline

The cast is OK because the return pointer will be cast to const

Definition at line 628 of file Array.h.

template<class T>
virtual void* casacore::Array< T >::getVStorage ( Bool deleteIt)
virtual

The following functions behave the same as the corresponding getStorage functions in the derived templated Array class.

They handle a pointer to a contiguous block of array data. If the array is not contiguous, a copy is used to make it contiguous.

Reimplemented from casacore::ArrayBase.

template<class T>
virtual const void* casacore::Array< T >::getVStorage ( Bool deleteIt) const
virtual

Reimplemented from casacore::ArrayBase.

template<class T>
virtual CountedPtr<ArrayBase> casacore::Array< T >::makeArray ( ) const
virtual

Make an empty array of the same template type.

Reimplemented from casacore::ArrayBase.

template<class T>
virtual CountedPtr<ArrayPositionIterator> casacore::Array< T >::makeIterator ( uInt  byDim) const
virtual

Create an ArrayIterator object of the correct type.

Reimplemented from casacore::ArrayBase.

template<class T>
void casacore::Array< T >::makeSteps ( )
inlineprotected

Fill the steps and the end for a derived class.

Definition at line 923 of file Array.h.

template<class T>
Array<T> casacore::Array< T >::nonDegenerate ( uInt  startingAxis = 0,
Bool  throwIfError = True 
) const

These member functions remove degenerate (ie.

length==1) axes from Arrays. Only axes greater than startingAxis are considered (normally one wants to remove trailing axes). The first two of these functions return an Array reference with axes removed. The latter two functions let this Array object reference the 'other' array with degenerated axes removed.
Unless throwIfError is False, an exception will be thrown if startingAxis exceeds the array's dimensionality.
The functions with argument ignoreAxes do not consider the axes given in that argument. In this way it can be achieved that degenerate axes are kept.
Caution: When the two functions returning void are invoked on a derived object (e;g; Matrix), an exception is thrown if removing the degenerate axes from other does not result in a correct number of axes;

template<class T>
Array<T> casacore::Array< T >::nonDegenerate ( const IPosition ignoreAxes) const
template<class T>
void casacore::Array< T >::nonDegenerate ( const Array< T > &  other,
uInt  startingAxis = 0,
Bool  throwIfError = True 
)
template<class T>
void casacore::Array< T >::nonDegenerate ( const Array< T > &  other,
const IPosition ignoreAxes 
)
inline

Definition at line 472 of file Array.h.

template<class T>
Allocator_private::BulkAllocator<T>* casacore::Array< T >::nonNewDelAllocator ( ) const
private

If the current allocator is NewDelAllocator<T>, BulkAllocator for DefaultAllocator<T> is returned, otherwise BulkAllocator for the current allocator is returned.

template<class T>
uInt casacore::Array< T >::nrefs ( ) const

The number of references the underlying storage has assigned to it.

It is 1 unless there are outstanding references to the storage (e.g., through a slice). Normally you have no need to do this since the arrays handle all of the references for you.

template<class T>
virtual Bool casacore::Array< T >::ok ( ) const
virtual

Check to see if the Array is consistent.

This is about the same thing as checking for invariants. If AIPS_DEBUG is defined, this is invoked after construction and on entry to most member functions.

Reimplemented from casacore::ArrayBase.

Reimplemented in casacore::Cube< T >, casacore::Cube< Double >, casacore::Cube< casacore::RigidVector< Double, 2 > >, casacore::Matrix< T >, casacore::Matrix< casacore::SquareMatrix< Complex, 2 > >, casacore::Matrix< Float >, casacore::Matrix< casacore::GaussianBeam >, casacore::Matrix< Double >, casacore::Matrix< Int >, casacore::Matrix< FType >, casacore::Matrix< Bool >, casacore::Matrix< Complex >, casacore::Vector< T >, casacore::Vector< typename casacore::FunctionTraits< T >::DiffType >, casacore::Vector< casacore::MEpoch >, casacore::Vector< casacore::SquareMatrix< Complex, 2 > >, casacore::Vector< casacore::MPosition >, casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< Double >::BaseType >::base > >, casacore::Vector< typename casacore::FunctionTraits< DComplex >::DiffType >, casacore::Vector< double >, casacore::Vector< Float >, casacore::Vector< casacore::AutoDiff< Double > >, casacore::Vector< typename casacore::FunctionTraits< Double >::DiffType >, casacore::Vector< casacore::Quantum >, casacore::Vector< Double >, casacore::Vector< casacore::Vector< Range > >, casacore::Vector< AutoDiff< T > >, casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< DComplex >::BaseType >::base > >, casacore::Vector< typename casacore::FunctionTraits< DComplex >::ArgType >, casacore::Vector< casacore::Unit >, casacore::Vector< Int >, casacore::Vector< Int64 >, casacore::Vector< typename casacore::FunctionTraits< Double >::ArgType >, casacore::Vector< casacore::MDirection >, casacore::Vector< casacore::MFrequency >, casacore::Vector< casacore::RORecordFieldPtr< Double > >, casacore::Vector< AutoDiffA< T > >, casacore::Vector< Type >, casacore::Vector< typename casacore::FunctionTraits< DComplex >::BaseType >, casacore::Vector< FType >, casacore::Vector< Bool >, casacore::Vector< typename casacore::FunctionTraits< T >::BaseType >, casacore::Vector< typename casacore::FunctionTraits< T >::ArgType >, casacore::Vector< typename casacore::FunctionTraits< Double >::BaseType >, casacore::Vector< casacore::Slicer * >, casacore::Vector< casacore::MeasComet * >, casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< T >::BaseType >::base > >, casacore::Vector< casacore::Quantum< Double > >, casacore::Vector< uInt >, casacore::Vector< Domain >, casacore::Vector< casacore::String >, and casacore::Vector< ArgType >.

template<class T>
T& casacore::Array< T >::operator() ( const IPosition )

Access a single element of the array.

This is relatively expensive. Extensive indexing should be done through one of the Array specializations (Vector, Matrix, Cube). If AIPS_DEBUG is defined, index checking will be performed.

Referenced by casacore::Cube< casacore::RigidVector< Double, 2 > >::operator()(), casacore::Matrix< Complex >::operator()(), and casacore::Vector< ArgType >::operator()().

template<class T>
const T& casacore::Array< T >::operator() ( const IPosition ) const
template<class T>
Array<T> casacore::Array< T >::operator() ( const IPosition start,
const IPosition end 
)

Get a reference to an array section extending from start to end (inclusive).

template<class T>
const Array<T> casacore::Array< T >::operator() ( const IPosition start,
const IPosition end 
) const
template<class T>
Array<T> casacore::Array< T >::operator() ( const IPosition start,
const IPosition end,
const IPosition inc 
)

Along the ith axis, every inc[i]'th element is chosen.

template<class T>
const Array<T> casacore::Array< T >::operator() ( const IPosition start,
const IPosition end,
const IPosition inc 
) const
template<class T>
Array<T> casacore::Array< T >::operator() ( const Slicer )

Get a reference to an array section using a Slicer.

template<class T>
const Array<T> casacore::Array< T >::operator() ( const Slicer ) const
template<class T>
const MaskedArray<T> casacore::Array< T >::operator() ( const LogicalArray< T > &  mask) const

The array is masked by the input LogicalArray.

This mask must conform to the array.

template<class T>
MaskedArray<T> casacore::Array< T >::operator() ( const LogicalArray< T > &  mask)
template<class T>
const MaskedArray<T> casacore::Array< T >::operator() ( const MaskedLogicalArray< T > &  mask) const

The array is masked by the input MaskedLogicalArray.

The mask is effectively the AND of the internal LogicalArray and the internal mask of the MaskedLogicalArray. The MaskedLogicalArray must conform to the array.

template<class T>
MaskedArray<T> casacore::Array< T >::operator() ( const MaskedLogicalArray< T > &  mask)
template<class T>
virtual Array<T>& casacore::Array< T >::operator= ( const Array< T > &  other)
virtual

Copy the values in other to this.

If the array on the left hand side has no elements, then it is resized to be the same size as as the array on the right hand side. Otherwise, the arrays must conform (same shapes).

IPosition shape(2,10,10); // some shape
Array<Double> ad(shape);
//..\.
Array<Double> ad2; // N.B. ad2.nelements() == 0
ad2 = ad; // ad2 resizes, then elements
// are copied.
shape = 20;
Array<Double> ad3(shape);
ad3 = ad; // Error: arrays do not conform

Note that the assign function can be used to assign a non-conforming array.

Reimplemented in casacore::Vector< T >, casacore::Vector< casacore::MPosition >, casacore::Vector< Float >, casacore::Vector< Double >, casacore::Vector< Int >, casacore::Vector< Int64 >, casacore::Vector< FType >, casacore::Vector< Bool >, casacore::Vector< casacore::String >, casacore::Matrix< T >, casacore::Matrix< Float >, casacore::Matrix< Double >, casacore::Matrix< Int >, casacore::Matrix< FType >, casacore::Matrix< Bool >, casacore::Matrix< Complex >, casacore::Cube< T >, and casacore::Cube< Double >.

Referenced by casacore::Cube< casacore::RigidVector< Double, 2 > >::operator=(), casacore::Matrix< Complex >::operator=(), and casacore::Vector< ArgType >::operator=().

template<class T>
Array<T>& casacore::Array< T >::operator= ( const T &  value)

Set every element of this array to "value".

In other words, a scalar behaves as if it were a constant conformant array.

template<class T>
Array<T>& casacore::Array< T >::operator= ( const MaskedArray< T > &  marray)

Copy to this those values in marray whose corresponding elements in marray's mask are True.

Thrown Exceptions

template<class T>
Array<T> casacore::Array< T >::operator[] ( size_t  i) const

Get the subset given by the i-th value of the last axis.

So for a cube it returns the i-th xy plane. For a Matrix it returns the i-th row. The returned array references the original array data; its dimensionality is one less. For a 1-dim array it still returns a 1-dim array.
Note: This function should not be used in tight loops as it is (much) slower than iterating using begin() and end(), ArrayIter, or ArrayAccessor;

template<class T>
virtual void casacore::Array< T >::postTakeStorage ( )
inlineprotectedvirtual
template<class T>
virtual void casacore::Array< T >::preTakeStorage ( const IPosition )
inlineprotectedvirtual

pre/post processing hook of takeStorage() for subclasses.

Reimplemented in casacore::Cube< T >, casacore::Cube< Double >, casacore::Cube< casacore::RigidVector< Double, 2 > >, casacore::Matrix< T >, casacore::Matrix< casacore::SquareMatrix< Complex, 2 > >, casacore::Matrix< Float >, casacore::Matrix< casacore::GaussianBeam >, casacore::Matrix< Double >, casacore::Matrix< Int >, casacore::Matrix< FType >, casacore::Matrix< Bool >, casacore::Matrix< Complex >, casacore::Vector< T >, casacore::Vector< typename casacore::FunctionTraits< T >::DiffType >, casacore::Vector< casacore::MEpoch >, casacore::Vector< casacore::SquareMatrix< Complex, 2 > >, casacore::Vector< casacore::MPosition >, casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< Double >::BaseType >::base > >, casacore::Vector< typename casacore::FunctionTraits< DComplex >::DiffType >, casacore::Vector< double >, casacore::Vector< Float >, casacore::Vector< casacore::AutoDiff< Double > >, casacore::Vector< typename casacore::FunctionTraits< Double >::DiffType >, casacore::Vector< casacore::Quantum >, casacore::Vector< Double >, casacore::Vector< casacore::Vector< Range > >, casacore::Vector< AutoDiff< T > >, casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< DComplex >::BaseType >::base > >, casacore::Vector< typename casacore::FunctionTraits< DComplex >::ArgType >, casacore::Vector< casacore::Unit >, casacore::Vector< Int >, casacore::Vector< Int64 >, casacore::Vector< typename casacore::FunctionTraits< Double >::ArgType >, casacore::Vector< casacore::MDirection >, casacore::Vector< casacore::MFrequency >, casacore::Vector< casacore::RORecordFieldPtr< Double > >, casacore::Vector< AutoDiffA< T > >, casacore::Vector< Type >, casacore::Vector< typename casacore::FunctionTraits< DComplex >::BaseType >, casacore::Vector< FType >, casacore::Vector< Bool >, casacore::Vector< typename casacore::FunctionTraits< T >::BaseType >, casacore::Vector< typename casacore::FunctionTraits< T >::ArgType >, casacore::Vector< typename casacore::FunctionTraits< Double >::BaseType >, casacore::Vector< casacore::Slicer * >, casacore::Vector< casacore::MeasComet * >, casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< T >::BaseType >::base > >, casacore::Vector< casacore::Quantum< Double > >, casacore::Vector< uInt >, casacore::Vector< Domain >, casacore::Vector< casacore::String >, and casacore::Vector< ArgType >.

Definition at line 897 of file Array.h.

template<class T>
void casacore::Array< T >::putStorage ( T *&  storage,
Bool  deleteAndCopy 
)

putStorage() is normally called after a call to getStorage() (cf).

The "storage" pointer is set to zero.

template<class T>
virtual void casacore::Array< T >::putVStorage ( void *&  storage,
Bool  deleteAndCopy 
)
virtual

Reimplemented from casacore::ArrayBase.

template<class T>
virtual void casacore::Array< T >::reference ( const Array< T > &  other)
virtual

After invocation, this array and other reference the same storage.

That is, modifying an element through one will show up in the other. The arrays appear to be identical; they have the same shape.
Please note that this function makes it possible to reference a const Array, thus effectively it makes a const Array non-const. Although this may seem undesirable at first sight, it is necessary to be able to make references to temporary Array objects, in particular to Array slices. Otherwise one first needs to use the copy constructor.

Reimplemented in casacore::Vector< T >, casacore::Vector< casacore::MPosition >, casacore::Vector< Float >, casacore::Vector< Double >, casacore::Vector< Int >, casacore::Vector< Int64 >, casacore::Vector< FType >, casacore::Vector< Bool >, casacore::Vector< casacore::String >, casacore::Matrix< T >, casacore::Matrix< Float >, casacore::Matrix< Double >, casacore::Matrix< Int >, casacore::Matrix< FType >, casacore::Matrix< Bool >, casacore::Matrix< Complex >, casacore::Cube< T >, and casacore::Cube< Double >.

Referenced by casacore::ValueHolder::getValue(), and casacore::RecordInterface::toArray().

template<class T>
Array<T> casacore::Array< T >::reform ( const IPosition shape) const

It is occasionally useful to have an array which access the same storage appear to have a different shape.

For example, turning an N-dimensional array into a Vector.
When the array data are contiguous, the array can be reshaped to any form as long as the number of elements stays the same. When not contiguous, it is only possible to remove or add axes with length 1.

IPosition squareShape(2,5,5);
Array<Float> square(squareShape);
IPosition lineShape(1,25);
Vector<Float> line(square.reform(lineShape));
// "square"'s storage may now be accessed through Vector "line"
template<class T>
bool casacore::Array< T >::reformOrResize ( const IPosition newShape,
uInt  resizePercentage = 0,
Bool  resizeIfNeeded = True 
)

Having an array that can be reused without requiring reallocation can be useful for large arrays.

The method reformOrResize permits this usage.

The reformOrResize method first attempts to reform the matrix so that it reuses the existing storage for an array with a new shape. If the existing storage will not hold the new shape, then the method will resize the array when resizeIfNeeded is true; if a resize is needed and resizeIfNeeded is false, then an ArrayConformanceError is thrown. The copyDataIfNeeded parameter is passed to resize if resizing is performed. resizePercentage is the percent of additional storage to be addeed when a resize is performed; this allows the allocations to be amortized when the caller expects to be calling this method again in the future. The parameter is used to define an allocation shape which is larger than the newShape by increasing the last dimension by resizePercentage percent (i.e., lastDim = (lastDim * (100 + resizePercentage)) / 100). If resizePercentage <= 0 then resizing uses newShape as-is. Returns true if resizing (allocation) was performed.

To truncate the array so that it no longer holds additional storage, use the resize method.

Array may not be shared with another Array object during this call. Exception thrown if it is shared.

template<class T>
void casacore::Array< T >::removeDegenerate ( uInt  startingAxis = 0,
Bool  throwIfError = True 
)

Remove degenerate axes from this Array object.

Note it does not make sense to use these functions on a derived object like Matrix, because it is not possible to remove axes from them.

template<class T>
void casacore::Array< T >::removeDegenerate ( const IPosition ignoreAxes)
template<class T>
virtual void casacore::Array< T >::resize ( )
virtual

Make this array a different shape.

If copyValues==True the old values are copied over to the new array. Copying is done on a per axis basis, thus a subsection with the minimum of the old and new shape is copied.
Resize without argument is equal to resize(IPosition()).
It is important to note that if multiple Array objects reference the same data storage, this Array object still references the same data storage as the other Array objects if the shape does not change. Otherwise this Array object references newly allocated storage, while the other Array objects still reference the existing data storage.
If you want to be sure that the data storage of this Array object is not referenced by other Array objects, the function unique should be called first.

Reimplemented in casacore::Vector< T >, casacore::Vector< typename casacore::FunctionTraits< T >::DiffType >, casacore::Vector< casacore::MEpoch >, casacore::Vector< casacore::SquareMatrix< Complex, 2 > >, casacore::Vector< casacore::MPosition >, casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< Double >::BaseType >::base > >, casacore::Vector< typename casacore::FunctionTraits< DComplex >::DiffType >, casacore::Vector< double >, casacore::Vector< Float >, casacore::Vector< casacore::AutoDiff< Double > >, casacore::Vector< typename casacore::FunctionTraits< Double >::DiffType >, casacore::Vector< casacore::Quantum >, casacore::Vector< Double >, casacore::Vector< casacore::Vector< Range > >, casacore::Vector< AutoDiff< T > >, casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< DComplex >::BaseType >::base > >, casacore::Vector< typename casacore::FunctionTraits< DComplex >::ArgType >, casacore::Vector< casacore::Unit >, casacore::Vector< Int >, casacore::Vector< Int64 >, casacore::Vector< typename casacore::FunctionTraits< Double >::ArgType >, casacore::Vector< casacore::MDirection >, casacore::Vector< casacore::MFrequency >, casacore::Vector< casacore::RORecordFieldPtr< Double > >, casacore::Vector< AutoDiffA< T > >, casacore::Vector< Type >, casacore::Vector< typename casacore::FunctionTraits< DComplex >::BaseType >, casacore::Vector< FType >, casacore::Vector< Bool >, casacore::Vector< typename casacore::FunctionTraits< T >::BaseType >, casacore::Vector< typename casacore::FunctionTraits< T >::ArgType >, casacore::Vector< typename casacore::FunctionTraits< Double >::BaseType >, casacore::Vector< casacore::Slicer * >, casacore::Vector< casacore::MeasComet * >, casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< T >::BaseType >::base > >, casacore::Vector< casacore::Quantum< Double > >, casacore::Vector< uInt >, casacore::Vector< Domain >, casacore::Vector< casacore::String >, casacore::Vector< ArgType >, casacore::Matrix< T >, casacore::Matrix< casacore::SquareMatrix< Complex, 2 > >, casacore::Matrix< Float >, casacore::Matrix< casacore::GaussianBeam >, casacore::Matrix< Double >, casacore::Matrix< Int >, casacore::Matrix< FType >, casacore::Matrix< Bool >, casacore::Matrix< Complex >, casacore::Cube< T >, casacore::Cube< Double >, and casacore::Cube< casacore::RigidVector< Double, 2 > >.

Referenced by casacore::TableExprGroupAggr::getArray(), casacore::MArrayBase::removeMask(), and casacore::TableExprNodeSet::toArray().

template<class T>
virtual void casacore::Array< T >::resize ( const IPosition newShape,
Bool  copyValues = False 
)
virtual

Resize the array and optionally copy the values.


The default implementation in ArrayBase throws an exception.

Reimplemented from casacore::ArrayBase.

template<class T>
virtual void casacore::Array< T >::resize ( const IPosition newShape,
Bool  copyValues,
ArrayInitPolicy  policy 
)
virtual

Resize the array and optionally copy the values.


The default implementation in ArrayBase throws an exception.

Reimplemented from casacore::ArrayBase.

Reimplemented in casacore::Vector< T >, casacore::Vector< typename casacore::FunctionTraits< T >::DiffType >, casacore::Vector< casacore::MEpoch >, casacore::Vector< casacore::SquareMatrix< Complex, 2 > >, casacore::Vector< casacore::MPosition >, casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< Double >::BaseType >::base > >, casacore::Vector< typename casacore::FunctionTraits< DComplex >::DiffType >, casacore::Vector< double >, casacore::Vector< Float >, casacore::Vector< casacore::AutoDiff< Double > >, casacore::Vector< typename casacore::FunctionTraits< Double >::DiffType >, casacore::Vector< casacore::Quantum >, casacore::Vector< Double >, casacore::Vector< casacore::Vector< Range > >, casacore::Vector< AutoDiff< T > >, casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< DComplex >::BaseType >::base > >, casacore::Vector< typename casacore::FunctionTraits< DComplex >::ArgType >, casacore::Vector< casacore::Unit >, casacore::Vector< Int >, casacore::Vector< Int64 >, casacore::Vector< typename casacore::FunctionTraits< Double >::ArgType >, casacore::Vector< casacore::MDirection >, casacore::Vector< casacore::MFrequency >, casacore::Vector< casacore::RORecordFieldPtr< Double > >, casacore::Vector< AutoDiffA< T > >, casacore::Vector< Type >, casacore::Vector< typename casacore::FunctionTraits< DComplex >::BaseType >, casacore::Vector< FType >, casacore::Vector< Bool >, casacore::Vector< typename casacore::FunctionTraits< T >::BaseType >, casacore::Vector< typename casacore::FunctionTraits< T >::ArgType >, casacore::Vector< typename casacore::FunctionTraits< Double >::BaseType >, casacore::Vector< casacore::Slicer * >, casacore::Vector< casacore::MeasComet * >, casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< T >::BaseType >::base > >, casacore::Vector< casacore::Quantum< Double > >, casacore::Vector< uInt >, casacore::Vector< Domain >, casacore::Vector< casacore::String >, casacore::Vector< ArgType >, casacore::Matrix< T >, casacore::Matrix< casacore::SquareMatrix< Complex, 2 > >, casacore::Matrix< Float >, casacore::Matrix< casacore::GaussianBeam >, casacore::Matrix< Double >, casacore::Matrix< Int >, casacore::Matrix< FType >, casacore::Matrix< Bool >, casacore::Matrix< Complex >, casacore::Cube< T >, casacore::Cube< Double >, and casacore::Cube< casacore::RigidVector< Double, 2 > >.

template<class T>
void casacore::Array< T >::set ( const T &  value)

Set every element of the array to "value." Also could use the assignment operator which assigns an array from a scalar.

template<class T>
void casacore::Array< T >::setEndIter ( )
inlineprotected

Set the end iterator.

Definition at line 927 of file Array.h.

Referenced by casacore::Array< casacore::String >::makeSteps().

template<class T>
virtual void casacore::Array< T >::takeStorage ( const IPosition shape,
T *  storage,
StorageInitPolicy  policy = COPY 
)
virtual

Replace the data values with those in the pointer storage.

The results are undefined if storage does not point at nelements() or more data elements. After takeStorage() is called, nrefs() is 1.

If policy is COPY, storage of a new copy is allocated by DefaultAllocator<T>. If policy is TAKE_OVER, storage will be destructed and released by NewDelAllocator<T>. It is strongly recommended to supply an appropriate allocator argument explicitly whenever policy == TAKE_OVER to let Array to know how to release the storage.

template<class T>
virtual void casacore::Array< T >::takeStorage ( const IPosition shape,
T *  storage,
StorageInitPolicy  policy,
AbstractAllocator< T > const &  allocator 
)
virtual

If policy is COPY, storage of a new copy is allocated by allocator.

If policy is TAKE_OVER, storage will be destructed and released by allocator. Otherwise, storage is ignored.

template<class T>
virtual void casacore::Array< T >::takeStorage ( const IPosition shape,
const T *  storage 
)
virtual

Since the pointer is const, a copy is always taken.

Storage of a new copy is allocated by DefaultAllocator<T>.

template<class T>
virtual void casacore::Array< T >::takeStorage ( const IPosition shape,
const T *  storage,
AbstractAllocator< T > const &  allocator 
)
virtual

Since the pointer is const, a copy is always taken.

Storage of a new copy is allocated by the specified allocator.

template<class T>
template<class U >
void casacore::Array< T >::tovector ( vector< T, U > &  out) const

Create an STL vector from an Array.

The created vector is a linear representation of the Array memory. See Vector for details of the operation and its reverse (i.e. creating a Vector from a vector), and for details of definition and instantiation.

template<class T>
vector<T> casacore::Array< T >::tovector ( ) const
template<class T>
void casacore::Array< T >::unique ( )

This ensures that this array does not reference any other storage.


Tip: When a section is taken of an array with non-unity strides, storage can be wasted if the array, which originally contained all the data, goes away; unique() also reclaims storage; This is an optimization users don't normally need to understand;

IPosition shape(;;;), blc(;;;), trc(;;;), inc(;;;);
Array<Float> af(shape);
inc = 2; // or anything > 1
Array<Float> aSection;reference(af(blc, trc, inc));
af;reference(anotherArray);
// aSection now references storage that has a stride
// in it, but nothing else is; Storage is wasted;
aSection;unique();


Friends And Related Function Documentation

template<class T>
friend class ArrayIterator< T >
friend

Used to iterate through Arrays.

Derived classes VectorIterator and MatrixIterator are probably more useful.

Definition at line 681 of file Array.h.

template<class T>
friend class Matrix< T >
friend

Needed to be a friend for Matrix<T>::reference()

Definition at line 687 of file Array.h.

Member Data Documentation

template<class T>
T* casacore::Array< T >::begin_p
protected

This pointer is adjusted to point to the first element of the array.

It is not necessarily the same thing as data->storage() since this array might be a section, e.g. have a blc which shifts us forward into the block.

Definition at line 916 of file Array.h.

Referenced by casacore::Cube< casacore::RigidVector< Double, 2 > >::at(), casacore::Array< casacore::String >::cbegin(), casacore::Array< casacore::String >::data(), casacore::Cube< casacore::RigidVector< Double, 2 > >::operator()(), casacore::Matrix< Complex >::operator()(), casacore::Vector< ArgType >::operator()(), casacore::Vector< ArgType >::operator[](), and casacore::Array< casacore::String >::setEndIter().

template<class T>
CountedPtr<Block<T> > casacore::Array< T >::data_p
protected

Reference counted block that contains the storage.

Definition at line 910 of file Array.h.

template<class T>
T* casacore::Array< T >::end_p
protected

The documentation for this class was generated from the following file: