use scirs2_core::ndarray::{Array1, Array2};
use scirs2_core::numeric::Float;
use std::fmt::Debug;
use super::{AttentionMechanism, LSTMLayer, LSTMNetwork, LSTMOptimizer, OutputProjection};
impl<T: Float + Debug + Send + Sync + 'static> OutputProjection<T> {
pub fn weight_snapshot(&self) -> &Array2<T> {
&self.weights
}
pub fn bias_snapshot(&self) -> &Array1<T> {
&self.bias
}
}
impl<T: Float + Debug + Send + Sync + 'static> LSTMLayer<T> {
pub fn weight_ih_snapshot(&self) -> &Array2<T> {
&self.weight_ih
}
pub fn weight_hh_snapshot(&self) -> &Array2<T> {
&self.weight_hh
}
}
impl<T: Float + Debug + Send + Sync + 'static> AttentionMechanism<T> {
pub fn projection_snapshots(&self) -> (&Array2<T>, &Array2<T>, &Array2<T>, &Array2<T>) {
(
&self.query_proj,
&self.key_proj,
&self.value_proj,
&self.output_proj,
)
}
}
impl<T: Float + Debug + Send + Sync + 'static> LSTMNetwork<T> {
pub fn layer_count(&self) -> usize {
self.layers.len()
}
pub fn layer(&self, index: usize) -> Option<&LSTMLayer<T>> {
self.layers.get(index)
}
pub fn output_projection_snapshot(&self) -> &OutputProjection<T> {
&self.output_projection
}
pub fn attention_snapshot(&self) -> Option<&AttentionMechanism<T>> {
self.attention.as_ref()
}
}
impl<T: Float + Debug + Send + Sync + 'static> LSTMOptimizer<T> {
pub fn first_layer_weight_snapshot(&self) -> Option<(&Array2<T>, &Array2<T>)> {
self.lstm_network
.layer(0)
.map(|layer| (layer.weight_ih_snapshot(), layer.weight_hh_snapshot()))
}
pub fn network_snapshot(&self) -> &LSTMNetwork<T> {
&self.lstm_network
}
}