Struct LstmState
pub struct LstmState<const D: usize> {
pub cell: Tensor<D>,
pub hidden: Tensor<D>,
}Expand description
State bundle for LSTM implementations.
Fields§
§cell: Tensor<D>The cell state.
The hidden state.
Implementations§
§impl<const D: usize> LstmState<D>
impl<const D: usize> LstmState<D>
pub fn new(cell: Tensor<D>, hidden: Tensor<D>) -> LstmState<D>
pub fn new(cell: Tensor<D>, hidden: Tensor<D>) -> LstmState<D>
Construct a new LstmState.
This is the inverse to Self::unpack.
§Arguments
cell- the cell state.hidden- the hidden state.
§Debug Assertion
cell.shape() == hidden.shape()
pub fn initial<S>(shape: S, device: &Device) -> LstmState<D>
pub fn initial<S>(shape: S, device: &Device) -> LstmState<D>
Allocate an initial zero state.
§Arguments
shape- the shape of the cell and hidden states.device- the device to allocate the state on.
pub fn unpack(self) -> (Tensor<D>, Tensor<D>)
pub fn unpack(self) -> (Tensor<D>, Tensor<D>)
Unpack the state to (cell, hidden).
This is the inverse to Self::new.
pub fn slice<S>(self, slices: S) -> LstmState<D>where
S: SliceArg,
pub fn slice<S>(self, slices: S) -> LstmState<D>where
S: SliceArg,
Slice the state.
See: Tensor::slice.
pub fn squeeze_dim<const D2: usize>(self, dim: impl AsIndex) -> LstmState<D2>
pub fn squeeze_dim<const D2: usize>(self, dim: impl AsIndex) -> LstmState<D2>
Squeeze a dimension from the state.
Negative dimensions are supported and count from the end.
See: Tensor::squeeze_dim.
pub fn unsqueeze_dim<const D2: usize>(self, dim: impl AsIndex) -> LstmState<D2>
pub fn unsqueeze_dim<const D2: usize>(self, dim: impl AsIndex) -> LstmState<D2>
Unsqueeze a dimension in the state.
Negative dimensions are supported and count from the end of the valid insertion positions.
See: Tensor::unsqueeze_dim.
pub fn stack<const D2: usize>(
states: Vec<LstmState<D>>,
dim: impl AsIndex,
) -> LstmState<D2>
pub fn stack<const D2: usize>( states: Vec<LstmState<D>>, dim: impl AsIndex, ) -> LstmState<D2>
Stack the states along the given dimension.
Negative dimensions are supported and count from the end of the valid insertion positions.
See: Tensor::stack.
pub fn chunk(self, n: usize, dim: impl AsIndex) -> Vec<LstmState<D>>
pub fn chunk(self, n: usize, dim: impl AsIndex) -> Vec<LstmState<D>>
Chunk the state into n states along the given dimension.
This is the inverse of stacking — useful for splitting multi-layer states back into per-layer states.
Negative dimensions are supported and count from the end.
See: Tensor::chunk.
Trait Implementations§
Auto Trait Implementations§
impl<const D: usize> Freeze for LstmState<D>
impl<const D: usize> RefUnwindSafe for LstmState<D>
impl<const D: usize> Send for LstmState<D>
impl<const D: usize> Sync for LstmState<D>
impl<const D: usize> Unpin for LstmState<D>
impl<const D: usize> UnsafeUnpin for LstmState<D>
impl<const D: usize> UnwindSafe for LstmState<D>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<K, Q> Comparable<Q> for K
impl<K, Q> Comparable<Q> for K
§impl<K, Q> Equivalent<Q> for K
impl<K, Q> Equivalent<Q> for K
§fn equivalent(&self, key: &Q) -> bool
fn equivalent(&self, key: &Q) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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>
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