- IPositionVersion = 1
- BufferLength = 4
IPosition objects are normally used to index into, and define the shapes of, multi-dimensional arrays. For example, if you have a 5 dimensional array, you need an IPosition of length 5 to index into the array (or to define its shape, etc.).
Unlike Vectors, IPositions always use copy semantics.
IPosition ip1(5); // An IPosition of length 5 ip1(0) = 11; ip1(1) = 5; ... ip1(4) = 6; // Indices 0-based IPosition ip2(ip1); // Copy constructor; a COPY
Binary operations must take place either with a conformnat (same size) IPosition or with an integer, which behaves as if it was an IPosition of the same size (i.e., length). All the usual binary arithmetic operations are available, as well as logical operations, which return Booleans. These all operate "element-by-element".
All non-inlined member functions of IPosition check invariants if the preprocessor symbol AIPS_DEBUG is defined. That is, the member functions check that ok() is true (constructors check after construction, other functions on entry to the function). If these tests fail, an AipsError exception is thrown; its message contains the line number and source file of the failure (it is thrown by the lAssert macro defined in aips/Assert.h).
IPosition blc(5), trc(5,1,2,3,4,5); blc = 0; // OR IPosition blc(5,0); //... if (blc > trc) { IPosition tmp; tmp = trc; // Swap trc = blc; blc = tmp; } //... trc += 5; // make the box 5 larger in all dimensions
An IPosition of size "length." The values in the object are undefined.
An IPosition of size "length." The values in the object get initialized to val.
An IPosition of size "length" with defined values. You need to supply a value for each element of the IPosition (up to 10). [Unfortunately varargs might not be sufficiently portable.]
Makes a copy (copy, NOT reference, semantics) of other.
Makes this a copy of other. "this" and "other" must either be conformant (same size) or this must be 0-length, in which case it will resize itself to be the same length as other.
Copy "value" into every position of this IPosition.
Construct a default axis path consisting of the values 0 .. nrdim-1.
Construct a full axis path from a (partially) given axis path. It fills the path with the non-given axis. It is checked if the given axis path is valid (i.e. if the axis are < nrdim and if they are not doubly defined). E.g.: in the 4D case an axis path [0,2] is returned as [0,2,1,3].
Make a list of axes which are the axes not given in axes up to the given dimension
Convert an IPosition to and from an Array
This member functions return an IPosition which has
degenerate (length==1) axes removed and the dimensionality reduced
appropriately.
Only axes greater than startingAxis are considered (normally one
wants to remove trailing axes.
Old values are copied on resize if copy==True..
If the size increases, values beyond the former size are undefined.
Index into the IPosition. Indices are zero-based. If the preprocessor
symbol AIPS_ARRAY_INDEX_CHECK is defined, operator() will check
"index" to ensure it is not out of bounds. If this check fails, an
AipsError will be thrown.
Get the storage.
Append this IPosition with another one (causing a resize).
Prepend this IPosition with another one (causing a resize).
Return an IPosition as the concetanation of this and another IPosition.
Set the first values of this IPosition to another IPosition.
An exception is thrown if the other IPosition is too long.
Set the last values of this IPosition to another IPosition.
An exception is thrown if the other IPosition is too long.
Construct an IPosition from the first n values of this
IPosition.
An exception is thrown if n is too high.
Construct an IPosition from the last n values of this
IPosition.
An exception is thrown if n is too high.
The number of elements in this IPosition. Since IPosition
objects use zero-based indexing, the maximum available index is
nelements() - 1.
conform returns true if nelements() == other.nelements().
Element-by-element arithmetic.
Returns 0 if nelements() == 0, otherwise it returns the product of
its elements.
Element-by-element comparison for equality.
It returns True if the lengths and all elements are equal.
Element-by-element comparison for equality.
It returns True if all elements are equal.
When skipDegeneratedAxes is True, axes with
length 1 are skipped in both operands.
Element-by-element comparison for (partial) equality.
It returns True if the lengths and the first nrCompare
elements are equal.
Is the other IPosition a subset of (or equal to) this IPosition?
It is a subset if zero or more axes of this IPosition do not occur
or are degenerated in the other and if the remaining axes are
in the same order.
Write an IPosition to an ostream in a simple text form.
Write an IPosition to an AipsIO stream in a binary format.
Write an IPosition to a LogIO stream.
Read an IPosition from an AipsIO stream in a binary format.
Will throw an AipsError if the current IPosition Version does not match
that of the one on disk.
Is this IPosition consistent?
Define the STL-style iterators.
It makes it possible to iterate through all data elements.
Throw an index error exception.
Element by element arithmetic on IPositions.
Returns the element by element minimum or maximum.
Element by element boolean operations on IPositions. The result is true
only if the operation yields true for every element of the IPosition.
Convert between IPosition and offset in an array.
The offset of an element in an array is the number of elements from the
origin that the element would be if the array were arranged linearly.
The origin of the array has an offset equal to 0, while the
"top right corner" of the array has an offset equal to one less than the
total number of elements in the array.
Two examples of offset would be the index in a carray and the seek position
in a file.
Convert from IPosition to offset in an array. The second of these
functions requires that type T have shape and origin members which return
IPositions.
Determine if the given offset or IPosition is inside the array. Returns
True if it is inside the Array. The second and fourth of these functions
require that type T have shape and origin members which return
IPositions.
IPosition nonDegenerate(uInt startingAxis=0) const
IPosition nonDegenerate(const IPosition& ignoreAxes) const
The functions with argument ignoreAxes do
not consider the axes given in that argument..
void resize(uInt newSize, Bool copy=True)
Int& operator[] (uInt index)
Int operator[] (uInt index) const
Int& operator() (uInt index)
Int operator() (uInt index) const
const Int *storage() const
void append (const IPosition& other)
void prepend (const IPosition& other)
IPosition concatenate (const IPosition& other) const
void setFirst (const IPosition& other)
void setLast (const IPosition& other)
IPosition getFirst (uInt n) const
IPosition getLast (uInt n) const
uInt nelements() const
uInt size() const
Bool conform(const IPosition& other) const
void operator += (const IPosition& other)
void operator -= (const IPosition& other)
void operator *= (const IPosition& other)
void operator /= (const IPosition& other)
void operator += (Int val)
void operator -= (Int val)
void operator *= (Int val)
void operator /= (Int val)
Int product() const
Bool isEqual (const IPosition& other) const
Note that an important difference between this function and operator==()
is that if the two IPositions have different lengths, this function
returns False, instead of throwing an exception as operator==() does.
Bool isEqual (const IPosition& other, Bool skipDegeneratedAxes) const
Bool isEqual (const IPosition& other, uInt nrCompare) const
Bool isSubSet (const IPosition& other) const
friend std::ostream& operator<<(std::ostream& os, const IPosition& ip)
friend AipsIO& operator<<(AipsIO& aio, const IPosition& ip)
friend LogIO& operator<<(LogIO& io, const IPosition& ip)
friend AipsIO& operator>>(AipsIO& aio, IPosition& ip)
Bool ok() const
iterator begin()
const_iterator begin() const
const_iterator end() const
IPosition shp(2,0);
for (IPosition::iterator iter=shp.begin(); iter!=shp.end(); iter++) {
*iter += 1;
}
void allocateBuffer()
Allocate a buffer with length size_p.
void throwIndexError() const
enum
Arithmetic Operations for IPosition's (source)
Interface
Description
Member Description
IPosition operator + (const IPosition& left, const IPosition& right)
Each operation is done on corresponding elements of the IPositions. The
two IPositions must have the same number of elements otherwise an
exception (ArrayConformanceError) will be thrown.
IPosition operator - (const IPosition& left, const IPosition& right)
IPosition operator * (const IPosition& left, const IPosition& right)
IPosition operator / (const IPosition& left, const IPosition& right)
IPosition operator + (const IPosition& left, Int val)
Each operation is done by appliying the integer argument to all elements
of the IPosition argument.
IPosition operator - (const IPosition& left, Int val)
IPosition operator * (const IPosition& left, Int val)
IPosition operator / (const IPosition& left, Int val)
IPosition operator + (Int val, const IPosition& right)
Same functions as above but with with the Int argument on the left side.
IPosition operator - (Int val, const IPosition& right)
IPosition operator * (Int val, const IPosition& right)
IPosition operator / (Int val, const IPosition& right)
IPosition max (const IPosition& left, const IPosition& right)
IPosition min (const IPosition& left, const IPosition& right)
Logical operations for IPosition's (source)
Interface
Description
Member Description
Bool operator == (const IPosition& left, const IPosition& right)
Each operation is done on corresponding elements of the IPositions. The
two IPositions must have the same number of elements otherwise an
exception (ArrayConformanceError) will be thrown.
Bool operator != (const IPosition& left, const IPosition& right)
Bool operator < (const IPosition& left, const IPosition& right)
Bool operator <= (const IPosition& left, const IPosition& right)
Bool operator > (const IPosition& left, const IPosition& right)
Bool operator >= (const IPosition& left, const IPosition& right)
Bool operator == (const IPosition& left, Int val)
Each operation is done by appliying the integer argument to all elements
Bool operator != (const IPosition& left, Int val)
Bool operator < (const IPosition& left, Int val)
Bool operator <= (const IPosition& left, Int val)
Bool operator > (const IPosition& left, Int val)
Bool operator >= (const IPosition& left, Int val)
Bool operator == (Int val, const IPosition& right)
Same functions as above but with with the Int argument on the left side.
Bool operator != (Int val, const IPosition& right)
Bool operator < (Int val, const IPosition& right)
Bool operator <= (Int val, const IPosition& right)
Bool operator > (Int val, const IPosition& right)
Bool operator >= (Int val, const IPosition& right)
Indexing functions for IPosition's (source)
Interface
Description
Member Description
IPosition toIPositionInArray (const uInt offset, const IPosition& shape)
Convert from offset to IPosition in an array. The second of these
functions requires that type T have shape and origin members which return
IPositions.
uInt toOffsetInArray (const IPosition& iposition, const IPosition& shape)
Bool isInsideArray (const uInt offset, const IPosition& shape)
Bool isInsideArray (const IPosition& iposition, const IPosition& shape)
Thrown Exceptions