Files
panic/include/math/exp.hpp
T

145 lines
3.7 KiB
C++

/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
*
* 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: exp.hpp
* Revision: 0.1.0
* Date: 29-07-2026
* Author: Michelle Bausager
*
* Description:
* Functions to calculate the exponential of numbers
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma once
#include <tensor/vector.hpp> // for panic::vector
#include <tensor/matrix.hpp> // for panic::matrix
namespace panic{
namespace math{
/**
* @brief calculates the exponential of a value.
*
* Computes:
* @code
* result = exp(k)
* @endcode
*
* @tparam T Numeric element type.
* @param k Value to take the exp of.
*
* @return The calculated value
*
* @note This function is omp-friendly.
*/
template <typename T>
T exp(const T x);
/**
* @brief Calculates the exponential elementwise in a vector
*
* Computes:
* @code
* c[i] = exp(a[i])
* @endcode
*
* @tparam T Numeric element type.
* @param a Input vector.
* @param c Output vector. Resized to match @p a.
*
* @return true if @p c was resized and filled successfully.
* @return false if resizing @p c failed.
*
* @note This overload writes the result into an existing vector to avoid
* unnecessary temporary allocations.
*/
template <typename T>
bool exp(const panic::tensor::vector<T>& a, panic::tensor::vector<T>& c);
/**
* @brief Calculates the exponential elementwise in a vector
*
* Computes:
* @code
* result[i] = exp(a[i])
* @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::tensor::vector<T> exp(const panic::tensor::vector<T>& a);
/**
* @brief Calculates the expnential elementwise of a matrix
*
* Computes:
* @code
* C(i,j) = exp(A(i,j))
* @endcode
*
* @tparam T Numeric element type.
* @param A Input matrix.
* @param C Output Matrix. Resized to match @p A.
*
* @return true if @p C was resized and filled successfully.
* @return false if resizing @p C failed.
*
* @note This overload writes the result into an existing vector to avoid
* unnecessary temporary allocations.
*/
template <typename T>
bool exp(const panic::tensor::matrix<T>& A, panic::tensor::matrix<T>& C);
/**
* @brief Returns the calculated ecponential elementwise of the matrix
*
* Computes:
* @code
* result(i,j) = exp(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::matrix<T> exp(const panic::tensor::matrix<T>& A);
} // namespace math
} // namespace panic