NNFS p.135
Sync public mirror / sync (push) Successful in 37s

Started on the iteration, not need to rewrite matadd.h and need to make matrandom.h.
This commit is contained in:
2025-10-07 19:06:33 +02:00
parent 66b3a4ee6b
commit c164d790db
14 changed files with 366 additions and 157 deletions
+38
View File
@@ -22,6 +22,44 @@ namespace numerics{
return mean;
}
template <typename T>
T vecmean_isequal(utils::Vector<T>& a, utils::Vector<T>& b, T tol=1e-12) {
uint64_t count = T{0};
const uint64_t N = a.size();
if (a.size() != b.size()){
throw std::runtime_error("vecmean_equal: dimension mismatch");
}
for (uint64_t i = 0; i < N; ++i) {
if ((a[i]-b[i]) < tol){
count += 1;
}
}
return static_cast<T>(count)/static_cast<T>(N);
}
template <typename Td, typename Ti>
Td vecmean_equal(utils::Vector<Ti>& a, utils::Vector<Ti>& b) {
Ti count = Ti{0};
const uint64_t N = a.size();
if (a.size() != b.size()){
throw std::runtime_error("vecmean_equal: dimension mismatch");
}
for (uint64_t i = 0; i < N; ++i) {
if (a[i]==b[i]){
count += Ti{1};
}
}
return static_cast<Td>(count)/static_cast<Td>(N);
}
} // namespace numerics