casacore
Public Member Functions | Protected Member Functions | Private Member Functions | List of all members
casacore::Vector< T > Class Template Reference

More...

#include <Vector.h>

Public Member Functions

 Vector ()
 A zero-length Vector. More...
 
 Vector (size_t Length)
 A Vector with a defined length and origin of zero. More...
 
 Vector (size_t Length, ArrayInitPolicy initPolicy)
 
 Vector (const IPosition &Length)
 
 Vector (const IPosition &Length, ArrayInitPolicy initPolicy)
 
 Vector (size_t Length, const T &initialValue)
 A Vector with a defined length and origin of zero. More...
 
 Vector (const IPosition &Length, const T &initialValue)
 
 Vector (const Block< T > &other, Int64 nr)
 Create a Vector from the given Block "other." Make it length "nr" and copy over that many elements. More...
 
 Vector (const Block< T > &other)
 Create a Vector of length other.nelements() and copy over its values. More...
 
 Vector (const Vector< T > &other)
 Create a reference to other. More...
 
 Vector (const Array< T > &other)
 Create a reference to the other array. More...
 
 Vector (const IPosition &shape, T *storage, StorageInitPolicy policy=COPY)
 Create an Vector of a given shape from a pointer. More...
 
 Vector (const IPosition &shape, T *storage, StorageInitPolicy policy, AbstractAllocator< T > const &allocator)
 Create an Vector of a given shape from a pointer. More...
 
 Vector (const IPosition &shape, const T *storage)
 Create an Vector of a given shape from a pointer. More...
 
template<class U , class V >
 Vector (const vector< U, V > &other)
 Create a Vector from an STL vector (see tovector() in Array for the reverse operation). More...
 
template<typename Iterator >
 Vector (Iterator first, size_t size, int dummy)
 Create a Vector from a container iterator and its length. More...
 
virtual ~Vector ()
 Define a destructor, otherwise the compiler makes a static one. More...
 
virtual void assign (const Array< T > &other)
 Assign the other array (which must be of dimension one) to this vector. More...
 
virtual void reference (const Array< T > &other)
 Create a reference to "other", which must be of dimension one. More...
 
void resize (size_t len, Bool copyValues=False)
 
void resize (size_t len, Bool copyValues, ArrayInitPolicy policy)
 
virtual void resize ()
 
virtual void resize (const IPosition &len, Bool copyValues, ArrayInitPolicy policy)
 
Vector< T > & operator= (const Vector< T > &other)
 Assign to this Vector. More...
 
virtual Array< T > & operator= (const Array< T > &other)
 Other must be a 1-dimensional array. More...
 
Array< T > & operator= (const T &val)
 Set every element of this Vector to Val. More...
 
Vector< T > & operator= (const MaskedArray< T > &marray)
 Copy to this those values in marray whose corresponding elements in marray's mask are True. More...
 
void toBlock (Block< T > &other) const
 Convert a Vector to a Block, resizing the block and copying values. More...
 
T & operator[] (size_t index)
 Single-pixel addressing. More...
 
const T & operator[] (size_t index) const
 
T & operator() (const IPosition &i)
 
const T & operator() (const IPosition &i) const
 
T & operator() (size_t index)
 
const T & operator() (size_t index) const
 
Vector< T > operator() (const Slice &slice)
 Take a slice of this vector. More...
 
const Vector< T > operator() (const Slice &slice) const
 
Array< T > operator() (const IPosition &blc, const IPosition &trc, const IPosition &incr)
 Slice using IPositions. More...
 
const Array< T > operator() (const IPosition &blc, const IPosition &trc, const IPosition &incr) const
 
Array< T > operator() (const IPosition &blc, const IPosition &trc)
 
const Array< T > operator() (const IPosition &blc, const IPosition &trc) const
 
Array< T > operator() (const Slicer &slicer)
 
const Array< T > operator() (const Slicer &slicer) const
 
MaskedArray< T > operator() (const LogicalArray &mask) const
 The array is masked by the input LogicalArray. More...
 
