Menu

[r31]: / trunk / include / _dgbmatrix- / _dgbmatrix-io.hpp  Maximize  Restore  History

Download this file

74 lines (62 with data), 2.3 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
//=============================================================================
/*! operator() for const object */
inline double& _dgbmatrix::operator()(const long& i, const long& j) const
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] _dgbmatrix::operator()(const long&, const long&) const"
<< std::endl;
#endif//CPPL_VERBOSE
#ifdef CPPL_DEBUG
if( i<0 || j<0 || M<=i || N<=j || i-j>KL || j-i>KU ){
std::cerr << "[ERROR] _dgbmatrix::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
//return Array[KU+i+(KL+KU)*j];
return Darray[j][KU-j+i];
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//=============================================================================
inline std::ostream& operator<<(std::ostream& s, const _dgbmatrix& mat)
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] operator<<(std::ostream&, const _dgbmatrix&)"
<< std::endl;
#endif//CPPL_VERBOSE
for(long i=0; i<mat.M; i++){
for(long j=0; j<mat.N; j++){
if( i-j>mat.KL || j-i>mat.KU ){ s << " x"; }
else{ s << " " << mat(i,j); }
}
s << std::endl;
}
mat.destroy();
return s;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//=============================================================================
inline void _dgbmatrix::write(const char *filename) const
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] _dgbmatrix::write(const char*) const"
<< std::endl;
#endif//CPPL_VERBOSE
std::ofstream s(filename, std::ios::trunc);
s << "dgbmatrix" << " "
<< M << " " << N << " " << KL << " " << KU << std::endl;
for(long i=0; i<M; i++){
for(long j=max(0,i-KL); j<min(N,i+KU+1); j++){
s << operator()(i,j) << " ";
}
s << std::endl;
}
s.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.