Sync public subset from Flux
This commit is contained in:
63
include/numerics/matdot.h
Normal file
63
include/numerics/matdot.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#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
|
||||
|
||||
Reference in New Issue
Block a user