My Project
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  return *this;
19 }
20 
24 
25 //=============================================================================
28 {
29 #ifdef CPPL_VERBOSE
30  std::cerr << "# [MARK] dgematrix::operator+=(const dgbmatrix&)"
31  << std::endl;
32 #endif//CPPL_VERBOSE
33 
34 #ifdef CPPL_DEBUG
35  if(N!=mat.N || M!=mat.M){
36  std::cerr << "[ERROR] dgematrix::operator+=(const dgbmatrix&)" << 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] dgematrix::operator-=(const dgbmatrix&)"
59  << std::endl;
60 #endif//CPPL_VERBOSE
61 
62 #ifdef CPPL_DEBUG
63  if(N!=mat.N || M!=mat.M){
64  std::cerr << "[ERROR] dgematrix::operator-=(const dgbmatrix&)" << 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 
81 //=============================================================================
84 {
85 #ifdef CPPL_VERBOSE
86  std::cerr << "# [MARK] dgematrix::operator*=(const dgbmatrix&)"
87  << std::endl;
88 #endif//CPPL_VERBOSE
89 
90 #ifdef CPPL_DEBUG
91  if(N!=mat.M){
92  std::cerr << "[ERROR] dgematrix::operator*=(const dgbmatrix&)" << std::endl
93  << "These two matrises can not make a product." << std::endl
94  << "Your input was (" << M << "x" << N << ") *= ("
95  << mat.M << "x" << mat.N << ")." << std::endl;
96  exit(1);
97  }
98 #endif//CPPL_DEBUG
99  dgematrix newmat(M,mat.N);
100  newmat.zero();
101 
102  for(long i=0; i<newmat.M; i++){ for(long j=0; j<newmat.N; j++){
103  for(long k=max(0,j-mat.KU); k<min(mat.M,j+mat.KL+1); k++){
104  newmat(i,j)+=operator()(i,k)*mat(k,j);
105  }
106  }}
107 
108  swap(*this,newmat);
109  return *this;
110 }
111 
115 
116 //=============================================================================
118 inline _dgematrix operator+(const dgematrix& matA, const dgbmatrix& matB)
119 {
120 #ifdef CPPL_VERBOSE
121  std::cerr << "# [MARK] operator+(const dgematrix&, const dgbmatrix&)"
122  << std::endl;
123 #endif//CPPL_VERBOSE
124 
125 #ifdef CPPL_DEBUG
126  if(matA.N!=matB.N || matA.M!=matB.M){
127  std::cerr << "[ERROR] operator+(dgematrix&, dgbmatrix&)" << std::endl
128  << "These two matrises can not make a summation." << std::endl
129  << "Your input was (" << matA.M << "x" << matA.N << ") + ("
130  << matB.M << "x" << matB.N << ")." << std::endl;
131  exit(1);
132  }
133 #endif//CPPL_DEBUG
134 
135  dgematrix newmat(matA);
136 
137  for(long i=0; i<matB.M; i++){
138  for(long j=max(0,i-matB.KL); j<min(matB.N,i+matB.KU+1); j++){
139  newmat(i,j)+=matB(i,j);
140  }
141  }
142 
143  return _(newmat);
144 }
145 
146 //=============================================================================
148 inline _dgematrix operator-(const dgematrix& matA, const dgbmatrix& matB)
149 {
150 #ifdef CPPL_VERBOSE
151  std::cerr << "# [MARK] operator-(const dgematrix&, const dgbmatrix&)"
152  << std::endl;
153 #endif//CPPL_VERBOSE
154 
155 #ifdef CPPL_DEBUG
156  if(matA.N!=matB.N || matA.M!=matB.M){
157  std::cerr << "[ERROR] operator+(dgematrix&, dgbmatrix&)" << std::endl
158  << "These two matrises can not make a summation." << std::endl
159  << "Your input was (" << matA.M << "x" << matA.N << ") + ("
160  << matB.M << "x" << matB.N << ")." << std::endl;
161  exit(1);
162  }
163 #endif//CPPL_DEBUG
164 
165  dgematrix newmat(matA);
166 
167  for(long i=0; i<matB.M; i++){
168  for(long j=max(0,i-matB.KL); j<min(matB.N,i+matB.KU+1); j++){
169  newmat(i,j)-=matB(i,j);
170  }
171  }
172 
173  return _(newmat);
174 }
175 
176 //=============================================================================
178 inline _dgematrix operator*(const dgematrix& matA, const dgbmatrix& matB)
179 {
180 #ifdef CPPL_VERBOSE
181  std::cerr << "# [MARK] operator*(const dgematrix&, const dgbmatrix&)"
182  << std::endl;
183 #endif//CPPL_VERBOSE
184 
185 #ifdef CPPL_DEBUG
186  if(matA.N!=matB.M){
187  std::cerr << "[ERROR] operator*(dgematrix&, dgbmatrix&)" << std::endl
188  << "These two matrises can not make a product." << std::endl
189  << "Your input was (" << matA.M << "x" << matA.N << ") * ("
190  << matB.M << "x" << matB.N << ")." << std::endl;
191  exit(1);
192  }
193 #endif//CPPL_DEBUG
194 
195  dgematrix newmat( matA.M, matB.N );
196  newmat.zero();
197 
198  long i, j, k;
199 #pragma omp parallel for private(j,k)
200  for(i=0; i<newmat.M; i++){
201  for(j=0; j<newmat.N; j++){
202  for(k=max(0,j-matB.KU); k<min(matB.M,j+matB.KL+1); k++){
203  newmat(i,j)+=matA(i,k)*matB(k,j);
204  }
205  }
206  }
207 
208  return _(newmat);
209 }
void zero()
Definition: dgematrix-misc.hpp:26
void resize(const long &, const long &)
Definition: dgematrix-misc.hpp:126
friend void swap(dgematrix &, dgematrix &)
Definition: dgematrix-misc.hpp:154
Real Double-precision General Dence Matrix Class.
Definition: dgematrix.hpp:3
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
Real Double-precision General Band Matrix Class.
Definition: dgbmatrix.hpp:3
friend _drovector operator*(const drovector &, const dgematrix &)
Definition: drovector-dgematrix.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
friend const _drovector & operator+(const _drovector &)
Definition: _drovector-unary.hpp:3
double & operator()(const long &, const long &)
Definition: dgematrix-io.hpp:3