concision_traits/
propagate.rs

1/*
2    Appellation: propagate <module>
3    Created At: 2026.01.06:14:13:38
4    Contrib: @FL03
5*/
6
7/// The [`Backward`] trait establishes a common interface for completing a single backward
8/// step in a neural network or machine learning model.
9pub trait Backward<X, Delta = X> {
10    type Elem;
11
12    fn backward(&mut self, input: &X, delta: &Delta, gamma: Self::Elem);
13}
14
15pub trait BackwardStep<T> {
16    type Data<_X>;
17    type Grad<_X>;
18    type Output;
19
20    fn backward(&mut self, input: &Self::Data<T>, delta: &Self::Grad<T>, gamma: T) -> Self::Output;
21}
22
23/// A consuming implementation of forward propagation
24pub trait ForwardOnce<Rhs> {
25    type Output;
26    /// a single forward step consuming the implementor
27    fn forward_once(self, input: Rhs) -> Self::Output;
28}
29/// The [`Forward`] trait describes a common interface for objects designated to perform a
30/// single forward step in a neural network or machine learning model.
31pub trait Forward<Rhs> {
32    type Output;
33    /// a single forward step
34    fn forward(&self, input: &Rhs) -> Self::Output;
35    /// this method enables the forward pass to be generically _activated_ using some closure.
36    /// This is useful for isolating the logic of the forward pass from that of the activation
37    /// function and is often used by layers and models.
38    fn forward_then<F>(&self, input: &Rhs, then: F) -> Self::Output
39    where
40        F: FnOnce(Self::Output) -> Self::Output,
41    {
42        then(self.forward(input))
43    }
44}
45
46pub trait ForwardMut<Rhs> {
47    type Output;
48    /// a single forward step with mutable access
49    fn forward_mut(&mut self, input: &Rhs) -> Self::Output;
50}