Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
matrix.h
Go to the documentation of this file.
1 /***************************************************************************
2  matrix.h - description
3  -------------------
4  email : georg.martius@web.de
5 ***************************************************************************/
6 // provides Matrix class with convinient operators
7 // and fast inversion for nonzero square matrixes
8 //
9 /***************************************************************************/
10 
11 #ifndef MATRIX_H
12 #define MATRIX_H
13 
14 #include <string.h>
15 #include <assert.h>
16 #include <list>
17 #include <vector>
18 #include <cstdlib>
19 
20 #include <iostream>
21 
22 #include "storeable.h"
23 
24 // TODO: add doxygen section
25 
26 /**
27  * namespace for the matrix library
28  *@author Georg Martius
29  */
30 namespace matrix{
31 
32  /// integer constant for use with exp function and (^) operator to transpose the matrix
33  extern const int T;
34 
35 /// type for matrix indices
36  typedef unsigned int I;
37  /// type for matrix elements
38  typedef double D;
39 
40  class Matrix;
41  typedef std::vector<Matrix> Matrices;
42 
43 #define D_Zero 0
44 #define D_One 1
45  /** Matrix type. Type D is datatype of matrix elements,
46  * which is fixed to double.
47  * Type I is the indextype of matrix elements,
48  * which is fixed to unsigned int.
49  * There are basicly two different types of operation:
50  * Inplace operations and copy operations.
51  * Please use the latter ones unless you know what you are doing.
52  * Just in case of critical performance optimisation use the inplace
53  * operations.
54  * The most convinient way is to use the overloaded operators
55  * (like + * ...).
56  * All constructed matrices are initialized with zero elements
57  * (unless data is given).
58  * All functions perform range checks if in debug mode
59  * (i.e. if NDEBUG is not defined).
60  * Please use debug version (default) for testing
61  * @see examples/matrix/matrixexample.cpp
62  *
63  * @author Georg Martius
64  */
65  class Matrix : public Storeable {
66  public:
67  /// default constructor: zero matrix (0x0)
69  : m(0), n(0), buffersize(0), data(0) {};
70  /** constucts a matrix with the given size.
71  If _data is null then the matrix is filled with zeros.
72  otherwise matrix will be filled with _data in a row-wise manner.
73  In this case _data must be at least _m*_n elements long
74  */
75  Matrix(I _m, I _n, const D* _data=0);
76  /** constucts a matrix with the given size and fills it with the default value
77  */
78  Matrix(I _m, I _n, D def);
79  /// constucts a instance on the base of a deep copy of the given matrix
80  Matrix (const Matrix& c);
81  /// copy move constructor
82  Matrix (Matrix&& c);
83  ~Matrix() { if(data) free(data); };
84 
85  public:
86  // /////////////////// Accessors ///////////////////////////////
87  /** @return number of rows */
88  I getM() const { return m; };
89  /** @return number of columns */
90  I getN() const { return n; };
91  /// @return number number elements in the matrix (getM()*getN())
92  I size() const { return n*m; };
93 
94 
95  /** @return element at position i,j (row, column index) */
96  inline D val(I i, I j) const {
97  assert( i<m && j<n);
98  return data[i*n+j];
99  };
100  /** @return reference to element at position i,j
101  (can be used as left side value) */
102  inline D& val(I i, I j) {
103  assert( i<m && j<n);
104  return data[i*n+j];
105  };
106 
107  /** @return element at position i,j (row, column index) and 0 if out of bounds */
108  inline D valDef0(I i, I j) const {
109  if(i<m && j<n)
110  return data[i*n+j];
111  else return 0;
112  };
113 
114  /** sets the size of the matrix and maybe the data if given (row-wise).
115  If data=null then the matrix is set to zero
116  @see toZero()
117  @see constructor Matrix(m,n,data)
118  */
119  void set(I _m, I _n, const D* _data=0);
120  /** sets the data (row-wise).
121  @param _data if null then matrix elements are set to zero
122  otherwise the field MUST have the length should be getM()*getN()*/
123  void set(const D* _data);
124  /** @return row-vector(as 1xN matrix) containing the index'th row */
125  Matrix row(I index) const;
126  /** @returns submatrix (as KxN matrix)
127  containing row from startindex to endindex inclusively (K=stopindex-endindex)
128  indices can be out of bounds, they are clipped in any case
129  */
130  Matrix rows(I startindex, I endindex) const;
131  /** @returns column-vector(as Mx1 matrix) containing the index'th column */
132  Matrix column(I index) const;
133  /** @returns submatrix (as MxK matrix)
134  containing column from startindex to endindex inclusively (K=endindex-startindex)
135  indices can be out of bounds, they are clipped in any case
136  */
137  Matrix columns(I startindex, I endindex) const;
138 
139 
140  /** stores the content of the matrix (row-wise) in the given buffer
141  @param buffer Buffer for storing the elements (should have the length given by len)
142  @param len Length of the provided buffer.
143  In any case only min(len, getM()*getN()) elements are copied.
144  @return number of actually written elements
145  */
146  int convertToBuffer(D* buffer, I len) const;
147 
148  /** @return a list of the content of the matrix (row-wise)
149  */
150  std::list<D> convertToList() const;
151 
152  /// returns a pointer to the data. UNSAFE!!!
153  const D* unsafeGetData() const{return data;}
154 
155  /* STOREABLE */
156  /** stores the Matrix into the given file stream (same as write)
157  */
158  bool store(FILE* f) const;
159 
160  /** reads a Matrix from the given file stream
161  uses read (or old binary format)
162  */
163  bool restore(FILE* f);
164 
165  /** writes the Matrix into the given file stream (ascii)
166  */
167  bool write(FILE* f) const;
168 
169  /** reads a Matrix from the given file stream (ascii)
170  */
171  bool read(FILE* f, bool skipIdentifier = false);
172 
173 
174  public:
175  // ////////////////////////////////////////////////////////////////////
176  // ///////////// operations /////////////////////////////
177  // (the result of the operation is not stored in one of the operands)
178  void add(const Matrix& a, const Matrix& b); ///< addition: this = a + b
179  void add(const Matrix& a, const D& summand); /// add scalar to each element
180  void sub(const Matrix& a, const Matrix& b); ///< subtraction: this = a - b
181  void mult(const Matrix& a, const Matrix& b);///< multiplication: this = a * b
182  void mult(const Matrix& a, const D& fac);///< scaling: this = a * fac
183 
184  void exp(const Matrix& a, int exponent);///< exponent, this = a^i, @see toExp
185 
186  /// returns true if matrix is a 0x0 matrix
187  bool isNulltimesNull() const;
188 
189  /// returns true if matrix is a vector
190  bool isVector() const;
191 
192  /** bytewise comparison (compares data buffer bytewise, which implies that
193  n1*m1 == n2*m2 but not necessarily n1==n2) */
194  bool equals(const Matrix& a) const;
195 
196  /// @return true of a and this have the same size
197  bool hasSameSizeAs(const Matrix& a) const { return n==a.getN() && m==a.getM(); };
198 
199  /** calculates the pseudoinverse, depending on the shape of the matrix
200  the left or right pseudoinverse is used.
201  If the matrix has more columns than rows then we use
202  \f[A^{+} = (A^T A + \lambda \mathbb I)^{-1}A^T\f]
203  otherwise
204  \f[A^{+} = A^T(A A^T + \lambda \mathbb I)^{-1}\f]
205  */
206  Matrix pseudoInverse(const D& lambda = 1e-8) const ;
207 
208  /** calculates the secure inverse of a square matrix.
209  If singular then the pseudoinverse is used.
210  */
211  Matrix secureInverse() const;
212 
213  /** returns true if all entries are normal floating point numbers,
214  otherwise false (e.g. for nan and inf)*/
215  bool hasNormalEntries() const;
216 
217 
218  /** maps the matrix to a new matrix
219  with all elements mapped with the given function
220  */
221  Matrix map(D (*fun)(D)) const;
222  /** like map but with additional double parameter for the mapping function
223  (first argument of fun is parameter, the second is the value)*/
224  Matrix mapP(D param, D (*fun)(D, D)) const;
225  /** like map but with additional arbitrary parameter for the mapping function */
226  Matrix mapP(void* param, D (*fun)(void*, D)) const;
227 
228  // Exotic operations ///////////
229  /** binary map operator for matrices.
230  The resulting matrix consists of the function values applied to the elements of a and b.
231  In haskell this would something like: map (uncurry . fun) $ zip a b
232  */
233  static Matrix map2( D (*fun)(D,D), const Matrix& a, const Matrix& b);
234 
235  /** like map2 but with additional parameter.
236  The first argument of fun is the parameter and the second and third
237  comes from the matrix elements.
238  In haskell this would something like: map (uncurry . (fun p)) $ zip a b
239  */
240  static Matrix map2P( D param, D (*fun)(D, D,D), const Matrix& a, const Matrix& b);
241  /** like map2P but with arbitrary paramters (void*) instead of double
242  */
243  static Matrix map2P( void* param, D (*fun)(void*, D,D), const Matrix& a, const Matrix& b);
244 
245 
246 
247  /** row-wise multiplication
248  @param factors column vector (Mx1) of factors, one for each row
249  */
250  Matrix multrowwise(const Matrix& factors) const;
251  /** column-wise multiplication
252  @param factors column vector (Mx1) of factors, one for each column
253  */
254  Matrix multcolwise(const Matrix& factors) const;
255 
256  /// optimised multiplication of Matrix with its transposed: M * M^T
257  Matrix multMT() const;
258  /// optimised multiplication of transpsoed of Matrix with itself: M^T * M
259  Matrix multTM() const;
260 
261  /// returns the product of all elements (\f$ \Pi_{ij} m_{ij} \f$)
262  D elementProduct() const;
263  /// returns the sum of all elements (\f$ \sum_{ij} m_{ij} \f$)
264  D elementSum() const;
265 
266  /** returns the sum of all squares of all elements (\f$ \sum_{ij} m_{ij}^2 \f$)
267  this is also known as the square of the Frobenius norm.
268  */
269  D norm_sqr() const;
270 
271  /// returns a matrix that consists of this matrix above A (number of rows is getM + a.getM())
272  Matrix above(const Matrix& a) const ;
273  /// returns a matrix that consists of this left beside A (number of columns is getN + a.getN())
274  Matrix beside(const Matrix& a) const ;
275 
276  public: // normal binary Operators
277  /// deep copy
278  Matrix& operator = (const Matrix& c) { copy(c); return *this; }
279  /// deep copy move operator
281  /// sum of two matrices
282  Matrix operator + (const Matrix& sum) const;
283  // Matrix operator + (const D& sum) const; /// new operator (guettler)
284  /// difference of two matrices
285  Matrix operator - (const Matrix& sum) const;
286  /** matrix product*/
287  Matrix operator * (const Matrix& fac) const;
288  /** product with scalar (D) (only right side) */
289  Matrix operator * (const D& fac) const;
290  /** special matrix potence:
291  @param exponent -1 -> inverse;
292  0 -> Identity Matrix;
293  1 -> itself;
294  T -> Transpose
295  */
296  Matrix operator ^ (int exponent) const;
297  /// row-wise multiplication
298  Matrix operator & (const Matrix& b) const;
299  /// combined assigment operator (higher performance)
300  Matrix& operator += (const Matrix& c) {toSum(c); return *this; }
301  /// combined assigment operator (higher performance)
302  Matrix& operator -= (const Matrix& c) {toDiff(c); return *this; }
303  /// combined assigment operator (higher performance)
305  Matrix result;
306  result.mult(*this, c);
307  this->copy(result);
308  return *this;
309  }
310  /// combined assigment operator (higher performance)
311  Matrix& operator *= (const D& fac) {toMult(fac); return *this; }
312  /// combined assigment operator (higher performance)
313  Matrix& operator &= (const Matrix& c) {toMultrowwise(c); return *this; }
314 
315  /// comparison operator (compares elements with tolerance distance of COMPARE_EPS)
316  bool operator == (const Matrix& c) const;
317  /** printing operator:
318  output format: mxn (\n row0\n..rown \n) where rowX is tab seperated list of values
319  */
320  friend std::ostream& operator<<(std::ostream& , const Matrix&);
321 
322  public:
323  // /////////////////// inplace Operators ///////////////////////////////
324  /** performs a deep copy of the given matrix */
325  void copy(const Matrix& c){ // Deep copy
326  m=c.m; n=c.n;
327  allocate();
328  memcpy(data,c.data,m*n*sizeof(D));
329  }
330 
331  Matrix& toTranspose(); ///< inplace transpose
332  Matrix& toZero(); ///< inplace converts matrix to zero matrix
333  Matrix& toId(); ///< inplace converts matrix to identity (use ^0 to get a copy version of it)
334  /// inplace addition: this = this + a
335  Matrix& toSum(const Matrix& a);
336  /// inplace addition: this = this + a, where a is a scalar
337  Matrix& toSum(const D& sum);
338 
339  /// inplace subtraction: this = this - a
340  Matrix& toDiff(const Matrix& a);
341 
342  /// inplace multiplication: this = this * a
343  Matrix& toMult(const Matrix& a);
344  /// inplace multiplication with scalar: this = this*fac
345  Matrix& toMult(const D& fac);
346 
347  /** special inplace matrix power:
348  @param exponent -1 -> inverse; (matrix MUST be SQUARE and NONZERO)
349  0 -> Identity Matrix;
350  1 -> itself;
351  n -> n-th power;
352  T -> Transpose
353  */
354  Matrix& toExp(int exponent);
355  /** inplace mapping of matrix elements (element-wise application) */
356  Matrix& toMap(D (*fun)(D));
357  /** like toMap, but with an extra double parameter for the mapping function. */
358  Matrix& toMapP(D param, D (*fun)(D, D));
359  /** like toMap, but with an extra arbitrary parameter for the mapping function. */
360  Matrix& toMapP(void* param, D (*fun)(void*, D));
361 
362  /** like toMap, but with using 2 matrices */
363  Matrix& toMap2(D (*fun)(D,D), const Matrix& b);
364 
365  /** like toMap2, but with additional parameter */
366  Matrix& toMap2P( D param, D (*fun)(D, D,D), const Matrix& b);
367  /** like toMap2P, but with arbitrary parameter */
368  Matrix& toMap2P( void* param, D (*fun)(void*, D,D), const Matrix& b);
369 
370  // Exotic operations
371  /** Inplace row-wise multiplication
372  @param factors column vector of factors, one for each row
373  */
374  Matrix& toMultrowwise(const Matrix& factors);
375  /** Inplace column-wise multiplication
376  @param factors column vector of factors, one for each column
377  */
378  Matrix& toMultcolwise(const Matrix& factors);
379 
380  /// sets the matrix a below this matrix
381  Matrix& toAbove(const Matrix& a);
382  /// sets the matrix a right beside this matrix
383  Matrix& toBeside(const Matrix& a);
384 
385  /// sorts the matrix (rowwise)
386  Matrix& toSort();
387 
388  /** reshapes the matrix without destroying the data.
389  Remember: The data is stored rowwise.
390 
391  Only shrinking is allowed i.e. m*n must be lower or equal to getM()*getN()
392  */
393  Matrix& reshape(I m, I n);
394 
395  /// adds the given value to the diagonal
396  Matrix& pluslambdaI(double lambda = 1e-8);
397 
398  /** adds one or more rows to the existing matrix and fills it with the given data
399  *
400  * same as toAbove(Matrix(numberRows,getN(),data))
401  * @param numberRows number of rows to add (this extends m)
402  * @param _data data to add
403  * @return the address of the matrix itself
404  */
405  Matrix& addRows(I numberRows, const D* _data=0);
406 
407  /**
408  * same as toAbove(dataMatrix)
409  * @param numberRows number of rows to add (unused)
410  * @param dataMatrix matrix which contains the data of the new rows
411  * @return the address of the matrix itself
412  */
413  Matrix& addRows(I numberRows, const Matrix& dataMatrix);
414 
415  /** adds one or more columns to the existing matrix
416  * same as toBeside(Matrix(getM, numberColumns, _data))
417  * @see toBeside()
418  * @param numberColumns number of columns to add (this extends n)
419  * @param _data data to add
420  * @return the address of the matrix itself
421  */
422  Matrix& addColumns(I numberColumns, const D* _data=0);
423 
424  /**
425  * same as toBeside(dataMatrix)
426  * @see toBeside()
427  * @param numberColumns number of columns to add (unused)
428  * @param dataMatrix matrix which contains the data of the new rows
429  * @return the address of the matrix itself
430  */
431  Matrix& addColumns(I numberColumns, const Matrix& dataMatrix);
432 
433 
434  /** removes one or more rows from the end if an existing matrix (inplace!),
435  same as reshape(getM()-numberRows, getN());
436  * @param numberRows number of rows to remove (from the end) (this reduces m)
437  * @return the address of the matrix itself
438  */
439  Matrix& removeRows(I numberRows);
440 
441  /** removes one or more columns from the end of the existing matrix (inplace!)
442  * resets the size of the matrix and deletes the appropiate data.
443  * @param numberColumns number of columns to remove (this reduces n)
444  * @return the address of the matrix itself
445  */
446  Matrix& removeColumns(I numberColumns);
447 
448  private:
449  // NOTE: buffersize determines available memory storage.
450  // m and n define the actual size
451  I m, n;
452  I buffersize; // max number if elements
453  D* data; // where the data contents of the matrix are stored
454 
455 
456  private: // internals
457  void allocate(); //internal allocation
458  /*inplace matrix invertation:
459  Matrix must be SQARE, in addition, all DIAGONAL ELEMENTS MUST BE NONZERO
460  (positive definite)
461  */
462 
463  void invertnonzero();
464  void invert3x3();
465  void invert2x2();
466  };
467 
468 } // namespace matrix
469 #endif
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