-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTry.cc
89 lines (79 loc) · 2.16 KB
/
Try.cc
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
#include <iostream>
#include "CppNN/Tensor.hpp"
#include "Network.hpp"
#ifdef COMPLETE_TEST
#include "CppNN/nn.hpp"
int main(){
// x
// Tensor input({2,2,1},false);
// float data[4]={3.,7.,4.,8.}; // 2 inference data points.
Tensor input({3,2,1},false);
float data[6]={3.,7.,4.,8.,5.,5.}; // 3 inference data points.
input.init(data);
input.printShape();
input.print();
// fc1
Schema fc1_weight_schema(2,fc1_w_schema,false);
Schema fc1_bias_schema(1,fc1_b_schema,false);
Tensor fc1_weight(fc1_weight_schema,fc1_w);
Tensor fc1_bias(fc1_bias_schema,fc1_b);
Linear fc1(2,4,true,&fc1_weight,&fc1_bias);
// fc2
Schema fc2_weight_schema(2,fc2_w_schema,false);
Schema fc2_bias_schema(1,fc2_b_schema,false);
Tensor fc2_weight(fc2_weight_schema,fc2_w);
Tensor fc2_bias(fc2_bias_schema,fc2_b);
Linear fc2(4,1,true,&fc2_weight,&fc2_bias);
// fc2(fc1(x))
Tensor* mid = fc1.forward(input);
Tensor* result = fc2.forward(*mid);
mid->destruct();
result->printShape();
result->print();
return 0;
}
#else
#ifdef UNIT_TEST
// Unit Test
int main(){
// x
Tensor input({3,2,1},false);
float data[6]={3.,7.,4.,8.,5.,5.}; // 3 inference data points.
input.init(data);
input.printShape();
input.print();
// test
printf("item: %.4f\n",input.get({1,0,0}));
input.view({1,1,3,2,1});
printf("item: %.4f\n",input.get({0,0,1,0,0}));
input.deview();
input.view({3,2,1,1});
printf("item: %.4f\n",input.get({1,0,0,0}));
input.deview();
input.view({3,1,2,1});
printf("item: %.4f\n",input.get({1,0,0,0}));
input.deview();
input.view({6,1,1});
printf("item: %.4f\n",input.get({2,0,0}));
input.deview();
input.view({6});
printf("item: %.4f\n",input.get({2}));
input.deview();
input.view({1,6});
printf("item: %.4f\n",input.get({0,2}));
input.deview();
input.permute({1,0,2});
input.printShape();
printf("item: %.4f\n",input.get({0,1,0}));
input.view({1,6});
printf("item: %.4f\n",input.get({0,1}));
input.deview();
return 0;
}
#else
int main(){
printf("Hello World!\n");
return 0;
}
#endif
#endif