-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoord_format_matrix.cpp
More file actions
46 lines (41 loc) · 1.15 KB
/
Copy pathcoord_format_matrix.cpp
File metadata and controls
46 lines (41 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "coord_format_matrix.hpp"
#include <fstream>
using namespace std;
size_t CCoordMatrix::getNZ() const {
return matrix.size();
}
size_t CCoordMatrix::getN() const {
return N;
}
uint64_t CCoordMatrix::getMatrixSize() const {
return uint64_t(N) * uint64_t(N);
}
size_t CCoordMatrix::generate(size_t N, size_t minInRow, size_t maxInRow, double powerPrecent) {
size_t NZ(0);
this->N = N;
matrix.clear();
//generate matrix elements
matrix.shrink_to_fit();
return NZ;
}
void CCoordMatrix::loadFromMatrixMarketFile(const string& filename) {
ifstream in(filename);
string buffer;
while (getline(in, buffer) &&
buffer[0] == '%')//ignore comments
;
size_t elementCount(0), m, n;
if (sscanf(buffer.c_str(), "%u %u %u", &m, &n, &elementCount) && m == n) {
N = m;
matrix.clear();
size_t i, j;
double value;
while (elementCount && getline(in, buffer)) {
sscanf(buffer.c_str(), "%u %u %lf", &i, &j, &value);
matrix.emplace_back(value, i - 1, j - 1);
--elementCount;
}
matrix.shrink_to_fit();
}
in.close();
}