TinyMatrix< M, N, T > Class Template Reference

this class is used to manage small squared matrices. There size is to be known at compilation time More...

#include <TinyMatrix.hpp>

Inheritance diagram for TinyMatrix< M, N, T >:

Inheritance graph
[legend]
Collaboration diagram for TinyMatrix< M, N, T >:

Collaboration graph
[legend]

List of all members.

Public Types

enum  { NumberOfLines = M, NumberOfRow = N }
typedef TinyVector< N > AssociatedVector
typedef TinyVector< M > AssociatedTransposedVector
typedef T ValueType

Public Member Functions

T & operator() (const size_t &i, const size_t &j)
const T & operator() (const size_t &i, const size_t &j) const
const TinyMatrix< M, N, T > & operator= (const TinyMatrix< M, N, T > &B)
const TinyMatrix< M, N, T > & operator+= (const TinyMatrix< M, N, T > &B)
const TinyMatrix< M, N, T > & operator-= (const TinyMatrix< M, N, T > &B)
template<size_t P>
TinyMatrix< M, P > operator* (const TinyMatrix< N, P > &B) const
TinyVector< M, T > operator* (const TinyVector< N, T > &v) const
TinyMatrix< M, N, T > operator* (const T &t) const
TinyMatrix< M, N, T > operator/ (const T &t) const
const TinyMatrix< M, N, T > & operator*= (const T &t)
const TinyMatrix< M, N, T > & operator/= (const T &t)
TinyMatrix< M, N, T > operator+ (const TinyMatrix< M, N, T > &B) const
TinyMatrix< M, N, T > operator- (const TinyMatrix< M, N, T > &B) const
 TinyMatrix ()
 TinyMatrix (const TinyMatrix< M, N, T > &B)
 TinyMatrix (const T &t)
 ~TinyMatrix ()

Private Attributes

__x [M][N]

Friends

TinyMatrix< M, N, T > operator* (const T &t, const TinyMatrix< M, N, T > &A)
std::ostream & operator<< (std::ostream &os, const TinyMatrix< M, N, T > &A)


Detailed Description

template<size_t M, size_t N, typename T = real_t>
class TinyMatrix< M, N, T >

this class is used to manage small squared matrices. There size is to be known at compilation time

specialization for matrices 1x1

,T>

Author:
Stéphane Del Pino
Date:
Thu Aug 7 18:31:38 2003
,T>
Author:
Stéphane Del Pino
Date:
Thu Aug 7 19:06:05 2003

Definition at line 37 of file TinyMatrix.hpp.


Member Typedef Documentation

template<size_t M, size_t N, typename T = real_t>
typedef TinyVector<N> TinyMatrix< M, N, T >::AssociatedVector

Type of compatibke vector

Definition at line 41 of file TinyMatrix.hpp.

template<size_t M, size_t N, typename T = real_t>
typedef TinyVector<M> TinyMatrix< M, N, T >::AssociatedTransposedVector

Type of compatible transposed vector

Definition at line 44 of file TinyMatrix.hpp.

template<size_t M, size_t N, typename T = real_t>
typedef T TinyMatrix< M, N, T >::ValueType

The type of the elements of the TinyMatrix

Definition at line 47 of file TinyMatrix.hpp.


Member Enumeration Documentation

template<size_t M, size_t N, typename T = real_t>
anonymous enum

Enumerator:
NumberOfLines  number of lines
NumberOfRow  number of rows

Definition at line 50 of file TinyMatrix.hpp.

00050        {
00051     NumberOfLines = M,          
00052     NumberOfRow   = N           
00053   };


Constructor & Destructor Documentation

template<size_t M, size_t N, typename T = real_t>
TinyMatrix< M, N, T >::TinyMatrix (  )  [inline]

Default constructor

Note:
matrix is initialized to 0

Definition at line 305 of file TinyMatrix.hpp.

00306   {
00307     T* y = __x[0];
00308     for (size_t i=0; i<M*N; i++) {
00309       y[i] = 0;
00310     }
00311   }

template<size_t M, size_t N, typename T = real_t>
TinyMatrix< M, N, T >::TinyMatrix ( const TinyMatrix< M, N, T > &  B  )  [inline]

Copy constructor

Parameters:
B the matrix to copy

Definition at line 318 of file TinyMatrix.hpp.

00319   {
00320     T* y = __x[0];
00321     const T* B_y = B.__x[0];
00322     for (size_t i=0; i<M*N; i++) {
00323       y[i] = B_y[i];
00324     }
00325   }

template<size_t M, size_t N, typename T = real_t>
TinyMatrix< M, N, T >::TinyMatrix ( const T &  t  )  [inline]

Constructs a matrix using a given T

Parameters:
t the given T
Note:
the built matrix is diagonal. Its coefficients are t for the first diagonal terms, 0 for others

