pub struct HvpResult<V: Differentiable> {
pub gradients: Gradients<V>,
pub hvp: Gradients<V>,
}Expand description
Result of a forward-over-reverse HVP computation.
Contains both the standard gradient and the Hessian-vector
product H*v, where v is the tangent direction set on leaf values
via Tape::leaf_with_tangent.
§Examples
ⓘ
use chainrules::{Tape, HvpResult};
use tenferro_einsum::tracked_einsum;
use tenferro_tensor::{MemoryOrder, Tensor};
use tenferro_device::LogicalMemorySpace;
let tape = Tape::<Tensor<f64>>::new();
let x = tape.leaf_with_tangent(
Tensor::ones(&[3], LogicalMemorySpace::MainMemory, MemoryOrder::ColumnMajor),
Tensor::ones(&[3], LogicalMemorySpace::MainMemory, MemoryOrder::ColumnMajor),
).unwrap();
let loss = tracked_einsum("i,i->", &[&x, &x]).unwrap();
let result: HvpResult<Tensor<f64>> = tape.hvp(&loss).unwrap();
let _grad = result.gradients.get(x.node_id().unwrap());
let _hv = result.hvp.get(x.node_id().unwrap());Fields§
§gradients: Gradients<V>Gradients.
hvp: Gradients<V>Hessian-vector product: H*v.
Auto Trait Implementations§
impl<V> Freeze for HvpResult<V>
impl<V> RefUnwindSafe for HvpResult<V>
impl<V> Send for HvpResult<V>
impl<V> Sync for HvpResult<V>
impl<V> Unpin for HvpResult<V>
impl<V> UnwindSafe for HvpResult<V>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more