-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathdev.c
More file actions
45 lines (39 loc) · 1.17 KB
/
Copy pathdev.c
File metadata and controls
45 lines (39 loc) · 1.17 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
#include "tensor.h"
Tensor* model(Tensor* inp, Tensor* w1, Tensor* w2) {
printf("forward pass\n");
Tensor* res = inp;
for (int l = 0; l < 2; l++) {
printf("layer %d\n", l);
if (l == 0)
res = matmul(res, w1);
else
res = matmul(res, w2);
print_tensor(res);
}
return res;
}
int main() {
Tensor* inp = create_zero_tensor((int[]){2,2},2);
for (int i = 0; i < 4; i++)
inp->data->values[i] = (float)i;
Tensor* w1 = create_zero_tensor((int[]){2,2}, 2);
Tensor* w2 = create_zero_tensor((int[]){2,2}, 2);
for (int i = 0; i < w1->data->size; i++) w1->data->values[i] = kaiming_uniform(784);
for (int i = 0; i < w2->data->size; i++) w2->data->values[i] = kaiming_uniform(128);
printf("w1:\n");
print_tensor(w1);
printf("w2:\n");
print_tensor(w2);
Tensor* out = model(inp, w1, w2);
printf("out\n");
print_tensor(out);
printf("w1o\n");
print_tensor(out->prevs[0]);
printf("w2\n");
print_tensor(out->prevs[1]);
printf("inp\n");
print_tensor(out->prevs[0]->prevs[0]);
printf("w1\n");
print_tensor(out->prevs[0]->prevs[1]);
return 0;
}