My Project
_zhematrix-io.hpp
1 //=============================================================================
3 inline __zhecomplex _zhematrix::operator()(const long& i, const long& j) const
4 {
5 #ifdef CPPL_VERBOSE
6  std::cerr << "# [MARK] _zhematrix::operator()(const long&, const long&) const"
7  << std::endl;
8 #endif//CPPL_VERBOSE
9 
10 #ifdef CPPL_DEBUG
11  if( i<0 || j<0 || N<=i || N<=j ){
12  std::cerr << "[ERROR] _zhematrix::operator()(long, long) const"
13  << std::endl
14  << "The required component is out of the matrix size."
15  << std::endl
16  << "Your input was (" << i << "," << j << ")." << std::endl;
17  exit(1);
18  }
19 #endif//CPPL_DEBUG
20 
21  //if(i>=j){ return __zhecomplex( Array[i+N*j], i, j ); }
22  //else { return __zhecomplex( Array[j+N*i], i, j ); }
23  if(i>=j){ return __zhecomplex( Darray[j][i], i, j ); }
24  else { return __zhecomplex( Darray[i][j], i, j ); }
25 }
26 
30 
31 //=============================================================================
32 inline std::ostream& operator<<(std::ostream& s, const _zhematrix& mat)
33 {
34 #ifdef CPPL_VERBOSE
35  std::cerr << "# [MARK] operator<<(std::ostream&, const _zhematrix&)"
36  << std::endl;
37 #endif//CPPL_VERBOSE
38 
39  for(long i=0; i<mat.N; i++){
40  for(long j=0; j<mat.N; j++){
41  if(i>j){ s << " " << mat(i,j) << " "; }
42  else if(i==j){ s << " " << std::real(mat(i,i)) << " "; }
43  else{ s << "{" << std::conj(mat(j,i)) << "} "; }
44  }
45  s << std::endl;
46 
47 #ifdef CPPL_DEBUG
48  if(std::fabs(std::imag(mat(i,i))) > CPPL_EPS){
49  std::cerr << "[WARNING] operator<<(std::ostream&, const _zhematrix&)"
50  << std::endl
51  << "The " << i << "th diagonal component of the zhematrix"
52  << "is not a real number." << std::endl;
53  }
54 #endif//CPPL_DEBUG
55  }
56 
57  mat.destroy();
58  return s;
59 }
60 
64 
65 //=============================================================================
66 inline void _zhematrix::write(const char* filename) const
67 {
68 #ifdef CPPL_VERBOSE
69  std::cerr << "# [MARK] _zhematrix::write(const char*) const"
70  << std::endl;
71 #endif//CPPL_VERBOSE
72 
73  std::ofstream s(filename, std::ios::trunc);
74 
75  s << "zhematrix" << " " << N << std::endl;
76  for(long i=0; i<N; i++){
77  for(long j=0; j<=i; j++ ){
78  s << operator()(i,j) << " ";
79  }
80  s << std::endl;
81 
82 #ifdef CPPL_DEBUG
83  if(std::fabs(std::imag(operator()(i,i))) > CPPL_EPS){
84  std::cerr << "[WARNING] _zhematrix::write(const char*)" << std::endl
85  << "The " << i << "th diagonal component of the zhematrix"
86  << "is not a real number." << std::endl;
87  }
88 #endif//CPPL_DEBUG
89  }
90 
91  s.close();
92  destroy();
93 }
std::complex< double > ** Darray
array of pointers of column head addresses
Definition: _zhematrix.hpp:9
(DO NOT USE) Smart-temporary Complex Double-precision Hermitian Matrix Class
Definition: _zhematrix.hpp:3
void destroy() const
Definition: _zhematrix-misc.hpp:3
long N
matrix column or row size
Definition: _zhematrix.hpp:7
__zhecomplex operator()(const long &, const long &) const
Definition: _zhematrix-io.hpp:3
friend _zgematrix i(const _zhematrix &)
Definition: _zhematrix-calc.hpp:21
(DO NOT USE) Shaddow Complex-double Class for zhematrix
Definition: __zhecomplex.hpp:3