49 lines
795 B
C++
49 lines
795 B
C++
#pragma once
|
|
|
|
#include <cstdint> //uint64_t
|
|
#include <cmath> // std::abs
|
|
|
|
#include "utils/vector.h"
|
|
#include "utils/matrix.h"
|
|
|
|
namespace numerics::detail{
|
|
|
|
|
|
|
|
template <typename T>
|
|
void inplace_sign_serial(T& c) {
|
|
if (c < T{0}){
|
|
c = T{-1};
|
|
}
|
|
else if(c > T{0}){
|
|
c = T{1};
|
|
}
|
|
else{
|
|
c = T{0};
|
|
}
|
|
}
|
|
|
|
template <typename T>
|
|
void inplace_sign_serial(utils::Vector<T>& v) {
|
|
const uint64_t n = v.size();
|
|
for (uint64_t i = 0; i < n; ++i){
|
|
inplace_sign_serial(v[i]);
|
|
}
|
|
}
|
|
|
|
|
|
template <typename T>
|
|
void inplace_sign_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){
|
|
inplace_sign_serial(A(i,j));
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
} // namespace numerics
|
|
|