concision_core/models/layout/
impl_model_layout.rs

1/*
2    Appellation: impl_model_layout <module>
3    Created At: 2025.12.09:07:46:57
4    Contrib: @FL03
5*/
6use super::ModelLayout;
7
8use crate::models::{Deep, NetworkDepth, RawModelLayout, Shallow};
9
10impl<F, D> ModelLayout<F, D>
11where
12    F: RawModelLayout,
13    D: NetworkDepth,
14{
15    /// creates a new instance of [`ModelLayout`] using the given features
16    pub const fn new(features: F) -> Self {
17        Self {
18            features,
19            _marker: core::marker::PhantomData::<D>,
20        }
21    }
22    /// returns a reference to the features of the model layout
23    pub const fn features(&self) -> &F {
24        &self.features
25    }
26    /// returns a mutable reference to the features of the model layout
27    pub const fn features_mut(&mut self) -> &mut F {
28        &mut self.features
29    }
30    /// returns a reference to the input of the model layout
31    pub fn input(&self) -> usize {
32        self.features().input()
33    }
34    /// returns a reference to the output of the model layout
35    pub fn output(&self) -> usize {
36        self.features().output()
37    }
38    /// returns a reference to the hidden features of the model layout
39    pub fn hidden(&self) -> usize {
40        self.features().hidden()
41    }
42    /// returns a reference to the depth, or number of hidden layers, of the model
43    pub fn layers(&self) -> usize {
44        self.features().depth()
45    }
46}
47
48impl<F, D> core::ops::Deref for ModelLayout<F, D>
49where
50    F: RawModelLayout,
51    D: NetworkDepth,
52{
53    type Target = F;
54
55    fn deref(&self) -> &Self::Target {
56        &self.features
57    }
58}
59
60impl<F, D> core::ops::DerefMut for ModelLayout<F, D>
61where
62    F: RawModelLayout,
63    D: NetworkDepth,
64{
65    fn deref_mut(&mut self) -> &mut Self::Target {
66        &mut self.features
67    }
68}
69
70impl<F> ModelLayout<F, Deep>
71where
72    F: RawModelLayout,
73{
74    /// creates a new instance of [`ModelLayout`] using the given features
75    pub const fn deep(features: F) -> Self {
76        Self::new(features)
77    }
78}
79
80impl<F> ModelLayout<F, Shallow>
81where
82    F: RawModelLayout,
83{
84    /// returns a new instance of the model layout using the given features and a shallow depth
85    pub const fn shallow(features: F) -> Self {
86        Self::new(features)
87    }
88}