First omp

This commit is contained in:
2026-06-23 15:07:55 +02:00
parent b842990cd4
commit 77d2dad320
18 changed files with 789 additions and 88 deletions
+25 -1
View File
@@ -53,7 +53,31 @@
namespace panic {
namespace io {
void print(const panic::tensor::vector& v){
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::io::print
//
// Description:
// The vector is printed out in square brackets.
// Overloaded for panic::uint, panic::int and panic::real
//--------------------------------------------------------------------------------------------------------------------------
void print(const panic::tensor::uint_vector& v){
std::cout << "[";
for (panic::uint_t i = 0; i < v.size()-1; ++i){
std::cout << v[i] << ", ";
}
std::cout << v[v.size()-1]<< "]" << std::endl;
}
void print(const panic::tensor::int_vector& v){
std::cout << "[";
for (panic::uint_t i = 0; i < v.size()-1; ++i){
std::cout << v[i] << ", ";
}
std::cout << v[v.size()-1]<< "]" << std::endl;
}
void print(const panic::tensor::real_vector& v){
std::cout << "[";
for (panic::uint_t i = 0; i < v.size()-1; ++i){
std::cout << v[i] << ", ";
+44 -21
View File
@@ -62,7 +62,8 @@ namespace panic{
// Description:
// Creates an empty vector.
//--------------------------------------------------------------------------------------------------------------------------
vector::vector() {
template <typename T>
vector<T>::vector() {
length = 0;
data = 0;
}
@@ -73,7 +74,8 @@ vector::vector() {
// Description:
// Creates a vector with size allocation and initializes all values to zero.
//--------------------------------------------------------------------------------------------------------------------------
vector::vector(panic::uint_t size){
template <typename T>
vector<T>::vector(panic::uint_t size){
length = size;
if (length == 0){
@@ -81,10 +83,10 @@ vector::vector(panic::uint_t size){
return;
}
data = new panic::real_t[length];
data = new T[length];
for (panic::uint_t i = 0; i < size; ++i){
data[i] = static_cast<panic::real_t>(0);
data[i] = static_cast<T>(0);
}
}
@@ -95,7 +97,8 @@ vector::vector(panic::uint_t size){
// Description:
// Creates a vector with size allocation and initializes all values.
//--------------------------------------------------------------------------------------------------------------------------
vector::vector(panic::uint_t size, panic::real_t value){
template <typename T>
vector<T>::vector(panic::uint_t size, T value){
length = size;
if (size == 0){
@@ -103,7 +106,7 @@ vector::vector(panic::uint_t size, panic::real_t value){
return;
}
data = new panic::real_t[size];
data = new T[size];
for (panic::uint_t i = 0; i < size; ++i){
data[i] = value;
@@ -118,7 +121,8 @@ vector::vector(panic::uint_t size, panic::real_t value){
// vector a(3);
// vector b = a;
//--------------------------------------------------------------------------------------------------------------------------
vector::vector(const vector& other){
template <typename T>
vector<T>::vector(const vector& other){
length = other.length;
if (length == 0){
@@ -126,7 +130,7 @@ vector::vector(const vector& other){
return;
}
data = new panic::real_t[length];
data = new T[length];
for (panic::uint_t i = 0; i < length; ++i){
data[i] = other.data[i];
@@ -139,7 +143,8 @@ vector::vector(const vector& other){
// Description:
// Deletes the data and releases the memory.
//--------------------------------------------------------------------------------------------------------------------------
vector::~vector(){
template <typename T>
vector<T>::~vector(){
delete[] data;
data = 0;
@@ -155,15 +160,16 @@ vector::~vector(){
// vector b(3);
// b = a;
//--------------------------------------------------------------------------------------------------------------------------
vector& vector::operator=(const vector& other){
template <typename T>
vector<T>& vector<T>::operator=(const vector& other){
if (this == &other){
return *this;
}
panic::real_t* new_data = 0;
T* new_data = 0;
if (other.length > 0){
new_data = new panic::real_t[other.length];
new_data = new T[other.length];
for (panic::uint_t i = 0; i < other.length; ++i){
new_data[i] = other.data[i];
@@ -184,7 +190,8 @@ vector& vector::operator=(const vector& other){
// Description:
// Returns the length/size of the vector
//--------------------------------------------------------------------------------------------------------------------------
panic::uint_t vector::size() const{
template <typename T>
panic::uint_t vector<T>::size() const{
return length;
}
@@ -194,7 +201,8 @@ panic::uint_t vector::size() const{
// Description:
// Resizes the vector to new length and keeps old values
//--------------------------------------------------------------------------------------------------------------------------
bool vector::resize(panic::uint_t new_size){
template <typename T>
bool vector<T>::resize(panic::uint_t new_size){
if (new_size == length){
return true;
}
@@ -206,7 +214,7 @@ bool vector::resize(panic::uint_t new_size){
return true;
}
panic::real_t* new_data = new panic::real_t[new_size];
T* new_data = new T[new_size];
panic::uint_t copy_size = length;
if (new_size < length){
@@ -218,7 +226,7 @@ bool vector::resize(panic::uint_t new_size){
}
for (panic::uint_t i = copy_size; i < new_size; ++i){
new_data[i] = static_cast<panic::real_t>(0);
new_data[i] = static_cast<T>(0);
}
delete[] data;
@@ -236,7 +244,8 @@ bool vector::resize(panic::uint_t new_size){
// Description:
// Fills te vector with a value
//--------------------------------------------------------------------------------------------------------------------------
bool vector::fill(panic::real_t value){
template <typename T>
bool vector<T>::fill(T value){
for (panic::uint_t i = 0; i < length; ++i){
data[i] = value;
}
@@ -250,7 +259,8 @@ bool vector::fill(panic::real_t value){
// Description:
// Lets you read and write v[index]
//--------------------------------------------------------------------------------------------------------------------------
panic::real_t& vector::operator[](panic::uint_t index){
template <typename T>
T& vector<T>::operator[](panic::uint_t index){
return data[index];
}
@@ -260,7 +270,8 @@ panic::real_t& vector::operator[](panic::uint_t index){
// Description:
// Lets you read v[index] from a const vector
//--------------------------------------------------------------------------------------------------------------------------
const panic::real_t& vector::operator[](panic::uint_t index) const{
template <typename T>
const T& vector<T>::operator[](panic::uint_t index) const{
return data[index];
}
@@ -270,7 +281,8 @@ const panic::real_t& vector::operator[](panic::uint_t index) const{
// Description:
// Lets you read and write v.at(index) with index bounse
//--------------------------------------------------------------------------------------------------------------------------
panic::real_t& vector::at(panic::uint_t index){
template <typename T>
T& vector<T>::at(panic::uint_t index){
if (index >= length){
return data[length-1];
@@ -285,7 +297,8 @@ panic::real_t& vector::at(panic::uint_t index){
// Description:
// Lets you read v[index] from a const vector with index bounse
//--------------------------------------------------------------------------------------------------------------------------
const panic::real_t& vector::at(panic::uint_t index) const{
template <typename T>
const T& vector<T>::at(panic::uint_t index) const{
if (index >= length){
return data[length-1];
}
@@ -293,5 +306,15 @@ const panic::real_t& vector::at(panic::uint_t index) const{
}
//---------------------------------------------------------------------------------------------------------------------------
// EXPLICIT TEMPLATE INSTANTIATION
//---------------------------------------------------------------------------------------------------------------------------
template struct vector<panic::real_t>;
template struct vector<panic::int_t>;
template struct vector<panic::uint_t>;
} // namespace tensor
} // namespace panic