Vector.h

Classes

Vector -- A 1-D Specialization of the Array class (full description)

template<class T> class Vector : public Array<T>

Interface

Public Members
Vector()
explicit Vector(uInt Length)
explicit Vector(const IPosition& Length)
Vector(uInt Length, const T &initialValue)
Vector(const IPosition& Length, const T &initialValue)
Vector(const Block<T> &other, Int nr)
explicit Vector(const Block<T> &other)
Vector(const Vector<T> &other)
Vector(const Array<T> &other)
Vector(const IPosition &shape, T *storage, StorageInitPolicy policy = COPY)
Vector(const IPosition &shape, const T *storage)
template <class U> Vector(const vector<T, U> &other)
virtual ~Vector()
virtual void assign (const Array<T>& other)
virtual void reference(Array<T> &other)
void resize(uInt len, Bool copyValues = False)
void resize(const IPosition &len, Bool copyValues)
virtual void resize()
virtual void resize(const IPosition &len)
Vector<T> &operator=(const Vector<T> &other)
virtual Array<T> &operator=(const Array<T> &other)
Array<T> &operator=(const T &val)
Vector<T> &operator= (const MaskedArray<T> &marray)
void toBlock(Block<T> &other) const
T &operator[](uInt index)
const T &operator[](uInt index) const
T &operator()(const IPosition &i)
const T &operator()(const IPosition &i) const
T &operator()(uInt index)
const T &operator()(uInt index) const
Vector<T> operator()(const Slice &slice)
Array<T> operator()(const IPosition &blc, const IPosition &trc, const IPosition &incr)
Array<T> operator()(const IPosition &blc, const IPosition &trc)
Array<T> operator()(const Slicer& slicer)
MaskedArray<T> operator() (const LogicalArray &mask) const
MaskedArray<T> operator() (const LogicalArray &mask)
MaskedArray<T> operator() (const MaskedLogicalArray &mask) const
MaskedArray<T> operator() (const MaskedLogicalArray &mask)
void shape(Int &Shape) const
const IPosition &shape() const
virtual void takeStorage(const IPosition &shape, T *storage, StorageInitPolicy policy = COPY)
virtual void takeStorage(const IPosition &shape, const T *storage)
virtual Bool ok() const
Protected Members
virtual void doNonDegenerate(Array<T> &other, const IPosition &ignoreAxes)
Private Members
void initVector(const Block<T> &, Int nr)
See Also
Array general global functions -- General global functions for Arrays.
Array IO -- Input/output operators for Arrays.
Array binary IO -- Simple binary input/output for Arrays.
Array Ascii IO -- Simple Ascii input/output for Arrays.
ArrayIterator -- Iterate an Array cursor through another Array.
ReadOnlyArrayIterator -- Iterate a const Array cursor through a const Array.
Array logical operations -- Logical operations for Arrays.
Array mathematical operations -- Mathematical operations for Arrays.
LogicalArray -- Logical valued Arrays.
LogicalVector -- Logical valued Vectors.
MaskedArray logical operations -- Logical operations for MaskedArrays, and between MaskedArrays and Arrays.
MaskedArray mathematical operations -- Mathematical operations for MaskedArrays, and between MaskedArrays and Arrays.
MaskedLogicalArray -- Masked LogicalArrays.
MaskedArray general global functions -- General global functions for MaskedArrays, and between MaskedArrays and Arrays.
Linear Algebra -- Linear algebra functions on Vectors and Matrices.
Linear Algebra -- Linear algebra functions on Vectors and Matrices.
Linear Algebra -- Linear algebra functions on Vectors and Matrices.

Description

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. A tutorial on using the array classes in general is available in the "AIPS++ Programming Manual".

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.

Member Description

Vector()

A zero-length Vector.

explicit Vector(uInt Length)
explicit Vector(const IPosition& Length)

A Vector with a defined length and origin of zero.

Vector(uInt Length, const T &initialValue)
Vector(const IPosition& Length, const T &initialValue)

A Vector with a defined length and origin of zero. Fill it with the initial value.

Vector(const Block<T> &other, Int nr)

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

explicit Vector(const Block<T> &other)

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

Vector(const Vector<T> &other)

Create a reference to other.

Warning The copy constructor should normally be avoided. More details are available under the documentation for Array.

Vector(const Array<T> &other)

If "other" is of dimension one, create a reference to it. See the warning associated with the copy constructor.

Vector(const IPosition &shape, T *storage, StorageInitPolicy policy = COPY)

Create an Vector of a given shape from a pointer.

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.

template <class U> Vector(const vector<T, U> &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. The appropriate templates are instantiated using the macro AIPS_VECTOR2_AUX_TEMPLATES(X) defined in Vector2.cc (X is the template argument needed).

virtual ~Vector()

Define a destructor, otherwise the (SUN) compiler makes a static one.

virtual void assign (const Array<T>& other)

Assign the other array (which must be dimension 1) to this vector. If the shapes mismatch, this array is resized.

virtual void reference(Array<T> &other)

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

void resize(uInt len, Bool copyValues = False)
void resize(const IPosition &len, Bool copyValues)
virtual void resize()
virtual void resize(const IPosition &len)

Resize this Vector to the given length. The default copyValues flag is False. Resize without argument is equal to resize(0, False).

virtual Array<T> &operator=(const Array<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.

Other must be a 1-dimensional array.

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.

Array<T> &operator=(const T &val)

Set every element of this Vector to Val.

Vector<T> &operator= (const MaskedArray<T> &marray)

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

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

T &operator[](uInt index)
const T &operator[](uInt index) const
T &operator()(const IPosition &i)
const T &operator()(const IPosition &i) const
T &operator()(uInt index)
const T &operator()(uInt index) const

Single-pixel addressing. If AIPS_ARRAY_INDEX_CHECK is defined, bounds checking is performed (not for [])..

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
    

Array<T> operator()(const IPosition &blc, const IPosition &trc, const IPosition &incr)
Array<T> operator()(const IPosition &blc, const IPosition &trc)
Array<T> operator()(const Slicer& slicer)

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

MaskedArray<T> operator() (const LogicalArray &mask)

The array is masked by the input LogicalArray. This mask must conform to the array.

Return a MaskedArray.

MaskedArray<T> operator() (const LogicalArray &mask) const

The array is masked by the input LogicalArray. This mask must conform to the array.

MaskedArray<T> operator() (const MaskedLogicalArray &mask)

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.

MaskedArray<T> operator() (const MaskedLogicalArray &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.

void shape(Int &Shape) const
const IPosition &shape() const

The length of the Vector.

virtual void takeStorage(const IPosition &shape, const T *storage)

Replace the data values with those in the pointer storage. The results are undefined is storage does not point at nelements() or more data elements. After takeStorage() is called, unique() is True.

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

virtual void takeStorage(const IPosition &shape, T *storage, StorageInitPolicy policy = COPY)

Replace the data values with those in the pointer storage. The results are undefined is storage does not point at nelements() or more data elements. After takeStorage() is called, unique() is True.

virtual Bool ok() const

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

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

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.

void initVector(const Block<T> &, Int nr)

Helper functions for constructors.