-
-
Notifications
You must be signed in to change notification settings - Fork 190
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
Add Hypergeometric 1F0 function and gradients #2962
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requesting changes to the types for readability. Please don't overuse auto
. It makes it hard to understand what's going on with the code.
* @return Hypergeometric 1F0 function | ||
*/ | ||
template <typename Ta, typename Tz, require_all_arithmetic_t<Ta, Tz>* = nullptr> | ||
auto hypergeometric_1f0(const Ta& a, const Tz& z) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use proper return type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the type assumptions being made, is Ta
and Tz
just double
and double
only?
If I'm reading this properly, this isn't vectorized or anything, is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to allow all combinations of int
/double
(as well as size_t
,float
, etc.)
Thanks @syclik! Updated to more explicit typing for readability |
Thank you!!! |
* @return Hypergeometric 1F0 function | ||
*/ | ||
template <typename Ta, typename Tz, require_all_arithmetic_t<Ta, Tz>* = nullptr> | ||
double hypergeometric_1f0(const Ta& a, const Tz& z) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the (double, double) -> double
full template specification? (sorry... notation is tough: Ta = double
, Tz = double
)
If so, this implementation doesn't make sense as the function template for hypergeomtric_1f0
and we should probably implement this as a normal function. What do you think?
Based on the other implementations, we're not actually taking the route of defining the function template in prim
and writing template specialization in each of the folders. We're using SFINAE to knock out template matches instead. So I think that means we don't have a single function template any more.
Am I thinking about this correctly? Thoughts?
(My concrete suggestion: change this function to not have any template parameters.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This templating is to implement the signatures:
(int, int) -> double
(int, double) -> double
(double, int) -> double
(double, double) -> double
So removing the template parameters would mean replacing this function definition with four definitions, which seems a little much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is the base template, I'd suggest having the return type be return_type<Ta, Tz>
instead of double
. I'll add the code suggestion right now.
The reason for that is the base template should be a catch-all for everything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double hypergeometric_1f0(const Ta& a, const Tz& z) { | |
return_type<Ta, Tz> hypergeometric_1f0(const Ta& a, const Tz& z) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something feels slightly off: the base template has 3 template parameters, but the specializations have 4? Was that intended? (Did I miss the actual base template declaration somewhere?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something feels slightly off: the base template has 3 template parameters, but the specializations have 4? Was that intended? (Did I miss the actual base template declaration somewhere?)
Sorry you've lost me, all of the implementations here only have two parameters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you counting the require_*
elements here? The number of those don't have to be consistent between the implementations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@syclik small ping
@syclik small ping to have a look at the review responses here |
Jenkins Console Log Machine informationNo LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focalCPU: G++: Clang: |
Co-authored-by: Daniel Lee <[email protected]>
Jenkins Console Log Machine informationNo LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focalCPU: G++: Clang: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andrjohns, thanks!! LGTM! Thanks for updating the code.
Merging! |
Summary
This PR exposes the
hypergeometric_1f0
function from Boost and adds gradients. The gradients for the 1F0 are much simpler than the other hypergeometric series and can be expressed analytically (no need for thegrad_pFq
function)Tests
prim
tests for values and throwing behaviour added,mix
tests for gradients added via the ad testing frameworkSide Effects
N/A
Release notes
Added the Hypergeometric 1F0 function and gradients
Checklist
Math issue #(issue number)
Copyright holder: Andrew Johnson
The copyright holder is typically you or your assignee, such as a university or company. By submitting this pull request, the copyright holder is agreeing to the license the submitted work under the following licenses:
- Code: BSD 3-clause (https://opensource.org/licenses/BSD-3-Clause)
- Documentation: CC-BY 4.0 (https://creativecommons.org/licenses/by/4.0/)
the basic tests are passing
./runTests.py test/unit
)make test-headers
)make test-math-dependencies
)make doxygen
)make cpplint
)the code is written in idiomatic C++ and changes are documented in the doxygen
the new changes are tested