Skip to content
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

Imaginary part of complex gradient is dropped #75

Closed
sethaxen opened this issue Apr 20, 2020 · 5 comments
Closed

Imaginary part of complex gradient is dropped #75

sethaxen opened this issue Apr 20, 2020 · 5 comments

Comments

@sethaxen
Copy link
Member

In a number of cases at least, it seems that the imaginary part of the gradient for complex inputs and real scalar outputs is dropped. A few examples:

julia> using FiniteDifferences

julia> x = randn(ComplexF64, 3)
3-element Array{Complex{Float64},1}:
   0.5296680539510132 + 0.508966079006392im
  0.45109029662066524 + 1.4033240412225767im
 -0.49491015411581324 + 0.15307916651762313im

julia> FiniteDifferences.grad(central_fdm(5, 1), x -> sum(abs2, x), x)[1] # expected: 2x
3-element Array{Float64,1}:
  1.0593361079020813
  0.9021805932413423
 -0.9898203082316152

julia> 2x
3-element Array{Complex{Float64},1}:
  1.0593361079020265 + 1.017932158012784im
  0.9021805932413305 + 2.8066480824451534im
 -0.9898203082316265 + 0.30615833303524626im

julia> FiniteDifferences.grad(central_fdm(5, 1), abs2, 1.0+2.0im)[1] # expected: 2.0 + 4.0im
1.9999999999999962

Also, am I supposed to see this error?

FiniteDifferences.grad(central_fdm(5, 1), abs2, 1+2im)[1] # expected: 2.0 + 4.0im
ERROR: InexactError: Int64(0.9879814839007404)
@willtebbutt
Copy link
Member

Thanks for raising the issue. What version of FiniteDifferences are you running?

@sethaxen
Copy link
Member Author

I saw this with both the most recent release (v0.9.6) and master on Julia 1.4.

@sethaxen
Copy link
Member Author

I just checked a few releases, and it looks like the return type became real in v0.9.3, but before that the imaginary part was just 0 going back at least to v0.8.

@willtebbutt
Copy link
Member

Closing this with #76 . @sethaxen please feel free to re-open if it turns out that this hasn't solved your issue.

@nickrobinson251
Copy link
Contributor

nickrobinson251 commented Apr 25, 2020

in #76 (#76 (comment)) it was decided this was a breaking change (rather than a bug fix), so the change is available in a new breaking release v0.10.0 (280c4fa)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants