Skip to main content

oa/ml/nn/
activation.gen.rs

1// @generated by tool/gen/nn/generate.py; DO NOT EDIT.
2// Source: tool/gen/nn/schema/ml/ml_nn_activation.json
3// generator_version=8; schema_sha256=5e544cf80400a3070354390826c3019e086ae1dfce45e4eaf640fb7476e318cc
4
5use crate::{Matrix, Result};
6
7use super::super::{Module, ModuleRegistry, matrix};
8
9// OA donor: oacpp/source/cpp/lib/oa/ml/nn/relu/relu.cpp
10// Adaptation: Rust ownership, ModuleRegistry and checked error contracts; preserved operation behavior
11/// Rectified linear unit module.
12pub struct Relu {
13	registry: ModuleRegistry,
14}
15
16impl Relu {
17	/// Construct the parameterless activation module.
18	pub const fn new() -> Self {
19		Self {
20			registry: ModuleRegistry::new(),
21		}
22	}
23
24	/// Apply the activation without submitting or waiting.
25	///
26	/// # Errors
27	///
28	/// Returns an error from the underlying Matrix operation.
29	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
50// OA donor: oacpp/source/cpp/lib/oa/ml/nn/gelu/gelu.cpp
51// Adaptation: Rust ownership, ModuleRegistry and checked error contracts; preserved operation behavior
52/// Gaussian error linear unit module using OA's tanh approximation.
53pub struct Gelu {
54	registry: ModuleRegistry,
55}
56
57impl Gelu {
58	/// Construct the parameterless activation module.
59	pub const fn new() -> Self {
60		Self {
61			registry: ModuleRegistry::new(),
62		}
63	}
64
65	/// Apply the activation without submitting or waiting.
66	///
67	/// # Errors
68	///
69	/// Returns an error from the underlying Matrix operation.
70	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
91// OA donor: oacpp/source/cpp/lib/oa/ml/nn/silu/silu.cpp
92// Adaptation: Rust ownership, ModuleRegistry and checked error contracts; preserved operation behavior
93/// Sigmoid linear unit module.
94pub struct Silu {
95	registry: ModuleRegistry,
96}
97
98impl Silu {
99	/// Construct the parameterless activation module.
100	pub const fn new() -> Self {
101		Self {
102			registry: ModuleRegistry::new(),
103		}
104	}
105
106	/// Apply the activation without submitting or waiting.
107	///
108	/// # Errors
109	///
110	/// Returns an error from the underlying Matrix operation.
111	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}