MaskedArray< T > operator() (const LogicalArray &mask)
 Return a MaskedArray. More...
 
MaskedArray< T > operator() (const MaskedLogicalArray &mask) const
 The array is masked by the input MaskedLogicalArray. More...
 
MaskedArray< T > operator() (const MaskedLogicalArray &mask)
 Return a MaskedArray. More...
 
const IPositionshape () const
 The length of the Vector. More...
 
void shape (Int &Shape) const
 
virtual Bool ok () const
 Verify that dimensionality is 1 and then call Array<T>::ok() More...
 

Protected Member Functions

virtual void preTakeStorage (const IPosition &shape)
 
virtual void doNonDegenerate (const Array< T > &other, const IPosition &ignoreAxes)
 Remove the degenerate axes from other and store result in this vector. More...
 

Private Member Functions

void initVector (const Block< T > &, Int64 nr)
 Helper functions for constructors. More...
 

Detailed Description

template<class T>
class casacore::Vector< T >

A 1-D Specialization of the Array class

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

Vector objects are one-dimensional specializations (e.g., more convenient and efficient indexing) of the general Array class. You might also want to look at the Array documentation to see inherited functionality.

Generally the member functions of Array are also available in Vector versions which take an integer where the array needs an IPosition. Since the Vector is one-dimensional, the IPositions are overkill, although you may use those versions if you want to.

Vector<Int> vi(100); // Vector 100 elements long.
vi.resize(50); // Now only 50 long.

Slices may be taken with the Slice class. To take a slice, one "indexes" with Slice(start, length, inc) where end and inc are optional.

Vector<Float> vf(100);
//..\.
vf(Slice(0,50,2)) = vf(Slice(1,50,2)); // Copy values from odd onto even
Vector<Float> firstHalf, secondHalf;
firstHalf.reference(vf(Slice(0,50)));
secondHalf.reference(vf(Slice(50,50)));
// Now we have aliases for two slices into the Vector

Element-by-element arithmetic and logical operations are available (in aips/ArrayMath.h and aips/ArrayLogical.h) as well as dot and cross products (in aips/MatrixMath.h).

A Vector can be constructed from an STL vector. The reverse operation (Array::tovector()) can construct an STL vector from any Array.
Tip: To create any other STL container from an Array (or the reverse), always create from/to a vector, and use the range constructor to create from/to others (like set, list, deque);

As with the Arrays, if the preprocessor symbol AIPS_DEBUG is defined at compile time invariants will be checked on entry to most member functions. Additionally, if AIPS_ARRAY_INDEX_CHECK is defined index operations will be bounds-checked. Neither of these should be defined for production code.

Definition at line 88 of file Vector.h.

Constructor & Destructor Documentation

◆ Vector() [1/16]

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

A zero-length Vector.

◆ Vector() [2/16]

template<class T >
casacore::Vector< T >::Vector ( size_t  Length)
explicit

A Vector with a defined length and origin of zero.

◆ Vector() [3/16]

template<class T >
casacore::Vector< T >::Vector ( size_t  Length,
ArrayInitPolicy  initPolicy 
)

◆ Vector() [4/16]

template<class T >
casacore::Vector< T >::Vector ( const IPosition Length)
explicit

◆ Vector() [5/16]

template<class T >
casacore::Vector< T >::Vector ( const IPosition Length,
ArrayInitPolicy  initPolicy 
)

◆ Vector() [6/16]

template<class T >
casacore::Vector< T >::Vector ( size_t  Length,
const T &  initialValue 
)

A Vector with a defined length and origin of zero.

Fill it with the initial value.

◆ Vector() [7/16]

template<class T >
casacore::Vector< T >::Vector ( const IPosition Length,
const T &  initialValue 
)

◆ Vector() [8/16]

template<class T >
casacore::Vector< T >::Vector ( const Block< T > &  other,
Int64  nr 
)

Create a Vector from the given Block "other." Make it length "nr" and copy over that many elements.

◆ Vector() [9/16]

template<class T >
casacore::Vector< T >::Vector ( const Block< T > &  other)
explicit

