Skip to content

vjp for a complex function with real inputs gives wrong results #6817

Answered by mattjj
fishjojo asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for the question! If you haven't taken a look already, I suggest reading the autodiff cookbook section on complex numbers and differentiation.

In general, the VJP of an R->C function will be a C->R function. That is, it'll always produce real results, and so the behavior you described is working as intended.

Fundamentally this comes down to the difference between JVPs/VJPs and the coefficients of a Jacobian matrix. I think you were expecting the (scalar) Jacobian, since indeed that's what the expression -iG exp(-iR⋅G) evaluates to. That's a reasonable thing to want! To get a Jacobian from autodiff, we have to figure out how to get it from JVPs and VJPs.

As you observed, if f : R->C

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@fishjojo
Comment options

@PhilipVinc
Comment options

@fishjojo
Comment options

Answer selected by fishjojo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants