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