concision_core/nn/model/
module.rs

1/*
2   Appellation: modules <traits::nn>
3   Contrib: FL03 <jo3mccain@icloud.com>
4*/
5use crate::{Config, Predict};
6
7pub type ModuleDyn<C, P> = Box<dyn Module<Config = C, Params = P>>;
8pub type DynModuleExt<X, Y, C, P> = Box<dyn ModuleExt<X, Config = C, Output = Y, Params = P>>;
9pub type Stack<X, Y, C, P> = Vec<Box<dyn ModuleExt<X, Config = C, Output = Y, Params = P>>>;
10
11/// A `Module` defines any object that may be used as a layer in a neural network.
12/// [Config](Module::Config) is a type that defines the configuration of the module; including any and all hyperparameters.
13/// [Params](Module::Params) is a type that defines the parameters of the module; typically references a Linear set of parameters { weights, bias }
14pub trait Module {
15    type Config: Config;
16    type Params;
17
18    fn config(&self) -> &Self::Config;
19
20    fn params(&self) -> &Self::Params;
21
22    fn params_mut(&mut self) -> &mut Self::Params;
23}
24
25pub trait ModuleExt<T>: Module + Predict<T> {}
26
27impl<T, M> ModuleExt<T> for M where M: Module + Predict<T> {}