CPPLapack
 All Classes Files Functions Variables Friends
_dssmatrix-io.hpp
Go to the documentation of this file.
00001 //=============================================================================
00002 /*! operator() for const object */
00003 inline double _dssmatrix::operator()(const long& i, const long& j) const
00004 {VERBOSE_REPORT;
00005 #ifdef  CPPL_DEBUG
00006   if( i<0 || j<0 || n<=i || n<=j ){
00007     ERROR_REPORT;
00008     std::cerr << "The required component is out of the matrix size." << std::endl
00009               << "Your input was (" << i << "," << j << ")." << std::endl;
00010     exit(1);
00011   }
00012 #endif//CPPL_DEBUG
00013   
00014   //// search (i,j) component ////
00015   const uint32_t ii(std::max(i,j)), jj(std::min(i,j));
00016   for(std::vector<uint32_t>::iterator p=line[ii].begin(); p!=line[ii].end(); p++){
00017     if(data[*p].i==ii && data[*p].j==jj){ return data[*p].v; }
00018   }
00019   
00020   //// (i,j) component was not found ////
00021   return 0.0;
00022 }
00023 
00024 ///////////////////////////////////////////////////////////////////////////////
00025 ///////////////////////////////////////////////////////////////////////////////
00026 ///////////////////////////////////////////////////////////////////////////////
00027 
00028 //=============================================================================
00029 inline std::ostream& operator<<(std::ostream& s, const _dssmatrix& mat)
00030 {VERBOSE_REPORT;
00031   for(long i=0; i<mat.n; i++){
00032     for(long j=0; j<mat.n; j++){
00033       if( i >= j ){
00034         std::vector<uint32_t>::iterator q;
00035         for(q=mat.line[i].begin(); q!=mat.line[i].end(); q++){
00036           if(long(mat.data[*q].j)==j){ break; }
00037         }
00038         if(q!=mat.line[i].end()){ s << " " << mat.data[*q].v << " "; }
00039         else{ s << " x "; }
00040       }
00041       else{//i<j
00042         std::vector<uint32_t>::iterator q;
00043         for(q=mat.line[i].begin(); q!=mat.line[i].end(); q++){
00044           if(long(mat.data[*q].j)==j){ break; }
00045         }
00046         if(q!=mat.line[i].end()){ s << "{" << mat.data[*q].v << "}"; }
00047         else{ s << "{x}"; }
00048       }
00049     }
00050     s << std::endl;
00051   }
00052   
00053   mat.destroy();
00054   return s;
00055 }
00056 
00057 ///////////////////////////////////////////////////////////////////////////////
00058 ///////////////////////////////////////////////////////////////////////////////
00059 ///////////////////////////////////////////////////////////////////////////////
00060 
00061 //=============================================================================
00062 inline void _dssmatrix::write(const char* filename) const
00063 {VERBOSE_REPORT;
00064   std::ofstream ofs(filename, std::ios::trunc);
00065   ofs.setf(std::cout.flags());
00066   ofs.precision(std::cout.precision());
00067   ofs.width(std::cout.width());
00068   ofs.fill(std::cout.fill());
00069   
00070   ofs << "#dssmatrix" << std::endl;
00071   for(std::vector<dcomponent>::const_iterator it=data.begin(); it!=data.end(); it++){
00072     ofs << it->i << " " << it->j << " " << it->v << std::endl;
00073   }
00074   
00075   ofs.close();
00076   destroy();
00077 }
 All Classes Files Functions Variables Friends