CPPLapack
 All Classes Files Functions Variables Friends Pages
dgsmatrix-dgbmatrix.hpp
Go to the documentation of this file.
1 //=============================================================================
2 /*! dgsmatrix+dgbmatrix operator */
3 inline _dgematrix operator+(const dgsmatrix& 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  dgematrix newmat( matA.to_dgematrix() );
15 
16  for(CPPL_INT i=0; i<matB.m; i++){
17  const CPPL_INT jmax =std::min(matB.n,i+matB.ku+1);
18  for(CPPL_INT j=std::max(CPPL_INT(0),i-matB.kl); j<jmax; j++){
19  newmat(i,j)+=matB(i,j);
20  }
21  }
22 
23  return _(newmat);
24 }
25 
26 //=============================================================================
27 /*! dgsmatrix-dgbmatrix operator */
28 inline _dgematrix operator-(const dgsmatrix& matA, const dgbmatrix& matB)
29 {CPPL_VERBOSE_REPORT;
30 #ifdef CPPL_DEBUG
31  if(matA.n!=matB.n || matA.m!=matB.m){
32  ERROR_REPORT;
33  std::cerr << "These two matrises can not make a summation." << std::endl
34  << "Your input was (" << matA.m << "x" << matA.n << ") + (" << matB.m << "x" << matB.n << ")." << std::endl;
35  exit(1);
36  }
37 #endif//CPPL_DEBUG
38 
39  dgematrix newmat( matA.to_dgematrix() );
40 
41  for(CPPL_INT i=0; i<matB.m; i++){
42  const CPPL_INT jmax =std::min(matB.n,i+matB.ku+1);
43  for(CPPL_INT j=std::max(CPPL_INT(0),i-matB.kl); j<jmax; j++){
44  newmat(i,j)-=matB(i,j);
45  }
46  }
47 
48  return _(newmat);
49 }
50 
51 //=============================================================================
52 /*! dgsmatrix*dgbmatrix operator */
53 inline _dgematrix operator*(const dgsmatrix& matA, const dgbmatrix& matB)
54 {CPPL_VERBOSE_REPORT;
55 #ifdef CPPL_DEBUG
56  if(matA.n!=matB.m){
57  ERROR_REPORT;
58  std::cerr << "These two matrises can not make a product." << std::endl
59  << "Your input was (" << matA.m << "x" << matA.n << ") * (" << matB.m << "x" << matB.n << ")." << std::endl;
60  exit(1);
61  }
62 #endif//CPPL_DEBUG
63 
64  dgematrix newmat( matA.m, matB.n );
65  newmat.zero();
66 
67  const std::vector<dcomponent>::const_iterator matA_data_end =matA.data.end();
68  for(std::vector<dcomponent>::const_iterator it=matA.data.begin(); it!=matA_data_end; it++){
69  const CPPL_INT jmax =std::min(matB.n,it->j+matB.ku+1);
70  for(CPPL_INT j=std::max(CPPL_INT(0),it->j-matB.kl); j<jmax; j++){
71  newmat(it->i,j) += it->v*matB(it->j,j);
72  }
73  }
74 
75  return _(newmat);
76 }
Real Double-precision General Sparse Matrix Class.
Definition: dgsmatrix.hpp:3
std::vector< dcomponent > data
matrix data
Definition: dgsmatrix.hpp:11
CPPL_INT m
matrix row size
Definition: dgbmatrix.hpp:9
CPPL_INT n
matrix column size
Definition: dgsmatrix.hpp:10
_dgematrix operator-(const dgsmatrix &matA, const dgbmatrix &matB)
dgematrix & zero()
_dgematrix i(const _dgbmatrix &mat)
Real Double-precision General Dence Matrix Class.
Definition: dgematrix.hpp:3
CPPL_INT kl
lower band width
Definition: dgbmatrix.hpp:11
_dgematrix operator*(const dgsmatrix &matA, const dgbmatrix &matB)
CPPL_INT ku
upper band width
Definition: dgbmatrix.hpp:12
(DO NOT USE) Smart-temporary Real Double-precision General Dence Matrix Class
Definition: _dgematrix.hpp:3
Real Double-precision General Band Matrix Class.
Definition: dgbmatrix.hpp:3
_dgematrix to_dgematrix() const
_dgematrix operator+(const dgsmatrix &matA, const dgbmatrix &matB)
CPPL_INT n
matrix column size
Definition: dgbmatrix.hpp:10
_dcovector _(dcovector &vec)
CPPL_INT m
matrix row size
Definition: dgsmatrix.hpp:9