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  shallow_copy(mat);
6  return *this;
7 }
8 
9 ///////////////////////////////////////////////////////////////////////////////
10 ///////////////////////////////////////////////////////////////////////////////
11 ///////////////////////////////////////////////////////////////////////////////
12 
13 //=============================================================================
14 /*! zgsmatrix+=_zgsmatrix operator */
16 {CPPL_VERBOSE_REPORT;
17 #ifdef CPPL_DEBUG
18  if(n!=mat.n || m!=mat.m){
19  ERROR_REPORT;
20  std::cerr << "These two matrises can not make a summation." << std::endl
21  << "Your input was (" << m << "x" << n << ") += (" << mat.m << "x" << mat.n << ")." << std::endl;
22  exit(1);
23  }
24 #endif//CPPL_DEBUG
25 
26  const std::vector<zcomponent>::const_iterator mat_data_end =mat.data.end();
27  for(std::vector<zcomponent>::const_iterator it=mat.data.begin(); it!=mat_data_end; it++){
28  (*this)(it->i,it->j) += it->v;
29  }
30 
31  mat.destroy();
32  return *this;
33 }
34 
35 //=============================================================================
36 /*! zgsmatrix-=_zgsmatrix operator */
38 {CPPL_VERBOSE_REPORT;
39 #ifdef CPPL_DEBUG
40  if(n!=mat.n || m!=mat.m){
41  ERROR_REPORT;
42  std::cerr << "These two matrises can not make a sutraction." << std::endl
43  << "Your input was (" << m << "x" << n << ") -= (" << mat.m << "x" << mat.n << ")." << std::endl;
44  exit(1);
45  }
46 #endif//CPPL_DEBUG
47 
48  const std::vector<zcomponent>::const_iterator mat_data_end =mat.data.end();
49  for(std::vector<zcomponent>::const_iterator it=mat.data.begin(); it!=mat_data_end; it++){
50  (*this)(it->i,it->j) -= it->v;
51  }
52 
53  mat.destroy();
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, 0 );
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>::iterator mat_rows_k_end =mat.rows[k].end();
76  for(std::vector<CPPL_INT>::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  mat.destroy();
83  return *this;
84 }
85 
86 ///////////////////////////////////////////////////////////////////////////////
87 ///////////////////////////////////////////////////////////////////////////////
88 ///////////////////////////////////////////////////////////////////////////////
89 
90 //=============================================================================
91 /*! zgsmatrix+_zgsmatrix operator */
92 inline _zgsmatrix operator+(const zgsmatrix& matA, const _zgsmatrix& matB)
93 {CPPL_VERBOSE_REPORT;
94 #ifdef CPPL_DEBUG
95  if(matA.n!=matB.n || matA.m!=matB.m){
96  ERROR_REPORT;
97  std::cerr << "These two matrises can not make a summation." << std::endl
98  << "Your input was (" << matA.m << "x" << matA.n << ") + (" << matB.m << "x" << matB.n << ")." << std::endl;
99  exit(1);
100  }
101 #endif//CPPL_DEBUG
102 
103  zgsmatrix newmat(matB);
104 
105  const std::vector<zcomponent>::const_iterator matA_data_end =matA.data.end();
106  for(std::vector<zcomponent>::const_iterator it=matA.data.begin(); it!=matA_data_end; it++){
107  newmat(it->i,it->j) += it->v;
108  }
109 
110  return _(newmat);
111 }
112 
113 //=============================================================================
114 /*! zgsmatrix-_zgsmatrix operator */
115 inline _zgsmatrix operator-(const zgsmatrix& matA, const _zgsmatrix& matB)
116 {CPPL_VERBOSE_REPORT;
117 #ifdef CPPL_DEBUG
118  if(matA.n!=matB.n || matA.m!=matB.m){
119  ERROR_REPORT;
120  std::cerr << "These two matrises can not make a subtraction." << std::endl
121  << "Your input was (" << matA.m << "x" << matA.n << ") - (" << matB.m << "x" << matB.n << ")." << std::endl;
122  exit(1);
123  }
124 #endif//CPPL_DEBUG
125 
126  zgsmatrix newmat(matB);
127  newmat.chsign();
128 
129  const std::vector<zcomponent>::const_iterator matA_data_end =matA.data.end();
130  for(std::vector<zcomponent>::const_iterator it=matA.data.begin(); it!=matA_data_end; it++){
131  newmat(it->i,it->j) += it->v;
132  }
133 
134  return _(newmat);
135 }
136 
137 //=============================================================================
138 /*! zgsmatrix*_zgsmatrix operator */
139 inline _zgsmatrix operator*(const zgsmatrix& matA, const _zgsmatrix& matB)
140 {CPPL_VERBOSE_REPORT;
141 #ifdef CPPL_DEBUG
142  if(matA.n!=matB.m){
143  ERROR_REPORT;
144  std::cerr << "These two matrises can not make a product." << std::endl
145  << "Your input was (" << matA.m << "x" << matA.n << ") * (" << matB.m << "x" << matB.n << ")." << std::endl;
146  exit(1);
147  }
148 #endif//CPPL_DEBUG
149 
150  zgsmatrix newmat(matA.m, matB.n);
151 
152  const std::vector<zcomponent>::const_iterator matA_data_end =matA.data.end();
153  for(std::vector<zcomponent>::const_iterator it=matA.data.begin(); it!=matA_data_end; it++){
154  CPPL_INT k =it->j;
155  const std::vector<CPPL_INT>::iterator matB_rows_k_end =matB.rows[k].end();
156  for(std::vector<CPPL_INT>::iterator p=matB.rows[k].begin(); p!=matB_rows_k_end; p++){
157  newmat(it->i,matB.data[*p].j) += it->v*matB.data[*p].v;
158  }
159  }
160 
161  matB.destroy();
162  return _(newmat);
163 }
std::vector< std::vector< CPPL_INT > > rows
array of vector to store the entry information of component for each row
Definition: _zgsmatrix.hpp:12
Complex Double-precision General Sparse Matrix Class.
Definition: zgsmatrix.hpp:3
zgsmatrix & operator=(const zgsmatrix &)
_zgsmatrix operator*(const zgsmatrix &matA, const _zgsmatrix &matB)
CPPL_INT n
matrix column size
Definition: _zgsmatrix.hpp:10
zgsmatrix & operator+=(const zgsmatrix &)
(DO NOT USE) Smart-temporary Real Double-precision General Sparse Matrix Class
Definition: _zgsmatrix.hpp:3
void shallow_copy(const _zgsmatrix &)
zgsmatrix & operator-=(const zgsmatrix &)
std::vector< zcomponent > data
matrix data
Definition: zgsmatrix.hpp:11
friend void swap(zgsmatrix &, zgsmatrix &)
CPPL_INT m
matrix row size
Definition: _zgsmatrix.hpp:9
void destroy() const
zgsmatrix & operator*=(const zgsmatrix &)
_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)
_zgsmatrix operator-(const zgsmatrix &matA, const _zgsmatrix &matB)
std::vector< zcomponent > data
matrix data
Definition: _zgsmatrix.hpp:11