Skip to main content

teeny_core/nn/activation/
elu.rs

1/*
2 * Copyright (c) 2026 Teenygrad.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *   http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use core::marker::PhantomData;
18
19use crate::{
20    dtype::{EagerTensor, Float, Tensor},
21    nn::Layer,
22};
23
24/// ELU (Exponential Linear Unit) activation layer.
25pub struct Elu<D: Float, T, const RANK: usize> {
26    /// The `alpha` scaling factor for negative inputs.
27    pub alpha: f64,
28    _pd: PhantomData<(D, T)>,
29}
30
31impl<D: Float, T, const RANK: usize> Elu<D, T, RANK> {
32    /// Creates a new `Elu` layer with the given `alpha`.
33    pub fn new(alpha: f64) -> Self {
34        Self {
35            alpha,
36            _pd: PhantomData,
37        }
38    }
39}
40
41impl<D: Float, T: Tensor<D, RANK> + EagerTensor, const RANK: usize> Layer<T> for Elu<D, T, RANK> {
42    type Output = T;
43    fn call(&self, _input: T) -> Self::Output {
44        todo!()
45    }
46}
47
48/// SELU (Scaled Exponential Linear Unit) activation layer.
49pub struct Selu<D: Float, T, const RANK: usize> {
50    _pd: PhantomData<(D, T)>,
51}
52
53impl<D: Float, T, const RANK: usize> Selu<D, T, RANK> {
54    /// Creates a new `Selu` layer.
55    pub fn new() -> Self {
56        Self { _pd: PhantomData }
57    }
58}
59
60impl<D: Float, T, const RANK: usize> Default for Selu<D, T, RANK> {
61    fn default() -> Self {
62        Self::new()
63    }
64}
65
66impl<D: Float, T: Tensor<D, RANK> + EagerTensor, const RANK: usize> Layer<T> for Selu<D, T, RANK> {
67    type Output = T;
68    fn call(&self, _input: T) -> Self::Output {
69        todo!()
70    }
71}
72
73/// CELU (Continuously Differentiable Exponential Linear Unit) activation layer.
74pub struct Celu<D: Float, T, const RANK: usize> {
75    /// The `alpha` scaling factor.
76    pub alpha: f64,
77    _pd: PhantomData<(D, T)>,
78}
79
80impl<D: Float, T, const RANK: usize> Celu<D, T, RANK> {
81    /// Creates a new `Celu` layer.
82    pub fn new(alpha: f64) -> Self {
83        Self {
84            alpha,
85            _pd: PhantomData,
86        }
87    }
88}
89
90impl<D: Float, T: Tensor<D, RANK> + EagerTensor, const RANK: usize> Layer<T> for Celu<D, T, RANK> {
91    type Output = T;
92    fn call(&self, _input: T) -> Self::Output {
93        todo!()
94    }
95}