util::Matrix< nRows, nCols, T > Class Template Reference

Class representing a fixed-size matrix. More...

#include <util/matrix.h>

Inheritance diagram for util::Matrix< nRows, nCols, T >:
Inheritance graph
[legend]

List of all members.

Public Types

typedef const T * const_iterator
typedef const T * const_pointer_type
typedef const T & const_reference_type
typedef T * iterator
typedef T * pointer_type
typedef T & reference_type
typedef T value_type

Public Member Functions

const T * c_data () const
 Returns a constant raw pointer on the data.
T * data ()
 Returns a raw pointer on the data.
void fillArray (T *array, bool row_first=true)
 Matrix (const T &value)
 Create a diagonal matrix.
 Matrix (const T *values, bool c_style=true)
 Fill in the matrix with the values.
template<typename T1 >
 Matrix (const Vector< nCols, T1 > *vecs)
 Fill the matrix with the array of vectors.
template<size_t nRows1, size_t nCols1, typename T1 >
 Matrix (const Matrix< nRows1, nCols1, T1 > &mat)
 Copy a matrix.
template<typename T1 >
 Matrix (const Matrix< nRows, nCols, T1 > &mat)
 Copy a matrix.
 Matrix (const Matrix &mat)
 Copy constructor.
 Matrix (void)
 Create a matrix filled with 0s.
bool operator!= (const Matrix &mat) const
operator() (size_t i, size_t j) const
 Return the value at row i, column j.
T & operator() (size_t i, size_t j)
 Return the value at row i, column j.
Vector< nRows, T > operator* (const Vector< nCols, T > &vec) const
 Matrix*Vector.
Matrix operator* (const T &scalar) const
 Matrix-scalar multiplication.
Matrixoperator*= (const Matrix &mat)
Matrixoperator*= (const T &scalar)
Matrix operator+ (const Matrix &mat) const
 Matrix addition.
Matrixoperator+= (const Matrix &mat)
Matrix operator- (const Matrix &mat) const
Matrix operator- (void) const
 Matrix subtraction.
Matrixoperator-= (const Matrix &mat)
Matrix operator/ (const T &scalar) const
 Matrix-scalar division.
Matrixoperator/= (const T &scalar)
Matrixoperator= (const T &value)
 Set the matrix to a diagonal matrix.
Matrixoperator= (const Matrix &mat)
bool operator== (const Matrix &mat) const
Vector< nCols, T > operator[] (size_t idx) const
 Returns the nth row.
Vector< nCols, T > & operator[] (size_t idx)
 Returns the nth row.
Matrix< nCols, nRows, T > operator~ ()
 Transpose the matrix.
trace () const
 Trace of the matrix.
Matrixzero (void)
 Set the matrix to all zero.

Static Public Member Functions

static Matrix identity ()
 Returns an identity matrix.
static size_t nbColumns ()
 Returns the number of columns of the matrix.
static size_t nbRows ()
 Returns the number of rows of the matrix.
static Matrix< 4, 4, T > rotation (const Vector< 4, T > &direction, T angle)
 Creates the 4x4 matrix corresponding to a rotation.
static Matrix< 3, 3, T > rotation (const Vector< 3, T > &direction, T angle)
 Creates the 3x3 matrix corresponding to a rotation.
static Vector< 2, size_t > size ()
 Returns the size of the matrix.

Friends

Matrix operator* (const T &scalar, const Matrix &mat)
 Matrix-scalar multiplication.
std::ostream & operator<< (std::ostream &out, const Matrix &mat)
QTextStreamoperator<< (QTextStream &out, const Matrix &mat)
std::istream & operator>> (std::istream &in, Matrix &mat)
QTextStreamoperator>> (QTextStream &in, Matrix &mat)

Related Functions

(Note that these are not member functions.)



template<size_t nRows, typename T >
cofactor (const Matrix< nRows, nRows, T > &mat, size_t i, size_t j)
 Returns the cofactor of the matrix for position (i,j).
template<size_t nRows, typename T >
det (const Matrix< nRows, nRows, T > &mat)
 Determinant of the matrix.
template<typename T >
det (const Matrix< 3, 3, T > &mat)
 Determinant of the matrix.
template<typename T >
det (const Matrix< 2, 2, T > &mat)
 Determinant of the matrix.
template<typename T >
det (const Matrix< 1, 1, T > &mat)
 Determinant of the matrix.
template<size_t nRows, typename T >
Matrix< nRows, nRows, T > inverse (const Matrix< nRows, nRows, T > &mat)
 Inverse the matrix.
template<typename T >
Matrix< 3, 3, T > inverse (const Matrix< 3, 3, T > &mat)
 Inverse the matrix.
