Robot Simulator of the Robotics Group for Self-Organization of Control
0.8.0
|
#include <matrix.h>
Public Member Functions | |
Matrix () | |
default constructor: zero matrix (0x0) More... | |
Matrix (I _m, I _n, const D *_data=0) | |
constucts a matrix with the given size. More... | |
Matrix (I _m, I _n, D def) | |
constucts a matrix with the given size and fills it with the default value More... | |
Matrix (const Matrix &c) | |
constucts a instance on the base of a deep copy of the given matrix More... | |
Matrix (Matrix &&c) | |
copy move constructor More... | |
~Matrix () | |
I | getM () const |
I | getN () const |
I | size () const |
D | val (I i, I j) const |
D & | val (I i, I j) |
D | valDef0 (I i, I j) const |
void | set (I _m, I _n, const D *_data=0) |
sets the size of the matrix and maybe the data if given (row-wise). More... | |
void | set (const D *_data) |
sets the data (row-wise). More... | |
Matrix | row (I index) const |
Matrix | rows (I startindex, I endindex) const |
Matrix | column (I index) const |
Matrix | columns (I startindex, I endindex) const |
int | convertToBuffer (D *buffer, I len) const |
stores the content of the matrix (row-wise) in the given buffer More... | |
std::list< D > | convertToList () const |
const D * | unsafeGetData () const |
returns a pointer to the data. UNSAFE!!! More... | |
bool | store (FILE *f) const |
stores the Matrix into the given file stream (same as write) More... | |
bool | restore (FILE *f) |
reads a Matrix from the given file stream uses read (or old binary format) More... | |
bool | write (FILE *f) const |
writes the Matrix into the given file stream (ascii) More... | |
bool | read (FILE *f, bool skipIdentifier=false) |
reads a Matrix from the given file stream (ascii) More... | |
void | add (const Matrix &a, const Matrix &b) |
addition: this = a + b More... | |
void | add (const Matrix &a, const D &summand) |
void | sub (const Matrix &a, const Matrix &b) |
add scalar to each element More... | |
void | mult (const Matrix &a, const Matrix &b) |
multiplication: this = a * b More... | |
void | mult (const Matrix &a, const D &fac) |
scaling: this = a * fac More... | |
void | exp (const Matrix &a, int exponent) |
exponent, this = a^i, More... | |
bool | isNulltimesNull () const |
returns true if matrix is a 0x0 matrix More... | |
bool | isVector () const |
returns true if matrix is a vector More... | |
bool | equals (const Matrix &a) const |
bytewise comparison (compares data buffer bytewise, which implies that n1*m1 == n2*m2 but not necessarily n1==n2) More... | |
bool | hasSameSizeAs (const Matrix &a) const |
Matrix | pseudoInverse (const D &lambda=1e-8) const |
calculates the pseudoinverse, depending on the shape of the matrix the left or right pseudoinverse is used. More... | |
Matrix | secureInverse () const |
calculates the secure inverse of a square matrix. More... | |
bool | hasNormalEntries () const |
returns true if all entries are normal floating point numbers, otherwise false (e.g. More... | |
Matrix | map (D(*fun)(D)) const |
maps the matrix to a new matrix with all elements mapped with the given function More... | |
Matrix | mapP (D param, D(*fun)(D, D)) const |
like map but with additional double parameter for the mapping function (first argument of fun is parameter, the second is the value) More... | |
Matrix | mapP (void *param, D(*fun)(void *, D)) const |
like map but with additional arbitrary parameter for the mapping function More... | |
Matrix | multrowwise (const Matrix &factors) const |
row-wise multiplication More... | |
Matrix | multcolwise (const Matrix &factors) const |
column-wise multiplication More... | |
Matrix | multMT () const |
optimised multiplication of Matrix with its transposed: M * M^T More... | |
Matrix | multTM () const |
optimised multiplication of transpsoed of Matrix with itself: M^T * M More... | |
D | elementProduct () const |
returns the product of all elements ( ) More... | |
D | elementSum () const |
returns the sum of all elements ( ) More... | |
D | norm_sqr () const |
returns the sum of all squares of all elements ( ) this is also known as the square of the Frobenius norm. More... | |
Matrix | above (const Matrix &a) const |
returns a matrix that consists of this matrix above A (number of rows is getM + a.getM()) More... | |
Matrix | beside (const Matrix &a) const |
returns a matrix that consists of this left beside A (number of columns is getN + a.getN()) More... | |
Matrix & | operator= (const Matrix &c) |
deep copy More... | |
Matrix & | operator= (Matrix &&c) |
deep copy move operator More... | |
Matrix | operator+ (const Matrix &sum) const |
sum of two matrices More... | |
Matrix | operator- (const Matrix &sum) const |
difference of two matrices More... | |
Matrix | operator* (const Matrix &fac) const |
matrix product More... | |
Matrix | operator* (const D &fac) const |
product with scalar (D) (only right side) More... | |
Matrix | operator^ (int exponent) const |
special matrix potence: More... | |
Matrix | operator& (const Matrix &b) const |
row-wise multiplication More... | |
Matrix & | operator+= (const Matrix &c) |
combined assigment operator (higher performance) More... | |
Matrix & | operator-= (const Matrix &c) |
combined assigment operator (higher performance) More... | |
Matrix & | operator*= (const Matrix &c) |
combined assigment operator (higher performance) More... | |
Matrix & | operator*= (const D &fac) |
combined assigment operator (higher performance) More... | |
Matrix & | operator&= (const Matrix &c) |
combined assigment operator (higher performance) More... | |
bool | operator== (const Matrix &c) const |
comparison operator (compares elements with tolerance distance of COMPARE_EPS) More... | |
void | copy (const Matrix &c) |
performs a deep copy of the given matrix More... | |
Matrix & | toTranspose () |
inplace transpose More... | |
Matrix & | toZero () |
inplace converts matrix to zero matrix More... | |
Matrix & | toId () |
inplace converts matrix to identity (use ^0 to get a copy version of it) More... | |
Matrix & | toSum (const Matrix &a) |
inplace addition: this = this + a More... | |
Matrix & | toSum (const D &sum) |
inplace addition: this = this + a, where a is a scalar More... | |
Matrix & | toDiff (const Matrix &a) |
inplace subtraction: this = this - a More... | |
Matrix & | toMult (const Matrix &a) |
inplace multiplication: this = this * a More... | |
Matrix & | toMult (const D &fac) |
inplace multiplication with scalar: this = this*fac More... | |
Matrix & | toExp (int exponent) |
special inplace matrix power: More... | |
Matrix & | toMap (D(*fun)(D)) |
inplace mapping of matrix elements (element-wise application) More... | |
Matrix & | toMapP (D param, D(*fun)(D, D)) |
like toMap, but with an extra double parameter for the mapping function. More... | |
Matrix & | toMapP (void *param, D(*fun)(void *, D)) |
like toMap, but with an extra arbitrary parameter for the mapping function. More... | |
Matrix & | toMap2 (D(*fun)(D, D), const Matrix &b) |
like toMap, but with using 2 matrices More... | |
Matrix & | toMap2P (D param, D(*fun)(D, D, D), const Matrix &b) |
like toMap2, but with additional parameter More... | |
Matrix & | toMap2P (void *param, D(*fun)(void *, D, D), const Matrix &b) |
like toMap2P, but with arbitrary parameter More... | |
Matrix & | toMultrowwise (const Matrix &factors) |
Inplace row-wise multiplication. More... | |
Matrix & | toMultcolwise (const Matrix &factors) |
Inplace column-wise multiplication. More... | |
Matrix & | toAbove (const Matrix &a) |
sets the matrix a below this matrix More... | |
Matrix & | toBeside (const Matrix &a) |
sets the matrix a right beside this matrix More... | |
Matrix & | toSort () |
sorts the matrix (rowwise) More... | |
Matrix & | reshape (I m, I n) |
reshapes the matrix without destroying the data. More... | |
Matrix & | pluslambdaI (double lambda=1e-8) |
adds the given value to the diagonal More... | |
Matrix & | addRows (I numberRows, const D *_data=0) |
adds one or more rows to the existing matrix and fills it with the given data More... | |
Matrix & | addRows (I numberRows, const Matrix &dataMatrix) |
same as toAbove(dataMatrix) More... | |
Matrix & | addColumns (I numberColumns, const D *_data=0) |
adds one or more columns to the existing matrix same as toBeside(Matrix(getM, numberColumns, _data)) More... | |
Matrix & | addColumns (I numberColumns, const Matrix &dataMatrix) |
same as toBeside(dataMatrix) More... | |
Matrix & | removeRows (I numberRows) |
removes one or more rows from the end if an existing matrix (inplace!), same as reshape(getM()-numberRows, getN()); More... | |
Matrix & | removeColumns (I numberColumns) |
removes one or more columns from the end of the existing matrix (inplace!) resets the size of the matrix and deletes the appropiate data. More... | |
Public Member Functions inherited from Storeable | |
virtual | ~Storeable () |
bool | storeToFile (const char *filename) const |
Provided for convenience. More... | |
bool | restoreFromFile (const char *filename) |
Provided for convenience. More... | |
Static Public Member Functions | |
static Matrix | map2 (D(*fun)(D, D), const Matrix &a, const Matrix &b) |
binary map operator for matrices. More... | |
static Matrix | map2P (D param, D(*fun)(D, D, D), const Matrix &a, const Matrix &b) |
like map2 but with additional parameter. More... | |
static Matrix | map2P (void *param, D(*fun)(void *, D, D), const Matrix &a, const Matrix &b) |
like map2P but with arbitrary paramters (void*) instead of double More... | |
Friends | |
std::ostream & | operator<< (std::ostream &, const Matrix &) |
printing operator: output format: mxn ( row0 ..rown ) where rowX is tab seperated list of values More... | |
Matrix type.
Type D is datatype of matrix elements, which is fixed to double. Type I is the indextype of matrix elements, which is fixed to unsigned int. 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 initialized with zero elements (unless data is given). All functions perform range checks if in debug mode (i.e. if NDEBUG is not defined). Please use debug version (default) for testing
|
inline |
default constructor: zero matrix (0x0)
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
constucts a matrix with the given size and fills it with the default value
|
inline |
returns a matrix that consists of this matrix above A (number of rows is getM + a.getM())
returns a matrix that consists of b below this
adds one or more columns to the existing matrix same as toBeside(Matrix(getM, numberColumns, _data))
numberColumns | number of columns to add (this extends n) |
_data | data to add |
same as toBeside(dataMatrix)
numberColumns | number of columns to add (unused) |
dataMatrix | matrix which contains the data of the new rows |
adds one or more rows to the existing matrix and fills it with the given data
same as toAbove(Matrix(numberRows,getN(),data))
numberRows | number of rows to add (this extends m) |
_data | data to add |
same as toAbove(dataMatrix)
numberRows | number of rows to add (unused) |
dataMatrix | matrix which contains the data of the new rows |
returns a matrix that consists of this left beside A (number of columns is getN + a.getN())
returns a matrix that consists of b right beside this
stores the content of the matrix (row-wise) in the given buffer
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. |
std::list< D > convertToList | ( | ) | const |
|
inline |
performs a deep copy of the given matrix
D elementProduct | ( | ) | const |
returns the product of all elements ( )
returns the product of all elements
D elementSum | ( | ) | const |
returns the sum of all elements ( )
returns the sum of all elements
bool equals | ( | const Matrix & | a | ) | const |
bytewise comparison (compares data buffer bytewise, which implies that n1*m1 == n2*m2 but not necessarily n1==n2)
|
inline |
|
inline |
bool hasNormalEntries | ( | ) | const |
returns true if all entries are normal floating point numbers, otherwise false (e.g.
for nan and inf)
|
inline |
bool isNulltimesNull | ( | ) | const |
returns true if matrix is a 0x0 matrix
ACCESSORS ///////////////////////////////////////////////////////////////.
returns true if matrix is a 0x0 matrix
bool isVector | ( | ) | const |
returns true if matrix is a vector
maps the matrix to a new matrix with all elements mapped with the given function
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
like map2 but with additional parameter.
The first argument of fun is the parameter and the second and third comes from the matrix elements. In haskell this would something like: map (uncurry . (fun p)) $ zip a b
like map2P but with arbitrary paramters (void*) instead of double
like map but with additional double parameter for the mapping function (first argument of fun is parameter, the second is the value)
like map but with additional arbitrary parameter for the mapping function
column-wise multiplication
factors | column vector (Mx1) of factors, one for each column |
row-wise multiplication
factors | column vector (Mx1) of factors, one for each row |
D norm_sqr | ( | ) | const |
returns the sum of all squares of all elements ( ) this is also known as the square of the Frobenius norm.
returns the sum of all elements
product with scalar (D) (only right side)
product with scalar (double)
bool operator== | ( | const Matrix & | c | ) | const |
comparison operator (compares elements with tolerance distance of COMPARE_EPS)
Matrix operator^ | ( | int | exponent | ) | const |
Matrix & pluslambdaI | ( | double | lambda = 1e-8 | ) |
adds the given value to the diagonal
calculates the pseudoinverse, depending on the shape of the matrix the left or right pseudoinverse is used.
If the matrix has more columns than rows then we use
otherwise
bool read | ( | FILE * | f, |
bool | skipIdentifier = false |
||
) |
reads a Matrix from the given file stream (ascii)
removes one or more columns from the end of the existing matrix (inplace!) resets the size of the matrix and deletes the appropiate data.
numberColumns | number of columns to remove (this reduces n) |
reshapes the matrix without destroying the data.
Remember: The data is stored rowwise.
Only shrinking is allowed i.e. m*n must be lower or equal to getM()*getN()
|
virtual |
Matrix secureInverse | ( | ) | const |
calculates the secure inverse of a square matrix.
If singular then the pseudoinverse is used.
sets the size of the matrix and maybe the data if given (row-wise).
If data=null then the matrix is set to zero
void set | ( | const D * | _data | ) |
sets the data (row-wise).
_data | if null then matrix elements are set to zero otherwise the field MUST have the length should be getM()*getN() |
|
virtual |
add scalar to each element
subtraction: this = a - b
Matrix & toExp | ( | int | exponent | ) |
special inplace matrix power:
exponent | -1 -> inverse; (matrix MUST be SQUARE and NONZERO) 0 -> Identity Matrix; 1 -> itself; n -> n-th power; T -> Transpose |
Matrix & toId | ( | ) |
inplace converts matrix to identity (use ^0 to get a copy version of it)
like toMap2, but with additional parameter
like toMap2P, but with arbitrary parameter
like toMap, but with an extra double parameter for the mapping function.
like toMap, but with an extra arbitrary parameter for the mapping function.
Inplace column-wise multiplication.
factors | column vector of factors, one for each column |
Inplace row-wise multiplication.
factors | column vector of factors, one for each row |
Matrix & toSort | ( | ) |
sorts the matrix (rowwise)
Matrix & toTranspose | ( | ) |
inplace transpose
Matrix & toZero | ( | ) |
inplace converts matrix to zero matrix
|
inline |
returns a pointer to the data. UNSAFE!!!
bool write | ( | FILE * | f | ) | const |
writes the Matrix into the given file stream (ascii)
|
friend |
printing operator: output format: mxn (
row0
..rown
) where rowX is tab seperated list of values