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()
Vector(uInt Length, Int Origin)
Vector(IPosition Length, IPosition Origin)
Vector(uInt Length)
Vector(const Block<T> &other, Int nr)
Vector(const Block<T> &other)
Vector(const Vector<T> &other)
Vector(const Array<T> &other)
~Vector()
void reference(Array<T> &other)
void resize(uInt len, Int origin)
void resize(const IPosition &len, const IPosition &origin)
void resize(uInt len)
void resize(const IPosition &len)
Vector<T> &operator=(const Vector<T> &other)
Array<T> &operator=(const Array<T> &other)
Array<T> &operator=(const T &val)
Vector<T> &operator= (const ROMaskedArray<T> &marray)
T &operator()(const IPosition &i)
const T &operator()(const IPosition &i) const
T &operator()(Int index)
const T &operator()(Int 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)
ROMaskedArray<T> operator() (const LogicalArray &mask) const
MaskedArray<T> operator() (const LogicalArray &mask)
ROMaskedArray<T> operator() (const ROMaskedLogicalArray &mask) const
MaskedArray<T> operator() (const ROMaskedLogicalArray &mask)
void origin(Int &Origin) const
IPosition origin() const
void shape(Int &Shape) const
IPosition shape() const
void end(Int &End) const
IPosition end() const
Bool ok() const
rtti_dcl_mbrf_p1(Vector<T>, Array<T>)
Private Members
void initVector(const Block<T> &, Int nr)

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

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.

Vector(IPosition Length, IPosition Origin)

A Vector with a defined length and origin.

Vector(uInt Length, Int Origin)

A Vector with a defined length and origin.

Vector(uInt Length)

A Vector with a defined length and origin of zero.

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.

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

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

void reference(Array<T> &other)

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

void resize(const IPosition &len, const IPosition &origin)

Resize this Vector to the given length and use the given origin.

void resize(uInt len, Int origin)

Resize this Vector to the given length and use the given origin.

void resize(const IPosition &len)

Resize this Vector to the given length. Zero-origin.

void resize(uInt len)

Resize this Vector to the given length. Zero-origin.

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 but not necessarily same origin).

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 but not necessarily same origin).

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

Set every element of this Vector to Val.

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

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

T &operator()(const IPosition &i)

Single-pixel addressing. If AIPS_ARRAY_INDEX_CHECK is defined, bounds checking is performed.

const T &operator()(const IPosition &i) const

Single-pixel addressing. If AIPS_ARRAY_INDEX_CHECK is defined, bounds checking is performed.

const T &operator()(Int index) const

Single-pixel addressing. If AIPS_ARRAY_INDEX_CHECK is defined, bounds checking is performed.

T &operator()(Int index)

Single-pixel addressing. If AIPS_ARRAY_INDEX_CHECK is defined, bounds checking is performed.

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)

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

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

Slice using IPositions. Required to be defined because 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, but it does not need to have the same origin.

Return a MaskedArray.

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

The array is masked by the input LogicalArray. This mask must conform to the array, but it does not need to have the same origin.

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

The array is masked by the input ROMaskedLogicalArray. The mask is effectively the AND of the internal LogicalArray and the internal mask of the ROMaskedLogicalArray. The ROMaskedLogicalArray must conform to the array, but it does not need to have the same origin.

Return a MaskedArray.

ROMaskedArray<T> operator() (const ROMaskedLogicalArray &mask) const

The array is masked by the input ROMaskedLogicalArray. The mask is effectively the AND of the internal LogicalArray and the internal mask of the ROMaskedLogicalArray. The ROMaskedLogicalArray must conform to the array, but it does not need to have the same origin.

IPosition origin() const

The position of the first element.

void origin(Int &Origin) const

The position of the first element.

IPosition shape() const

The length of the Vector.

void shape(Int &Shape) const

The length of the Vector.

IPosition end() const

The position of the last element.

void end(Int &End) const

The position of the last element.

Bool ok() const

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

rtti_dcl_mbrf_p1(Vector<T>, Array<T>)

Macro to define the typeinfo member functions

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

Helper functions for constructors.

Copyright © 1995 Associated Universities Inc., Washington, D.C.