VERB_code_2.3
dgbmatrix-misc.hpp
1 //=============================================================================
3 inline void dgbmatrix::clear()
4 {
5 #ifdef CPPL_VERBOSE
6  std::cerr << "# [MARK] dgbmatrix::clear()"
7  << std::endl;
8 #endif//CPPL_VERBOSE
9 
10 #ifdef CPPL_DEBUG
11  std::cerr << "# [NOTE] dgbmatrix::clear() "
12  << " An array at " << Array
13  << " is going to be cleared." << std::endl;
14 #endif//CPPL_DEBUG
15 
16  M =0;
17  N =0;
18  KL =0;
19  KU =0;
20  delete [] Array;
21  Array =NULL;
22  delete [] Darray;
23  Darray =NULL;
24 }
25 
26 
27 //=============================================================================
29 inline void dgbmatrix::zero()
30 {
31 #ifdef CPPL_VERBOSE
32  std::cerr << "# [MARK] dgbmatrix::zero()"
33  << std::endl;
34 #endif//CPPL_VERBOSE
35 
36  for(long i=0; i<(KL+KU+1)*N; i++){ Array[i] =0.0; }
37 }
38 
39 //=============================================================================
41 inline void dgbmatrix::identity()
42 {
43 #ifdef CPPL_VERBOSE
44  std::cerr << "# [MARK] dgbmatrix::identity()"
45  << std::endl;
46 #endif//CPPL_VERBOSE
47 
48 #ifdef CPPL_DEBUG
49  if(M!=N){
50  std::cerr << "[ERROR] dgbmatrix::identity()" << std::endl
51  << "Only square matrix can be a identity matrix." << std::endl
52  << "The matrix size was " << M << "x" << N << "." << std::endl;
53  exit(1);
54  }
55 #endif//CPPL_DEBUG
56 
57  for(long i=0; i<(KL+KU+1)*N; i++){ Array[i] =0.0; }
58  for(long i=0; i<M; i++){ operator()(i,i) =1.0; }
59 }
60 
61 //=============================================================================
63 inline void dgbmatrix::chsign()
64 {
65 #ifdef CPPL_VERBOSE
66  std::cerr << "# [MARK] dgbmatrix::chsign()"
67  << std::endl;
68 #endif//CPPL_VERBOSE
69 
70  for(long i=0; i<(KL+KU+1)*N; i++){ Array[i] =-Array[i]; }
71 }
72 //=============================================================================
74 inline void dgbmatrix::copy(const dgbmatrix& mat)
75 {
76 #ifdef CPPL_VERBOSE
77  std::cerr << "# [MARK] dgbmatrix::copy(const dgbmatrix&)"
78  << std::endl;
79 #endif//CPPL_VERBOSE
80 
81 #ifdef CPPL_DEBUG
82  std::cerr << "# [NOTE] dgbmatrix::copy(const dgbmatrix&) "
83  << "A dgbmatrix at " << Array << " is going to be deleted. ";
84 #endif//CPPL_DEBUG
85 
86  M =mat.M;
87  N =mat.N;
88  KL =mat.KL;
89  KU =mat.KU;
90  delete [] Array;
91  Array =new double[(mat.KL+mat.KU+1)*mat.N];
92  delete [] Darray;
93  Darray =new double*[N];
94  for(int i=0; i<N; i++){ Darray[i] =&Array[i*(KL+KU+1)]; }
95 
96  dcopy_((mat.KL+mat.KU+1)*mat.N, mat.Array, 1, Array, 1);
97 
98 #ifdef CPPL_DEBUG
99  std::cerr << "Then, a COPY of a dgbmatrix has been cleated at "
100  << Array << "." << std::endl;
101 #endif//CPPL_DEBUG
102 }
103 
104 //=============================================================================
107 inline void dgbmatrix::shallow_copy(const _dgbmatrix& mat)
108 {
109 #ifdef CPPL_VERBOSE
110  std::cerr << "# [MARK] dgbmatrix::shallow_copy(const _dgbmatrix&)"
111  << std::endl;
112 #endif//CPPL_VERBOSE
113 
114 #ifdef CPPL_DEBUG
115  std::cerr << "# [NOTE] dgbmatrix::shallow_copy(const dgbmatrix&) "
116  << "A dgbmatrix at " << Array << " is going to be deleted "
117  << "and point at " << mat.Array << " instead." << std::endl;
118 #endif//CPPL_DEBUG
119 
120  M =mat.M;
121  N =mat.N;
122  KL =mat.KL;
123  KU =mat.KU;
124  delete [] Array;
125  Array =mat.Array;
126  delete [] Darray;
127  Darray =mat.Darray;
128 }
129 
130 //=============================================================================
132 inline void dgbmatrix::resize(const long& _m, const long& _n,
133  const long& _kl, const long& _ku)
134 {
135 #ifdef CPPL_VERBOSE
136  std::cerr << "# [MARK] dgbmatrix::resize(const long&, const long&, const long&, const long&)"
137  << std::endl;
138 #endif//CPPL_VERBOSE
139 
140 #ifdef CPPL_DEBUG
141  if( _m<0 || _n<0 || _kl<0 || _ku<0 || _m<_kl || _n<_ku ){
142  std::cerr << "[ERROR] dgbmatrix::resize"
143  << "(const long&, const long&, const long&, const long&)"
144  << std::endl
145  << "It is impossible to make a matrix you ordered. "
146  << std::endl
147  << "Your input was ("
148  << _m << "," << _n << ","<< _ku << "," << _kl << ")."
149  << std::endl;
150  exit(1);
151  }
152 #endif//CPPL_DEBUG
153 
154  M =_m;
155  N =_n;
156  KL =_kl;
157  KU =_ku;
158  delete [] Array;
159  Array =new double[(KL+KU+1)*N];
160  delete [] Darray;
161  Darray =new double*[N];
162  for(int i=0; i<N; i++){ Darray[i] =&Array[i*(KL+KU+1)]; }
163 }
164 
165 //=============================================================================
167 inline void swap(dgbmatrix& A, dgbmatrix& B)
168 {
169 #ifdef CPPL_VERBOSE
170  std::cerr << "# [MARK] swap(dgbmatrix&, dgbmatrix&)"
171  << std::endl;
172 #endif//CPPL_VERBOSE
173 
174  long A_m(A.M), A_n(A.N), A_kl(A.KL), A_ku(A.KU);
175  double* A_array(A.Array);
176  double** A_darray = A.Darray; // double** A_darray(A.Darray);
177  A.M=B.M; A.N=B.N; A.KL=B.KL; A.KU=B.KU; A.Array=B.Array; A.Darray=B.Darray;
178  B.M=A_m; B.N=A_n; B.KL=A_kl; B.KU=A_ku; B.Array=A_array; B.Darray=A_darray;
179 }
180 
181 //=============================================================================
183 inline _dgbmatrix _(dgbmatrix& mat)
184 {
185 #ifdef CPPL_VERBOSE
186  std::cerr << "# [MARK] _(dgbmatrix&)"
187  << std::endl;
188 #endif//CPPL_VERBOSE
189 
190  _dgbmatrix newmat;
191 
192  newmat.M =mat.M;
193  newmat.N =mat.N;
194  newmat.KL =mat.KL;
195  newmat.KU =mat.KU;
196  newmat.Array =mat.Array;
197  newmat.Darray =mat.Darray;
198 
199  mat.M =0;
200  mat.N =0;
201  mat.KL =0;
202  mat.KU =0;
203  mat.Array =NULL;
204  mat.Darray =NULL;
205 
206  return newmat;
207 }
friend _dgematrix i(const dgbmatrix &)
Definition: dgbmatrix-calc.hpp:22
long KL
lower band width
Definition: _dgbmatrix.hpp:9
void shallow_copy(const _dgbmatrix &)
Definition: dgbmatrix-misc.hpp:107
long M
matrix row size
Definition: _dgbmatrix.hpp:7
double & operator()(const long &, const long &)
Definition: dgbmatrix-io.hpp:3
long N
matrix column size
Definition: _dgbmatrix.hpp:8
double * Array
1D Array to store matrix data
Definition: _dgbmatrix.hpp:11
double ** Darray
array of pointers of column head addresses
Definition: _dgbmatrix.hpp:12
Real Double-precision General Band Matrix Class.
Definition: dgbmatrix.hpp:3
void clear()
Definition: dgbmatrix-misc.hpp:3
void identity()
Definition: dgbmatrix-misc.hpp:41
void copy(const dgbmatrix &)
Definition: dgbmatrix-misc.hpp:74
void zero()
Definition: dgbmatrix-misc.hpp:29
void chsign()
Definition: dgbmatrix-misc.hpp:63
(DO NOT USE) Smart-temporary Real Double-precision General Band Matrix Class
Definition: _dgbmatrix.hpp:3
void resize(const long &, const long &, const long &, const long &)
Definition: dgbmatrix-misc.hpp:132
double * Array
1D Array to store vector data
Definition: _drovector.hpp:8
long KU
upper band width
Definition: _dgbmatrix.hpp:10