Skip to content

Latest commit

 

History

History
30 lines (25 loc) · 955 Bytes

README.md

File metadata and controls

30 lines (25 loc) · 955 Bytes

micrograd.rs

Quit your shitty ass job and go learn some skills.

- George Hotz

Insanely lightweight Rust implementation of Andrej Karpathy's micrograd.

Example

use micrograd::Value;

fn main() {
    let x = Value::new(1f32);
    let y = Value::new(2f32);
    
    let z = &x * &y;
    
    z.backward();
    assert_eq!(x.grad(), 2f32);
    assert_eq!(y.grad(), 1f32);
}

Supported types

Value<T> requires T to implement Differentiable. You can support your own types by implementing micrograd::Differentiable for them.

Features

This crate performs no heap allocations, all the values and the graph are stored entirely on stack. Thus graph requires all the nodes to be alive during backward, otherwise the code will not compile since borrow checker does not allow invalid references.