Crates.io | regrad |
lib.rs | regrad |
version | 0.2.0 |
source | src |
created_at | 2024-10-05 05:31:01.459619 |
updated_at | 2024-10-05 07:44:25.248687 |
description | A simple library to backpropagate gradients through a computation graph |
homepage | |
repository | |
max_upload_size | |
id | 1397410 |
size | 10,207 |
backtrack in rust
cargo add regrad
use regrad::Value;
fn main() {
let v1 = Value::from(1.2);
let v2 = Value::from(3.4);
let v3 = &(&v1 * &v1) * &v2;
dbg!(v3.data());
assert_eq!(v3.data(), 4.896);
v3.backward();
dbg!(v1.gradient());
dbg!(v2.gradient());
dbg!(v3.gradient());
assert_eq!(v1.gradient(), 8.16);
assert_eq!(v2.gradient(), 1.44);
assert_eq!(v3.gradient(), 1.0);
}