47 if(
row < b.
row)
return true;
48 if(b.
row <
row)
return false;
59 err =
"Not a sparse matrix.\n";
68 err =
"Not a real matrix.\n";
75 std::vector<MatrixElement> elements;
78 for(
int i = 0; i < nz; ++i) {
83 int count = fscanf(f,
"%d %d %lf", &y, &x, &e.
value);
85 std::ostringstream oss;
86 oss<<
"Error parsing line "<< (i + 1);
90 }
else if(isPattern) {
91 int count = fscanf(f,
"%d %df", &y, &x);
93 std::ostringstream oss;
94 oss<<
"Error parsing line "<< (i + 1);
102 elements.push_back(e);
107 elements.push_back(e);
111 std::sort(elements.begin(), elements.end());
115 nz = (int)elements.size();
119 m->csr.resize(height + 1);
121 m->matrix.resize(nz);
122 for(
int i = 0; i < nz; ++i) {
126 m->matrix[i] = e.
value;
131 for(
int i = 0; i < height; ++i) {
132 int count = m->csr[i];
136 m->csr[height] =
scan;
144 std::auto_ptr<SparseMatrix>* ppMatrix, std::string& err) {
146 FILE* f = fopen(filename,
"r");
148 err =
"Could not open file.";
159 std::auto_ptr<SparseMatrix>* ppMatrix) {
161 FILE* f = fopen(filename,
"rb");
165 fread(&m->height, 4, 1, f);
166 fread(&m->width, 4, 1, f);
167 fread(&m->nz, 4, 1, f);
169 m->csr.resize(m->height + 1);
170 m->cols.resize(m->nz);
171 m->matrix.resize(m->nz);
173 fread(&m->csr[0], 4, m->height + 1, f);
174 fread(&m->cols[0], 4, m->nz, f);
175 fread(&m->matrix[0], 8, m->nz, f);
185 FILE* f = fopen(filename,
"wb");
188 fwrite(&m.
height, 4, 1, f);
189 fwrite(&m.
width, 4, 1, f);
190 fwrite(&m.
nz, 4, 1, f);
193 fwrite(&m.
cols[0], 4, m.
nz, f);
201 std::auto_ptr<SparseMatrix>* ppMatrix, std::string& err) {
205 std::auto_ptr<SparseMatrix> m;
207 sprintf(s,
"%s.bin", filename);
211 if(!success)
return false;
213 printf(
"Creating temp file %s...\n", s);
231 for(
int i = 0; i < m.
height; ++i) {
232 int count = m.
csr[i + 1] - m.
csr[i];
233 double x = count - stats.
mean;
240 for(
int i = 0; i < m.
height; ++i) {
241 int count = m.
csr[i + 1] - m.
csr[i];
242 double x = count - stats.
mean;
243 skewness += x * x * x;
254 std::auto_ptr<SparseMatrix>* ppC) {
261 int64 numProducts = 0;
262 for(
int row = 0; row < A.
height; ++row) {
263 std::map<int, double> rowMap;
264 int aCsr0 = A.
csr[row];
265 int aCsr1 = (row + 1 < A.
height) ? A.
csr[row + 1] : A.
nz;
267 for(
int i = aCsr0; i < aCsr1; ++i) {
268 int aCol = A.
cols[i];
271 int bCsr0 = B.
csr[aCol];
272 int bCsr1 = (aCol + 1 < B.
height) ? B.
csr[aCol + 1] : B.
nz;
274 numProducts += bCsr1 - bCsr0;
276 for(
int j = bCsr0; j < bCsr1; ++j)
281 std::map<int, double>::const_iterator i = rowMap.begin();
282 C->csr.push_back(C->nz);
283 while(i != rowMap.end()) {
284 C->cols.push_back(i->first);
285 C->matrix.push_back(i->second);
288 C->nz += (int)rowMap.size();
297 int64 numProducts = 0;
298 for(
int ai = 0; ai < A.
nz; ++ai) {
299 int aCol = A.
cols[ai];
300 int bCsr0 = B.
csr[aCol];
301 int bCsr1 = (aCol + 1 < B.
width) ? B.
csr[aCol + 1] : B.
nz;
302 numProducts += bCsr1 - bCsr0;
308 int* colMin,
int* colMax) {
311 for(
int row = 0; row < A.
height; ++row) {
315 int csr0 = A.
csr[row];
316 int csr1 = A.
csr[row + 1];
317 for(
int i = csr0; i < csr1; ++i) {
318 int aCol = A.
cols[i];