Starting on the model.h, but need to make layer structs and structs for loss and optimizers
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
#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
|
||||
|
||||
Reference in New Issue
Block a user