concision_linear/impls/model/
impl_model.rs1use crate::{Config, Linear, LinearParams};
6use concision::prelude::{Module, Predict, PredictError};
7use nd::RemoveAxis;
8
9impl<A, K, D> Module for Linear<A, K, D>
10where
11 D: RemoveAxis,
12{
13 type Config = Config<K, D>;
14 type Params = LinearParams<A, K, D>;
15
16 fn config(&self) -> &Self::Config {
17 &self.config
18 }
19
20 fn params(&self) -> &Self::Params {
21 &self.params
22 }
23
24 fn params_mut(&mut self) -> &mut Self::Params {
25 &mut self.params
26 }
27}
28
29impl<U, V, A, K, D> Predict<U> for Linear<A, K, D>
30where
31 D: RemoveAxis,
32 LinearParams<A, K, D>: Predict<U, Output = V>,
33{
34 type Output = V;
35
36 #[cfg_attr(
37 feature = "tracing",
38 tracing::instrument(skip_all, level = "debug", name = "predict", target = "linear")
39 )]
40 fn predict(&self, input: &U) -> Result<Self::Output, PredictError> {
41 #[cfg(feature = "tracing")]
42 tracing::debug!("Predicting with linear model");
43 self.params().predict(input)
44 }
45}