Started Loss, done softmax, up to p.125
I've implemented alot of support functions that needs to be refactored, optimised and tested; mean.h, exponential.h, matdiv.h matsum.h matsubtract.h. Maybe we need to have a look at if matdiv/matmul should be in the same. Same with matadd/matsubtract and if some of it should be in matvec.h.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
#ifndef _matdiv_n_
|
||||
#define _matdiv_n_
|
||||
|
||||
|
||||
#include "./utils/matrix.h"
|
||||
#include "./core/omp_config.h"
|
||||
|
||||
|
||||
namespace numerics{
|
||||
|
||||
// ---------------- Serial baseline ----------------
|
||||
template <typename T>
|
||||
utils::Matrix<T> matdiv(const utils::Matrix<T>& A, const utils::Vector<T>& b, std::string method){
|
||||
|
||||
utils::Matrix<T> C = A;
|
||||
|
||||
if (method == "row"){
|
||||
for (uint64_t i = 0; i < A.rows(); ++i){
|
||||
for (uint64_t j = 0; j < A.cols(); ++j){
|
||||
C(i,j) /= b[j];
|
||||
}
|
||||
}
|
||||
}else if (method == "col"){
|
||||
for (uint64_t i = 0; i < A.rows(); ++i){
|
||||
for (uint64_t j = 0; j < A.cols(); ++j){
|
||||
C(i,j) /= b[i];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
throw std::runtime_error("matdiv: choose div by: 'row' or 'col'");
|
||||
}
|
||||
return C;
|
||||
}
|
||||
|
||||
|
||||
} // namespace numerics
|
||||
|
||||
#endif // _matdiv_n_
|
||||
Reference in New Issue
Block a user