use crate::math::common::Aligned64;
pub struct LstmLayer<const I: usize, const H: usize, const IH: usize, const H4: usize> {
pub input_hidden_weights: Aligned64<[[[f32; H]; IH]; 4]>,
pub bias: Aligned64<[f32; H4]>,
pub state: Aligned64<[f32; IH]>,
pub cell_state: Aligned64<[f32; H]>,
pub cell_error: Aligned64<[f32; H]>,
pub gates: Aligned64<[f32; H4]>,
}
impl<const I: usize, const H: usize, const IH: usize, const H4: usize> LstmLayer<I, H, IH, H4> {
pub fn new() -> Self {
Self {
input_hidden_weights: Aligned64([[[0.0f32; H]; IH]; 4]),
bias: Aligned64([0.0; H4]),
state: Aligned64([0.0; IH]),
cell_state: Aligned64([0.0; H]),
cell_error: Aligned64([0.0; H]),
gates: Aligned64([0.0; H4]),
}
}
#[inline(always)]
pub fn get_hidden_state(&self) -> &[f32] {
&self.state[I..]
}
pub fn reset_input_slot(&mut self) {
self.state[..I].fill(0.0);
}
pub fn reset_states(&mut self) {
self.state.fill(0.0);
self.cell_state.fill(0.0);
self.cell_error.fill(0.0);
self.gates.fill(0.0);
}
}
impl<const I: usize, const H: usize, const IH: usize, const H4: usize> Default
for LstmLayer<I, H, IH, H4>
{
fn default() -> Self {
Self::new()
}
}