KrisLibrary  1.0.0
BlockTridiagonalMatrix.h
1 #ifndef MATH_BLOCK_TRIDIAGONAL_MATRIX
2 #define MATH_BLOCK_TRIDIAGONAL_MATRIX
3 
4 #include "matrix.h"
5 #include "BlockVector.h"
6 
7 namespace Math {
8 
10 {
11 public:
13 
15  BlockTridiagonalMatrix(int nBlock);
16  BlockTridiagonalMatrix(int nBlock,int nMat);
17  BlockTridiagonalMatrix(int nBlock,int nMat,Real initVal);
18 
19  inline int numBlockRows() const { return (int)diagonal.size(); }
20  inline int numBlockCols() const { return (int)diagonal.size(); }
21  int numTotalRows() const;
22  int numTotalCols() const;
23  void resize(int nBlock);
24  void resize(int nBlock,int nMat);
25  void resize(int nBlock,int nMat,Real initVal);
26  void resizeSimilar(const MyT&);
27  void clear();
28 
29  Matrix& operator()(int i,int j);
30  const Matrix& operator()(int i,int j) const;
31 
32  inline void operator += (const MyT& a) { inc(a); }
33  inline void operator -= (const MyT& a) { dec(a); }
34  void add(const MyT&,const MyT&);
35  void sub(const MyT&,const MyT&);
36  void mul(const MyT&,Real c);
37  void div(const MyT&,Real c);
38  void inc(const MyT&);
39  void dec(const MyT&);
40  void madd(const MyT&,Real c);
41  void mul(const BlockVector& a,BlockVector& x) const;
42  void mulTranspose(const BlockVector& a,BlockVector& x) const;
43  void madd(const BlockVector& a,BlockVector& x) const;
44  void maddTranspose(const BlockVector& a,BlockVector& x) const;
45 
46  void setZero();
47  void set(Real);
48  void setIdentity();
49  void setTranspose(const MyT&);
50  bool solveInverse_LU(const BlockVector& b,BlockVector& x) const;
51  bool solveInverse_Cholesky(const BlockVector& b,BlockVector& x) const; //valid only if positive definite
52 
53  void inplaceTranspose();
54 
55  void getMatrix(Matrix&) const;
56 
57  inline bool isEmpty() const { return diagonal.empty(); }
58  bool isValid() const;
59  bool hasDims(const MyT& m) const;
60  bool hasDims(int nBlock,int nMat) const;
61 
62  std::vector<Matrix> diagonal,upperDiagonal,lowerDiagonal;
63 };
64 
65 } //namespace Math
66 
67 
68 #endif
Definition: BlockTridiagonalMatrix.h:9
Definition: BlockVector.h:9
Contains all definitions in the Math package.
Definition: WorkspaceBound.h:12