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 ($(
42 $name:ident::$call:ident($($rest:tt)*)
43 ),* $(,)?) => {
44 $(
45 unary!(@impl $name::$call($($rest)*));
46 )*
47 };
48}
49
50unary! {
51 Heavyside::heavyside(self),
52 LinearActivation::linear(self),
53 Sigmoid::sigmoid(self),
54 Softmax::softmax(&self),
55 ReLU::relu(&self),
56 Tanh::tanh(&self),
57}
58
59pub trait SoftmaxAxis: Softmax {
60 fn softmax_axis(self, axis: usize) -> Self::Output;
61}