Matrix Class Reference

#include <matrix.h>

List of all members.


Detailed Description

Matrix type.

Type D is datatype of matrix elements, which is fixed to double. There are basicly two different types of operation: Inplace operations and copy operations. Please use the latter ones unless you know what you are doing. Just in case of critical performance optimisation use the inplace operations. The most convinient way is to use the overloaded operators (like + * ...). All constructed matrices are initialised with zero elements (unless data is given). All functions perform range checks if in debug mode (NDEBUG is not defined). Please use -lmatrix_debug for testing.

Author:
Georg Martius

Definition at line 127 of file matrix.h.

Public Member Functions

 Matrix ()
 default constructor: zero matrix (0x0)
 Matrix (unsigned short _m, unsigned short _n, const D *_data=0)
 constucts a matrix with the given size.
 Matrix (const Matrix &c)
 constucts a instance on the base of a deep copy of the given matrix
 ~Matrix ()
unsigned short getM () const
unsigned short getN () const
D val (unsigned short i, unsigned short j) const
Dval (unsigned short i, unsigned short j)
void set (unsigned short _m, unsigned short _n, const D *_data=0)
 sets the size of the matrix and maybe the data if given (row-wise).
void set (const D *_data)
 sets the data (row-wise).
Matrix row (unsigned short index) const
Matrix column (unsigned short index) const
int convertToBuffer (D *buffer, unsigned int len) const
 stores the content of the matrix (row-wise) in the given buffer
list< DconvertToList () const
void add (const Matrix &a, const Matrix &b)
 addition: this = a + b
void sub (const Matrix &a, const Matrix &b)
 subtraction: this = a - b
void mult (const Matrix &a, const Matrix &b)
 multiplication: this = a * b
void mult (const Matrix &a, const D &fac)
 scaling: this = a * fac
Matrix map (D(*fun)(D)) const
 maps the matrix to a new matrix with all elements mapped with the given function
Matrix mapP (void *param, D(*fun)(void *, D)) const
 like map but with additional parameter for the mapping function
Matrix multrowwise (const Matrix &factors) const
 row-wise multiplication
Matrix multcolwise (const Matrix &factors) const
 column-wise multiplication
Matrix multMT () const
 optimised multiplication of Matrix with its transposed: M * M^T
Matrix multTM () const
 optimised multiplication of transpsoed of Matrix with itself: M^T * M
D elementProduct () const
 returns the product of all elements
D elementSum () const
 returns the sum of all elements
Matrix above (const Matrix &a) const
 returns a matrix that consists of b below this
Matrixoperator= (const Matrix &c)
 deep copy
Matrix operator+ (const Matrix &sum) const
Matrix operator- (const Matrix &sum) const
Matrix operator * (const Matrix &fac) const
 matrix product
Matrix operator * (const D &fac) const
 product with scalar (double)
Matrix operator^ (int exponent) const
 special matrix potence:
Matrixoperator+= (const Matrix &c)
 performant combined assigment operators
Matrixoperator-= (const Matrix &c)
Matrixoperator *= (const Matrix &c)
Matrixoperator *= (const D &fac)
bool operator== (const Matrix &c) const
 comparison operator (compares elements with tolerance distance of COMPARE_EPS)
void copy (const Matrix &c)
 performs a deep copy of the given matrix
void toTranspose ()
 inplace transpose
void toZero ()
 inplace converts matrix to zero matrix
void toId ()
 inplace converts matrix to identity (use ^0 to get a copy version of it)
void toSum (const Matrix &a)
 inplace addition: this = this + a
void toDiff (const Matrix &a)
 inplace subtraction: this = this - a
void toMult (const D &fac)
 inplace multiplication with scalar: this = this*fac
void toExp (int exponent)
 special inplace matrix potence:
void toMap (D(*fun)(D))
 inplace mapping of matrix elements (element-wise application)
void toMapP (void *param, D(*fun)(void *, D))
 like toMap, but with an extra parameter for the mapping function.
void toMultrowwise (const Matrix &factors)
 Inplace row-wise multiplication.
void toMultcolwise (const Matrix &factors)
 Inplace column-wise multiplication.
void toAbove (const Matrix &a)
 sets the matrix a below (this) matrix

Static Public Member Functions

static Matrix map2 (D(*fun)(D, D), const Matrix &a, const Matrix &b)
 binary map operator for matrices.

Friends

ostream & operator<< (ostream &, const Matrix &)
 printing operator: output format: mxn (
row0
.


Constructor & Destructor Documentation

Matrix  )  [inline]
 

default constructor: zero matrix (0x0)

Definition at line 130 of file matrix.h.

Matrix unsigned short  _m,
unsigned short  _n,
const D _data = 0
 

constucts a matrix with the given size.

If _data is null then the matrix is filled with zeros. otherwise matrix will be filled with _data in a row-wise manner. In this case _data must be at least _m*_n elements long

Definition at line 90 of file matrix.cpp.

Matrix const Matrix c  ) 
 

constucts a instance on the base of a deep copy of the given matrix

Definition at line 85 of file matrix.cpp.

~Matrix  )  [inline]
 

Definition at line 140 of file matrix.h.


Member Function Documentation

Matrix above const Matrix a  )  const
 

returns a matrix that consists of b below this

Definition at line 383 of file matrix.cpp.

void add const Matrix a,
const Matrix b
 

addition: this = a + b

Definition at line 192 of file matrix.cpp.

Matrix column unsigned short  index  )  const
 

Returns:
column-vector(as Nx1 matrix) containing the index'th column

Definition at line 115 of file matrix.cpp.

int convertToBuffer D buffer,
unsigned int  len
const
 

stores the content of the matrix (row-wise) in the given buffer

Parameters:
buffer Buffer for storing the elements (should have the length given by len)
len Length of the provided buffer. In any case only min(len, getM()*getN()) elements are copied.
Returns:
number of actually written elements

Definition at line 138 of file matrix.cpp.

list< D > convertToList  )  const
 

Returns:
a list of the content of the matrix (row-wise)

Definition at line 147 of file matrix.cpp.

void copy const Matrix c  )  [inline]
 

performs a deep copy of the given matrix

Definition at line 277 of file matrix.h.

D elementProduct  )  const
 

returns the product of all elements

Definition at line 365 of file matrix.cpp.

D elementSum  )  const
 

returns the sum of all elements

Definition at line 374 of file matrix.cpp.

unsigned short getM  )  const [inline]
 

Returns:
number of rows

Definition at line 145 of file matrix.h.

unsigned short getN  )  const [inline]
 

Returns:
number of columns

Definition at line 147 of file matrix.h.

Matrix map D(*)(D fun  )  const
 

maps the matrix to a new matrix with all elements mapped with the given function

Definition at line 273 of file matrix.cpp.

static Matrix map2 D(*)(D, D fun,
const Matrix a,
const Matrix b
[inline, static]
 

binary map operator for matrices.

The resulting matrix consists of the function values applied to the elements of a and b. In haskell this would something like: map (uncurry . fun) $ zip a b

Definition at line 207 of file matrix.h.

Matrix mapP void *  param,
D(*)(void *, D fun
const
 

like map but with additional parameter for the mapping function

Definition at line 286 of file matrix.cpp.

void mult const Matrix a,
const D fac
 

scaling: this = a * fac

Definition at line 222 of file matrix.cpp.

void mult const Matrix a,
const Matrix b
 

multiplication: this = a * b

Definition at line 204 of file matrix.cpp.

Matrix multcolwise const Matrix factors  )  const
 

column-wise multiplication

Parameters:
factors column vector (Mx1) of factors, one for each column

Definition at line 324 of file matrix.cpp.

Matrix multMT  )  const
 

optimised multiplication of Matrix with its transposed: M * M^T

Definition at line 331 of file matrix.cpp.

Matrix multrowwise const Matrix factors  )  const
 

row-wise multiplication

Parameters:
factors column vector (Mx1) of factors, one for each row

Definition at line 318 of file matrix.cpp.

Matrix multTM  )  const
 

optimised multiplication of transpsoed of Matrix with itself: M^T * M

Definition at line 348 of file matrix.cpp.

Matrix operator * const D fac  )  const
 

product with scalar (double)

Definition at line 496 of file matrix.cpp.

Matrix operator * const Matrix fac  )  const
 

matrix product

Definition at line 490 of file matrix.cpp.

Matrix& operator *= const D fac  )  [inline]
 

Definition at line 263 of file matrix.h.

Matrix& operator *= const Matrix c  )  [inline]
 

Definition at line 258 of file matrix.h.

