-
Notifications
You must be signed in to change notification settings - Fork 101
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
Test type-stability of functions #43
base: master
Are you sure you want to change the base?
Conversation
I believe the instabilities in if typemin(Cint) <= nu <= typemax(Cint) for which there is no The tests pass in Julia 0.6 with the following patch: diff --git a/src/bessel.jl b/src/bessel.jl
index 958ac37..4f52082 100644
--- a/src/bessel.jl
+++ b/src/bessel.jl
@@ -388,6 +388,8 @@ function besselj(nu::Real, x::AbstractFloat)
if isinteger(nu)
if typemin(Cint) <= nu <= typemax(Cint)
return besselj(Cint(nu), x)
+ else
+ error()
end
elseif x < 0
throw(DomainError(x, "`x` must be nonnegative."))
@@ -443,8 +445,12 @@ Bessel function of the second kind of order `nu`, ``Y_\\nu(x)``.
function bessely(nu::Real, x::AbstractFloat)
if x < 0
throw(DomainError(x, "`x` must be nonnegative."))
- elseif isinteger(nu) && typemin(Cint) <= nu <= typemax(Cint)
- return bessely(Cint(nu), x)
+ elseif isinteger(nu)
+ if typemin(Cint) <= nu <= typemax(Cint)
+ return bessely(Cint(nu), x)
+ else
+ error()
+ end
end
real(bessely(float(nu), complex(x)))
end Well, in place of |
Excellent catch @giordano |
Hmm actually I think the problem is a little different. The problem is not with the conditionals but rather bessely(nu::Real, z::Complex) in SpecialFunctions at C:\Users\Mus\.julia\v0.7\SpecialFunctions\src\bessel.jl:470 always return a |
Uhm, not sure I understand what you mean: julia> besselj(-3f0, complex(3f0))
-0.30906272f0 - 3.7849267f-17im
julia> bessely(-3f0, complex(3f0))
0.5385416f0 + 0.0f0im are correctly Maybe the issue is how those methods are called? |
Consider julia> x = 2f0
2.0f0
julia> nu = 2.0
2.0
julia> bessely(nu,x)
-0.6174081f0
This calls julia> real(bessely(float(nu), complex(x)))
-0.6174081041906828 which is called on line 449 and this causes the type instability |
So we're saying the same thing 🙂 |
Basically, but I don't think the patch you propose actually fixes the type instability; may need to stick |
Anyways I think the discussion got sidetracked, since these are besides the point of this PR. |
bump |
@giordano Should we get this merged? If so, would it be possible for you to rebase? |
Use
@inferred
to test type-stability of functions.besselj
andbessely
are unstable in Julia 0.6 and 0.7.digamma
,trigamma
,invdigamma
,polygamma
,eta
,zeta
are unstable in Julia 0.7 only.Type-instability of
digamma
was already reported in issue #42.