sym-ildl  1.2
Incomplete LDL' factorizations of indefinite symmetric and skew-symmetric matrices.
lilc_matrix_save.h
1 //-*-mode:c++-*-
2 #ifndef _LILC_MATRIX_SAVE_H_
3 #define _LILC_MATRIX_SAVE_H_
4 
5 inline void put_header(std::string& header, bool sym = false)
6 {
7  header= "%%MatrixMarket matrix coordinate real ";
8  if (sym)
9  header += "symmetric"; //maybe change later to have symmetric/complex/blah as options
10  else
11  header += "general";
12 }
13 
14 template <class el_type>
15 bool lilc_matrix<el_type> :: save(std::string filename, bool sym)
16 {
17  std::ofstream out(filename.c_str(), std::ios::out | std::ios::binary);
18  if(!out)
19  return false;
20 
21  out.flags(std::ios_base::scientific);
22  out.precision(16);
23  std::string header;
24  put_header(header, sym);
25 
26  out << header << std::endl;
27  out << n_rows() << " " << n_cols() << " " << nnz() << "\n";
28 
29  for(int i = 0; i < n_cols(); i++) {
30  for(unsigned int j = 0; j < m_idx[i].size(); j++) {
31  out << m_idx[i][j]+1 << " " << i+1 << " " << m_x[i][j] << "\n";
32  }
33  }
34 
35  out.close();
36  return true;
37 }
38 
39 #endif
bool save(std::string filename, bool sym=false)
Saves a matrix in matrix market format.
Definition: lilc_matrix_save.h:15