Skip to content

bugfix/issue 336 length 0 checks after consistency check - #1207

Merged
rok-cesnovar merged 9 commits into
stan-dev:developfrom
bstatcomp:bugfix/issue-336-length-0-checks
Apr 21, 2019
Merged

rok-cesnovar merged 9 commits into
stan-dev:developfrom
bstatcomp:bugfix/issue-336-length-0-checks

Conversation

@rok-cesnovar

Copy link
Copy Markdown
Member

Summary

Fixing an old issue #336. This PR does the following cleanup in lpmf and lpdf files:

  • !(length(a) && length(b)...) is replaced with size_zero(a,b,...)
  • size_zero checks are moved under the consistency checks to identify bugs more easily
  • T_lp lp(0.0);, T_partials_return logp(0.0); etc were moved to be allocated after the checks pass

Tests

No new tests.

Side Effects

/

Checklist

@bob-carpenter bob-carpenter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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)));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reverted.

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()));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same comment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reverted.

Comment thread stan/math/prim/scal/prob/beta_lpdf.hpp Outdated
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]));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same comment again. These can't be std:: here because the values might not be double.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reverted.

@rok-cesnovar

rok-cesnovar commented Apr 19, 2019 •

Copy link
Copy Markdown
Member Author

Yeah the std:: was a goof on my part. Will revert those changes.
EDIT: goof*

@rok-cesnovar

Copy link
Copy Markdown
Member Author

Thank you for the review. I reverted back the unnecessary uses of std::. Sorry about that. Changed return 0.0 to return 0. Ready for re-review.

@bob-carpenter

Copy link
Copy Markdown
Member

Thanks. This is ready to merge when the tests pass.

@rok-cesnovar

Copy link
Copy Markdown
Member Author

Thanks!

The upstream CmdStan tests, specifically Non-windows interface tests with MPI are stuck with the following error:

echo STAN_MPI=true
make build-mpi
Cannot contact gelman-group-linux: java.lang.InterruptedException

I tried restarting the tests but had no luck. @serban-nicusor-toptal is the person to tag for this right? Nothing urgent tho.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants