My Project
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  return *this;
19 }
20 
24 
25 //=============================================================================
28 {
29 #ifdef CPPL_VERBOSE
30  std::cerr << "# [MARK] zgematrix::operator+=(const zgbmatrix&)"
31  << std::endl;
32 #endif//CPPL_VERBOSE
33 
34 #ifdef CPPL_DEBUG
35  if(N!=mat.N || M!=mat.M){
36  std::cerr << "[ERROR] zgematrix::operator+=(const zgbmatrix&)" << std::endl
37  << "These two matrises can not make a summation." << std::endl
38  << "Your input was (" << M << "x" << N << ") += ("
39  << mat.M << "x" << mat.N << ")." << std::endl;
40  exit(1);
41  }
42 #endif//CPPL_DEBUG
43 
44  for(long i=0; i<mat.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 //=============================================================================
56 {
57 #ifdef CPPL_VERBOSE
58  std::cerr << "# [MARK] zgematrix::operator-=(const zgbmatrix&)"
59  << std::endl;
60 #endif//CPPL_VERBOSE
61 
62 #ifdef CPPL_DEBUG
63  if(N!=mat.N || M!=mat.M){
64  std::cerr << "[ERROR] zgematrix::operator-=(const zgbmatrix&)" << std::endl
65  << "These two matrises can not make a subtraction." << std::endl
66  << "Your input was (" << M << "x" << N << ") -= ("
67  << mat.M << "x" << mat.N << ")." << std::endl;
68  exit(1);
69  }
70 #endif//CPPL_DEBUG
71 
72  for(long i=0; i<mat.M; i++){
73  for(long j=max(0,i-mat.KL); j<min(N,i+mat.KU+1); j++){
74  operator()(i,j)-=mat(i,j);
75  }
76  }
77 
78  return *this;
79 }
80 //=============================================================================
83 {
84 #ifdef CPPL_VERBOSE
85  std::cerr << "# [MARK] zgematrix::operator*=(const zgbmatrix&)"
86  << std::endl;
87 #endif//CPPL_VERBOSE
88 
89 #ifdef CPPL_DEBUG
90  if(N!=mat.M){
91  std::cerr << "[ERROR] zgematrix::operator*=(const zgbmatrix&)" << std::endl
92  << "These two matrises can not make a product." << std::endl
93  << "Your input was (" << M << "x" << N << ") *= ("
94  << mat.M << "x" << mat.N << ")." << std::endl;
95  exit(1);
96  }
97 #endif//CPPL_DEBUG
98  zgematrix newmat(M,mat.N);
99  newmat.zero();
100 
101  for(long i=0; i<newmat.m; i++){ for(long j=0; j<newmat.n; j++){
102  for(long k=max(0,j-mat.KU); k<min(mat.M,j+mat.KL+1); k++){
103  newmat(i,j)+=operator()(i,k)*mat(k,j);
104  }
105  }}
106 
107  swap(*this,newmat);
108  return *this;
109 }
110 
114 
115 //=============================================================================
117 inline _zgematrix operator+(const zgematrix& matA, const zgbmatrix& matB)
118 {
119 #ifdef CPPL_VERBOSE
120  std::cerr << "# [MARK] operator+(const zgematrix&, const zgbmatrix&)"
121  << std::endl;
122 #endif//CPPL_VERBOSE
123 
124 #ifdef CPPL_DEBUG
125  if(matA.N!=matB.N || matA.M!=matB.M){
126  std::cerr << "[ERROR] operator+(zgematrix&, zgbmatrix&)" << std::endl
127  << "These two matrises can not make a summation." << std::endl
128  << "Your input was (" << matA.M << "x" << matA.N << ") + ("
129  << matB.M << "x" << matB.N << ")." << std::endl;
130  exit(1);
131  }
132 #endif//CPPL_DEBUG
133 
134  zgematrix newmat(matA);
135 
136  for(long i=0; i<matB.M; i++){
137  for(long j=max(0,i-matB.KL); j<min(matB.N,i+matB.KU+1); j++){
138  newmat(i,j)+=matB(i,j);
139  }
140  }
141 
142  return _(newmat);
143 }
144 
145 //=============================================================================
147 inline _zgematrix operator-(const zgematrix& matA, const zgbmatrix& matB)
148 {
149 #ifdef CPPL_VERBOSE
150  std::cerr << "# [MARK] operator-(const zgematrix&, const zgbmatrix&)"
151  << std::endl;
152 #endif//CPPL_VERBOSE
153 
154 #ifdef CPPL_DEBUG
155  if(matA.N!=matB.N || matA.M!=matB.M){
156  std::cerr << "[ERROR] operator+(zgematrix&, zgbmatrix&)" << std::endl
157  << "These two matrises can not make a summation." << std::endl
158  << "Your input was (" << matA.M << "x" << matA.N << ") + ("
159  << matB.M << "x" << matB.N << ")." << std::endl;
160  exit(1);
161  }
162 #endif//CPPL_DEBUG
163 
164  zgematrix newmat(matA);
165 
166  for(long i=0; i<matB.M; i++){
167  for(long j=max(0,i-matB.KL); j<min(matB.N,i+matB.KU+1); j++){
168  newmat(i,j)-=matB(i,j);
169  }
170  }
171 
172  return _(newmat);
173 }
174 
175 //=============================================================================
177 inline _zgematrix operator*(const zgematrix& matA, const zgbmatrix& matB)
178 {
179 #ifdef CPPL_VERBOSE
180  std::cerr << "# [MARK] operator*(const zgematrix&, const zgbmatrix&)"
181  << std::endl;
182 #endif//CPPL_VERBOSE
183 
184 #ifdef CPPL_DEBUG
185  if(matA.N!=matB.M){
186  std::cerr << "[ERROR] operator*(zgematrix&, zgbmatrix&)" << std::endl
187  << "These two matrises can not make a product." << std::endl
188  << "Your input was (" << matA.M << "x" << matA.N << ") * ("
189  << matB.M << "x" << matB.N << ")." << std::endl;
190  exit(1);
191  }
192 #endif//CPPL_DEBUG
193 
194  zgematrix newmat( matA.M, matB.N );
195  newmat.zero();
196 
197  long i, j, k;
198 #pragma omp parallel for private(j,k)
199  for(i=0; i<newmat.m; i++){
200  for(j=0; j<newmat.n; j++){
201  for(k=max(0,j-matB.KU); k<min(matB.M,j+matB.KL+1); k++){
202  newmat(i,j)+=matA(i,k)*matB(k,j);
203  }
204  }
205  }
206 
207  return _(newmat);
208 }
void resize(const long &, const long &)
Definition: zgematrix-misc.hpp:126
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
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
(DO NOT USE) Smart-temporary Complex Double-precision General Dence Matrix Class
Definition: _zgematrix.hpp:3
void zero()
Definition: zgematrix-misc.hpp:26
Complex Double-precision General Band Matrix Class.
Definition: zgbmatrix.hpp:3
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 const & m
matrix row size (readable)
Definition: zgematrix.hpp:14
zgematrix & operator+=(const zgematrix &)
Definition: zgematrix-zgematrix.hpp:22
friend void swap(zgematrix &, zgematrix &)
Definition: zgematrix-misc.hpp:154
long const & n
matrix column size (readable)
Definition: zgematrix.hpp:15
friend const _zrovector & operator+(const _zrovector &)
Definition: _zrovector-unary.hpp:3