Skip to main content

composed_hvp

Function composed_hvp 

Source
pub fn composed_hvp<F, Func>(f: Func, x: &[F], v: &[F]) -> (F, Vec<F>, Vec<F>)
where F: Float + BtapeThreadLocal, Func: FnOnce(&[Dual<BReverse<F>>]) -> Dual<BReverse<F>>,
Available on crate feature bytecode only.
Expand description

Forward-over-reverse HVP via type-level composition.

Records f with Dual<BReverse<F>> inputs (tangent direction v baked in as constants), then runs two reverse sweeps — one from the primal output (gradient) and one from the tangent output (HVP).

Returns (f(x), gradient, H·v).

For repeated HVP with different v, prefer record + BytecodeTape::hvp. This function re-records each call.