pub const fn autodiff<F, G, T: Tuple, R>(f: F, df: G, args: T) -> R🔬This is a nightly-only experimental API. (
core_intrinsics)Expand description
Generates the LLVM body for the automatic differentiation of f using Enzyme,
with df as the derivative function and args as its arguments.
Used internally as the body of df when expanding the #[autodiff_forward]
and #[autodiff_reverse] attribute macros.
Type Parameters:
F: The original function to differentiate. Must be a function item.G: The derivative function. Must be a function item.T: A tuple of arguments passed todf.R: The return type of the derivative function.
This shows where the autodiff intrinsic is used during macro expansion:
ⓘ
#[autodiff_forward(df1, Dual, Const, Dual)]
pub fn f1(x: &[f64], y: f64) -> f64 {
unimplemented!()
}expands to:
ⓘ
#[rustc_autodiff]
#[inline(never)]
pub fn f1(x: &[f64], y: f64) -> f64 {
::core::panicking::panic("not implemented")
}
#[rustc_autodiff(Forward, 1, Dual, Const, Dual)]
pub fn df1(x: &[f64], bx_0: &[f64], y: f64) -> (f64, f64) {
::core::intrinsics::autodiff(f1::<>, df1::<>, (x, bx_0, y))
}