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