CPPLapack
 All Classes Files Functions Variables Friends Pages
zcovector_small-functions.hpp
Go to the documentation of this file.
1 //=============================================================================
2 /*! convert zcovector_small to zcovector */
3 template<CPPL_INT l>
5 {CPPL_VERBOSE_REPORT;
6  zcovector vec(l);
7  for(CPPL_INT k=0; k<l; k++){
8  vec(k) =(*this)(k);
9  }
10  return _(vec);
11 }
12 
13 ///////////////////////////////////////////////////////////////////////////////
14 ///////////////////////////////////////////////////////////////////////////////
15 ///////////////////////////////////////////////////////////////////////////////
16 
17 //=============================================================================
18 /*! operator() */
19 template<CPPL_INT l>
20 inline comple& zcovector_small<l>::operator()(const CPPL_INT& k)
21 {CPPL_VERBOSE_REPORT;
22 #ifdef CPPL_DEBUG
23  if( k<0 || l<=k ){
24  ERROR_REPORT;
25  std::cerr << "The required component is out of the vector size." << std::endl
26  << "Your input is (" << k << "), whereas the vector size is " << l << "." << std::endl;
27  exit(1);
28  }
29 #endif//CPPL_DEBUG
30 
31  return array[k];
32 }
33 
34 //=============================================================================
35 /*! operator() for const */
36 template<CPPL_INT l>
37 inline comple zcovector_small<l>::operator()(const CPPL_INT& k) const
38 {CPPL_VERBOSE_REPORT;
39 #ifdef CPPL_DEBUG
40  if( k<0 || l<=k ){
41  ERROR_REPORT;
42  std::cerr << "The required component is out of the vector size." << std::endl
43  << "Your input is (" << k << "), whereas the vector size is " << l << "." << std::endl;
44  exit(1);
45  }
46 #endif//CPPL_DEBUG
47 
48  return array[k];
49 }
50 
51 //=============================================================================
52 /*! set */
53 template<CPPL_INT l>
54 inline zcovector_small<l>& zcovector_small<l>::set(const CPPL_INT& k, const comple& v)
55 {CPPL_VERBOSE_REPORT;
56  (*this)(k) =v;
57  return *this;
58 }
59 
60 //=============================================================================
61 /*! operator<< */
62 template<CPPL_INT l>
63 inline std::ostream& operator<<(std::ostream& s, const zcovector_small<l>& A)
64 {CPPL_VERBOSE_REPORT;
65  s << std::setiosflags(std::ios::showpos);
66  for(CPPL_INT i=0; i<l; i++){
67  s << A(i) << std::endl;
68  }
69  return s;
70 }
71 
72 //=============================================================================
73 /*! write to file */
74 template<CPPL_INT l>
75 inline void zcovector_small<l>::write(const char* filename) const
76 {CPPL_VERBOSE_REPORT;
77  std::ofstream ofs(filename, std::ios::trunc);
78  ofs.setf(std::cout.flags());
79  ofs.precision(std::cout.precision());
80  ofs.width(std::cout.width());
81  ofs.fill(std::cout.fill());
82 
83  ofs << "#zcovector" << " " << l << std::endl;
84  for(CPPL_INT k=0; k<l; k++){
85  ofs << (*this)(k) << std::endl;
86  }
87  ofs.close();
88 }
89 
90 //=============================================================================
91 /*! read from file */
92 template<CPPL_INT l>
93 inline void zcovector_small<l>::read(const char* filename)
94 {CPPL_VERBOSE_REPORT;
95  std::ifstream s( filename );
96  if(!s){
97  ERROR_REPORT;
98  std::cerr << "The file \"" << filename << "\" can not be opened." << std::endl;
99  exit(1);
100  }
101 
102  std::string id;
103  s >> id;
104  if( id != "zcovector" && id != "#zcovector" ){
105  ERROR_REPORT;
106  std::cerr << "The type name of the file \"" << filename << "\" is not zcovector." << std::endl
107  << "Its type name was " << id << " ." << std::endl;
108  exit(1);
109  }
110 
111  CPPL_INT _l;
112  s >> _l;
113  if(l!=_l){
114  ERROR_REPORT;
115  std::cerr << "Matrix size is invalid." << std::endl;
116  exit(1);
117  }
118  for(CPPL_INT k=0; k<l; k++){
119  s >> (*this)(k);
120  }
121  if(s.eof()){
122  ERROR_REPORT;
123  std::cerr << "There is something is wrong with the file \"" << filename << "\"." << std::endl
124  << "Most likely, there is not enough data components, or a linefeed code or space code is missing at the end of the last line." << std::endl;
125  exit(1);
126  }
127 
128  s >> id;//tmp
129  if(!s.eof()){
130  ERROR_REPORT;
131  std::cerr << "There is something is wrong with the file \"" << filename << "\"." << std::endl
132  << "Most likely, there are extra data components." << std::endl;
133  exit(1);
134  }
135 
136  s.close();
137 }
138 
139 ///////////////////////////////////////////////////////////////////////////////
140 ///////////////////////////////////////////////////////////////////////////////
141 ///////////////////////////////////////////////////////////////////////////////
142 ///////////////////////////////////////////////////////////////////////////////
143 ///////////////////////////////////////////////////////////////////////////////
144 ///////////////////////////////////////////////////////////////////////////////
145 
146 //=============================================================================
147 /*! return transposed zrovector_small */
148 template<CPPL_INT l>
150 {CPPL_VERBOSE_REPORT;
152  for(CPPL_INT i=0; i<l; i++){
153  X(i) =A(i);
154  }
155  return X;
156 }
157 
158 //=============================================================================
159 /*! return its 2-norm */
160 template<CPPL_INT l>
161 inline comple nrm2(const zcovector_small<l>& A)
162 {CPPL_VERBOSE_REPORT;
163  comple v(0);
164  for(CPPL_INT i=0; i<l; i++){
165  v+=A(i)*A(i);
166  }
167  return std::sqrt(v);
168 }
169 
170 //=============================================================================
171 /*! return index of the maximum component */
172 template<CPPL_INT l>
173 inline void idamax(CPPL_INT& K, const zcovector_small<l>& A)
174 {CPPL_VERBOSE_REPORT;
175  comple max(-1.);
176  for(int k=0; k<l; k++){
177  if( max<fabs(A(k)) ){
178  K=k;
179  max =fabs(A(k));
180  }
181  }
182  return;
183 }
184 
185 //=============================================================================
186 /*! return the maximum component */
187 template<CPPL_INT l>
188 inline comple damax(const zcovector_small<l>& A)
189 {CPPL_VERBOSE_REPORT;
190  CPPL_INT k(0);
191  idamax(k,A);
192  return A(k);
193 }
194 
195 ///////////////////////////////////////////////////////////////////////////////
196 ///////////////////////////////////////////////////////////////////////////////
197 ///////////////////////////////////////////////////////////////////////////////
198 
199 //=============================================================================
200 /*! zero */
201 template<CPPL_INT l>
203 {CPPL_VERBOSE_REPORT;
204  for(CPPL_INT k=0; k<l; k++){
205  array[k] =0.;
206  }
207  return *this;
208 }
209 
210 ///////////////////////////////////////////////////////////////////////////////
211 ///////////////////////////////////////////////////////////////////////////////
212 ///////////////////////////////////////////////////////////////////////////////
213 
214 //=============================================================================
215 /*! zcovector_small+=zcovector_small operator */
216 template<CPPL_INT l>
218 {CPPL_VERBOSE_REPORT;
219  for(CPPL_INT i=0; i<l; i++){
220  A(i) +=B(i);
221  }
222  return A;
223 }
224 
225 //=============================================================================
226 /*! zcovector_small-=zcovector_small operator */
227 template<CPPL_INT l>
229 {CPPL_VERBOSE_REPORT;
230  for(CPPL_INT i=0; i<l; i++){
231  A(i) -=B(i);
232  }
233  return A;
234 }
235 
236 //=============================================================================
237 /*! zcovector_small*=double operator */
238 template<CPPL_INT l>
240 {CPPL_VERBOSE_REPORT;
241  for(CPPL_INT i=0; i<l; i++){
242  A(i) *=v;
243  }
244  return A;
245 }
246 
247 //=============================================================================
248 /*! zcovector_small*=comple operator */
249 template<CPPL_INT l>
251 {CPPL_VERBOSE_REPORT;
252  for(CPPL_INT i=0; i<l; i++){
253  A(i) *=v;
254  }
255  return A;
256 }
257 
258 //=============================================================================
259 /*! zcovector_small/=double operator */
260 template<CPPL_INT l>
262 {CPPL_VERBOSE_REPORT;
263  for(CPPL_INT i=0; i<l; i++){
264  A(i) /=v;
265  }
266  return A;
267 }
268 
269 //=============================================================================
270 /*! zcovector_small/=comple operator */
271 template<CPPL_INT l>
273 {CPPL_VERBOSE_REPORT;
274  for(CPPL_INT i=0; i<l; i++){
275  A(i) /=v;
276  }
277  return A;
278 }
279 
280 ///////////////////////////////////////////////////////////////////////////////
281 ///////////////////////////////////////////////////////////////////////////////
282 ///////////////////////////////////////////////////////////////////////////////
283 
284 //=============================================================================
285 /*! unary + operator */
286 template<CPPL_INT l>
288 {CPPL_VERBOSE_REPORT;
289  return A;
290 }
291 
292 //=============================================================================
293 /*! unary - operator */
294 template<CPPL_INT l>
296 {CPPL_VERBOSE_REPORT;
298  for(CPPL_INT i=0; i<l; i++){
299  X(i) =-A(i);
300  }
301  return X;
302 }
303 
304 ///////////////////////////////////////////////////////////////////////////////
305 ///////////////////////////////////////////////////////////////////////////////
306 ///////////////////////////////////////////////////////////////////////////////
307 
308 //=============================================================================
309 /*! zcovector_small+zcovector_small operator */
310 template<CPPL_INT l>
312 {CPPL_VERBOSE_REPORT;
314  for(CPPL_INT i=0; i<l; i++){
315  X(i) =A(i)+B(i);
316  }
317  return X;
318 }
319 
320 //=============================================================================
321 /*! zcovector_small-zcovector_small operator */
322 template<CPPL_INT l>
324 {CPPL_VERBOSE_REPORT;
326  for(CPPL_INT i=0; i<l; i++){
327  X(i) =A(i)-B(i);
328  }
329  return X;
330 }
331 
332 ///////////////////////////////////////////////////////////////////////////////
333 ///////////////////////////////////////////////////////////////////////////////
334 ///////////////////////////////////////////////////////////////////////////////
335 
336 //=============================================================================
337 /*! zcovector_small*double operator */
338 template<CPPL_INT n>
339 inline zcovector_small<n> operator*(const zcovector_small<n>& A, const double& v)
340 {CPPL_VERBOSE_REPORT;
342  for(CPPL_INT i=0; i<n; i++){
343  C(i) =A(i)*v;
344  }
345  return C;
346 }
347 
348 //=============================================================================
349 /*! zcovector_small*comple operator */
350 template<CPPL_INT n>
351 inline zcovector_small<n> operator*(const zcovector_small<n>& A, const comple& v)
352 {CPPL_VERBOSE_REPORT;
354  for(CPPL_INT i=0; i<n; i++){
355  C(i) =A(i)*v;
356  }
357  return C;
358 }
359 
360 //=============================================================================
361 /*! zcovector_small*zrovector_small operator */
362 template<CPPL_INT m, CPPL_INT n>
364 {CPPL_VERBOSE_REPORT;
366  for(CPPL_INT i=0; i<m; i++){
367  for(CPPL_INT j=0; j<n; j++){
368  mat(i,j) =A(i)*B(j);
369  }
370  }
371  return mat;
372 }
373 
374 ///////////////////////////////////////////////////////////////////////////////
375 ///////////////////////////////////////////////////////////////////////////////
376 ///////////////////////////////////////////////////////////////////////////////
377 
378 //=============================================================================
379 /*! zcovector_small/double operator */
380 template<CPPL_INT n>
381 inline zcovector_small<n> operator/(const zcovector_small<n>& A, const double& v)
382 {CPPL_VERBOSE_REPORT;
384  for(CPPL_INT i=0; i<n; i++){
385  C(i) =A(i)/v;
386  }
387  return C;
388 }
389 
390 //=============================================================================
391 /*! zcovector_small/comple operator */
392 template<CPPL_INT n>
393 inline zcovector_small<n> operator/(const zcovector_small<n>& A, const comple& v)
394 {CPPL_VERBOSE_REPORT;
396  for(CPPL_INT i=0; i<n; i++){
397  C(i) =A(i)/v;
398  }
399  return C;
400 }
401 
402 ///////////////////////////////////////////////////////////////////////////////
403 ///////////////////////////////////////////////////////////////////////////////
404 ///////////////////////////////////////////////////////////////////////////////
405 
406 //=============================================================================
407 /*! zcovector_small%zcovector_small (inner product) operator */
408 template<CPPL_INT l>
409 inline comple operator%(const zcovector_small<l>& A, const zcovector_small<l>& B)
410 {CPPL_VERBOSE_REPORT;
411  comple v(0.);
412  for(CPPL_INT i=0; i<l; i++){
413  v +=A(i)*B(i);
414  }
415  return v;
416 }
417 
418 ///////////////////////////////////////////////////////////////////////////////
419 ///////////////////////////////////////////////////////////////////////////////
420 ///////////////////////////////////////////////////////////////////////////////
421 
422 //=============================================================================
423 /*! Hadamard product */
424 template<CPPL_INT l>
426 {CPPL_VERBOSE_REPORT;
428  for(CPPL_INT i=0; i<l; i++){
429  C(i) =A(i)*B(i);
430  }
431  return C;
432 }
zcovector_small< n > operator/(const zcovector_small< n > &A, const double &v)
comple & operator()(const CPPL_INT &)
comple operator%(const zcovector_small< l > &A, const zcovector_small< l > &B)
_dgematrix i(const _dgbmatrix &mat)
zcovector_small< l > hadamard(const zcovector_small< l > &A, const zcovector_small< l > &B)
zcovector_small< l > & operator*=(zcovector_small< l > &A, const double &v)
comple nrm2(const zcovector_small< l > &A)
Samll Complex Double-precision Column Vector Class.
zcovector_small< l > & set(const CPPL_INT &, const comple &)
Samll Complex Double-precision Row Vector Class.
zcovector_small< l > & zero()
zcovector_small< l > operator-(const zcovector_small< l > &A)
void idamax(CPPL_INT &K, const zcovector_small< l > &A)
comple damax(const zcovector_small< l > &A)
void write(const char *filename) const
zrovector_small< l > t(const zcovector_small< l > &A)
_zcovector to_zcovector() const
void read(const char *filename)
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
zcovector_small< l > & operator/=(zcovector_small< l > &A, const double &v)
zcovector_small< l > & operator-=(zcovector_small< l > &A, const zcovector_small< l > &B)
_dcovector _(dcovector &vec)
zcovector_small< l > & operator+=(zcovector_small< l > &A, const zcovector_small< l > &B)
zcovector_small< n > operator*(const zcovector_small< n > &A, const double &v)
Samll Complex Double-precision General Dence Matrix Class.
const zcovector_small< l > & operator+(const zcovector_small< l > &A)