9709949a5b
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.
56 lines
1.6 KiB
C++
56 lines
1.6 KiB
C++
#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
|
|
|