Fittet new functions to everying in neural networks. Still need to optimise for uint64_t vs int64_t and vec vs mat in some places.
This commit is contained in:
@@ -3,14 +3,14 @@
|
||||
#include <cstdint> //uint64_t
|
||||
//#include <stdexcept> // std::runtime_error
|
||||
|
||||
#include "../utils/vector.h"
|
||||
#include "../utils/matrix.h"
|
||||
#include "utils/vector.h"
|
||||
#include "utils/matrix.h"
|
||||
|
||||
namespace numerics::detail{
|
||||
|
||||
// ---------------- Matrix ----------------
|
||||
template <typename T>
|
||||
inline bool equal_serial(const utils::Matrix<T>& A, const utils::Matrix<T> & B) {
|
||||
inline bool equal_all_serial(const utils::Matrix<T>& A, const utils::Matrix<T> & B) {
|
||||
const uint64_t rows = A.rows();
|
||||
const uint64_t cols = A.cols();
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace numerics::detail{
|
||||
|
||||
// ---------------- Vector ----------------
|
||||
template <typename T>
|
||||
inline bool equal_serial(const utils::Vector<T>& v, const utils::Vector<T>& p) {
|
||||
inline bool equal_all_serial(const utils::Vector<T>& v, const utils::Vector<T>& p) {
|
||||
const uint64_t N = v.size();
|
||||
if (N != p.size()){
|
||||
return false;
|
||||
@@ -43,5 +43,47 @@ namespace numerics::detail{
|
||||
return true;
|
||||
}
|
||||
|
||||
// ---------------- Matrix ----------------
|
||||
template <typename T>
|
||||
inline utils::Matrix<T> equal_elementwise_serial(const 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("equal_elementwise_serial: Dimention misfit");
|
||||
}
|
||||
|
||||
utils::Matrix<T> C(rows, cols, T{0});
|
||||
|
||||
for (uint64_t i = 0; i < rows; ++i){
|
||||
for (uint64_t j = 0; j < cols; ++j){
|
||||
if (A(i,j) == B(i,j)){
|
||||
C(i,j) = T{1};
|
||||
}
|
||||
}
|
||||
}
|
||||
return C;
|
||||
}
|
||||
|
||||
// ---------------- Vector ----------------
|
||||
template <typename T>
|
||||
inline utils::Vector<T> equal_elementwise_serial(const utils::Vector<T>& v, const utils::Vector<T>& p) {
|
||||
const uint64_t N = v.size();
|
||||
if (N != p.size()){
|
||||
throw std::runtime_error("equal_elementwise_serial: Dimention misfit");
|
||||
}
|
||||
|
||||
utils::Vector<T> y(N, T{0});
|
||||
|
||||
for (uint64_t i = 0; i < N; ++i){
|
||||
if ((v[i] == p[i])){
|
||||
y[i] = T{1};
|
||||
}
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace numerics
|
||||
|
||||
|
||||
Reference in New Issue
Block a user