use crate::nn::module::Module;
use crate::tensor::Tensor;
pub struct ReLU;
impl ReLU {
pub fn new() -> Self {
ReLU {}
}
}
impl Default for ReLU {
fn default() -> Self {
Self::new()
}
}
impl Module for ReLU {
fn forward(&self, inputs: &Tensor) -> Tensor {
inputs.relu()
}
fn parameters(&self) -> Vec<Tensor> {
Vec::new()
}
}
pub struct LeakyReLU {
pub negative_slope: f32,
}
impl LeakyReLU {
pub fn new(negative_slope: f32) -> Self {
Self { negative_slope }
}
}
impl Default for LeakyReLU {
fn default() -> Self {
Self::new(0.01)
}
}
impl Module for LeakyReLU {
fn forward(&self, inputs: &Tensor) -> Tensor {
inputs.leaky_relu(self.negative_slope)
}
fn parameters(&self) -> Vec<Tensor> {
Vec::new()
}
}
pub struct GELU;
impl GELU {
pub fn new() -> Self {
GELU {}
}
}
impl Default for GELU {
fn default() -> Self {
Self::new()
}
}
impl Module for GELU {
fn forward(&self, inputs: &Tensor) -> Tensor {
inputs.gelu()
}
fn parameters(&self) -> Vec<Tensor> {
Vec::new()
}
}
pub struct SiLU;
impl SiLU {
pub fn new() -> Self {
SiLU {}
}
}
impl Default for SiLU {
fn default() -> Self {
Self::new()
}
}
impl Module for SiLU {
fn forward(&self, inputs: &Tensor) -> Tensor {
inputs.silu()
}
fn parameters(&self) -> Vec<Tensor> {
Vec::new()
}
}
pub type Swish = SiLU;
pub struct Tanh;
impl Tanh {
pub fn new() -> Self {
Tanh {}
}
}
impl Default for Tanh {
fn default() -> Self {
Self::new()
}
}
impl Module for Tanh {
fn forward(&self, inputs: &Tensor) -> Tensor {
inputs.tanh()
}
fn parameters(&self) -> Vec<Tensor> {
Vec::new()
}
}
pub struct Sigmoid;
impl Sigmoid {
pub fn new() -> Self {
Sigmoid {}
}
}
impl Default for Sigmoid {
fn default() -> Self {
Self::new()
}
}
impl Module for Sigmoid {
fn forward(&self, inputs: &Tensor) -> Tensor {
inputs.sigmoid()
}
fn parameters(&self) -> Vec<Tensor> {
Vec::new()
}
}
pub struct ELU {
pub alpha: f32,
}
impl ELU {
pub fn new(alpha: f32) -> Self {
Self { alpha }
}
}
impl Default for ELU {
fn default() -> Self {
Self::new(1.0)
}
}
impl Module for ELU {
fn forward(&self, inputs: &Tensor) -> Tensor {
inputs.elu(self.alpha)
}
fn parameters(&self) -> Vec<Tensor> {
Vec::new()
}
}
pub struct Softplus {
pub beta: f32,
pub threshold: f32,
}
impl Softplus {
pub fn new(beta: f32, threshold: f32) -> Self {
Self { beta, threshold }
}
}
impl Default for Softplus {
fn default() -> Self {
Self::new(1.0, 20.0)
}
}
impl Module for Softplus {
fn forward(&self, inputs: &Tensor) -> Tensor {
inputs.softplus(self.beta)
}
fn parameters(&self) -> Vec<Tensor> {
Vec::new()
}
}
pub struct Softmax;
impl Softmax {
pub fn new() -> Self {
Softmax {}
}
}
impl Default for Softmax {
fn default() -> Self {
Self::new()
}
}
impl Module for Softmax {
fn forward(&self, inputs: &Tensor) -> Tensor {
inputs.softmax()
}
fn parameters(&self) -> Vec<Tensor> {
Vec::new()
}
}