concision_core/traits/
train.rs

1/*
2   Appellation: train <module>
3   Contrib: FL03 <jo3mccain@icloud.com>
4*/
5
6pub trait ApplyGradient {
7    type Gradient;
8
9    fn apply_gradient(&mut self, gradient: &Self::Gradient);
10}
11
12/// [Backward] describes an object capable of backward propagation.
13pub trait Backward {
14    type Output;
15
16    fn backward(&self) -> Self::Output;
17}
18
19pub trait Compile {
20    type Dataset;
21
22    fn compile(&mut self, dataset: &Self::Dataset);
23}
24
25pub trait Train: Compile {
26    type Output;
27
28    fn train(&mut self) -> Self::Output;
29}
30
31impl<S> Backward for Option<S>
32where
33    S: Backward,
34{
35    type Output = Option<S::Output>;
36
37    fn backward(&self) -> Self::Output {
38        match self {
39            Some(s) => Some(s.backward()),
40            None => None,
41        }
42    }
43}