-
I'd like to compute the derivative of the function
and the output is
You can see that the forward mode gives correct answer, but the reverse mode (by vjp) has a type conversion which leads to real derivatives. If I convert the input to complex numbers, the reverse mode works right. Is this a bug or am I doing anything wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
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 As you observed, if Luckily, since What do you think? |
Beta Was this translation helpful? Give feedback.
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
…