Matrix operator+ const Matrix sum  )  const
 

Definition at line 479 of file matrix.cpp.

Matrix& operator+= const Matrix c  )  [inline]
 

performant combined assigment operators

Definition at line 256 of file matrix.h.

Matrix operator- const Matrix sum  )  const
 

Definition at line 484 of file matrix.cpp.

Matrix& operator-= const Matrix c  )  [inline]
 

Definition at line 257 of file matrix.h.

Matrix& operator= const Matrix c  )  [inline]
 

deep copy

Definition at line 241 of file matrix.h.

bool operator== const Matrix c  )  const
 

comparison operator (compares elements with tolerance distance of COMPARE_EPS)

Definition at line 513 of file matrix.cpp.

Matrix operator^ int  exponent  )  const
 

special matrix potence:

Parameters:
exponent -1 -> inverse; 0 -> Identity Matrix; 1 -> itself; T -> Transpose

Definition at line 506 of file matrix.cpp.

Matrix row unsigned short  index  )  const
 

Returns:
row-vector(as 1xN matrix) containing the index'th row

Definition at line 109 of file matrix.cpp.

void set const D _data  ) 
 

sets the data (row-wise).

Parameters:
_data if null then matrix elements are set to zero otherwise the field MUST have the length should be getM()*getN()

Definition at line 132 of file matrix.cpp.

void set unsigned short  _m,
unsigned short  _n,
const D _data = 0
 

sets the size of the matrix and maybe the data if given (row-wise).

If data=null then the matrix is set to zero

See also:
toZero()

constructor Matrix(m,n,data)

Definition at line 125 of file matrix.cpp.

void sub const Matrix a,
const Matrix b
 

subtraction: this = a - b

Definition at line 198 of file matrix.cpp.

void toAbove const Matrix a  ) 
 

sets the matrix a below (this) matrix

Definition at line 310 of file matrix.cpp.

void toDiff const Matrix a  )  [inline]
 

inplace subtraction: this = this - a

Definition at line 294 of file matrix.h.

void toExp int  exponent  ) 
 

special inplace matrix potence:

Parameters:
exponent -1 -> inverse; (matrix MUST be SQUARE and NONZERO) 0 -> Identity Matrix; 1 -> itself; T -> Transpose

Definition at line 242 of file matrix.cpp.

void toId  ) 
 

inplace converts matrix to identity (use ^0 to get a copy version of it)

Definition at line 184 of file matrix.cpp.

void toMap D(*)(D fun  ) 
 

inplace mapping of matrix elements (element-wise application)

Definition at line 266 of file matrix.cpp.

void toMapP void *  param,
D(*)(void *, D fun
 

like toMap, but with an extra parameter for the mapping function.

Definition at line 279 of file matrix.cpp.

void toMult const D fac  ) 
 

inplace multiplication with scalar: this = this*fac

Definition at line 231 of file matrix.cpp.

void toMultcolwise const Matrix factors  ) 
 

Inplace column-wise multiplication.

Parameters:
factors column vector of factors, one for each column

Definition at line 301 of file matrix.cpp.

void toMultrowwise const Matrix factors  ) 
 

Inplace row-wise multiplication.

Parameters:
factors column vector of factors, one for each row

Definition at line 292 of file matrix.cpp.

void toSum const Matrix a  )  [inline]
 

inplace addition: this = this + a

Definition at line 287 of file matrix.h.

void toTranspose  ) 
 

inplace transpose

Definition at line 162 of file matrix.cpp.

void toZero  ) 
 

inplace converts matrix to zero matrix

Definition at line 180 of file matrix.cpp.

D& val unsigned short  i,
unsigned short  j
[inline]
 

Returns:
reference to element at position i,j (can be used as left side value)

Definition at line 155 of file matrix.h.

D val unsigned short  i,
unsigned short  j
const [inline]
 

Returns:
element at position i,j (row, column index)

Definition at line 149 of file matrix.h.


Friends And Related Function Documentation

ostream& operator<< ostream &  str,
const Matrix mat
[friend]
 

printing operator: output format: mxn (
row0
.

.rown
) where rowX is tab seperated list of values

Definition at line 527 of file matrix.cpp.


Generated on Tue Apr 4 19:05:27 2006 for Robotsystem from Robot Group Leipzig by  doxygen 1.4.5