casacore
|
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. More...
#include <Array.h>
Classes | |
class | BaseIteratorSTL |
See the function begin() and end() for a detailed description of the STL iterator capability. 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 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 < ArrayBase > | makeArray () const override |
Make an empty array of the same template type. More... | |
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< ArrayBase > | getSection (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 < ArrayPositionIterator > | makeIterator (size_t byDim) const override |
Create an ArrayIterator object of the correct type. More... | |
Alloc & | allocator () |
Retrieve the allocator associated with this array. More... | |
const Alloc & | allocator () 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 | |
ArrayBase & | assign (const ArrayBase &) |
Assignment. More... | |
ArrayBase & | operator= (const ArrayBase &)=delete |
ArrayBase & | operator= (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 IPosition & | shape () const |
The length of each axis. More... | |
IPosition | endPosition () const |
A convenience function: endPosition(i) = shape(i) - 1; i.e. More... | |
const IPosition & | steps () 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 |
Friends | |
class | ArrayIterator< T, Alloc > |
Used to iterate through Arrays. More... | |
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 |
template<typename ST , typename SAlloc > | |
void | swap (Array< ST, SAlloc > &left, Array< ST, SAlloc > &right) |
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... | |
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 |
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 void | copyToContiguousStorage (T *dst, Array< T, Alloc > const &src, std::true_type) |
static void | copyToContiguousStorage (T *, Array< T, Alloc > const &, std::false_type) |
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... | |
static void | copyToContiguousStorage (T *dst, Array< T, Alloc > const &src) |
Additional Inherited Members | |
Static Public Member Functions inherited from casacore::ArrayBase | |
static unsigned | arrayVersion () |
Array version for major change (used by ArrayIO). 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... | |
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... | |
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.
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, ...).
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:
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";
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.
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
typedef const T* casacore::Array< T, Alloc >::const_contiter |
typedef ConstIteratorSTL casacore::Array< T, Alloc >::const_iterator |
typedef const T* casacore::Array< T, Alloc >::const_pointer |
typedef const T& casacore::Array< T, Alloc >::const_reference |
typedef T* casacore::Array< T, Alloc >::contiter |
typedef IteratorSTL casacore::Array< T, Alloc >::iterator |
typedef T* casacore::Array< T, Alloc >::pointer |
typedef T casacore::Array< T, Alloc >::value_type |
casacore::Array< T, Alloc >::Array | ( | const Alloc & | allocator = Alloc() | ) |
Result has dimensionality of zero, and nelements is zero.
|
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,
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>
.
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:
casacore::Array< T, Alloc >::Array | ( | std::initializer_list< T > | list, |
const Alloc & | allocator = Alloc() |
||
) |
Construct a one-dimensional array from an initializer list.
Example:
casacore::Array< T, Alloc >::Array | ( | const Array< T, Alloc > & | other | ) |
After construction, this and other reference the same storage.
|
noexcept |
Source will be empty after this call.
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.
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>
.
casacore::Array< T, Alloc >::Array | ( | const IPosition & | shape, |
InputIterator | startIter, | ||
const Alloc & | allocator = Alloc() |
||
) |
Construct an array from an iterator and a shape.
|
virtualnoexcept |
Frees up storage only if this array was the last reference to it.
|
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.
|
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.
|
protectednoexcept |
Source will be empty with given shape after this call.
const Array<T, Alloc> casacore::Array< T, Alloc >::addDegenerate | ( | size_t | numAxes | ) | const |
Array<T, Alloc> casacore::Array< T, Alloc >::addDegenerate | ( | size_t | numAxes | ) |
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.
|
inline |
|
inline |
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)
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.
|
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).
Note that the assign function can be used to assign a non-conforming array.
Definition at line 285 of file Array.h.
Referenced by casacore::Matrix< Complex >::assign_conforming(), and casacore::Array< T, std::allocator< T > >::operator=().
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.
|
private |
Implementation for assign for copyable types.
Referenced by casacore::Array< T, std::allocator< T > >::assign_conforming().
|
inlineprivate |
|
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.
|
inline |
Get the begin iterator object for any array.
Definition at line 859 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::arrayTransformInPlace(), casacore::MArrayMath_global_functions_MArray_mathematical_operations::avdev(), casacore::MArray< T >::flatten(), casacore::python::to_list< casacore::Array< casacore::String > >::makeobject(), casacore::python::to_list< casacore::Vector< casacore::String > >::makeobject(), 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().
|
inline |
size_t casacore::Array< T, Alloc >::capacity | ( | ) | const |
Returns the number of elements allocated.
This value is >= to the value returned by size().
|
inline |
Get the begin iterator object for a contiguous array.
Definition at line 871 of file Array.h.
Referenced by casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayContTransform(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayTransformInPlace(), casacore::MArrayMath_global_functions_MArray_mathematical_operations::avdev(), casacore::MArray< T >::flatten(), 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().
|
inline |
|
inline |
Definition at line 875 of file Array.h.
Referenced by casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayContTransform(), casacore::ArrayMath_global_functions_Array_mathematical_operations::arrayTransformInPlace(), casacore::MArrayMath_global_functions_MArray_mathematical_operations::avdev(), casacore::MArray< T >::flatten(), 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().
|
inline |
|
inlineprotectedvirtual |
|
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.
|
inline |
bool casacore::Array< T, Alloc >::conform | ( | const MaskedArray< T > & | other | ) | 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.
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:
which likely would be simpler to understand. (Should copy() be deprecated and removed?)
TODO deprecate
Definition at line 341 of file Array.h.
Referenced by casacore::Array< T, std::allocator< T > >::copy().
|
private |
Makes a copy using the allocator.
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
.
|
staticprivate |
|
inlinestaticprivate |
|
inlinestaticprotected |
|
inline |
Get a pointer to the beginning of the array.
Note that the array may not be contiguous.
Definition at line 604 of file Array.h.
Referenced by casacore::ArrayLogical_global_functions_Array_logical_operations::allSame(), casacore::MArrayMath_global_functions_MArray_mathematical_operations::boxedArrayMath(), casacore::MArray< T >::flatten(), casacore::LSQaips::getErrors(), casacore::ArrayBaseAccessor< T >::init(), casacore::MArrayMath_global_functions_MArray_mathematical_operations::partialArrayMath(), casacore::HDF5Record::readArr(), casacore::LSQaips::solve(), and casacore::HDF5Record::writeArr().
|
inline |
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.
|
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 >, casacore::Matrix< Double >, and casacore::Matrix< T >.
Referenced by casacore::Array< T, std::allocator< T > >::nonDegenerate().
|
inline |
Definition at line 863 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::arrayTransformInPlace(), casacore::MArrayMath_global_functions_MArray_mathematical_operations::avdev(), casacore::MArray< T >::flatten(), casacore::python::to_list< casacore::Array< casacore::String > >::makeobject(), casacore::python::to_list< casacore::Vector< casacore::String > >::makeobject(), 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().
|
inline |
|
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::Vector< T, Alloc >, casacore::Vector< typename casacore::FunctionTraits< T >::DiffType >, casacore::Vector< casacore::SquareMatrix< Complex, 2 > >, casacore::Vector< casacore::MPosition >, casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< Double >::BaseType >::base > >, casacore::Vector< typename casacore::FunctionTraits< DComplex >::DiffType >, casacore::Vector< double >, casacore::Vector< Float >, casacore::Vector< casacore::AutoDiff< Double > >, casacore::Vector< typename casacore::FunctionTraits< Double >::DiffType >, casacore::Vector< casacore::Quantum >, casacore::Vector< Double >, casacore::Vector< casacore::Vector< Range > >, casacore::Vector< AutoDiff< T > >, casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< DComplex >::BaseType >::base > >, casacore::Vector< T >, casacore::Vector< typename casacore::FunctionTraits< DComplex >::ArgType >, casacore::Vector< casacore::Unit >, casacore::Vector< Int >, casacore::Vector< rownr_t >, casacore::Vector< Int64 >, casacore::Vector< casacore::MDirection >, casacore::Vector< typename casacore::FunctionTraits< Double >::ArgType >, casacore::Vector< casacore::MFrequency >, casacore::Vector< casacore::RORecordFieldPtr< Double > >, casacore::Vector< size_t >, casacore::Vector< AutoDiffA< T > >, casacore::Vector< Type >, casacore::Vector< typename casacore::FunctionTraits< DComplex >::BaseType >, casacore::Vector< FType >, casacore::Vector< Bool >, casacore::Vector< typename casacore::FunctionTraits< T >::BaseType >, casacore::Vector< typename casacore::FunctionTraits< T >::ArgType >, casacore::Vector< typename casacore::FunctionTraits< Double >::BaseType >, casacore::Vector< casacore::Slicer * >, casacore::Vector< casacore::MeasComet * >, casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< T >::BaseType >::base > >, casacore::Vector< uInt >, casacore::Vector< casacore::Quantum< Double > >, casacore::Vector< Domain >, casacore::Vector< casacore::String >, casacore::Vector< ArgType >, casacore::Cube< T, Alloc >, casacore::Cube< Double >, and casacore::Cube< casacore::RigidVector< Double, 2 > >.
Definition at line 956 of file Array.h.
Referenced by casacore::Array< T, std::allocator< T > >::checkBeforeResize().
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
|
overridevirtual |
Reimplemented from casacore::ArrayBase.
|
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.
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.:
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, std::allocator< T > >::getStorage().
|
inline |
|
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.
|
overridevirtual |
Reimplemented from casacore::ArrayBase.
|
inlineprivate |
|
overridevirtual |
Make an empty array of the same template type.
Reimplemented from casacore::ArrayBase.
|
overridevirtual |
Create an ArrayIterator object of the correct type.
Reimplemented from casacore::ArrayBase.
|
inlineprotected |
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;
Array<T, Alloc> casacore::Array< T, Alloc >::nonDegenerate | ( | const IPosition & | ignoreAxes | ) | const |
void casacore::Array< T, Alloc >::nonDegenerate | ( | const Array< T, Alloc > & | other, |
size_t | startingAxis = 0 , |
||
bool | throwIfError = true |
||
) |
|
inline |
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, std::allocator< T > >::isUnique().
|
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::Vector< T, Alloc >, casacore::Vector< typename casacore::FunctionTraits< T >::DiffType >, casacore::Vector< casacore::SquareMatrix< Complex, 2 > >, casacore::Vector< casacore::MPosition >, casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< Double >::BaseType >::base > >, casacore::Vector< typename casacore::FunctionTraits< DComplex >::DiffType >, casacore::Vector< double >, casacore::Vector< Float >, casacore::Vector< casacore::AutoDiff< Double > >, casacore::Vector< typename casacore::FunctionTraits< Double >::DiffType >, casacore::Vector< casacore::Quantum >, casacore::Vector< Double >, casacore::Vector< casacore::Vector< Range > >, casacore::Vector< AutoDiff< T > >, casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< DComplex >::BaseType >::base > >, casacore::Vector< T >, casacore::Vector< typename casacore::FunctionTraits< DComplex >::ArgType >, casacore::Vector< casacore::Unit >, casacore::Vector< Int >, casacore::Vector< rownr_t >, casacore::Vector< Int64 >, casacore::Vector< casacore::MDirection >, casacore::Vector< typename casacore::FunctionTraits< Double >::ArgType >, casacore::Vector< casacore::MFrequency >, casacore::Vector< casacore::RORecordFieldPtr< Double > >, casacore::Vector< size_t >, casacore::Vector< AutoDiffA< T > >, casacore::Vector< Type >, casacore::Vector< typename casacore::FunctionTraits< DComplex >::BaseType >, casacore::Vector< FType >, casacore::Vector< Bool >, casacore::Vector< typename casacore::FunctionTraits< T >::BaseType >, casacore::Vector< typename casacore::FunctionTraits< T >::ArgType >, casacore::Vector< typename casacore::FunctionTraits< Double >::BaseType >, casacore::Vector< casacore::Slicer * >, casacore::Vector< casacore::MeasComet * >, casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< T >::BaseType >::base > >, casacore::Vector< uInt >, casacore::Vector< casacore::Quantum< Double > >, casacore::Vector< Domain >, casacore::Vector< casacore::String >, casacore::Vector< ArgType >, casacore::Cube< T, Alloc >, casacore::Cube< Double >, and casacore::Cube< casacore::RigidVector< Double, 2 > >.
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< casacore::RigidVector< Double, 2 > >::operator()(), casacore::Matrix< Complex >::operator()(), and casacore::Vector< ArgType >::operator()().
const T& casacore::Array< T, Alloc >::operator() | ( | const IPosition & | ) | const |
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).
const Array<T, Alloc> casacore::Array< T, Alloc >::operator() | ( | const IPosition & | start, |
const IPosition & | end | ||
) | const |
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.
const Array<T, Alloc> casacore::Array< T, Alloc >::operator() | ( | const IPosition & | start, |
const IPosition & | end, | ||
const IPosition & | inc | ||
) | const |
Array<T, Alloc> casacore::Array< T, Alloc >::operator() | ( | const Slicer & | ) |
Get a reference to an array section using a Slicer.
const Array<T, Alloc> casacore::Array< T, Alloc >::operator() | ( | const Slicer & | ) | const |
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.
MaskedArray<T> casacore::Array< T, Alloc >::operator() | ( | const LogicalArray< T, Alloc > & | mask | ) |
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.
MaskedArray<T> casacore::Array< T, Alloc >::operator() | ( | const MaskedLogicalArray< T, Alloc > & | mask | ) |
|
inline |
TODO we should change the semantics.
Definition at line 300 of file Array.h.
Referenced by casacore::Cube< casacore::RigidVector< Double, 2 > >::operator=(), and casacore::Matrix< Complex >::operator=().
|
inline |
Calls assign_conforming().
Array<T, Alloc>& casacore::Array< T, Alloc >::operator= | ( | Array< T, Alloc > && | other | ) |
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.
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;
|
inlineprotectedvirtual |
|
inlineprotectedvirtual |
pre/post processing hook of takeStorage() for subclasses.
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 >, and casacore::Cube< casacore::RigidVector< Double, 2 > >.
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().
|
overridevirtual |
Reimplemented from casacore::ArrayBase.
|
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::ValueHolder::getValue(), casacore::MArray< casacore::String >::MArray(), casacore::MArray< casacore::String >::reference(), and casacore::RecordInterface::toArray().
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.
Referenced by casacore::ArrayMath_global_functions_Array_mathematical_operations::expandArray(), and casacore::TableExprNodeSet::toArray().
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.
void casacore::Array< T, Alloc >::removeDegenerate | ( | size_t | startingAxis = 0 , |
bool | throwIfError = true |
||
) |
void casacore::Array< T, Alloc >::removeDegenerate | ( | const IPosition & | ignoreAxes | ) |
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< casacore::String >::fill(), casacore::TableExprGroupAggr::getArray(), casacore::MArrayBase::removeMask(), casacore::MArray< casacore::String >::resize(), and casacore::Vector< ArgType >::resize().
|
overridevirtual |
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, Alloc >, casacore::Vector< typename casacore::FunctionTraits< T >::DiffType >, casacore::Vector< casacore::SquareMatrix< Complex, 2 > >, casacore::Vector< casacore::MPosition >, casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< Double >::BaseType >::base > >, casacore::Vector< typename casacore::FunctionTraits< DComplex >::DiffType >, casacore::Vector< double >, casacore::Vector< Float >, casacore::Vector< casacore::AutoDiff< Double > >, casacore::Vector< typename casacore::FunctionTraits< Double >::DiffType >, casacore::Vector< casacore::Quantum >, casacore::Vector< Double >, casacore::Vector< casacore::Vector< Range > >, casacore::Vector< AutoDiff< T > >, casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< DComplex >::BaseType >::base > >, casacore::Vector< T >, casacore::Vector< typename casacore::FunctionTraits< DComplex >::ArgType >, casacore::Vector< casacore::Unit >, casacore::Vector< Int >, casacore::Vector< rownr_t >, casacore::Vector< Int64 >, casacore::Vector< casacore::MDirection >, casacore::Vector< typename casacore::FunctionTraits< Double >::ArgType >, casacore::Vector< casacore::MFrequency >, casacore::Vector< casacore::RORecordFieldPtr< Double > >, casacore::Vector< size_t >, casacore::Vector< AutoDiffA< T > >, casacore::Vector< Type >, casacore::Vector< typename casacore::FunctionTraits< DComplex >::BaseType >, casacore::Vector< FType >, casacore::Vector< Bool >, casacore::Vector< typename casacore::FunctionTraits< T >::BaseType >, casacore::Vector< typename casacore::FunctionTraits< T >::ArgType >, casacore::Vector< typename casacore::FunctionTraits< Double >::BaseType >, casacore::Vector< casacore::Slicer * >, casacore::Vector< casacore::MeasComet * >, casacore::Vector< casacore::Vector< typename casacore::LSQTraits< typename casacore::FunctionTraits< T >::BaseType >::base > >, casacore::Vector< uInt >, casacore::Vector< casacore::Quantum< Double > >, casacore::Vector< Domain >, casacore::Vector< casacore::String >, and casacore::Vector< ArgType >.
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.
|
inlineprotected |
Set the end iterator.
Definition at line 997 of file Array.h.
Referenced by casacore::Array< T, std::allocator< T > >::makeSteps().
|
protected |
Swap this array with another array.
Normally, casacore::swap() should be used instead.
|
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
.
|
virtual |
Since the pointer is const, a copy is always taken.
Storage of a new copy is allocated by the specified allocator.
void casacore::Array< T, Alloc >::tovector | ( | std::vector< T, U > & | out | ) | const |
std::vector<T> casacore::Array< T, Alloc >::tovector | ( | ) | const |
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;
|
friend |
Used to iterate through Arrays.
Derived classes VectorIterator and MatrixIterator are probably more useful.
|
friend |
Referenced by casacore::swap().
|
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, std::allocator< T > >::cbegin(), casacore::Array< T, std::allocator< T > >::data(), casacore::Cube< casacore::RigidVector< Double, 2 > >::operator()(), casacore::Matrix< Complex >::operator()(), casacore::Vector< ArgType >::operator()(), casacore::Vector< ArgType >::operator[](), and casacore::Array< T, std::allocator< T > >::setEndIter().
|
protected |
Shared pointer to a Storage that contains the data.
Definition at line 980 of file Array.h.
Referenced by casacore::Array< T, std::allocator< T > >::allocator(), and casacore::Array< T, std::allocator< T > >::isUnique().
|
protected |
The end for an STL-style iteration.
Definition at line 989 of file Array.h.
Referenced by casacore::Array< T, std::allocator< T > >::cend(), casacore::Array< T, std::allocator< T > >::end(), and casacore::Array< T, std::allocator< T > >::setEndIter().
|
static |