Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/3161 parse tuples json #3165

Merged
merged 72 commits into from
Mar 7, 2023
Merged

Conversation

mitzimorris
Copy link
Member

Submission Checklist

  • Run unit tests: ./runTests.py src/test/unit
  • Run cpplint: make cpplint
  • Declare copyright holder and open-source license: see below

Summary

Updates json parser and data handler to allow tuples, including tuples of tuples, arrays of tuples, tuples of arrays of tuples, etc.

Intended Effect

Allow users to supply init files of JSON data corresponding to Stan program tuple variables.

How to Verify

Unit tests.

Side Effects

Parser allows nested objects.

Documentation

N/A

Copyright and Licensing

Please list the copyright holder for the work you are submitting (this will be you or your assignee, such as a university or company): Columbia University

By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses:

@mitzimorris
Copy link
Member Author

re-review?

@mitzimorris
Copy link
Member Author

I broke the unit tests for ill-formed JSON which the handler should detect and report into from file "json_data_test.cpp" into a new test file, "ill_formed_json_test.cpp", and then added more tests for redefining tuple and array of tuple vars.

Copy link
Member

@WardBrian WardBrian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest changes seemed to have introduced a regression, which suggests a new case to test against! (tuple-of-array-of-tuple seems to not trigger the array-of-tuple logic)

And a few more concrete failure tests I'd like to see

src/stan/io/json/json_data_handler.hpp Outdated Show resolved Hide resolved
@mitzimorris
Copy link
Member Author

Added logic to ignore top-level entries with names that aren't legal Stan varnames and corresponding unit tests.
Ready for re-review.

Copy link
Member

@WardBrian WardBrian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the work on this! I think it's ready to merge

Comment on lines +5 to +6
"_x_desc_" : "array of tuples",
"_x_def_" : "array[2] (array[3] real, array[2, 2] real, real) x;",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Comment] I think this is very nice that we can have this kind of thing now


"_legal.JSON" : ["but invalid.stanvar", "-inf", [2.2, 3.3]],
"_also" : "the following",
"x.2" : [ {"1": 0, "2": 1}, {"1": 1}]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Comment] This is probably a problem for the documentation later, but part of me does worry someone will try to write something like this and it will be silently ignored.
Making it always issue a warning is too much (and I don't think we have an ostream laying around to push warnings to), so I don't think we should do anything, just wanted to flag it as a concern

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants