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
+37 -49
View File
@@ -35,10 +35,11 @@
//---------------------------------------------------------------------------------------------------------------------------
// INCLUDE DESCRIPTION
//-----------------------------------------------------------------------------------------------------
#include <io/print_tensor.hpp>
#include <iostream> // for std::cout, std::endl
//#include <io/print_tensor.hpp>
#include <tensor/vector.hpp> // for panic::tensor::vector
#include <tensor/matrix.hpp>
#include <tensor/vector.hpp> // for panic::vector
#include <tensor/matrix.hpp> // for panic::matrix
//---------------------------------------------------------------------------------------------------------------------------
// DEFINE DESCRIPTION
@@ -61,32 +62,32 @@ namespace panic {
//
// Description:
// 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 << "[";
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::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;
return true;
}
void print_vector(const panic::tensor::real_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;
//--------------------------------------------------------------------------------------------------------------------------
// EXPLICIT TEMPLATE INSTANTIATION
//
// The implementation is in this .cpp file.
// Build the overload for the official PANIC numeric types.
//--------------------------------------------------------------------------------------------------------------------------
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:
// 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 << "[";
for (panic::types::uint_t i = 0; i < A.rows(); ++i){
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;
}
}
return true;
}
void print_matrix(const panic::tensor::int_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;
}
}
}
//--------------------------------------------------------------------------------------------------------------------------
// EXPLICIT TEMPLATE INSTANTIATION
//
// The implementation is in this .cpp file.
// Build the overload for the official PANIC numeric types.
//--------------------------------------------------------------------------------------------------------------------------
template bool print_matrix<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& A
);
template bool print_matrix<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& A
);
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
+83 -62
View File
@@ -38,19 +38,23 @@
#include <math/add.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
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// 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 add_omp_min_work = 10000;
//---------------------------------------------------------------------------------------------------------------------------
// FUNCTION PROTOTYPE
// INPLEMENTATION
//---------------------------------------------------------------------------------------------------------------------------
namespace panic {
@@ -77,9 +81,12 @@ bool add(const panic::tensor::vector<T>& a, const T k, panic::tensor::vector<T>&
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,
const panic::types::uint_t k,
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;
}
//---------------------------------------------------------------------------------------------------------------------------
// 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>
add(const panic::tensor::vector<panic::types::uint_t>& a,
const panic::types::uint_t k
@@ -128,10 +138,6 @@ template panic::tensor::vector<panic::types::real_t>
);
//--------------------------------------------------------------------------------------------------------------------------
// 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;
}
//---------------------------------------------------------------------------------------------------------------------------
// 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,
const panic::tensor::vector<panic::types::uint_t>& b,
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
//
@@ -195,9 +198,12 @@ panic::tensor::vector<T> add(const panic::tensor::vector<T>& a, const panic::ten
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>
add(const panic::tensor::vector<panic::types::uint_t>& a,
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
//
@@ -242,9 +246,12 @@ bool add(const panic::tensor::matrix<T>& A, const T k, panic::tensor::matrix<T>&
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,
const panic::types::uint_t k,
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;
}
//---------------------------------------------------------------------------------------------------------------------------
// 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>
add(const panic::tensor::matrix<panic::types::uint_t>& A,
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;
}
//---------------------------------------------------------------------------------------------------------------------------
// 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,
const panic::tensor::matrix<panic::types::uint_t>& B,
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
//
@@ -363,9 +373,12 @@ panic::tensor::matrix<T> add(const panic::tensor::matrix<T>& A, const panic::ten
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>
add(const panic::tensor::matrix<panic::types::uint_t>& A,
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;
}
//---------------------------------------------------------------------------------------------------------------------------
// 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,
const panic::tensor::vector<panic::types::uint_t>& b,
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;
}
//---------------------------------------------------------------------------------------------------------------------------
// 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>
add_rowwise(const panic::tensor::matrix<panic::types::uint_t>& A,
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
//
@@ -504,9 +520,12 @@ bool add_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<
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,
const panic::tensor::vector<panic::types::uint_t>& b,
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;
}
//---------------------------------------------------------------------------------------------------------------------------
// 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>
add_colwise(const panic::tensor::matrix<panic::types::uint_t>& A,
const panic::tensor::vector<panic::types::uint_t>& b
@@ -558,6 +580,5 @@ template panic::tensor::matrix<panic::types::real_t>
} // namespace math
} // namespace panic
+37 -30
View File
@@ -36,20 +36,24 @@
// INCLUDE DESCRIPTION
//-----------------------------------------------------------------------------------------------------
#include <math/matmul.hpp>
#include <tensor/matrix.hpp> // for panic::tensor::real_matrix
#include <config/omp.hpp>
//---------------------------------------------------------------------------------------------------------------------------
// DEFINE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
#include <tensor/matrix.hpp> // for panic::tensor::matrix
//---------------------------------------------------------------------------------------------------------------------------
// 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;
//---------------------------------------------------------------------------------------------------------------------------
// FUNCTION PROTOTYPE
// INPLEMENTATION
//---------------------------------------------------------------------------------------------------------------------------
namespace panic {
@@ -103,32 +107,12 @@ bool matmul(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B
}
return true;
}
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::matmul
// EXPLICIT TEMPLATE INSTANTIATION
//
// Description:
// Multiply two matrices and returns the result.
// The implementation is in this .cpp file.
// 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>(
const panic::tensor::matrix<panic::types::uint_t>& A,
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
);
//--------------------------------------------------------------------------------------------------------------------------
// 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>(
const panic::tensor::matrix<panic::types::uint_t>& A,
const panic::tensor::matrix<panic::types::uint_t>& B
+10 -19
View File
@@ -36,24 +36,20 @@
// INCLUDE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
#include <tensor/matrix.hpp>
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
#include <config/omp.hpp>
//---------------------------------------------------------------------------------------------------------------------------
// DEFINE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// TYPE 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 matrix_omp_min_size = 10000;
//---------------------------------------------------------------------------------------------------------------------------
// FUNCTION PROTOTYPE
//---------------------------------------------------------------------------------------------------------------------------
namespace panic{
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
//
// Description:
// Copy-contructor, makes a deep copy of another matrix like this:
// matrix A(3);
// matrix B = A;
// Copy-contructor, makes a deep copy of another matrix
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
matrix<T>::matrix(const matrix& other){
@@ -170,10 +164,7 @@ matrix<T>::~matrix(){
// Function Name : panic::tensor::matrix::operator=
//
// Description:
// Copy-assignment. Copies from another matrix like this:
// matrix A(5);
// matrix B(3);
// B = A;
// Copy-assignment. Copies from another matrix.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
matrix<T>& matrix<T>::operator=(const matrix& other){