ForwardDiff.jl icon indicating copy to clipboard operation
ForwardDiff.jl copied to clipboard

Support derivative(f, ::Complex)

Open dlfivefifty opened this issue 2 years ago • 2 comments

I think the following should work:

julia> ForwardDiff.derivative(identity, 1+im)
ERROR: DimensionMismatch: derivative(f, x) expects that x is a real number (does not support Wirtinger derivatives). Separate real and imaginary parts of the input.
Stacktrace:
 [1] derivative(f::Function, x::Complex{Int64})
   @ ForwardDiff ~/.julia/packages/ForwardDiff/PcZ48/src/derivative.jl:73
 [2] top-level scope
   @ REPL[35]:1

Note that https://github.com/JuliaDiff/ForwardDiff.jl/issues?q=is%3Aissue+is%3Aclosed+complex supports Complex{<:Dual} so the implementation would be really straightforward.

I was surprised not to see a discussion on this. Would a PR adding automatic support for complex differentiation be merged?

dlfivefifty avatar Nov 24 '23 11:11 dlfivefifty

I also cam across this - it would be quite nice, also for classroom demonstration

ranocha avatar May 23 '24 11:05 ranocha