almost complete. Need to doublecheck names for functions in *_serial.h
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint> //uint64_t
|
||||
#include <stdexcept> // std::runtime_error
|
||||
|
||||
#include "../utils/vector.h"
|
||||
#include "../utils/matrix.h"
|
||||
|
||||
namespace numerics::detail{
|
||||
|
||||
// ---------------- Matrix * Matrix ----------------
|
||||
template <typename T>
|
||||
inline utils::Matrix<T> matmul_serial(const utils::Matrix<T>& A, const utils::Matrix<T>& B){
|
||||
const uint64_t m = A.rows();
|
||||
const uint64_t n = A.cols(); // also B.rows()
|
||||
const uint64_t p = B.cols();
|
||||
if(n != B.rows()){
|
||||
throw std::runtime_error("matmul: dimension mismatch");
|
||||
}
|
||||
T tmp;
|
||||
utils::Matrix<T> C(m, p, T{0});
|
||||
for (uint64_t i = 0; i < m; ++i){
|
||||
for (uint64_t j = 0; j < n; ++j){
|
||||
tmp = A(i,j);
|
||||
for (uint64_t k = 0; k < p; ++k){
|
||||
C(i,k) += tmp * B(j,k);
|
||||
}
|
||||
}
|
||||
}
|
||||
return C;
|
||||
}
|
||||
|
||||
|
||||
} // namespace numerics
|
||||
|
||||
Reference in New Issue
Block a user