86 const string_view name = [&filename]() {
87 const std::string::size_type lastDot = filename.find_last_of(
'.');
88 if (lastDot != std::string_view::npos)
return filename.substr(0, lastDot);
92 vector<pair<int, int> > entries;
93 for (
int i = 0; i < cols; ++i) {
94 const int& rbeg =
Ap[i];
95 const int& rend =
Ap[i + 1];
96 for (
int j = rbeg; j < rend; ++j) {
97 entries.push_back(make_pair(
Aii[j], i));
98 if (
Aii[j] != i) entries.push_back(make_pair(i,
Aii[j]));
102 sort(entries.begin(), entries.end(),
ColSort());
104 const string output_filename(filename);
105 std::ofstream fout(output_filename);
106 fout <<
"# name: " << name << std::endl;
107 fout <<
"# type: sparse matrix" << std::endl;
108 fout <<
"# nnz: " << entries.size() << std::endl;
109 fout <<
"# rows: " << rows << std::endl;
110 fout <<
"# columns: " << cols << std::endl;
111 for (vector<pair<int, int> >::const_iterator it = entries.begin();
112 it != entries.end(); ++it) {
113 const pair<int, int>& entry = *it;
114 fout << entry.first <<
" " << entry.second <<
" 0"