40 const std::vector<TripletEntry>& triplets) {
41 const string name = [&filename]() {
42 const std::string::size_type lastDot = filename.find_last_of(
'.');
43 if (lastDot != std::string::npos)
return filename.substr(0, lastDot);
47 std::ofstream fout(filename.c_str());
48 fout <<
"# name: " << name << std::endl;
49 fout <<
"# type: sparse matrix" << std::endl;
50 fout <<
"# nnz: " << triplets.size() << std::endl;
51 fout <<
"# rows: " << rows << std::endl;
52 fout <<
"# columns: " << cols << std::endl;
54 fout << setprecision(9) << endl;
56 fout << entry.r + 1 <<
" " << entry.c + 1 <<
" " << entry.x << std::endl;
61bool writeVector(
const string& filename,
const double* v,
int n) {
62 ofstream os(filename.c_str());
64 for (
int i = 0; i < n; i++) os << *v++ << endl;
68bool writeCCSMatrix(
const string& filename,
int rows,
int cols,
const int* Ap,
69 const int* Ai,
const double* Ax,
70 bool upperTriangleSymmetric) {
71 vector<TripletEntry> entries;
72 entries.reserve((
size_t)Ap[cols]);
73 for (
int i = 0; i < cols; i++) {
74 const int& rbeg = Ap[i];
75 const int& rend = Ap[i + 1];
76 for (
int j = rbeg; j < rend; j++) {
78 if (upperTriangleSymmetric && Ai[j] != i)
87 const int* Ai,
const int* Aj,
const double* Ax,
88 bool upperTriangleSymmetric) {
89 vector<TripletEntry> entries;
91 for (
int i = 0; i < nz; ++i) {
93 if (upperTriangleSymmetric && Ai[i] != Aj[i])
static bool writeTripletEntries(const std::string &filename, int rows, int cols, const std::vector< TripletEntry > &triplets)
bool writeCCSMatrix(const string &filename, int rows, int cols, const int *Ap, const int *Ai, const double *Ax, bool upperTriangleSymmetric)
bool writeVector(const string &filename, const double *v, int n)
bool writeTripletMatrix(const std::string &filename, int nz, int rows, int cols, const int *Ai, const int *Aj, const double *Ax, bool upperTriangleSymmetric)