CPPLapack
 All Classes Files Functions Variables Friends Pages
_zhematrix-io.hpp
Go to the documentation of this file.
1 //=============================================================================
2 /*! operator() for object */
3 inline zhecomplex _zhematrix::operator()(const CPPL_INT& i, const CPPL_INT& j) const
4 {CPPL_VERBOSE_REPORT;
5 #ifdef CPPL_DEBUG
6  if( i<0 || j<0 || n<=i || n<=j ){
7  ERROR_REPORT;
8  std::cerr << "The required component is out of the matrix size." << std::endl
9  << "Your input is (" << i << "," << j << "), whereas the matrix size is (" << n << "," << n << ")." << std::endl;
10  exit(1);
11  }
12 #endif//CPPL_DEBUG
13 
14  if(i>=j){ return zhecomplex(i,j, darray[j][i]); }
15  else { return zhecomplex(i,j, darray[i][j]); }
16 }
17 
18 ///////////////////////////////////////////////////////////////////////////////
19 ///////////////////////////////////////////////////////////////////////////////
20 ///////////////////////////////////////////////////////////////////////////////
21 
22 //=============================================================================
23 inline std::ostream& operator<<(std::ostream& s, const _zhematrix& mat)
24 {CPPL_VERBOSE_REPORT;
25  for(CPPL_INT i=0; i<mat.n; i++){
26  for(CPPL_INT j=0; j<mat.n; j++){
27  if(i>j){
28  s << " " << mat(i,j) << " ";
29  }
30  else if(i==j){
31  s << " " << std::real(mat(i,i)) << " ";
32  }
33  else{
34  s << "{" << std::conj(mat.darray[i][j]) << "} ";
35  }
36  }
37  s << std::endl;
38 
39 #ifdef CPPL_DEBUG
40  if(std::fabs(std::imag(mat(i,i))) > DBL_MIN){
41  WARNING_REPORT;
42  std::cerr << "The " << i << "th diagonal component of the zhematrix is not a real number." << std::endl;
43  }
44 #endif//CPPL_DEBUG
45  }
46 
47  mat.destroy();
48  return s;
49 }
50 
51 ///////////////////////////////////////////////////////////////////////////////
52 ///////////////////////////////////////////////////////////////////////////////
53 ///////////////////////////////////////////////////////////////////////////////
54 
55 //=============================================================================
56 inline void _zhematrix::write(const char* filename) const
57 {CPPL_VERBOSE_REPORT;
58  std::ofstream ofs(filename, std::ios::trunc);
59  ofs.setf(std::cout.flags());
60  ofs.precision(std::cout.precision());
61  ofs.width(std::cout.width());
62  ofs.fill(std::cout.fill());
63 
64  ofs << "#zhematrix " << n << std::endl;
65  for(CPPL_INT i=0; i<n; i++){
66  for(CPPL_INT j=0; j<=i; j++ ){
67  ofs << operator()(i,j) << " ";
68  }
69  ofs << std::endl;
70 
71 #ifdef CPPL_DEBUG
72  if(std::fabs(std::imag(operator()(i,i))) > DBL_MIN){
73  WARNING_REPORT;
74  std::cerr << "The " << i << "th diagonal component of the zhematrix is not a real number." << std::endl;
75  }
76 #endif//CPPL_DEBUG
77  }
78 
79  ofs.close();
80  destroy();
81 }
(DO NOT USE) Smart-temporary Complex Double-precision Hermitian Matrix Class
Definition: _zhematrix.hpp:3
CPPL_INT n
matrix column size
Definition: _zhematrix.hpp:11
_dgematrix i(const _dgbmatrix &mat)
zhecomplex operator()(const CPPL_INT &, const CPPL_INT &) const
std::ostream & operator<<(std::ostream &s, const _zhematrix &mat)
_zcovector conj(const _zcovector &vec)
void write(const char *) const
(DO NOT USE) Complex-double Class for Hermitian matrices
Definition: zhecomplex.hpp:3
void destroy() const
dcovec3 imag(const dquater &q)
comple ** darray
array of pointers of column head addresses
Definition: _zhematrix.hpp:13
friend _zgematrix i(const _zhematrix &)