36 lines
864 B
C++
36 lines
864 B
C++
#pragma once
|
|
|
|
#include "./core/omp_config.h"
|
|
#include "./utils/matrix.h"
|
|
|
|
|
|
namespace utils{
|
|
|
|
template <typename To, typename From>
|
|
void inplace_matcast(const utils::Matrix<From>& A, utils::Matrix<To>& B) {
|
|
if ((A.rows() != B.rows()) || (A.cols() != B.cols())){
|
|
throw std::runtime_error("inplace_matcast: dimension mismatch");
|
|
}
|
|
const uint64_t rows = A.rows();
|
|
const uint64_t cols = A.cols();
|
|
|
|
for (uint64_t i = 0; i < rows; ++i){
|
|
for (uint64_t j = 0; j < cols; ++j){
|
|
B(i,j) = static_cast<To>(A(i,j));
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
template <typename To, typename From>
|
|
utils::Matrix<To> matcast(const utils::Matrix<From>& A) {
|
|
utils::Matrix<To> B(A.rows(), A.cols(), To{0});
|
|
|
|
inplace_matcast(A,B);
|
|
|
|
return B;
|
|
}
|
|
|
|
} // end namespace utils
|
|
|