CPPLapack
 All Classes Files Functions Variables Friends Pages
_dsymatrix-io.hpp
Go to the documentation of this file.
1 //=============================================================================
2 /*! operator() for object */
3 inline double& _dsymatrix::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  if( i >= j ){
15  //return array[i+n*j];
16  return darray[j][i];
17  } else {
18  //return array[j+n*i];
19  return darray[i][j];
20  }
21 }
22 
23 ///////////////////////////////////////////////////////////////////////////////
24 ///////////////////////////////////////////////////////////////////////////////
25 ///////////////////////////////////////////////////////////////////////////////
26 
27 //=============================================================================
28 inline std::ostream& operator<<(std::ostream& s, const _dsymatrix& mat)
29 {CPPL_VERBOSE_REPORT;
30  for(CPPL_INT i=0; i<mat.n; i++){
31  for(CPPL_INT j=0; j<mat.n; j++){
32  if( i >= j ){
33  s << " " << mat(i,j) << " ";
34  } else {
35  s << "{" << mat(i,j) << "} ";
36  }
37  }
38  s << std::endl;
39  }
40 
41  mat.destroy();
42  return s;
43 }
44 
45 ///////////////////////////////////////////////////////////////////////////////
46 ///////////////////////////////////////////////////////////////////////////////
47 ///////////////////////////////////////////////////////////////////////////////
48 
49 //=============================================================================
50 inline void _dsymatrix::write(const char* filename) const
51 {CPPL_VERBOSE_REPORT;
52  std::ofstream ofs(filename, std::ios::trunc);
53  ofs.setf(std::cout.flags());
54  ofs.precision(std::cout.precision());
55  ofs.width(std::cout.width());
56  ofs.fill(std::cout.fill());
57 
58  ofs << "#dsymatrix " << n << std::endl;
59  for(CPPL_INT i=0; i<n; i++){
60  for(CPPL_INT j=0; j<=i; j++ ){
61  ofs << operator()(i,j) << " ";
62  }
63  ofs << std::endl;
64  }
65 
66  ofs.close();
67  destroy();
68 }
friend _dsymatrix i(const _dsymatrix &)
void write(const char *) const
void destroy() const
_dgematrix i(const _dgbmatrix &mat)
double ** darray
array of pointers of column head addresses
Definition: _dsymatrix.hpp:13
double & operator()(const CPPL_INT &, const CPPL_INT &) const
(DO NOT USE) Smart-temporary Real Double-precision Symmetric Matrix Class
Definition: _dsymatrix.hpp:3
CPPL_INT n
matrix column size
Definition: _dsymatrix.hpp:11
std::ostream & operator<<(std::ostream &s, const _dsymatrix &mat)