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:
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "./core/omp_config.h"
|
||||
#include "./utils/matrix.h"
|
||||
#include "core/omp_config.h"
|
||||
#include "utils/matrix.h"
|
||||
|
||||
|
||||
namespace utils{
|
||||
|
||||
@@ -6,3 +6,4 @@
|
||||
#include "./utils/generators.h"
|
||||
#include "./utils/random.h"
|
||||
#include "./utils/matcast.h"
|
||||
#include "./utils/veccast.h"
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "core/omp_config.h"
|
||||
#include "utils/matrix.h"
|
||||
|
||||
|
||||
namespace utils{
|
||||
|
||||
template <typename To, typename From>
|
||||
void inplace_veccast(const utils::Vector<From>& a, utils::Vector<To>& b) {
|
||||
if (a.size() != b.size()){
|
||||
throw std::runtime_error("inplace_veccast: dimension mismatch");
|
||||
}
|
||||
|
||||
uint64_t n = a.size();
|
||||
|
||||
for (uint64_t i = 0; i < n; ++i){
|
||||
b[i] = static_cast<To>(a[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename To, typename From>
|
||||
utils::Vector<To> veccast(const utils::Vector<From>& a) {
|
||||
utils::Vector<To> b(a.size(), To{0});
|
||||
|
||||
inplace_veccast(a,b);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
} // end namespace utils
|
||||
|
||||
Reference in New Issue
Block a user