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_FillableVec.hpp>
00016 #include <fei_CSRMat.hpp>
00017 #include <fei_CSVec.hpp>
00018 
00019 
00020 FEI_OSTREAM& operator<<(FEI_OSTREAM& os, fei::Vector& vec)
00021 {
00022   vec.writeToStream(os);
00023   return(os);
00024 }
00025 
00026 FEI_OSTREAM& operator<<(FEI_OSTREAM& os, fei::Matrix& mat)
00027 {
00028   mat.writeToStream(os);
00029   return(os);
00030 }
00031 
00032 FEI_OSTREAM& operator<<(FEI_OSTREAM& os, fei::FillableVec& vec)
00033 {
00034   fei::FillableVec::iterator
00035     iter = vec.begin(), iter_end = vec.end();
00036 
00037   os << "   numEntries: " << vec.size() << FEI_ENDL;
00038 
00039   for(; iter!=iter_end; ++iter) {
00040     os << "     " << iter->first<< ": "<<iter->second << FEI_ENDL;
00041   }
00042 
00043   return(os);
00044 }
00045 
00046 FEI_OSTREAM& operator<<(FEI_OSTREAM& os, fei::FillableMat& mat)
00047 {
00048   os << "num rows: " << mat.getNumRows() << FEI_ENDL;
00049   fei::FillableMat::iterator
00050     iter = mat.begin(), iter_end = mat.end();
00051 
00052   for(; iter!=iter_end; ++iter) {
00053     int row = iter->first;
00054     fei::FillableVec::iterator
00055      viter = iter->second->begin(), viter_end = iter->second->end();
00056 
00057     os << row << ": ";
00058     for(; viter!=viter_end; ++viter) {
00059       os << "("<<viter->first<<","<<viter->second<<") ";
00060     }
00061     os << FEI_ENDL;
00062   }
00063 
00064   return(os);
00065 }
00066 
00067 FEI_OSTREAM& operator<<(FEI_OSTREAM& os, fei::CSVec& vec)
00068 {
00069   size_t len = vec.size();
00070 
00071   os << "   numEntries: " << len << FEI_ENDL;
00072 
00073   for(size_t i=0; i<len; ++i) {
00074     os << "     " << vec.indices()[i]<< ": "<<vec.coefs()[i] << FEI_ENDL;
00075   }
00076 
00077   return(os);
00078 }
00079 
00080 FEI_OSTREAM& operator<<(FEI_OSTREAM& os, fei::CSRMat& mat)
00081 {
00082   os << "num rows: " << mat.getNumRows() << FEI_ENDL;
00083 
00084   const std::vector<int>& rows = mat.getGraph().rowNumbers;
00085   const int* rowoffs = &(mat.getGraph().rowOffsets[0]);
00086   const std::vector<int>& cols = mat.getGraph().packedColumnIndices;
00087   const double* coefs = &(mat.getPackedCoefs()[0]);
00088 
00089   for(size_t i=0; i<rows.size(); ++i) {
00090     int row = rows[i];
00091 
00092     os << row << ": ";
00093     for(int j=rowoffs[i]; j<rowoffs[i+1]; ++j) {
00094       os << "("<<cols[j]<<","<<coefs[j]<<") ";
00095     }
00096     os << FEI_ENDL;
00097   }
00098 
00099   return(os);
00100 }
00101 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends
Generated on Wed Apr 13 10:08:24 2011 for FEI by  doxygen 1.6.3