concision_core/activate/traits/
unary.rs1macro_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 $name:ident::$call:ident($($rest:tt)*)
48 ),* $(,)?) => {
49 $(
50 _unary!(@impl $name::$call($($rest)*));
51 )*
52 };
53}
54
55unary! {
56 Heavyside::heavyside(self),
57 LinearActivation::linear(self),
58 Sigmoid::sigmoid(self),
59 Softmax::softmax(&self),
60 ReLU::relu(&self),
61 Tanh::tanh(&self),
62}
63
64pub trait SoftmaxAxis: Softmax {
65 fn softmax_axis(self, axis: usize) -> Self::Output;
66}