Crate chainrules_core

Crate chainrules_core 

Source
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:

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§

AutodiffError
AD-specific error type.
SavePolicy
Saved-tensor retention policy for reverse-mode rules.

Traits§

Differentiable
Trait defining the tangent space for a differentiable type.
ForwardRule
Forward-mode AD rule interface (frule).
ReverseRule
Reverse-mode AD rule interface (rrule).

Type Aliases§

AdResult
Result alias for AD APIs.