Activation Softmax Forward done
This commit is contained in:
@@ -0,0 +1,158 @@
|
||||
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
*
|
||||
* 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: sum.hpp
|
||||
* Revision: 0.1.0
|
||||
* Date: 25-06-2026
|
||||
* Author: Michelle Bausager
|
||||
*
|
||||
* Description:
|
||||
* Functions to sum up arrays
|
||||
*
|
||||
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||
#pragma once
|
||||
|
||||
#include <tensor/vector.hpp> // for panic::vector
|
||||
#include <tensor/matrix.hpp> // for panic::matrix
|
||||
|
||||
namespace panic{
|
||||
namespace math{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Returns the sum value of a vector
|
||||
*
|
||||
* Computes:
|
||||
* @code
|
||||
* result = sum(a)
|
||||
* @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>
|
||||
T sum(const panic::tensor::vector<T>& a);
|
||||
|
||||
/**
|
||||
* @brief Returns the sum value of a matrix.
|
||||
*
|
||||
* Computes:
|
||||
* @code
|
||||
* result = sum(A)
|
||||
* @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>
|
||||
T sum(const panic::tensor::matrix<T>& A);
|
||||
|
||||
/**
|
||||
* @brief Find the sum values row-wise of a matrix.
|
||||
*
|
||||
* Computes:
|
||||
* @code
|
||||
* c(i) = sum(A(i,j))
|
||||
* @endcode
|
||||
*
|
||||
* @tparam T Numeric element type.
|
||||
* @param A Input matrix.
|
||||
* @param c Output vector. 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 sum_rowwise(const panic::tensor::matrix<T>& A, panic::tensor::vector<T>& c);
|
||||
|
||||
/**
|
||||
* @brief Returns a new matrix containing the sum row-wise elementwise.
|
||||
*
|
||||
* Computes:
|
||||
* @code
|
||||
* result[i] = sum(A(i,j))
|
||||
* @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::vector<T> sum_rowwise(const panic::tensor::matrix<T>& A);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Find the sumation values column-wise of a matrix.
|
||||
*
|
||||
* Computes:
|
||||
* @code
|
||||
* C(j) = sum(A(i,j))
|
||||
* @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 sum_colwise(const panic::tensor::matrix<T>& A, panic::tensor::vector<T>& c);
|
||||
|
||||
/**
|
||||
* @brief Returns a new matrix containing the sumation column-wise elementwise.
|
||||
*
|
||||
* Computes:
|
||||
* @code
|
||||
* result[j] = sum(A(i,j))
|
||||
* @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::vector<T> sum_colwise(const panic::tensor::matrix<T>& A);
|
||||
|
||||
} // namespace math
|
||||
} // namespace panic
|
||||
Reference in New Issue
Block a user