My Project
zgbmatrix-zgbmatrix.hpp
1 //=============================================================================
5 {
6 #ifdef CPPL_VERBOSE
7  std::cerr << "# [MARK] zgbmatrix::operator=(const zgbmatrix&)"
8  << std::endl;
9 #endif//CPPL_VERBOSE
10 
11  if(Array!=mat.Array){ // if it is NOT self substitution
12  copy(mat);
13  }
14  return *this;
15 }
16 
20 
21 //=============================================================================
25 {
26 #ifdef CPPL_VERBOSE
27  std::cerr << "# [MARK] zgbmatrix::operator+=(const zgbmatrix&)"
28  << std::endl;
29 #endif//CPPL_VERBOSE
30 
31 #ifdef CPPL_DEBUG
32  if(N!=mat.N || M!=mat.M){
33  std::cerr << "[ERROR] zgbmatrix::operator+=(zgbmatrix&)" << std::endl
34  << "These two matrises can not make a summation." << std::endl
35  << "Your input was"
36  << "(" << M <<"x"<< N <<","<< KL <<":"<< KU << ") "<< "+="
37  << "("<< mat.M <<"x"<< mat.N <<","<< mat.KL <<":"<< mat.KU <<") "
38  << std::endl;
39  exit(1);
40  }
41 #endif//CPPL_DEBUG
42 
43  if(KL>=mat.KL && KU>=mat.KU){
44  for(long i=0; i<M; i++){
45  for(long j=max(0,i-mat.KL); j<min(N,i+mat.KU+1); j++){
46  operator()(i,j)+=mat(i,j);
47  }
48  }
49 
50  return *this;
51  }
52 
53  else{
54  zgbmatrix newmat(M,N,max(KL,mat.KL),max(KU,mat.KU));
55  newmat.zero();
56  for(long i=0; i<M; i++){
57  for(long j=max(0,i-KL); j<min(N,i+KU+1); j++){
58  newmat(i,j)+=operator()(i,j);
59  }
60  for(long j=max(0,i-mat.KL); j<min(mat.N,i+mat.KU+1); j++){
61  newmat(i,j)+=mat(i,j);
62  }
63  }
64 
65  swap(*this,newmat);
66  return *this;
67  }
68 }
69 
70 //=============================================================================
74 {
75 #ifdef CPPL_VERBOSE
76  std::cerr << "# [MARK] zgbmatrix::operator-=(const zgbmatrix&)"
77  << std::endl;
78 #endif//CPPL_VERBOSE
79 
80 #ifdef CPPL_DEBUG
81  if(N!=mat.N || M!=mat.M){
82  std::cerr << "[ERROR] zgbmatrix::operator-=(zgbmatrix&)" << std::endl
83  << "These two matrises can not make a subtraction." << std::endl
84  << "Your input was"
85  << "(" << M <<"x"<< N <<","<< KL <<":"<< KU << ") "<< "-="
86  << "("<< mat.M <<"x"<< mat.N <<","<< mat.KL <<":"<< mat.KU <<") "
87  << std::endl;
88  exit(1);
89  }
90 #endif//CPPL_DEBUG
91 
92  if(KL>=mat.KL && KU>=mat.KU){
93  for(long i=0; i<M; i++){
94  for(long j=max(0,i-mat.KL); j<min(N,i+mat.KU+1); j++){
95  operator()(i,j)-=mat(i,j);
96  }
97  }
98 
99  return *this;
100  }
101 
102  else{
103  zgbmatrix newmat(M,N,max(KL,mat.KL),max(KU,mat.KU));
104  newmat.zero();
105  for(long i=0; i<M; i++){
106  for(long j=max(0,i-KL); j<min(N,i+KU+1); j++){
107  newmat(i,j)+=operator()(i,j);
108  }
109  for(long j=max(0,i-mat.KL); j<min(mat.N,i+mat.KU+1); j++){
110  newmat(i,j)-=mat(i,j);
111  }
112  }
113 
114  swap(*this,newmat);
115  return *this;
116  }
117 }
118 
119 //=============================================================================
122 {
123 #ifdef CPPL_VERBOSE
124  std::cerr << "# [MARK] zgbmatrix::operator*=(const zgbmatrix&)"
125  << std::endl;
126 #endif//CPPL_VERBOSE
127 
128 #ifdef CPPL_DEBUG
129  if(N!=mat.M){
130  std::cerr << "[ERROR] zgbmatrix::operator*=(zgbmatrix&)" << std::endl
131  << "These two matrises can not make a product." << std::endl
132  << "Your input was (" << M << "x" << N << ") * ("
133  << mat.M << "x" << mat.N << ")." << std::endl;
134  exit(1);
135  }
136 #endif//CPPL_DEBUG
137 
138  zgbmatrix newmat( M, mat.N, KU+mat.KL-1, KL+mat.KU+1 );
139  newmat.zero();
140 
141  for(long i=0; i<newmat.M; i++){
142  for(long j=max(0,i-newmat.kl); j<min(newmat.n,i+newmat.ku+1); j++){
143  for(long k=max( max(0,i-KL), max(0,j-mat.KU) );
144  k< min( min(N,i+KU+1), min(mat.M,j+mat.KL+1) ); k++){
145  newmat(i,j)+= operator()(i,k)*mat(k,j);
146  }
147  }
148  }
149 
150  swap(*this,newmat);
151  return *this;
152 }
153 
157 
158 //=============================================================================
160 inline _zgbmatrix operator+(const zgbmatrix& matA, const zgbmatrix& matB)
161 {
162 #ifdef CPPL_VERBOSE
163  std::cerr << "# [MARK] operator+(const zgbmatrix&, const zgbmatrix&)"
164  << std::endl;
165 #endif//CPPL_VERBOSE
166 
167 #ifdef CPPL_DEBUG
168  if(matA.N!=matB.N || matA.M!=matB.M){
169  std::cerr << "[ERROR] operator+(zgbmatrix&, zgbmatrix&)" << std::endl
170  << "These two matrises can not make a summation." << std::endl
171  << "Your input was (" << matA.M << "x" << matA.N << ") + ("
172  << matB.M << "x" << matB.N << ")." << std::endl;
173  exit(1);
174  }
175 #endif//CPPL_DEBUG
176 
177  zgbmatrix newmat(matA.M,matA.N,max(matA.KL,matB.KL),max(matA.KU,matB.KU));
178  newmat.zero();
179 
180  for(long i=0; i<matA.M; i++){
181  for(long j=max(0,i-matA.KL); j<min(matA.N,i+matA.KU+1); j++){
182  newmat(i,j)+=matA(i,j);
183  }
184  for(long j=max(0,i-matB.KL); j<min(matB.N,i+matB.KU+1); j++){
185  newmat(i,j)+=matB(i,j);
186  }
187  }
188 
189  return _(newmat);
190 }
191 
192 //=============================================================================
194 inline _zgbmatrix operator-(const zgbmatrix& matA, const zgbmatrix& matB)
195 {
196 #ifdef CPPL_VERBOSE
197  std::cerr << "# [MARK] operator-(const zgbmatrix&, const zgbmatrix&)"
198  << std::endl;
199 #endif//CPPL_VERBOSE
200 
201 #ifdef CPPL_DEBUG
202  if(matA.N!=matB.N || matA.M!=matB.M){
203  std::cerr << "[ERROR] operator-(zgbmatrix&, zgbmatrix&)" << std::endl
204  << "These two matrises can not make a subtraction." << std::endl
205  << "Your input was (" << matA.M << "x" << matA.N << ") - ("
206  << matB.M << "x" << matB.N << ")." << std::endl;
207  exit(1);
208  }
209 #endif//CPPL_DEBUG
210 
211  zgbmatrix newmat(matA.M,matA.N,max(matA.KL,matB.KL),max(matA.KU,matB.KU));
212  newmat.zero();
213 
214  for(long i=0; i<matA.M; i++){
215  for(long j=max(0,i-matA.KL); j<min(matA.N,i+matA.KU+1); j++){
216  newmat(i,j)+=matA(i,j);
217  }
218  for(long j=max(0,i-matB.KL); j<min(matB.N,i+matB.KU+1); j++){
219  newmat(i,j)-=matB(i,j);
220  }
221  }
222 
223  return _(newmat);
224 }
225 
226 //=============================================================================
228 inline _zgbmatrix operator*(const zgbmatrix& matA, const zgbmatrix& matB)
229 {
230 #ifdef CPPL_VERBOSE
231  std::cerr << "# [MARK] operator*(const zgbmatrix&, const zgbmatrix&)"
232  << std::endl;
233 #endif//CPPL_VERBOSE
234 
235 #ifdef CPPL_DEBUG
236  if(matA.N!=matB.M){
237  std::cerr << "[ERROR] operator*(zgbmatrix&, zgbmatrix&)" << std::endl
238  << "These two matrises can not make a product." << std::endl
239  << "Your input was (" << matA.M << "x" << matA.N << ") * ("
240  << matB.M << "x" << matB.N << ")." << std::endl;
241  exit(1);
242  }
243 #endif//CPPL_DEBUG
244 
245  zgbmatrix newmat( matA.M, matB.N, matA.KU+matB.KL-1, matA.KL+matB.KU+1 );
246  newmat.zero();
247 
248  long i, j, k;
249 #pragma omp parallel for private(j,k)
250  for(i=0; i<newmat.m; i++){
251  for(j=max(0,i-newmat.kl); j<min(newmat.n,i+newmat.ku+1); j++){
252  for(k=max( max(0,i-matA.KL), max(0,j-matB.KU) );
253  k< min( min(matA.N,i+matA.KU+1), min(matB.M,j+matB.KL+1) ); k++){
254  newmat(i,j)+= matA(i,k)*matB(k,j);
255  }
256  }
257  }
258 
259  return _(newmat);
260 }
std::complex< double > & operator()(const long &, const long &)
Definition: zgbmatrix-io.hpp:3
friend _zgematrix i(const zgbmatrix &)
Definition: zgbmatrix-calc.hpp:22
zgbmatrix & operator*=(const zgbmatrix &)
Definition: zgbmatrix-zgbmatrix.hpp:121
friend _zrovector operator-(const _zrovector &)
Definition: _zrovector-unary.hpp:15
void copy(const zgbmatrix &)
Definition: zgbmatrix-misc.hpp:74
zgbmatrix & operator+=(const zgbmatrix &)
Definition: zgbmatrix-zgbmatrix.hpp:24
zgbmatrix & operator=(const zgbmatrix &)
Definition: zgbmatrix-zgbmatrix.hpp:4
Complex Double-precision General Band Matrix Class.
Definition: zgbmatrix.hpp:3
zgbmatrix & operator-=(const zgbmatrix &)
Definition: zgbmatrix-zgbmatrix.hpp:73
friend _zrovector operator*(const zrovector &, const zgematrix &)
Definition: zrovector-zgematrix.hpp:3
(DO NOT USE) Smart-temporary Complex Double-precision General Band Matrix Class
Definition: _zgbmatrix.hpp:3
long const & kl
lower band width (readable)
Definition: zgbmatrix.hpp:18
void zero()
Definition: zgbmatrix-misc.hpp:29
long const & n
matrix column size (readable)
Definition: zgbmatrix.hpp:17
long const & m
matrix row size (readable)
Definition: zgbmatrix.hpp:16
friend const _zrovector & operator+(const _zrovector &)
Definition: _zrovector-unary.hpp:3
friend void swap(zgbmatrix &, zgbmatrix &)
Definition: zgbmatrix-misc.hpp:167
long const & ku
upper band width (readable)
Definition: zgbmatrix.hpp:19
std::complex< double > * Array
1D Array to store vector data
Definition: _zrovector.hpp:8