First matrix implementation with print_matrix in io
This commit is contained in:
2026-06-23 20:28:11 +02:00
parent 77d2dad320
commit a791201f3a
34 changed files with 824 additions and 1907 deletions
+10 -1
View File
@@ -24,7 +24,7 @@
* Module Name: tensor
* File Name: vector.cpp
* Revision: 0.1.0
* Date: 21-06-2026
* Date: 23-06-2026
* Author: Michelle Bausager
*
* Description:
@@ -36,6 +36,7 @@
// INCLUDE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
#include <tensor/vector.hpp>
#include <config/omp.hpp>
//---------------------------------------------------------------------------------------------------------------------------
// DEFINE DESCRIPTION
@@ -48,6 +49,7 @@
//---------------------------------------------------------------------------------------------------------------------------
// VARIABLE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
static const panic::uint_t vector_omp_min_size = 10000;
//---------------------------------------------------------------------------------------------------------------------------
// FUNCTION PROTOTYPE
@@ -85,6 +87,7 @@ vector<T>::vector(panic::uint_t size){
data = new T[length];
PANIC_OMP_PARALLEL_FOR_IF(length > vector_omp_min_size)
for (panic::uint_t i = 0; i < size; ++i){
data[i] = static_cast<T>(0);
}
@@ -108,6 +111,7 @@ vector<T>::vector(panic::uint_t size, T value){
data = new T[size];
PANIC_OMP_PARALLEL_FOR_IF(length > vector_omp_min_size)
for (panic::uint_t i = 0; i < size; ++i){
data[i] = value;
}
@@ -132,6 +136,7 @@ vector<T>::vector(const vector& other){
data = new T[length];
PANIC_OMP_PARALLEL_FOR_IF(length > vector_omp_min_size)
for (panic::uint_t i = 0; i < length; ++i){
data[i] = other.data[i];
}
@@ -171,6 +176,7 @@ vector<T>& vector<T>::operator=(const vector& other){
if (other.length > 0){
new_data = new T[other.length];
PANIC_OMP_PARALLEL_FOR_IF(length > vector_omp_min_size)
for (panic::uint_t i = 0; i < other.length; ++i){
new_data[i] = other.data[i];
}
@@ -221,10 +227,12 @@ bool vector<T>::resize(panic::uint_t new_size){
copy_size = new_size;
}
PANIC_OMP_PARALLEL_FOR_IF(copy_size > vector_omp_min_size)
for (panic::uint_t i = 0; i < copy_size; ++i){
new_data[i] = data[i];
}
PANIC_OMP_PARALLEL_FOR_IF(copy_size - new_size > vector_omp_min_size)
for (panic::uint_t i = copy_size; i < new_size; ++i){
new_data[i] = static_cast<T>(0);
}
@@ -246,6 +254,7 @@ bool vector<T>::resize(panic::uint_t new_size){
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
bool vector<T>::fill(T value){
PANIC_OMP_PARALLEL_FOR_IF(length > vector_omp_min_size)
for (panic::uint_t i = 0; i < length; ++i){
data[i] = value;
}