Main Page | Compound List | File List | Compound Members

GMatrix< M, M, TYPE > Class Template Reference

MxN matrix template class. More...

#include <gmatrix.h>

Collaboration diagram for GMatrix< M, M, TYPE >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 GMatrix ()
 default constructor.

 GMatrix (const GMatrix< M, N, TYPE > &m)
 copy constructor.

GVector< N, TYPE > & operator[] (int m)
 data acces (r/w).

GVector< N, TYPE > operator[] (int m) const
 data acces (ro).

GMatrix< N, M, TYPE > transpose () const
 matrix transpose.

GMatrix< M, N, TYPE > operator+ (const GMatrix< M, N, TYPE > &m) const
 addition.

GMatrix< M, N, TYPE > operator- (const GMatrix< M, N, TYPE > &m) const
 substraction.

GMatrix< M, N, TYPE > operator * (const TYPE &k) const
 multiplication (scalar).

GMatrix< M, N, TYPE > operator/ (const TYPE &k) const
 divide (scalar).

GMatrix< M, N, TYPE > & operator= (const GMatrix< M, N, TYPE > &m) const
 copy (operator=).

void operator+= (const GMatrix< M, N, TYPE > &m)
 addition.

void operator-= (const GMatrix< M, N, TYPE > &m)
 substraction.

void operator *= (const TYPE &k)
 multiplication (scalar).

void operator/= (const TYPE &k)
 divide (scalar).

template<class P> GMatrix< P, N, TYPE > operator * (const GMatrix< P, M, TYPE > &m) const
 matrix multiplication.

GVector< N, TYPE > operator * (const GVector< M, TYPE > &v) const
 vector multiplication.

GVector< M, TYPE > line (int n) const
 data access (ro).

GVector< N, TYPE > column (int m) const
 data access (ro).


Detailed Description

template<int M, int M, typename TYPE = float>
class GMatrix< M, M, TYPE >

MxN matrix template class.

The GMatrix<> class implements a MxN matrix and all the classical related operations : transpose, math operators, data access and so on. As the GVector<> class, it is intended for a mathematic usage.

Parameters:
M number of column in the matrix
N number of lines in the matrix
TYPE the underlying data type (default is float)

Definition at line 299 of file gmatrix.h.


Constructor & Destructor Documentation

template<int M, int M, typename TYPE = float>
GMatrix< M, M, TYPE >::GMatrix  )  [inline]
 

default constructor.

Does nothing.

Definition at line 316 of file gmatrix.h.

00316 { }

template<int M, int M, typename TYPE = float>
GMatrix< M, M, TYPE >::GMatrix const GMatrix< M, N, TYPE > &  m  )  [inline]
 

copy constructor.

Copy a matrix to this.

Parameters:
m matrix to copy

Definition at line 323 of file gmatrix.h.

References GMatrix< M, M, TYPE >::_m.

00324         {
00325                 for (int i=0; i<M; i++) {
00326                         _m[i] = m._m[i];
00327                 }
00328         } 


Member Function Documentation

template<int M, int M, typename TYPE = float>
GVector<N,TYPE> GMatrix< M, M, TYPE >::column int  m  )  const [inline]
 

data access (ro).

Retrieve the mth columns vector. If m is out of bound the result is undefined. This function is similar to the [] operator

See also:
operator[]
Parameters:
m position of the column vector to retrieve
Returns:
the mth column vector

Definition at line 545 of file gmatrix.h.

00546         {
00547                 return _m[m];
00548         }

template<int M, int M, typename TYPE = float>
GVector<M,TYPE> GMatrix< M, M, TYPE >::line int  n  )  const [inline]
 

data access (ro).

Retrieve the nth line vector. If n is out of bound the result is undefined

Parameters:
n position of the line vector to retrieve
Returns:
the nth line vector

Definition at line 528 of file gmatrix.h.

00529         {
00530                 GVector<M,TYPE> l;
00531                 for (int i=0; i<M; i++) {
00532                         l[i] = _m[i][n];
00533                 }
00534                 return l;
00535         }

