-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error differentiating through complex power due to isinteger #637
Comments
What is Guessing from the stack trace, I think the MWE is this: julia> (Dual(1, 0.2) + 0im) ^ Dual(3, 0.1)
ERROR: InexactError: Int(Int64, Dual{Nothing}(3.0,0.1))
Stacktrace:
[1] Int64
@ ~/.julia/packages/ForwardDiff/vXysl/src/dual.jl:364 [inlined]
[2] convert
@ ./number.jl:7 [inlined]
[3] _cpow(z::Complex{Dual{Nothing, Float64, 1}}, p::Dual{Nothing, Float64, 1})
@ Base ./complex.jl:791
[4] ^(z::Complex{Dual{Nothing, Float64, 1}}, p::Dual{Nothing, Float64, 1})
@ Base ./complex.jl:860 Changing |
test_func is a function that constructs a pdf from a fourier inverted characteristic version, and is an object from the Interpolations package. But I believe this is might indeed be related to your comment that you just linked. I wonder why I didn't face this before even though I have been differentiating through this particular piece of code for quite some time, and it still works well in the previous cases where I do it. |
It's in this particular line from https://gitlab.com/tom.plaa/CharacteristicInvFourier.jl/-/blob/main/src/CharacteristicInvFourier.jl#L101
So yes, equivalent it seems. What's confusing to me is that it never gave that error before, and now I tried to declare a single local instance of that function inside another and suddenly everything breaks. |
Ok. One guess might be that earlier operations made the dual part zero, or the real part non-integer? But I don't know. I don't think ForwardDiff has changed much. Edit: Seeing broadcasting in your line, if you are using Zygote, its broadcasting has a fairly recent change. Before, this would use Dual only for real numbers, and something much slower otherwise. After, it uses Dual for complex numbers too. Note that unlike the other 481 problems, I don't think this shortcut behind an julia> (Dual(1.1, 0.2) + 0im) ^ Dual(3, 0.0) # takes the isinteger shortcut
Dual{Nothing}(1.3310000000000004,0.7260000000000002) + Dual{Nothing}(0.0,0.0)*im
julia> (Dual(1.1, 0.2) + 0im) ^ Dual(3.00001, 0.0) # does not, should be very close
Dual{Nothing}(1.3310012685790982,0.7260031119545418) + Dual{Nothing}(0.0,0.0)*im |
Interesting point, but do you mean I can try that temporary hack to get around the convertion for now?
Where Here is the version that raises this error:
I don't understand why declaring my function as a local instance breaks, but the other case doesn't. |
I understood the difference, the try/catch statement was just hiding the error and assigning -Inf's all the way down. It would be like:
Although we currently have
Which means that to make this coherent it would instead be |
I have a weird case where a complex power is giving me an inexact error because the
_cpow
helper function determines my object to be an integer.Truncated error message:
So given that
It seems that we can get the following MWE:
This is the associated culprit line in complex.jl that tries to do this conversion to Int (only the relevant part is shown):
Admittedly, I am not sure if the partials should be considered for determining if it's an integer or not.
The text was updated successfully, but these errors were encountered: