burn_core/nn/
tanh.rs

1use crate as burn;
2
3use crate::module::Module;
4use crate::tensor::Tensor;
5use crate::tensor::backend::Backend;
6
7/// Applies the tanh activation function element-wise
8/// See also [tanh](burn::tensor::activation::tanh)
9#[derive(Module, Clone, Debug, Default)]
10pub struct Tanh;
11
12impl Tanh {
13    /// Create the module.
14    pub fn new() -> Self {
15        Self {}
16    }
17    /// Applies the forward pass on the input tensor.
18    ///
19    /// # Shapes
20    ///
21    /// - input: `[..., any]`
22    /// - output: `[..., any]`
23    pub fn forward<B: Backend, const D: usize>(&self, input: Tensor<B, D>) -> Tensor<B, D> {
24        crate::tensor::activation::tanh(input)
25    }
26}
27
28#[cfg(test)]
29mod tests {
30    use super::*;
31
32    #[test]
33    fn display() {
34        let layer = Tanh::new();
35
36        assert_eq!(alloc::format!("{layer}"), "Tanh");
37    }
38}