teeny_core/nn/activation/softmax.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/// Softmax activation layer: normalizes along `dim` so values sum to 1.
25pub struct Softmax<D: Float, T, const RANK: usize> {
26 /// The dimension to normalize along.
27 pub dim: usize,
28 _pd: PhantomData<(D, T)>,
29}
30
31impl<D: Float, T, const RANK: usize> Softmax<D, T, RANK> {
32 /// Creates a new `Softmax` layer.
33 pub fn new(dim: usize) -> Self {
34 Self {
35 dim,
36 _pd: PhantomData,
37 }
38 }
39}
40
41impl<D: Float, T: Tensor<D, RANK> + EagerTensor, const RANK: usize> Layer<T>
42 for Softmax<D, T, RANK>
43{
44 type Output = T;
45
46 fn call(&self, _input: T) -> Self::Output {
47 todo!()
48 }
49}