template<typename T >
Matrix< 2, 2, T > inverse (const Matrix< 2, 2, T > &mat)
 Inverse the matrix.
template<typename T >
Matrix< 1, 1, T > inverse (const Matrix< 1, 1, T > &mat)
 Inverse the matrix.
template<size_t nRows, size_t nCols, typename T , typename T1 , typename T2 >
Matrix< nRows, nCols, T > map (const T &(*fct)(const T1 &, const T2 &), const Matrix< nRows, nCols, T1 > &m1, const Matrix< nRows, nCols, T2 > &m2)
 Apply a binary function to each element of the matrix.
template<size_t nRows, size_t nCols, typename T , typename T1 , typename T2 >
Matrix< nRows, nCols, T > map (T(*fct)(const T1 &, const T2 &), const Matrix< nRows, nCols, T1 > &m1, const Matrix< nRows, nCols, T2 > &m2)
 Apply a binary function to each element of the matrix.
template<size_t nRows, size_t nCols, typename T , typename T1 , typename T2 >
Matrix< nRows, nCols, T > map (T(*fct)(T1, T2), const Matrix< nRows, nCols, T1 > &m1, const Matrix< nRows, nCols, T2 > &m2)
 Apply a binary function to each element of the matrix.
template<size_t nRows, size_t nCols, typename T >
Matrix< nRows, nCols, T > map (const T &(*fct)(const T &, const T &), const Matrix< nRows, nCols, T > &m1, const Matrix< nRows, nCols, T > &m2)
 Apply a binary function to each element of the matrix.
template<size_t nRows, size_t nCols, typename T >
Matrix< nRows, nCols, T > map (T(*fct)(const T &, const T &), const Matrix< nRows, nCols, T > &m1, const Matrix< nRows, nCols, T > &m2)
 Apply a binary function to each element of the matrix.
template<size_t nRows, size_t nCols, typename T >
Matrix< nRows, nCols, T > map (T(*fct)(T, T), const Matrix< nRows, nCols, T > &m1, const Matrix< nRows, nCols, T > &m2)
 Apply a binary function to each element of the matrix.
template<size_t nRows, size_t nCols, typename T , typename T1 >
Matrix< nRows, nCols, T > map (T(*fct)(const T1 &), const Matrix< nRows, nCols, T1 > &m)
 Apply a unary function to each element of the matrix.
template<size_t nRows, size_t nCols, typename T , typename T1 >
Matrix< nRows, nCols, T > map (T(*fct)(T1), const Matrix< nRows, nCols, T1 > &m)
 Apply a unary function to each element of the matrix.
template<size_t nRows, size_t nCols, typename T , typename T1 >
Matrix< nRows, nCols, T > map (const T &(*fct)(const T1 &), const Matrix< nRows, nCols, T1 > &m)
 Apply a unary function to each element of the matrix.
template<size_t nRows, size_t nCols, typename T >
Matrix< nRows, nCols, T > map (T(*fct)(const T &), const Matrix< nRows, nCols, T > &m)
 Apply a unary function to each element of the matrix.
template<size_t nRows, size_t nCols, typename T >
Matrix< nRows, nCols, T > map (T(*fct)(T), const Matrix< nRows, nCols, T > &m)
 Apply a unary function to each element of the matrix.
template<size_t nRows, size_t nCols, typename T >
Matrix< nRows, nCols, T > map (const T &(*fct)(const T &), const Matrix< nRows, nCols, T > &m)
 Apply a unary function to each element of the matrix.
template<size_t nRows, size_t nCols, typename T >
norm (const Matrix< nRows, nCols, T > &mat)
 Return the norm of the matrix.
template<size_t nRows, size_t nCols, typename T >
normsq (const Matrix< nRows, nCols, T > &mat)
 Return the square norm of the matrix.
template<size_t nRows, size_t nSize, size_t nCols, typename T >
Matrix< nRows, nCols, T > operator* (const Matrix< nRows, nSize, T > &mat1, const Matrix< nSize, nCols, T > &mat2)
 Matrix multiplication.
template<size_t nRows, size_t nCols, typename T >
Matrix< nCols, nRows, T > transpose (const Matrix< nRows, nCols, T > &mat)
 Transpose a matrix.

Detailed Description

template<size_t nRows, size_t nCols, typename T = double>
class util::Matrix< nRows, nCols, T >

Class representing a fixed-size matrix.

This class is optimized for small-sized matrix (3x3 or 4x4).

Definition at line 25 of file matrix.h.


Constructor & Destructor Documentation

