Main Page | Compound List | File List | Compound Members

gmatrix::GMatrix< M, N, TYPE > Class Template Reference

MxN matrix template class. More...

#include <gmatrix.h>

Collaboration diagram for gmatrix::GMatrix< M, N, 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).

const 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)
 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<int 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 > premul (const GVector< N, TYPE > &v) const
 operator* emulation.

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 N, typename TYPE = float>
class gmatrix::GMatrix< M, N, 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 325 of file gmatrix.h.


Constructor & Destructor Documentation

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

default constructor.

Does nothing.

Definition at line 342 of file gmatrix.h.

00342 { }

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

copy constructor.

Copy a matrix to this.

Parameters:
m matrix to copy

Definition at line 349 of file gmatrix.h.

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

00350                 {
00351                         for (int i=0; i<M; i++) {
00352                                 _m[i] = m._m[i];
00353                         }
00354                 } 


Member Function Documentation

template<int M, int N, typename TYPE = float>
GVector<N,TYPE> gmatrix::GMatrix< M, N, 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 586 of file gmatrix.h.

00587                 {
00588                         return _m[m];
00589                 }

template<int M, int N, typename TYPE = float>
GVector<M,TYPE> gmatrix::GMatrix< M, N, 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 569 of file gmatrix.h.

00570                 {
00571                         GVector<M,TYPE> l;
00572                         for (int i=0; i<M; i++) {
00573                                 l[i] = _m[i][n];
00574                         }
00575                         return l;
00576                 }

template<int M, int N, typename TYPE = float>
GVector<N,TYPE> gmatrix::GMatrix< M, N, 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 534 of file gmatrix.h.

References gmatrix::GMatrix< M, N, TYPE >::transpose().

00535                 {
00536                         GMatrix<N,M,TYPE> t = this->transpose();
00537                         GVector<N,TYPE> r;
00538                         for (int n=0; n<N; n++) {
00539                                 r[n] = t[n]*v;
00540                         }
00541                         return r;
00542                 }

template<int M, int N, typename TYPE = float>
template<int P>
GMatrix<P,N,TYPE> gmatrix::GMatrix< M, N, 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 516 of file gmatrix.h.

References gmatrix::GMatrix< M, N, TYPE >::transpose().

00517                 {
00518                         GMatrix<N,M,TYPE> s = this->transpose();
00519                         GMatrix<P,N,TYPE> r;
00520                         for (int p=0; p<P; p++) {
00521                                 for (int n=0; n<N; n++) {
00522                                         r[p][n] = m[p] * s[n];
00523                                 }
00524                         }
00525                         return r;
00526                 }

template<int M, int N, typename TYPE = float>
GMatrix<M,N,TYPE> gmatrix::GMatrix< M, N, 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 424 of file gmatrix.h.

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

00425                 {
00426                         GMatrix<M,N,TYPE> r;
00427                         for (int i=0; i<M; i++) {
00428                                 r._m[i] = _m[i] * k;
00429                         }
00430                         return r;
00431                 }

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

multiplication (scalar).

Multiply the current matrix by a scalar

Parameters:
k the scalar

Definition at line 490 of file gmatrix.h.

00491                 {
00492                         for (int i=0; i<M; i++) {
00493                                 _m[i] *= k;
00494                         }
00495                 }

template<int M, int N, typename TYPE = float>
GMatrix<M,N,TYPE> gmatrix::GMatrix< M, N, 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 394 of file gmatrix.h.

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

00395                 {
00396                         GMatrix<M,N,TYPE> r;
00397                         for (int i=0; i<M; i++) {
00398                                 r._m[i] = _m[i] + m._m[i];
00399                         }
00400                         return r;
00401                 }

template<int M, int N, typename TYPE = float>
void gmatrix::GMatrix< M, N, 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 466 of file gmatrix.h.

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

00467                 {
00468                         for (int i=0; i<M; i++) {
00469                                 _m[i] += m._m[i];
00470                         }
00471                 }

template<int M, int N, typename TYPE = float>
GMatrix<M,N,TYPE> gmatrix::GMatrix< M, N, 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 409 of file gmatrix.h.

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

00410                 {
00411                         GMatrix<M,N,TYPE> r;
00412                         for (int i=0; i<M; i++) {
00413                                 r._m[i] = _m[i] - m._m[i];
00414                         }
00415                         return r;
00416                 }

template<int M, int N, typename TYPE = float>
void gmatrix::GMatrix< M, N, 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 478 of file gmatrix.h.

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

00479                 {
00480                         for (int i=0; i<M; i++) {
00481                                 _m[i] -= m._m[i];
00482                         }
00483                 }

template<int M, int N, typename TYPE = float>
GMatrix<M,N,TYPE> gmatrix::GMatrix< M, N, 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 439 of file gmatrix.h.

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

00440                 {
00441                         GMatrix<M,N,TYPE> r;
00442                         for (int i=0; i<M; i++) {
00443                                 r._m[i] = _m[i] / k;
00444                         }
00445                         return r;
00446                 }

template<int M, int N, typename TYPE = float>
void gmatrix::GMatrix< M, N, 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 502 of file gmatrix.h.

00503                 {
00504                         for (int i=0; i<M; i++) {
00505                                 _m[i] /= k;
00506                         }
00507                 }

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

copy (operator=).

Copy a matrix to this.

Parameters:
m matrix to copy

Definition at line 453 of file gmatrix.h.

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

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

template<int M, int N, typename TYPE = float>
const GVector<N,TYPE>& gmatrix::GMatrix< M, N, 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 370 of file gmatrix.h.

00370 { return _m[m]; }

template<int M, int N, typename TYPE = float>
GVector<N,TYPE>& gmatrix::GMatrix< M, N, 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 362 of file gmatrix.h.

00362 { return _m[m]; }

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

operator* emulation.

multiply a vector v by the current matrix. Adding a premul function was necessary beacause the VC6 compiler have to way to find the difference between operator*(TYPE, GMatrix<TYPE<) and operator*(GVector<TYPE<,GMatrix<TYPE<).

See also:
operator*
Parameters:
v the vector
Returns:
v * (*this)

Definition at line 553 of file gmatrix.h.

00554                 {
00555                         GVector<M,TYPE> r;
00556                         for (int m=0; m<M; m++) {
00557                                 r[m] = v*_m[m];
00558                         }
00559                         return r;
00560                 }

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

matrix transpose.

transpose the current matrix

Returns:
the transposed NxM matrix

Definition at line 377 of file gmatrix.h.

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

00378                 {
00379                         GMatrix<N,M,TYPE> r;
00380                         for (int i=0; i<M; i++) {
00381                                 for (int j=0;j<N;j++) {
00382                                         r[j][i] = _m[i][j];
00383                                 }
00384                         }
00385                         return r;
00386                 }


The documentation for this class was generated from the following file:
Generated on Thu Aug 12 16:22:28 2004 for GMATRIX by doxygen 1.3.3