39 bool operator()(
const pair<int, int>& e1,
const pair<int, int>& e2)
const 41 return e1.second < e2.second || (e1.second == e2.second && e1.first < e2.first);
45 MatrixStructure::MatrixStructure() :
46 n(0), m(0), Ap(0), Aii(0), maxN(0), maxNz(0)
93 string name = filename;
94 std::string::size_type lastDot = name.find_last_of(
'.');
95 if (lastDot != std::string::npos)
96 name = name.substr(0, lastDot);
98 vector<pair<int, int> > entries;
99 for (
int i=0; i < cols; ++i) {
100 const int& rbeg =
Ap[i];
101 const int& rend =
Ap[i+1];
102 for (
int j = rbeg; j < rend; ++j) {
103 entries.push_back(make_pair(
Aii[j], i));
105 entries.push_back(make_pair(i,
Aii[j]));
109 sort(entries.begin(), entries.end(),
ColSort());
111 std::ofstream fout(filename);
112 fout <<
"# name: " << name << std::endl;
113 fout <<
"# type: sparse matrix" << std::endl;
114 fout <<
"# nnz: " << entries.size() << std::endl;
115 fout <<
"# rows: " << rows << std::endl;
116 fout <<
"# columns: " << cols << std::endl;
117 for (vector<pair<int, int> >::const_iterator it = entries.begin(); it != entries.end(); ++it) {
118 const pair<int, int>& entry = *it;
119 fout << entry.first <<
" " << entry.second <<
" 0" << std::endl;
int * Ap
column pointers for A, of size n+1
int maxNz
size of the allocated memory
int n
A is m-by-n. n must be >= 0.
bool operator()(const pair< int, int > &e1, const pair< int, int > &e2) const
int m
A is m-by-n. m must be >= 0.
void alloc(int n_, int nz)
int * Aii
row indices of A, of size nz = Ap [n]
int maxN
size of the allocated memory
bool write(const char *filename) const