102 lines
3.0 KiB
C++
102 lines
3.0 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: dot.hpp
|
|
* Revision: 0.1.0
|
|
* Date: 31-07-2026
|
|
* Author: Michelle Bausager
|
|
*
|
|
* Description:
|
|
* Functions to calculate dot product of tensors;
|
|
*
|
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
#pragma once
|
|
//---------------------------------------------------------------------------------------------------------------------------
|
|
// INCLUDE DESCRIPTION
|
|
//-----------------------------------------------------------------------------------------------------
|
|
|
|
#include <tensor/vector.hpp>
|
|
#include <tensor/matrix.hpp> // for panic::real_matrix
|
|
|
|
namespace panic{
|
|
namespace math{
|
|
|
|
/**
|
|
* @brief Returns dor product of vector and vector.
|
|
*
|
|
* Computes:
|
|
* @code
|
|
* @endcode
|
|
*
|
|
* @tparam T Numeric element type.
|
|
* @param a First vector.
|
|
* @param b Second vector for dot product. Need to be @p a.size()
|
|
*
|
|
*/
|
|
template <typename T>
|
|
T dot(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b);
|
|
|
|
/**
|
|
* @brief Returns a new vector of dot product of a matrix and vector.
|
|
*
|
|
* Computes:
|
|
* @code
|
|
* @endcode
|
|
*
|
|
* @tparam T Numeric element type.
|
|
* @param A Input matrix.
|
|
* @param b Input vector. @ p b.size needs to be the size of @p A.cols.
|
|
* @param c Output vector with result.
|
|
*
|
|
* @return true if success
|
|
* @return false if resizeing fails or dimention mismatch
|
|
*
|
|
*/
|
|
template <typename T>
|
|
bool dot(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& b, panic::tensor::vector<T>& c);
|
|
|
|
|
|
/**
|
|
* @brief Returns a new vector of dot product of a matrix and vector.
|
|
*
|
|
* Computes:
|
|
* @code
|
|
* @endcode
|
|
*
|
|
* @tparam T Numeric element type.
|
|
* @param A Input matrix.
|
|
* @param b Input vector. @ p b.size needs to be the size of @p A.cols.
|
|
*
|
|
* @return A new matrix containing the result.
|
|
* @return An empty vector if the operation fails.
|
|
*
|
|
* @note This overload is convenient, but may allocate a new matrix.
|
|
*/
|
|
template <typename T>
|
|
panic::tensor::vector<T> dot(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& b);
|
|
|
|
|
|
|
|
} // namespace math
|
|
} // namespace panic
|