/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * * 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: add.hpp * Revision: 0.1.0 * Date: 25-06-2026 * Author: Michelle Bausager * * Description: * Functions to add panic::tensor togther; * *++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ #pragma one //--------------------------------------------------------------------------------------------------------------------------- // INCLUDE DESCRIPTION //--------------------------------------------------------------------------------------------------------------------------- #include // for panic::real_vector (uint_vector, int_vector) #include // for panic::real_matrix (uint_matrix, int_matrix) //--------------------------------------------------------------------------------------------------------------------------- // DEFINE DESCRIPTION //--------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------- // VARIABLE DESCRIPTION //--------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------- // FUNCTION PROTOTYPE //--------------------------------------------------------------------------------------------------------------------------- namespace panic{ namespace math{ //-------------------------------------------------------------------------------------------------------------------------- // Function Name : panic::math::add // // Description: // Adds a scaler to a panic::tensor::vector // c(2) = a(2) + k // // Inputs: // // a const panic::tensor::vector& // // k const // // Outputs: // c panic::tensor::vector& // // Returns: // bool // // Notes: // The c vector is resized if nessessary. //-------------------------------------------------------------------------------------------------------------------------- template bool add(const panic::tensor::vector& a, const T k, panic::tensor::vector& c); //-------------------------------------------------------------------------------------------------------------------------- // Function Name : panic::math::add // // Description: // Adds a scaler to a panic::tensor::vector // c(2) = a(2) + k // // Inputs: // // a const panic::tensor::vector& // // k const // // Outputs: // None. // // Returns: // c panic::tensor::vector // // Notes: // Makes new vector and returns the result. //-------------------------------------------------------------------------------------------------------------------------- template panic::tensor::vector add(const panic::tensor::vector& a, const T k); //-------------------------------------------------------------------------------------------------------------------------- // Function Name : panic::math::add // // Description: // Adds two panic::tensor::vector // c(2) = a(2) + b(2) // // Inputs: // // a const panic::tensor::vector& // // b const panic::tensor::vector& // // Outputs: // c panic::tensor::vector& // // Returns: // bool // // Notes: // If input vector dimentions are not correct, output is a empty vector and returns false. // The c vector is resized if nessessary. //-------------------------------------------------------------------------------------------------------------------------- template bool add(const panic::tensor::vector& a, const panic::tensor::vector& b, panic::tensor::vector& c); //-------------------------------------------------------------------------------------------------------------------------- // Function Name : panic::math::add // // Description: // Adds two panic::tensor::vector // c(2) = a(2) + b(2) // // Inputs: // // a const panic::tensor::vector& // // b const panic::tensor::vector& // // Outputs: // None. // // Returns: // c panic::tensor::vector // // Notes: // If input vector dimentions are not correct, return is an empty vector. // Makes new vector and returns the result. //-------------------------------------------------------------------------------------------------------------------------- template panic::tensor::vector add(const panic::tensor::vector& a, const panic::tensor::vector& b); //-------------------------------------------------------------------------------------------------------------------------- // Function Name : panic::math::add // // Description: // Adds a scaler to a panic::tensor::matrix // C(2,2) = A(2,2) + k // // Inputs: // // A const panic::tensor::matrix& // // k const T // // Outputs: // C panic::tensor::matrix& // // Returns: // bool // // Notes: // The C matrix is resized if nessessary. //-------------------------------------------------------------------------------------------------------------------------- template bool add(const panic::tensor::matrix& A, const T k, panic::tensor::matrix& C); //-------------------------------------------------------------------------------------------------------------------------- // Function Name : panic::math::add // // Description: // Adds a scaler to a panic::tensor::matrix // C(2,2) = A(2,2) + k // // Inputs: // // A const panic::tensor::matrix& // // k const T // // Outputs: // None. // // Returns: // C panic::tensor::matrix // // Notes: // Creates new matrix, C, for the result. //-------------------------------------------------------------------------------------------------------------------------- template panic::tensor::matrix add(const panic::tensor::matrix& A, const T k); //-------------------------------------------------------------------------------------------------------------------------- // Function Name : panic::math::add // // Description: // Adds two panic::tensor::matrix // C(2,2) = A(2,2) + B(2,2) // // Inputs: // // A const panic::tensor::matrix& // // B const panic::tensor::matrix& // // Outputs: // C panic::tensor::matrix& // // Returns: // bool // // Notes: // If input matrix dimentions are not correct, outputs an a empty matrix and returns false. // The C matrix is resized if nessessary. //-------------------------------------------------------------------------------------------------------------------------- template bool add(const panic::tensor::matrix& A, const panic::tensor::matrix& B, panic::tensor::matrix& C); //-------------------------------------------------------------------------------------------------------------------------- // Function Name : panic::math::add // // Description: // Adds two panic::tensor::matrix // C(2,2) = A(2,2) + B(2,2) // // Inputs: // // A const panic::tensor::matrix& // // B const panic::tensor::matrix& // // Outputs: // None. // // Returns: // C panic::tensor::matrix // // Notes: // If input matrix dimentions are not correct, returns an a empty matrix. // Creates new matrix, C, for the result. //-------------------------------------------------------------------------------------------------------------------------- template panic::tensor::matrix add(const panic::tensor::matrix& A, const panic::tensor::matrix& B); //-------------------------------------------------------------------------------------------------------------------------- // Function Name : panic::math::add_rowwise // // Description: // Adds two panic::tensor::matrix // C(2,3) = A(2,3) + b(2) // // Inputs: // // A const panic::tensor::matrix& // // b const panic::tensor::vector& // // Outputs: // C panic::tensor::matrix& // // Returns: // bool // // Notes: // If input vector dimentions are not correct, outputs an a empty matrix and returns false. // The C matrix is resized if nessessary. //-------------------------------------------------------------------------------------------------------------------------- template bool add_rowwise(const panic::tensor::matrix& A, const panic::tensor::vector& b, panic::tensor::matrix& C); //-------------------------------------------------------------------------------------------------------------------------- // Function Name : panic::math::add_rowwise // // Description: // Adds two panic::tensor::matrix // C(2,3) = A(2,3) + b(2) // // Inputs: // // A const panic::tensor::matrix& // // b const panic::tensor::vector& // // Outputs: // None. // // Returns: // C panic::tensor::matrix& // // Notes: // If input vector dimentions are not correct, returns an a empty matrix. // Creates new matrix, C, for the result. //-------------------------------------------------------------------------------------------------------------------------- template panic::tensor::matrix add_rowwise(const panic::tensor::matrix& A, const panic::tensor::vector& b); //-------------------------------------------------------------------------------------------------------------------------- // Function Name : panic::math::add_colwise // // Description: // Adds two panic::tensor::matrix // C(2,3) = A(2,3) + b(3) // // Inputs: // // A const panic::tensor::matrix& // // b const panic::tensor::vector& // // Outputs: // C panic::tensor::matrix& // // Returns: // bool // // Notes: // If input vector dimentions are not correct, outputs an a empty matrix and returns false. // The C matrix is resized if nessessary. //-------------------------------------------------------------------------------------------------------------------------- template bool add_colwise(const panic::tensor::matrix& A, const panic::tensor::vector& b, panic::tensor::matrix& C); //-------------------------------------------------------------------------------------------------------------------------- // Function Name : panic::math::add_colwise // // Description: // Adds two panic::tensor::matrix // C(2,3) = A(2,3) + b(3) // // Inputs: // // A const panic::tensor::matrix& // // b const panic::tensor::vector& // // Outputs: // None. // // Returns: // C panic::tensor::matrix& // // Notes: // If input vector dimentions are not correct, returns an a empty matrix. // Creates new matrix, C, for the result. //-------------------------------------------------------------------------------------------------------------------------- template panic::tensor::matrix add_colwise(const panic::tensor::matrix& A, const panic::tensor::vector& b); } // namespace math } // namespace panic