Public Member Functions | Private Member Functions | Private Attributes | Friends

alize::Matrix< T > Class Template Reference

#include <Matrix.h>

Inheritance diagram for alize::Matrix< T >:
Inheritance graph
[legend]
Collaboration diagram for alize::Matrix< T >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Matrix (unsigned long rows=0, unsigned long cols=0)
 Matrix (const FileName &f)
 Matrix (const FileName &f, const Config &c)
template<class R >
 Matrix (const RealVector< R > &v)
 Matrix (const Feature &f)
 Matrix (const DoubleSquareMatrix &M)
Matrix< T > & operator= (const Matrix< T > &m)
bool operator== (const Matrix< T > &m) const
bool operator!= (const Matrix< T > &m) const
 Matrix (const Matrix< T > &m)
virtual ~Matrix ()
unsigned long cols () const
unsigned long rows () const
void setDimensions (const unsigned long rows, const unsigned long cols)
template<class R >
void setAllValues (R v)
T & operator() (unsigned long row, unsigned long col)
operator() (unsigned long row, unsigned long col) const
Matrix< T > & transpose ()
Matrix< T > transpose () const
Matrix< T > & invert ()
Matrix< T > invert () const
Matrix< T > operator* (const Matrix< T > &m) const
Matrix< T > & operator*= (const Matrix< T > &m)
Matrix< T > & operator*= (double v)
Matrix< T > operator* (double v) const
Matrix< T > operator+ (const Matrix< T > &m) const
Matrix< T > & operator+= (const Matrix< T > &m)
Matrix< T > operator- (const Matrix< T > &m) const
Matrix< T > & operator-= (const Matrix< T > &m)
void save (const FileName &f)
void save (const FileName &f, const Config &c)
void saveDT (const FileName &f, const Config &c)
void saveDB (const FileName &f, const Config &c)
void load (const FileName &f)
void load (const FileName &f, const Config &c)
void loadDT (const FileName &f, const Config &c)
void loadDB (const FileName &f, const Config &c)
void randomInit ()
T * getArray () const
virtual String toString () const
virtual String getClassName () const
Matrix< T > crop (unsigned long line, unsigned long col, unsigned long n_rows, unsigned long n_cols)
void concatCols (const Matrix< T > &M1, const Matrix< T > &M2)
void concatRows (const Matrix< T > &M1, const Matrix< T > &M2)

Private Member Functions

unsigned long fabs (unsigned long x)
void ludcmp (T **a, int n, int *indx, T *d)
void lubksb (T **a, int n, int *indx, T b[])

Private Attributes

unsigned long _cols
unsigned long _rows
RealVector< T > _array

Friends

class TestMatrix

Detailed Description

template<class T>
class alize::Matrix< T >

This template class implements a matrix of type-T values.
Inside the object, the matrix is stored as a single-dimension array.
WARNING : contrary to class DoubleSquareMatrix, row index is FIRST argument and column index is SECOND argument
This will probably change for class DoubleSquareMatrix in next release of Alize

Author:
Frederic Wils frederic.wils@lia.univ-avignon.fr
Version:
1.0
Date:
2006

Definition at line 111 of file Matrix.h.


Constructor & Destructor Documentation

template<class T>
alize::Matrix< T >::Matrix ( unsigned long  rows = 0,
unsigned long  cols = 0 
) [inline]

Creates a matrix of type T

Parameters:
ccols of the matrix
rrows of the matrix

Definition at line 121 of file Matrix.h.

template<class T>
alize::Matrix< T >::Matrix ( const FileName f ) [inline, explicit]

Creates a matrix of type T and loads its content from a file

Parameters:
ffile name

Definition at line 127 of file Matrix.h.

template<class T>
alize::Matrix< T >::Matrix ( const FileName f,
const Config c 
) [inline, explicit]

Creates a matrix of type T and loads its content from a file

Parameters:
ffile name
cconfiguration

Definition at line 134 of file Matrix.h.

template<class T>
template<class R >
alize::Matrix< T >::Matrix ( const RealVector< R > &  v ) [inline, explicit]

Creates a matrix of type T with 1 row and v.size() rows
Copy content of v into this matrix

Parameters:
vthe vector

Definition at line 141 of file Matrix.h.

References alize::RealVector< T >::size().

template<class T>
alize::Matrix< T >::Matrix ( const Feature f ) [inline, explicit]

Creates a matrix of type T with 1 row and f.getVectSize() rows
Copy content of the feature into this matrix

Parameters:
fthe feature

