use crate::activate::Activator;
use crate::nn::layer::LayerBase;
use concision_params::RawParams;
use concision_traits::Forward;
impl<F, P, A> LayerBase<F, P>
where
P: RawParams<Elem = A>,
{
pub const fn new(rho: F, params: P) -> Self {
Self { rho, params }
}
pub fn from_params(params: P) -> Self
where
F: Default,
{
Self::new(<F>::default(), params)
}
pub fn from_rho<Sh>(rho: F) -> Self
where
P: Default,
{
Self::new(rho, <P>::default())
}
pub const fn params(&self) -> &P {
&self.params
}
pub const fn params_mut(&mut self) -> &mut P {
&mut self.params
}
pub const fn rho(&self) -> &F {
&self.rho
}
pub const fn rho_mut(&mut self) -> &mut F {
&mut self.rho
}
#[inline]
pub fn with_params<Y>(self, params: Y) -> LayerBase<F, Y>
where
F: Activator<Y>,
{
LayerBase {
rho: self.rho,
params,
}
}
#[inline]
pub fn with_rho<G>(self, rho: G) -> LayerBase<G, P>
where
G: Activator<P>,
{
LayerBase {
rho,
params: self.params,
}
}
#[inline]
pub fn activate<X, Y>(&self, input: X) -> Y
where
F: Activator<X, Output = Y>,
{
self.rho().activate(input)
}
pub fn forward<U, V>(&self, input: &U) -> V
where
Self: Forward<U, Output = V>,
{
<Self as Forward<U>>::forward(self, input)
}
}