Loading...
Searching...
No Matches
casacore::Array< T > Class Template Reference
casa package (libcasa_casa) » Arrays_module

More...

`#include <Array.h>`

## Classes

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

## Public Types

typedef T | value_type
| Define the STL-style iterator functions (only forward iterator).
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.
typedef T * | pointer
| Pointer to an element type.
typedef const T * | const_pointer
| Constant pointer to the element type.
typedef IteratorSTL | iterator
typedef ConstIteratorSTL | const_iterator
typedef T * | contiter
typedef const T * | const_contiter

## Public Member Functions

| Array ()
| Result has dimensionality of zero, and nelements is zero.
| Array (const IPosition &shape)
| Create an array of the given shape, i.e.
| Array (const IPosition &shape, const T &initialValue)
| Create an array of the given shape and initialize it with the initial value.
| Array (const IPosition &shape, uninitializedType)
| Constructor to create an uninitialized array.
| Array (std::initializer_list< T > list)
| Construct a one-dimensional array from an initializer list.
| Array (const Array< T > &other)
| After construction, this and other reference the same storage.
| Array (Array< T > &&source) noexcept
| Source will be empty after this call.
| Array (const IPosition &shape, T *storage, StorageInitPolicy policy=COPY)
| Create an Array of a given shape from a pointer.
| Array (const IPosition &shape, const T *storage)
| Create an Array of a given shape from a pointer.
template<typename InputIterator>
| Array (const IPosition &shape, InputIterator startIter)
| Construct an array from an iterator and a shape.
virtual | ~Array () noexcept
| Frees up storage only if this array was the last reference to it.
virtual std::unique_ptr< ArrayBase > | makeArray () const override
| Make an empty array of the same template type.
void | assign (const Array< T > &other)
| Assign the other array to this array.
void | assignBase (const ArrayBase &other, bool checkType=true) override
| Assign the source array to this array.
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.
template<typename Callable>
void | apply (Callable function)
| Apply the function to every element of the array.
virtual void | reference (const Array< T > &other)
| After invocation, this array and other reference the same storage.
Array< T > & | assign_conforming (const Array< T > &other)
| Copy the values in other to this.
Array< T > & | assign_conforming (const MaskedArray< T > &marray)
| Copy to this those values in marray whose corresponding elements in marray's mask are true.
Array< T > & | operator= (const Array< T > &other)
| TODO we should change the semantics.
Array< T > & | operator= (const MaskedArray< T > &marray)
| Calls assign_conforming().
Array< T > & | operator= (Array< T > &&other)
| The move operator takes the storage from the given array.
Array< T > & | operator= (const T &value)
| Set every element of this array to "value".
Array< T > | copy () const
| This makes a copy of the array and returns it.
void | copyMatchingPart (const Array< T > &from)
| This function copies the matching part of from array to this array.
void | unique ()
| This ensures that this array does not reference any other storage.
template<class U>
void | tovector (std::vector< T, U > &out) const
| Create an STL vector from an Array.
std::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.
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.
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.
size_t | capacity () const
| Returns the number of elements allocated.
Array< T > | nonDegenerate (size_t startingAxis=0, bool throwIfError=true) const
| These member functions remove degenerate (ie.
Array< T > | nonDegenerate (const IPosition &ignoreAxes) const
void | nonDegenerate (const Array< T > &other, size_t startingAxis=0, bool throwIfError=true)
void | nonDegenerate (const Array< T > &other, const IPosition &ignoreAxes)
void | removeDegenerate (size_t startingAxis=0, bool throwIfError=true)
| Remove degenerate axes from this Array object.
void | removeDegenerate (const IPosition &ignoreAxes)
const Array< T > | 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.
Array< T > | addDegenerate (size_t numAxes)
void | resize ()
| Make this array a different shape.
void | resize (const IPosition &newShape, bool copyValues=false) override
| Resize the array and optionally copy the values.
T & | operator() (const IPosition &)
| Access a single element of the array.
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).
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.
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.
const Array< T > | operator() (const Slicer &) const
std::unique_ptr< ArrayBase > | getSection (const Slicer &) const override
| Get a reference to a section of an array.
Array< T > | operator[] (size_t i) const
| Get the subset given by the i-th value of the last axis.
Array< T > | diagonals (size_t firstAxis=0, long long diag=0) const
| Get the diagonal of each matrix part in the full array.
const MaskedArray< T > | operator() (const LogicalArray &mask) const
| The array is masked by the input LogicalArray.
MaskedArray< T > | operator() (const LogicalArray &mask)
const MaskedArray< T > | operator() (const MaskedLogicalArray &mask) const
| The array is masked by the input MaskedLogicalArray.
MaskedArray< T > | operator() (const MaskedLogicalArray &mask)
size_t | nrefs () const
| The number of references the underlying storage has assigned to it.
virtual bool | ok () const override
| Check to see if the Array is consistent.
bool | conform (const Array< T > &other) const
| Are the shapes identical?
bool | conform (const MaskedArray< T > &other) const
T * | data ()
| Get a pointer to the beginning of the array.
const T * | data () const
T * | getStorage (bool &deleteIt)
| Generally use of this should be shunned, except to use a FORTRAN routine or something similar.
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.
const void * | getVStorage (bool &deleteIt) const override
void | putStorage (T *&storage, bool deleteAndCopy)
| putStorage() is normally called after a call to getStorage() (cf).
void | putVStorage (void *&storage, bool deleteAndCopy) override
void | freeStorage (const T *&storage, bool deleteIt) const
| If deleteIt is set, delete "storage".
void | freeVStorage (const void *&storage, bool deleteIt) const override
virtual void | takeStorage (const IPosition &shape, T *storage, StorageInitPolicy policy=COPY)
| Replace the data values with those in the pointer storage.
virtual void | takeStorage (const IPosition &shape, const T *storage)
| Since the pointer is const, a copy is always taken.
std::unique_ptr< ArrayPositionIterator > | makeIterator (size_t byDim) const override
| Create an ArrayIterator object of the correct type.
iterator | begin ()
| Get the begin iterator object for any array.
const_iterator | begin () const
iterator | end ()
const_iterator | end () const
contiter | cbegin ()
| Get the begin iterator object for a contiguous array.
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.
| ArrayBase (const ArrayBase &other)
| Copy constructor.
| ArrayBase (ArrayBase &&source) noexcept
ArrayBase & | assign (const ArrayBase &)
| Assignment.
ArrayBase & | operator= (const ArrayBase &)=delete
ArrayBase & | operator= (ArrayBase &&) noexcept
virtual | ~ArrayBase () noexcept
| Destructor.
size_t | ndim () const
| The dimensionality of this array.
size_t | nelements () const
| How many elements does this array have?
size_t | size () const
bool | empty () const
| Is the array empty (i.e.
bool | contiguousStorage () const
| Are the array data contiguous?
const IPosition & | shape () const
| The length of each axis.
IPosition | endPosition () const
| A convenience function: endPosition(i) = shape(i) - 1; i.e.
const IPosition & | steps () const
| Return steps to be made if stepping one element in a dimension.
void | validateConformance (const ArrayBase &) const
| Various helper functions.
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 > &&source, const IPosition &shapeForSource) noexcept
| Source will be empty with given shape after this call.
void | swap (Array< T > &other)
| Swap this array with another array.
virtual void | preTakeStorage (const IPosition &)
| pre/post processing hook of takeStorage() for subclasses.
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.
virtual size_t | fixedDimensionality () const
| Subclasses can return their dimensionality.
virtual void | checkAssignableType (ArrayBase &arrayBase) const
virtual void | doNonDegenerate (const Array< T > &other, const IPosition &ignoreAxes)
| Remove the degenerate axes from the Array object.
void | makeSteps ()
| Fill the steps and the end for a derived class.
void | setEndIter ()
| Set the end iterator.
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.
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.
bool | isStorageContiguous () const
| Determine if the storage of a subset is contiguous.
void | checkVectorShape ()
| Check if the shape of a vector is correct.
void | checkMatrixShape ()
| Check if the shape of a matrix is correct.
void | checkCubeShape ()
| Check if the shape of a cube is correct.
void | baseReform (ArrayBase &tmp, const IPosition &shape, bool strict=true) const
| Reform the array to a shape with the same nr of elements.
void | baseNonDegenerate (const ArrayBase &other, const IPosition &ignoreAxes)
| Remove the degenerate axes from the Array object.
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.
size_t | makeSubset (ArrayBase &out, const IPosition &b, const IPosition &e, const IPosition &i)
| Make a subset of an array.
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.
bool | conform2 (const ArrayBase &other) const
| Are the shapes identical?
void | baseMakeSteps ()
| Make the indexing step sizes.
bool | copyVectorHelper (const ArrayBase &other)
| Helper function for templated Vector class.

