Skip to content
Snippets Groups Projects
Commit 75f48084 authored by Fabian Paus's avatar Fabian Paus
Browse files

Suport compact Eigen::Vector JSON representation

parent 449b9519
No related branches found
No related tags found
No related merge requests found
......@@ -88,12 +88,19 @@ namespace jsonbase
{
for (int row = 0; row < matrix.rows(); ++row)
{
nlohmann::json jrow = nlohmann::json::array();
for (int col = 0; col < matrix.cols(); ++col)
if (matrix.cols() > 1)
{
jrow.push_back(matrix(row, col));
nlohmann::json jrow = nlohmann::json::array();
for (int col = 0; col < matrix.cols(); ++col)
{
jrow.push_back(matrix(row, col));
}
j.push_back(jrow);
}
else
{
j.push_back(matrix(row, 0));
}
j.push_back(jrow);
}
}
......@@ -107,10 +114,17 @@ namespace jsonbase
for (std::size_t row = 0; row < j.size(); ++row)
{
const auto& jrow = j.at(row);
for (std::size_t col = 0; col < jrow.size(); ++col)
if (jrow.is_array())
{
for (std::size_t col = 0; col < jrow.size(); ++col)
{
const auto& value = jrow.at(col);
matrix(static_cast<Index>(row), static_cast<Index>(col)) = value.get<Scalar>();
}
}
else
{
const auto& value = jrow.at(col);
matrix(static_cast<Index>(row), static_cast<Index>(col)) = value.get<Scalar>();
matrix(static_cast<Index>(row), 0) = jrow.get<Scalar>();
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment