Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef MATRIX_H
00023 #define MATRIX_H
00024
00025 #include <stdio.h>
00026 #include <string.h>
00027 #include <stdlib.h>
00028 #include <iostream>
00029 #include <vector>
00030
00031 #ifndef _MSC_VER
00032 #include <stdint.h>
00033 #else
00034 typedef __int8 int8_t;
00035 typedef __int16 int16_t;
00036 typedef __int32 int32_t;
00037 typedef __int64 int64_t;
00038 typedef unsigned __int8 uint8_t;
00039 typedef unsigned __int16 uint16_t;
00040 typedef unsigned __int32 uint32_t;
00041 typedef unsigned __int64 uint64_t;
00042 #endif
00043
00044 #define endll endl << endl // double end line definition
00045
00046 typedef double FLOAT;
00047
00048
00049 class Matrix {
00050
00051 public:
00052
00053
00054 Matrix ();
00055 Matrix (const int32_t m,const int32_t n);
00056 Matrix (const int32_t m,const int32_t n,const FLOAT* val_);
00057 Matrix (const Matrix &M);
00058 ~Matrix ();
00059
00060
00061 Matrix& operator= (const Matrix &M);
00062
00063
00064 void getData(FLOAT* val_,int32_t i1=0,int32_t j1=0,int32_t i2=-1,int32_t j2=-1);
00065
00066
00067 Matrix getMat(int32_t i1,int32_t j1,int32_t i2=-1,int32_t j2=-1);
00068 void setMat(const Matrix &M,const int32_t i,const int32_t j);
00069
00070
00071 void setVal(FLOAT s,int32_t i1=0,int32_t j1=0,int32_t i2=-1,int32_t j2=-1);
00072
00073
00074 void setDiag(FLOAT s,int32_t i1=0,int32_t i2=-1);
00075
00076
00077 void zero();
00078
00079
00080 Matrix extractCols (std::vector<int> idx);
00081
00082
00083 static Matrix eye (const int32_t m);
00084 void eye ();
00085
00086
00087 static Matrix diag(const Matrix &M);
00088
00089
00090 static Matrix reshape(const Matrix &M,int32_t m,int32_t n);
00091
00092
00093 static Matrix rotMatX(const FLOAT &angle);
00094 static Matrix rotMatY(const FLOAT &angle);
00095 static Matrix rotMatZ(const FLOAT &angle);
00096
00097
00098 Matrix operator+ (const Matrix &M);
00099 Matrix operator- (const Matrix &M);
00100 Matrix operator* (const Matrix &M);
00101 Matrix operator* (const FLOAT &s);
00102 Matrix operator/ (const Matrix &M);
00103 Matrix operator/ (const FLOAT &s);
00104 Matrix operator- ();
00105 Matrix operator~ ();
00106 FLOAT l2norm ();
00107 FLOAT mean ();
00108
00109
00110 static Matrix cross (const Matrix &a, const Matrix &b);
00111 static Matrix inv (const Matrix &M);
00112 bool inv ();
00113 FLOAT det ();
00114 bool solve (const Matrix &M,FLOAT eps=1e-20);
00115 bool lu(int32_t *idx, FLOAT &d, FLOAT eps=1e-20);
00116 void svd(Matrix &U,Matrix &W,Matrix &V);
00117
00118
00119 friend std::ostream& operator<< (std::ostream& out,const Matrix& M);
00120
00121
00122 FLOAT **val;
00123 int32_t m,n;
00124
00125 private:
00126
00127 void allocateMemory (const int32_t m_,const int32_t n_);
00128 void releaseMemory ();
00129 inline FLOAT pythag(FLOAT a,FLOAT b);
00130
00131 };
00132
00133 #endif // MATRIX_H