This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen
View | Details | Raw Unified | Return to bug 856
Collapse All | Expand All

(-)a/unsupported/Eigen/src/SparseExtra/MarketIO.h (-1 / +12 lines)
Lines 216-243 bool loadMarketVector(VectorType& vec, c Link Here
216
  in.close();
216
  in.close();
217
  if (i!=n){
217
  if (i!=n){
218
    std::cerr<< "Unable to read all elements from file " << filename << "\n";
218
    std::cerr<< "Unable to read all elements from file " << filename << "\n";
219
    return false;
219
    return false;
220
  }
220
  }
221
  return true;
221
  return true;
222
}
222
}
223
223
224
std::string ReplaceString(std::string subject, const std::string& search, const std::string& replace)
225
{
226
  size_t pos = 0;
227
  while ((pos = subject.find(search, pos)) != std::string::npos) {
228
    subject.replace(pos, search.length(), replace);
229
    pos += replace.length();
230
  }
231
  return subject;
232
}
233
224
template<typename SparseMatrixType>
234
template<typename SparseMatrixType>
225
bool saveMarket(const SparseMatrixType& mat, const std::string& filename, int sym = 0)
235
bool saveMarket(const SparseMatrixType& mat, const std::string& filename, int sym = 0, const std::string comment= "")
226
{
236
{
227
  typedef typename SparseMatrixType::Scalar Scalar;
237
  typedef typename SparseMatrixType::Scalar Scalar;
228
  std::ofstream out(filename.c_str(),std::ios::out);
238
  std::ofstream out(filename.c_str(),std::ios::out);
229
  if(!out)
239
  if(!out)
230
    return false;
240
    return false;
231
  
241
  
232
  out.flags(std::ios_base::scientific);
242
  out.flags(std::ios_base::scientific);
233
  out.precision(64);
243
  out.precision(64);
234
  std::string header; 
244
  std::string header; 
235
  internal::putMarketHeader<Scalar>(header, sym); 
245
  internal::putMarketHeader<Scalar>(header, sym); 
246
  out << "% "  <<  ReplaceString(comment, "\n", "\n%") << std::endl;
236
  out << header << std::endl; 
247
  out << header << std::endl; 
237
  out << mat.rows() << " " << mat.cols() << " " << mat.nonZeros() << "\n";
248
  out << mat.rows() << " " << mat.cols() << " " << mat.nonZeros() << "\n";
238
  int count = 0;
249
  int count = 0;
239
  for(int j=0; j<mat.outerSize(); ++j)
250
  for(int j=0; j<mat.outerSize(); ++j)
240
    for(typename SparseMatrixType::InnerIterator it(mat,j); it; ++it)
251
    for(typename SparseMatrixType::InnerIterator it(mat,j); it; ++it)
241
    {
252
    {
242
      ++ count;
253
      ++ count;
243
      internal::PutMatrixElt(it.value(), it.row()+1, it.col()+1, out);
254
      internal::PutMatrixElt(it.value(), it.row()+1, it.col()+1, out);

Return to bug 856