Skip to main content

teeny_core/nn/activation/
gelu.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/// GELU (Gaussian Error Linear Unit) activation layer.
25pub struct Gelu<D: Float, T, const RANK: usize> {
26    _pd: PhantomData<(D, T)>,
27}
28
29impl<D: Float, T, const RANK: usize> Gelu<D, T, RANK> {
30    /// Creates a new `Gelu` layer.
31    pub fn new() -> Self {
32        Self { _pd: PhantomData }
33    }
34}
35
36impl<D: Float, T, const RANK: usize> Default for Gelu<D, T, RANK> {
37    fn default() -> Self {
38        Self::new()
39    }
40}
41
42impl<D: Float, T: Tensor<D, RANK> + EagerTensor, const RANK: usize> Layer<T> for Gelu<D, T, RANK> {
43    type Output = T;
44    fn call(&self, _input: T) -> Self::Output {
45        todo!()
46    }
47}
48
49/// Mish activation layer (`x * tanh(softplus(x))`).
50pub struct Mish<D: Float, T, const RANK: usize> {
51    _pd: PhantomData<(D, T)>,
52}
53
54impl<D: Float, T, const RANK: usize> Mish<D, T, RANK> {
55    /// Creates a new `Mish` layer.
56    pub fn new() -> Self {
57        Self { _pd: PhantomData }
58    }
59}
60
61impl<D: Float, T, const RANK: usize> Default for Mish<D, T, RANK> {
62    fn default() -> Self {
63        Self::new()
64    }
65}
66
67impl<D: Float, T: Tensor<D, RANK> + EagerTensor, const RANK: usize> Layer<T> for Mish<D, T, RANK> {
68    type Output = T;
69    fn call(&self, _input: T) -> Self::Output {
70        todo!()
71    }
72}