Comment rewrite

This commit is contained in:
2026-07-25 14:54:13 +02:00
parent 8fd1b7762e
commit a30b410f89
10 changed files with 583 additions and 625 deletions
+1 -1
View File
@@ -168,7 +168,7 @@
// //
// That means the same code still works on microcontrollers and non-OpenMP builds. // That means the same code still works on microcontrollers and non-OpenMP builds.
#define PANIC_OMP_PARALLEL_FOR #define PANIC_OMP_PARALLEL_FOR
#define PANIC_OMP_PARALLEL_FOR_IF(condition) #define PANIC_OMP_PARALLEL_FOR_IF(condition) static_cast<void>(sizeof(condition));
#endif #endif
+39 -61
View File
@@ -31,74 +31,52 @@
* Functions to print out tensors with std::cout << x std::endl; * Functions to print out tensors with std::cout << x std::endl;
* *
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ *++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma one #pragma once
//---------------------------------------------------------------------------------------------------------------------------
// INCLUDE DESCRIPTION
//-----------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------- #include <tensor/vector.hpp> // for panic::vector
// DEFINE DESCRIPTION #include <tensor/matrix.hpp> // for panic::matrix
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// VARIABLE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// FUNCTION PROTOTYPE
//---------------------------------------------------------------------------------------------------------------------------
namespace panic{ namespace panic{
namespace io{ namespace io{
//-------------------------------------------------------------------------------------------------------------------------- /**
// Function Name : panic::io::print_vector * @brief prints out vector to iostream.
// *
// Description: * Computes:
// Prints a vector out in the terminal * @code
// * print_vector(a)
// Inputs: * @endcode
// v const panic::tensor::uint_vector& *
// const panic::tensor::int_vector& * @tparam T Numeric element type.
// const panic::tensor::real_vector& * @param a Input vector.
// vector to print *
// * @return true if @p a was successfully printed.
// Outputs: * @return false if printing of @p c failed.
// None. *
// * @note N/A
// Returns: */
// void template <typename T>
// bool print_vector(const panic::tensor::vector<T>& v);
// Notes:
// The vector is printed out in square brackets.
//--------------------------------------------------------------------------------------------------------------------------
void print_vector(const panic::tensor::uint_vector& v);
void print_vector(const panic::tensor::int_vector& v);
void print_vector(const panic::tensor::real_vector& v);
//-------------------------------------------------------------------------------------------------------------------------- /**
// Function Name : panic::io::print_matrix * @brief prints out matrix to iostream.
// *
// Description: * Computes:
// Prints a matrix out in the terminal * @code
// * print_matrix(a)
// Inputs: * @endcode
// v const panic::tensor::uint_matrix& *
// const panic::tensor::int_matrix& * @tparam T Numeric element type.
// const panic::tensor::real_matrix& * @param A Input matrix.
// matrix to print *
// * @return true if @p A was successfully printed.
// Outputs: * @return false if printing of @p C failed.
// None. *
// * @note N/A
// Returns: */
// void template <typename T>
// bool print_matrix(const panic::tensor::matrix<T>& A);
// Notes:
// The matrix is printed out in square brackets.
//--------------------------------------------------------------------------------------------------------------------------
void print_matrix(const panic::tensor::uint_matrix& v);
void print_matrix(const panic::tensor::int_matrix& v);
void print_matrix(const panic::tensor::real_matrix& v);
+223 -289
View File
@@ -1,4 +1,5 @@
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ /**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* *
* PANIC * PANIC
* Portable Algorithms and Numerics In C++ * Portable Algorithms and Numerics In C++
@@ -30,333 +31,266 @@
* Description: * Description:
* Functions to add panic::tensor togther; * Functions to add panic::tensor togther;
* *
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ *++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#pragma one *
//--------------------------------------------------------------------------------------------------------------------------- * @file add.hpp
// INCLUDE DESCRIPTION * @brief Public API for element-wise addition operations on PANIC vectors and matrices.
//--------------------------------------------------------------------------------------------------------------------------- *
#include <tensor/vector.hpp> // for panic::real_vector (uint_vector, int_vector) * This header contains the declarations that users of the math module should call.
#include <tensor/matrix.hpp> // for panic::real_matrix (uint_matrix, int_matrix) * The comments here describe how each function is used, what dimensions are required,
//--------------------------------------------------------------------------------------------------------------------------- * and what is returned on failure.
// DEFINE DESCRIPTION *
//--------------------------------------------------------------------------------------------------------------------------- * Implementation details, OpenMP thresholds, and explicit template instantiations are
* kept in add.cpp.
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma once
//--------------------------------------------------------------------------------------------------------------------------- #include <tensor/vector.hpp> // for panic::vector
// VARIABLE DESCRIPTION #include <tensor/matrix.hpp> // for panic::matrix
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// FUNCTION PROTOTYPE
//---------------------------------------------------------------------------------------------------------------------------
namespace panic{ namespace panic{
namespace math{ namespace math{
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::add /**
// * @brief Adds a scalar to every element of a vector.
// Description: *
// Adds a scaler to a panic::tensor::vector * Computes:
// c(2) = a(2) + k * @code
// * c[i] = a[i] + k
// Inputs: * @endcode
// *
// a const panic::tensor::vector<T>& * @tparam T Numeric element type.
// * @param a Input vector.
// k const <T> * @param k Scalar value added to each element of @p a.
// * @param c Output vector. Resized to match @p a.
// Outputs: *
// c panic::tensor::vector<T>& * @return true if @p c was resized and filled successfully.
// * @return false if resizing @p c failed.
// Returns: *
// bool * @note This overload writes the result into an existing vector to avoid
// * unnecessary temporary allocations.
// Notes: */
// The c vector is resized if nessessary.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T> template <typename T>
bool add(const panic::tensor::vector<T>& a, const T k, panic::tensor::vector<T>& c); bool add(const panic::tensor::vector<T>& a, const T k, panic::tensor::vector<T>& c);
//-------------------------------------------------------------------------------------------------------------------------- /**
// Function Name : panic::math::add * @brief Returns a new vector containing a scalar added to every element.
// *
// Description: * Computes:
// Adds a scaler to a panic::tensor::vector * @code
// c(2) = a(2) + k * result[i] = a[i] + k
// * @endcode
// Inputs: *
// * @tparam T Numeric element type.
// a const panic::tensor::vector<T>& * @param a Input vector.
// * @param k Scalar value added to each element of @p a.
// k const <T> *
// * @return A new vector containing the result.
// Outputs: * @return An empty vector if the operation fails.
// None. *
// * @note This overload is convenient, but may allocate a new vector.
// Returns: */
// c panic::tensor::vector<T>
//
// Notes:
// Makes new vector and returns the result.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T> template <typename T>
panic::tensor::vector<T> add(const panic::tensor::vector<T>& a, const T k); panic::tensor::vector<T> add(const panic::tensor::vector<T>& a, const T k);
//-------------------------------------------------------------------------------------------------------------------------- /**
// Function Name : panic::math::add * @brief Adds a vector elementwise too a vector.
// *
// Description: * Computes:
// Adds two panic::tensor::vector * @code
// c(2) = a(2) + b(2) * c[i] = a[i] + b[i]
// * @endcode
// Inputs: *
// * @tparam T Numeric element type.
// a const panic::tensor::vector<T>& * @param a First vector.
// * @param b Second vector. Must have size of @p a
// b const panic::tensor::vector<T>& * @param c Output vector. Resized to match @p a.
// *
// Outputs: * @return true if @p c was resized and filled successfully.
// c panic::tensor::vector<T>& * @return false if vector sizes do not match or resizing @p c failed.
// */
// 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 <typename T> template <typename T>
bool add(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b, panic::tensor::vector<T>& c); bool add(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b, panic::tensor::vector<T>& c);
//-------------------------------------------------------------------------------------------------------------------------- /**
// Function Name : panic::math::add * @brief Returns a new vector containing a vector added elementwise.
// *
// Description: * Computes:
// Adds two panic::tensor::vector * @code
// c(2) = a(2) + b(2) * result[i] = a[i] + b[i]
// * @endcode
// Inputs: *
// * @tparam T Numeric element type.
// a const panic::tensor::vector<T>& * @param a First vector.
// * @param b Second vector. Must have size of @p a
// b const panic::tensor::vector<T>& * @param k Scalar value added to each element of @p a.
// *
// Outputs: * @return A new vector containing the result.
// None. * @return An empty vector if the operation fails.
// *
// Returns: * @note This overload is convenient, but may allocate a new vector.
// c panic::tensor::vector<T> */
//
// Notes:
// If input vector dimentions are not correct, return is an empty vector.
// Makes new vector and returns the result.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T> template <typename T>
panic::tensor::vector<T> add(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b); panic::tensor::vector<T> add(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b);
//-------------------------------------------------------------------------------------------------------------------------- /**
// Function Name : panic::math::add * @brief Adds a scalar to every element of a matix.
// *
// Description: * Computes:
// Adds a scaler to a panic::tensor::matrix * @code
// C(2,2) = A(2,2) + k * C(i,j) = A(i,j) + k
// * @endcode
// Inputs: *
// * @tparam T Numeric element type.
// A const panic::tensor::matrix<T>& * @param A Input matrix.
// * @param k Scalar value added to each element of @p A.
// k const T * @param C Output Matrix. Resized to match @p A.
// *
// Outputs: * @return true if @p C was resized and filled successfully.
// C panic::tensor::matrix<T>& * @return false if resizing @p C failed.
// *
// Returns: * @note This overload writes the result into an existing vector to avoid
// bool * unnecessary temporary allocations.
// */
// Notes:
// The C matrix is resized if nessessary.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T> template <typename T>
bool add(const panic::tensor::matrix<T>& A, const T k, panic::tensor::matrix<T>& C); bool add(const panic::tensor::matrix<T>& A, const T k, panic::tensor::matrix<T>& C);
//-------------------------------------------------------------------------------------------------------------------------- /**
// Function Name : panic::math::add * @brief Returns a new matrix containing a scalar added to every element.
// *
// Description: * Computes:
// Adds a scaler to a panic::tensor::matrix * @code
// C(2,2) = A(2,2) + k * result(i,j) = A(i,j) + k
// * @endcode
// Inputs: *
// * @tparam T Numeric element type.
// A const panic::tensor::matrix<T>& * @param A Input matrix.
// * @param k Scalar value added to each element of @p A.
// k const T *
// * @return A new matrix containing the result.
// Outputs: * @return An empty matrix if the operation fails.
// None. *
// * @note This overload is convenient, but may allocate a new vector.
// Returns: */
// C panic::tensor::matrix<T>
//
// Notes:
// Creates new matrix, C, for the result.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T> template <typename T>
panic::tensor::matrix<T> add(const panic::tensor::matrix<T>& A, const T k); panic::tensor::matrix<T> add(const panic::tensor::matrix<T>& A, const T k);
/**
//-------------------------------------------------------------------------------------------------------------------------- * @brief Adds a matrix elementwise too a matrix.
// Function Name : panic::math::add *
// * Computes:
// Description: * @code
// Adds two panic::tensor::matrix * C(i,j) = A(i,j) + B(i,j)
// C(2,2) = A(2,2) + B(2,2) * @endcode
// *
// Inputs: * @tparam T Numeric element type.
// * @param A First matrix.
// A const panic::tensor::matrix<T>& * @param B Second matrix. Must have size of @p A.
// * @param C Output matrix. Resized to match @p A.
// B const panic::tensor::matrix<T>& *
// * @return true if @p C was resized and filled successfully.
// Outputs: * @return false if vector sizes do not match or resizing @p c failed.
// C panic::tensor::matrix<T>& */
//
// 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 <typename T> template <typename T>
bool add(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, panic::tensor::matrix<T>& C); bool add(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, panic::tensor::matrix<T>& C);
//-------------------------------------------------------------------------------------------------------------------------- /**
// Function Name : panic::math::add * @brief Returns a new matrix containing a matrix added elementwise.
// *
// Description: * Computes:
// Adds two panic::tensor::matrix * @code
// C(2,2) = A(2,2) + B(2,2) * result(i,j) = A(i,j) + B(i,j)
// * @endcode
// Inputs: *
// * @tparam T Numeric element type.
// A const panic::tensor::matrix<T>& * @param A Input matrix.
// * @param B Second matrix. Must have size of @p A.
// B const panic::tensor::matrix<T>& *
// * @return A new matrix containing the result.
// Outputs: * @return An empty matrix if the operation fails.
// None. *
// * @note This overload is convenient, but may allocate a new vector.
// Returns: */
// C panic::tensor::matrix<T>
//
// Notes:
// If input matrix dimentions are not correct, returns an a empty matrix.
// Creates new matrix, C, for the result.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T> template <typename T>
panic::tensor::matrix<T> add(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B); panic::tensor::matrix<T> add(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B);
//-------------------------------------------------------------------------------------------------------------------------- /**
// Function Name : panic::math::add_rowwise * @brief Adds a vector rowwise too a matrix.
// *
// Description: * Computes:
// Adds two panic::tensor::matrix * @code
// C(2,3) = A(2,3) + b(2) * C(i,j) = A(i,j) + b[i]
// * @endcode
// Inputs: *
// * @tparam T Numeric element type.
// A const panic::tensor::matrix<T>& * @param A Matrix.
// * @param b Vector. Must have size of @p A.cols().
// b const panic::tensor::vector<T>& * @param C Output matrix. Resized to match @p A.
// *
// Outputs: * @return true if @p C was resized and filled successfully.
// C panic::tensor::matrix& * @return false if vector sizes do not match or resizing @p c failed.
// */
// 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 <typename T> template <typename T>
bool add_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C); bool add_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C);
//-------------------------------------------------------------------------------------------------------------------------- /**
// Function Name : panic::math::add_rowwise * @brief Adds a vector rowwise too a matrix.
// *
// Description: * Computes:
// Adds two panic::tensor::matrix * @code
// C(2,3) = A(2,3) + b(2) * result(i,j) = A(i,j) + b[i]
// * @endcode
// Inputs: *
// * @tparam T Numeric element type.
// A const panic::tensor::matrix<T>& * @param A Matrix.
// * @param b Vector. Must have size of @p A.cols().
// b const panic::tensor::vector<T>& *
// * @return A new matrix containing the result.
// Outputs: * @return An empty matrix if the operation fails.
// None. *
// * @note This overload is convenient, but may allocate a new vector.
// Returns: */
// C panic::tensor::matrix<T>&
//
// Notes:
// If input vector dimentions are not correct, returns an a empty matrix.
// Creates new matrix, C, for the result.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T> template <typename T>
panic::tensor::matrix<T> add_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b); panic::tensor::matrix<T> add_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b);
//-------------------------------------------------------------------------------------------------------------------------- /**
// Function Name : panic::math::add_colwise * @brief Adds a vector colwise too a matrix.
// *
// Description: * Computes:
// Adds two panic::tensor::matrix * @code
// C(2,3) = A(2,3) + b(3) * C(i,j) = A(i,j) + b[j]
// * @endcode
// Inputs: *
// * @tparam T Numeric element type.
// A const panic::tensor::matrix<T>& * @param A Matrix.
// * @param b Vector. Must have size of @p A.rows().
// b const panic::tensor::vector<T>& * @param C Output matrix. Resized to match @p A.
// *
// Outputs: * @return true if @p C was resized and filled successfully.
// C panic::tensor::matrix& * @return false if vector sizes do not match or resizing @p c failed.
// */
// 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 <typename T> template <typename T>
bool add_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C); bool add_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C);
//-------------------------------------------------------------------------------------------------------------------------- /**
// Function Name : panic::math::add_colwise * @brief Adds a vector colwise too a matrix.
// *
// Description: * Computes:
// Adds two panic::tensor::matrix * @code
// C(2,3) = A(2,3) + b(3) * result(i,j) = A(i,j) + b[j]
// * @endcode
// Inputs: *
// * @tparam T Numeric element type.
// A const panic::tensor::matrix<T>& * @param A Matrix.
// * @param b Vector. Must have size of @p A.rows().
// b const panic::tensor::vector<T>& *
// * @return A new matrix containing the result.
// Outputs: * @return An empty matrix if the operation fails.
// None. *
// * @note This overload is convenient, but may allocate a new vector.
// Returns: */
// C panic::tensor::matrix<T>&
//
// Notes:
// If input vector dimentions are not correct, returns an a empty matrix.
// Creates new matrix, C, for the result.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T> template <typename T>
panic::tensor::matrix<T> add_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b); panic::tensor::matrix<T> add_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b);
+37 -47
View File
@@ -31,7 +31,7 @@
* Functions to print out tensors with std::cout << x std::endl; * Functions to print out tensors with std::cout << x std::endl;
* *
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ *++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma one #pragma once
//--------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------
// INCLUDE DESCRIPTION // INCLUDE DESCRIPTION
//----------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------
@@ -50,55 +50,45 @@
namespace panic{ namespace panic{
namespace math{ namespace math{
//-------------------------------------------------------------------------------------------------------------------------- /**
// Function Name : panic::math::matmul * @brief Calculates matrix multiplication of two matrices.
// *
// Description: * Computes:
// Multiplies to panic::tensor::real_matrix * @code
// C(2,4) = A(2,3) * B(3,4) * C(n, p) = A(n,m) + B(m,p)
// * @endcode
// Inputs: *
// * @tparam T Numeric element type.
// A const panic::tensor::real_matrix& * @param A First matrix.
// * @param B Second matrix. @ p B.rows needs to be the size of @p A.cols.
// B const panic::tensor::real_matrix& * @param C Output matrix. Resized to C(A.rows, B.cols).
// *
// Outputs: * @return true if @p C was resized and filled successfully.
// C panic::tensor::real_matrix& * @return false if resizing @p C failed or A==B.
// *
// Returns: * @note This overload writes the result into an existing matrix to avoid
// bool * unnecessary temporary allocations.
// */
// Notes:
// If input matrix dimentions are not correct, output is a empty matrix and returns false.
// The C matrix is resized if nessessary.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T> template <typename T>
bool matmul(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, panic::tensor::matrix<T>& C); bool matmul(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, panic::tensor::matrix<T>& C);
//-------------------------------------------------------------------------------------------------------------------------- /**
// Function Name : panic::math::matmul * @brief Returns a new matrix of multiplication of two matrices.
// *
// Description: * Computes:
// Multiplies to panic::tensor::real_matrix * @code
// C(2,4) = A(2,3) * B(3,4) * result(n, p) = A(n,m) + B(m,p)
// * @endcode
// Inputs: *
// * @tparam T Numeric element type.
// A const panic::tensor::real_matrix& * @param A First matrix.
// * @param B Second matrix. @ p B.rows needs to be the size of @p A.cols.
// B const panic::tensor::real_matrix& *
// * @return A new matrix containing the result.
// Outputs: * @return An empty vector if the operation fails.
// None. *
// * @note This overload is convenient, but may allocate a new matrix.
// Returns: */
// C panic::tensor::real_matrix&
//
// Notes:
// If input matrix dimentions are not correct, returns an a empty matrix.
// Creates new matrix, C, for the result.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T> template <typename T>
panic::tensor::matrix<T> matmul(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B); panic::tensor::matrix<T> matmul(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B);
+115 -57
View File
@@ -37,88 +37,154 @@
//--------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t #include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
//---------------------------------------------------------------------------------------------------------------------------
// DEFINE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// TYPE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// Type Name : panic::tensor::matrix
//
// Description:
// Dynamic matrix storing T values.
// The matrix owns its memory and releases it in the destructor.
//
// Member Variables:
// n panic::uint_t
// Number of rows in the matrix.
// m panic::uint_t
// Number of columns in the matrix.
//
// data T*
// Pointer to the allocated matrix data.
//
// Notes:
// This matrix uses dynamic allocation with new[] and delete[].
// Copying performs a deep copy.
//---------------------------------------------------------------------------------------------------------------------------
namespace panic{ namespace panic{
namespace tensor{ namespace tensor{
/**
* @brief struct for matrix object
*
* The struct is used for all PANIC libraries
* It uses dynamic allocation with new[] nad delete[].
* Copying performs a deep copy.
*/
template <typename T> template <typename T>
struct matrix{ struct matrix{
// Variable for number of rows
panic::types::uint_t n; panic::types::uint_t n;
// Variable for number of cols
panic::types::uint_t m; panic::types::uint_t m;
// Variable for length of data array
panic::types::uint_t length; panic::types::uint_t length;
// Pointer to data array
T* data; T* data;
// empty contructor /**
* @brief Empthy constructor
*
*/
matrix(); matrix();
// contructor with size allocation /**
* @brief Contructor with size allocation.
*
* @param rows Number of rows in the matrix
* @param cols Number of columns in the matrix
*/
matrix(panic::types::uint_t rows, panic::types::uint_t cols); matrix(panic::types::uint_t rows, panic::types::uint_t cols);
// contructor with size allocation and sets it all to a value /**
* @brief Contructor with size allocation and sets it all to a value.
*
* @param rows Number of rows in the matrix
* @param cols Number of columns in the matrix
* @param value all the values in the matrix.
*/
matrix(panic::types::uint_t rows, panic::types::uint_t cols, T value); matrix(panic::types::uint_t rows, panic::types::uint_t cols, T value);
// copy-contructor /**
// matrix A(3,3); * @brief Copy-contructor.
// matrix B = A; *
* Computes:
* @code
* matrix A(3,3);
* matrix B = A;
* @endcode
*
*/
matrix(const matrix& other); matrix(const matrix& other);
// de-contructor, releases memory /**
* @brief De-contructor, releases memory.
*
* @note Releases memory.
*/
~matrix(); ~matrix();
// copy-assignment /**
//matrix A(5); * @brief Copy-assignment.
//matrix B(3); *
//B = A; * Computes:
* @code
* matrix A(3,3);
* matrix B(5,8);
* B = A;
* @endcode
*
*/
matrix& operator=(const matrix& other); matrix& operator=(const matrix& other);
// function returns rows. /**
// const tells compiler that the fuction don't edit the objert. * @brief Returns number of rows.
*
* Computes:
* @code
* n = A.rows();
* @endcode
*
* @note The const tells compiler that the fuction don't edit the objert.
*/
panic::types::uint_t rows() const; panic::types::uint_t rows() const;
// function returns columns. /**
// const tells compiler that the fuction don't edit the objert. * @brief Returns number of columns.
*
* Computes:
* @code
* m = A.cols();
* @endcode
*
* @note The const tells compiler that the fuction don't edit the objert.
*/
panic::types::uint_t cols() const; panic::types::uint_t cols() const;
// function to resize data vector /**
* @brief Function to resize data matrix.
*
* Computes:
* @code
* A.resize(3,4);
* @endcode
*
* @note It hold all the privious functions if avaliable.
*/
bool resize(panic::types::uint_t new_n, panic::types::uint_t new_m); bool resize(panic::types::uint_t new_n, panic::types::uint_t new_m);
// fill data with value /**
* @brief Fill data with value.
*
* Computes:
* @code
* A.fill(3.1415);
* @endcode
*
* @note Sets all values in the matrix.
*/
bool fill(T value); bool fill(T value);
// lets you read and write matrix data using row and column /**
// Example: * @brief Read and write matrix data using row and column
// A(1, 2) *
// This is unchecked and fast. * Computes:
* @code
* n = A(1,2);
* @endcode
*
* @note This is unchecked and fast.
*/
T& operator()(panic::types::uint_t index_n, panic::types::uint_t index_m); T& operator()(panic::types::uint_t index_n, panic::types::uint_t index_m);
// lets you read matrix data using row and column from a const matrix
/**
* @brief Read from const matrix data using row and column
*
* Computes:
* @code
* n = const A(1,2);
* @endcode
*
* @note This is unchecked and fast.
*/
const T& operator()(panic::types::uint_t index_n, panic::types::uint_t index_m) const; const T& operator()(panic::types::uint_t index_n, panic::types::uint_t index_m) const;
}; };
@@ -144,12 +210,4 @@ extern template struct matrix<panic::types::uint_t>;
} // namespace tensor } // namespace tensor
} // namespace panic } // namespace panic
//---------------------------------------------------------------------------------------------------------------------------
// VARIABLE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// FUNCTION PROTOTYPE
//---------------------------------------------------------------------------------------------------------------------------
+1 -10
View File
@@ -32,18 +32,9 @@
* *
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ *++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma once #pragma once
//---------------------------------------------------------------------------------------------------------------------------
// INCLUDE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t #include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
//---------------------------------------------------------------------------------------------------------------------------
// DEFINE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// TYPE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------
// Type Name : panic::tensor::vector // Type Name : panic::tensor::vector
+37 -49
View File
@@ -35,10 +35,11 @@
//--------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------
// INCLUDE DESCRIPTION // INCLUDE DESCRIPTION
//----------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------
#include <io/print_tensor.hpp>
#include <iostream> // for std::cout, std::endl #include <iostream> // for std::cout, std::endl
//#include <io/print_tensor.hpp>
#include <tensor/vector.hpp> // for panic::tensor::vector #include <tensor/vector.hpp> // for panic::vector
#include <tensor/matrix.hpp> #include <tensor/matrix.hpp> // for panic::matrix
//--------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------
// DEFINE DESCRIPTION // DEFINE DESCRIPTION
@@ -61,32 +62,32 @@ namespace panic {
// //
// Description: // Description:
// The vector is printed out in square brackets. // The vector is printed out in square brackets.
// Overloaded for panic::uint, panic::int and panic::real
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void print_vector(const panic::tensor::uint_vector& v){ template <typename T>
bool print_vector(const panic::tensor::vector<T>& v){
std::cout << "["; std::cout << "[";
for (panic::types::uint_t i = 0; i < v.size()-1; ++i){ for (panic::types::uint_t i = 0; i < v.size()-1; ++i){
std::cout << v[i] << ", "; std::cout << v[i] << ", ";
} }
std::cout << v[v.size()-1]<< "]" << std::endl; std::cout << v[v.size()-1]<< "]" << std::endl;
} return true;
void print_vector(const panic::tensor::int_vector& v){
std::cout << "[";
for (panic::types::uint_t i = 0; i < v.size()-1; ++i){
std::cout << v[i] << ", ";
}
std::cout << v[v.size()-1]<< "]" << std::endl;
} }
void print_vector(const panic::tensor::real_vector& v){ //--------------------------------------------------------------------------------------------------------------------------
std::cout << "["; // EXPLICIT TEMPLATE INSTANTIATION
for (panic::types::uint_t i = 0; i < v.size()-1; ++i){ //
std::cout << v[i] << ", "; // The implementation is in this .cpp file.
} // Build the overload for the official PANIC numeric types.
std::cout << v[v.size()-1]<< "]" << std::endl; //--------------------------------------------------------------------------------------------------------------------------
template bool print_vector<panic::types::uint_t>(const panic::tensor::vector<panic::types::uint_t>& v
);
template bool print_vector<panic::types::int_t>(const panic::tensor::vector<panic::types::int_t>& v
);
template bool print_vector<panic::types::real_t>(const panic::tensor::vector<panic::types::real_t>& v
);
}
@@ -95,9 +96,9 @@ void print_vector(const panic::tensor::real_vector& v){
// //
// Description: // Description:
// The matrix is printed out in square brackets. // The matrix is printed out in square brackets.
// Overloaded for panic::uint, panic::int and panic::real
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void print_matrix(const panic::tensor::uint_matrix& A){ template <typename T>
bool print_matrix(const panic::tensor::matrix<T>& A){
std::cout << "["; std::cout << "[";
for (panic::types::uint_t i = 0; i < A.rows(); ++i){ for (panic::types::uint_t i = 0; i < A.rows(); ++i){
std::cout << "["; std::cout << "[";
@@ -110,37 +111,24 @@ void print_matrix(const panic::tensor::uint_matrix& A){
std::cout << A(A.rows()-1,A.cols()-1) << "]]" << std::endl; std::cout << A(A.rows()-1,A.cols()-1) << "]]" << std::endl;
} }
} }
return true;
} }
void print_matrix(const panic::tensor::int_matrix& A){ //--------------------------------------------------------------------------------------------------------------------------
std::cout << "["; // EXPLICIT TEMPLATE INSTANTIATION
for (panic::types::uint_t i = 0; i < A.rows(); ++i){ //
std::cout << "["; // The implementation is in this .cpp file.
for (panic::types::uint_t j = 0; j < A.cols(); ++j){ // Build the overload for the official PANIC numeric types.
std::cout << A(i,j) << ", "; //--------------------------------------------------------------------------------------------------------------------------
} template bool print_matrix<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& A
if (i < A.rows()-1){ );
std::cout << A(A.rows()-1,A.cols()-1) << "]" << std::endl; template bool print_matrix<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& A
}else{ );
std::cout << A(A.rows()-1,A.cols()-1) << "]]" << std::endl; template bool print_matrix<panic::types::real_t>(const panic::tensor::matrix<panic::types::real_t>& A
} );
}
}
void print_matrix(const panic::tensor::real_matrix& A){
std::cout << "[";
for (panic::types::uint_t i = 0; i < A.rows(); ++i){
std::cout << "[";
for (panic::types::uint_t j = 0; j < A.cols(); ++j){
std::cout << A(i,j) << ", ";
}
if (i < A.rows()-1){
std::cout << A(A.rows()-1,A.cols()-1) << "]" << std::endl;
}else{
std::cout << A(A.rows()-1,A.cols()-1) << "]]" << std::endl;
}
}
}
} // namespace io } // namespace io
+83 -62
View File
@@ -38,19 +38,23 @@
#include <math/add.hpp> #include <math/add.hpp>
#include <config/omp.hpp> #include <config/omp.hpp>
//#include <tensor/matrix.hpp> // for panic::tensor::real_matrix
#include <tensor/vector.hpp> // for panic::vector
#include <tensor/matrix.hpp> // for panic::matrix
//--------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------
// DEFINE DESCRIPTION // PRIVATE CONSTANTS
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// VARIABLE DESCRIPTION
//--------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------
/**
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
*
* Small vectors and matrices are kept serial because the overhead of starting
* worker threads can be larger than the work itself.
*/
static const panic::types::uint_t add_omp_min_work = 10000; static const panic::types::uint_t add_omp_min_work = 10000;
//--------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------
// FUNCTION PROTOTYPE // INPLEMENTATION
//--------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------
namespace panic { namespace panic {
@@ -77,9 +81,12 @@ bool add(const panic::tensor::vector<T>& a, const T k, panic::tensor::vector<T>&
return true; return true;
} }
//--------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
// EXPLICIT TEMPLATE DECLARATION // EXPLICIT TEMPLATE INSTANTIATION
//--------------------------------------------------------------------------------------------------------------------------- //
// The implementation is in this .cpp file.
// Build the overload for the official PANIC numeric types.
//--------------------------------------------------------------------------------------------------------------------------
template bool add<panic::types::uint_t>(const panic::tensor::vector<panic::types::uint_t>& a, template bool add<panic::types::uint_t>(const panic::tensor::vector<panic::types::uint_t>& a,
const panic::types::uint_t k, const panic::types::uint_t k,
panic::tensor::vector<panic::types::uint_t>& c panic::tensor::vector<panic::types::uint_t>& c
@@ -111,9 +118,12 @@ panic::tensor::vector<T> add(const panic::tensor::vector<T>& a, const T k){
return c; return c;
} }
//--------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
// EXPLICIT TEMPLATE DECLARATION // EXPLICIT TEMPLATE INSTANTIATION
//--------------------------------------------------------------------------------------------------------------------------- //
// The implementation is in this .cpp file.
// Build the overload for the official PANIC numeric types.
//--------------------------------------------------------------------------------------------------------------------------
template panic::tensor::vector<panic::types::uint_t> template panic::tensor::vector<panic::types::uint_t>
add(const panic::tensor::vector<panic::types::uint_t>& a, add(const panic::tensor::vector<panic::types::uint_t>& a,
const panic::types::uint_t k const panic::types::uint_t k
@@ -128,10 +138,6 @@ template panic::tensor::vector<panic::types::real_t>
); );
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::add // Function Name : panic::math::add
// //
@@ -156,9 +162,12 @@ bool add(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b, p
return true; return true;
} }
//--------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
// EXPLICIT TEMPLATE DECLARATION // EXPLICIT TEMPLATE INSTANTIATION
//--------------------------------------------------------------------------------------------------------------------------- //
// The implementation is in this .cpp file.
// Build the overload for the official PANIC numeric types.
//--------------------------------------------------------------------------------------------------------------------------
template bool add(const panic::tensor::vector<panic::types::uint_t>& a, template bool add(const panic::tensor::vector<panic::types::uint_t>& a,
const panic::tensor::vector<panic::types::uint_t>& b, const panic::tensor::vector<panic::types::uint_t>& b,
panic::tensor::vector<panic::types::uint_t>& c panic::tensor::vector<panic::types::uint_t>& c
@@ -173,12 +182,6 @@ template bool add(const panic::tensor::vector<panic::types::real_t>& a,
); );
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::add // Function Name : panic::math::add
// //
@@ -195,9 +198,12 @@ panic::tensor::vector<T> add(const panic::tensor::vector<T>& a, const panic::ten
return c; return c;
} }
//--------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
// EXPLICIT TEMPLATE DECLARATION // EXPLICIT TEMPLATE INSTANTIATION
//--------------------------------------------------------------------------------------------------------------------------- //
// The implementation is in this .cpp file.
// Build the overload for the official PANIC numeric types.
//--------------------------------------------------------------------------------------------------------------------------
template panic::tensor::vector<panic::types::uint_t> template panic::tensor::vector<panic::types::uint_t>
add(const panic::tensor::vector<panic::types::uint_t>& a, add(const panic::tensor::vector<panic::types::uint_t>& a,
const panic::tensor::vector<panic::types::uint_t>& b const panic::tensor::vector<panic::types::uint_t>& b
@@ -212,8 +218,6 @@ template panic::tensor::vector<panic::types::real_t>
); );
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::add // Function Name : panic::math::add
// //
@@ -242,9 +246,12 @@ bool add(const panic::tensor::matrix<T>& A, const T k, panic::tensor::matrix<T>&
return true; return true;
} }
//--------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
// EXPLICIT TEMPLATE DECLARATION // EXPLICIT TEMPLATE INSTANTIATION
//--------------------------------------------------------------------------------------------------------------------------- //
// The implementation is in this .cpp file.
// Build the overload for the official PANIC numeric types.
//--------------------------------------------------------------------------------------------------------------------------
template bool add(const panic::tensor::matrix<panic::types::uint_t>& A, template bool add(const panic::tensor::matrix<panic::types::uint_t>& A,
const panic::types::uint_t k, const panic::types::uint_t k,
panic::tensor::matrix<panic::types::uint_t>& C panic::tensor::matrix<panic::types::uint_t>& C
@@ -277,9 +284,12 @@ panic::tensor::matrix<T> add(const panic::tensor::matrix<T>& A, const T k){
return C; return C;
} }
//--------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
// EXPLICIT TEMPLATE DECLARATION // EXPLICIT TEMPLATE INSTANTIATION
//--------------------------------------------------------------------------------------------------------------------------- //
// The implementation is in this .cpp file.
// Build the overload for the official PANIC numeric types.
//--------------------------------------------------------------------------------------------------------------------------
template panic::tensor::matrix<panic::types::uint_t> template panic::tensor::matrix<panic::types::uint_t>
add(const panic::tensor::matrix<panic::types::uint_t>& A, add(const panic::tensor::matrix<panic::types::uint_t>& A,
const panic::types::uint_t k const panic::types::uint_t k
@@ -326,9 +336,12 @@ bool add(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, p
return true; return true;
} }
//--------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
// EXPLICIT TEMPLATE DECLARATION // EXPLICIT TEMPLATE INSTANTIATION
//--------------------------------------------------------------------------------------------------------------------------- //
// The implementation is in this .cpp file.
// Build the overload for the official PANIC numeric types.
//--------------------------------------------------------------------------------------------------------------------------
template bool add(const panic::tensor::matrix<panic::types::uint_t>& A, template bool add(const panic::tensor::matrix<panic::types::uint_t>& A,
const panic::tensor::matrix<panic::types::uint_t>& B, const panic::tensor::matrix<panic::types::uint_t>& B,
panic::tensor::matrix<panic::types::uint_t>& C panic::tensor::matrix<panic::types::uint_t>& C
@@ -344,9 +357,6 @@ template bool add(const panic::tensor::matrix<panic::types::real_t>& A,
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::add // Function Name : panic::math::add
// //
@@ -363,9 +373,12 @@ panic::tensor::matrix<T> add(const panic::tensor::matrix<T>& A, const panic::ten
return C; return C;
} }
//--------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
// EXPLICIT TEMPLATE DECLARATION // EXPLICIT TEMPLATE INSTANTIATION
//--------------------------------------------------------------------------------------------------------------------------- //
// The implementation is in this .cpp file.
// Build the overload for the official PANIC numeric types.
//--------------------------------------------------------------------------------------------------------------------------
template panic::tensor::matrix<panic::types::uint_t> template panic::tensor::matrix<panic::types::uint_t>
add(const panic::tensor::matrix<panic::types::uint_t>& A, add(const panic::tensor::matrix<panic::types::uint_t>& A,
const panic::tensor::matrix<panic::types::uint_t>& B const panic::tensor::matrix<panic::types::uint_t>& B
@@ -413,9 +426,12 @@ bool add_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<
return true; return true;
} }
//--------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
// EXPLICIT TEMPLATE DECLARATION // EXPLICIT TEMPLATE INSTANTIATION
//--------------------------------------------------------------------------------------------------------------------------- //
// The implementation is in this .cpp file.
// Build the overload for the official PANIC numeric types.
//--------------------------------------------------------------------------------------------------------------------------
template bool add_rowwise(const panic::tensor::matrix<panic::types::uint_t>& A, template bool add_rowwise(const panic::tensor::matrix<panic::types::uint_t>& A,
const panic::tensor::vector<panic::types::uint_t>& b, const panic::tensor::vector<panic::types::uint_t>& b,
panic::tensor::matrix<panic::types::uint_t>& C panic::tensor::matrix<panic::types::uint_t>& C
@@ -448,9 +464,12 @@ panic::tensor::matrix<T> add_rowwise(const panic::tensor::matrix<T>& A, const pa
return C; return C;
} }
//--------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
// EXPLICIT TEMPLATE DECLARATION // EXPLICIT TEMPLATE INSTANTIATION
//--------------------------------------------------------------------------------------------------------------------------- //
// The implementation is in this .cpp file.
// Build the overload for the official PANIC numeric types.
//--------------------------------------------------------------------------------------------------------------------------
template panic::tensor::matrix<panic::types::uint_t> template panic::tensor::matrix<panic::types::uint_t>
add_rowwise(const panic::tensor::matrix<panic::types::uint_t>& A, add_rowwise(const panic::tensor::matrix<panic::types::uint_t>& A,
const panic::tensor::vector<panic::types::uint_t>& b const panic::tensor::vector<panic::types::uint_t>& b
@@ -467,9 +486,6 @@ template panic::tensor::matrix<panic::types::real_t>
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::add_colwise // Function Name : panic::math::add_colwise
// //
@@ -504,9 +520,12 @@ bool add_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<
return true; return true;
} }
//--------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
// EXPLICIT TEMPLATE DECLARATION // EXPLICIT TEMPLATE INSTANTIATION
//--------------------------------------------------------------------------------------------------------------------------- //
// The implementation is in this .cpp file.
// Build the overload for the official PANIC numeric types.
//--------------------------------------------------------------------------------------------------------------------------
template bool add_colwise(const panic::tensor::matrix<panic::types::uint_t>& A, template bool add_colwise(const panic::tensor::matrix<panic::types::uint_t>& A,
const panic::tensor::vector<panic::types::uint_t>& b, const panic::tensor::vector<panic::types::uint_t>& b,
panic::tensor::matrix<panic::types::uint_t>& C panic::tensor::matrix<panic::types::uint_t>& C
@@ -539,9 +558,12 @@ panic::tensor::matrix<T> add_colwise(const panic::tensor::matrix<T>& A, const pa
return C; return C;
} }
//--------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
// EXPLICIT TEMPLATE DECLARATION // EXPLICIT TEMPLATE INSTANTIATION
//--------------------------------------------------------------------------------------------------------------------------- //
// The implementation is in this .cpp file.
// Build the overload for the official PANIC numeric types.
//--------------------------------------------------------------------------------------------------------------------------
template panic::tensor::matrix<panic::types::uint_t> template panic::tensor::matrix<panic::types::uint_t>
add_colwise(const panic::tensor::matrix<panic::types::uint_t>& A, add_colwise(const panic::tensor::matrix<panic::types::uint_t>& A,
const panic::tensor::vector<panic::types::uint_t>& b const panic::tensor::vector<panic::types::uint_t>& b
@@ -558,6 +580,5 @@ template panic::tensor::matrix<panic::types::real_t>
} // namespace math } // namespace math
} // namespace panic } // namespace panic
+37 -30
View File
@@ -36,20 +36,24 @@
// INCLUDE DESCRIPTION // INCLUDE DESCRIPTION
//----------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------
#include <math/matmul.hpp> #include <math/matmul.hpp>
#include <tensor/matrix.hpp> // for panic::tensor::real_matrix
#include <config/omp.hpp> #include <config/omp.hpp>
//--------------------------------------------------------------------------------------------------------------------------- #include <tensor/matrix.hpp> // for panic::tensor::matrix
// DEFINE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------
// VARIABLE DESCRIPTION // PRIVATE CONSTANTS
//--------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------
/**
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
*
* Small vectors and matrices are kept serial because the overhead of starting
* worker threads can be larger than the work itself.
*/
static const panic::types::uint_t matmul_omp_min_work = 10000; static const panic::types::uint_t matmul_omp_min_work = 10000;
//--------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------
// FUNCTION PROTOTYPE // INPLEMENTATION
//--------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------
namespace panic { namespace panic {
@@ -103,32 +107,12 @@ bool matmul(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B
} }
return true; return true;
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::matmul // EXPLICIT TEMPLATE INSTANTIATION
// //
// Description: // The implementation is in this .cpp file.
// Multiply two matrices and returns the result. // Build the overload for the official PANIC numeric types.
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
template <typename T>
panic::tensor::matrix<T> matmul(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B){
panic::tensor::matrix<T> C;
if (!matmul(A,B,C)){
return panic::tensor::matrix<T>();
}
return C;
}
//---------------------------------------------------------------------------------------------------------------------------
// EXPLICIT TEMPLATE DECLARATION
//---------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------
// Function : bool matmul(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, panic::tensor::matrix<T>& C)
template bool matmul<panic::types::uint_t>( template bool matmul<panic::types::uint_t>(
const panic::tensor::matrix<panic::types::uint_t>& A, const panic::tensor::matrix<panic::types::uint_t>& A,
const panic::tensor::matrix<panic::types::uint_t>& B, const panic::tensor::matrix<panic::types::uint_t>& B,
@@ -147,8 +131,31 @@ template bool matmul<panic::types::real_t>(
panic::tensor::matrix<panic::types::real_t>& C panic::tensor::matrix<panic::types::real_t>& C
); );
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::matmul
//
// Description:
// Multiply two matrices and returns the result.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
panic::tensor::matrix<T> matmul(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B){
panic::tensor::matrix<T> C;
if (!matmul(A,B,C)){
return panic::tensor::matrix<T>();
}
return C;
}
//--------------------------------------------------------------------------------------------------------------------------
// EXPLICIT TEMPLATE INSTANTIATION
//
// The implementation is in this .cpp file.
// Build the overload for the official PANIC numeric types.
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
// Function : panic::tensor::matrix<T> matmul(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B)
template panic::tensor::matrix<panic::types::uint_t> matmul<panic::types::uint_t>( template panic::tensor::matrix<panic::types::uint_t> matmul<panic::types::uint_t>(
const panic::tensor::matrix<panic::types::uint_t>& A, const panic::tensor::matrix<panic::types::uint_t>& A,
const panic::tensor::matrix<panic::types::uint_t>& B const panic::tensor::matrix<panic::types::uint_t>& B
+10 -19
View File
@@ -36,24 +36,20 @@
// INCLUDE DESCRIPTION // INCLUDE DESCRIPTION
//--------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------
#include <tensor/matrix.hpp> #include <tensor/matrix.hpp>
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
#include <config/omp.hpp> #include <config/omp.hpp>
//--------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------
// DEFINE DESCRIPTION // PRIVATE CONSTANTS
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// TYPE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// VARIABLE DESCRIPTION
//--------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------
/**
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
*
* Small vectors and matrices are kept serial because the overhead of starting
* worker threads can be larger than the work itself.
*/
static const panic::types::uint_t matrix_omp_min_size = 10000; static const panic::types::uint_t matrix_omp_min_size = 10000;
//---------------------------------------------------------------------------------------------------------------------------
// FUNCTION PROTOTYPE
//---------------------------------------------------------------------------------------------------------------------------
namespace panic{ namespace panic{
namespace tensor{ namespace tensor{
@@ -127,9 +123,7 @@ matrix<T>::matrix(panic::types::uint_t rows, panic::types::uint_t cols, T value)
// Constructor Name : panic::tensor::matrix::matrix // Constructor Name : panic::tensor::matrix::matrix
// //
// Description: // Description:
// Copy-contructor, makes a deep copy of another matrix like this: // Copy-contructor, makes a deep copy of another matrix
// matrix A(3);
// matrix B = A;
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
template <typename T> template <typename T>
matrix<T>::matrix(const matrix& other){ matrix<T>::matrix(const matrix& other){
@@ -170,10 +164,7 @@ matrix<T>::~matrix(){
// Function Name : panic::tensor::matrix::operator= // Function Name : panic::tensor::matrix::operator=
// //
// Description: // Description:
// Copy-assignment. Copies from another matrix like this: // Copy-assignment. Copies from another matrix.
// matrix A(5);
// matrix B(3);
// B = A;
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
template <typename T> template <typename T>
matrix<T>& matrix<T>::operator=(const matrix& other){ matrix<T>& matrix<T>::operator=(const matrix& other){