Repository navigation
bugfix/issue 336 length 0 checks after consistency check - #1207
Conversation
…gs/RELEASE_500/final)
bob-carpenter
left a comment
There was a problem hiding this comment.
My main comment is that the std:: qualifiers on a lot of the functions will be too restrictive if we wan to apply these for higher order autodiff types. I think instead they need a using std::??? in each scope for all the standard lib functions being used.
| if (!include_summand<propto, T_x, T_alpha, T_beta>::value) | ||
| return 0.0; | ||
|
|
||
| T_partials_return logp(0.0); |
There was a problem hiding this comment.
This is great you moved this up. All these 0.0 can be 0, but that's mostly cosmetic because the compiler will deal with the type.
There was a problem hiding this comment.
Changed all the 0.0 to 0 in the touched files.
|
|
||
| if (y.cols() == 0 || y.rows() == 0) | ||
| T_lp lp(0.0); | ||
| if (size_zero(y)) |
There was a problem hiding this comment.
In the last function, these just returned 0 (which will get promoted) and the lp variable was defined later. I liked it the way it was in the last function, but either way, it should probably be consistent.
There was a problem hiding this comment.
Agreed, fixed to return 0 and define lp later.
| .select(theta + log1p(exp(log_phi - theta)), | ||
| log_phi + log1p(exp(theta - log_phi))); | ||
| .select(theta + Eigen::log1p(Eigen::exp(log_phi - theta)), | ||
| log_phi + Eigen::log1p(Eigen::exp(theta - log_phi))); |
There was a problem hiding this comment.
With all the autos, I can't tell the types here, but if these are autodiff types, we want to be applying our own functions rather than Eigen's.
Are these select functions performant with the comparison?
And why roll your own log-sum-exp this way? Can't you just use the vectorized one?
|
|
||
| Matrix<T_partials_return, Dynamic, 1> theta_derivative | ||
| = as_array_or_scalar(y_val_vec) - exp(theta.array()); | ||
| = as_array_or_scalar(y_val_vec) - std::exp(theta.array()); |
There was a problem hiding this comment.
std:: is inappropriate if this is anything other than double arguments . So either T_partials_return has to be double, or there hsouldn't be a std:: here. You may need a using std::exp in scope, though.
| if (include_summand<propto, T_partials_return>::value) { | ||
| logp += sum(as_array_or_scalar(y_val_vec) * theta.array() | ||
| - exp(theta.array())); | ||
| - std::exp(theta.array())); |
| for (size_t n = 0; n < length(y); n++) { | ||
| if (include_summand<propto, T_y, T_scale_succ>::value) | ||
| log_y[n] = log(value_of(y_vec[n])); | ||
| log_y[n] = std::log(value_of(y_vec[n])); |
There was a problem hiding this comment.
Same comment again. These can't be std:: here because the values might not be double.
|
Yeah the std:: was a goof on my part. Will revert those changes. |
|
Thank you for the review. I reverted back the unnecessary uses of |
|
Thanks. This is ready to merge when the tests pass. |
|
Thanks! The upstream CmdStan tests, specifically Non-windows interface tests with MPI are stuck with the following error: I tried restarting the tests but had no luck. @serban-nicusor-toptal is the person to tag for this right? Nothing urgent tho. |
Summary
Fixing an old issue #336. This PR does the following cleanup in lpmf and lpdf files:
!(length(a) && length(b)...)is replaced withsize_zero(a,b,...)size_zerochecks are moved under the consistency checks to identify bugs more easilyT_lp lp(0.0);,T_partials_return logp(0.0);etc were moved to be allocated after the checks passTests
No new tests.
Side Effects
/
Checklist
Math issue Length 0 checks should come after checking for mismatched sizes #336
Copyright holder: Rok Češnovar, Univ. of Ljubljana
the basic tests are passing
the code is written in idiomatic C++ and changes are documented in the doxygen
[] the new changes are tested