36 typedef unsigned int I;
41 typedef std::vector<Matrix>
Matrices;
69 : m(0), n(0), buffersize(0), data(0) {};
119 void set(
I _m,
I _n,
const D* _data=0);
123 void set(
const D* _data);
158 bool store(FILE* f)
const;
167 bool write(FILE* f)
const;
171 bool read(FILE* f,
bool skipIdentifier =
false);
306 result.
mult(*
this, c);
328 memcpy(data,c.data,m*n*
sizeof(
D));
463 void invertnonzero();
Matrix type.
Definition: matrix.h:65
Matrix & toAbove(const Matrix &a)
sets the matrix a below this matrix
Definition: matrix.cpp:565
D elementSum() const
returns the sum of all elements ( )
Definition: matrix.cpp:681
Interface for objects, that can be stored and restored to/from a file stream (binary).
Definition: storeable.h:33
std::list< D > convertToList() const
Definition: matrix.cpp:169
Matrix & toTranspose()
inplace transpose
Definition: matrix.cpp:255
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 para...
Definition: matrix.cpp:487
I getM() const
Definition: matrix.h:88
Matrix row(I index) const
Definition: matrix.cpp:110
Matrix & toMapP(D param, D(*fun)(D, D))
like toMap, but with an extra double parameter for the mapping function.
Definition: matrix.cpp:472
void sub(const Matrix &a, const Matrix &b)
add scalar to each element
Definition: matrix.cpp:318
Matrix multcolwise(const Matrix &factors) const
column-wise multiplication
Definition: matrix.cpp:630
bool hasSameSizeAs(const Matrix &a) const
Definition: matrix.h:197
Matrix & toMap2P(D param, D(*fun)(D, D, D), const Matrix &b)
like toMap2, but with additional parameter
Definition: matrix.cpp:515
Matrix & operator+=(const Matrix &c)
combined assigment operator (higher performance)
Definition: matrix.h:300
void mult(const Matrix &a, const Matrix &b)
multiplication: this = a * b
Definition: matrix.cpp:332
Matrix()
default constructor: zero matrix (0x0)
Definition: matrix.h:68
Matrix beside(const Matrix &a) const
returns a matrix that consists of this left beside A (number of columns is getN + a...
Definition: matrix.cpp:708
I size() const
Definition: matrix.h:92
Matrix & operator&=(const Matrix &c)
combined assigment operator (higher performance)
Definition: matrix.h:313
Matrix & toMult(const Matrix &a)
inplace multiplication: this = this * a
Definition: matrix.cpp:359
D val(I i, I j) const
Definition: matrix.h:96
Matrix & toMap(D(*fun)(D))
inplace mapping of matrix elements (element-wise application)
Definition: matrix.cpp:458
Matrix operator-(const Matrix &sum) const
difference of two matrices
Definition: matrix.cpp:853
Matrix & toSum(const Matrix &a)
inplace addition: this = this + a
Definition: matrix.cpp:303
Matrix operator*(const Matrix &fac) const
matrix product
Definition: matrix.cpp:860
Matrix column(I index) const
Definition: matrix.cpp:127
Matrix & toDiff(const Matrix &a)
inplace subtraction: this = this - a
Definition: matrix.cpp:324
~Matrix()
Definition: matrix.h:83
void add(const Matrix &a, const Matrix &b)
addition: this = a + b
Definition: matrix.cpp:288
D & val(I i, I j)
Definition: matrix.h:102
Matrix & pluslambdaI(double lambda=1e-8)
adds the given value to the diagonal
Definition: matrix.cpp:615
static Matrix map2P(D param, D(*fun)(D, D, D), const Matrix &a, const Matrix &b)
like map2 but with additional parameter.
Definition: matrix.cpp:533
Matrix & toZero()
inplace converts matrix to zero matrix
Definition: matrix.cpp:274
Matrix operator+(const Matrix &sum) const
sum of two matrices
Definition: matrix.cpp:847
unsigned int I
type for matrix indices
Definition: matrix.h:36
void copy(const Matrix &c)
performs a deep copy of the given matrix
Definition: matrix.h:325
bool restore(FILE *f)
reads a Matrix from the given file stream uses read (or old binary format)
Definition: matrix.cpp:221
Matrix & addRows(I numberRows, const D *_data=0)
adds one or more rows to the existing matrix and fills it with the given data
Definition: matrix.cpp:717
I getN() const
Definition: matrix.h:90
int convertToBuffer(D *buffer, I len) const
stores the content of the matrix (row-wise) in the given buffer
Definition: matrix.cpp:160
Matrix & addColumns(I numberColumns, const D *_data=0)
adds one or more columns to the existing matrix same as toBeside(Matrix(getM, numberColumns, _data))
Definition: matrix.cpp:728
Matrix pseudoInverse(const D &lambda=1e-8) const
calculates the pseudoinverse, depending on the shape of the matrix the left or right pseudoinverse is...
Definition: matrix.cpp:436
bool write(FILE *f) const
writes the Matrix into the given file stream (ascii)
Definition: matrix.cpp:179
bool read(FILE *f, bool skipIdentifier=false)
reads a Matrix from the given file stream (ascii)
Definition: matrix.cpp:190
Matrix & removeRows(I numberRows)
removes one or more rows from the end if an existing matrix (inplace!), same as reshape(getM()-number...
Definition: matrix.cpp:736
D valDef0(I i, I j) const
Definition: matrix.h:108
Matrix above(const Matrix &a) const
returns a matrix that consists of this matrix above A (number of rows is getM + a.getM())
Definition: matrix.cpp:700
Matrix & operator*=(const Matrix &c)
combined assigment operator (higher performance)
Definition: matrix.h:304
bool isNulltimesNull() const
returns true if matrix is a 0x0 matrix
Definition: matrix.cpp:80
void exp(const Matrix &a, int exponent)
exponent, this = a^i,
Definition: matrix.cpp:375
Matrix multTM() const
optimised multiplication of transpsoed of Matrix with itself: M^T * M
Definition: matrix.cpp:654
Matrix rows(I startindex, I endindex) const
Definition: matrix.cpp:116
bool store(FILE *f) const
stores the Matrix into the given file stream (same as write)
Definition: matrix.cpp:208
Matrix & removeColumns(I numberColumns)
removes one or more columns from the end of the existing matrix (inplace!) resets the size of the mat...
Definition: matrix.cpp:741
Matrix map(D(*fun)(D)) const
maps the matrix to a new matrix with all elements mapped with the given function
Definition: matrix.cpp:466
D elementProduct() const
returns the product of all elements ( )
Definition: matrix.cpp:671
static Matrix map2(D(*fun)(D, D), const Matrix &a, const Matrix &b)
binary map operator for matrices.
Definition: matrix.cpp:509
Matrix & reshape(I m, I n)
reshapes the matrix without destroying the data.
Definition: matrix.cpp:607
void set(I _m, I _n, const D *_data=0)
sets the size of the matrix and maybe the data if given (row-wise).
Definition: matrix.cpp:147
Matrix & toMultrowwise(const Matrix &factors)
Inplace row-wise multiplication.
Definition: matrix.cpp:545
std::vector< Matrix > Matrices
Definition: matrix.h:40
Matrix & toId()
inplace converts matrix to identity (use ^0 to get a copy version of it)
Definition: matrix.cpp:279
Matrix multMT() const
optimised multiplication of Matrix with its transposed: M * M^T
Definition: matrix.cpp:637
const int T
integer constant for use with exp function and (^) operator to transpose the matrix ...
Definition: matrix.cpp:21
Matrix multrowwise(const Matrix &factors) const
row-wise multiplication
Definition: matrix.cpp:624
Matrix & toSort()
sorts the matrix (rowwise)
Definition: matrix.cpp:602
bool equals(const Matrix &a) const
bytewise comparison (compares data buffer bytewise, which implies that n1*m1 == n2*m2 but not necessa...
Definition: matrix.cpp:104
bool hasNormalEntries() const
returns true if all entries are normal floating point numbers, otherwise false (e.g.
Definition: matrix.cpp:417
Matrix & toBeside(const Matrix &a)
sets the matrix a right beside this matrix
Definition: matrix.cpp:573
Matrix secureInverse() const
calculates the secure inverse of a square matrix.
Definition: matrix.cpp:424
Matrix & toMap2(D(*fun)(D, D), const Matrix &b)
like toMap, but with using 2 matrices
Definition: matrix.cpp:500
Matrix operator^(int exponent) const
special matrix potence:
Definition: matrix.cpp:876
Matrix columns(I startindex, I endindex) const
Definition: matrix.cpp:136
Matrix & toExp(int exponent)
special inplace matrix power:
Definition: matrix.cpp:385
Matrix & operator=(const Matrix &c)
deep copy
Definition: matrix.h:278
bool operator==(const Matrix &c) const
comparison operator (compares elements with tolerance distance of COMPARE_EPS)
Definition: matrix.cpp:889
double D
type for matrix elements
Definition: matrix.h:38
int c
Definition: hexapod.cpp:56
friend std::ostream & operator<<(std::ostream &, const Matrix &)
printing operator: output format: mxn ( row0 ..rown ) where rowX is tab seperated list of values ...
Definition: matrix.cpp:903
Matrix & operator-=(const Matrix &c)
combined assigment operator (higher performance)
Definition: matrix.h:302
Matrix operator&(const Matrix &b) const
row-wise multiplication
Definition: matrix.cpp:883
const D * unsafeGetData() const
returns a pointer to the data. UNSAFE!!!
Definition: matrix.h:153
bool isVector() const
returns true if matrix is a vector
Definition: matrix.cpp:85
Matrix & toMultcolwise(const Matrix &factors)
Inplace column-wise multiplication.
Definition: matrix.cpp:555
D norm_sqr() const
returns the sum of all squares of all elements ( ) this is also known as the square of the Frobenius ...
Definition: matrix.cpp:690