VERB_code_2.3
zgematrix-_zgbmatrix.hpp
1 //=============================================================================
4 {
5 #ifdef CPPL_VERBOSE
6  std::cerr << "# [MARK] zgematrix::operator=(const _zgbmatrix&)"
7  << std::endl;
8 #endif//CPPL_VERBOSE
9 
10  resize(mat.M, mat.N);
11  zero();
12  for(long i=0; i<mat.M; i++){
13  for(long j=max(0,i-mat.KL); j<min(N,i+mat.KU+1); j++){
14  operator()(i,j)=mat(i,j);
15  }
16  }
17 
18  mat.destroy();
19  return *this;
20 }
21 
25 
26 //=============================================================================
29 {
30 #ifdef CPPL_VERBOSE
31  std::cerr << "# [MARK] zgematrix::operator+=(const _zgbmatrix&)"
32  << std::endl;
33 #endif//CPPL_VERBOSE
34 
35 #ifdef CPPL_DEBUG
36  if(N!=mat.N || M!=mat.M){
37  std::cerr << "[ERROR] zgematrix::operator+=(const _zgbmatrix&)" << std::endl
38  << "These two matrises can not make a summation." << std::endl
39  << "Your input was (" << M << "x" << N << ") += ("
40  << mat.M << "x" << mat.N << ")." << std::endl;
41  exit(1);
42  }
43 #endif//CPPL_DEBUG
44 
45  for(long i=0; i<mat.M; i++){
46  for(long j=max(0,i-mat.KL); j<min(N,i+mat.KU+1); j++){
47  operator()(i,j)+=mat(i,j);
48  }
49  }
50 
51  mat.destroy();
52  return *this;
53 }
54 
55 //=============================================================================
58 {
59 #ifdef CPPL_VERBOSE
60  std::cerr << "# [MARK] zgematrix::operator-=(const _zgbmatrix&)"
61  << std::endl;
62 #endif//CPPL_VERBOSE
63 
64 #ifdef CPPL_DEBUG
65  if(N!=mat.N || M!=mat.M){
66  std::cerr << "[ERROR] zgematrix::operator-=(const _zgbmatrix&)" << std::endl
67  << "These two matrises can not make a subtraction." << std::endl
68  << "Your input was (" << M << "x" << N << ") -= ("
69  << mat.M << "x" << mat.N << ")." << std::endl;
70  exit(1);
71  }
72 #endif//CPPL_DEBUG
73 
74  for(long i=0; i<mat.M; i++){
75  for(long j=max(0,i-mat.KL); j<min(N,i+mat.KU+1); j++){
76  operator()(i,j)-=mat(i,j);
77  }
78  }
79 
80  mat.destroy();
81  return *this;
82 }
83 //=============================================================================
86 {
87 #ifdef CPPL_VERBOSE
88  std::cerr << "# [MARK] zgematrix::operator*=(const _zgbmatrix&)"
89  << std::endl;
90 #endif//CPPL_VERBOSE
91 
92 #ifdef CPPL_DEBUG
93  if(N!=mat.M){
94  std::cerr << "[ERROR] zgematrix::operator*=(const _zgbmatrix&)" << std::endl
95  << "These two matrises can not make a product." << std::endl
96  << "Your input was (" << M << "x" << N << ") *= ("
97  << mat.M << "x" << mat.N << ")." << std::endl;
98  exit(1);
99  }
100 #endif//CPPL_DEBUG
101 
102  zgematrix newmat(M,mat.N);
103  newmat.zero();
104 
105  for(long i=0; i<newmat.m; i++){ for(long j=0; j<newmat.n; j++){
106  for(long k=max(0,j-mat.KU); k<min(mat.M,j+mat.KL+1); k++){
107  newmat(i,j)+=operator()(i,k)*mat(k,j);
108  }
109  }}
110 
111  swap(*this,newmat);
112  mat.destroy();
113  return *this;
114 }
115 
119 
120 //=============================================================================
122 inline _zgematrix operator+(const zgematrix& matA, const _zgbmatrix& matB)
123 {
124 #ifdef CPPL_VERBOSE
125  std::cerr << "# [MARK] operator+(const zgematrix&, const _zgbmatrix&)"
126  << std::endl;
127 #endif//CPPL_VERBOSE
128 
129 #ifdef CPPL_DEBUG
130  if(matA.N!=matB.N || matA.M!=matB.M){
131  std::cerr << "[ERROR] operator+(zgematrix&, zgbmatrix&)" << std::endl
132  << "These two matrises can not make a summation." << std::endl
133  << "Your input was (" << matA.M << "x" << matA.N << ") + ("
134  << matB.M << "x" << matB.N << ")." << std::endl;
135  exit(1);
136  }
137 #endif//CPPL_DEBUG
138 
139  zgematrix newmat(matA);
140 
141  for(long i=0; i<matB.M; i++){
142  for(long j=max(0,i-matB.KL); j<min(matB.N,i+matB.KU+1); j++){
143  newmat(i,j)+=matB(i,j);
144  }
145  }
146 
147  matB.destroy();
148  return _(newmat);
149 }
150 
151 //=============================================================================
153 inline _zgematrix operator-(const zgematrix& matA, const _zgbmatrix& matB)
154 {
155 #ifdef CPPL_VERBOSE
156  std::cerr << "# [MARK] operator-(const zgematrix&, const _zgbmatrix&)"
157  << std::endl;
158 #endif//CPPL_VERBOSE
159 
160 #ifdef CPPL_DEBUG
161  if(matA.N!=matB.N || matA.M!=matB.M){
162  std::cerr << "[ERROR] operator+(zgematrix&, _zgbmatrix&)" << std::endl
163  << "These two matrises can not make a summation." << std::endl
164  << "Your input was (" << matA.M << "x" << matA.N << ") + ("
165  << matB.M << "x" << matB.N << ")." << std::endl;
166  exit(1);
167  }
168 #endif//CPPL_DEBUG
169 
170  zgematrix newmat(matA);
171 
172  for(long i=0; i<matB.M; i++){
173  for(long j=max(0,i-matB.KL); j<min(matB.N,i+matB.KU+1); j++){
174  newmat(i,j)-=matB(i,j);
175  }
176  }
177 
178  matB.destroy();
179  return _(newmat);
180 }
181 
182 //=============================================================================
184 inline _zgematrix operator*(const zgematrix& matA, const _zgbmatrix& matB)
185 {
186 #ifdef CPPL_VERBOSE
187  std::cerr << "# [MARK] operator*(const zgematrix&, const _zgbmatrix&)"
188  << std::endl;
189 #endif//CPPL_VERBOSE
190 
191 #ifdef CPPL_DEBUG
192  if(matA.N!=matB.M){
193  std::cerr << "[ERROR] operator*(zgematrix&, _zgbmatrix&)" << std::endl
194  << "These two matrises can not make a product." << std::endl
195  << "Your input was (" << matA.M << "x" << matA.N << ") * ("
196  << matB.M << "x" << matB.N << ")." << std::endl;
197  exit(1);
198  }
199 #endif//CPPL_DEBUG
200 
201  zgematrix newmat( matA.M, matB.N );
202  newmat.zero();
203 
204  long i, j, k;
205 #pragma omp parallel for private(j,k)
206  for(i=0; i<newmat.m; i++){
207  for(j=0; j<newmat.n; j++){
208  for(k=max(0,j-matB.KU); k<min(matB.M,j+matB.KL+1); k++){
209  newmat(i,j)+=matA(i,k)*matB(k,j);
210  }
211  }
212  }
213 
214  matB.destroy();
215  return _(newmat);
216 }
void resize(const long &, const long &)
Definition: zgematrix-misc.hpp:126
double max(double v1, double v2)
Return maximum.
Definition: variousFunctions.cpp:355
long const & m
matrix row size (readable)
Definition: zgematrix.hpp:14
zgematrix & operator-=(const zgematrix &)
Definition: zgematrix-zgematrix.hpp:45
friend _zrovector operator-(const _zrovector &)
Definition: _zrovector-unary.hpp:15
zgematrix & operator=(const zgematrix &)
Definition: zgematrix-zgematrix.hpp:3
long N
matrix column size
Definition: _zgbmatrix.hpp:8
long const & n
matrix column size (readable)
Definition: zgematrix.hpp:15
void destroy() const
Definition: _zgbmatrix-misc.hpp:3
friend _zgematrix i(const zgematrix &)
Definition: zgematrix-calc.hpp:21
zgematrix & operator*=(const zgematrix &)
Definition: zgematrix-zgematrix.hpp:68
Complex Double-precision General Dence Matrix Class.
Definition: zgematrix.hpp:3
long KU
upper band width
Definition: _zgbmatrix.hpp:10
(DO NOT USE) Smart-temporary Complex Double-precision General Dence Matrix Class
Definition: _zgematrix.hpp:3
void zero()
Definition: zgematrix-misc.hpp:26
std::complex< double > & operator()(const long &, const long &)
Definition: zgematrix-io.hpp:3
friend _zrovector operator*(const zrovector &, const zgematrix &)
Definition: zrovector-zgematrix.hpp:3
long M
matrix row size
Definition: _zgbmatrix.hpp:7
(DO NOT USE) Smart-temporary Complex Double-precision General Band Matrix Class
Definition: _zgbmatrix.hpp:3
zgematrix & operator+=(const zgematrix &)
Definition: zgematrix-zgematrix.hpp:22
friend void swap(zgematrix &, zgematrix &)
Definition: zgematrix-misc.hpp:154
friend const _zrovector & operator+(const _zrovector &)
Definition: _zrovector-unary.hpp:3
long KL
lower band width
Definition: _zgbmatrix.hpp:9