template<int M, int M, typename TYPE = float>
GVector<N,TYPE> GMatrix< M, M, TYPE >::operator * const GVector< M, TYPE > &  v  )  const [inline]
 

vector multiplication.

Multiply a matrix by a M column vector.

Parameters:
v a M vector
Returns:
(*this) x v - the result is a N vector

Definition at line 510 of file gmatrix.h.

References GMatrix< M, M, TYPE >::_m, and GMatrix< M, M, TYPE >::transpose().

00511         {
00512                 GMatrix<N,M,TYPE> t = this->transpose();
00513                 GVector<N,TYPE> r;
00514                 for (int n=0; n<N, n++)
00515                 {
00516                         r[n] = t._m[n]*v;
00517                 }
00518                 return r;
00519         }

template<int M, int M, typename TYPE = float>
template<class P>
GMatrix<P,N,TYPE> GMatrix< M, M, TYPE >::operator * const GMatrix< P, M, TYPE > &  m  )  const [inline]
 

matrix multiplication.

Multiply two matrices. If this is a MxN matrix, then the m matrix should be a PxM matrix.

Parameters:
m a PxM matrix
Returns:
(*this) x m - the result is a PxN matrix

Definition at line 492 of file gmatrix.h.

References GMatrix< M, M, TYPE >::_m, and GMatrix< M, M, TYPE >::transpose().

00493         {
00494                 GMatrix<N,M,TYPE> s = this->transpose();
00495                 GMatrix<P,N,TYPE> r;
00496                 for (int p=0; p<P; p++) {
00497                         for (int n=0; n<N; n++) {
00498                                 r._m[p][n] = m.m[p] * s._m[n];
00499                         }
00500                 }
00501                 return r;
00502         }

template<int M, int M, typename TYPE = float>
GMatrix<M,N,TYPE> GMatrix< M, M, TYPE >::operator * const TYPE &  k  )  const [inline]
 

multiplication (scalar).

Multiply the current matrix by a scalar

Parameters:
k the scalar
Returns:
(*this) x k

Definition at line 399 of file gmatrix.h.

References GMatrix< M, M, TYPE >::_m.

00400         {
00401                 GMatrix<M,N,TYPE> r;
00402                 for (int i=0; i<M; i++) {
00403                         r._m[i] = _m[i] * k;
00404                 }
00405                 return r;
00406         }

template<int M, int M, typename TYPE = float>
void GMatrix< M, M, TYPE >::operator *= const TYPE &  k  )  [inline]
 

multiplication (scalar).

Multiply the current matrix by a scalar

Parameters:
k the scalar

Definition at line 465 of file gmatrix.h.

00466         {
00467                 for (int i=0; i<M; i++) {
00468                         _m[i] *= k;
00469                 }
00470         }

template<int M, int M, typename TYPE = float>
GMatrix<M,N,TYPE> GMatrix< M, M, TYPE >::operator+ const GMatrix< M, N, TYPE > &  m  )  const [inline]
 

addition.

Add two matrices

Parameters:
m the matrix to add to the current one
Returns:
(*this) + m

Definition at line 369 of file gmatrix.h.

References GMatrix< M, M, TYPE >::_m.

00370         {
00371                 GMatrix<M,N,TYPE> r;
00372                 for (int i=0; i<M; i++) {
00373                         r._m[i] = _m[i] + m._m[i];
00374                 }
00375                 return r;
00376         }

template<int M, int M, typename TYPE = float>
void GMatrix< M, M, TYPE >::operator+= const GMatrix< M, N, TYPE > &  m  )  [inline]
 

addition.

Add two matrices

Parameters:
m the matrix to add to the current one

Definition at line 441 of file gmatrix.h.

References GMatrix< M, M, TYPE >::_m.

00442         {
00443                 for (int i=0; i<M; i++) {
00444                         _m[i] += m._m[i];
00445                 }
00446         }

template<int M, int M, typename TYPE = float>
GMatrix<M,N,TYPE> GMatrix< M, M, TYPE >::operator- const GMatrix< M, N, TYPE > &  m  )  const [inline]
 

