pub struct RnnCell { /* private fields */ }Expand description
One Elman recurrent cell with an explicit caller-owned hidden state.
Implementations§
Source§impl RnnCell
impl RnnCell
pub fn new_with_seed( input_size: usize, hidden_size: usize, bias: bool, seed: u64, ) -> Result<Self>
Sourcepub fn new_with_seed_on(
runtime: &Runtime,
input_size: usize,
hidden_size: usize,
bias: bool,
seed: u64,
) -> Result<Self>
pub fn new_with_seed_on( runtime: &Runtime, input_size: usize, hidden_size: usize, bias: bool, seed: u64, ) -> Result<Self>
Construct a deterministically initialized RNN cell.
§Errors
Returns an error when dimensions are zero, hidden size exceeds 1024, arithmetic overflows, or parameter allocation fails.
Sourcepub fn new_from_matrices(
weight_ih: Matrix,
weight_hh: Matrix,
bias_ih: Matrix,
bias_hh: Matrix,
) -> Result<Self>
pub fn new_from_matrices( weight_ih: Matrix, weight_hh: Matrix, bias_ih: Matrix, bias_hh: Matrix, ) -> Result<Self>
Construct a biased RNN cell from exact matrices.
§Errors
Returns an error unless weights use [H, I] and [H, H], biases use
[H], and all values satisfy the F32 runtime and hidden-size contract.
Sourcepub fn new_from_weights(weight_ih: Matrix, weight_hh: Matrix) -> Result<Self>
pub fn new_from_weights(weight_ih: Matrix, weight_hh: Matrix) -> Result<Self>
Construct a bias-free RNN cell from exact weight matrices.
§Errors
Returns an error unless both weights satisfy the F32 runtime, shape, and hidden-size contract.
Sourcepub fn zero_state(&self, batch: usize) -> Result<Matrix>
pub fn zero_state(&self, batch: usize) -> Result<Matrix>
Create a zero hidden state [batch, hidden] on this cell’s runtime.
§Errors
Returns an error when batch is zero, shape arithmetic overflows, or allocation fails.
Sourcepub fn step(&self, input: &Matrix, hidden: &Matrix) -> Result<Matrix>
pub fn step(&self, input: &Matrix, hidden: &Matrix) -> Result<Matrix>
Apply one recurrent step to [B, I] input and [B, H] hidden state.
§Errors
Returns an error when the input/hidden contract or runtime recording fails.
Sourcepub const fn input_size(&self) -> usize
pub const fn input_size(&self) -> usize
Return the configured input width.
Return the recurrent hidden width.
Sourcepub fn all_parameters(&self) -> Result<Vec<Parameter>>
pub fn all_parameters(&self) -> Result<Vec<Parameter>>
Return parameters in weight-ih, weight-hh, bias-ih, bias-hh order.
Trait Implementations§
Source§impl Module for RnnCell
impl Module for RnnCell
Source§fn forward(&self, input: &Matrix) -> Result<Matrix>
fn forward(&self, input: &Matrix) -> Result<Matrix>
Source§fn registry(&self) -> &ModuleRegistry
fn registry(&self) -> &ModuleRegistry
Source§fn parameters(&self) -> Vec<Parameter>
fn parameters(&self) -> Vec<Parameter>
Source§fn named_parameters(&self) -> Vec<NamedParameter>
fn named_parameters(&self) -> Vec<NamedParameter>
Source§fn named_buffers(&self) -> Vec<NamedBuffer>
fn named_buffers(&self) -> Vec<NamedBuffer>
Source§fn all_parameters(&self) -> Result<Vec<Parameter>>
fn all_parameters(&self) -> Result<Vec<Parameter>>
Source§fn all_named_parameters(&self) -> Result<Vec<NamedParameter>>
fn all_named_parameters(&self) -> Result<Vec<NamedParameter>>
Source§fn all_named_buffers(&self) -> Result<Vec<NamedBuffer>>
fn all_named_buffers(&self) -> Result<Vec<NamedBuffer>>
Source§fn all_named_state_u32(&self) -> Result<Vec<NamedStateU32>>
fn all_named_state_u32(&self) -> Result<Vec<NamedStateU32>>
u32 scalar state in
deterministic depth-first order. Read more