JuliaDiff / AbstractDifferentiation.jl

An abstract interface for automatic differentiation.
https://juliadiff.org/AbstractDifferentiation.jl/
MIT License
135 stars 18 forks source link

Complex pullback support #22

Open sethaxen opened 2 years ago

sethaxen commented 2 years ago

I realized that if the _dot function introduced in #21 is wrapped with real, then pullback_function works for complex arrays as well, whenever gradient supports complex inputs for a given backend. But at least in the scalar case, the real dot product can be computed twice as efficiently as real(_dot(x, y)).

sethaxen commented 2 years ago

Not certain if this package wants to support complex AD (with Jacobians as the primitive, complex support is a little awkward), but to me it seems like, if the AD supports complex numbers, then at least for pushforwards, pullbacks, and gradients, it'd be nice if we did too.

mohamed82008 commented 2 years ago

I agree. Even Jacobians can be supported as long as either the inputs or outputs are real.

sethaxen commented 2 years ago

That's right, and even with both complex inputs and outputs, it can be supported by interleaving the real and imaginary parts into one real vector, but having the eltype be dependent on the real-ness of input and output starts to feel messy.

mohamed82008 commented 2 years ago

ya complex input and output is messy, let's stick to the simple cases