1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// @generated by tool/gen/nn/generate.py; DO NOT EDIT.
// Source: tool/gen/nn/schema/ml/ml_nn_activation.json
// generator_version=8; schema_sha256=5e544cf80400a3070354390826c3019e086ae1dfce45e4eaf640fb7476e318cc
use crate::{Matrix, Result};
use super::super::{Module, ModuleRegistry, matrix};
// OA donor: oacpp/source/cpp/lib/oa/ml/nn/relu/relu.cpp
// Adaptation: Rust ownership, ModuleRegistry and checked error contracts; preserved operation behavior
/// Rectified linear unit module.
pub struct Relu {
registry: ModuleRegistry,
}
impl Relu {
/// Construct the parameterless activation module.
pub const fn new() -> Self {
Self {
registry: ModuleRegistry::new(),
}
}
/// Apply the activation without submitting or waiting.
///
/// # Errors
///
/// Returns an error from the underlying Matrix operation.
pub fn forward(&self, input: &Matrix) -> Result<Matrix> {
matrix::relu(input)
}
}
impl Default for Relu {
fn default() -> Self {
Self::new()
}
}
impl Module for Relu {
fn forward(&self, input: &Matrix) -> Result<Matrix> {
Relu::forward(self, input)
}
fn registry(&self) -> &ModuleRegistry {
&self.registry
}
}
// OA donor: oacpp/source/cpp/lib/oa/ml/nn/gelu/gelu.cpp
// Adaptation: Rust ownership, ModuleRegistry and checked error contracts; preserved operation behavior
/// Gaussian error linear unit module using OA's tanh approximation.
pub struct Gelu {
registry: ModuleRegistry,
}
impl Gelu {
/// Construct the parameterless activation module.
pub const fn new() -> Self {
Self {
registry: ModuleRegistry::new(),
}
}
/// Apply the activation without submitting or waiting.
///
/// # Errors
///
/// Returns an error from the underlying Matrix operation.
pub fn forward(&self, input: &Matrix) -> Result<Matrix> {
matrix::gelu(input)
}
}
impl Default for Gelu {
fn default() -> Self {
Self::new()
}
}
impl Module for Gelu {
fn forward(&self, input: &Matrix) -> Result<Matrix> {
Gelu::forward(self, input)
}
fn registry(&self) -> &ModuleRegistry {
&self.registry
}
}
// OA donor: oacpp/source/cpp/lib/oa/ml/nn/silu/silu.cpp
// Adaptation: Rust ownership, ModuleRegistry and checked error contracts; preserved operation behavior
/// Sigmoid linear unit module.
pub struct Silu {
registry: ModuleRegistry,
}
impl Silu {
/// Construct the parameterless activation module.
pub const fn new() -> Self {
Self {
registry: ModuleRegistry::new(),
}
}
/// Apply the activation without submitting or waiting.
///
/// # Errors
///
/// Returns an error from the underlying Matrix operation.
pub fn forward(&self, input: &Matrix) -> Result<Matrix> {
matrix::silu(input)
}
}
impl Default for Silu {
fn default() -> Self {
Self::new()
}
}
impl Module for Silu {
fn forward(&self, input: &Matrix) -> Result<Matrix> {
Silu::forward(self, input)
}
fn registry(&self) -> &ModuleRegistry {
&self.registry
}
}