-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
22 lines (18 loc) · 778 Bytes
/
main.c
File metadata and controls
22 lines (18 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "forward.h"
#include "log.h"
#include "tensor.h"
int
main ()
{
log_set_level (LOG_INFO);
smart tensor_t *a = tensor ((float[]) { 1., 2., 3., 4., 5., 6. }, (int[]) { 2, 3 }, 2, true);
smart tensor_t *b = tensor ((float[]) { 1., 2., 3., 4., 5., 6. }, (int[]) { 3, 2 }, 2, true);
smart tensor_t *c = tensor_matmul (a, b);
smart tensor_t *f = tensor_sum (c, NULL, 0);
tensor_backward (f); // compute gradients
tensor_print (a, PRINT_ALL); // print tensors a.data and a.grad = d(f)/d(a)
tensor_print (b, PRINT_ALL); // print tensors b.data and b.grad = d(f)/d(b)
tensor_print (c, PRINT_ALL); // print tensors c.data and c.grad = d(f)/d(c)
tensor_print (f, PRINT_ALL); // print tensors f.data and f.grad = d(f)/d(f)
return 0;
}