pub trait GradientProvider {
    fn gradient<P>(&mut self, p: &P) -> Option<Box<P::Array>>
    where
        P: HasUniqueId + HasArrayType<Dtype = f32> + HasDevice + HasArrayData
; }
Expand description

Represents something that can return a gradient for a given key.

This is very similar to what Gradients does, however the intention is that any this object be passed to CanUpdateWithGradients.

Gradients does not implement this, so you have to go through an optimizer to update a CanUpdateWithGradients. Although it very easily could.

See crate::optim::Sgd and crate::optim::Adam for examples on implementing this.

Required Methods

Retrieves the data associated with p if there is any. This can modify self, for instance if velocities are calculated based on the associated data!

Implementors