BlockMatrix.h
Go to the documentation of this file.00001 #ifndef BLOCKMATRIX_H
00002 #define BLOCKMATRIX_H
00003
00004
00005
00006
00007
00008
00009
00014 #ifndef BLOCKMATRIX_DECLARACION
00015 #define BLOCKMATRIX_DECLARACION
00016
00017 struct tPos;
00018
00019 struct tBlockPos
00020 {
00021 int blockNr;
00022 int blockPos;
00023
00024 tBlockPos(int _blockNr, int _blockPos): blockNr(_blockNr),
00025 blockPos(_blockPos)
00026 {}
00027 };
00028
00029
00030
00031
00032 template <class TRing>
00033 class TMatrix;
00034
00035
00042 template <class TRing>
00043 class BlockMatrix
00044 {
00045
00046
00047
00048 public:
00049 typedef typename TRing::ElementType TNum;
00050
00051
00052 protected:
00053
00054
00055
00058 int rows;
00059 int cols;
00060
00061 int rowBlockSize;
00062 int colBlockSize;
00063
00064 const TRing* ring;
00065
00066
00067 TNum* data;
00068 string name;
00069
00075 int extendedRowNum;
00076 int extendedColNum;
00077
00078
00079
00082 public:
00083
00084
00085
00086 static int refit(int number, int multipleTo) ;
00087
00088
00091 BlockMatrix( int _rowBlockSize,
00092 int _colBlockSize,
00093 int _rows,
00094 int _cols,
00095 const TRing* _ring,
00096 string _name = "unnamedMatrix" );
00097
00098 BlockMatrix( const BlockMatrix& mat);
00099
00100
00101
00107 void fillZero();
00108 void randomInit(long * randomSeed);
00114 inline int getColNum() const { return cols; };
00115 inline int getRowNum() const { return rows; };
00116
00118 inline int getBlocksPerRow() const { return extendedRowNum/rowBlockSize; };
00120 inline int getBlocksPerCol() const { return extendedColNum/colBlockSize; };
00121
00122
00123 inline int getRowBlockSize() const { return rowBlockSize; };
00124 inline int getColBlockSize() const { return colBlockSize; };
00125
00126 inline int getBlockNum() const { return getBlocksPerRow()*getBlocksPerCol(); };
00127 inline int getBlockSize() const { return rowBlockSize*colBlockSize; };
00128
00129 size_t getSize() const { return extendedRowNum*extendedColNum; };
00130
00131 bool blocksAreSquare() const { return rowBlockSize==colBlockSize; };
00132
00133 std::string getName() const { return name; };
00134 void setName(string _name) { name = _name; };
00140 void checkBounds(int row, int col) const;
00141 void checkBlockBounds(int _blockNum, int _blockPos) const;
00147 tBlockPos computeBlockPos(int _row, int _col) const;
00148 tPos computeNormalPos(int _blockNr, int _blockPos) const;
00155 inline void setVal(const int row, const int col,const TNum z);
00156 TNum getVal(const int row, const int col) const;
00157
00158 inline TNum& getValRef(const int row, const int col);
00159 const TNum& getConstValRef(const int row,const int col) const;
00160
00161 inline void setBlockVal(const int blockNr,const int blockPos,const TNum z);
00162 inline TNum getBlockVal(const int blockNr,const int blockPos);
00163
00164 inline TNum* getBlockValAddr(const int blockNr, const int blockPos);
00165
00171 bool isZero();
00172
00173 template <class TemplateMatrix> bool operator==(const TemplateMatrix& mat) const;
00174
00175
00176
00177 BlockMatrix& operator=(const BlockMatrix& mat);
00178
00179
00184
00185
00186
00187
00188
00189
00194 TMatrix<TRing>* unblock();
00200
00201 void outputMatrix(ostream & os) const;
00202 void printValue(ostream & os) const;
00204 virtual ~BlockMatrix();
00205 };
00206
00207
00208
00209 #endif //BLOCKMATRIX_DECLARACION
00210
00211
00212 #include "BlockMatrix.cpp"
00213
00214 #endif // end BLOCKMATRIX_H