VERB_code_2.3
zssmatrix-misc.hpp
1 //=============================================================================
3 inline void zssmatrix::clear()
4 {
5 #ifdef CPPL_VERBOSE
6  std::cerr << "# [MARK] zssmatrix::clear()"
7  << std::endl;
8 #endif//CPPL_VERBOSE
9 
10 #ifdef CPPL_DEBUG
11  std::cerr << "# [NOTE] zssmatrix::clear() "
12  << " An array at " << Array
13  << " is going to be cleared." << std::endl;
14 #endif//CPPL_DEBUG
15 
16  M =N =CAP =VOL=0;
17  delete [] Array; Array =NULL;
18  delete [] Indx; Indx =NULL;
19  delete [] Jndx; Jndx =NULL;
20 }
21 
22 //=============================================================================
24 inline void zssmatrix::zero()
25 {
26 #ifdef CPPL_VERBOSE
27  std::cerr << "# [MARK] zssmatrix::zero()"
28  << std::endl;
29 #endif//CPPL_VERBOSE
30 
31  VOL =0;
32 }
33 
34 //=============================================================================
36 inline void zssmatrix::chsign()
37 {
38 #ifdef CPPL_VERBOSE
39  std::cerr << "# [MARK] zssmatrix::chsign()"
40  << std::endl;
41 #endif//CPPL_VERBOSE
42 
43  for(long i=0; i<VOL; i++){ Array[i] =-Array[i]; }
44 }
45 
46 //=============================================================================
48 inline void zssmatrix::copy(const zssmatrix& mat)
49 {
50 #ifdef CPPL_VERBOSE
51  std::cerr << "# [MARK] zssmatrix::copy(const zssmatrix&)"
52  << std::endl;
53 #endif//CPPL_VERBOSE
54 
55 #ifdef CPPL_DEBUG
56  std::cerr << "# [NOTE] zssmatrix::copy(const zssmatrix&) "
57  << "A zssmatrix at " << Array << " is going to be deleted.";
58 #endif//CPPL_DEBUG
59 
60  resize(mat.M, mat.N, mat.CAP);
61  VOL =mat.VOL;
62  zcopy_(VOL, mat.Array, 1, Array, 1);
63  for(long i=0; i<VOL; i++){
64  Indx[i] =mat.Indx[i];
65  Jndx[i] =mat.Jndx[i];
66  }
67 
68 #ifdef CPPL_DEBUG
69  std::cerr << " Then, a COPY of a zssmatrix has been cleated at "
70  << Array << "." << std::endl;
71 #endif//CPPL_DEBUG
72 }
73 
74 //=============================================================================
77 inline void zssmatrix::shallow_copy(const _zssmatrix& mat)
78 {
79 #ifdef CPPL_VERBOSE
80  std::cerr << "# [MARK] zssmatrix::shallow_copy(const _zssmatrix&)"
81  << std::endl;
82 #endif//CPPL_VERBOSE
83 
84 #ifdef CPPL_DEBUG
85  std::cerr << "# [NOTE] zssmatrix:shallow_copy(const _zssmatrix&) "
86  << "A zssmatrix at " << Array << " is going to be deleted, "
87  << "and point at " << mat.Array << " instead." << std::endl;
88 #endif//CPPL_DEBUG
89 
90  delete [] Array;
91  delete [] Indx;
92  delete [] Jndx;
93  M =mat.M;
94  N =mat.N;
95  CAP =mat.CAP;
96  VOL =mat.VOL;
97  Array =mat.Array;
98  Indx =mat.Indx;
99  Jndx =mat.Jndx;
100 }
101 
102 //=============================================================================
104 inline void zssmatrix::resize(const long& _m, const long& _n, const long& _c)
105 {
106 #ifdef CPPL_VERBOSE
107  std::cerr << "# [MARK] zssmatrix::resize(const long&, const long&, const long&)"
108  << std::endl;
109 #endif//CPPL_VERBOSE
110 
111 #ifdef CPPL_DEBUG
112  if( _m<0 || _n<0 || _c<0 ){
113  std::cerr << "[ERROR] zssmatrix::resize"
114  << "(const long&, const long&, const long&)"
115  << std::endl
116  << "Matrix sizes and the length of arrays "
117  << "must be positive integers. " << std::endl
118  << "Your input was (" << _m << "," << _n << "," << _c << ")."
119  << std::endl;
120  exit(1);
121  }
122 #endif//CPPL_DEBUG
123 
124  delete [] Array;
125  M =_m;
126  N =_n;
127  CAP =_c;
128  VOL =0;
129  Array =new std::complex<double>[CAP];
130  Indx =new long[CAP];
131  Jndx =new long[CAP];
132 }
133 
134 //=============================================================================
136 inline void zssmatrix::expand(const long& dc)
137 {
138 #ifdef CPPL_VERBOSE
139  std::cerr << "# [MARK] zssmatrix::expand(const long&)"
140  << std::endl;
141 #endif//CPPL_VERBOSE
142 
143 #ifdef CPPL_DEBUG
144  if( dc<0 ){
145  std::cerr << "[ERROR] zssmatrix::expand(const long&)" << std::endl
146  << "The argument must be a positive integer. " << std::endl
147  << "Your input was (" << dc << ")." << std::endl;
148  exit(1);
149  }
150 #endif//CPPL_DEBUG
151 
152  CAP+=dc;
153  std::complex<double>* newArray(new std::complex<double>[CAP]);
154  long *newIndx(new long[CAP]), *newJndx(new long[CAP]);
155 
156  for(int c=0; c<VOL; c++){
157  newArray[c] =Array[c];
158  newIndx[c] =Indx[c];
159  newJndx[c] =Jndx[c];
160  }
161 
162  delete [] Array;
163  delete [] Indx;
164  delete [] Jndx;
165  Array =newArray;
166  Indx =newIndx;
167  Jndx =newJndx;
168 }
169 
170 //=============================================================================
172 inline bool zssmatrix::isListed(const long& i, const long& j)
173 {
174 #ifdef CPPL_VERBOSE
175  std::cerr << "# [MARK] zssmatrix::isListed(const long&, const long&)"
176  << std::endl;
177 #endif//CPPL_VERBOSE
178 
179 #ifdef CPPL_DEBUG
180  if( i<0 || j<0 || M<=i || N<=j ){
181  std::cerr << "[ERROR] zssmatrix::isListed(const long&, const long&)"
182  << std::endl
183  << "The required component is out of the matrix size."
184  << std::endl
185  << "Your input was (" << i << "," << j << ")." << std::endl;
186  exit(1);
187  }
188 #endif//CPPL_DEBUG
189 
190  for(int c=0; c<VOL; c++){
191  if(Indx[c]==i && Jndx[c]==j){ return 1; }
192  }
193 
194  return 0;
195 }
196 
197 
198 //=============================================================================
200 inline long zssmatrix::number(const long& i, const long& j)
201 {
202 #ifdef CPPL_VERBOSE
203  std::cerr << "# [MARK] zssmatrix::number(const long&, const long&)"
204  << std::endl;
205 #endif//CPPL_VERBOSE
206 
207 #ifdef CPPL_DEBUG
208  if( i<0 || j<0 || M<=i || N<=j ){
209  std::cerr << "[ERROR] zssmatrix::number(const long&, const long&)"
210  << std::endl
211  << "The required component is out of the matrix size."
212  << std::endl
213  << "Your input was (" << i << "," << j << ")." << std::endl;
214  exit(1);
215  }
216 #endif//CPPL_DEBUG
217 
218  for(long c=0; c<VOL; c++){
219  if(Indx[c]==i && Jndx[c]==j){ return c; }
220  }
221 
222  return -1;
223 }
224 
225 
226 //=============================================================================
228 inline void swap(zssmatrix& A, zssmatrix& B)
229 {
230 #ifdef CPPL_VERBOSE
231  std::cerr << "# [MARK] swap(zssmatrix&, zssmatrix&)"
232  << std::endl;
233 #endif//CPPL_VERBOSE
234 
235  long A_M(A.M), A_N(A.N), A_CAP(A.CAP), A_VOL(A.VOL);
236  std::complex<double>* A_Array(A.Array);
237  long *A_Indx(A.Indx), *A_Jndx(A.Jndx);
238  A.M=B.M; A.N=B.N; A.CAP=B.CAP; A.VOL=B.VOL;
239  A.Array=B.Array; A.Indx=B.Indx; A.Jndx=B.Jndx;
240  B.M=A_M; B.N=A_N; B.CAP=A_CAP; B.VOL=A_VOL;
241  B.Array=A_Array; B.Indx=A_Indx; B.Jndx=A_Jndx;
242 }
243 
244 //=============================================================================
246 inline _zssmatrix _(zssmatrix& mat)
247 {
248 #ifdef CPPL_VERBOSE
249  std::cerr << "# [MARK] _(zssmatrix&)"
250  << std::endl;
251 #endif//CPPL_VERBOSE
252 
253  _zssmatrix newmat;
254 
255  newmat.M =mat.M;
256  newmat.N =mat.N;
257  newmat.CAP =mat.CAP;
258  newmat.VOL =mat.VOL;
259  newmat.Array =mat.Array;
260  newmat.Indx =mat.Indx;
261  newmat.Jndx =mat.Jndx;
262 
263  mat.M =0;
264  mat.N =0;
265  mat.CAP =0;
266  mat.VOL =0;
267  mat.Array =NULL;
268  mat.Indx =NULL;
269  mat.Jndx =NULL;
270 
271  return newmat;
272 }
273 
277 
278 //=============================================================================
280 inline void zssmatrix::checkup()
281 {
282 #ifdef CPPL_VERBOSE
283  std::cerr << "# [MARK] zssmatrix::checkup()"
284  << std::endl;
285 #endif//CPPL_VERBOSE
286 
288  if(CAP<0){
289  std::cerr << "[ERROR] zssmatrix::checkup()" << std::endl
290  << "The cap is not valid." << std::endl
291  << "CAP was " << CAP << "." << std::endl;
292  exit(1);
293  }
294 
296  if(VOL<0 || VOL==CAP){
297  std::cerr << "[ERROR] zssmatrix::checkup()" << std::endl
298  << "The vol is not valid." << std::endl
299  << "VOL was " << VOL << "while CAP is " << CAP << "."
300  << std::endl;
301  exit(1);
302  }
303 
305  for(long c=0; c<VOL; c++){
307  if(Indx[c]<0 || Indx[c]>=M){
308  std::cerr << "[ERROR] zssmatrix::checkup()" << std::endl
309  << "The indx of the " << c
310  << "th element is out of the matrix size." << std::endl
311  << "Indx[" << c << "] was " << Indx[c] << "." << std::endl;
312  exit(1);
313  }
314 
316  if(Jndx[c]<0 || Jndx[c]>=N){
317  std::cerr << "[ERROR] zssmatrix::checkup()" << std::endl
318  << "The jndx of the " << c
319  << "th element is out of the matrix size." << std::endl
320  << "Jndx[" << c << "] was " << Jndx[c] << "." << std::endl;
321  exit(1);
322  }
323 
325  for(long C=c+1; C<VOL; C++){
326  if(Indx[c]==Indx[C] && Jndx[c]==Jndx[C]){
327  std::cerr << "[ERROR] zssmatrix::checkup()" << std::endl
328  << "The (" << Indx[c] << ", " << Jndx[c]
329  << ") component is std::complex<double>-listed at the "
330  << c << "th and the" << C << "the elements."<< std::endl;
331  exit(1);
332  }
333  }
334  }
335 
337  std::cerr << "# [NOTE] zssmatrix::checkup() "
338  << "This sparse matrix is fine." << std::endl;
339 }
void checkup()
Definition: zssmatrix-misc.hpp:280
void clear()
Definition: zssmatrix-misc.hpp:3
long M
matrix row size
Definition: _zssmatrix.hpp:7
long VOL
the number of non-zero components
Definition: _zssmatrix.hpp:10
void zero()
Definition: zssmatrix-misc.hpp:24
bool isListed(const long &, const long &)
Definition: zssmatrix-misc.hpp:172
(DO NOT USE) Smart-temporary Complex Double-precision Sparse Matrix Class
Definition: _zssmatrix.hpp:3
void expand(const long &)
Definition: zssmatrix-misc.hpp:136
void chsign()
Definition: zssmatrix-misc.hpp:36
void copy(const zssmatrix &)
Definition: zssmatrix-misc.hpp:48
long * Jndx
1D array to store the j-index of non-zero matrix components
Definition: _zssmatrix.hpp:13
void shallow_copy(const _zssmatrix &)
Definition: zssmatrix-misc.hpp:77
long CAP
the length of data arrays
Definition: _zssmatrix.hpp:9
long number(const long &, const long &)
Definition: zssmatrix-misc.hpp:200
std::complex< double > * Array
1D array to store non-zero matrix data
Definition: _zssmatrix.hpp:11
void resize(const long &, const long &, const long &)
Definition: zssmatrix-misc.hpp:104
std::complex< double > * Array
1D Array to store vector data
Definition: _zrovector.hpp:8
long N
matrix column size
Definition: _zssmatrix.hpp:8
Complex Double-precision Sparse Matrix Class.
Definition: zssmatrix.hpp:3
long * Indx
1D array to store the i-index of non-zero matrix components
Definition: _zssmatrix.hpp:12