casacore
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
casacore::Matrix< T > Class Template Reference

More...

#include <Matrix.h>

Public Member Functions

 Matrix ()
 A Matrix of length zero in each dimension; zero origin. More...
 
 Matrix (size_t l1, size_t l2)
 A Matrix with "l1" rows and "l2" columns. More...
 
 Matrix (size_t l1, size_t l2, ArrayInitPolicy initPolicy)
 A Matrix with "l1" rows and "l2" columns. More...
 
 Matrix (size_t l1, size_t l2, const T &initialValue)
 A Matrix with "l1" rows and "l2" columns. More...
 
 Matrix (const IPosition &len)
 A matrix of shape with shape "len". More...
 
 Matrix (const IPosition &len, ArrayInitPolicy initPolicy)
 A matrix of shape with shape "len". More...
 
 Matrix (const IPosition &len, const T &initialValue)
 A matrix of shape with shape "len". More...
 
 Matrix (const Matrix< T > &other)
 The copy constructor uses reference semantics. More...
 
 Matrix (const Array< T > &other)
 Construct a Matrix by reference from "other". More...
 
 Matrix (const IPosition &shape, T *storage, StorageInitPolicy policy=COPY)
 Create an Matrix of a given shape from a pointer. More...
 
 Matrix (const IPosition &shape, T *storage, StorageInitPolicy policy, AbstractAllocator< T > const &allocator)
 Create an Matrix of a given shape from a pointer. More...
 
 Matrix (const IPosition &shape, const T *storage)
 Create an Matrix of a given shape from a pointer. More...
 
virtual ~Matrix ()
 Define a destructor, otherwise the (SUN) compiler makes a static one. More...
 
virtual void assign (const Array< T > &other)
 Assign the other array (which must be dimension 2) to this matrix. More...
 
virtual void reference (const Array< T > &other)
 Make this matrix a reference to other. More...
 
void resize (size_t nx, size_t ny, Bool copyValues=False)
 
void resize (size_t nx, size_t ny, Bool copyValues, ArrayInitPolicy policy)
 
virtual void resize ()
 
virtual void resize (const IPosition &newShape, Bool copyValues, ArrayInitPolicy policy)
 
Matrix< T > & operator= (const Matrix< T > &other)
 Copy the values from other to this Matrix. More...
 
virtual Array< T > & operator= (const Array< T > &other)
 
Array< T > & operator= (const T &val)
 Copy val into every element of this Matrix; i.e. More...
 
Matrix< T > & operator= (const MaskedArray< T > &marray)
 Copy to this those values in marray whose corresponding elements in marray's mask are True. More...
 
T & operator() (const IPosition &i)
 Single-pixel addressing. More...
 
const T & operator() (const IPosition &i) const
 
T & operator() (size_t i1, size_t i2)
 
const T & operator() (size_t i1, size_t i2) const
 
MaskedArray< T > operator() (const LogicalArray &mask) const
 The array is masked by the input LogicalArray. More...
 
MaskedArray< T > operator() (const LogicalArray &mask)
 Return a MaskedArray. More...
 
MaskedArray< T > operator() (const MaskedLogicalArray &mask) const
 The array is masked by the input MaskedLogicalArray. More...
 
MaskedArray< T > operator() (const MaskedLogicalArray &mask)
 Return a MaskedArray. More...
 
Vector< T > row (size_t i)
 Returns a reference to the i'th row. More...
 
const Vector< T > row (size_t i) const
 
Vector< T > column (size_t j)
 Returns a reference to the j'th column. More...
 
const Vector< T > column (size_t j) const
 
Vector< T > diagonal (Int64 n=0)
 Returns a diagonal from the Matrix. More...
 
const Vector< T > diagonal (Int64 n=0) const
 
Matrix< T > operator() (const Slice &sliceX, const Slice &sliceY)
 Take a slice of this matrix. More...
 
const Matrix< T > operator() (const Slice &sliceX, const Slice &sliceY) const
 
Array< T > operator() (const IPosition &blc, const IPosition &trc, const IPosition &incr)
 Slice using IPositions. More...
 