Definition at line 152 of file Matrix.h.

References alize::Feature::getVectSize().

template<class T>
alize::Matrix< T >::Matrix ( const DoubleSquareMatrix< T > &  M ) [inline, explicit]

Creates a matrix of type T with from a DoubleSquareMatrix (idxs are inverted)

Parameters:
fthe feature

Definition at line 164 of file Matrix.h.

References alize::DoubleSquareMatrix::size().

template<class T>
alize::Matrix< T >::Matrix ( const Matrix< T > &  m ) [inline]

Definition at line 191 of file Matrix.h.

template<class T>
virtual alize::Matrix< T >::~Matrix (  ) [inline, virtual]

Definition at line 194 of file Matrix.h.


Member Function Documentation

template<class T>
unsigned long alize::Matrix< T >::cols (  ) const [inline]

Returns the number of columns of this matrix

Definition at line 198 of file Matrix.h.

Referenced by alize::Matrix< T >::concatCols(), and alize::Matrix< T >::concatRows().

template<class T>
void alize::Matrix< T >::concatCols ( const Matrix< T > &  M1,
const Matrix< T > &  M2 
) [inline]

Concatenate two matrices in column within the current one

Parameters:
M1the first matrix to concatenate
M2the second matrix to concatenate

Definition at line 635 of file Matrix.h.

References alize::Matrix< T >::cols(), alize::Matrix< T >::getArray(), and alize::Matrix< T >::rows().

template<class T>
void alize::Matrix< T >::concatRows ( const Matrix< T > &  M1,
const Matrix< T > &  M2 
) [inline]

Concatenate two matrices in line within the current one

Parameters:
M1the first matrix to concatenate
M2the second matrix to concatenate

Definition at line 661 of file Matrix.h.

References alize::Matrix< T >::cols(), alize::Matrix< T >::getArray(), and alize::Matrix< T >::rows().

template<class T>
Matrix<T> alize::Matrix< T >::crop ( unsigned long  line,
unsigned long  col,
unsigned long  n_rows,
unsigned long  n_cols 
) [inline]

Extract a sub matrix from the current one

Returns:
a submatrix
Parameters:
lineline number of the first selected element
colcolumn number of the first selected element
n_rowsnumber of line of the sub matrix
n_colsnumber of columns of the sub matrix

Definition at line 612 of file Matrix.h.

References alize::Matrix< T >::getArray().

template<class T>
unsigned long alize::Matrix< T >::fabs ( unsigned long  x ) [inline, private]

Definition at line 693 of file Matrix.h.

template<class T>
T* alize::Matrix< T >::getArray (  ) const [inline]

Use this method to access directly to the internal vector

Returns:
a pointer on the first element
Warning:
Fast but dangerous ! Use preferably operator()(row, col).

Definition at line 586 of file Matrix.h.

Referenced by alize::Matrix< T >::concatCols(), alize::Matrix< T >::concatRows(), and alize::Matrix< T >::crop().

template<class T>
virtual String alize::Matrix< T >::getClassName (  ) const [inline, virtual]

Returns the name of the class

Returns:
the name of the class of the object as a String

Implements alize::Object.

Definition at line 603 of file Matrix.h.

template<class T>
Matrix<T> alize::Matrix< T >::invert (  ) const [inline]

Inverts this constant matrix into a new matrix

Returns:
the new matrix

Definition at line 331 of file Matrix.h.

References alize::Matrix< T >::invert().

template<class T>
Matrix<T>& alize::Matrix< T >::invert (  ) [inline]

Inverts this matrix

Returns:
this matrix

Definition at line 276 of file Matrix.h.

References NULL.

Referenced by alize::Matrix< T >::invert().

template<class T>
void alize::Matrix< T >::load ( const FileName f ) [inline]

Loads a matrix depending on loadMatrixFormat

Parameters:
ffile name
Returns:
this matrix

Definition at line 504 of file Matrix.h.

References alize::Matrix< T >::load().

Referenced by alize::Matrix< T >::load().

template<class T>
void alize::Matrix< T >::load ( const FileName f,
const Config c 
) [inline]

Loads a matrix depending on loadMatrixFormat

Parameters:
ffile name
cconfiguration
Returns:
this matrix

Definition at line 511 of file Matrix.h.

References alize::Config::getParam().

template<class T>
void alize::Matrix< T >::loadDB ( const FileName f,
const Config c 
) [inline]

Loads a matrix from a file (Dense Binary Matrix format)