template<size_t nRows, size_t nCols, typename T = double>
util::Matrix< nRows, nCols, T >::Matrix ( void   )  [inline]

Create a matrix filled with 0s.

Definition at line 42 of file matrix.h.

00043       {
00044         for( size_t i = 0 ; i < nRows ; i++ )
00045           for( size_t j = 0 ; j < nCols ; j++ )
00046             rows[ i ][ j ] = 0;
00047       }

template<size_t nRows, size_t nCols, typename T = double>
util::Matrix< nRows, nCols, T >::Matrix ( const Matrix< nRows, nCols, T > &  mat  )  [inline]

Copy constructor.

Definition at line 52 of file matrix.h.

00053       {
00054         for(size_t i = 0 ; i < nRows ; i++)
00055           rows[i] = mat.rows[i];
00056       }

template<size_t nRows, size_t nCols, typename T = double>
template<typename T1 >
util::Matrix< nRows, nCols, T >::Matrix ( const Matrix< nRows, nCols, T1 > &  mat  )  [inline, explicit]

Copy a matrix.

Can be used to cast a matrix onto another type.

Definition at line 64 of file matrix.h.

00065         {
00066           for(size_t i = 0 ; i < nRows ; i++)
00067             rows[i] = mat.rows[i];
00068         }

template<size_t nRows, size_t nCols, typename T = double>
template<size_t nRows1, size_t nCols1, typename T1 >
util::Matrix< nRows, nCols, T >::Matrix ( const Matrix< nRows1, nCols1, T1 > &  mat  )  [inline, explicit]

Copy a matrix.

Can be used to copy a matrix with more or less dimensions.

If the input has more dimensions, then the extra ones are just ignored. If the input has less dimensions, 1s are inserted in the diagonal, and 0s outside

Definition at line 79 of file matrix.h.

00080         {
00081           int rowMax = nRows1 < nRows ? nRows1 : nRows;
00082           int colMax = nCols1 < nCols ? nCols1 : nCols;
00083           for(size_t i = 0 ; i < rowMax ; i++)
00084           {
00085             Vector<nCols,T>& c = rows[i];
00086             const Vector<nCols1,T1>& c1 = mat[i];
00087             for(size_t j = 0 ; j < colMax ; j++)
00088               c[j] = c1[j];
00089             if(colMax < nCols)
00090               for(size_t j = colMax ; j < nCols ; ++j)
00091                 c[j] = i==j ? T(1) : T(0);
00092           }
00093           if(rowMax < nRows)
00094           {
00095             for(size_t i = rowMax ; i < nRows ; ++i)
00096             {
00097               Vector<nCols,T>& c = rows[i];
00098               for(size_t j = colMax ; j < nCols ; ++j)
00099                 c[j] = i==j ? T(1) : T(0);
00100             }
00101           }
00102         }

template<size_t nRows, size_t nCols, typename T = double>
template<typename T1 >
util::Matrix< nRows, nCols, T >::Matrix ( const Vector< nCols, T1 > *  vecs  )  [inline]

Fill the matrix with the array of vectors.

Parameters:
vecs Array of nRows vectors.

Definition at line 115 of file matrix.h.

00116         {
00117           for(size_t i = 0 ; i < nRows ; i++)
00118             rows[i] = vecs[i];
00119         }

template<size_t nRows, size_t nCols, typename T = double>
util::Matrix< nRows, nCols, T >::Matrix ( const T *  values,
bool  c_style = true 
) [inline]

Fill in the matrix with the values.

Parameters:
values nRows*nCols array. If c_style is true, values is rows first (i.e. the first values correspond to the first row). Otherwise, values are columns first.
c_style Determine the ordering of values.

Definition at line 130 of file matrix.h.

00131       {
00132         if(c_style)
00133         {
00134           for(size_t i = 0 ; i < nRows ; i++)
00135           {
00136             rows[i] = Vector<nCols,T>(values + (i*nCols));
00137           }
00138         }
00139         else
00140         {
00141           for(size_t i = 0 ; i < nRows ; i++)
00142             for(size_t j = 0 ; j < nCols ; j++)
00143             {
00144               rows[i][j] = values[i+j*nRows];
00145             }
00146         }
00147       }

template<size_t nRows, size_t nCols, typename T = double>
util::Matrix< nRows, nCols, T >::Matrix ( const T &  value  )  [inline]

Create a diagonal matrix.

Parameters:
value Value placed on the diagonal.

Definition at line 154 of file matrix.h.

00155       {
00156         for(size_t i = 0 ; i < nRows ; i++)
00157           for(size_t j = 0 ; j < nCols ; j++)
00158             rows[i][j] = (i==j)?value:0;
00159       }


Member Function Documentation

template<size_t nRows, size_t nCols, typename T = double>
const T* util::Matrix< nRows, nCols, T >::c_data (  )  const [inline]

Returns a constant raw pointer on the data.

The data are organised on by rows. (i.e. in the same order than OpenGL)

Definition at line 183 of file matrix.h.

00183 { return rows[0].c_data(); }

template<size_t nRows, size_t nCols, typename T = double>
T* util::Matrix< nRows, nCols, T >::data (  )  [inline]

Returns a raw pointer on the data.

The data are organised on by rows. (i.e. in the same order than OpenGL)

Definition at line 190 of file matrix.h.

00190 { return rows[0].data(); }

template<size_t nRows, size_t nCols, typename T = double>
static Matrix util::Matrix< nRows, nCols, T >::identity (  )  [inline, static]

Returns an identity matrix.

Definition at line 410 of file matrix.h.

00411       {
00412         Matrix mat(1);
00413         return mat;
00414       }

template<size_t nRows, size_t nCols, typename T = double>
static size_t util::Matrix< nRows, nCols, T >::nbColumns (  )  [inline, static]

Returns the number of columns of the matrix.

Definition at line 176 of file matrix.h.

00176 { return nCols; }

template<size_t nRows, size_t nCols, typename T = double>
static size_t util::Matrix< nRows, nCols, T >::nbRows (  )  [inline, static]

Returns the number of rows of the matrix.

Definition at line 171 of file matrix.h.

00171 { return nRows; }

template<size_t nRows, size_t nCols, typename T = double>
T util::Matrix< nRows, nCols, T >::operator() ( size_t  i,
size_t  j 
) const [inline]

Return the value at row i, column j.

Definition at line 402 of file matrix.h.

00403       {
00404         return rows[i][j];
00405       }

template<size_t nRows, size_t nCols, typename T = double>
T& util::Matrix< nRows, nCols, T >::operator() ( size_t  i,
size_t  j 
) [inline]

Return the value at row i, column j.

Definition at line 394 of file matrix.h.

00395       {
00396         return rows[i][j];
00397       }

template<size_t nRows, size_t nCols, typename T = double>
Vector<nRows,T> util::Matrix< nRows, nCols, T >::operator* ( const Vector< nCols, T > &  vec  )  const [inline]

Matrix*Vector.

Definition at line 273 of file matrix.h.

00274       {
00275         Vector<nRows,T> ans;
00276         for(size_t i = 0 ; i < nRows ; ++i)
00277         {
00278           T value = 0;
00279           for(size_t j = 0 ; j < nCols ; ++j)
00280             value += rows[i][j] * vec[j];
00281           ans[i] = value;
00282         }
00283         return ans;
00284       }

template<size_t nRows, size_t nCols, typename T = double>
Matrix util::Matrix< nRows, nCols, T >::operator* ( const T &  scalar  )  const [inline]

Matrix-scalar multiplication.

Definition at line 234 of file matrix.h.

00235       {
00236         Matrix ans;
00237 
00238         for(size_t i = 0 ; i < nRows ; i++)
00239           ans[i] = rows[i] * scalar;
00240 
00241         return ans;
00242       }

template<size_t nRows, size_t nCols, typename T = double>
Matrix util::Matrix< nRows, nCols, T >::operator+ ( const Matrix< nRows, nCols, T > &  mat  )  const [inline]

Matrix addition.

Matrix subtraction

Definition at line 208 of file matrix.h.

00209       {
00210         Matrix ans;
00211 
00212         for(size_t i = 0 ; i < nRows ; i++)
00213           ans.rows[i] = rows[i] + mat.rows[i];
00214 
00218         return ans;
00219       }

template<size_t nRows, size_t nCols, typename T = double>
Matrix util::Matrix< nRows, nCols, T >::operator- ( void   )  const [inline]

Matrix subtraction.

Definition at line 195 of file matrix.h.

00196       {
00197         Matrix ans;
00198 
00199         for(size_t i = 0 ; i < nRows ; i++)
00200           ans.rows[i] = -rows[i];
00201 
00202         return ans;
00203       }

template<size_t nRows, size_t nCols, typename T = double>
Matrix util::Matrix< nRows, nCols, T >::operator/ ( const T &  scalar  )  const [inline]

Matrix-scalar division.

Definition at line 247 of file matrix.h.

00248       {
00249         Matrix ans;
00250 
00251         for(size_t i = 0 ; i < nRows ; i++)
00252           ans[i] = rows[i] / scalar;
00253 
00254         return ans;
00255       }

