-
Notifications
You must be signed in to change notification settings - Fork 148
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
StackOverflowError with complex sqrt
#324
Comments
This is basically JuliaLang/julia#26552 I believe. |
I'm running into the same issue when trying to get a derivative over a complex sqrt operation. Here I was able to reproduce the error in a simplified way: > x = ForwardDiff.Dual{Nothing}(1,0.0,0.0,0.0)*im
> sqrt(x)
StackOverflowError:
Stacktrace:
[1] Type at ./complex.jl:12 [inlined] (repeats 2 times)
[2] float at ./complex.jl:967 [inlined]
[3] sqrt(::Complex{ForwardDiff.Dual{Nothing,Float64,3}}) at ./complex.jl:461 (repeats 80000 times) Has anyone found a solution for this? |
I too am running into this |
This is a problem for me as well. Any ideas about how to deal with this? |
I run into same error with a just updated Turing/ForwardDiff. |
See the discussion in #157 |
I am trying this out in julia v1.6 and it's sometimes working okay now. function Base.ssqs(x::T, y::T) where T <: ForwardDiff.Dual
k::Int = 0
ρ = x*x + y*y
@show x
if !isfinite(ρ) && (isinf(x) || isinf(y))
ρ = convert(T, Inf)
elseif isinf(ρ) || (ρ==0 && (x!=0 || y!=0)) || ρ<nextfloat(zero(T))/(2*eps(T)^2)
m::T = max(abs(x), abs(y))
@show m
k = m==0 ? m : Base.exponent(m)
xk, yk = Base.ldexp(x,-k), Base.ldexp(y,-k)
ρ = xk*xk + yk*yk
end
ρ, k
end
|
When differentiating over a complex sqrt
x0 = 5
ForwardDiff.derivative(x -> sqrt(1im * x), x0)
a StackOverflowError is encountered.
The stacktrace points to the following declaration
sqrt(z::Complex) = sqrt(float(z))
I have found similar issues #111 #196 #239, but I don't see how I can fix this problem.
The text was updated successfully, but these errors were encountered: