Skip to main content

teeny_core/nn/activation/
sigmoid.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/// Sigmoid activation layer: `1 / (1 + e^-x)`.
25pub struct Sigmoid<D: Float, T, const RANK: usize> {
26    _pd: PhantomData<(D, T)>,
27}
28
29impl<D: Float, T, const RANK: usize> Sigmoid<D, T, RANK> {
30    /// Creates a new `Sigmoid` layer.
31    pub fn new() -> Self {
32        Self { _pd: PhantomData }
33    }
34}
35
36impl<D: Float, T, const RANK: usize> Default for Sigmoid<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>
43    for Sigmoid<D, T, RANK>
44{
45    type Output = T;
46    fn call(&self, _input: T) -> Self::Output {
47        todo!()
48    }
49}
50
51/// SiLU/Swish activation layer: `x * sigmoid(x)`.
52pub struct Silu<D: Float, T, const RANK: usize> {
53    _pd: PhantomData<(D, T)>,
54}
55
56impl<D: Float, T, const RANK: usize> Silu<D, T, RANK> {
57    /// Creates a new `Silu` layer.
58    pub fn new() -> Self {
59        Self { _pd: PhantomData }
60    }
61}
62
63impl<D: Float, T, const RANK: usize> Default for Silu<D, T, RANK> {
64    fn default() -> Self {
65        Self::new()
66    }
67}
68
69impl<D: Float, T: Tensor<D, RANK> + EagerTensor, const RANK: usize> Layer<T> for Silu<D, T, RANK> {
70    type Output = T;
71    fn call(&self, _input: T) -> Self::Output {
72        todo!()
73    }
74}
75
76/// Log-sigmoid activation layer: `ln(sigmoid(x))`.
77pub struct Logsigmoid<D: Float, T, const RANK: usize> {
78    _pd: PhantomData<(D, T)>,
79}
80
81impl<D: Float, T, const RANK: usize> Logsigmoid<D, T, RANK> {
82    /// Creates a new `Logsigmoid` layer.
83    pub fn new() -> Self {
84        Self { _pd: PhantomData }
85    }
86}
87
88impl<D: Float, T, const RANK: usize> Default for Logsigmoid<D, T, RANK> {
89    fn default() -> Self {
90        Self::new()
91    }
92}
93
94impl<D: Float, T: Tensor<D, RANK> + EagerTensor, const RANK: usize> Layer<T>
95    for Logsigmoid<D, T, RANK>
96{
97    type Output = T;
98    fn call(&self, _input: T) -> Self::Output {
99        todo!()
100    }
101}