casacore
Classes | Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions | Static Private Member Functions | Friends | List of all members
casacore::Array< T, Alloc > Class Template Reference

More...

#include <Array.h>

Classes

class  BaseIteratorSTL
 
More...
 
class  ConstIteratorSTL
 
class  IteratorSTL
 
struct  uninitializedType
 This is a tag for the constructor that may be used to construct an uninitialized Array. More...
 

Public Types

typedef Alloc allocator_type
 Define the STL-style iterator functions (only forward iterator). More...
 
typedef T value_type
 Element type. More...
 
typedef const T & const_reference
 TODO This is how std containers define a reference type, but the name 'reference' is already taken by a method. More...
 
typedef T * pointer
 Pointer to an element type. More...
 
typedef const T * const_pointer
 Constant pointer to the element type. More...
 
typedef IteratorSTL iterator
 
typedef ConstIteratorSTL const_iterator
 
typedef T * contiter
 
typedef const T * const_contiter
 

Public Member Functions

 Array (const Alloc &allocator=Alloc())
 Result has dimensionality of zero, and nelements is zero. More...
 
 Array (const IPosition &shape, const Alloc &allocator=Alloc())
 Create an array of the given shape, i.e. More...
 
 Array (const IPosition &shape, const T &initialValue, const Alloc &allocator=Alloc())
 Create an array of the given shape and initialize it with the initial value. More...
 
 Array (const IPosition &shape, uninitializedType, const Alloc &allocator=Alloc())
 Constructor to create an uninitialized array. More...
 
 Array (std::initializer_list< T > list, const Alloc &allocator=Alloc())
 Construct a one-dimensional array from an initializer list. More...
 
 Array (const Array< T, Alloc > &other)
 After construction, this and other reference the same storage. More...
 
 Array (Array< T, Alloc > &&source) noexcept
 Source will be empty after this call. More...
 
 Array (const IPosition &shape, T *storage, StorageInitPolicy policy=COPY, const Alloc &allocator=Alloc())
 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...
 
template<typename InputIterator >
 Array (const IPosition &shape, InputIterator startIter, const Alloc &allocator=Alloc())
 Construct an array from an iterator and a shape. More...
 
virtual ~Array () noexcept
 Frees up storage only if this array was the last reference to it. More...
 
virtual std::unique_ptr< ArrayBasemakeArray () const override
 Make an empty array of the same template type. More...
 
Alloc & allocator ()
 Retrieve the allocator associated with this array. More...
 
const Alloc & allocator () const
 
void assign (const Array< T, Alloc > &other)
 Assign the other array to this array. More...
 
void assignBase (const ArrayBase &other, bool checkType=true) override
 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...
 
template<typename Callable >
void apply (Callable function)
 Apply the function to every element of the array. More...
 
virtual void reference (const Array< T, Alloc > &other)
 After invocation, this array and other reference the same storage. More...
 
Array< T, Alloc > & assign_conforming (const Array< T, Alloc > &other)
 Copy the values in other to this. More...
 
template<typename MaskAlloc >
Array< T, Alloc > & assign_conforming (const MaskedArray< T, Alloc, MaskAlloc > &marray)
 Copy to this those values in marray whose corresponding elements in marray's mask are true. More...
 
Array< T, Alloc > & operator= (const Array< T, Alloc > &other)
 TODO we should change the semantics. More...
 
template<typename MaskAlloc >
Array< T, Alloc > & operator= (const MaskedArray< T, Alloc, MaskAlloc > &marray)
 Calls assign_conforming(). More...
 
Array< T, Alloc > & operator= (Array< T, Alloc > &&other)
 The move operator takes the storage from the given array. More...
 
Array< T, Alloc > & operator= (const T &value)
 Set every element of this array to "value". More...
 
Array< T, Alloc > copy () const
 This makes a copy of the array and returns it. More...
 
