g-ad 0.1.0

Autodiff engine for the g tensor library
docs.rs failed to build g-ad-0.1.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.

First-order reverse AD.

[grad] is functional: every call clears all reachable leaf slots before its reverse pass and returns only that output's gradients. [backward] intentionally accumulates into leaf slots until [zero_grad] is called.

Example

use g_core::Tensor;
# fn main() -> g_core::Result<()> {
let x = Tensor::from_slice_f32(&[2.0], &[])?.with_requires_grad();
let y = g_ad::mul(&x, &x)?; // x^2
let g = g_ad::grad(&y, &[&x])?;
assert!((g[0].item_f32()? - 4.0).abs() < 1e-6);
# Ok(())
# }

Semantics

The reverse engine walks the graph as a DAG, so a node shared by several consumers is differentiated exactly once per pass. Tracked ops return tensors carrying [Backward] VJP nodes; when no input requires gradients the op simply calls the CPU kernel and stays off the tape.