does have no sens (diagonal is not well defined)

Definition at line 336 of file TinyMatrix.hpp.

00337   {
00338     for (size_t i=0; i<M; i++)
00339       for (size_t j=0; j<N; j++)
00340         __x[i][j] = (i==j)?t:0;
00341   }

template<size_t M, size_t N, typename T = real_t>
TinyMatrix< M, N, T >::~TinyMatrix (  )  [inline]

The destructor

Definition at line 347 of file TinyMatrix.hpp.

00348   {
00349     ;
00350   }


Member Function Documentation

template<size_t M, size_t N, typename T = real_t>
T& TinyMatrix< M, N, T >::operator() ( const size_t &  i,
const size_t &  j 
) [inline]

Access to the $(i,j)$ coefficient of the matrix

Parameters:
i the line number
j the row number
Returns:
$ A_{ij} $

Definition at line 68 of file TinyMatrix.hpp.

00069   {
00070     ASSERT ((i<M) && (j<N));
00071     return __x[i][j];
00072   }

template<size_t M, size_t N, typename T = real_t>
const T& TinyMatrix< M, N, T >::operator() ( const size_t &  i,
const size_t &  j 
) const [inline]

Read-only access to the (i,j) coefficient of the matrix

Parameters:
i the line number
j the row number
Returns:
$ A_{ij} $

Definition at line 82 of file TinyMatrix.hpp.

00083   {
00084     ASSERT ((i<M) && (j<N));
00085     return __x[i][j];
00086   }

template<size_t M, size_t N, typename T = real_t>
const TinyMatrix<M,N,T>& TinyMatrix< M, N, T >::operator= ( const TinyMatrix< M, N, T > &  B  )  [inline]

Makes the current matrix be equal to a given one

Parameters:
B the given matrix
Returns:
the matrix $ A := B $

Definition at line 95 of file TinyMatrix.hpp.

00096   {
00097     T* y = __x[0];
00098     const T* B_y = B.__x[0];
00099     for (size_t i=0; i<M*N; i++)
00100       y[i] = B_y[i];
00101     return (*this);
00102   }

template<size_t M, size_t N, typename T = real_t>
const TinyMatrix<M,N,T>& TinyMatrix< M, N, T >::operator+= ( const TinyMatrix< M, N, T > &  B  )  [inline]

Adds a matrix to a given one

Parameters:
B the matrix to add
Returns:
$ A := A +B $

Definition at line 111 of file TinyMatrix.hpp.

00112   {
00113     T* y = __x[0];
00114     const T* B_y = B.__x[0];
00115     for (size_t i=0; i<M*N; i++)
00116       y[i] += B_y[i];
00117     return (*this);
00118   }

template<size_t M, size_t N, typename T = real_t>
const TinyMatrix<M,N,T>& TinyMatrix< M, N, T >::operator-= ( const TinyMatrix< M, N, T > &  B  )  [inline]

Substracts a given matrix

Parameters:
B the matrix to substract
Returns:
$ A := A-B $

Definition at line 127 of file TinyMatrix.hpp.

00128   {
00129     T* y = __x[0];
00130     const T* B_y = B.__x[0];
00131     for (size_t i=0; i<M*N; i++)
00132       y[i] -= B_y[i];
00133     return (*this);
00134   }

template<size_t M, size_t N, typename T = real_t>
template<size_t P>
TinyMatrix<M,P> TinyMatrix< M, N, T >::operator* ( const TinyMatrix< N, P > &  B  )  const [inline]

Computes the product on the right to a given compatible matrix

Parameters:
B the given matrix
Returns:
$ AB $

Definition at line 144 of file TinyMatrix.hpp.

00145   {
00146     TinyMatrix<M,P> C(0);
00147     for (size_t i=0; i<M; i++)
00148       for (size_t j=0; j<P; j++)
00149         for (size_t k=0; k<N; k++)
00150           C(i,j) += __x[i][k] * B(k,j);
00151     return C;
00152   }

template<size_t M, size_t N, typename T = real_t>
TinyVector<M,T> TinyMatrix< M, N, T >::operator* ( const TinyVector< N, T > &  v  )  const [inline]

Computes the product with a given compatible vector

Parameters:
v the given vector
Returns:
$ Av $

Definition at line 161 of file TinyMatrix.hpp.

00162   {
00163     TinyVector<M,T> u = 0;
00164     for (size_t i=0; i<M; i++)
00165       for (size_t j=0; j<N; j++)
00166           u[i] += __x[i][j] * v[j];
00167     return u;
00168   }

template<size_t M, size_t N, typename T = real_t>
TinyMatrix<M,N,T> TinyMatrix< M, N, T >::operator* ( const T &  t  )  const [inline]

