Dense Layer, Add

added the dense layer with a forward functions. I also made the add functions for most cases.
This commit is contained in:
2026-06-25 19:43:07 +02:00
parent 9b20278395
commit 189d605bfa
27 changed files with 1657 additions and 902 deletions
+21 -21
View File
@@ -49,7 +49,7 @@
//---------------------------------------------------------------------------------------------------------------------------
// VARIABLE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
static const panic::uint_t matrix_omp_min_size = 10000;
static const panic::types::uint_t matrix_omp_min_size = 10000;
//---------------------------------------------------------------------------------------------------------------------------
// FUNCTION PROTOTYPE
@@ -79,7 +79,7 @@ matrix<T>::matrix() {
// Creates a matrix with size allocation and initializes all values to zero.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
matrix<T>::matrix(panic::uint_t rows, panic::uint_t cols){
matrix<T>::matrix(panic::types::uint_t rows, panic::types::uint_t cols){
n = rows;
m = cols;
length = n*m;
@@ -92,7 +92,7 @@ matrix<T>::matrix(panic::uint_t rows, panic::uint_t cols){
data = new T[length];
PANIC_OMP_PARALLEL_FOR_IF(length > matrix_omp_min_size)
for (panic::uint_t i = 0; i < length; ++i){
for (panic::types::uint_t i = 0; i < length; ++i){
data[i] = static_cast<T>(0);
}
@@ -105,7 +105,7 @@ matrix<T>::matrix(panic::uint_t rows, panic::uint_t cols){
// Creates a matrix with size allocation and initializes all values.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
matrix<T>::matrix(panic::uint_t rows, panic::uint_t cols, T value){
matrix<T>::matrix(panic::types::uint_t rows, panic::types::uint_t cols, T value){
n = rows;
m = cols;
length = n*m;
@@ -118,7 +118,7 @@ matrix<T>::matrix(panic::uint_t rows, panic::uint_t cols, T value){
data = new T[length];
PANIC_OMP_PARALLEL_FOR_IF(length > matrix_omp_min_size)
for (panic::uint_t i = 0; i < length; ++i){
for (panic::types::uint_t i = 0; i < length; ++i){
data[i] = value;
}
}
@@ -145,7 +145,7 @@ matrix<T>::matrix(const matrix& other){
data = new T[length];
PANIC_OMP_PARALLEL_FOR_IF(length > matrix_omp_min_size)
for (panic::uint_t i = 0; i < length; ++i){
for (panic::types::uint_t i = 0; i < length; ++i){
data[i] = other.data[i];
}
}
@@ -186,8 +186,8 @@ matrix<T>& matrix<T>::operator=(const matrix& other){
if (other.length > 0){
new_data = new T[other.length];
PANIC_OMP_PARALLEL_FOR_IF(length > matrix_omp_min_size)
for (panic::uint_t i = 0; i < other.length; ++i){
PANIC_OMP_PARALLEL_FOR_IF(other.length > matrix_omp_min_size)
for (panic::types::uint_t i = 0; i < other.length; ++i){
new_data[i] = other.data[i];
}
}
@@ -209,7 +209,7 @@ matrix<T>& matrix<T>::operator=(const matrix& other){
// Returns the length/size of the matrix
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
panic::uint_t matrix<T>::rows() const{
panic::types::uint_t matrix<T>::rows() const{
return n;
}
@@ -220,7 +220,7 @@ panic::uint_t matrix<T>::rows() const{
// Returns the length/size of the matrix
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
panic::uint_t matrix<T>::cols() const{
panic::types::uint_t matrix<T>::cols() const{
return m;
}
@@ -231,7 +231,7 @@ panic::uint_t matrix<T>::cols() const{
// Resizes the matrix to new dimentions and keeps old values
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
bool matrix<T>::resize(panic::uint_t new_n, panic::uint_t new_m){
bool matrix<T>::resize(panic::types::uint_t new_n, panic::types::uint_t new_m){
if ((new_n == n) && (new_m == m)){
return true;
@@ -247,22 +247,22 @@ bool matrix<T>::resize(panic::uint_t new_n, panic::uint_t new_m){
return true;
}
panic::uint_t new_length = new_n*new_m;
panic::types::uint_t new_length = new_n*new_m;
T* new_data = new T[new_length];
panic::uint_t copy_size = length;
panic::types::uint_t copy_size = length;
if (new_length < length){
copy_size = new_length;
}
PANIC_OMP_PARALLEL_FOR_IF(copy_size > matrix_omp_min_size)
for (panic::uint_t i = 0; i < copy_size; ++i){
for (panic::types::uint_t i = 0; i < copy_size; ++i){
new_data[i] = data[i];
}
PANIC_OMP_PARALLEL_FOR_IF(new_length - copy_size > matrix_omp_min_size)
for (panic::uint_t i = copy_size; i < new_length; ++i){
for (panic::types::uint_t i = copy_size; i < new_length; ++i){
new_data[i] = static_cast<T>(0);
}
@@ -286,7 +286,7 @@ bool matrix<T>::resize(panic::uint_t new_n, panic::uint_t new_m){
template <typename T>
bool matrix<T>::fill(T value){
PANIC_OMP_PARALLEL_FOR_IF(length > matrix_omp_min_size)
for (panic::uint_t i = 0; i < length; ++i){
for (panic::types::uint_t i = 0; i < length; ++i){
data[i] = value;
}
@@ -300,7 +300,7 @@ bool matrix<T>::fill(T value){
// Lets you read and write A(2,3)
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
T& matrix<T>::operator()(panic::uint_t index_n, panic::uint_t index_m){
T& matrix<T>::operator()(panic::types::uint_t index_n, panic::types::uint_t index_m){
return data[index_n*m + index_m];
}
@@ -312,7 +312,7 @@ T& matrix<T>::operator()(panic::uint_t index_n, panic::uint_t index_m){
// Lets you read A(2,3) from a const matrix
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
const T& matrix<T>::operator()(panic::uint_t index_n, panic::uint_t index_m) const{
const T& matrix<T>::operator()(panic::types::uint_t index_n, panic::types::uint_t index_m) const{
return data[index_n*m + index_m];
}
@@ -321,9 +321,9 @@ const T& matrix<T>::operator()(panic::uint_t index_n, panic::uint_t index_m) con
// EXPLICIT TEMPLATE INSTANTIATION
//---------------------------------------------------------------------------------------------------------------------------
template struct matrix<panic::real_t>;
template struct matrix<panic::int_t>;
template struct matrix<panic::uint_t>;
template struct matrix<panic::types::real_t>;
template struct matrix<panic::types::int_t>;
template struct matrix<panic::types::uint_t>;
} // namespace tensor