## Static Protected Member Functions

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

## Protected Attributes

std::shared_ptr< arrays_internal::Storage< T > > | data_p
| Shared pointer to a Storage that contains the data.
T * | begin_p
| This pointer is adjusted to point to the first element of the array.
T * | end_p
| The end for an STL-style iteration.
Protected Attributes inherited from casacore::ArrayBase
size_t | nels_p
| Number of elements in the array.
size_t | ndimen_p
| Dimensionality of the array.
bool | contiguous_p
| Are the data contiguous?
IPosition | length_p
| Used to hold the shape, increment into the underlying storage and originalLength of the array.
IPosition | inc_p
IPosition | originalLength_p
IPosition | steps_p
| Used to hold the step to next element in each dimension.

## Private Member Functions

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

## Static Private Member Functions

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

## Friends

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

## Additional Inherited Members

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

## Detailed Description

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

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 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]
//..\.
casacore::Array::Array
Array()
Result has dimensionality of zero, and nelements is zero.
casacore::IPosition
Definition IPosition.h:117

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.
casacore::Array::reference
virtual void reference(const Array< T > &other)
After invocation, this array and other reference the same storage.
casacore::Cube
Definition Cube.h:72
casacore::Cube::xyPlane
Matrix< T > xyPlane(size_t zplane)
Extract a plane as a matrix referencing the original data.

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);
casacore::offset
int offset(int, int) const
compute a linear offset from array indicies
casacore::array
T * array
The actual storage.
Definition Block.h:689

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

- Integrate into the Lattice hierarchy
- Factor out the common functions (shape etc) into a type-independent base class.

Definition at line 154 of file Array.h.

## Member Typedef Documentation

## const_contiter

template<typename T>

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

Definition at line 840 of file Array.h.

## const_iterator

template<typename T>

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

Definition at line 838 of file Array.h.

## const_pointer

template<typename T>

typedef const T* casacore::Array< T >::const_pointer

Constant pointer to the element type.

Definition at line 836 of file Array.h.

## const_reference

template<typename T>

typedef const T& casacore::Array< T >::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 832 of file Array.h.

## contiter

template<typename T>

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

Definition at line 839 of file Array.h.

## iterator

template<typename T>

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

Definition at line 837 of file Array.h.

## pointer

template<typename T>

typedef T* casacore::Array< T >::pointer

Pointer to an element type.

Definition at line 834 of file Array.h.

## value_type

template<typename 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;
}
casacore::ArrayBase::shape
const IPosition & shape() const
The length of each axis.
Definition ArrayBase.h:123
casacore::Array::iterator
IteratorSTL iterator
Definition Array.h:837

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.

Element type

Definition at line 828 of file Array.h.

## Constructor & Destructor Documentation

## Array() [1/13]

template<typename T>

casacore::Array< T >::Array | ( |  | ) |

Result has dimensionality of zero, and nelements is zero.

Referenced by casacore::Array< T >::BaseIteratorSTL::BaseIteratorSTL(), casacore::Array< T >::ConstIteratorSTL::ConstIteratorSTL(), and casacore::Array< T >::IteratorSTL::IteratorSTL().

## Array() [2/13]

template<typename 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,

## Array() [3/13]

template<typename 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>.

## Array() [4/13]

template<typename T>

casacore::Array< T >::Array | ( | const IPosition & | shape,
|  | uninitializedType | )

Constructor to create an uninitialized array.

This constructor can for example be called with:

Array<int> a(shape, Array<int>::uninitialized);
casacore::Array::uninitialized
static struct casacore::Array::uninitializedType uninitialized

## Array() [5/13]

template<typename T>

casacore::Array< T >::Array | ( | std::initializer_list< T > | list | ) |

Construct a one-dimensional array from an initializer list.

Example:

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

## Array() [6/13]

template<typename T>

casacore::Array< T >::Array | ( | const Array< T > & | other | ) |

After construction, this and other reference the same storage.

## Array() [7/13]

template<typename T>

casacore::Array< T >::Array | ( | Array< T > && | source | ) |

noexcept

Source will be empty after this call.

## Array() [8/13]

template<typename 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 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);
casacore::DefaultAllocator
An aligned allocator with the default alignment.
Definition Allocator.h:386
casacore::TAKE_OVER
@ TAKE_OVER
TAKE_OVER is used to indicate that the Array should just use the external storage (i....
Definition ArrayBase.h:57

## Array() [9/13]

template<typename 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>.

## Array() [10/13]

template<typename T>
template<typename InputIterator>

casacore::Array< T >::Array | ( | const IPosition & | shape,
|  | InputIterator | startIter )

Construct an array from an iterator and a shape.

## ~Array()

template<typename T>

virtual casacore::Array< T >::~Array | ( |  | ) |

virtual noexcept

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

## Array() [11/13]

template<typename T>
template<typename Integral>

casacore::Array< T >::Array | ( | const IPosition & | shape,
|  | Integral | startIter,
|  | 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>
template<typename InputIterator>

casacore::Array< T >::Array | ( | const IPosition & | shape,
|  | InputIterator | startIter,
|  | 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>

casacore::Array< T >::Array | ( | Array< T > && | source,
|  | const IPosition & | shapeForSource )

protected noexcept

Source will be empty with given shape after this call.

## Member Function Documentation

## addDegenerate() [1/2]

template<typename T>

Array< T > casacore::Array< T >::addDegenerate | ( | size_t | numAxes | ) |

## addDegenerate() [2/2]

template<typename T>

const Array< T > casacore::Array< T >::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>

bool casacore::Array< T >::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.

## apply()

template<typename T>
template<typename Callable>

void casacore::Array< T >::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>

void casacore::Array< T >::assign | ( | const Array< T > & | other | ) |

Assign the other array to this array.

If the shapes mismatch, this array is resized.

## assign_conforming() [1/2]

template<typename T>

Array< T > & casacore::Array< T >::assign_conforming | ( | const Array< T > & | 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 277 of file Array.h.

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

## assign_conforming() [2/2]

template<typename T>

Array< T > & casacore::Array< T >::assign_conforming | ( | const MaskedArray< T > & | marray | ) |

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

### Thrown Exceptions

- ArrayConformanceError

## assign_conforming_implementation() [1/2]

template<typename T>

Array< T > & casacore::Array< T >::assign_conforming_implementation | ( | const Array< T > & | ,
|  | std::false_type | )

inline private

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

Definition at line 885 of file Array.h.

## assign_conforming_implementation() [2/2]

template<typename T>

Array< T > & casacore::Array< T >::assign_conforming_implementation | ( | const Array< T > & | other,
|  | std::true_type | )

private

Implementation for assign for copyable types.

Referenced by casacore::Array< LogicalArrayElem >::assign_conforming().

## assignBase()

template<typename T>

void casacore::Array< T >::assignBase | ( | const ArrayBase & | source,
|  | bool | checkType = true )

override 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.

## begin() [1/2]

template<typename T>

iterator casacore::Array< T >::begin | ( |  | ) |

inline

Get the begin iterator object for any array.

Definition at line 844 of file Array.h.

Referenced by casacore::MArrayLogical_global_functions_MArray_logical_operations::allEQ(), casacore::MArrayLogical_global_functions_MArray_logical_operations::anyEQ(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayContTransform(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayContTransform(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayContTransform(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayContTransform(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayTransformInPlace(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayTransformInPlace(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayTransformInPlace(), casacore::MArrayMath_global_functions_MArray_mathematical_operations::avdev(), casacore::MArrayMath_global_functions_MArray_mathematical_operations::max(), casacore::MArrayMath_global_functions_MArray_mathematical_operations::min(), casacore::MArrayLogical_global_functions_MArray_logical_operations::nfalse(), casacore::MArrayLogical_global_functions_MArray_logical_operations::ntrue(), casacore::MArrayMath_global_functions_MArray_mathematical_operations::product(), casacore::MArrayMath_global_functions_MArray_mathematical_operations::rms(), casacore::MArrayMath_global_functions_MArray_mathematical_operations::slidingArrayMath(), casacore::MArrayMath_global_functions_MArray_mathematical_operations::sum(), casacore::MArrayMath_global_functions_MArray_mathematical_operations::sumsqr(), and casacore::MArrayMath_global_functions_MArray_mathematical_operations::variance().

## begin() [2/2]

template<typename T>

const_iterator casacore::Array< T >::begin | ( |  | ) | const

inline

Definition at line 846 of file Array.h.

## capacity()

template<typename T>

size_t casacore::Array< T >::capacity | ( |  | ) | const

Returns the number of elements allocated.

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

## cbegin() [1/2]

template<typename T>

contiter casacore::Array< T >::cbegin | ( |  | ) |

inline

Get the begin iterator object for a contiguous array.

Definition at line 856 of file Array.h.

Referenced by casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayContTransform(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayContTransform(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayContTransform(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayContTransform(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayTransformInPlace(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayTransformInPlace(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayTransformInPlace(), casacore::MArrayMath_global_functions_MArray_mathematical_operations::avdev(), casacore::MArrayMath_global_functions_MArray_mathematical_operations::max(), casacore::MArrayMath_global_functions_MArray_mathematical_operations::min(), casacore::MArrayLogical_global_functions_MArray_logical_operations::nfalse(), casacore::MArrayLogical_global_functions_MArray_logical_operations::ntrue(), casacore::MArrayMath_global_functions_MArray_mathematical_operations::product(), casacore::MArrayMath_global_functions_MArray_mathematical_operations::rms(), casacore::MArrayMath_global_functions_MArray_mathematical_operations::sum(), casacore::MArrayMath_global_functions_MArray_mathematical_operations::sumsqr(), and casacore::MArrayMath_global_functions_MArray_mathematical_operations::variance().

## cbegin() [2/2]

template<typename T>

const_contiter casacore::Array< T >::cbegin | ( |  | ) | const

inline

Definition at line 858 of file Array.h.

## cend() [1/2]

template<typename T>

contiter casacore::Array< T >::cend | ( |  | ) |

inline

Definition at line 860 of file Array.h.

Referenced by casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayContTransform(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayContTransform(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayContTransform(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayContTransform(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayTransformInPlace(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayTransformInPlace(), and casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayTransformInPlace().

## cend() [2/2]

template<typename T>

const_contiter casacore::Array< T >::cend | ( |  | ) | const

inline

Definition at line 862 of file Array.h.

## checkAssignableType()

template<typename T>

virtual void casacore::Array< T >::checkAssignableType | ( | ArrayBase & | arrayBase | ) | const

inline protected virtual

Definition at line 940 of file Array.h.

## checkBeforeResize()

template<typename T>

void casacore::Array< T >::checkBeforeResize | ( | const IPosition & | newShape | ) |

inline protected

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 924 of file Array.h.

## conform() [1/2]

template<typename T>

bool casacore::Array< T >::conform | ( | const Array< T > & | other | ) | const

inline

Are the shapes identical?

Definition at line 584 of file Array.h.

## conform() [2/2]

template<typename T>

bool casacore::Array< T >::conform | ( | const MaskedArray< T > & | other | ) | const

## copy()

template<typename T>

Array< T > casacore::Array< T >::copy | ( |  | ) | 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());
//..\.
}
casacore::arg
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

## copyMatchingPart()

template<typename 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.

## copyToContiguousStorage() [1/3]

template<typename T>

void casacore::Array< T >::copyToContiguousStorage | ( | T * | ,
|  | Array< T > const & | ,
|  | std::false_type | )

inline static private

Definition at line 890 of file Array.h.

## copyToContiguousStorage() [2/3]

template<typename T>

void casacore::Array< T >::copyToContiguousStorage | ( | T * | dst,
|  | Array< T > const & | src )

inline static protected

Definition at line 948 of file Array.h.

## copyToContiguousStorage() [3/3]

template<typename T>

void casacore::Array< T >::copyToContiguousStorage | ( | T * | dst,
|  | Array< T > const & | src,
|  | std::true_type | )

static private

Referenced by casacore::Array< LogicalArrayElem >::copyToContiguousStorage().

## data() [1/2]

template<typename T>

T * casacore::Array< T >::data | ( |  | ) |

inline

Get a pointer to the beginning of the array.

Note that the array may not be contiguous.

Definition at line 592 of file Array.h.

Referenced by casacore::ArrayLogical_global_functions_Array_logical_operations::allSame(), casacore::MArrayMath_global_functions_MArray_mathematical_operations::boxedArrayMath(), casacore::ArrayMath_global_functions_Array_mathematical_operations::expandArray(), casacore::MArray< T >::flatten(), and casacore::MArrayMath_global_functions_MArray_mathematical_operations::partialArrayMath().

## data() [2/2]

template<typename T>

const T * casacore::Array< T >::data | ( |  | ) | const

inline

Definition at line 594 of file Array.h.

## diagonals()

template<typename T>

Array< T > casacore::Array< T >::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>

virtual void casacore::Array< T >::doNonDegenerate | ( | const Array< T > & | other,
|  | const IPosition & | ignoreAxes )

protected virtual

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

Referenced by casacore::Array< LogicalArrayElem >::nonDegenerate().

## end() [1/2]

template<typename T>

iterator casacore::Array< T >::end | ( |  | ) |

inline

Definition at line 848 of file Array.h.

Referenced by casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayContTransform(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayContTransform(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayContTransform(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayContTransform(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayTransformInPlace(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayTransformInPlace(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayTransformInPlace(), casacore::Array< T >::BaseIteratorSTL::BaseIteratorSTL(), casacore::Array< T >::ConstIteratorSTL::ConstIteratorSTL(), and casacore::Array< T >::IteratorSTL::IteratorSTL().

## end() [2/2]

template<typename T>

const_iterator casacore::Array< T >::end | ( |  | ) | const

inline

Definition at line 850 of file Array.h.

## fixedDimensionality()

template<typename T>

virtual size_t casacore::Array< T >::fixedDimensionality | ( |  | ) | const

inline protected virtual

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

Definition at line 938 of file Array.h.

Referenced by casacore::Array< LogicalArrayElem >::checkBeforeResize().

## freeStorage()

template<typename 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. TODO this function can not be const for stateful allocators

Referenced by casacore::StokesIStManColumn::putArrayGeneric().

## freeVStorage()

template<typename T>

void casacore::Array< T >::freeVStorage | ( | const void *& | storage,
|  | bool | deleteIt ) const

override virtual

Reimplemented from casacore::ArrayBase.

## getSection()

template<typename T>

std::unique_ptr< ArrayBase > casacore::Array< T >::getSection | ( | const Slicer & |  | ) | const

override 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.

## getStorage() [1/2]

template<typename 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.
casacore::storage
T * storage()
If you really, really, need a "raw" pointer to the beginning of the storage area this will give it to...
Definition Block.h:550

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(), casacore::StokesIStManColumn::getArrayGeneric(), casacore::Array< LogicalArrayElem >::getStorage(), and casacore::StokesIStManColumn::putArrayGeneric().

## getStorage() [2/2]

template<typename 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 620 of file Array.h.

## getVStorage() [1/2]

template<typename T>

const void * casacore::Array< T >::getVStorage | ( | bool & | deleteIt | ) | const

override virtual

Reimplemented from casacore::ArrayBase.

## getVStorage() [2/2]

template<typename T>

void * casacore::Array< T >::getVStorage | ( | bool & | deleteIt | ) |

override 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.

## isUnique()

template<typename T>

bool casacore::Array< T >::isUnique | ( |  | ) | const

inline private

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

Definition at line 896 of file Array.h.

## makeArray()

template<typename T>

virtual std::unique_ptr< ArrayBase > casacore::Array< T >::makeArray | ( |  | ) | const

override virtual

Make an empty array of the same template type.

Reimplemented from casacore::ArrayBase.

## makeIterator()

template<typename T>

std::unique_ptr< ArrayPositionIterator > casacore::Array< T >::makeIterator | ( | size_t | byDim | ) | const

override virtual

Create an ArrayIterator object of the correct type.

Reimplemented from casacore::ArrayBase.

## makeSteps()

template<typename T>

void casacore::Array< T >::makeSteps | ( |  | ) |

inline protected

Fill the steps and the end for a derived class.

Definition at line 975 of file Array.h.

## nonDegenerate() [1/4]

template<typename T>

void casacore::Array< T >::nonDegenerate | ( | const Array< T > & | other,
|  | const IPosition & | ignoreAxes )

inline

Definition at line 461 of file Array.h.

## nonDegenerate() [2/4]

template<typename T>

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

## nonDegenerate() [3/4]

template<typename T>

Array< T > casacore::Array< T >::nonDegenerate | ( | const IPosition & | ignoreAxes | ) | const

## nonDegenerate() [4/4]

template<typename T>

Array< T > casacore::Array< T >::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>

size_t 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. 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< LogicalArrayElem >::isUnique().

## ok()

template<typename T>

virtual bool casacore::Array< T >::ok | ( |  | ) | const

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

## operator()() [1/12]

template<typename 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).

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

## operator()() [2/12]

template<typename T>

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

## operator()() [3/12]

template<typename 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).

## operator()() [4/12]

template<typename T>

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

## operator()() [5/12]

template<typename 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.

## operator()() [6/12]

template<typename T>

const Array< T > casacore::Array< T >::operator() | ( | const IPosition & | start,
|  | const IPosition & | end,
|  | const IPosition & | inc ) const

## operator()() [7/12]

template<typename T>

MaskedArray< T > casacore::Array< T >::operator() | ( | const LogicalArray< T > & | mask | ) |

## operator()() [8/12]

template<typename 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.

## operator()() [9/12]

template<typename T>

MaskedArray< T > casacore::Array< T >::operator() | ( | const MaskedLogicalArray< T > & | mask | ) |

## operator()() [10/12]

template<typename 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.

## operator()() [11/12]

template<typename T>

Array< T > casacore::Array< T >::operator() | ( | const Slicer & |  | ) |

Get a reference to an array section using a Slicer.

## operator()() [12/12]

template<typename T>

const Array< T > casacore::Array< T >::operator() | ( | const Slicer & |  | ) | const

## operator=() [1/4]

template<typename T>

Array< T > & casacore::Array< T >::operator= | ( | Array< T > && | 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>

Array< T > & casacore::Array< T >::operator= | ( | const Array< T > & | other | ) |

inline

TODO we should change the semantics.

Definition at line 291 of file Array.h.

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

## operator=() [3/4]

template<typename T>

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

inline

Calls assign_conforming().

Definition at line 295 of file Array.h.

## operator=() [4/4]

template<typename 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.

## operator[]()

template<typename 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;

## postTakeStorage()

template<typename T>

virtual void casacore::Array< T >::postTakeStorage | ( |  | ) |

inline protected virtual

Definition at line 915 of file Array.h.

## preTakeStorage()

template<typename T>

virtual void casacore::Array< T >::preTakeStorage | ( | const IPosition & |  | ) |

inline protected virtual

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

Reimplemented in casacore::Cube< T >, casacore::Cube< casacore::RigidVector< Double, 2 > >, casacore::Cube< Double >, casacore::Cube< LogicalArrayElem >, casacore::Matrix< T >, casacore::Matrix< Bool >, casacore::Matrix< casacore::GaussianBeam >, casacore::Matrix< casacore::SquareMatrix< Complex, 2 > >, casacore::Matrix< Complex >, casacore::Matrix< Double >, casacore::Matrix< Float >, casacore::Matrix< FType >, casacore::Matrix< Int >, casacore::Matrix< Int64 >, and casacore::Matrix< LogicalArrayElem >.

Definition at line 913 of file Array.h.

## putStorage()

template<typename 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.

Referenced by casacore::ArrayMath_global_functions_Array_mathematical_operations::expandArray(), and casacore::StokesIStManColumn::getArrayGeneric().

## putVStorage()

template<typename T>

void casacore::Array< T >::putVStorage | ( | void *& | storage,
|  | bool | deleteAndCopy )

override virtual

Reimplemented from casacore::ArrayBase.

## reference()

template<typename 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.

Referenced by casacore::ArrayMath_global_functions_Array_mathematical_operations::expandArray(), and casacore::MArrayMath_global_functions_MArray_mathematical_operations::slidingArrayMath().

## reform()

template<typename 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"
casacore::Vector
Definition Vector.h:82
casacore::square
TableExprNode square(const TableExprNode &node)
Definition ExprNode.h:1350

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

## reformOrResize()

template<typename T>

bool casacore::Array< T >::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>

void casacore::Array< T >::removeDegenerate | ( | const IPosition & | ignoreAxes | ) |

## removeDegenerate() [2/2]

template<typename T>

void casacore::Array< T >::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>

void casacore::Array< T >::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::TableExprGroupAggr::getArray(), casacore::Vector< LogicalArrayElem >::resize(), and casacore::TableExprNodeSet::toArray().

## resize() [2/2]

template<typename T>

void casacore::Array< T >::resize | ( | const IPosition & | newShape,
|  | bool | copyValues = false )

override 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< casacore::String >, and casacore::Vector< LogicalArrayElem >.

## set()

template<typename 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.

## setEndIter()

template<typename T>

void casacore::Array< T >::setEndIter | ( |  | ) |

inline protected

Set the end iterator.

Definition at line 979 of file Array.h.

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

## swap()

template<typename T>

void casacore::Array< T >::swap | ( | Array< T > & | other | ) |

protected

Swap this array with another array.

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

## takeStorage() [1/2]

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

## takeStorage() [2/2]

template<typename 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 allocator. If policy is TAKE_OVER, storage will be destructed and released by allocator.

## tovector() [1/2]

template<typename T>

std::vector< T > casacore::Array< T >::tovector | ( |  | ) | const

## tovector() [2/2]

template<typename T>
template<class U>

void casacore::Array< T >::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>

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();
casacore::Array::unique
void unique()
This ensures that this array does not reference any other storage.
casacore::reference
value_type & reference
Definition Block.h:583

## Friends And Related Symbol Documentation

## ArrayIterator< T >

template<typename T>

friend class ArrayIterator< T >

friend

Used to iterate through Arrays.

Derived classes VectorIterator and MatrixIterator are probably more useful.

Definition at line 654 of file Array.h.

## swap

template<typename T>
template<typename ST>

void swap | ( | Array< ST > & | left,
|  | Array< ST > & | right )

friend

## Member Data Documentation

## begin_p

template<typename 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 968 of file Array.h.

## data_p

template<typename T>

std::shared_ptr<arrays_internal::Storage<T> > casacore::Array< T >::data_p

protected

Shared pointer to a Storage that contains the data.

Definition at line 962 of file Array.h.

## end_p

template<typename T>

T* casacore::Array< T >::end_p

protected

The end for an STL-style iteration.

Definition at line 971 of file Array.h.

## uninitialized

template<typename T>

struct casacore::Array::uninitializedType casacore::Array< T >::uninitialized

static

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

- casa/Arrays/Array.h