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