FEI  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fei_ostream_ops.cpp
1 /*--------------------------------------------------------------------*/
2 /* Copyright 2005 Sandia Corporation. */
3 /* Under the terms of Contract DE-AC04-94AL85000, there is a */
4 /* non-exclusive license for use of this work by or on behalf */
5 /* of the U.S. Government. Export of this program may require */
6 /* a license from the United States Government. */
7 /*--------------------------------------------------------------------*/
8 
9 #include <fei_macros.hpp>
10 #include <fei_ostream_ops.hpp>
11 
12 #include <fei_Vector.hpp>
13 #include <fei_Matrix.hpp>
14 #include <fei_FillableMat.hpp>
15 #include <fei_CSRMat.hpp>
16 #include <fei_CSVec.hpp>
17 
18 
19 FEI_OSTREAM& operator<<(FEI_OSTREAM& os, fei::Vector& vec)
20 {
21  vec.writeToStream(os);
22  return(os);
23 }
24 
25 FEI_OSTREAM& operator<<(FEI_OSTREAM& os, fei::Matrix& mat)
26 {
27  mat.writeToStream(os);
28  return(os);
29 }
30 
31 FEI_OSTREAM& operator<<(FEI_OSTREAM& os, fei::FillableMat& mat)
32 {
33  os << "num rows: " << mat.getNumRows() << FEI_ENDL;
34  fei::FillableMat::iterator
35  iter = mat.begin(), iter_end = mat.end();
36 
37  for(; iter!=iter_end; ++iter) {
38  int row = iter->first;
39  const fei::CSVec* v = iter->second;
40  const std::vector<int>& v_ind = v->indices();
41  const std::vector<double>& v_coef = v->coefs();
42  os << row << ": ";
43  for(size_t i=0; i<v_ind.size(); ++i) {
44  os << "("<<v_ind[i]<<","<<v_coef[i]<<") ";
45  }
46  os << FEI_ENDL;
47  }
48 
49  return(os);
50 }
51 
52 FEI_OSTREAM& operator<<(FEI_OSTREAM& os, fei::CSVec& vec)
53 {
54  size_t len = vec.size();
55 
56  os << " numEntries: " << len << FEI_ENDL;
57 
58  for(size_t i=0; i<len; ++i) {
59  os << " " << vec.indices()[i]<< ": "<<vec.coefs()[i] << FEI_ENDL;
60  }
61 
62  return(os);
63 }
64 
65 FEI_OSTREAM& operator<<(FEI_OSTREAM& os, fei::CSRMat& mat)
66 {
67  os << "num rows: " << mat.getNumRows() << FEI_ENDL;
68 
69  const std::vector<int>& rows = mat.getGraph().rowNumbers;
70  const int* rowoffs = &(mat.getGraph().rowOffsets[0]);
71  const std::vector<int>& cols = mat.getGraph().packedColumnIndices;
72  const double* coefs = &(mat.getPackedCoefs()[0]);
73 
74  for(size_t i=0; i<rows.size(); ++i) {
75  int row = rows[i];
76 
77  os << row << ": ";
78  for(int j=rowoffs[i]; j<rowoffs[i+1]; ++j) {
79  os << "("<<cols[j]<<","<<coefs[j]<<") ";
80  }
81  os << FEI_ENDL;
82  }
83 
84  return(os);
85 }
86 
std::vector< int > rowNumbers
std::vector< int > packedColumnIndices
std::vector< int > rowOffsets
virtual int writeToStream(FEI_OSTREAM &ostrm, bool matrixMarketFormat=true)=0
virtual int writeToStream(FEI_OSTREAM &ostrm, bool matrixMarketFormat=true)=0
std::ostream & operator<<(std::ostream &out, const SerialBandDenseMatrixPrinter< OrdinalType, ScalarType > printer)