casa
$Rev:20696$
|
A 1-D Specialization of the Array class. More...
#include <Vector.h>
Public Member Functions | |
Vector () | |
A zero-length Vector. | |
Vector (uInt Length) | |
A Vector with a defined length and origin of zero. | |
Vector (const IPosition &Length) | |
Vector (uInt Length, const T &initialValue) | |
A Vector with a defined length and origin of zero. | |
Vector (const IPosition &Length, const T &initialValue) | |
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. | |
Vector (const Array< T > &other) | |
Create a reference to the other array. | |
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. | |
template<class U > | |
Vector (const vector< T, U > &other) | |
Create a Vector from an STL vector (see tovector() in Array for the reverse operation). | |
template<class U > | |
Vector (const std::set< U > &other) | |
virtual | ~Vector () |
Define a destructor, otherwise the compiler makes a static one. | |
virtual void | assign (const Array< T > &other) |
Assign the other array (which must be of dimension one) to this vector. | |
virtual void | reference (const Array< T > &other) |
Create a reference to "other", which must be of dimension one. | |
void | resize (uInt len, Bool copyValues=False) |
Resize this Vector to the given length. | |
virtual void | resize (const IPosition &len, Bool copyValues=False) |
virtual void | resize () |
Make this array a different shape. | |
Vector< T > & | operator= (const Vector< T > &other) |
Assign to this Vector. | |
virtual Array< T > & | operator= (const Array< T > &other) |
Other must be a 1-dimensional array. | |
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. | |
T & | operator[] (uInt index) |
Single-pixel addressing. | |
const T & | operator[] (uInt index) const |
Get the subset given by the i-th value of the last axis. | |
T & | operator() (const IPosition &i) |
Access a single element of the array. | |
const T & | operator() (const IPosition &i) const |
T & | operator() (uInt index) |
const T & | operator() (uInt index) const |
Vector< T > | operator() (const Slice &slice) |
Take a slice of this vector. | |
const Vector< T > | operator() (const Slice &slice) const |
Array< T > | operator() (const IPosition &blc, const IPosition &trc, const IPosition &incr) |
Slice using IPositions. | |
const Array< T > | operator() (const IPosition &blc, const IPosition &trc, const IPosition &incr) const |
Array< T > | operator() (const IPosition &blc, const IPosition &trc) |
Get a reference to an array section extending from start to end (inclusive). | |
const Array< T > | operator() (const IPosition &blc, const IPosition &trc) const |
Array< T > | operator() (const Slicer &slicer) |
Get a reference to an array section using a Slicer. | |
const Array< T > | operator() (const Slicer &slicer) const |
MaskedArray< T > | operator() (const LogicalArray &mask) const |
The array is masked by the input LogicalArray. | |
MaskedArray< T > | operator() (const LogicalArray &mask) |
Return a MaskedArray. | |
MaskedArray< T > | operator() (const MaskedLogicalArray &mask) const |
The array is masked by the input MaskedLogicalArray. | |
MaskedArray< T > | operator() (const MaskedLogicalArray &mask) |
Return a MaskedArray. | |
void | shape (Int &Shape) const |
The length of the Vector. | |
const IPosition & | shape () const |
The length of each axis. | |
virtual void | takeStorage (const IPosition &shape, T *storage, StorageInitPolicy policy=COPY) |
Replace the data values with those in the pointer storage . | |
virtual void | takeStorage (const IPosition &shape, const T *storage) |
Since the pointer is const, a copy is always taken. | |
virtual Bool | ok () const |
Verify that dimensionality is 1 and then call Array<T>::ok() | |
Protected Member Functions | |
virtual void | doNonDegenerate (const Array< T > &other, const IPosition &ignoreAxes) |
Remove the degenerate axes from other and store result in this vector. | |
Private Member Functions | |
void | initVector (const Block< T > &, Int nr) |
Helper functions for constructors. |
A 1-D Specialization of the Array class.
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.
casa::Vector< T >::Vector | ( | ) |
A zero-length Vector.
casa::Vector< T >::Vector | ( | uInt | Length | ) | [explicit] |
A Vector with a defined length and origin of zero.
casa::Vector< T >::Vector | ( | const IPosition & | Length | ) | [explicit] |
casa::Vector< T >::Vector | ( | uInt | Length, |
const T & | initialValue | ||
) |
A Vector with a defined length and origin of zero.
Fill it with the initial value.
casa::Vector< T >::Vector | ( | const IPosition & | Length, |
const T & | initialValue | ||
) |
casa::Vector< T >::Vector | ( | const Block< T > & | other, |
Int | nr | ||
) |
casa::Vector< T >::Vector | ( | const Block< T > & | other | ) | [explicit] |
Create a Vector of lenght other.nelements() and copy over its values.
casa::Vector< T >::Vector | ( | const Vector< T > & | other | ) |
Create a reference to other.
casa::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.
casa::Vector< T >::Vector | ( | const IPosition & | shape, |
T * | storage, | ||
StorageInitPolicy | policy = COPY |
||
) |
Create an Vector of a given shape from a pointer.
casa::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.
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
; In case of DIY template instantiation the appropriate templates are instantiated using the macro AIPS_VECTOR2_AUX_TEMPLATES(X)
defined in Vector2;cc
(X
is the template argument needed);
virtual casa::Vector< T >::~Vector | ( | ) | [virtual] |
Define a destructor, otherwise the compiler makes a static one.
virtual void casa::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.
Reimplemented from casa::Array< T >.
Referenced by casa::vi::VisBuffer2Adapter::allSelectedSpectralWindows(), casa::CTBuffer::arrayId(), casa::CTBuffer::fieldId(), casa::CFBuffer::getCoordList(), casa::VisibilityResampler::getParams(), casa::ImageStatsCalculator::setAxes(), casa::ImageStatsCalculator::setExcludePix(), casa::ImageStatsCalculator::setIncludePix(), casa::ImageStatsCalculator::setPlotStats(), and casa::CTBuffer::spectralWindows().
virtual void casa::Vector< T >::doNonDegenerate | ( | const Array< T > & | other, |
const IPosition & | ignoreAxes | ||
) | [protected, virtual] |
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.
Reimplemented from casa::Array< T >.
void casa::Vector< T >::initVector | ( | const Block< T > & | , |
Int | nr | ||
) | [private] |
Helper functions for constructors.
virtual Bool casa::Vector< T >::ok | ( | ) | const [virtual] |
Verify that dimensionality is 1 and then call Array<T>::ok()
Reimplemented from casa::Array< T >.
T& casa::Vector< T >::operator() | ( | const IPosition & | ) | [inline] |
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). If AIPS_DEBUG is defined, index checking will be performed.
Reimplemented from casa::Array< T >.
Definition at line 204 of file Vector.h.
Referenced by casa::Vector< ArgType >::operator()().
const T& casa::Vector< T >::operator() | ( | const IPosition & | i | ) | const [inline] |
Reimplemented from casa::Array< T >.
T& casa::Vector< T >::operator() | ( | uInt | index | ) | [inline] |
const T& casa::Vector< T >::operator() | ( | uInt | index | ) | const [inline] |
Vector<T> casa::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
const Vector<T> casa::Vector< T >::operator() | ( | const Slice & | slice | ) | const |
Array<T> casa::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.
Reimplemented from casa::Array< T >.
const Array<T> casa::Vector< T >::operator() | ( | const IPosition & | blc, |
const IPosition & | trc, | ||
const IPosition & | incr | ||
) | const [inline] |
Reimplemented from casa::Array< T >.
Array<T> casa::Vector< T >::operator() | ( | const IPosition & | start, |
const IPosition & | end | ||
) | [inline] |
Get a reference to an array section extending from start to end (inclusive).
Reimplemented from casa::Array< T >.
const Array<T> casa::Vector< T >::operator() | ( | const IPosition & | blc, |
const IPosition & | trc | ||
) | const [inline] |
Reimplemented from casa::Array< T >.
Array<T> casa::Vector< T >::operator() | ( | const Slicer & | ) | [inline] |
Get a reference to an array section using a Slicer.
Reimplemented from casa::Array< T >.
const Array<T> casa::Vector< T >::operator() | ( | const Slicer & | slicer | ) | const [inline] |
Reimplemented from casa::Array< T >.
MaskedArray<T> casa::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.
Reimplemented from casa::Array< T >.
MaskedArray<T> casa::Vector< T >::operator() | ( | const LogicalArray & | mask | ) | [inline] |
MaskedArray<T> casa::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.
Reimplemented from casa::Array< T >.
MaskedArray<T> casa::Vector< T >::operator() | ( | const MaskedLogicalArray & | mask | ) | [inline] |
Vector<T>& casa::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.
Referenced by casa::Vector< ArgType >::operator=().
virtual Array<T>& casa::Vector< T >::operator= | ( | const Array< T > & | other | ) | [virtual] |
Other must be a 1-dimensional array.
Reimplemented from casa::Array< T >.
Array<T>& casa::Vector< T >::operator= | ( | const T & | val | ) | [inline] |
Set every element of this Vector to Val.
Reimplemented from casa::Array< T >.
Vector<T>& casa::Vector< T >::operator= | ( | const MaskedArray< T > & | marray | ) | [inline] |
Copy to this those values in marray whose corresponding elements in marray's mask are True.
Reimplemented from casa::Array< T >.
T& casa::Vector< T >::operator[] | ( | uInt | index | ) | [inline] |
const T& casa::Vector< T >::operator[] | ( | uInt | i | ) | const [inline] |
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;
Reimplemented from casa::Array< T >.
virtual void casa::Vector< T >::reference | ( | const Array< T > & | other | ) | [virtual] |
Create a reference to "other", which must be of dimension one.
Reimplemented from casa::Array< T >.
Referenced by casa::VBStore::reference(), casa::LFBase::setBaselineFlag(), casa::VisibilityResampler::setMaps(), and casa::VisibilityResampler::setParams().
void casa::Vector< T >::resize | ( | uInt | len, |
Bool | copyValues = False |
||
) | [inline] |
Resize this Vector to the given length.
The default copyValues flag is False.
Resize without argument is equal to resize(0, False).
Definition at line 166 of file Vector.h.
Referenced by ASDM_TABLE_BASE::_2CASAString1D(), ASDM_TABLE_BASE::at2CASA1D(), casa::AWConvFunc::AWConvFunc(), casa::AWVisResampler::AWVisResampler(), ASDM_TABLE_BASE::basic2CASA1D(), casa::VisibilityResamplerBase::cacheAxisIncrements(), casa::VisibilityIteratorReadImpl::CJones(), ASDM_TABLE_BASE::enum2CASA1D(), ASDM_TABLE_BASE::ext2CASA1D(), casa::LSQaips::getErrors(), casa::EVLAAperture::getPolMap(), casa::ALMAAperture::getPolMap(), casa::ATerm::getPolMap(), casa::CFTerms::getPolMap(), ASDM_TABLE_BASE::interval2CASA1D(), casa::MSStateParse::reset(), casa::MSUvDistParse::reset(), casa::MSPolnParse::reset(), casa::MSArrayParse::reset(), casa::MSScanParse::reset(), casa::MSObservationParse::reset(), casa::MSSpwParse::reset(), casa::ALMAAperture::resetAntTypeMap(), casa::Vector< ArgType >::resize(), casa::CTPatchedInterp::setDefAntMap(), casa::CTPatchedInterp::setDefFldMap(), casa::CTPatchedInterp::setDefSpwMap(), casa::ALMAAperture::setPolMap(), casa::CFTerms::setPolMap(), casa::ATerm::setPolMap(), casa::SynthesisUtils::SETVEC(), casa::AWVisResampler::SETVEC(), casa::LSQaips::solve(), casa::vi::VisBuffer2Adapter::uvw(), casa::EVLAAperture::vbRow2CFKeyMap(), and casa::ATerm::vbRow2CFKeyMap().
virtual void casa::Vector< T >::resize | ( | const IPosition & | len, |
Bool | copyValues = False |
||
) | [virtual] |
Reimplemented from casa::Array< T >.
virtual void casa::Vector< T >::resize | ( | ) | [virtual] |
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.
Reimplemented from casa::Array< T >.
void casa::Vector< T >::shape | ( | Int & | Shape | ) | const [inline] |
The length of the Vector.
Definition at line 291 of file Vector.h.
Referenced by casa::SynthesisUtils::SETVEC(), casa::AWVisResampler::SETVEC(), and casa::VectorView< Bool >::VectorView().
const IPosition& casa::Vector< T >::shape | ( | ) | const [inline] |
The length of each axis.
Reimplemented from casa::ArrayBase.
virtual void casa::Vector< T >::takeStorage | ( | const IPosition & | shape, |
T * | storage, | ||
StorageInitPolicy | policy = COPY |
||
) | [virtual] |
Replace the data values with those in the pointer storage
.
The results are undefined is storage does not point at nelements() or more data elements. After takeStorage() is called, unique()
is True.
Reimplemented from casa::Array< T >.
virtual void casa::Vector< T >::takeStorage | ( | const IPosition & | shape, |
const T * | storage | ||
) | [virtual] |
Since the pointer is const, a copy is always taken.
Reimplemented from casa::Array< T >.
void casa::Vector< T >::toBlock | ( | Block< T > & | other | ) | const |