Skip to content

Commit d1ced08

Browse files
committed
update
Signed-off-by: FL03 <jo3mccain@icloud.com>
1 parent e92f0ff commit d1ced08

4 files changed

Lines changed: 37 additions & 11 deletions

File tree

core/src/nn/layer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ mod types {
2525
#[cfg(feature = "alloc")]
2626
use alloc::boxed::Box;
2727
use concision_params::{Params, ParamsBase};
28-
use concision_traits::activate::{HeavySide, Linear, ReLU, Sigmoid, TanhActivator};
28+
use concision_traits::activate::{HeavySide, HyperbolicTangent, Linear, ReLU, Sigmoid};
2929

3030
/// A type alias for a layer configured to use the [`ParamsBase`] instance
3131
pub type LayerParamsBase<F, S, D = ndarray::Ix2, A = f32> = LayerBase<F, ParamsBase<S, D, A>>;
@@ -36,7 +36,7 @@ mod types {
3636
/// A type alias for a [`Layer`] using a sigmoid activation function.
3737
pub type SigmoidLayer<T> = LayerBase<Sigmoid, T>;
3838
/// An alias for a [`Layer`] that uses the hyperbolic tangent function.
39-
pub type TanhLayer<T> = LayerBase<TanhActivator, T>;
39+
pub type TanhLayer<T> = LayerBase<HyperbolicTangent, T>;
4040
/// A [`Layer`] type using the ReLU activation function.
4141
pub type ReluLayer<T> = LayerBase<ReLU, T>;
4242
/// A [`Layer`] type using the heavyside activation function.

core/src/nn/layer/impl_layer.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ impl<F, P, A> LayerBase<F, P>
1212
where
1313
P: RawParams<Elem = A>,
1414
{
15-
/// create a new [`Layer`] from the given activation function and parameters.
15+
/// create a new [`LayerBase`] from the given activation function and parameters.
1616
pub const fn new(rho: F, params: P) -> Self {
1717
Self { rho, params }
1818
}
19-
/// create a new [`Layer`] from the given parameters assuming the logical default for
19+
/// create a new [`LayerBase`] from the given parameters assuming the logical default for
2020
/// the activation of type `F`.
2121
pub fn from_params(params: P) -> Self
2222
where
2323
F: Default,
2424
{
2525
Self::new(<F>::default(), params)
2626
}
27-
/// create a new [`Layer`] from the given activation function and shape.
27+
/// create a new [`LayerBase`] from the given activation function and shape.
2828
pub fn from_rho<Sh>(rho: F) -> Self
2929
where
3030
P: Default,
@@ -47,6 +47,7 @@ where
4747
pub const fn rho_mut(&mut self) -> &mut F {
4848
&mut self.rho
4949
}
50+
#[inline]
5051
/// consumes the current instance and returns another with the given parameters.
5152
pub fn with_params<Y>(self, params: Y) -> LayerBase<F, Y>
5253
where
@@ -57,18 +58,19 @@ where
5758
params,
5859
}
5960
}
61+
#[inline]
6062
/// consumes the current instance and returns another with the given activation function.
6163
/// This is useful during the creation of the model, when the activation function is not known yet.
6264
pub fn with_rho<G>(self, rho: G) -> LayerBase<G, P>
6365
where
6466
G: Activator<P>,
65-
F: Activator<P>,
6667
{
6768
LayerBase {
6869
rho,
6970
params: self.params,
7071
}
7172
}
73+
#[inline]
7274
/// apply the configured activation function onto some input, producing some output
7375
pub fn activate<X, Y>(&self, input: X) -> Y
7476
where

core/src/nn/layer/impl_layer_repr.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use super::LayerBase;
66

77
use concision_params::{ParamsBase, RawParams};
8-
use concision_traits::{Activator, Linear, ReLU, Sigmoid, TanhActivator};
8+
use concision_traits::{Activator, HyperbolicTangent, Linear, ReLU, Sigmoid};
99
use ndarray::{ArrayBase, DataOwned, Dimension, RawData, RemoveAxis, ShapeBuilder};
1010

1111
impl<F, S, D, A> LayerBase<F, ArrayBase<S, D, A>>
@@ -27,6 +27,18 @@ where
2727
params: ArrayBase::default(shape),
2828
}
2929
}
30+
31+
pub fn dim(&self) -> D::Pattern {
32+
self.params().dim()
33+
}
34+
35+
pub fn raw_dim(&self) -> D {
36+
self.params().raw_dim()
37+
}
38+
39+
pub fn shape(&self) -> &[usize] {
40+
self.params().shape()
41+
}
3042
}
3143

3244
impl<F, S, D, E, A> LayerBase<F, ParamsBase<S, D, A>>
@@ -65,6 +77,18 @@ where
6577
pub const fn weights_mut(&mut self) -> &mut ArrayBase<S, D, A> {
6678
self.params_mut().weights_mut()
6779
}
80+
81+
pub fn dim(&self) -> D::Pattern {
82+
self.params().dim()
83+
}
84+
85+
pub fn raw_dim(&self) -> D {
86+
self.params().raw_dim()
87+
}
88+
89+
pub fn shape(&self) -> &[usize] {
90+
self.params().shape()
91+
}
6892
}
6993

7094
impl<F, P, A> LayerBase<F, P>
@@ -100,15 +124,15 @@ where
100124
}
101125
}
102126

103-
impl<A, P> LayerBase<TanhActivator, P>
127+
impl<A, P> LayerBase<HyperbolicTangent, P>
104128
where
105129
P: RawParams<Elem = A>,
106130
{
107-
/// initialize a new layer using a [`HyperbolicTangent`] activation function and the given
131+
/// initialize a new layer using a [`TanhActivator`] activation function and the given
108132
/// parameters.
109133
pub const fn tanh(params: P) -> Self {
110134
Self {
111-
rho: TanhActivator,
135+
rho: HyperbolicTangent,
112136
params,
113137
}
114138
}

traits/src/activate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ activator! {
104104
pub struct Linear.linear where T: crate::activate::LinearActivation;
105105
pub struct ReLU.relu where T: crate::activate::ReLUActivation;
106106
pub struct Sigmoid.sigmoid where T: crate::activate::SigmoidActivation;
107-
pub struct TanhActivator.tanh where T: crate::activate::TanhActivation;
107+
pub struct HyperbolicTangent.tanh where T: crate::activate::TanhActivation;
108108
pub struct HeavySide.heavyside where T: crate::activate::HeavysideActivation;
109109
pub struct Softmax.softmax where T: crate::activate::SoftmaxActivation;
110110
}

0 commit comments

Comments
 (0)