VERB_code_2.3
dgematrix-_dgbmatrix.hpp
1 //=============================================================================
4 {
5 #ifdef CPPL_VERBOSE
6  std::cerr << "# [MARK] dgematrix::operator=(const _dgbmatrix&)"
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] dgematrix::operator+=(const _dgbmatrix&)"
32  << std::endl;
33 #endif//CPPL_VERBOSE
34 
35 #ifdef CPPL_DEBUG
36  if(N!=mat.N || M!=mat.M){
37  std::cerr << "[ERROR] dgematrix::operator+=(const _dgbmatrix&)" << 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] dgematrix::operator-=(const _dgbmatrix&)"
61  << std::endl;
62 #endif//CPPL_VERBOSE
63 
64 #ifdef CPPL_DEBUG
65  if(N!=mat.N || M!=mat.M){
66  std::cerr << "[ERROR] dgematrix::operator-=(const _dgbmatrix&)" << 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] dgematrix::operator*=(const _dgbmatrix&)"
89  << std::endl;
90 #endif//CPPL_VERBOSE
91 
92 #ifdef CPPL_DEBUG
93  if(N!=mat.M){
94  std::cerr << "[ERROR] dgematrix::operator*=(const _dgbmatrix&)" << 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  dgematrix 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 _dgematrix operator+(const dgematrix& matA, const _dgbmatrix& matB)
123 {
124 #ifdef CPPL_VERBOSE
125  std::cerr << "# [MARK] operator+(const dgematrix&, const _dgbmatrix&)"
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+(dgematrix&, dgbmatrix&)" << 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  dgematrix 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 _dgematrix operator-(const dgematrix& matA, const _dgbmatrix& matB)
154 {
155 #ifdef CPPL_VERBOSE
156  std::cerr << "# [MARK] operator-(const dgematrix&, const _dgbmatrix&)"
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+(dgematrix&, _dgbmatrix&)" << 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  dgematrix 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 _dgematrix operator*(const dgematrix& matA, const _dgbmatrix& matB)
185 {
186 #ifdef CPPL_VERBOSE
187  std::cerr << "# [MARK] operator*(const dgematrix&, const _dgbmatrix&)"
188  << std::endl;
189 #endif//CPPL_VERBOSE
190 
191 #ifdef CPPL_DEBUG
192  if(matA.N!=matB.M){
193  std::cerr << "[ERROR] operator*(dgematrix&, _dgbmatrix&)" << 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  dgematrix 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 zero()
Definition: dgematrix-misc.hpp:26
double max(double v1, double v2)
Return maximum.
Definition: variousFunctions.cpp:355
long KL
lower band width
Definition: _dgbmatrix.hpp:9
void resize(const long &, const long &)
Definition: dgematrix-misc.hpp:126
long M
matrix row size
Definition: _dgbmatrix.hpp:7
void destroy() const
Definition: _dgbmatrix-misc.hpp:3
friend void swap(dgematrix &, dgematrix &)
Definition: dgematrix-misc.hpp:154
Real Double-precision General Dence Matrix Class.
Definition: dgematrix.hpp:3
long N
matrix column size
Definition: _dgbmatrix.hpp:8
dgematrix & operator=(const dgematrix &)
Definition: dgematrix-dgematrix.hpp:3
dgematrix & operator*=(const dgematrix &)
Definition: dgematrix-dgematrix.hpp:68
friend _drovector operator-(const _drovector &)
Definition: _drovector-unary.hpp:15
(DO NOT USE) Smart-temporary Real Double-precision General Dence Matrix Class
Definition: _dgematrix.hpp:3
friend _drovector operator*(const drovector &, const dgematrix &)
Definition: drovector-dgematrix.hpp:3
(DO NOT USE) Smart-temporary Real Double-precision General Band Matrix Class
Definition: _dgbmatrix.hpp:3
dgematrix & operator-=(const dgematrix &)
Definition: dgematrix-dgematrix.hpp:45
friend _dgematrix i(const dgematrix &)
Definition: dgematrix-calc.hpp:21
dgematrix & operator+=(const dgematrix &)
Definition: dgematrix-dgematrix.hpp:22
long KU
upper band width
Definition: _dgbmatrix.hpp:10
friend const _drovector & operator+(const _drovector &)
Definition: _drovector-unary.hpp:3
double & operator()(const long &, const long &)
Definition: dgematrix-io.hpp:3