Matrix< T, NumberTraits > Class Template Reference

#include <Matrix.h>

List of all members.

Public Types

typedef Matrix< T, NumberTraits > matrix_type
 A shorthand for Matrix< T, NumberTraits >.
typedef T number_type
 The type of the elements the matrix holds.
typedef NumberTraits traits_type
 The AlgebraicTraits type associated to the type of matrix elements.
typedef NumberTraits::norm_type norm_type
 A type for the norm of a matrix.

Public Member Functions

 Matrix ()
 operator const number_type *const * () const
 operator number_type ** ()
const matrix_type zero () const
const matrix_type one () const
unsigned int rows () const
unsigned int cols () const
bool isNull () const
bool resize (unsigned int r, unsigned int c)
void swapRows (unsigned int i, unsigned int j)
void swapCols (unsigned int i, unsigned int j)
void multiplyRow (unsigned int row, const number_type &value)
void multiplyRowAndAddToRow (unsigned int source, unsigned int dest, const number_type &value)
void multiplyCol (unsigned int col, const number_type &value)
void multiplyColAndAddToCol (unsigned int source, unsigned int dest, const number_type &value)
void fill (const number_type &value)
 Matrix (unsigned int nRows, unsigned int nCols)
 Matrix (unsigned int dim)
 Matrix (const matrix_type &other)
 ~Matrix ()
matrix_typeoperator= (const matrix_type &other)
number_type determinant () const
void getCofactor (unsigned int i, unsigned int j, matrix_type &cofactor) const
void getMinor (const IndexSet &keep_rows, const IndexSet &keep_cols, matrix_type &minor) const
matrix_typetranspose ()
matrix_type operator * (const matrix_type &rhs) const
matrix_type operator- () const
matrix_type operator+ (const matrix_type &rhs) const
matrix_type operator- (const matrix_type &rhs) const
matrix_type operator/ (const matrix_type &rhs) const
matrix_typeoperator+= (const matrix_type &rhs)
matrix_typeoperator-= (const matrix_type &rhs)
matrix_typeoperator *= (const matrix_type &rhs)
matrix_typeoperator/= (const matrix_type &rhs)
bool operator== (const matrix_type &rhs) const
bool operator!= (const matrix_type &rhs) const
bool operator< (const matrix_type &rhs) const
matrix_type inverse () const
number_type getNorm () const
number_type getEuclideanNorm () const
void display (std::ostream &os=std::cout) const
void load (std::istream &is)
void save (std::ostream &os) const

Classes

struct  Int2Type


Detailed Description

template<class T, class NumberTraits = AlgebraicTraits< T >>
class Matrix< T, NumberTraits >

Is represented as a pointer to an array containing pointers to arrays containing the elements of each row of the matrix, and two integers representing the number of rows and the number of columns in the matrix. The matrix class provides the following public type definitions that are used throughout the implementation of the class "Matrix"

Definition at line 30 of file Matrix.h.


Constructor & Destructor Documentation

template<class T, class NumberTraits = AlgebraicTraits< T >>
Matrix< T, NumberTraits >::Matrix (  )  [inline]

Default constructor, constructs an empty matrix

Definition at line 48 of file Matrix.h.

template<class T, class NumberTraits = AlgebraicTraits< T >>
Matrix< T, NumberTraits >::Matrix ( unsigned int  nRows,
unsigned int  nCols 
) [inline]

Constructor

Parameters:
nRows no. of matrix rows
nCols no. of matrix columns

Definition at line 375 of file Matrix.h.

template<class T, class NumberTraits = AlgebraicTraits< T >>
Matrix< T, NumberTraits >::Matrix ( unsigned int  dim  )  [inline, explicit]

Constructs a square matrix

Parameters:
dim no. of matrix rows and columns

Definition at line 384 of file Matrix.h.

template<class T, class NumberTraits = AlgebraicTraits< T >>
Matrix< T, NumberTraits >::Matrix ( const matrix_type other  )  [inline]

Copy constructor

Parameters:
other matrix to copy

Definition at line 393 of file Matrix.h.

References Matrix< T, NumberTraits >::m_nCols, and Matrix< T, NumberTraits >::m_nRows.

template<class T, class NumberTraits = AlgebraicTraits< T >>
Matrix< T, NumberTraits >::~Matrix (  )  [inline]

Destructor

Definition at line 417 of file Matrix.h.


Member Function Documentation

template<class T, class NumberTraits = AlgebraicTraits< T >>
Matrix< T, NumberTraits >::operator const number_type *const * (  )  const [inline]

Provides read-only access to the elements of the matrix in the same way as accessing a C 2 dimensional array. e.g. M[0][0]

Returns:
const pointer to an array of const pointers pointing to the rows of the matrix

Definition at line 57 of file Matrix.h.

template<class T, class NumberTraits = AlgebraicTraits< T >>
Matrix< T, NumberTraits >::operator number_type ** (  )  [inline]

Provides read-write access to the elements of the matrix in the same way as accessing a C 2 dimensional array. e.g. M[0][0]

Returns:
pointer to an array of pointers pointing to the rows of the matrix

Definition at line 67 of file Matrix.h.

template<class T, class NumberTraits = AlgebraicTraits< T >>
const matrix_type Matrix< T, NumberTraits >::zero (  )  const [inline]

Create the zero matrix having the same dimensions as this matrix. This matrix can not be empty.

Definition at line 79 of file Matrix.h.

Referenced by Matrix< T, NumberTraits >::one().

Here is the caller graph for this function:

template<class T, class NumberTraits = AlgebraicTraits< T >>
const matrix_type Matrix< T, NumberTraits >::one (  )  const [inline]

Create the identity matrix having the same dimensions as this matrix. This matrix can not be empty.

Definition at line 101 of file Matrix.h.

References Matrix< T, NumberTraits >::zero().

Referenced by Matrix< T, NumberTraits >::inverse().

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T, class NumberTraits = AlgebraicTraits< T >>
unsigned int Matrix< T, NumberTraits >::rows (  )  const [inline]

Get the count of rows of this matrix

Returns:
the number of rows this matrix has

Definition at line 129 of file Matrix.h.

Referenced by checkColumn(), checkSmithForm(), getMinimumDegreeElemIndexesInMatrix(), processColumn3(), processRow3(), recursiveSmithNormalForm3(), and smithNormalForm3().

Here is the caller graph for this function:

template<class T, class NumberTraits = AlgebraicTraits< T >>
unsigned int Matrix< T, NumberTraits >::cols (  )  const [inline]

Get the count of columns of this matrix

Returns:
the number of columns this matrix has

Definition at line 137 of file Matrix.h.

Referenced by checkRow(), checkSmithForm(), getMinimumDegreeElemIndexesInMatrix(), processColumn3(), processRow3(), recursiveSmithNormalForm3(), and smithNormalForm3().

Here is the caller graph for this function:

template<class T, class NumberTraits = AlgebraicTraits< T >>
bool Matrix< T, NumberTraits >::isNull (  )  const [inline]

Determine if this matrix is empty

Returns:
true if this is an empty matrix, and false otherwise

Definition at line 145 of file Matrix.h.

Referenced by Matrix< T, NumberTraits >::operator=().

Here is the caller graph for this function:

template<class T, class NumberTraits = AlgebraicTraits< T >>
bool Matrix< T, NumberTraits >::resize ( unsigned int  r,
unsigned int  c 
) [inline]

Resize the matrix to have the given number of rows and columns. The original data in the matrix will be lost if either the number of rows or the number of columns is increased.

Parameters:
r new number of rows
c new number of columns
Returns:
true if the function succeeded

Definition at line 247 of file Matrix.h.

Referenced by Matrix< T, NumberTraits >::getCofactor(), Matrix< T, NumberTraits >::getMinor(), and smithNormalForm3().

Here is the caller graph for this function:

template<class T, class NumberTraits = AlgebraicTraits< T >>
void Matrix< T, NumberTraits >::swapRows ( unsigned int  i,
unsigned int  j 
) [inline]

Swap two rows in this matrix.

Parameters:
i row to swap
j the other row to swap

Definition at line 272 of file Matrix.h.

Referenced by Matrix< T, NumberTraits >::inverse(), and processColumn3().

Here is the caller graph for this function:

template<class T, class NumberTraits = AlgebraicTraits< T >>
void Matrix< T, NumberTraits >::swapCols ( unsigned int  i,
unsigned int  j 
) [inline]

Swap two columns in this matrix.

Parameters:
i column to swap
j the other column to swap

Definition at line 284 of file Matrix.h.

Referenced by processRow3(), and recursiveSmithNormalForm3().

Here is the caller graph for this function:

template<class T, class NumberTraits = AlgebraicTraits< T >>
void Matrix< T, NumberTraits >::multiplyRow ( unsigned int  row,
const number_type value 
) [inline]

Multiply all elements of a row by a constant

Parameters:
row row index
value multiplier

Definition at line 298 of file Matrix.h.

template<class T, class NumberTraits = AlgebraicTraits< T >>
void Matrix< T, NumberTraits >::multiplyRowAndAddToRow ( unsigned int  source,
unsigned int  dest,
const number_type value 
) [inline]

Multiply all elements of a row by a constant and add to another row

Parameters:
source source row index
dest destination row index
value multiplier

Definition at line 311 of file Matrix.h.

template<class T, class NumberTraits = AlgebraicTraits< T >>
void Matrix< T, NumberTraits >::multiplyCol ( unsigned int  col,
const number_type value 
) [inline]

Multiply all elements of a column by a constant

Parameters:
col column index
value multiplier

Definition at line 329 of file Matrix.h.

template<class T, class NumberTraits = AlgebraicTraits< T >>
void Matrix< T, NumberTraits >::multiplyColAndAddToCol ( unsigned int  source,
unsigned int  dest,
const number_type value 
) [inline]

Multiply all elements of a column by a constant and add to another column

Parameters:
source source column index
dest destination column index
value multiplier

Definition at line 342 of file Matrix.h.

Referenced by recursiveSmithNormalForm3().

Here is the caller graph for this function:

template<class T, class NumberTraits = AlgebraicTraits< T >>
void Matrix< T, NumberTraits >::fill ( const number_type value  )  [inline]

Set all elements of this matrix to the given value

Parameters:
value value to set all matrix elements

Definition at line 362 of file Matrix.h.

Referenced by smithNormalForm3().

Here is the caller graph for this function:

template<class T, class NumberTraits = AlgebraicTraits< T >>
matrix_type& Matrix< T, NumberTraits >::operator= ( const matrix_type other  )  [inline]

Assignment operator.

If the matrices don't have the same dimensions it's probably a user mistake so the function report an error and return this matrix unchanged. If this matrix is null it allocates memory and copies source matrix

Parameters:
other matrix to copy
Returns:
reference to this matrix

Definition at line 431 of file Matrix.h.

References Matrix< T, NumberTraits >::isNull(), Matrix< T, NumberTraits >::m_nCols, and Matrix< T, NumberTraits >::m_nRows.

Here is the call graph for this function:

template<class T, class NumberTraits = AlgebraicTraits< T >>
number_type Matrix< T, NumberTraits >::determinant (  )  const [inline]

Computes the determinant of this matrix

Returns:
The value of the determinant
Remarks:
If the matrix elements are from a field algebraic structure it uses Gaussian elimination to compute the determinant, complexity = O(n^3). Else it uses laplace minors (cofactors). It is used with rings (algebraic structures where usually elements don't have a reciprocal with regard to the * operation e.g. the ring of polynomials with real coefficients). This is highly inefficient complexity = O(n!)

Definition at line 485 of file Matrix.h.

template<class T, class NumberTraits = AlgebraicTraits< T >>
void Matrix< T, NumberTraits >::getCofactor ( unsigned int  i,
unsigned int  j,
matrix_type cofactor 
) const [inline]

Computes a cofactor for this matrix by removing line i and col j

Parameters:
i the line no. we remove from this matrix
j the column no. we remove from this matrix
cofactor a reference to the matrix that will contain the cofactor

Definition at line 627 of file Matrix.h.

References Matrix< T, NumberTraits >::resize().

Referenced by recursiveSmithNormalForm3().

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T, class NumberTraits = AlgebraicTraits< T >>
void Matrix< T, NumberTraits >::getMinor ( const IndexSet keep_rows,
const IndexSet keep_cols,
matrix_type minor 
) const [inline]

Computes a minor for this matrix

Minors are always square matrices so keep_rows and keep_cols must contain the same number of indexes

Parameters:
keep_rows a set of row indexes to keep
keep_cols a set of column indexes to keep
minor a reference to the matrix that will contain the minor

Definition at line 667 of file Matrix.h.

References IndexSet::find(), Matrix< T, NumberTraits >::m_nCols, Matrix< T, NumberTraits >::m_nRows, Matrix< T, NumberTraits >::resize(), and IndexSet::size().

Here is the call graph for this function:

template<class T, class NumberTraits = AlgebraicTraits< T >>
matrix_type& Matrix< T, NumberTraits >::transpose (  )  [inline]

Transposes this matrix.Replaces element [i][j] with element [j][i]

Returns:
A refference to this matrix.
Remarks:
If the matrix is not square the matrix dimmensions will change after this operation

Definition at line 784 of file Matrix.h.

template<class T, class NumberTraits = AlgebraicTraits< T >>
matrix_type Matrix< T, NumberTraits >::operator * ( const matrix_type rhs  )  const [inline]

Matrix multiplication.

Complexity = O(n^3)

Parameters:
rhs right hand side matrix
Returns:
the result of the multiplication

Definition at line 826 of file Matrix.h.

References Matrix< T, NumberTraits >::m_nCols, and Matrix< T, NumberTraits >::m_nRows.

template<class T, class NumberTraits = AlgebraicTraits< T >>
matrix_type Matrix< T, NumberTraits >::operator- (  )  const [inline]

Unary minus

Returns:
zero minus this matrix

Definition at line 861 of file Matrix.h.

References Matrix< T, NumberTraits >::m_nCols, and Matrix< T, NumberTraits >::m_nRows.

template<class T, class NumberTraits = AlgebraicTraits< T >>
matrix_type Matrix< T, NumberTraits >::operator+ ( const matrix_type rhs  )  const [inline]

Matrix addition

Matrices must have the same number of rows and columns to perform addition

Parameters:
rhs right hand side matrix
Returns:
the result of the addition

Definition at line 882 of file Matrix.h.

References Matrix< T, NumberTraits >::m_nCols, and Matrix< T, NumberTraits >::m_nRows.

template<class T, class NumberTraits = AlgebraicTraits< T >>
matrix_type Matrix< T, NumberTraits >::operator- ( const matrix_type rhs  )  const [inline]

Matrix subtraction

Matrices must have the same number of rows and columns to perform subtraction

Parameters:
rhs right hand side matrix
Returns:
the result of the subtraction

Definition at line 912 of file Matrix.h.

References Matrix< T, NumberTraits >::m_nCols, and Matrix< T, NumberTraits >::m_nRows.

template<class T, class NumberTraits = AlgebraicTraits< T >>
matrix_type Matrix< T, NumberTraits >::operator/ ( const matrix_type rhs  )  const [inline]

Matrix division

Matrices must have the same number of rows and columns to perform division. If the right hand side matrix is not inversable an exception is thrown

Parameters:
rhs right hand side matrix
Returns:
the result of the addition

Definition at line 941 of file Matrix.h.

References Matrix< T, NumberTraits >::inverse(), Matrix< T, NumberTraits >::m_nCols, and Matrix< T, NumberTraits >::m_nRows.

Here is the call graph for this function:

template<class T, class NumberTraits = AlgebraicTraits< T >>
matrix_type& Matrix< T, NumberTraits >::operator+= ( const matrix_type rhs  )  [inline]

Addition assignment

Matrices must have the same number of rows and columns to perform addition.

Parameters:
rhs right hand side matrix
Returns:
refference to the result of the addition

Definition at line 960 of file Matrix.h.

References Matrix< T, NumberTraits >::m_nCols, and Matrix< T, NumberTraits >::m_nRows.

template<class T, class NumberTraits = AlgebraicTraits< T >>
matrix_type& Matrix< T, NumberTraits >::operator-= ( const matrix_type rhs  )  [inline]

Subtraction assignment

Matrices must have the same number of rows and columns to perform subtraction.

Parameters:
rhs right hand side matrix
Returns:
refference to the result of the subtraction

Definition at line 986 of file Matrix.h.

References Matrix< T, NumberTraits >::m_nCols, and Matrix< T, NumberTraits >::m_nRows.

template<class T, class NumberTraits = AlgebraicTraits< T >>
matrix_type& Matrix< T, NumberTraits >::operator *= ( const matrix_type rhs  )  [inline]

Multiplication assignment

Matrices should be compatible to perform multiplication i.e. the number of columns of the first matrix should be equal to the number of rows of the second matrix.

Parameters:
rhs right hand side matrix
Returns:
refference to the result of the multiplication

Definition at line 1014 of file Matrix.h.

References Matrix< T, NumberTraits >::m_nRows.

template<class T, class NumberTraits = AlgebraicTraits< T >>
matrix_type& Matrix< T, NumberTraits >::operator/= ( const matrix_type rhs  )  [inline]

Division assignment

Matrices should be square and have the same dimensions. If the second matrix is not inversable an exception is thrown.

Parameters:
rhs right hand side matrix
Returns:
refference to the result of the division

Definition at line 1034 of file Matrix.h.

References Matrix< T, NumberTraits >::m_nCols, and Matrix< T, NumberTraits >::m_nRows.

template<class T, class NumberTraits = AlgebraicTraits< T >>
bool Matrix< T, NumberTraits >::operator== ( const matrix_type rhs  )  const [inline]

Equality operator

Matrices should have the same number of columns and rows.

Parameters:
rhs right hand side matrix
Returns:
true if matrices are equal, false otherwise

Definition at line 1055 of file Matrix.h.

References Matrix< T, NumberTraits >::m_nCols, and Matrix< T, NumberTraits >::m_nRows.

Referenced by Matrix< T, NumberTraits >::operator!=().

Here is the caller graph for this function:

template<class T, class NumberTraits = AlgebraicTraits< T >>
bool Matrix< T, NumberTraits >::operator!= ( const matrix_type rhs  )  const [inline]

Inequality operator

Matrices should have the same number of columns and rows.

Parameters:
rhs right hand side matrix
Returns:
true if matrices are different, false otherwise

Definition at line 1083 of file Matrix.h.

References Matrix< T, NumberTraits >::operator==().

Here is the call graph for this function:

template<class T, class NumberTraits = AlgebraicTraits< T >>
bool Matrix< T, NumberTraits >::operator< ( const matrix_type rhs  )  const [inline]

Comparison operator

This function merely compares the norms of the matrices.

Parameters:
rhs right hand side matrix
Returns:
true if the norm of this matrix is less than the norm of the other matrix

Definition at line 1096 of file Matrix.h.

References Matrix< T, NumberTraits >::getNorm(), and Matrix< T, NumberTraits >::m_nRows.

Here is the call graph for this function:

template<class T, class NumberTraits = AlgebraicTraits< T >>
matrix_type Matrix< T, NumberTraits >::inverse (  )  const [inline]

Compute the inverse of this matrix

Algorithm uses the relation obtained through elementary transformations) between the composed matrices [A:I] and [I:A^-1]. Complexity = O(n^3). This matrix must be a square matrix. If this matrix is not inversable an exception is thrown

Returns:
the inverse of this matrix

Definition at line 1114 of file Matrix.h.

References Matrix< T, NumberTraits >::m_nCols, Matrix< T, NumberTraits >::m_nRows, Matrix< T, NumberTraits >::one(), Matrix< T, NumberTraits >::swapRows(), and AlgebraicTraits< T >::zero().

Referenced by Matrix< T, NumberTraits >::operator/().

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T, class NumberTraits = AlgebraicTraits< T >>
number_type Matrix< T, NumberTraits >::getNorm (  )  const [inline]

Compute the euclidean norm of this matrix

Returns:
the value of the norm

Definition at line 1234 of file Matrix.h.

Referenced by Matrix< T, NumberTraits >::operator<().

Here is the caller graph for this function:

template<class T, class NumberTraits = AlgebraicTraits< T >>
number_type Matrix< T, NumberTraits >::getEuclideanNorm (  )  const [inline]

Compute the euclidean norm of this matrix

Returns:
the value of the norm

Definition at line 1248 of file Matrix.h.

template<class T, class NumberTraits = AlgebraicTraits< T >>
void Matrix< T, NumberTraits >::display ( std::ostream &  os = std::cout  )  const [inline]

Display this matrix to a stream

Parameters:
os stream to display this matrix

Definition at line 1283 of file Matrix.h.

template<class T, class NumberTraits = AlgebraicTraits< T >>
void Matrix< T, NumberTraits >::load ( std::istream &  is  )  [inline]

Load this from a stream

Parameters:
is stream to load from

Definition at line 1298 of file Matrix.h.

template<class T, class NumberTraits = AlgebraicTraits< T >>
void Matrix< T, NumberTraits >::save ( std::ostream &  os  )  const [inline]

Save this to a stream

Parameters:
os stream to save to

Definition at line 1320 of file Matrix.h.


The documentation for this class was generated from the following file:
Math-Objects Library Docs  Generated by: doxygen