summaryrefslogtreecommitdiffstats
path: root/example/direct.c
blob: 29da5d3af3678ddedf66f2ec9bafa1b458312852 (plain)
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

// direct.c - Example usage of direct.h computation graph

#include <stdio.h>

typedef double direct_value_t;

#define DT_IMPLEMENTATION
#include "../include/direct.h"

int main() {
  node_t x0 = {.x = 0.0, .function = dt_add};
  node_t x1 = {.x = 0.0, .function = dt_one};
  node_t x2 = {.x = 0.0, .function = dt_add};
  node_t x3 = {.x = 0.0, .function = dt_add};
  node_t x4 = {.x = 0.0, .function = dt_add};
  node_t x5 = {.x = 0.0, .function = dt_add};
  node_t x6 = {.x = 0.0, .function = dt_one};

  dt_connect(&x0, &x2);
  dt_connect(&x0, &x1);
  dt_connect(&x0, &x3);
  dt_connect(&x2, &x1);
  dt_connect(&x2, &x4);
  dt_connect(&x3, &x4);
  dt_connect(&x4, &x5);
  dt_connect(&x4, &x6);
  dt_connect(&x5, &x6);

  dt_update_trace(&x0);
  printf("data: %lf\n", x0.x);
  dt_update_trace(&x0);
  printf("data: %lf\n", x0.x);
  dt_update_trace(&x0);
  printf("data: %lf\n", x0.x);

  dt_clear_edges(&x0);
  dt_clear_edges(&x1);
  dt_clear_edges(&x2);
  dt_clear_edges(&x3);
  dt_clear_edges(&x4);
  dt_clear_edges(&x5);
  dt_clear_edges(&x6);

  return 0;
}