CPPLapack
 All Classes Files Functions Variables Friends Pages
_zhsmatrix-io.hpp
Go to the documentation of this file.
1 //=============================================================================
2 /*! operator() for const object */
3 inline comple _zhsmatrix::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 << "x" << n << "." << std::endl;
10  exit(1);
11  }
12 #endif//CPPL_DEBUG
13 
14  //// search (i,j) component ////
15  const CPPL_INT ii(std::max(i,j)), jj(std::min(i,j));
16 
17  const std::vector<CPPL_INT>::const_iterator line_ii_end =line[ii].end();
18  for(std::vector<CPPL_INT>::const_iterator p=line[ii].begin(); p!=line_ii_end; p++){
19  if(data[*p].j==jj){
20  if( i>j ){ return data[*p].v; }//ii=i
21  else{ return std::conj(data[*p].v); }//ii=j
22  }
23  }
24 
25  //// (i,j) component was not found ////
26  return comple(0.0,0.0);
27 }
28 
29 ///////////////////////////////////////////////////////////////////////////////
30 ///////////////////////////////////////////////////////////////////////////////
31 ///////////////////////////////////////////////////////////////////////////////
32 
33 //=============================================================================
34 inline std::ostream& operator<<(std::ostream& s, const _zhsmatrix& mat)
35 {CPPL_VERBOSE_REPORT;
36  for(CPPL_INT i=0; i<mat.n; i++){
37  for(CPPL_INT j=0; j<mat.n; j++){
38  if( i >= j ){
39  std::vector<CPPL_INT>::iterator q;
40  const std::vector<CPPL_INT>::iterator mat_line_i_end =mat.line[i].end();
41  for(q=mat.line[i].begin(); q!=mat_line_i_end; q++){
42  if( mat.data[*q].j==j ){ break; }
43  }
44  if(q!=mat_line_i_end){ s << " " << mat.data[*q].v << " "; }
45  else{ s << " x "; }
46  }
47  else{//i<j
48  std::vector<CPPL_INT>::iterator q;
49  const std::vector<CPPL_INT>::iterator mat_line_i_end =mat.line[i].end();
50  for(q=mat.line[i].begin(); q!=mat_line_i_end; q++){
51  if( mat.data[*q].j==j ){ break; }
52  }
53  if(q!=mat_line_i_end){ s << "{" << mat.data[*q].v << "}"; }
54  else{ s << "{x}"; }
55  }
56  }
57  s << std::endl;
58  }
59 
60  mat.destroy();
61  return s;
62 }
63 
64 ///////////////////////////////////////////////////////////////////////////////
65 ///////////////////////////////////////////////////////////////////////////////
66 ///////////////////////////////////////////////////////////////////////////////
67 
68 //=============================================================================
69 inline void _zhsmatrix::write(const char* filename) const
70 {CPPL_VERBOSE_REPORT;
71  std::ofstream ofs(filename, std::ios::trunc);
72  ofs.setf(std::cout.flags());
73  ofs.precision(std::cout.precision());
74  ofs.width(std::cout.width());
75  ofs.fill(std::cout.fill());
76 
77  ofs << "#zhsmatrix " << n << " " << data.size() << std::endl;
78 
79  const std::vector<zcomponent>::const_iterator data_end =data.end();
80  for(std::vector<zcomponent>::const_iterator it=data.begin(); it!=data_end; it++){
81  ofs << it->i << " " << it->j << " " << it->v << std::endl;
82  }
83 
84  ofs.close();
85  destroy();
86 }
std::vector< zcomponent > data
matrix data
Definition: _zhsmatrix.hpp:12
comple operator()(const CPPL_INT &, const CPPL_INT &) const
void destroy() const
std::ostream & operator<<(std::ostream &s, const _zhsmatrix &mat)
_dgematrix i(const _dgbmatrix &mat)
_zcovector conj(const _zcovector &vec)
CPPL_INT n
matrix column size
Definition: _zhsmatrix.hpp:11
void write(const char *) const
std::vector< std::vector< CPPL_INT > > line
vector of vector to store the entry information of component for each row and column ...
Definition: _zhsmatrix.hpp:13
(DO NOT USE) Smart-temporary Complex Double-precision Hermitian Sparse Matrix Class ...
Definition: _zhsmatrix.hpp:3