HvpResult

Struct HvpResult 

Source
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>
where <V as Differentiable>::Tangent: Send,

§

impl<V> Sync for HvpResult<V>
where <V as Differentiable>::Tangent: Sync,

§

impl<V> Unpin for HvpResult<V>
where <V as Differentiable>::Tangent: Unpin,

§

impl<V> UnwindSafe for HvpResult<V>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.