TMatrix.h
Go to the documentation of this file.00001 #ifndef TMATRIX_H
00002 #define TMATRIX_H
00003
00004
00005
00011
00012
00013
00014
00015
00016 #include <vector>
00017 #include "TVector.h"
00018
00019
00020
00025
00026 #ifndef TMATRIX_DECLARACION
00027 #define TMATRIX_DECLARACION
00028
00029
00031 struct tPos
00032 {
00033 unsigned int row;
00034 unsigned int col;
00035
00036 tPos(unsigned int row_, unsigned int col_): row(row_), col(col_)
00037 { }
00038 };
00039
00040
00041
00042 template <class TRing>
00043 class BlockMatrix;
00044
00045
00046
00052 template <class TRing>
00053 class TMatrix
00054 {
00055 public:
00056 typedef typename TRing::ElementType TNum;
00057 typedef typename TRing::ElementType ElementType;
00058 typedef TRing RingType;
00059
00060
00061
00062 protected:
00063
00064
00065 unsigned int rows_m;
00066 unsigned int cols_m;
00067
00068 const TRing* ring;
00069
00070
00071 TNum* data;
00072 string name;
00073
00074 TNum** pcolumn;
00075
00076
00077 public:
00078
00081 TMatrix(unsigned int rowNum, unsigned int colNum, const TRing* _ring, std::string name="nonameMatrix");
00082
00083 TMatrix( const TMatrix& mat);
00084
00085 template <class _istream>
00086 TMatrix( const TRing* _ring, _istream& sstream, std::string _name="");
00087
00088 TMatrix(std::string strMatrix, const TRing* _ring, std::string _name="nonameMatrix");
00089
00090 template <class TemplateMatrix>
00091 TMatrix(const TemplateMatrix &mat, const TRing* _ring);
00092
00093
00094 TMatrix(unsigned int _zeilen, unsigned int _spalten,
00095 const TRing* _ring, TVector<TRing> & vec,std::string _name ="" );
00096
00102 void fillZero();
00103 void randomInit(long * _pRandomSeed);
00109 size_t getSize() const;
00110 unsigned int getColNum() const {return cols_m;};
00111 unsigned int getRowNum() const {return rows_m;};
00112
00113
00114 std::string getName() const { return name; };
00115 void setName(std::string _name) { name=_name; }
00116 const TRing* getRing() const { return ring; }
00122 void checkBounds(unsigned int _row, unsigned int _col) const;
00129 inline void setVal (const unsigned int _row,const unsigned int _col,const TNum z);
00130
00131 TNum getVal (const unsigned int _row,const unsigned int _col) const;
00132
00133 const TNum& getConstValRef (const unsigned int _row,const unsigned int _col) const;
00134
00135 inline TNum& getValRef (const unsigned int _row,const unsigned int _col);
00136
00137 inline TNum* getValAddr (const unsigned int _row,const unsigned int _col);
00138
00139 TNum& getRowRef(unsigned int _row);
00145 TNum* getRow (unsigned int _row) const;
00146
00147 TNum* getCol (unsigned int _col) const;
00148
00149 TVector<TRing>* convertToVector () const;
00150
00151
00152 TVector<TRing> * getRowAsVector(unsigned int _row ) const;
00153 TVector<TRing> * getColAsVector(unsigned int _col ) const;
00154
00155 TNum* getDiag() const;
00156
00157 TVector<TRing>* getTrace() const;
00163 bool isZero() const;
00164 bool isNotZero() const;
00165
00166 bool isIdentity() const;
00167
00168 bool operator==(const TMatrix& mat) const;
00169
00170 TMatrix* operator*(const TMatrix& mat) const;
00171
00172 TMatrix* operator|(const TMatrix& mat) const;
00173
00174 TMatrix& operator=(const TMatrix& mat);
00175
00176 TVector<TRing>* operator*(TVector<TRing>& vec) const;
00177
00178 TMatrix* getSubMatrix(unsigned int firstrow,unsigned int firstcol,unsigned int lastrow,unsigned int lastcol) const;
00184 unsigned int getRank() const;
00185 unsigned int getRank(bool inplace);
00186 TMatrix* getKernel() const;
00187 TMatrix* getRowEchelonForm() const;
00188 TMatrix * getRowBasis() const;
00189 vector<bool> getLeadingVariables();
00190 vector<bool> getFreeVariables();
00191
00192 TVector<TRing>* solveLGS(TVector<TRing> &rightHandSide);
00193
00198 TMatrix* getTransposed() const;
00199
00200 TMatrix & transposeInPlace();
00201
00202 BlockMatrix<TRing>* getBlocked(unsigned int rowBlockSize, unsigned int colBlockSize) const;
00208
00209 void printInMacaulayStyle(std::ostream & os, bool assignment = false) const;
00210 void printValue(std::ostream & os) const;
00211 void printValueInMacaulayStyle(std::ostream & os) const;
00214 virtual ~TMatrix();
00215
00216
00217 protected:
00218
00219 inline void init( );
00220
00221 template <class _istream>
00222 void createFromStream(_istream & dataStream);
00223
00227 inline size_t getDataPos(unsigned int row, unsigned int col) const { return row*cols_m+ col; }
00228
00229 };
00230
00231
00232 #endif //TMATRIX_DECLARACION
00233
00234 #include "BlockMatrix.h"
00235 #include "TMatrix.cpp"
00236
00237 #endif