Menu

[r136]: / trunk / include / _dssmatrix- / _dssmatrix-io.hpp  Maximize  Restore  History

Download this file

78 lines (68 with data), 2.8 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
76
77
//=============================================================================
/*! operator() for const object */
inline double _dssmatrix::operator()(const long& i, const long& j) const
{VERBOSE_REPORT;
#ifdef CPPL_DEBUG
if( i<0 || j<0 || n<=i || n<=j ){
std::cerr << "[ERROR] _dssmatrix::operator()(long, long)" << std::endl
<< "The required component is out of the matrix size." << std::endl
<< "Your input was (" << i << "," << j << ")." << std::endl;
exit(1);
}
#endif//CPPL_DEBUG
//// search (i,j) component ////
const uint32_t ii(std::max(i,j)), jj(std::min(i,j));
for(std::vector<uint32_t>::iterator p=line[ii].begin(); p!=line[ii].end(); p++){
if(data[*p].i==ii && data[*p].j==jj){ return data[*p].v; }
}
//// (i,j) component was not found ////
return 0.0;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//=============================================================================
inline std::ostream& operator<<(std::ostream& s, const _dssmatrix& mat)
{VERBOSE_REPORT;
for(long i=0; i<mat.n; i++){
for(long j=0; j<mat.n; j++){
if( i >= j ){
std::vector<uint32_t>::iterator q;
for(q=mat.line[i].begin(); q!=mat.line[i].end(); q++){
if(long(mat.data[*q].j)==j){ break; }
}
if(q!=mat.line[i].end()){ s << " " << mat.data[*q].v << " "; }
else{ s << " x "; }
}
else{//i<j
std::vector<uint32_t>::iterator q;
for(q=mat.line[i].begin(); q!=mat.line[i].end(); q++){
if(long(mat.data[*q].j)==j){ break; }
}
if(q!=mat.line[i].end()){ s << "{" << mat.data[*q].v << "}"; }
else{ s << "{x}"; }
}
}
s << std::endl;
}
mat.destroy();
return s;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//=============================================================================
inline void _dssmatrix::write(const char* filename) const
{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 << "dssmatrix" << std::endl;
for(std::vector<dcomponent>::const_iterator it=data.begin(); it!=data.end(); it++){
ofs << it->i << " " << it->j << " " << it->v << std::endl;
}
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.