Diffractor.jl
Diffractor.jl copied to clipboard
`x.re` gives a Tangent not a Complex
trafficstars
julia> gradient(x -> x.re, 2+3im)
(Tangent{Complex{Int64}}(re = 1,),)
julia> gradient(x -> abs2(x * x.re), 4+5im)
ERROR: MethodError: no method matching +(::ComplexF64, ::Tangent{Complex{Int64}, NamedTuple{(:re,), Tuple{Float64}}})
~~I suspect we should fix this in ChainRulesCore. IIUC this works in Zygote because it turns the Tangent types into NamedTuples internally. Should we move the issue there?~~
julia> t = Tangent{Complex{Int64}}(re = 1,)
julia> t + 1im
1 + 1im
julia> t + 1.0im
ERROR: MethodError: no method matching +(::Tangent{Complex{Int64}, NamedTuple{(:re,), Tuple{Int64}}}, ::ComplexF64)
~~We probably have to modify Base.:+(a::Tangent{P}, b::P) where {P} = b + a to handle projections? (Did not check)~~
Oh, sorry, I retract all the above, indeed it should just return a Complex number