CPPLapack
 All Classes Files Functions Variables Friends Pages
_dgbmatrix-dgbmatrix.hpp
Go to the documentation of this file.
1 //=============================================================================
2 /*! _dgbmatrix+dgbmatrix operator */
3 inline _dgbmatrix operator+(const _dgbmatrix& matA, const dgbmatrix& matB)
4 {CPPL_VERBOSE_REPORT;
5 #ifdef CPPL_DEBUG
6  if(matA.n!=matB.n || matA.m!=matB.m){
7  ERROR_REPORT;
8  std::cerr << "These two matrises can not make a summation." << std::endl
9  << "Your input was (" << matA.m << "x" << matA.n << ") + (" << matB.m << "x" << matB.n << ")." << std::endl;
10  exit(1);
11  }
12 #endif//CPPL_DEBUG
13 
14  if(matA.kl>=matB.kl && matA.ku>=matB.ku){
15  for(CPPL_INT i=0; i<matB.m; i++){
16  const CPPL_INT jmax =std::min(matB.n,i+matB.ku+1);
17  for(CPPL_INT j=std::max(CPPL_INT(0),i-matB.kl); j<jmax; j++){
18  matA(i,j) += matB(i,j);
19  }
20  }
21 
22  return matA;
23  }
24 
25  else{
26  dgbmatrix newmat(matA.m,matA.n,std::max(matA.kl,matB.kl),std::max(matA.ku,matB.ku));
27  newmat.zero();
28 
29  for(CPPL_INT i=0; i<matA.m; i++){
30  const CPPL_INT jmax1 =std::min(matA.n,i+matA.ku+1);
31  for(CPPL_INT j=std::max(CPPL_INT(0),i-matA.kl); j<jmax1; j++){
32  newmat(i,j) += matA(i,j);
33  }
34  const CPPL_INT jmax2 =std::min(matB.n,i+matB.ku+1);
35  for(CPPL_INT j=std::max(CPPL_INT(0),i-matB.kl); j<jmax2; j++){
36  newmat(i,j) += matB(i,j);
37  }
38  }
39 
40  matA.destroy();
41  return _(newmat);
42  }
43 }
44 
45 //=============================================================================
46 /*! _dgbmatrix-dgbmatrix operator */
47 inline _dgbmatrix operator-(const _dgbmatrix& matA, const dgbmatrix& matB)
48 {CPPL_VERBOSE_REPORT;
49 #ifdef CPPL_DEBUG
50  if(matA.n!=matB.n || matA.m!=matB.m){
51  ERROR_REPORT;
52  std::cerr << "These two matrises can not make a subtraction." << std::endl
53  << "Your input was (" << matA.m << "x" << matA.n << ") - (" << matB.m << "x" << matB.n << ")." << std::endl;
54  exit(1);
55  }
56 #endif//CPPL_DEBUG
57 
58  if(matA.kl>=matB.kl && matA.ku>=matB.ku){
59  for(CPPL_INT i=0; i<matB.m; i++){
60  const CPPL_INT jmax =std::min(matB.n,i+matB.ku+1);
61  for(CPPL_INT j=std::max(CPPL_INT(0),i-matB.kl); j<jmax; j++){
62  matA(i,j) -= matB(i,j);
63  }
64  }
65 
66  return matA;
67  }
68 
69  else{
70  dgbmatrix newmat(matA.m,matA.n,std::max(matA.kl,matB.kl),std::max(matA.ku,matB.ku));
71  newmat.zero();
72 
73  for(CPPL_INT i=0; i<matA.m; i++){
74  const CPPL_INT jmax1 =std::min(matA.n,i+matA.ku+1);
75  for(CPPL_INT j=std::max(CPPL_INT(0),i-matA.kl); j<jmax1; j++){
76  newmat(i,j) += matA(i,j);
77  }
78  const CPPL_INT jmax2 =std::min(matB.n,i+matB.ku+1);
79  for(CPPL_INT j=std::max(CPPL_INT(0),i-matB.kl); j<jmax2; j++){
80  newmat(i,j) -= matB(i,j);
81  }
82  }
83 
84  return _(newmat);
85  }
86 }
87 
88 //=============================================================================
89 /*! _dgbmatrix*dgbmatrix operator */
90 inline _dgbmatrix operator*(const _dgbmatrix& matA, const dgbmatrix& matB)
91 {CPPL_VERBOSE_REPORT;
92 #ifdef CPPL_DEBUG
93  if(matA.n!=matB.m){
94  ERROR_REPORT;
95  std::cerr << "These two matrises can not make a product." << std::endl
96  << "Your input was (" << matA.m << "x" << matA.n << ") * (" << matB.m << "x" << matB.n << ")." << std::endl;
97  exit(1);
98  }
99 #endif//CPPL_DEBUG
100 
101  dgbmatrix newmat( matA.m, matB.n, std::min(matA.kl+matB.kl,matA.m-1), std::min(matA.ku+matB.ku,matB.n-1) );
102  newmat.zero();
103 
104  for(CPPL_INT i=0; i<newmat.m; i++){
105  const CPPL_INT jmax =std::min(newmat.n,i+newmat.ku+1);
106  for(CPPL_INT j=std::max(CPPL_INT(0),i-newmat.kl); j<jmax; j++){
107  const CPPL_INT kmax =std::min( std::min(matA.n,i+matA.ku+1), std::min(matB.m,j+matB.kl+1) );
108  for(CPPL_INT k=std::max( std::max(CPPL_INT(0),i-matA.kl), std::max(CPPL_INT(0),j-matB.ku) ); k<kmax; k++){
109  newmat(i,j) += matA(i,k)*matB(k,j);
110  }
111  }
112  }
113 
114  matA.destroy();
115  return _(newmat);
116 }
CPPL_INT m
matrix row size
Definition: dgbmatrix.hpp:9
CPPL_INT ku
upper band width
Definition: _dgbmatrix.hpp:12
void destroy() const
_dgematrix i(const _dgbmatrix &mat)
CPPL_INT kl
lower band width
Definition: dgbmatrix.hpp:11
CPPL_INT kl
lower band width
Definition: _dgbmatrix.hpp:11
CPPL_INT ku
upper band width
Definition: dgbmatrix.hpp:12
CPPL_INT n
matrix column size
Definition: _dgbmatrix.hpp:10
Real Double-precision General Band Matrix Class.
Definition: dgbmatrix.hpp:3
_dgbmatrix operator+(const _dgbmatrix &matA, const dgbmatrix &matB)
(DO NOT USE) Smart-temporary Real Double-precision General Band Matrix Class
Definition: _dgbmatrix.hpp:3
dgbmatrix & zero()
CPPL_INT n
matrix column size
Definition: dgbmatrix.hpp:10
_dgbmatrix operator-(const _dgbmatrix &matA, const dgbmatrix &matB)
_dcovector _(dcovector &vec)
_dgbmatrix operator*(const _dgbmatrix &matA, const dgbmatrix &matB)
CPPL_INT m
matrix row size
Definition: _dgbmatrix.hpp:9