-
Notifications
You must be signed in to change notification settings - Fork 0
/
input_test.cpp
193 lines (138 loc) · 4.37 KB
/
input_test.cpp
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// #include <iostream>
// #include <fstream>
// #include <regex>
// #include <string>
// #include <vector>
// using namespace std;
// int main() {
// vector<double> temp_line;
// vector<vector<double>> Vec_Dti;
// string line;
// ifstream in("./native/examples/npsavetest.txt"); //读入文件
// regex pat_regex("[[:digit:]]+"); //匹配原则,这里代表一个或多个数字
// while(getline(in, line)) { //按行读取
// for (sregex_iterator it(line.begin(), line.end(), pat_regex), end_it; it != end_it; ++it) { //表达式匹配,匹配一行中所有满足条件的字符
// cout << it->str() << " "; //输出匹配成功的数据
// temp_line.push_back(stoi(it->str())); //将数据转化为int型并存入一维vector中
// }
// cout << endl;
// Vec_Dti.push_back(temp_line); //保存所有数据
// temp_line.clear();
// }
// cout << endl << endl;
// for(auto i : Vec_Dti) { //输出存入vector后的数据
// for(auto j : i) {
// cout << j << " ";
// }
// cout << endl;
// }
// ifstream in("./native/examples/npsavetest.txt");
// vector<string> lines;
// string str;
// while (std::getline(in, str))
// {
// if (str.size() > 0)
// {
// lines.push_back(str);
// }
// }
// in.close();
// return 0;
// }
#include <fstream>
#include <iostream>
#include <sstream>
#include <vector>
#include <cstdlib>
#include <cstring>
using namespace std;
int main() {
ifstream is("./native/params/fcn.bias.txt");
int line_size = 500 * 3;
char line[line_size];
is.seekg(0, is.end);
int file_size = is.tellg();
is.seekg(0, is.beg);
int line_number = 1;
vector<double> result;
while(is.good()) {
is.getline(line, file_size);
if(strlen(line) == 0) {
continue;
}
result.push_back(atof(line));
}
is.close();
for(int i=0; i<result.size() ;i++) { //输出存入vector后的数据
cout << result[i] << endl;
}
// ifstream is("./native/params/fcn.weight.txt");
// int line_size = 10000 * 3;
// char line[line_size];
// is.seekg(0, is.end);
// int file_size = is.tellg();
// is.seekg(0, is.beg);
// int line_number = 1;
// //vector< vector<double> >result;
// vector< vector<double> >result;
// while(is.good()) {
// is.getline(line, file_size);
// if(strlen(line) == 0) {
// continue;
// }
// stringstream ss;
// ss << line;
// char number_str[100];
// vector<double> line_doubles;
// while(ss.good()) {
// ss.getline(number_str, line_size, ' ');
// if(strlen(number_str) == 0) {
// continue;
// }
// line_doubles.push_back(atof(number_str));
// //std::cout << "get number:" << atof(number_str) << std::endl;
// }
// //std::cout << "get line_doubles size:" << line_doubles.size() << std::endl;
// result.push_back(line_doubles);
// //std::cout << "get line" << "(" << line_number++ <<"):" << line << std::endl;
// }
// //std::cout << "get result size:" << result.size() << std::endl;
// is.close();
// vector< vector<double> > fc;
// fc=result;
// for(auto i : fc) { //输出存入vector后的数据
// for(auto j : i) {
// cout << j << " ";
// }
// cout << endl;
// }
//reshape operation
// vector<vector<vector<double>>> reshape(3, vector<vector<double>>(64 , vector<double>(result[0].size(), 0)));
// for (int i=0;i<reshape.size();i++){
// for(int j=0;j<reshape[0].size();j++){
// for(int k=0;k<reshape[0][0].size();k++){
// reshape[i][j][k] = result[j+i*(reshape[0].size())][k];
// }
// }
// }
// ofstream outputfile;
// outputfile.open ("./native/examples/reshape.txt");
// for (int i=0;i<reshape.size();i++){
// for(int j=0;j<reshape[0].size();j++){
// for(int k=0;k<reshape[0][0].size();k++){
// outputfile<<reshape[i][j][k]<<endl;
// }
// }
// }
// outputfile.close();
// cout<<"reshape matrix size 0 "<<reshape.size()<<endl;
// cout<<"reshape matrix size 1 "<<reshape[0].size()<<endl;
// cout<<"reshape matrix size 2 "<<reshape[0][0].size()<<endl;
// for(int i=0;i< reshape.size(); i++) { //输出存入vector后的数据
// for(int j=0; j<reshape[0].size();j++) {
// for(int k=0; j<reshape[0][0].size();k++){
// cout << reshape[i][j][k] << endl;
// }
// }
// }
}