37 lines
807 B
C++
37 lines
807 B
C++
#pragma once
|
|
|
|
#include <cstdint> //uint64_t
|
|
#include <cmath> // std::abs
|
|
|
|
#include "utils/vector.h"
|
|
#include "utils/matrix.h"
|
|
|
|
namespace numerics::detail{
|
|
|
|
|
|
// ---------------- Elemenwise ----------------
|
|
template <typename T>
|
|
void inplace_abs_scalar_serial(T& c) {
|
|
c = static_cast<T>(std::abs(c));
|
|
}
|
|
|
|
template <typename T>
|
|
void inplace_abs_elementwise_serial(utils::Matrix<T>& A) {
|
|
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::abs(A(i,j)));
|
|
}
|
|
}
|
|
}
|
|
|
|
template <typename T>
|
|
void inplace_abs_elementwise_serial(utils::Vector<T>& v) {
|
|
for (uint64_t i = 0; i < v.size(); ++i){
|
|
v[i] = static_cast<T>(std::abs(v[i]));
|
|
}
|
|
}
|
|
} // namespace numerics
|
|
|