Matrix.h
Classes
- Matrix -- A 2-D Specialization of the Array class (full description)
template<class T> class Matrix : public Array<T>
Interface
- Public Members
- Matrix()
- Matrix(uInt l1, uInt l2)
- Matrix(uInt l1, uInt l2, const T &initialValue)
- Matrix(const IPosition &len)
- Matrix(const IPosition &len, const T &initialValue)
- Matrix(const Matrix<T> &other)
- Matrix(const Array<T> &other)
- Matrix(const IPosition &shape, T *storage, StorageInitPolicy policy = COPY)
- Matrix(const IPosition &shape, const T *storage)
- virtual ~Matrix()
- virtual void assign (const Array<T>& other)
- virtual void reference(Array<T> &other)
- void resize(uInt nx, uInt ny)
- virtual void resize()
- virtual void resize(const IPosition &len)
- Matrix<T> &operator=(const Matrix<T> &other)
- virtual Array<T> &operator=(const Array<T> &other)
- Array<T> &operator=(const T &val)
- Matrix<T> &operator= (const MaskedArray<T> &marray)
- T &operator()(const IPosition &i)
- const T &operator()(const IPosition &i) const
- T &operator()(uInt i1, uInt i2)
- const T &operator()(uInt i1, uInt i2) const
- 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)
- Vector<T> row(uInt i)
- Vector<T> row(uInt i) const
- const Vector<T> row(uInt i) const
- Vector<T> column(uInt j)
- Vector<T> column(uInt j) const
- const Vector<T> column(uInt j) const
- Vector<T> diagonal( )
- Vector<T> diagonal( ) const
- const Vector<T> diagonal( ) const
- Vector<T> diagonal(Int n)
- Vector<T> diagonal(Int n) const
- const Vector<T> diagonal(Int n) const
- Matrix<T> operator()(const Slice &sliceX, const Slice &sliceY)
- 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)
- void shape(Int &s1, Int &s2) const
- const IPosition &shape() const
- uInt nrow() const
- uInt ncolumn() 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 makeIndexingConstants()
- 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.
- LogicalMatrix -- Logical valued Matrices.
- 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.
Matrix objects are two-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
Matrix versions which take a pair of integers where the array
needs an IPosition. Since the Matrix
is two-dimensional, the IPositions are overkill, although you may
use those versions if you want to.
Matrix<Int> mi(100,100); // Shape is 100x100
mi.resize(50,50); // Shape now 50x50
Slices may be taken with the Slice class. To take a slice, one "indexes"
with one Slice(start, length, inc) for each axis,
where end and inc are optional.
Additionally, there are row(), column() and diagonal()
member functions which return Vector's which refer to the storage back
in the Matrix:
Matrix<Float> mf(100, 100);
mf.diagonal() = 1;
Correct indexing order of a matrix is:
Matrix<Int> mi(n1,n2) // [nrow, ncolumn]
for (uInt j=0; j<mi.ncolumn(); j++) {
for (uInt i=0; i<mi.nrow(); i++) {
mi(i,j) = i*j;
}
}
Element-by-element arithmetic and logical operations are available (in
aips/ArrayMath.h and aips/ArrayLogical.h). Other Matrix operations (e.g.
LU decomposition) are available, and more appear periodically.
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
A Matrix of length zero in each dimension; zero origin.
Matrix(uInt l1, uInt l2)
A Matrix with "l1" rows and "l2" columns.
Matrix(uInt l1, uInt l2, const T &initialValue)
A Matrix with "l1" rows and "l2" columns.
Fill it with the initial value.
A matrix of shape with shape "len".
Matrix(const IPosition &len, const T &initialValue)
A matrix of shape with shape "len".
Fill it with the initial value.
Matrix(const Matrix<T> &other)
The copy constructor uses reference semantics.
The copy constructor should normally be avoided. More
details are available under the documentation for Array.
Construct a Matrix by reference from "other". "other must have
ndim() of 2 or less. The warning which applies to the copy constructor
is also valid here.
Matrix(const IPosition &shape, T *storage, StorageInitPolicy policy = COPY)
Create an Matrix of a given shape from a pointer.
Matrix(const IPosition &shape, const T *storage)
Create an Matrix of a given shape from a pointer. Because the pointer
is const, a copy is always made.
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 2) to this matrix.
If the shapes mismatch, this array is resized.
Make this matrix a reference to other. Other must be of dimensionality
2 or less.
void resize(uInt nx, uInt ny)
virtual void resize()
virtual void resize(const IPosition &len)
Resize to the given shape (must be 2-dimensional).
Resize without argument is equal to resize(0,0).
Matrix<T> &operator=(const Matrix<T> &other)
virtual Array<T> &operator=(const Array<T> &other)
Copy the values from other to this Matrix. If this matrix has zero
elements then it will resize to be the same shape as other; otherwise
other must conform to this.
Note that the assign function can be used to assign a
non-conforming matrix.
Copy val into every element of this Matrix; i.e. behaves as if
val were a constant conformant matrix.
Matrix<T> &operator= (const MaskedArray<T> &marray)
Copy to this those values in marray whose corresponding elements
in marray's mask are True.
T &operator()(const IPosition &i)
const T &operator()(const IPosition &i) const
T &operator()(uInt i1, uInt i2)
const T &operator()(uInt i1, uInt i2) const
Single-pixel addressing. If AIPS_ARRAY_INDEX_CHECK is defined,
bounds checking is performed.
The array is masked by the input LogicalArray.
This mask must conform to the array.
Return a MaskedArray.
The array is masked by the input LogicalArray.
This mask must conform to the array.
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.
Vector<T> row(uInt i)
Vector<T> row(uInt i) const
const Vector<T> row(uInt i) const
Returns a reference to the i'th row.
Returns a reference to the j'th column
Returns a diagonal from the Matrix. The Matrix must be square.
n==0 is the main diagonal. n>0 is above the main diagonal, n<0
is below it.
Returns a diagonal from the Matrix. The Matrix must be square.
Matrix<T> operator()(const Slice &sliceX, const Slice &sliceY)
Take a slice of this matrix. Slices are always indexed starting
at zero. This uses reference semantics, i.e. changing a value
in the slice changes the original.
Matrix<Double> vd(100,100);
//...
vd(Slice(0,10),Slice(10,10)) = -1.0; // 10x10 sub-matrix set to -1.0
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.
void shape(Int &s1, Int &s2) const
const IPosition &shape() const
The length of each axis of the Matrix.
uInt nrow() const
The number of rows in the Matrix, i.e. the length of the first axis.
The number of columns in the Matrix, i.e. the length of the 2nd axis.
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
Checks that the Matrix is consistent (invariants check out).
virtual void doNonDegenerate(Array<T> &other, const IPosition &ignoreAxes)
Remove the degenerate axes from other and store result in this matrix.
An exception is thrown if removing degenerate axes does not result
in a matrix.
Helper fn to calculate the indexing constants.