const Array< T > operator() (const IPosition &blc, const IPosition &trc, const IPosition &incr) const
 
Array< T > operator() (const IPosition &blc, const IPosition &trc)
 
const Array< T > operator() (const IPosition &blc, const IPosition &trc) const
 
Array< T > operator() (const Slicer &slicer)
 
const Array< T > operator() (const Slicer &slicer) const
 
const IPositionshape () const
 The length of each axis of the Matrix. More...
 
void shape (Int &s1, Int &s2) const
 
size_t nrow () const
 The number of rows in the Matrix, i.e. More...
 
size_t ncolumn () const
 The number of columns in the Matrix, i.e. More...
 
virtual Bool ok () const
 Checks that the Matrix is consistent (invariants check out). More...
 

Static Public Member Functions

static Matrix< T > identity (size_t n)
 Create an identity matrix of side length n. More...
 

Protected Member Functions

virtual void preTakeStorage (const IPosition &shape)
 
virtual void postTakeStorage ()
 
virtual void doNonDegenerate (const Array< T > &other, const IPosition &ignoreAxes)
 Remove the degenerate axes from other and store result in this matrix. More...
 

Private Member Functions

void makeIndexingConstants ()
 Helper fn to calculate the indexing constants. More...
 

Private Attributes

size_t xinc_p
 Cached constants to improve indexing. More...
 
size_t yinc_p
 

Detailed Description

template<class T>
class casacore::Matrix< T >

A 2-D Specialization of the Array class

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

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.

Definition at line 94 of file Matrix.h.

Constructor & Destructor Documentation

◆ Matrix() [1/12]

template<class T >
casacore::Matrix< T >::Matrix ( )

A Matrix of length zero in each dimension; zero origin.

◆ Matrix() [2/12]

template<class T >
casacore::Matrix< T >::Matrix ( size_t  l1,
size_t  l2 
)

A Matrix with "l1" rows and "l2" columns.

◆ Matrix() [3/12]

template<class T >
casacore::Matrix< T >::Matrix ( size_t  l1,
size_t  l2,
ArrayInitPolicy  initPolicy 
)

A Matrix with "l1" rows and "l2" columns.

◆ Matrix() [4/12]

template<class T >
casacore::Matrix< T >::Matrix ( size_t  l1,
size_t  l2,
const T &  initialValue 
)

A Matrix with "l1" rows and "l2" columns.

Fill it with the initial value.

◆ Matrix() [5/12]

template<class T >
casacore::Matrix< T >::Matrix ( const IPosition len)

A matrix of shape with shape "len".

◆ Matrix() [6/12]

template<class T >
casacore::Matrix< T >::Matrix ( const IPosition len,
ArrayInitPolicy  initPolicy 
)

A matrix of shape with shape "len".

◆ Matrix() [7/12]

template<class T >
casacore::Matrix< T >::Matrix ( const IPosition len,
const T &  initialValue 
)

A matrix of shape with shape "len".

Fill it with the initial value.

◆ Matrix() [8/12]

template<class T >
casacore::Matrix< T >::Matrix ( const Matrix< T > &  other)

The copy constructor uses reference semantics.

◆ Matrix() [9/12]

template<class T >
casacore::Matrix< T >::Matrix ( const Array< T > &  other)

Construct a Matrix by reference from "other".

"other must have ndim() of 2 or less.

◆ Matrix() [10/12]

template<class T >
casacore::Matrix< T >::Matrix ( const IPosition shape,
T *  storage,
StorageInitPolicy  policy = COPY 
)

Create an Matrix of a given shape from a pointer.

◆ Matrix() [11/12]

template<class T >
casacore::Matrix< T >::Matrix ( const IPosition shape,
T *  storage,
StorageInitPolicy  policy,
AbstractAllocator< T > const &  allocator 
)

Create an Matrix of a given shape from a pointer.

◆ Matrix() [12/12]

template<class T >
casacore::Matrix< T >::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.

◆ ~Matrix()

template<class T >
virtual casacore::Matrix< T >::~Matrix ( )
virtual

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

