//=============================================================================
/*! operator() for const object */
inline double _dssmatrix::operator()(const long& i, const long& j) const
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] _dssmatrix::operator()(const long&, const long&) const" << std::endl;
#endif//CPPL_VERBOSE
#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 ////
for(std::vector< std::pair<long,long> >::iterator p=Line[i].begin(); p!=Line[i].end(); p++){
if(p->first==j){ return Data[p->second].v; }
}
//// (i,j) component was not found ////
return 0.0;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//=============================================================================
inline std::ostream& operator<<(std::ostream& s, const _dssmatrix& mat)
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] operator<<(std::ostream&, const _dssmatrix&)" << std::endl;
#endif//CPPL_VERBOSE
for(long i=0; i<mat.N; i++){
for(long j=0; j<mat.N; j++){
if( i >= j ){
std::vector< std::pair<long,long> >::iterator q;
for(q=mat.Line[i].begin(); q!=mat.Line[i].end(); q++){
if(q->first==j){ break; }
}
if(q!=mat.Line[i].end()){ s << " " << mat.Data[q->second].v << " "; }
else{ s << " x "; }
}
else{//i<j
std::vector< std::pair<long,long> >::iterator q;
for(q=mat.Line[i].begin(); q!=mat.Line[i].end(); q++){
if(q->first==j){ break; }
}
if(q!=mat.Line[i].end()){ s << "{" << mat.Data[q->second].v << "}"; }
else{ s << "{x}"; }
}
}
s << std::endl;
}
mat.destroy();
return s;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//=============================================================================
inline void _dssmatrix::write(const char* filename) const
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] _dssmatrix::write(const char*) const"
<< std::endl;
#endif//CPPL_VERBOSE
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();
}