Menu

[r168]: / trunk / include / _zhematrix- / _zhematrix-io.hpp  Maximize  Restore  History

Download this file

76 lines (65 with data), 2.6 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//=============================================================================
/*! operator() for object */
inline zhecomplex _zhematrix::operator()(const long& i, const long& j) const
{CPPL_VERBOSE_REPORT;
#ifdef CPPL_DEBUG
if( i<0 || j<0 || n<=i || n<=j ){
ERROR_REPORT;
std::cerr << "The required component is out of the matrix size." << std::endl
<< "Your input was (" << i << "," << j << ")." << std::endl;
exit(1);
}
#endif//CPPL_DEBUG
if(i>=j){ return zhecomplex(i,j, darray[j][i]); }
else { return zhecomplex(i,j, darray[i][j]); }
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//=============================================================================
inline std::ostream& operator<<(std::ostream& s, const _zhematrix& mat)
{CPPL_VERBOSE_REPORT;
for(long i=0; i<mat.n; i++){
for(long j=0; j<mat.n; j++){
if(i>j){ s << " " << mat(i,j) << " "; }
else if(i==j){ s << " " << std::real(mat(i,i)) << " "; }
else{ s << "{" << std::conj(mat.darray[i][j]) << "} "; }
}
s << std::endl;
#ifdef CPPL_DEBUG
if(std::fabs(std::imag(mat(i,i))) > DBL_MIN){
WARNING_REPORT;
std::cerr << "The " << i << "th diagonal component of the zhematrix is not a real number." << std::endl;
}
#endif//CPPL_DEBUG
}
mat.destroy();
return s;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//=============================================================================
inline void _zhematrix::write(const char* filename) const
{CPPL_VERBOSE_REPORT;
std::ofstream ofs(filename, std::ios::trunc);
ofs.setf(std::cout.flags());
ofs.precision(std::cout.precision());
ofs.width(std::cout.width());
ofs.fill(std::cout.fill());
ofs << "#zhematrix" << " " << n << std::endl;
for(long i=0; i<n; i++){
for(long j=0; j<=i; j++ ){
ofs << operator()(i,j) << " ";
}
ofs << std::endl;
#ifdef CPPL_DEBUG
if(std::fabs(std::imag(operator()(i,i))) > DBL_MIN){
WARNING_REPORT;
std::cerr << "The " << i << "th diagonal component of the zhematrix is not a real number." << std::endl;
}
#endif//CPPL_DEBUG
}
ofs.close();
destroy();
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.