My Project
_zssmatrix-io.hpp
1 //=============================================================================
3 inline std::complex<double> _zssmatrix::operator()(const long& i, const long& j) const
4 {
5 #ifdef CPPL_VERBOSE
6  std::cerr << "# [MARK] _zssmatrix::operator()(const long&, const long&) const"
7  << std::endl;
8 #endif//CPPL_VERBOSE
9 
10 #ifdef CPPL_DEBUG
11  if( i<0 || j<0 || M<=i || N<=j ){
12  std::cerr << "[ERROR] _zssmatrix::operator()(long, long)" << std::endl
13  << "The required component is out of the matrix size."
14  << std::endl
15  << "Your input was (" << i << "," << j << ")." << std::endl;
16  exit(1);
17  }
18 #endif//CPPL_DEBUG
19 
20  for(long c=0; c<VOL; c++){
21  if(Indx[c]==i && Jndx[c]==j){ return Array[c]; }
22  }
23 
24  return std::complex<double>(0.0,0.0);
25 }
26 
30 
31 //=============================================================================
32 inline std::ostream& operator<<(std::ostream& s, const _zssmatrix& mat)
33 {
34 #ifdef CPPL_VERBOSE
35  std::cerr << "# [MARK] operator<<(std::ostream&, const _zssmatrix&)"
36  << std::endl;
37 #endif//CPPL_VERBOSE
38 
39  long c;
40  for(long i=0; i<mat.M; i++){
41  for(long j=0; j<mat.N; j++){
42  c=0;
43  while(c<mat.VOL){
44  if(mat.Indx[c]==i && mat.Jndx[c]==j){ break; }
45  c++;
46  }
47  if(c!=mat.VOL){ s << mat.Array[c] << " "; }
48  else{ s << "x "; }
49  }
50  s << std::endl;
51  }
52 
53  mat.destroy();
54  return s;
55 }
56 
60 
61 //=============================================================================
62 inline void _zssmatrix::write(const char* filename) const
63 {
64 #ifdef CPPL_VERBOSE
65  std::cerr << "# [MARK] _zssmatrix::write(const char*) const"
66  << std::endl;
67 #endif//CPPL_VERBOSE
68 
69  std::ofstream s(filename, std::ios::trunc);
70 
71  s << "_zssmatrix" << " " << M << " " << N << " " << CAP << std::endl;
72  for(long c=0; c<VOL; c++){
73  s << Indx[c] << " " << Jndx[c] << " " << Array[c] << std::endl;
74  }
75 
76  s.close();
77  destroy();
78 }
long M
matrix row size
Definition: _zssmatrix.hpp:7
long VOL
the number of non-zero components
Definition: _zssmatrix.hpp:10
(DO NOT USE) Smart-temporary Complex Double-precision Sparse Matrix Class
Definition: _zssmatrix.hpp:3
long CAP
the length of data arrays
Definition: _zssmatrix.hpp:9
std::complex< double > * Array
1D array to store non-zero matrix data
Definition: _zssmatrix.hpp:11
void destroy() const
Definition: _zssmatrix-misc.hpp:3
std::complex< double > operator()(const long &, const long &) const
Definition: _zssmatrix-io.hpp:3
long N
matrix column size
Definition: _zssmatrix.hpp:8
long * Jndx
1D array to store the j-index of non-zero matrix components
Definition: _zssmatrix.hpp:13
long * Indx
1D array to store the i-index of non-zero matrix components
Definition: _zssmatrix.hpp:12