-
-
Notifications
You must be signed in to change notification settings - Fork 93
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
Large values in data are not passed properly to Stan #1023
Comments
Wow, that's super weird! But this is actually a Stan (or CmdStan) issue and not an issue with CmdStanR passing the wrong value. I verified that the JSON file passed to CmdStan is correct and I also ran CmdStan itself (not via CmdStanR) and the same problem occurs. I'll transfer the issue to the CmdStan repo. |
I just transferred this issue from CmdStanR to CmdStan because I verified that the same problem happens when using CmdStan directly without CmdStanR. But I'm not sure if this is a CmdStan bug or if it should be moved to |
perhaps it's an I/O error. is the input data for CmdStan in rdump or JSON format? |
The example provided by Martin uses CmdStanR so it was using JSON I/O (and I verified the JSON file was written correctly and also that the same problem occurs without CmdStanR just using CmdStan).
This happens on my Mac and Martin's Windows computer so it doesn't seem to be related to the OS. |
OK then, will investigate. |
Thanks for looking into this so quickly and for the additional verification! |
The problem is that 3e9 is written in JSON or R dump as 3000000000 and that is parsed as an integer. If I place
in a .data.R I get an error that its beyond int range.
gets parsed as an integer and then seems to get converted to a double in some bizarre way. This however works fine
|
Any idea why it's a problem with 3e9 but doesn't seem to be a problem with 3e8? |
I am guessing it has to do with the fact that 3e8 can be represented as an integer, but 3e9 can not be. |
Are the values as read by the JSON parser already incorrect? |
It looks like RapidJSON supports JSON schema. |
Yeah, the logic is supposed to be that the parser first attempts parsing a number without a decimal point as an integer and once it recognizes the number is too big it parses its as a double. That seems to not be working as expected. I havent had the time to look into that. Will do ASAP.
That is doable as we can get info on types on data variables from stanc3. I would avoid this for now but we can start to think about it if there is no solution for the above. |
I've looked into the values that generate problems in my case. {"qData": [2245935000, 2418300000] } But it looks like at least rapidjson master parses them well (as Uint on my machine). But then in cmdstan I get |
adding a check that the sign is as expected would catch this problem, no? |
For me it looks like the cause of the error is at json_data_handler.hpp#L228 when unsigned is converted to signed. For the numbers from the example above this leads to the flip of the sign. |
Integers in Stan are always signed. I guess we should not let rapidjson parse them to uint as uint is useless for the Stan use case. |
IIUC the rapidjson code, it's not possible to change which handler would be called. |
Describe the bug
When putting very large numbers (roughly around 1e9) into data, wrong walues may get passed to stan.
To Reproduce
Expected behavior
Print 3e9 in the second case
Operating system
Windows 10
CmdStanR version number
0.4.0.9000 (just installed from GitHub)
The text was updated successfully, but these errors were encountered: