-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Better error messages for incomplete probability calls #1021
Better error messages for incomplete probability calls #1021
Conversation
Isn't that what happens also if you use 3 non-existent functions? Won't it only error for the first one? |
Definitely! Just wanted to ask what would be a good way to test, in light of this (since I can't throw all the different cases in one large file) :-) |
I guess a few short test files, each with a faulty signature in a subfolder should be fine. |
A question on which I don't have an answer to, is if we envision a case where one of the non-lpdf/lpmf suffixed functions is implemented, but we don't have an lpdf/lpmf function implementation. So, things like there is a foo_rng but no foo_lpdf. We don't right now and that would probably be bad anyway, so I don't think we need to handle it. Just thinking out loud. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outside of the error message, for which I would like someone else's input, this all looks good.
That would be very bad, I agree. It would also impact twiddle statements. I think it's worth special-casing |
Oh nice, yeah. That would also be great, also include lupdf vs lupmf if we add that. |
Our of curiosity, what happens if there’s a user defined function Also, I think the original issue suggested listing the suffixes which are available, do we still want that? |
Oh and one more thing before I forget: stanc3/src/middle/Stan_math_signatures.ml Lines 222 to 223 in b0f2bd3
However, note that the above suggest categorical_rng does not exist but it is actually added laterstanc3/src/middle/Stan_math_signatures.ml Lines 977 to 983 in b0f2bd3
where we also have categorical_logit_glm which is completely absent in distributions .
Many more distribution functions are scattered around the file. These should all be consolidated in the |
For: functions {
real bar_lpdf(real x) {
return(x);
}
}
model {
target += bar_lcdf(1|0,1);
} I get:
Another option would be to add a link to the functions-reference docs (I personally like compiler errors that do that), but I'd be happy to add whatever people think is right. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be very nice for users I think. A few comments, and there are a few tests I'd like added:
user_defined:
functions {
real bar_lpdf(real x){
return 1.0;
}
}
model {
target += bar_lpmf(19.2);
}
user_defined_no_rng
functions {
real bar_lpdf(real x){
return 1.0;
}
}
generated quantities {
real x = bar_rng(10);
}
(also, if there are any builtin distributions without RNG's we should test one. Not sure)
user_defined_no_cdf:
functions {
real bar_lpdf(real x){
return 1.0;
}
}
model{
target += bar_lcdf(1|0,1);
}
and something that tests the older/deprecated _cdf_log/_ccdf_log, like
model {
target += von_mises_ccdf_log(1, 0,1);
}
These currently output a variety of things, and we should discuss what we want them to say
test/integration/bad/missing_dist_suffix/non_existing_distribution_suffix4.stan
Outdated
Show resolved
Hide resolved
Here's a test case for a distribution w/o rng suffix: generated quantities {
real x = multi_gp_cholesky_rng([[0,0],[0,0]], [1,0]);
} |
Partially because of @nhuurre's comment above and partially because of the output for user-defined functions, I wonder if we just shouldn't test if the function is a 'known' distribution family if it has a known suffix? It would mean userdefined functions would also get the output, but maybe that's good? |
From the original issue
It would be confusing the other way too, if a legit typo gets reported as unimplemented functionality. |
Good point. I do wonder if the user-defined family should be handled though, like if someone defines bar_lpdf should we give this error when they try to use bar_lcdf? |
…tion_suffix4.stan Co-authored-by: Brian Ward <[email protected]>
@WardBrian added the tests you've requested, I think the behaviour is expected but would appreciate an extra look at this. |
#995 is in, which hopefully lets you handle the suffixes a bit nicer. Looking at the tests now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks much cleaner now! I think there is one remaining issue we should fix before merging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @adamhaber !
Fixes #987 .
Not sure what would be the best way to test this. I've built and ran stanc on
and I'm getting the right error message but only on the first line.
Submission Checklist
Release notes
Improved error messages for incomplete probability library calls.
Copyright and Licensing
By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the BSD 3-clause license (https://opensource.org/licenses/BSD-3-Clause)