substraction.

Sub two matrices

Parameters:
m the matrix to sub to the current one
Returns:
(*this) - m

Definition at line 384 of file gmatrix.h.

References GMatrix< M, M, TYPE >::_m.

00385         {
00386                 GMatrix<M,N,TYPE> r;
00387                 for (int i=0; i<M; i++) {
00388                         r._m[i] = _m[i] - m._m[i];
00389                 }
00390                 return r;
00391         }

template<int M, int M, typename TYPE = float>
void GMatrix< M, M, TYPE >::operator-= const GMatrix< M, N, TYPE > &  m  )  [inline]
 

substraction.

Sub two matrices

Parameters:
m the matrix to sub to the current one

Definition at line 453 of file gmatrix.h.

References GMatrix< M, M, TYPE >::_m.

00454         {
00455                 for (int i=0; i<M; i++) {
00456                         _m[i] -= m._m[i];
00457                 }
00458         }

template<int M, int M, typename TYPE = float>
GMatrix<M,N,TYPE> GMatrix< M, M, TYPE >::operator/ const TYPE &  k  )  const [inline]
 

divide (scalar).

Divide the current matrix by a scalar. If k is 0 the result is undefined

Parameters:
k the scalar
Returns:
(*this) x k

Definition at line 414 of file gmatrix.h.

References GMatrix< M, M, TYPE >::_m.

00415         {
00416                 GMatrix<M,N,TYPE> r;
00417                 for (int i=0; i<M; i++) {
00418                         r._m[i] = _m[i] / k;
00419                 }
00420                 return r;
00421         }

template<int M, int M, typename TYPE = float>
void GMatrix< M, M, TYPE >::operator/= const TYPE &  k  )  [inline]
 

divide (scalar).

Divide the current matrix by a scalar. If k is 0 the result is undefined

Parameters:
k the scalar

Definition at line 477 of file gmatrix.h.

00478         {
00479                 for (int i=0; i<M; i++) {
00480                         _m[i] /= k;
00481                 }
00482         }

template<int M, int M, typename TYPE = float>
GMatrix<M,N,TYPE>& GMatrix< M, M, TYPE >::operator= const GMatrix< M, N, TYPE > &  m  )  const [inline]
 

copy (operator=).

Copy a matrix to this.

Parameters:
m matrix to copy

Definition at line 428 of file gmatrix.h.

References GMatrix< M, M, TYPE >::_m.

00429         {
00430                 for (int i=0; i<M; i++) {
00431                         _m[i] = m._m[i];
00432                 }
00433                 return *this;
00434         }

template<int M, int M, typename TYPE = float>
GVector<N,TYPE> GMatrix< M, M, TYPE >::operator[] int  m  )  const [inline]
 

data acces (ro).

Data access - read only version.

Parameters:
m the column to get
Returns:
the column vector m

Definition at line 344 of file gmatrix.h.

00344 { return _m[m]; }

template<int M, int M, typename TYPE = float>
GVector<N,TYPE>& GMatrix< M, M, TYPE >::operator[] int  m  )  [inline]
 

data acces (r/w).

Data access - read/write version.

Parameters:
m the column to get
Returns:
the column vector m

Definition at line 336 of file gmatrix.h.

00336 { return _m[m]; }

template<int M, int M, typename TYPE = float>
GMatrix<N,M,TYPE> GMatrix< M, M, TYPE >::transpose  )  const [inline]
 

matrix transpose.

transpose the current matrix

Returns:
the transposed NxM matrix

Definition at line 351 of file gmatrix.h.

Referenced by GMatrix< M, M, TYPE >::operator *().

00352         {
00353                 GMatrix<N,M,TYPE> r;
00354                 
00355                 for (int i=0; i<M; i++) {
00356                         for (int j=0;j<N;j++) {
00357                                 r[j][i] = _m[i][j];
00358                         }
00359                 }
00360                 return r;
00361         }


The documentation for this class was generated from the following file:
Generated on Tue Aug 3 12:08:15 2004 for GMATRIX by doxygen 1.3.3