FEI Version of the Day
fei_ostream_ops.cpp
00001 /*--------------------------------------------------------------------*/
00002 /*    Copyright 2005 Sandia Corporation.                              */
00003 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00004 /*    non-exclusive license for use of this work by or on behalf      */
00005 /*    of the U.S. Government.  Export of this program may require     */
00006 /*    a license from the United States Government.                    */
00007 /*--------------------------------------------------------------------*/
00008 
00009 #include <fei_macros.hpp>
00010 #include <fei_ostream_ops.hpp>
00011 
00012 #include <fei_Vector.hpp>
00013 #include <fei_Matrix.hpp>
00014 #include <fei_FillableMat.hpp>
00015 #include <fei_CSRMat.hpp>
00016 #include <fei_CSVec.hpp>
00017 
00018 
00019 FEI_OSTREAM& operator<<(FEI_OSTREAM& os, fei::Vector& vec)
00020 {
00021   vec.writeToStream(os);
00022   return(os);
00023 }
00024 
00025 FEI_OSTREAM& operator<<(FEI_OSTREAM& os, fei::Matrix& mat)
00026 {
00027   mat.writeToStream(os);
00028   return(os);
00029 }
00030 
00031 FEI_OSTREAM& operator<<(FEI_OSTREAM& os, fei::FillableMat& mat)
00032 {
00033   os << "num rows: " << mat.getNumRows() << FEI_ENDL;
00034   fei::FillableMat::iterator
00035     iter = mat.begin(), iter_end = mat.end();
00036 
00037   for(; iter!=iter_end; ++iter) {
00038     int row = iter->first;
00039     const fei::CSVec* v = iter->second;
00040     const std::vector<int>& v_ind = v->indices();
00041     const std::vector<double>& v_coef = v->coefs();
00042     os << row << ": ";
00043     for(size_t i=0; i<v_ind.size(); ++i) {
00044       os << "("<<v_ind[i]<<","<<v_coef[i]<<") ";
00045     }
00046     os << FEI_ENDL;
00047   }
00048 
00049   return(os);
00050 }
00051 
00052 FEI_OSTREAM& operator<<(FEI_OSTREAM& os, fei::CSVec& vec)
00053 {
00054   size_t len = vec.size();
00055 
00056   os << "   numEntries: " << len << FEI_ENDL;
00057 
00058   for(size_t i=0; i<len; ++i) {
00059     os << "     " << vec.indices()[i]<< ": "<<vec.coefs()[i] << FEI_ENDL;
00060   }
00061 
00062   return(os);
00063 }
00064 
00065 FEI_OSTREAM& operator<<(FEI_OSTREAM& os, fei::CSRMat& mat)
00066 {
00067   os << "num rows: " << mat.getNumRows() << FEI_ENDL;
00068 
00069   const std::vector<int>& rows = mat.getGraph().rowNumbers;
00070   const int* rowoffs = &(mat.getGraph().rowOffsets[0]);
00071   const std::vector<int>& cols = mat.getGraph().packedColumnIndices;
00072   const double* coefs = &(mat.getPackedCoefs()[0]);
00073 
00074   for(size_t i=0; i<rows.size(); ++i) {
00075     int row = rows[i];
00076 
00077     os << row << ": ";
00078     for(int j=rowoffs[i]; j<rowoffs[i+1]; ++j) {
00079       os << "("<<cols[j]<<","<<coefs[j]<<") ";
00080     }
00081     os << FEI_ENDL;
00082   }
00083 
00084   return(os);
00085 }
00086 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends