64 lines
1.3 KiB
C++
64 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include "./core/omp_config.h"
|
|
|
|
#include "./utils/matrix.h"
|
|
#include "./utils/vector.h"
|
|
|
|
|
|
namespace numerics{
|
|
|
|
|
|
template <typename T>
|
|
utils::Vector<T> matdot_row(const utils::Matrix<T>& A, const utils::Matrix<T>& B){
|
|
|
|
if (A.rows() != B.rows() || A.cols() != B.cols()){
|
|
throw std::runtime_error("matmul: dimension mismatch");
|
|
}
|
|
|
|
const uint64_t rows = A.rows();
|
|
const uint64_t cols = A.cols();
|
|
|
|
|
|
utils::Vector<T> c(rows, T{0});
|
|
|
|
for (uint64_t i = 0; i < rows; ++i){
|
|
T sum = T{0};
|
|
for (uint64_t j = 0; j < cols; ++j){
|
|
sum += A(i,j) * A(i,j);
|
|
}
|
|
c[i] = sum;
|
|
}
|
|
return c;
|
|
}
|
|
|
|
template <typename T>
|
|
utils::Vector<T> matdot_col(const utils::Matrix<T>& A, const utils::Matrix<T>& B){
|
|
|
|
if (A.rows() != B.rows() || A.cols() != B.cols()){
|
|
throw std::runtime_error("matmul: dimension mismatch");
|
|
}
|
|
|
|
const uint64_t rows = A.rows();
|
|
const uint64_t cols = A.cols();
|
|
|
|
|
|
utils::Vector<T> c(cols, T{0});
|
|
|
|
for (uint64_t j = 0; j < cols; ++j){
|
|
T sum = T{0};
|
|
for (uint64_t i = 0; i < rows; ++i){
|
|
sum += A(i,j) * A(i,j);
|
|
}
|
|
c[j] = sum;
|
|
}
|
|
return c;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace numerics
|
|
|