VERB_code_2.3
zhematrix-misc.hpp
1 //=============================================================================
3 inline void zhematrix::complete() const
4 {
5 #ifdef CPPL_VERBOSE
6  std::cerr << "# [MARK] zhematrix::complete() const"
7  << std::endl;
8 #endif//CPPL_VERBOSE
9 
10  for(long i=0; i<N; i++){
11  for(long j=0; j<i; j++){
12  Darray[i][j] =std::conj(Darray[j][i]);
13  }
14 #ifdef CPPL_DEBUG
15  if(std::fabs(std::imag(operator()(i,i))) > CPPL_EPS){
16  std::cerr << "[WARNING] zhematrix::complete() const" << std::endl
17  << "The " << i << "th diagonal component of the zhematrix"
18  << "is not a real number." << std::endl;
19  }
20 #endif//CPPL_DEBUG
21  }
22 }
23 
24 //=============================================================================
26 inline void zhematrix::clear()
27 {
28 #ifdef CPPL_VERBOSE
29  std::cerr << "# [MARK] zhematrix::clear()"
30  << std::endl;
31 #endif//CPPL_VERBOSE
32 
33 #ifdef CPPL_DEBUG
34  std::cerr << "# [NOTE] zhematrix::clear() "
35  << " An array at " << Array
36  << " is going to be cleared." << std::endl;
37 #endif//CPPL_DEBUG
38 
39  N =0;
40  delete [] Array;
41  Array =NULL;
42  delete [] Darray;
43  Darray =NULL;
44 }
45 
46 //=============================================================================
48 inline void zhematrix::zero()
49 {
50 #ifdef CPPL_VERBOSE
51  std::cerr << "# [MARK] zhematrix::zero()"
52  << std::endl;
53 #endif//CPPL_VERBOSE
54 
55  for(long i=0; i<N; i++){ for(long j=0; j<=i; j++){
56  Array[i] =std::complex<double>(0.0,0.0);
57  }}
58 }
59 
60 //=============================================================================
62 inline void zhematrix::identity()
63 {
64 #ifdef CPPL_VERBOSE
65  std::cerr << "# [MARK] zhematrix::identity()"
66  << std::endl;
67 #endif//CPPL_VERBOSE
68 
69  for(long i=0; i<N; i++){
70  for(long j=0; j<i; j++){
71  Darray[j][i] =std::complex<double>(0.0,0.0);
72  }
73  Darray[i][i] =std::complex<double>(1.0,0.0);
74  }
75 }
76 
77 //=============================================================================
79 inline void zhematrix::chsign()
80 {
81 #ifdef CPPL_VERBOSE
82  std::cerr << "# [MARK] zhematrix::chsign()"
83  << std::endl;
84 #endif//CPPL_VERBOSE
85 
86  for(long i=0; i<N; i++){
87  for(long j=0; j<=i; j++){
88  Darray[j][i] =-Darray[j][i];
89  }
90  }
91 }
92 
93 //=============================================================================
95 inline void zhematrix::copy(const zhematrix& mat)
96 {
97 #ifdef CPPL_VERBOSE
98  std::cerr << "# [MARK] zhematrix::copy(const zhematrix&)"
99  << std::endl;
100 #endif//CPPL_VERBOSE
101 
102 #ifdef CPPL_DEBUG
103  std::cerr << "# [NOTE] zhematrix::copy(const zhematrix&) "
104  << "A zhematrix at " << Array << " is going to be deleted.";
105 #endif//CPPL_DEBUG
106 
107  N =mat.N;
108  delete [] Array;
109  Array =new std::complex<double>[N*N];
110  delete [] Darray;
111  Darray =new std::complex<double>*[N];
112  for(int i=0; i<N; i++){ Darray[i] =&Array[i*N]; }
113 
114  zcopy_(mat.N*mat.N, mat.Array, 1, Array, 1);
115 
116 #ifdef CPPL_DEBUG
117  std::cerr << " Then, a COPY of a zhematrix has been cleated at "
118  << Array << "." << std::endl;
119 #endif//CPPL_DEBUG
120 }
121 
122 //=============================================================================
125 inline void zhematrix::shallow_copy(const _zhematrix& mat)
126 {
127 #ifdef CPPL_VERBOSE
128  std::cerr << "# [MARK] zhematrix::shallow_copy(const _zhematrix&)"
129  << std::endl;
130 #endif//CPPL_VERBOSE
131 
132 #ifdef CPPL_DEBUG
133  std::cerr << "# [NOTE] zhematrix:shallow_copy(const _zhematrix&) "
134  << "A zhematrix at " << Array << " is going to be deleted, "
135  << "and point at " << mat.Array << " instead." << std::endl;
136 #endif//CPPL_DEBUG
137 
138  N =mat.N;
139  delete [] Array;
140  Array =mat.Array;
141  delete [] Darray;
142  Darray =mat.Darray;
143 }
144 
145 //=============================================================================
147 inline void zhematrix::resize(const long& _n)
148 {
149 #ifdef CPPL_VERBOSE
150  std::cerr << "# [MARK] zhematrix::resize(const long&)"
151  << std::endl;
152 #endif//CPPL_VERBOSE
153 
154 #ifdef CPPL_DEBUG
155  if( _n<0 ){
156  std::cerr << "[ERROR] zhematrix::resize(const long&, const long&)"
157  << std::endl
158  << "Matrix sizes must be positive integers." << std::endl
159  << "Your input was (" << _n << ")." << std::endl;
160  exit(1);
161  }
162 #endif//CPPL_DEBUG
163 
164  N =_n;
165  delete [] Array;
166  Array =new std::complex<double>[N*N];
167  delete [] Darray;
168  Darray =new std::complex<double>*[N];
169  for(int i=0; i<N; i++){ Darray[i] =&Array[i*N]; }
170 }
171 
172 //=============================================================================
174 inline void swap(zhematrix& A, zhematrix& B)
175 {
176 #ifdef CPPL_VERBOSE
177  std::cerr << "# [MARK] swap(zhematrix&, zhematrix&)"
178  << std::endl;
179 #endif//CPPL_VERBOSE
180 
181  long A_n(A.N);
182  std::complex<double>* A_array(A.Array);
183  std::complex<double>** A_darray = A.Darray; // std::complex<double>** A_darray(A.Darray);
184  A.N=B.N; A.Array=B.Array; A.Darray=B.Darray;
185  B.N=A_n; B.Array=A_array; B.Darray=A_darray;
186 }
187 
188 //=============================================================================
190 inline _zhematrix _(zhematrix& mat)
191 {
192 #ifdef CPPL_VERBOSE
193  std::cerr << "# [MARK] _(zhematrix&)"
194  << std::endl;
195 #endif//CPPL_VERBOSE
196 
197  _zhematrix newmat;
198 
199  newmat.N =mat.N;
200  newmat.Array =mat.Array;
201  newmat.Darray =mat.Darray;
202 
203  mat.N =0;
204  mat.Array =NULL;
205  mat.Darray =NULL;
206 
207  return newmat;
208 }
(DO NOT USE) Smart-temporary Complex Double-precision Hermitian Matrix Class
Definition: _zhematrix.hpp:3
void shallow_copy(const _zhematrix &)
Definition: zhematrix-misc.hpp:125
void clear()
Definition: zhematrix-misc.hpp:26
void complete() const
Definition: zhematrix-misc.hpp:3
std::complex< double > * Array
1D Array to store matrix data
Definition: _zhematrix.hpp:8
void identity()
Definition: zhematrix-misc.hpp:62
void copy(const zhematrix &)
Definition: zhematrix-misc.hpp:95
std::complex< double > ** Darray
array of pointers of column head addresses
Definition: _zhematrix.hpp:9
friend _zgematrix i(const zhematrix &)
Definition: zhematrix-calc.hpp:20
void chsign()
Definition: zhematrix-misc.hpp:79
std::complex< double > * Array
1D Array to store vector data
Definition: _zrovector.hpp:8
Complex Double-precision Hermitian Matrix Class [L-type (UPLO=L) Strage].
Definition: zhematrix.hpp:4
long N
matrix column or row size
Definition: _zhematrix.hpp:7
void resize(const long &)
Definition: zhematrix-misc.hpp:147
void zero()
Definition: zhematrix-misc.hpp:48