Member Function Documentation

◆ assign()

template<class T >
virtual void casacore::Matrix< T >::assign ( const Array< T > &  other)
virtual

Assign the other array (which must be dimension 2) to this matrix.

If the shapes mismatch, this array is resized.

◆ column() [1/2]

template<class T >
Vector<T> casacore::Matrix< T >::column ( size_t  j)

Returns a reference to the j'th column.

◆ column() [2/2]

template<class T >
const Vector<T> casacore::Matrix< T >::column ( size_t  j) const

◆ diagonal() [1/2]

template<class T >
Vector<T> casacore::Matrix< T >::diagonal ( Int64  n = 0)

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.

◆ diagonal() [2/2]

template<class T >
const Vector<T> casacore::Matrix< T >::diagonal ( Int64  n = 0) const

◆ doNonDegenerate()

template<class T >
virtual void casacore::Matrix< T >::doNonDegenerate ( const Array< T > &  other,
const IPosition ignoreAxes 
)
protectedvirtual

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.

◆ identity()

template<class T >
static Matrix<T> casacore::Matrix< T >::identity ( size_t  n)
static

Create an identity matrix of side length n.

(Could not do this as a constructor because of ambiguities with other constructors).

◆ makeIndexingConstants()

template<class T >
void casacore::Matrix< T >::makeIndexingConstants ( )
private

Helper fn to calculate the indexing constants.

◆ ncolumn()

template<class T >
size_t casacore::Matrix< T >::ncolumn ( ) const
inline

The number of columns in the Matrix, i.e.

the length of the 2nd axis.

Definition at line 305 of file Matrix.h.

◆ nrow()

template<class T >
size_t casacore::Matrix< T >::nrow ( ) const
inline

The number of rows in the Matrix, i.e.

the length of the first axis.

Definition at line 301 of file Matrix.h.

◆ ok()

template<class T >
virtual Bool casacore::Matrix< T >::ok ( ) const
virtual

Checks that the Matrix is consistent (invariants check out).

◆ operator()() [1/16]

template<class T >
Array<T> casacore::Matrix< T >::operator() ( const IPosition blc,
const IPosition trc 
)
inline

Definition at line 284 of file Matrix.h.

◆ operator()() [2/16]

template<class T >
const Array<T> casacore::Matrix< T >::operator() ( const IPosition blc,
const IPosition trc 
) const
inline

Definition at line 286 of file Matrix.h.

◆ operator()() [3/16]

template<class T >
Array<T> casacore::Matrix< 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.

Definition at line 278 of file Matrix.h.

◆ operator()() [4/16]

template<class T >
const Array<T> casacore::Matrix< T >::operator() ( const IPosition blc,
const IPosition trc,
const IPosition incr 
) const
inline

Definition at line 281 of file Matrix.h.

◆ operator()() [5/16]

template<class T >
T& casacore::Matrix< T >::operator() ( const IPosition i)
inline

Single-pixel addressing.

If AIPS_ARRAY_INDEX_CHECK is defined, bounds checking is performed.

Definition at line 186 of file Matrix.h.

◆ operator()() [6/16]

template<class T >
const T& casacore::Matrix< T >::operator() ( const IPosition i) const
inline

Definition at line 188 of file Matrix.h.

◆ operator()() [7/16]

template<class T >
MaskedArray<T> casacore::Matrix< T >::operator() ( const LogicalArray &  mask)
inline

Return a MaskedArray.

Definition at line 219 of file Matrix.h.

◆ operator()() [8/16]

template<class T >
MaskedArray<T> casacore::Matrix< 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.

Definition at line 215 of file Matrix.h.

◆ operator()() [9/16]

template<class T >
MaskedArray<T> casacore::Matrix< T >::operator() ( const MaskedLogicalArray &  mask)
inline

Return a MaskedArray.

Definition at line 236 of file Matrix.h.

◆ operator()() [10/16]

template<class T >
MaskedArray<T> casacore::Matrix< 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.

Definition at line 232 of file Matrix.h.

◆ operator()() [11/16]

template<class T >
Matrix<T> casacore::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

