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