template<size_t nRows, size_t nCols, typename T = double>
Matrix& util::Matrix< nRows, nCols, T >::operator= ( const T &  value  )  [inline]

Set the matrix to a diagonal matrix.

Parameters:
value Value to put on the diagonal

Definition at line 432 of file matrix.h.

00433       {
00434         for( size_t i = 0 ; i < nRows ; ++i )
00435         {
00436           for( size_t j = 0 ; j < nCols ; ++j )
00437           {
00438             if( i == j )
00439               rows[ i ][ j ] = value;
00440             else
00441               rows[ i ][ j ] = 0;
00442           }
00443         }
00444         return *this;
00445       }

template<size_t nRows, size_t nCols, typename T = double>
Vector<nCols,T> util::Matrix< nRows, nCols, T >::operator[] ( size_t  idx  )  const [inline]

Returns the nth row.

Parameters:
idx Index of the returned row

Definition at line 386 of file matrix.h.

00387       {
00388         return rows[idx];
00389       }

template<size_t nRows, size_t nCols, typename T = double>
Vector<nCols,T>& util::Matrix< nRows, nCols, T >::operator[] ( size_t  idx  )  [inline]

Returns the nth row.

Parameters:
idx Index of the returned row

Definition at line 376 of file matrix.h.

00377       {
00378         return rows[idx];
00379       }

template<size_t nRows, size_t nCols, typename T = double>
Matrix<nCols,nRows,T> util::Matrix< nRows, nCols, T >::operator~ (  )  [inline]

Transpose the matrix.

Definition at line 450 of file matrix.h.

00451       {
00452         Matrix<nCols,nRows,T> t;
00453         for( size_t i = 0 ; i < nRows ; ++i )
00454           for( size_t j = 0 ; j < nCols ; ++j )
00455             t[ i ][ j ] = rows[ j ][ i ];
00456         return t;
00457       }

template<size_t nRows, size_t nCols, typename T = double>
static Matrix<4,4,T> util::Matrix< nRows, nCols, T >::rotation ( const Vector< 4, T > &  direction,
angle 
) [inline, static]

Creates the 4x4 matrix corresponding to a rotation.

Parameters:
direction Axes of the rotation
angle Angle of the rotation

Definition at line 485 of file matrix.h.

00486       {
00487         T ca = std::cos( angle );
00488         T sa = std::sin( angle );
00489         Matrix<4,4,T> r;
00490         double x = direction.x()/direction.t();
00491         double y = direction.y()/direction.t();
00492         double z = direction.z()/direction.t();
00493         r[ 0 ].set( ca+(1-ca)*x*x,   (1-ca)*x*y-sa*z, (1-ca)*z*x+sa*y, 0 );
00494         r[ 1 ].set( (1-ca)*y*x+sa*z, ca+(1-ca)*y*y,   (1-ca)*z*y-sa*x, 0 );
00495         r[ 2 ].set( (1-ca)*x*z-sa*y, (1-ca)*y*z+sa*x, ca+(1-ca)*z*z, 0 );
00496         r[ 3 ].set( 0, 0, 0, 1 );
00497         return r;
00498       }

template<size_t nRows, size_t nCols, typename T = double>
static Matrix<3,3,T> util::Matrix< nRows, nCols, T >::rotation ( const Vector< 3, T > &  direction,
angle 
) [inline, static]

Creates the 3x3 matrix corresponding to a rotation.

Parameters:
direction Axes of the rotation
angle Angle of the rotation

Definition at line 465 of file matrix.h.

00466       {
00467         T ca = std::cos( angle );
00468         T sa = std::sin( angle );
00469         Matrix<3,3,T> r;
00470         double x = direction.x();
00471         double y = direction.y();
00472         double z = direction.z();
00473         r[ 0 ].set( ca+(1-ca)*x*x,   (1-ca)*x*y-sa*z, (1-ca)*z*x+sa*y );
00474         r[ 1 ].set( (1-ca)*y*x+sa*z, ca+(1-ca)*y*y,   (1-ca)*z*y-sa*x );
00475         r[ 2 ].set( (1-ca)*x*z-sa*y, (1-ca)*y*z+sa*x, ca+(1-ca)*z*z );
00476         return r;
00477       }

template<size_t nRows, size_t nCols, typename T = double>
static Vector<2,size_t> util::Matrix< nRows, nCols, T >::size (  )  [inline, static]

Returns the size of the matrix.

First element is number of rows, second is number of columns

Definition at line 166 of file matrix.h.

00166 { return Vector<2,size_t>(nRows, nCols); }

template<size_t nRows, size_t nCols, typename T = double>
T util::Matrix< nRows, nCols, T >::trace (  )  const [inline]