Computes the product with a given T on the right

Parameters:
t the given T
Returns:
$ t A $

Definition at line 177 of file TinyMatrix.hpp.

00178   {
00179     TinyMatrix<M,N,T> B;
00180     for (size_t i=0; i<M; i++)
00181       for (size_t j=0; j<N; j++)
00182           B.__x[i][j] = __x[i][j] * t;
00183     return B;
00184   }

template<size_t M, size_t N, typename T = real_t>
TinyMatrix<M,N,T> TinyMatrix< M, N, T >::operator/ ( const T &  t  )  const [inline]

Computes the product with the invert of a given vector on the right

Parameters:
t the given vector
Returns:
$ t^{-1} A $

Definition at line 193 of file TinyMatrix.hpp.

00194   {
00195     ASSERT(t != 0);
00196     TinyMatrix<M,N,T> B;
00197     const T t_1 = 1./t;
00198     for (size_t i=0; i<M; i++)
00199       for (size_t j=0; j<N; j++)
00200           B.__x[i][j] = __x[i][j] * t_1;
00201     return B;
00202   }

template<size_t M, size_t N, typename T = real_t>
const TinyMatrix<M,N,T>& TinyMatrix< M, N, T >::operator*= ( const T &  t  )  [inline]

Multiplies a matrix by a given T on the right

Parameters:
t the given T
Returns:
$ A := t A $

Definition at line 211 of file TinyMatrix.hpp.

00212   {
00213     for (size_t i=0; i<M; i++)
00214       for (size_t j=0; j<N; j++)
00215         __x[i][j] *= t;
00216     return (*this);
00217   }

template<size_t M, size_t N, typename T = real_t>
const TinyMatrix<M,N,T>& TinyMatrix< M, N, T >::operator/= ( const T &  t  )  [inline]

Multiplies a matrix by the invert of a given T on the right

Parameters:
t the given T
Returns:
$ A := t^{-1} A $

Definition at line 226 of file TinyMatrix.hpp.

00227   {
00228     const T t_1 = 1./t;
00229     for (size_t i=0; i<M; i++)
00230       for (size_t j=0; j<N; j++)
00231         __x[i][j] *= t_1;
00232     return (*this);
00233   }

template<size_t M, size_t N, typename T = real_t>
TinyMatrix<M,N,T> TinyMatrix< M, N, T >::operator+ ( const TinyMatrix< M, N, T > &  B  )  const [inline]

Computes the sum of two matrices

Parameters:
B the second matrix
Returns:
$ A+B $

Definition at line 256 of file TinyMatrix.hpp.

00257   {
00258     TinyMatrix<M,N,T> C;
00259     for (size_t i=0; i<M; i++)
00260       for (size_t j=0; j<N; j++)
00261         C.__x[i][j] = __x[i][j] + B.__x[i][j];
00262     return C;
00263   }

template<size_t M, size_t N, typename T = real_t>
TinyMatrix<M,N,T> TinyMatrix< M, N, T >::operator- ( const TinyMatrix< M, N, T > &  B  )  const [inline]

Computes the difference of two matrices

Parameters:
B the second matrix
Returns:
$ A - B $

Definition at line 272 of file TinyMatrix.hpp.

00273   {
00274     TinyMatrix<M,N,T> C;
00275     for (size_t i=0; i<M; i++)
00276       for (size_t j=0; j<N; j++)
00277           C.__x[i][j] = __x[i][j] - B.__x[i][j];
00278     return C;
00279   }


Friends And Related Function Documentation

template<size_t M, size_t N, typename T = real_t>
TinyMatrix<M,N,T> operator* ( const T &  t,
const TinyMatrix< M, N, T > &  A 
) [friend]

Computes the product by a T on the left

Parameters:
t the multiplicative T
A the matrix
Returns:
$ t A $

Definition at line 243 of file TinyMatrix.hpp.

00245   {
00246     return (A*t);
00247   }

template<size_t M, size_t N, typename T = real_t>
std::ostream& operator<< ( std::ostream &  os,
const TinyMatrix< M, N, T > &  A 
) [friend]

Prints a matrix to a stream

Parameters:
os the given stream
A the given matrix
Returns:
the modified stream

Definition at line 289 of file TinyMatrix.hpp.

00291   {
00292     for (size_t i=0; i<M; i++) {
00293       for (size_t j=0; j<N; j++)
00294         os << A(i,j) << " ";
00295       os << '\n';
00296     }
00297     return os;
00298   }


Member Data Documentation

template<size_t M, size_t N, typename T = real_t>
T TinyMatrix< M, N, T >::__x[M][N] [private]


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

Generated on Wed Nov 19 00:16:26 2008 for FreeFEM3D (aka ff3d) by  doxygen 1.5.6