Create a Vector of length other.nelements() and copy over its values.

◆ Vector() [10/16]

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

Create a reference to other.

◆ Vector() [11/16]

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

Create a reference to the other array.

It is always possible if the array has zero or one axes. If it has > 1 axes, it is only possible if the array has at most one axis with length > 1. In that case the degenerated axes are removed.

◆ Vector() [12/16]

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

Create an Vector of a given shape from a pointer.

◆ Vector() [13/16]

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

Create an Vector of a given shape from a pointer.

◆ Vector() [14/16]

template<class T >
casacore::Vector< T >::Vector ( const IPosition shape,
const T *  storage 
)

Create an Vector of a given shape from a pointer.

Because the pointer is const, a copy is always made.

◆ Vector() [15/16]

template<class T >
template<class U , class V >
casacore::Vector< T >::Vector ( const vector< U, V > &  other)

Create a Vector from an STL vector (see tovector() in Array for the reverse operation).


Tip: Both this constructor and the tovector() are defined in Vector2;cc;
It does implicit promotion/demotion of the type U if different from T.

◆ Vector() [16/16]

template<class T >
template<typename Iterator >
casacore::Vector< T >::Vector ( Iterator  first,
size_t  size,
int  dummy 
)

Create a Vector from a container iterator and its length.


Note: The length is used instead of last, because the distance function needed to calculate the length can be expensive;
A third dummy argument is unfortunately needed to avoid ambiguity with another Vector constructor (taking two uInts);

◆ ~Vector()

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

Define a destructor, otherwise the compiler makes a static one.

Member Function Documentation

◆ assign()

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

Assign the other array (which must be of dimension one) to this vector.

If the shapes mismatch, this array is resized.

◆ doNonDegenerate()

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

Remove the degenerate axes from other and store result in this vector.

An exception is thrown if removing degenerate axes does not result in a vector.

◆ initVector()

template<class T >
void casacore::Vector< T >::initVector ( const Block< T > &  ,
Int64  nr 
)
private

Helper functions for constructors.

◆ ok()

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

Verify that dimensionality is 1 and then call Array<T>::ok()

◆ operator()() [1/16]

template<class T >
Array<T> casacore::Vector< T >::operator() ( const IPosition blc,
const IPosition trc 
)
inline

Definition at line 250 of file Vector.h.

◆ operator()() [2/16]

template<class T >
const Array<T> casacore::Vector< T >::operator() ( const IPosition blc,
const IPosition trc 
) const
inline

Definition at line 252 of file Vector.h.

◆ operator()() [3/16]

template<class T >
Array<T> casacore::Vector< T >::operator() ( const IPosition blc,
const IPosition trc,
const IPosition incr 
)
inline

Slice using IPositions.

Required to be defined, otherwise the base class versions are hidden.

Definition at line 244 of file Vector.h.

◆ operator()() [4/16]

template<class T >
const Array<T> casacore::Vector< T >::operator() ( const IPosition blc,
const IPosition trc,
const IPosition incr 
) const
inline

Definition at line 247 of file Vector.h.

◆ operator()() [5/16]

template<class T >
T& casacore::Vector< T >::operator() ( const IPosition i)
inline

Definition at line 207 of file Vector.h.

◆ operator()() [6/16]

template<class T >
const T& casacore::Vector< T >::operator() ( const IPosition i) const
inline

Definition at line 209 of file Vector.h.

◆ operator()() [7/16]

template<class T >
MaskedArray<T> casacore::Vector< T >::operator() ( const LogicalArray &  mask)
inline

Return a MaskedArray.

Definition at line 269 of file Vector.h.

◆ operator()() [8/16]

template<class T >
MaskedArray<T> casacore::Vector< T >::operator() ( const LogicalArray &  mask) const
inline

The array is masked by the input LogicalArray.

This mask must conform to the array.

Return a MaskedArray.

Definition at line 265 of file Vector.h.

◆ operator()() [9/16]

template<class T >
MaskedArray<T> casacore::Vector< T >::operator() ( const MaskedLogicalArray &  mask)
inline

