Expand description
Core AD trait definitions (like Julia’s ChainRulesCore.jl).
This crate defines the interface for automatic differentiation without providing an AD engine. It contains:
Differentiable— tangent space definition for any value typeReverseRule— per-operation reverse-mode rule (rrule/pullback)ForwardRule— per-operation forward-mode rule (frule/pushforward)- Error types (
AutodiffError,AdResult) NodeId,SavePolicy— graph node identifier and save strategy
The AD engine (TrackedTensor, DualTensor, pullback, hvp) lives in
the chainrules crate.
Operation-specific AD rules (e.g., einsum rrule/frule) live in the crate that defines the operation.
§Examples
Implementing Differentiable for a custom type:
ⓘ
use chainrules_core::Differentiable;
#[derive(Clone)]
struct MyVec(Vec<f64>);
impl Differentiable for MyVec {
type Tangent = MyVec;
fn zero_tangent(&self) -> MyVec {
MyVec(vec![0.0; self.0.len()])
}
fn accumulate_tangent(a: MyVec, b: &MyVec) -> MyVec {
MyVec(a.0.iter().zip(&b.0).map(|(x, y)| x + y).collect())
}
}Structs§
- NodeId
- Stable identifier of an AD graph node.
Enums§
- Autodiff
Error - AD-specific error type.
- Save
Policy - Saved-tensor retention policy for reverse-mode rules.
Traits§
- Differentiable
- Trait defining the tangent space for a differentiable type.
- Forward
Rule - Forward-mode AD rule interface (frule).
- Reverse
Rule - Reverse-mode AD rule interface (rrule).
Type Aliases§
- AdResult
- Result alias for AD APIs.