-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
100 lines (85 loc) · 1.73 KB
/
test.cpp
File metadata and controls
100 lines (85 loc) · 1.73 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include "json.hpp"
#include <iomanip>
#include "sparsemat.h"
#include "tensor.h"
void TestFileReading()
{
std::ifstream myfile("matrix.dat");
// myfile.open(mat_file);
if(!myfile.is_open())
{
std::cout<<"can't open the matrix file!"<<std::endl;
exit(1);
}
std::string line;
getline(myfile,line);
std::istringstream split_line(line);
int row, col, nnz;
split_line >> row >> col >> nnz;
std::cout<<row<<" "<<col<<" "<<nnz<<std::endl;
int i_idx, j_idx;
double val;
for(int i=0;i<nnz;i++)
{
getline(myfile,line);
std::istringstream tmp_line(line);
tmp_line >> i_idx >> j_idx >> val;
std::cout<< i_idx << " "<<j_idx<<" "<<val<<std::endl;
}
getline(myfile,line);
if(!myfile.eof())
std::cout<<"Reading file is not finished!"<< std::endl;
myfile.close();
}
void TestJSON()
{
nlohmann::json features;
std::string name = "nrow";
int n=10;
features[name] = n;
std::ofstream jsonfile("test.json");
jsonfile << std::setw(4) << features << std::endl;
}
SpaCOO foo()
{
std::cout<<"enter foo() function"<<std::endl;
std::string file="matrix.dat";
SpaCOO coo;
coo.ReadMat0(file);
std::cout<<"leave foo() function"<<std::endl;
return coo;
}
void TestMatrix()
{
/* SpaCOO a; */
SpaCOO a(3,3,4);
a = foo();
/* SpaCOO a(foo()); */
std::cout<<a.GetRow()<<std::endl;
}
void TestSpmv()
{
std::string file="matrix.dat";
SpaCOO *coo = new SpaCOO;
coo->ReadMat0(file);
SpaCSR csr(*coo);
delete coo;
/* SpaCOO coo; */
/* coo.ReadMat0(file); */
/* SpaCSR csr(coo); */
Vec b(csr.GetCol(),1.0);
Vec a = csr * b;
a.PrintPartialTensor(5);
}
int main()
{
/* TestFileReading(); */
/* TestJSON(); */
/* TestMatrix(); */
TestSpmv();
return 0;
}