ready for parralization

This commit is contained in:
2025-09-12 22:58:52 +02:00
parent cb825aec40
commit 320436ce98
14 changed files with 920 additions and 294 deletions
+24 -25
View File
@@ -44,6 +44,9 @@ public:
// vector.size();
uint64_t size() const noexcept { return v.size(); }
void resize(uint64_t new_size, const T& value = T()) {
v.resize(new_size, value);
}
//###########################################
//# VECTOR: == and != #
@@ -303,38 +306,19 @@ public:
Vector<T> result = *this;
result.inplace_power(a);
return result;
}
//################################################
//# VECTOR: Scalar Square #
//################################################
template <typename U, typename = typename std::enable_if<std::is_convertible<U, T>::value>::type>
void inplace_square(const U a){
const uint64_t n = v.size();
for (uint64_t i = 0; i < n; ++i){
v[i] = static_cast<T>(std::sqrt(v[i], a));
}
}
template <typename U, typename = typename std::enable_if<std::is_convertible<U, T>::value>::type>
Vector<T> square(const U a) const{
Vector<T> result = *this;
result.inplace_square(a);
return result;
}
//################################################
//# VECTOR: Vector square #
//################################################
void inplace_square(const Vector<T>& a){
if (a.size() != v.size()){
throw std::runtime_error("utill:Vector.inplace_square -> Dimensions does not fit");
}
uint64_t n = a.size();
void inplace_sqrt(){
uint64_t n = v.size();
for (uint64_t i = 0; i < n; ++i){
v[i] = static_cast<T>(std::sqrt(v[i], a[i]));
v[i] = static_cast<T>(std::sqrt(v[i]));
}
}
Vector<T> square(const Vector<T>& a) const{
Vector<T> sqrt() const{
Vector<T> result = *this;
result.inplace_square(a);
result.inplace_sqrt();
return result;
}
//###################################################
@@ -344,7 +328,7 @@ public:
if (a.size() != v.size()){
throw std::runtime_error("utill:Vector.dot -> Dimensions does not fit");
}
T result;
T result = T{0};
const uint64_t n = v.size();
for (uint64_t i = 0; i < n; ++i){
result += a[i]*v[i];
@@ -368,6 +352,21 @@ public:
T norm() const{
return static_cast<T>(std::sqrt(this->dot(*this)));
}
//############################################
//# VECTOR: Normalize #
//############################################
void inplace_normalize() {
T norm = this->norm();
if (norm == T{0}){
throw std::runtime_error("utils::Vector.normalize -> zero norm");
}
this->inplace_divide(norm);
}
Vector<T> normalize() const{
Vector<T> result = *this;
result.inplace_normalize();
return result;
}
//######################################################
//# VECTOR: Support Functions #
//######################################################