Parameters:
ffile name
cconfiguration
Returns:
this matrix

Definition at line 551 of file Matrix.h.

References alize::String::c_str(), and alize::Exception::toString().

template<class T>
void alize::Matrix< T >::loadDT ( const FileName f,
const Config c 
) [inline]

Loads a matrix from a file (Dense Text Matrix File Format)
http://tedlab.mit.edu/~dr/SVDLIBC/SVD_F_DT.html

Parameters:
ffile name
cconfiguration
Returns:
this matrix

Definition at line 523 of file Matrix.h.

References alize::XLine::getElement(), alize::XList::getLine(), alize::XList::rewind(), alize::String::toDouble(), and alize::String::toLong().

template<class T>
void alize::Matrix< T >::lubksb ( T **  a,
int  n,
int *  indx,
b[] 
) [inline, private]

Definition at line 748 of file Matrix.h.

template<class T>
void alize::Matrix< T >::ludcmp ( T **  a,
int  n,
int *  indx,
T *  d 
) [inline, private]

Definition at line 694 of file Matrix.h.

References TINY.

template<class T>
bool alize::Matrix< T >::operator!= ( const Matrix< T > &  m ) const [inline]

Definition at line 189 of file Matrix.h.

template<class T>
T alize::Matrix< T >::operator() ( unsigned long  row,
unsigned long  col 
) const [inline]

Overloaded operator() to access an element in this CONSTANT matrix.

Parameters:
rowrow of the element to access
colcolumn of the element to access
Returns:
a COPY of the element
Exceptions:
IndexOutOfBoundsException

Definition at line 239 of file Matrix.h.

template<class T>
T& alize::Matrix< T >::operator() ( unsigned long  row,
unsigned long  col 
) [inline]

Overloaded operator() to access an element in this matrix.

Parameters:
rowrow of the element to access
colcolumn of the element to access
Returns:
a REFERENCE to the element
Exceptions:
IndexOutOfBoundsException

Definition at line 226 of file Matrix.h.

template<class T>
Matrix<T> alize::Matrix< T >::operator* ( double  v ) const [inline]

Multiplies this matrix by a scalar value and returns the result in another matrix

Parameters:
vthe scalar value
Returns:
a matrix

Definition at line 385 of file Matrix.h.

References alize::Matrix< T >::_array.

template<class T>
Matrix<T> alize::Matrix< T >::operator* ( const Matrix< T > &  m ) const [inline]

Multiplies this matrix by an other matrix and returns the result in a new matrix (new matrix = this * m);

Parameters:
mthe matrix
Returns:
a new matrix

Definition at line 342 of file Matrix.h.

References alize::Matrix< T >::_array, alize::Matrix< T >::_cols, alize::Matrix< T >::_rows, and alize::Matrix< T >::setAllValues().

template<class T>
Matrix<T>& alize::Matrix< T >::operator*= ( double  v ) [inline]

Multiplies this matrix by a scalar value

Parameters:
vthe scalar value
Returns:
this matrix

Definition at line 374 of file Matrix.h.

template<class T>
Matrix<T>& alize::Matrix< T >::operator*= ( const Matrix< T > &  m ) [inline]

Multiplies this matrix by an other matrix (this *= m)

Parameters:
ma matrix
Returns:
this matrix

Definition at line 364 of file Matrix.h.

template<class T>
Matrix<T> alize::Matrix< T >::operator+ ( const Matrix< T > &  m ) const [inline]

Adds this matrix and an other matrix and returns the result in a new matrix (new matrix = this + m);

Parameters:
mthe matrix
Returns:
a new matrix

Definition at line 397 of file Matrix.h.

References alize::Matrix< T >::_array.

template<class T>
Matrix<T>& alize::Matrix< T >::operator+= ( const Matrix< T > &  m ) [inline]

Adds this matrix and an other matrix (this += m)

Parameters:
ma matrix
Returns:
this matrix

Definition at line 408 of file Matrix.h.

References alize::Matrix< T >::_array, alize::Matrix< T >::_cols, and alize::Matrix< T >::_rows.

template<class T>
Matrix<T> alize::Matrix< T >::operator- ( const Matrix< T > &  m ) const [inline]

Substracts a matrix from this matrix and returns the result in a new matrix (new matrix = this - m);

Parameters:
mthe matrix
Returns:
a new matrix

Definition at line 421 of file Matrix.h.

References alize::Matrix< T >::_array.

template<class T>
Matrix<T>& alize::Matrix< T >::operator-= ( const Matrix< T > &  m ) [inline]

Substracts a matrix from this matrix (this -= m)

Parameters:
ma matrix
Returns:
this matrix

Definition at line 432 of file Matrix.h.

References alize::Matrix< T >::_array, alize::Matrix< T >::_cols, and alize::Matrix< T >::_rows.

template<class T>
Matrix<T>& alize::Matrix< T >::operator= ( const Matrix< T > &  m ) [inline]

Copy operator. Copy a matrix into this matrix

Parameters:
mthe matrix

Definition at line 176 of file Matrix.h.

References alize::Matrix< T >::_array, alize::Matrix< T >::_cols, and alize::Matrix< T >::_rows.

template<class T>
bool alize::Matrix< T >::operator== ( const Matrix< T > &  m ) const [inline]
template<class T>
void alize::Matrix< T >::randomInit (  ) [inline]

Random init of a matrix

Returns:
this matrix

Definition at line 572 of file Matrix.h.

References alize::String::c_str(), and alize::Exception::toString().

template<class T>
unsigned long alize::Matrix< T >::rows (  ) const [inline]

Returns the number of rows of this matrix

Definition at line 202 of file Matrix.h.

Referenced by alize::Matrix< T >::concatCols(), and alize::Matrix< T >::concatRows().

template<class T>
void alize::Matrix< T >::save ( const FileName f,
const Config c 
) [inline]

Saves a matrix depending on the saveMatrixFormat type

Parameters:
ffile name
cconfiguration
Returns:
this matrix

Definition at line 451 of file Matrix.h.

References alize::Config::getParam().

template<class T>
void alize::Matrix< T >::save ( const FileName f ) [inline]

Saves a matrix depending on the saveMatrixFormat type

Parameters:
ffile name
Returns:
this matrix

Definition at line 444 of file Matrix.h.

References alize::Matrix< T >::save().

Referenced by alize::Matrix< T >::save().

template<class T>
void alize::Matrix< T >::saveDB ( const FileName f,
const Config c 
) [inline]

Save a matrix in a file (Dense Binary Matrix format)

Parameters:
ffile name
cconfiguration
Returns:
this matrix

Definition at line 483 of file Matrix.h.

References alize::String::c_str(), and alize::Exception::toString().

template<class T>
void alize::Matrix< T >::saveDT ( const FileName f,
const Config c 
) [inline]

Saves this matrix in a file (Dense Text Matrix File Format)
http://tedlab.mit.edu/~dr/SVDLIBC/SVD_F_DT.html

Parameters:
ffile name
cconfiguration
Returns:
this matrix

Definition at line 464 of file Matrix.h.

References alize::XLine::addElement(), alize::XList::addLine(), and alize::XList::save().

template<class T>
template<class R >
void alize::Matrix< T >::setAllValues ( R  v ) [inline]

Sets all the values to a a particular value

Parameters:
vthe value to set

Definition at line 218 of file Matrix.h.

Referenced by alize::Matrix< T >::operator*().

template<class T>
void alize::Matrix< T >::setDimensions ( const unsigned long  rows,
const unsigned long  cols 
) [inline]

Sets the new dimensions of the matrix

Parameters:
colsthe number of columns
rowsthe number of rows

Definition at line 208 of file Matrix.h.

template<class T>
virtual String alize::Matrix< T >::toString (  ) const [inline, virtual]

This method is frequently overridden in the derived classes. If it is not, it returns the name of the class of the object and the address of the object

Returns:
a description of the object

Reimplemented from alize::Object.

Definition at line 588 of file Matrix.h.

template<class T>
Matrix<T>& alize::Matrix< T >::transpose (  ) [inline]

Transposes this matrix

Returns:
this matrix

Definition at line 249 of file Matrix.h.

References alize::RealVector< T >::getArray().

Referenced by alize::Matrix< T >::transpose().

template<class T>
Matrix<T> alize::Matrix< T >::transpose (  ) const [inline]

Transposes this constant matrix into a new matrix

Returns:
the new matrix

Definition at line 267 of file Matrix.h.

References alize::Matrix< T >::transpose().


Friends And Related Function Documentation

template<class T>
friend class TestMatrix [friend]

Definition at line 113 of file Matrix.h.


Member Data Documentation

template<class T>
RealVector<T> alize::Matrix< T >::_array [private]
template<class T>
unsigned long alize::Matrix< T >::_cols [private]
template<class T>
unsigned long alize::Matrix< T >::_rows [private]

The documentation for this class was generated from the following file: