Skip to content
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

issue 1010 - Replacing Boost functions with cmath (Part 2 - error checking) #1080

Merged
merged 4 commits into from
Jan 31, 2019
Merged

issue 1010 - Replacing Boost functions with cmath (Part 2 - error checking) #1080

merged 4 commits into from
Jan 31, 2019

Conversation

andrjohns
Copy link
Collaborator

Summary

Addresses part 2 of issue #1010, replacing boost::math:: functions that need input checking and platform-specific return handling

The following functions have been replaced:

  • acosh
  • atanh
  • lgamma
  • log1p
  • tgamma

Tests

Only major change is that lgamma(0) now expects an inf return rather than nan

Side Effects

N/A

Checklist

return x;
} else {
check_greater_or_equal("acosh", "x", x, 1);
#ifdef _WIN32
Copy link
Member

Choose a reason for hiding this comment

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

Do you remember what this was about? Why do we need this ifdef?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep. acosh(inf) is expected to return inf, but under windows acosh(inf) returns nan. More background here: #1067 (comment)

Copy link
Member

@syclik syclik left a comment

Choose a reason for hiding this comment

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

Thank you! I only had one question... it looked like lgamma was the only one with a change at 0. Is that right? I think lgamma(0) should return inf.

Thinking about it, I don't think there's going to be a problem by changing it from nan to inf. It'll break both ways.

@@ -11,5 +11,5 @@ TEST(MathFunctions, lgammaStanMathUsing) { using stan::math::lgamma; }
TEST(MathFunctions, lgamma_nan) {
double nan = std::numeric_limits<double>::quiet_NaN();
EXPECT_PRED1(boost::math::isnan<double>, stan::math::lgamma(nan));
EXPECT_PRED1(boost::math::isnan<double>, stan::math::lgamma(0));
EXPECT_PRED1(boost::math::isinf<double>, stan::math::lgamma(0));
Copy link
Member

Choose a reason for hiding this comment

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

Was this the only change in behavior? I didn't see anything else.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, lgamma(0) was the only change in behaviour, everything else remains the same

@seantalts
Copy link
Member

@syclik is this good to go? We could use it to fix #1063 which will let us start getting Math PRs through again while we don't have any EC2 nodes (spot pricing went way up).

@syclik
Copy link
Member

syclik commented Jan 31, 2019

@seantalts, thanks for the bump! I missed @andrjohns's response (thanks!!!).

Merging.

@syclik syclik merged commit d1667a4 into stan-dev:develop Jan 31, 2019
@seantalts
Copy link
Member

I'm digging into why this didn't fix #1063 and just came across a comment there that std::lgamma isn't thread-safe? Is that right? I see a note that the POSIX implementation of lgamma isn't thread-safe, but I can't tell if the C++ std::lgamma is using the POSIX implementation of lgamma under the hood or not.

@wds15
Copy link
Contributor

wds15 commented Jan 31, 2019

uh... thread safety would be very good (if not required) to have...

@seantalts
Copy link
Member

Agreed. @bob-carpenter, I think it was you who originally wrote that lgamma wasn't thread safe - can you confirm that that's true of the one in this PR (std::lgamma)? We may need to switch back to the boost one

@bob-carpenter
Copy link
Contributor

bob-carpenter commented Feb 1, 2019 via email

@bob-carpenter
Copy link
Contributor

See: https://en.cppreference.com/w/cpp/numeric/math/lgamma

It says:

The POSIX version of lgamma is not thread-safe: each execution of the function stores the sign of the gamma function of arg in the static external variable signgam. Some implementations provide lgamma_r, which takes a pointer to user-provided storage for singgam as the second parameter, and is thread-safe.

@bgoodri
Copy link
Contributor

bgoodri commented Feb 2, 2019 via email

@bob-carpenter
Copy link
Contributor

bob-carpenter commented Feb 2, 2019 via email

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.

8 participants