Done with activation softmax backwards

This commit is contained in:
2026-07-31 19:08:57 +02:00
parent d7b74ab40f
commit 11da534fd6
30 changed files with 3029 additions and 184 deletions
+176
View File
@@ -0,0 +1,176 @@
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
*
* PANIC
* Portable Algorithms and Numerics In C++
*
* Scientific computing from scratch, with feeling.
*
* Copyright (c) 2026 Michelle Bausager
*
* This file is part of PANIC.
*
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
* You may redistribute and/or modify it under the terms of the GPL.
*
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the LICENSE file for the full license text.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* Project Name: PANIC
* Module Name: math
* File Name: argmax.hpp
* Revision: 0.1.0
* Date: 31-07-2026
* Author: Michelle Bausager
*
* Description:
* Functions to find the index of the maximum value;
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma once
#include <config/types.hpp>
#include <tensor/vector.hpp> // for panic::vector
#include <tensor/matrix.hpp> // for panic::matrix
namespace panic{
namespace math{
/**
* @brief Returns the index of maximum value of a vector
*
* Computes:
* @code
* @endcode
*
* @tparam T Numeric element type.
* @param a Input vector.
*
* @return A new vector containing the result.
* @return An empty vector if the operation fails.
*
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
panic::types::uint_t argmax(const panic::tensor::vector<T>& a);
/**
* @brief Calculates the index of the maximum value of a matrix.
*
* Computes:
* @code
* @endcode
*
* @tparam T Numeric element type.
* @param A Input matrix.
* @param b Output vector for index
*
* @return A new matrix containing the result.
* @return An empty matrix if the operation fails.
*
*/
template <typename T>
bool argmax(const panic::tensor::matrix<T>& A, panic::tensor::uint_vector& b);
/**
* @brief Returns the index of the maximum value of a matrix.
*
* Computes:
* @code
* @endcode
*
* @tparam T Numeric element type.
* @param A Input matrix.
*
* @return A new matrix containing the result.
* @return An empty matrix if the operation fails.
*
*/
template <typename T>
panic::types::uint_t argmax(const panic::tensor::matrix<T>& A);
/**
* @brief Find the index of the maximum values row-wise of a matrix.
*
* Computes:
* @code
* @endcode
*
* @tparam T Numeric element type.
* @param A Input matrix.
* @param C Output vector with indexes. Resized to match @p A.cols().
*
* @return true if @p c was resized and filled successfully.
* @return false if vector sizes do not match or resizing @p c failed.
*/
template <typename T>
bool argmax_rowwise(const panic::tensor::matrix<T>& A, panic::tensor::uint_vector& c);
/**
* @brief Returns a new matrix containing the index of the maiximum row-wise elementwise.
*
* Computes:
* @code
* @endcode
*
* @tparam T Numeric element type.
* @param A Input matrix.
*
* @return A new matrix containing the result.
* @return An empty matrix if the operation fails.
*
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
panic::tensor::uint_vector argmax_rowwise(const panic::tensor::matrix<T>& A);
/**
* @brief Find the index of the maximum values column-wise of a matrix.
*
* Computes:
* @code
* @endcode
*
* @tparam T Numeric element type.
* @param A Input matrix.
* @param C Output matrix. Resized to match @p A.rows().
*
* @return true if @p c was resized and filled successfully.
* @return false if vector sizes do not match or resizing @p c failed.
*/
template <typename T>
bool argmax_colwise(const panic::tensor::matrix<T>& A, panic::tensor::uint_vector& c);
/**
* @brief Returns a new matrix containing the index of the maiximum column-wise elementwise.
*
* Computes:
* @code
* @endcode
*
* @tparam T Numeric element type.
* @param A Input matrix.
*
* @return A new matrix containing the result.
* @return An empty matrix if the operation fails.
*
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
panic::tensor::uint_vector argmax_colwise(const panic::tensor::matrix<T>& A);
} // namespace math
} // namespace panic