CPPLapack
 All Classes Files Functions Variables Friends Pages
zgbmatrix-misc.hpp
Go to the documentation of this file.
1 //=============================================================================
2 /*! clear all the matrix data and set the sizes 0 */
3 inline void zgbmatrix::clear()
4 {CPPL_VERBOSE_REPORT;
5  m =0;
6  n =0;
7  kl =0;
8  ku =0;
9  delete [] array;
10  array =NULL;
11  delete [] darray;
12  darray =NULL;
13 }
14 
15 
16 //=============================================================================
17 /*! change the matrix into a zero matrix */
19 {CPPL_VERBOSE_REPORT;
20  const CPPL_INT size =(kl+ku+1)*n;
21  for(CPPL_INT i=0; i<size; i++){
22  array[i] =comple(0.,0.);
23  }
24  return *this;
25 }
26 
27 //=============================================================================
28 /*! change the matrix into an identity matrix */
30 {CPPL_VERBOSE_REPORT;
31 #ifdef CPPL_DEBUG
32  if(m!=n){
33  ERROR_REPORT;
34  std::cerr << "Only square matrix can be a identity matrix." << std::endl
35  << "The matrix size was " << m << "x" << n << "." << std::endl;
36  exit(1);
37  }
38 #endif//CPPL_DEBUG
39 
40  const CPPL_INT size =(kl+ku+1)*n;
41  for(CPPL_INT i=0; i<size; i++){
42  array[i] =comple(0.,0.);
43  }
44  for(CPPL_INT i=0; i<m; i++){
45  operator()(i,i) =comple(1.,0.);
46  }
47 
48  return *this;
49 }
50 
51 //=============================================================================
52 /*! change sign(+/-) of the matrix */
53 inline void zgbmatrix::chsign()
54 {CPPL_VERBOSE_REPORT;
55  const CPPL_INT size =(kl+ku+1)*n;
56  for(CPPL_INT i=0; i<size; i++){
57  array[i] =-array[i];
58  }
59 }
60 
61 //=============================================================================
62 /*! make a deep copy of the matrix */
63 inline void zgbmatrix::copy(const zgbmatrix& mat)
64 {CPPL_VERBOSE_REPORT;
65  m =mat.m;
66  n =mat.n;
67  kl =mat.kl;
68  ku =mat.ku;
69  delete [] array;
70  array =new comple[(mat.kl+mat.ku+1)*mat.n];
71  delete [] darray;
72  darray =new comple*[n];
73  for(int i=0; i<n; i++){
74  darray[i] =&array[i*(kl+ku+1)];
75  }
76 
77  CPPL_INT size =(mat.kl+mat.ku+1)*mat.n;
78  CPPL_INT inc =1;
79  zcopy_(&size, mat.array, &inc, array, &inc);
80 }
81 
82 //=============================================================================
83 /*! make a shallow copy of the matrix\n
84  This function is not designed to be used in project codes. */
85 inline void zgbmatrix::shallow_copy(const _zgbmatrix& mat)
86 {CPPL_VERBOSE_REPORT;
87  m =mat.m;
88  n =mat.n;
89  kl =mat.kl;
90  ku =mat.ku;
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 zgbmatrix::resize(const CPPL_INT& _m, const CPPL_INT& _n,
102  const CPPL_INT& _kl, const CPPL_INT& _ku)
103 {CPPL_VERBOSE_REPORT;
104 #ifdef CPPL_DEBUG
105  if( _m<0 || _n<0 || _kl<0 || _ku<0 || _m<_kl || _n<_ku ){
106  ERROR_REPORT;
107  std::cerr << "It is impossible to make a matrix you ordered. " << std::endl
108  << "Your input was (" << _m << "," << _n << ","<< _ku << "," << _kl << ")." << std::endl;
109  exit(1);
110  }
111 #endif//CPPL_DEBUG
112 
113  m =_m;
114  n =_n;
115  kl =_kl;
116  ku =_ku;
117  delete [] array;
118  array =new comple[(kl+ku+1)*n];
119  delete [] darray;
120  darray =new comple*[n];
121  for(int i=0; i<n; i++){
122  darray[i] =&array[i*(kl+ku+1)];
123  }
124 }
125 
126 ///////////////////////////////////////////////////////////////////////////////
127 ///////////////////////////////////////////////////////////////////////////////
128 ///////////////////////////////////////////////////////////////////////////////
129 
130 //=============================================================================
131 /*! get row of the matrix */
132 inline _zrovector zgbmatrix::row(const CPPL_INT& _m) const
133 {CPPL_VERBOSE_REPORT;
134 #ifdef CPPL_DEBUG
135  if( _m<0 || _m>m ){
136  ERROR_REPORT;
137  std::cerr << "Input row number must be between 0 and " << m << "." << std::endl
138  << "Your input was " << _m << "." << std::endl;
139  exit(1);
140  }
141 #endif//CPPL_DEBUG
142 
143  zrovector v =zrovector(n).zero();
144 
145  const CPPL_INT jmax =std::min(n,_m+ku+1);
146  for(CPPL_INT j=std::max(CPPL_INT(0),_m-kl); j<jmax; j++){
147  v(j)=(*this)(_m,j);
148  }
149 
150  return _(v);
151 }
152 
153 //=============================================================================
154 /*! get column of the matrix */
155 inline _zcovector zgbmatrix::col(const CPPL_INT& _n) const
156 {CPPL_VERBOSE_REPORT;
157 #ifdef CPPL_DEBUG
158  if( _n<0 || _n>n ){
159  ERROR_REPORT;
160  std::cerr << "Input row number must be between 0 and " << n << "." << std::endl
161  << "Your input was " << _n << "." << std::endl;
162  exit(1);
163  }
164 #endif//CPPL_DEBUG
165 
166  zcovector v =zcovector(m).zero();
167 
168  const CPPL_INT imax =std::min(m,_n+kl+1);
169  for(CPPL_INT i=std::max(CPPL_INT(0),_n-ku); i<imax; i++){
170  v(i)=(*this)(i,_n);
171  }
172 
173  return _(v);
174 }
175 
176 ///////////////////////////////////////////////////////////////////////////////
177 ///////////////////////////////////////////////////////////////////////////////
178 ///////////////////////////////////////////////////////////////////////////////
179 
180 //=============================================================================
181 /*! swap two matrices */
182 inline void swap(zgbmatrix& A, zgbmatrix& B)
183 {CPPL_VERBOSE_REPORT;
184  CPPL_INT A_m =A.m, A_n =A.n, A_kl =A.kl, A_ku =A.ku;
185  comple* A_array =A.array;
186  comple** A_darray =A.darray;
187 
188  A.m=B.m; A.n=B.n; A.kl=B.kl; A.ku=B.ku; A.array=B.array; A.darray=B.darray;
189  B.m=A_m; B.n=A_n; B.kl=A_kl; B.ku=A_ku; B.array=A_array; B.darray=A_darray;
190 }
191 
192 //=============================================================================
193 /*! convert user object to smart-temporary object */
194 inline _zgbmatrix _(zgbmatrix& mat)
195 {CPPL_VERBOSE_REPORT;
196  _zgbmatrix newmat;
197 
198  //////// shallow copy ////////
199  newmat.m =mat.m;
200  newmat.n =mat.n;
201  newmat.kl =mat.kl;
202  newmat.ku =mat.ku;
203  newmat.array =mat.array;
204  newmat.darray =mat.darray;
205 
206  //////// nullify ////////
207  mat.m =0;
208  mat.n =0;
209  mat.kl =0;
210  mat.ku =0;
211  mat.array =NULL;
212  mat.darray =NULL;
213 
214  return newmat;
215 }
CPPL_INT ku
upper band width
Definition: _zgbmatrix.hpp:12
zgbmatrix & identity()
comple & operator()(const CPPL_INT &, const CPPL_INT &)
Definition: zgbmatrix-io.hpp:3
zcovector & zero()
zgbmatrix & zero()
friend _zgematrix i(const zgbmatrix &)
void clear()
CPPL_INT kl
lower band width
Definition: _zgbmatrix.hpp:11
_zrovector row(const CPPL_INT &) const
comple ** darray
array of pointers of column head addresses
Definition: zgbmatrix.hpp:14
void copy(const zgbmatrix &)
_zgbmatrix _(zgbmatrix &mat)
CPPL_INT n
matrix column size
Definition: zgbmatrix.hpp:10
CPPL_INT ku
upper band width
Definition: zgbmatrix.hpp:12
void resize(const CPPL_INT &, const CPPL_INT &, const CPPL_INT &, const CPPL_INT &)
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
CPPL_INT m
matrix row size
Definition: zgbmatrix.hpp:9
Complex Double-precision General Band Matrix Class.
Definition: zgbmatrix.hpp:3
(DO NOT USE) Smart-temporary Complex Double-precision General Band Matrix Class
Definition: _zgbmatrix.hpp:3
void swap(zgbmatrix &A, zgbmatrix &B)
CPPL_INT kl
lower band width
Definition: zgbmatrix.hpp:11
CPPL_INT m
matrix row size
Definition: _zgbmatrix.hpp:9
comple * array
1D array to store matrix data
Definition: _zgbmatrix.hpp:13
void nullify() const
comple ** darray
array of pointers of column head addresses
Definition: _zgbmatrix.hpp:14
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
CPPL_INT n
matrix column size
Definition: _zgbmatrix.hpp:10
friend _zgbmatrix _(zgbmatrix &)
_zcovector col(const CPPL_INT &) const
zrovector & zero()
comple * array
1D array to store matrix data
Definition: zgbmatrix.hpp:13
void shallow_copy(const _zgbmatrix &)