micrograd 0.1.0
Small C implementation of micrograd
Loading...
Searching...
No Matches
value.h File Reference

Scalar value and autograd graph API. More...

#include <stdbool.h>
#include <stddef.h>
Include dependency graph for value.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  mg_graph_checkpoint
 Snapshot of a graph's allocation state. More...
 

Typedefs

typedef struct mg_graph mg_graph
 Opaque owner of a linked list of mg_value nodes.
 
typedef struct mg_value mg_value
 Opaque scalar node in a computation graph.
 

Functions

mg_graphmg_graph_new (void)
 Create a new graph.
 
void mg_graph_free (mg_graph *g)
 Free a graph and all values it owns.
 
void mg_zero_grad (mg_graph *g)
 Set all mg_value gradients in a graph to zero.
 
mg_graph_checkpoint mg_graph_save (const mg_graph *g)
 Create a snapshot of the graph's current allocation state.
 
void mg_graph_restore (mg_graph *g, mg_graph_checkpoint checkpoint)
 Restore the graph to a previous checkpoint.
 
float mg_data (const mg_value *v)
 Get the scalar data of a value.
 
float mg_grad (const mg_value *v)
 Get the gradient of a value.
 
void mg_set_data (mg_value *v, float data)
 Set the scalar data of a value.
 
void mg_set_grad (mg_value *v, float grad)
 Set the gradient of a value.
 
mg_valuemg_scalar (mg_graph *g, float data)
 Create a new scalar value.
 
mg_valuemg_add (mg_graph *g, mg_value *a, mg_value *b)
 Add two values.
 
mg_valuemg_sub (mg_graph *g, mg_value *a, mg_value *b)
 Subtract one value from another.
 
mg_valuemg_mul (mg_graph *g, mg_value *a, mg_value *b)
 Multiply two values.
 
mg_valuemg_div (mg_graph *g, mg_value *a, mg_value *b)
 Divide one value by another.
 
mg_valuemg_pow (mg_graph *g, mg_value *a, mg_value *b)
 Raise one value to the power of another.
 
mg_valuemg_neg (mg_graph *g, mg_value *a)
 Negate a value.
 
mg_valuemg_square (mg_graph *g, mg_value *a)
 Square a value.
 
mg_valuemg_relu (mg_graph *g, mg_value *a)
 Apply the ReLU activation function to a value.
 
mg_valuemg_tanh (mg_graph *g, mg_value *a)
 Apply the tanh activation function to a value.
 
mg_valuemg_exp (mg_graph *g, mg_value *a)
 Apply the exponential function to a value.
 
bool mg_backward (mg_graph *g, mg_value *out)
 Compute gradients for all values that contribute to an output value.
 

Detailed Description

Scalar value and autograd graph API.