Refactor eigenMatrix_to_vector function to handle both row-major and column-major matrices
This commit is contained in:
parent
2f8ec213c8
commit
5be331b863
18
src/run.cpp
18
src/run.cpp
@ -20,6 +20,21 @@ using TugType = double;
|
||||
using RowMajorMat =
|
||||
Eigen::Matrix<TugType, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
|
||||
|
||||
static inline std::vector<TugType>
|
||||
eigenMatrix_to_vector(const Eigen::MatrixX<TugType> &mat) {
|
||||
if (mat.IsRowMajor) {
|
||||
return std::vector<TugType>(mat.data(), mat.data() + mat.size());
|
||||
} else {
|
||||
std::vector<TugType> out_vec(mat.size());
|
||||
for (int i = 0; i < mat.rows(); i++) {
|
||||
for (int j = 0; j < mat.cols(); j++) {
|
||||
out_vec[i * mat.cols() + j] = mat(i, j);
|
||||
}
|
||||
}
|
||||
return out_vec;
|
||||
}
|
||||
}
|
||||
|
||||
double run_bench(const bench_input &input, const std::string &output_file) {
|
||||
std::vector<std::vector<double>> raw_data =
|
||||
read_conc_csv<double>(input.csv_file, input.ncols, input.nrows);
|
||||
@ -77,8 +92,7 @@ double run_bench(const bench_input &input, const std::string &output_file) {
|
||||
|
||||
const auto &result = grid.getConcentrations();
|
||||
|
||||
raw_data[i] =
|
||||
std::vector<TugType>(result.data(), result.data() + result.size());
|
||||
raw_data[i] = eigenMatrix_to_vector(result);
|
||||
}
|
||||
|
||||
const auto end_t = std::chrono::high_resolution_clock::now();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user