Refactor progress
Sync public mirror / sync (push) Failing after 27s

Next step is ramdom and equal. I also need to have a look at add and the serial naming of the functions.
This commit is contained in:
2026-01-13 20:07:27 +01:00
parent 48f329feef
commit 9709949a5b
52 changed files with 2038 additions and 1058 deletions
+55
View File
@@ -0,0 +1,55 @@
#pragma once
#include <cstdint> //uint64_t
#include <stdexcept> // std::runtime_error
#include <cmath> // std::pow
#include "../utils/vector.h"
#include "../utils/matrix.h"
namespace numerics::detail{
// ---------------- Scalar ----------------
template <typename T>
void inplace_pow_scalar_serial(utils::Matrix<T>& A, const T c) {
const uint64_t rows = A.rows();
const uint64_t cols = A.cols();
for (uint64_t i = 0; i < rows; ++i){
for (uint64_t j = 0; j < cols; ++j){
A(i,j) = static_cast<T>(std::pow(A(i,j),c));
}
}
}
template <typename T>
void inplace_pow_scalar_serial(utils::Vector<T>& v, const T c) {
for (uint64_t i = 0; i < v.size(); ++i){
v[i] = static_cast<T>(std::pow(v[i], c));
}
}
// ---------------- Elemenwise ----------------
template <typename T>
void inplace_pow_elementwise_serial(utils::Matrix<T>& A, const utils::Matrix<T>& B) {
const uint64_t rows = A.rows();
const uint64_t cols = A.cols();
if (rows != B.rows() || cols != B.cols()) {
throw std::runtime_error("inplace_pow_elementwise_serial: dimension mismatch");
}
for (uint64_t i = 0; i < rows; ++i){
for (uint64_t j = 0; j < cols; ++j){
A(i,j) = static_cast<T>(std::pow(A(i,j), B(i,j)));
}
}
}
template <typename T>
void inplace_pow_elementwise_serial(utils::Vector<T>& v, const utils::Vector<T>& p) {
if (v.size() != p.size()) {
throw std::runtime_error("inplace_pow_elementwise_serial: dimension mismatch");
}
for (uint64_t i = 0; i < v.size(); ++i){
v[i] = static_cast<T>(std::pow(v[i], p[i]));
}
}
} // namespace numerics