CPPLapack
 All Classes Files Functions Variables Friends Pages
zgsmatrix-zgsmatrix.hpp
Go to the documentation of this file.
1 //=============================================================================
2 /*! zgsmatrix=zgsmatrix operator */
4 {CPPL_VERBOSE_REPORT;
5  if(&data!=&mat.data){ // if it is NOT self substitution
6  copy(mat);
7  }
8  return *this;
9 }
10 
11 ///////////////////////////////////////////////////////////////////////////////
12 ///////////////////////////////////////////////////////////////////////////////
13 ///////////////////////////////////////////////////////////////////////////////
14 
15 //=============================================================================
16 /*! zgsmatrix+=zgsmatrix operator */
18 {CPPL_VERBOSE_REPORT;
19 #ifdef CPPL_DEBUG
20  if(n!=mat.n || m!=mat.m){
21  ERROR_REPORT;
22  std::cerr << "These two matrises can not make a summation." << std::endl
23  << "Your input was (" << m << "x" << n << ") += (" << mat.m << "x" << mat.n << ")." << std::endl;
24  exit(1);
25  }
26 #endif//CPPL_DEBUG
27 
28  const std::vector<zcomponent>::const_iterator mat_data_end =mat.data.end();
29  for(std::vector<zcomponent>::const_iterator it=mat.data.begin(); it!=mat_data_end; it++){
30  (*this)(it->i,it->j) +=it->v;
31  }
32 
33  return *this;
34 }
35 
36 //=============================================================================
37 /*! zgsmatrix-=zgsmatrix operator */
39 {CPPL_VERBOSE_REPORT;
40 #ifdef CPPL_DEBUG
41  if(n!=mat.n || m!=mat.m){
42  ERROR_REPORT;
43  std::cerr << "These two matrises can not make a sutraction." << std::endl
44  << "Your input was (" << m << "x" << n << ") -= (" << mat.m << "x" << mat.n << ")." << std::endl;
45  exit(1);
46  }
47 #endif//CPPL_DEBUG
48 
49  const std::vector<zcomponent>::const_iterator mat_data_end =mat.data.end();
50  for(std::vector<zcomponent>::const_iterator it=mat.data.begin(); it!=mat_data_end; it++){
51  (*this)(it->i,it->j) -=it->v;
52  }
53 
54  return *this;
55 }
56 
57 //=============================================================================
58 /*! zgsmatrix*=zgsmatrix operator */
60 {CPPL_VERBOSE_REPORT;
61 #ifdef CPPL_DEBUG
62  if(n!=mat.m){
63  ERROR_REPORT;
64  std::cerr << "These two matrises can not make a product." << std::endl
65  << "Your input was (" << m << "x" << n << ") *= (" << mat.m << "x" << mat.n << ")." << std::endl;
66  exit(1);
67  }
68 #endif//CPPL_DEBUG
69 
70  zgsmatrix newmat(m, mat.n);
71 
72  const std::vector<zcomponent>::const_iterator data_end =data.end();
73  for(std::vector<zcomponent>::const_iterator it=data.begin(); it!=data_end; it++){
74  CPPL_INT k =it->j;
75  const std::vector<CPPL_INT>::const_iterator mat_rows_k_end =mat.rows[k].end();
76  for(std::vector<CPPL_INT>::const_iterator p=mat.rows[k].begin(); p!=mat_rows_k_end; p++){
77  newmat(it->i,mat.data[*p].j) +=it->v*mat.data[*p].v;
78  }
79  }
80 
81  swap(*this,newmat);
82  return *this;
83 }
84 
85 ///////////////////////////////////////////////////////////////////////////////
86 ///////////////////////////////////////////////////////////////////////////////
87 ///////////////////////////////////////////////////////////////////////////////
88 
89 //=============================================================================
90 /*! zgsmatrix+zgsmatrix operator */
91 inline _zgsmatrix operator+(const zgsmatrix& matA, const zgsmatrix& matB)
92 {CPPL_VERBOSE_REPORT;
93 #ifdef CPPL_DEBUG
94  if(matA.n!=matB.n || matA.m!=matB.m){
95  ERROR_REPORT;
96  std::cerr << "These two matrises can not make a summation." << std::endl
97  << "Your input was (" << matA.m << "x" << matA.n << ") + (" << matB.m << "x" << matB.n << ")." << std::endl;
98  exit(1);
99  }
100 #endif//CPPL_DEBUG
101 
102  zgsmatrix newmat(matA);
103 
104  const std::vector<zcomponent>::const_iterator matB_data_end =matB.data.end();
105  for(std::vector<zcomponent>::const_iterator it=matB.data.begin(); it!=matB_data_end; it++){
106  newmat(it->i, it->j) +=it->v;
107  }
108 
109  return _(newmat);
110 }
111 
112 //=============================================================================
113 /*! zgsmatrix-zgsmatrix operator */
114 inline _zgsmatrix operator-(const zgsmatrix& matA, const zgsmatrix& matB)
115 {CPPL_VERBOSE_REPORT;
116 #ifdef CPPL_DEBUG
117  if(matA.n!=matB.n || matA.m!=matB.m){
118  ERROR_REPORT;
119  std::cerr << "These two matrises can not make a subtraction." << std::endl
120  << "Your input was (" << matA.m << "x" << matA.n << ") - (" << matB.m << "x" << matB.n << ")." << std::endl;
121  exit(1);
122  }
123 #endif//CPPL_DEBUG
124 
125  zgsmatrix newmat(matA);
126 
127  const std::vector<zcomponent>::const_iterator matB_data_end =matB.data.end();
128  for(std::vector<zcomponent>::const_iterator it=matB.data.begin(); it!=matB_data_end; it++){
129  newmat(it->i, it->j) -=it->v;
130  }
131 
132  return _(newmat);
133 }
134 
135 //=============================================================================
136 /*! zgsmatrix*zgsmatrix operator */
137 inline _zgsmatrix operator*(const zgsmatrix& matA, const zgsmatrix& matB)
138 {CPPL_VERBOSE_REPORT;
139 #ifdef CPPL_DEBUG
140  if(matA.n!=matB.m){
141  ERROR_REPORT;
142  std::cerr << "These two matrises can not make a product." << std::endl
143  << "Your input was (" << matA.m << "x" << matA.n << ") * (" << matB.m << "x" << matB.n << ")." << std::endl;
144  exit(1);
145  }
146 #endif//CPPL_DEBUG
147 
148  zgsmatrix newmat(matA.m, matB.n);
149 
150  const std::vector<zcomponent>::const_iterator matA_data_end =matA.data.end();
151  for(std::vector<zcomponent>::const_iterator it=matA.data.begin(); it!=matA_data_end; it++){
152  CPPL_INT k =it->j;
153  const std::vector<CPPL_INT>::const_iterator matB_rows_k_end =matB.rows[k].end();
154  for(std::vector<CPPL_INT>::const_iterator p=matB.rows[k].begin(); p!=matB_rows_k_end; p++){
155  newmat(it->i,matB.data[*p].j) +=it->v*matB.data[*p].v;
156  }
157  }
158 
159  return _(newmat);
160 }
Complex Double-precision General Sparse Matrix Class.
Definition: zgsmatrix.hpp:3
zgsmatrix & operator=(const zgsmatrix &)
zgsmatrix & operator+=(const zgsmatrix &)
(DO NOT USE) Smart-temporary Real Double-precision General Sparse Matrix Class
Definition: _zgsmatrix.hpp:3
void copy(const zgsmatrix &)
zgsmatrix & operator-=(const zgsmatrix &)
std::vector< std::vector< CPPL_INT > > rows
array of vector to store the entry information of component for each row
Definition: zgsmatrix.hpp:12
std::vector< zcomponent > data
matrix data
Definition: zgsmatrix.hpp:11
friend void swap(zgsmatrix &, zgsmatrix &)
_zgsmatrix operator+(const zgsmatrix &matA, const zgsmatrix &matB)
zgsmatrix & operator*=(const zgsmatrix &)
_zgsmatrix operator-(const zgsmatrix &matA, const zgsmatrix &matB)
_zgsmatrix operator*(const zgsmatrix &matA, const zgsmatrix &matB)
CPPL_INT m
matrix row size
Definition: zgsmatrix.hpp:9
CPPL_INT n
matrix column size
Definition: zgsmatrix.hpp:10
_dcovector _(dcovector &vec)