//=============================================================================
/*! operator() for const object */
inline std::complex<double> _zgsmatrix::operator()(const long& i, const long& j) const
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] _zgsmatrix::operator()(const long&, const long&) const"
<< std::endl;
#endif//CPPL_VERBOSE
#ifdef CPPL_DEBUG
if( i<0 || j<0 || M<=i || N<=j ){
std::cerr << "[ERROR] _zgsmatrix::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=Rows[i].begin(); p!=Rows[i].end(); p++){
if(p->first==j){ return Array[p->second]; }
}
//// (i,j) component was not found ////
return std::complex<double>(0.0,0.0);
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//=============================================================================
inline std::ostream& operator<<(std::ostream& s, const _zgsmatrix& mat)
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] operator<<(std::ostream&, const _zgsmatrix&)"
<< std::endl;
#endif//CPPL_VERBOSE
for(long i=0; i<mat.M; i++){
for(long j=0; j<mat.N; j++){
std::vector< std::pair<long,long> >::iterator q;
for(q=mat.Rows[i].begin(); q!=mat.Rows[i].end(); q++){
if(q->first==j){ break; }
}
if(q!=mat.Rows[i].end()){ s << mat.Array[q->second] << " "; }
else{ s << "x "; }
}
s << std::endl;
}
mat.destroy();
return s;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//=============================================================================
inline void _zgsmatrix::write(const char* filename) const
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] _zgsmatrix::write(const char*) const"
<< std::endl;
#endif//CPPL_VERBOSE
std::ofstream s(filename, std::ios::trunc);
s << "_zgsmatrix" << " " << M << " " << N << " " << CAP << std::endl;
for(long c=0; c<VOL; c++){
s << Indx[c] << " " << Jndx[c] << " " << Array[c] << std::endl;
}
s.close();
destroy();
}