CPPLapack
 All Classes Files Functions Variables Friends Pages
zhematrix-misc.hpp
Go to the documentation of this file.
1 //=============================================================================
2 /*! complete the upper-right components */
3 inline void zhematrix::complete() const
4 {CPPL_VERBOSE_REPORT;
5  for(CPPL_INT i=0; i<n; i++){
6  for(CPPL_INT j=0; j<i; j++){
7  darray[i][j] =std::conj(darray[j][i]);
8  }
9 #ifdef CPPL_DEBUG
10  if(std::fabs(std::imag(operator()(i,i))) > DBL_MIN){
11  WARNING_REPORT;
12  std::cerr << "The " << i << "th diagonal component of the zhematrix is not a real number." << std::endl;
13  }
14 #endif//CPPL_DEBUG
15  }
16 }
17 
18 //=============================================================================
19 /*! clear all the matrix data and set the sizes 0 */
20 inline void zhematrix::clear()
21 {CPPL_VERBOSE_REPORT;
22  n =0;
23  delete [] array;
24  array =NULL;
25  delete [] darray;
26  darray =NULL;
27 }
28 
29 //=============================================================================
30 /*! change the matrix into a zero matrix */
32 {CPPL_VERBOSE_REPORT;
33  for(CPPL_INT j=0; j<n; j++){
34  for(CPPL_INT i=j; i<n; i++){
35  darray[j][i]=comple(0.,0.);
36  }
37  }
38  return *this;
39 }
40 
41 //=============================================================================
42 /*! change the matrix into an identity matrix */
44 {CPPL_VERBOSE_REPORT;
45  for(CPPL_INT j=0; j<n; j++){
46  darray[j][j] =comple(1.,0.);
47  for(CPPL_INT i=j+1; i<n; i++){
48  darray[j][i]=comple(0.,0.);
49  }
50  }
51  return *this;
52 }
53 
54 //=============================================================================
55 /*! change sign(+/-) of the matrix */
56 inline void zhematrix::chsign()
57 {CPPL_VERBOSE_REPORT;
58  for(CPPL_INT j=0; j<n; j++){
59  for(CPPL_INT i=j; i<n; i++){
60  darray[j][i] =-darray[j][i];
61  }
62  }
63 }
64 
65 //=============================================================================
66 /*! make a deep copy of the matrix */
67 inline void zhematrix::copy(const zhematrix& mat)
68 {CPPL_VERBOSE_REPORT;
69  n =mat.n;
70  delete [] array;
71  array =new comple[n*n];
72  delete [] darray;
73  darray =new comple*[n];
74  for(int i=0; i<n; i++){
75  darray[i] =&array[i*n];
76  }
77 
78  for(CPPL_INT j=0; j<n; j++){
79  for(CPPL_INT i=j; i<n; i++){
80  darray[j][i] =mat.darray[j][i];
81  }
82  }
83 }
84 
85 //=============================================================================
86 /*! make a shallow copy of the matrix\n
87  This function is not designed to be used in project codes. */
88 inline void zhematrix::shallow_copy(const _zhematrix& mat)
89 {CPPL_VERBOSE_REPORT;
90  n =mat.n;
91  delete [] array;
92  array =mat.array;
93  delete [] darray;
94  darray =mat.darray;
95 
96  mat.nullify();
97 }
98 
99 //=============================================================================
100 /*! resize the matrix */
101 inline void zhematrix::resize(const CPPL_INT& _n)
102 {CPPL_VERBOSE_REPORT;
103 #ifdef CPPL_DEBUG
104  if( _n<0 ){
105  ERROR_REPORT;
106  std::cerr << "Matrix sizes must be positive integers." << std::endl
107  << "Your input was (" << _n << ")." << std::endl;
108  exit(1);
109  }
110 #endif//CPPL_DEBUG
111 
112  n =_n;
113  delete [] array;
114  array =new comple[n*n];
115  delete [] darray;
116  darray =new comple*[n];
117  for(int i=0; i<n; i++){
118  darray[i] =&array[i*n];
119  }
120 }
121 
122 ///////////////////////////////////////////////////////////////////////////////
123 ///////////////////////////////////////////////////////////////////////////////
124 ///////////////////////////////////////////////////////////////////////////////
125 
126 //=============================================================================
127 /*! get row of the matrix */
128 inline _zrovector zhematrix::row(const CPPL_INT& _m) const
129 {CPPL_VERBOSE_REPORT;
130 #ifdef CPPL_DEBUG
131  if( _m<0 || _m>m ){
132  ERROR_REPORT;
133  std::cerr << "Input row number must be between 0 and " << m << "." << std::endl
134  << "Your input was " << _m << "." << std::endl;
135  exit(1);
136  }
137 #endif//CPPL_DEBUG
138 
139  zrovector v(n);
140  for(CPPL_INT j=0; j<n; j++){
141  v(j)=(*this)(_m,j);
142  }
143  return _(v);
144 }
145 
146 //=============================================================================
147 /*! get column of the matrix */
148 inline _zcovector zhematrix::col(const CPPL_INT& _n) const
149 {CPPL_VERBOSE_REPORT;
150 #ifdef CPPL_DEBUG
151  if( _n<0 || _n>n ){
152  ERROR_REPORT;
153  std::cerr << "Input row number must be between 0 and " << n << "." << std::endl
154  << "Your input was " << _n << "." << std::endl;
155  exit(1);
156  }
157 #endif//CPPL_DEBUG
158 
159  zcovector v(m);
160  for(CPPL_INT i=0; i<m; i++){
161  v(i)=(*this)(i,_n);
162  }
163  return _(v);
164 }
165 
166 ///////////////////////////////////////////////////////////////////////////////
167 ///////////////////////////////////////////////////////////////////////////////
168 ///////////////////////////////////////////////////////////////////////////////
169 
170 //=============================================================================
171 /*! swap two matrices */
172 inline void swap(zhematrix& A, zhematrix& B)
173 {CPPL_VERBOSE_REPORT;
174  CPPL_INT A_n =A.n;
175  comple* A_array =A.array;
176  comple** A_darray =A.darray;
177  A.n=B.n; A.array=B.array; A.darray=B.darray;
178  B.n=A_n; B.array=A_array; B.darray=A_darray;
179 }
180 
181 //=============================================================================
182 /*! convert user object to smart-temporary object */
183 inline _zhematrix _(zhematrix& mat)
184 {CPPL_VERBOSE_REPORT;
185  _zhematrix newmat;
186 
187  //////// shallow copy ////////
188  newmat.n =mat.n;
189  newmat.array =mat.array;
190  newmat.darray =mat.darray;
191 
192  //////// nullify ////////
193  mat.n =0;
194  mat.array =NULL;
195  mat.darray =NULL;
196 
197  return newmat;
198 }
(DO NOT USE) Smart-temporary Complex Double-precision Hermitian Matrix Class
Definition: _zhematrix.hpp:3
void shallow_copy(const _zhematrix &)
zhematrix & identity()
_zcovector col(const CPPL_INT &) const
_zhematrix _(zhematrix &mat)
_zrovector row(const CPPL_INT &) const
zhematrix & zero()
CPPL_INT n
matrix column size
Definition: _zhematrix.hpp:11
void swap(zhematrix &A, zhematrix &B)
void nullify() const
_zcovector conj(const _zcovector &vec)
void complete() const
CPPL_INT const & m
matrix row size
Definition: zhematrix.hpp:10
void copy(const zhematrix &)
CPPL_INT n
matrix column size
Definition: zhematrix.hpp:11
Complex Double-precision Row Vector Class.
Definition: zrovector.hpp:3
(DO NOT USE) Smart-temporary Complex Double-precision Row Vector Class
Definition: _zrovector.hpp:3
friend _zgematrix i(const zhematrix &)
comple * array
1D array to store matrix data
Definition: zhematrix.hpp:12
comple * array
1D array to store matrix data
Definition: _zhematrix.hpp:12
dcovec3 imag(const dquater &q)
void resize(const CPPL_INT &)
friend _zhematrix _(zhematrix &)
Complex Double-precision Hermitian Matrix Class [l-type (UPLO=l) Strage].
Definition: zhematrix.hpp:4
comple ** darray
array of pointers of column head addresses
Definition: zhematrix.hpp:13
comple ** darray
array of pointers of column head addresses
Definition: _zhematrix.hpp:13
Complex Double-precision Column Vector Class.
Definition: zcovector.hpp:3
(DO NOT USE) Smart-temporary Complex Double-precision Column Vector Class
Definition: _zcovector.hpp:3