-
-
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
Generate Quantities segfaults for zero-length parameter array #990
Comments
thanks for the clear and detailed report. sounds like a bug. will investigate. |
@mitzimorris, confirmed this is a bug. I tracked it down and it needs to be fixed in the stan-dev/stan repo. I'll come up with a minimal example and show what's going on. I think one way to solve it is to introduce a function that's generated by stanc3, but there may be other ways to address the problem. |
standalone GQ currently only checks that the total number of parameter in the model matches the total number of parameters in the supplied fitted_params file. not sure what it would do if you have two container parameters with dimensions controlled by data inputs, e.g., variables I, J, K, which specify vector lengths, and fitted_params was the result of parameters fitted to data where I=4, J=5, K=6, and the supplied model data was I=3, J=4, K=8. conclusion: standalone GQ shoudl check on parameter dimensions as well. parameter dimensions on the input can be parsed out of the header. if the Stanc3 compiler can add a function that reports the parameter dimensions on the instatiated model, this would allow for better and more robust input handling. |
This was resolved by stan-dev/stan#3179 |
Summary:
generate_quantities
throws a segfault when the model includes zero-length parameter arrays.Description:
I've seen an idiom suggested in the Stan forums for including optional parameters in Stan models, where the optional parameter is sized as an array of length 0 or 1 depending on whether it is to be included. This idiom works very well for sampling, but CmdStan segfaults whenever
generate_quantities
is run on a model with a zero-length parameter.Reproducible Steps:
The following is a small reproducible example of the issue. There are a few obvious ways this Stan program could be rewritten to avoid this issue, but there are other cases where the rewrite is quite a bit less obvious.
Sample program (
opt-param.stan
):Sample data (
opt-data.json
):Reproducible steps:
Current Output:
The last command above yields a runtime error:
[1] 91352 segmentation fault ./opt-param generate_quantities fitted_params=opt-fit.csv data output
Expected Output:
I expected the generated quantities to be output as usual. In the example above, everything works perfectly if
use_intercept
is set to1
in the data file.Additional Information:
I'm running macOS 10.15.7.
Current Version:
v2.26.1
The text was updated successfully, but these errors were encountered: