-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[WIP] port of Cephes implementation of Beta function (fixes #14256) #14349
Conversation
direct ports need to retain original copyright notices. either the header of this file should be modified to note the exception (along with license.md and contrib/add_license_to_files.jl) or we could make a separate file if we expect to port anything else from the same source. |
|
||
# Asymptotic expansion for ln(|B(a, b)|) for a > ASYMP_FACTOR*max(|b|, 1). | ||
function lbeta_asymp(a::Number, b::Number) | ||
r, s = lgammma_r(b) |
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.
lgamma_r
sorry, I was working and testing a temporary file, should pass tests now |
You still have 3 |
will do |
The basic problem is that the Cephes code is really only for double precision. You can't use the same constant factors |
real(a) <= 0.0 && isinteger(a) && return beta_negint(a, b) | ||
real(b) <= 0.0 && isinteger(b) && return beta_negint(b, a) | ||
|
||
if abs(a) < abs(b) |
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.
Note that abs
is unnecessarily slow for complex numbers. I would tend to define a fastabs(x)
, where fastabs(x::Real) = abs(x)
and fastabs(z::Complex) = abs(real(z)) + abs(imag(z))
. This is within a factor of sqrt(2)
of abs(z)
but is much faster, and the sqrt(2)
factor doesn't really matter for an application like this if you adjust the thresholds accordingly.
- use fastabs for complex numbers - add a test for asymptotic behaviour from issue JuliaLang#4301
todo:
|
|
port of https://github.com/scipy/scipy/blob/0cff7a5fe6226668729fc2551105692ce114c2b3/scipy/special/cephes/beta.c#L61-L133
Copyright issues (none actually) are discussed in #14256
see also #14165 for its relation with the binomial function
Comments appreciated @tkelman @stevengj @andreasnoack
TODO