Trace of the matrix.

Definition at line 503 of file matrix.h.

00504       {
00505         T acc = 0;
00506         for(size_t i = 0 ; i < std::min(nRows,nCols) ; ++i)
00507         {
00508           acc += rows[i][i];
00509         }
00510         return acc;
00511       }

template<size_t nRows, size_t nCols, typename T = double>
Matrix& util::Matrix< nRows, nCols, T >::zero ( void   )  [inline]

Set the matrix to all zero.

Definition at line 419 of file matrix.h.

00420       {
00421         for(size_t i = 0 ; i < nRows ; i++)
00422           for(size_t j = 0 ; j < nCols ; j++)
00423             rows[i][j] = 0.0;
00424         return (*this);
00425       }


Friends And Related Function Documentation

template<size_t nRows, typename T >
T cofactor ( const Matrix< nRows, nRows, T > &  mat,
size_t  i,
size_t  j 
) [related]

Returns the cofactor of the matrix for position (i,j).

template<size_t nRows, typename T >
T det ( const Matrix< nRows, nRows, T > &  mat  )  [related]

Determinant of the matrix.

Warning:
the method used is $O(n^3)$ complexity !
template<typename T >
T det ( const Matrix< 3, 3, T > &  mat  )  [related]

Determinant of the matrix.

template<typename T >
T det ( const Matrix< 2, 2, T > &  mat  )  [related]

Determinant of the matrix.

template<typename T >
T det ( const Matrix< 1, 1, T > &  mat  )  [related]

Determinant of the matrix.

template<size_t nRows, typename T >
Matrix< nRows, nRows, T > inverse ( const Matrix< nRows, nRows, T > &  mat  )  [related]

Inverse the matrix.

Warning:
This algorithm is sub-optimal
template<typename T >
Matrix< 3, 3, T > inverse ( const Matrix< 3, 3, T > &  mat  )  [related]

Inverse the matrix.

template<typename T >
Matrix< 2, 2, T > inverse ( const Matrix< 2, 2, T > &  mat  )  [related]

Inverse the matrix.

template<typename T >
Matrix< 1, 1, T > inverse ( const Matrix< 1, 1, T > &  mat  )  [related]

Inverse the matrix.

template<size_t nRows, size_t nCols, typename T , typename T1 , typename T2 >
Matrix< nRows, nCols, T > map ( const T &(*)(const T1 &, const T2 &)  fct,
const Matrix< nRows, nCols, T1 > &  m1,
const Matrix< nRows, nCols, T2 > &  m2 
) [related]

Apply a binary function to each element of the matrix.

Definition at line 876 of file matrix.h.

00877   {
00878     Matrix<nRows,nCols,T> result;
00879     for(size_t i = 0 ; i < nRows ; ++i)
00880     {
00881       const Vector<nCols,T1>& mrow1 = m1[i];
00882       const Vector<nCols,T2>& mrow2 = m2[i];
00883       Vector<nCols,T>& rrow = result[i];
00884       for(size_t j = 0 ; j < nCols ; ++j)
00885       {
00886         rrow[j] = (*fct)(mrow1[j], mrow2[j]);
00887       }
00888     }
00889     return result;
00890   }

template<size_t nRows, size_t nCols, typename T , typename T1 , typename T2 >
Matrix< nRows, nCols, T > map ( T(*)(const T1 &, const T2 &)  fct,
const Matrix< nRows, nCols, T1 > &  m1,
const Matrix< nRows, nCols, T2 > &  m2 
) [related]

Apply a binary function to each element of the matrix.

Definition at line 854 of file matrix.h.

00855   {
00856     Matrix<nRows,nCols,T> result;
00857     for(size_t i = 0 ; i < nRows ; ++i)
00858     {
00859       const Vector<nCols,T1>& mrow1 = m1[i];
00860       const Vector<nCols,T2>& mrow2 = m2[i];
00861       Vector<nCols,T>& rrow = result[i];
00862       for(size_t j = 0 ; j < nCols ; ++j)
00863       {
00864         rrow[j] = (*fct)(mrow1[j], mrow2[j]);
00865       }
00866     }
00867     return result;
00868   }

template<size_t nRows, size_t nCols, typename T , typename T1 , typename T2 >
Matrix< nRows, nCols, T > map ( T(*)(T1, T2)  fct,
const Matrix< nRows, nCols, T1 > &  m1,
const Matrix< nRows, nCols, T2 > &  m2 
) [related]

Apply a binary function to each element of the matrix.

Definition at line 832 of file matrix.h.