◆ operator()() [12/16]

template<class T >
const Matrix<T> casacore::Matrix< T >::operator() ( const Slice sliceX,
const Slice sliceY 
) const

◆ operator()() [13/16]

template<class T >
Array<T> casacore::Matrix< T >::operator() ( const Slicer slicer)
inline

Definition at line 288 of file Matrix.h.

◆ operator()() [14/16]

template<class T >
const Array<T> casacore::Matrix< T >::operator() ( const Slicer slicer) const
inline

Definition at line 290 of file Matrix.h.

◆ operator()() [15/16]

template<class T >
T& casacore::Matrix< T >::operator() ( size_t  i1,
size_t  i2 
)
inline

Definition at line 190 of file Matrix.h.

◆ operator()() [16/16]

template<class T >
const T& casacore::Matrix< T >::operator() ( size_t  i1,
size_t  i2 
) const
inline

Definition at line 199 of file Matrix.h.

◆ operator=() [1/4]

template<class T >
virtual Array<T>& casacore::Matrix< T >::operator= ( const Array< T > &  other)
virtual

◆ operator=() [2/4]

template<class T >
Matrix<T>& casacore::Matrix< T >::operator= ( const MaskedArray< T > &  marray)
inline

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

Definition at line 179 of file Matrix.h.

◆ operator=() [3/4]

template<class T >
Matrix<T>& casacore::Matrix< T >::operator= ( const Matrix< 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.

◆ operator=() [4/4]

template<class T >
Array<T>& casacore::Matrix< T >::operator= ( const T &  val)
inline

Copy val into every element of this Matrix; i.e.

behaves as if val were a constant conformant matrix.

Definition at line 174 of file Matrix.h.

◆ postTakeStorage()

template<class T >
virtual void casacore::Matrix< T >::postTakeStorage ( )
protectedvirtual

◆ preTakeStorage()

template<class T >
virtual void casacore::Matrix< T >::preTakeStorage ( const IPosition shape)
protectedvirtual

◆ reference()

template<class T >
virtual void casacore::Matrix< T >::reference ( const Array< T > &  other)
virtual

Make this matrix a reference to other.

Other must be of dimensionality 2 or less.

◆ resize() [1/4]

template<class T >
virtual void casacore::Matrix< T >::resize ( )
virtual

◆ resize() [2/4]

template<class T >
virtual void casacore::Matrix< T >::resize ( const IPosition newShape,
Bool  copyValues,
ArrayInitPolicy  policy 
)
virtual

◆ resize() [3/4]

template<class T >
void casacore::Matrix< T >::resize ( size_t  nx,
size_t  ny,
Bool  copyValues,
ArrayInitPolicy  policy 
)

◆ resize() [4/4]

template<class T >
void casacore::Matrix< T >::resize ( size_t  nx,
size_t  ny,
Bool  copyValues = False 
)
inline

◆ row() [1/2]

template<class T >
Vector<T> casacore::Matrix< T >::row ( size_t  i)

Returns a reference to the i'th row.

◆ row() [2/2]

template<class T >
const Vector<T> casacore::Matrix< T >::row ( size_t  i) const

◆ shape() [1/2]

template<class T >
const IPosition& casacore::Matrix< T >::shape ( ) const
inline

The length of each axis of the Matrix.

Definition at line 295 of file Matrix.h.

◆ shape() [2/2]

template<class T >
void casacore::Matrix< T >::shape ( Int s1,
Int s2 
) const
inline

Definition at line 297 of file Matrix.h.

Member Data Documentation

◆ xinc_p

template<class T >
size_t casacore::Matrix< T >::xinc_p
private

Cached constants to improve indexing.

Definition at line 322 of file Matrix.h.

Referenced by casacore::Matrix< Complex >::operator()().

◆ yinc_p

template<class T >
size_t casacore::Matrix< T >::yinc_p
private

Definition at line 322 of file Matrix.h.

Referenced by casacore::Matrix< Complex >::operator()().


The documentation for this class was generated from the following files:
casacore::uInt
unsigned int uInt
Definition: aipstype.h:51