-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCSR.cu
53 lines (46 loc) · 1.16 KB
/
CSR.cu
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
47
48
49
50
51
52
53
#include "COO.cuh"
#include "CSR.cuh"
#include <math.h> /* floor */
#include <cuda.h>
CSR::CSR(const COO & c){
row_offset.resize(c.dimensions + 1);
col_vec.resize(c.numberOfEntries);
val_vec.resize(c.numberOfEntries);
int row_size = 0;
int row = 0;
int index = 0;
row_offset[0] = 0;
while(row < c.dimensions){
if(c.row_vec[index] == row){
row_size++;
index++;
} else {
row_offset[row+1] = row_size;
row++;
}
}
col_vec = c.col_vec;
val_vec = c.val_vec;
}
std::string CSR::toString(){
std::stringstream ss;
std::string myMatrix;
ss << "\t\tCSR Matrix" << std::endl;
ss << "Row offsets" << std::endl;
for(int i = 0; i< row_offset.size(); i++){
ss << "\t" << row_offset[i];
}
ss << std::endl;
ss << "Column indices" << std::endl;
for(int i = 0; i< col_vec.size(); i++){
ss << "\t" << col_vec[i];
}
ss << std::endl;
ss << "values" << std::endl;
for(int i = 0; i< val_vec.size(); i++){
ss << "\t" << val_vec[i];
}
ss << std::endl;
myMatrix = ss.str();
return myMatrix;
}