Skip to content

Commit

Permalink
add logic for json
Browse files Browse the repository at this point in the history
  • Loading branch information
Huangzizhou committed Nov 28, 2023
1 parent 0ed9d59 commit edbd473
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/polysolve/JSONUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ namespace nlohmann

if (j.is_number())
{
matrix.resize(1, 1);
matrix.resize((nrows == -1) ? 1 : nrows, (ncols == -1) ? 1 : ncols);
matrix(0, 0) = j.get<Scalar>();
}
else if (j.is_array())
{
if (j.size() == 0) // empty array
matrix.resize(0, 0);
matrix.setZero(std::max(0, nrows), std::max(0, ncols));
else if (j.at(0).is_number()) // 1D array
{
assert(nrows == -1 || ncols == -1); // at least one dimension can be resized
Expand Down
6 changes: 5 additions & 1 deletion tests/test_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ TEST_CASE("json_to_eigen", "[json]")
REQUIRE(c.cols() == 2);

// empty json array
a = input[4];
REQUIRE(a.size() == 0);
b = input[4];
REQUIRE(b.size() == 0);
c = input[4];
REQUIRE(c.size() == 0);

// single number
c = input[5];
REQUIRE(c(0) == 1);
Expand Down

0 comments on commit edbd473

Please sign in to comment.