00833   {
00834     Matrix<nRows,nCols,T> result;
00835     for(size_t i = 0 ; i < nRows ; ++i)
00836     {
00837       const Vector<nCols,T1>& mrow1 = m1[i];
00838       const Vector<nCols,T2>& mrow2 = m2[i];
00839       Vector<nCols,T>& rrow = result[i];
00840       for(size_t j = 0 ; j < nCols ; ++j)
00841       {
00842         rrow[j] = (*fct)(mrow1[j], mrow2[j]);
00843       }
00844     }
00845     return result;
00846   }

template<size_t nRows, size_t nCols, typename T >
Matrix< nRows, nCols, T > map ( const T &(*)(const T &, const T &)  fct,
const Matrix< nRows, nCols, T > &  m1,
const Matrix< nRows, nCols, T > &  m2 
) [related]

Apply a binary function to each element of the matrix.

Definition at line 810 of file matrix.h.

00811   {
00812     Matrix<nRows,nCols,T> result;
00813     for(size_t i = 0 ; i < nRows ; ++i)
00814     {
00815       const Vector<nCols,T>& mrow1 = m1[i];
00816       const Vector<nCols,T>& mrow2 = m2[i];
00817       Vector<nCols,T>& rrow = result[i];
00818       for(size_t j = 0 ; j < nCols ; ++j)
00819       {
00820         rrow[j] = (*fct)(mrow1[j], mrow2[j]);
00821       }
00822     }
00823     return result;
00824   }

template<size_t nRows, size_t nCols, typename T >
Matrix< nRows, nCols, T > map ( T(*)(const T &, const T &)  fct,
const Matrix< nRows, nCols, T > &  m1,
const Matrix< nRows, nCols, T > &  m2 
) [related]

Apply a binary function to each element of the matrix.

Definition at line 788 of file matrix.h.

00789   {
00790     Matrix<nRows,nCols,T> result;
00791     for(size_t i = 0 ; i < nRows ; ++i)
00792     {
00793       const Vector<nCols,T>& mrow1 = m1[i];
00794       const Vector<nCols,T>& mrow2 = m2[i];
00795       Vector<nCols,T>& rrow = result[i];
00796       for(size_t j = 0 ; j < nCols ; ++j)
00797       {
00798         rrow[j] = (*fct)(mrow1[j], mrow2[j]);
00799       }
00800     }
00801     return result;
00802   }

template<size_t nRows, size_t nCols, typename T >
Matrix< nRows, nCols, T > map ( T(*)(T, T)  fct,
const Matrix< nRows, nCols, T > &  m1,
const Matrix< nRows, nCols, T > &  m2 
) [related]

Apply a binary function to each element of the matrix.

Definition at line 766 of file matrix.h.

00767   {
00768     Matrix<nRows,nCols,T> result;
00769     for(size_t i = 0 ; i < nRows ; ++i)
00770     {
00771       const Vector<nCols,T>& mrow1 = m1[i];
00772       const Vector<nCols,T>& mrow2 = m2[i];
00773       Vector<nCols,T>& rrow = result[i];
00774       for(size_t j = 0 ; j < nCols ; ++j)
00775       {
00776         rrow[j] = (*fct)(mrow1[j], mrow2[j]);
00777       }
00778     }
00779     return result;
00780   }

template<size_t nRows, size_t nCols, typename T , typename T1 >
Matrix< nRows, nCols, T > map ( T(*)(const T1 &)  fct,
const Matrix< nRows, nCols, T1 > &  m 
) [related]

Apply a unary function to each element of the matrix.

Definition at line 745 of file matrix.h.

00746   {
00747     Matrix<nRows,nCols,T> result;
00748     for(size_t i = 0 ; i < nRows ; ++i)
00749     {
00750       const Vector<nCols,T1>& mrow = m[i];
00751       Vector<nCols,T>& rrow = result[i];
00752       for(size_t j = 0 ; j < nCols ; ++j)
00753       {
00754         rrow[j] = (*fct)(mrow[j]);
00755       }
00756     }
00757     return result;
00758   }

template<size_t nRows, size_t nCols, typename T , typename T1 >
Matrix< nRows, nCols, T > map ( T(*)(T1)  fct,
const Matrix< nRows, nCols, T1 > &  m 
) [related]

Apply a unary function to each element of the matrix.

Definition at line 723 of file matrix.h.

00724   {
00725     Matrix<nRows,nCols,T> result;
00726     for(size_t i = 0 ; i < nRows ; ++i)
00727     {
00728       const Vector<nCols,T1>& mrow = m[i];
00729       Vector<nCols,T>& rrow = result[i];
00730       for(size_t j = 0 ; j < nCols ; ++j)
00731       {
00732         rrow[j] = (*fct)(mrow[j]);
00733       }
00734     }
00735     return result;
00736   }

template<size_t nRows, size_t nCols, typename T , typename T1 >
Matrix< nRows, nCols, T > map ( const T &(*)(const T1 &)  fct,
const Matrix< nRows, nCols, T1 > &  m 
) [related]

Apply a unary function to each element of the matrix.

Definition at line 702 of file matrix.h.

00703   {
00704     Matrix<nRows,nCols,T> result;
00705     for(size_t i = 0 ; i < nRows ; ++i)
00706     {
00707       const Vector<nCols,T1>& mrow = m[i];
00708       Vector<nCols,T>& rrow = result[i];
00709       for(size_t j = 0 ; j < nCols ; ++j)
00710       {
00711         rrow[j] = (*fct)(mrow[j]);
00712       }
00713     }
00714     return result;
00715   }

template<size_t nRows, size_t nCols, typename T >
Matrix< nRows, nCols, T > map ( T(*)(const T &)  fct,
const Matrix< nRows, nCols, T > &  m 
) [related]

Apply a unary function to each element of the matrix.

Definition at line 681 of file matrix.h.

00682   {
00683     Matrix<nRows,nCols,T> result;
00684     for(size_t i = 0 ; i < nRows ; ++i)
00685     {
00686       const Vector<nCols,T>& mrow = m[i];
00687       Vector<nCols,T>& rrow = result[i];
00688       for(size_t j = 0 ; j < nCols ; ++j)
00689       {
00690         rrow[j] = (*fct)(mrow[j]);
00691       }
00692     }
00693     return result;
00694   }

template<size_t nRows, size_t nCols, typename T >
Matrix< nRows, nCols, T > map ( T(*)(T)  fct,
const Matrix< nRows, nCols, T > &  m 
) [related]

Apply a unary function to each element of the matrix.

Definition at line 659 of file matrix.h.

00660   {
00661     Matrix<nRows,nCols,T> result;
00662     for(size_t i = 0 ; i < nRows ; ++i)
00663     {
00664       const Vector<nCols,T>& mrow = m[i];
00665       Vector<nCols,T>& rrow = result[i];
00666       for(size_t j = 0 ; j < nCols ; ++j)
00667       {
00668         rrow[j] = (*fct)(mrow[j]);
00669       }
00670     }
00671     return result;
00672   }

template<size_t nRows, size_t nCols, typename T >
Matrix< nRows, nCols, T > map ( const T &(*)(const T &)  fct,
const Matrix< nRows, nCols, T > &  m 
) [related]

Apply a unary function to each element of the matrix.

Definition at line 638 of file matrix.h.

00639   {
00640     Matrix<nRows,nCols,T> result;
00641     for(size_t i = 0 ; i < nRows ; ++i)
00642     {
00643       const Vector<nCols,T>& mrow = m[i];
00644       Vector<nCols,T>& rrow = result[i];
00645       for(size_t j = 0 ; j < nCols ; ++j)
00646       {
00647         rrow[j] = (*fct)(mrow[j]);
00648       }
00649     }
00650     return result;
00651   }

template<size_t nRows, size_t nCols, typename T >
T norm ( const Matrix< nRows, nCols, T > &  mat  )  [related]

Return the norm of the matrix.

The norm is defined as the square-root of the sum of the square of the values.

template<size_t nRows, size_t nCols, typename T >
T normsq ( const Matrix< nRows, nCols, T > &  mat  )  [related]

Return the square norm of the matrix.

See also:
norm(const Matrix&)
template<size_t nRows, size_t nSize, size_t nCols, typename T >
Matrix< nRows, nCols, T > operator* ( const Matrix< nRows, nSize, T > &  mat1,
const Matrix< nSize, nCols, T > &  mat2 
) [related]

Matrix multiplication.

template<size_t nRows, size_t nCols, typename T = double>
Matrix operator* ( const T &  scalar,
const Matrix< nRows, nCols, T > &  mat 
) [friend]

Matrix-scalar multiplication.

Definition at line 260 of file matrix.h.

00261       {
00262         Matrix ans;
00263 
00264         for(size_t i = 0 ; i < nRows ; i++)
00265           ans[i] = scalar * mat.rows[i];
00266 
00267         return ans;
00268       }

template<size_t nRows, size_t nCols, typename T >
Matrix< nCols, nRows, T > transpose ( const Matrix< nRows, nCols, T > &  mat  )  [related]

Transpose a matrix.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Fri May 31 15:38:33 2013 for VVE by  doxygen 1.6.3