concision_core/activate/traits/
unary.rs

1/*
2    appellation: unary <module>
3    authors: @FL03
4*/
5
6macro_rules! _unary {
7    (@impl $name:ident::$call:ident(self)) => {
8        paste::paste! {
9            pub trait $name {
10                type Output;
11
12                fn $call(self) -> Self::Output;
13
14                fn [<$call _derivative>](self) -> Self::Output;
15            }
16        }
17
18    };
19    (@impl $name:ident::$call:ident(&self)) => {
20        paste::paste! {
21            pub trait $name {
22                type Output;
23
24                fn $call(&self) -> Self::Output;
25
26                fn [<$call _derivative>](&self) -> Self::Output;
27            }
28        }
29    };
30    (@impl $name:ident::$call:ident(&mut self)) => {
31        paste::paste! {
32            pub trait $name {
33                type Output;
34
35                fn $call(&mut self) -> Self::Output;
36
37                fn [<$call _derivative>](&mut self) -> Self::Output;
38            }
39        }
40    };
41    ($name:ident::$call:ident($($rest:tt)*)) => {
42        _unary!(@impl $name::$call($($rest)*));
43    };
44}
45macro_rules! unary {
46    {
47        $(
48            $name:ident::$call:ident($($rest:tt)*)
49        ),* $(,)?
50    } => {
51        $(
52            _unary!(@impl $name::$call($($rest)*));
53        )*
54    };
55}
56
57unary! {
58    Heavyside::heavyside(self),
59    LinearActivation::linear(self),
60    Sigmoid::sigmoid(self),
61    Softmax::softmax(&self),
62    ReLU::relu(&self),
63    Tanh::tanh(&self),
64}
65
66pub trait SoftmaxAxis: Softmax {
67    fn softmax_axis(self, axis: usize) -> Self::Output;
68}