Return a MaskedArray.

Definition at line 286 of file Vector.h.

◆ operator()() [10/16]

template<class T >
MaskedArray<T> casacore::Vector< T >::operator() ( const MaskedLogicalArray &  mask) const
inline

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.

Return a MaskedArray.

Definition at line 282 of file Vector.h.

◆ operator()() [11/16]

template<class T >
Vector<T> casacore::Vector< T >::operator() ( const Slice slice)

Take a slice of this vector.

Slices are always indexed starting at zero. This uses reference semantics, i.e. changing a value in the slice changes the original.

Vector<Double> vd(100);
//..\.
vd(Slice(0,10)) = -1.0; // First 10 elements of vd set to -1

◆ operator()() [12/16]

template<class T >
const Vector<T> casacore::Vector< T >::operator() ( const Slice slice) const

◆ operator()() [13/16]

template<class T >
Array<T> casacore::Vector< T >::operator() ( const Slicer slicer)
inline

Definition at line 254 of file Vector.h.

◆ operator()() [14/16]

template<class T >
const Array<T> casacore::Vector< T >::operator() ( const Slicer slicer) const
inline

Definition at line 256 of file Vector.h.

◆ operator()() [15/16]

template<class T >
T& casacore::Vector< T >::operator() ( size_t  index)
inline

Definition at line 211 of file Vector.h.

◆ operator()() [16/16]

template<class T >
const T& casacore::Vector< T >::operator() ( size_t  index) const
inline

Definition at line 219 of file Vector.h.

◆ operator=() [1/4]

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

Other must be a 1-dimensional array.

◆ operator=() [2/4]

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

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

Definition at line 192 of file Vector.h.

◆ operator=() [3/4]

template<class T >
Array<T>& casacore::Vector< T >::operator= ( const T &  val)
inline

Set every element of this Vector to Val.

Definition at line 187 of file Vector.h.

◆ operator=() [4/4]

template<class T >
Vector<T>& casacore::Vector< T >::operator= ( const Vector< T > &  other)

Assign to this Vector.

If this Vector is zero-length, then resize to be the same size as other. Otherwise this and other have to be conformant (same size).
Note that the assign function can be used to assign a non-conforming vector.

◆ operator[]() [1/2]

template<class T >
T& casacore::Vector< T >::operator[] ( size_t  index)
inline

Single-pixel addressing.

If AIPS_ARRAY_INDEX_CHECK is defined, bounds checking is performed (not for [])..

Definition at line 203 of file Vector.h.

◆ operator[]() [2/2]

template<class T >
const T& casacore::Vector< T >::operator[] ( size_t  index) const
inline

Definition at line 205 of file Vector.h.

◆ preTakeStorage()

template<class T >
virtual void casacore::Vector< T >::preTakeStorage ( const IPosition shape)
protectedvirtual

◆ reference()

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

Create a reference to "other", which must be of dimension one.

◆ resize() [1/4]

template<class T >
virtual void casacore::Vector< T >::resize ( )
virtual

◆ resize() [2/4]

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

◆ resize() [3/4]

template<class T >
void casacore::Vector< T >::resize ( size_t  len,
Bool  copyValues,
ArrayInitPolicy  policy 
)
inline

Definition at line 169 of file Vector.h.

◆ resize() [4/4]

template<class T >
void casacore::Vector< T >::resize ( size_t  len,
Bool  copyValues = False 
)
inline

◆ shape() [1/2]

template<class T >
const IPosition& casacore::Vector< T >::shape ( ) const
inline

The length of the Vector.

Definition at line 293 of file Vector.h.

◆ shape() [2/2]

template<class T >
void casacore::Vector< T >::shape ( Int Shape) const
inline

Definition at line 295 of file Vector.h.

◆ toBlock()

template<class T >
void casacore::Vector< T >::toBlock ( Block< T > &  other) const

Convert a Vector to a Block, resizing the block and copying values.

This is done this way to avoid having the simpler Block class containing dependencies on the Vector class.


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