pub struct DynState { /* private fields */ }Expand description
A type-erased optimizer state for a single parameter.
It wraps a concrete O::State<D> together with its rank D so that the rank can be recovered
when the state is later interpreted by the originating Optimizer (during a step, a device
transfer or serialization).
Implementations§
Source§impl DynState
impl DynState
Sourcepub fn create<T: Send + Sync + 'static>(state: T, rank: usize) -> Self
pub fn create<T: Send + Sync + 'static>(state: T, rank: usize) -> Self
Erase a concrete optimizer state of rank rank.
Sourcepub fn downcast<T: Clone + Send + Sync + 'static>(self) -> T
pub fn downcast<T: Clone + Send + Sync + 'static>(self) -> T
Recover the concrete state by value, moving it out when this is the only handle and
cloning only when the underlying state is still shared. Panics if T does not match the
stored type.
Sourcepub fn downcast_ref<T: 'static>(&self) -> &T
pub fn downcast_ref<T: 'static>(&self) -> &T
Borrow the concrete state without cloning. Panics if T does not match the stored type.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for DynState
impl !UnwindSafe for DynState
impl Freeze for DynState
impl Send for DynState
impl Sync for DynState
impl Unpin for DynState
impl UnsafeUnpin for DynState
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneExpand for Twhere
T: Clone,
impl<T> CloneExpand for Twhere
T: Clone,
fn __expand_clone_method(&self, _: &Scope) -> T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more