-
Notifications
You must be signed in to change notification settings - Fork 226
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
Unexpected instantiation of chi_squared_distribution
in C++17
#754
Comments
You want to:
? |
Yup, that's what I was thinking. I'd change |
Unfortunately we can't use |
Ah, I didn't know that. Thanks for the correction! I'll put together a PR for this (probably over the weekend). I'll also poke through other distributions to see if they're open to the same behavior. |
Looks like we need to be using deduction guides, with promotion of integer types to double, ie use There would be quite a bit of #if logic and general testing required I suspect :( |
OK, I don't really have the time to go through all of these right now, but this branch: https://github.com/boostorg/math/tree/issue754 demonstrates tests and changes required for the normal_distribution by way of an example. Diff: https://github.com/boostorg/math/compare/issue754 @NAThompson do we need this for all the integrators and possibly other stuff as well? |
You can see we have a static_assert in tanh_sinh:
and exp_sinh:
and gauss: math/include/boost/math/quadrature/gauss.hpp Line 1182 in a36f6a5
and Gauss-Kronrod:
I haven't gone through all of the integrators, but I expect a bit of effort. |
I like the deduction guide approach, but as @mborland notes in #755 it seems to require C++17 support. So do you guys want to go with As I'm not familiar with the guts of boost::math, I'm just trying to get a feel for what you guys would like. |
Is this even an issue prior to C++17 given that deduced class template arguments are a C++17 feature? OK, I guess someone could deliberately try to instantiate Just thinking out loud here.... |
Oh yeah, you're absolutely right: it's not an issue prior to C++17. Slickest solution is your deduction guide with the proper #if, and a static_assert for the silly case. I'll work on a PR this weekend. |
Looks like deduction guides are the way to go. Old versions of clang with SFINAE don't seem to work quite right. |
…ted on real type - issue boostorg#754
…g#754 [linux] [apple] [standalone] GCC-8 and clang 6-8 were unhappy with the no-arg cases, which use the default template arg, not the deduction guide, anyway.
…g#754 GCC-8 and clang 6-8 were unhappy with the no-arg cases, which use the default template arg, not the deduction guide, anyway.
* Demonstrate deduction guides for normal_distribution. * Add missing test case. * add class template argument deduction guides for distributions templated on real type - issue #754 * Remove no-arg tests in test_dist_deduction_guides.cpp - issue #754 GCC-8 and clang 6-8 were unhappy with the no-arg cases, which use the default template arg, not the deduction guide, anyway. * remove unused deduction guide for fisher_f - issue #754 Co-authored-by: jzmaddock <john@johnmaddock.co.uk>
The following is valid in C++17, AFAIK.
The above code produces the following unexpected output under GCC and clang with
-std=c++17
.In C++17, we may be able to omit the class template arguments (CTAD) in favor of allowing the compiler to deduce them.
chi_squared_distribution
is parameterized by aRealType
template argument, defaulting to adouble
.In the first case, where I don't explicitly provide the template argument, the compiler deduces the template parameter
RealType
to be anint
based on the argument passed to the ctor.I think it is unexpected/bad to allow instantiating a
chi_squared_distribution
with an integralRealType
.The ctor should happily accept an integral degrees of freedom, but the type used for the calculations shouldn't be integral.
Perhaps
chi_squared_distribution
could useenable_if
to check thatRealType
is_floating_point
?This would force the user to explicitly provide the class template argument in cases where CTAD chooses the "wrong" type.
I'd be happy to submit a PR. Is the proposed solution okay? Is there a better solution?
Additionally, there may be distributions other than
chi_squared_distribution
that are affected by the same pattern.os: Arch Linux, Linux 5.16.3
boost version: 1.78.0-1 (from Arch repo)
compiler: GCC 11.1.0, clang 13.0.0-4
The text was updated successfully, but these errors were encountered: