oa/ml/nn/
activation.gen.rs1use crate::{Matrix, Result};
6
7use super::super::{Module, ModuleRegistry, matrix};
8
9pub struct Relu {
13 registry: ModuleRegistry,
14}
15
16impl Relu {
17 pub const fn new() -> Self {
19 Self {
20 registry: ModuleRegistry::new(),
21 }
22 }
23
24 pub fn forward(&self, input: &Matrix) -> Result<Matrix> {
30 matrix::relu(input)
31 }
32}
33
34impl Default for Relu {
35 fn default() -> Self {
36 Self::new()
37 }
38}
39
40impl Module for Relu {
41 fn forward(&self, input: &Matrix) -> Result<Matrix> {
42 Relu::forward(self, input)
43 }
44
45 fn registry(&self) -> &ModuleRegistry {
46 &self.registry
47 }
48}
49
50pub struct Gelu {
54 registry: ModuleRegistry,
55}
56
57impl Gelu {
58 pub const fn new() -> Self {
60 Self {
61 registry: ModuleRegistry::new(),
62 }
63 }
64
65 pub fn forward(&self, input: &Matrix) -> Result<Matrix> {
71 matrix::gelu(input)
72 }
73}
74
75impl Default for Gelu {
76 fn default() -> Self {
77 Self::new()
78 }
79}
80
81impl Module for Gelu {
82 fn forward(&self, input: &Matrix) -> Result<Matrix> {
83 Gelu::forward(self, input)
84 }
85
86 fn registry(&self) -> &ModuleRegistry {
87 &self.registry
88 }
89}
90
91pub struct Silu {
95 registry: ModuleRegistry,
96}
97
98impl Silu {
99 pub const fn new() -> Self {
101 Self {
102 registry: ModuleRegistry::new(),
103 }
104 }
105
106 pub fn forward(&self, input: &Matrix) -> Result<Matrix> {
112 matrix::silu(input)
113 }
114}
115
116impl Default for Silu {
117 fn default() -> Self {
118 Self::new()
119 }
120}
121
122impl Module for Silu {
123 fn forward(&self, input: &Matrix) -> Result<Matrix> {
124 Silu::forward(self, input)
125 }
126
127 fn registry(&self) -> &ModuleRegistry {
128 &self.registry
129 }
130}