void copyMatchingPart (const Array< T, Alloc > &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 (std::vector< T, U > &out) const
 Create an STL vector from an Array. More...
 
std::vector< T > tovector () const
 
Array< T, Alloc > 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, size_t 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, size_t 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, Alloc > nonDegenerate (size_t startingAxis=0, bool throwIfError=true) const
 These member functions remove degenerate (ie. More...
 
Array< T, Alloc > nonDegenerate (const IPosition &ignoreAxes) const
 
void nonDegenerate (const Array< T, Alloc > &other, size_t startingAxis=0, bool throwIfError=true)
 
void nonDegenerate (const Array< T, Alloc > &other, const IPosition &ignoreAxes)
 
void removeDegenerate (size_t startingAxis=0, bool throwIfError=true)
 Remove degenerate axes from this Array object. More...
 
void removeDegenerate (const IPosition &ignoreAxes)
 
const Array< T, Alloc > addDegenerate (size_t 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, Alloc > addDegenerate (size_t numAxes)
 
void resize ()
 Make this array a different shape. More...
 
void resize (const IPosition &newShape, bool copyValues=false) override
 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, Alloc > operator() (const IPosition &start, const IPosition &end)
 Get a reference to an array section extending from start to end (inclusive). More...
 
const Array< T, Alloc > operator() (const IPosition &start, const IPosition &end) const
 
Array< T, Alloc > 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, Alloc > operator() (const IPosition &start, const IPosition &end, const IPosition &inc) const
 
Array< T, Alloc > operator() (const Slicer &)
 Get a reference to an array section using a Slicer. More...
 
const Array< T, Alloc > operator() (const Slicer &) const
 
std::unique_ptr< ArrayBasegetSection (const Slicer &) const override
 Get a reference to a section of an array. More...
 
Array< T, Alloc > operator[] (size_t i) const
 Get the subset given by the i-th value of the last axis. More...
 
Array< T, Alloc > diagonals (size_t firstAxis=0, long long 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)
 
size_t nrefs () const
 The number of references the underlying storage has assigned to it. More...
 
virtual bool ok () const override
 Check to see if the Array is consistent. More...
 
bool conform (const Array< T, Alloc > &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
 
void * getVStorage (bool &deleteIt) override
 The following functions behave the same as the corresponding getStorage functions in the derived templated Array class. More...
 
const void * getVStorage (bool &deleteIt) const override
 
void putStorage (T *&storage, bool deleteAndCopy)
 putStorage() is normally called after a call to getStorage() (cf). More...
 
void putVStorage (void *&storage, bool deleteAndCopy) override
 
void freeStorage (const T *&storage, bool deleteIt) const
 If deleteIt is set, delete "storage". More...
 
void freeVStorage (const void *&storage, bool deleteIt) const override
 
virtual void takeStorage (const IPosition &shape, T *storage, StorageInitPolicy policy=COPY, const Alloc &allocator=Alloc())
 Replace the data values with those in the pointer storage. More...
 
virtual void takeStorage (const IPosition &shape, const T *storage, const Alloc &allocator=Alloc())
 Since the pointer is const, a copy is always taken. More...
 
std::unique_ptr< ArrayPositionIteratormakeIterator (size_t byDim) const override
 Create an ArrayIterator object of the correct type. 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
 
- Public Member Functions inherited from casacore::ArrayBase
 ArrayBase () noexcept
 
 ArrayBase (const IPosition &shape)
 Create an array of the given shape, i.e. More...
 
 ArrayBase (const ArrayBase &other)
 Copy constructor. More...
 
 ArrayBase (ArrayBase &&source) noexcept
 
ArrayBaseassign (const ArrayBase &)
 Assignment. More...
 
ArrayBaseoperator= (const ArrayBase &)=delete
 
ArrayBaseoperator= (ArrayBase &&) noexcept
 
virtual ~ArrayBase () noexcept
 Destructor. More...
 
size_t 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 (size_t index) const
 
void validateIndex (size_t index1, size_t index2) const
 
void validateIndex (size_t index1, size_t index2, size_t index3) const
 

Static Public Attributes

static struct casacore::Array::uninitializedType uninitialized
 

Protected Member Functions

 Array (Array< T, Alloc > &&source, const IPosition &shapeForSource) noexcept
 Source will be empty with given shape after this call. More...
 
void swap (Array< T, Alloc > &other)
 Swap this array with another array. More...
 
virtual void preTakeStorage (const IPosition &)
 pre/post processing hook of takeStorage() for subclasses. More...
 
virtual void postTakeStorage ()
 
void checkBeforeResize (const IPosition &newShape)
 This function is called when this array is about to be resized, before any work is done. More...
 
virtual size_t fixedDimensionality () const
 Subclasses can return their dimensionality. More...
 
virtual void checkAssignableType (ArrayBase &arrayBase) const
 
virtual void doNonDegenerate (const Array< T, Alloc > &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...
 
- Protected Member Functions inherited from casacore::ArrayBase
 ArrayBase (ArrayBase &&source, const IPosition &shapeForSource) noexcept
 For subclasses, this move constructor allows the moved-from object to obtain a given shape after resizing. More...
 
void swap (ArrayBase &source) noexcept
 
bool reformOrResize (const IPosition &newShape, bool resizeIfNeeded, size_t nReferences, long long nElementsAllocated, bool copyDataIfNeeded, size_t 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 &, size_t 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 (size_t firstAxis, long long 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...
 
bool copyVectorHelper (const ArrayBase &other)
 Helper function for templated Vector class. More...
 

Static Protected Member Functions

static void copyToContiguousStorage (T *dst, Array< T, Alloc > const &src)
 

Protected Attributes

std::shared_ptr< arrays_internal::Storage< T, Alloc > > data_p
 Shared pointer to a Storage that contains the data. 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...
 
- Protected Attributes inherited from casacore::ArrayBase
size_t nels_p
 Number of elements in the array. More...
 
size_t 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...
 

Private Member Functions

template<typename Integral >
 Array (const IPosition &shape, Integral startIter, const Alloc &allocator, std::true_type)
 Implementation of constructor taking a Shape, a Templated parameter and an allocator. More...
 
template<typename InputIterator >
 Array (const IPosition &shape, InputIterator startIter, const Alloc &allocator, std::false_type)
 Implementation of constructor taking a Shape, a Templated parameter and an allocator. More...
 
Array< T, Alloc > copy (const Alloc &allocator) const
 Makes a copy using the allocator. More...
 
Array< T, Alloc > & assign_conforming_implementation (const Array< T, Alloc > &other, std::true_type)
 Implementation for assign for copyable types. More...
 
Array< T, Alloc > & assign_conforming_implementation (const Array< T, Alloc > &, std::false_type)
 Implementation for assign for non-copyable types: can not be assigned. More...
 
bool isUnique () const
 An Array is unique when the container is shared and when nrefs==1. More...
 

Static Private Member Functions

static void copyToContiguousStorage (T *dst, Array< T, Alloc > const &src, std::true_type)
 
static void copyToContiguousStorage (T *, Array< T, Alloc > const &, std::false_type)
 

Friends

class ArrayIterator< T, Alloc >
 Used to iterate through Arrays. More...
 
template<typename ST , typename SAlloc >
void swap (Array< ST, SAlloc > &left, Array< ST, SAlloc > &right)
 

Additional Inherited Members

- Static Public Member Functions inherited from casacore::ArrayBase
static unsigned arrayVersion ()
 Array version for major change (used by ArrayIO). More...
 

Detailed Description

template<typename T, typename Alloc>
class casacore::Array< T, Alloc >

A templated N-D Array class with zero origin. Array<T, Alloc> 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 the Vector, Matrix, and Cube subclasses.

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);
TableExprNode array(const TableExprNode &values, const TableExprNodeSet &shape)
Create an array of the given shape and fill it with the values.
Definition: ExprNode.h:1929

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, Alloc> (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 156 of file Array.h.

Member Typedef Documentation

◆ allocator_type

template<typename T , typename Alloc >
typedef Alloc casacore::Array< T, Alloc >::allocator_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;
}
const IPosition & shape() const
The length of each axis.
Definition: ArrayBase.h:125
IteratorSTL iterator
Definition: Array.h:852

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.

Type of allocator used to allocate and deallocate space

Definition at line 841 of file Array.h.

◆ const_contiter

template<typename T , typename Alloc >
typedef const T* casacore::Array< T, Alloc >::const_contiter

Definition at line 855 of file Array.h.

◆ const_iterator

template<typename T , typename Alloc >
typedef ConstIteratorSTL casacore::Array< T, Alloc >::const_iterator

Definition at line 853 of file Array.h.

◆ const_pointer

template<typename T , typename Alloc >
typedef const T* casacore::Array< T, Alloc >::const_pointer

Constant pointer to the element type.

Definition at line 851 of file Array.h.

◆ const_reference

template<typename T , typename Alloc >
typedef const T& casacore::Array< T, Alloc >::const_reference

TODO This is how std containers define a reference type, but the name 'reference' is already taken by a method.

typedef T& reference;

Definition at line 847 of file Array.h.

◆ contiter

template<typename T , typename Alloc >
typedef T* casacore::Array< T, Alloc >::contiter

Definition at line 854 of file Array.h.

◆ iterator

template<typename T , typename Alloc >
typedef IteratorSTL casacore::Array< T, Alloc >::iterator

Definition at line 852 of file Array.h.

◆ pointer

template<typename T , typename Alloc >
typedef T* casacore::Array< T, Alloc >::pointer

Pointer to an element type.

Definition at line 849 of file Array.h.

◆ value_type

template<typename T , typename Alloc >
typedef T casacore::Array< T, Alloc >::value_type

Element type.

Definition at line 843 of file Array.h.

Constructor & Destructor Documentation

◆ Array() [1/13]

template<typename T , typename Alloc >
casacore::Array< T, Alloc >::Array ( const Alloc &  allocator = Alloc())

Result has dimensionality of zero, and nelements is zero.

◆ Array() [2/13]

template<typename T , typename Alloc >
casacore::Array< T, Alloc >::Array ( const IPosition shape,
const Alloc &  allocator = Alloc() 
)
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,

◆ Array() [3/13]

template<typename T , typename Alloc >
casacore::Array< T, Alloc >::Array ( const IPosition shape,
const T &  initialValue,
const Alloc &  allocator = Alloc() 
)

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

Storage is allocated by DefaultAllocator<T>.

◆ Array() [4/13]

template<typename T , typename Alloc >
casacore::Array< T, Alloc >::Array ( const IPosition shape,
uninitializedType  ,
const Alloc &  allocator = Alloc() 
)

Constructor to create an uninitialized array.

This constructor can for example be called with:

static struct casacore::Array::uninitializedType uninitialized

◆ Array() [5/13]

template<typename T , typename Alloc >
casacore::Array< T, Alloc >::Array ( std::initializer_list< T >  list,
const Alloc &  allocator = Alloc() 
)

Construct a one-dimensional array from an initializer list.

Example:

Array<int> a({5, 6, 7, 8});

◆ Array() [6/13]

template<typename T , typename Alloc >
casacore::Array< T, Alloc >::Array ( const Array< T, Alloc > &  other)

After construction, this and other reference the same storage.

◆ Array() [7/13]

template<typename T , typename Alloc >
casacore::Array< T, Alloc >::Array ( Array< T, Alloc > &&  source)
noexcept

Source will be empty after this call.

◆ Array() [8/13]

template<typename T , typename Alloc >
casacore::Array< T, Alloc >::Array ( const IPosition shape,
T *  storage,
StorageInitPolicy  policy = COPY,
const Alloc &  allocator = Alloc() 
)

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 the specified allocator.

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);
long long product() const
Returns 0 if nelements() == 0, otherwise it returns the product of its elements.
@ TAKE_OVER
TAKE_OVER is used to indicate that the Array should just use the external storage (i....
Definition: ArrayBase.h:59
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.

◆ Array() [9/13]

template<typename T , typename Alloc >
casacore::Array< T, Alloc >::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>.

◆ Array() [10/13]

template<typename T , typename Alloc >
template<typename InputIterator >
casacore::Array< T, Alloc >::Array ( const IPosition shape,
InputIterator  startIter,
const Alloc &  allocator = Alloc() 
)

Construct an array from an iterator and a shape.

◆ ~Array()

template<typename T , typename Alloc >
virtual casacore::Array< T, Alloc >::~Array ( )
virtualnoexcept

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

◆ Array() [11/13]

template<typename T , typename Alloc >
template<typename Integral >
casacore::Array< T, Alloc >::Array ( const IPosition shape,
Integral  startIter,
const Alloc &  allocator,
std::true_type   
)
private

Implementation of constructor taking a Shape, a Templated parameter and an allocator.

This method implements it for when T is integral, in which case the templated parameter is the initial value.

◆ Array() [12/13]

template<typename T , typename Alloc >
template<typename InputIterator >
casacore::Array< T, Alloc >::Array ( const IPosition shape,
InputIterator  startIter,
const Alloc &  allocator,
std::false_type   
)
private

Implementation of constructor taking a Shape, a Templated parameter and an allocator.

This method implements it for when T is NOT integral, in which case the templated parameter is an iterator.

◆ Array() [13/13]

template<typename T , typename Alloc >
casacore::Array< T, Alloc >::Array ( Array< T, Alloc > &&  source,
const IPosition shapeForSource 
)
protectednoexcept

Source will be empty with given shape after this call.

Member Function Documentation

◆ addDegenerate() [1/2]

template<typename T , typename Alloc >
Array<T, Alloc> casacore::Array< T, Alloc >::addDegenerate ( size_t  numAxes)

◆ addDegenerate() [2/2]

template<typename T , typename Alloc >
const Array<T, Alloc> casacore::Array< T, Alloc >::addDegenerate ( size_t  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.

◆ adjustLastAxis()

template<typename T , typename Alloc >
bool casacore::Array< T, Alloc >::adjustLastAxis ( const IPosition newShape,
size_t  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.

◆ allocator() [1/2]

template<typename T , typename Alloc >
Alloc& casacore::Array< T, Alloc >::allocator ( )
inline

Retrieve the allocator associated with this array.

Definition at line 234 of file Array.h.

References casacore::Array< T, Alloc >::data_p.

◆ allocator() [2/2]

template<typename T , typename Alloc >
const Alloc& casacore::Array< T, Alloc >::allocator ( ) const
inline

Definition at line 235 of file Array.h.

References casacore::Array< T, Alloc >::data_p.

◆ apply()

template<typename T , typename Alloc >
template<typename Callable >
void casacore::Array< T, Alloc >::apply ( Callable  function)

Apply the function to every element of the array.

This modifies the array in place. (TODO this version made the other versions of apply() redundant)

◆ assign()

template<typename T , typename Alloc >
void casacore::Array< T, Alloc >::assign ( const Array< T, Alloc > &  other)

Assign the other array to this array.

If the shapes mismatch, this array is resized.

◆ assign_conforming() [1/2]

template<typename T , typename Alloc >
Array<T, Alloc>& casacore::Array< T, Alloc >::assign_conforming ( const Array< T, Alloc > &  other)
inline

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.

Definition at line 285 of file Array.h.

References casacore::Array< T, Alloc >::assign_conforming_implementation().

Referenced by casacore::Matrix< T, Alloc >::assign_conforming(), and casacore::Array< T, Alloc >::operator=().

◆ assign_conforming() [2/2]

template<typename T , typename Alloc >
template<typename MaskAlloc >
Array<T, Alloc>& casacore::Array< T, Alloc >::assign_conforming ( const MaskedArray< T, Alloc, MaskAlloc > &  marray)

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

Thrown Exceptions

◆ assign_conforming_implementation() [1/2]

template<typename T , typename Alloc >
Array<T, Alloc>& casacore::Array< T, Alloc >::assign_conforming_implementation ( const Array< T, Alloc > &  ,
std::false_type   
)
inlineprivate

Implementation for assign for non-copyable types: can not be assigned.

Definition at line 903 of file Array.h.

◆ assign_conforming_implementation() [2/2]

template<typename T , typename Alloc >
Array<T, Alloc>& casacore::Array< T, Alloc >::assign_conforming_implementation ( const Array< T, Alloc > &  other,
std::true_type   
)
private

Implementation for assign for copyable types.

Referenced by casacore::Array< T, Alloc >::assign_conforming().

◆ assignBase()

template<typename T , typename Alloc >
void casacore::Array< T, Alloc >::assignBase ( const ArrayBase source,
bool  checkType = true 
)
overridevirtual

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.

◆ begin() [1/2]

template<typename T , typename Alloc >
iterator casacore::Array< T, Alloc >::begin ( )
inline

◆ begin() [2/2]

template<typename T , typename Alloc >
const_iterator casacore::Array< T, Alloc >::begin ( ) const
inline

Definition at line 861 of file Array.h.

◆ capacity()

template<typename T , typename Alloc >
size_t casacore::Array< T, Alloc >::capacity ( ) const

Returns the number of elements allocated.

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

◆ cbegin() [1/2]

template<typename T , typename Alloc >
contiter casacore::Array< T, Alloc >::cbegin ( )
inline

◆ cbegin() [2/2]

template<typename T , typename Alloc >
const_contiter casacore::Array< T, Alloc >::cbegin ( ) const
inline

Definition at line 873 of file Array.h.

References casacore::Array< T, Alloc >::begin_p.

◆ cend() [1/2]

template<typename T , typename Alloc >
contiter casacore::Array< T, Alloc >::cend ( )
inline

◆ cend() [2/2]

template<typename T , typename Alloc >
const_contiter casacore::Array< T, Alloc >::cend ( ) const
inline

Definition at line 877 of file Array.h.

References casacore::Array< T, Alloc >::end_p.

◆ checkAssignableType()

template<typename T , typename Alloc >
virtual void casacore::Array< T, Alloc >::checkAssignableType ( ArrayBase arrayBase) const
inlineprotectedvirtual

Definition at line 958 of file Array.h.

References casacore::pa().

◆ checkBeforeResize()

template<typename T , typename Alloc >
void casacore::Array< T, Alloc >::checkBeforeResize ( const IPosition newShape)
inlineprotected

This function is called when this array is about to be resized, before any work is done.

Subclasses can throw an exception if the size doesn't match, e.g. if a Matrix is resized to have 3 dimensions. Before this function existed, assign-like functions had to be virtual. However, for non-copyable types, assign can't exist. This is fine for non-virtual methods (they just can't be called), but virtual methods cause the who class to fail to be instantiatable.

Definition at line 942 of file Array.h.

References casacore::Array< T, Alloc >::fixedDimensionality(), casacore::IPosition::size(), and casacore::to_string().

◆ conform() [1/2]

template<typename T , typename Alloc >
bool casacore::Array< T, Alloc >::conform ( const Array< T, Alloc > &  other) const
inline

Are the shapes identical?

Definition at line 596 of file Array.h.

References casacore::ArrayBase::conform2().

◆ conform() [2/2]

template<typename T , typename Alloc >
bool casacore::Array< T, Alloc >::conform ( const MaskedArray< T > &  other) const

◆ copy() [1/2]

template<typename T , typename Alloc >
Array<T, Alloc> casacore::Array< T, Alloc >::copy ( ) const
inline

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());
//..\.
}
LatticeExprNode arg(const LatticeExprNode &expr)

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?)

TODO deprecate

Definition at line 341 of file Array.h.

◆ copy() [2/2]

template<typename T , typename Alloc >
Array<T, Alloc> casacore::Array< T, Alloc >::copy ( const Alloc &  allocator) const
private

Makes a copy using the allocator.

◆ copyMatchingPart()

template<typename T , typename Alloc >
void casacore::Array< T, Alloc >::copyMatchingPart ( const Array< T, Alloc > &  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.

◆ copyToContiguousStorage() [1/3]

template<typename T , typename Alloc >
static void casacore::Array< T, Alloc >::copyToContiguousStorage ( T *  ,
Array< T, Alloc > const &  ,
std::false_type   
)
inlinestaticprivate

Definition at line 908 of file Array.h.

◆ copyToContiguousStorage() [2/3]

template<typename T , typename Alloc >
static void casacore::Array< T, Alloc >::copyToContiguousStorage ( T *  dst,
Array< T, Alloc > const &  src 
)
inlinestaticprotected

Definition at line 966 of file Array.h.

References casacore::Array< T, Alloc >::copyToContiguousStorage().

◆ copyToContiguousStorage() [3/3]

template<typename T , typename Alloc >
static void casacore::Array< T, Alloc >::copyToContiguousStorage ( T *  dst,
Array< T, Alloc > const &  src,
std::true_type   
)
staticprivate

◆ data() [1/2]

template<typename T , typename Alloc >
T* casacore::Array< T, Alloc >::data ( )
inline

◆ data() [2/2]

template<typename T , typename Alloc >
const T* casacore::Array< T, Alloc >::data ( ) const
inline

Definition at line 606 of file Array.h.

References casacore::Array< T, Alloc >::begin_p.

◆ diagonals()

template<typename T , typename Alloc >
Array<T, Alloc> casacore::Array< T, Alloc >::diagonals ( size_t  firstAxis = 0,
long long  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.

◆ doNonDegenerate()

template<typename T , typename Alloc >
virtual void casacore::Array< T, Alloc >::doNonDegenerate ( const Array< T, Alloc > &  other,
const IPosition ignoreAxes 
)
protectedvirtual

Remove the degenerate axes from the Array object.

This is the implementation of the nonDegenerate functions. It has a different name to be able to make it virtual without having the "hide virtual function" message when compiling derived classes.

Reimplemented in casacore::Matrix< T, Alloc >, and casacore::Matrix< T >.

Referenced by casacore::Array< T, Alloc >::nonDegenerate().

◆ end() [1/2]

template<typename T , typename Alloc >
iterator casacore::Array< T, Alloc >::end ( )
inline

◆ end() [2/2]

template<typename T , typename Alloc >
const_iterator casacore::Array< T, Alloc >::end ( ) const
inline

Definition at line 865 of file Array.h.

References casacore::Array< T, Alloc >::end_p.

◆ fixedDimensionality()

template<typename T , typename Alloc >
virtual size_t casacore::Array< T, Alloc >::fixedDimensionality ( ) const
inlineprotectedvirtual

Subclasses can return their dimensionality.

The Array class will make sure that whenever it is resized, the dimensionality is checked. Array's constructors do not check the dimensionality, because the subclass hasn't been created yet at that point. Subclasses should therefore make sure to call the constructors appropriately. For classes that return 0, any resize will be allowed.

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

Definition at line 956 of file Array.h.

Referenced by casacore::Array< T, Alloc >::checkBeforeResize().

◆ freeStorage()

template<typename T , typename Alloc >
void casacore::Array< T, Alloc >::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. TODO this function can not be const for stateful allocators

◆ freeVStorage()

template<typename T , typename Alloc >
void casacore::Array< T, Alloc >::freeVStorage ( const void *&  storage,
bool  deleteIt 
) const
overridevirtual

Reimplemented from casacore::ArrayBase.

◆ getSection()

template<typename T , typename Alloc >
std::unique_ptr<ArrayBase> casacore::Array< T, Alloc >::getSection ( const Slicer ) const
overridevirtual

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.

◆ getStorage() [1/2]

template<typename T , typename Alloc >
T* casacore::Array< T, Alloc >::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::ArrayMath_global_functions_Array_mathematical_operations::expandArray(), and casacore::Array< T, Alloc >::getStorage().

◆ getStorage() [2/2]

template<typename T , typename Alloc >
const T* casacore::Array< T, Alloc >::getStorage ( bool &  deleteIt) const
inline

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

Definition at line 632 of file Array.h.

References casacore::Array< T, Alloc >::getStorage().

◆ getVStorage() [1/2]

template<typename T , typename Alloc >
const void* casacore::Array< T, Alloc >::getVStorage ( bool &  deleteIt) const
overridevirtual

Reimplemented from casacore::ArrayBase.

◆ getVStorage() [2/2]

template<typename T , typename Alloc >
void* casacore::Array< T, Alloc >::getVStorage ( bool &  deleteIt)
overridevirtual

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.

◆ isUnique()

template<typename T , typename Alloc >
bool casacore::Array< T, Alloc >::isUnique ( ) const
inlineprivate

An Array is unique when the container is shared and when nrefs==1.

Definition at line 914 of file Array.h.

References casacore::Array< T, Alloc >::data_p, and casacore::Array< T, Alloc >::nrefs().

◆ makeArray()

template<typename T , typename Alloc >
virtual std::unique_ptr<ArrayBase> casacore::Array< T, Alloc >::makeArray ( ) const
overridevirtual

Make an empty array of the same template type.

Reimplemented from casacore::ArrayBase.

◆ makeIterator()

template<typename T , typename Alloc >
std::unique_ptr<ArrayPositionIterator> casacore::Array< T, Alloc >::makeIterator ( size_t  byDim) const
overridevirtual

Create an ArrayIterator object of the correct type.

Reimplemented from casacore::ArrayBase.

◆ makeSteps()

template<typename T , typename Alloc >
void casacore::Array< T, Alloc >::makeSteps ( )
inlineprotected

Fill the steps and the end for a derived class.

Definition at line 993 of file Array.h.

References casacore::ArrayBase::baseMakeSteps(), and casacore::Array< T, Alloc >::setEndIter().

◆ nonDegenerate() [1/4]

template<typename T , typename Alloc >
void casacore::Array< T, Alloc >::nonDegenerate ( const Array< T, Alloc > &  other,
const IPosition ignoreAxes 
)
inline

Definition at line 473 of file Array.h.

References casacore::Array< T, Alloc >::doNonDegenerate().

◆ nonDegenerate() [2/4]

template<typename T , typename Alloc >
void casacore::Array< T, Alloc >::nonDegenerate ( const Array< T, Alloc > &  other,
size_t  startingAxis = 0,
bool  throwIfError = true 
)

◆ nonDegenerate() [3/4]

template<typename T , typename Alloc >
Array<T, Alloc> casacore::Array< T, Alloc >::nonDegenerate ( const IPosition ignoreAxes) const

◆ nonDegenerate() [4/4]

template<typename T , typename Alloc >
Array<T, Alloc> casacore::Array< T, Alloc >::nonDegenerate ( size_t  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;

◆ nrefs()

template<typename T , typename Alloc >
size_t casacore::Array< T, Alloc >::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. NB: Even when nrefs()==1, the array might be shared, because the the storage itself might be shared. Therefore, this function should not be used outside debugging. TODO make protected.

Referenced by casacore::Array< T, Alloc >::isUnique().

◆ ok()

template<typename T , typename Alloc >
virtual bool casacore::Array< T, Alloc >::ok ( ) const
overridevirtual

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::Matrix< T, Alloc >, casacore::Matrix< casacore::SquareMatrix< Complex, 2 > >, casacore::Matrix< Float >, casacore::Matrix< casacore::GaussianBeam >, casacore::Matrix< Double >, casacore::Matrix< T >, casacore::Matrix< Int >, casacore::Matrix< Int64 >, casacore::Matrix< FType >, casacore::Matrix< Bool >, casacore::Matrix< Complex >, casacore::Cube< T, Alloc >, casacore::Cube< Double >, casacore::Cube< casacore::RigidVector< Double, 2 > >, casacore::Vector< T, Alloc >, casacore::Vector< Quantum< Double > >, casacore::Vector< casacore::SquareMatrix< Complex, 2 > >, casacore::Vector< casacore::MPosition >, casacore::Vector< Float >, casacore::Vector< double >, casacore::Vector< Double >, casacore::Vector< casacore::Vector< Range > >, casacore::Vector< T >, casacore::Vector< Int >, casacore::Vector< casacore::Unit >, casacore::Vector< rownr_t >, casacore::Vector< Int64 >, casacore::Vector< casacore::MDirection >, casacore::Vector< casacore::MFrequency >, casacore::Vector< casacore::RORecordFieldPtr< Double > >, casacore::Vector< size_t >, casacore::Vector< FType >, casacore::Vector< Bool >, casacore::Vector< typename casacore::FunctionTraits< T >::BaseType >, casacore::Vector< typename casacore::FunctionTraits< T >::ArgType >, casacore::Vector< casacore::Slicer * >, casacore::Vector< casacore::Quantum< Double > >, casacore::Vector< casacore::MeasComet * >, casacore::Vector< Domain >, casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< T >::BaseType >::base > >, casacore::Vector< uInt >, casacore::Vector< ArgType >, and casacore::Vector< casacore::String >.

◆ operator()() [1/12]

template<typename T , typename Alloc >
T& casacore::Array< T, Alloc >::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).

Referenced by casacore::Cube< T, Alloc >::operator()(), casacore::Matrix< T, Alloc >::operator()(), and casacore::Vector< T, Alloc >::operator()().

◆ operator()() [2/12]

template<typename T , typename Alloc >
const T& casacore::Array< T, Alloc >::operator() ( const IPosition ) const

◆ operator()() [3/12]

template<typename T , typename Alloc >
Array<T, Alloc> casacore::Array< T, Alloc >::operator() ( const IPosition start,
const IPosition end 
)

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

◆ operator()() [4/12]

template<typename T , typename Alloc >
const Array<T, Alloc> casacore::Array< T, Alloc >::operator() ( const IPosition start,
const IPosition end 
) const

◆ operator()() [5/12]

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

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

◆ operator()() [6/12]

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

◆ operator()() [7/12]

template<typename T , typename Alloc >
MaskedArray<T> casacore::Array< T, Alloc >::operator() ( const LogicalArray< T, Alloc > &  mask)

◆ operator()() [8/12]

template<typename T , typename Alloc >
const MaskedArray<T> casacore::Array< T, Alloc >::operator() ( const LogicalArray< T, Alloc > &  mask) const

The array is masked by the input LogicalArray.

This mask must conform to the array.

◆ operator()() [9/12]

template<typename T , typename Alloc >
MaskedArray<T> casacore::Array< T, Alloc >::operator() ( const MaskedLogicalArray< T, Alloc > &  mask)

◆ operator()() [10/12]

template<typename T , typename Alloc >
const MaskedArray<T> casacore::Array< T, Alloc >::operator() ( const MaskedLogicalArray< T, Alloc > &  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.

◆ operator()() [11/12]

template<typename T , typename Alloc >
Array<T, Alloc> casacore::Array< T, Alloc >::operator() ( const Slicer )

Get a reference to an array section using a Slicer.

◆ operator()() [12/12]

template<typename T , typename Alloc >
const Array<T, Alloc> casacore::Array< T, Alloc >::operator() ( const Slicer ) const

◆ operator=() [1/4]

template<typename T , typename Alloc >
Array<T, Alloc>& casacore::Array< T, Alloc >::operator= ( Array< T, Alloc > &&  other)

The move operator takes the storage from the given array.

After moving an Array, the source Array will be left empty.

◆ operator=() [2/4]

template<typename T , typename Alloc >
Array<T, Alloc>& casacore::Array< T, Alloc >::operator= ( const Array< T, Alloc > &  other)
inline

TODO we should change the semantics.

Definition at line 300 of file Array.h.

References casacore::Array< T, Alloc >::assign_conforming().

Referenced by casacore::Cube< T, Alloc >::operator=(), and casacore::Matrix< T, Alloc >::operator=().

◆ operator=() [3/4]

template<typename T , typename Alloc >
template<typename MaskAlloc >
Array<T, Alloc>& casacore::Array< T, Alloc >::operator= ( const MaskedArray< T, Alloc, MaskAlloc > &  marray)
inline

◆ operator=() [4/4]

template<typename T , typename Alloc >
Array<T, Alloc>& casacore::Array< T, Alloc >::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.

◆ operator[]()

template<typename T , typename Alloc >
Array<T, Alloc> casacore::Array< T, Alloc >::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;

◆ postTakeStorage()

template<typename T , typename Alloc >
virtual void casacore::Array< T, Alloc >::postTakeStorage ( )
inlineprotectedvirtual

Definition at line 933 of file Array.h.

◆ preTakeStorage()

template<typename T , typename Alloc >
virtual void casacore::Array< T, Alloc >::preTakeStorage ( const IPosition )
inlineprotectedvirtual

◆ putStorage()

template<typename T , typename Alloc >
void casacore::Array< T, Alloc >::putStorage ( T *&  storage,
bool  deleteAndCopy 
)

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

The "storage" pointer is set to zero.

Referenced by casacore::ArrayMath_global_functions_Array_mathematical_operations::expandArray().

◆ putVStorage()

template<typename T , typename Alloc >
void casacore::Array< T, Alloc >::putVStorage ( void *&  storage,
bool  deleteAndCopy 
)
overridevirtual

Reimplemented from casacore::ArrayBase.

◆ reference()

template<typename T , typename Alloc >
virtual void casacore::Array< T, Alloc >::reference ( const Array< T, Alloc > &  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.

Referenced by casacore::ArrayMath_global_functions_Array_mathematical_operations::expandArray(), casacore::MArray< T >::MArray(), casacore::MArray< T >::reference(), and casacore::MArrayMath_global_functions_MArray_mathematical_operations::slidingArrayMath().

◆ reform()

template<typename T , typename Alloc >
Array<T, Alloc> casacore::Array< T, Alloc >::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"
TableExprNode square(const TableExprNode &node)
Definition: ExprNode.h:1346

Referenced by casacore::ArrayMath_global_functions_Array_mathematical_operations::expandArray(), and casacore::TableExprNodeSet::toArray().

◆ reformOrResize()

template<typename T , typename Alloc >
bool casacore::Array< T, Alloc >::reformOrResize ( const IPosition newShape,
size_t  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.

◆ removeDegenerate() [1/2]

template<typename T , typename Alloc >
void casacore::Array< T, Alloc >::removeDegenerate ( const IPosition ignoreAxes)

◆ removeDegenerate() [2/2]

template<typename T , typename Alloc >
void casacore::Array< T, Alloc >::removeDegenerate ( size_t  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.

◆ resize() [1/2]

template<typename T , typename Alloc >
void casacore::Array< T, Alloc >::resize ( )

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.

Referenced by casacore::MArray< T >::fill(), casacore::TableExprGroupAggr::getArray(), casacore::MArrayBase::removeMask(), casacore::MArray< T >::resize(), casacore::Vector< T, Alloc >::resize(), and casacore::TableExprNodeSet::toArray().

◆ resize() [2/2]

template<typename T , typename Alloc >
void casacore::Array< T, Alloc >::resize ( const IPosition newShape,
bool  copyValues = false 
)
overridevirtual

◆ set()

template<typename T , typename Alloc >
void casacore::Array< T, Alloc >::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.

◆ setEndIter()

template<typename T , typename Alloc >
void casacore::Array< T, Alloc >::setEndIter ( )
inlineprotected

◆ swap()

template<typename T , typename Alloc >
void casacore::Array< T, Alloc >::swap ( Array< T, Alloc > &  other)
protected

Swap this array with another array.

Normally, casacore::swap() should be used instead.

◆ takeStorage() [1/2]

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

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

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

◆ takeStorage() [2/2]

template<typename T , typename Alloc >
virtual void casacore::Array< T, Alloc >::takeStorage ( const IPosition shape,
T *  storage,
StorageInitPolicy  policy = COPY,
const Alloc &  allocator = Alloc() 
)
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 allocator. If policy is TAKE_OVER, storage will be destructed and released by allocator.

◆ tovector() [1/2]

template<typename T , typename Alloc >
std::vector<T> casacore::Array< T, Alloc >::tovector ( ) const

◆ tovector() [2/2]

template<typename T , typename Alloc >
template<class U >
void casacore::Array< T, Alloc >::tovector ( std::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.

◆ unique()

template<typename T , typename Alloc >
void casacore::Array< T, Alloc >::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();
virtual void reference(const Array< T, Alloc > &other)
After invocation, this array and other reference the same storage.
void unique()
This ensures that this array does not reference any other storage.


Friends And Related Function Documentation

◆ ArrayIterator< T, Alloc >

template<typename T , typename Alloc >
friend class ArrayIterator< T, Alloc >
friend

Used to iterate through Arrays.

Derived classes VectorIterator and MatrixIterator are probably more useful.

Definition at line 666 of file Array.h.

◆ swap

template<typename T , typename Alloc >
template<typename ST , typename SAlloc >
void swap ( Array< ST, SAlloc > &  left,
Array< ST, SAlloc > &  right 
)
friend

Member Data Documentation

◆ begin_p

template<typename T , typename Alloc >
T* casacore::Array< T, Alloc >::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 986 of file Array.h.

Referenced by casacore::Array< T, Alloc >::cbegin(), casacore::Array< T, Alloc >::data(), casacore::Matrix< T, Alloc >::operator()(), casacore::Cube< T, Alloc >::operator()(), casacore::Vector< T, Alloc >::operator()(), casacore::Vector< T, Alloc >::operator[](), and casacore::Array< T, Alloc >::setEndIter().

◆ data_p

template<typename T , typename Alloc >
std::shared_ptr<arrays_internal::Storage<T, Alloc> > casacore::Array< T, Alloc >::data_p
protected

Shared pointer to a Storage that contains the data.

Definition at line 980 of file Array.h.

Referenced by casacore::Array< T, Alloc >::allocator(), and casacore::Array< T, Alloc >::isUnique().

◆ end_p

template<typename T , typename Alloc >
T* casacore::Array< T, Alloc >::end_p
protected

The end for an STL-style iteration.

Definition at line 989 of file Array.h.

Referenced by casacore::Array< T, Alloc >::cend(), and casacore::Array< T, Alloc >::end().

◆ uninitialized

template<typename T , typename Alloc >
struct casacore::Array::uninitializedType casacore::Array< T, Alloc >::uninitialized
static

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