Skip to content

Manual type promotion for arcsine distribution#1373

Open
JacobHass8 wants to merge 6 commits intoboostorg:developfrom
JacobHass8:dist-maintenance
Open

Manual type promotion for arcsine distribution#1373
JacobHass8 wants to merge 6 commits intoboostorg:developfrom
JacobHass8:dist-maintenance

Conversation

@JacobHass8
Copy link
Contributor

This tries to rewrite #1299 in a more human readable way. See #1294 for the same issue with the logistic distribution.

@JacobHass8
Copy link
Contributor Author

@mborland what do you think of this version? I made a number of actual changes to the code that I'd like to get your opinion on. I left comments below.

On an unrelated note, I wasn't able to get b2 to run test_arcsine. I was getting more errors than I could count. Is it set up to run or is it skipped for some reason?

Comment on lines +210 to +217
if (x == x_min)
{
return 1;
}
else if (x == x_max)
{
return 0;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These special cases used to be swapped (e.g. when x == x_min we returned 0). Is this because the input to ccdf is actually the complement of x? I was very confused reading this right below the definition of cdf.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe so yes, but this doesn't look right to me, and will surely only work for x_min, x_max = [0,1] ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, since we're using acos then x really is the complement 1-x (when arcsine is defined on [0,1]). In this case, I think what I have written is correct. When x==x_min, the ccdf becomes 2/pi acos(0)=1.

Why do you say this should only work for x_min, x_max = [0,1]?

Copy link
Collaborator

Choose a reason for hiding this comment

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

When dealing with the complement, isn't the range (of the complement that is, and we really should have named the variable something other than x in the code) now [1 - x_max, 1 - x_min] ? Sorry, it's late here, and my brain is frazzled after a long week... so I might be talking rubbish ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I think since x is defined on [x_min, x_max] then the complement is also defined on [x_min, x_max].

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmmm, if x is in [1,2] then 1-x must be in [-1,0] surely?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but why does the complement of x have to be 1-x? Isn't the complement something like 3-x? This maps x=2 to 1 and x=1 to 2.

result = -3;
return result / 2;
typedef policies::evaluation_t<RealType, Policy> policy_promoted_type;
return static_cast<RealType>(static_cast<policy_promoted_type>(-3) / static_cast<policy_promoted_type>(2));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can't -1.5 be expressed exactly in binary? If so, then we don't have to go through all this type promotion.

Copy link
Member

Choose a reason for hiding this comment

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

You should be able to. You could also make this:

static const auto return_val {static_cast<RealType>(static_cast<policy_promoted_type>(-3) / static_cast<policy_promoted_type>(2))};
return return_val;

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, and decimal too ;) So I'd say we're covered.

Copy link
Contributor Author

@JacobHass8 JacobHass8 Mar 6, 2026

Choose a reason for hiding this comment

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

Wait, so should I replace it with

static const auto return_val {static_cast<RealType>(static_cast<policy_promoted_type>(-3) / static_cast<policy_promoted_type>(2))};
return return_val;

or just

return -1.5

@mborland
Copy link
Member

mborland commented Mar 6, 2026

On an unrelated note, I wasn't able to get b2 to run test_arcsine. I was getting more errors than I could count. Is it set up to run or is it skipped for some reason?

It is setup to run, and I just tried it on head and the test ran fine. What's the issue? You can try pch=off if you're getting a bunch of errors propagating from the usage of pre-compiled headers.

@mborland
Copy link
Member

mborland commented Mar 6, 2026

I do think this approach looks better. Thanks!

@codecov
Copy link

codecov bot commented Mar 7, 2026

Codecov Report

❌ Patch coverage is 85.48387% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.33%. Comparing base (e6fb7d3) to head (5e75917).

Files with missing lines Patch % Lines
include/boost/math/distributions/arcsine.hpp 85.48% 9 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1373      +/-   ##
===========================================
- Coverage    95.34%   95.33%   -0.01%     
===========================================
  Files          825      825              
  Lines        68160    68167       +7     
===========================================
+ Hits         64986    64989       +3     
- Misses        3174     3178       +4     
Files with missing lines Coverage Δ
include/boost/math/policies/policy.hpp 95.83% <ø> (ø)
include/boost/math/distributions/arcsine.hpp 91.66% <85.48%> (+0.33%) ⬆️

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e6fb7d3...5e75917. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JacobHass8
Copy link
Contributor Author

On an unrelated note, I wasn't able to get b2 to run test_arcsine. I was getting more errors than I could count. Is it set up to run or is it skipped for some reason?

It is setup to run, and I just tried it on head and the test ran fine. What's the issue? You can try pch=off if you're getting a bunch of errors propagating from the usage of pre-compiled headers.

There were just a ton of errors in my code. I missed a couple of closing brackets which caused a large amount of errors.

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.

3 participants