Struct easy_ml::differentiation::WengertList
source · [−]pub struct WengertList<T> { /* private fields */ }
Expand description
A list of operations performed in a forward pass of a dynamic computational graph, used for Reverse Mode Automatic Differentiation.
This is dynamic, as in, you build the Wengert list at runtime by performing operations like addition and multiplication on Records that were created with that Wengert list.
When you perform a backward pass to obtain the gradients you travel back up the computational graph using the stored intermediate values from this list to compute all the gradients of the inputs and every intermediate step with respect to an output.
Although sophisticated implementations can make the Wengert list only log(N) in length by storing only some of the intermediate steps of N computational steps, this implementation is not as sophisticated, and will store all of them.
Panics
Every operation and nearly every method a Record has involves manipulating the record’s history on its referenced WengertList. This WengertList itself maintains a RefCell which tracks borrows at runtime rather than compile time. This is neccessary to maintain the illusion that Records are just ordinary numbers, and the side effects of doing arithmetic with Records are limited to their referenced WengertList. Hence, the Rust compiler infers that it is not safe to share references to WengertLists between threads, nor transfer Records across threads. If you called a method on two Records that both mutably borrowed from the same WengertList at once, which could be trivially done with multiple threads, then the code would panic. Easy ML shouldn’t allow you to do this in safe Rust because each mutable borrow of the WengertList is dropped at the end of each Record method call, and you can’t call two methods simulatenously without threading.
Implementations
sourceimpl<T: Primitive> WengertList<T>
impl<T: Primitive> WengertList<T>
sourcepub fn new() -> WengertList<T>
pub fn new() -> WengertList<T>
Creates a new empty WengertList from which Records can be constructed.
sourceimpl<T> WengertList<T>
impl<T> WengertList<T>
sourceimpl<T: Numeric + Primitive> WengertList<T>
impl<T: Numeric + Primitive> WengertList<T>
sourcepub fn variable(&self, x: T) -> Record<'_, T>
pub fn variable(&self, x: T) -> Record<'_, T>
Creates a record backed by this WengertList.
You can alternatively use the record constructor on the Record type.
Trait Implementations
sourceimpl<T: Clone + Primitive> Clone for WengertList<T>
impl<T: Clone + Primitive> Clone for WengertList<T>
Any Wengert list of a Cloneable type implements clone
sourceimpl<T: Debug> Debug for WengertList<T>
impl<T: Debug> Debug for WengertList<T>
Auto Trait Implementations
impl<T> !RefUnwindSafe for WengertList<T>
impl<T> Send for WengertList<T> where
T: Send,
impl<T> !Sync for WengertList<T>
impl<T> Unpin for WengertList<T> where
T: Unpin,
impl<T> UnwindSafe for WengertList<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more